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 stolbec;
|
||||
int tab_len;
|
||||
int anchor_y;
|
||||
|
||||
int body_magrin=5;
|
||||
int basic_line_h=22;
|
||||
@ -66,6 +65,7 @@ char val[4096];
|
||||
|
||||
#include "..\TWB\absolute_url.h"
|
||||
#include "..\TWB\links.h"
|
||||
#include "..\TWB\anchors.h"
|
||||
#include "..\TWB\colors.h"
|
||||
#include "..\TWB\unicode_tags.h"
|
||||
#include "..\TWB\img_cache.h"
|
||||
@ -91,8 +91,8 @@ void TWebBrowser::DrawStyle()
|
||||
stolbec_len = strlen(#line) * zoom;
|
||||
line_length = stolbec_len * list.font_w;
|
||||
|
||||
WriteBufText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data);
|
||||
if (style.b) WriteBufText(start_x+1, 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) 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.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
|
||||
if (link) {
|
||||
@ -121,7 +121,7 @@ void TWebBrowser::Prepare(){
|
||||
link_color_inactive = 0x0000FF;
|
||||
link_color_active = 0xFF0000;
|
||||
bg_color = 0xFFFFFF;
|
||||
DrawBuf.Fill(bg_color);
|
||||
DrawBuf.Fill(0, bg_color);
|
||||
PageLinks.Clear();
|
||||
strcpy(#header, #version);
|
||||
draw_y = body_magrin;
|
||||
@ -275,9 +275,9 @@ void TWebBrowser::SetStyle() {
|
||||
if (!opened) strcat(#line, "\" ");
|
||||
return;
|
||||
}
|
||||
//if (isattr("id=")) || (isattr("name=")) { //very bad: if the tag is not the last it wound work
|
||||
//add anchor
|
||||
//}
|
||||
if (isattr("id=")) || (isattr("name=")) { // TO FIX: works only if the param is the last
|
||||
anchors.add(#val, draw_y);
|
||||
}
|
||||
if (istag("body")) {
|
||||
t_body = opened;
|
||||
do{
|
||||
@ -287,7 +287,7 @@ void TWebBrowser::SetStyle() {
|
||||
if (isattr("bgcolor="))
|
||||
{
|
||||
bg_color = GetColor(#val);
|
||||
DrawBuf.Fill(bg_color);
|
||||
DrawBuf.Fill(0, bg_color);
|
||||
}
|
||||
} while(GetNextParam());
|
||||
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
|
||||
|
||||
//libraries
|
||||
#define MEMSIZE 4096 * 200
|
||||
#define MEMSIZE 1024 * 800
|
||||
#include "..\lib\gui.h"
|
||||
#include "..\lib\draw_buf.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";
|
||||
|
||||
#ifdef LANG_RUS
|
||||
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.8d";
|
||||
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.82";
|
||||
?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥"
|
||||
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤¨© á« ©¤"
|
||||
char loading[] = "‡ £à㧪 áâà ¨æë...<br>";
|
||||
@ -46,7 +46,7 @@ char link_menu[] =
|
||||
"Š®¯¨à®¢ âì áá뫪ã
|
||||
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
|
||||
#else
|
||||
char version[]="Text-based Browser 1.8d";
|
||||
char version[]="Text-based Browser 1.82";
|
||||
?define IMAGES_CACHE_CLEARED "Images cache cleared"
|
||||
?define T_LAST_SLIDE "This slide is the last"
|
||||
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.visible = WB1.list.h;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -524,13 +524,16 @@ void ClickLink()
|
||||
{
|
||||
if (URL[1] == NULL) {
|
||||
WB1.list.first = 0;
|
||||
strcpy(#URL, history.current());
|
||||
}
|
||||
else {
|
||||
strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
|
||||
strcpy(#URL, history.current());
|
||||
if (anchors.get_anchor_pos(#URL+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#URL+1);
|
||||
}
|
||||
ShowPage();
|
||||
strlcpy(#anchor, #URL, sizeof(anchor));
|
||||
strcpy(#URL, history.current());
|
||||
strcpy(#editURL, #URL);
|
||||
strcat(#editURL, #anchor);
|
||||
DrawEditBoxWebView();
|
||||
WB1.DrawPage();
|
||||
return;
|
||||
}
|
||||
//liner.ru#1
|
||||
|
@ -16,7 +16,8 @@ struct collection
|
||||
dword element_offset[4000];
|
||||
int add();
|
||||
int addn();
|
||||
dword get();
|
||||
dword get(); //get_name_by_pos
|
||||
dword get_pos_by_name();
|
||||
void drop();
|
||||
void increase_data_size();
|
||||
};
|
||||
@ -56,6 +57,14 @@ struct collection
|
||||
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() {
|
||||
if (data_start) free(data_start);
|
||||
data_size = data_start = element_offset[count] = count = 0;
|
||||
|
@ -11,14 +11,17 @@ dword buf_data;
|
||||
|
||||
struct DrawBufer {
|
||||
dword bufx, bufy, bufw, bufh;
|
||||
dword fill_color;
|
||||
|
||||
bool Init();
|
||||
void Show();
|
||||
void Fill();
|
||||
void DrawBar();
|
||||
void WriteText();
|
||||
void PutPixel();
|
||||
void AlignCenter();
|
||||
void AlignRight();
|
||||
void IncreaseBufSize();
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
dword alloc_size, free_ram_size;
|
||||
char error_str[256];
|
||||
bufx = i_bufx;
|
||||
bufy = i_bufy;
|
||||
bufw = i_bufw;
|
||||
bufh = i_bufh;
|
||||
free(buf_data);
|
||||
free_ram_size = GetFreeRAM() * 1024;
|
||||
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);
|
||||
buf_data = free(buf_data);
|
||||
IncreaseBufSize();
|
||||
//debugval("buf_data",buf_data);
|
||||
if (!buf_data) return false;
|
||||
ESDWORD[buf_data] = bufw;
|
||||
@ -51,24 +46,36 @@ bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrawBufer::Fill(dword fill_color)
|
||||
void DrawBufer::Fill(dword start_pointer, i_fill_color)
|
||||
{
|
||||
dword i;
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user