Subversion Repositories Kolibri OS

Rev

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

Rev 7462 Rev 7466
Line 1... Line 1...
1
#define MEMSIZE 4096*25
1
#define MEMSIZE 4096*25
Line -... Line 2...
-
 
2
 
-
 
3
//===================================================//
-
 
4
//                                                   //
-
 
5
//                       LIB                         //
-
 
6
//                                                   //
-
 
7
//===================================================//
2
 
8
 
3
#include "../lib/io.h"
9
#include "../lib/io.h"
4
#include "../lib/gui.h"
10
#include "../lib/gui.h"
5
#include "../lib/list_box.h"
11
#include "../lib/list_box.h"
Line 11... Line 17...
11
#include "../lib/obj/iconv.h"
17
#include "../lib/obj/iconv.h"
12
#include "../lib/obj/proc_lib.h"
18
#include "../lib/obj/proc_lib.h"
Line 13... Line 19...
13
 
19
 
Line -... Line 20...
-
 
20
#include "../lib/patterns/simple_open_dialog.h"
-
 
21
 
-
 
22
//===================================================//
-
 
23
//                                                   //
-
 
24
//                       DATA                        //
-
 
25
//                                                   //
14
#include "../lib/patterns/simple_open_dialog.h"
26
//===================================================//
15
 
27
 
16
#define TOOLBAR_H 34
28
#define TOOLBAR_H 34
Line 17... Line 29...
17
#define TOOLBAR_ICON_WIDTH  26
29
#define TOOLBAR_ICON_WIDTH  26
Line 18... Line 30...
18
#define TOOLBAR_ICON_HEIGHT 24
30
#define TOOLBAR_ICON_HEIGHT 24
19
 
31
 
20
#define DEFAULT_EDITOR "/sys/tinypad"
32
#define DEFAULT_EDITOR "/sys/tinypad"
21
 
33
 
Line 22... Line 34...
22
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
34
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
23
#define VERSION "Text Reader v1.22"
35
#define VERSION "Text Reader v1.3"
Line 32... Line 44...
32
Ctrl+Tab - select charset
44
Ctrl+Tab - select charset
33
Ctrl+E - reopen current file in another app
45
Ctrl+E - reopen current file in another app
Line 34... Line 46...
34
 
46
 
Line -... Line 47...
-
 
47
Press any key..."
-
 
48
 
-
 
49
dword color_schemes[] = {
-
 
50
0xFFFfff, 0,
-
 
51
0xF0F0F0, 0,
-
 
52
0xE9E5DA, 0,
-
 
53
0xF0F0C7, 0,
-
 
54
0xFCF0DA, 0x574531,
-
 
55
0xFDF6E3, 0x303A41,
-
 
56
0x282C34, 0xABB2BF,
-
 
57
0x282923, 0xD8D8D2
-
 
58
};
-
 
59
 
-
 
60
char color_scheme_names[] =
-
 
61
"White & Black
-
 
62
Grey & Black      RtfRead
-
 
63
Khaki & Black     QNX
-
 
64
Lemon & Black     Fb2Read
-
 
65
Antique & Black   Pocket
-
 
66
Linen & Black     Horst
-
 
67
DarkGrey & Grey   Godot
35
Press any key..."
68
DarkGrey & Grey   Monokai";
36
 
69
 
Line 37... Line 70...
37
char default_dir[] = "/rd/1";
70
char default_dir[] = "/rd/1";
38
od_filter filter2 = { 8, "TXT\0\0" };
71
od_filter filter2 = { 8, "TXT\0\0" };
Line 39... Line 72...
39
 
72
 
40
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
73
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
Line 41... Line 74...
41
llist list;
74
llist list;
42
 
75
 
43
proc_info Form;
76
proc_info Form;
-
 
77
char title[4196];
-
 
78
 
-
 
79
bool help_opened = false;
Line 44... Line 80...
44
char title[4196];
80
int charsets_mx;
45
 
81
int reopenin_mx;
46
bool help_opened = false;
82
int colscheme_mx;
47
int charsets_menu_left = 0;
83
 
48
int reopenin_menu_left = 0;
84
int curcol_scheme;
49
 
85
 
50
enum {
86
enum {
51
	OPEN_FILE,
87
	OPEN_FILE,
-
 
88
	MAGNIFY_MINUS,
52
	MAGNIFY_MINUS,
89
	MAGNIFY_PLUS,
Line 53... Line 90...
53
	MAGNIFY_PLUS,
90
	CHANGE_ENCODING,
Line 54... Line 91...
54
	CHANGE_ENCODING,
91
	RUN_EDIT,
55
	RUN_EDIT,
92
	SHOW_INFO,
-
 
93
	SHOW_FILE_PROPERTIES,
-
 
94
	COLOR_SCHEME
-
 
95
};
-
 
96
 
-
 
97
int encoding;
-
 
98
 
Line 56... Line 99...
56
	SHOW_INFO,
99
dword bg_color;
57
	SHOW_FILE_PROPERTIES
100
dword text_color;
Line -... Line 101...
-
 
101
 
-
 
102
//===================================================//
-
 
103
//                                                   //
-
 
104
//                 INTERNAL INCLUDES                 //
-
 
105
//                                                   //
-
 
106
//===================================================//
58
};
107
 
59
 
108
#include "ini.h"
60
int encoding;
109
#include "prepare_page.h"
61
 
110
 
62
dword bg_color = 0xF0F0F0;
111
//===================================================//
63
dword text_color = 0;
112
//                                                   //
64
 
113
//                       CODE                        //
65
#include "ini.h"
114
//                                                   //
66
#include "prepare_page.h"
115
//===================================================//
Line 67... Line -...
67
 
-
 
68
void InitDlls()
116
 
69
{
117
void InitDlls()
70
	load_dll(boxlib,    #box_lib_init,   0);
118
{
71
	load_dll(libio,     #libio_init,     1);
119
	load_dll(boxlib,    #box_lib_init,   0);
72
	load_dll(libimg,    #libimg_init,    1);
120
	load_dll(libio,     #libio_init,     1);
-
 
121
	load_dll(libimg,    #libimg_init,    1);
73
	load_dll(libini,    #lib_init,       1);
122
	load_dll(libini,    #lib_init,       1);
74
	load_dll(iconv_lib, #iconv_open,     0);
123
	load_dll(iconv_lib, #iconv_open,     0);
75
	load_dll(Proc_lib,  #OpenDialog_init,0);
124
	load_dll(Proc_lib,  #OpenDialog_init,0);
76
}
125
}
77
 
126
 
Line 104... Line 153...
104
				draw_window();
153
				draw_window();
105
		}
154
		}
106
	}
155
	}
107
}
156
}
Line -... Line 157...
-
 
157
 
-
 
158
//===================================================//
-
 
159
//                                                   //
-
 
160
//                      EVENTS                       //
-
 
161
//                                                   //
Line 108... Line 162...
108
 
162
//===================================================//
109
 
163
 
Line 110... Line 164...
110
void HandleButtonEvent()
164
void HandleButtonEvent()
Line 132... Line 186...
132
			break;
186
			break;
133
		case CHANGE_ENCODING:
187
		case CHANGE_ENCODING:
134
			EventShowEncodingList();
188
			EventShowEncodingList();
135
			break;
189
			break;
136
		case RUN_EDIT:
190
		case RUN_EDIT:
137
			EventShowEdit();
191
			EventShowReopenMenu();
-
 
192
			break;
-
 
193
		case COLOR_SCHEME:
-
 
194
			EventShowColorSchemesList();
138
			break;
195
			break;
139
		case SHOW_INFO:
196
		case SHOW_INFO:
140
			EventShowInfo();
197
			EventShowInfo();
141
			break;
198
			break;
142
	}
199
	}
Line 169... Line 226...
169
				break;
226
				break;
170
			case SCAN_CODE_DOWN:
227
			case SCAN_CODE_DOWN:
171
				EventMagnifyMinus();
228
				EventMagnifyMinus();
172
				break;
229
				break;
173
			case SCAN_CODE_KEY_E:
230
			case SCAN_CODE_KEY_E:
174
				EventShowEdit();
231
				EventShowReopenMenu();
175
				break;
232
				break;
176
			case SCAN_CODE_TAB:
233
			case SCAN_CODE_TAB:
177
				EventChangeEncoding();
234
				EventChangeEncoding();
178
				break;
235
				break;
179
		}
236
		}
Line 197... Line 254...
197
		list.first = scroll.position;
254
		list.first = scroll.position;
198
		DrawPage(); 
255
		DrawPage(); 
199
	}
256
	}
200
}
257
}
Line 201... Line -...
201
 
-
 
202
 
258
 
Line 203... Line 259...
203
/* ----------------------------------------------------- */
259
/* ----------------------------------------------------- */
204
 
260
 
205
void EventOpenFile()
261
void EventOpenFile()
Line 235... Line 291...
235
		kfont.size.pt++;
291
		kfont.size.pt++;
236
	else
292
	else
237
		PreparePage();
293
		PreparePage();
238
}
294
}
Line 239... Line 295...
239
 
295
 
-
 
296
void EventShowEncodingList()
-
 
297
{
-
 
298
	menu.selected = encoding + 1;
-
 
299
	menu.show(Form.left+5 + charsets_mx, Form.top+29+skin_height, 130,
-
 
300
		"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
-
 
301
}
-
 
302
 
240
void EventShowEdit()
303
void EventShowReopenMenu()
241
{
304
{
242
	menu.selected = 0;
305
	menu.selected = 0;
243
	menu.show(Form.left+5 + reopenin_menu_left, Form.top+29+skin_height, 130,
306
	menu.show(Form.left+5 + reopenin_mx, Form.top+29+skin_height, 130,
244
		"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView", 20);
307
		"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther", 20);
Line 245... Line 308...
245
}
308
}
246
 
309
 
247
void EventShowEncodingList()
310
void EventShowColorSchemesList()
248
{
311
{
-
 
312
	menu.selected = curcol_scheme + 1;
-
 
313
	menu.show(Form.left+5 + colscheme_mx, Form.top+29+skin_height, 175, #color_scheme_names, 30);
-
 
314
}
-
 
315
 
-
 
316
void EventSetColorScheme(dword _setn)
-
 
317
{
249
	menu.selected = encoding + 1;
318
	curcol_scheme = _setn;
250
	menu.show(Form.left+5 + charsets_menu_left, Form.top+29+skin_height, 130,
319
	bg_color   = color_schemes[curcol_scheme*2];
Line 251... Line 320...
251
		"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
320
	text_color = color_schemes[curcol_scheme*2+1];
252
}
321
}
253
 
322
 
Line 271... Line 340...
271
	RunProgram(_app, #param);
340
	RunProgram(_app, #param);
272
}
341
}
Line 273... Line 342...
273
 
342
 
274
void EventMenuClick()
343
void EventMenuClick()
-
 
344
{
275
{
345
	byte open_param[4096];
276
	switch(menu.cur_y)
346
	switch(menu.cur_y)
277
	{
347
	{
278
		//Encoding
348
		//Encoding
279
		case 10...15:
349
		case 10...15:
Line 293... Line 363...
293
			EventOpenFileInAnotherProgram("/sys/fb2read");
363
			EventOpenFileInAnotherProgram("/sys/fb2read");
294
			break;
364
			break;
295
		case 24:
365
		case 24:
296
			EventOpenFileInAnotherProgram("/sys/develop/heed");
366
			EventOpenFileInAnotherProgram("/sys/develop/heed");
297
			break;
367
			break;
-
 
368
		case 25:
-
 
369
			sprintf(#open_param,"~%s",#param);
-
 
370
			RunProgram("/sys/@open", #open_param);
-
 
371
			break;
-
 
372
		//ColorSchemes
-
 
373
		case 30...38:
-
 
374
			EventSetColorScheme(menu.cur_y-30);
-
 
375
			PreparePage();
-
 
376
			break;
298
	}
377
	}
299
	menu.cur_y = 0;
378
	menu.cur_y = 0;
300
}
379
}
Line -... Line 380...
-
 
380
 
-
 
381
//===================================================//
301
 
382
//                                                   //
302
/* ------------------------------------------- */
-
 
-
 
383
//               DRAWS AND OTHER FUNCS               //
-
 
384
//                                                   //
Line 303... Line 385...
303
 
385
//===================================================//
304
 
386
 
305
void OpenFile(dword f_path) 
387
void OpenFile(dword f_path) 
306
{
388
{
Line 321... Line 403...
321
	list.ClearList();
403
	list.ClearList();
322
}
404
}
Line 323... Line 405...
323
 
405
 
324
void draw_window()
406
void draw_window()
325
{
407
{
-
 
408
	#define BUTTONS_GAP 6
326
	#define PADDING 6
409
	#define BLOCKS_GAP 15
327
	#define TOOLBAR_BUTTON_WIDTH 26
410
	#define TOOLBAR_BUTTON_WIDTH 26
328
	incn x;
411
	incn x;
329
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
412
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
330
	GetProcessInfo(#Form, SelfInfo);
413
	GetProcessInfo(#Form, SelfInfo);
Line 336... Line 419...
336
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
419
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
337
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
420
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
Line 338... Line 421...
338
	
421
	
339
	x.n = 0;
422
	x.n = 0;
340
	DrawToolbarButton(OPEN_FILE,       x.inc(8));
423
	DrawToolbarButton(OPEN_FILE,       x.inc(8));
-
 
424
	DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP));
341
	DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING));
425
 
342
	DrawToolbarButton(MAGNIFY_MINUS,   x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
426
	DrawToolbarButton(MAGNIFY_MINUS,   x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP));
343
	DrawToolbarButton(MAGNIFY_PLUS,    x.inc(TOOLBAR_BUTTON_WIDTH - 1));
-
 
344
	DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
-
 
345
		charsets_menu_left = x.n;
427
	DrawToolbarButton(MAGNIFY_PLUS,    x.inc(TOOLBAR_BUTTON_WIDTH - 1));
346
	DrawToolbarButton(RUN_EDIT,        x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
-
 
347
		reopenin_menu_left = x.n;
-
 
Line -... Line 428...
-
 
428
	DrawToolbarButton(COLOR_SCHEME,    x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); colscheme_mx = x.n;
-
 
429
 
-
 
430
	DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); charsets_mx = x.n;
Line 348... Line 431...
348
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
431
	DrawToolbarButton(RUN_EDIT,        x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); reopenin_mx = x.n;
349
	
432
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
350
	
433
	
351
	if ((Form.cwidth-scroll.size_x-1 == list.w) && 
434
	if ((Form.cwidth-scroll.size_x-1 == list.w) && 
352
		(Form.cheight-TOOLBAR_H == list.h) && 
435
		(Form.cheight-TOOLBAR_H == list.h) && 
353
		(list.count) 
436
		(list.count) 
354
	)
437
	)
355
	{
438
	{
356
		DrawPage(); 
439
		DrawPage(); 
-
 
440
	} else {
357
	} else {
441
		PreparePage();
358
		PreparePage();
442
	}		
Line 359... Line 443...
359
	}
443
	
360
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
444
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);