Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7286 leency 1
#define MEMSIZE 4096*100
6043 leency 2
 
7450 leency 3
#include "../lib/gui.h"
6805 leency 4
#include "../lib/kfont.h"
6043 leency 5
#include "../lib/io.h"
7450 leency 6
#include "../lib/cursor.h"
7231 leency 7
 
6043 leency 8
#include "../lib/obj/box_lib.h"
9
#include "../lib/obj/libini.h"
10
#include "../lib/obj/iconv.h"
7231 leency 11
#include "../lib/obj/libimg.h"
6043 leency 12
#include "../lib/obj/proc_lib.h"
13
#include "../lib/obj/http.h"
7231 leency 14
 
6043 leency 15
#include "../lib/patterns/simple_open_dialog.h"
16
#include "../lib/patterns/history.h"
6058 leency 17
#include "../lib/patterns/http_downloader.h"
6366 leency 18
#include "../browser/download_manager.h"
6043 leency 19
 
7293 leency 20
llist list;
21
 
22
#include "link.h"
23
#include "canvas.h"
24
#include "favicon.h"
25
 
6043 leency 26
char default_dir[] = "/rd/1";
7285 leency 27
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
6043 leency 28
 
29
char accept_language[]= "Accept-Language: ru\n";
30
 
31
#define TOOLBAR_H 36
32
#define TOOLBAR_ICON_WIDTH  26
33
#define TOOLBAR_ICON_HEIGHT 24
7293 leency 34
#define STATUSBAR_H 15
6043 leency 35
 
36
#define DEFAULT_EDITOR "/sys/tinypad"
37
#define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt"
38
 
39
//ATTENTION: each page must have '\0' character at the end of the file
40
char buidin_page_home[] = FROM "buidin_pages\\home.htm";
41
char buidin_page_about[] = FROM "buidin_pages\\about.htm";
42
char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
43
 
44
#define UML 4096*2
45
 
46
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};
47
 
48
proc_info Form;
49
char title[4196];
50
 
51
enum {
52
	OPEN_FILE,
53
	MAGNIFY_MINUS,
54
	MAGNIFY_PLUS,
55
	CHANGE_ENCODING,
56
	RUN_EDIT,
57
	GO_BACK,
58
	GO_FORWARD,
6058 leency 59
	SANDWICH
6043 leency 60
};
61
 
7293 leency 62
char address[UML];
7291 leency 63
edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,NULL,2,19,19};
6043 leency 64
 
7293 leency 65
bool debug_mode=false;
66
 
6043 leency 67
#include "ini.h"
68
#include "gui.h"
69
#include "prepare_page.h"
7285 leency 70
//#include "special.h"
6043 leency 71
 
6366 leency 72
#define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nDownloader\nAbout"
6058 leency 73
 
6043 leency 74
void InitDlls()
75
{
76
	load_dll(boxlib,    #box_lib_init,   0);
77
	load_dll(libHTTP,   #http_lib_init,  1);
78
	load_dll(libio,     #libio_init,     1);
79
	load_dll(libimg,    #libimg_init,    1);
80
	//load_dll(libini,    #lib_init,       1);
81
	load_dll(iconv_lib, #iconv_open,     0);
82
	load_dll(Proc_lib,  #OpenDialog_init,0);
83
}
84
 
85
 
86
void main()
6058 leency 87
{
6043 leency 88
	InitDlls();
89
	OpenDialog_init stdcall (#o_dialog);
7286 leency 90
	LoadIniSettings();
6806 leency 91
	kfont.init(DEFAULT_FONT);
6043 leency 92
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
93
	list.no_selection = true;
7293 leency 94
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
6043 leency 95
	loop()
96
	{
97
		switch(WaitEvent())
98
		{
99
			case evMouse:
100
				HandleMouseEvent();
101
				break;
102
			case evKey:
103
				HandleKeyEvent();
104
				break;
105
			case evButton:
106
				HandleButtonEvent();
107
				break;
7293 leency 108
			case evNetwork:
109
				HandleNetworkEvent();
110
				break;
6043 leency 111
			case evReDraw:
6053 leency 112
				draw_window();
7450 leency 113
				if (menu.cur_y>=10) && (menu.cur_y<20) {
114
					encoding = menu.cur_y - 10;
6058 leency 115
					EventPageRefresh();
7450 leency 116
					menu.cur_y = 0;
6043 leency 117
				}
7450 leency 118
				if (menu.cur_y>=20) {
119
					menu.cur_y-=20;
120
					if (menu.cur_y==0) EventPageRefresh();
121
					if (menu.cur_y==1) EventRunEdit();
122
					if (menu.cur_y==2) EventShowHistory();
123
					if (menu.cur_y==3) EventShowDownloader();
124
					if (menu.cur_y==4) EventShowInfo();
125
					menu.cur_y = 0;
6058 leency 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();
7293 leency 172
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
173
		switch (key_scancode)
174
		{
175
			case SCAN_CODE_UP:
176
				EventMagnifyPlus();
177
				return;
178
			case SCAN_CODE_DOWN:
179
				EventMagnifyMinus();
180
				return;
181
			case SCAN_CODE_KEY_O:
182
				EventOpenDialog();
183
				return;
184
			case SCAN_CODE_KEY_E:
185
				EventRunEdit();
186
				return;
187
			case SCAN_CODE_KEY_H:
188
				EventShowHistory();
189
				return;
190
			case SCAN_CODE_TAB:
191
				EventChangeEncoding();
192
				return;
193
		}
194
	}
6043 leency 195
	switch (key_scancode)
196
	{
7293 leency 197
		case SCAN_CODE_F1:
6043 leency 198
			EventShowInfo();
199
			return;
7293 leency 200
		case SCAN_CODE_F12:
201
			EventChangeDebugMode();
202
			return;
6043 leency 203
		case SCAN_CODE_ENTER:
204
			EventOpenAddress(#address);
205
			return;
206
		case SCAN_CODE_BS:
7506 leency 207
			if (! address_box.flags & ed_focus) {
6043 leency 208
				EventGoBack();
209
				return;
210
			}
211
	}
7506 leency 212
	if (list.ProcessKey(key_scancode)) && (! address_box.flags & ed_focus) {
6043 leency 213
		DrawPage();
214
		return;
215
	}
7293 leency 216
	if (key_ascii != ASCII_KEY_ENTER)
6043 leency 217
	&& (key_ascii != ASCII_KEY_PGDN)
218
	&& (key_ascii != ASCII_KEY_PGUP) {
6641 leency 219
		EAX = key_editbox;
6043 leency 220
		edit_box_key stdcall(#address_box);
221
	}
222
}
223
 
224
 
225
void HandleMouseEvent()
226
{
227
	edit_box_mouse stdcall (#address_box);
228
	mouse.get();
229
	list.wheel_size = 7;
7293 leency 230
 
231
	if (link.hover(mouse.x, mouse.y)) {
232
		if (-1 == link.active) {
233
			DrawStatusBar( " " ); //just clean status bar
7291 leency 234
		}
235
		else {
7293 leency 236
			DrawStatusBar( link.get_active_url() );
7291 leency 237
		}
238
	}
7293 leency 239
 
240
	if (mouse.key&MOUSE_LEFT) && (mouse.up) {
241
		if (-1 != link.active) EventOpenAddress( link.get_active_url() );
242
	}
243
 
6043 leency 244
	if (list.MouseScroll(mouse.vert)) {
245
		DrawPage();
246
		return;
247
	}
7293 leency 248
 
6043 leency 249
	scrollbar_v_mouse (#scroll);
250
	if (list.first != scroll.position) {
251
		list.first = scroll.position;
252
		DrawPage();
253
	}
254
}
255
 
7293 leency 256
void HandleNetworkEvent()
257
{
258
	char favicon_address[UML];
6043 leency 259
 
7293 leency 260
	if (downloader.state == STATE_IN_PROGRESS) {
261
		downloader.MonitorProgress();
262
 
263
		if (downloader.httpd.content_length>0)
264
			DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*
265
				downloader.httpd.content_received/downloader.httpd.content_length);
266
		else
267
			DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
268
	}
269
 
270
	if (downloader.state == STATE_COMPLETED)
271
	{
272
		if (!strncmp(downloader.url,"http://gate.aspero.pro/",22)) {
273
			strcpy(#address,downloader.url + 29);
274
		}
275
		else {
276
			strcpy(#address,downloader.url);
277
		}
278
		downloader.Stop();
279
		DrawAddressBox();
280
		io.buffer_data = downloader.bufpointer;
281
		/*
282
		get_absolute_url(#favicon_address, #address, "/favicon.ico");
283
		favicon.get(#favicon_address);
284
		*/
285
		PostOpenPageActions();
286
	}
287
}
288
 
289
 
6043 leency 290
/* ----------------------------------------------------- */
291
 
292
void EventOpenDialog()
293
{
294
	OpenDialog_start stdcall (#o_dialog);
295
	if (o_dialog.status) EventOpenAddress(#openfile_path);
296
}
297
 
298
void EventOpenAddress(dword _new_address)
299
{
300
char temp[UML];
7293 leency 301
char getUrl[UML];
6043 leency 302
	if (!ESBYTE[_new_address]) return;
303
	debugln("====================================");
7293 leency 304
	debug("address: ");
6043 leency 305
	debugln(_new_address);
306
	strlcpy(#address, _new_address, UML);
307
	strlwr(#address);
308
	DrawAddressBox();
309
 
310
	/*
311
	There could be several possible types of addresses:
312
	- build in page
313
	- local file
314
	- url
315
	So we need to detect what incoming address is
316
	and then halndle it in the propper way.
317
	*/
318
 
319
	io.buffer_data = 0;
6152 leency 320
	favicon.get(NULL);
6043 leency 321
 
322
	// - build in page
323
	if (!strncmp(#address,"aelia:",6)) {
324
		debugln("this is buildin page");
325
		if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
326
		if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
327
		if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
7293 leency 328
		PostOpenPageActions();
6043 leency 329
	}
330
	// - local file
331
	else if (check_is_the_adress_local(#address)==true) {
332
		debugln("this is local address");
333
		io.read(#address);
7293 leency 334
		PostOpenPageActions();
6043 leency 335
	}
336
	// - url
337
	else {
338
		debugln("this is url");
7293 leency 339
		if (!strncmp(#address,"https://",8)) {
340
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #address);
341
		}
342
		else if (!strncmp(#address,"http://",7)) {
343
			strlcpy(#getUrl, #address, UML);
344
		}
345
		else {
6043 leency 346
			strcpy(#temp, "http://");
347
			strlcpy(#temp, #address, UML);
348
			strlcpy(#address, #temp, UML);
349
			DrawAddressBox();
7293 leency 350
			strlcpy(#getUrl, #address, UML);
6043 leency 351
		}
7293 leency 352
		downloader.Start(#getUrl);
6043 leency 353
	}
7293 leency 354
}
6043 leency 355
 
7293 leency 356
void PostOpenPageActions()
357
{
6043 leency 358
	if (!io.buffer_data) {
359
		debugln("page not found");
360
		io.buffer_data = #buidin_page_not_found;
361
	}
362
 
363
	history.add(#address);
6152 leency 364
	favicon.draw(address_box.left-18, address_box.top-1);
6043 leency 365
 
366
	/*
367
	Great! So we have the page in our buffer.
368
	We don't know is it a plain text or html.
369
	So we need to parse it and draw.
370
	*/
371
 
372
	list.KeyHome();
373
	PreparePage();
374
}
375
 
376
void EventMagnifyPlus()
377
{
6806 leency 378
	kfont.size.pt++;
379
	if(!kfont.changeSIZE())
380
		kfont.size.pt--;
6043 leency 381
	else
382
		PreparePage();
383
}
384
 
385
void EventMagnifyMinus()
386
{
6806 leency 387
	kfont.size.pt--;
388
	if(!kfont.changeSIZE())
389
		kfont.size.pt++;
6043 leency 390
	else
391
		PreparePage();
392
}
393
 
394
void EventRunEdit()
395
{
396
	if (check_is_the_adress_local(history.current())==true) {
397
		io.run(DEFAULT_EDITOR, history.current());
398
	}
399
	else {
400
		//io.write(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); // <--- doesn't work, smth odd, need to check
7227 leency 401
		CreateFile(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH);
6043 leency 402
		io.run(DEFAULT_EDITOR, DEFAULT_PREVIEW_PATH);
403
	}
404
}
405
 
406
void EventChangeEncoding()
407
{
408
	menu.selected = encoding + 1;
409
	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);
410
}
411
 
412
void EventShowInfo() {
413
	EventOpenAddress("aelia:about");
414
}
415
 
416
void EventShowHistory()
417
{
418
	EventOpenAddress("aelia:history");
419
}
420
 
421
void EventGoBack()
422
{
423
	if (history.back()) EventOpenAddress(history.current());
424
}
425
 
426
void EventGoForward()
427
{
428
	if (history.forward()) EventOpenAddress(history.current());
429
}
430
 
6058 leency 431
void EventShowSandwichMenu()
432
{
433
	menu.selected = 0;
434
	menu.show(Form.left+Form.cwidth-130,Form.top+TOOLBAR_H+skin_height-10, 130, SANDWICH_MENU, 20);
435
}
436
 
437
void EventPageRefresh()
438
{
439
	EventOpenAddress(history.current());
440
}
441
 
6366 leency 442
void EventShowDownloader()
443
{
444
	if (!downloader_opened) {
445
		downloader_edit = NULL;
446
		CreateThread(#Downloader,#downloader_stak+4092);
447
	}
448
}
449
 
7293 leency 450
void EventChangeDebugMode()
451
{
452
	debug_mode ^= 1;
453
	if (debug_mode) notify("'Debug mode ON'-I");
454
	else notify("'Debug mode OFF'-I");
455
	return;
456
}
457
 
6043 leency 458
/* ------------------------------------------- */
459
 
460
 
461
void draw_window()
462
{
6746 leency 463
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
6043 leency 464
	GetProcessInfo(#Form, SelfInfo);
465
	if (Form.status_window>2) return;
466
 
467
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
468
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
7293 leency 469
 
470
	system.color.get();
471
 
472
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
473
		Form.cheight-TOOLBAR_H-STATUSBAR_H, kfont.size.pt+4);
6043 leency 474
 
475
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
476
	DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
477
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
478
 
479
	DrawToolbarButton(GO_BACK,         8);
480
	DrawToolbarButton(GO_FORWARD,      33);
481
	DrawToolbarButton(OPEN_FILE,       68);
6058 leency 482
	DrawToolbarButton(MAGNIFY_PLUS,    Form.cwidth - 125);
483
	DrawToolbarButton(MAGNIFY_MINUS,   Form.cwidth - 100);
484
	DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 64);
485
	DrawToolbarButton(SANDWICH,        Form.cwidth - 31);
6043 leency 486
 
487
	DrawAddressBox();
488
 
489
	if ((Form.cwidth-scroll.size_x-1 == list.w) &&
490
		(Form.cheight-TOOLBAR_H == list.h) &&
491
		(list.count)
492
	)
493
	{
494
		DrawPage();
495
	}
496
	else
497
	{
6806 leency 498
		if (!kfont.raw) {                           //this code need to be run
6043 leency 499
			if (param) EventOpenAddress(#param);    //only once at browser sturtup
500
			else EventOpenAddress("aelia:home");
501
		}
502
		else PreparePage();
503
	}
504
 
505
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
7293 leency 506
	DrawStatusBar(NULL);
6043 leency 507
}
508
 
509
void DrawPage()
510
{
511
	list.CheckDoesValuesOkey();
6808 leency 512
	if (list.count) {
513
		kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w);
514
	}
6043 leency 515
	DrawScroller();
516
}
517
 
518
void DrawAddressBox()
519
{
6152 leency 520
	address_box.left = 97+19;
6043 leency 521
	address_box.top = 11;
6058 leency 522
	address_box.width = Form.cwidth - address_box.left - 138;
6152 leency 523
	DrawRectangle(address_box.left-4-19, address_box.top-5, address_box.width+6+19, 23, 0x8C8C8C);
524
	DrawWideRectangle(address_box.left-3-19, address_box.top-3, address_box.width+5+19, 21, 4, address_box.color);
6043 leency 525
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address);
526
	address_box.offset = 0;
527
	edit_box_draw stdcall(#address_box);
6152 leency 528
	favicon.draw(address_box.left-18, address_box.top-1);
529
	DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff);
7285 leency 530
}
531
 
7293 leency 532
PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, NULL, 0};
533
void DrawStatusBar(dword _status_text)
534
{
535
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, system.color.work);
536
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, 0x8C8C8C);
537
 
538
	if (_status_text) {
539
		status_text.start_x = 7;
540
		status_text.start_y = Form.cheight - STATUSBAR_H + 3;
541
		status_text.area_size_x = Form.cwidth - status_text.start_x -3;
542
		status_text.font_color = system.color.work_text;
543
		status_text.text_pointer = _status_text;
544
		PathShow_prepare stdcall(#status_text);
545
		PathShow_draw stdcall(#status_text);
546
	}
547
}