Subversion Repositories Kolibri OS

Rev

Rev 4554 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4554 Rev 4558
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
//images
28
//images
29
#include "img\toolbar_icons.c"
29
#include "img\toolbar_icons.c"
30
#include "img\URLgoto.txt";
30
#include "img\URLgoto.txt";
31
 
31
 
32
#ifdef LANG_RUS
32
#ifdef LANG_RUS
33
	char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.67";
33
	char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.67";
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
	unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm";
37
	unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm";
38
#else
38
#else
39
	char version[]=" Text-based Browser 0.99.67";
39
	char version[]=" Text-based Browser 0.99.67";
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
	unsigned char page_not_found[] = FROM "html\page_not_found_en.htm";
43
	unsigned char page_not_found[] = FROM "html\page_not_found_en.htm";
44
#endif
44
#endif
45
 
45
 
46
byte native_http=0;
46
byte native_http=0;
47
 
47
 
48
proc_info Form;
48
proc_info Form;
49
#define WIN_W 640
49
#define WIN_W 640
50
#define WIN_H 480
50
#define WIN_H 480
51
 
51
 
52
char search_path[]="http://nigma.ru/index.php?s=";
52
char search_path[]="http://nigma.ru/index.php?s=";
-
 
53
char str_location[]="location\0";
-
 
54
int redirected = 0;
53
 
55
 
54
char stak[4096];
56
char stak[4096];
55
mouse m;
57
mouse m;
56
int action_buf;
58
int action_buf;
57
 
59
 
58
dword http_transfer = 0;
60
dword http_transfer = 0;
59
dword http_buffer;
61
dword http_buffer;
60
 
62
 
61
int	downloader_id;
63
int	downloader_id;
62
 
64
 
63
#include "..\TWB\TWB.c"
65
#include "..\TWB\TWB.c"
64
#include "menu_rmb.h"
66
#include "menu_rmb.h"
65
 
67
 
66
char editURL[sizeof(URL)];
68
char editURL[sizeof(URL)];
67
int	mouse_twb;
69
int	mouse_twb;
68
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
70
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
69
 
71
 
70
#define URL_HISTORY "WebView://history"
72
#define URL_HISTORY "WebView://history"
71
 
73
 
72
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
74
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
73
 
75
 
74
 
76
 
75
void main()
77
void main()
76
{
78
{
77
	int key, btn;
79
	int key, btn;
78
	int half_scroll_size;
80
	int half_scroll_size;
79
	int scroll_used=0, show_menu;
81
	int scroll_used=0, show_menu;
80
	
82
	
81
	mem_Init();
83
	mem_Init();
82
	CursorPointer.Load(#CursorFile);
84
	CursorPointer.Load(#CursorFile);
83
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
85
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
84
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
86
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
85
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
87
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
86
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
88
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
87
	
89
	
88
	if (!URL) strcpy(#URL, "/sys/index.htm");
90
	if (!URL) strcpy(#URL, "/sys/index.htm");
89
	Form.width=WIN_W;
91
	Form.width=WIN_W;
90
	Form.height=WIN_H;
92
	Form.height=WIN_H;
91
	SetElementSizes();
93
	SetElementSizes();
92
	OpenPage();
94
	OpenPage();
93
 
95
 
94
	SetEventMask(0xa7);
96
	SetEventMask(0xa7);
95
	loop()
97
	loop()
96
	{
98
	{
97
		WaitEventTimeout(2);
99
		WaitEventTimeout(2);
98
		switch(EAX & 0xFF)
100
		switch(EAX & 0xFF)
99
		{
101
		{
100
			CASE evMouse:
102
			CASE evMouse:
101
				if (!CheckActiveProcess(Form.ID)) break;
103
				if (!CheckActiveProcess(Form.ID)) break;
102
 
104
 
103
				edit_box_mouse stdcall (#address_box);
105
				edit_box_mouse stdcall (#address_box);
104
 
106
 
105
				m.get();
107
				m.get();
106
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
108
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
107
				
109
				
108
				if (m.y>WB1.list.y) && (m.y
110
				if (m.y>WB1.list.y) && (m.y
109
				{
111
				{
110
					if (m.pkm)
112
					if (m.pkm)
111
					{
113
					{
112
						show_menu = 1;
114
						show_menu = 1;
113
					}
115
					}
114
					if (!m.pkm) && (show_menu)
116
					if (!m.pkm) && (show_menu)
115
					{
117
					{
116
						show_menu = 0;
118
						show_menu = 0;
117
						SwitchToAnotherThread();
119
						SwitchToAnotherThread();
118
						CreateThread(#menu_rmb,#stak+4092);
120
						CreateThread(#menu_rmb,#stak+4092);
119
						break; 
121
						break; 
120
					}
122
					}
121
				}
123
				}
122
 
124
 
123
				if (m.vert)
125
				if (m.vert)
124
				{
126
				{
125
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse(bufpointer, bufsize);
127
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse(bufpointer, bufsize);
126
				}
128
				}
127
				
129
				
128
				if (!m.lkm) scroll_used=0;
130
				if (!m.lkm) scroll_used=0;
129
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) 
131
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) 
130
				&& (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
132
				&& (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
131
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
133
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
132
				{
134
				{
133
					scroll_used=1;
135
					scroll_used=1;
134
				}
136
				}
135
				
137
				
136
				if (scroll_used)
138
				if (scroll_used)
137
				{
139
				{
138
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
140
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
139
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
141
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
140
					btn=WB1.list.first;
142
					btn=WB1.list.first;
141
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
143
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
142
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
144
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
143
					if (btn<>WB1.list.first) WB1.Parse(bufpointer, bufsize);
145
					if (btn<>WB1.list.first) WB1.Parse(bufpointer, bufsize);
144
				}
146
				}
145
 
147
 
146
				break;
148
				break;
147
			case evButton:
149
			case evButton:
148
				btn=GetButtonID();
150
				btn=GetButtonID();
149
				if (btn==1)
151
				if (btn==1)
150
				{
152
				{
151
					KillProcess(downloader_id);
153
					KillProcess(downloader_id);
152
					ExitProcess();
154
					ExitProcess();
153
				}
155
				}
154
				ELSE
156
				ELSE
155
				{
157
				{
156
					Scan(btn);
158
					Scan(btn);
157
				}
159
				}
158
				break;
160
				break;
159
			case evKey:
161
			case evKey:
160
				key = GetKey();
162
				key = GetKey();
161
				
163
				
162
				if (address_box.flags & 0b10) SWITCH(key)
164
				if (address_box.flags & 0b10) SWITCH(key)
163
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
165
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
164
 
166
 
165
				Scan(key);
167
				Scan(key);
166
				
168
				
167
				_EDIT_MARK:
169
				_EDIT_MARK:
168
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
170
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
169
				break;
171
				break;
170
			case evReDraw:
172
			case evReDraw:
171
				if (action_buf) { Scan(action_buf); action_buf=0;}
173
				if (action_buf) { Scan(action_buf); action_buf=0;}
172
				Draw_Window();
174
				Draw_Window();
173
				break;
175
				break;
174
				
176
				
175
			case evNetwork:
177
			case evNetwork:
176
				if (http_transfer > 0) {
178
				if (http_transfer > 0) {
177
					http_process stdcall (http_transfer);
179
					http_process stdcall (http_transfer);
178
					$push EAX
180
					$push EAX
179
					ESI = http_transfer;
181
					ESI = http_transfer;
180
					bufpointer = ESI.http_msg.content_ptr;
182
					bufpointer = ESI.http_msg.content_ptr;
181
					bufsize = ESI.http_msg.content_received;
183
					bufsize = ESI.http_msg.content_received;
182
					WB1.Parse(bufpointer, bufsize);
184
					WB1.Parse(bufpointer, bufsize);
183
					
185
					
184
					$pop EAX	
186
					$pop EAX	
185
					if (EAX == 0) {	
187
					if (EAX == 0) {	
-
 
188
						ESI = http_transfer;
-
 
189
						// Handle redirects
-
 
190
						if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)  {
-
 
191
							redirected++;
-
 
192
							if (redirected<=5) {
-
 
193
								http_find_header_field stdcall (http_transfer, #str_location);
-
 
194
								if (EAX!=0) {
-
 
195
									ESI = EAX;
-
 
196
									EDI = #URL;
-
 
197
									do {
-
 
198
										$lodsb;
-
 
199
										$stosb;
-
 
200
									} while (AL != 0) && (AL != 13) && (AL != 10));
-
 
201
									DSBYTE[EDI-1]='\0';
-
 
202
								}
-
 
203
							} else {
-
 
204
							//TODO: display error (too many redirects)
-
 
205
							}
-
 
206
						} else {
-
 
207
							redirected = 0;
-
 
208
						}
186
						// Loading the page is complete, free resources
209
						// Loading the page is complete, free resources
187
						http_free stdcall (http_transfer);
210
						http_free stdcall (http_transfer);
188
						http_transfer=0;	
211
						http_transfer=0;	
-
 
212
						if (redirected>0) {
-
 
213
							WB1.GetNewUrl();
189
						Draw_Window();		// stop button => refresh button
214
							strcpy(#editURL, #URL);
-
 
215
							OpenPage();
190
					} else {
216
						} else {
191
						// We are still loading the page, this means that because of crappy memory manager,
-
 
192
						// the address of the HTTP data may change. 
217
							Draw_Window();		// stop button => refresh button
193
						// Because this would result in pagefault when redrawing window while loading, we disable this possibility.
-
 
194
						bufsize = 0;
218
						}
195
					}
219
					}
196
				}
220
				}
197
			default:
221
			default:
198
				if (downloader_id<>0)
222
				if (downloader_id<>0)
199
				{
223
				{
200
					if (GetProcessSlot(downloader_id)<>0) break;
224
					if (GetProcessSlot(downloader_id)<>0) break;
201
					downloader_id=0;
225
					downloader_id=0;
202
					WB1.list.first = WB1.list.count = 0;
226
					WB1.list.first = WB1.list.count = 0;
203
					WB1.ReadHtml(_WIN);
227
					WB1.ReadHtml(_WIN);
204
					Draw_Window();
228
					Draw_Window();
205
				}
229
				}
206
		}
230
		}
207
	}
231
	}
208
}
232
}
209
 
233
 
210
void SetElementSizes()
234
void SetElementSizes()
211
{
235
{
212
	address_box.width = Form.width - 266;
236
	address_box.width = Form.width - 266;
213
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
237
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
214
	WB1.list.column_max = WB1.list.w - 30 / 6;
238
	WB1.list.column_max = WB1.list.w - 30 / 6;
215
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
239
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
216
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h);
240
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h);
217
}
241
}
218
 
242
 
219
 
243
 
220
void Draw_Window()
244
void Draw_Window()
221
{
245
{
222
	int j;
246
	int j;
223
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
247
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
224
 
248
 
225
	GetProcessInfo(#Form, SelfInfo);
249
	GetProcessInfo(#Form, SelfInfo);
226
	if (Form.status_window>2)
250
	if (Form.status_window>2)
227
	{
251
	{
228
		DrawTitle(#header);
252
		DrawTitle(#header);
229
		return;
253
		return;
230
	}
254
	}
231
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
255
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
232
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
256
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
233
	
257
	
234
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
258
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
235
	if (GetProcessSlot(downloader_id)<>0) || (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn);
259
	if (GetProcessSlot(downloader_id)<>0) || (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn);
236
	
260
	
237
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
261
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
238
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
262
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
239
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
263
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
240
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
264
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
241
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
265
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
242
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
266
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
243
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
267
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
244
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
268
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
245
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
269
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
246
 
270
 
247
	SetElementSizes();
271
	SetElementSizes();
248
	ShowPage();
272
	ShowPage();
249
 
273
 
250
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
274
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
251
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
275
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
252
}
276
}
253
 
277
 
254
 
278
 
255
void Scan(int id)
279
void Scan(int id)
256
{
280
{
257
	if (id >= 400) ProcessLinks(id);
281
	if (id >= 400) ProcessLinks(id);
258
	
282
	
259
	switch (id)
283
	switch (id)
260
	{
284
	{
261
		case 011: //Ctrk+K 
285
		case 011: //Ctrk+K 
262
			WB1.ReadHtml(_KOI);
286
			WB1.ReadHtml(_KOI);
263
			WB1.Parse(bufpointer, bufsize);
287
			WB1.Parse(bufpointer, bufsize);
264
			return;
288
			return;
265
 
289
 
266
		case 021: //Ctrl+U
290
		case 021: //Ctrl+U
267
			WB1.ReadHtml(_UTF);
291
			WB1.ReadHtml(_UTF);
268
			WB1.Parse(bufpointer, bufsize);
292
			WB1.Parse(bufpointer, bufsize);
269
			return;
293
			return;
270
 
294
 
271
		case 004: //Ctrl+D
295
		case 004: //Ctrl+D
272
			WB1.ReadHtml(_DOS);
296
			WB1.ReadHtml(_DOS);
273
			WB1.Parse(bufpointer, bufsize);
297
			WB1.Parse(bufpointer, bufsize);
274
			return;
298
			return;
275
 
299
 
276
		case 005: //Win encoding
300
		case 005: //Win encoding
277
			WB1.ReadHtml(_WIN);
301
			WB1.ReadHtml(_WIN);
278
			WB1.Parse(bufpointer, bufsize);
302
			WB1.Parse(bufpointer, bufsize);
279
			return;
303
			return;
280
 
304
 
281
		case 009: //free img cache
305
		case 009: //free img cache
282
			ImgCache.Free();
306
			ImgCache.Free();
283
			notify(IMAGES_CACHE_CLEARED);
307
			notify(IMAGES_CACHE_CLEARED);
284
			WB1.Parse(bufpointer, bufsize);
308
			WB1.Parse(bufpointer, bufsize);
285
			return;
309
			return;
286
 
310
 
287
		case 003: //history
311
		case 003: //history
288
			strcpy(#URL, URL_HISTORY);
312
			strcpy(#URL, URL_HISTORY);
289
			OpenPage();
313
			OpenPage();
290
			return;
314
			return;
291
 
315
 
292
		case BACK:
316
		case BACK:
293
			if (!BrowserHistory.GoBack()) return;
317
			if (!BrowserHistory.GoBack()) return;
294
			OpenPage();
318
			OpenPage();
295
			return;
319
			return;
296
		case FORWARD:
320
		case FORWARD:
297
			if (!BrowserHistory.GoForward()) return;
321
			if (!BrowserHistory.GoForward()) return;
298
			OpenPage();
322
			OpenPage();
299
			return;
323
			return;
300
		case 052:  //F3
324
		case 052:  //F3
301
			if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL);
325
			if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL);
302
			else RunProgram("/rd/1/tinypad", #download_path);
326
			else RunProgram("/rd/1/tinypad", #download_path);
303
			return;
327
			return;
304
		case 054: //F5
328
		case 054: //F5
305
			IF(address_box.flags & 0b10) WB1.Parse(bufpointer, bufsize);
329
			IF(address_box.flags & 0b10) WB1.Parse(bufpointer, bufsize);
306
			return;
330
			return;
307
 
331
 
308
		case REFRESH:
332
		case REFRESH:
309
			if (http_transfer<>0)
333
			if (http_transfer<>0)
310
			{
334
			{
311
				EAX = http_transfer;
335
				EAX = http_transfer;
312
				EAX = EAX.http_msg.content_ptr;		// get pointer to data
336
				EAX = EAX.http_msg.content_ptr;		// get pointer to data
313
				$push	EAX							// save it on the stack
337
				$push	EAX							// save it on the stack
314
				http_free stdcall (http_transfer);	// abort connection
338
				http_free stdcall (http_transfer);	// abort connection
315
				$pop	EAX							
339
				$pop	EAX							
316
				mem_Free(EAX);						// free data
340
				mem_Free(EAX);						// free data
317
				http_transfer=0;
341
				http_transfer=0;
318
				bufsize = 0;
342
				bufsize = 0;
319
			}
343
			}
320
			if (GetProcessSlot(downloader_id)<>0)
344
			if (GetProcessSlot(downloader_id)<>0)
321
			{
345
			{
322
				KillProcess(downloader_id);
346
				KillProcess(downloader_id);
323
				pause(20);
347
				pause(20);
324
				Draw_Window();
348
				Draw_Window();
325
				return;
349
				return;
326
			}
350
			}
327
			anchor_line_num=WB1.list.first;
351
			anchor_line_num=WB1.list.first;
328
			anchor[0]='|';
352
			anchor[0]='|';
329
			OpenPage();
353
			OpenPage();
330
			return;
354
			return;
331
		case 014:
355
		case 014:
332
		case 020:
356
		case 020:
333
		case NEWTAB:
357
		case NEWTAB:
334
			MoveSize(190,80,OLD,OLD);
358
			MoveSize(190,80,OLD,OLD);
335
			RunProgram(#program_path, #URL);
359
			RunProgram(#program_path, #URL);
336
			return;
360
			return;
337
			
361
			
338
		case HOME:
362
		case HOME:
339
			strcpy(#editURL, "http://kolibrios.org/en/index.htm");
363
			strcpy(#editURL, "http://kolibrios.org/en/index.htm");
340
		case GOTOURL:
364
		case GOTOURL:
341
		case 0x0D: //enter
365
		case 0x0D: //enter
342
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
366
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
343
			strcat(#URL, #editURL);
367
			strcat(#URL, #editURL);
344
			OpenPage();
368
			OpenPage();
345
			return;
369
			return;
346
		case SEARCHWEB:
370
		case SEARCHWEB:
347
			strcpy(#URL, #search_path);
371
			strcpy(#URL, #search_path);
348
			strcat(#URL, #editURL);
372
			strcat(#URL, #editURL);
349
			OpenPage();
373
			OpenPage();
350
			return;
374
			return;
351
 
375
 
352
		case 183: //PgDown
376
		case 183: //PgDown
353
			if (WB1.list.count < WB1.list.visible) return;
377
			if (WB1.list.count < WB1.list.visible) return;
354
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
378
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
355
			WB1.list.first += WB1.list.visible + 2;
379
			WB1.list.first += WB1.list.visible + 2;
356
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
380
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
357
			WB1.Parse(bufpointer, bufsize);
381
			WB1.Parse(bufpointer, bufsize);
358
			return;
382
			return;
359
 
383
 
360
		case 184: //PgUp
384
		case 184: //PgUp
361
			if (WB1.list.count < WB1.list.visible) return;
385
			if (WB1.list.count < WB1.list.visible) return;
362
			IF(WB1.list.first == 0) return;
386
			IF(WB1.list.first == 0) return;
363
			WB1.list.first -= WB1.list.visible - 2;
387
			WB1.list.first -= WB1.list.visible - 2;
364
			IF(WB1.list.first < 0) WB1.list.first = 0;
388
			IF(WB1.list.first < 0) WB1.list.first = 0;
365
			WB1.Parse(bufpointer, bufsize);
389
			WB1.Parse(bufpointer, bufsize);
366
			return;
390
			return;
367
 
391
 
368
		case 178:
392
		case 178:
369
		case BTN_UP:
393
		case BTN_UP:
370
			if (WB1.list.first <= 0) return;
394
			if (WB1.list.first <= 0) return;
371
			WB1.list.first--;
395
			WB1.list.first--;
372
			WB1.Parse(bufpointer, bufsize);
396
			WB1.Parse(bufpointer, bufsize);
373
			return;
397
			return;
374
 
398
 
375
		case 177: 
399
		case 177: 
376
		case BTN_DOWN:
400
		case BTN_DOWN:
377
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
401
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
378
			WB1.list.first++;
402
			WB1.list.first++;
379
			WB1.Parse(bufpointer, bufsize);
403
			WB1.Parse(bufpointer, bufsize);
380
			return;
404
			return;
381
 
405
 
382
		case 180: //home
406
		case 180: //home
383
			if (WB1.list.KeyHome()) WB1.Parse(bufpointer, bufsize);
407
			if (WB1.list.KeyHome()) WB1.Parse(bufpointer, bufsize);
384
			return; 
408
			return; 
385
 
409
 
386
		case 181: //end
410
		case 181: //end
387
			if (WB1.list.count < WB1.list.visible) return;
411
			if (WB1.list.count < WB1.list.visible) return;
388
			if (WB1.list.KeyEnd()) WB1.Parse(bufpointer, bufsize);
412
			if (WB1.list.KeyEnd()) WB1.Parse(bufpointer, bufsize);
389
			return;
413
			return;
390
	}
414
	}
391
}
415
}
392
 
416
 
393
 
417
 
394
 
418
 
395
void ProcessLinks(int id)
419
void ProcessLinks(int id)
396
{
420
{
397
	strcpy(#URL, PageLinks.GetURL(id-401));	
421
	strcpy(#URL, PageLinks.GetURL(id-401));	
398
	//$1 - Condition Script
422
	//$1 - Condition Script
399
	if (URL[0] == '$')
423
	if (URL[0] == '$')
400
	{
424
	{
401
		if (URL[1]=='-') && (condition_href) condition_href--;
425
		if (URL[1]=='-') && (condition_href) condition_href--;
402
		if (URL[1]=='+') 
426
		if (URL[1]=='+') 
403
		{
427
		{
404
			if (condition_href
428
			if (condition_href
405
		}
429
		}
406
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
430
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
407
		strcpy(#URL, BrowserHistory.CurrentUrl());
431
		strcpy(#URL, BrowserHistory.CurrentUrl());
408
		ShowPage();
432
		ShowPage();
409
		return;
433
		return;
410
	}
434
	}
411
	//#1
435
	//#1
412
	if (URL[0] == '#')
436
	if (URL[0] == '#')
413
	{
437
	{
414
		strcpy(#anchor, #URL+strrchr(#URL, '#'));		
438
		strcpy(#anchor, #URL+strrchr(#URL, '#'));		
415
		strcpy(#URL, BrowserHistory.CurrentUrl());
439
		strcpy(#URL, BrowserHistory.CurrentUrl());
416
		WB1.list.first=WB1.list.count-WB1.list.visible;
440
		WB1.list.first=WB1.list.count-WB1.list.visible;
417
		ShowPage();
441
		ShowPage();
418
		return;
442
		return;
419
	}
443
	}
420
	//liner.ru#1
444
	//liner.ru#1
421
	if (strrchr(#URL, '#')!=-1)
445
	if (strrchr(#URL, '#')!=-1)
422
	{
446
	{
423
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
447
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
424
		URL[strrchr(#URL, '#')-1] = 0x00;
448
		URL[strrchr(#URL, '#')-1] = 0x00;
425
	}
449
	}
426
	
450
	
427
	WB1.GetNewUrl();
451
	WB1.GetNewUrl();
428
	
452
	
429
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
453
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
430
	{
454
	{
431
		//if (strstr(#URL,"http:")) 
455
		//if (strstr(#URL,"http:")) 
432
		RunProgram("/sys/media/kiv", #URL);
456
		RunProgram("/sys/media/kiv", #URL);
433
		strcpy(#editURL, BrowserHistory.CurrentUrl());
457
		strcpy(#editURL, BrowserHistory.CurrentUrl());
434
		strcpy(#URL, BrowserHistory.CurrentUrl());
458
		strcpy(#URL, BrowserHistory.CurrentUrl());
435
		return;
459
		return;
436
	}
460
	}
437
	if (!strcmpn(#URL,"mailto:", 7))
461
	if (!strcmpn(#URL,"mailto:", 7))
438
	{
462
	{
439
		notify(#URL);
463
		notify(#URL);
440
		strcpy(#editURL, BrowserHistory.CurrentUrl());
464
		strcpy(#editURL, BrowserHistory.CurrentUrl());
441
		strcpy(#URL, BrowserHistory.CurrentUrl());
465
		strcpy(#URL, BrowserHistory.CurrentUrl());
442
		return;
466
		return;
443
	}
467
	}
444
 
468
 
445
	OpenPage();
469
	OpenPage();
446
	return;
470
	return;
447
}
471
}
448
 
472
 
449
void OpenPage()
473
void OpenPage()
450
{
474
{
451
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
475
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
452
	KillProcess(downloader_id);
476
	KillProcess(downloader_id);
453
	strcpy(#editURL, #URL);
477
	strcpy(#editURL, #URL);
454
	BrowserHistory.AddUrl();
478
	BrowserHistory.AddUrl();
455
	strcpy(#header, #version);
479
	strcpy(#header, #version);
456
	pre_text =0;
480
	pre_text =0;
457
	if (!strncmp(#URL,"http:",5))
481
	if (!strncmp(#URL,"http:",5))
458
	{
482
	{
459
		if (native_http)
483
		if (native_http)
460
		{
484
		{
461
			http_get stdcall (#URL, 0);	
485
			http_get stdcall (#URL, 0);	
462
			http_transfer = EAX;
486
			http_transfer = EAX;
463
			IF (http_transfer < 0) notify("Error from HTTP lib");
487
			IF (http_transfer < 0) notify("Error from HTTP lib");
464
		}
488
		}
465
		else
489
		else
466
		{
490
		{
467
			KillProcess(downloader_id);
491
			KillProcess(downloader_id);
468
			DeleteFile(#download_path);
492
			DeleteFile(#download_path);
469
			downloader_id = RunProgram("/sys/network/downloader", #URL);
493
			downloader_id = RunProgram("/sys/network/downloader", #URL);
470
			IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
494
			IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
471
		}
495
		}
472
		Draw_Window();
496
		Draw_Window();
473
		return;
497
		return;
474
	}
498
	}
475
	WB1.list.first = WB1.list.count =0;
499
	WB1.list.first = WB1.list.count =0;
476
	WB1.ReadHtml(_WIN);
500
	WB1.ReadHtml(_WIN);
477
	ShowPage();
501
	ShowPage();
478
}
502
}
479
 
503
 
480
void ShowPage()
504
void ShowPage()
481
{
505
{
482
	address_box.size = address_box.pos = strlen(#editURL);
506
	address_box.size = address_box.pos = strlen(#editURL);
483
	address_box.offset=0;
507
	address_box.offset=0;
484
	edit_box_draw stdcall(#address_box);
508
	edit_box_draw stdcall(#address_box);
485
 
509
 
486
	if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else
510
	if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else
487
	if (!bufsize)
511
	if (!bufsize)
488
	{
512
	{
489
		PageLinks.Clear();
513
		PageLinks.Clear();
490
		if (GetProcessSlot(downloader_id)<>0)
514
		if (GetProcessSlot(downloader_id)<>0)
491
			WB1.Parse(#loading, sizeof(loading));
515
			WB1.Parse(#loading, sizeof(loading));
492
		else
516
		else
493
			WB1.Parse(#page_not_found, sizeof(page_not_found));
517
			WB1.Parse(#page_not_found, sizeof(page_not_found));
494
	}
518
	}
495
	else
519
	else
496
		WB1.Parse(bufpointer, bufsize);
520
		WB1.Parse(bufpointer, bufsize);
497
 
521
 
498
	if (!header) strcpy(#header, #version);
522
	if (!header) strcpy(#header, #version);
499
	if (!strcmp(#version, #header)) DrawTitle(#header);
523
	if (!strcmp(#version, #header)) DrawTitle(#header);
500
}
524
}
501
 
525
 
502
ShowHistory()
526
ShowHistory()
503
{
527
{
504
		int i;
528
		int i;
505
		static int history_pointer;
529
		static int history_pointer;
506
		
530
		
507
		free(history_pointer);
531
		free(history_pointer);
508
		history_pointer = malloc(64000);
532
		history_pointer = malloc(64000);
509
		strcat(history_pointer, " History

History

");
533
		strcat(history_pointer, " History

History

");
510
		strcat(history_pointer, "

Visited pages


");
534
		strcat(history_pointer, "

Visited pages


");
511
		for (i=1; i
535
		for (i=1; i
512
		{
536
		{
513
			strcat(history_pointer, "
514
			strcat(history_pointer, BrowserHistory.GetUrl(i));
538
			strcat(history_pointer, BrowserHistory.GetUrl(i));
515
			strcat(history_pointer, "'>");
539
			strcat(history_pointer, "'>");
516
			strcat(history_pointer, BrowserHistory.GetUrl(i));
540
			strcat(history_pointer, BrowserHistory.GetUrl(i));
517
			strcat(history_pointer, "
");
541
			strcat(history_pointer, "
");
518
		}
542
		}
519
		strcat(history_pointer, "

Cached images


");
543
		strcat(history_pointer, "

Cached images


");
520
		for (i=1; i
544
		for (i=1; i
521
		{
545
		{
522
			strcat(history_pointer, "
523
			strcat(history_pointer, #pics[i].path);
547
			strcat(history_pointer, #pics[i].path);
524
			strcat(history_pointer, "' />
");
548
			strcat(history_pointer, "' />
");
525
			strcat(history_pointer, #pics[i].path);
549
			strcat(history_pointer, #pics[i].path);
526
		}
550
		}
527
		bufpointer = history_pointer;
551
		bufpointer = history_pointer;
528
		WB1.Parse(history_pointer, strlen(history_pointer));
552
		WB1.Parse(history_pointer, strlen(history_pointer));
529
}
553
}
530
 
554
 
531
 
555
 
532
stop:





556
stop: