Subversion Repositories Kolibri OS

Rev

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

Rev 3466 Rev 3468
1
//HTML Viewer in C--
1
//HTML Viewer in C--
2
//Copyright 2007-2012 by Veliant & Leency
2
//Copyright 2007-2012 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\lib.obj\truetype.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
 
23
 
24
 
24
 
25
#define URL param
25
#define URL param
26
int use_truetype = 0;
26
int use_truetype = 0;
27
char fontlol[64];
27
char fontlol[64];
28
 
28
 
29
char editURL[sizeof(URL)],
29
char editURL[sizeof(URL)],
30
	page_links[12000],
30
	page_links[12000],
31
	header[2048];
31
	header[2048];
32
 
32
 
33
struct lines{
33
struct lines{
34
	int visible, all, first, column_max;
34
	int visible, all, first, column_max;
35
};
35
};
36
 
36
 
37
int	mouse_dd;
37
int	mouse_dd;
38
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
38
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};
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};
40
 
40
 
41
 
41
 
42
proc_info Form;
42
proc_info Form;
43
#define WIN_W 640
43
#define WIN_W 640
44
#define WIN_H 480
44
#define WIN_H 480
45
 
45
 
46
 
46
 
47
char stak[512];
47
char stak[512];
48
mouse m;
48
mouse m;
49
 
49
 
50
#include "TWB.h"
50
#include "TWB.h"
51
#include "include\menu_rmb.h"
51
#include "include\menu_rmb.h"
52
 
52
 
53
 
53
 
54
void main()
54
void main()
55
{
55
{
56
	int btn, key;
56
	int btn, key;
57
	int half_scroll_size;
57
	int half_scroll_size;
58
	int scroll_used=0;
58
	int scroll_used=0;
59
	
59
	
60
	mem_Init();
60
	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();}
61
	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);
62
	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);
63
	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("Error: library doesn't exists - TrueType"w); use_truetype = 2; }
64
	if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Warning: library doesn't exists - TrueType"w); use_truetype = 2; }
65
	else init_font(#fontlol);
65
	else init_font(#fontlol);
66
	
66
	
67
	if (!URL) strcpy(#URL, "/sys/home.htm");
67
	if (!URL) strcpy(#URL, "/sys/home.htm");
68
	strcpy(#editURL, #URL);
68
	strcpy(#editURL, #URL);
69
	
69
	
70
	Form.width=WIN_W;
70
	Form.width=WIN_W;
71
	Form.height=WIN_H;
71
	Form.height=WIN_H;
72
	SetElementSizes();
72
	SetElementSizes();
73
	WB1.OpenPage();
73
	WB1.OpenPage();
74
 
74
 
75
	SetEventMask(0x27);
75
	SetEventMask(0x27);
76
	loop()
76
	loop()
77
	{
77
	{
78
		WaitEventTimeout(2);
78
		WaitEventTimeout(2);
79
		switch(EAX & 0xFF)
79
		switch(EAX & 0xFF)
80
		{
80
		{
81
			CASE evMouse:
81
			CASE evMouse:
82
				/*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
82
				/*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
83
				if (lines.first <> scroll1.position)
83
				if (lines.first <> scroll1.position)
84
				{
84
				{
85
					lines.first = scroll1.position;
85
					lines.first = scroll1.position;
86
					WB1.ParseHTML(buf, filesize);
86
					WB1.ParseHTML(buf, filesize);
87
					//break;
87
					//break;
88
				};*/
88
				};*/
89
				
89
				
90
				btn=GetProcessSlot(Form.ID); 
90
				btn=GetProcessSlot(Form.ID); 
91
				IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì
91
				IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì
92
 
92
 
93
				edit_box_mouse stdcall (#address_box);
93
				edit_box_mouse stdcall (#address_box);
94
 
94
 
95
				m.get();
95
				m.get();
96
				
96
				
97
				if (m.pkm) && (m.y>WB1.top) && (m.y
97
				if (m.pkm) && (m.y>WB1.top) && (m.y
98
				{
98
				{
99
					SwitchToAnotherThread();
99
					SwitchToAnotherThread();
100
					CreateThread(#menu_rmb,#stak); 
100
					CreateThread(#menu_rmb,#stak); 
101
				}
101
				}
102
 
102
 
103
				IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
103
				IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
104
				{
104
				{
105
					IF (lines.first==0) break;
105
					IF (lines.first==0) break;
106
					IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
106
					IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
107
					WB1.Scan(ID1);
107
					WB1.Scan(ID1);
108
					break;
108
					break;
109
				} 
109
				} 
110
				IF (m.vert==1)
110
				IF (m.vert==1)
111
				{
111
				{
112
					IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
112
					IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
113
					ELSE	{
113
					ELSE	{
114
						lines.first+=2;
114
						lines.first+=2;
115
						WB1.Scan(ID2);
115
						WB1.Scan(ID2);
116
					}
116
					}
117
					break;
117
					break;
118
				}
118
				}
119
				
119
				
120
				if (!m.lkm) scroll_used=0;
120
				if (!m.lkm) scroll_used=0;
121
				if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16)
121
				if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16)
122
				&& (m.ylines.visible) && (m.lkm)
122
				&& (m.ylines.visible) && (m.lkm)
123
					scroll_used=1;
123
					scroll_used=1;
124
				
124
				
125
				if (scroll_used)
125
				if (scroll_used)
126
				{
126
				{
127
					half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
127
					half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
128
					IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
128
					IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
129
					btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
129
					btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
130
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
130
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
131
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
131
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
132
					if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
132
					if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
133
				}
133
				}
134
 
134
 
135
				break;
135
				break;
136
			case evButton:
136
			case evButton:
137
				btn=GetButtonID();
137
				btn=GetButtonID();
138
				if (btn==1)
138
				if (btn==1)
139
				{
139
				{
140
					KillProcess(downloader_id);
140
					KillProcess(downloader_id);
141
					ExitProcess();
141
					ExitProcess();
142
				}
142
				}
143
				ELSE
143
				ELSE
144
				{
144
				{
145
					WB1.Scan(btn);
145
					WB1.Scan(btn);
146
				}
146
				}
147
				break;
147
				break;
148
			case evKey:
148
			case evKey:
149
				key = GetKey();
149
				key = GetKey();
150
				
150
				
151
				if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
151
				if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
152
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
152
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } 
153
 
153
 
154
				WB1.Scan(key);
154
				WB1.Scan(key);
155
				
155
				
156
				_EDIT_MARK:
156
				_EDIT_MARK:
157
				if (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
157
				if (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
158
				break;
158
				break;
159
			case evReDraw:
159
			case evReDraw:
160
				Draw_Window();
160
				Draw_Window();
161
				break;
161
				break;
162
			default:
162
			default:
163
				if (downloader_id<>0)
163
				if (downloader_id<>0)
164
				{
164
				{
165
					if (GetProcessSlot(downloader_id)<>0) break;
165
					if (GetProcessSlot(downloader_id)<>0) break;
166
					downloader_id=0;
166
					downloader_id=0;
167
					lines.first = lines.all = 0;
167
					lines.first = lines.all = 0;
168
					WB1.ReadHtml(_WIN);
168
					WB1.ReadHtml(_WIN);
169
					Draw_Window();
169
					Draw_Window();
170
				}
170
				}
171
		}
171
		}
172
	}
172
	}
173
}
173
}
174
 
174
 
175
void SetElementSizes()
175
void SetElementSizes()
176
{
176
{
177
	address_box.width = Form.width-266;
177
	address_box.width = Form.width-266;
178
	WB1.top = 44;
178
	WB1.top = 44;
179
	WB1.width = Form.width - 10 - scroll1.size_x;
179
	WB1.width = Form.width - 10 - scroll1.size_x;
180
	WB1.height = Form.height - WB1.top - GetSkinHeight() - 4;
180
	WB1.height = Form.height - WB1.top - GetSkinHeight() - 4;
181
	WB1.line_h = 10;
181
	WB1.line_h = 10;
182
	lines.column_max = WB1.width - 30 / 6;
182
	lines.column_max = WB1.width - 30 / 6;
183
	lines.visible = WB1.height - 3 / WB1.line_h - 2;
183
	lines.visible = WB1.height - 3 / WB1.line_h - 2;
-
 
184
	DrawBufInit();
184
}
185
}
185
 
186
 
186
 
187
 
187
void Draw_Window()
188
void Draw_Window()
188
{
189
{
189
	int j;
190
	int j;
190
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
191
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
191
 
192
 
192
	GetProcessInfo(#Form, SelfInfo);
193
	GetProcessInfo(#Form, SelfInfo);
193
	if (Form.status_window>2)
194
	if (Form.status_window>2)
194
	{
195
	{
195
		DrawTitle(#header);
196
		DrawTitle(#header);
196
		return;
197
		return;
197
	}
198
	}
198
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
199
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
199
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
200
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
200
	
201
	
201
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
202
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
202
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
203
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
203
	
204
	
204
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
205
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
205
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
206
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
206
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
207
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
207
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
208
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
208
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
209
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
209
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
210
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
210
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
211
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
211
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
212
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
212
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
213
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
213
 
214
 
214
	SetElementSizes();
215
	SetElementSizes();
215
	WB1.ShowPage();
216
	WB1.ShowPage();
216
 
217
 
217
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
218
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
218
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
219
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
219
}
220
}
220
 
221
 
221
 
222
 
222
stop:
223
stop: