Subversion Repositories Kolibri OS

Rev

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