Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7770 → Rev 7771

/programs/cmm/browser/WebView.c
6,7 → 6,7
#endif
 
//libraries
#define MEMSIZE 1024 * 850
#define MEMSIZE 1024 * 1000
#include "..\lib\gui.h"
#include "..\lib\draw_buf.h"
#include "..\lib\list_box.h"
29,25 → 29,29
#include "..\lib\patterns\simple_open_dialog.h"
#include "..\lib\patterns\toolbar_button.h"
 
#include "texts.h"
#include "cache.h"
#include "show_src.h"
#include "download_manager.h"
_history history;
#include "history.h"
 
bool debug_mode = false;
 
#include "..\TWB\TWB.c" //HTML Parser, a core component
#include "texts.h"
#include "cache.h"
 
TWebBrowser WB1;
_history history;
 
#define URL_SIZE 4000
#include "history.h"
 
#define PADDING 9
#define SKIN_Y 24
#define TSZE 25
#define STATUSBAR_H 15
#define TAB_H 20
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
dword STATUSBAR_H = 15;
 
#define URL_SIZE 4000
 
int action_buf;
 
_http http = 0;
59,8 → 63,9
proc_info Form;
 
enum {
ENCODINGS=900,
BACK_BUTTON=1000,
NEW_TAB=600,
ENCODINGS=700,
BACK_BUTTON=800,
FORWARD_BUTTON,
REFRESH_BUTTON,
GOTOURL_BUTTON,
76,8 → 81,12
UPDATE_BROWSER,
COPY_LINK_URL,
DOWNLOAD_LINK_CONTENTS,
TAB_ID,
TAB_CLOSE_ID = 900
};
 
#include "tabs.h"
 
char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
 
165,18 → 174,26
 
case evKey:
GetKeys();
//if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;}
 
if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;}
}
 
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
if (key_scancode == SCAN_CODE_KEY_T)
|| (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
if (key_scancode == SCAN_CODE_LEFT) {ProcessEvent(BACK_BUTTON);break;}
if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
if (key_scancode == SCAN_CODE_KEY_O) EventOpenDialog();
else if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
else if (key_scancode == SCAN_CODE_KEY_U) EventViewSource();
else if (key_scancode == SCAN_CODE_KEY_T) EventOpenNewTab(URL_SERVICE_HOMEPAGE);
else if (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
else if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
else if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
else if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
else if (key_scancode == SCAN_CODE_LEFT) ProcessEvent(BACK_BUTTON);
else if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
else if (key_scancode == SCAN_CODE_KEY_W) EventCloseActiveTab();
else if (key_scancode == SCAN_CODE_TAB) EventActivateNextTab();
break;
}
if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
185,14 → 202,11
{
if (key_scancode == SCAN_CODE_ENTER) {
ProcessEvent(key_scancode);
}
else {
} else {
EAX = key_editbox;
edit_box_key stdcall(#address_box);
}
}
else
{
} else {
#define KEY_SCROLL_N 11
if (SCAN_CODE_UP == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
203,7 → 217,7
break;
 
case evReDraw:
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
DefineAndDrawWindow(40, //GetScreenWidth()-800/2-random(80),
GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
GetProcessInfo(#Form, SelfInfo);
system.color.get();
245,8 → 259,8
void SetElementSizes()
{
address_box.width = Form.cwidth - address_box.left - 52 - 16;
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H);
WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
WB1.list.wheel_size = 7 * BASIC_LINE_H;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
WB1.list.visible = WB1.list.h;
265,7 → 279,7
 
DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180));
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
280,23 → 294,33
DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
WB1.list.h-1, scroll_wv.bckg_col);
 
if (WB1.list.w!=WB1.DrawBuf.bufw) {
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
if (!BrowserWidthChanged()) {
WB1.DrawPage();
DrawOmnibox();
}
DrawProgress();
DrawStatusBar(NULL);
DrawTabsBar();
}
 
bool BrowserWidthChanged()
{
dword source_mode_holder;
if (WB1.list.w!=DrawBuf.bufw) {
DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
if (!strncmp(history.current(),"http",4)) {
//nihuya ne izyashnoe reshenie, no pust' poka butet tak
i=source_mode;
source_mode_holder = source_mode;
LoadInternalPage(#loading_text, sizeof(loading_text));
source_mode=i;
source_mode = source_mode_holder;
}
OpenPage(history.current());
} else {
WB1.DrawPage();
DrawOmnibox();
return true;
}
DrawProgress();
DrawStatusBar(NULL);
return false;
}
 
 
void EventChangeEncodingAndLoadPage(int _new_encoding)
{
dword newbuf, newsize;
335,7 → 359,7
EventSubmitOmnibox();
return;
case REFRESH_BUTTON:
if (http.transfer > 0) {
if (http.transfer) {
StopLoading();
draw_window();
} else {
393,8 → 417,23
if (debug_mode) notify("'Debug mode ON'-I");
else notify("'Debug mode OFF'-I");
return;
case NEW_TAB:
if (http.transfer) break;
EventOpenNewTab(URL_SERVICE_HOMEPAGE);
return;
case TAB_ID...TAB_ID+TABS_MAX:
if (http.transfer) break;
if (mouse.mkm) {
EventTabClose(id__ - TAB_ID);
} else {
EventTabClick(id__ - TAB_ID);
}
return;
case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX:
EventTabClose(id__ - TAB_CLOSE_ID);
return;
}
}
 
void StopLoading()
{
456,10 → 495,14
 
StopLoading();
 
strcpy(#editURL, _open_URL);
address_box.flags=0;
DrawOmnibox();
if (open_new_tab) {
open_new_tab = false;
EventOpenNewTab(_open_URL);
return;
}
 
SetOmniboxText(_open_URL);
 
strncpy(#new_url, _open_URL, URL_SIZE);
 
//Exclude # from the URL to the load page
535,7 → 578,7
return;
}
 
if (http.transfer > 0) {
if (http.transfer) {
StopLoading();
history.back();
}
607,6 → 650,7
}
WB1.ParseHtml(_bufdata, _in_bufsize);
DrawStatusBar(NULL);
DrawActiveTab();
if (source_mode) {
source_mode = false;
ShowSource(WB1.bufpointer, _in_bufsize);
689,9 → 733,11
void EventViewSource()
{
char source_view_param[URL_SIZE+1];
strcpy(#source_view_param, "-source ");
strncat(#source_view_param, history.current(), URL_SIZE);
RunProgram(#program_path, #source_view_param);
//strcpy(#source_view_param, "-source ");
//strncat(#source_view_param, history.current(), URL_SIZE);
//RunProgram(#program_path, #source_view_param);
source_mode = true;
EventOpenNewTab(history.current());
}
 
dword GetFileSize(dword _path)
781,5 → 827,12
DrawProgress();
}
 
void SetOmniboxText(dword _text)
{
strcpy(#editURL, _text);
address_box.flags=0;
DrawOmnibox();
}
 
 
stop:
/programs/cmm/browser/tabs.h
0,0 → 1,209
 
//===================================================//
// //
// MODULE //
// //
//===================================================//
 
#define TABS_MAX 5
 
TWebBrowser data[TABS_MAX+1];
_history tabstory[TABS_MAX+1];
 
struct TAB
{
int count;
signed int active;
bool add();
bool close();
void save_state();
void restore();
} tab = {1,0};
 
 
bool TAB::add()
{
if (count==TABS_MAX) return false;
save_state();
count++;
active = count-1;
history = tabstory[active];
return true;
}
 
bool TAB::close(int _tab_number)
{
int i;
if (count==1) return false;
for (i=_tab_number; i<=TABS_MAX; i++) {
data[i] = data[i+1];
tabstory[i] = tabstory[i+1];
}
if (_tab_number<active) && (active>0) active--;
if (active==count-1) && (active>0) active--;
count--;
return true;
}
 
void TAB::save_state()
{
tabstory[active] = history;
data[active] = WB1;
}
 
void TAB::restore(int _id)
{
tab.active = _id;
WB1 = data[_id];
history = tabstory[_id];
}
 
//===================================================//
// //
// WebView Actions //
// //
//===================================================//
 
#define DEFAULT_TABW 220
int tab_w = DEFAULT_TABW;
 
int GetTabWidth()
{
if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else
return Form.cwidth - TAB_H - 2 / tab.count;
}
 
void DrawTab(int _id)
{
#define CLOSE_S 13
dword bgcol, border_bottom_color;
char header_no_version[sizeof(TWebBrowser.header)];
char name[DEFAULT_TABW/6];
int xxx = _id * tab_w;
 
if (_id==tab.active) {
tab.save_state();
bgcol = system.color.work_light;
border_bottom_color = system.color.work_light;
} else {
bgcol=system.color.work;
border_bottom_color = system.color.work_graph;
}
if (data[_id].header) {
strncpy(#header_no_version, #data[_id].header, strlen(#data[_id].header)-sizeof(version)-2);
strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
}
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_dark);
DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, system.color.work_text, #name);
 
DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, system.color.work_dark);
WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, system.color.work_light, "x");
}
 
void DrawActiveTab()
{
if (tab_w == GetTabWidth()) DrawTab(tab.active);
else DrawTabsBar();
}
 
void DrawNewTabButton()
{
dword btn_light = MixColors(system.color.work_button, 0xFFFfff, 220);
dword btn_dark = MixColors(system.color.work_button, 0, 180);
int xxx = tab.count * tab_w;
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_graph);
DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, system.color.work_button);
DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+");
}
 
void DrawTabsBar()
{
dword i;
tab_w = GetTabWidth();
for (i=0; i<tab.count; i++) DrawTab(i);
DrawNewTabButton();
i = tab_w * i + TAB_H + 2;
DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(system.color.work_dark, system.color.work, 128));
DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, system.color.work_graph);
}
 
void EventTabClose(int _id)
{
DeleteButton(tab.count);
if (_id == tab.active) {
tab.close(_id);
tab.restore(tab.active);
WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
WB1.DrawPage();
SetOmniboxText(history.current());
} else {
tab.close(_id);
}
DrawTabsBar();
}
 
void EventCloseActiveTab()
{
EventTabClose(tab.active);
}
 
void EventTabClick(int _id)
{
if (_id>=tab.count) _id = 0;
if (_id==-1) _id = tab.count-1;
tab.save_state();
tab.restore(_id);
SetElementSizes();
if (!BrowserWidthChanged()) {
DrawTabsBar();
WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
WB1.DrawPage();
}
SetOmniboxText(history.current());
}
 
void EventOpenNewTab(dword _url)
{
tab.add();
OpenPage(_url);
DrawTabsBar();
}
 
void EventActivateNextTab()
{
EventTabClick(tab.active+1);
}
 
void EventActivatePreviousTab()
{
EventTabClick(tab.active-1);
}
 
 
:void DebugTabs()
{
debugln("\n\n\nHISTORY==========================");
history.add("history");
history.debug();
 
debugln("\n\n\nTABSTORY[0]======================");
tabstory[0].add("tabstory0");
tabstory[0].debug();
 
debugln("\n\n\nTABSTORY[1]======================");
tabstory[1].add("tabstory1");
tabstory[1].debug();
 
debugln("\n\n\n\n");
debugval("history.items.data_start", history.items.data_start);
debugval("tabstory[0].items.data_start", tabstory[0].items.data_start);
debugval("tabstory[1].items.data_start", tabstory[1].items.data_start);
debugln("\n\n\n\n");
}
/programs/cmm/browser/texts.h
1,4 → 1,4
char version[]="WebView 2.26";
char version[]="WebView 2.4";
 
#ifdef LANG_RUS
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";