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