Subversion Repositories Kolibri OS

Rev

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