2020-03-26 01:12:32 +01:00
|
|
|
#include "..\TWB\colors.h"
|
|
|
|
#include "..\TWB\anchors.h"
|
2020-04-10 18:19:52 +02:00
|
|
|
#include "..\TWB\parse_tag.h"
|
2020-03-30 23:29:52 +02:00
|
|
|
#include "..\TWB\special.h"
|
2020-05-30 00:24:39 +02:00
|
|
|
#include "..\TWB\img.h"
|
2020-04-04 01:17:28 +02:00
|
|
|
#include "..\TWB\tag_list.h"
|
2020-03-29 12:57:14 +02:00
|
|
|
dword page_bg;
|
2020-04-04 01:17:28 +02:00
|
|
|
dword link_color_default;
|
2020-03-29 12:57:14 +02:00
|
|
|
dword link_color_active;
|
|
|
|
#include "..\TWB\links.h"
|
2013-12-27 13:30:42 +01:00
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
#define BODY_MARGIN 6
|
|
|
|
#define BASIC_LINE_H 18
|
2015-08-19 14:48:31 +02:00
|
|
|
|
2020-04-10 18:19:52 +02:00
|
|
|
DrawBufer DrawBuf;
|
|
|
|
char line[500];
|
|
|
|
|
2015-08-19 14:48:31 +02:00
|
|
|
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,
|
2020-03-21 15:33:54 +01:00
|
|
|
button,
|
2020-04-04 01:17:28 +02:00
|
|
|
image;
|
2020-03-26 01:12:32 +01:00
|
|
|
dword bg_color;
|
2020-04-04 01:17:28 +02:00
|
|
|
LIST tag_list;
|
|
|
|
dword tag_title;
|
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;
|
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-04-04 01:17:28 +02:00
|
|
|
int cur_encoding, custom_encoding;
|
|
|
|
bool link, t_html, t_body;
|
|
|
|
dword bufpointer;
|
|
|
|
dword bufsize;
|
2020-05-18 12:03:45 +02:00
|
|
|
dword is_html;
|
2020-04-04 01:17:28 +02:00
|
|
|
|
2020-04-10 18:19:52 +02:00
|
|
|
void Paint();
|
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();
|
2020-03-25 01:18:19 +01:00
|
|
|
bool CheckForLineBreak();
|
2020-04-04 21:13:03 +02:00
|
|
|
void NewLine();
|
|
|
|
void DrawScroller();
|
|
|
|
void ChangeEncoding();
|
|
|
|
void DrawPage();
|
2020-04-04 01:17:28 +02:00
|
|
|
char header[150];
|
|
|
|
};
|
2014-03-12 23:56:28 +01:00
|
|
|
|
2020-03-29 12:57:14 +02:00
|
|
|
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
|
2014-01-18 12:46:58 +01:00
|
|
|
|
2015-08-19 14:54:01 +02:00
|
|
|
//============================================================================================
|
2020-04-10 18:19:52 +02:00
|
|
|
void TWebBrowser::Paint()
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2016-12-21 11:56:06 +01:00
|
|
|
dword start_x, line_length, stolbec_len;
|
2020-04-04 21:13:03 +02:00
|
|
|
dword text_color__;
|
2013-12-27 00:36:17 +01:00
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
if (style.tag_title)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-04-04 01:17:28 +02:00
|
|
|
strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
|
|
|
|
strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
|
|
|
|
strncat(#header, #version, sizeof(TWebBrowser.header)-1);
|
2020-03-30 23:29:52 +02:00
|
|
|
line = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (t_html) && (!t_body) {
|
2013-12-27 00:36:17 +01:00
|
|
|
line = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-21 11:56:06 +01:00
|
|
|
if (line)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-04-04 01:17:28 +02:00
|
|
|
start_x = stolbec * list.font_w + BODY_MARGIN + 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-04-04 21:13:03 +02:00
|
|
|
text_color__ = text_colors[text_color_index];
|
|
|
|
if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default;
|
|
|
|
|
2020-05-07 17:43:50 +02:00
|
|
|
DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL);
|
|
|
|
if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL);
|
2020-04-04 21:13:03 +02:00
|
|
|
if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__);
|
|
|
|
if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__);
|
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-04-04 01:17:28 +02:00
|
|
|
DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default);
|
2020-05-22 23:39:04 +02:00
|
|
|
links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom);
|
2020-03-22 20:50:16 +01:00
|
|
|
}
|
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 =
|
2020-04-04 01:17:28 +02:00
|
|
|
link = text_color_index = text_colors[0] = style.tag_title = false;
|
|
|
|
style.tag_list.reset();
|
|
|
|
link_color_default = 0x0000FF;
|
2014-01-19 23:46:58 +01:00
|
|
|
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);
|
2020-05-22 23:39:04 +02:00
|
|
|
links.clear();
|
2020-03-26 01:12:32 +01:00
|
|
|
anchors.clear();
|
2020-03-30 23:29:52 +02:00
|
|
|
header = NULL;
|
2020-04-04 01:17:28 +02:00
|
|
|
cur_encoding = CH_CP866;
|
|
|
|
draw_y = BODY_MARGIN;
|
2013-12-27 00:36:17 +01:00
|
|
|
stolbec = 0;
|
|
|
|
line = 0;
|
2020-03-26 01:12:32 +01:00
|
|
|
zoom = 1;
|
2020-03-29 12:57:14 +02:00
|
|
|
//hold original buffer
|
|
|
|
if (o_bufpointer) o_bufpointer=free(o_bufpointer);
|
|
|
|
o_bufpointer = malloc(bufsize);
|
|
|
|
memmov(o_bufpointer, bufpointer, bufsize);
|
2020-04-04 01:17:28 +02:00
|
|
|
if (custom_encoding != -1) {
|
|
|
|
cur_encoding = custom_encoding;
|
2020-04-13 15:16:55 +02:00
|
|
|
bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
|
2020-04-04 01:17:28 +02:00
|
|
|
}
|
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
|
|
|
|
}
|
2020-04-10 18:19:52 +02:00
|
|
|
if (line_len < sizeof(line)) chrcat(#line, _char);
|
2020-03-26 01:12:32 +01:00
|
|
|
CheckForLineBreak();
|
|
|
|
}
|
|
|
|
//============================================================================================
|
2020-04-04 01:17:28 +02:00
|
|
|
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
|
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;
|
2020-04-04 01:17:28 +02:00
|
|
|
bufsize = _bufsize;
|
2020-04-10 18:19:52 +02:00
|
|
|
if (bufpointer != _bufpointer) {
|
|
|
|
bufpointer = malloc(bufsize);
|
|
|
|
memmov(bufpointer, _bufpointer, bufsize);
|
|
|
|
} else {
|
|
|
|
custom_encoding = CH_CP866;
|
|
|
|
}
|
2020-03-22 20:50:16 +01:00
|
|
|
SetPageDefaults();
|
2020-05-18 12:03:45 +02:00
|
|
|
is_html = true;
|
|
|
|
if (!strstri(bufpointer, "<body")) {
|
2020-03-23 16:53:56 +01:00
|
|
|
t_body = true;
|
2020-05-27 17:19:19 +02:00
|
|
|
if (!strstri(bufpointer, "<html")) && (!strstr(bufpointer, "<?xml")) && (!strstr(bufpointer, "<xml")) {
|
2020-05-18 12:03:45 +02:00
|
|
|
style.pre = true; //show linebreaks for a plaint text
|
|
|
|
is_html = false;
|
|
|
|
}
|
2020-03-23 16:53:56 +01:00
|
|
|
}
|
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) {
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2015-09-01 11:36:58 +02:00
|
|
|
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-04-10 18:19:52 +02:00
|
|
|
if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
|
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 '<':
|
2020-05-18 12:03:45 +02:00
|
|
|
if (!is_html) goto _default;
|
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];
|
2020-04-04 21:13:03 +02:00
|
|
|
if (bukva == '\x9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
|
2013-12-27 00:36:17 +01:00
|
|
|
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);
|
2020-04-04 21:13:03 +02:00
|
|
|
//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);
|
2020-05-18 12:03:45 +02:00
|
|
|
if (j = strstri(bufpos, #tag.params)) 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-29 12:57:14 +02:00
|
|
|
if (tag.name) {
|
2020-03-25 01:18:19 +01:00
|
|
|
CheckForLineBreak();
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.name) SetStyle();
|
2020-03-22 20:50:16 +01:00
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
2020-05-18 12:03:45 +02:00
|
|
|
_default:
|
2020-03-26 01:12:32 +01:00
|
|
|
AddCharToTheLine(ESBYTE[bufpos]);
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
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;
|
2020-04-04 01:17:28 +02:00
|
|
|
custom_encoding = -1;
|
2020-03-30 23:29:52 +02:00
|
|
|
if (!header) {
|
2020-04-04 01:17:28 +02:00
|
|
|
strncpy(#header, #version, sizeof(TWebBrowser.header)-1);
|
2020-03-30 23:29:52 +02:00
|
|
|
DrawTitle(#header);
|
|
|
|
}
|
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-30 23:29:52 +02:00
|
|
|
//Do we need a line break?
|
2020-03-25 01:18:19 +01:00
|
|
|
if (strlen(#line)*zoom + stolbec < list.column_max) return false;
|
2020-03-30 23:29:52 +02:00
|
|
|
//Yes, we do. Lets calculate where...
|
2020-03-25 01:18:19 +01:00
|
|
|
line_break_pos = strrchr(#line, ' ');
|
2020-03-30 23:29:52 +02:00
|
|
|
//Is a new line fits in the current line?
|
2020-03-25 01:18:19 +01:00
|
|
|
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--;
|
|
|
|
}
|
2020-03-30 23:29:52 +02:00
|
|
|
//Maybe a new line is too big for the whole new line? Then we have to split it
|
2020-04-04 01:17:28 +02:00
|
|
|
if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
|
2020-03-30 23:29:52 +02:00
|
|
|
line_break_pos = list.column_max/zoom - stolbec;
|
2020-03-21 15:33:54 +01:00
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
strcpy(#new_line_text, #line + line_break_pos);
|
2020-03-30 23:29:52 +02:00
|
|
|
line[line_break_pos] = 0x00;
|
|
|
|
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2020-03-30 23:29:52 +02:00
|
|
|
|
2014-03-30 13:57:13 +02:00
|
|
|
strcpy(#line, #new_line_text);
|
|
|
|
NewLine();
|
2020-04-04 21:13:03 +02:00
|
|
|
//while (CheckForLineBreak()==true) {};
|
2020-03-25 01:18:19 +01:00
|
|
|
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-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-30 23:29:52 +02:00
|
|
|
}
|
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-30 23:29:52 +02:00
|
|
|
if (tag.is("title")) {
|
2020-04-04 01:17:28 +02:00
|
|
|
style.tag_title = tag.opened;
|
2020-03-30 23:29:52 +02:00
|
|
|
if (!tag.opened) DrawTitle(#header);
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("body")) {
|
|
|
|
t_body = tag.opened;
|
2020-05-07 23:13:43 +02:00
|
|
|
if (value = tag.get_value_of("link=")) link_color_default = 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);
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("bgcolor=")) {
|
2020-05-22 23:39:04 +02:00
|
|
|
style.bg_color = page_bg = GetColor(value);
|
2020-03-26 01:12:32 +01:00
|
|
|
DrawBuf.Fill(0, page_bg);
|
2017-09-28 20:59:04 +02:00
|
|
|
}
|
2020-04-04 21:13:03 +02:00
|
|
|
// Autodetecting encoding if no encoding was set
|
|
|
|
if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
|
|
|
|
if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
|
2020-04-16 08:39:58 +02:00
|
|
|
else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
|
2020-04-04 21:13:03 +02:00
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 21:13:03 +02:00
|
|
|
if (tag.is("br")) { NewLine(); return; }
|
2020-04-15 21:22:26 +02:00
|
|
|
if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) {
|
2020-04-13 13:51:56 +02:00
|
|
|
style.b = tag.opened;
|
|
|
|
return;
|
|
|
|
}
|
2020-04-15 21:22:26 +02:00
|
|
|
if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; }
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("a")) {
|
|
|
|
if (tag.opened)
|
2013-12-27 00:36:17 +01:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
|
|
|
|
{
|
2020-04-04 21:13:03 +02:00
|
|
|
link = true;
|
2020-05-22 23:39:04 +02:00
|
|
|
links.add_link(value);
|
2020-03-26 01:12:32 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-04 21:13:03 +02:00
|
|
|
link = false;
|
2020-05-07 23:13:43 +02:00
|
|
|
style.bg_color = page_bg;
|
2013-12-27 00:36:17 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-04-04 21:13:03 +02:00
|
|
|
if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
|
|
|
|
NewLine();
|
|
|
|
strcpy(#line, "IFRAME: ");
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2020-04-04 21:13:03 +02:00
|
|
|
link=true;
|
2020-05-22 23:39:04 +02:00
|
|
|
links.add_link(value);
|
2020-04-10 18:19:52 +02:00
|
|
|
strncpy(#line, value, sizeof(line)-1);
|
2020-04-04 21:13:03 +02:00
|
|
|
while (CheckForLineBreak()) {};
|
2020-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2020-04-04 21:13:03 +02:00
|
|
|
link=false;
|
|
|
|
NewLine();
|
|
|
|
}
|
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")) {
|
2020-03-27 21:18:44 +01:00
|
|
|
if (streq(#tag.prior,"div")) && (tag.opened) return;
|
2020-03-22 20:50:16 +01:00
|
|
|
NewLine();
|
|
|
|
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-04-13 13:51:56 +02:00
|
|
|
if (tag.is("p")) || (tag.is("w:p")) {
|
2020-03-27 21:18:44 +01:00
|
|
|
IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
|
2014-03-23 23:49:49 +01:00
|
|
|
NewLine();
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 21:13:03 +02:00
|
|
|
if (tag.is("pre")) { style.pre = tag.opened; return; }
|
2020-03-29 12:57:14 +02:00
|
|
|
if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("tr")) { if (tag.opened) NewLine(); 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; }
|
2020-04-05 09:33:55 +02:00
|
|
|
if (tag.is("dl")) {
|
|
|
|
if (tag.opened) NewLine();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tag.is("dd")) {
|
|
|
|
//NewLine();
|
|
|
|
//if (tag.opened) stolbec += 5; //stolbec overflow!
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("blockquote")) { style.blq = tag.opened; return; }
|
2020-04-04 01:17:28 +02:00
|
|
|
if (tag.is("code")) {
|
|
|
|
if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg;
|
|
|
|
style.pre = tag.opened; return;
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("img")) {
|
|
|
|
if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
|
2020-04-10 18:19:52 +02:00
|
|
|
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-04-10 18:19:52 +02:00
|
|
|
Paint();
|
2020-03-21 15:33:54 +01:00
|
|
|
text_color_index--;
|
|
|
|
style.image = false;
|
2020-04-04 01:17:28 +02:00
|
|
|
//ImgCache.Images( list.x, draw_y, list.w);
|
2020-03-21 15:33:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-30 23:29:52 +02:00
|
|
|
if (tag.is("h4")) {
|
2020-04-04 01:17:28 +02:00
|
|
|
NewLine();
|
2020-03-30 23:29:52 +02:00
|
|
|
NewLine();
|
|
|
|
style.h = tag.opened;
|
|
|
|
style.b = tag.opened;
|
|
|
|
}
|
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;
|
2020-03-30 23:29:52 +02:00
|
|
|
if (tag.opened) {
|
2020-04-04 01:17:28 +02:00
|
|
|
if (!style.pre) NewLine();
|
2016-12-11 23:58:11 +01:00
|
|
|
draw_y += 10;
|
2020-04-04 01:17:28 +02:00
|
|
|
zoom=2;
|
|
|
|
list.font_type |= 10011001b;
|
|
|
|
list.item_h = BASIC_LINE_H * 2 - 2;
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("h1")) style.b = true;
|
2020-03-30 23:29:52 +02:00
|
|
|
} else {
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.is("h1")) style.b = false;
|
2016-12-11 23:58:11 +01:00
|
|
|
NewLine();
|
2020-04-04 01:17:28 +02:00
|
|
|
zoom=1;
|
|
|
|
list.font_type = 10011000b;
|
|
|
|
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")) {
|
2020-04-04 01:17:28 +02:00
|
|
|
style.tag_list.upd_level(tag.opened, DT);
|
2020-03-26 01:12:32 +01:00
|
|
|
if (tag.opened) NewLine();
|
2013-12-29 13:48:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 01:17:28 +02:00
|
|
|
if (tag.is("ul")) {
|
|
|
|
style.tag_list.upd_level(tag.opened, UL);
|
|
|
|
if (!tag.opened) && (!style.pre) NewLine();
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 01:17:28 +02:00
|
|
|
if (tag.is("ol")) {
|
|
|
|
style.tag_list.upd_level(tag.opened, OL);
|
|
|
|
if (!tag.opened) && (!style.pre) NewLine();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tag.is("li")) && (tag.opened)
|
|
|
|
{
|
|
|
|
if (!style.tag_list.level) style.tag_list.upd_level(1, UL);
|
|
|
|
if (!style.pre) NewLine();
|
|
|
|
if (style.tag_list.get_order_type() == UL) {
|
|
|
|
strcpy(#line, "\31 ");
|
|
|
|
stolbec = style.tag_list.level * 5 - 2;
|
2015-08-19 17:14:52 +02:00
|
|
|
}
|
2020-04-04 01:17:28 +02:00
|
|
|
if (style.tag_list.get_order_type() == OL) {
|
|
|
|
sprintf(#line, "%i. ", style.tag_list.inc_counter());
|
|
|
|
stolbec = style.tag_list.level * 5 - strlen(#line);
|
2020-03-30 23:29:52 +02:00
|
|
|
}
|
2020-04-04 01:17:28 +02:00
|
|
|
return;
|
2015-08-19 17:14:52 +02:00
|
|
|
}
|
2020-04-04 21:13:03 +02:00
|
|
|
if (tag.is("q"))
|
|
|
|
{
|
|
|
|
if (tag.opened) {
|
|
|
|
EAX = strlen(#line);
|
|
|
|
if (line[EAX-1] != ' ') chrcat(#line, ' ');
|
|
|
|
chrcat(#line, '\"');
|
|
|
|
}
|
|
|
|
if (!tag.opened) strcat(#line, "\" ");
|
|
|
|
return;
|
|
|
|
}
|
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-04-04 01:17:28 +02:00
|
|
|
if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) {
|
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);
|
2020-04-04 21:13:03 +02:00
|
|
|
if (streq(value,"utf-8")) || (streq(value,"utf8")) ChangeEncoding(CH_UTF8);
|
|
|
|
else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) ChangeEncoding(CH_CP1251);
|
|
|
|
else if (streq(value,"dos")) || (streq(value,"cp-866")) ChangeEncoding(CH_CP866);
|
|
|
|
else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) ChangeEncoding(CH_ISO8859_5);
|
|
|
|
else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) ChangeEncoding(CH_KOI8);
|
2020-03-30 23:29:52 +02:00
|
|
|
}
|
2013-12-27 00:36:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-22 20:50:16 +01: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
|
|
|
//============================================================================================
|
2020-04-04 21:13:03 +02:00
|
|
|
void TWebBrowser::ChangeEncoding(int _new_encoding)
|
|
|
|
{
|
|
|
|
if (cur_encoding == _new_encoding) return;
|
|
|
|
cur_encoding = _new_encoding;
|
2020-04-13 15:16:55 +02:00
|
|
|
bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
|
2020-04-04 21:13:03 +02:00
|
|
|
if (header) {
|
2020-04-13 15:16:55 +02:00
|
|
|
ChangeCharset(cur_encoding, "CP866", #header);
|
2020-04-04 21:13:03 +02:00
|
|
|
DrawTitle(#header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//============================================================================================
|
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
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
if (!stolbec) && (draw_y==BODY_MARGIN) return;
|
2020-03-21 15:33:54 +01:00
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) {
|
2020-03-23 16:53:56 +01:00
|
|
|
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
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
onleft = list.x + BODY_MARGIN;
|
2016-12-11 23:58:11 +01:00
|
|
|
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;
|
2020-04-04 01:17:28 +02:00
|
|
|
stolbec += style.tag_list.level * 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();
|
|
|
|
}
|