Subversion Repositories Kolibri OS

Rev

Rev 6058 | 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
 
3
#include "../lib/font.h"
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/libimg_load_skin.h"
15
#include "../lib/patterns/simple_open_dialog.h"
16
#include "../lib/patterns/history.h"
6058 leency 17
#include "../lib/patterns/http_downloader.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
 
6043 leency 62
#include "ini.h"
63
#include "gui.h"
6053 leency 64
#include "label.h"
6058 leency 65
#include "link.h"
6043 leency 66
#include "prepare_page.h"
6058 leency 67
//#include "special_symbols.h"
6043 leency 68
 
6058 leency 69
#define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nAbout"
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);
6059 leency 87
	CursorPointer.Load(#CursorFile);
6043 leency 88
	label.init(DEFAULT_FONT);
89
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
90
	LoadIniSettings();
91
	list.no_selection = true;
92
	SetEventMask(10000000000000000000000001100111b);
93
	loop()
94
	{
95
		switch(WaitEvent())
96
		{
97
			case evMouse:
98
				HandleMouseEvent();
99
				break;
100
			case evKey:
101
				HandleKeyEvent();
102
				break;
103
			case evButton:
104
				HandleButtonEvent();
105
				break;
106
			case evReDraw:
6053 leency 107
				draw_window();
6058 leency 108
				if (menu.list.cur_y>=10) && (menu.list.cur_y<20) {
6043 leency 109
					encoding = menu.list.cur_y - 10;
6058 leency 110
					EventPageRefresh();
6053 leency 111
					menu.list.cur_y = 0;
6043 leency 112
				}
6058 leency 113
				if (menu.list.cur_y>=20) {
114
					menu.list.cur_y-=20;
115
					if (menu.list.cur_y==0) EventPageRefresh();
116
					if (menu.list.cur_y==1) EventRunEdit();
117
					if (menu.list.cur_y==2) EventShowHistory();
118
					if (menu.list.cur_y==3) EventShowInfo();
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
		return;
203
	}
204
	if (list.ProcessKey(key_scancode)) {
205
		DrawPage();
206
		return;
207
	}
208
	if (key_ascii != 0x0d)
209
	&& (key_ascii != ASCII_KEY_PGDN)
210
	&& (key_ascii != ASCII_KEY_PGUP) {
211
		EAX = key_ascii << 8;
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;
6058 leency 222
	link.hover();
6043 leency 223
	if (list.MouseScroll(mouse.vert)) {
224
		DrawPage();
225
		return;
226
	}
227
	scrollbar_v_mouse (#scroll);
228
	if (list.first != scroll.position) {
229
		list.first = scroll.position;
230
		DrawPage();
231
	}
232
}
233
 
234
 
235
/* ----------------------------------------------------- */
236
 
237
void EventOpenDialog()
238
{
239
	OpenDialog_start stdcall (#o_dialog);
240
	if (o_dialog.status) EventOpenAddress(#openfile_path);
241
}
242
 
243
void EventOpenAddress(dword _new_address)
244
{
245
char temp[UML];
246
	if (!ESBYTE[_new_address]) return;
247
	debugln("====================================");
248
	debug("address: ");
249
	debugln(_new_address);
250
	strlcpy(#address, _new_address, UML);
251
	strlwr(#address);
252
	DrawAddressBox();
253
 
254
	/*
255
	There could be several possible types of addresses:
256
	- build in page
257
	- local file
258
	- url
259
	So we need to detect what incoming address is
260
	and then halndle it in the propper way.
261
	*/
262
 
263
	io.buffer_data = 0;
264
 
265
	// - build in page
266
	if (!strncmp(#address,"aelia:",6)) {
267
		debugln("this is buildin page");
268
		if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
269
		if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
270
		if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
271
	}
272
	// - local file
273
	else if (check_is_the_adress_local(#address)==true) {
274
		debugln("this is local address");
275
		io.read(#address);
276
	}
277
	// - url
278
	else {
279
		debugln("this is url");
280
		if (strncmp(#address,"http://",7)!=0) {
281
			strcpy(#temp, "http://");
282
			strlcpy(#temp, #address, UML);
283
			strlcpy(#address, #temp, UML);
284
			DrawAddressBox();
285
		}
286
		if (!downloader.Start(#address)) {
287
			downloader.Stop();
6053 leency 288
		} else {
6043 leency 289
			while (downloader.state!=STATE_COMPLETED)
290
			{
291
				downloader.MonitorProgress();
292
				if (downloader.data_full_size>0)
293
					DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*downloader.data_downloaded_size/downloader.data_full_size);
294
				else
295
					DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
296
			}
6058 leency 297
			strcpy(#address,downloader.url);
298
			DrawAddressBox();
6043 leency 299
			io.buffer_data = downloader.bufpointer;
300
		}
301
	}
302
 
303
	if (!io.buffer_data) {
304
		debugln("page not found");
305
		io.buffer_data = #buidin_page_not_found;
306
	}
307
 
308
	history.add(#address);
309
 
310
	/*
311
	Great! So we have the page in our buffer.
312
	We don't know is it a plain text or html.
313
	So we need to parse it and draw.
314
	*/
315
 
316
	list.KeyHome();
317
	list.ClearList();
318
	PreparePage();
319
}
320
 
321
void EventMagnifyPlus()
322
{
323
	label.size.pt++;
324
	if(!label.changeSIZE())
325
		label.size.pt--;
326
	else
327
		PreparePage();
328
}
329
 
330
void EventMagnifyMinus()
331
{
332
	label.size.pt--;
333
	if(!label.changeSIZE())
334
		label.size.pt++;
335
	else
336
		PreparePage();
337
}
338
 
339
void EventRunEdit()
340
{
341
	if (check_is_the_adress_local(history.current())==true) {
342
		io.run(DEFAULT_EDITOR, history.current());
343
	}
344
	else {
345
		//io.write(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); // <--- doesn't work, smth odd, need to check
346
		WriteFile(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH);
347
		io.run(DEFAULT_EDITOR, DEFAULT_PREVIEW_PATH);
348
	}
349
}
350
 
351
void EventChangeEncoding()
352
{
353
	menu.selected = encoding + 1;
354
	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);
355
}
356
 
357
void EventShowInfo() {
358
	EventOpenAddress("aelia:about");
359
}
360
 
361
void EventShowHistory()
362
{
363
	EventOpenAddress("aelia:history");
364
}
365
 
366
void EventGoBack()
367
{
368
	if (history.back()) EventOpenAddress(history.current());
369
}
370
 
371
void EventGoForward()
372
{
373
	if (history.forward()) EventOpenAddress(history.current());
374
}
375
 
6058 leency 376
void EventShowSandwichMenu()
377
{
378
	menu.selected = 0;
379
	menu.show(Form.left+Form.cwidth-130,Form.top+TOOLBAR_H+skin_height-10, 130, SANDWICH_MENU, 20);
380
}
381
 
382
void EventPageRefresh()
383
{
384
	EventOpenAddress(history.current());
385
}
386
 
6043 leency 387
/* ------------------------------------------- */
388
 
389
 
390
void draw_window()
391
{
392
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
393
	GetProcessInfo(#Form, SelfInfo);
394
	if (Form.status_window>2) return;
395
 
396
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
397
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
398
 
399
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
400
	DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
401
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
402
 
403
	DrawToolbarButton(GO_BACK,         8);
404
	DrawToolbarButton(GO_FORWARD,      33);
405
	DrawToolbarButton(OPEN_FILE,       68);
6058 leency 406
	DrawToolbarButton(MAGNIFY_PLUS,    Form.cwidth - 125);
407
	DrawToolbarButton(MAGNIFY_MINUS,   Form.cwidth - 100);
408
	DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 64);
409
	DrawToolbarButton(SANDWICH,        Form.cwidth - 31);
6043 leency 410
 
411
	DrawAddressBox();
412
 
413
	if ((Form.cwidth-scroll.size_x-1 == list.w) &&
414
		(Form.cheight-TOOLBAR_H == list.h) &&
415
		(list.count)
416
	)
417
	{
418
		DrawPage();
419
	}
420
	else
421
	{
422
		if (!label.raw) {                           //this code need to be run
423
			if (param) EventOpenAddress(#param);    //only once at browser sturtup
424
			else EventOpenAddress("aelia:home");
425
		}
426
		else PreparePage();
427
	}
428
 
429
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
430
}
431
 
432
void DrawPage()
433
{
434
	list.CheckDoesValuesOkey();
435
	if (list.count) _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw);
436
	DrawScroller();
437
}
438
 
439
void DrawAddressBox()
440
{
441
	address_box.left = 97;
442
	address_box.top = 11;
6058 leency 443
	address_box.width = Form.cwidth - address_box.left - 138;
6043 leency 444
	DrawRectangle(address_box.left-4, address_box.top-5, address_box.width+6, 23, 0x8C8C8C);
445
	DrawWideRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 21, 4, address_box.color);
446
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address);
447
	address_box.offset = 0;
448
	edit_box_draw stdcall(#address_box);
449
}