Rev 7533 | Rev 7624 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7533 | Rev 7621 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #define _WIN32 |
2 | #define _WIN32 |
3 | #include "fitz.h" |
3 | #include "fitz.h" |
4 | #include "mupdf.h" |
4 | #include "mupdf.h" |
5 | #include "muxps.h" |
- | |
6 | #include "pdfapp.h" |
5 | #include "pdfapp.h" |
7 | #include "icons/allbtns.h" |
6 | #include "icons/allbtns.h" |
8 | #include "kolibri.c" |
7 | #include "kolibri.c" |
9 | 8 | ||
10 | // need to be a part of menuet/os.h |
9 | // need to be a part of menuet/os.h |
11 | #define BT_DEL 0x80000000 |
10 | #define BT_DEL 0x80000000 |
12 | #define BT_HIDE 0x40000000 |
11 | #define BT_HIDE 0x40000000 |
13 | #define BT_NOFRAME 0x20000000 |
12 | #define BT_NOFRAME 0x20000000 |
14 | 13 | ||
15 | #define evReDraw 1 |
14 | #define evReDraw 1 |
16 | #define evKey 2 |
15 | #define evKey 2 |
17 | #define evButton 3 |
16 | #define evButton 3 |
18 | #define evMouse 6 |
17 | #define evMouse 6 |
19 | #define evNetwork 8 |
18 | #define evNetwork 8 |
20 | 19 | ||
21 | #define ASCII_KEY_LEFT 176 |
20 | #define ASCII_KEY_LEFT 176 |
22 | #define ASCII_KEY_RIGHT 179 |
21 | #define ASCII_KEY_RIGHT 179 |
23 | #define ASCII_KEY_DOWN 177 |
22 | #define ASCII_KEY_DOWN 177 |
24 | #define ASCII_KEY_UP 178 |
23 | #define ASCII_KEY_UP 178 |
25 | #define ASCII_KEY_HOME 180 |
24 | #define ASCII_KEY_HOME 180 |
26 | #define ASCII_KEY_END 181 |
25 | #define ASCII_KEY_END 181 |
27 | #define ASCII_KEY_PGDN 183 |
26 | #define ASCII_KEY_PGDN 183 |
28 | #define ASCII_KEY_PGUP 184 |
27 | #define ASCII_KEY_PGUP 184 |
29 | 28 | ||
30 | #define ASCII_KEY_BS 8 |
29 | #define ASCII_KEY_BS 8 |
31 | #define ASCII_KEY_TAB 9 |
30 | #define ASCII_KEY_TAB 9 |
32 | #define ASCII_KEY_ENTER 13 |
31 | #define ASCII_KEY_ENTER 13 |
33 | #define ASCII_KEY_ESC 27 |
32 | #define ASCII_KEY_ESC 27 |
34 | #define ASCII_KEY_DEL 182 |
33 | #define ASCII_KEY_DEL 182 |
35 | #define ASCII_KEY_INS 185 |
34 | #define ASCII_KEY_INS 185 |
36 | #define ASCII_KEY_SPACE 032 |
35 | #define ASCII_KEY_SPACE 032 |
37 | 36 | ||
38 | struct blit_call |
37 | struct blit_call |
39 | { |
38 | { |
40 | int dstx; |
39 | int dstx; |
41 | int dsty; |
40 | int dsty; |
42 | int w; |
41 | int w; |
43 | int h; |
42 | int h; |
44 | 43 | ||
45 | int srcx; |
44 | int srcx; |
46 | int srcy; |
45 | int srcy; |
47 | int srcw; |
46 | int srcw; |
48 | int srch; |
47 | int srch; |
49 | 48 | ||
50 | unsigned char *d; |
49 | unsigned char *d; |
51 | int stride; |
50 | int stride; |
52 | }; |
51 | }; |
53 | 52 | ||
54 | void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter |
53 | void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter |
55 | { |
54 | { |
56 | struct blit_call image; |
55 | struct blit_call image; |
57 | image.dstx=dstx; |
56 | image.dstx=dstx; |
58 | image.dsty=dsty; |
57 | image.dsty=dsty; |
59 | image.w=w; |
58 | image.w=w; |
60 | image.h=h; |
59 | image.h=h; |
61 | image.srcx=srcx; |
60 | image.srcx=srcx; |
62 | image.srcy=srcy; |
61 | image.srcy=srcy; |
63 | image.srcw=srcw; |
62 | image.srcw=srcw; |
64 | image.srch=srch; |
63 | image.srch=srch; |
65 | image.stride=stride; |
64 | image.stride=stride; |
66 | image.d=d; |
65 | image.d=d; |
67 | asm ("int $0x40"::"a"(73),"b"(0),"c"(&image)); |
66 | asm ("int $0x40"::"a"(73),"b"(0),"c"(&image)); |
68 | } |
67 | } |
69 | 68 | ||
70 | void run_app() |
69 | void run_app() |
71 | { |
70 | { |
72 | return; |
71 | return; |
73 | } |
72 | } |
74 | 73 | ||
75 | 74 | ||
76 | int __menuet__get_mouse_wheels(void) |
75 | int __menuet__get_mouse_wheels(void) |
77 | { |
76 | { |
78 | int val; |
77 | int val; |
79 | asm ("int $0x40":"=a"(val):"a"(37),"b"(7)); |
78 | asm ("int $0x40":"=a"(val):"a"(37),"b"(7)); |
80 | return val; |
79 | return val; |
81 | }; |
80 | }; |
82 | 81 | ||
83 | /*==== DATA ====*/ |
82 | /*==== DATA ====*/ |
84 | 83 | ||
85 | static char Title[1024] = "uPDF"; |
84 | static char Title[1024] = "uPDF"; |
86 | static pdfapp_t gapp; |
85 | static pdfapp_t gapp; |
87 | char debugstr[256]; |
86 | char debugstr[256]; |
88 | char do_not_blit=0; |
87 | char do_not_blit=0; |
89 | 88 | ||
90 | #define TOOLBAR_HEIGHT 34 |
89 | #define TOOLBAR_HEIGHT 34 |
91 | struct process_table_entry Form; |
90 | struct process_table_entry Form; |
92 | 91 | ||
93 | #define DOCUMENT_BORDER 0x979797 |
92 | #define DOCUMENT_BORDER 0x979797 |
94 | #define DOCUMENT_BG 0xABABAB |
93 | #define DOCUMENT_BG 0xABABAB |
95 | 94 | ||
96 | #define SCROLL_H 25 |
95 | #define SCROLL_H 25 |
97 | 96 | ||
98 | short show_area_w = 65; |
97 | short show_area_w = 65; |
99 | short show_area_x; |
98 | short show_area_x; |
100 | 99 | ||
101 | char key_mode_enter_page_number; |
100 | char key_mode_enter_page_number; |
102 | int new_page_number; |
101 | int new_page_number; |
103 | 102 | ||
104 | static short window_center, draw_h, draw_w; |
103 | static short window_center, draw_h, draw_w; |
105 | 104 | ||
106 | const char *help[] = { |
105 | const char *help[] = { |
107 | "Keys:", |
106 | "Keys:", |
108 | " ", |
107 | " ", |
109 | "PageUp - go to previous page", |
108 | "PageUp - go to previous page", |
110 | "PageDown - go to next page", |
109 | "PageDown - go to next page", |
111 | "Home - go to first page", |
110 | "Home - go to first page", |
112 | "End - go to last page", |
111 | "End - go to last page", |
113 | "Down arrow - scroll current page down", |
112 | "Down arrow - scroll current page down", |
114 | "Up arrow - scroll current page up", |
113 | "Up arrow - scroll current page up", |
115 | "+/- - zoom in/out", |
114 | "+/- - zoom in/out", |
116 | "[ or l - rotate page 90 deg to the left", |
115 | "[ or l - rotate page 90 deg to the left", |
117 | "] or r - rotate page 90 deg to the right", |
116 | "] or r - rotate page 90 deg to the right", |
118 | "g - grayscale on/off", |
117 | "g - grayscale on/off", |
119 | " ", |
118 | " ", |
120 | "Press Escape to hide help", |
119 | "Press Escape to hide help", |
121 | 0 |
120 | 0 |
122 | }; |
121 | }; |
123 | 122 | ||
124 | /*==== CODE ====*/ |
123 | /*==== CODE ====*/ |
125 | 124 | ||
126 | 125 | ||
127 | // not implemented yet |
126 | // not implemented yet |
128 | void wincursor(pdfapp_t *app, int curs) { } |
127 | void wincursor(pdfapp_t *app, int curs) { } |
129 | void winhelp(pdfapp_t *app) { } |
128 | void winhelp(pdfapp_t *app) { } |
130 | void winresize(pdfapp_t *app, int w, int h) { } |
129 | void winresize(pdfapp_t *app, int w, int h) { } |
131 | void windocopy(pdfapp_t *app) { } |
130 | void windocopy(pdfapp_t *app) { } |
132 | void winopenuri(pdfapp_t *app, char *buf) { } |
131 | void winopenuri(pdfapp_t *app, char *buf) { } |
133 | void winrepaintsearch(pdfapp_t *app) { } |
132 | void winrepaintsearch(pdfapp_t *app) { } |
134 | 133 | ||
135 | 134 | ||
136 | void winwarn(pdfapp_t *app, char *msg) |
135 | void winwarn(pdfapp_t *app, char *msg) |
137 | { |
136 | { |
138 | fprintf(stderr, "mupdf: %s\n", msg); |
137 | fprintf(stderr, "mupdf: %s\n", msg); |
139 | } |
138 | } |
140 | 139 | ||
141 | 140 | ||
142 | void winerror(pdfapp_t *app, fz_error error) |
141 | void winerror(pdfapp_t *app, fz_error error) |
143 | { |
142 | { |
144 | fz_catch(error, "aborting"); |
143 | fz_catch(error, "aborting"); |
145 | exit(1); |
144 | exit(1); |
146 | } |
145 | } |
147 | 146 | ||
148 | 147 | ||
149 | char *winpassword(pdfapp_t *app, char *filename) |
148 | char *winpassword(pdfapp_t *app, char *filename) |
150 | { |
149 | { |
151 | char *r = ""; |
150 | char *r = ""; |
152 | return r; |
151 | return r; |
153 | random(); |
152 | random(); |
154 | } |
153 | } |
155 | 154 | ||
156 | 155 | ||
157 | void wintitle(pdfapp_t *app, char *s) |
156 | void wintitle(pdfapp_t *app, char *s) |
158 | { |
157 | { |
159 | char* param = *(char**)0x1C; |
158 | char* param = *(char**)0x1C; |
160 | sprintf(Title,"%s - uPDF", strrchr(param, '/') + 1 ); |
159 | sprintf(Title,"%s - uPDF", strrchr(param, '/') + 1 ); |
161 | } |
160 | } |
162 | 161 | ||
163 | 162 | ||
164 | void winreloadfile(pdfapp_t *app) |
163 | void winreloadfile(pdfapp_t *app) |
165 | { |
164 | { |
166 | //pdfapp_close(app); |
165 | //pdfapp_close(app); |
167 | //pdfapp_open(app, filename, 0, 1); |
166 | //pdfapp_open(app, filename, 0, 1); |
168 | } |
167 | } |
169 | 168 | ||
170 | void winclose(pdfapp_t *app) |
169 | void winclose(pdfapp_t *app) |
171 | { |
170 | { |
172 | pdfapp_close(&gapp); |
171 | pdfapp_close(&gapp); |
173 | __menuet__sys_exit(); |
172 | __menuet__sys_exit(); |
174 | } |
173 | } |
175 | 174 | ||
176 | void RunOpenApp() |
175 | void RunOpenApp() |
177 | { |
176 | { |
178 | RunApp("/sys/lod", "*pdf* /kolibrios/media/updf"); |
177 | RunApp("/sys/lod", "*pdf* /kolibrios/media/updf"); |
179 | } |
178 | } |
180 | 179 | ||
181 | 180 | ||
182 | void winrepaint(pdfapp_t *app) |
181 | void winrepaint(pdfapp_t *app) |
183 | { |
182 | { |
184 | winblit(&gapp); |
183 | winblit(&gapp); |
185 | } |
184 | } |
186 | 185 | ||
187 | 186 | ||
188 | void winblit(pdfapp_t *app) |
187 | void winblit(pdfapp_t *app) |
189 | { |
188 | { |
190 | 189 | ||
191 | if (do_not_blit) return; |
190 | if (do_not_blit) return; |
192 | 191 | ||
193 | if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination(); |
192 | if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination(); |
194 | 193 | ||
195 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
194 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
196 | 195 | ||
197 | gapp.panx = 0; |
196 | gapp.panx = 0; |
198 | if (gapp.image->n == 4) { |
197 | if (gapp.image->n == 4) { |
199 | blit(window_center + Form.client_left, |
198 | blit(window_center + Form.client_left, |
200 | Form.client_top + TOOLBAR_HEIGHT, |
199 | Form.client_top + TOOLBAR_HEIGHT, |
201 | Form.client_width, |
200 | Form.client_width, |
202 | Form.client_height - TOOLBAR_HEIGHT, |
201 | Form.client_height - TOOLBAR_HEIGHT, |
203 | gapp.panx, |
202 | gapp.panx, |
204 | gapp.pany, |
203 | gapp.pany, |
205 | gapp.image->w, |
204 | gapp.image->w, |
206 | gapp.image->h, |
205 | gapp.image->h, |
207 | gapp.image->w * gapp.image->n, |
206 | gapp.image->w * gapp.image->n, |
208 | gapp.image->samples |
207 | gapp.image->samples |
209 | ); |
208 | ); |
210 | } |
209 | } |
211 | else if (gapp.image->n == 2) |
210 | else if (gapp.image->n == 2) |
212 | { |
211 | { |
213 | int i = gapp.image->w*gapp.image->h; |
212 | int i = gapp.image->w*gapp.image->h; |
214 | unsigned char *color = malloc(i*4); |
213 | unsigned char *color = malloc(i*4); |
215 | if (color != NULL) |
214 | if (color != NULL) |
216 | { |
215 | { |
217 | unsigned char *s = gapp.image->samples; |
216 | unsigned char *s = gapp.image->samples; |
218 | unsigned char *d = color; |
217 | unsigned char *d = color; |
219 | for (; i > 0 ; i--) |
218 | for (; i > 0 ; i--) |
220 | { |
219 | { |
221 | d[2] = d[1] = d[0] = *s++; |
220 | d[2] = d[1] = d[0] = *s++; |
222 | d[3] = *s++; |
221 | d[3] = *s++; |
223 | d += 4; |
222 | d += 4; |
224 | } |
223 | } |
225 | blit(window_center + Form.client_left, |
224 | blit(window_center + Form.client_left, |
226 | Form.client_top + TOOLBAR_HEIGHT, |
225 | Form.client_top + TOOLBAR_HEIGHT, |
227 | Form.client_width, |
226 | Form.client_width, |
228 | Form.client_height - TOOLBAR_HEIGHT, |
227 | Form.client_height - TOOLBAR_HEIGHT, |
229 | gapp.panx, |
228 | gapp.panx, |
230 | gapp.pany, |
229 | gapp.pany, |
231 | gapp.image->w, |
230 | gapp.image->w, |
232 | gapp.image->h, |
231 | gapp.image->h, |
233 | gapp.image->w * 4, |
232 | gapp.image->w * 4, |
234 | color |
233 | color |
235 | ); |
234 | ); |
236 | free(color); |
235 | free(color); |
237 | } |
236 | } |
238 | } |
237 | } |
239 | } |
238 | } |
240 | 239 | ||
241 | 240 | ||
242 | void DrawPageSides(void) |
241 | void DrawPageSides(void) |
243 | { |
242 | { |
244 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
243 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
245 | if (gapp.image->h < Form.client_height - TOOLBAR_HEIGHT) draw_h = gapp.image->h - gapp.pany; else draw_h = Form.client_height - TOOLBAR_HEIGHT; |
244 | if (gapp.image->h < Form.client_height - TOOLBAR_HEIGHT) draw_h = gapp.image->h - gapp.pany; else draw_h = Form.client_height - TOOLBAR_HEIGHT; |
246 | if (gapp.image->w < Form.client_width) |
245 | if (gapp.image->w < Form.client_width) |
247 | { |
246 | { |
248 | kol_paint_bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
247 | kol_paint_bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
249 | kol_paint_bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
248 | kol_paint_bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
250 | kol_paint_bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
249 | kol_paint_bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
251 | kol_paint_bar(window_center + gapp.image->w+1, TOOLBAR_HEIGHT, Form.client_width - window_center - gapp.image->w - 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
250 | kol_paint_bar(window_center + gapp.image->w+1, TOOLBAR_HEIGHT, Form.client_width - window_center - gapp.image->w - 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
252 | } |
251 | } |
253 | if (gapp.image->w < Form.client_width) |
252 | if (gapp.image->w < Form.client_width) |
254 | { |
253 | { |
255 | draw_w = gapp.image->w + 2; |
254 | draw_w = gapp.image->w + 2; |
256 | } |
255 | } |
257 | else |
256 | else |
258 | { |
257 | { |
259 | window_center = 1; |
258 | window_center = 1; |
260 | draw_w = Form.client_width; |
259 | draw_w = Form.client_width; |
261 | } |
260 | } |
262 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER); |
261 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER); |
263 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, draw_w, Form.client_height - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG); |
262 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, draw_w, Form.client_height - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG); |
264 | } |
263 | } |
265 | 264 | ||
266 | 265 | ||
267 | 266 | ||
268 | int main (void) |
267 | int main (void) |
269 | { |
268 | { |
270 | char ii, mouse_wheels_state; |
269 | char ii, mouse_wheels_state; |
271 | char* original_command_line = *(char**)0x1C; |
270 | char* original_command_line = *(char**)0x1C; |
272 | 271 | ||
273 | if (*original_command_line == 0) { |
272 | if (*original_command_line == 0) { |
274 | kol_board_puts("Running uPDF without any param"); |
273 | kol_board_puts("Running uPDF without any param"); |
275 | RunOpenApp(); |
274 | RunOpenApp(); |
276 | __menuet__sys_exit(); |
275 | __menuet__sys_exit(); |
277 | } |
276 | } |
278 | 277 | ||
279 | kol_board_puts(original_command_line); |
278 | kol_board_puts(original_command_line); |
280 | kol_board_puts("\n"); |
279 | kol_board_puts("\n"); |
281 | 280 | ||
282 | char buf[128]; |
281 | char buf[128]; |
283 | int resolution = 72; |
282 | int resolution = 72; |
284 | int pageno = 1; |
283 | int pageno = 1; |
285 | fz_accelerate(); |
284 | fz_accelerate(); |
286 | kol_board_puts("PDF init\n"); |
285 | kol_board_puts("PDF init\n"); |
287 | pdfapp_init(&gapp); |
286 | pdfapp_init(&gapp); |
288 | gapp.scrw = 600; |
287 | gapp.scrw = 600; |
289 | gapp.scrh = 400; |
288 | gapp.scrh = 400; |
290 | gapp.resolution = resolution; |
289 | gapp.resolution = resolution; |
291 | gapp.pageno = pageno; |
290 | gapp.pageno = pageno; |
292 | kol_board_puts("PDF Open\n"); |
291 | kol_board_puts("PDF Open\n"); |
293 | pdfapp_open(&gapp, original_command_line, 0, 0); |
292 | pdfapp_open(&gapp, original_command_line, 0, 0); |
294 | kol_board_puts("PDF Opened\n"); |
293 | kol_board_puts("PDF Opened\n"); |
295 | wintitle(&gapp, 0); |
294 | wintitle(&gapp, 0); |
296 | 295 | ||
297 | kol_board_puts("Inital paint\n"); |
296 | kol_board_puts("Inital paint\n"); |
298 | 297 | ||
299 | int butt, key, screen_max_x, screen_max_y; |
298 | int butt, key, screen_max_x, screen_max_y; |
300 | __menuet__get_screen_max(&screen_max_x, &screen_max_y); |
299 | __menuet__get_screen_max(&screen_max_x, &screen_max_y); |
301 | __menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE); |
300 | __menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE); |
302 | 301 | ||
303 | for(;;) |
302 | for(;;) |
304 | { |
303 | { |
305 | 304 | ||
306 | switch(__menuet__wait_for_event()) |
305 | switch(__menuet__wait_for_event()) |
307 | { |
306 | { |
308 | case evReDraw: |
307 | case evReDraw: |
309 | // gapp.shrinkwrap = 2; |
308 | // gapp.shrinkwrap = 2; |
310 | __menuet__window_redraw(1); |
309 | __menuet__window_redraw(1); |
311 | __menuet__define_window(screen_max_x / 2 - 350-50+kos_random(50), |
310 | __menuet__define_window(screen_max_x / 2 - 350-50+kos_random(50), |
312 | screen_max_y / 2 - 300-50+kos_random(50), |
311 | screen_max_y / 2 - 300-50+kos_random(50), |
313 | 700, 600, 0x73000000, 0x800000FF, Title); |
312 | 700, 600, 0x73000000, 0x800000FF, Title); |
314 | __menuet__window_redraw(2); |
313 | __menuet__window_redraw(2); |
315 | __menuet__get_process_table(&Form, PID_WHOAMI); |
314 | __menuet__get_process_table(&Form, PID_WHOAMI); |
316 | if (Form.window_state > 2) continue; //fix rolled up |
315 | if (Form.window_state > 2) continue; //fix rolled up |
317 | Form.client_width++; //fix for Menuet kernel bug |
316 | Form.client_width++; //fix for Menuet kernel bug |
318 | Form.client_height++; //fix for Menuet kernel bug |
317 | Form.client_height++; //fix for Menuet kernel bug |
319 | DrawWindow(); |
318 | DrawWindow(); |
320 | break; |
319 | break; |
321 | 320 | ||
322 | case evKey: |
321 | case evKey: |
323 | key = __menuet__getkey(); |
322 | key = __menuet__getkey(); |
324 | if (key_mode_enter_page_number) |
323 | if (key_mode_enter_page_number) |
325 | { |
324 | { |
326 | HandleNewPageNumber(key); |
325 | HandleNewPageNumber(key); |
327 | break; |
326 | break; |
328 | } |
327 | } |
329 | if (key==ASCII_KEY_ESC) DrawWindow(); //close help |
328 | if (key==ASCII_KEY_ESC) DrawWindow(); //close help |
330 | if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']'); |
329 | if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']'); |
331 | if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '['); |
330 | if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '['); |
332 | if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g'); |
331 | if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g'); |
333 | if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G'); |
332 | if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G'); |
334 | if (key=='g' ) pdfapp_onkey(&gapp, 'c'); |
333 | if (key=='g' ) pdfapp_onkey(&gapp, 'c'); |
335 | if ((key=='[' ) || (key=='l')) PageRotateLeft(); |
334 | if ((key=='[' ) || (key=='l')) PageRotateLeft(); |
336 | if ((key==']' ) || (key=='r')) PageRotateRight(); |
335 | if ((key==']' ) || (key=='r')) PageRotateRight(); |
337 | if (key==ASCII_KEY_DOWN ) PageScrollDown(); |
336 | if (key==ASCII_KEY_DOWN ) PageScrollDown(); |
338 | if (key==ASCII_KEY_UP ) PageScrollUp(); |
337 | if (key==ASCII_KEY_UP ) PageScrollUp(); |
339 | if (key=='-') PageZoomOut(); |
338 | if (key=='-') PageZoomOut(); |
340 | if ((key=='=') || (key=='+')) PageZoomIn(); |
339 | if ((key=='=') || (key=='+')) PageZoomIn(); |
341 | break; |
340 | break; |
342 | 341 | ||
343 | case evButton: |
342 | case evButton: |
344 | butt = __menuet__get_button_id(); |
343 | butt = __menuet__get_button_id(); |
345 | if(butt==1) __menuet__sys_exit(); |
344 | if(butt==1) __menuet__sys_exit(); |
346 | if(butt==10) RunOpenApp(); |
345 | if(butt==10) RunOpenApp(); |
347 | if(butt==11) PageZoomOut(); //magnify - |
346 | if(butt==11) PageZoomOut(); //magnify - |
348 | if(butt==12) PageZoomIn(); //magnify + |
347 | if(butt==12) PageZoomIn(); //magnify + |
349 | if(butt==13) //show help |
348 | if(butt==13) //show help |
350 | { |
349 | { |
351 | kol_paint_bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2); |
350 | kol_paint_bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2); |
352 | __menuet__write_text(20, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
351 | __menuet__write_text(20, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
353 | __menuet__write_text(21, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
352 | __menuet__write_text(21, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
354 | for (ii=0; help[ii]!=0; ii++) { |
353 | for (ii=0; help[ii]!=0; ii++) { |
355 | __menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0); |
354 | __menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0); |
356 | } |
355 | } |
357 | } |
356 | } |
358 | if(butt==14) pdfapp_onkey(&gapp, '['); //previous page |
357 | if(butt==14) pdfapp_onkey(&gapp, '['); //previous page |
359 | if(butt==15) pdfapp_onkey(&gapp, ']'); //next page |
358 | if(butt==15) pdfapp_onkey(&gapp, ']'); //next page |
360 | if(butt==16) PageRotateLeft(); |
359 | if(butt==16) PageRotateLeft(); |
361 | if(butt==17) PageRotateRight(); |
360 | if(butt==17) PageRotateRight(); |
362 | if(butt==20) GetNewPageNumber(); |
361 | if(butt==20) GetNewPageNumber(); |
363 | break; |
362 | break; |
364 | 363 | ||
365 | case evMouse: |
364 | case evMouse: |
366 | if (mouse_wheels_state = __menuet__get_mouse_wheels()) |
365 | if (mouse_wheels_state = __menuet__get_mouse_wheels()) |
367 | { |
366 | { |
368 | if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); } |
367 | if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); } |
369 | if (mouse_wheels_state==-1) { PageScrollUp(); PageScrollUp(); } |
368 | if (mouse_wheels_state==-1) { PageScrollUp(); PageScrollUp(); } |
370 | } |
369 | } |
371 | //sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state); |
370 | //sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state); |
372 | //kol_board_puts(debugstr); |
371 | //kol_board_puts(debugstr); |
373 | //pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state) |
372 | //pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state) |
374 | break; |
373 | break; |
375 | } |
374 | } |
376 | } |
375 | } |
377 | } |
376 | } |
378 | 377 | ||
379 | 378 | ||
380 | void GetNewPageNumber(void) |
379 | void GetNewPageNumber(void) |
381 | { |
380 | { |
382 | new_page_number = gapp.pageno; |
381 | new_page_number = gapp.pageno; |
383 | key_mode_enter_page_number = 1; |
382 | key_mode_enter_page_number = 1; |
384 | HandleNewPageNumber(0); |
383 | HandleNewPageNumber(0); |
385 | } |
384 | } |
386 | 385 | ||
387 | void HandleNewPageNumber(unsigned char key) |
386 | void HandleNewPageNumber(unsigned char key) |
388 | { |
387 | { |
389 | char label_new_page[8]; |
388 | char label_new_page[8]; |
390 | 389 | ||
391 | if ((key >= '0') && (key <= '9')) |
390 | if ((key >= '0') && (key <= '9')) |
392 | { |
391 | { |
393 | new_page_number = new_page_number * 10 + key - '0'; |
392 | new_page_number = new_page_number * 10 + key - '0'; |
394 | } |
393 | } |
395 | if (key == ASCII_KEY_BS) |
394 | if (key == ASCII_KEY_BS) |
396 | { |
395 | { |
397 | new_page_number /= 10; |
396 | new_page_number /= 10; |
398 | } |
397 | } |
399 | if (key == ASCII_KEY_ENTER) |
398 | if (key == ASCII_KEY_ENTER) |
400 | { |
399 | { |
401 | ApplyNewPageNumber(); |
400 | ApplyNewPageNumber(); |
402 | return; |
401 | return; |
403 | } |
402 | } |
404 | if (key==ASCII_KEY_ESC) |
403 | if (key==ASCII_KEY_ESC) |
405 | { |
404 | { |
406 | key_mode_enter_page_number = 0; |
405 | key_mode_enter_page_number = 0; |
407 | DrawWindow(); |
406 | DrawWindow(); |
408 | return; |
407 | return; |
409 | } |
408 | } |
410 | 409 | ||
411 | itoa(new_page_number, label_new_page, 10); |
410 | itoa(new_page_number, label_new_page, 10); |
412 | strcat(label_new_page, "_"); |
411 | strcat(label_new_page, "_"); |
413 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xFDF88E); |
412 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xFDF88E); |
414 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(label_new_page)*6/2, 14, 0x000000, label_new_page, strlen(label_new_page)); |
413 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(label_new_page)*6/2, 14, 0x000000, label_new_page, strlen(label_new_page)); |
415 | 414 | ||
416 | if (new_page_number > gapp.pagecount) ApplyNewPageNumber(); |
415 | if (new_page_number > gapp.pagecount) ApplyNewPageNumber(); |
417 | } |
416 | } |
418 | 417 | ||
419 | void ApplyNewPageNumber(void) |
418 | void ApplyNewPageNumber(void) |
420 | { |
419 | { |
421 | key_mode_enter_page_number = 0; |
420 | key_mode_enter_page_number = 0; |
422 | gapp.pageno = new_page_number -1; |
421 | gapp.pageno = new_page_number -1; |
423 | pdfapp_onkey(&gapp, ']'); |
422 | pdfapp_onkey(&gapp, ']'); |
424 | } |
423 | } |
425 | 424 | ||
426 | void DrawPagination(void) |
425 | void DrawPagination(void) |
427 | { |
426 | { |
428 | char pages_display[12]; |
427 | char pages_display[12]; |
429 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xF4F4F4); |
428 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xF4F4F4); |
430 | sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount); |
429 | sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount); |
431 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display)); |
430 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display)); |
432 | } |
431 | } |
433 | 432 | ||
434 | 433 | ||
435 | 434 | ||
436 | 435 | ||
437 | void DrawWindow(void) |
436 | void DrawWindow(void) |
438 | { |
437 | { |
439 | kol_paint_bar(0, 0, Form.client_width, TOOLBAR_HEIGHT - 1, 0xe1e1e1); // bar on the top (buttons holder) |
438 | kol_paint_bar(0, 0, Form.client_width, TOOLBAR_HEIGHT - 1, 0xe1e1e1); // bar on the top (buttons holder) |
440 | kol_paint_bar(0, TOOLBAR_HEIGHT - 1, Form.client_width, 1, 0x7F7F7F); |
439 | kol_paint_bar(0, TOOLBAR_HEIGHT - 1, Form.client_width, 1, 0x7F7F7F); |
441 | DrawToolbarButton(8,0); //open_folder |
440 | DrawToolbarButton(8,0); //open_folder |
442 | DrawToolbarButton(42,1); //magnify - |
441 | DrawToolbarButton(42,1); //magnify - |
443 | DrawToolbarButton(67,2); //magnify + |
442 | DrawToolbarButton(67,2); //magnify + |
444 | DrawToolbarButton(101,6); //rotate left |
443 | DrawToolbarButton(101,6); //rotate left |
445 | DrawToolbarButton(126,7); //rotate right |
444 | DrawToolbarButton(126,7); //rotate right |
446 | DrawToolbarButton(Form.client_width - 160,3); //show help |
445 | DrawToolbarButton(Form.client_width - 160,3); //show help |
447 | show_area_x = Form.client_width - show_area_w - 34; |
446 | show_area_x = Form.client_width - show_area_w - 34; |
448 | DrawToolbarButton(show_area_x - 26,4); //prev page |
447 | DrawToolbarButton(show_area_x - 26,4); //prev page |
449 | DrawToolbarButton(show_area_x + show_area_w,5); //nex page |
448 | DrawToolbarButton(show_area_x + show_area_w,5); //nex page |
450 | __menuet__make_button(show_area_x-1, 5, show_area_w+1, 23, 20 + BT_HIDE, 0xA4A4A4); |
449 | __menuet__make_button(show_area_x-1, 5, show_area_w+1, 23, 20 + BT_HIDE, 0xA4A4A4); |
451 | kol_paint_bar(show_area_x, 5, show_area_w, 1, 0xA4A4A4); |
450 | kol_paint_bar(show_area_x, 5, show_area_w, 1, 0xA4A4A4); |
452 | kol_paint_bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4); |
451 | kol_paint_bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4); |
453 | winblit(&gapp); |
452 | winblit(&gapp); |
454 | DrawPageSides(); |
453 | DrawPageSides(); |
455 | } |
454 | } |
456 | 455 | ||
457 | void DrawToolbarButton(int x, char image_id) |
456 | void DrawToolbarButton(int x, char image_id) |
458 | { |
457 | { |
459 | __menuet__make_button(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0); |
458 | __menuet__make_button(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0); |
460 | __menuet__putimage(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image); |
459 | __menuet__putimage(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image); |
461 | } |
460 | } |
462 | 461 | ||
463 | 462 | ||
464 | /* Actions */ |
463 | /* Actions */ |
465 | 464 | ||
466 | void PageScrollDown(void) |
465 | void PageScrollDown(void) |
467 | { |
466 | { |
468 | //pdfapp_onkey(&gapp, 'k'); //move down |
467 | //pdfapp_onkey(&gapp, 'k'); //move down |
469 | if (gapp.image->h - gapp.pany - SCROLL_H < Form.client_height - TOOLBAR_HEIGHT) |
468 | if (gapp.image->h - gapp.pany - SCROLL_H < Form.client_height - TOOLBAR_HEIGHT) |
470 | { |
469 | { |
471 | pdfapp_onkey(&gapp, '.'); |
470 | pdfapp_onkey(&gapp, '.'); |
472 | } |
471 | } |
473 | else { |
472 | else { |
474 | gapp.pany += SCROLL_H; |
473 | gapp.pany += SCROLL_H; |
475 | winblit(&gapp); |
474 | winblit(&gapp); |
476 | } |
475 | } |
477 | } |
476 | } |
478 | 477 | ||
479 | 478 | ||
480 | void PageScrollUp(void) |
479 | void PageScrollUp(void) |
481 | { |
480 | { |
482 | //pdfapp_onkey(&gapp, 'j'); //move up |
481 | //pdfapp_onkey(&gapp, 'j'); //move up |
483 | if (gapp.pany >= SCROLL_H) { |
482 | if (gapp.pany >= SCROLL_H) { |
484 | gapp.pany -= SCROLL_H; |
483 | gapp.pany -= SCROLL_H; |
485 | winblit(&gapp); |
484 | winblit(&gapp); |
486 | } |
485 | } |
487 | else { |
486 | else { |
488 | //not very nice way of using do_not_blit, but it simple |
487 | //not very nice way of using do_not_blit, but it simple |
489 | if (gapp.pageno == 1) return; |
488 | if (gapp.pageno == 1) return; |
490 | do_not_blit = 1; |
489 | do_not_blit = 1; |
491 | pdfapp_onkey(&gapp, ','); |
490 | pdfapp_onkey(&gapp, ','); |
492 | do_not_blit = 0; |
491 | do_not_blit = 0; |
493 | gapp.pany = gapp.image->h - SCROLL_H - Form.client_height + TOOLBAR_HEIGHT; |
492 | gapp.pany = gapp.image->h - SCROLL_H - Form.client_height + TOOLBAR_HEIGHT; |
494 | if (gapp.pany < 0) gapp.pany = 0; |
493 | if (gapp.pany < 0) gapp.pany = 0; |
495 | //sprintf (debugstr, "gapp.pany: %d \n", gapp.pany); |
494 | //sprintf (debugstr, "gapp.pany: %d \n", gapp.pany); |
496 | //kol_board_puts(debugstr); |
495 | //kol_board_puts(debugstr); |
497 | winblit(&gapp); |
496 | winblit(&gapp); |
498 | } |
497 | } |
499 | } |
498 | } |
500 | 499 | ||
501 | void RunApp(char app[], char param[]) |
500 | void RunApp(char app[], char param[]) |
502 | { |
501 | { |
503 | kol_struct70 r; |
502 | kol_struct70 r; |
504 | r.p00 = 7; |
503 | r.p00 = 7; |
505 | r.p04 = 0; |
504 | r.p04 = 0; |
506 | r.p08 = param; |
505 | r.p08 = param; |
507 | r.p12 = 0; |
506 | r.p12 = 0; |
508 | r.p16 = 0; |
507 | r.p16 = 0; |
509 | r.p20 = 0; |
508 | r.p20 = 0; |
510 | r.p21 = app; |
509 | r.p21 = app; |
511 | kol_file_70(&r); |
510 | kol_file_70(&r); |
512 | } |
511 | } |
513 | 512 | ||
514 | 513 | ||
515 | void PageZoomIn(void) |
514 | void PageZoomIn(void) |
516 | { |
515 | { |
517 | pdfapp_onkey(&gapp, '+'); |
516 | pdfapp_onkey(&gapp, '+'); |
518 | DrawPageSides(); |
517 | DrawPageSides(); |
519 | } |
518 | } |
520 | 519 | ||
521 | 520 | ||
522 | void PageZoomOut(void) |
521 | void PageZoomOut(void) |
523 | { |
522 | { |
524 | pdfapp_onkey(&gapp, '-'); |
523 | pdfapp_onkey(&gapp, '-'); |
525 | DrawPageSides(); |
524 | DrawPageSides(); |
526 | } |
525 | } |
527 | 526 | ||
528 | void PageRotateLeft(void) |
527 | void PageRotateLeft(void) |
529 | { |
528 | { |
530 | pdfapp_onkey(&gapp, 'L'); |
529 | pdfapp_onkey(&gapp, 'L'); |
531 | DrawPageSides(); |
530 | DrawPageSides(); |
532 | } |
531 | } |
533 | 532 | ||
534 | void PageRotateRight(void) |
533 | void PageRotateRight(void) |
535 | { |
534 | { |
536 | pdfapp_onkey(&gapp, 'R'); |
535 | pdfapp_onkey(&gapp, 'R'); |
537 | DrawPageSides(); |
536 | DrawPageSides(); |
538 | }>>=>>>> |
537 | }>>=>>>> |