WebView: Remove condition script, code update, prepar

llist: configurable mouse wheel size

git-svn-id: svn://kolibrios.org@5749 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-08-19 15:14:52 +00:00
parent a428a4fd42
commit 714d366ac8
4 changed files with 73 additions and 199 deletions

View File

@ -1,6 +1,4 @@
dword bufpointer;
dword o_bufpointer;
dword bufsize;
scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
@ -28,6 +26,7 @@ struct TWebBrowser {
void LoadInternalPage(); void LoadInternalPage();
void NewLine(); void NewLine();
void Perenos(); void Perenos();
void BufEncode();
byte end_parsing; byte end_parsing;
} WB1; } WB1;
@ -39,18 +38,10 @@ byte
cur_encoding, cur_encoding,
t_html, t_html,
t_body; t_body;
/*
struct _condition {
byte
text_active,
text_val,
href,
max
} condition;
*/
byte condition_text_active, condition_text_val, condition_href, condition_max;
dword bufpointer;
dword o_bufpointer;
dword bufsize;
dword text_colors[300]; dword text_colors[300];
dword text_color_index; dword text_color_index;
@ -78,7 +69,6 @@ char anchor[256];
#include "..\TWB\unicode_tags.h" #include "..\TWB\unicode_tags.h"
#include "..\TWB\img_cache.h" #include "..\TWB\img_cache.h"
#include "..\TWB\parce_tag.h" #include "..\TWB\parce_tag.h"
#include "..\TWB\table.h"
//============================================================================================ //============================================================================================
@ -133,10 +123,8 @@ void TWebBrowser::Parse(){
int line_len; int line_len;
style.b = style.i = style.u = style.s = style.blq = t_html = t_body = style.b = style.i = style.u = style.s = style.blq = t_html = t_body =
style.li = link = ignor_text = text_color_index = text_colors[0] = style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0;
style.li_tab = condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè
end_parsing = false; end_parsing = false;
condition_max = 255;
style.align = ALIGN_LEFT; style.align = ALIGN_LEFT;
link_color_inactive = 0x0000FF; link_color_inactive = 0x0000FF;
link_color_active = 0xFF0000; link_color_active = 0xFF0000;
@ -150,15 +138,27 @@ void TWebBrowser::Parse(){
draw_line_width = list.w * DrawBuf.zoom; draw_line_width = list.w * DrawBuf.zoom;
style.pre = 1; //for plaint text use CP866 for other UTF
if (strstri(bufpointer, "html")) style.pre = 0; if (strstri(bufpointer, "html"))
{
style.pre = 0;
cur_encoding = CH_CP866;
//WB1.list.SetFont(8, 14, 10111000b);
//list.line_h = list.font_h + 4;
}
else
{
style.pre = 1;
cur_encoding = CH_UTF8;
//WB1.list.SetFont(8, 14, 10001000b);
//list.line_h = list.font_h + 4;
}
for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;) for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;)
{ {
if (end_parsing) break; if (end_parsing) break;
bukva = ESBYTE[bufpos]; bukva = ESBYTE[bufpos];
if (ignor_text) && (bukva!='<') continue; if (ignor_text) && (bukva!='<') continue;
if (condition_text_active) && (condition_text_val != condition_href) && (bukva!='<') continue;
switch (bukva) switch (bukva)
{ {
case 0x0a: case 0x0a:
@ -190,7 +190,7 @@ void TWebBrowser::Parse(){
if (bukva = GetUnicodeSymbol()) goto DEFAULT_MARK; if (bukva = GetUnicodeSymbol()) goto DEFAULT_MARK;
break; break;
case '<': case '<':
bufpos++; //ïðîìîòàåì ñèìâîë < bufpos++;
tag = attr = tagparam = ignor_param = NULL; tag = attr = tagparam = ignor_param = NULL;
if (ESBYTE[bufpos] == '!') //ôèëüòðàöèÿ âíóòðè <!-- -->, äåðçêî if (ESBYTE[bufpos] == '!') //ôèëüòðàöèÿ âíóòðè <!-- -->, äåðçêî
{ {
@ -226,10 +226,6 @@ void TWebBrowser::Parse(){
} }
strlwr(#tag); strlwr(#tag);
if (condition_text_active) && (condition_text_val != condition_href)
{
if (strcmp(#tag, "/condition")!=0) break;
}
if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/ if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
if (tagparam) GetNextParam(); if (tagparam) GetNextParam();
@ -293,40 +289,31 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
} }
else opened = 1; else opened = 1;
if (istag("html")) if (istag("html")) {
{
t_html = opened; t_html = opened;
return; return;
} }
if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) { ignor_text = opened; return; }
if (istag("script")) || (istag("style")) || (istag("binary")) || (istag("select")) ignor_text = opened;
if (istag("form")) if (!opened) ignor_text = false; if (istag("form")) if (!opened) ignor_text = false;
if(istag("title")) {
if(istag("title"))
{
if (opened) header=NULL; if (opened) header=NULL;
else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
return; return;
} }
if (ignor_text) return; if (ignor_text) return;
IF(istag("q")) IF(istag("q"))
{ {
if (opened) strcat(#line, " \""); if (opened) strcat(#line, " \"");
if (!opened) strcat(#line, "\" "); if (!opened) strcat(#line, "\" ");
return;
} }
if (anchor) && (isattr("id=")) { //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
if (anchor) && (isattr("id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
{
if (!strcmp(#anchor, #val)) anchor_line_num=list.first+stroka; if (!strcmp(#anchor, #val)) anchor_line_num=list.first+stroka;
} }
if (istag("body")) {
if (istag("body"))
{
t_body = opened; t_body = opened;
do{ do{
if (isattr("condition_max=")) condition_max = atoi(#val);
if (isattr("link=")) link_color_inactive = GetColor(#val); if (isattr("link=")) link_color_inactive = GetColor(#val);
if (isattr("alink=")) link_color_active = GetColor(#val); if (isattr("alink=")) link_color_active = GetColor(#val);
if (isattr("text=")) text_colors[0]=GetColor(#val); if (isattr("text=")) text_colors[0]=GetColor(#val);
@ -336,28 +323,19 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
DrawBuf.Fill(bg_color); DrawBuf.Fill(bg_color);
} }
} while(GetNextParam()); } while(GetNextParam());
if (opened) && (cur_encoding==CH_NULL) if (opened) && (cur_encoding==CH_NULL) debugln("Document has no information about encoding, UTF will be used");
{
debugln("Document has no information about encoding, UTF will be used");
//BufEncode(CH_UTF8);
}
return; return;
} }
if (istag("a")) {
if (istag("a"))
{
if (opened) if (opened)
{ {
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
do{ do{
if (isattr("href=")) if (isattr("href="))
{ {
if (stroka - 1 > list.visible) || (stroka < -2) return; if (stroka - 1 > list.visible) || (stroka < -2) return;
text_color_index++; text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1]; text_colors[text_color_index] = text_colors[text_color_index-1];
link = 1; link = 1;
text_colors[text_color_index] = link_color_inactive; text_colors[text_color_index] = link_color_inactive;
PageLinks.AddLink(#val, DrawBuf.zoom * stolbec * list.font_w + left1, top1-DrawBuf.zoom); PageLinks.AddLink(#val, DrawBuf.zoom * stolbec * list.font_w + left1, top1-DrawBuf.zoom);
@ -377,31 +355,20 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
} }
return; return;
} }
if (istag("font")) {
if (istag("font"))
{
if (opened) if (opened)
{ {
text_color_index++; text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1]; text_colors[text_color_index] = text_colors[text_color_index-1];
do{ do{
if (strcmp(#attr, "color=") == 0) //&& (attr[1] == '#') if (isattr("color=")) text_colors[text_color_index] = GetColor(#val);
{
text_colors[text_color_index] = GetColor(#val);
}
} while(GetNextParam()); } while(GetNextParam());
} }
else else if (text_color_index > 0) text_color_index--;
if (text_color_index > 0) text_color_index--;
return;
}
if (istag("br")) {
NewLine();
return; return;
} }
if (istag("div")) || (istag("header")) || (istag("article")) || (istag("footer")) { if (istag("div")) || (istag("header")) || (istag("article")) || (istag("footer")) {
IF(oldtag[0] <>'h') NewLine(); IF(oldtag[0] != 'h') NewLine();
if (isattr("bgcolor=")) if (isattr("bgcolor="))
{ {
bg_color=GetColor(#val); bg_color=GetColor(#val);
@ -415,50 +382,17 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
IF(opened) NewLine(); IF(opened) NewLine();
return; return;
} }
if (istag("br")) { NewLine(); return; }
if(istag("table")) { if (istag("tr")) { if (opened) { NewLine(); strcat(#line, "| "); } return; }
table.active = opened; if (istag("td")) || (istag("th")) { if (!opened) strcat(#line, " | "); return; }
NewLine(); if (istag("b")) || (istag("strong")) || (istag("big")) { style.b = opened; return; }
if (opened) table.NewTable(); if (istag("i")) || (istag("em")) || (istag("subtitle")) { style.i=opened; return; }
} if (istag("u")) || (istag("ins")) { style.u=opened; return;}
if (istag("s")) || (istag("strike")) || (istag("del")) { style.s=opened; return; }
if(istag("td")) { if (istag("dd")) { stolbec += 5; return; }
if (opened) if (istag("blockquote")) { style.blq = opened; return; }
{ if (istag("pre")) || (istag("code")) { style.pre = opened; return; }
table.cur_col++; if (istag("img")) { ImgCache.Images( left1, top1, WB1.list.w); return; }
table.row_h = 0;
do {
if (isattr("width="))
{
table.col_w[table.cur_col] = atoi(#val);
// NewLine();
// strcpy(#line, #val);
// NewLine();
}
} while(GetNextParam());
}
else
{
if (table.row_h > table.row_max_h) table.row_max_h = table.row_h;
}
}
if(istag("tr")) {
if (opened)
{
table.cur_col = 0;
table.row_max_h = 0;
table.row_start = stroka;
}
else
{
NewLine();
if (table.cur_row == 0) table.max_cols = table.cur_col;
table.cur_row++;
table.max_cols = table.cur_col;
}
}
/* /*
if (istag("center")) if (istag("center"))
{ {
@ -481,7 +415,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
return; return;
} }
*/ */
if (istag("h1")) || (istag("h2")) || (istag("h3")) || (istag("h4")) { if (istag("h1")) || (istag("h2")) || (istag("h3")) || (istag("h4")) || (istag("caption")) {
NewLine(); NewLine();
if (opened) && (stroka>1) NewLine(); if (opened) && (stroka>1) NewLine();
strcpy(#oldtag, #tag); strcpy(#oldtag, #tag);
@ -500,26 +434,9 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
} }
else else
oldtag=NULL; oldtag=NULL;
if (istag("dt")) {
if (istag("b")) || (istag("strong")) || (istag("big")) {
style.b = opened;
return;
}
if(istag("i")) || (istag("em")) || (istag("subtitle")) {
style.i = opened;
return;
}
if (istag("dt"))
{
style.li = opened; style.li = opened;
IF(opened == 0) return; if (opened) NewLine();
NewLine();
return;
}
if (istag("condition"))
{
condition_text_active = opened;
if (opened) && (isattr("show_if=")) condition_text_val = atoi(#val);
return; return;
} }
if (istag("li")) || (istag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè if (istag("li")) || (istag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
@ -534,19 +451,16 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
} }
return; return;
} }
if (istag("u")) || (istag("ins")) style.u = opened; if (istag("ul")) || (istag("ol")) {
if (istag("s")) || (istag("strike")) || (istag("del")) style.s = opened; if (!opened)
if (istag("ul")) || (istag("ol")) IF(!opened) {
{ style.li = opened;
style.li = opened; style.li_tab--;
style.li_tab--; NewLine();
NewLine(); }
} ELSE style.li_tab++; else style.li_tab++;
if (istag("dd")) stolbec += 5; }
if (istag("blockquote")) style.blq = opened; if (istag("hr")) {
if (istag("pre")) || (istag("code")) style.pre = opened;
if (istag("hr"))
{
if (anchor) || (stroka < -1) if (anchor) || (stroka < -1)
{ {
stroka+=2; stroka+=2;
@ -557,26 +471,18 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color); DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color);
NewLine(); NewLine();
} }
if (istag("img")) if (istag("meta")) || (istag("?xml")) {
{
ImgCache.Images( left1, top1, WB1.list.w);
return;
}
if (istag("meta")) || (istag("?xml"))
{
do{ do{
if (isattr("charset=")) || (isattr("content=")) || (isattr("encoding=")) if (isattr("charset=")) || (isattr("content=")) || (isattr("encoding="))
{ {
strcpy(#val, #val[strrchr(#val, '=')]); //ïîèñê â content= strcpy(#val, #val[strrchr(#val, '=')]); //ïîèñê â content=
strlwr(#val); strlwr(#val);
meta_encoding = CH_NULL; if (isval("utf-8")) || (isval("utf8")) meta_encoding = CH_UTF8;
if (isval("utf-8")) || (isval("utf8")) meta_encoding = CH_UTF8;
else if (isval("koi8-r")) || (isval("koi8-u")) meta_encoding = CH_KOI8; else if (isval("koi8-r")) || (isval("koi8-u")) meta_encoding = CH_KOI8;
else if (isval("windows-1251")) || (isval("windows1251")) meta_encoding = CH_CP1251; else if (isval("windows-1251")) || (isval("windows1251")) meta_encoding = CH_CP1251;
else if (isval("windows-1252")) || (isval("windows1252")) meta_encoding = CH_CP1252;
else if (isval("iso-8859-5")) || (isval("iso8859-5")) meta_encoding = CH_ISO8859_5; else if (isval("iso-8859-5")) || (isval("iso8859-5")) meta_encoding = CH_ISO8859_5;
else if (isval("dos")) || (isval("cp-866")) meta_encoding = CH_CP866; else if (isval("dos")) || (isval("cp-866")) meta_encoding = CH_CP866;
if (cur_encoding==CH_NULL) BufEncode(meta_encoding); if (cur_encoding!=meta_encoding) BufEncode(meta_encoding);
return; return;
} }
} while(GetNextParam()); } while(GetNextParam());
@ -584,7 +490,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) {
} }
} }
void BufEncode(int set_new_encoding) void TWebBrowser::BufEncode(int set_new_encoding)
{ {
int bufpointer_realsize; int bufpointer_realsize;
cur_encoding = set_new_encoding; cur_encoding = set_new_encoding;
@ -597,10 +503,6 @@ void BufEncode(int set_new_encoding)
{ {
strcpy(bufpointer, o_bufpointer); strcpy(bufpointer, o_bufpointer);
} }
if (set_new_encoding == CH_CP1251)
{
bufpointer = ChangeCharset("CP1251", "UTF-8", bufpointer);
}
} }
//============================================================================================ //============================================================================================
void TWebBrowser::DrawScroller() void TWebBrowser::DrawScroller()

View File

@ -1,19 +0,0 @@
struct Table
{
byte active;
byte max_cols;
byte max_rows;
byte cur_col;
byte cur_row;
int col_w[32];
int row_start, row_h, row_max_h;
void NewTable();
} table;
void Table::NewTable()
{
cur_row = 0;
cur_col = 0;
max_rows = 0;
max_cols = 0;
}

View File

@ -30,14 +30,14 @@
char homepage[] = FROM "html\\homepage.htm"; char homepage[] = FROM "html\\homepage.htm";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.22"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.23";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>"; char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\page_not_found_ru.htm"; char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n"; char accept_language[]= "Accept-Language: ru\n";
#else #else
char version[]=" Text-based Browser 1.22"; char version[]=" Text-based Browser 1.23";
?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last" ?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>"; char loading[] = "Loading...<br>";
@ -308,6 +308,7 @@ void SetElementSizes()
address_box.width = Form.cwidth - address_box.left - 25 - 22; address_box.width = Form.cwidth - address_box.left - 25 - 22;
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom, WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom,
Form.cheight - TOOLBAR_H - STATUSBAR_H, WB1.list.font_h + WB1.DrawBuf.zoom + WB1.DrawBuf.zoom * WB1.DrawBuf.zoom); Form.cheight - TOOLBAR_H - STATUSBAR_H, WB1.list.font_h + WB1.DrawBuf.zoom + WB1.DrawBuf.zoom * WB1.DrawBuf.zoom);
WB1.list.wheel_size = 7;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h; WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h); WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
@ -317,6 +318,7 @@ void Draw_Window()
{ {
int img_off; int img_off;
// tab { // tab {
/*
if (TAB_H) if (TAB_H)
{ {
DrawBar(0, 0, TAB_W, TAB_H+1, panel_color); DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
@ -326,7 +328,7 @@ void Draw_Window()
DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color); DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0); img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
} }
else DrawBar(0,0, Form.cwidth,1, col_bg); else */ DrawBar(0,0, Form.cwidth,1, col_bg);
// } // }
DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color); DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
@ -494,19 +496,6 @@ void ProcessLinks(int id)
} }
strcpy(#URL, PageLinks.GetURL(id-401)); strcpy(#URL, PageLinks.GetURL(id-401));
//$1 - Condition Script
if (URL[0] == '$')
{
if (URL[1]=='-') && (condition_href) condition_href--;
else if (URL[1]=='+')
{
if (condition_href<condition_max) condition_href++; else notify(T_LAST_SLIDE);
}
else condition_href = atoi(#URL+1);
strcpy(#URL, BrowserHistory.CurrentUrl());
ShowPage();
return;
}
//#1 //#1
if (URL[0] == '#') if (URL[0] == '#')
{ {

View File

@ -12,6 +12,7 @@ struct llist
int x, y, w, h, line_h, text_y; int x, y, w, h, line_h, text_y;
dword font_w, font_h, font_type; dword font_w, font_h, font_type;
int count, visible, first, current, column_max; //visible = row_max int count, visible, first, current, column_max; //visible = row_max
int wheel_size;
int active; int active;
void ClearList(); void ClearList();
int MouseOver(int xx, yy); int MouseOver(int xx, yy);
@ -57,6 +58,7 @@ void llist::SetSizes(int xx, yy, ww, hh, line_hh)
line_h = line_hh; line_h = line_hh;
text_y = line_h - font_h / 2; text_y = line_h - font_h / 2;
visible = h / line_h; visible = h / line_h;
wheel_size = 3;
//if (visible > count) visible=count; //if (visible > count) visible=count;
} }
@ -74,13 +76,13 @@ int llist::MouseScroll(dword scroll_state)
if (scroll_state == 65535) if (scroll_state == 65535)
{ {
if (first == 0) return 0; if (first == 0) return 0;
if (first > 3) first -= 2; else first=0; if (first > wheel_size+1) first -= wheel_size; else first=0;
return 1; return 1;
} }
if (scroll_state == 1) if (scroll_state == 1)
{ {
if (visible + first == count) return 0; if (visible + first == count) return 0;
if (visible+first+3 > count) first = count - visible; else first+=2; if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
return 1; return 1;
} }
return 0; return 0;