From e1d611df85711dec71eb06fa996c2b6e195f38ba Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 18 Mar 2020 00:45:36 +0000 Subject: [PATCH] WebView 1.82: dynamic realloc finally, working anchors again! git-svn-id: svn://kolibrios.org@7738 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 16 ++++----- programs/cmm/TWB/anchors.h | 21 +++++++++++ programs/cmm/browser/WebView.c | 19 +++++----- programs/cmm/lib/collection.h | 11 +++++- programs/cmm/lib/draw_buf.h | 66 ++++++++++++++++++++++++++-------- 5 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 programs/cmm/TWB/anchors.h diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index 4dc60184d9..17f1ed468e 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -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) { diff --git a/programs/cmm/TWB/anchors.h b/programs/cmm/TWB/anchors.h new file mode 100644 index 0000000000..45babf4564 --- /dev/null +++ b/programs/cmm/TWB/anchors.h @@ -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)); +} + diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index d738eae6bc..093760b3c4 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -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 "Это последний слайд" char loading[] = "Загрузка страницы...
"; @@ -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...
"; @@ -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 diff --git a/programs/cmm/lib/collection.h b/programs/cmm/lib/collection.h index 481a96d89a..43e10dd1ec 100644 --- a/programs/cmm/lib/collection.h +++ b/programs/cmm/lib/collection.h @@ -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= 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= bufh) IncreaseBufSize(); + for (j=0; j= 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 \ No newline at end of file