Subversion Repositories Kolibri OS

Rev

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