Subversion Repositories Kolibri OS

Rev

Rev 5821 | Rev 7533 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5821 Rev 7475
Line 3... Line 3...
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"
Line 8... Line 9...
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
Line 75... Line 76...
75
};
76
};
Line 76... Line 77...
76
 
77
 
Line 77... Line 78...
77
/*==== DATA ====*/
78
/*==== DATA ====*/
78
 
-
 
79
static char Title[1024] = "uPDF";
79
 
80
static char * filename = "/hd0/1/yand.pdf";
80
static char Title[1024] = "uPDF";
81
static pdfapp_t gapp;
81
static pdfapp_t gapp;
Line 82... Line 82...
82
char debugstr[256];
82
char debugstr[256];
Line 182... Line 182...
182
	if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination();
182
	if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination();
Line 183... Line 183...
183
 
183
 
Line 184... Line 184...
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, 
Line 194... Line 194...
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)
Line 231... Line 232...
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
}
Line 253... Line 254...
253
 
254
 
254
 
255
 
255
 
256
 
256
int main (void)
257
int main (void)
257
{
258
{
-
 
259
	char ii, mouse_wheels_state;
Line 258... Line 260...
258
	char ii, mouse_wheels_state;
260
	char* original_command_line = *(char**)0x1C;
259
	char* original_command_line = *(char**)0x1C;
261
	kol_board_puts(original_command_line);
260
	__menuet__debug_out(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");
-
 
273
	pdfapp_open(&gapp, original_command_line, 0, 0);
274
	kol_board_puts("PDF Open\n");
274
	__menuet__debug_out("PDF Opened\n");
275
	pdfapp_open(&gapp, original_command_line, 0, 0);
Line 275... Line 276...
275
	wintitle(&gapp, 0);
276
	kol_board_puts("PDF Opened\n");
276
	
277
	wintitle(&gapp, 0);
277
 
278
	 
Line 287... Line 288...
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
Line 320... Line 323...
320
			break;
323
			break;
Line 321... Line 324...
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
			}
Line 346... Line 349...
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
}
Line 387... Line 390...
387
		return;
390
		return;
388
	}
391
	}
Line 389... Line 392...
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);
Line 393... Line 396...
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
 
Line 403... Line 406...
403
}
406
}
Line 404... Line 407...
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));
Line 411... Line 414...
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);
Line 430... Line 433...
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);
Line 470... Line 473...
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
}
Line -... Line 482...
-
 
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
}
Line 479... Line 495...
479
 
495
 
480
 
496
 
481
void PageZoomIn(void)
497
void PageZoomIn(void)
482
{
498
{