Subversion Repositories Kolibri OS

Rev

Rev 5962 | 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."
22
#define VERSION "Text Reader v1.03"
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.no_bg_copy = true;
79
	font.color      = 0;
80
	font.bg_color   = 0xFFFFFF;
81
 
82
	font.load(DEFAULT_FONT);
83
 
84
	if (!font.data) {
85
		io.run("/sys/@notify","'Error: Font is not loaded.' -E");
86
		ExitProcess();
87
	}
88
 
5819 leency 89
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
5923 leency 90
 
5819 leency 91
	LoadIniSettings();
5923 leency 92
 
5819 leency 93
	OpenFile(#param);
94
	list.no_selection = true;
95
	SetEventMask(10000000000000000000000001100111b);
96
	loop()
97
	{
5923 leency 98
		switch(WaitEvent())
99
		{
100
			case evMouse:
101
				HandleMouseEvent();
5819 leency 102
				break;
5923 leency 103
			case evKey:
104
				HandleKeyEvent();
105
				break;
106
			case evButton:
107
				HandleButtonEvent();
108
				break;
109
			case evReDraw:
110
				if (action_buf) {
111
					OpenFile(#param);
112
					PreparePage();
113
					action_buf = false;
114
				};
115
				draw_window();
116
		}
5819 leency 117
	}
118
}
119
 
5980 leency 120
 
121
void HandleButtonEvent()
5819 leency 122
{
5923 leency 123
 
5980 leency 124
	byte btn = GetButtonID();
125
	if (btn==1) {
126
		SaveIniSettings();
127
		ExitProcess();
128
	}
129
	btn-=10;
130
	switch(btn)
5923 leency 131
	{
5980 leency 132
		case OPEN_FILE:
133
			EventOpenFile();
134
			break;
135
		case MAGNIFY_PLUS:
136
			EventMagnifyPlus();
137
			break;
138
		case MAGNIFY_MINUS:
139
			EventMagnifyMinus();
140
			break;
141
		case CHANGE_ENCODING:
142
			EventChangeEncoding();
143
			break;
144
		case RUN_EDIT:
145
			EventRunEdit();
146
			break;
147
		case SHOW_INFO:
148
			EventShowInfo();
149
			break;
5923 leency 150
	}
5819 leency 151
}
152
 
153
 
5980 leency 154
void HandleKeyEvent()
5819 leency 155
{
5980 leency 156
	if (help_opened) {
157
		help_opened = false;
158
		DrawPage();
159
		return;
160
	}
161
	GetKeys();
162
	if (key_scancode==059) {
163
		EventShowInfo();
164
		return;
165
	}
166
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
167
		switch (key_scancode)
168
		{
169
			case 024:
170
				EventOpenFile();
171
				break;
172
			case SCAN_CODE_UP:
173
				EventMagnifyPlus();
174
				break;
175
			case SCAN_CODE_DOWN:
176
				EventMagnifyMinus();
177
				break;
178
			case 018:
179
				EventRunEdit();
180
				break;
181
			case SCAN_CODE_TAB:
182
				EventChangeEncoding();
183
				break;
5819 leency 184
		}
5980 leency 185
		return;
5819 leency 186
	}
5980 leency 187
	if (list.ProcessKey(key_scancode))
188
		DrawPage();
189
}
5819 leency 190
 
191
 
5980 leency 192
void HandleMouseEvent()
193
{
194
	mouse.get();
195
	list.wheel_size = 7;
196
	if (list.MouseScroll(mouse.vert)) {
197
		DrawPage();
198
		return;
5819 leency 199
	}
5980 leency 200
	scrollbar_v_mouse (#scroll);
201
	if (list.first != scroll.position) {
202
		list.first = scroll.position;
203
		DrawPage();
204
	}
5819 leency 205
}
206
 
5980 leency 207
 
208
/* ----------------------------------------------------- */
209
 
210
void EventOpenFile()
5819 leency 211
{
5980 leency 212
	OpenDialog_start stdcall (#o_dialog);
213
	OpenFile(#openfile_path);
214
	PreparePage();
5819 leency 215
}
216
 
5980 leency 217
void EventMagnifyPlus()
5819 leency 218
{
5980 leency 219
	font.size.text++;
220
	if(!font.changeSIZE())
221
		font.size.text--;
222
	else
223
		PreparePage();
5819 leency 224
}
225
 
5980 leency 226
void EventMagnifyMinus()
227
{
228
	font.size.text--;
229
	if(!font.changeSIZE())
230
		font.size.text++;
231
	else
232
		PreparePage();
233
}
234
 
235
void EventRunEdit()
236
{
237
	io.run(DEFAULT_EDITOR, #param);
238
}
239
 
240
void EventChangeEncoding()
241
{
242
	CreateThread(#menu_rmb,#stak+4092);
243
}
244
 
245
void EventShowInfo() {
246
	help_opened = true;
247
	DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff);
248
	WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION);
249
	WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20);
250
}
251
 
252
/* ------------------------------------------- */
253
 
254
 
5819 leency 255
void OpenFile(dword f_path)
256
{
257
	int tmp;
258
	if (ESBYTE[f_path]) {
259
		strcpy(#param, f_path);
260
		io.read(#param);
261
		strcpy(#title, #param);
262
		strcat(#title, " - Text Reader");
263
	}
264
	else {
265
		if (list.count) return;
5923 leency 266
		io.buffer_data = INTRO_TEXT;
5819 leency 267
		strcpy(#title, "Text Reader");
268
	}
269
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
270
	list.KeyHome();
271
	list.ClearList();
272
}
273
 
5980 leency 274
void draw_window()
275
{
276
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
277
	GetProcessInfo(#Form, SelfInfo);
278
	if (Form.status_window>2) return;
279
 
280
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
281
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
282
 
283
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
284
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
285
 
286
	DrawToolbarButton(OPEN_FILE,       8);
287
	DrawToolbarButton(MAGNIFY_PLUS,    42);
288
	DrawToolbarButton(MAGNIFY_MINUS,   67);
289
	DrawToolbarButton(CHANGE_ENCODING, 101);
290
	DrawToolbarButton(RUN_EDIT,        135);
291
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
292
 
293
	if ((Form.cwidth-scroll.size_x-1 == list.w) &&
294
		(Form.cheight-TOOLBAR_H == list.h) &&
295
		(list.count)
296
	)
297
	{
298
		DrawPage();
299
	} else {
300
		PreparePage();
301
	}
302
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
5923 leency 303
}
5980 leency 304
 
305
void DrawPage()
306
{
307
	_PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + font.buffer);
308
	DrawScroller();
309
}