Subversion Repositories Kolibri OS

Rev

Rev 3081 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3067 leency 1
//HTML Viewer in C--
2
//Copyright 2007-2012 by Veliant & Leency
3107 leency 3
//Asper, lev, Lrz, Barsuk, Nable...
3067 leency 4
//home icon - rachel fu, GPL licence
5
 
3107 leency 6
//libraries
3067 leency 7
#include "..\lib\kolibri.h"
8
#include "..\lib\strings.h"
9
#include "..\lib\figures.h"
10
#include "..\lib\encoding.h"
11
#include "..\lib\file_system.h"
12
#include "..\lib\mem.h"
13
#include "..\lib\dll.h"
3107 leency 14
//*.obj libraries
15
#include "..\lib\lib.obj\box_lib.h"
16
#include "..\lib\lib.obj\libio_lib.h"
17
#include "..\lib\lib.obj\libimg_lib.h"
18
#include "..\lib\lib.obj\truetype.h"
19
//images
3067 leency 20
#include "img\toolbar_icons.c"
21
#include "img\URLgoto.txt";
22
 
23
 
24
#define URL param
25
int use_truetype = 0;
26
 
27
char editURL[sizeof(URL)],
28
	page_links[12000],
29
	header[300];
30
 
31
struct lines{
32
	int visible, all, first, column_max;
33
};
34
 
35
int	mouse_dd;
36
edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
37
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}; //details in scroll_lib.h--
38
 
39
 
40
proc_info Form;
41
#define WIN_W 640
42
#define WIN_H 480
43
 
44
 
45
dword stak[100]; //меню ПКМ
46
mouse m;
47
 
48
#include "TWB.h"
49
#include "include\menu_rmb.h"
50
 
51
 
52
void tre()
53
{
54
	char *font_picture;
55
	char text[20];
56
	int width=600;
57
	int height=20;
58
//	char palette[256*4];
59
	int x;
60
 
61
	text_out stdcall ("hello world\0",#fontlol, 17, 0x0, 10, 10);
62
	text_out stdcall ("heyeyey!\0",#fontlol, 27, 0x0, 10, 30);
63
	text_out stdcall ("alarm!\0", #fontlol, 47, 0x00FF0000, 10, 70);
64
	/*
65
	strcpy(#text, "hello world\0");
66
 
67
	debug("get width\n");
68
	get_width stdcall (#text, #fontinfo, height);
69
	width=EAX;
70
	for (x=0;x<20;x++)  {
71
	init_font(#fontinfo);
72
	debug("yaya\n");
73
	font_picture=mem_Alloc(width*height);
74
	text[1]=30+x;
75
	truetype stdcall (#text, #fontinfo, font_picture,  width, height);
76
 
77
	debug("blyad'!\n");
78
 
79
 
80
 
81
	PutPaletteImage(font_picture,width,height,0,20*x,8,#palette);
82
	mem_Free(font_picture); }*/
83
}
84
 
85
char fontlol[64];
86
 
87
void main()
88
{
89
	int btn;
90
	byte key;
91
	int half_scroll_size;
92
	int scroll_used=0;
93
 
94
	mem_Init();
3107 leency 95
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
96
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
97
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
98
	if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Error: library doesn't exists - TrueType"w); use_truetype = 2; }
3067 leency 99
	else init_font(#fontlol);
100
 
101
	if (!URL) strcpy(#URL, "/sys/home.htm");
102
	strcpy(#editURL, #URL);
103
 
104
	Form.width=WIN_W;
105
	Form.height=WIN_H;
106
 
107
	SetElementSizes();
108
 
109
	WB1.OpenPage();
110
 
111
	SetEventMask(0x27);
112
	loop()
113
	{
114
		WaitEventTimeout(2);
115
		switch(EAX & 0xFF)
116
		{
117
			CASE evMouse:
118
				/*scrollbar_v_mouse (#scroll1);      //конченый скролл притормажимает, идём "своим путём"
119
				if (lines.first <> scroll1.position)
120
				{
121
					lines.first = scroll1.position;
122
					WB1.ParseHTML(buf, filesize);
123
					//break;
124
				};*/
125
 
126
				btn=GetProcessSlot(Form.ID);
127
				IF (btn<>GetActiveProcess()) break; //если окно не активно на события мыши не реагируем
128
 
129
				edit_box_mouse stdcall (#edit1);
130
 
131
				m.get();
132
 
133
				if (m.pkm) && (m.y>WB1.top) && (m.y
134
				{
135
					SwitchToAnotherThread();
136
					CreateThread(#menu_rmb,#stak);
137
				}
138
 
139
				IF (m.vert==65535) //прокрутка колёсиком
140
				{
141
					IF (lines.first==0) break;
142
					IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
143
					WB1.Scan(ID1);
144
					break;
145
				}
146
				IF (m.vert==1)
147
				{
148
					IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
149
					ELSE	{
150
						lines.first+=2;
151
						WB1.Scan(ID2);
152
					}
153
					break;
154
				}
155
 
156
				if (!m.lkm) scroll_used=0;
157
				if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16)
158
				&& (m.ylines.visible) && (m.lkm)
159
					scroll_used=1;
160
 
161
				if (scroll_used)
162
				{
163
					half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
164
					IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //если курсор над окном
165
					btn=lines.first; //сохраняем старое количество
166
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
167
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
168
					if (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать
169
				}
170
 
171
				break;
172
			case evButton:
173
				btn=GetButtonID();
174
				IF (btn==1)
175
				{
176
					KillProcess(downloader_id);
177
					ExitProcess();
178
				}
179
				ELSE
180
				{
181
					WB1.Scan(btn);
182
				}
183
				break;
184
			case evKey:
185
				key = GetKey();
186
 
3081 leency 187
				if (edit1.flags  & 0b10) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки
3067 leency 188
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
189
 
190
				WB1.Scan(key);
191
 
192
				_EDIT_MARK:
193
				IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //адресная строка
194
				break;
195
			case evReDraw:
196
				Draw_Window();
197
				break;
198
			default:
199
				if (downloader_id<>0)
200
				{
201
					if (GetProcessSlot(downloader_id)<>0) break;
202
					downloader_id=0;
203
					lines.first = lines.all = 0;
204
					WB1.ReadHtml(_WIN);
205
					Draw_Window();
206
				}
207
		}
208
	}
209
}
210
 
211
void SetElementSizes()
212
{
213
	edit1.width=Form.width-266;
214
	WB1.top=44;
215
	WB1.width=Form.width-13;
216
	WB1.height=onTop(43,5);
217
	lines.column_max = WB1.width - 30 / 6;
218
	lines.visible = WB1.height - 3 / 10 - 2;
219
}
220
 
221
 
222
void Draw_Window()
223
{
224
	int j;
225
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0,0);
226
 
227
	GetProcessInfo(#Form, SelfInfo);
228
	if (Form.status_window>2) //если свернуто в заголовок, ничего не рисуем
229
	{
230
		DrawTitle(#header);
231
		return;
232
	}
233
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
234
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
235
 
236
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
237
	if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10);
238
 
239
	DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //закрашиваем фон под тулбаром
240
	DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //выпуклость
241
	DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //выпуклость
242
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
243
	PutImage(#URLgoto,40,19,onLeft(57,0),14);
244
	DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
245
	DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
246
	DrawRectangle(205,14,onLeft(58,205),18,0x94AECE); //ободок полосы адреса
247
	DrawRectangle(206,15,onLeft(59,205),16,0xE4ECF3);
248
 
249
	SetElementSizes();
250
	WB1.ShowPage();
251
	//tre();
252
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
253
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
254
}
255
 
256
int onLeft(dword right,left) {return Form.width-right-left;}
257
int onTop(dword down,up) {return Form.height-GetSkinHeight()-down-up;}
258
 
259
 
260
stop: