Subversion Repositories Kolibri OS

Rev

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

Rev 7758 Rev 7759
Line 1... Line -...
1
//HTML Viewer in C--
-
 
2
//Copyright 2007-2020 by Veliant & Leency
1
//Copyright 2007-2020 by Veliant & Leency
3
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
2
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
Line 4... Line 3...
4
 
3
 
5
#ifndef AUTOBUILD
4
#ifndef AUTOBUILD
Line 26... Line 25...
26
 
25
 
27
//useful patterns
26
//useful patterns
28
#include "..\lib\patterns\history.h"
27
#include "..\lib\patterns\history.h"
29
#include "..\lib\patterns\http_downloader.h"
28
#include "..\lib\patterns\http_downloader.h"
-
 
29
#include "..\lib\patterns\simple_open_dialog.h"
Line 30... Line 30...
30
#include "..\lib\patterns\simple_open_dialog.h"
30
#include "..\lib\patterns\toolbar_button.h"
31
 
31
 
32
#include "show_src.h"
32
#include "show_src.h"
33
#include "download_manager.h"
33
#include "download_manager.h"
34
_history history;
34
_history history;
35
#include "history.h"
35
#include "history.h"
Line -... Line 36...
-
 
36
bool debug_mode = false;
-
 
37
#include "..\TWB\TWB.c" //HTML Parser, a core component
36
bool debug_mode = false;
38
 
Line 37... Line 39...
37
#include "..\TWB\TWB.c"
39
TWebBrowser WB1;
38
 
40
 
39
char version[]="WebView 2.0 Gold";
41
char version[]="WebView 2.1";
40
 
42
 
Line 86... Line 88...
86
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
88
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
87
dword STATUSBAR_H = 15;
89
dword STATUSBAR_H = 15;
Line 88... Line 90...
88
 
90
 
Line 89... Line 91...
89
int action_buf;
91
int action_buf;
Line 90... Line 92...
90
 
92
 
Line 91... Line 93...
91
_http http = {0, 0, 0, 0, 0, 0, 0};
93
_http http = 0;
92
 
94
 
93
bool source_mode = false;
95
bool source_mode = false;
Line 94... Line 96...
94
 
96
 
-
 
97
progress_bar wv_progress_bar;
95
progress_bar wv_progress_bar;
98
char stak[4096];
96
char stak[4096];
99
proc_info Form;
97
proc_info Form;
100
 
98
 
101
enum { 
-
 
102
	ENCODINGS=900,
99
enum { 
103
	BACK_BUTTON=1000, 
100
	BACK_BUTTON=1000, 
104
	FORWARD_BUTTON, 
101
	FORWARD_BUTTON, 
105
	REFRESH_BUTTON, 
102
	REFRESH_BUTTON, 
106
	GOTOURL_BUTTON, 
103
	GOTOURL_BUTTON, 
107
	CHANGE_ENCODING,
Line 157... Line 161...
157
	Libimg_LoadImage(#skin, "/sys/toolbar.png");
161
	Libimg_LoadImage(#skin, "/sys/toolbar.png");
158
	HandleParam();
162
	HandleParam();
159
	skin.h = 26;
163
	skin.h = 26;
160
	WB1.list.SetFont(8, 14, 10011000b);
164
	WB1.list.SetFont(8, 14, 10011000b);
161
	WB1.list.no_selection = true;
165
	WB1.list.no_selection = true;
-
 
166
	WB1.custom_encoding = -1;
162
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
167
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
163
	loop() switch(WaitEvent())
168
	loop() switch(WaitEvent())
164
	{
169
	{
165
		case evMouse:
170
		case evMouse:
166
			edit_box_mouse stdcall (#address_box);
171
			edit_box_mouse stdcall (#address_box);
Line 235... Line 240...
235
			}
240
			}
236
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
241
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
237
				GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
242
				GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
238
			GetProcessInfo(#Form, SelfInfo);
243
			GetProcessInfo(#Form, SelfInfo);
239
			system.color.get();
244
			system.color.get();
240
			if (Form.status_window>2) { DrawTitle(#header); break; }
245
			if (Form.status_window>2) break;
241
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
246
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
242
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
247
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
243
			draw_window();
248
			draw_window();
244
			break;
249
			break;
Line 271... Line 276...
271
	}
276
	}
272
}
277
}
Line 273... Line 278...
273
 
278
 
274
void SetElementSizes()
279
void SetElementSizes()
275
{
-
 
276
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
280
{
277
	address_box.width = Form.cwidth - address_box.left - 52 - 16;
281
	address_box.width = Form.cwidth - address_box.left - 52 - 16;
278
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, 
282
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, 
279
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
283
		Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H);
280
	WB1.list.wheel_size = 7 * basic_line_h;
284
	WB1.list.wheel_size = 7 * BASIC_LINE_H;
281
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
285
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
282
	WB1.list.visible = WB1.list.h;
286
	WB1.list.visible = WB1.list.h;
Line 283... Line -...
283
}
-
 
284
 
287
}
285
 
288
 
286
 
289
 
287
void draw_window()
290
void draw_window()
Line 294... Line 297...
294
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark);
297
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark);
295
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
298
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
296
	DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
299
	DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
297
	DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
300
	DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
Line 298... Line 301...
298
 
301
 
299
	DrawTopPanelButton(BACK_BUTTON, PADDING-1, 30);
302
	DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30);
300
	DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, 31);
303
	DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31);
301
	DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, -1);
304
	DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1);
Line 302... Line -...
302
	for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
-
 
303
 
305
	for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
Line 304... Line 306...
304
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, system.color.work);
306
 
305
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
307
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
Line 306... Line 308...
306
 
308
 
307
	DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, 
309
	DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, 
308
		WB1.list.h-1, scroll_wv.bckg_col);
310
		WB1.list.h-1, scroll_wv.bckg_col);
309
 
311
 
310
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
312
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
311
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
-
 
312
		if (!strncmp(history.current(),"http",4)) {
313
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
313
			//nihuya ne izyachnoe reshenie, no pust' poka butet tak
314
		if (!strncmp(history.current(),"http",4)) {
314
			i=source_mode;
-
 
315
			debugval("source_mode", source_mode);
315
			//nihuya ne izyashnoe reshenie, no pust' poka butet tak
316
			LoadInternalPage(#loading_text, sizeof(loading_text));
316
			i=source_mode;
317
			source_mode=i;
317
			LoadInternalPage(#loading_text, sizeof(loading_text));
318
			debugval("source_mode", source_mode);
318
			source_mode=i;
319
		}
319
		}
320
		OpenPage(history.current());
320
		OpenPage(history.current());
321
	} else { 
321
	} else { 
-
 
322
		WB1.DrawPage(); 
-
 
323
		DrawOmnibox(); 
-
 
324
	}
-
 
325
	DrawProgress();
-
 
326
	DrawStatusBar(NULL);
-
 
327
}
-
 
328
 
-
 
329
void EventChangeEncodingAndLoadPage(int _new_encoding)
-
 
330
{
-
 
331
	dword newbuf, newsize;
-
 
332
	WB1.custom_encoding = _new_encoding;
-
 
333
	newsize = strlen(WB1.o_bufpointer);
322
		WB1.DrawPage(); 
334
	newbuf = malloc(newsize);
Line 323... Line 335...
323
		DrawOmnibox(); 
335
	memmov(newbuf, WB1.o_bufpointer, newsize);
324
	}
336
	LoadInternalPage(newbuf, newsize);
325
	DrawProgress();
337
	free(newbuf);
326
}
338
}
-
 
339
 
-
 
340
 
-
 
341
void ProcessEvent(dword id__)
327
 
342
{
328
 
343
	switch (id__)
329
void ProcessEvent(dword id__)
344
	{
330
{
345
		case ENCODINGS...ENCODINGS+6:
331
	switch (id__)
346
			EventChangeEncodingAndLoadPage(id__-ENCODINGS);
Line 354... Line 369...
354
				draw_window();
369
				draw_window();
355
			} else {
370
			} else {
356
				OpenPage(history.current());
371
				OpenPage(history.current());
357
			}
372
			}
358
			return;
373
			return;
-
 
374
		case CHANGE_ENCODING:
-
 
375
			EventShowEncodingsList(Form.cwidth - 150, status_text.start_y-117);
-
 
376
			return;
359
		case SANDWICH_BUTTON:
377
		case SANDWICH_BUTTON:
360
			EventShowMainMenu(Form.cwidth - 215, TOOLBAR_H-6);
378
			EventShowMainMenu(Form.cwidth - 215, TOOLBAR_H-6);
361
			return;
379
			return;
362
		case VIEW_SOURCE:
380
		case VIEW_SOURCE:
363
			EventViewSource();
381
			EventViewSource();
364
			break;
382
			break;
365
		case EDIT_SOURCE:
383
		case EDIT_SOURCE:
366
			if (check_is_the_adress_local(history.current())) {
384
			if (check_is_the_adress_local(history.current())) {
367
				RunProgram("/rd/1/tinypad", history.current());
385
				RunProgram("/rd/1/tinypad", history.current());
368
			} else {
386
			} else {
369
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
387
				CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
370
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
388
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
371
			}
389
			}
372
			return;
390
			return;
373
		case VIEW_HISTORY:
391
		case VIEW_HISTORY:
374
			OpenPage(URL_SERVICE_HISTORY);
392
			OpenPage(URL_SERVICE_HISTORY);
Line 596... Line 614...
596
 
614
 
597
void LoadInternalPage(dword _bufdata, _in_bufsize){
615
void LoadInternalPage(dword _bufdata, _in_bufsize){
598
	if (!_bufdata) || (!_in_bufsize) {
616
	if (!_bufdata) || (!_in_bufsize) {
599
		LoadInternalPage(#page_not_found, sizeof(page_not_found));
617
		LoadInternalPage(#page_not_found, sizeof(page_not_found));
600
	} else {
-
 
601
		bufsize = _in_bufsize;
-
 
602
		if (bufpointer!=_bufdata) free(bufpointer);
-
 
603
		bufpointer = malloc(bufsize);
-
 
604
		memmov(bufpointer, _bufdata, bufsize);
618
	} else {
605
		WB1.list.first = 0; //scroll page to the top
619
		WB1.list.first = 0; //scroll page to the top
606
		DrawOmnibox();
620
		DrawOmnibox();
607
		if(!strrchr(#editURL, '#')) {
621
		if(!strrchr(#editURL, '#')) {
608
			strcat(#editURL, #anchors.current);
622
			strcat(#editURL, #anchors.current);
609
			DrawOmnibox();
623
			DrawOmnibox();
610
		}
624
		}
-
 
625
		WB1.ParseHtml(_bufdata, _in_bufsize);
611
		WB1.ParseHtml();
626
		DrawStatusBar(NULL);
612
		if (source_mode) {
627
		if (source_mode) {
613
			source_mode = false;
628
			source_mode = false;
614
			ShowSource(bufpointer, bufsize);
629
			ShowSource(WB1.bufpointer, _in_bufsize);
615
		} else {
630
		} else {
616
			WB1.DrawPage();			
631
			WB1.DrawPage();			
617
		}
632
		}
618
	}
633
	}
Line 636... Line 651...
636
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
651
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
637
}
652
}
Line 638... Line 653...
638
 
653
 
639
void EventShowPageMenu(dword _left, _top)
654
void EventShowPageMenu(dword _left, _top)
-
 
655
{
640
{
656
	menu.selected = 0;
641
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
657
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
Line -... Line 658...
-
 
658
}
-
 
659
 
-
 
660
void EventShowEncodingsList(dword _left, _top)
-
 
661
{
-
 
662
	menu.selected = WB1.cur_encoding + 1;
-
 
663
	menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 100, 
-
 
664
		"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", ENCODINGS);
642
}
665
}
643
 
666
 
-
 
667
void EventShowMainMenu(dword _left, _top)
644
void EventShowMainMenu(dword _left, _top)
668
{
645
{
669
	menu.selected = 0;
Line 646... Line 670...
646
	menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 140, #main_menu, OPEN_FILE);
670
	menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 140, #main_menu, OPEN_FILE);
647
}
671
}
-
 
672
 
648
 
673
void EventShowLinkMenu(dword _left, _top)
649
void EventShowLinkMenu(dword _left, _top)
674
{
Line 650... Line 675...
650
{
675
	menu.selected = 0;
651
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
676
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
Line 686... Line 711...
686
	RunProgram(#program_path, #source_view_param);
711
	RunProgram(#program_path, #source_view_param);
687
}
712
}
Line 688... Line 713...
688
 
713
 
689
void DrawStatusBar(dword _status_text)
714
void DrawStatusBar(dword _status_text)
-
 
715
{
690
{
716
	status_text.font_color = system.color.work_text;
691
	status_text.start_x = 10;
717
	status_text.start_x = 10;
692
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
718
	status_text.start_y = Form.cheight - STATUSBAR_H + 4;
693
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
719
	status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
-
 
720
	//DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
-
 
721
	DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
694
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
722
	if (_status_text) {
695
	status_text.text_pointer = _status_text;
723
		status_text.text_pointer = _status_text;
696
	PathShow_prepare stdcall(#status_text);
724
		PathShow_prepare stdcall(#status_text);
697
	PathShow_draw stdcall(#status_text);
725
		PathShow_draw stdcall(#status_text);		
698
}
-
 
699
 
-
 
700
 
-
 
701
void DrawOvalBorder(dword x,y,w,h, light,dark,right,dots)
-
 
702
{
-
 
703
	DrawBar(x+1,    y,     w, 1,   light);
-
 
704
	DrawBar(x+1,    y+h+1, w, 1,   dark);
-
 
705
	DrawBar(x,      y+1,   1, h-1, light);
-
 
706
	DrawBar(x+w+1,  y+2,   1, h-2, right);
-
 
707
 
-
 
708
	PutPixel(x,     y,     dots);
-
 
709
	PutPixel(x+w+1, y+h+1, dots);
-
 
710
	PutPixel(x,     y+h+1, dots);
-
 
711
	PutPixel(x+w+1, y,     dots);
-
 
712
	
-
 
713
	PutPixel(x,     y+h, dark);
-
 
714
	PutPixel(x+w+1, y+1, light);
-
 
715
	PutPixel(x+w+1, y+h, dark);	
-
 
716
}
-
 
717
 
-
 
718
libimg_image top_icons;
-
 
719
libimg_image left_icons;
-
 
720
 
726
	}
721
void DrawTopPanelButton(dword _button_id, _x, signed int _icon_n)
-
 
722
{
-
 
723
	static dword semi_white=0, bg_col, bg_col_light, bg_col_dark, bg_dark;
-
 
724
	if (!semi_white) {
727
	DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
725
		bg_col = system.color.work;
-
 
726
		if (GrayScaleImage(#bg_col,1,1)<65) bg_dark=true; else bg_dark=false;
-
 
727
		Libimg_LoadImage(#top_icons, "/sys/icons16.png");
-
 
728
		Libimg_LoadImage(#left_icons, "/sys/icons16.png");
-
 
729
 
728
		60, 12, CHANGE_ENCODING);
730
		semi_white = MixColors(system.color.work, 0xFFFfff, bg_dark*90 + 96);
729
	WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
731
		bg_col_dark = MixColors(system.color.work, system.color.work_graph, 90);
-
 
732
		bg_col_light = MixColors(semi_white, 0xFFFfff, bg_dark*90 + 10);
-
 
733
 
-
 
734
		Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffFFFfff, semi_white);
-
 
735
		Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffCACBD6, MixColors(semi_white, 0, 220));
-
 
736
 
-
 
737
		Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffFFFfff, system.color.work);
-
 
738
		Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffCACBD6, MixColors(system.color.work, 0, 200));		
-
 
739
	}
-
 
740
 
-
 
741
	DrawWideRectangle(_x+1, PADDING+1, TSZE, TSZE, 5, semi_white);
-
 
742
	DrawOvalBorder(_x, PADDING, TSZE, TSZE, bg_col_light, bg_col_dark, semi_white, system.color.work);
-
 
743
 
-
 
744
	DefineHiddenButton(_x, PADDING, TSZE+1, TSZE+1, _button_id);
-
 
745
	if (_icon_n==-1) {
-
 
746
		DrawBar(_x+6, PADDING+5, 16, 16, semi_white);
-
 
747
	} else {
-
 
748
		img_draw stdcall(top_icons.image, _x+6, PADDING+5, 16, 16, 0, _icon_n*16);
-
 
749
	}
730
		status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
Line 750... Line 731...
750
}
731
}
751
 
732
 
752
void DrawOmnibox()
733
void DrawOmnibox()
Line 753... Line 734...
753
{
734
{
-
 
735
	int skin_x_offset;
754
	int skin_x_offset;
736
	
755
	
737
	DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph, 
756
	DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph, system.color.work_graph, system.color.work_graph, system.color.work_dark);
738
		system.color.work_graph, system.color.work_graph, system.color.work_dark);
Line 757... Line 739...
757
	DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
739
	DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);