Subversion Repositories Kolibri OS

Rev

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

Rev 4687 Rev 4688
1
//HTML Viewer in C--
1
//HTML Viewer in C--
2
//Copyright 2007-2013 by Veliant & Leency
2
//Copyright 2007-2013 by Veliant & Leency
3
//Asper, lev, Lrz, Barsuk, Nable...
3
//Asper, lev, Lrz, Barsuk, Nable...
4
//home icon - rachel fu, GPL licence
4
//home icon - rachel fu, GPL licence
5
 
5
 
6
#ifndef AUTOBUILD
6
#ifndef AUTOBUILD
7
	#include "lang.h--"
7
	#include "lang.h--"
8
#endif
8
#endif
9
 
9
 
10
//libraries
10
//libraries
11
#define MEMSIZE 0x100000
11
#define MEMSIZE 0x100000
12
#include "..\lib\kolibri.h"
12
#include "..\lib\kolibri.h"
13
#include "..\lib\strings.h"
13
#include "..\lib\strings.h"
14
#include "..\lib\figures.h"
14
#include "..\lib\figures.h"
15
#include "..\lib\encoding.h"
15
#include "..\lib\encoding.h"
16
#include "..\lib\file_system.h"
16
#include "..\lib\file_system.h"
17
#include "..\lib\mem.h"
17
#include "..\lib\mem.h"
18
#include "..\lib\dll.h"
18
#include "..\lib\dll.h"
19
#include "..\lib\draw_buf.h"
19
#include "..\lib\draw_buf.h"
20
#include "..\lib\list_box.h"
20
#include "..\lib\list_box.h"
21
#include "..\lib\cursor.h"
21
#include "..\lib\cursor.h"
22
 
22
 
23
//*.obj libraries
23
//*.obj libraries
24
#include "..\lib\lib.obj\box_lib.h"
24
#include "..\lib\lib.obj\box_lib.h"
25
#include "..\lib\lib.obj\libio_lib.h"
25
#include "..\lib\lib.obj\libio_lib.h"
26
#include "..\lib\lib.obj\libimg_lib.h"
26
#include "..\lib\lib.obj\libimg_lib.h"
27
#include "..\lib\lib.obj\http.h"
27
#include "..\lib\lib.obj\http.h"
28
 
28
 
29
char homepage[] = FROM "html\homepage.htm";
29
char homepage[] = FROM "html\homepage.htm";
30
 
30
 
31
#ifdef LANG_RUS
31
#ifdef LANG_RUS
32
	char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.0 Beta 2";
32
	char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.0 Beta 2";
33
	?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
33
	?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
34
	?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
34
	?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
35
	char loading[] = "‡ £à㧪  áâà ­¨æë...
";
35
	char loading[] = "‡ £à㧪  áâà ­¨æë...
";
36
	char page_not_found[] = FROM "html\page_not_found_ru.htm";
36
	char page_not_found[] = FROM "html\page_not_found_ru.htm";
37
	char accept_language[]= "Accept-Language: ru\n";
37
	char accept_language[]= "Accept-Language: ru\n";
38
#else
38
#else
39
	char version[]=" Text-based Browser 1.0 Beta 2";
39
	char version[]=" Text-based Browser 1.0 Beta 2";
40
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
40
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
41
	?define T_LAST_SLIDE "This slide is the last"
41
	?define T_LAST_SLIDE "This slide is the last"
42
	char loading[] = "Loading...
";
42
	char loading[] = "Loading...
";
43
	char page_not_found[] = FROM "html\page_not_found_en.htm";
43
	char page_not_found[] = FROM "html\page_not_found_en.htm";
44
	char accept_language[]= "Accept-Language: en\n";	
44
	char accept_language[]= "Accept-Language: en\n";	
45
#endif
45
#endif
46
 
46
 
47
proc_info Form;
47
proc_info Form;
48
#define WIN_W 640
48
#define WIN_W 640
49
#define WIN_H 480
49
#define WIN_H 480
50
 
50
 
51
char search_path[]="http://nigma.ru/index.php?s=";
51
char search_path[]="http://nigma.ru/index.php?s=";
52
char str_location[]="location\0";
52
char str_location[]="location\0";
53
int redirected = 0;
53
int redirected = 0;
54
 
54
 
55
char stak[4096];
55
char stak[4096];
56
mouse m;
56
mouse m;
57
int action_buf;
57
int action_buf;
58
 
58
 
59
dword http_transfer = 0;
59
dword http_transfer = 0;
60
dword http_buffer;
60
dword http_buffer;
61
 
61
 
62
dword TAB_H = 19;
62
dword TAB_H = 19;
63
dword TAB_W = 150;
63
dword TAB_W = 150;
64
dword TOOLBAR_H = 50;
64
dword TOOLBAR_H = 50;
65
dword STATUSBAR_H =18;
65
dword STATUSBAR_H =18;
66
dword col_bg = 0xE4DFE1;
66
dword col_bg = 0xE4DFE1;
67
dword panel_color = 0xF1F1F1;
67
dword panel_color = 0xF1F1F1;
68
dword border_color = 0x9F9F9F;
68
dword border_color = 0x9F9F9F;
69
 
69
 
70
pb progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
70
pb progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
71
 
71
 
72
#include "..\TWB\TWB.c"
72
#include "..\TWB\TWB.c"
73
#include "menu_rmb.h"
73
#include "menu_rmb.h"
74
#include "history.h"
74
#include "history.h"
75
 
75
 
76
char editURL[sizeof(URL)];
76
char editURL[sizeof(URL)];
77
int	mouse_twb;
77
int	mouse_twb;
78
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
78
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
79
 
79
 
80
#define URL_SERVICE_HISTORY "WebView://history"
80
#define URL_SERVICE_HISTORY "WebView://history"
81
#define URL_SERVICE_HOME "WebView://home"
81
#define URL_SERVICE_HOME "WebView://home"
82
 
82
 
83
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
83
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
84
 
84
 
85
struct skin {
85
struct skin {
86
	dword image, w, h;
86
	dword image, w, h;
87
} skin;
87
} skin;
88
 
88
 
89
int LoadSkin()
89
int LoadSkin()
90
{
90
{
91
	skin.image = load_image(abspath("wv_skin.png"));
91
	skin.image = load_image(abspath("wv_skin.png"));
92
	if (!skin.image) notify("WebView skin file 'wv_skin.png' not found, program will terminate");
92
	if (!skin.image) notify("WebView skin file 'wv_skin.png' not found, program will terminate");
93
	skin.w = DSWORD[skin.image+4];
93
	skin.w = DSWORD[skin.image+4];
94
	skin.h = DSWORD[skin.image+8];
94
	skin.h = DSWORD[skin.image+8];
95
}
95
}
96
 
96
 
97
void DrawProgress()
97
void DrawProgress()
98
{
98
{
99
	unsigned long btn;
99
	unsigned long btn;
100
	//progressbar_draw stdcall(#progress_bar);
100
	//progressbar_draw stdcall(#progress_bar);
101
	progress_bar.width = progress_bar.left = 0;
101
	progress_bar.width = progress_bar.left = 0;
102
	if (http_transfer == 0) return;
102
	if (http_transfer == 0) return;
103
	if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30;
103
	if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30;
104
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color);
104
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color);
105
}
105
}
106
 
106
 
107
void main()
107
void main()
108
{
108
{
109
	unsigned long key, btn;
109
	unsigned long key, btn;
110
	int half_scroll_size;
110
	int half_scroll_size;
111
	int scroll_used=0, show_menu;
111
	int scroll_used=0, show_menu;
112
	
112
	
113
	mem_Init();
113
	mem_Init();
114
	CursorPointer.Load(#CursorFile);
114
	CursorPointer.Load(#CursorFile);
115
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj");
115
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj");
116
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
116
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
117
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
117
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
118
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
118
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
119
	LoadSkin();
119
	LoadSkin();
120
	
120
	
121
	Form.width=WIN_W;
121
	Form.width=WIN_W;
122
	Form.height=WIN_H;
122
	Form.height=WIN_H;
123
	SetElementSizes();
123
	SetElementSizes();
124
	if (!URL) strcpy(#URL, URL_SERVICE_HOME);
124
	if (!URL) strcpy(#URL, URL_SERVICE_HOME);
125
	OpenPage();
125
	OpenPage();
126
 
126
 
127
	SetEventMask(0xa7);
127
	SetEventMask(0xa7);
128
	loop()
128
	loop()
129
	{
129
	{
130
		WaitEventTimeout(2);
130
		WaitEventTimeout(2);
131
		switch(EAX & 0xFF)
131
		switch(EAX & 0xFF)
132
		{
132
		{
133
			CASE evMouse:
133
			CASE evMouse:
134
				if (!CheckActiveProcess(Form.ID)) break;
134
				if (!CheckActiveProcess(Form.ID)) break;
135
				//Edit URL
135
				//Edit URL
136
				edit_box_mouse stdcall (#address_box);
136
				edit_box_mouse stdcall (#address_box);
137
				m.get();
137
				m.get();
138
				//Links hover
138
				//Links hover
139
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
139
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
140
				//Menu
140
				//Menu
141
				if (m.y>WB1.list.y) && (m.y
141
				if (m.y>WB1.list.y) && (m.y
142
				{
142
				{
143
					if (m.pkm)
143
					if (m.pkm)
144
					{
144
					{
145
						show_menu = 1;
145
						show_menu = 1;
146
					}
146
					}
147
					if (!m.pkm) && (show_menu)
147
					if (!m.pkm) && (show_menu)
148
					{
148
					{
149
						show_menu = 0;
149
						show_menu = 0;
150
						SwitchToAnotherThread();
150
						SwitchToAnotherThread();
151
						CreateThread(#menu_rmb,#stak+4092);
151
						CreateThread(#menu_rmb,#stak+4092);
152
						break; 
152
						break; 
153
					}
153
					}
154
				}
154
				}
155
				//Mouse scroll
155
				//Mouse scroll
156
				if (m.vert)
156
				if (m.vert)
157
				{
157
				{
158
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
158
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
159
				}
159
				}
160
				//Drag scroller
160
				//Drag scroller
161
				scroll_wv.all_redraw = 0;
161
				scroll_wv.all_redraw = 0;
162
				if (!m.lkm) scroll_used=0;
162
				if (!m.lkm) scroll_used=0;
163
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) 
163
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) 
164
				&& (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
164
				&& (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
165
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
165
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
166
				{
166
				{
167
					scroll_used=1;
167
					scroll_used=1;
168
				}				
168
				}				
169
				if (scroll_used)
169
				if (scroll_used)
170
				{
170
				{
171
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
171
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
172
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
172
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
173
					btn=WB1.list.first;
173
					btn=WB1.list.first;
174
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
174
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
175
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
175
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
176
					if (btn<>WB1.list.first) WB1.Parse();
176
					if (btn<>WB1.list.first) WB1.Parse();
177
				}
177
				}
178
				break;
178
				break;
179
			case evButton:
179
			case evButton:
180
				btn=GetButtonID();
180
				btn=GetButtonID();
181
				if (btn==1)	ExitProcess();
181
				if (btn==1)	ExitProcess();
182
				Scan(btn);
182
				Scan(btn);
183
				break;
183
				break;
184
			case evKey:
184
			case evKey:
185
				key = GetKey();
185
				key = GetKey();
186
				
186
				
187
				if (address_box.flags & 0b10) SWITCH(key)
187
				if (address_box.flags & 0b10) SWITCH(key)
188
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
188
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
189
 
189
 
190
				Scan(key);
190
				Scan(key);
191
				
191
				
192
				_EDIT_MARK:
192
				_EDIT_MARK:
193
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
193
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
194
				break;
194
				break;
195
			case evReDraw:
195
			case evReDraw:
196
				if (action_buf) Scan(action_buf);
196
				if (action_buf) Scan(action_buf);
197
				Draw_Window();
197
				Draw_Window();
198
				break;
198
				break;
199
				
199
				
200
			case evNetwork:
200
			case evNetwork:
201
				if (http_transfer > 0) {
201
				if (http_transfer > 0) {
202
					http_process stdcall (http_transfer);
202
					http_process stdcall (http_transfer);
203
					$push EAX
203
					$push EAX
204
					ESI = http_transfer;
204
					ESI = http_transfer;
205
					progress_bar.max = ESI.http_msg.content_length;
205
					progress_bar.max = ESI.http_msg.content_length;
206
					if (progress_bar.value != ESI.http_msg.content_received)
206
					if (progress_bar.value != ESI.http_msg.content_received)
207
					{
207
					{
208
						progress_bar.value = ESI.http_msg.content_received;	
208
						progress_bar.value = ESI.http_msg.content_received;	
209
						DrawProgress();
209
						DrawProgress();
210
					}
210
					}
211
					$pop EAX
211
					$pop EAX
212
					if (EAX == 0) {
212
					if (EAX == 0) {
213
						ESI = http_transfer;
213
						ESI = http_transfer;
214
						// Handle redirects
214
						// Handle redirects
215
						if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
215
						if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
216
						{
216
						{
217
							redirected++;
217
							redirected++;
218
							if (redirected<=5)
218
							if (redirected<=5)
219
							{
219
							{
220
								http_find_header_field stdcall (http_transfer, #str_location);
220
								http_find_header_field stdcall (http_transfer, #str_location);
221
								if (EAX!=0) {
221
								if (EAX!=0) {
222
									ESI = EAX;
222
									ESI = EAX;
223
									EDI = #URL;
223
									EDI = #URL;
224
									do {
224
									do {
225
										$lodsb;
225
										$lodsb;
226
										$stosb;
226
										$stosb;
227
									} while (AL != 0) && (AL != 13) && (AL != 10));
227
									} while (AL != 0) && (AL != 13) && (AL != 10));
228
									DSBYTE[EDI-1]='\0';
228
									DSBYTE[EDI-1]='\0';
229
								}
229
								}
230
							}
230
							}
231
							else
231
							else
232
							{
232
							{
233
							//TODO: display error (too many redirects)
233
							//TODO: display error (too many redirects)
234
							}
234
							}
235
						} 
235
						} 
236
						else
236
						else
237
						{
237
						{
238
							redirected = 0;
238
							redirected = 0;
239
						}
239
						}
240
						// Loading the page is complete, free resources
240
						// Loading the page is complete, free resources
241
						if (redirected>0)
241
						if (redirected>0)
242
						{
242
						{
243
							http_free stdcall (http_transfer);
243
							http_free stdcall (http_transfer);
244
							http_transfer=0;
244
							http_transfer=0;
245
							PageLinks.GetAbsoluteURL(#URL);
245
							PageLinks.GetAbsoluteURL(#URL);
246
							BrowserHistory.current--;
246
							BrowserHistory.current--;
247
							strcpy(#editURL, #URL);
247
							strcpy(#editURL, #URL);
248
							OpenPage();
248
							OpenPage();
249
						}
249
						}
250
						else
250
						else
251
						{
251
						{
252
							BrowserHistory.AddUrl();
252
							BrowserHistory.AddUrl();
253
							ESI = http_transfer;
253
							ESI = http_transfer;
254
							bufpointer = ESI.http_msg.content_ptr;
254
							bufpointer = ESI.http_msg.content_ptr;
255
							bufsize = ESI.http_msg.content_received;
255
							bufsize = ESI.http_msg.content_received;
256
							http_free stdcall (http_transfer);
256
							http_free stdcall (http_transfer);
257
							http_transfer=0;
257
							http_transfer=0;
258
							SetPageDefaults();
258
							SetPageDefaults();
259
							Draw_Window();		// stop button => refresh button
259
							Draw_Window();		// stop button => refresh button
260
						}
260
						}
261
					}
261
					}
262
				}
262
				}
263
		}
263
		}
264
	}
264
	}
265
}
265
}
266
 
266
 
267
void SetElementSizes()
267
void SetElementSizes()
268
{
268
{
269
	address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
269
	address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
270
	address_box.width = Form.cwidth - address_box.left - 25 - 22;
270
	address_box.width = Form.cwidth - address_box.left - 25 - 22;
271
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 10);
271
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 10);
272
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
272
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
273
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
273
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
274
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
274
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
275
}
275
}
276
 
276
 
277
void Draw_Window()
277
void Draw_Window()
278
{
278
{
279
	int img_off;
279
	int img_off;
280
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
280
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
281
	GetProcessInfo(#Form, SelfInfo);
281
	GetProcessInfo(#Form, SelfInfo);
282
	if (Form.status_window>2) { DrawTitle(#header); return; }
282
	if (Form.status_window>2) { DrawTitle(#header); return; }
283
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
283
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
284
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
284
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
285
	// tab {
285
	// tab {
286
	DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
286
	DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
287
	WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
287
	WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
288
	WriteText(4, 6, 0x80, 0, "Index.htm");
288
	WriteText(4, 6, 0x80, 0, "Index.htm");
289
	// }
289
	// }
290
	DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
290
	DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
291
	DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
291
	DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
292
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
292
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
293
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
293
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
294
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
294
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
295
	img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
295
	img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
296
 
296
 
297
	SetElementSizes();
297
	SetElementSizes();
298
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
298
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
299
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
299
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
300
	// < / >
300
	// < / >
301
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
301
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
302
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
302
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
303
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
303
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
304
	// refrash
304
	// refrash
305
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
305
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
306
	if (http_transfer > 0) img_off = 131; else img_off = 52;
306
	if (http_transfer > 0) img_off = 131; else img_off = 52;
307
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
307
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
308
	// config
308
	// config
309
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
309
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
310
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);	
310
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);	
311
 
311
 
312
	ShowPage();
312
	ShowPage();
313
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
313
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
314
	//status bar
314
	//status bar
315
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
315
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
316
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
316
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
317
	progress_bar.top = Form.cheight - STATUSBAR_H + 4;
317
	progress_bar.top = Form.cheight - STATUSBAR_H + 4;
318
	DrawProgress();
318
	DrawProgress();
319
}
319
}
320
 
320
 
321
 
321
 
322
void ChangeCharset(byte new_charset)
322
void ChangeCharset(byte new_charset)
323
{
323
{
324
	BufEncode(new_charset);
324
	BufEncode(new_charset);
325
	WB1.Parse();	
325
	WB1.Parse();	
326
}
326
}
327
 
327
 
328
void Scan(int id)
328
void Scan(int id)
329
{
329
{
330
	action_buf=0;
330
	action_buf=0;
331
	if (id >= 400) 
331
	if (id >= 400) 
332
	{
332
	{
333
		ProcessLinks(id);
333
		ProcessLinks(id);
334
		return;
334
		return;
335
	}
335
	}
336
	switch (id)
336
	switch (id)
337
	{
337
	{
338
		case 011: //Ctrk+K 
338
		case 011: //Ctrk+K 
339
			ChangeCharset(_KOI);
339
			ChangeCharset(_KOI);
340
			return;
340
			return;
341
 
341
 
342
		case 021: //Ctrl+U
342
		case 021: //Ctrl+U
343
			ChangeCharset(_UTF);
343
			ChangeCharset(_UTF);
344
			return;
344
			return;
345
 
345
 
346
		case 004: //Ctrl+D
346
		case 004: //Ctrl+D
347
			ChangeCharset(_DOS);
347
			ChangeCharset(_DOS);
348
			return;
348
			return;
349
 
349
 
350
		case 005: //Win encoding
350
		case 005: //Win encoding
351
			ChangeCharset(_WIN);
351
			ChangeCharset(_WIN);
352
			return;
352
			return;
353
 
353
 
354
		case 009: //free img cache
354
		case 009: //free img cache
355
			ImgCache.Free();
355
			ImgCache.Free();
356
			notify(IMAGES_CACHE_CLEARED);
356
			notify(IMAGES_CACHE_CLEARED);
357
			WB1.Parse();
357
			WB1.Parse();
358
			return;
358
			return;
359
 
359
 
360
		case 003: //history
360
		case 003: //history
361
			strcpy(#URL, URL_SERVICE_HISTORY);
361
			strcpy(#URL, URL_SERVICE_HISTORY);
362
			OpenPage();
362
			OpenPage();
363
			return;
363
			return;
364
 
364
 
365
		case BACK:
365
		case BACK:
366
			if (!BrowserHistory.GoBack()) return;
366
			if (!BrowserHistory.GoBack()) return;
367
			OpenPage();
367
			OpenPage();
368
			return;
368
			return;
369
		case FORWARD:
369
		case FORWARD:
370
			if (!BrowserHistory.GoForward()) return;
370
			if (!BrowserHistory.GoForward()) return;
371
			OpenPage();
371
			OpenPage();
372
			return;
372
			return;
373
		case 052:  //F3
373
		case 052:  //F3
374
			if (strncmp(#URL,"http:",5)==0) 
374
			if (strncmp(#URL,"http:",5)==0) 
375
			{
375
			{
376
				WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp");
376
				WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp");
377
				if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp");
377
				if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp");
378
			}
378
			}
379
			else
379
			else
380
			{
380
			{
381
				RunProgram("/rd/1/tinypad", #URL);
381
				RunProgram("/rd/1/tinypad", #URL);
382
			}
382
			}
383
			return;
383
			return;
384
		case 054: //F5
384
		case 054: //F5
385
			IF(address_box.flags & 0b10) WB1.Parse();
385
			IF(address_box.flags & 0b10) return;
386
			return;
-
 
387
 
-
 
388
		case REFRESH:
386
		case REFRESH:
389
			if (http_transfer > 0) 
387
			if (http_transfer > 0) 
390
			{
388
			{
391
				StopLoading();
389
				StopLoading();
392
				Draw_Window();
390
				Draw_Window();
393
			}
391
			}
394
			else OpenPage();
392
			else OpenPage();
395
			return;
393
			return;
396
		case 014:
394
		case 014:
397
		case 020:
395
		case 020:
398
		case NEWTAB:
396
		case NEWTAB:
399
			MoveSize(190,80,OLD,OLD);
397
			MoveSize(190,80,OLD,OLD);
400
			RunProgram(#program_path, #URL);
398
			RunProgram(#program_path, #URL);
401
			return;
399
			return;
402
			
400
			
403
		case HOME:
401
		case HOME:
404
			strcpy(#editURL, "http://kolibrios.org/");
402
			strcpy(#editURL, "http://kolibrios.org/");
405
		case GOTOURL:
403
		case GOTOURL:
406
		case 0x0D: //enter
404
		case 0x0D: //enter
407
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
405
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
408
			strcat(#URL, #editURL);
406
			strcat(#URL, #editURL);
409
			OpenPage();
407
			OpenPage();
410
			return;
408
			return;
411
		case SEARCHWEB:
409
		case SEARCHWEB:
412
			strcpy(#URL, #search_path);
410
			strcpy(#URL, #search_path);
413
			strcat(#URL, #editURL);
411
			strcat(#URL, #editURL);
414
			OpenPage();
412
			OpenPage();
415
			return;
413
			return;
416
 
414
 
417
		case 183: //PgDown
415
		case 183: //PgDown
418
			if (WB1.list.count < WB1.list.visible) return;
416
			if (WB1.list.count < WB1.list.visible) return;
419
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
417
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
420
			WB1.list.first += WB1.list.visible + 2;
418
			WB1.list.first += WB1.list.visible + 2;
421
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
419
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
422
			WB1.Parse();
420
			WB1.Parse();
423
			return;
421
			return;
424
 
422
 
425
		case 184: //PgUp
423
		case 184: //PgUp
426
			if (WB1.list.count < WB1.list.visible) return;
424
			if (WB1.list.count < WB1.list.visible) return;
427
			IF(WB1.list.first == 0) return;
425
			IF(WB1.list.first == 0) return;
428
			WB1.list.first -= WB1.list.visible - 2;
426
			WB1.list.first -= WB1.list.visible - 2;
429
			IF(WB1.list.first < 0) WB1.list.first = 0;
427
			IF(WB1.list.first < 0) WB1.list.first = 0;
430
			WB1.Parse();
428
			WB1.Parse();
431
			return;
429
			return;
432
 
430
 
433
		case 178:
431
		case 178:
434
		case BTN_UP:
432
		case BTN_UP:
435
			if (WB1.list.first <= 0) return;
433
			if (WB1.list.first <= 0) return;
436
			WB1.list.first--;
434
			WB1.list.first--;
437
			WB1.Parse();
435
			WB1.Parse();
438
			return;
436
			return;
439
 
437
 
440
		case 177: 
438
		case 177: 
441
		case BTN_DOWN:
439
		case BTN_DOWN:
442
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
440
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
443
			WB1.list.first++;
441
			WB1.list.first++;
444
			WB1.Parse();
442
			WB1.Parse();
445
			return;
443
			return;
446
 
444
 
447
		case 180: //home
445
		case 180: //home
448
			if (WB1.list.KeyHome()) WB1.Parse();
446
			if (WB1.list.KeyHome()) WB1.Parse();
449
			return; 
447
			return; 
450
 
448
 
451
		case 181: //end
449
		case 181: //end
452
			if (WB1.list.count < WB1.list.visible) return;
450
			if (WB1.list.count < WB1.list.visible) return;
453
			if (WB1.list.KeyEnd()) WB1.Parse();
451
			if (WB1.list.KeyEnd()) WB1.Parse();
454
			return;
452
			return;
455
		case 312:
453
		case 312:
456
			SwitchToAnotherThread();
454
			SwitchToAnotherThread();
457
			m.y = TOOLBAR_H-6;
455
			m.y = TOOLBAR_H-6;
458
			m.x = Form.cwidth - 167;
456
			m.x = Form.cwidth - 167;
459
			CreateThread(#menu_rmb,#stak+4092);
457
			CreateThread(#menu_rmb,#stak+4092);
460
	}
458
	}
461
}
459
}
462
 
460
 
463
 
461
 
464
 
462
 
465
void ProcessLinks(int id)
463
void ProcessLinks(int id)
466
{
464
{
467
	if (http_transfer > 0) 
465
	if (http_transfer > 0) 
468
	{
466
	{
469
		StopLoading();
467
		StopLoading();
470
		BrowserHistory.current--;
468
		BrowserHistory.current--;
471
	}
469
	}
472
 
470
 
473
	strcpy(#URL, PageLinks.GetURL(id-401));	
471
	strcpy(#URL, PageLinks.GetURL(id-401));	
474
	//$1 - Condition Script
472
	//$1 - Condition Script
475
	if (URL[0] == '$')
473
	if (URL[0] == '$')
476
	{
474
	{
477
		if (URL[1]=='-') && (condition_href) condition_href--;
475
		if (URL[1]=='-') && (condition_href) condition_href--;
478
		if (URL[1]=='+') 
476
		if (URL[1]=='+') 
479
		{
477
		{
480
			if (condition_href
478
			if (condition_href
481
		}
479
		}
482
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
480
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
483
		strcpy(#URL, BrowserHistory.CurrentUrl());
481
		strcpy(#URL, BrowserHistory.CurrentUrl());
484
		ShowPage();
482
		ShowPage();
485
		return;
483
		return;
486
	}
484
	}
487
	//#1
485
	//#1
488
	if (URL[0] == '#')
486
	if (URL[0] == '#')
489
	{
487
	{
490
		strcpy(#anchor, #URL+strrchr(#URL, '#'));		
488
		strcpy(#anchor, #URL+strrchr(#URL, '#'));		
491
		strcpy(#URL, BrowserHistory.CurrentUrl());
489
		strcpy(#URL, BrowserHistory.CurrentUrl());
492
		WB1.list.first=WB1.list.count-WB1.list.visible;
490
		WB1.list.first=WB1.list.count-WB1.list.visible;
493
		ShowPage();
491
		ShowPage();
494
		return;
492
		return;
495
	}
493
	}
496
	//liner.ru#1
494
	//liner.ru#1
497
	if (strrchr(#URL, '#')!=-1)
495
	if (strrchr(#URL, '#')!=-1)
498
	{
496
	{
499
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
497
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
500
		URL[strrchr(#URL, '#')-1] = 0x00;
498
		URL[strrchr(#URL, '#')-1] = 0x00;
501
	}
499
	}
502
	
500
	
503
	PageLinks.GetAbsoluteURL(#URL);
501
	PageLinks.GetAbsoluteURL(#URL);
504
	
502
	
505
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
503
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
506
	{
504
	{
507
		//if (strstr(#URL,"http:")) 
505
		//if (strstr(#URL,"http:")) 
508
		RunProgram("/sys/media/kiv", #URL);
506
		RunProgram("/sys/media/kiv", #URL);
509
		strcpy(#editURL, BrowserHistory.CurrentUrl());
507
		strcpy(#editURL, BrowserHistory.CurrentUrl());
510
		strcpy(#URL, BrowserHistory.CurrentUrl());
508
		strcpy(#URL, BrowserHistory.CurrentUrl());
511
		return;
509
		return;
512
	}
510
	}
513
	if (!strcmpn(#URL,"mailto:", 7))
511
	if (!strcmpn(#URL,"mailto:", 7))
514
	{
512
	{
515
		notify(#URL);
513
		notify(#URL);
516
		strcpy(#editURL, BrowserHistory.CurrentUrl());
514
		strcpy(#editURL, BrowserHistory.CurrentUrl());
517
		strcpy(#URL, BrowserHistory.CurrentUrl());
515
		strcpy(#URL, BrowserHistory.CurrentUrl());
518
		return;
516
		return;
519
	}
517
	}
520
	OpenPage();
518
	OpenPage();
521
	return;
519
	return;
522
}
520
}
523
 
521
 
524
void StopLoading()
522
void StopLoading()
525
{
523
{
526
	if (http_transfer<>0)
524
	if (http_transfer<>0)
527
	{
525
	{
528
		EAX = http_transfer;
526
		EAX = http_transfer;
529
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
527
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
530
		$push	EAX							// save it on the stack
528
		$push	EAX							// save it on the stack
531
		http_free stdcall (http_transfer);	// abort connection
529
		http_free stdcall (http_transfer);	// abort connection
532
		$pop	EAX							
530
		$pop	EAX							
533
		mem_Free(EAX);						// free data
531
		mem_Free(EAX);						// free data
534
		http_transfer=0;
532
		http_transfer=0;
535
		bufsize = 0;
533
		bufsize = 0;
536
		bufpointer = mem_Free(bufpointer);
534
		bufpointer = mem_Free(bufpointer);
537
	}
535
	}
538
	progress_bar.value = 0;
536
	progress_bar.value = 0;
539
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
537
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
540
}
538
}
541
 
539
 
542
void SetPageDefaults()
540
void SetPageDefaults()
543
{
541
{
544
	strcpy(#header, #version);
542
	strcpy(#header, #version);
545
	pre_text = 0;
543
	pre_text = 0;
546
	WB1.list.count = WB1.list.first = 0;
544
	WB1.list.count = WB1.list.first = 0;
547
	stroka = 0;
545
	stroka = 0;
548
	cur_encoding = _DEFAULT;
546
	cur_encoding = _DEFAULT;
549
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
547
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
550
	anchor_line_num=WB1.list.first;
548
	anchor_line_num=WB1.list.first;
551
	anchor[0]='|';
549
	anchor[0]='|';
552
}
550
}
553
 
551
 
554
void OpenPage()
552
void OpenPage()
555
{
553
{
556
	StopLoading();
554
	StopLoading();
557
	strcpy(#editURL, #URL);
555
	strcpy(#editURL, #URL);
558
	BrowserHistory.AddUrl();
556
	BrowserHistory.AddUrl();
559
	if (strncmp(#URL,"WebView:",8)==0) return;
557
	if (strncmp(#URL,"WebView:",8)==0) return;
560
	if (strncmp(#URL,"http:",5)==0)
558
	if (strncmp(#URL,"http:",5)==0)
561
	{
559
	{
562
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
560
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
563
		http_get stdcall (#URL, #accept_language);
561
		http_get stdcall (#URL, #accept_language);
564
		http_transfer = EAX;
562
		http_transfer = EAX;
565
		if (http_transfer == 0)
563
		if (http_transfer == 0)
566
		{
564
		{
567
			StopLoading();
565
			StopLoading();
568
			bufsize = 0;
566
			bufsize = 0;
569
			bufpointer = mem_Free(bufpointer);
567
			bufpointer = mem_Free(bufpointer);
570
			ShowPage();
568
			ShowPage();
571
			return;
569
			return;
572
		}
570
		}
573
	}
571
	}
574
	else
572
	else
575
	{
573
	{
576
		file_size stdcall (#URL);
574
		file_size stdcall (#URL);
577
		bufsize = EBX;
575
		bufsize = EBX;
578
		if (bufsize)
576
		if (bufsize)
579
		{
577
		{
580
			bufpointer = mem_Free(bufpointer);
578
			bufpointer = mem_Free(bufpointer);
581
			bufpointer = mem_Alloc(bufsize);
579
			bufpointer = mem_Alloc(bufsize);
582
			SetPageDefaults();
580
			SetPageDefaults();
583
			ReadFile(0, bufsize, bufpointer, #URL);				
581
			ReadFile(0, bufsize, bufpointer, #URL);				
584
		}
582
		}
585
		ShowPage();
583
		ShowPage();
586
	}
584
	}
587
}
585
}
588
 
586
 
589
void ShowPage()
587
void ShowPage()
590
{
588
{
591
	address_box.size = address_box.pos = strlen(#editURL);
589
	address_box.size = address_box.pos = strlen(#editURL);
592
	address_box.offset=0;
590
	address_box.offset=0;
593
	edit_box_draw stdcall(#address_box);
591
	edit_box_draw stdcall(#address_box);
594
 
592
 
595
	if (strcmp(#URL, URL_SERVICE_HOME)==0) WB1.Prepare(#homepage, sizeof(homepage)); else
593
	if (strcmp(#URL, URL_SERVICE_HOME)==0) WB1.Prepare(#homepage, sizeof(homepage)); else
596
	if (strcmp(#URL, URL_SERVICE_HISTORY)==0) ShowHistory(); else
594
	if (strcmp(#URL, URL_SERVICE_HISTORY)==0) ShowHistory(); else
597
	if (!bufsize)
595
	if (!bufsize)
598
	{
596
	{
599
		PageLinks.Clear();
597
		PageLinks.Clear();
600
		if (http_transfer<>0)
598
		if (http_transfer<>0)
601
		{
599
		{
602
			WB1.Prepare(#loading, sizeof(loading));
600
			WB1.Prepare(#loading, sizeof(loading));
603
		}
601
		}
604
		else
602
		else
605
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
603
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
606
	}
604
	}
607
	else
605
	else
608
		WB1.Parse();
606
		WB1.Parse();
609
 
607
 
610
	if (!header) strcpy(#header, #version);
608
	if (!header) strcpy(#header, #version);
611
	if (!strcmp(#version, #header)) DrawTitle(#header);
609
	if (!strcmp(#version, #header)) DrawTitle(#header);
612
}
610
}
613
 
611
 
614
 
612
 
615
 
613
 
616
 
614
 
617
stop:
615
stop:
618
>

616
>