2020-03-26 01:12:32 +01:00
|
|
|
#include "..\TWB\colors.h"
|
|
|
|
#include "..\TWB\anchors.h"
|
|
|
|
#include "..\TWB\parce_tag.h"
|
|
|
|
#include "..\TWB\absolute_url.h"
|
|
|
|
char line[500];
|
|
|
|
#include "..\TWB\unicode_tags.h"
|
2013-12-27 13:30:42 +01:00
|
|
|
|
2015-08-19 14:48:31 +02:00
|
|
|
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
|
|
|
|
|
|
|
|
struct _style {
|
2020-03-26 01:12:32 +01:00
|
|
|
bool
|
2016-12-11 23:58:11 +01:00
|
|
|
b, u, s, h,
|
2015-08-19 14:48:31 +02:00
|
|
|
pre,
|
|
|
|
blq,
|
|
|
|
li,
|
|
|
|
li_tab,
|
2020-03-21 15:33:54 +01:00
|
|
|
button,
|
|
|
|
image,
|
2015-08-19 14:48:31 +02:00
|
|
|
align;
|
2020-03-26 01:12:32 +01:00
|
|
|
dword bg_color;
|
2015-08-19 14:48:31 +02:00
|
|
|
};
|
2013-12-27 13:30:42 +01:00
|
|
|
|
2013-12-27 00:36:17 +01:00
|
|
|
struct TWebBrowser {
|
2014-01-27 21:16:33 +01:00
|
|
|
llist list;
|
2015-08-19 14:48:31 +02:00
|
|
|
_style style;
|
2014-01-18 12:46:58 +01:00
|
|
|
DrawBufer DrawBuf;
|
2020-03-26 01:12:32 +01:00
|
|
|
dword draw_y, stolbec;
|
2016-12-21 11:56:06 +01:00
|
|
|
int zoom;
|
2020-03-26 01:12:32 +01:00
|
|
|
dword o_bufpointer;
|
2020-03-22 20:50:16 +01:00
|
|
|
void SetPageDefaults();
|
2020-03-26 01:12:32 +01:00
|
|
|
void AddCharToTheLine();
|
|
|
|
void ParseHtml();
|
2015-08-23 12:12:13 +02:00
|
|
|
void SetStyle();
|
|
|
|
void DrawStyle();
|
2013-12-27 00:36:17 +01:00
|
|
|
void DrawPage();
|
|
|
|
void DrawScroller();
|
2014-03-15 16:16:08 +01:00
|
|
|
void NewLine();
|
2020-03-25 01:18:19 +01:00
|
|
|
bool CheckForLineBreak();
|
2015-08-19 17:14:52 +02:00
|
|
|
void BufEncode();
|
2014-03-23 18:12:21 +01:00
|
|
|
} WB1;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
dword link_color_inactive;
|
|
|
|
dword link_color_active;
|
|
|
|
dword page_bg;
|
2015-08-19 14:48:31 +02:00
|
|
|
|
2020-03-21 15:33:54 +01:00
|
|
|
bool
|
2015-08-19 14:48:31 +02:00
|
|
|
link,
|
|
|
|
cur_encoding,
|
|
|
|
t_html,
|
|
|
|
t_body;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
#include "..\TWB\img_cache.h"
|
|
|
|
#include "..\TWB\links.h"
|
|
|
|
|
2015-09-01 11:36:58 +02:00
|
|
|
dword bufpointer=0;
|
|
|
|
dword bufsize=0;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
int body_magrin=6;
|
2016-12-11 23:58:11 +01:00
|
|
|
int basic_line_h=22;
|
2014-03-12 23:56:28 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
char header[150];
|
2015-08-23 21:59:44 +02:00
|
|
|
char oldtag[100];
|
2014-01-18 12:46:58 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
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};
|
2014-01-18 12:46:58 +01:00
|
|
|
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2015-08-23 12:12:13 +02:00
|
|
|
void TWebBrowser::DrawStyle()
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
dword start_x, line_length, stolbec_len;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
|
|
|
if (!header)
|
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
strncpy(#header, #line, sizeof(header)-1);
|
2013-12-27 00:36:17 +01:00
|
|
|
line = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-03-13 00:30:28 +01:00
|
|
|
if (t_html) && (!t_body) return;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
if (line)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2016-12-11 23:58:11 +01:00
|
|
|
start_x = stolbec * list.font_w + body_magrin + list.x;
|
2016-12-21 11:56:06 +01:00
|
|
|
stolbec_len = strlen(#line) * zoom;
|
2015-08-23 21:59:44 +02:00
|
|
|
line_length = stolbec_len * list.font_w;
|
2015-08-05 00:21:08 +02:00
|
|
|
|
2020-03-23 16:53:56 +01:00
|
|
|
if (debug_mode) {
|
2020-03-25 01:18:19 +01:00
|
|
|
DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
|
2020-03-23 16:53:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 19:49:45 +01:00
|
|
|
if (style.bg_color!=page_bg) {
|
2020-03-25 01:18:19 +01:00
|
|
|
DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
|
2020-03-21 19:49:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 15:33:54 +01:00
|
|
|
if (style.image) {
|
2020-03-21 19:49:45 +01:00
|
|
|
DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
|
2020-03-21 15:33:54 +01:00
|
|
|
}
|
|
|
|
if (style.button) {
|
|
|
|
DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
|
|
|
|
DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:45:36 +01:00
|
|
|
DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line);
|
|
|
|
if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line);
|
2016-12-21 11:56:06 +01:00
|
|
|
if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
|
|
|
|
if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
|
2015-03-16 15:20:32 +01:00
|
|
|
if (link) {
|
2020-03-22 20:54:20 +01:00
|
|
|
if (line[0]==' ') && (line[1]==NULL) {} else {
|
2020-03-25 01:18:19 +01:00
|
|
|
DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, link_color_inactive);
|
2020-03-22 20:50:16 +01:00
|
|
|
PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom);
|
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2014-03-30 13:57:13 +02:00
|
|
|
stolbec += stolbec_len;
|
2020-03-25 01:18:19 +01:00
|
|
|
if (debug_mode) debug(#line);
|
|
|
|
line = NULL;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2020-03-22 20:50:16 +01:00
|
|
|
void TWebBrowser::SetPageDefaults()
|
|
|
|
{
|
|
|
|
style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
|
|
|
|
style.li = link = text_color_index = text_colors[0] = style.li_tab = false;
|
2015-08-19 14:48:31 +02:00
|
|
|
style.align = ALIGN_LEFT;
|
2014-01-19 23:46:58 +01:00
|
|
|
link_color_inactive = 0x0000FF;
|
|
|
|
link_color_active = 0xFF0000;
|
2020-03-21 19:49:45 +01:00
|
|
|
page_bg = 0xFFFFFF;
|
|
|
|
style.bg_color = page_bg;
|
|
|
|
DrawBuf.Fill(0, page_bg);
|
2014-01-21 20:22:03 +01:00
|
|
|
PageLinks.Clear();
|
2020-03-26 01:12:32 +01:00
|
|
|
anchors.clear();
|
|
|
|
strncpy(#header, #version, sizeof(header)-1);
|
2020-03-22 20:50:16 +01:00
|
|
|
cur_encoding = CH_NULL;
|
2016-12-11 23:58:11 +01:00
|
|
|
draw_y = body_magrin;
|
2013-12-27 00:36:17 +01:00
|
|
|
stolbec = 0;
|
|
|
|
line = 0;
|
2020-03-26 01:12:32 +01:00
|
|
|
zoom = 1;
|
|
|
|
if (o_bufpointer) free(o_bufpointer);
|
|
|
|
o_bufpointer = 0;
|
2020-03-22 20:50:16 +01:00
|
|
|
}
|
|
|
|
//============================================================================================
|
2020-03-26 01:12:32 +01:00
|
|
|
void TWebBrowser::AddCharToTheLine(unsigned char _char)
|
|
|
|
{
|
|
|
|
dword line_len;
|
|
|
|
if (_char<=15) _char=' ';
|
|
|
|
line_len = strlen(#line);
|
|
|
|
if (!style.pre) && (_char == ' ')
|
|
|
|
{
|
|
|
|
if (line[line_len-1]==' ') return; //no double spaces
|
|
|
|
if (!stolbec) && (!line) return; //no paces at the beginning of the line
|
|
|
|
}
|
|
|
|
if (line_len < sizeof(line)) chrcat(#line, _char);
|
|
|
|
CheckForLineBreak();
|
|
|
|
}
|
|
|
|
//============================================================================================
|
|
|
|
void TWebBrowser::ParseHtml(){
|
2020-03-22 20:50:16 +01:00
|
|
|
word bukva[2];
|
2020-03-26 01:12:32 +01:00
|
|
|
char unicode_symbol[10];
|
|
|
|
dword unicode_symbol_result;
|
2020-03-22 20:50:16 +01:00
|
|
|
dword j;
|
2020-03-26 01:12:32 +01:00
|
|
|
bool ignor_param=false;
|
|
|
|
int tab_len;
|
2020-03-22 20:50:16 +01:00
|
|
|
dword bufpos;
|
|
|
|
SetPageDefaults();
|
2020-03-23 16:53:56 +01:00
|
|
|
if (strstri(bufpointer, "<body")==-1) {
|
|
|
|
t_body = true;
|
|
|
|
if (strstri(bufpointer, "<html")==-1) style.pre = true; //show linebreaks for a plaint text
|
|
|
|
}
|
2015-08-27 01:45:56 +02:00
|
|
|
for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2014-01-22 01:08:47 +01:00
|
|
|
bukva = ESBYTE[bufpos];
|
2013-12-27 00:36:17 +01:00
|
|
|
switch (bukva)
|
|
|
|
{
|
|
|
|
case 0x0a:
|
2020-03-26 01:12:32 +01:00
|
|
|
if (style.pre) {
|
2015-09-01 11:36:58 +02:00
|
|
|
DrawStyle();
|
|
|
|
NewLine();
|
2020-03-26 01:12:32 +01:00
|
|
|
} else {
|
|
|
|
AddCharToTheLine(0x0a);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
break;
|
|
|
|
case 0x09:
|
|
|
|
if (style.pre) {
|
|
|
|
tab_len = strlen(#line) + stolbec % 4;
|
|
|
|
if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
|
2013-12-27 00:36:17 +01:00
|
|
|
for (j=0; j<tab_len; j++;) chrcat(#line,' ');
|
2020-03-26 01:12:32 +01:00
|
|
|
} else {
|
|
|
|
AddCharToTheLine(0x09);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
break;
|
2013-12-27 00:36:17 +01:00
|
|
|
case '&': // and so on
|
2020-03-26 01:12:32 +01:00
|
|
|
for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-03-23 16:53:56 +01:00
|
|
|
bukva = ESBYTE[bufpos+j];
|
2020-03-26 01:12:32 +01:00
|
|
|
chrcat(#unicode_symbol, bukva);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (bukva = GetUnicodeSymbol(#unicode_symbol)) {
|
2020-03-23 16:53:56 +01:00
|
|
|
bufpos += j;
|
2020-03-25 01:18:19 +01:00
|
|
|
CheckForLineBreak();
|
2020-03-23 16:53:56 +01:00
|
|
|
} else {
|
2020-03-26 01:12:32 +01:00
|
|
|
AddCharToTheLine('&');
|
2020-03-23 16:53:56 +01:00
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
break;
|
|
|
|
case '<':
|
2015-08-19 17:14:52 +02:00
|
|
|
bufpos++;
|
2015-08-23 21:59:44 +02:00
|
|
|
if (!strncmp(bufpos,"!--",3))
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2017-09-17 14:35:45 +02:00
|
|
|
bufpos+=3;
|
|
|
|
while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize)
|
|
|
|
{
|
|
|
|
bufpos++;
|
|
|
|
}
|
2020-03-22 20:50:16 +01:00
|
|
|
bufpos+=2;
|
2017-09-17 14:35:45 +02:00
|
|
|
break;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
tag.reset();
|
|
|
|
if (ESBYTE[bufpos] == '/') {
|
|
|
|
tag.opened = false;
|
|
|
|
bufpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ignor_param=false;
|
2016-11-21 21:25:00 +01:00
|
|
|
while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2014-01-22 01:08:47 +01:00
|
|
|
bukva = ESBYTE[bufpos];
|
2013-12-27 00:36:17 +01:00
|
|
|
if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
|
|
|
|
if (!ignor_param) && (bukva <>' ')
|
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
if (strlen(#tag.name)+1<sizeof(tag.name)) chrcat(#tag.name, bukva);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ignor_param = true;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (strlen(#tag.params)+1<sizeof(tag.params)) strcat(#tag.params, #bukva);
|
|
|
|
// chrncat(#tag.params, bukva, sizeof(tag.params)-1);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2014-01-22 01:08:47 +01:00
|
|
|
bufpos++;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
strlwr(#tag.name);
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2020-03-22 20:50:16 +01:00
|
|
|
// ignore text inside the next tags
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) {
|
|
|
|
sprintf(#tag.params, "</%s>", #tag.name);
|
|
|
|
j = strstri(bufpos, #tag.params);
|
|
|
|
if (j!=-1) bufpos = j-1;
|
2020-03-22 20:50:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
|
|
|
|
if (tag.params) tag.parse_params();
|
2020-03-22 20:50:16 +01:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.name) && (!tag.is("i")) && (!tag.is("svg")) {
|
2020-03-25 01:18:19 +01:00
|
|
|
CheckForLineBreak();
|
2020-03-22 20:50:16 +01:00
|
|
|
DrawStyle();
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.name) SetStyle();
|
2020-03-22 20:50:16 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
strncpy(#oldtag, #tag.name, sizeof(oldtag)-1);
|
2013-12-27 00:36:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
2020-03-26 01:12:32 +01:00
|
|
|
AddCharToTheLine(ESBYTE[bufpos]);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-23 12:12:13 +02:00
|
|
|
DrawStyle();
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2020-03-26 01:12:32 +01:00
|
|
|
list.count = draw_y;
|
2020-03-27 11:38:54 +01:00
|
|
|
list.CheckDoesValuesOkey();
|
|
|
|
anchors.current = NULL;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2020-03-25 01:18:19 +01:00
|
|
|
bool TWebBrowser::CheckForLineBreak()
|
2014-03-30 13:57:13 +02:00
|
|
|
{
|
2020-03-25 01:18:19 +01:00
|
|
|
int line_break_pos;
|
2014-03-30 13:57:13 +02:00
|
|
|
char new_line_text[4096];
|
2020-03-25 01:18:19 +01:00
|
|
|
if (strlen(#line)*zoom + stolbec < list.column_max) return false;
|
|
|
|
line_break_pos = strrchr(#line, ' ');
|
|
|
|
if (line_break_pos*zoom + stolbec > list.column_max) {
|
|
|
|
line_break_pos = list.column_max/zoom - stolbec;
|
|
|
|
while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
|
|
|
|
}
|
|
|
|
if (!line_break_pos) && (strlen(#line)*zoom>list.column_max) {
|
|
|
|
line_break_pos=list.column_max/zoom;
|
2020-03-21 15:33:54 +01:00
|
|
|
if (!stolbec)&&(style.pre) draw_y-=list.item_h; //hack to fix https://prnt.sc/rk3kyt
|
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
strcpy(#new_line_text, #line + line_break_pos);
|
|
|
|
line[line_break_pos] = 0x00;
|
2015-08-23 12:12:13 +02:00
|
|
|
DrawStyle();
|
2014-03-30 13:57:13 +02:00
|
|
|
strcpy(#line, #new_line_text);
|
|
|
|
NewLine();
|
2020-03-25 01:18:19 +01:00
|
|
|
//if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak();
|
|
|
|
return true;
|
2014-03-30 13:57:13 +02:00
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2015-08-27 01:45:56 +02:00
|
|
|
void TWebBrowser::SetStyle() {
|
2020-03-23 16:53:56 +01:00
|
|
|
char img_path[4096]=0;
|
2020-03-21 15:33:54 +01:00
|
|
|
int meta_encoding;
|
2020-03-26 01:12:32 +01:00
|
|
|
|
|
|
|
dword value;
|
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
|
|
|
|
anchors.add(value, draw_y);
|
|
|
|
if (anchors.current) && (streq(value, #anchors.current+1)) {
|
|
|
|
list.first = draw_y;
|
|
|
|
anchors.current = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("html")) {
|
|
|
|
t_html = tag.opened;
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if(tag.is("title")) {
|
|
|
|
if (tag.opened) header=NULL;
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
IF(tag.is("q"))
|
2014-01-19 23:46:58 +01:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.opened) {
|
2020-03-25 01:18:19 +01:00
|
|
|
meta_encoding = strlen(#line);
|
|
|
|
if (line[meta_encoding-1] != ' ') chrcat(#line, ' ');
|
|
|
|
chrcat(#line, '\"');
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (!tag.opened) strcat(#line, "\" ");
|
2015-08-19 17:14:52 +02:00
|
|
|
return;
|
2014-01-19 23:46:58 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("body")) {
|
|
|
|
t_body = tag.opened;
|
|
|
|
if (value = tag.get_value_of("link=")) link_color_inactive = GetColor(value);
|
|
|
|
if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value);
|
|
|
|
if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value);
|
|
|
|
if (value = tag.get_value_of("bgcolor=")) {
|
|
|
|
style.bg_color = page_bg = GetColor(value);
|
|
|
|
DrawBuf.Fill(0, page_bg);
|
2017-09-28 20:59:04 +02:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.opened) {
|
|
|
|
if (cur_encoding==CH_NULL) {
|
|
|
|
cur_encoding = CH_CP866;
|
|
|
|
//BufEncode(CH_UTF8);
|
|
|
|
debugln("Document has no information about encoding!");
|
|
|
|
}
|
|
|
|
if (!streq(#header, #version)) {
|
2017-10-06 19:50:03 +02:00
|
|
|
ChangeCharset(charsets[cur_encoding], "CP866", #header);
|
2020-03-26 01:12:32 +01:00
|
|
|
strncat(#header, " - ", sizeof(header)-1);
|
|
|
|
strncat(#header, #version, sizeof(header)-1);
|
2017-10-06 19:50:03 +02:00
|
|
|
}
|
2017-09-28 20:59:04 +02:00
|
|
|
DrawTitle(#header);
|
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("a")) {
|
|
|
|
if (tag.opened)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2016-11-21 21:25:00 +01:00
|
|
|
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
|
|
|
|
{
|
|
|
|
text_color_index++;
|
|
|
|
text_colors[text_color_index] = text_colors[text_color_index-1];
|
|
|
|
link = 1;
|
|
|
|
text_colors[text_color_index] = link_color_inactive;
|
|
|
|
PageLinks.AddLink(value);
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-27 00:36:17 +01:00
|
|
|
link = 0;
|
|
|
|
IF(text_color_index > 0) text_color_index--;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("font")) {
|
2020-03-21 19:49:45 +01:00
|
|
|
style.bg_color = page_bg;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.opened)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
|
|
|
text_color_index++;
|
|
|
|
text_colors[text_color_index] = text_colors[text_color_index-1];
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value);
|
|
|
|
if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2015-08-19 17:14:52 +02:00
|
|
|
else if (text_color_index > 0) text_color_index--;
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("div")) {
|
|
|
|
if (streq(#oldtag,"div")) && (tag.opened) return;
|
2020-03-22 20:50:16 +01:00
|
|
|
NewLine();
|
|
|
|
//IF (oldtag[0] != 'h')
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
|
2020-03-22 20:50:16 +01:00
|
|
|
NewLine();
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("p")) {
|
2020-03-22 20:50:16 +01:00
|
|
|
IF (oldtag[0] == 'h') || (streq(#oldtag,"td")) || (streq(#oldtag,"p")) return;
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2020-03-26 01:12:32 +01:00
|
|
|
//IF(tag.opened) NewLine();
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("br")) { NewLine(); return; }
|
|
|
|
if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
|
|
|
|
if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; }
|
|
|
|
if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
|
|
|
|
if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
|
|
|
|
if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
|
|
|
|
if (tag.is("dd")) { stolbec += 5; return; }
|
|
|
|
if (tag.is("blockquote")) { style.blq = tag.opened; return; }
|
|
|
|
if (tag.is("pre")) || (tag.is("code")) { style.pre = tag.opened; return; }
|
|
|
|
if (tag.is("img")) {
|
|
|
|
if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
|
|
|
|
if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
|
|
|
|
if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
|
2020-03-25 01:18:19 +01:00
|
|
|
if (!img_path) { line=0; return; }
|
2020-03-21 15:33:54 +01:00
|
|
|
style.image = true;
|
|
|
|
text_color_index++;
|
|
|
|
text_colors[text_color_index] = 0x9A6F29;
|
|
|
|
if (!line) {
|
|
|
|
if (!strncmp(#img_path, "data:", 5)) img_path=0;
|
2020-03-23 16:53:56 +01:00
|
|
|
replace_char(#img_path, '?', NULL, strlen(#img_path));
|
2020-03-21 15:33:54 +01:00
|
|
|
sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
|
|
|
|
line[50]= NULL;
|
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
while (CheckForLineBreak()) {};
|
2020-03-21 15:33:54 +01:00
|
|
|
DrawStyle();
|
|
|
|
text_color_index--;
|
|
|
|
style.image = false;
|
2020-03-26 01:12:32 +01:00
|
|
|
//ImgCache.Images( list.x, draw_y, WB1.list.w);
|
2020-03-21 15:33:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
|
|
|
|
style.h = tag.opened;
|
|
|
|
if (tag.opened)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2016-12-11 23:58:11 +01:00
|
|
|
NewLine();
|
|
|
|
draw_y += 10;
|
2016-12-21 11:56:06 +01:00
|
|
|
WB1.zoom=2;
|
2016-01-08 03:19:41 +01:00
|
|
|
WB1.list.font_type |= 10011001b;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("align=")) {
|
|
|
|
if (streq(value, "center")) style.align = ALIGN_CENTER;
|
|
|
|
if (streq(value, "right")) style.align = ALIGN_RIGHT;
|
|
|
|
}
|
2016-12-11 23:58:11 +01:00
|
|
|
list.item_h = basic_line_h * 2;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("h1")) style.b = true;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2015-08-23 21:59:44 +02:00
|
|
|
else
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("h1")) style.b = false;
|
2016-12-11 23:58:11 +01:00
|
|
|
NewLine();
|
2016-12-21 11:56:06 +01:00
|
|
|
WB1.zoom=1;
|
2016-01-08 03:19:41 +01:00
|
|
|
WB1.list.font_type = 10011000b;
|
2015-08-19 14:48:31 +02:00
|
|
|
style.align = ALIGN_LEFT;
|
2016-12-11 23:58:11 +01:00
|
|
|
list.item_h = basic_line_h;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("dt")) {
|
|
|
|
style.li = tag.opened;
|
|
|
|
if (tag.opened) NewLine();
|
2013-12-29 13:48:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("li")) || (tag.is("dt"))
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
style.li = tag.opened;
|
|
|
|
if (tag.opened)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2020-03-21 19:49:45 +01:00
|
|
|
stolbec = style.li_tab * 5 - 2;
|
2020-03-21 15:33:54 +01:00
|
|
|
strcpy(#line, "\31 ");
|
2020-03-21 19:49:45 +01:00
|
|
|
//stolbec-=2;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("ul")) || (tag.is("ol")) {
|
|
|
|
if (!tag.opened)
|
2015-08-19 17:14:52 +02:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
style.li = tag.opened;
|
2015-08-19 17:14:52 +02:00
|
|
|
style.li_tab--;
|
|
|
|
NewLine();
|
|
|
|
}
|
|
|
|
else style.li_tab++;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("hr")) {
|
|
|
|
if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
|
2015-08-27 01:45:56 +02:00
|
|
|
$push edi;
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2015-08-27 01:45:56 +02:00
|
|
|
$pop edi;
|
2020-03-22 20:50:16 +01:00
|
|
|
draw_y += 10;
|
2016-12-11 23:58:11 +01:00
|
|
|
DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2020-03-22 20:50:16 +01:00
|
|
|
draw_y += 10;
|
2015-08-27 01:45:56 +02:00
|
|
|
return;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("meta")) || (tag.is("?xml")) {
|
2016-01-08 03:19:41 +01:00
|
|
|
meta_encoding = CH_NULL;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
|
|
|
|
{
|
|
|
|
value += strrchr(value, '='); //search in content=
|
|
|
|
strlwr(value);
|
|
|
|
if (streq(value,"utf-8")) || (streq(value,"utf8")) meta_encoding = CH_UTF8;
|
|
|
|
else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251;
|
|
|
|
else if (streq(value,"dos")) || (streq(value,"cp-866")) meta_encoding = CH_CP866;
|
|
|
|
else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) meta_encoding = CH_ISO8859_5;
|
|
|
|
else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) meta_encoding = CH_KOI8;
|
|
|
|
}
|
2016-01-08 03:19:41 +01:00
|
|
|
if (meta_encoding!=CH_NULL) BufEncode(meta_encoding);
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-22 20:50:16 +01:00
|
|
|
//============================================================================================
|
2016-12-21 11:56:06 +01:00
|
|
|
void TWebBrowser::BufEncode(dword set_new_encoding)
|
2015-08-10 09:09:10 +02:00
|
|
|
{
|
2017-09-28 20:59:04 +02:00
|
|
|
if (cur_encoding == set_new_encoding) return;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (o_bufpointer==0) {
|
2015-08-10 09:09:10 +02:00
|
|
|
o_bufpointer = malloc(bufsize);
|
|
|
|
strcpy(o_bufpointer, bufpointer);
|
2020-03-26 01:12:32 +01:00
|
|
|
} else {
|
2015-08-10 09:09:10 +02:00
|
|
|
strcpy(bufpointer, o_bufpointer);
|
|
|
|
}
|
2020-03-21 15:33:54 +01:00
|
|
|
//debugval("cur_encoding ", cur_encoding);
|
|
|
|
//debugval("set_new_encoding", set_new_encoding);
|
2017-09-28 20:59:04 +02:00
|
|
|
cur_encoding = set_new_encoding;
|
|
|
|
bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);
|
2015-08-10 09:09:10 +02:00
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2014-03-21 22:21:11 +01:00
|
|
|
void TWebBrowser::DrawScroller()
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2013-12-27 13:30:42 +01:00
|
|
|
scroll_wv.max_area = list.count;
|
|
|
|
scroll_wv.cur_area = list.visible;
|
|
|
|
scroll_wv.position = list.first;
|
2015-03-16 15:20:32 +01:00
|
|
|
scroll_wv.all_redraw = 0;
|
2014-01-19 18:12:45 +01:00
|
|
|
scroll_wv.start_x = list.x + list.w;
|
2014-01-22 01:08:47 +01:00
|
|
|
scroll_wv.start_y = list.y;
|
2015-08-05 00:21:08 +02:00
|
|
|
scroll_wv.size_y = list.h;
|
2013-12-27 13:30:42 +01:00
|
|
|
scrollbar_v_draw(#scroll_wv);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2014-03-23 23:49:49 +01:00
|
|
|
void TWebBrowser::NewLine()
|
2014-01-18 12:46:58 +01:00
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
dword onleft, ontop;
|
2020-03-21 15:33:54 +01:00
|
|
|
static int empty_line=0;
|
2014-03-23 23:49:49 +01:00
|
|
|
|
2016-12-11 23:58:11 +01:00
|
|
|
if (!stolbec) && (draw_y==body_magrin) return;
|
2020-03-21 15:33:54 +01:00
|
|
|
|
2020-03-23 16:53:56 +01:00
|
|
|
if (style.li) && (stolbec == style.li_tab * 5) {
|
|
|
|
if (empty_line<1) empty_line++;
|
|
|
|
else return;
|
|
|
|
} else if (!stolbec) {
|
2020-03-21 15:33:54 +01:00
|
|
|
if (empty_line<1) empty_line++;
|
|
|
|
else return;
|
|
|
|
} else {
|
|
|
|
empty_line=0;
|
|
|
|
}
|
2016-12-11 23:58:11 +01:00
|
|
|
|
|
|
|
onleft = list.x + body_magrin;
|
|
|
|
ontop = draw_y + list.y;
|
2014-03-13 00:30:28 +01:00
|
|
|
if (t_html) && (!t_body) return;
|
2016-12-11 23:58:11 +01:00
|
|
|
draw_y += list.item_h;
|
2015-08-19 14:48:31 +02:00
|
|
|
if (style.blq) stolbec = 6; else stolbec = 0;
|
|
|
|
if (style.li) stolbec = style.li_tab * 5;
|
2020-03-25 01:18:19 +01:00
|
|
|
if (debug_mode) debugln(NULL);
|
2014-01-19 21:06:42 +01:00
|
|
|
}
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2015-08-23 12:12:13 +02:00
|
|
|
void TWebBrowser::DrawPage()
|
|
|
|
{
|
2016-12-11 23:58:11 +01:00
|
|
|
PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);
|
2015-08-23 12:12:13 +02:00
|
|
|
DrawScroller();
|
|
|
|
}
|