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