Subversion Repositories Kolibri OS

Rev

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