Subversion Repositories Kolibri OS

Rev

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

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