WebView 1.48: support all site encodings (not only UTF8), use lib/menu.h, fix black screen after changing window size

git-svn-id: svn://kolibrios.org@6045 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-01-08 02:19:41 +00:00
parent 5f2eec40f1
commit 8181cb284f
5 changed files with 57 additions and 112 deletions

View File

@ -135,12 +135,12 @@ void TWebBrowser::Prepare(){
if (strstri(bufpointer, "html"))
{
style.pre = 0;
cur_encoding = CH_UTF8;
cur_encoding = CH_NULL;
}
else
{
style.pre = 1;
cur_encoding = CH_CP866;
cur_encoding = CH_NULL;
}
for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
{
@ -368,7 +368,7 @@ void TWebBrowser::SetStyle() {
if (opened)
{
WB1.DrawBuf.zoom=2;
WB1.list.font_type |= 10111001b;
WB1.list.font_type |= 10011001b;
if (isattr("align=")) && (isval("center")) style.align = ALIGN_CENTER;
if (isattr("align=")) && (isval("right")) style.align = ALIGN_RIGHT;
if (stroka>1) NewLine();
@ -376,7 +376,7 @@ void TWebBrowser::SetStyle() {
else
{
WB1.DrawBuf.zoom=1;
WB1.list.font_type = 10111000b;
WB1.list.font_type = 10011000b;
style.align = ALIGN_LEFT;
}
return;
@ -416,6 +416,7 @@ void TWebBrowser::SetStyle() {
return;
}
if (istag("meta")) || (istag("?xml")) {
meta_encoding = CH_NULL;
do{
if (isattr("charset=")) || (isattr("content=")) || (isattr("encoding="))
{
@ -426,10 +427,9 @@ void TWebBrowser::SetStyle() {
else if (isval("windows-1251")) || (isval("windows1251")) meta_encoding = CH_CP1251;
else if (isval("iso-8859-5")) || (isval("iso8859-5")) meta_encoding = CH_ISO8859_5;
else if (isval("dos")) || (isval("cp-866")) meta_encoding = CH_CP866;
if (cur_encoding!=meta_encoding) BufEncode(meta_encoding);
return;
}
} while(GetNextParam());
if (meta_encoding!=CH_NULL) BufEncode(meta_encoding);
return;
}
}
@ -437,7 +437,6 @@ void TWebBrowser::SetStyle() {
void TWebBrowser::BufEncode(int set_new_encoding)
{
int bufpointer_realsize;
cur_encoding = set_new_encoding;
if (o_bufpointer==0)
{
o_bufpointer = malloc(bufsize);
@ -447,6 +446,11 @@ void TWebBrowser::BufEncode(int set_new_encoding)
{
strcpy(bufpointer, o_bufpointer);
}
if (cur_encoding!=set_new_encoding) {
cur_encoding = set_new_encoding;
debugln(charsets[cur_encoding]);
bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);
}
}
//============================================================================================
void TWebBrowser::DrawScroller()

View File

@ -15,6 +15,7 @@
#include "..\lib\cursor.h"
#include "..\lib\collection.h"
#include "..\lib\font.h"
#include "..\lib\menu.h"
//*.obj libraries
#include "..\lib\obj\box_lib.h"
@ -29,19 +30,31 @@
char homepage[] = FROM "html\\homepage.htm";
#ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.42";
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.48";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n";
char rmb_menu[] =
"<EFBFBD>®á¬®âà¥âì ¨á室­¨ª
<EFBFBD>¥¤ ªâ¨à®¢ âì ¨á室­¨ª
ˆáâ®à¨ï
Žç¨áâ¨âì ªíè ª à⨭®ª
Œ¥­¥¤¦¥à § £à㧮ª";
#else
char version[]=" Text-based Browser 1.42";
char version[]=" Text-based Browser 1.48";
?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>";
char page_not_found[] = FROM "html\page_not_found_en.htm";
char accept_language[]= "Accept-Language: en\n";
char rmb_menu[] =
"View source
Edit source
History
Free image cache
Download Manager";
#endif
#define URL_SERVICE_HISTORY "WebView://history"
@ -86,7 +99,6 @@ enum {
};
#include "..\TWB\TWB.c"
#include "menu.h"
#include "history.h"
#include "show_src.h"
#include "http_downloader.h"
@ -108,13 +120,12 @@ void main()
load_dll(libimg, #libimg_init,1);
load_dll(libHTTP, #http_lib_init,1);
load_dll(iconv_lib, #iconv_open,0);
//load_dll(kmenu, #akmenu_init,0);
Libimg_LoadImage(#skin, abspath("wv_skin.png"));
SetSkinColors();
CreateDir("/tmp0/1/downloads");
if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
WB1.DrawBuf.zoom = 1;
WB1.list.SetFont(8, 14, 10111000b);
WB1.list.SetFont(8, 14, 10011000b);
WB1.list.no_selection = true;
label.init(DEFAULT_FONT);
SetEventMask(0xa7);
@ -129,7 +140,10 @@ void main()
if (WB1.list.MouseOver(mouse.x, mouse.y))
{
PageLinks.Hover(mouse.x, WB1.list.first*WB1.list.item_h + mouse.y, link_color_inactive, link_color_active, bg_color);
if (bufsize) && (mouse.pkm) && (mouse.up) { CreateThread(#menu_rmb,#stak+4092); break; }
if (bufsize) && (mouse.pkm) && (mouse.up) {
menu.show(Form.left+mouse.x-6,Form.top+mouse.y+skin_height+3, 180, #rmb_menu, VIEW_SOURCE);
break;
}
if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
}
scrollbar_v_mouse (#scroll_wv);
@ -161,7 +175,10 @@ void main()
break;
case evReDraw:
if (action_buf) Scan(action_buf);
if (menu.list.cur_y) {
Scan(menu.list.cur_y);
menu.list.cur_y = 0;
}
DefineAndDrawWindow(GetScreenWidth()-800/2,GetScreenHeight()-600/2,800,600,0x73,col_bg,0,0);
GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) { DrawTitle(#header); break; }
@ -249,7 +266,10 @@ void SetElementSizes()
WB1.list.wheel_size = 7;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
WB1.list.visible = WB1.list.h - 5 / WB1.list.item_h;
if (WB1.list.w!=WB1.DrawBuf.bufw) WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h * 30);
if (WB1.list.w!=WB1.DrawBuf.bufw) {
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h * 30);
Scan(REFRESH_BUTTON);
}
}
@ -332,7 +352,7 @@ void Scan(dword id__)
case SANDWICH_BUTTON:
mouse.y = TOOLBAR_H-6;
mouse.x = Form.cwidth - 167;
CreateThread(#menu_rmb,#stak+4092);
menu.show(Form.left+mouse.x-6,Form.top+mouse.y+skin_height+3, 180, #rmb_menu, VIEW_SOURCE);
return;
case VIEW_SOURCE:
WB1.list.first = 0;

View File

@ -8,7 +8,7 @@ ShowHistory()
history_pointer = malloc(history.items.data_size+256);
strcat(history_pointer, "<html><head><title>History</title></head><body><h1>History</h1>");
strcat(history_pointer, "<h2>Visited pages</h2><blockquote><br>");
for (i=1; i<history.items.count; i++)
for (i=0; i<history.items.count; i++)
{
strcat(history_pointer, " <a href='");
strcat(history_pointer, history.items.get(i));

View File

@ -1,77 +0,0 @@
//Leency - 2012-2013
char *ITEMS_LIST[]={
#ifdef LANG_RUS
"<EFBFBD>®á¬®âà¥âì ¨á室­¨ª",
"<EFBFBD>¥¤ ªâ¨à®¢ âì ¨á室­¨ª",
"ˆáâ®à¨ï",
"Žç¨áâ¨âì ªíè ª à⨭®ª",
"Œ¥­¥¤¦¥à § £à㧮ª",
#else
"View source",
"Edit source",
"History",
"Free image cache",
"Download Manager",
#endif
0};
llist menu;
void menu_rmb()
{
proc_info MenuForm;
menu.ClearList();
while (ITEMS_LIST[menu.count]) menu.count++;
menu.SetSizes(2,2,177,menu.count*19,19);
SetEventMask(100111b);
_BEGIN_APPLICATION_MENU:
switch(WaitEvent())
{
case evMouse:
GetProcessInfo(#MenuForm, SelfInfo);
if (!CheckActiveProcess(MenuForm.ID)) ExitProcess();
mouse.get();
if (menu.ProcessMouse(mouse.x, mouse.y)) DrawMenuList();
if (mouse.lkm)&&(mouse.up) ItemClick();
break;
case evKey:
GetKeys();
if (key_scancode==SCAN_CODE_ESC) ExitProcess();
if (key_scancode==SCAN_CODE_ENTER) ItemClick();
if (menu.ProcessKey(key_scancode)) DrawMenuList();
break;
case evReDraw:
DefineAndDrawWindow(Form.left+mouse.x-6,Form.top+mouse.y+GetSkinHeight()+3,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF);
DrawPopup(0,0,menu.w,menu.h+3,0, col_bg,border_color);
DrawMenuList();
}
goto _BEGIN_APPLICATION_MENU;
}
void DrawMenuList()
{
int N;
for (N=0; N<menu.count; N++;)
{
if (N==menu.cur_y)
DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, 0x94AECE);
else
{
DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, col_bg);
WriteText(19,N*menu.item_h+9,0x80,0xf2f2f2,ITEMS_LIST[N]);
}
WriteText(18,N*menu.item_h+8,0x80,0x000000,ITEMS_LIST[N]);
}
}
void ItemClick()
{
action_buf = VIEW_SOURCE + menu.cur_y;
ExitProcess();
}

View File

@ -29,9 +29,9 @@ dword ChangeCharset(dword from_chs, to_chs, conv_buf)
iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
if (EAX==-1)
{
debug(from_chs);
debug(to_chs);
debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
debugln(from_chs);
debugln(to_chs);
debugln("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
return 0;
}
cd = EAX;
@ -42,12 +42,10 @@ dword ChangeCharset(dword from_chs, to_chs, conv_buf)
cd = EAX;
if (cd!=0)
{
debug("iconv: something is wrong with stdcall iconv()");
debugln("iconv: something is wrong with stdcall iconv()");
debugi(cd);
debug("in_len");
debugi(in_len);
debug("out_len");
debugi(out_len);
debug("in_len:"); debugi(in_len);
debug("out_len:"); debugi(out_len);
new_buf = free(new_buf);
return 0;
}