WebView 2.0 beta 4: highlight a link as a single item, more refactoring

git-svn-id: svn://kolibrios.org@7757 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-03-29 10:57:14 +00:00
parent 7b61a5afa1
commit 2c4fa5e173
17 changed files with 268 additions and 261 deletions

View File

@ -2,8 +2,12 @@
#include "..\TWB\anchors.h"
#include "..\TWB\parce_tag.h"
#include "..\TWB\absolute_url.h"
char line[500];
#include "..\TWB\unicode_tags.h"
#include "..\TWB\img_cache.h"
dword page_bg;
dword link_color_inactive;
dword link_color_active;
#include "..\TWB\links.h"
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
@ -39,15 +43,10 @@ struct TWebBrowser {
void BufEncode();
} WB1;
dword page_bg;
#include "..\TWB\img_cache.h"
dword link_color_inactive;
dword link_color_active;
char line[500];
bool link, cur_encoding, t_html, t_body;
#include "..\TWB\links.h"
dword bufpointer=0;
dword bufsize=0;
@ -57,7 +56,7 @@ char header[150];
int body_magrin=6;
int basic_line_h=22;
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,15,0,0xeeeeee,0xBBBbbb,0xeeeeee};
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
//============================================================================================
void TWebBrowser::DrawStyle()
@ -128,8 +127,10 @@ void TWebBrowser::SetPageDefaults()
stolbec = 0;
line = 0;
zoom = 1;
if (o_bufpointer) free(o_bufpointer);
o_bufpointer = 0;
//hold original buffer
if (o_bufpointer) o_bufpointer=free(o_bufpointer);
o_bufpointer = malloc(bufsize);
memmov(o_bufpointer, bufpointer, bufsize);
}
//============================================================================================
void TWebBrowser::AddCharToTheLine(unsigned char _char)
@ -187,7 +188,7 @@ void TWebBrowser::ParseHtml(){
bukva = ESBYTE[bufpos+j];
chrcat(#unicode_symbol, bukva);
}
if (bukva = GetUnicodeSymbol(#unicode_symbol)) {
if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
bufpos += j;
CheckForLineBreak();
} else {
@ -242,7 +243,7 @@ void TWebBrowser::ParseHtml(){
if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
if (tag.params) tag.parse_params();
if (tag.name) && (!tag.is("i")) && (!tag.is("svg")) {
if (tag.name) {
CheckForLineBreak();
DrawStyle();
if (tag.name) SetStyle();
@ -300,12 +301,12 @@ void TWebBrowser::SetStyle() {
t_html = tag.opened;
return;
}
if(tag.is("title")) {
if (tag.is("title")) {
if (tag.opened) header=NULL;
return;
}
IF(tag.is("q"))
if (tag.is("q"))
{
if (tag.opened) {
meta_encoding = strlen(#line);
@ -384,6 +385,7 @@ void TWebBrowser::SetStyle() {
return;
}
if (tag.is("br")) { NewLine(); return; }
if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; }
if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
@ -459,7 +461,7 @@ void TWebBrowser::SetStyle() {
if (tag.is("ul")) || (tag.is("ol")) {
if (!tag.opened)
{
style.li = tag.opened;
style.li = false;
style.li_tab--;
NewLine();
}
@ -495,17 +497,10 @@ void TWebBrowser::SetStyle() {
//============================================================================================
void TWebBrowser::BufEncode(dword set_new_encoding)
{
if (cur_encoding == set_new_encoding) return;
if (o_bufpointer==0) {
o_bufpointer = malloc(bufsize);
strcpy(o_bufpointer, bufpointer);
} else {
strcpy(bufpointer, o_bufpointer);
if (cur_encoding != set_new_encoding) {
cur_encoding = set_new_encoding;
bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);
}
//debugval("cur_encoding ", cur_encoding);
//debugval("set_new_encoding", set_new_encoding);
cur_encoding = set_new_encoding;
bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);
}
//============================================================================================
void TWebBrowser::DrawScroller()

View File

@ -1,40 +1,33 @@
dword GetAbsoluteURL(dword in_URL)
:dword GetAbsoluteURL(dword new_URL, base_URL)
{
int i;
dword orig_URL = in_URL;
dword orig_URL = new_URL;
char newurl[URL_SIZE+1];
strcpy(#newurl, base_URL);
while (i=strstr(in_URL, "&"))
while (i=strstr(new_URL, "&"))
{
strcpy(i+1, i+5);
}
if (check_is_the_url_absolute(in_URL)) return orig_URL;
if (check_is_the_url_absolute(new_URL)) return orig_URL;
IF (!strncmp(in_URL,"//", 2))
IF (!strncmp(new_URL,"//", 2))
{
strcpy(#newurl, "http:");
strcat(#newurl, in_URL);
strcat(#newurl, new_URL);
strcpy(orig_URL, #newurl);
return orig_URL;
}
IF (!strncmp(in_URL,"./", 2)) in_URL+=2;
if (!http.transfer)
{
strcpy(#newurl, history.current());
}
else
{
strcpy(#newurl, history.items.get(history.active-2));
}
IF (!strncmp(new_URL,"./", 2)) new_URL+=2;
if (ESBYTE[in_URL] == '/') //remove everything after site domain name
if (ESBYTE[new_URL] == '/') //remove everything after site domain name
{
i = strchr(#newurl+8, '/');
if (i) ESBYTE[i]=0;
in_URL+=1;
new_URL+=1;
}
_CUT_ST_LEVEL_MARK:
@ -44,16 +37,16 @@ dword GetAbsoluteURL(dword in_URL)
newurl[strrchr(#newurl, '/')] = 0x00;
}
IF (!strncmp(in_URL,"../",3))
IF (!strncmp(new_URL,"../",3))
{
in_URL+=3;
new_URL+=3;
newurl[strrchr(#newurl, '/')-1] = 0x00;
goto _CUT_ST_LEVEL_MARK;
}
if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/");
strcat(#newurl, in_URL);
strcat(#newurl, new_URL);
strcpy(orig_URL, #newurl);
return orig_URL;
}

View File

@ -52,7 +52,9 @@ void ImageCache::Images(dword left1, top1, width1)
imgh = DSWORD[pics[cur_pic].image+8];
if (imgw > width1) imgw = width1;
//draw_y += imgh + 5; TEMPORARY TURN OFF!!!
/*
draw_y += imgh + 5; TEMPORARY TURN OFF!!!
if (top1+imgh<WB1.list.y) || (top1>WB1.list.y+WB1.list.h-10) return; //if all image is out of visible area
if (top1<WB1.list.y) //if image partly visible (at the top)
{
@ -69,7 +71,6 @@ void ImageCache::Images(dword left1, top1, width1)
img_draw stdcall (pics[cur_pic].image, left1-5, top1, imgw, imgh,0,img_lines_first);
DrawBar(left1+imgw - 5, top1, WB1.list.w-imgw, imgh, page_bg);
DrawBar(WB1.list.x, top1+imgh, WB1.list.w, -imgh % WB1.list.item_h + WB1.list.item_h, page_bg);
/*
if (link)
{
UnsafeDefineButton(left1 - 5, top1, imgw, imgh-1, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);

View File

@ -9,26 +9,30 @@ dword CursorFile = FROM "../TWB/pointer.cur";
struct array_link {
dword link;
int x,y,w,h;
unsigned int x,y,w,h;
unsigned int unic_id;
int underline, underline_h;
};
struct LinksArray {
array_link links[MAXLINKS];
collection page_links;
int count;
int active;
unsigned int count;
unsigned int unic_count;
unsigned int active;
bool HoverAndProceed();
void AddLink();
void AddText();
dword GetURL();
void Clear();
void DrawUnderline();
} PageLinks;
void LinksArray::AddLink(dword lpath)
{
if (count>= MAXLINKS) return;
page_links.add(lpath);
unic_count++;
}
void LinksArray::AddText(dword _x, _y, _w, _h, _link_underline, _underline_h)
@ -41,6 +45,7 @@ void LinksArray::AddText(dword _x, _y, _w, _h, _link_underline, _underline_h)
links[count].underline = _link_underline;
links[count].underline_h = _underline_h;
links[count].link = page_links.get(page_links.count-1);
links[count].unic_id = unic_count;
count++;
}
@ -55,12 +60,24 @@ void LinksArray::Clear()
page_links.realloc_size = 4096 * 32;
count = 0;
active = -1;
unic_count = 0;
CursorPointer.Restore();
}
void LinksArray::DrawUnderline(dword und_id, list_first, list_y, color)
{
int i;
for (i=0; i<count; i++)
{
if (links[i].unic_id==links[und_id].unic_id) && (links[i].y + links[i].h - list_first > list_y) {
DrawBar(links[i].x, links[i].y + links[i].h - list_first, links[i].w, links[i].underline_h, color);
}
}
}
PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, NULL, 0};
bool LinksArray::HoverAndProceed(dword mx, my)
bool LinksArray::HoverAndProceed(dword mx, my, list_y, list_first)
{
int i;
if (!count) return true;
@ -68,10 +85,10 @@ bool LinksArray::HoverAndProceed(dword mx, my)
{
if (mx>links[i].x) && (my>links[i].y)
&& (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h)
&& (my>WB1.list.y+WB1.list.first)
&& (my>list_y+list_first)
{
if (mouse.lkm) && (mouse.down) {
DrawRectangle(links[active].x, -WB1.list.first + links[active].y,
DrawRectangle(links[active].x, -list_first + links[active].y,
links[active].w, links[active].h, 0);
return false;
}
@ -91,10 +108,15 @@ bool LinksArray::HoverAndProceed(dword mx, my)
if (active==i) return false;
CursorPointer.Load(#CursorFile);
CursorPointer.Set();
if (links[active].underline) DrawUnderline(links[active].x, -WB1.list.first + links[active].y
+ links[active].h, links[active].w, links[active].underline_h, link_color_inactive);
if (links[i].underline) DrawUnderline(links[i].x, -WB1.list.first + links[i].y
+ links[i].h, links[i].w, links[i].underline_h, page_bg);
if (links[active].underline) {
DrawUnderline(active, list_first, list_y, link_color_inactive);
}
if (links[i].underline) {
DrawUnderline(i, list_first, list_y, page_bg);
}
active = i;
DrawStatusBar(links[active].link);
return true;
@ -104,15 +126,10 @@ bool LinksArray::HoverAndProceed(dword mx, my)
{
CursorPointer.Restore();
if (links[active].underline) {
DrawUnderline(links[active].x, -WB1.list.first + links[active].y + links[active].h,links[active].w,
links[active].underline_h, link_color_inactive);
DrawUnderline(active, list_first, list_y, link_color_inactive);
}
DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
DrawStatusBar(NULL);
active = -1;
}
}
void DrawUnderline(dword x,y,w,h,color)
{
if (y>WB1.list.y) DrawBar(x,y,w,h,color);
}

View File

@ -1,14 +1,9 @@
char *unicode_symbols[]={
"#32", " ",
"#34", "\"", "quot","\"",
"#38", "&", "amp", "&",
"#39", "'",
"#039","'",
"#60", "<", "lt", "<",
"#62", ">", "gt", ">",
"#91", "[",
"#93", "]",
"#96", "'",
"quot","\"",
"amp", "&",
"lt", "<",
"gt", ">",
"#183","\31", "middot", "\31",
"#149","-",
"#151","-",
"#160"," ", "nbsp", " ",
@ -32,11 +27,13 @@ char *unicode_symbols[]={
"#8211", "-",
"#8217", "'",
"#8220", "\"",
"#8222", "\"", "ldquo", "\"",
"#8221", "\"", "rdquo", "\"",
"#8470", "N",
"#8722", "-",
"#9642", "-", //square in the middle of the line
"#65122", "+",
"uarr", "\24",
"darr", "\25",
@ -53,33 +50,31 @@ char *unicode_symbols[]={
unsigned char unicode_chars[] = "€亗儎厗噲墛媽崕彁憭摂晼棙櫄洔潪煚、¥ウЖ┆<EFBFBD><EFBFBD><EFBFBD>徕沅彐玷殛腱眍镳駂<EFBFBD>243i\105\244\0";
bool GetUnicodeSymbol(dword in_tag)
bool GetUnicodeSymbol(dword _line, in_tag, size)
{
int j, specia1040;
int j;
int code;
for (j=0; unicode_symbols[j]!=0; j+=2;)
{
if (!strcmp(in_tag, unicode_symbols[j]))
{
strcat(#line, unicode_symbols[j+1]);
strncat(_line, unicode_symbols[j+1], size);
return true;
}
}
specia1040 = atoi(in_tag + 1) - 1040;
if (ESBYTE[in_tag+1] == '1') && (specia1040>=0)
&& (specia1040<=72) && (strlen(in_tag) == 5)
if (ESBYTE[in_tag]=='#')
{
if (strlen(#line)<sizeof(line)-2) {
/*
j = strlen(#line);
line[j] = unicode_chars[specia1040];
line[j+1] = EOS;
*/
chrcat(#line, unicode_chars[specia1040]);
code = atoi(in_tag + 1);
if (code>=0) && (code<=255) {
chrncat(_line, code, size); //NOT ALL ASCII CODES IN KOLIBRI ARE COMPATABLE WITH STANDARDS
return true;
}
if (code>=1040) && (code<=1040+72) {
chrncat(_line, unicode_chars[code-1040], size);
return true;
}
return true;
}
return false;

View File

@ -23,6 +23,8 @@ llist list;
#include "canvas.h"
#include "favicon.h"
_history history;
char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };

View File

@ -23,13 +23,26 @@
#include "..\lib\obj\http.h"
#include "..\lib\obj\iconv.h"
#include "..\lib\obj\proc_lib.h"
//useful patterns
#include "..\lib\patterns\history.h"
#include "..\lib\patterns\http_downloader.h"
#include "..\lib\patterns\simple_open_dialog.h"
#include "show_src.h"
_http http = {0, 0, 0, 0, 0, 0, 0};
#include "download_manager.h"
_history history;
#include "history.h"
bool debug_mode = false;
dword col_bg = 0xE3E2E2;
dword panel_color = 0xE3E2E2;
dword border_color = 0x787878;
#include "..\TWB\TWB.c"
#ifdef LANG_RUS
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 2.0 beta2";
char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 2.0 beta4";
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
char homepage[] = FROM "html\\homepage_ru.htm""\0";
char help[] = FROM "html\\help_ru.htm""\0";
@ -43,7 +56,7 @@ char link_menu[] =
"Š®¯¨à®¢ âì áá뫪ã
ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
#else
char version[]="Text-based Browser 2.0 beta2";
char version[]="Text-based Browser 2.0 beta4";
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
char homepage[] = FROM "html\\homepage_en.htm""\0";
char help[] = FROM "html\\help_en.htm""\0";
@ -60,19 +73,6 @@ Download link contents";
#define URL_SIZE 4000
dword col_bg = 0xE3E2E2;
dword panel_color = 0xE3E2E2;
dword border_color = 0x787878;
bool debug_mode = false;
_http http = {0, 0, 0, 0, 0, 0, 0};
#include "..\TWB\TWB.c"
#include "history.h"
#include "show_src.h"
#include "download_manager.h"
#define URL_SERVICE_HISTORY "WebView:history"
#define URL_SERVICE_HOMEPAGE "WebView:home"
#define URL_SERVICE_HELP "WebView:help"
@ -158,7 +158,7 @@ void main()
case evMouse:
edit_box_mouse stdcall (#address_box);
mouse.get();
if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
&& (mouse.pkm) && (mouse.up) {
if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
break;
@ -250,7 +250,7 @@ void main()
{
http.handle_redirect();
http.free();
GetAbsoluteURL(#http.redirect_url);
GetAbsoluteURL(#http.redirect_url, history.current());
debug("Redirect: "); debugln(#http.redirect_url);
history.back();
OpenPage(#http.redirect_url);
@ -277,7 +277,7 @@ void SetElementSizes()
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
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, 800*20);
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
OpenPage(history.current());
}
}
@ -301,13 +301,12 @@ void draw_window()
if (!header) {
OpenPage(history.current());
WB1.DrawScroller();
}
else {
} else {
WB1.DrawPage();
DrawOmnibox();
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x,
scroll_wv.size_y-1, scroll_wv.bckg_col);
}
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x,
scroll_wv.size_y-1, scroll_wv.bckg_col);
DrawProgress();
}
@ -401,21 +400,24 @@ void StopLoading()
}
//rewrite into
//bool strrpl(dword dst, from, to, dst_len); !!!!!!!!
void ReplaceSpaceInUrl(dword url, size) {
//bool strrpl(dword dst, from, into, dst_len);
bool ReplaceSpaceInUrl(dword url, size) {
unsigned int i, j;
for (i=size-3; i>0; i--)
bool was_changed=false;
for (i=url+size-3; i>url; i--)
{
if (ESBYTE[i]!=' ') continue;
for (j=size-3; j>i; j--) {
for (j=url+size-3; j>=i; j--) {
ESBYTE[j+3]=ESBYTE[j+2];
ESBYTE[j+2]=ESBYTE[j+1];
ESBYTE[j+1]=ESBYTE[j];
}
ESBYTE[i] = '%';
ESBYTE[i+1] = '2';
ESBYTE[i+2] = '0';
was_changed = true;
}
debugln(url);
return was_changed;
}
bool GetLocalFileData(dword _path)
@ -462,7 +464,11 @@ void OpenPage(dword _open_URL)
img_draw stdcall(skin.image, address_box.left+address_box.width+1,
address_box.top-3, 17, skin.h, 85, SKIN_Y);
//ReplaceSpaceInUrl(#new_url, URL_SIZE);
if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
strcpy(#editURL, #new_url);
DrawOmnibox();
}
if (!strncmp(#new_url,"http:",5)) {
http.get(#new_url);
} else if (!strncmp(#new_url,"https://",8)) {
@ -509,7 +515,7 @@ void EventClickLink(dword _click_URL)
}
strcpy(#new_url, _click_URL);
GetAbsoluteURL(#new_url);
GetAbsoluteURL(#new_url, history.current());
if (strrchr(#new_url, '#')!=0) {
anchors.take_anchor_from(#new_url);
@ -594,14 +600,13 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){
strcat(#editURL, #anchors.current);
DrawOmnibox();
}
WB1.ParseHtml();
if (source_mode) {
source_mode = false;
WB1.ParseHtml();
ShowSource(bufpointer, bufsize);
return;
} else {
WB1.DrawPage();
}
WB1.ParseHtml();
WB1.DrawPage();
}
}

View File

@ -38,8 +38,8 @@ dword ShowSource(dword _bufdata, _in_bufsize)
dword source_buf_start;
opened_font_counter=0;
source_buf_end = malloc(_in_bufsize*5);
source_buf_start = source_buf_end;
source_buf_start = malloc(_in_bufsize*5);
source_buf_end = source_buf_start;
SourceBufAdd(TEXT, "<html><head><title>View Source</title><body><pre>");
@ -89,6 +89,6 @@ dword ShowSource(dword _bufdata, _in_bufsize)
source_buf_end++;
}
ESBYTE[source_buf_end] = 0;
LoadInternalPage(source_buf_start, _in_bufsize);
LoadInternalPage(source_buf_start, source_buf_end-source_buf_start);
free(source_buf_start);
}

View File

@ -14,13 +14,11 @@
#include "..\lib\obj\box_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\obj\http.h"
#include "..\lib\obj\iconv.h"
#include "..\lib\obj\proc_lib.h"
#include "..\lib\patterns\history.h"
#include "..\lib\patterns\http_downloader.h"
_http http = {0, 0, 0, 0, 0, 0, 0};
//useful patterns
#include "..\lib\patterns\simple_open_dialog.h"
char homepage[] = FROM "html\\homepage.htm""\0";
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
@ -28,7 +26,7 @@ char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
char version[]="C-- Code View";
char accept_language[]= "Accept-Language: en\n";
#define URL_SERVICE_HOME "CodeView://home"
#define URL_SERVICE_HOME "CodeView:home"
proc_info Form;
@ -52,24 +50,33 @@ enum {
#define URL_SIZE 4000;
#include "..\TWB\TWB.c"
#include "show_src.h"
#include "highlight_c.h"
char URL[URL_SIZE+1];
char editURL[URL_SIZE+1];
char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "C\0H\0C--\0H--\0CPP\0\0" };
char current_path[URL_SIZE+1];
char edit_path[URL_SIZE+1];
int mouse_twb;
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#editURL,#mouse_twb,2,19,19};
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#edit_path,#mouse_twb,2,19,19};
#define SKIN_Y 24
void main()
void LoadLibraries()
{
int i;
int id;
load_dll(boxlib, #box_lib_init,0);
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
load_dll(iconv_lib, #iconv_open,0);
if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#o_dialog);
}
void main()
{
int i;
LoadLibraries();
if (param) strcpy(#current_path, #param); else strcpy(#current_path, URL_SERVICE_HOME);
WB1.list.SetFont(8, 14, 10011000b);
WB1.list.no_selection = true;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
@ -89,23 +96,28 @@ void main()
break;
case evButton:
id=GetButtonID();
if (1==id) ExitProcess();
if (GetButtonID()==1) ExitProcess();
break;
case evKey:
GetKeys();
if (SCAN_CODE_F5 == key_scancode) {
OpenPage();
OpenPage(#current_path);
}
if (SCAN_CODE_F3 == key_scancode) {
RunProgram("/rd/1/tinypad", #URL);
RunProgram("/rd/1/tinypad", #current_path);
}
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
}
if (address_box.flags & 0b10)
{
if (key_ascii == ASCII_KEY_ENTER) EventGoToPage();
if (key_ascii == ASCII_KEY_ENTER) {
OpenPage(#edit_path);
}
else {
EAX = key_editbox;
edit_box_key stdcall(#address_box);
@ -126,7 +138,8 @@ void main()
if (Form.status_window>2) { DrawTitle(#header); break; }
if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
Draw_Window();
SetElementSizes();
draw_window();
break;
}
}
@ -144,76 +157,48 @@ void SetElementSizes()
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);
OpenPage();
OpenPage(#current_path);
}
}
void Draw_Window()
void draw_window()
{
DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
SetElementSizes();
DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+4, 25,border_color);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
DrawEditBoxWebView();
if (!header)
OpenPage();
else {
if (!header) {
OpenPage(#current_path);
} else {
WB1.DrawPage();
DrawEditBoxWebView();
}
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
}
void EventGoToPage()
{
if (!editURL[0]) {
strcpy(#URL, URL_SERVICE_HOME);
}
else
{
strcpy(#URL, #editURL);
}
OpenPage();
}
void SetPageDefaults()
void OpenPage(dword _path)
{
strncpy(#header, #version, sizeof(header)-1);
WB1.list.count = WB1.list.first = 0;
cur_encoding = CH_NULL;
}
void OpenPage()
{
char getUrl[URL_SIZE+1];
strcpy(#editURL, #URL);
history.add(#URL);
if (!strncmp(#URL,"CodeView:",8))
{
SetPageDefaults();
if (!strcmp(#URL, URL_SERVICE_HOME)) LoadInternalPage(#homepage, sizeof(homepage));
DrawEditBoxWebView();
dword buf, size;
strcpy(#current_path, _path);
if (streq(_path, URL_SERVICE_HOME)) {
LoadInternalPage(#homepage, sizeof(homepage));
return;
}
else
file_size stdcall (_path);
if (EBX)
{
file_size stdcall (#URL);
bufsize = EBX;
if (bufsize)
{
free(bufpointer);
bufpointer = malloc(bufsize);
SetPageDefaults();
ReadFile(0, bufsize, bufpointer, #URL);
ShowCodeSource();
LoadInternalPage(bufpointer, bufsize);
}
ShowPage();
size = EBX;
buf = malloc(size);
ReadFile(0, size, buf, _path);
ShowCodeSource();
free(buf);
return;
}
LoadInternalPage(NULL,NULL);
}
DrawEditBoxWebView()
@ -221,27 +206,43 @@ DrawEditBoxWebView()
int skin_x_offset;
DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#edit_path);
address_box.offset = 0;
edit_box_draw stdcall(#address_box);
skin_x_offset = 51;
img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
}
void LoadInternalPage(dword bufpos, in_filesize){
bufsize = in_filesize;
bufpointer = bufpos;
ShowPage();
}
void ShowPage()
void LoadInternalPage(dword _bufpos, _bufsize)
{
if (bufpointer) free(bufpointer);
if (!_bufpos) || (!_bufsize) {
LoadInternalPage(#page_not_found, sizeof(page_not_found));
return;
}
strcpy(#edit_path, #current_path);
DrawEditBoxWebView();
if (!bufsize) LoadInternalPage(#page_not_found, sizeof(page_not_found));
bufpointer = _bufpos;
bufsize = _bufsize;
bufpointer = malloc(bufsize);
strcpy(bufpointer, _bufpos);
WB1.list.first = 0;
WB1.ParseHtml();
WB1.DrawPage();
}
void EventOpenDialog()
{
OpenDialog_start stdcall (#o_dialog);
if (o_dialog.status) {
OpenPage(#openfile_path);
}
}
void DrawStatusBar() {return;};
void EventClickLink() {return;};
void EventShowLinkMenu() {return;};

View File

@ -14,7 +14,7 @@ char* C_HL_keywords[] = {
":void ", ":int ", ":bool ", ":dword ", NULL
};
dword ShowCodeSource()
dword ShowCodeSource(dword _bufpointer, _bufsize)
{
dword new_buf, new_buf_start, i;
int mode = CODE;
@ -24,11 +24,11 @@ dword ShowCodeSource()
dword keyn;
dword keycolor;
new_buf = malloc(bufsize*10);
new_buf = malloc(_bufsize*10);
new_buf_start = new_buf;
sprintf(new_buf,"<html><head><body><pre>",#URL);
sprintf(new_buf,"<html><head><title>%s</title><body><pre>",#current_path);
new_buf += strlen(new_buf);
for (i=bufpointer; i<bufpointer+bufsize; i++)
for (i=_bufpointer; i<_bufpointer+_bufsize; i++)
{
if ('<' == ESBYTE[i]) {
strcpy(new_buf, "&lt;");
@ -116,7 +116,6 @@ dword ShowCodeSource()
_CONTINUE:
}
ESBYTE[new_buf] = 0;
bufsize = new_buf - new_buf_start;
free(bufpointer);
bufpointer = new_buf_start;
LoadInternalPage(new_buf_start, new_buf - new_buf_start);
free(new_buf_start);
}

View File

@ -5,8 +5,9 @@
<body>
<br>
CodeView is a sipmle C--/C/C++ code viewer based on TWB component.
CodeView is a sipmle C--/C/C++ code viewer based on TWB component.<br>
<br>
Press Ctrl+O to open a file.
</body>
</html>

View File

@ -1,14 +1,10 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=cp-866" />
<title>File not found</title>
<meta charset=cp-866 />
<title>File not found</title>
</head>
<body>
<h1>&nbsp;File not found</h1>
<ul>
<li>
Check page address, there may have been made a typo.<br>
</li>
</ul>
<h1>&nbsp;File not found</h1>
Please, check file address, there may have been made a typo.
</body>
</html>

View File

@ -50,6 +50,8 @@ enum {
ONLY_OPEN
};
_history history;
struct Eolite_colors
{
bool def;

View File

@ -269,6 +269,8 @@ struct llist
:void llist_copy(dword dest, src)
{
memmov(dest, src, sizeof(llist));
/*
EDI = dest;
ESI = src;
EDI.llist.x = ESI.llist.x;
@ -286,6 +288,7 @@ struct llist
EDI.llist.cur_y = ESI.llist.cur_y;
EDI.llist.column_max = ESI.llist.column_max;
EDI.llist.active = ESI.llist.active;
*/
}
#endif

View File

@ -7,7 +7,7 @@ struct _history {
int back();
int forward();
dword current();
} history;
};
int _history::add(dword in)
{

View File

@ -114,6 +114,30 @@ L1:
}
}
/*
signed int strncmp(dword s1, s2, signed n)
unsigned char _s1,_s2;
{
if (n == 0)
return 0;
do {
_s1 = DSBYTE[s1];
_s2 = DSBYTE[s2];
if (_s1 != _s2)
{
$dec s2
return _s1 - _s2;
}
$inc s2
if (_s1 == 0)
break;
$inc s1
$dec n
} while (n);
return 0;
}
*/
/*
inline signed int strncmp(dword text1,text2,len)
{
@ -134,7 +158,7 @@ inline fastcall unsigned int strlen( EDI)
EAX-=2+ECX;
}
inline strnlen(dword str, dword maxlen)
inline dword strnlen(dword str, dword maxlen)
{
dword cp;
for (cp = str; (maxlen != 0) && (DSBYTE[cp] != '\0'); cp++, maxlen--);
@ -181,19 +205,6 @@ inline signed int strcmp(dword text1, text2)
return 0;
}
/*
TODO: rewrite streq() using pure assembliy
inline fastcall void strcpy( EDI, ESI)
{
$cld
L2:
$lodsb
$stosb
$test al,al
$jnz L2
}
*/
inline fastcall streq(ESI, EDI)
{
@ -212,31 +223,6 @@ inline fastcall streq(ESI, EDI)
return true;
}
/*
signed int strncmp(dword s1, s2, signed n)
unsigned char _s1,_s2;
{
if (n == 0)
return 0;
do {
_s1 = DSBYTE[s1];
_s2 = DSBYTE[s2];
if (_s1 != _s2)
{
$dec s2
return _s1 - _s2;
}
$inc s2
if (_s1 == 0)
break;
$inc s1
$dec n
} while (n);
return 0;
}
*/
inline fastcall void strcpy( EDI, ESI)
{
$cld
@ -395,13 +381,13 @@ inline fastcall void strcat( EDI, ESI)
}
}
:void strncat(dword dst, src, dword len)
:void strncat(dword dst, src, len)
{
while (ESBYTE[dst]) && (len) {
dst++;
len--;
}
while (ESBYTE[src]) && (len) {
while (ESBYTE[src]) && (len>1) {
ESBYTE[dst] = ESBYTE[src];
dst++;
src++;
@ -410,6 +396,18 @@ inline fastcall void strcat( EDI, ESI)
ESBYTE[dst] = 0;
}
:void chrncat(dword dst, unsigned char s, dword len)
{
while (ESBYTE[dst]) && (len) {
dst++;
len--;
}
if (len>1) {
ESBYTE[dst] = s;
ESBYTE[dst+1] = 0;
}
}
inline fastcall void chrcat(ESI, DI)
{
while (ESBYTE[ESI]) ESI++;

View File

@ -22,7 +22,6 @@
#include "../lib/obj/netcode.h"
#include "../lib/obj/iconv.h"
//patterns
#include "../lib/patterns/history.h"
#include "../lib/patterns/http_downloader.h"
//images
byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons.raw";