Links implementation fully rewritten

git-svn-id: svn://kolibrios.org@4491 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2014-01-19 22:46:58 +00:00
parent 498bfb6f7a
commit f60d20d830
4 changed files with 140 additions and 73 deletions

View File

@ -1,6 +1,6 @@
#include "..\lib\draw_buf.h" #include "..\lib\draw_buf.h"
#include "..\lib\list_box.h" #include "..\lib\list_box.h"
#include "..\TWB\links.h"
int downloader_id; int downloader_id;
@ -35,7 +35,7 @@ struct TWebBrowser {
TWebBrowser WB1; TWebBrowser WB1;
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab, byte b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab,
link, ignor_text, cur_encoding, text_align; link, ignor_text, cur_encoding, text_align;
byte condition_text_active, condition_text_val, condition_href, condition_max; byte condition_text_active, condition_text_val, condition_href, condition_max;
@ -45,7 +45,8 @@ enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
dword text_colors[300]; dword text_colors[300];
dword text_color_index; dword text_color_index;
dword link_color; dword link_color_inactive;
dword link_color_active;
dword bg_color; dword bg_color;
int stroka; int stroka;
@ -65,7 +66,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\links.h"
@ -212,7 +212,8 @@ void TWebBrowser::ParseHTML(dword bword){
condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè
condition_max = 255; condition_max = 255;
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
link_color = 0x0000FF; link_color_inactive = 0x0000FF;
link_color_active = 0xFF0000;
bg_color = 0xFFFFFF; bg_color = 0xFFFFFF;
DrawBuf.Fill(bg_color); DrawBuf.Fill(bg_color);
PageLinks.Clear(); PageLinks.Clear();
@ -331,9 +332,9 @@ void TWebBrowser::ParseHTML(dword bword){
TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
} }
DrawPage(); DrawPage();
line=NULL;
if (tag) WhatTextStyle(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //îáðàáîòêà òåãîâ if (tag) WhatTextStyle(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //îáðàáîòêà òåãîâ
line=NULL;
tag = parametr = tagparam = ignor_param = NULL; tag = parametr = tagparam = ignor_param = NULL;
break; break;
@ -384,35 +385,46 @@ void TWebBrowser::ParseHTML(dword bword){
char oldtag[100]; char oldtag[100];
void TWebBrowser::WhatTextStyle(int left1, top1, width1) { void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
dword hr_color; dword hr_color;
byte opened;
//ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ //ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
if (tag[0] == '/') if (tag[0] == '/')
{ {
rez = 0; opened = 0;
strcpy(#tag, #tag+1); strcpy(#tag, #tag+1);
} }
else rez = 1; else opened = 1;
if (isTag("html")) if (isTag("html"))
{ {
IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0; IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (opened==0) ignor_text = 1; ELSE ignor_text = 0;
return; return;
} }
if (isTag("script")) || (isTag("style")) || (isTag("binary")) ignor_text = rez; if (isTag("script")) || (isTag("style")) || (isTag("binary")) ignor_text = opened;
if(isTag("title")) if(isTag("title"))
{ {
if (rez) 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")) chrcat(#line, '\"'); IF(isTag("q"))
{
if (opened)
{
TextGoDown(left1, top1, width1);
strcat(#line, ' \"');
}
if (!opened)
{
chrcat(#line, '\"');
TextGoDown(left1, top1, width1);
}
}
if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
{ {
@ -422,8 +434,9 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (isTag("body")) if (isTag("body"))
{ {
do{ do{
if (!strcmp(#parametr, "condition_max=")) { condition_max = atoi(#options); debugi(condition_max); } if (!strcmp(#parametr, "condition_max=")) condition_max = atoi(#options);
if (!strcmp(#parametr, "link=")) link_color = GetColor(#options); if (!strcmp(#parametr, "link=")) link_color_inactive = GetColor(#options);
if (!strcmp(#parametr, "alink=")) link_color_active = GetColor(#options);
if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options); if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
if (!strcmp(#parametr, "bgcolor=")) if (!strcmp(#parametr, "bgcolor="))
{ {
@ -436,7 +449,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (isTag("a")) if (isTag("a"))
{ {
if (rez) if (opened)
{ {
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
@ -450,8 +463,8 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
link = 1; link = 1;
blink++; blink++;
text_colors[text_color_index] = link_color; text_colors[text_color_index] = link_color_inactive;
PageLinks.Add(#options); PageLinks.AddLink(#options, stolbec*6+left1, top1);
} }
if (anchor) && (!strcmp(#parametr, "name=")) if (anchor) && (!strcmp(#parametr, "name="))
{ {
@ -464,6 +477,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
else { else {
link = 0; link = 0;
PageLinks.AddText(#line, strlen(#line)*6, list.line_h);
IF(text_color_index > 0) text_color_index--; IF(text_color_index > 0) text_color_index--;
} }
return; return;
@ -471,7 +485,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (isTag("font")) if (isTag("font"))
{ {
if (rez) 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];
@ -498,14 +512,14 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (isTag("p")) { if (isTag("p")) {
IF(oldtag[0] == 'h') return; IF(oldtag[0] == 'h') return;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
IF(rez) TextGoDown(left1, top1 + 10, width1); IF(opened) TextGoDown(left1, top1 + 10, width1);
return; return;
} }
/* /*
if (isTag("center")) if (isTag("center"))
{ {
if (rez) text_align = ALIGN_CENTER; if (opened) text_align = ALIGN_CENTER;
if (!rez) if (!opened)
{ {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
@ -514,8 +528,8 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
if (isTag("right")) if (isTag("right"))
{ {
if (rez) text_align = ALIGN_RIGHT; if (opened) text_align = ALIGN_RIGHT;
if (!rez) if (!opened)
{ {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
@ -525,15 +539,15 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
*/ */
if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) { if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1); if (opened) && (stroka>1) TextGoDown(left1, top1 + 10, width1);
strcpy(#oldtag, #tag); strcpy(#oldtag, #tag);
if (rez) if (opened)
{ {
if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER; if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER;
if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT; if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT;
b_text = 1; b_text = 1;
} }
if (!rez) if (!opened)
{ {
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
b_text = 0; b_text = 0;
@ -544,47 +558,47 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
oldtag=NULL; oldtag=NULL;
if (isTag("b")) || (isTag("strong")) || (isTag("big")) { if (isTag("b")) || (isTag("strong")) || (isTag("big")) {
b_text = rez; b_text = opened;
return; return;
} }
if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) { if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) {
i_text = rez; i_text = opened;
return; return;
} }
if (isTag("dt")) if (isTag("dt"))
{ {
li_text = rez; li_text = opened;
IF(rez == 0) return; IF(opened == 0) return;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
return; return;
} }
if (isTag("condition")) if (isTag("condition"))
{ {
condition_text_active = rez; condition_text_active = opened;
if (rez) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options); if (opened) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options);
return; return;
} }
if (isTag("li")) || (isTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè if (isTag("li")) || (isTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
{ {
li_text = rez; li_text = opened;
if (rez) if (opened)
{ {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555); if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
} }
return; return;
} }
if (isTag("u")) || (isTag("ins")) u_text = rez; if (isTag("u")) || (isTag("ins")) u_text = opened;
if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = rez; if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = opened;
if (isTag("ul")) || (isTag("ol")) IF(!rez) if (isTag("ul")) || (isTag("ol")) IF(!opened)
{ {
li_text = rez; li_text = opened;
li_tab--; li_tab--;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
} ELSE li_tab++; } ELSE li_tab++;
if (isTag("dd")) stolbec += 5; if (isTag("dd")) stolbec += 5;
if (isTag("blockquote")) blq_text = rez; if (isTag("blockquote")) blq_text = opened;
if (isTag("pre")) pre_text = rez; if (isTag("pre")) pre_text = opened;
if (isTag("hr")) if (isTag("hr"))
{ {
if (anchor) || (stroka < -1) if (anchor) || (stroka < -1)
@ -599,7 +613,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
if (isTag("img")) if (isTag("img"))
{ {
ImgCache1.Images( left1, top1, width1); ImgCache.Images( left1, top1, width1);
return; return;
} }
if (isTag("meta")) || (isTag("?xml")) if (isTag("meta")) || (isTag("?xml"))
@ -617,6 +631,16 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
} }
/*
char *encodings = {
"utf-8", _UTF,
"utf8", _UTF,
"koi8-r", _KOI,
"koi8-u", _KOI,
"dos", _DOS,
"cp-866", _DOS
};
*/
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
{ {

View File

@ -6,14 +6,14 @@ struct s_image
s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) ); s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) );
struct ImgCache { struct ImageCache {
int pics_count; int pics_count;
void Free(); void Free();
int GetImage(); int GetImage();
void Images(); void Images();
} ImgCache1; };
void ImgCache::Free() void ImageCache::Free()
{ {
for ( ; pics_count>0; pics_count--) for ( ; pics_count>0; pics_count--)
{ {
@ -22,7 +22,7 @@ void ImgCache::Free()
} }
} }
int ImgCache::GetImage(dword i_path) int ImageCache::GetImage(dword i_path)
{ {
int i; int i;
for (i=0; i<pics_count; i++) if (!strcmp(#pics[i].path, i_path)) return i; //image exists for (i=0; i<pics_count; i++) if (!strcmp(#pics[i].path, i_path)) return i; //image exists
@ -34,7 +34,7 @@ int ImgCache::GetImage(dword i_path)
} }
void ImgCache::Images(int left1, top1, width1) void ImageCache::Images(int left1, top1, width1)
{ {
dword image; dword image;
char img_path[4096], alt[4096]; char img_path[4096], alt[4096];
@ -97,4 +97,6 @@ void ImgCache::Images(int left1, top1, width1)
img_draw stdcall (pics[cur_pic].image, left1-5, top1, w, h,0,img_lines_first); img_draw stdcall (pics[cur_pic].image, left1-5, top1, w, h,0,img_lines_first);
DrawBar(left1+w - 5, top1, WB1.list.w-w, h, bg_color); DrawBar(left1+w - 5, top1, WB1.list.w-w, h, bg_color);
IF (link) UnsafeDefineButton(left1 - 5, top1, w, h-1, blink + BT_HIDE, 0xB5BFC9); IF (link) UnsafeDefineButton(left1 - 5, top1, w, h-1, blink + BT_HIDE, 0xB5BFC9);
} }
ImageCache ImgCache;

View File

@ -1,36 +1,76 @@
struct array_link {
dword link, text;
int x,y,w,h;
};
struct LinksArray struct LinksArray
{ {
array_link links[100];
char page_links[12000]; char page_links[12000];
void Add(); dword buflen;
int count, active;
void Hover();
void AddLink();
void AddText();
dword GetURL(); dword GetURL();
void Clear(); void Clear();
} PageLinks; };
void LinksArray::Add(dword new_link) void LinksArray::AddLink(dword new_link, int link_x, link_y)
{ {
strcat(#page_links, new_link); links[count].x = link_x;
strcat(#page_links, "|"); links[count].y = link_y;
links[count].link = buflen;
strcpy(buflen, new_link);
buflen += strlen(new_link)+1;
count++;
}
void LinksArray::AddText(dword new_text, int link_w, link_h)
{
if (count<1) return;
links[count-1].w = link_w;
links[count-1].h = link_h;
links[count-1].text = buflen;
strcpy(buflen, new_text);
buflen += strlen(new_text)+1;
} }
dword LinksArray::GetURL(int id) dword LinksArray::GetURL(int id)
{ {
int i, j = 0; return links[id].link;
for (i = 0; i <= id - 401; i++)
{
do
{
j++;
if (j>=strlen(#page_links)) return;
}
while (page_links[j] <>'|');
}
page_links[j] = 0x00;
strcpy(#URL, #page_links+strrchr(#page_links, '|'));
return #URL;
} }
void LinksArray::Clear() void LinksArray::Clear()
{ {
strcpy(#page_links,"|"); buflen = #page_links;
} count = 0;
active = -1;
}
void LinksArray::Hover(dword mx, my, link_col_in, link_col_a)
{
int i;
if (active>=0)
{
WriteText(links[active].x,links[active].y, 0x80, link_col_in, links[active].text);
DrawBar(links[active].x,links[active].y+8,links[active].w,1, link_col_in);
active = -1;
}
for (i=0; i<count; i++)
{
if (mx>links[i].x) && (my>links[i].y) && (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h)
{
WriteText(links[i].x,links[i].y, 0x80, link_col_a, links[i].text);
DrawBar(links[i].x,links[i].y+8,links[i].w,1, link_col_a);
active = i;
return;
}
}
}
LinksArray PageLinks;

View File

@ -25,11 +25,11 @@
#include "img\URLgoto.txt"; #include "img\URLgoto.txt";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.61"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.63";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
#else #else
char version[]=" Text-based Browser 0.99.61"; char version[]=" Text-based Browser 0.99.63";
?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"
#endif #endif
@ -91,6 +91,7 @@ void main()
edit_box_mouse stdcall (#address_box); edit_box_mouse stdcall (#address_box);
m.get(); m.get();
PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active);
if (m.y>WB1.list.y) && (m.y<Form.height) && (filesize) if (m.y>WB1.list.y) && (m.y<Form.height) && (filesize)
{ {
@ -238,7 +239,7 @@ void Scan(int id)
return; return;
case 002: //free img cache case 002: //free img cache
ImgCache1.Free(); ImgCache.Free();
notify(IMAGES_CACHE_CLEARED); notify(IMAGES_CACHE_CLEARED);
WB1.ParseHTML(buf); WB1.ParseHTML(buf);
return; return;
@ -337,7 +338,7 @@ void Scan(int id)
void ProcessLinks(int id) void ProcessLinks(int id)
{ {
strcpy(#URL, PageLinks.GetURL(id)); strcpy(#URL, PageLinks.GetURL(id-401));
//$1 - Condition Script //$1 - Condition Script
if (URL[0] == '$') if (URL[0] == '$')