Subversion Repositories Kolibri OS

Rev

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

Rev 5886 Rev 5923
Line 10... Line 10...
10
#include "../lib/obj/proc_lib.h"
10
#include "../lib/obj/proc_lib.h"
11
#include "../lib/patterns/libimg_load_skin.h"
11
#include "../lib/patterns/libimg_load_skin.h"
12
#include "../lib/patterns/simple_open_dialog.h"
12
#include "../lib/patterns/simple_open_dialog.h"
Line 13... Line 13...
13
 
13
 
-
 
14
#define TOOLBAR_H 34
-
 
15
#define TOOLBAR_ICON_WIDTH  26
-
 
16
#define TOOLBAR_ICON_HEIGHT 24
-
 
17
 
-
 
18
#define TOOLBAR_OPEN_FILE_LEFT       8
-
 
19
#define TOOLBAR_MAGNIFY_PLUS_LEFT    42
-
 
20
#define TOOLBAR_MAGNIFY_MINUS_LEFT   67
-
 
21
#define TOOLBAR_CHANGE_ENCODING_LEFT 101
-
 
22
#define TOOLBAR_RUN_EDIT_LEFT        135
-
 
23
 
-
 
24
#define DEFAULT_FONT   "/sys/fonts/Tahoma.kf"
-
 
25
#define DEFAULT_EDITOR "/sys/tinypad"
-
 
26
 
Line 14... Line 27...
14
#define TOOLBAR_H 34
27
#define INTRO_TEXT "This is a plain text reader.\nTry to open some text file."
15
 
28
 
Line 16... Line 29...
16
char default_dir[] = "/rd/1";
29
char default_dir[] = "/rd/1";
Line 27... Line 40...
27
char char_width[255];
40
char char_width[255];
28
dword line_offset;
41
dword line_offset;
29
#define DWORD 4;
42
#define DWORD 4;
Line 30... Line 43...
30
 
43
 
31
enum {
44
enum {
32
	OPEN_FILE,
45
	OPEN_FILE = 10,
33
	MAGNIFY_MINUS,
46
	MAGNIFY_MINUS,
34
	MAGNIFY_PLUS,
47
	MAGNIFY_PLUS,
35
	CHANGE_ENCODING,
48
	CHANGE_ENCODING,
36
	RUN_EDIT,
49
	RUN_EDIT,
37
	SHOW_INFO,
50
	SHOW_INFO,
Line 38... Line 51...
38
};
51
};
39
 
52
 
Line 40... Line 53...
40
#include "ini.h"
53
#include "ini.h"
41
#include "menu.h"
54
#include "menu.h"
42
 
-
 
43
void main()
55
 
44
{   
56
void InitDlls()
45
	byte btn;
57
{
46
	load_dll(boxlib, #box_lib_init,0);
58
	load_dll(boxlib,    #box_lib_init,   0);
47
	load_dll(libio, #libio_init,1);
59
	load_dll(libio,     #libio_init,     1);
48
	load_dll(libimg, #libimg_init,1);
60
	load_dll(libimg,    #libimg_init,    1);
-
 
61
	load_dll(libini,    #lib_init,       1);
-
 
62
	load_dll(iconv_lib, #iconv_open,     0);
-
 
63
	load_dll(Proc_lib,  #OpenDialog_init,0);
-
 
64
}
-
 
65
 
-
 
66
void EventShowInfo()
-
 
67
{
-
 
68
	ShowAbout();
-
 
69
}
-
 
70
 
-
 
71
void EventOpenFile()
-
 
72
{
-
 
73
	OpenDialog_start stdcall (#o_dialog);
-
 
74
	OpenFile(#openfile_path);
-
 
75
	PreparePage();
-
 
76
}
-
 
77
 
-
 
78
void EventMagnifyPlus()
-
 
79
{
-
 
80
	font.size.text++;
-
 
81
	if(!font.changeSIZE())
-
 
82
		font.size.text--;
-
 
83
	else
-
 
84
		PreparePage();
-
 
85
}
-
 
86
 
-
 
87
void EventMagnifyMinus()
-
 
88
{
-
 
89
	font.size.text--;
-
 
90
	if(!font.changeSIZE())
-
 
91
		font.size.text++;
-
 
92
	else
-
 
93
		PreparePage();
-
 
94
}
-
 
95
 
-
 
96
void EventRunEdit()
-
 
97
{
-
 
98
	io.run(DEFAULT_EDITOR, #param);
-
 
99
}
-
 
100
 
-
 
101
void EventChangeEncoding()
-
 
102
{
-
 
103
	CreateThread(#menu_rmb,#stak+4092);
-
 
104
}
-
 
105
 
-
 
106
void HandleMouseEvent()
-
 
107
{
-
 
108
	mouse.get();
-
 
109
	list.wheel_size = 7;
-
 
110
	if (list.MouseScroll(mouse.vert)) {
-
 
111
		DrawPage(); 
-
 
112
		return; 
-
 
113
	}
-
 
114
	scrollbar_v_mouse (#scroll);
-
 
115
	if (list.first != scroll.position) {
-
 
116
		list.first = scroll.position;
-
 
117
		DrawPage(); 
-
 
118
	}
-
 
119
}
-
 
120
 
-
 
121
void HandleKeyEvent()
-
 
122
{
-
 
123
	if (help_opened) {
-
 
124
		help_opened = false;
-
 
125
		DrawPage();
-
 
126
		return; 
-
 
127
	}
-
 
128
	GetKeys();
-
 
129
	if (key_scancode==059) {
-
 
130
		EventShowInfo();
-
 
131
		return;
-
 
132
	}
-
 
133
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
-
 
134
		switch (key_scancode)
-
 
135
		{
-
 
136
			case 024:
-
 
137
				EventOpenFile();
-
 
138
				break;
-
 
139
			case SCAN_CODE_UP:
-
 
140
				EventMagnifyPlus();
-
 
141
				break;
-
 
142
			case SCAN_CODE_DOWN:
-
 
143
				EventMagnifyMinus();
-
 
144
				break;
-
 
145
			case 018:
-
 
146
				EventRunEdit();
-
 
147
				break;
-
 
148
			case SCAN_CODE_TAB:
-
 
149
				EventChangeEncoding();
-
 
150
				break;
-
 
151
		}
-
 
152
		return;
-
 
153
	}
-
 
154
	if (list.ProcessKey(key_scancode))
-
 
155
		DrawPage();
-
 
156
}
-
 
157
 
-
 
158
void HandleButtonEvent()
-
 
159
{
-
 
160
	
-
 
161
	byte btn = GetButtonID();
-
 
162
	if (btn==1) {
-
 
163
		SaveIniSettings();
-
 
164
		ExitProcess();
-
 
165
	}
-
 
166
	btn-=10;
-
 
167
	switch(btn)
-
 
168
	{
-
 
169
		case OPEN_FILE:
-
 
170
			EventOpenFile();
-
 
171
			break;
-
 
172
		case MAGNIFY_PLUS:
-
 
173
			EventMagnifyPlus();
-
 
174
			break;
-
 
175
		case MAGNIFY_MINUS:
-
 
176
			EventMagnifyMinus();
-
 
177
			break;
-
 
178
		case CHANGE_ENCODING:
-
 
179
			EventChangeEncoding();
-
 
180
			break;
-
 
181
		case RUN_EDIT:
-
 
182
			EventRunEdit();
-
 
183
			break;
-
 
184
		case SHOW_INFO:
-
 
185
			EventShowInfo();
-
 
186
			break;
-
 
187
	}
-
 
188
}
-
 
189
 
-
 
190
void main()
49
	load_dll(libini, #lib_init,1);
191
{   	
-
 
192
	InitDlls();
-
 
193
	
-
 
194
	OpenDialog_init stdcall (#o_dialog);
50
	load_dll(iconv_lib, #iconv_open,0);
195
	
-
 
196
	font.no_bg_copy = true;
-
 
197
	font.color      = 0;
-
 
198
	font.bg_color   = 0xFFFFFF;
-
 
199
	
51
	load_dll(Proc_lib, #OpenDialog_init,0);
200
	font.load(DEFAULT_FONT);
-
 
201
	
-
 
202
	if (!font.data) {
-
 
203
		io.run("/sys/@notify","'Error: Font is not loaded.' -E");
52
	OpenDialog_init stdcall (#o_dialog);
204
		ExitProcess();
-
 
205
	}
53
	font.no_bg_copy = true; font.color = 0; font.bg_color = 0xFFFFFF;
206
	
-
 
207
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
54
	font.load("/sys/fonts/Tahoma.kf"); if (!font.data) { io.run("/sys/@notify","'Error: Font is not loaded.' -E"); ExitProcess(); }
208
	
55
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
209
	LoadIniSettings();
56
	LoadIniSettings();
210
	
57
	OpenFile(#param);
211
	OpenFile(#param);
58
	list.no_selection = true;
212
	list.no_selection = true;
59
	SetEventMask(10000000000000000000000001100111b);
213
	SetEventMask(10000000000000000000000001100111b);
60
	loop()
214
	loop()
61
	{
215
	{
62
	switch(WaitEvent())
216
		switch(WaitEvent())
63
	{
-
 
64
	   	case evMouse:
-
 
65
      		mouse.get();
-
 
66
      		list.wheel_size = 7;
217
		{
67
			if (list.MouseScroll(mouse.vert)) { DrawPage(); break; }
218
			case evMouse:
68
			scrollbar_v_mouse (#scroll); if (list.first != scroll.position) { list.first = scroll.position; DrawPage(); }
-
 
69
			break;
219
				HandleMouseEvent();
70
		case evKey:
-
 
71
			if (help_opened) { help_opened=false; DrawPage(); break; }
-
 
72
			GetKeys();
-
 
73
			if (key_scancode==059) goto _SHOW_INFO;
-
 
74
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
-
 
75
				if (key_scancode==024) goto _OPEN_FILE;
-
 
76
				if (key_scancode==SCAN_CODE_UP) goto _MAGNIFY_PLUS;
-
 
77
				if (key_scancode==SCAN_CODE_DOWN) goto _MAGNIFY_MINUS;
-
 
78
				if (key_scancode==018) goto _RUN_EDIT;
-
 
79
				if (key_scancode==SCAN_CODE_TAB) goto _CHANGE_ENCODING;
-
 
80
				break;
220
				break;
81
			}
221
			case evKey:
82
			if (list.ProcessKey(key_scancode)) DrawPage();
222
				HandleKeyEvent();
83
			break;
-
 
84
		case evButton:
-
 
85
			btn = GetButtonID();
-
 
86
			if (btn==1) { SaveIniSettings(); ExitProcess(); }
-
 
87
			btn-=10;
-
 
88
			if (btn==OPEN_FILE) { _OPEN_FILE: OpenDialog_start stdcall (#o_dialog); OpenFile(#openfile_path); PreparePage(); }
-
 
89
			else if (btn==MAGNIFY_PLUS)  { _MAGNIFY_PLUS: font.size.text++; if(!font.changeSIZE())font.size.text--; else PreparePage(); }
-
 
90
			else if (btn==MAGNIFY_MINUS) { _MAGNIFY_MINUS: font.size.text--; if(!font.changeSIZE())font.size.text++; else PreparePage(); }
-
 
91
			else if (btn==CHANGE_ENCODING) { _CHANGE_ENCODING: CreateThread(#menu_rmb,#stak+4092); break; }
223
				break;
92
			else if (btn==RUN_EDIT) { _RUN_EDIT: io.run("/sys/tinypad",#param); }
224
			case evButton:
93
			else if (btn==SHOW_INFO) { _SHOW_INFO: ShowAbout(); }
225
				HandleButtonEvent();
94
			break;
226
				break;
95
		case evReDraw:
227
			case evReDraw:
Line 106... Line 238...
106
void draw_window()
238
void draw_window()
107
{
239
{
108
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
240
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
109
	GetProcessInfo(#Form, SelfInfo);
241
	GetProcessInfo(#Form, SelfInfo);
110
	if (Form.status_window>2) return;
242
	if (Form.status_window>2) return;
-
 
243
 
111
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
244
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
112
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
245
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
-
 
246
	
113
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
247
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
114
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
248
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
-
 
249
	
115
	DrawToolbarButton(OPEN_FILE, 8);
250
	DrawToolbarButton(OPEN_FILE,       TOOLBAR_OPEN_FILE_LEFT);
116
	DrawToolbarButton(MAGNIFY_PLUS, 42);
251
	DrawToolbarButton(MAGNIFY_PLUS,    TOOLBAR_MAGNIFY_PLUS_LEFT);
117
	DrawToolbarButton(MAGNIFY_MINUS, 67);
252
	DrawToolbarButton(MAGNIFY_MINUS,   TOOLBAR_MAGNIFY_MINUS_LEFT);
118
	DrawToolbarButton(CHANGE_ENCODING, 101);
253
	DrawToolbarButton(CHANGE_ENCODING, TOOLBAR_CHANGE_ENCODING_LEFT);
119
	DrawToolbarButton(RUN_EDIT, 135);
254
	DrawToolbarButton(RUN_EDIT,        TOOLBAR_RUN_EDIT_LEFT);
120
	DrawToolbarButton(SHOW_INFO, Form.cwidth - 34);
255
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
-
 
256
	
121
	if (Form.cwidth-scroll.size_x-1 == list.w) && (Form.cheight-TOOLBAR_H == list.h) && (list.count) DrawPage(); else PreparePage();
257
	if ((Form.cwidth-scroll.size_x-1 == list.w) && 
-
 
258
		(Form.cheight-TOOLBAR_H == list.h) && 
-
 
259
		(list.count) 
-
 
260
	)
-
 
261
	{
-
 
262
		DrawPage(); 
-
 
263
	} else {
-
 
264
		PreparePage();
-
 
265
	}
122
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
266
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
123
}
267
}
Line 124... Line 268...
124
 
268
 
125
void DrawPage()
269
void DrawPage()
Line 136... Line 280...
136
	dword bufoff;
280
	dword bufoff;
137
	dword line_length=30;
281
	dword line_length=30;
138
	dword stroka_y = 5;
282
	dword stroka_y = 5;
139
	dword stroka=0;
283
	dword stroka=0;
140
	int i, srch_pos;
284
	int i, srch_pos;
-
 
285
	
141
	font.changeSIZE();
286
	font.changeSIZE();
142
	list.w = Form.cwidth-scroll.size_x-1;
287
	list.w = Form.cwidth-scroll.size_x-1;
143
	//get font chars width, need to increase performance
288
	//get font chars width, need to increase performance
144
	for (i=0; i<256; i++) char_width[i] = font.symbol_size(i);
289
	for (i=0; i<256; i++) char_width[i] = font.symbol_size(i);
145
	//get font buffer height
290
	//get font buffer height
Line 197... Line 342...
197
	DrawPage();
342
	DrawPage();
198
}
343
}
Line 199... Line 344...
199
 
344
 
200
void DrawToolbarButton(char image_id, int x)
345
void DrawToolbarButton(char image_id, int x)
201
{
346
{
202
	DefineButton(x, 5, 26-1, 24-1, 10+image_id + BT_HIDE, 0);
347
	DefineButton(x, 5, TOOLBAR_ICON_WIDTH-1, TOOLBAR_ICON_HEIGHT-1, 10+image_id + BT_HIDE, 0);
203
	img_draw stdcall(skin.image, x, 5, 26, 24, 0, image_id*24);
348
	img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, 0, image_id*TOOLBAR_ICON_HEIGHT);
Line 204... Line 349...
204
}
349
}
205
 
350
 
206
void DrawScroller()
351
void DrawScroller()
Line 225... Line 370...
225
		strcpy(#title, #param);
370
		strcpy(#title, #param);
226
		strcat(#title, " - Text Reader"); 
371
		strcat(#title, " - Text Reader"); 
227
	}
372
	}
228
	else {
373
	else {
229
		if (list.count) return;
374
		if (list.count) return;
230
		io.buffer_data = "This is a plain text reader.\nTry to open some text file.";
375
		io.buffer_data = INTRO_TEXT;
231
		strcpy(#title, "Text Reader"); 
376
		strcpy(#title, "Text Reader"); 
232
	}
377
	}
233
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
378
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
234
	list.KeyHome();
379
	list.KeyHome();
235
	list.ClearList();
380
	list.ClearList();
236
}
381
}
Line 237... Line 382...
237
 
382
 
238
 
383
 
239
 
384
 
240
char *about[] = {
385
char *about[] = {
241
	"Text Reader v1.0",
386
	"Text Reader v1.01",
242
	"Idea: Leency, punk_joker",
387
	"Idea: Leency, punk_joker",
243
	"Code: Leency, KolibriOS Team",
388
	"Code: Leency, Veliant, KolibriOS Team",
244
	" ",
389
	" ",
245
	"Hotkeys:",
390
	"Hotkeys:",