Subversion Repositories Kolibri OS

Rev

Rev 5980 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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