Subversion Repositories Kolibri OS

Rev

Rev 7291 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7291 Rev 7293
Line 17... Line 17...
17
#include "../lib/patterns/simple_open_dialog.h"
17
#include "../lib/patterns/simple_open_dialog.h"
18
#include "../lib/patterns/history.h"
18
#include "../lib/patterns/history.h"
19
#include "../lib/patterns/http_downloader.h"
19
#include "../lib/patterns/http_downloader.h"
20
#include "../browser/download_manager.h"
20
#include "../browser/download_manager.h"
Line -... Line 21...
-
 
21
 
-
 
22
llist list;
-
 
23
 
-
 
24
#include "link.h"
-
 
25
#include "canvas.h"
-
 
26
#include "favicon.h"
21
 
27
 
22
char default_dir[] = "/rd/1";
28
char default_dir[] = "/rd/1";
Line 23... Line 29...
23
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
29
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
Line 24... Line 30...
24
 
30
 
25
char accept_language[]= "Accept-Language: ru\n";
31
char accept_language[]= "Accept-Language: ru\n";
26
 
32
 
-
 
33
#define TOOLBAR_H 36
Line 27... Line 34...
27
#define TOOLBAR_H 36
34
#define TOOLBAR_ICON_WIDTH  26
28
#define TOOLBAR_ICON_WIDTH  26
35
#define TOOLBAR_ICON_HEIGHT 24
Line 29... Line 36...
29
#define TOOLBAR_ICON_HEIGHT 24
36
#define STATUSBAR_H 15
Line 37... Line 44...
37
char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
44
char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
Line 38... Line 45...
38
 
45
 
Line 39... Line 46...
39
#define UML 4096*2
46
#define UML 4096*2
40
 
-
 
Line 41... Line 47...
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};
47
 
42
llist list;
48
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};
Line 43... Line 49...
43
 
49
 
Line 53... Line 59...
53
	GO_BACK,
59
	GO_BACK,
54
	GO_FORWARD,
60
	GO_FORWARD,
55
	SANDWICH
61
	SANDWICH
56
};
62
};
Line 57... Line 63...
57
 
63
 
58
char address[UML]="http://";
64
char address[UML];
Line 59... Line 65...
59
edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,NULL,2,19,19};
65
edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,NULL,2,19,19};
-
 
66
 
60
 
67
bool debug_mode=false;
61
#include "favicon.h"
68
 
62
#include "ini.h"
-
 
63
#include "gui.h"
-
 
64
#include "link.h"
69
#include "ini.h"
65
#include "canvas.h"
70
#include "gui.h"
Line 66... Line 71...
66
#include "prepare_page.h"
71
#include "prepare_page.h"
Line 86... Line 91...
86
	OpenDialog_init stdcall (#o_dialog);
91
	OpenDialog_init stdcall (#o_dialog);
87
	LoadIniSettings();
92
	LoadIniSettings();
88
	kfont.init(DEFAULT_FONT);
93
	kfont.init(DEFAULT_FONT);
89
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
94
	Libimg_LoadImage(#skin, abspath("toolbar.png"));
90
	list.no_selection = true;
95
	list.no_selection = true;
91
	SetEventMask(10000000000000000000000001100111b);
96
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
92
	loop()
97
	loop()
93
	{
98
	{
94
		switch(WaitEvent())
99
		switch(WaitEvent())
95
		{
100
		{
96
			case evMouse:
101
			case evMouse:
Line 100... Line 105...
100
				HandleKeyEvent();
105
				HandleKeyEvent();
101
				break;
106
				break;
102
			case evButton:
107
			case evButton:
103
				HandleButtonEvent();
108
				HandleButtonEvent();
104
				break;
109
				break;
-
 
110
			case evNetwork:
-
 
111
				HandleNetworkEvent();
-
 
112
				break;
105
			case evReDraw:
113
			case evReDraw:
106
				draw_window();
114
				draw_window();
107
				if (menu.list.cur_y>=10) && (menu.list.cur_y<20) {
115
				if (menu.list.cur_y>=10) && (menu.list.cur_y<20) {
108
					encoding = menu.list.cur_y - 10;
116
					encoding = menu.list.cur_y - 10;
109
					EventPageRefresh();
117
					EventPageRefresh();
Line 161... Line 169...
161
 
169
 
162
 
170
 
163
void HandleKeyEvent()
171
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
			}
172
{
179
	}
173
	GetKeys();
180
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
174
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
181
		switch (key_scancode)
-
 
182
		{
-
 
183
			case 024: //O
-
 
184
				EventOpenDialog();
175
		switch (key_scancode)
185
				break;
176
		{
186
			case SCAN_CODE_UP:
177
			case SCAN_CODE_UP:
187
				EventMagnifyPlus();
178
				EventMagnifyPlus();
188
				break;
179
				return;
189
			case SCAN_CODE_DOWN:
180
			case SCAN_CODE_DOWN:
190
				EventMagnifyMinus();
181
				EventMagnifyMinus();
-
 
182
				return;
-
 
183
			case SCAN_CODE_KEY_O:
-
 
184
				EventOpenDialog();
191
				break;
185
				return;
192
			case 018: //E
186
			case SCAN_CODE_KEY_E:
193
				EventRunEdit();
187
				EventRunEdit();
194
				break;
188
				return;
195
			case 035: //H
189
			case SCAN_CODE_KEY_H:
196
				EventShowHistory();
190
				EventShowHistory();
197
				break;
191
				return;
198
			case SCAN_CODE_TAB:
192
			case SCAN_CODE_TAB:
-
 
193
				EventChangeEncoding();
-
 
194
				return;
-
 
195
		}
-
 
196
	}
-
 
197
	switch (key_scancode) 
-
 
198
	{
-
 
199
		case SCAN_CODE_F1:
-
 
200
			EventShowInfo();
-
 
201
			return;
-
 
202
		case SCAN_CODE_F12:
-
 
203
			EventChangeDebugMode();
-
 
204
			return;
-
 
205
		case SCAN_CODE_ENTER:
-
 
206
			EventOpenAddress(#address);
-
 
207
			return;
-
 
208
		case SCAN_CODE_BS:
-
 
209
			if (! address_box.flags & 0b10) {
199
				EventChangeEncoding();
210
				EventGoBack();
200
				break;
211
				return;
201
		}
212
			}
202
	}
213
	}
203
	if (list.ProcessKey(key_scancode)) {
214
	if (list.ProcessKey(key_scancode)) && (! address_box.flags & 0b10) {
204
		DrawPage();
215
		DrawPage();
205
		return;
216
		return;
206
	}
217
	}
207
	if (key_ascii != 0x0d)
218
	if (key_ascii != ASCII_KEY_ENTER)
208
	&& (key_ascii != ASCII_KEY_PGDN) 
219
	&& (key_ascii != ASCII_KEY_PGDN) 
209
	&& (key_ascii != ASCII_KEY_PGUP) {
220
	&& (key_ascii != ASCII_KEY_PGUP) {
210
		EAX = key_editbox;
221
		EAX = key_editbox;
Line 216... Line 227...
216
void HandleMouseEvent()
227
void HandleMouseEvent()
217
{
228
{
218
	edit_box_mouse stdcall (#address_box);
229
	edit_box_mouse stdcall (#address_box);
219
	mouse.get();
230
	mouse.get();
220
	list.wheel_size = 7;
231
	list.wheel_size = 7;
-
 
232
 
221
	if (link.hover()) {
233
	if (link.hover(mouse.x, mouse.y)) {
222
		if (link.active == -1) {
234
		if (-1 == link.active) {
223
			debugln("unhovered");
235
			DrawStatusBar( " " ); //just clean status bar	
224
		}
236
		}
225
		else {
237
		else {
226
			debugln(link.text.get(link.active));
-
 
227
			debugln(link.url.get(link.active));			
238
			DrawStatusBar( link.get_active_url() );
228
		}
239
		}
229
	}
240
	}
-
 
241
 
-
 
242
	if (mouse.key&MOUSE_LEFT) && (mouse.up) {
-
 
243
		if (-1 != link.active) EventOpenAddress( link.get_active_url() );
-
 
244
	}
-
 
245
 
230
	if (list.MouseScroll(mouse.vert)) {
246
	if (list.MouseScroll(mouse.vert)) {
231
		DrawPage(); 
247
		DrawPage(); 
232
		return; 
248
		return; 
233
	}
249
	}
-
 
250
 
234
	scrollbar_v_mouse (#scroll);
251
	scrollbar_v_mouse (#scroll);
235
	if (list.first != scroll.position) {
252
	if (list.first != scroll.position) {
236
		list.first = scroll.position;
253
		list.first = scroll.position;
237
		DrawPage(); 
254
		DrawPage(); 
238
	}
255
	}
239
}
256
}
Line -... Line 257...
-
 
257
 
-
 
258
void HandleNetworkEvent()
-
 
259
{
-
 
260
	char favicon_address[UML];
-
 
261
 
-
 
262
	if (downloader.state == STATE_IN_PROGRESS) {
-
 
263
		downloader.MonitorProgress();
-
 
264
 
-
 
265
		if (downloader.httpd.content_length>0)
-
 
266
			DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*
-
 
267
				downloader.httpd.content_received/downloader.httpd.content_length); 
-
 
268
		else
-
 
269
			DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);		
-
 
270
	} 
-
 
271
	
-
 
272
	if (downloader.state == STATE_COMPLETED) 
-
 
273
	{
-
 
274
		if (!strncmp(downloader.url,"http://gate.aspero.pro/",22)) {
-
 
275
			strcpy(#address,downloader.url + 29);
-
 
276
		}
-
 
277
		else {
-
 
278
			strcpy(#address,downloader.url);
-
 
279
		}
-
 
280
		downloader.Stop();
-
 
281
		DrawAddressBox();
-
 
282
		io.buffer_data = downloader.bufpointer;
-
 
283
		/*
-
 
284
		get_absolute_url(#favicon_address, #address, "/favicon.ico");
-
 
285
		favicon.get(#favicon_address);
-
 
286
		*/
-
 
287
		PostOpenPageActions();
-
 
288
	}
-
 
289
}
Line 240... Line 290...
240
 
290
 
Line 241... Line 291...
241
 
291
 
242
/* ----------------------------------------------------- */
292
/* ----------------------------------------------------- */
Line 248... Line 298...
248
}
298
}
Line 249... Line 299...
249
 
299
 
250
void EventOpenAddress(dword _new_address)
300
void EventOpenAddress(dword _new_address)
251
{
301
{
252
char temp[UML];
302
char temp[UML];
253
char favicon_address[UML];
303
char getUrl[UML];
254
	if (!ESBYTE[_new_address]) return;
304
	if (!ESBYTE[_new_address]) return;
255
	debugln("====================================");
305
	debugln("====================================");
256
	debug("address: ");
306
	debug("address: "); 
257
	debugln(_new_address);
307
	debugln(_new_address);
Line 275... Line 325...
275
	if (!strncmp(#address,"aelia:",6)) {
325
	if (!strncmp(#address,"aelia:",6)) {
276
		debugln("this is buildin page");
326
		debugln("this is buildin page");
277
		if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
327
		if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
278
		if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
328
		if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
279
		if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
329
		if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
-
 
330
		PostOpenPageActions();
280
	}
331
	}
281
	// - local file
332
	// - local file
282
	else if (check_is_the_adress_local(#address)==true) {
333
	else if (check_is_the_adress_local(#address)==true) {
283
		debugln("this is local address");
334
		debugln("this is local address");
284
		io.read(#address);
335
		io.read(#address);
-
 
336
		PostOpenPageActions();
285
	}
337
	}
286
	// - url
338
	// - url
287
	else {
339
	else {
288
		debugln("this is url");
340
		debugln("this is url");
289
		if (strncmp(#address,"http://",7)!=0) {
341
		if (!strncmp(#address,"https://",8)) {
-
 
342
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #address);
-
 
343
		}
-
 
344
		else if (!strncmp(#address,"http://",7)) {
-
 
345
			strlcpy(#getUrl, #address, UML);
-
 
346
		}
-
 
347
		else {
290
			strcpy(#temp, "http://");
348
			strcpy(#temp, "http://");
291
			strlcpy(#temp, #address, UML);
349
			strlcpy(#temp, #address, UML);
292
			strlcpy(#address, #temp, UML);
350
			strlcpy(#address, #temp, UML);
293
			DrawAddressBox();
351
			DrawAddressBox();
-
 
352
			strlcpy(#getUrl, #address, UML);
294
		}
353
		}
295
		if (!downloader.Start(#address)) {
-
 
296
			downloader.Stop();
354
		downloader.Start(#getUrl);
297
		} else {
-
 
298
			while (downloader.state!=STATE_COMPLETED)
-
 
299
			{ 
-
 
300
				downloader.MonitorProgress(); 
-
 
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); 
-
 
304
				else
-
 
305
					DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
-
 
306
			}
-
 
307
			strcpy(#address,downloader.url);
-
 
308
			DrawAddressBox();
-
 
309
			io.buffer_data = downloader.bufpointer;
-
 
310
			get_absolute_url(#favicon_address, #address, "/favicon.ico");
-
 
311
			favicon.get(#favicon_address);
-
 
312
		}
355
	}
313
	}
356
}
Line -... Line 357...
-
 
357
 
-
 
358
void PostOpenPageActions()
314
 
359
{
315
	if (!io.buffer_data) {
360
	if (!io.buffer_data) {
316
		debugln("page not found");
361
		debugln("page not found");
317
		io.buffer_data = #buidin_page_not_found;
362
		io.buffer_data = #buidin_page_not_found;
Line 325... Line 370...
325
	We don't know is it a plain text or html.
370
	We don't know is it a plain text or html.
326
	So we need to parse it and draw.
371
	So we need to parse it and draw.
327
	*/
372
	*/
Line 328... Line 373...
328
 
373
 
329
	list.KeyHome();
-
 
330
	list.ClearList();
374
	list.KeyHome();
331
	PreparePage();
375
	PreparePage();
Line 332... Line 376...
332
}
376
}
333
 
377
 
Line 403... Line 447...
403
		downloader_edit = NULL;
447
		downloader_edit = NULL;
404
		CreateThread(#Downloader,#downloader_stak+4092);
448
		CreateThread(#Downloader,#downloader_stak+4092);
405
	}
449
	}
406
}
450
}
Line -... Line 451...
-
 
451
 
-
 
452
void EventChangeDebugMode()
-
 
453
{
-
 
454
	debug_mode ^= 1;
-
 
455
	if (debug_mode) notify("'Debug mode ON'-I");
-
 
456
	else notify("'Debug mode OFF'-I");
-
 
457
	return;
-
 
458
}
407
 
459
 
Line 408... Line 460...
408
/* ------------------------------------------- */
460
/* ------------------------------------------- */
409
 
461
 
Line 415... Line 467...
415
	if (Form.status_window>2) return;
467
	if (Form.status_window>2) return;
Line 416... Line 468...
416
 
468
 
417
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
469
	if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
Line -... Line 470...
-
 
470
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
-
 
471
 
-
 
472
	system.color.get();
-
 
473
 
-
 
474
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, 
418
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
475
		Form.cheight-TOOLBAR_H-STATUSBAR_H, kfont.size.pt+4);
419
	
476
	
420
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
477
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
Line 421... Line 478...
421
	DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
478
	DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
Line 446... Line 503...
446
		}
503
		}
447
		else PreparePage();
504
		else PreparePage();
448
	}
505
	}
Line 449... Line 506...
449
 
506
 
-
 
507
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
450
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
508
	DrawStatusBar(NULL);
Line 451... Line 509...
451
}
509
}
452
 
510
 
453
void DrawPage()
511
void DrawPage()
Line 471... Line 529...
471
	edit_box_draw stdcall(#address_box);
529
	edit_box_draw stdcall(#address_box);
472
	favicon.draw(address_box.left-18, address_box.top-1);
530
	favicon.draw(address_box.left-18, address_box.top-1);
473
	DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff);
531
	DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff);
474
}
532
}
Line -... Line 533...
-
 
533
 
-
 
534
PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, NULL, 0};
-
 
535
void DrawStatusBar(dword _status_text)
-
 
536
{
-
 
537
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, system.color.work);
-
 
538
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, 0x8C8C8C);
-
 
539
 
-
 
540
	if (_status_text) {
-
 
541
		status_text.start_x = 7;
-
 
542
		status_text.start_y = Form.cheight - STATUSBAR_H + 3;
-
 
543
		status_text.area_size_x = Form.cwidth - status_text.start_x -3;
-
 
544
		status_text.font_color = system.color.work_text;
-
 
545
		status_text.text_pointer = _status_text;
-
 
546
		PathShow_prepare stdcall(#status_text);
-
 
547
		PathShow_draw stdcall(#status_text);
-
 
548
	}