Subversion Repositories Kolibri OS

Rev

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

Rev 6806 Rev 6808
1
#define MEMSIZE 4096*25
1
#define MEMSIZE 4096*25
2
 
2
 
3
#include "../lib/kfont.h"
3
#include "../lib/kfont.h"
4
#include "../lib/io.h"
4
#include "../lib/io.h"
5
#include "../lib/gui.h"
5
#include "../lib/gui.h"
6
#include "../lib/list_box.h"
6
#include "../lib/list_box.h"
7
#include "../lib/menu.h"
7
#include "../lib/menu.h"
8
#include "../lib/obj/box_lib.h"
8
#include "../lib/obj/box_lib.h"
9
#include "../lib/obj/libini.h"
9
#include "../lib/obj/libini.h"
10
#include "../lib/obj/iconv.h"
10
#include "../lib/obj/iconv.h"
11
#include "../lib/obj/proc_lib.h"
11
#include "../lib/obj/proc_lib.h"
12
#include "../lib/patterns/libimg_load_skin.h"
12
#include "../lib/patterns/libimg_load_skin.h"
13
#include "../lib/patterns/simple_open_dialog.h"
13
#include "../lib/patterns/simple_open_dialog.h"
14
 
14
 
15
#define TOOLBAR_H 34
15
#define TOOLBAR_H 34
16
#define TOOLBAR_ICON_WIDTH  26
16
#define TOOLBAR_ICON_WIDTH  26
17
#define TOOLBAR_ICON_HEIGHT 24
17
#define TOOLBAR_ICON_HEIGHT 24
18
 
18
 
19
#define DEFAULT_EDITOR "/sys/tinypad"
19
#define DEFAULT_EDITOR "/sys/tinypad"
20
 
20
 
21
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
21
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
22
#define VERSION "Text Reader v1.2"
22
#define VERSION "Text Reader v1.2"
23
#define ABOUT "Idea: Leency, punk_joker
23
#define ABOUT "Idea: Leency, punk_joker
24
Code: Leency, Veliant, KolibriOS Team
24
Code: Leency, Veliant, KolibriOS Team
25
 
25
 
26
Hotkeys:
26
Hotkeys:
27
Ctrl+O - open file
27
Ctrl+O - open file
28
Ctrl+Up - bigger font
28
Ctrl+Up - bigger font
29
Ctrl+Down - smaller font
29
Ctrl+Down - smaller font
30
Ctrl+Tab - select charset
30
Ctrl+Tab - select charset
31
Ctrl+E - edit current document
31
Ctrl+E - edit current document
32
 
32
 
33
Press any key..."
33
Press any key..."
34
 
34
 
35
char default_dir[] = "/rd/1";
35
char default_dir[] = "/rd/1";
36
od_filter filter2 = {0,0};
36
od_filter filter2 = {0,0};
37
 
37
 
38
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};
38
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};
39
llist list;
39
llist list;
40
 
40
 
41
proc_info Form;
41
proc_info Form;
42
char title[4196];
42
char title[4196];
43
 
43
 
44
byte help_opened = false;
44
byte help_opened = false;
45
 
45
 
46
enum {
46
enum {
47
	OPEN_FILE,
47
	OPEN_FILE,
48
	MAGNIFY_MINUS,
48
	MAGNIFY_MINUS,
49
	MAGNIFY_PLUS,
49
	MAGNIFY_PLUS,
50
	CHANGE_ENCODING,
50
	CHANGE_ENCODING,
51
	RUN_EDIT,
51
	RUN_EDIT,
52
	SHOW_INFO,
52
	SHOW_INFO,
53
};
53
};
54
 
54
 
55
#include "ini.h"
55
#include "ini.h"
56
#include "gui.h"
56
#include "gui.h"
57
#include "prepare_page.h"
57
#include "prepare_page.h"
58
 
58
 
59
 
59
 
60
void InitDlls()
60
void InitDlls()
61
{
61
{
62
	load_dll(boxlib,    #box_lib_init,   0);
62
	load_dll(boxlib,    #box_lib_init,   0);
63
	load_dll(libio,     #libio_init,     1);
63
	load_dll(libio,     #libio_init,     1);
64
	load_dll(libimg,    #libimg_init,    1);
64
	load_dll(libimg,    #libimg_init,    1);
65
	load_dll(libini,    #lib_init,       1);
65
	load_dll(libini,    #lib_init,       1);
66
	load_dll(iconv_lib, #iconv_open,     0);
66
	load_dll(iconv_lib, #iconv_open,     0);
67
	load_dll(Proc_lib,  #OpenDialog_init,0);
67
	load_dll(Proc_lib,  #OpenDialog_init,0);
68
}
68
}
69
 
69
 
70
 
70
 
71
void main()
71
void main()
72
{   	
72
{   	
73
	InitDlls();	
73
	InitDlls();	
74
	OpenDialog_init stdcall (#o_dialog);
74
	OpenDialog_init stdcall (#o_dialog);
75
	kfont.init(DEFAULT_FONT);
75
	kfont.init(DEFAULT_FONT);
76
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
76
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
77
	LoadIniSettings();
77
	LoadIniSettings();
78
	OpenFile(#param);
78
	OpenFile(#param);
79
	list.no_selection = true;
79
	list.no_selection = true;
80
	SetEventMask(10000000000000000000000001100111b);
80
	SetEventMask(10000000000000000000000001100111b);
81
	loop()
81
	loop()
82
	{
82
	{
83
		switch(WaitEvent())
83
		switch(WaitEvent())
84
		{
84
		{
85
			case evMouse:
85
			case evMouse:
86
				HandleMouseEvent();
86
				HandleMouseEvent();
87
				break;
87
				break;
88
			case evKey:
88
			case evKey:
89
				HandleKeyEvent();
89
				HandleKeyEvent();
90
				break;
90
				break;
91
			case evButton:
91
			case evButton:
92
				HandleButtonEvent();
92
				HandleButtonEvent();
93
				break;
93
				break;
94
			case evReDraw:
94
			case evReDraw:
95
				if (menu.list.cur_y) {
95
				if (menu.list.cur_y) {
96
					encoding = menu.list.cur_y - 10;
96
					encoding = menu.list.cur_y - 10;
97
					OpenFile(#param); 
97
					OpenFile(#param); 
98
					PreparePage();
98
					PreparePage();
99
					menu.list.cur_y = NULL;
99
					menu.list.cur_y = NULL;
100
				};
100
				};
101
				draw_window();
101
				draw_window();
102
		}
102
		}
103
	}
103
	}
104
}
104
}
105
 
105
 
106
 
106
 
107
void HandleButtonEvent()
107
void HandleButtonEvent()
108
{
108
{
109
	
109
	
110
	byte btn = GetButtonID();
110
	byte btn = GetButtonID();
111
	if (btn==1) {
111
	if (btn==1) {
112
		SaveIniSettings();
112
		SaveIniSettings();
113
		ExitProcess();
113
		ExitProcess();
114
	}
114
	}
115
	btn-=10;
115
	btn-=10;
116
	switch(btn)
116
	switch(btn)
117
	{
117
	{
118
		case OPEN_FILE:
118
		case OPEN_FILE:
119
			EventOpenFile();
119
			EventOpenFile();
120
			break;
120
			break;
121
		case MAGNIFY_PLUS:
121
		case MAGNIFY_PLUS:
122
			EventMagnifyPlus();
122
			EventMagnifyPlus();
123
			break;
123
			break;
124
		case MAGNIFY_MINUS:
124
		case MAGNIFY_MINUS:
125
			EventMagnifyMinus();
125
			EventMagnifyMinus();
126
			break;
126
			break;
127
		case CHANGE_ENCODING:
127
		case CHANGE_ENCODING:
128
			EventChangeEncoding();
128
			EventChangeEncoding();
129
			break;
129
			break;
130
		case RUN_EDIT:
130
		case RUN_EDIT:
131
			EventRunEdit();
131
			EventRunEdit();
132
			break;
132
			break;
133
		case SHOW_INFO:
133
		case SHOW_INFO:
134
			EventShowInfo();
134
			EventShowInfo();
135
			break;
135
			break;
136
	}
136
	}
137
}
137
}
138
 
138
 
139
 
139
 
140
void HandleKeyEvent()
140
void HandleKeyEvent()
141
{
141
{
142
	if (help_opened) {
142
	if (help_opened) {
143
		help_opened = false;
143
		help_opened = false;
144
		DrawPage();
144
		DrawPage();
145
		return; 
145
		return; 
146
	}
146
	}
147
	GetKeys();
147
	GetKeys();
148
	if (key_scancode==059) {
148
	if (key_scancode==059) {
149
		EventShowInfo();
149
		EventShowInfo();
150
		return;
150
		return;
151
	}
151
	}
152
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
152
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
153
		switch (key_scancode)
153
		switch (key_scancode)
154
		{
154
		{
155
			case 024:
155
			case 024:
156
				EventOpenFile();
156
				EventOpenFile();
157
				break;
157
				break;
158
			case SCAN_CODE_UP:
158
			case SCAN_CODE_UP:
159
				EventMagnifyPlus();
159
				EventMagnifyPlus();
160
				break;
160
				break;
161
			case SCAN_CODE_DOWN:
161
			case SCAN_CODE_DOWN:
162
				EventMagnifyMinus();
162
				EventMagnifyMinus();
163
				break;
163
				break;
164
			case 018:
164
			case 018:
165
				EventRunEdit();
165
				EventRunEdit();
166
				break;
166
				break;
167
			case SCAN_CODE_TAB:
167
			case SCAN_CODE_TAB:
168
				EventChangeEncoding();
168
				EventChangeEncoding();
169
				break;
169
				break;
170
		}
170
		}
171
		return;
171
		return;
172
	}
172
	}
173
	if (list.ProcessKey(key_scancode))
173
	if (list.ProcessKey(key_scancode))
174
		DrawPage();
174
		DrawPage();
175
}
175
}
176
 
176
 
177
 
177
 
178
void HandleMouseEvent()
178
void HandleMouseEvent()
179
{
179
{
180
	mouse.get();
180
	mouse.get();
181
	list.wheel_size = 7;
181
	list.wheel_size = 7;
182
	if (list.MouseScroll(mouse.vert)) {
182
	if (list.MouseScroll(mouse.vert)) {
183
		DrawPage(); 
183
		DrawPage(); 
184
		return; 
184
		return; 
185
	}
185
	}
186
	scrollbar_v_mouse (#scroll);
186
	scrollbar_v_mouse (#scroll);
187
	if (list.first != scroll.position) {
187
	if (list.first != scroll.position) {
188
		list.first = scroll.position;
188
		list.first = scroll.position;
189
		DrawPage(); 
189
		DrawPage(); 
190
	}
190
	}
191
}
191
}
192
 
192
 
193
 
193
 
194
/* ----------------------------------------------------- */
194
/* ----------------------------------------------------- */
195
 
195
 
196
void EventOpenFile()
196
void EventOpenFile()
197
{
197
{
198
	OpenDialog_start stdcall (#o_dialog);
198
	OpenDialog_start stdcall (#o_dialog);
199
	OpenFile(#openfile_path);
199
	OpenFile(#openfile_path);
200
	PreparePage();
200
	PreparePage();
201
}
201
}
202
 
202
 
203
void EventMagnifyPlus()
203
void EventMagnifyPlus()
204
{
204
{
205
	kfont.size.pt++;
205
	kfont.size.pt++;
206
	if(!kfont.changeSIZE())
206
	if(!kfont.changeSIZE())
207
		kfont.size.pt--;
207
		kfont.size.pt--;
208
	else
208
	else
209
		PreparePage();
209
		PreparePage();
210
}
210
}
211
 
211
 
212
void EventMagnifyMinus()
212
void EventMagnifyMinus()
213
{
213
{
214
	kfont.size.pt--;
214
	kfont.size.pt--;
215
	if(!kfont.changeSIZE())
215
	if(!kfont.changeSIZE())
216
		kfont.size.pt++;
216
		kfont.size.pt++;
217
	else
217
	else
218
		PreparePage();
218
		PreparePage();
219
}
219
}
220
 
220
 
221
void EventRunEdit()
221
void EventRunEdit()
222
{
222
{
223
	io.run(DEFAULT_EDITOR, #param);
223
	io.run(DEFAULT_EDITOR, #param);
224
}
224
}
225
 
225
 
226
void EventChangeEncoding()
226
void EventChangeEncoding()
227
{
227
{
228
	menu.selected = encoding + 1;
228
	menu.selected = encoding + 1;
229
	menu.show(Form.left+104, Form.top+29+skin_height, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
229
	menu.show(Form.left+104, Form.top+29+skin_height, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
230
}
230
}
231
 
231
 
232
void EventShowInfo() {
232
void EventShowInfo() {
233
	help_opened = true;
233
	help_opened = true;
234
	DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff);
234
	DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff);
235
	WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION);
235
	WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION);
236
	WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20);
236
	WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20);
237
}
237
}
238
 
238
 
239
/* ------------------------------------------- */
239
/* ------------------------------------------- */
240
 
240
 
241
 
241
 
242
void OpenFile(dword f_path) 
242
void OpenFile(dword f_path) 
243
{
243
{
244
	int tmp;
244
	int tmp;
245
	if (ESBYTE[f_path]) {
245
	if (ESBYTE[f_path]) {
246
		strcpy(#param, f_path);
246
		strcpy(#param, f_path);
247
		io.read(#param);
247
		io.read(#param);
248
		strcpy(#title, #param);
248
		strcpy(#title, #param);
249
		strcat(#title, " - Text Reader"); 
249
		strcat(#title, " - Text Reader"); 
250
	}
250
	}
251
	else {
251
	else {
252
		if (list.count) return;
252
		if (list.count) return;
253
		io.buffer_data = INTRO_TEXT;
253
		io.buffer_data = INTRO_TEXT;
254
		strcpy(#title, "Text Reader"); 
254
		strcpy(#title, "Text Reader"); 
255
	}
255
	}
256
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
256
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
257
	list.KeyHome();
257
	list.KeyHome();
258
	list.ClearList();
258
	list.ClearList();
259
}
259
}
260
 
260
 
261
void draw_window()
261
void draw_window()
262
{
262
{
263
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
263
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
264
	GetProcessInfo(#Form, SelfInfo);
264
	GetProcessInfo(#Form, SelfInfo);
265
	if (Form.status_window>2) return;
265
	if (Form.status_window>2) return;
266
 
266
 
267
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
267
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
268
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
268
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
269
	
269
	
270
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
270
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
271
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
271
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
272
	
272
	
273
	DrawToolbarButton(OPEN_FILE,       8);
273
	DrawToolbarButton(OPEN_FILE,       8);
274
	DrawToolbarButton(MAGNIFY_PLUS,    42);
274
	DrawToolbarButton(MAGNIFY_PLUS,    42);
275
	DrawToolbarButton(MAGNIFY_MINUS,   67);
275
	DrawToolbarButton(MAGNIFY_MINUS,   67);
276
	DrawToolbarButton(CHANGE_ENCODING, 101);
276
	DrawToolbarButton(CHANGE_ENCODING, 101);
277
	DrawToolbarButton(RUN_EDIT,        135);
277
	DrawToolbarButton(RUN_EDIT,        135);
278
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
278
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
279
	
279
	
280
	if ((Form.cwidth-scroll.size_x-1 == list.w) && 
280
	if ((Form.cwidth-scroll.size_x-1 == list.w) && 
281
		(Form.cheight-TOOLBAR_H == list.h) && 
281
		(Form.cheight-TOOLBAR_H == list.h) && 
282
		(list.count) 
282
		(list.count) 
283
	)
283
	)
284
	{
284
	{
285
		DrawPage(); 
285
		DrawPage(); 
286
	} else {
286
	} else {
287
		PreparePage();
287
		PreparePage();
288
	}
288
	}
289
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
289
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
290
}
290
}
291
 
291
 
292
void DrawPage()
292
void DrawPage()
293
{
293
{
294
	_PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + kfont.raw);
294
	kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w);
295
	DrawScroller();
295
	DrawScroller();
296
}
296
}