Subversion Repositories Kolibri OS

Rev

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