Subversion Repositories Kolibri OS

Rev

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

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

614
>