Subversion Repositories Kolibri OS

Rev

Rev 7284 | Rev 7422 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7284 Rev 7293
1
//HTML Viewer in C--
1
//HTML Viewer in C--
2
//Copyright 2007-2017 by Veliant & Leency
2
//Copyright 2007-2017 by Veliant & Leency
3
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
3
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
4
 
4
 
5
#ifndef AUTOBUILD
5
#ifndef AUTOBUILD
6
	#include "lang.h--"
6
	#include "lang.h--"
7
#endif
7
#endif
8
 
8
 
9
//libraries
9
//libraries
10
#define MEMSIZE 4096 * 200
10
#define MEMSIZE 4096 * 200
11
#include "..\lib\gui.h"
11
#include "..\lib\gui.h"
12
#include "..\lib\draw_buf.h"
12
#include "..\lib\draw_buf.h"
13
#include "..\lib\list_box.h"
13
#include "..\lib\list_box.h"
14
#include "..\lib\cursor.h"
14
#include "..\lib\cursor.h"
15
#include "..\lib\collection.h"
15
#include "..\lib\collection.h"
16
#include "..\lib\menu.h"
16
#include "..\lib\menu.h"
17
#include "..\lib\random.h"
17
#include "..\lib\random.h"
18
#include "..\lib\clipboard.h"
18
#include "..\lib\clipboard.h"
19
 
19
 
20
//*.obj libraries
20
//*.obj libraries
21
#include "..\lib\obj\box_lib.h"
21
#include "..\lib\obj\box_lib.h"
22
#include "..\lib\obj\libio.h"
22
#include "..\lib\obj\libio.h"
23
#include "..\lib\obj\libimg.h"
23
#include "..\lib\obj\libimg.h"
24
#include "..\lib\obj\http.h"
24
#include "..\lib\obj\http.h"
25
#include "..\lib\obj\iconv.h"
25
#include "..\lib\obj\iconv.h"
26
//useful patterns
26
//useful patterns
27
#include "..\lib\patterns\history.h"
27
#include "..\lib\patterns\history.h"
28
#include "..\lib\patterns\http_downloader.h"
28
#include "..\lib\patterns\http_downloader.h"
29
 
29
 
30
_http http = {0, 0, 0, 0, 0, 0, 0};
30
_http http = {0, 0, 0, 0, 0, 0, 0};
31
 
31
 
32
char homepage[] = FROM "html\\homepage.htm""\0";
32
char homepage[] = FROM "html\\homepage.htm""\0";
33
 
33
 
34
#ifdef LANG_RUS
34
#ifdef LANG_RUS
35
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.8";
35
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.8";
36
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
36
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
37
?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
37
?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
38
char loading[] = "‡ £à㧪  áâà ­¨æë...
";
38
char loading[] = "‡ £à㧪  áâà ­¨æë...
";
39
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
39
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
40
char accept_language[]= "Accept-Language: ru\n";
40
char accept_language[]= "Accept-Language: ru\n";
41
char rmb_menu[] = 
41
char rmb_menu[] = 
42
"®á¬®âà¥âì ¨á室­¨ª
42
"®á¬®âà¥âì ¨á室­¨ª
43
¥¤ ªâ¨à®¢ âì ¨á室­¨ª
43
¥¤ ªâ¨à®¢ âì ¨á室­¨ª
44
ˆáâ®à¨ï
44
ˆáâ®à¨ï
45
Œ¥­¥¤¦¥à § £à㧮ª";
45
Œ¥­¥¤¦¥à § £à㧮ª";
46
char link_menu[] =
46
char link_menu[] =
47
"Š®¯¨à®¢ âì áá뫪ã
47
"Š®¯¨à®¢ âì áá뫪ã
48
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
48
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
49
#else
49
#else
50
char version[]="Text-based Browser 1.8";
50
char version[]="Text-based Browser 1.8";
51
?define IMAGES_CACHE_CLEARED "Images cache cleared"
51
?define IMAGES_CACHE_CLEARED "Images cache cleared"
52
?define T_LAST_SLIDE "This slide is the last"
52
?define T_LAST_SLIDE "This slide is the last"
53
char loading[] = "Loading...
";
53
char loading[] = "Loading...
";
54
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
54
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
55
char accept_language[]= "Accept-Language: en\n";
55
char accept_language[]= "Accept-Language: en\n";
56
char rmb_menu[] =
56
char rmb_menu[] =
57
"View source
57
"View source
58
Edit source
58
Edit source
59
History
59
History
60
Download Manager";
60
Download Manager";
61
char link_menu[] =
61
char link_menu[] =
62
"Copy link
62
"Copy link
63
Download link contents";
63
Download link contents";
64
#endif
64
#endif
65
 
65
 
66
 
66
 
67
#define URL_SERVICE_HISTORY "WebView://history"
67
#define URL_SERVICE_HISTORY "WebView://history"
68
#define URL_SERVICE_HOME "WebView://home"
68
#define URL_SERVICE_HOME "WebView://home"
69
#define URL_SERVICE_SOURCE "WebView://source:"
69
#define URL_SERVICE_SOURCE "WebView://source:"
70
 
70
 
71
proc_info Form;
71
proc_info Form;
72
 
72
 
73
//char search_path[]="http://nigma.ru/index.php?s=";
73
//char search_path[]="http://nigma.ru/index.php?s=";
74
int redirected = 0;
74
int redirected = 0;
75
 
75
 
76
char stak[4096];
76
char stak[4096];
77
 
77
 
78
int action_buf;
78
int action_buf;
79
 
79
 
80
dword TOOLBAR_H = 40;
80
dword TOOLBAR_H = 40;
81
dword STATUSBAR_H = 15;
81
dword STATUSBAR_H = 15;
82
dword col_bg;
82
dword col_bg;
83
dword panel_color;
83
dword panel_color;
84
dword border_color;
84
dword border_color;
85
 
85
 
86
bool debug_mode = false;
86
bool debug_mode = false;
87
bool old_tag_parser_mode = false;
87
bool old_tag_parser_mode = false;
88
 
88
 
89
progress_bar wv_progress_bar;
89
progress_bar wv_progress_bar;
90
bool souce_mode = false;
90
bool souce_mode = false;
91
bool open_in_a_new_window = false;
91
bool open_in_a_new_window = false;
92
 
92
 
93
enum { 
93
enum { 
94
	BACK_BUTTON=1000, 
94
	BACK_BUTTON=1000, 
95
	FORWARD_BUTTON, 
95
	FORWARD_BUTTON, 
96
	REFRESH_BUTTON, 
96
	REFRESH_BUTTON, 
97
	GOTOURL_BUTTON, 
97
	GOTOURL_BUTTON, 
98
	SANDWICH_BUTTON,
98
	SANDWICH_BUTTON,
99
	VIEW_SOURCE=1100,
99
	VIEW_SOURCE=1100,
100
	EDIT_SOURCE,
100
	EDIT_SOURCE,
101
	VIEW_HISTORY,
101
	VIEW_HISTORY,
102
	//FREE_IMG_CACHE,
102
	//FREE_IMG_CACHE,
103
	DOWNLOAD_MANAGER,
103
	DOWNLOAD_MANAGER,
104
	COPY_LINK_URL=1200,
104
	COPY_LINK_URL=1200,
105
	DOWNLOAD_LINK_CONTENTS,
105
	DOWNLOAD_LINK_CONTENTS,
106
};
106
};
107
 
107
 
108
#include "..\TWB\TWB.c"
108
#include "..\TWB\TWB.c"
109
#include "history.h"
109
#include "history.h"
110
#include "show_src.h"
110
#include "show_src.h"
111
#include "download_manager.h"
111
#include "download_manager.h"
112
 
112
 
113
char editURL[sizeof(URL)];
113
char editURL[sizeof(URL)];
114
int	mouse_twb;
114
int	mouse_twb;
115
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
115
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
116
 
116
 
117
 
117
 
118
void main()
118
void main()
119
{
119
{
120
	load_dll(boxlib, #box_lib_init,0);
120
	load_dll(boxlib, #box_lib_init,0);
121
	load_dll(libio, #libio_init,1);
121
	load_dll(libio, #libio_init,1);
122
	load_dll(libimg, #libimg_init,1);
122
	load_dll(libimg, #libimg_init,1);
123
	load_dll(libHTTP, #http_lib_init,1);
123
	load_dll(libHTTP, #http_lib_init,1);
124
	load_dll(iconv_lib, #iconv_open,0);
124
	load_dll(iconv_lib, #iconv_open,0);
125
	Libimg_LoadImage(#skin, abspath("wv_skin.png"));
125
	Libimg_LoadImage(#skin, abspath("wv_skin.png"));
126
	SetSkinColors();
126
	SetSkinColors();
127
	CreateDir("/tmp0/1/downloads");
127
	CreateDir("/tmp0/1/downloads");
128
	if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
128
	if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
129
	WB1.list.SetFont(8, 14, 10011000b);
129
	WB1.list.SetFont(8, 14, 10011000b);
130
	WB1.list.no_selection = true;
130
	WB1.list.no_selection = true;
131
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
131
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
132
	loop() switch(WaitEvent())
132
	loop() switch(WaitEvent())
133
	{
133
	{
134
		case evMouse:
134
		case evMouse:
135
			edit_box_mouse stdcall (#address_box);
135
			edit_box_mouse stdcall (#address_box);
136
			mouse.get();
136
			mouse.get();
137
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
137
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
138
			&& (bufsize) && (mouse.pkm) && (mouse.up) {
138
			&& (bufsize) && (mouse.pkm) && (mouse.up) {
139
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
139
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
140
				break;
140
				break;
141
			}
141
			}
142
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
142
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
143
			scrollbar_v_mouse (#scroll_wv);
143
			scrollbar_v_mouse (#scroll_wv);
144
			if (WB1.list.first != scroll_wv.position)
144
			if (WB1.list.first != scroll_wv.position)
145
			{
145
			{
146
				WB1.list.first = scroll_wv.position;
146
				WB1.list.first = scroll_wv.position;
147
				WB1.DrawPage();
147
				WB1.DrawPage();
148
				break;
148
				break;
149
			}
149
			}
150
			break;
150
			break;
151
 
151
 
152
		case evButton:
152
		case evButton:
153
			ProcessEvent(GetButtonID());
153
			ProcessEvent(GetButtonID());
154
			break;
154
			break;
155
 
155
 
156
		case evKey:
156
		case evKey:
157
			GetKeys();
157
			GetKeys();
158
			if (address_box.flags & 0b10)  
158
			if (address_box.flags & 0b10)  
159
			{
159
			{
160
				if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
160
				if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
161
					EAX = key_editbox; 
161
					EAX = key_editbox; 
162
					edit_box_key stdcall(#address_box);
162
					edit_box_key stdcall(#address_box);
163
				}
163
				}
164
			}
164
			}
165
			else 
165
			else 
166
			{
166
			{
167
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
167
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
168
				else ProcessEvent(key_scancode);
168
				else ProcessEvent(key_scancode);
169
			}
169
			}
170
			break;
170
			break;
171
 
171
 
172
		case evReDraw:
172
		case evReDraw:
173
			if (menu.list.cur_y) {
173
			if (menu.list.cur_y) {
174
				ProcessEvent(menu.list.cur_y);
174
				ProcessEvent(menu.list.cur_y);
175
				menu.list.cur_y = 0;
175
				menu.list.cur_y = 0;
176
			}
176
			}
177
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
177
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
178
			GetProcessInfo(#Form, SelfInfo);
178
			GetProcessInfo(#Form, SelfInfo);
179
			if (Form.status_window>2) { DrawTitle(#header); break; }
179
			if (Form.status_window>2) { DrawTitle(#header); break; }
180
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
180
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
181
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
181
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
182
			Draw_Window();
182
			Draw_Window();
183
			break;
183
			break;
184
			
184
			
185
		case evNetwork:
185
		case evNetwork:
186
			if (http.transfer > 0) {
186
			if (http.transfer > 0) {
187
				http.receive();
187
				http.receive();
188
				EventUpdateProgressBar();
188
				EventUpdateProgressBar();
189
				if (http.receive_result == 0) {
189
				if (http.receive_result == 0) {
190
					// Handle redirects
190
					// Handle redirects
191
					if (http.status_code >= 300) && (http.status_code < 400)
191
					if (http.status_code >= 300) && (http.status_code < 400)
192
					{
192
					{
193
						redirected++;
193
						redirected++;
194
						if (redirected>5)
194
						if (redirected>5)
195
						{
195
						{
196
							notify("'Too many redirects.' -E");
196
							notify("'Too many redirects.' -E");
197
							StopLoading();
197
							StopLoading();
198
						}
198
						}
199
						else
199
						else
200
						{
200
						{
201
							http.handle_redirect();
201
							http.handle_redirect();
202
							http.free();
202
							http.free();
203
							GetAbsoluteURL(#http.redirect_url);
203
							GetAbsoluteURL(#http.redirect_url);
204
							history.back();
204
							history.back();
205
							strcpy(#editURL, #URL);
205
							strcpy(#editURL, #URL);
206
							DrawEditBoxWebView();
206
							DrawEditBoxWebView();
207
							OpenPage();
207
							OpenPage();
208
						}
208
						}
209
						break;
209
						break;
210
					} 
210
					} 
211
					redirected = 0;
211
					redirected = 0;
212
					// Loading the page is complete, free resources
212
					// Loading the page is complete, free resources
213
					history.add(#URL);
213
					history.add(#URL);
214
					bufpointer = http.content_pointer;
214
					bufpointer = http.content_pointer;
215
					bufsize = http.content_received;
215
					bufsize = http.content_received;
216
					http.free();
216
					http.free();
217
					SetPageDefaults();
217
					SetPageDefaults();
218
					ShowPage();
218
					ShowPage();
219
				}
219
				}
220
			}
220
			}
221
	}
221
	}
222
}
222
}
223
 
223
 
224
void SetElementSizes()
224
void SetElementSizes()
225
{
225
{
226
	address_box.top = TOOLBAR_H/2-10;
226
	address_box.top = TOOLBAR_H/2-10;
227
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
227
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
228
	address_box.width = Form.cwidth - address_box.left - 50;
228
	address_box.width = Form.cwidth - address_box.left - 50;
229
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, 
229
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, 
230
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
230
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
231
	WB1.list.wheel_size = 7 * basic_line_h;
231
	WB1.list.wheel_size = 7 * basic_line_h;
232
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
232
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
233
	WB1.list.visible = WB1.list.h;
233
	WB1.list.visible = WB1.list.h;
234
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
234
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
235
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
235
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
236
		ProcessEvent(REFRESH_BUTTON);
236
		ProcessEvent(REFRESH_BUTTON);
237
	}
237
	}
238
}
238
}
239
 
239
 
240
 
240
 
241
 
241
 
242
void Draw_Window()
242
void Draw_Window()
243
{
243
{
244
	DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
244
	DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
245
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
245
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
246
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
246
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
247
	SetElementSizes();
247
	SetElementSizes();
248
	DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color);
248
	DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color);
249
	DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0);
249
	DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0);
250
	DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0);
250
	DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0);
251
	img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 3, 0);
251
	img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 3, 0);
252
	DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
252
	DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
253
	DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
253
	DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
254
	img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0);
254
	img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0);
255
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
255
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
256
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
256
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
257
	if (!header) 
257
	if (!header) 
258
		OpenPage(); 
258
		OpenPage(); 
259
	else { 
259
	else { 
260
		WB1.DrawPage(); 
260
		WB1.DrawPage(); 
261
		DrawEditBoxWebView(); 
261
		DrawEditBoxWebView(); 
262
	}
262
	}
263
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
263
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
264
	DrawProgress();
264
	DrawProgress();
265
}
265
}
266
 
266
 
267
 
267
 
268
void ProcessEvent(dword id__)
268
void ProcessEvent(dword id__)
269
{
269
{
270
	switch (id__)
270
	switch (id__)
271
	{
271
	{
272
		case 1:
272
		case 1:
273
			ExitProcess();
273
			ExitProcess();
274
			return;
274
			return;
275
		case SCAN_CODE_BS:
275
		case SCAN_CODE_BS:
276
		case BACK_BUTTON:
276
		case BACK_BUTTON:
277
			if (history.back()) {
277
			if (history.back()) {
278
				strcpy(#URL, history.current());
278
				strcpy(#URL, history.current());
279
				OpenPage();
279
				OpenPage();
280
			}
280
			}
281
			return;
281
			return;
282
		case FORWARD_BUTTON:
282
		case FORWARD_BUTTON:
283
			if (history.forward()) {
283
			if (history.forward()) {
284
				strcpy(#URL, history.current());
284
				strcpy(#URL, history.current());
285
				OpenPage();
285
				OpenPage();
286
			}
286
			}
287
			return;
287
			return;
288
		case GOTOURL_BUTTON:
288
		case GOTOURL_BUTTON:
289
		case SCAN_CODE_ENTER:
289
		case SCAN_CODE_ENTER:
290
			if (!editURL[0]) {
290
			if (!editURL[0]) {
291
				strcpy(#URL, URL_SERVICE_HOME);
291
				strcpy(#URL, URL_SERVICE_HOME);
292
			}
292
			}
293
			else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
293
			else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
294
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
294
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
295
			{
295
			{
296
				strcpy(#URL, #editURL);
296
				strcpy(#URL, #editURL);
297
			}
297
			}
298
			else
298
			else
299
			{
299
			{
300
				strlcpy(#URL,"http://",7);
300
				strlcpy(#URL,"http://",7);
301
				strcat(#URL, #editURL);
301
				strcat(#URL, #editURL);
302
			}
302
			}
303
			OpenPage();
303
			OpenPage();
304
			return;
304
			return;
305
		case 063: //F5
305
		case SCAN_CODE_F5:
306
			IF(address_box.flags & 0b10) return;
306
			IF(address_box.flags & 0b10) return;
307
		case REFRESH_BUTTON:
307
		case REFRESH_BUTTON:
308
			if (http.transfer > 0) 
308
			if (http.transfer > 0) 
309
			{
309
			{
310
				StopLoading();
310
				StopLoading();
311
				Draw_Window();
311
				Draw_Window();
312
			}
312
			}
313
			else OpenPage();
313
			else OpenPage();
314
			return;
314
			return;
315
		case SANDWICH_BUTTON:
315
		case SANDWICH_BUTTON:
316
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
316
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
317
			return;
317
			return;
318
		case VIEW_SOURCE:
318
		case VIEW_SOURCE:
319
			WB1.list.first = 0;
319
			WB1.list.first = 0;
320
			ShowSource();
320
			ShowSource();
321
			WB1.LoadInternalPage(bufpointer, bufsize);
321
			WB1.LoadInternalPage(bufpointer, bufsize);
322
			break;
322
			break;
323
		case EDIT_SOURCE:
323
		case EDIT_SOURCE:
324
			if (!strncmp(#URL,"http",4)) 
324
			if (!strncmp(#URL,"http",4)) 
325
			{
325
			{
326
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
326
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
327
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
327
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
328
			}
328
			}
329
			else RunProgram("/rd/1/tinypad", #URL);
329
			else RunProgram("/rd/1/tinypad", #URL);
330
			return;
330
			return;
331
		// case FREE_IMG_CACHE:
331
		// case FREE_IMG_CACHE:
332
		// 	ImgCache.Free();
332
		// 	ImgCache.Free();
333
		// 	notify(IMAGES_CACHE_CLEARED);
333
		// 	notify(IMAGES_CACHE_CLEARED);
334
		// 	WB1.DrawPage();
334
		// 	WB1.DrawPage();
335
		// 	return;
335
		// 	return;
336
		case VIEW_HISTORY:
336
		case VIEW_HISTORY:
337
			strcpy(#URL, URL_SERVICE_HISTORY);
337
			strcpy(#URL, URL_SERVICE_HISTORY);
338
			OpenPage();
338
			OpenPage();
339
			return;
339
			return;
340
		case DOWNLOAD_MANAGER:
340
		case DOWNLOAD_MANAGER:
341
			if (!downloader_opened) {
341
			if (!downloader_opened) {
342
				downloader_edit = NULL;
342
				downloader_edit = NULL;
343
				CreateThread(#Downloader,#downloader_stak+4092);
343
				CreateThread(#Downloader,#downloader_stak+4092);
344
			}
344
			}
345
			return;
345
			return;
346
		case COPY_LINK_URL:
346
		case COPY_LINK_URL:
347
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
347
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
348
			notify("'URL copied to clipboard'O");
348
			notify("'URL copied to clipboard'O");
349
			return;
349
			return;
350
		case DOWNLOAD_LINK_CONTENTS:
350
		case DOWNLOAD_LINK_CONTENTS:
351
			if (!downloader_opened) {
351
			if (!downloader_opened) {
352
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
352
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
353
				CreateThread(#Downloader,#downloader_stak+4092);
353
				CreateThread(#Downloader,#downloader_stak+4092);
354
			}
354
			}
355
			return;
355
			return;
356
		case SCAN_CODE_F12:
356
		case SCAN_CODE_F12:
357
			debug_mode ^= 1;
357
			debug_mode ^= 1;
358
			if (debug_mode) notify("'Debug mode ON'-I");
358
			if (debug_mode) notify("'Debug mode ON'-I");
359
			else notify("'Debug mode OFF'-I");
359
			else notify("'Debug mode OFF'-I");
360
			return;
360
			return;
361
		case SCAN_CODE_F11:
361
		case SCAN_CODE_F11:
362
			old_tag_parser_mode ^= 1;
362
			old_tag_parser_mode ^= 1;
363
			if (old_tag_parser_mode) notify("'Old tag parser ON'-I");
363
			if (old_tag_parser_mode) notify("'Old tag parser ON'-I");
364
			else notify("'Old tag parser OFF'-I");
364
			else notify("'Old tag parser OFF'-I");
365
			return;
365
			return;
366
	}
366
	}
367
}
367
}
368
 
368
 
369
void StopLoading()
369
void StopLoading()
370
{
370
{
371
	if (http.transfer)
371
	if (http.transfer)
372
	{
372
	{
373
		EAX = http.transfer;
373
		EAX = http.transfer;
374
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
374
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
375
		$push	EAX							// save it on the stack
375
		$push	EAX							// save it on the stack
376
		http_free stdcall (http.transfer);	// abort connection
376
		http_free stdcall (http.transfer);	// abort connection
377
		$pop	EAX							
377
		$pop	EAX							
378
		free(EAX);						// free data
378
		free(EAX);						// free data
379
		http.transfer=0;
379
		http.transfer=0;
380
		bufsize = 0;
380
		bufsize = 0;
381
		bufpointer = free(bufpointer);
381
		bufpointer = free(bufpointer);
382
	}
382
	}
383
	wv_progress_bar.value = 0;
383
	wv_progress_bar.value = 0;
384
	DrawEditBoxWebView();
384
	DrawEditBoxWebView();
385
}
385
}
386
 
386
 
387
void SetPageDefaults()
387
void SetPageDefaults()
388
{
388
{
389
	strcpy(#header, #version);
389
	strcpy(#header, #version);
390
	WB1.list.count = WB1.list.first = 0;
390
	WB1.list.count = WB1.list.first = 0;
391
	cur_encoding = CH_NULL;
391
	cur_encoding = CH_NULL;
392
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
392
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
393
}
393
}
394
 
394
 
395
void OpenPage()
395
void OpenPage()
396
{
396
{
397
	char getUrl[sizeof(URL)];
397
	char getUrl[sizeof(URL)];
398
	StopLoading();
398
	StopLoading();
399
	souce_mode = false;
399
	souce_mode = false;
400
	strcpy(#editURL, #URL);
400
	strcpy(#editURL, #URL);
401
	history.add(#URL);
401
	history.add(#URL);
402
	if (!strncmp(#URL,"WebView:",8))
402
	if (!strncmp(#URL,"WebView:",8))
403
	{
403
	{
404
		SetPageDefaults();
404
		SetPageDefaults();
405
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
405
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
406
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
406
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
407
		DrawEditBoxWebView();
407
		DrawEditBoxWebView();
408
		return;
408
		return;
409
	}
409
	}
410
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8)) 
410
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8)) 
411
	{
411
	{
412
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
412
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
413
 
413
 
414
		if (!strncmp(#URL,"http:",5)) {
414
		if (!strncmp(#URL,"http:",5)) {
415
			http.get(#URL);
415
			http.get(#URL);
416
		}
416
		}
417
		if (!strncmp(#URL,"https://",8)) {
417
		if (!strncmp(#URL,"https://",8)) {
418
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
418
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
419
			http.get(#getUrl);
419
			http.get(#getUrl);
420
		}
420
		}
421
		//http.get(#URL);
421
		//http.get(#URL);
422
		if (!http.transfer)
422
		if (!http.transfer)
423
		{
423
		{
424
			StopLoading();
424
			StopLoading();
425
			bufsize = 0;
425
			bufsize = 0;
426
			bufpointer = free(bufpointer);
426
			bufpointer = free(bufpointer);
427
			ShowPage();
427
			ShowPage();
428
			return;
428
			return;
429
		}
429
		}
430
	}
430
	}
431
	else
431
	else
432
	{
432
	{
433
		file_size stdcall (#URL);
433
		file_size stdcall (#URL);
434
		bufsize = EBX;
434
		bufsize = EBX;
435
		if (bufsize)
435
		if (bufsize)
436
		{
436
		{
437
			free(bufpointer);
437
			free(bufpointer);
438
			bufpointer = malloc(bufsize);
438
			bufpointer = malloc(bufsize);
439
			SetPageDefaults();
439
			SetPageDefaults();
440
			ReadFile(0, bufsize, bufpointer, #URL);
440
			ReadFile(0, bufsize, bufpointer, #URL);
441
		}
441
		}
442
		ShowPage();
442
		ShowPage();
443
	}
443
	}
444
}
444
}
445
 
445
 
446
DrawEditBoxWebView()
446
DrawEditBoxWebView()
447
{
447
{
448
	DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
448
	DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
449
	DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
449
	DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
450
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
450
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
451
	address_box.offset = 0;
451
	address_box.offset = 0;
452
	edit_box_draw stdcall(#address_box);
452
	edit_box_draw stdcall(#address_box);
453
	if (http.transfer > 0) EAX = 131; else EAX = 54;
453
	if (http.transfer > 0) EAX = 131; else EAX = 54;
454
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, EAX, 0);
454
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, EAX, 0);
455
}
455
}
456
 
456
 
457
 
457
 
458
void ShowPage()
458
void ShowPage()
459
{
459
{
460
	DrawEditBoxWebView();
460
	DrawEditBoxWebView();
461
	if (!bufsize)
461
	if (!bufsize)
462
	{
462
	{
463
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
463
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
464
		else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
464
		else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
465
	}
465
	}
466
	else
466
	else
467
	{
467
	{
468
		WB1.Prepare();
468
		WB1.Prepare();
469
	}
469
	}
470
}
470
}
471
 
471
 
472
byte UrlExtIs(dword ext)
472
byte UrlExtIs(dword ext)
473
{
473
{
474
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
474
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
475
	return false;
475
	return false;
476
}
476
}
477
 
477
 
478
int SetSkinColors()
478
int SetSkinColors()
479
{
479
{
480
	dword image_data;
480
	dword image_data;
481
	image_data = DSDWORD[skin.image+24];
481
	image_data = DSDWORD[skin.image+24];
482
	col_bg = DSDWORD[image_data];
482
	col_bg = DSDWORD[image_data];
483
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
483
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
484
	border_color = DSDWORD[skin.w*4*7 + image_data];
484
	border_color = DSDWORD[skin.w*4*7 + image_data];
485
	wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
485
	wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
486
	$and col_bg, 0x00ffffff
486
	$and col_bg, 0x00ffffff
487
	$and panel_color, 0x00ffffff
487
	$and panel_color, 0x00ffffff
488
	$and border_color, 0x00ffffff
488
	$and border_color, 0x00ffffff
489
	$and wv_progress_bar.progress_color, 0x00ffffff
489
	$and wv_progress_bar.progress_color, 0x00ffffff
490
}
490
}
491
 
491
 
492
void DrawProgress()
492
void DrawProgress()
493
{
493
{
494
	dword persent;
494
	dword persent;
495
	if (http.transfer == 0) return;
495
	if (http.transfer == 0) return;
496
	if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
496
	if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
497
	DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
497
	DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
498
}
498
}
499
 
499
 
500
 
500
 
501
char anchor[256];
501
char anchor[256];
502
void ClickLink()
502
void ClickLink()
503
{
503
{
504
	if (http.transfer > 0) 
504
	if (http.transfer > 0) 
505
	{
505
	{
506
		StopLoading();
506
		StopLoading();
507
		history.back();
507
		history.back();
508
	}
508
	}
509
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
509
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
510
	//#1
510
	//#1
511
	if (URL[0] == '#')
511
	if (URL[0] == '#')
512
	{
512
	{
513
		if (URL[1] == NULL) {
513
		if (URL[1] == NULL) {
514
			WB1.list.first = 0;
514
			WB1.list.first = 0;
515
			strcpy(#URL, history.current());
515
			strcpy(#URL, history.current());
516
		}
516
		}
517
		else {
517
		else {
518
			strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
518
			strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
519
			strcpy(#URL, history.current());
519
			strcpy(#URL, history.current());
520
		}
520
		}
521
		ShowPage();			
521
		ShowPage();			
522
		return;
522
		return;
523
	}
523
	}
524
	//liner.ru#1
524
	//liner.ru#1
525
	if (strrchr(#URL, '#')!=0)
525
	if (strrchr(#URL, '#')!=0)
526
	{
526
	{
527
		strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
527
		strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
528
		URL[strrchr(#URL, '#')-1] = 0x00;
528
		URL[strrchr(#URL, '#')-1] = 0x00;
529
	}
529
	}
530
 
530
 
531
	if (!strncmp(#URL,"mailto:", 7))
531
	if (!strncmp(#URL,"mailto:", 7))
532
	{
532
	{
533
		notify(#URL);
533
		notify(#URL);
534
		strcpy(#editURL, history.current());
534
		strcpy(#editURL, history.current());
535
		strcpy(#URL, history.current());
535
		strcpy(#URL, history.current());
536
		return;
536
		return;
537
	}
537
	}
538
 
538
 
539
	GetAbsoluteURL(#URL);
539
	GetAbsoluteURL(#URL);
540
 
540
 
541
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
541
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
542
	{
542
	{
543
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
543
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
544
		{	
544
		{	
545
			RunProgram("/sys/@open", #URL);
545
			RunProgram("/sys/@open", #URL);
546
			strcpy(#editURL, history.current());
546
			strcpy(#editURL, history.current());
547
			strcpy(#URL, history.current());
547
			strcpy(#URL, history.current());
548
			return;
548
			return;
549
		}
549
		}
550
	}
550
	}
551
	else	
551
	else	
552
	{
552
	{
553
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) 
553
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) 
554
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
554
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
555
		|| (UrlExtIs(".7z")==true) {
555
		|| (UrlExtIs(".7z")==true) {
556
			if (!downloader_opened) {
556
			if (!downloader_opened) {
557
				strcpy(#downloader_edit, #URL);
557
				strcpy(#downloader_edit, #URL);
558
				CreateThread(#Downloader,#downloader_stak+4092);
558
				CreateThread(#Downloader,#downloader_stak+4092);
559
				strcpy(#editURL, history.current());
559
				strcpy(#editURL, history.current());
560
				strcpy(#URL, history.current());
560
				strcpy(#URL, history.current());
561
			}
561
			}
562
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
562
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
563
			return;
563
			return;
564
		}
564
		}
565
	}
565
	}
566
	if (open_in_a_new_window)
566
	if (open_in_a_new_window)
567
	{
567
	{
568
		RunProgram(#program_path, #URL);
568
		RunProgram(#program_path, #URL);
569
		strcpy(#editURL, history.current());
569
		strcpy(#editURL, history.current());
570
		strcpy(#URL, history.current());
570
		strcpy(#URL, history.current());
571
	}
571
	}
572
	else 
572
	else 
573
	{
573
	{
574
		OpenPage();
574
		OpenPage();
575
	}
575
	}
576
	open_in_a_new_window = false;
576
	open_in_a_new_window = false;
577
}
577
}
578
 
578
 
579
void EventShowPageMenu(dword _left, _top)
579
void EventShowPageMenu(dword _left, _top)
580
{
580
{
581
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
581
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
582
}
582
}
583
 
583
 
584
void EventShowLinkMenu(dword _left, _top)
584
void EventShowLinkMenu(dword _left, _top)
585
{
585
{
586
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
586
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
587
}
587
}
588
 
588
 
589
void EventUpdateProgressBar()
589
void EventUpdateProgressBar()
590
{
590
{
591
	wv_progress_bar.max = http.content_length;
591
	wv_progress_bar.max = http.content_length;
592
	if (wv_progress_bar.value != http.content_received)
592
	if (wv_progress_bar.value != http.content_received)
593
	{
593
	{
594
		wv_progress_bar.value = http.content_received;	
594
		wv_progress_bar.value = http.content_received;	
595
		DrawProgress();
595
		DrawProgress();
596
	}
596
	}
597
}
597
}
598
 
598
 
599
DrawStatusBar(dword _status_text)
599
DrawStatusBar(dword _status_text)
600
{
600
{
601
	status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
601
	status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
602
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
602
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
603
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
603
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
604
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
604
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
605
	status_text.text_pointer = _status_text;
605
	status_text.text_pointer = _status_text;
606
	PathShow_prepare stdcall(#status_text);
606
	PathShow_prepare stdcall(#status_text);
607
	PathShow_draw stdcall(#status_text);
607
	PathShow_draw stdcall(#status_text);
608
}
608
}
609
 
609
 
610
stop:

610
stop: