1#ifdef _WIN32
2#include <windows.h>
3void 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
18enum
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
58enum side { ALL, T, R, B, L };
59enum fill { NONE = 0, X = 1, Y = 2, BOTH = 3 };
60enum anchor { CENTER, N, NE, E, SE, S, SW, W, NW };
61
62struct layout
63{
64 enum side side;
65 enum fill fill;
66 enum anchor anchor;
67 int padx, pady;
68};
69
70struct 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
102extern struct ui ui;
103
104void ui_init(int w, int h, const char *title);
105void ui_quit(void);
106void ui_invalidate(void);
107void ui_finish(void);
108
109void ui_set_clipboard(const char *buf);
110const char *ui_get_clipboard(void);
111
112void ui_init_fonts(void);
113void ui_finish_fonts(void);
114
115void ui_draw_string(float x, float y, const char *str);
116void ui_draw_string_part(float x, float y, const char *s, const char *e);
117void ui_draw_character(float x, float y, int c);
118float ui_measure_character(int ucs);
119float ui_measure_string(const char *str);
120float ui_measure_string_part(const char *s, const char *e);
121
122struct line { char *a, *b; };
123
124int ui_break_lines(char *a, struct line *lines, int nlines, int width, int *maxwidth);
125void ui_draw_lines(float x, float y, struct line *lines, int n);
126
127struct texture
128{
129 GLuint id;
130 int x, y, w, h;
131 float s, t;
132};
133
134void ui_texture_from_pixmap(struct texture *tex, fz_pixmap *pix);
135void ui_draw_image(struct texture *tex, float x, float y);
136
137enum
138{
139 UI_INPUT_NONE = 0,
140 UI_INPUT_EDIT = 1,
141 UI_INPUT_ACCEPT = 2,
142};
143
144struct input
145{
146 char text[16*1024];
147 char *end, *p, *q;
148 int scroll;
149};
150
151struct list
152{
153 fz_irect area;
154 int scroll_y;
155 int item_y;
156 int is_tree;
157};
158
159void ui_begin(void);
160void ui_end(void);
161
162int ui_mouse_inside(fz_irect area);
163
164void ui_layout(enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
165fz_irect ui_pack_layout(int slave_w, int slave_h, enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
166fz_irect ui_pack(int slave_w, int slave_h);
167int ui_available_width(void);
168int ui_available_height(void);
169void ui_pack_push(fz_irect cavity);
170void ui_pack_pop(void);
171
172void ui_dialog_begin(int w, int h);
173void ui_dialog_end(void);
174void ui_panel_begin(int w, int h, int padx, int pady, int opaque);
175void ui_panel_end(void);
176
177void ui_spacer(void);
178void ui_splitter(int *x, int min, int max, enum side side);
179void ui_label(const char *fmt, ...);
180void ui_label_with_scrollbar(char *text, int width, int height, int *scroll);
181int ui_button(const char *label);
182int ui_checkbox(const char *label, int *value);
183int ui_slider(int *value, int min, int max, int width);
184int ui_select(const void *id, const char *current, const char *options[], int n);
185
186void ui_input_init(struct input *input, const char *text);
187int ui_input(struct input *input, int width, int height);
188void ui_scrollbar(int x0, int y0, int x1, int y1, int *value, int page_size, int max);
189
190void ui_tree_begin(struct list *list, int count, int req_w, int req_h, int is_tree);
191int ui_tree_item(struct list *list, const void *id, const char *label, int selected, int depth, int is_branch, int *is_open);
192void ui_tree_end(struct list *list);
193
194void ui_list_begin(struct list *list, int count, int req_w, int req_h);
195int ui_list_item(struct list *list, const void *id, const char *label, int selected);
196void ui_list_end(struct list *list);
197
198int ui_popup(const void *id, const char *label, int is_button, int count);
199int ui_popup_item(const char *title);
200void ui_popup_end(void);
201
202void ui_init_open_file(const char *dir, int (*filter)(const char *fn));
203int ui_open_file(char filename[]);
204void ui_init_save_file(const char *path, int (*filter)(const char *fn));
205int ui_save_file(char filename[], void (*extra_panel)(void));
206
207void ui_show_warning_dialog(const char *fmt, ...);
208void ui_show_error_dialog(const char *fmt, ...);
209
210/* Theming */
211
212enum
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
227void glColorHex(unsigned int hex);
228void ui_draw_bevel(fz_irect area, int depressed);
229void ui_draw_ibevel(fz_irect area, int depressed);
230void ui_draw_bevel_rect(fz_irect area, unsigned int fill, int depressed);
231void ui_draw_ibevel_rect(fz_irect area, unsigned int fill, int depressed);
232
233/* App */
234
235extern fz_context *ctx;
236extern pdf_document *pdf;
237extern pdf_page *page;
238extern fz_stext_page *page_text;
239extern pdf_annot *selected_annot;
240extern fz_matrix draw_page_ctm, view_page_ctm, view_page_inv_ctm;
241extern fz_rect page_bounds, draw_page_bounds, view_page_bounds;
242extern fz_irect view_page_area;
243extern char filename[];
244extern int showform;
245extern int showannotate;
246extern int reloadrequested;
247
248void toggle_annotate();
249void run_main_loop(void);
250void do_annotate_panel(void);
251void do_annotate_canvas(fz_irect canvas_area);
252void do_widget_panel(void);
253void do_widget_canvas(fz_irect canvas_area);
254void load_page(void);
255void render_page(void);
256void update_title(void);
257void reload(void);
258void do_save_pdf_file(void);
259