Subversion Repositories Kolibri OS

Rev

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