Subversion Repositories Kolibri OS

Rev

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

Rev 3990 Rev 4026
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
//libraries
6
//libraries
7
#define MEMSIZE 0x100000
7
#define MEMSIZE 0x100000
8
#include "..\lib\kolibri.h"
8
#include "..\lib\kolibri.h"
9
#include "..\lib\strings.h"
9
#include "..\lib\strings.h"
10
#include "..\lib\figures.h"
10
#include "..\lib\figures.h"
11
#include "..\lib\encoding.h"
11
#include "..\lib\encoding.h"
12
#include "..\lib\file_system.h"
12
#include "..\lib\file_system.h"
13
#include "..\lib\mem.h"
13
#include "..\lib\mem.h"
14
#include "..\lib\dll.h"
14
#include "..\lib\dll.h"
15
//*.obj libraries
15
//*.obj libraries
16
#include "..\lib\lib.obj\box_lib.h"
16
#include "..\lib\lib.obj\box_lib.h"
17
#include "..\lib\lib.obj\libio_lib.h"
17
#include "..\lib\lib.obj\libio_lib.h"
18
#include "..\lib\lib.obj\libimg_lib.h"
18
#include "..\lib\lib.obj\libimg_lib.h"
19
#include "..\lib\lib.obj\truetype.h"
19
#include "..\lib\list_box.h"
20
//images
20
//images
21
#include "img\toolbar_icons.c"
21
#include "img\toolbar_icons.c"
22
#include "img\URLgoto.txt";
22
#include "img\URLgoto.txt";
-
 
23
 
-
 
24
#ifndef AUTOBUILD
-
 
25
	#include "lang.h--"
-
 
26
#endif
-
 
27
 
-
 
28
#ifdef LANG_RUS
-
 
29
	char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.08";
-
 
30
	?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
-
 
31
#else
-
 
32
	char version[]=" Text-based Browser 0.99.08";
-
 
33
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
-
 
34
#endif
23
 
35
 
24
 
-
 
25
#define URL param
36
 
26
int use_truetype = 0;
37
#define URL param
27
char fontlol[64];
38
char fontlol[64];
28
 
39
 
29
char editURL[sizeof(URL)],
40
char editURL[sizeof(URL)],
30
	page_links[12000],
41
	page_links[12000],
31
	header[2048];
42
	header[2048];
32
 
43
 
33
struct lines{
44
struct lines{
34
	int visible, all, first, column_max;
45
	int visible, all, first, column_max;
35
};
46
};
36
 
47
 
37
int	mouse_dd;
48
int	mouse_dd;
38
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
49
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
39
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
50
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
40
 
51
 
41
 
52
 
42
proc_info Form;
53
proc_info Form;
43
#define WIN_W 640
54
#define WIN_W 640
44
#define WIN_H 480
55
#define WIN_H 480
45
 
56
 
46
 
57
 
47
char stak[512];
58
char stak[512];
48
mouse m;
59
mouse m;
-
 
60
 
-
 
61
int action_buf;
49
 
62
 
50
#include "TWB.h"
63
#include "TWB.h"
51
#include "include\menu_rmb.h"
64
#include "include\menu_rmb.h"
52
 
65
 
53
 
66
 
54
void main()
67
void main()
55
{
68
{
56
	int btn, key;
69
	int btn, key;
57
	int half_scroll_size;
70
	int half_scroll_size;
58
	int scroll_used=0;
71
	int scroll_used=0, show_menu;
59
	
72
	
60
	mem_Init();
73
	mem_Init();
61
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
74
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
62
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
75
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
63
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
76
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
64
	if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Warning: library doesn't exists - TrueType"w); use_truetype = 2; }
-
 
65
	else init_font(#fontlol);
-
 
66
	
77
	
67
	if (!URL) strcpy(#URL, "/sys/index.htm");
78
	if (!URL) strcpy(#URL, "/sys/index.htm");
68
	strcpy(#editURL, #URL);
79
	strcpy(#editURL, #URL);
69
	
80
	
70
	Form.width=WIN_W;
81
	Form.width=WIN_W;
71
	Form.height=WIN_H;
82
	Form.height=WIN_H;
72
	SetElementSizes();
83
	SetElementSizes();
73
	WB1.OpenPage();
84
	WB1.OpenPage();
74
 
85
 
75
	SetEventMask(0x27);
86
	SetEventMask(0x27);
76
	loop()
87
	loop()
77
	{
88
	{
78
		WaitEventTimeout(2);
89
		WaitEventTimeout(2);
79
		switch(EAX & 0xFF)
90
		switch(EAX & 0xFF)
80
		{
91
		{
81
			CASE evMouse:
92
			CASE evMouse:
82
				/*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
93
				/*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
83
				if (lines.first <> scroll1.position)
94
				if (lines.first <> scroll1.position)
84
				{
95
				{
85
					lines.first = scroll1.position;
96
					lines.first = scroll1.position;
86
					WB1.ParseHTML(buf, filesize);
97
					WB1.ParseHTML(buf, filesize);
87
					//break;
98
					//break;
88
				};*/
99
				};*/
89
				
100
				
90
				btn=GetProcessSlot(Form.ID); 
101
				btn=GetProcessSlot(Form.ID); 
91
				if (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì
102
				if (btn<>GetActiveProcess()) break;
92
 
103
 
93
				edit_box_mouse stdcall (#address_box);
104
				edit_box_mouse stdcall (#address_box);
94
 
105
 
95
				m.get();
106
				m.get();
96
				
107
				
97
				if (m.pkm) && (m.y>WB1.top) && (m.y
108
				if (m.y>WB1.top) && (m.y
-
 
109
				{
-
 
110
					if (m.pkm)
-
 
111
					{
-
 
112
						show_menu = 1;
-
 
113
					}
-
 
114
					if (!m.pkm) && (show_menu)
-
 
115
					{
98
				{
116
						show_menu = 0;
99
					SwitchToAnotherThread();
117
						SwitchToAnotherThread();
100
					CreateThread(#menu_rmb,#stak);
118
						CreateThread(#menu_rmb,#stak);
101
					break; 
119
						break; 
102
				}
120
					}
-
 
121
				}
103
 
122
 
104
				if (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
123
				if (m.vert==65535)
105
				{
124
				{
106
					if (lines.first==0) break;
125
					if (lines.first==0) break;
107
					if (lines.first>3) lines.first-=2; ELSE lines.first=1;
126
					if (lines.first>3) lines.first-=2; ELSE lines.first=1;
108
					WB1.Scan(ID1);
127
					WB1.Scan(ID1);
109
					break;
128
					break;
110
				} 
129
				} 
111
				if (m.vert==1)
130
				if (m.vert==1)
112
				{
131
				{
113
					if(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
132
					if(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
-
 
133
					else
114
					ELSE	{
134
					{
115
						lines.first+=2;
135
						lines.first+=2;
116
						WB1.Scan(ID2);
136
						WB1.Scan(ID2);
117
					}
137
					}
118
					break;
138
					break;
119
				}
139
				}
120
				
140
				
121
				if (!m.lkm) scroll_used=0;
141
				if (!m.lkm) scroll_used=0;
122
				if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x) 
142
				if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x) 
123
					&& (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
143
				&& (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
124
					&& (lines.all>lines.visible) && (m.lkm)
144
				&& (lines.all>lines.visible) && (m.lkm)
125
					{
145
				{
126
						scroll_used=1;
146
					scroll_used=1;
127
					}
147
				}
128
				
148
				
129
				if (scroll_used)
149
				if (scroll_used)
130
				{
150
				{
131
					half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
151
					half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
132
					if (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
152
					if (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
133
					btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
153
					btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
134
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
154
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
135
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
155
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
136
					if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
156
					if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
137
				}
157
				}
138
 
158
 
139
				break;
159
				break;
140
			case evButton:
160
			case evButton:
141
				btn=GetButtonID();
161
				btn=GetButtonID();
142
				if (btn==1)
162
				if (btn==1)
143
				{
163
				{
144
					KillProcess(downloader_id);
164
					KillProcess(downloader_id);
145
					ExitProcess();
165
					ExitProcess();
146
				}
166
				}
147
				ELSE
167
				ELSE
148
				{
168
				{
149
					WB1.Scan(btn);
169
					WB1.Scan(btn);
150
				}
170
				}
151
				break;
171
				break;
152
			case evKey:
172
			case evKey:
153
				key = GetKey();
173
				key = GetKey();
154
				
174
				
155
				if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
175
				if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
156
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
176
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
157
 
177
 
158
				WB1.Scan(key);
178
				WB1.Scan(key);
159
				
179
				
160
				_EDIT_MARK:
180
				_EDIT_MARK:
161
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
181
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
162
				break;
182
				break;
163
			case evReDraw:
183
			case evReDraw:
-
 
184
				if (action_buf) { WB1.Scan(action_buf); action_buf=0;}
164
				Draw_Window();
185
				Draw_Window();
165
				break;
186
				break;
166
			default:
187
			default:
167
				if (downloader_id<>0)
188
				if (downloader_id<>0)
168
				{
189
				{
169
					if (GetProcessSlot(downloader_id)<>0) break;
190
					if (GetProcessSlot(downloader_id)<>0) break;
170
					downloader_id=0;
191
					downloader_id=0;
171
					lines.first = lines.all = 0;
192
					lines.first = lines.all = 0;
172
					WB1.ReadHtml(_WIN);
193
					WB1.ReadHtml(_WIN);
173
					Draw_Window();
194
					Draw_Window();
174
				}
195
				}
175
		}
196
		}
176
	}
197
	}
177
}
198
}
178
 
199
 
179
void SetElementSizes()
200
void SetElementSizes()
180
{
201
{
181
	address_box.width = Form.width-266;
202
	address_box.width = Form.width-266;
182
	WB1.top = 44;
203
	WB1.top = 44;
183
	WB1.width = Form.width - 10 - scroll1.size_x;
204
	WB1.width = Form.width - 10 - scroll1.size_x;
184
	WB1.height = Form.height - WB1.top - GetSkinHeight() - 4;
205
	WB1.height = Form.height - WB1.top - GetSkinHeight() - 4;
185
	WB1.line_h = 10;
206
	WB1.line_h = 10;
186
	lines.column_max = WB1.width - 30 / 6;
207
	lines.column_max = WB1.width - 30 / 6;
187
	lines.visible = WB1.height - 3 / WB1.line_h - 2;
208
	lines.visible = WB1.height - 3 / WB1.line_h - 2;
188
	DrawBufInit();
209
	DrawBufInit();
189
}
210
}
190
 
211
 
191
 
212
 
192
void Draw_Window()
213
void Draw_Window()
193
{
214
{
194
	int j;
215
	int j;
195
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
216
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
196
 
217
 
197
	GetProcessInfo(#Form, SelfInfo);
218
	GetProcessInfo(#Form, SelfInfo);
198
	if (Form.status_window>2)
219
	if (Form.status_window>2)
199
	{
220
	{
200
		DrawTitle(#header);
221
		DrawTitle(#header);
201
		return;
222
		return;
202
	}
223
	}
203
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
224
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
204
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
225
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
205
	
226
	
206
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
227
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
207
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
228
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
208
	
229
	
209
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
230
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
210
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
231
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
211
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
232
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
212
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
233
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
213
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
234
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
214
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
235
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
215
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
236
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
216
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
237
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
217
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
238
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
218
 
239
 
219
	SetElementSizes();
240
	SetElementSizes();
220
	WB1.ShowPage();
241
	WB1.ShowPage();
221
 
242
 
222
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
243
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
223
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
244
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
224
}
245
}
225
 
246
 
226
 
247
 
227
stop:
248
stop: