Subversion Repositories Kolibri OS

Rev

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