Subversion Repositories Kolibri OS

Rev

Rev 4415 | Rev 4417 | 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
 
4085 leency 6
#ifndef AUTOBUILD
7
	#include "lang.h--"
8
#endif
9
 
3107 leency 10
//libraries
3363 leency 11
#define MEMSIZE 0x100000
3067 leency 12
#include "..\lib\kolibri.h"
13
#include "..\lib\strings.h"
14
#include "..\lib\figures.h"
15
#include "..\lib\encoding.h"
16
#include "..\lib\file_system.h"
17
#include "..\lib\mem.h"
18
#include "..\lib\dll.h"
4415 leency 19
#include "..\lib\list_box.h"
3107 leency 20
//*.obj libraries
21
#include "..\lib\lib.obj\box_lib.h"
22
#include "..\lib\lib.obj\libio_lib.h"
23
#include "..\lib\lib.obj\libimg_lib.h"
24
//images
3067 leency 25
#include "img\toolbar_icons.c"
26
#include "img\URLgoto.txt";
27
 
4026 leency 28
#ifdef LANG_RUS
4416 leency 29
	char version[]=" Текстовый браузер 0.99.31";
30
	?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
4026 leency 31
#else
4416 leency 32
	char version[]=" Text-based Browser 0.99.31";
4026 leency 33
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
34
#endif
35
 
3067 leency 36
proc_info Form;
37
#define WIN_W 640
38
#define WIN_H 480
39
 
4416 leency 40
char search_path[]="http://nigma.ru/index.php?s=";
3067 leency 41
 
4074 leency 42
char stak[4096];
3067 leency 43
mouse m;
4026 leency 44
int action_buf;
45
 
4416 leency 46
 
47
 
4411 leency 48
#include "..\TWB\TWB.c"
49
#include "menu_rmb.h"
3067 leency 50
 
51
 
52
void main()
53
{
4081 leency 54
	int key, btn;
3067 leency 55
	int half_scroll_size;
4026 leency 56
	int scroll_used=0, show_menu;
3067 leency 57
 
58
	mem_Init();
3107 leency 59
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
4415 leency 60
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio");
61
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg");
3067 leency 62
 
3987 leency 63
	if (!URL) strcpy(#URL, "/sys/index.htm");
3067 leency 64
	strcpy(#editURL, #URL);
65
 
66
	Form.width=WIN_W;
67
	Form.height=WIN_H;
68
	SetElementSizes();
4416 leency 69
	OpenPage();
3067 leency 70
 
71
	SetEventMask(0x27);
72
	loop()
73
	{
74
		WaitEventTimeout(2);
75
		switch(EAX & 0xFF)
76
		{
77
			CASE evMouse:
4414 leency 78
				/*
79
				//not work well, so we are use custom way of processing scroll
4416 leency 80
				scrollbar_v_mouse (#scroll_wv);
81
				if (WB1.list.first <> scroll_wv.position)
3067 leency 82
				{
4416 leency 83
					WB1.list.first = scroll_wv.position;
3067 leency 84
					WB1.ParseHTML(buf, filesize);
4414 leency 85
				};
86
				*/
3067 leency 87
 
4081 leency 88
				if (!CheckActiveProcess(Form.ID)) break;
3067 leency 89
 
3466 leency 90
				edit_box_mouse stdcall (#address_box);
3067 leency 91
 
92
				m.get();
93
 
4414 leency 94
				if (m.y>WB1.list.y) && (m.y
3067 leency 95
				{
4026 leency 96
					if (m.pkm)
97
					{
98
						show_menu = 1;
99
					}
100
					if (!m.pkm) && (show_menu)
101
					{
102
						show_menu = 0;
103
						SwitchToAnotherThread();
4074 leency 104
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 105
						break;
106
					}
3067 leency 107
				}
108
 
4415 leency 109
				if (m.vert)
3067 leency 110
				{
4415 leency 111
					if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(buf);
3067 leency 112
				}
113
 
114
				if (!m.lkm) scroll_used=0;
4416 leency 115
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
116
				&& (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
4415 leency 117
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
4026 leency 118
				{
119
					scroll_used=1;
120
				}
3067 leency 121
 
122
				if (scroll_used)
123
				{
4415 leency 124
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
4416 leency 125
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
126
					btn=WB1.list.first;
4415 leency 127
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
128
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
4416 leency 129
					if (btn<>WB1.list.first) WB1.ParseHTML(buf);
3067 leency 130
				}
131
 
132
				break;
133
			case evButton:
134
				btn=GetButtonID();
3464 leency 135
				if (btn==1)
3067 leency 136
				{
137
					KillProcess(downloader_id);
138
					ExitProcess();
139
				}
140
				ELSE
141
				{
4413 leency 142
					Scan(btn);
3067 leency 143
				}
144
				break;
145
			case evKey:
146
				key = GetKey();
147
 
4416 leency 148
				if (address_box.flags & 0b10) SWITCH(key)
3067 leency 149
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
150
 
4413 leency 151
				Scan(key);
3067 leency 152
 
153
				_EDIT_MARK:
4416 leency 154
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
3067 leency 155
				break;
156
			case evReDraw:
4413 leency 157
				if (action_buf) { Scan(action_buf); action_buf=0;}
3067 leency 158
				Draw_Window();
159
				break;
160
			default:
161
				if (downloader_id<>0)
162
				{
163
					if (GetProcessSlot(downloader_id)<>0) break;
164
					downloader_id=0;
4415 leency 165
					WB1.list.first = WB1.list.count = 0;
3067 leency 166
					WB1.ReadHtml(_WIN);
167
					Draw_Window();
168
				}
169
		}
170
	}
171
}
172
 
173
void SetElementSizes()
174
{
4416 leency 175
	address_box.width = Form.width - 266;
176
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
4415 leency 177
	WB1.list.column_max = WB1.list.w - 30 / 6;
178
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
3468 leency 179
	DrawBufInit();
3067 leency 180
}
181
 
182
 
183
void Draw_Window()
184
{
185
	int j;
3466 leency 186
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
3067 leency 187
 
188
	GetProcessInfo(#Form, SelfInfo);
3464 leency 189
	if (Form.status_window>2)
3067 leency 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);
3363 leency 198
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
3067 leency 199
 
3464 leency 200
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
201
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);