Subversion Repositories Kolibri OS

Rev

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

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