Subversion Repositories Kolibri OS

Rev

Rev 4728 | Rev 5403 | 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"
4508 leency 19
#include "..\lib\draw_buf.h"
20
#include "..\lib\list_box.h"
21
#include "..\lib\cursor.h"
22
 
3107 leency 23
//*.obj libraries
24
#include "..\lib\lib.obj\box_lib.h"
25
#include "..\lib\lib.obj\libio_lib.h"
26
#include "..\lib\lib.obj\libimg_lib.h"
4536 leency 27
#include "..\lib\lib.obj\http.h"
3067 leency 28
 
4677 leency 29
char homepage[] = FROM "html\homepage.htm";
30
 
4026 leency 31
#ifdef LANG_RUS
4728 leency 32
	char version[]=" Текстовый браузер 1.0 Beta 6.1";
4416 leency 33
	?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
4417 leency 34
	?define T_LAST_SLIDE "Это последний слайд"
4550 leency 35
	char loading[] = "Загрузка страницы...
";
4677 leency 36
	char page_not_found[] = FROM "html\page_not_found_ru.htm";
4649 leency 37
	char accept_language[]= "Accept-Language: ru\n";
4026 leency 38
#else
4728 leency 39
	char version[]=" Text-based Browser 1.0 Beta 6.1";
4026 leency 40
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
4417 leency 41
	?define T_LAST_SLIDE "This slide is the last"
4550 leency 42
	char loading[] = "Loading...
";
4677 leency 43
	char page_not_found[] = FROM "html\page_not_found_en.htm";
4649 leency 44
	char accept_language[]= "Accept-Language: en\n";
4026 leency 45
#endif
46
 
3067 leency 47
proc_info Form;
48
#define WIN_W 640
49
#define WIN_H 480
50
 
4416 leency 51
char search_path[]="http://nigma.ru/index.php?s=";
4558 hidnplayr 52
char str_location[]="location\0";
53
int redirected = 0;
3067 leency 54
 
4074 leency 55
char stak[4096];
3067 leency 56
mouse m;
4026 leency 57
int action_buf;
58
 
4565 leency 59
dword http_transfer = 0;
4537 leency 60
dword http_buffer;
4534 leency 61
 
4692 leency 62
dword TAB_H = false; //19;
4677 leency 63
dword TAB_W = 150;
4692 leency 64
dword TOOLBAR_H = 31; //50;
4718 leency 65
dword STATUSBAR_H =15;
66
dword col_bg;
67
dword panel_color;
68
dword border_color;
4677 leency 69
 
4686 leency 70
pb progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
4718 leency 71
byte souce_mode = false;
4677 leency 72
 
4411 leency 73
#include "..\TWB\TWB.c"
74
#include "menu_rmb.h"
4636 leency 75
#include "history.h"
4718 leency 76
#include "show_src.h"
3067 leency 77
 
4534 leency 78
char editURL[sizeof(URL)];
79
int	mouse_twb;
4677 leency 80
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
4534 leency 81
 
4677 leency 82
#define URL_SERVICE_HISTORY "WebView://history"
83
#define URL_SERVICE_HOME "WebView://home"
4718 leency 84
#define URL_SERVICE_SOURCE "WebView://source:"
4534 leency 85
 
4488 leency 86
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
3067 leency 87
 
4718 leency 88
struct struct_skin {
4677 leency 89
	dword image, w, h;
4718 leency 90
	int Load();
4677 leency 91
} skin;
4488 leency 92
 
4718 leency 93
int struct_skin::Load()
4677 leency 94
{
4718 leency 95
	dword image_data;
4677 leency 96
	skin.image = load_image(abspath("wv_skin.png"));
4686 leency 97
	if (!skin.image) notify("WebView skin file 'wv_skin.png' not found, program will terminate");
4677 leency 98
	skin.w = DSWORD[skin.image+4];
99
	skin.h = DSWORD[skin.image+8];
4718 leency 100
	image_data = DSDWORD[skin.image+24];
101
 
4846 leency 102
	col_bg = DSDWORD[image_data];
4718 leency 103
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
104
	border_color = DSDWORD[skin.w*4*7 + image_data];
105
	progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
106
	$and col_bg, 0x00ffffff
107
	$and panel_color, 0x00ffffff
108
	$and border_color, 0x00ffffff
109
	$and progress_bar.progress_color, 0x00ffffff
4677 leency 110
}
111
 
4686 leency 112
void DrawProgress()
113
{
114
	unsigned long btn;
115
	//progressbar_draw stdcall(#progress_bar);
116
	progress_bar.width = progress_bar.left = 0;
117
	if (http_transfer == 0) return;
118
	if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30;
119
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color);
120
}
121
 
4718 leency 122
 
3067 leency 123
void main()
124
{
4686 leency 125
	unsigned long key, btn;
3067 leency 126
	int half_scroll_size;
4026 leency 127
	int scroll_used=0, show_menu;
3067 leency 128
 
129
	mem_Init();
4536 leency 130
	CursorPointer.Load(#CursorFile);
4686 leency 131
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj");
4536 leency 132
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
133
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
4540 leency 134
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
4718 leency 135
	skin.Load();
3067 leency 136
 
137
	Form.width=WIN_W;
138
	Form.height=WIN_H;
139
	SetElementSizes();
4677 leency 140
	if (!URL) strcpy(#URL, URL_SERVICE_HOME);
4416 leency 141
	OpenPage();
3067 leency 142
 
4536 leency 143
	SetEventMask(0xa7);
3067 leency 144
	loop()
145
	{
146
		WaitEventTimeout(2);
147
		switch(EAX & 0xFF)
148
		{
149
			CASE evMouse:
4081 leency 150
				if (!CheckActiveProcess(Form.ID)) break;
4636 leency 151
				//Edit URL
3466 leency 152
				edit_box_mouse stdcall (#address_box);
3067 leency 153
				m.get();
4636 leency 154
				//Links hover
4550 leency 155
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
4636 leency 156
				//Menu
4540 leency 157
				if (m.y>WB1.list.y) && (m.y
3067 leency 158
				{
4026 leency 159
					if (m.pkm)
160
					{
161
						show_menu = 1;
162
					}
163
					if (!m.pkm) && (show_menu)
164
					{
165
						show_menu = 0;
166
						SwitchToAnotherThread();
4074 leency 167
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 168
						break;
169
					}
3067 leency 170
				}
4636 leency 171
				//Mouse scroll
4415 leency 172
				if (m.vert)
3067 leency 173
				{
4636 leency 174
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
3067 leency 175
				}
4636 leency 176
				//Drag scroller
4677 leency 177
				scroll_wv.all_redraw = 0;
3067 leency 178
				if (!m.lkm) scroll_used=0;
4416 leency 179
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)