Subversion Repositories Kolibri OS

Rev

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

Rev 7281 Rev 7282
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.74";
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.74";
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
 
-
 
86
bool debug_mode = false;
-
 
87
bool old_tag_parser_mode = false;
85
 
88
 
86
progress_bar wv_progress_bar;
89
progress_bar wv_progress_bar;
87
bool souce_mode = false;
90
bool souce_mode = false;
88
bool open_in_a_new_window = false;
91
bool open_in_a_new_window = false;
89
 
92
 
90
enum { 
93
enum { 
91
	BACK_BUTTON=1000, 
94
	BACK_BUTTON=1000, 
92
	FORWARD_BUTTON, 
95
	FORWARD_BUTTON, 
93
	REFRESH_BUTTON, 
96
	REFRESH_BUTTON, 
94
	GOTOURL_BUTTON, 
97
	GOTOURL_BUTTON, 
95
	SANDWICH_BUTTON,
98
	SANDWICH_BUTTON,
96
	VIEW_SOURCE=1100,
99
	VIEW_SOURCE=1100,
97
	EDIT_SOURCE,
100
	EDIT_SOURCE,
98
	VIEW_HISTORY,
101
	VIEW_HISTORY,
99
	//FREE_IMG_CACHE,
102
	//FREE_IMG_CACHE,
100
	DOWNLOAD_MANAGER,
103
	DOWNLOAD_MANAGER,
101
	COPY_LINK=1200,
104
	COPY_LINK_URL=1200,
102
	DOWNLOAD_LINK_CONTENTS,
105
	DOWNLOAD_LINK_CONTENTS,
103
};
106
};
104
 
107
 
105
#include "..\TWB\TWB.c"
108
#include "..\TWB\TWB.c"
106
#include "history.h"
109
#include "history.h"
107
#include "show_src.h"
110
#include "show_src.h"
108
#include "download_manager.h"
111
#include "download_manager.h"
109
 
112
 
110
char editURL[sizeof(URL)];
113
char editURL[sizeof(URL)];
111
int	mouse_twb;
114
int	mouse_twb;
112
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};
113
 
116
 
114
 
117
 
115
void main()
118
void main()
116
{
119
{
117
	CursorPointer.Load(#CursorFile);
-
 
118
	load_dll(boxlib, #box_lib_init,0);
120
	load_dll(boxlib, #box_lib_init,0);
119
	load_dll(libio, #libio_init,1);
121
	load_dll(libio, #libio_init,1);
120
	load_dll(libimg, #libimg_init,1);
122
	load_dll(libimg, #libimg_init,1);
121
	load_dll(libHTTP, #http_lib_init,1);
123
	load_dll(libHTTP, #http_lib_init,1);
122
	load_dll(iconv_lib, #iconv_open,0);
124
	load_dll(iconv_lib, #iconv_open,0);
123
	Libimg_LoadImage(#skin, abspath("wv_skin.png"));
125
	Libimg_LoadImage(#skin, abspath("wv_skin.png"));
124
	SetSkinColors();
126
	SetSkinColors();
125
	CreateDir("/tmp0/1/downloads");
127
	CreateDir("/tmp0/1/downloads");
126
	if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
128
	if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
127
	WB1.list.SetFont(8, 14, 10011000b);
129
	WB1.list.SetFont(8, 14, 10011000b);
128
	WB1.list.no_selection = true;
130
	WB1.list.no_selection = true;
129
	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);
130
	loop() switch(WaitEvent())
132
	loop() switch(WaitEvent())
131
	{
133
	{
132
		case evMouse:
134
		case evMouse:
133
			edit_box_mouse stdcall (#address_box);
135
			edit_box_mouse stdcall (#address_box);
134
			mouse.get();
136
			mouse.get();
135
			if (WB1.list.MouseOver(mouse.x, mouse.y))
-
 
136
			{
-
 
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
					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
			}
-
 
144
			scrollbar_v_mouse (#scroll_wv);
143
			scrollbar_v_mouse (#scroll_wv);
145
			if (WB1.list.first != scroll_wv.position)
144
			if (WB1.list.first != scroll_wv.position)
146
			{
145
			{
147
				WB1.list.first = scroll_wv.position;
146
				WB1.list.first = scroll_wv.position;
148
				WB1.DrawPage();
147
				WB1.DrawPage();
149
				break;
148
				break;
150
			}
149
			}
151
			break;
150
			break;
152
 
151
 
153
		case evButton:
152
		case evButton:
154
			ProcessEvent(GetButtonID());
153
			ProcessEvent(GetButtonID());
155
			break;
154
			break;
156
 
155
 
157
		case evKey:
156
		case evKey:
158
			GetKeys();
157
			GetKeys();
159
			if (address_box.flags & 0b10)  
158
			if (address_box.flags & 0b10)  
160
			{
159
			{
161
				if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
160
				if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else {
162
					EAX = key_editbox; 
161
					EAX = key_editbox; 
163
					edit_box_key stdcall(#address_box);
162
					edit_box_key stdcall(#address_box);
164
				}
163
				}
165
			}
164
			}
166
			else 
165
			else 
167
			{
166
			{
168
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
167
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
169
				else ProcessEvent(key_scancode);
168
				else ProcessEvent(key_scancode);
170
			}
169
			}
171
			break;
170
			break;
172
 
171
 
173
		case evReDraw:
172
		case evReDraw:
174
			if (menu.list.cur_y) {
173
			if (menu.list.cur_y) {
175
				ProcessEvent(menu.list.cur_y);
174
				ProcessEvent(menu.list.cur_y);
176
				menu.list.cur_y = 0;
175
				menu.list.cur_y = 0;
177
			}
176
			}
178
			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);
179
			GetProcessInfo(#Form, SelfInfo);
178
			GetProcessInfo(#Form, SelfInfo);
180
			if (Form.status_window>2) { DrawTitle(#header); break; }
179
			if (Form.status_window>2) { DrawTitle(#header); break; }
181
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
180
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
182
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
181
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
183
			Draw_Window();
182
			Draw_Window();
184
			break;
183
			break;
185
			
184
			
186
		case evNetwork:
185
		case evNetwork:
187
			if (http.transfer > 0) {
186
			if (http.transfer > 0) {
188
				http.receive();
187
				http.receive();
189
				EventUpdateProgressBar();
188
				EventUpdateProgressBar();
190
				if (http.receive_result == 0) {
189
				if (http.receive_result == 0) {
191
					// Handle redirects
190
					// Handle redirects
192
					if (http.status_code >= 300) && (http.status_code < 400)
191
					if (http.status_code >= 300) && (http.status_code < 400)
193
					{
192
					{
194
						redirected++;
193
						redirected++;
195
						if (redirected<=5)
194
						if (redirected>5)
196
						{
-
 
197
							if (http.handle_redirect()) {
-
 
198
								if (!strncmp(#URL,"https://",8))
-
 
199
								{
195
						{
200
									history.back();
-
 
201
									strcpy(#editURL, history.current());
-
 
202
									strcpy(#URL, history.current());
196
							notify("'Too many redirects.' -E");
203
									ShowErrorMessageThatHttpsIsNotSupportedYet();
-
 
204
									StopLoading();
197
							StopLoading();
205
									break;	
-
 
206
								}
-
 
207
							}
-
 
208
						}
198
						}
209
						else
199
						else
210
						{
200
						{
211
							notify("Too many redirects");
201
							http.handle_redirect();
212
							StopLoading();
-
 
213
							break;
-
 
214
						}
-
 
215
					} 
-
 
216
					else
-
 
217
					{
-
 
218
						redirected = 0;
-
 
219
					}
-
 
220
					// Loading the page is complete, free resources
-
 
221
					if (redirected>0)
-
 
222
					{
-
 
223
						http.free();
202
							http.free();
224
						GetAbsoluteURL(#URL);
203
							GetAbsoluteURL(#http.redirect_url);
225
						history.back();
204
							history.back();
226
						strcpy(#editURL, #URL);
205
							strcpy(#editURL, #URL);
227
						DrawEditBoxWebView();
206
							DrawEditBoxWebView();
228
						OpenPage();
207
							OpenPage();
229
					}
208
						}
230
					else
209
						break;
231
					{
210
					} 
-
 
211
					redirected = 0;
-
 
212
					// Loading the page is complete, free resources
232
						history.add(#URL);
213
					history.add(#URL);
233
						ESI = http.transfer;
-
 
234
						bufpointer = ESI.http_msg.content_ptr;
214
					bufpointer = http.content_pointer;
235
						bufsize = ESI.http_msg.content_received;
215
					bufsize = http.content_received;
236
						http.free();
216
					http.free();
237
						SetPageDefaults();
217
					SetPageDefaults();
238
						ShowPage();
218
					ShowPage();
239
					}
219
				}
240
				}
220
			}
241
			}
221
	}
242
	}
222
}
243
}
-
 
244
 
223
 
245
void SetElementSizes()
224
void SetElementSizes()
246
{
225
{
247
	address_box.top = TOOLBAR_H/2-10;
226
	address_box.top = TOOLBAR_H/2-10;
248
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
227
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
249
	address_box.width = Form.cwidth - address_box.left - 50;
228
	address_box.width = Form.cwidth - address_box.left - 50;
250
	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, 
251
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
230
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
252
	WB1.list.wheel_size = 7 * basic_line_h;
231
	WB1.list.wheel_size = 7 * basic_line_h;
253
	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;
254
	WB1.list.visible = WB1.list.h;
233
	WB1.list.visible = WB1.list.h;
255
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
234
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
256
		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);
257
		ProcessEvent(REFRESH_BUTTON);
236
		ProcessEvent(REFRESH_BUTTON);
258
	}
237
	}
259
}
238
}
260
 
239
 
261
 
240
 
262
 
241
 
263
void Draw_Window()
242
void Draw_Window()
264
{
243
{
265
	DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
244
	DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
266
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
245
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
267
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
246
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
268
	SetElementSizes();
247
	SetElementSizes();
269
	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);
270
	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);
271
	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);
272
	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);
273
	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);
274
	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);
275
	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);
276
	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);
277
	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) 
-
 
258
		OpenPage(); 
-
 
259
	else { 
-
 
260
		WB1.DrawPage(); 
278
	if (!header) OpenPage(); else { WB1.DrawPage(); DrawEditBoxWebView(); }
261
		DrawEditBoxWebView(); 
-
 
262
	}
279
	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);
280
	DrawProgress();
264
	DrawProgress();
281
}
265
}
282
 
266
 
283
 
267
 
284
void ProcessEvent(dword id__)
268
void ProcessEvent(dword id__)
285
{
269
{
286
	switch (id__)
270
	switch (id__)
287
	{
271
	{
288
		case 1:
272
		case 1:
289
			ExitProcess();
273
			ExitProcess();
290
			return;
274
			return;
291
		case SCAN_CODE_BS:
275
		case SCAN_CODE_BS:
292
		case BACK_BUTTON:
276
		case BACK_BUTTON:
293
			if (history.back()) {
277
			if (history.back()) {
294
				strcpy(#URL, history.current());
278
				strcpy(#URL, history.current());
295
				OpenPage();
279
				OpenPage();
296
			}
280
			}
297
			return;
281
			return;
298
		case FORWARD_BUTTON:
282
		case FORWARD_BUTTON:
299
			if (history.forward()) {
283
			if (history.forward()) {
300
				strcpy(#URL, history.current());
284
				strcpy(#URL, history.current());
301
				OpenPage();
285
				OpenPage();
302
			}
286
			}
303
			return;
287
			return;
304
		case GOTOURL_BUTTON:
288
		case GOTOURL_BUTTON:
305
		case SCAN_CODE_ENTER:
289
		case SCAN_CODE_ENTER:
-
 
290
			if (!editURL[0]) {
-
 
291
				strcpy(#URL, URL_SERVICE_HOME);
-
 
292
			}
306
			if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
293
			else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') 
307
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
294
			|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
308
			{
295
			{
309
				strcpy(#URL, #editURL);
296
				strcpy(#URL, #editURL);
310
			}
297
			}
311
			else
298
			else
312
			{
299
			{
313
				strlcpy(#URL,"http://",7);
300
				strlcpy(#URL,"http://",7);
314
				strcat(#URL, #editURL);
301
				strcat(#URL, #editURL);
315
			}
302
			}
316
			OpenPage();
303
			OpenPage();
317
			return;
304
			return;
318
		case 063: //F5
305
		case 063: //F5
319
			IF(address_box.flags & 0b10) return;
306
			IF(address_box.flags & 0b10) return;
320
		case REFRESH_BUTTON:
307
		case REFRESH_BUTTON:
321
			if (http.transfer > 0) 
308
			if (http.transfer > 0) 
322
			{
309
			{
323
				StopLoading();
310
				StopLoading();
324
				Draw_Window();
311
				Draw_Window();
325
			}
312
			}
326
			else OpenPage();
313
			else OpenPage();
327
			return;
314
			return;
328
		case SANDWICH_BUTTON:
315
		case SANDWICH_BUTTON:
329
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
316
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
330
			return;
317
			return;
331
		case VIEW_SOURCE:
318
		case VIEW_SOURCE:
332
			WB1.list.first = 0;
319
			WB1.list.first = 0;
333
			ShowSource();
320
			ShowSource();
334
			WB1.LoadInternalPage(bufpointer, bufsize);
321
			WB1.LoadInternalPage(bufpointer, bufsize);
335
			break;
322
			break;
336
		case EDIT_SOURCE:
323
		case EDIT_SOURCE:
337
			if (!strncmp(#URL,"http:",5)) 
324
			if (!strncmp(#URL,"http",4)) 
338
			{
325
			{
339
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
326
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
340
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
327
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
341
			}
328
			}
342
			else RunProgram("/rd/1/tinypad", #URL);
329
			else RunProgram("/rd/1/tinypad", #URL);
343
			return;
330
			return;
344
		// case FREE_IMG_CACHE:
331
		// case FREE_IMG_CACHE:
345
		// 	ImgCache.Free();
332
		// 	ImgCache.Free();
346
		// 	notify(IMAGES_CACHE_CLEARED);
333
		// 	notify(IMAGES_CACHE_CLEARED);
347
		// 	WB1.DrawPage();
334
		// 	WB1.DrawPage();
348
		// 	return;
335
		// 	return;
349
		case VIEW_HISTORY:
336
		case VIEW_HISTORY:
350
			strcpy(#URL, URL_SERVICE_HISTORY);
337
			strcpy(#URL, URL_SERVICE_HISTORY);
351
			OpenPage();
338
			OpenPage();
352
			return;
339
			return;
353
		case DOWNLOAD_MANAGER:
340
		case DOWNLOAD_MANAGER:
354
			if (!downloader_opened) {
341
			if (!downloader_opened) {
355
				downloader_edit = NULL;
342
				downloader_edit = NULL;
356
				CreateThread(#Downloader,#downloader_stak+4092);
343
				CreateThread(#Downloader,#downloader_stak+4092);
357
			}
344
			}
358
			return;
345
			return;
359
		case COPY_LINK:
346
		case COPY_LINK_URL:
360
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
347
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
361
			notify("'URL copied to clipboard'O");
348
			notify("'URL copied to clipboard'O");
362
			return;
349
			return;
363
		case DOWNLOAD_LINK_CONTENTS:
350
		case DOWNLOAD_LINK_CONTENTS:
364
			if (!downloader_opened) {
351
			if (!downloader_opened) {
365
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
352
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
366
				CreateThread(#Downloader,#downloader_stak+4092);
353
				CreateThread(#Downloader,#downloader_stak+4092);
367
			}
354
			}
368
			return;
355
			return;
-
 
356
		case SCAN_CODE_F12:
-
 
357
			debug_mode ^= 1;
-
 
358
			if (debug_mode) notify("'Debug mode ON'-I");
-
 
359
			else notify("'Debug mode OFF'-I");
-
 
360
			return;
-
 
361
		case SCAN_CODE_F11:
-
 
362
			old_tag_parser_mode ^= 1;
-
 
363
			if (old_tag_parser_mode) notify("'Old tag parser ON'-I");
-
 
364
			else notify("'Old tag parser OFF'-I");
-
 
365
			return;
369
	}
366
	}
370
}
367
}
371
 
368
 
372
void StopLoading()
369
void StopLoading()
373
{
370
{
374
	if (http.transfer)
371
	if (http.transfer)
375
	{
372
	{
376
		EAX = http.transfer;
373
		EAX = http.transfer;
377
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
374
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
378
		$push	EAX							// save it on the stack
375
		$push	EAX							// save it on the stack
379
		http_free stdcall (http.transfer);	// abort connection
376
		http_free stdcall (http.transfer);	// abort connection
380
		$pop	EAX							
377
		$pop	EAX							
381
		free(EAX);						// free data
378
		free(EAX);						// free data
382
		http.transfer=0;
379
		http.transfer=0;
383
		bufsize = 0;
380
		bufsize = 0;
384
		bufpointer = free(bufpointer);
381
		bufpointer = free(bufpointer);
385
	}
382
	}
386
	wv_progress_bar.value = 0;
383
	wv_progress_bar.value = 0;
387
	DrawEditBoxWebView();
384
	DrawEditBoxWebView();
388
}
385
}
389
 
386
 
390
void SetPageDefaults()
387
void SetPageDefaults()
391
{
388
{
392
	strcpy(#header, #version);
389
	strcpy(#header, #version);
393
	WB1.list.count = WB1.list.first = 0;
390
	WB1.list.count = WB1.list.first = 0;
394
	cur_encoding = CH_NULL;
391
	cur_encoding = CH_NULL;
395
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
392
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
396
}
393
}
397
 
394
 
398
void OpenPage()
395
void OpenPage()
399
{
396
{
-
 
397
	char getUrl[sizeof(URL)];
400
	StopLoading();
398
	StopLoading();
401
	souce_mode = false;
399
	souce_mode = false;
402
	strcpy(#editURL, #URL);
400
	strcpy(#editURL, #URL);
403
	history.add(#URL);
401
	history.add(#URL);
404
	if (!strncmp(#URL,"WebView:",8))
402
	if (!strncmp(#URL,"WebView:",8))
405
	{
403
	{
406
		SetPageDefaults();
404
		SetPageDefaults();
407
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
405
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
408
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
406
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
409
		DrawEditBoxWebView();
407
		DrawEditBoxWebView();
410
		return;
408
		return;
411
	}
409
	}
412
	if (!strncmp(#URL,"http:",5))
410
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8)) 
413
	{
411
	{
414
		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
 
-
 
414
		if (!strncmp(#URL,"http:",5)) {
415
		http.get(#URL);
415
			http.get(#URL);
-
 
416
		}
-
 
417
		if (!strncmp(#URL,"https://",8)) {
-
 
418
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
-
 
419
			http.get(#getUrl);
-
 
420
		}
-
 
421
		//http.get(#URL);
416
		if (!http.transfer)
422
		if (!http.transfer)
417
		{
423
		{
418
			StopLoading();
424
			StopLoading();
419
			bufsize = 0;
425
			bufsize = 0;
420
			bufpointer = free(bufpointer);
426
			bufpointer = free(bufpointer);
421
			ShowPage();
427
			ShowPage();
422
			return;
428
			return;
423
		}
429
		}
424
	}
430
	}
425
	else
431
	else
426
	{
432
	{
427
		file_size stdcall (#URL);
433
		file_size stdcall (#URL);
428
		bufsize = EBX;
434
		bufsize = EBX;
429
		if (bufsize)
435
		if (bufsize)
430
		{
436
		{
431
			free(bufpointer);
437
			free(bufpointer);
432
			bufpointer = malloc(bufsize);
438
			bufpointer = malloc(bufsize);
433
			SetPageDefaults();
439
			SetPageDefaults();
434
			ReadFile(0, bufsize, bufpointer, #URL);
440
			ReadFile(0, bufsize, bufpointer, #URL);
435
		}
441
		}
436
		ShowPage();
442
		ShowPage();
437
	}
443
	}
438
}
444
}
439
 
445
 
440
DrawEditBoxWebView()
446
DrawEditBoxWebView()
441
{
447
{
442
	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);
443
	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);
444
	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);
445
	address_box.offset = 0;
451
	address_box.offset = 0;
446
	edit_box_draw stdcall(#address_box);
452
	edit_box_draw stdcall(#address_box);
447
	if (http.transfer > 0) EAX = 131; else EAX = 54;
453
	if (http.transfer > 0) EAX = 131; else EAX = 54;
448
	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);
449
}
455
}
450
 
456
 
451
 
457
 
452
void ShowPage()
458
void ShowPage()
453
{
459
{
454
	DrawEditBoxWebView();
460
	DrawEditBoxWebView();
455
	debugval("bufsize", bufsize);
-
 
456
	if (!bufsize)
461
	if (!bufsize)
457
	{
462
	{
458
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
463
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
459
		else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
464
		else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
460
	}
465
	}
461
	else
466
	else
462
	{
467
	{
463
		WB1.Prepare();
468
		WB1.Prepare();
464
	}
469
	}
465
}
470
}
466
 
471
 
467
byte UrlExtIs(dword ext)
472
byte UrlExtIs(dword ext)
468
{
473
{
469
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
474
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
470
	return false;
475
	return false;
471
}
476
}
472
 
477
 
473
int SetSkinColors()
478
int SetSkinColors()
474
{
479
{
475
	dword image_data;
480
	dword image_data;
476
	image_data = DSDWORD[skin.image+24];
481
	image_data = DSDWORD[skin.image+24];
477
	col_bg = DSDWORD[image_data];
482
	col_bg = DSDWORD[image_data];
478
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
483
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
479
	border_color = DSDWORD[skin.w*4*7 + image_data];
484
	border_color = DSDWORD[skin.w*4*7 + image_data];
480
	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];
481
	$and col_bg, 0x00ffffff
486
	$and col_bg, 0x00ffffff
482
	$and panel_color, 0x00ffffff
487
	$and panel_color, 0x00ffffff
483
	$and border_color, 0x00ffffff
488
	$and border_color, 0x00ffffff
484
	$and wv_progress_bar.progress_color, 0x00ffffff
489
	$and wv_progress_bar.progress_color, 0x00ffffff
485
}
490
}
486
 
491
 
487
void DrawProgress()
492
void DrawProgress()
488
{
493
{
489
	unsigned long btn;
494
	dword persent;
490
	if (http.transfer == 0) return;
495
	if (http.transfer == 0) return;
491
	if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
496
	if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
492
	DrawBar(address_box.left-2, address_box.top+20, btn, 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);
493
}
498
}
494
 
499
 
495
 
500
 
496
char anchor[256];
501
char anchor[256];
497
void ClickLink()
502
void ClickLink()
498
{
503
{
499
	if (http.transfer > 0) 
504
	if (http.transfer > 0) 
500
	{
505
	{
501
		StopLoading();
506
		StopLoading();
502
		history.back();
507
		history.back();
503
	}
508
	}
504
 
-
 
505
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));	
509
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
506
	//#1
510
	//#1
507
	if (URL[0] == '#')
511
	if (URL[0] == '#')
508
	{
512
	{
509
		if (URL[1] == NULL) {
513
		if (URL[1] == NULL) {
510
			WB1.list.first = 0;
514
			WB1.list.first = 0;
511
			strcpy(#URL, history.current());
515
			strcpy(#URL, history.current());
512
		}
516
		}
513
		else {
517
		else {
514
			strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
518
			strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
515
			strcpy(#URL, history.current());
519
			strcpy(#URL, history.current());
516
		}
520
		}
517
		ShowPage();			
521
		ShowPage();			
518
		return;
522
		return;
519
	}
523
	}
520
	//liner.ru#1
524
	//liner.ru#1
521
	if (strrchr(#URL, '#')!=0)
525
	if (strrchr(#URL, '#')!=0)
522
	{
526
	{
523
		strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
527
		strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
524
		URL[strrchr(#URL, '#')-1] = 0x00;
528
		URL[strrchr(#URL, '#')-1] = 0x00;
525
	}
529
	}
526
 
530
 
527
	if (!strncmp(#URL,"mailto:", 7))
531
	if (!strncmp(#URL,"mailto:", 7))
528
	{
532
	{
529
		notify(#URL);
533
		notify(#URL);
530
		strcpy(#editURL, history.current());
534
		strcpy(#editURL, history.current());
531
		strcpy(#URL, history.current());
535
		strcpy(#URL, history.current());
532
		return;
536
		return;
533
	}
537
	}
534
 
-
 
535
	if (!strncmp(#URL,"https://",8))
-
 
536
	{
-
 
537
		ShowErrorMessageThatHttpsIsNotSupportedYet();
-
 
538
		strcpy(#editURL, history.current());
-
 
539
		strcpy(#URL, history.current());
-
 
540
		return;
-
 
541
	}
-
 
542
	
538
 
543
	GetAbsoluteURL(#URL);
539
	GetAbsoluteURL(#URL);
544
 
540
 
545
	if (strncmp(#URL,"http://",7)!=0)
541
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
546
	{
542
	{
547
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
543
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
548
		{	
544
		{	
549
			RunProgram("/sys/@open", #URL);
545
			RunProgram("/sys/@open", #URL);
550
			strcpy(#editURL, history.current());
546
			strcpy(#editURL, history.current());
551
			strcpy(#URL, history.current());
547
			strcpy(#URL, history.current());
552
			return;
548
			return;
553
		}
549
		}
554
	}
550
	}
555
	else	
551
	else	
556
	{
552
	{
557
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) 
553
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) 
558
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
554
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
559
		|| (UrlExtIs(".7z")==true) {
555
		|| (UrlExtIs(".7z")==true) {
560
			if (!downloader_opened) {
556
			if (!downloader_opened) {
561
				strcpy(#downloader_edit, #URL);
557
				strcpy(#downloader_edit, #URL);
562
				CreateThread(#Downloader,#downloader_stak+4092);
558
				CreateThread(#Downloader,#downloader_stak+4092);
563
				strcpy(#editURL, history.current());
559
				strcpy(#editURL, history.current());
564
				strcpy(#URL, history.current());
560
				strcpy(#URL, history.current());
565
			}
561
			}
566
			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");
567
			return;
563
			return;
568
		}
564
		}
569
	}
565
	}
570
	if (open_in_a_new_window)
566
	if (open_in_a_new_window)
571
	{
567
	{
572
		RunProgram(#program_path, #URL);
568
		RunProgram(#program_path, #URL);
573
		strcpy(#editURL, history.current());
569
		strcpy(#editURL, history.current());
574
		strcpy(#URL, history.current());
570
		strcpy(#URL, history.current());
575
	}
571
	}
576
	else 
572
	else 
577
	{
573
	{
578
		OpenPage();
574
		OpenPage();
579
	}
575
	}
580
	open_in_a_new_window = false;
576
	open_in_a_new_window = false;
581
}
577
}
582
 
578
 
583
void EventShowPageMenu(dword _left, _top)
579
void EventShowPageMenu(dword _left, _top)
584
{
580
{
585
	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);
586
}
582
}
587
 
583
 
588
void EventShowLinkMenu(dword _left, _top)
584
void EventShowLinkMenu(dword _left, _top)
589
{
585
{
590
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK);
586
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
591
}
587
}
592
 
588
 
593
void EventUpdateProgressBar()
589
void EventUpdateProgressBar()
594
{
590
{
595
	wv_progress_bar.max = http.content_length;
591
	wv_progress_bar.max = http.content_length;
596
	if (wv_progress_bar.value != http.content_received)
592
	if (wv_progress_bar.value != http.content_received)
597
	{
593
	{
598
		wv_progress_bar.value = http.content_received;	
594
		wv_progress_bar.value = http.content_received;	
599
		DrawProgress();
595
		DrawProgress();
600
	}
596
	}
601
}
597
}
602
 
-
 
603
 
-
 
604
void ShowErrorMessageThatHttpsIsNotSupportedYet()
-
 
605
{
-
 
606
	notify("'HTTPS protocol is not supported yet' -E");
-
 
607
}
-
 
608
 
598
 
609
DrawStatusBar(dword _status_text)
599
DrawStatusBar(dword _status_text)
610
{
600
{
611
	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;
612
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
602
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
613
	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;
614
	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);
615
	status_text.text_pointer = _status_text;
605
	status_text.text_pointer = _status_text;
616
	PathShow_prepare stdcall(#status_text);
606
	PathShow_prepare stdcall(#status_text);
617
	PathShow_draw stdcall(#status_text);
607
	PathShow_draw stdcall(#status_text);
618
}
608
}
619
 
609
 
620
stop:
610
stop:

621
>

-