Subversion Repositories Kolibri OS

Rev

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