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