Subversion Repositories Kolibri OS

Rev

Rev 2840 | 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"
2818 leency 17
#include "..\lib\ttf_fonts.h"
18
//картинки
19
#include "img\toolbar_icons.c"
20
#include "img\URLgoto.txt";
2811 leency 21
 
2818 leency 22
 
2844 leency 23
#define URL param
24
 
25
char editURL[4096],
2811 leency 26
	page_links[12000],
2840 leency 27
	header[300];
2811 leency 28
 
29
struct lines{
30
	int visible, all, first, column_max;
31
};
32
 
33
int	mouse_dd;
34
edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,248,#editURL,#mouse_dd,2,19,19};
35
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--
36
 
2844 leency 37
 
2811 leency 38
proc_info Form;
2844 leency 39
#define WIN_W 640
40
#define WIN_H 480
41
 
42
 
2811 leency 43
dword stak[100]; //меню ПКМ
44
mouse m;
45
 
46
#include "TWB.h"
47
#include "include\menu_rmb.h"
48
 
49
 
50
void main()
51
{
52
	int btn;
53
	byte key;
54
	int half_scroll_size;
55
 
56
	mem_Init();
57
	load_dll2(libio, #libio_init,1);
58
	load_dll2(libimg, #libimg_init,1);
59
	load_dll2(boxlib, #edit_box_draw,0);
60
	load_dll2(#abox_lib, #boxlib_init,0);
2818 leency 61
	//load_dll2(libtruetype, #truetype,0);
2811 leency 62
 
2844 leency 63
	if (!URL) strcpy(#URL, "/sys/index.htm");
2811 leency 64
	strcpy(#editURL, #URL);
65
 
2844 leency 66
	Form.width=WIN_W;
67
	Form.height=WIN_H;
68
 
69
	SetElementSizes();
70
 
2811 leency 71
	WB1.OpenPage();
72
 
73
	SetEventMask(0x27);
74
	loop()
75
	{
76
		WaitEventTimeout(2);
77
		switch(EAX & 0xFF)
78
		{
79
			CASE evMouse:
80
				/*scrollbar_v_mouse (#scroll1);      //конченый скролл притормажимает, идём "своим путём"
81
				if (lines.first <> scroll1.position)
82
				{
83
					lines.first = scroll1.position;
84
					WB1.ParseHTML(buf, filesize);
85
					//break;
86
				};*/
87
 
2825 leency 88
				btn=GetProcessSlot(Form.ID);
89
				IF (btn<>GetActiveProcess()) break; //если окно не активно на события мыши не реагируем
2811 leency 90
 
91
				edit_box_mouse stdcall (#edit1);
92
 
93
				m.get();
94
 
95
				if (m.pkm) && (m.y>WB1.top) && (m.y
96
				{
2840 leency 97
					SwitchToAnotherThread();
2811 leency 98
					CreateThread(#menu_rmb,#stak);
99
				}
100
 
101
				IF (m.vert==65535) //прокрутка колёсиком
102
				{
103
					IF (lines.first==0) break;
104
					IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
105
					WB1.Scan(ID1);
106
					break;
107
				}
108
				IF (m.vert==1)
109
				{
110
					IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
111
					ELSE	{
112
						lines.first+=2;
113
						WB1.Scan(ID2);
114
					}
115
					break;
116
				}
117
 
118
				IF (lines.all
119
				half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
120
				if (m.x>=WB1.width-14) && (m.x<=WB1.width+6)
121
				&& (m.y>WB1.top+16) && (m.y
122
				&& (lines.all>lines.visible) while (m.lkm)
123
				{
2818 leency 124
					IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //если курсор над окном
2811 leency 125
					btn=lines.first; //сохраняем старое количество
126
					lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
127
					IF (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
2823 leency 128
					IF (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать
2811 leency 129
					m.get();
130
				}
131
 
132
				break;
133
			case evButton:
134
				btn=GetButtonID();
135
				IF (btn==1)
136
				{
137
					KillProcess(downloader_id);
138
					ExitProcess();
139
				}
140
				ELSE
141
				{
142
					WB1.Scan(btn);
143
				}
144
				break;
145
			case evKey:
146
				key = GetKey();
147
 
148
				if (edit1.flags == 66) || (edit1.flags == 98) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки
149
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
150
 
151
				WB1.Scan(key);
152
 
153
				_EDIT_MARK:
154
				IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //адресная строка
155
				break;
156
			case evReDraw:
157
				Draw_Window();
158
				break;
159
			default:
160
				if (downloader_id<>0)
161
				{
162
					if (GetProcessSlot(downloader_id)<>0) break;
163
					downloader_id=0;
164
					lines.first = lines.all = 0;
165
					WB1.ReadHtml(_WIN);
166
					Draw_Window();
167
				}
168
		}
169
	}
170
}
171
 
2844 leency 172
void SetElementSizes()
173
{
174
	edit1.width=Form.width-266;
175
	WB1.top=44;
176
	WB1.width=Form.width-13;
177
	WB1.height=onTop(43,5);
178
	lines.column_max = WB1.width - 30 / 6;
179
	lines.visible = WB1.height - 3 / 10 - 2;
180
}
2811 leency 181
 
2844 leency 182
 
2811 leency 183
void Draw_Window()
184
{
185
	int j;
2844 leency 186
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0,0,0);
2811 leency 187
 
188
	GetProcessInfo(#Form, SelfInfo);
189
	if (Form.status_window>2) //если свернуто в заголовок, ничего не рисуем
190
	{
191
		DrawTitle(#header);
192
		return;
193
	}
194
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
195
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
196
 
197
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
198
	if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10);
199
 
200
	DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //закрашиваем фон под тулбаром
201
	DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //выпуклость
202
	DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //выпуклость
2818 leency 203
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
2811 leency 204
	PutImage(#URLgoto,40,19,onLeft(57,0),14);
205
	DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
206
	DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
207
	DrawRegion(205,14,onLeft(58,205),18,0x94AECE); //ободок полосы адреса
208
	DrawRegion(206,15,onLeft(59,205),16,0xE4ECF3);
209
 
2844 leency 210
	SetElementSizes();
2811 leency 211
	WB1.ShowPage();
2818 leency 212
 
213
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
214
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
2811 leency 215
}
216
 
217
int onLeft(dword right,left) {return Form.width-right-left;}
218
int onTop(dword down,up) {return Form.height-GetSkinWidth()-down-up;}
219
 
220
 
221
stop: