HTMLv: WebView independent now

code refactoring #4

git-svn-id: svn://kolibrios.org@4416 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2013-12-27 12:30:42 +00:00
parent b0297021f9
commit 3fe0fbddb3
4 changed files with 78 additions and 87 deletions

View File

@ -6,14 +6,24 @@ dword
filesize, filesize,
blink; blink;
#define URL param
int mouse_twb;
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
scroll_bar scroll_wv = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
char editURL[sizeof(URL)],
page_links[12000],
header[2048];
char download_path[]="/rd/1/.download"; char download_path[]="/rd/1/.download";
char search_path[]="http://nigma.ru/index.php?s=";
struct TWebBrowser { struct TWebBrowser {
llist list; //need #include "..\lib\list_box.h" llist list; //need #include "..\lib\list_box.h"
void GetNewUrl(); void GetNewUrl();
void OpenPage();
void ReadHtml(byte); void ReadHtml(byte);
void ShowPage(); void ShowPage();
void ParseHTML(dword); void ParseHTML(dword);
@ -45,6 +55,7 @@ char line[500],
options[4096], options[4096],
anchor[256]; anchor[256];
#include "..\TWB\history.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"
@ -157,30 +168,6 @@ void TWebBrowser::ReadHtml(byte encoding)
} }
void TWebBrowser::OpenPage()
{
if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
KillProcess(downloader_id);
strcpy(#editURL, #URL);
BrowserHistory.AddUrl();
strcpy(#header, #version);
pre_text =0;
if (!strcmp(get_URL_part(5),"http:")))
{
KillProcess(downloader_id);
DeleteFile(#download_path);
IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
downloader_id = RunProgram("/sys/network/downloader", #URL);
IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
Draw_Window();
return;
}
list.first = list.count =0;
ReadHtml(_WIN);
WB1.ShowPage();
}
void TWebBrowser::ShowPage() void TWebBrowser::ShowPage()
{ {
address_box.size = address_box.pos = strlen(#editURL); address_box.size = address_box.pos = strlen(#editURL);
@ -189,7 +176,7 @@ void TWebBrowser::ShowPage()
if (!filesize) if (!filesize)
{ {
DrawBar(list.x, list.y, list.w+scroll1.size_x+1, list.h, 0xFFFFFF); //fill all DrawBar(list.x, list.y, list.w+scroll_wv.size_x+1, list.h, 0xFFFFFF); //fill all
if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading..."); if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading...");
else else
{ {
@ -614,14 +601,14 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
{ {
scroll1.max_area = list.count; scroll_wv.max_area = list.count;
scroll1.cur_area = list.visible; scroll_wv.cur_area = list.visible;
scroll1.position = list.first; scroll_wv.position = list.first;
scroll1.all_redraw=1; scroll_wv.all_redraw=1;
scroll1.start_x = WB1.list.x + WB1.list.w; scroll_wv.start_x = WB1.list.x + WB1.list.w;
scroll1.size_y=WB1.list.h; scroll_wv.size_y=WB1.list.h;
scrollbar_v_draw(#scroll1); scrollbar_v_draw(#scroll_wv);
} }

View File

@ -24,7 +24,6 @@ void FreeImgCache()
if (pics[num_of_pics].image) img_destroy stdcall (pics[num_of_pics].image); if (pics[num_of_pics].image) img_destroy stdcall (pics[num_of_pics].image);
pics[num_of_pics].path = NULL; pics[num_of_pics].path = NULL;
} }
notify(IMAGES_CACHE_CLEARED);
} }
@ -42,8 +41,6 @@ void Images(int left1, top1, width1)
if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0) if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
{ {
debug("image options:");
debug(#options);
//get path: absolute or relative //get path: absolute or relative
if (options[0]=='/') if (options[0]=='/')
strcpy(#img_path, #options); strcpy(#img_path, #options);
@ -51,9 +48,7 @@ void Images(int left1, top1, width1)
{ {
img_path[strrchr(#img_path, '/')] = '\0'; img_path[strrchr(#img_path, '/')] = '\0';
strcat(#img_path, #options); strcat(#img_path, #options);
} }
debug("image img_path:");
debug(#img_path);
cur_pic=GetOrSetPicNum(#img_path); cur_pic=GetOrSetPicNum(#img_path);
if (!pics[cur_pic].path) if (!pics[cur_pic].path)
{ {

View File

@ -26,38 +26,25 @@
#include "img\URLgoto.txt"; #include "img\URLgoto.txt";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ҐЄбв®ўл© Ўа г§Ґа 0.99.3"; char version[]=" ¥ªáâ®¢ë© ¡à ã§¥à 0.99.31";
?define IMAGES_CACHE_CLEARED "Љни Є авЁ­®Є ®зЁйҐ­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
#else #else
char version[]=" Text-based Browser 0.99.3"; char version[]=" Text-based Browser 0.99.31";
?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define IMAGES_CACHE_CLEARED "Images cache cleared"
#endif #endif
#define URL param
char fontlol[64];
char editURL[sizeof(URL)],
page_links[12000],
header[2048];
int mouse_dd;
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
proc_info Form; proc_info Form;
#define WIN_W 640 #define WIN_W 640
#define WIN_H 480 #define WIN_H 480
char search_path[]="http://nigma.ru/index.php?s=";
char stak[4096]; char stak[4096];
mouse m; mouse m;
int action_buf; int action_buf;
#include "history.h"
#include "..\TWB\TWB.c" #include "..\TWB\TWB.c"
#include "menu_rmb.h" #include "menu_rmb.h"
@ -79,7 +66,7 @@ void main()
Form.width=WIN_W; Form.width=WIN_W;
Form.height=WIN_H; Form.height=WIN_H;
SetElementSizes(); SetElementSizes();
WB1.OpenPage(); OpenPage();
SetEventMask(0x27); SetEventMask(0x27);
loop() loop()
@ -90,10 +77,10 @@ void main()
CASE evMouse: CASE evMouse:
/* /*
//not work well, so we are use custom way of processing scroll //not work well, so we are use custom way of processing scroll
scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll_wv);
if (WB1.list.first <> scroll1.position) if (WB1.list.first <> scroll_wv.position)
{ {
WB1.list.first = scroll1.position; WB1.list.first = scroll_wv.position;
WB1.ParseHTML(buf, filesize); WB1.ParseHTML(buf, filesize);
}; };
*/ */
@ -125,8 +112,8 @@ void main()
} }
if (!m.lkm) scroll_used=0; if (!m.lkm) scroll_used=0;
if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x) if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
&& (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y) && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
&& (WB1.list.count>WB1.list.visible) && (m.lkm) && (WB1.list.count>WB1.list.visible) && (m.lkm)
{ {
scroll_used=1; scroll_used=1;
@ -135,11 +122,11 @@ void main()
if (scroll_used) if (scroll_used)
{ {
half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; //åñëè êóðñîð íàä îêíîì if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
btn=WB1.list.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî btn=WB1.list.first;
WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
if (btn<>WB1.list.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü if (btn<>WB1.list.first) WB1.ParseHTML(buf);
} }
break; break;
@ -158,13 +145,13 @@ void main()
case evKey: case evKey:
key = GetKey(); key = GetKey();
if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè if (address_box.flags & 0b10) SWITCH(key)
{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
Scan(key); Scan(key);
_EDIT_MARK: _EDIT_MARK:
if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
break; break;
case evReDraw: case evReDraw:
if (action_buf) { Scan(action_buf); action_buf=0;} if (action_buf) { Scan(action_buf); action_buf=0;}
@ -185,8 +172,8 @@ void main()
void SetElementSizes() void SetElementSizes()
{ {
address_box.width = Form.width-266; address_box.width = Form.width - 266;
WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10); WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
WB1.list.column_max = WB1.list.w - 30 / 6; WB1.list.column_max = WB1.list.w - 30 / 6;
WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
DrawBufInit(); DrawBufInit();
@ -223,8 +210,8 @@ void Draw_Window()
SetElementSizes(); SetElementSizes();
WB1.ShowPage(); WB1.ShowPage();
DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
} }
@ -251,16 +238,17 @@ void Scan(int id)
case 002: //free img cache case 002: //free img cache
FreeImgCache(); FreeImgCache();
notify(IMAGES_CACHE_CLEARED);
WB1.ParseHTML(buf); WB1.ParseHTML(buf);
return; return;
case BACK: case BACK:
if (!BrowserHistory.GoBack()) return; if (!BrowserHistory.GoBack()) return;
WB1.OpenPage(); OpenPage();
return; return;
case FORWARD: case FORWARD:
if (!BrowserHistory.GoForward()) return; if (!BrowserHistory.GoForward()) return;
WB1.OpenPage(); OpenPage();
return; return;
case 052: //F3 case 052: //F3
if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL);
@ -280,7 +268,7 @@ void Scan(int id)
} }
anchor_line_num=WB1.list.first; anchor_line_num=WB1.list.first;
anchor[0]='|'; anchor[0]='|';
WB1.OpenPage(); OpenPage();
return; return;
case 014: case 014:
case 020: case 020:
@ -295,12 +283,12 @@ void Scan(int id)
case 0x0D: //enter case 0x0D: //enter
if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
strcat(#URL, #editURL); strcat(#URL, #editURL);
WB1.OpenPage(); OpenPage();
return; return;
case SEARCHWEB: case SEARCHWEB:
strcpy(#URL, #search_path); strcpy(#URL, #search_path);
strcat(#URL, #editURL); strcat(#URL, #editURL);
WB1.OpenPage(); OpenPage();
return; return;
case 183: //PgDown case 183: //PgDown
@ -320,15 +308,15 @@ void Scan(int id)
return; return;
case 178: case 178:
case BTN_UP: //мотаем вверх case BTN_UP: //ìîòàåì ââåðõ
IF(WB1.list.first <= 0) return; if (WB1.list.first <= 0) return;
WB1.list.first--; WB1.list.first--;
WB1.ParseHTML(buf); WB1.ParseHTML(buf);
return; return;
case 177: case 177:
case BTN_DOWN: //мотаем вниз case BTN_DOWN: //ìîòàåì âíèç
IF(WB1.list.visible + WB1.list.first >= WB1.list.count) return; if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
WB1.list.first++; WB1.list.first++;
WB1.ParseHTML(buf); WB1.ParseHTML(buf);
return; return;
@ -365,7 +353,7 @@ void ProcessLinks(int id)
if (strrchr(#URL, '#')<>-1) if (strrchr(#URL, '#')<>-1)
{ {
strcpy(#anchor, #URL+strrchr(#URL, '#')); strcpy(#anchor, #URL+strrchr(#URL, '#'));
URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà URL[strrchr(#URL, '#')-1] = 0x00;
} }
WB1.GetNewUrl(); WB1.GetNewUrl();
@ -386,12 +374,33 @@ void ProcessLinks(int id)
return; return;
} }
WB1.OpenPage(); OpenPage();
return; return;
} }
void OpenPage()
{
if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
KillProcess(downloader_id);
strcpy(#editURL, #URL);
BrowserHistory.AddUrl();
strcpy(#header, #version);
pre_text =0;
if (!strcmp(get_URL_part(5),"http:")))
{
KillProcess(downloader_id);
DeleteFile(#download_path);
IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
downloader_id = RunProgram("/sys/network/downloader", #URL);
IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
Draw_Window();
return;
}
WB1.list.first = WB1.list.count =0;
WB1.ReadHtml(_WIN);
WB1.ShowPage();
}
stop: stop: