1 /*
2  * Copyright (c) 2003-2004 the xdvik development team
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef DVI_SEARCH_H_
24 #define DVI_SEARCH_H_
25 
26 #include "xdvi-config.h"
27 #include "xdvi.h"
28 
29 #include "search-dialog.h"
30 #include "dvisel.h"
31 
32 /* Widget names that are used in callbacks */
33 #define Xdvi_SEARCHBOX_INPUT_NAME "searchbox_input"
34 #define Xdvi_SEARCH_POPUP_NAME "find_popup"
35 
36 /* A sorted dynamic array that maps text buffer (i.e. word)
37  * positions to DVI file offsets.
38  */
39 
40 struct pos_info {
41     size_t buffer_pos;	/* position in text buffer */
42     struct bbox bbox;	/* bounding box of this word */
43 };
44 
45 struct page_mapping {
46     int pageno;
47     int offset;
48 };
49 
50 struct word_info {
51     char *txt_buf;	 /* contains scanned text as whitespace separated strings */
52     size_t txt_buf_size; /* size of above buffer */
53     size_t curr_buf_idx;	 /* current position in buffer */
54     struct bbox *bboxes;	/* dynamic array of position infos */
55     size_t bboxes_size;	/* size of above array */
56     size_t bboxes_idx;	 /* current position in buffer */
57     const struct page_mapping *page_mapping;		/* list of page offsets, for bbox_pass */
58     struct search_settings *settings;	/* pointer to search settings, for bbox_pass */
59     int buffer_offset;	/* offset to start of buffer from text on previous pages */
60     Boolean bbox_pass;		/* whether we're scanning for bounding boxes of match */
61     Boolean search_scan_pass;	/* whether we're scanning for text in string search */
62     Boolean text_selection_pass; /* whether we're scanning for text selection */
63 };
64 
65 struct save_or_print_info; /* forward declaration */
66 
67 extern void isearch_start(void);
68 extern void search_dvi(XtPointer settings);
69 extern void search_restart(XtPointer settings);
70 extern Boolean search_extract_text(struct save_or_print_info *info);
71 extern Boolean search_have_match(int pageno);
72 extern int search_inside_bbox_match(int x, int y);
73 extern void search_draw_inverted_regions(void);
74 extern void search_signal_page_changed(void);
75 extern void search_reset_info(void);
76 extern void search_erase_highlighting(Boolean flag);
77 extern void search_putback_expose(void);
78 extern char *get_text_selection(int *len, int x, int y, int w, int h);
79 
80 #if 0
81 #define TEST_DELAY(s)				\
82     do {					\
83 	TRACE_FIND((stderr, s));		\
84 	int i, j;				\
85 	XSync(DISP, False);			\
86 	for (i = 0; i < 10000; i++)		\
87 	    for (j = 0; j < 20000; j++);	\
88     } while (0)
89 #else
90 #define TEST_DELAY(s) /* as nothing */
91 #endif
92 
93 #endif /* DVI_SEARCH_H_ */
94 
95