Subversion Repositories Kolibri OS

Rev

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

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

632
>