Subversion Repositories Kolibri OS

Rev

Rev 7621 | Rev 8429 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7621 Rev 7624
Line 4... Line 4...
4
#include "mupdf.h"
4
#include "mupdf.h"
5
#include "pdfapp.h"
5
#include "pdfapp.h"
6
#include "icons/allbtns.h"
6
#include "icons/allbtns.h"
7
#include "kolibri.c"
7
#include "kolibri.c"
Line 8... Line -...
8
 
-
 
9
// need to be a part of menuet/os.h
-
 
10
#define BT_DEL      0x80000000
-
 
11
#define BT_HIDE     0x40000000
-
 
12
#define BT_NOFRAME  0x20000000
-
 
13
 
-
 
14
#define evReDraw  1
-
 
15
#define evKey     2
-
 
16
#define evButton  3
-
 
17
#define evMouse   6
-
 
18
#define evNetwork 8
-
 
19
 
-
 
20
#define ASCII_KEY_LEFT  176
-
 
21
#define ASCII_KEY_RIGHT 179
-
 
22
#define ASCII_KEY_DOWN  177
-
 
23
#define ASCII_KEY_UP    178
-
 
24
#define ASCII_KEY_HOME  180
-
 
25
#define ASCII_KEY_END   181
-
 
26
#define ASCII_KEY_PGDN  183
-
 
27
#define ASCII_KEY_PGUP  184
-
 
28
 
-
 
29
#define ASCII_KEY_BS    8
-
 
30
#define ASCII_KEY_TAB   9
-
 
31
#define ASCII_KEY_ENTER 13
-
 
32
#define ASCII_KEY_ESC   27
-
 
33
#define ASCII_KEY_DEL   182
-
 
34
#define ASCII_KEY_INS   185
-
 
35
#define ASCII_KEY_SPACE 032
-
 
36
 
-
 
37
struct blit_call
-
 
38
{
-
 
39
   int dstx;       
-
 
40
   int dsty;
-
 
41
   int w;
-
 
42
   int h;
-
 
43
 
-
 
44
   int srcx;
-
 
45
   int srcy;
-
 
46
   int srcw;
-
 
47
   int srch;
-
 
48
 
-
 
49
   unsigned char *d;
-
 
50
   int   stride;
-
 
51
};
-
 
52
 
-
 
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
{
-
 
55
	struct blit_call image;
-
 
56
	image.dstx=dstx;
-
 
57
	image.dsty=dsty;
-
 
58
	image.w=w;
-
 
59
	image.h=h;
-
 
60
	image.srcx=srcx;
-
 
61
	image.srcy=srcy;
-
 
62
	image.srcw=srcw;
-
 
63
	image.srch=srch;
-
 
64
	image.stride=stride;
-
 
65
	image.d=d;
-
 
66
	asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
-
 
67
}
-
 
68
 
8
 
69
void run_app()
9
void run_app()
70
{
10
{
71
	return;
11
	return;
Line 72... Line -...
72
}
-
 
73
 
-
 
74
 
-
 
75
int __menuet__get_mouse_wheels(void)
-
 
76
{
-
 
77
    int val;
-
 
78
    asm ("int $0x40":"=a"(val):"a"(37),"b"(7));
-
 
79
    return val;
-
 
80
};
12
}
Line 81... Line 13...
81
 
13
 
82
/*==== DATA ====*/
14
/*==== DATA ====*/
83
 
15
 
Line 193... Line 125...
193
 
125
 
Line 194... Line 126...
194
	if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0;
126
	if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0;
195
 
127
 
196
	gapp.panx = 0;
128
	gapp.panx = 0;
197
	if (gapp.image->n == 4) {
129
	if (gapp.image->n == 4) {
198
		 	blit(window_center + Form.client_left, 
130
		 	kos_blit(window_center + Form.client_left, 
199
		 		Form.client_top + TOOLBAR_HEIGHT, 
131
		 		Form.client_top + TOOLBAR_HEIGHT, 
200
		 		Form.client_width, 
132
		 		Form.client_width, 
201
		 		Form.client_height - TOOLBAR_HEIGHT, 
133
		 		Form.client_height - TOOLBAR_HEIGHT, 
Line 219... Line 151...
219
			{
151
			{
220
				d[2] = d[1] = d[0] = *s++;
152
				d[2] = d[1] = d[0] = *s++;
221
				d[3] = *s++;
153
				d[3] = *s++;
222
				d += 4;
154
				d += 4;
223
			}
155
			}
224
			blit(window_center + Form.client_left, 
156
			kos_blit(window_center + Form.client_left, 
225
				Form.client_top + TOOLBAR_HEIGHT, 
157
				Form.client_top + TOOLBAR_HEIGHT, 
226
				Form.client_width, 
158
				Form.client_width, 
227
				Form.client_height - TOOLBAR_HEIGHT, 
159
				Form.client_height - TOOLBAR_HEIGHT, 
228
		 		gapp.panx, 
160
		 		gapp.panx, 
229
		 		gapp.pany, 
161
		 		gapp.pany, 
Line 238... Line 170...
238
}
170
}
Line 239... Line 171...
239
 
171
 
240
 
172
 
241
void DrawPageSides(void)
173
void DrawPageSides(void)
242
{
174
{	
-
 
175
	if (gapp.image->h < Form.client_height - TOOLBAR_HEIGHT) {
243
	if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0;
176
		draw_h = gapp.image->h - gapp.pany; 
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;
177
	} else {
-
 
178
		draw_h = Form.client_height - TOOLBAR_HEIGHT;
-
 
179
	}
-
 
180
	
-
 
181
	if (gapp.image->w < Form.client_width) {
245
	if (gapp.image->w < Form.client_width)
182
		window_center = (Form.client_width - gapp.image->w) / 2;
246
	{
183
		draw_w = gapp.image->w + 2;
247
		kol_paint_bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG);
184
		kol_paint_bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG);
248
		kol_paint_bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER);
185
		kol_paint_bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER);
249
		kol_paint_bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER);
-
 
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);
-
 
251
	}
-
 
252
	if (gapp.image->w < Form.client_width) 
-
 
253
	{
-
 
254
		draw_w = gapp.image->w + 2;
186
		kol_paint_bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER);
255
	}
-
 
256
	else
187
		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);
257
	{
188
	} else {
258
		window_center = 1;
189
		window_center = 1;
259
		draw_w = Form.client_width;
-
 
260
	}
-
 
261
	kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER);
-
 
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);
-
 
263
}
-
 
264
 
-
 
265
 
-
 
266
 
-
 
267
int main (void)
-
 
268
{
-
 
269
	char ii, mouse_wheels_state;
-
 
270
	char* original_command_line = *(char**)0x1C;
-
 
271
	
-
 
272
	if (*original_command_line == 0) {
-
 
273
		kol_board_puts("Running uPDF without any param");
-
 
274
		RunOpenApp();
-
 
275
		__menuet__sys_exit();
-
 
276
	}
-
 
277
 
-
 
278
	kol_board_puts(original_command_line);
-
 
279
	kol_board_puts("\n");
-
 
280
	
-
 
281
	char buf[128];
-
 
282
	int resolution = 72;
-
 
283
	int pageno = 1;
-
 
284
	fz_accelerate();
-
 
285
	kol_board_puts("PDF init\n");
-
 
286
	pdfapp_init(&gapp);
-
 
287
	gapp.scrw = 600;
-
 
288
	gapp.scrh = 400;
-
 
289
	gapp.resolution = resolution;
-
 
290
	gapp.pageno = pageno;
-
 
291
	kol_board_puts("PDF Open\n");
-
 
292
	pdfapp_open(&gapp, original_command_line, 0, 0);
-
 
293
	kol_board_puts("PDF Opened\n");
-
 
294
	wintitle(&gapp, 0);
-
 
295
	 
-
 
296
	kol_board_puts("Inital paint\n");
-
 
297
	
-
 
298
	int butt, key, screen_max_x, screen_max_y;
-
 
299
	__menuet__get_screen_max(&screen_max_x, &screen_max_y);
-
 
300
	__menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE);
-
 
301
 
-
 
Line 302... Line -...
302
 for(;;)
-
 
303
 {
-
 
304
 
-
 
305
	switch(__menuet__wait_for_event())
-
 
306
	{
-
 
307
		case evReDraw:
-
 
308
			// gapp.shrinkwrap = 2;
-
 
309
			__menuet__window_redraw(1);
-
 
310
			__menuet__define_window(screen_max_x / 2 - 350-50+kos_random(50), 
-
 
311
			screen_max_y / 2 - 300-50+kos_random(50), 
-
 
312
			700, 600, 0x73000000, 0x800000FF, Title);
-
 
313
			__menuet__window_redraw(2);
-
 
314
			__menuet__get_process_table(&Form, PID_WHOAMI);
-
 
315
			if (Form.window_state > 2) continue; //fix rolled up
-
 
316
			Form.client_width++; //fix for Menuet kernel bug
-
 
317
			Form.client_height++; //fix for Menuet kernel bug
-
 
318
			DrawWindow();
-
 
319
			break;
-
 
320
 
-
 
321
		case evKey:
-
 
322
			key = __menuet__getkey(); 
-
 
323
			if (key_mode_enter_page_number)
-
 
324
			{
-
 
325
				HandleNewPageNumber(key);
-
 
326
				break;
-
 
327
			}
-
 
328
			if (key==ASCII_KEY_ESC)  DrawWindow(); //close help 
-
 
329
			if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']');
-
 
330
			if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '[');
-
 
331
			if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g');
-
 
332
			if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G');
-
 
333
			if (key=='g' ) pdfapp_onkey(&gapp, 'c');
-
 
334
			if ((key=='[' ) || (key=='l')) PageRotateLeft();
-
 
335
			if ((key==']' ) || (key=='r')) PageRotateRight();
-
 
336
			if (key==ASCII_KEY_DOWN ) PageScrollDown();
-
 
337
			if (key==ASCII_KEY_UP ) PageScrollUp();
-
 
338
			if (key=='-') PageZoomOut();
-
 
339
			if ((key=='=') || (key=='+')) PageZoomIn();
-
 
340
			break;
-
 
341
 
-
 
342
		case evButton:
-
 
343
			butt = __menuet__get_button_id();
-
 
344
			if(butt==1) __menuet__sys_exit();
-
 
345
			if(butt==10) RunOpenApp();
-
 
346
			if(butt==11) PageZoomOut(); //magnify -
-
 
347
			if(butt==12) PageZoomIn(); //magnify +
190
		draw_w = Form.client_width;
348
			if(butt==13) //show help
-
 
349
			{
191
	}
350
				kol_paint_bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2);	
-
 
351
				__menuet__write_text(20, TOOLBAR_HEIGHT + 20      , 0x90000000, "uPDF for KolibriOS v1.2", 0);
192
	
352
				__menuet__write_text(21, TOOLBAR_HEIGHT + 20      , 0x90000000, "uPDF for KolibriOS v1.2", 0);
-
 
353
				for (ii=0; help[ii]!=0; ii++) {
-
 
354
					__menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0);
-
 
355
				}
-
 
356
			}
-
 
357
			if(butt==14) pdfapp_onkey(&gapp, '['); //previous page
-
 
358
			if(butt==15) pdfapp_onkey(&gapp, ']'); //next page
-
 
359
			if(butt==16) PageRotateLeft();
-
 
360
			if(butt==17) PageRotateRight();
-
 
361
			if(butt==20) GetNewPageNumber();
-
 
362
			break;
-
 
363
 
-
 
364
		case evMouse:
-
 
365
			if (mouse_wheels_state = __menuet__get_mouse_wheels())
-
 
366
			{
-
 
367
				if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); }
-
 
368
				if (mouse_wheels_state==-1) { PageScrollUp();  PageScrollUp();   }
-
 
369
			}
-
 
370
			//sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state);
-
 
371
			//kol_board_puts(debugstr);
-
 
372
			//pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state)
-
 
373
			break;
193
	kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER);
Line 374... Line 194...
374
	}
194
	kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, 
375
  }
195
		draw_w, Form.client_height - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG);
Line 428... Line 248...
428
	kol_paint_bar(show_area_x,  6, show_area_w, 22, 0xF4F4F4);
248
	kol_paint_bar(show_area_x,  6, show_area_w, 22, 0xF4F4F4);
429
	sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount);
249
	sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount);
430
	__menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display));
250
	__menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display));
431
}
251
}
Line -... Line 252...
-
 
252
 
432
 
253
void DrawToolbarButton(int x, char image_id)
-
 
254
{
-
 
255
	__menuet__make_button(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0);
433
 
256
	__menuet__putimage(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image);
Line 434... Line 257...
434
 
257
}
435
 
258
 
436
void DrawWindow(void)
259
void DrawWindow(void)
437
{
260
{
Line 451... Line 274...
451
	kol_paint_bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4);
274
	kol_paint_bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4);
452
	winblit(&gapp);
275
	winblit(&gapp);
453
	DrawPageSides();
276
	DrawPageSides();
454
}
277
}
Line 455... Line -...
455
 
-
 
456
void DrawToolbarButton(int x, char image_id)
-
 
457
{
-
 
458
	__menuet__make_button(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0);
-
 
459
	__menuet__putimage(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image);
-
 
460
}
-
 
Line 461... Line 278...
461
 
278
 
Line 462... Line 279...
462
 
279
 
463
/* Actions */
280
/* Actions */
Line 534... Line 351...
534
{
351
{
535
	pdfapp_onkey(&gapp, 'R');
352
	pdfapp_onkey(&gapp, 'R');
536
	DrawPageSides();
353
	DrawPageSides();
537
}
354
}
Line -... Line 355...
-
 
355
 
-
 
356
int main (void)
-
 
357
{
-
 
358
	char ii, mouse_wheels_state;
-
 
359
	char* original_command_line = *(char**)0x1C;
-
 
360
	
-
 
361
	if (*original_command_line == 0) {
-
 
362
		kol_board_puts("uPDF: no param set, showing OpenDialog");
-
 
363
		RunOpenApp();
-
 
364
		__menuet__sys_exit();
-
 
365
	}
-
 
366
 
-
 
367
	kol_board_puts(original_command_line);
-
 
368
	kol_board_puts("\n");
-
 
369
	
-
 
370
	char buf[128];
-
 
371
	int resolution = 72;
-
 
372
	int pageno = 1;
-
 
373
	fz_accelerate();
-
 
374
	kol_board_puts("PDF init\n");
-
 
375
	pdfapp_init(&gapp);
-
 
376
	gapp.scrw = 600;
-
 
377
	gapp.scrh = 400;
-
 
378
	gapp.resolution = resolution;
-
 
379
	gapp.pageno = pageno;
-
 
380
	kol_board_puts("PDF Open\n");
-
 
381
	pdfapp_open(&gapp, original_command_line, 0, 0);
-
 
382
	kol_board_puts("PDF Opened\n");
-
 
383
	wintitle(&gapp, 0);
-
 
384
	 
-
 
385
	kol_board_puts("Inital paint\n");
-
 
386
	
-
 
387
	int butt, key, screen_max_x, screen_max_y;
-
 
388
	__menuet__get_screen_max(&screen_max_x, &screen_max_y);
-
 
389
	__menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE);
-
 
390
 
-
 
391
 for(;;)
-
 
392
 {
-
 
393
 
-
 
394
	switch(__menuet__wait_for_event())
-
 
395
	{
-
 
396
		case evReDraw:
-
 
397
			// gapp.shrinkwrap = 2;
-
 
398
			__menuet__window_redraw(1);
-
 
399
			__menuet__define_window(screen_max_x / 2 - 350-50+kos_random(50), 
-
 
400
			screen_max_y / 2 - 300-50+kos_random(50), 
-
 
401
			700, 600, 0x73000000, 0x800000FF, Title);
-
 
402
			__menuet__window_redraw(2);
-
 
403
			__menuet__get_process_table(&Form, PID_WHOAMI);
-
 
404
			if (Form.window_state > 2) continue; //fix rolled up
-
 
405
			Form.client_width++; //fix for Menuet kernel bug
-
 
406
			Form.client_height++; //fix for Menuet kernel bug
-
 
407
			DrawWindow();
-
 
408
			break;
-
 
409
 
-
 
410
		case evKey:
-
 
411
			key = __menuet__getkey(); 
-
 
412
			if (key_mode_enter_page_number)
-
 
413
			{
-
 
414
				HandleNewPageNumber(key);
-
 
415
				break;
-
 
416
			}
-
 
417
			if (key==ASCII_KEY_ESC)  DrawWindow(); //close help 
-
 
418
			if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']');
-
 
419
			if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '[');
-
 
420
			if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g');
-
 
421
			if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G');
-
 
422
			if (key=='g' ) pdfapp_onkey(&gapp, 'c');
-
 
423
			if ((key=='[' ) || (key=='l')) PageRotateLeft();
-
 
424
			if ((key==']' ) || (key=='r')) PageRotateRight();
-
 
425
			if (key==ASCII_KEY_DOWN ) PageScrollDown();
-
 
426
			if (key==ASCII_KEY_UP ) PageScrollUp();
-
 
427
			if (key=='-') PageZoomOut();
-
 
428
			if ((key=='=') || (key=='+')) PageZoomIn();
-
 
429
			break;
-
 
430
 
-
 
431
		case evButton:
-
 
432
			butt = __menuet__get_button_id();
-
 
433
			if(butt==1) __menuet__sys_exit();
-
 
434
			if(butt==10) RunOpenApp();
-
 
435
			if(butt==11) PageZoomOut(); //magnify -
-
 
436
			if(butt==12) PageZoomIn(); //magnify +
-
 
437
			if(butt==13) //show help
-
 
438
			{
-
 
439
				kol_paint_bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2);	
-
 
440
				__menuet__write_text(20, TOOLBAR_HEIGHT + 20      , 0x90000000, "uPDF for KolibriOS v1.2", 0);
-
 
441
				__menuet__write_text(21, TOOLBAR_HEIGHT + 20      , 0x90000000, "uPDF for KolibriOS v1.2", 0);
-
 
442
				for (ii=0; help[ii]!=0; ii++) {
-
 
443
					__menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0);
-
 
444
				}
-
 
445
			}
-
 
446
			if(butt==14) pdfapp_onkey(&gapp, '['); //previous page
-
 
447
			if(butt==15) pdfapp_onkey(&gapp, ']'); //next page
-
 
448
			if(butt==16) PageRotateLeft();
-
 
449
			if(butt==17) PageRotateRight();
-
 
450
			if(butt==20) GetNewPageNumber();
-
 
451
			break;
-
 
452
 
-
 
453
		case evMouse:
-
 
454
			if (mouse_wheels_state = kos_get_mouse_wheels())
-
 
455
			{
-
 
456
				if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); }
-
 
457
				if (mouse_wheels_state==-1) { PageScrollUp();  PageScrollUp();   }
-
 
458
			}
-
 
459
			//sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state);
-
 
460
			//kol_board_puts(debugstr);
-
 
461
			//pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state)
-
 
462
			break;
-
 
463
	}
-
 
464
  }
538
465
}