Subversion Repositories Kolibri OS

Rev

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

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

539
>