Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6043 leency 1
#define MEMSIZE 4096*30
2
 
3
#include "../lib/font.h"
4
#include "../lib/io.h"
5
#include "../lib/gui.h"
6
#include "../lib/list_box.h"
7
#include "../lib/menu.h"
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/obj/http.h"
13
#include "../lib/patterns/libimg_load_skin.h"
14
#include "../lib/patterns/simple_open_dialog.h"
15
#include "../lib/patterns/history.h"
16
 
17
#include "../browser/http_downloader.h"
18
#include "parse_address.h"
19
 
20
char default_dir[] = "/rd/1";
21
od_filter filter2 = {0,0};
22
 
23
char accept_language[]= "Accept-Language: ru\n";
24
 
25
#define TOOLBAR_H 36
26
#define TOOLBAR_ICON_WIDTH  26
27
#define TOOLBAR_ICON_HEIGHT 24
28
 
29
#define DEFAULT_EDITOR "/sys/tinypad"
30
#define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt"
31
 
32
//ATTENTION: each page must have '\0' character at the end of the file
33
char buidin_page_home[] = FROM "buidin_pages\\home.htm";
34
char buidin_page_about[] = FROM "buidin_pages\\about.htm";
35
char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
36
 
37
#define UML 4096*2
38
 
39
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};
40
llist list;
41
 
42
proc_info Form;
43
char title[4196];
44
 
45
enum {
46
	OPEN_FILE,
47
	MAGNIFY_MINUS,
48
	MAGNIFY_PLUS,
49
	CHANGE_ENCODING,
50
	RUN_EDIT,
51
	SHOW_INFO,
52
	GO_BACK,
53
	GO_FORWARD,
54
};
55
 
56
char address[UML]="http://";
57
int	mouse_address_box;
58
edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,#mouse_address_box,2,19,19};
59
 
60
#include "ini.h"
61
#include "gui.h"
62
#include "prepare_page.h"
63
 
64
void InitDlls()
65
{
66
	load_dll(boxlib,    #box_lib_init,   0);
67
	load_dll(libHTTP,   #http_lib_init,  1);
68
	load_dll(libio,     #libio_init,     1);
69
	load_dll(libimg,    #libimg_init,    1);
70
	//load_dll(libini,    #lib_init,       1);
71
	load_dll(iconv_lib, #iconv_open,     0);
72
	load_dll(Proc_lib,  #OpenDialog_init,0);
73
}
74
 
75
 
76
void main()
77
{
78
	InitDlls();
79
	OpenDialog_init stdcall (#o_dialog);
80
	label.init(DEFAULT_FONT);
81
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
82
	LoadIniSettings();
83
	list.no_selection = true;
84
	SetEventMask(10000000000000000000000001100111b);
85
	loop()
86
	{
87
		switch(WaitEvent())
88
		{
89
			case evMouse:
90
				HandleMouseEvent();
91
				break;
92
			case evKey:
93
				HandleKeyEvent();
94
				break;
95
			case evButton:
96
				HandleButtonEvent();
97
				break;
98
			case evReDraw:
99
				if (menu.list.cur_y) {
100
					encoding = menu.list.cur_y - 10;
101
					debugln("evReDraw: charset changed");
102
					EventOpenAddress(history.current());
103
				}
104
				draw_window();
105
		}
106
	}
107
}
108
 
109
 
110
void HandleButtonEvent()
111
{
112
	byte btn = GetButtonID();
113
	if (btn==1) {
114
		SaveIniSettings();
115
		ExitProcess();
116
	}
117
	switch(btn-10)
118
	{
119
		case GO_BACK:
120
			EventGoBack();
121
			break;
122
		case GO_FORWARD:
123
			EventGoForward();
124
			break;
125
		case OPEN_FILE:
126
			EventOpenDialog();
127
			break;
128
		case MAGNIFY_PLUS:
129
			EventMagnifyPlus();
130
			break;
131
		case MAGNIFY_MINUS:
132
			EventMagnifyMinus();
133
			break;
134
		case CHANGE_ENCODING:
135
			EventChangeEncoding();
136
			break;
137
		case RUN_EDIT:
138
			EventRunEdit();
139
			break;
140
		case SHOW_INFO:
141
			EventShowInfo();
142
			break;
143
	}
144
}
145
 
146
 
147
void HandleKeyEvent()
148
{
149
	GetKeys();
150
	switch (key_scancode)
151
	{
152
		case 059:
153
			EventShowInfo();
154
			return;
155
		case SCAN_CODE_ENTER:
156
			EventOpenAddress(#address);
157
			return;
158
		case SCAN_CODE_BS:
159
			if (! address_box.flags & 0b10) {
160
				EventGoBack();
161
				return;
162
			}
163
	}
164
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
165
		switch (key_scancode)
166
		{
167
			case 024: //O
168
				EventOpenDialog();
169
				break;
170
			case SCAN_CODE_UP:
171
				EventMagnifyPlus();
172
				break;
173
			case SCAN_CODE_DOWN:
174
				EventMagnifyMinus();
175
				break;
176
			case 018: //E
177
				EventRunEdit();
178
				break;
179
			case 035: //H
180
				EventShowHistory();
181
				break;
182
			case SCAN_CODE_TAB:
183
				EventChangeEncoding();
184
				break;
185
		}
186
		return;
187
	}
188
	if (list.ProcessKey(key_scancode)) {
189
		DrawPage();
190
		return;
191
	}
192
	if (key_ascii != 0x0d)
193
	&& (key_ascii != ASCII_KEY_PGDN)
194
	&& (key_ascii != ASCII_KEY_PGUP) {
195
		EAX = key_ascii << 8;
196
		edit_box_key stdcall(#address_box);
197
	}
198
}
199
 
200
 
201
void HandleMouseEvent()
202
{
203
	edit_box_mouse stdcall (#address_box);
204
	mouse.get();
205
	list.wheel_size = 7;
206
	if (list.MouseScroll(mouse.vert)) {
207
		DrawPage();
208
		return;
209
	}
210
	scrollbar_v_mouse (#scroll);
211
	if (list.first != scroll.position) {
212
		list.first = scroll.position;
213
		DrawPage();
214
	}
215
}
216
 
217
 
218
/* ----------------------------------------------------- */
219
 
220
void EventOpenDialog()
221
{
222
	OpenDialog_start stdcall (#o_dialog);
223
	if (o_dialog.status) EventOpenAddress(#openfile_path);
224
}
225
 
226
void EventOpenAddress(dword _new_address)
227
{
228
char temp[UML];
229
	if (!ESBYTE[_new_address]) return;
230
	debugln("====================================");
231
	debug("address: ");
232
	debugln(_new_address);
233
	strlcpy(#address, _new_address, UML);
234
	strlwr(#address);
235
	DrawAddressBox();
236
 
237
	/*
238
	There could be several possible types of addresses:
239
	- build in page
240
	- local file
241
	- url
242
	So we need to detect what incoming address is
243
	and then halndle it in the propper way.
244
	*/
245
 
246
	io.buffer_data = 0;
247
 
248
	// - build in page
249
	if (!strncmp(#address,"aelia:",6)) {
250
		debugln("this is buildin page");
251
		if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
252
		if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
253
		if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
254
	}
255
	// - local file
256
	else if (check_is_the_adress_local(#address)==true) {
257
		debugln("this is local address");
258
		io.read(#address);
259
	}
260
	// - url
261
	else {
262
		debugln("this is url");
263
		if (strncmp(#address,"http://",7)!=0) {
264
			strcpy(#temp, "http://");
265
			strlcpy(#temp, #address, UML);
266
			strlcpy(#address, #temp, UML);
267
			DrawAddressBox();
268
		}
269
		if (!downloader.Start(#address)) {
270
			downloader.Stop();
271
		} else {
272
			while (downloader.state!=STATE_COMPLETED)
273
			{
274
				downloader.MonitorProgress();
275
				if (downloader.data_full_size>0)
276
					DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*downloader.data_downloaded_size/downloader.data_full_size);
277
				else
278
					DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
279
			}
280
			io.buffer_data = downloader.bufpointer;
281
		}
282
	}
283
 
284
	if (!io.buffer_data) {
285
		debugln("page not found");
286
		io.buffer_data = #buidin_page_not_found;
287
	}
288
 
289
	history.add(#address);
290
 
291
	/*
292
	Great! So we have the page in our buffer.
293
	We don't know is it a plain text or html.
294
	So we need to parse it and draw.
295
	*/
296
 
297
	list.KeyHome();
298
	list.ClearList();
299
	PreparePage();
300
}
301
 
302
void EventMagnifyPlus()
303
{
304
	label.size.pt++;
305
	if(!label.changeSIZE())
306
		label.size.pt--;
307
	else
308
		PreparePage();
309
}
310
 
311
void EventMagnifyMinus()
312
{
313
	label.size.pt--;
314
	if(!label.changeSIZE())
315
		label.size.pt++;
316
	else
317
		PreparePage();
318
}
319
 
320
void EventRunEdit()
321
{
322
	if (check_is_the_adress_local(history.current())==true) {
323
		io.run(DEFAULT_EDITOR, history.current());
324
	}
325
	else {
326
		//io.write(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); // <--- doesn't work, smth odd, need to check
327
		WriteFile(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH);
328
		io.run(DEFAULT_EDITOR, DEFAULT_PREVIEW_PATH);
329
	}
330
}
331
 
332
void EventChangeEncoding()
333
{
334
	menu.selected = encoding + 1;
335
	menu.show(Form.left+Form.cwidth-97,Form.top+TOOLBAR_H+skin_height-6, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
336
}
337
 
338
void EventShowInfo() {
339
	EventOpenAddress("aelia:about");
340
}
341
 
342
void EventShowHistory()
343
{
344
	EventOpenAddress("aelia:history");
345
}
346
 
347
void EventGoBack()
348
{
349
	if (history.back()) EventOpenAddress(history.current());
350
}
351
 
352
void EventGoForward()
353
{
354
	if (history.forward()) EventOpenAddress(history.current());
355
}
356
 
357
/* ------------------------------------------- */
358
 
359
 
360
void draw_window()
361
{
362
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
363
	GetProcessInfo(#Form, SelfInfo);
364
	if (Form.status_window>2) return;
365
 
366
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
367
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
368
 
369
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
370
	DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
371
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
372
 
373
	DrawToolbarButton(GO_BACK,         8);
374
	DrawToolbarButton(GO_FORWARD,      33);
375
	DrawToolbarButton(OPEN_FILE,       68);
376
	DrawToolbarButton(MAGNIFY_PLUS,    Form.cwidth - 161);
377
	DrawToolbarButton(MAGNIFY_MINUS,   Form.cwidth - 136);
378
	DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 102);
379
	DrawToolbarButton(RUN_EDIT,        Form.cwidth - 68);
380
	DrawToolbarButton(SHOW_INFO,       Form.cwidth - 34);
381
 
382
	DrawAddressBox();
383
 
384
	if ((Form.cwidth-scroll.size_x-1 == list.w) &&
385
		(Form.cheight-TOOLBAR_H == list.h) &&
386
		(list.count)
387
	)
388
	{
389
		DrawPage();
390
	}
391
	else
392
	{
393
		if (!label.raw) {                           //this code need to be run
394
			if (param) EventOpenAddress(#param);    //only once at browser sturtup
395
			else EventOpenAddress("aelia:home");
396
		}
397
		else PreparePage();
398
	}
399
 
400
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
401
}
402
 
403
void DrawPage()
404
{
405
	list.CheckDoesValuesOkey();
406
	if (list.count) _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw);
407
	DrawScroller();
408
}
409
 
410
void DrawAddressBox()
411
{
412
	address_box.left = 97;
413
	address_box.top = 11;
414
	address_box.width = Form.cwidth - address_box.left - 172;
415
	DrawRectangle(address_box.left-4, address_box.top-5, address_box.width+6, 23, 0x8C8C8C);
416
	DrawWideRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 21, 4, address_box.color);
417
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address);
418
	address_box.offset = 0;
419
	edit_box_draw stdcall(#address_box);
420
}