Subversion Repositories Kolibri OS

Rev

Rev 5496 | Rev 5508 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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