forked from KolibriOS/kolibrios
WebView 1.82: dynamic realloc finally, working anchors again!
git-svn-id: svn://kolibrios.org@7738 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
00f82ec9ff
commit
e1d611df85
@ -50,7 +50,6 @@ dword bg_color;
|
|||||||
int draw_y;
|
int draw_y;
|
||||||
int stolbec;
|
int stolbec;
|
||||||
int tab_len;
|
int tab_len;
|
||||||
int anchor_y;
|
|
||||||
|
|
||||||
int body_magrin=5;
|
int body_magrin=5;
|
||||||
int basic_line_h=22;
|
int basic_line_h=22;
|
||||||
@ -66,6 +65,7 @@ char val[4096];
|
|||||||
|
|
||||||
#include "..\TWB\absolute_url.h"
|
#include "..\TWB\absolute_url.h"
|
||||||
#include "..\TWB\links.h"
|
#include "..\TWB\links.h"
|
||||||
|
#include "..\TWB\anchors.h"
|
||||||
#include "..\TWB\colors.h"
|
#include "..\TWB\colors.h"
|
||||||
#include "..\TWB\unicode_tags.h"
|
#include "..\TWB\unicode_tags.h"
|
||||||
#include "..\TWB\img_cache.h"
|
#include "..\TWB\img_cache.h"
|
||||||
@ -91,8 +91,8 @@ void TWebBrowser::DrawStyle()
|
|||||||
stolbec_len = strlen(#line) * zoom;
|
stolbec_len = strlen(#line) * zoom;
|
||||||
line_length = stolbec_len * list.font_w;
|
line_length = stolbec_len * list.font_w;
|
||||||
|
|
||||||
WriteBufText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data);
|
DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line);
|
||||||
if (style.b) WriteBufText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data);
|
if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line);
|
||||||
if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
|
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]);
|
if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
|
||||||
if (link) {
|
if (link) {
|
||||||
@ -121,7 +121,7 @@ void TWebBrowser::Prepare(){
|
|||||||
link_color_inactive = 0x0000FF;
|
link_color_inactive = 0x0000FF;
|
||||||
link_color_active = 0xFF0000;
|
link_color_active = 0xFF0000;
|
||||||
bg_color = 0xFFFFFF;
|
bg_color = 0xFFFFFF;
|
||||||
DrawBuf.Fill(bg_color);
|
DrawBuf.Fill(0, bg_color);
|
||||||
PageLinks.Clear();
|
PageLinks.Clear();
|
||||||
strcpy(#header, #version);
|
strcpy(#header, #version);
|
||||||
draw_y = body_magrin;
|
draw_y = body_magrin;
|
||||||
@ -275,9 +275,9 @@ void TWebBrowser::SetStyle() {
|
|||||||
if (!opened) strcat(#line, "\" ");
|
if (!opened) strcat(#line, "\" ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if (isattr("id=")) || (isattr("name=")) { //very bad: if the tag is not the last it wound work
|
if (isattr("id=")) || (isattr("name=")) { // TO FIX: works only if the param is the last
|
||||||
//add anchor
|
anchors.add(#val, draw_y);
|
||||||
//}
|
}
|
||||||
if (istag("body")) {
|
if (istag("body")) {
|
||||||
t_body = opened;
|
t_body = opened;
|
||||||
do{
|
do{
|
||||||
@ -287,7 +287,7 @@ void TWebBrowser::SetStyle() {
|
|||||||
if (isattr("bgcolor="))
|
if (isattr("bgcolor="))
|
||||||
{
|
{
|
||||||
bg_color = GetColor(#val);
|
bg_color = GetColor(#val);
|
||||||
DrawBuf.Fill(bg_color);
|
DrawBuf.Fill(0, bg_color);
|
||||||
}
|
}
|
||||||
} while(GetNextParam());
|
} while(GetNextParam());
|
||||||
if (opened) && (cur_encoding==CH_NULL) {
|
if (opened) && (cur_encoding==CH_NULL) {
|
||||||
|
21
programs/cmm/TWB/anchors.h
Normal file
21
programs/cmm/TWB/anchors.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
struct _anchors {
|
||||||
|
collection anchor_name;
|
||||||
|
collection anchor_position;
|
||||||
|
void add();
|
||||||
|
int get_anchor_pos();
|
||||||
|
} anchors;
|
||||||
|
|
||||||
|
void _anchors::add(dword _name, _pos)
|
||||||
|
{
|
||||||
|
anchor_name.add(_name);
|
||||||
|
anchor_position.add(itoa(_pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
int _anchors::get_anchor_pos(dword _get_name)
|
||||||
|
{
|
||||||
|
dword pos_name = anchor_name.get_pos_by_name(_get_name);
|
||||||
|
if (pos_name==-1) return -1;
|
||||||
|
return atoi(anchor_position.get(pos_name));
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//libraries
|
//libraries
|
||||||
#define MEMSIZE 4096 * 200
|
#define MEMSIZE 1024 * 800
|
||||||
#include "..\lib\gui.h"
|
#include "..\lib\gui.h"
|
||||||
#include "..\lib\draw_buf.h"
|
#include "..\lib\draw_buf.h"
|
||||||
#include "..\lib\list_box.h"
|
#include "..\lib\list_box.h"
|
||||||
@ -31,7 +31,7 @@ _http http = {0, 0, 0, 0, 0, 0, 0};
|
|||||||
char homepage[] = FROM "html\\homepage.htm""\0";
|
char homepage[] = FROM "html\\homepage.htm""\0";
|
||||||
|
|
||||||
#ifdef LANG_RUS
|
#ifdef LANG_RUS
|
||||||
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.8d";
|
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.82";
|
||||||
?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥"
|
?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥"
|
||||||
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤¨© á« ©¤"
|
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤¨© á« ©¤"
|
||||||
char loading[] = "‡ £à㧪 áâà ¨æë...<br>";
|
char loading[] = "‡ £à㧪 áâà ¨æë...<br>";
|
||||||
@ -46,7 +46,7 @@ char link_menu[] =
|
|||||||
"Š®¯¨à®¢ âì áá뫪ã
|
"Š®¯¨à®¢ âì áá뫪ã
|
||||||
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
|
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
|
||||||
#else
|
#else
|
||||||
char version[]="Text-based Browser 1.8d";
|
char version[]="Text-based Browser 1.82";
|
||||||
?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>";
|
||||||
@ -242,7 +242,7 @@ void SetElementSizes()
|
|||||||
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;
|
WB1.list.visible = WB1.list.h;
|
||||||
if (WB1.list.w!=WB1.DrawBuf.bufw) {
|
if (WB1.list.w!=WB1.DrawBuf.bufw) {
|
||||||
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
|
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*20);
|
||||||
ProcessEvent(REFRESH_BUTTON);
|
ProcessEvent(REFRESH_BUTTON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,13 +524,16 @@ void ClickLink()
|
|||||||
{
|
{
|
||||||
if (URL[1] == NULL) {
|
if (URL[1] == NULL) {
|
||||||
WB1.list.first = 0;
|
WB1.list.first = 0;
|
||||||
strcpy(#URL, history.current());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
|
if (anchors.get_anchor_pos(#URL+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#URL+1);
|
||||||
strcpy(#URL, history.current());
|
|
||||||
}
|
}
|
||||||
ShowPage();
|
strlcpy(#anchor, #URL, sizeof(anchor));
|
||||||
|
strcpy(#URL, history.current());
|
||||||
|
strcpy(#editURL, #URL);
|
||||||
|
strcat(#editURL, #anchor);
|
||||||
|
DrawEditBoxWebView();
|
||||||
|
WB1.DrawPage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//liner.ru#1
|
//liner.ru#1
|
||||||
|
@ -16,7 +16,8 @@ struct collection
|
|||||||
dword element_offset[4000];
|
dword element_offset[4000];
|
||||||
int add();
|
int add();
|
||||||
int addn();
|
int addn();
|
||||||
dword get();
|
dword get(); //get_name_by_pos
|
||||||
|
dword get_pos_by_name();
|
||||||
void drop();
|
void drop();
|
||||||
void increase_data_size();
|
void increase_data_size();
|
||||||
};
|
};
|
||||||
@ -56,6 +57,14 @@ struct collection
|
|||||||
return data_start + element_offset[pos];
|
return data_start + element_offset[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:dword collection::get_pos_by_name(dword name) {
|
||||||
|
dword i;
|
||||||
|
for (i=0; i<count; i++) {
|
||||||
|
if (strcmp(data_start + element_offset[i], name)==0) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
:void collection::drop() {
|
:void collection::drop() {
|
||||||
if (data_start) free(data_start);
|
if (data_start) free(data_start);
|
||||||
data_size = data_start = element_offset[count] = count = 0;
|
data_size = data_start = element_offset[count] = count = 0;
|
||||||
|
@ -11,14 +11,17 @@ dword buf_data;
|
|||||||
|
|
||||||
struct DrawBufer {
|
struct DrawBufer {
|
||||||
dword bufx, bufy, bufw, bufh;
|
dword bufx, bufy, bufw, bufh;
|
||||||
|
dword fill_color;
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void Show();
|
void Show();
|
||||||
void Fill();
|
void Fill();
|
||||||
void DrawBar();
|
void DrawBar();
|
||||||
|
void WriteText();
|
||||||
void PutPixel();
|
void PutPixel();
|
||||||
void AlignCenter();
|
void AlignCenter();
|
||||||
void AlignRight();
|
void AlignRight();
|
||||||
|
void IncreaseBufSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
char draw_buf_not_enaught_ram[] =
|
char draw_buf_not_enaught_ram[] =
|
||||||
@ -30,20 +33,12 @@ Free RAM: %i Mb' -E";
|
|||||||
|
|
||||||
bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
||||||
{
|
{
|
||||||
dword alloc_size, free_ram_size;
|
|
||||||
char error_str[256];
|
|
||||||
bufx = i_bufx;
|
bufx = i_bufx;
|
||||||
bufy = i_bufy;
|
bufy = i_bufy;
|
||||||
bufw = i_bufw;
|
bufw = i_bufw;
|
||||||
bufh = i_bufh;
|
bufh = i_bufh;
|
||||||
free(buf_data);
|
buf_data = free(buf_data);
|
||||||
free_ram_size = GetFreeRAM() * 1024;
|
IncreaseBufSize();
|
||||||
alloc_size = bufw * bufh * 4 + 8;
|
|
||||||
if (alloc_size >= free_ram_size) {
|
|
||||||
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576);
|
|
||||||
notify(#error_str);
|
|
||||||
}
|
|
||||||
buf_data = malloc(alloc_size);
|
|
||||||
//debugval("buf_data",buf_data);
|
//debugval("buf_data",buf_data);
|
||||||
if (!buf_data) return false;
|
if (!buf_data) return false;
|
||||||
ESDWORD[buf_data] = bufw;
|
ESDWORD[buf_data] = bufw;
|
||||||
@ -51,24 +46,36 @@ bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBufer::Fill(dword fill_color)
|
void DrawBufer::Fill(dword start_pointer, i_fill_color)
|
||||||
{
|
{
|
||||||
dword i;
|
dword i;
|
||||||
dword max_i = bufw * bufh * 4 + buf_data + 8;
|
dword max_i = bufw * bufh * 4 + buf_data + 8;
|
||||||
for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
fill_color = i_fill_color;
|
||||||
|
for (i=buf_data+start_pointer+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBufer::DrawBar(dword x, y, w, h, color)
|
void DrawBufer::DrawBar(dword x, y, w, h, color)
|
||||||
{
|
{
|
||||||
dword i, j;
|
dword i, j;
|
||||||
for (j=0; j<h; j++)
|
if (y + h >= bufh) IncreaseBufSize();
|
||||||
{
|
for (j=0; j<h; j++) {
|
||||||
for (i = y+j*bufw+x<<2+8+buf_data; i<y+j*bufw+x+w<<2+8+buf_data; i+=4) {
|
for (i = y+j*bufw+x<<2+8+buf_data; i<y+j*bufw+x+w<<2+8+buf_data; i+=4) {
|
||||||
ESDWORD[i] = color;
|
ESDWORD[i] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawBuf_WriteText(dword x, y, byte fontType, dword color, str_offset)
|
||||||
|
{
|
||||||
|
EDI = buf_data;
|
||||||
|
WriteText(x, y, fontType, color, str_offset);
|
||||||
|
}
|
||||||
|
void DrawBufer::WriteText(dword x, y, byte fontType, dword color, str_offset)
|
||||||
|
{
|
||||||
|
if (y + 30 >= bufh) IncreaseBufSize();
|
||||||
|
DrawBuf_WriteText(x, y, fontType, color, str_offset);
|
||||||
|
}
|
||||||
|
|
||||||
void DrawBufer::PutPixel(dword x, y, color)
|
void DrawBufer::PutPixel(dword x, y, color)
|
||||||
{
|
{
|
||||||
dword pos = y*bufw+x*4+8+buf_data;
|
dword pos = y*bufw+x*4+8+buf_data;
|
||||||
@ -142,4 +149,35 @@ void DrawBufer::Show()
|
|||||||
PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
|
PutPaletteImage(buf_data+8, bufw, bufh, bufx, bufy, 32, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawBufer::IncreaseBufSize()
|
||||||
|
{
|
||||||
|
static dword alloc_counter;
|
||||||
|
static dword bufh_initial;
|
||||||
|
dword alloc_size;
|
||||||
|
dword free_ram_size;
|
||||||
|
char error_str[256];
|
||||||
|
|
||||||
|
if (!buf_data) {
|
||||||
|
alloc_counter = 1;
|
||||||
|
bufh_initial = bufh;
|
||||||
|
alloc_size = bufw * bufh * 4 + 8;
|
||||||
|
buf_data = malloc(alloc_size);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alloc_counter++;
|
||||||
|
bufh = bufh_initial * alloc_counter;
|
||||||
|
alloc_size = bufw * bufh * 4 + 8;
|
||||||
|
buf_data = realloc(buf_data, alloc_size);
|
||||||
|
Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
free_ram_size = GetFreeRAM() * 1024;
|
||||||
|
if (alloc_size >= free_ram_size) {
|
||||||
|
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576);
|
||||||
|
notify(#error_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user