1 #ifndef MUPDF_GL_APP_H
2 #define MUPDF_GL_APP_H
3 
4 #ifdef _WIN32
5 #include <windows.h>
6 void win_install(void);
7 #endif
8 
9 #include "mupdf/fitz.h"
10 #include "mupdf/ucdn.h"
11 #include "mupdf/pdf.h" /* for pdf specifics and forms */
12 
13 #ifndef __APPLE__
14 #include <GL/freeglut.h>
15 #else
16 #include <GLUT/glut.h>
17 #endif
18 
19 /* UI */
20 
21 enum
22 {
23 	/* regular control characters */
24 	KEY_ESCAPE = 27,
25 	KEY_ENTER = '\r',
26 	KEY_TAB = '\t',
27 	KEY_BACKSPACE = '\b',
28 	KEY_DELETE = 127,
29 
30 	KEY_CTL_A = 'A' - 64,
31 	KEY_CTL_B, KEY_CTL_C, KEY_CTL_D, KEY_CTL_E, KEY_CTL_F,
32 	KEY_CTL_G, KEY_CTL_H, KEY_CTL_I, KEY_CTL_J, KEY_CTL_K, KEY_CTL_L,
33 	KEY_CTL_M, KEY_CTL_N, KEY_CTL_O, KEY_CTL_P, KEY_CTL_Q, KEY_CTL_R,
34 	KEY_CTL_S, KEY_CTL_T, KEY_CTL_U, KEY_CTL_V, KEY_CTL_W, KEY_CTL_X,
35 	KEY_CTL_Y, KEY_CTL_Z,
36 
37 	/* reuse control characters > 127 for special keys */
38 	KEY_INSERT = 128,
39 	KEY_PAGE_UP,
40 	KEY_PAGE_DOWN,
41 	KEY_HOME,
42 	KEY_END,
43 	KEY_LEFT,
44 	KEY_UP,
45 	KEY_RIGHT,
46 	KEY_DOWN,
47 	KEY_F1,
48 	KEY_F2,
49 	KEY_F3,
50 	KEY_F4,
51 	KEY_F5,
52 	KEY_F6,
53 	KEY_F7,
54 	KEY_F8,
55 	KEY_F9,
56 	KEY_F10,
57 	KEY_F11,
58 	KEY_F12,
59 };
60 
61 enum side { ALL, T, R, B, L };
62 enum fill { NONE = 0, X = 1, Y = 2, BOTH = 3 };
63 enum anchor { CENTER, N, NE, E, SE, S, SW, W, NW };
64 
65 struct layout
66 {
67 	enum side side;
68 	enum fill fill;
69 	enum anchor anchor;
70 	int padx, pady;
71 };
72 
73 struct ui
74 {
75 	int window_w, window_h;
76 
77 	int x, y;
78 	int down, down_x, down_y;
79 	int middle, middle_x, middle_y;
80 	int right, right_x, right_y;
81 
82 	int scroll_x, scroll_y;
83 	int key, mod, plain;
84 
85 	int grab_down, grab_middle, grab_right;
86 	const void *hot, *active, *focus;
87 	int last_cursor, cursor;
88 
89 	int fontsize;
90 	int baseline;
91 	int lineheight;
92 	int gridsize;
93 
94 	struct layout *layout;
95 	fz_irect *cavity;
96 	struct layout layout_stack[32];
97 	fz_irect cavity_stack[32];
98 
99 	int overlay;
100 	GLuint overlay_list;
101 
102 	void (*dialog)(void);
103 };
104 
105 extern struct ui ui;
106 
107 void ui_init(int w, int h, const char *title);
108 void ui_quit(void);
109 void ui_invalidate(void);
110 void ui_finish(void);
111 
112 void ui_set_clipboard(const char *buf);
113 const char *ui_get_clipboard(void);
114 
115 void ui_init_fonts(void);
116 void ui_finish_fonts(void);
117 
118 void ui_draw_string(float x, float y, const char *str);
119 void ui_draw_string_part(float x, float y, const char *s, const char *e);
120 void ui_draw_character(float x, float y, int c);
121 float ui_measure_character(int ucs);
122 float ui_measure_string(const char *str);
123 float ui_measure_string_part(const char *s, const char *e);
124 
125 struct line { char *a, *b; };
126 
127 int ui_break_lines(char *a, struct line *lines, int nlines, int width, int *maxwidth);
128 void ui_draw_lines(float x, float y, struct line *lines, int n);
129 
130 struct texture
131 {
132 	GLuint id;
133 	int x, y, w, h;
134 	float s, t;
135 };
136 
137 void ui_texture_from_pixmap(struct texture *tex, fz_pixmap *pix);
138 void ui_draw_image(struct texture *tex, float x, float y);
139 
140 enum
141 {
142 	UI_INPUT_NONE = 0,
143 	UI_INPUT_EDIT = 1,
144 	UI_INPUT_ACCEPT = 2,
145 };
146 
147 struct input
148 {
149 	char text[16*1024];
150 	char *end, *p, *q;
151 	int scroll;
152 };
153 
154 struct list
155 {
156 	fz_irect area;
157 	int scroll_y;
158 	int item_y;
159 	int is_tree;
160 };
161 
162 void ui_begin(void);
163 void ui_end(void);
164 
165 int ui_mouse_inside(fz_irect area);
166 
167 void ui_layout(enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
168 fz_irect ui_pack_layout(int slave_w, int slave_h, enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
169 fz_irect ui_pack(int slave_w, int slave_h);
170 int ui_available_width(void);
171 int ui_available_height(void);
172 void ui_pack_push(fz_irect cavity);
173 void ui_pack_pop(void);
174 
175 void ui_dialog_begin(int w, int h);
176 void ui_dialog_end(void);
177 void ui_panel_begin(int w, int h, int padx, int pady, int opaque);
178 void ui_panel_end(void);
179 
180 void ui_spacer(void);
181 void ui_splitter(int *x, int min, int max, enum side side);
182 void ui_label(const char *fmt, ...);
183 void ui_label_with_scrollbar(char *text, int width, int height, int *scroll);
184 
185 int ui_button(const char *label);
186 /* flags: bit 0 -> disabled. all other bits 0 for now. */
187 int ui_button_aux(const char *label, int flags);
188 int ui_checkbox(const char *label, int *value);
189 int ui_checkbox_aux(const char *label, int *value, int flags);
190 int ui_slider(int *value, int min, int max, int width);
191 int ui_select(const void *id, const char *current, const char *options[], int n);
192 int ui_select_aux(const void *id, const char *current, const char *options[], int n, int flags);
193 
194 void ui_input_init(struct input *input, const char *text);
195 int ui_input(struct input *input, int width, int height);
196 void ui_scrollbar(int x0, int y0, int x1, int y1, int *value, int page_size, int max);
197 
198 void ui_tree_begin(struct list *list, int count, int req_w, int req_h, int is_tree);
199 int ui_tree_item(struct list *list, const void *id, const char *label, int selected, int depth, int is_branch, int *is_open);
200 void ui_tree_end(struct list *list);
201 
202 void ui_list_begin(struct list *list, int count, int req_w, int req_h);
203 int ui_list_item(struct list *list, const void *id, const char *label, int selected);
204 void ui_list_end(struct list *list);
205 
206 int ui_popup(const void *id, const char *label, int is_button, int count);
207 int ui_popup_item(const char *title);
208 int ui_popup_aux(const void *id, const char *label, int is_button, int count, int flags);
209 int ui_popup_item_aux(const char *title, int flags);
210 void ui_popup_end(void);
211 
212 void ui_init_open_file(const char *dir, int (*filter)(const char *fn));
213 int ui_open_file(char filename[], const char *label);
214 void ui_init_save_file(const char *path, int (*filter)(const char *fn));
215 int ui_save_file(char filename[], void (*extra_panel)(void), const char *label);
216 
217 void ui_show_warning_dialog(const char *fmt, ...);
218 void ui_show_error_dialog(const char *fmt, ...);
219 
220 /* Theming */
221 
222 enum
223 {
224 	UI_COLOR_PANEL = 0xc0c0c0,
225 	UI_COLOR_BUTTON = 0xc0c0c0,
226 	UI_COLOR_SCROLLBAR = 0xdfdfdf,
227 	UI_COLOR_TEXT_BG = 0xffffff,
228 	UI_COLOR_TEXT_FG = 0x000000,
229 	UI_COLOR_TEXT_GRAY = 0x808080,
230 	UI_COLOR_TEXT_SEL_BG = 0x000080,
231 	UI_COLOR_TEXT_SEL_FG = 0xffffff,
232 	UI_COLOR_BEVEL_1 = 0x000000,
233 	UI_COLOR_BEVEL_2 = 0x808080,
234 	UI_COLOR_BEVEL_3 = 0xdfdfdf,
235 	UI_COLOR_BEVEL_4 = 0xffffff,
236 };
237 
238 void glColorHex(unsigned int hex);
239 void ui_draw_bevel(fz_irect area, int depressed);
240 void ui_draw_ibevel(fz_irect area, int depressed);
241 void ui_draw_bevel_rect(fz_irect area, unsigned int fill, int depressed);
242 void ui_draw_ibevel_rect(fz_irect area, unsigned int fill, int depressed);
243 
244 /* App */
245 
246 extern fz_context *ctx;
247 extern pdf_document *pdf;
248 extern pdf_page *page;
249 extern fz_stext_page *page_text;
250 extern pdf_annot *selected_annot;
251 extern fz_matrix draw_page_ctm, view_page_ctm, view_page_inv_ctm;
252 extern fz_rect page_bounds, draw_page_bounds, view_page_bounds;
253 extern fz_irect view_page_area;
254 extern char filename[];
255 extern int showform;
256 extern int showannotate;
257 extern int reloadrequested;
258 extern char *search_needle;
259 extern int search_hit_count;
260 extern fz_quad search_hit_quads[];
261 
262 int search_has_results(void);
263 enum {
264 	ANNOTATE_MODE_NONE = 0,
265 	ANNOTATE_MODE_NORMAL = 1,
266 	ANNOTATE_MODE_REDACT = 2
267 };
268 void toggle_annotate(int mode);
269 void run_main_loop(void);
270 void do_annotate_panel(void);
271 void do_annotate_canvas(fz_irect canvas_area);
272 void do_redact_panel(void);
273 void do_widget_canvas(fz_irect canvas_area);
274 void load_page(void);
275 void render_page(void);
276 void update_title(void);
277 void reload(void);
278 void do_save_pdf_file(void);
279 void do_save_signed_pdf_file(void);
280 int do_sign(void);
281 void trace_action(const char *fmt, ...);
282 void trace_page_update(void);
283 void trace_save_snapshot(void);
284 
285 #endif
286