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

View File

@ -6,14 +6,14 @@ struct s_image
s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) );
struct ImgCache {
struct ImageCache {
int pics_count;
void Free();
int GetImage();
void Images();
} ImgCache1;
};
void ImgCache::Free()
void ImageCache::Free()
{
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;
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;
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);
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);
}
}
ImageCache ImgCache;

View File

@ -1,36 +1,76 @@
struct array_link {
dword link, text;
int x,y,w,h;
};
struct LinksArray
{
array_link links[100];
char page_links[12000];
void Add();
dword buflen;
int count, active;
void Hover();
void AddLink();
void AddText();
dword GetURL();
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);
strcat(#page_links, "|");
links[count].x = link_x;
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)
{
int i, j = 0;
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;
return links[id].link;
}
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";
#ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.61";
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.63";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
#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 T_LAST_SLIDE "This slide is the last"
#endif
@ -91,6 +91,7 @@ void main()
edit_box_mouse stdcall (#address_box);
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)
{
@ -238,7 +239,7 @@ void Scan(int id)
return;
case 002: //free img cache
ImgCache1.Free();
ImgCache.Free();
notify(IMAGES_CACHE_CLEARED);
WB1.ParseHTML(buf);
return;
@ -337,7 +338,7 @@ void Scan(int id)
void ProcessLinks(int id)
{
strcpy(#URL, PageLinks.GetURL(id));
strcpy(#URL, PageLinks.GetURL(id-401));
//$1 - Condition Script
if (URL[0] == '$')