WebVIew 2.4: tabs

git-svn-id: svn://kolibrios.org@7771 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-04-10 16:19:52 +00:00
parent 3f59e384f1
commit 672bbcf6a0
15 changed files with 413 additions and 116 deletions

View File

@ -1,6 +1,6 @@
#include "..\TWB\colors.h" #include "..\TWB\colors.h"
#include "..\TWB\anchors.h" #include "..\TWB\anchors.h"
#include "..\TWB\parce_tag.h" #include "..\TWB\parse_tag.h"
#include "..\TWB\special.h" #include "..\TWB\special.h"
#include "..\TWB\img_cache.h" #include "..\TWB\img_cache.h"
#include "..\TWB\tag_list.h" #include "..\TWB\tag_list.h"
@ -12,6 +12,9 @@ dword link_color_active;
#define BODY_MARGIN 6 #define BODY_MARGIN 6
#define BASIC_LINE_H 18 #define BASIC_LINE_H 18
DrawBufer DrawBuf;
char line[500];
struct _style { struct _style {
bool bool
b, u, s, h, b, u, s, h,
@ -27,7 +30,6 @@ struct _style {
struct TWebBrowser { struct TWebBrowser {
llist list; llist list;
_style style; _style style;
DrawBufer DrawBuf;
dword draw_y, stolbec; dword draw_y, stolbec;
int zoom; int zoom;
dword o_bufpointer; dword o_bufpointer;
@ -36,7 +38,7 @@ struct TWebBrowser {
dword bufpointer; dword bufpointer;
dword bufsize; dword bufsize;
void DrawStyle(); void Paint();
void SetPageDefaults(); void SetPageDefaults();
void AddCharToTheLine(); void AddCharToTheLine();
void ParseHtml(); void ParseHtml();
@ -46,14 +48,13 @@ struct TWebBrowser {
void DrawScroller(); void DrawScroller();
void ChangeEncoding(); void ChangeEncoding();
void DrawPage(); void DrawPage();
char line[500];
char header[150]; char header[150];
}; };
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
//============================================================================================ //============================================================================================
void TWebBrowser::DrawStyle() void TWebBrowser::Paint()
{ {
dword start_x, line_length, stolbec_len; dword start_x, line_length, stolbec_len;
dword text_color__; dword text_color__;
@ -96,7 +97,6 @@ void TWebBrowser::DrawStyle()
text_color__ = text_colors[text_color_index]; text_color__ = text_colors[text_color_index];
if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default; if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default;
DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line); DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line);
if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line); if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line);
if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__); if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__);
@ -151,7 +151,7 @@ void TWebBrowser::AddCharToTheLine(unsigned char _char)
if (line[line_len-1]==' ') return; //no double spaces if (line[line_len-1]==' ') return; //no double spaces
if (!stolbec) && (!line) return; //no paces at the beginning of the line if (!stolbec) && (!line) return; //no paces at the beginning of the line
} }
if (line_len < sizeof(TWebBrowser.line)) chrcat(#line, _char); if (line_len < sizeof(line)) chrcat(#line, _char);
CheckForLineBreak(); CheckForLineBreak();
} }
//============================================================================================ //============================================================================================
@ -164,8 +164,12 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
int tab_len; int tab_len;
dword bufpos; dword bufpos;
bufsize = _bufsize; bufsize = _bufsize;
bufpointer = malloc(bufsize); if (bufpointer != _bufpointer) {
memmov(bufpointer, _bufpointer, bufsize); bufpointer = malloc(bufsize);
memmov(bufpointer, _bufpointer, bufsize);
} else {
custom_encoding = CH_CP866;
}
SetPageDefaults(); SetPageDefaults();
if (strstri(bufpointer, "<body")==-1) { if (strstri(bufpointer, "<body")==-1) {
t_body = true; t_body = true;
@ -178,7 +182,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
{ {
case 0x0a: case 0x0a:
if (style.pre) { if (style.pre) {
DrawStyle(); Paint();
NewLine(); NewLine();
} else { } else {
AddCharToTheLine(0x0a); AddCharToTheLine(0x0a);
@ -199,7 +203,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
bukva = ESBYTE[bufpos+j]; bukva = ESBYTE[bufpos+j];
chrcat(#unicode_symbol, bukva); chrcat(#unicode_symbol, bukva);
} }
if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(TWebBrowser.line)-1)) { if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
bufpos += j; bufpos += j;
CheckForLineBreak(); CheckForLineBreak();
} else { } else {
@ -256,7 +260,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
if (tag.name) { if (tag.name) {
CheckForLineBreak(); CheckForLineBreak();
DrawStyle(); Paint();
if (tag.name) SetStyle(); if (tag.name) SetStyle();
} }
break; break;
@ -264,7 +268,7 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
AddCharToTheLine(ESBYTE[bufpos]); AddCharToTheLine(ESBYTE[bufpos]);
} }
} }
DrawStyle(); Paint();
NewLine(); NewLine();
list.count = draw_y; list.count = draw_y;
list.CheckDoesValuesOkey(); list.CheckDoesValuesOkey();
@ -296,7 +300,7 @@ bool TWebBrowser::CheckForLineBreak()
strcpy(#new_line_text, #line + line_break_pos); strcpy(#new_line_text, #line + line_break_pos);
line[line_break_pos] = 0x00; line[line_break_pos] = 0x00;
DrawStyle(); Paint();
strcpy(#line, #new_line_text); strcpy(#line, #new_line_text);
NewLine(); NewLine();
@ -359,12 +363,12 @@ void TWebBrowser::SetStyle() {
if (tag.is("iframe")) && (value = tag.get_value_of("src=")) { if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
NewLine(); NewLine();
strcpy(#line, "IFRAME: "); strcpy(#line, "IFRAME: ");
DrawStyle(); Paint();
link=true; link=true;
PageLinks.AddLink(value); PageLinks.AddLink(value);
strncpy(#line, value, sizeof(TWebBrowser.line)-1); strncpy(#line, value, sizeof(line)-1);
while (CheckForLineBreak()) {}; while (CheckForLineBreak()) {};
DrawStyle(); Paint();
link=false; link=false;
NewLine(); NewLine();
} }
@ -416,8 +420,8 @@ void TWebBrowser::SetStyle() {
} }
if (tag.is("img")) { if (tag.is("img")) {
if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1); if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(TWebBrowser.line)-3) && (value) sprintf(#line, "[%s]", value); if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(TWebBrowser.line)-3) && (value) sprintf(#line, "[%s]", value); if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
if (!img_path) { line=0; return; } if (!img_path) { line=0; return; }
style.image = true; style.image = true;
text_color_index++; text_color_index++;
@ -429,7 +433,7 @@ void TWebBrowser::SetStyle() {
line[50]= NULL; line[50]= NULL;
} }
while (CheckForLineBreak()) {}; while (CheckForLineBreak()) {};
DrawStyle(); Paint();
text_color_index--; text_color_index--;
style.image = false; style.image = false;
//ImgCache.Images( list.x, draw_y, list.w); //ImgCache.Images( list.x, draw_y, list.w);

View File

@ -7,6 +7,9 @@ dword CursorFile = FROM "../TWB/pointer.cur";
#define MAXLINKS 2000 #define MAXLINKS 2000
bool open_new_window=false;
bool open_new_tab=false;
struct array_link { struct array_link {
dword link; dword link;
unsigned int x,y,w,h; unsigned int x,y,w,h;
@ -54,7 +57,6 @@ dword LinksArray::GetURL(int id)
return links[id].link; return links[id].link;
} }
bool open_new_window=false;
void LinksArray::Clear() void LinksArray::Clear()
{ {
page_links.drop(); page_links.drop();
@ -95,9 +97,15 @@ bool LinksArray::HoverAndProceed(dword mx, my, list_y, list_first)
return false; return false;
} }
if (mouse.mkm) && (mouse.up) { if (mouse.mkm) && (mouse.up) {
open_new_window = true; if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
EventClickLink(PageLinks.GetURL(PageLinks.active)); open_new_window = true;
open_new_window = false; EventClickLink(PageLinks.GetURL(PageLinks.active));
open_new_window = false;
} else {
open_new_tab = true;
EventClickLink(PageLinks.GetURL(PageLinks.active));
open_new_tab = false;
}
return false; return false;
} }
if (mouse.lkm) && (mouse.up) { if (mouse.lkm) && (mouse.up) {

View File

@ -6,7 +6,7 @@
#endif #endif
//libraries //libraries
#define MEMSIZE 1024 * 850 #define MEMSIZE 1024 * 1000
#include "..\lib\gui.h" #include "..\lib\gui.h"
#include "..\lib\draw_buf.h" #include "..\lib\draw_buf.h"
#include "..\lib\list_box.h" #include "..\lib\list_box.h"
@ -29,24 +29,28 @@
#include "..\lib\patterns\simple_open_dialog.h" #include "..\lib\patterns\simple_open_dialog.h"
#include "..\lib\patterns\toolbar_button.h" #include "..\lib\patterns\toolbar_button.h"
#include "show_src.h"
#include "download_manager.h"
_history history;
#include "history.h"
bool debug_mode = false;
#include "..\TWB\TWB.c" //HTML Parser, a core component
#include "texts.h" #include "texts.h"
#include "cache.h" #include "cache.h"
#include "show_src.h"
#include "download_manager.h"
bool debug_mode = false;
#include "..\TWB\TWB.c" //HTML Parser, a core component
TWebBrowser WB1; TWebBrowser WB1;
_history history;
#define URL_SIZE 4000 #include "history.h"
#define PADDING 9 #define PADDING 9
#define SKIN_Y 24 #define SKIN_Y 24
#define TSZE 25 #define TSZE 25
#define STATUSBAR_H 15
#define TAB_H 20
dword TOOLBAR_H = PADDING+TSZE+PADDING+2; dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
dword STATUSBAR_H = 15;
#define URL_SIZE 4000
int action_buf; int action_buf;
@ -59,8 +63,9 @@ char stak[4096];
proc_info Form; proc_info Form;
enum { enum {
ENCODINGS=900, NEW_TAB=600,
BACK_BUTTON=1000, ENCODINGS=700,
BACK_BUTTON=800,
FORWARD_BUTTON, FORWARD_BUTTON,
REFRESH_BUTTON, REFRESH_BUTTON,
GOTOURL_BUTTON, GOTOURL_BUTTON,
@ -76,8 +81,12 @@ enum {
UPDATE_BROWSER, UPDATE_BROWSER,
COPY_LINK_URL, COPY_LINK_URL,
DOWNLOAD_LINK_CONTENTS, DOWNLOAD_LINK_CONTENTS,
TAB_ID,
TAB_CLOSE_ID = 900
}; };
#include "tabs.h"
char default_dir[] = "/rd/1"; char default_dir[] = "/rd/1";
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" }; od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
@ -165,18 +174,26 @@ void main()
case evKey: case evKey:
GetKeys(); GetKeys();
//if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;}
if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;}
}
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) { if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;} if (key_scancode == SCAN_CODE_KEY_O) EventOpenDialog();
if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;} else if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;} else if (key_scancode == SCAN_CODE_KEY_U) EventViewSource();
if (key_scancode == SCAN_CODE_KEY_T) else if (key_scancode == SCAN_CODE_KEY_T) EventOpenNewTab(URL_SERVICE_HOMEPAGE);
|| (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;} else if (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;} else if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;} else if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;} else if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
if (key_scancode == SCAN_CODE_LEFT) {ProcessEvent(BACK_BUTTON);break;} else if (key_scancode == SCAN_CODE_LEFT) ProcessEvent(BACK_BUTTON);
if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;} else if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;} else if (key_scancode == SCAN_CODE_KEY_W) EventCloseActiveTab();
else if (key_scancode == SCAN_CODE_TAB) EventActivateNextTab();
break;
} }
if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON); if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
@ -185,14 +202,11 @@ void main()
{ {
if (key_scancode == SCAN_CODE_ENTER) { if (key_scancode == SCAN_CODE_ENTER) {
ProcessEvent(key_scancode); ProcessEvent(key_scancode);
} } else {
else {
EAX = key_editbox; EAX = key_editbox;
edit_box_key stdcall(#address_box); edit_box_key stdcall(#address_box);
} }
} } else {
else
{
#define KEY_SCROLL_N 11 #define KEY_SCROLL_N 11
if (SCAN_CODE_UP == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp(); if (SCAN_CODE_UP == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown(); if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
@ -203,7 +217,7 @@ void main()
break; break;
case evReDraw: case evReDraw:
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), DefineAndDrawWindow(40, //GetScreenWidth()-800/2-random(80),
GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0); GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
system.color.get(); system.color.get();
@ -245,8 +259,8 @@ void main()
void SetElementSizes() void SetElementSizes()
{ {
address_box.width = Form.cwidth - address_box.left - 52 - 16; address_box.width = Form.cwidth - address_box.left - 52 - 16;
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H); Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
WB1.list.wheel_size = 7 * BASIC_LINE_H; WB1.list.wheel_size = 7 * BASIC_LINE_H;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
WB1.list.visible = WB1.list.h; WB1.list.visible = WB1.list.h;
@ -265,7 +279,7 @@ void draw_window()
DrawBar(0,0, Form.cwidth,PADDING, system.color.work); DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work); DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark); DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180));
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph); DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work); DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work); DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
@ -280,23 +294,33 @@ void draw_window()
DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
WB1.list.h-1, scroll_wv.bckg_col); WB1.list.h-1, scroll_wv.bckg_col);
if (WB1.list.w!=WB1.DrawBuf.bufw) { if (!BrowserWidthChanged()) {
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
if (!strncmp(history.current(),"http",4)) {
//nihuya ne izyashnoe reshenie, no pust' poka butet tak
i=source_mode;
LoadInternalPage(#loading_text, sizeof(loading_text));
source_mode=i;
}
OpenPage(history.current());
} else {
WB1.DrawPage(); WB1.DrawPage();
DrawOmnibox(); DrawOmnibox();
} }
DrawProgress(); DrawProgress();
DrawStatusBar(NULL); DrawStatusBar(NULL);
DrawTabsBar();
} }
bool BrowserWidthChanged()
{
dword source_mode_holder;
if (WB1.list.w!=DrawBuf.bufw) {
DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
if (!strncmp(history.current(),"http",4)) {
//nihuya ne izyashnoe reshenie, no pust' poka butet tak
source_mode_holder = source_mode;
LoadInternalPage(#loading_text, sizeof(loading_text));
source_mode = source_mode_holder;
}
OpenPage(history.current());
return true;
}
return false;
}
void EventChangeEncodingAndLoadPage(int _new_encoding) void EventChangeEncodingAndLoadPage(int _new_encoding)
{ {
dword newbuf, newsize; dword newbuf, newsize;
@ -335,7 +359,7 @@ void ProcessEvent(dword id__)
EventSubmitOmnibox(); EventSubmitOmnibox();
return; return;
case REFRESH_BUTTON: case REFRESH_BUTTON:
if (http.transfer > 0) { if (http.transfer) {
StopLoading(); StopLoading();
draw_window(); draw_window();
} else { } else {
@ -393,6 +417,21 @@ void ProcessEvent(dword id__)
if (debug_mode) notify("'Debug mode ON'-I"); if (debug_mode) notify("'Debug mode ON'-I");
else notify("'Debug mode OFF'-I"); else notify("'Debug mode OFF'-I");
return; return;
case NEW_TAB:
if (http.transfer) break;
EventOpenNewTab(URL_SERVICE_HOMEPAGE);
return;
case TAB_ID...TAB_ID+TABS_MAX:
if (http.transfer) break;
if (mouse.mkm) {
EventTabClose(id__ - TAB_ID);
} else {
EventTabClick(id__ - TAB_ID);
}
return;
case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX:
EventTabClose(id__ - TAB_CLOSE_ID);
return;
} }
} }
@ -456,9 +495,13 @@ void OpenPage(dword _open_URL)
StopLoading(); StopLoading();
strcpy(#editURL, _open_URL); if (open_new_tab) {
address_box.flags=0; open_new_tab = false;
DrawOmnibox(); EventOpenNewTab(_open_URL);
return;
}
SetOmniboxText(_open_URL);
strncpy(#new_url, _open_URL, URL_SIZE); strncpy(#new_url, _open_URL, URL_SIZE);
@ -535,7 +578,7 @@ void EventClickLink(dword _click_URL)
return; return;
} }
if (http.transfer > 0) { if (http.transfer) {
StopLoading(); StopLoading();
history.back(); history.back();
} }
@ -607,6 +650,7 @@ void LoadInternalPage(dword _bufdata, _in_bufsize){
} }
WB1.ParseHtml(_bufdata, _in_bufsize); WB1.ParseHtml(_bufdata, _in_bufsize);
DrawStatusBar(NULL); DrawStatusBar(NULL);
DrawActiveTab();
if (source_mode) { if (source_mode) {
source_mode = false; source_mode = false;
ShowSource(WB1.bufpointer, _in_bufsize); ShowSource(WB1.bufpointer, _in_bufsize);
@ -689,9 +733,11 @@ void EventOpenDialog()
void EventViewSource() void EventViewSource()
{ {
char source_view_param[URL_SIZE+1]; char source_view_param[URL_SIZE+1];
strcpy(#source_view_param, "-source "); //strcpy(#source_view_param, "-source ");
strncat(#source_view_param, history.current(), URL_SIZE); //strncat(#source_view_param, history.current(), URL_SIZE);
RunProgram(#program_path, #source_view_param); //RunProgram(#program_path, #source_view_param);
source_mode = true;
EventOpenNewTab(history.current());
} }
dword GetFileSize(dword _path) dword GetFileSize(dword _path)
@ -781,5 +827,12 @@ void DrawOmnibox()
DrawProgress(); DrawProgress();
} }
void SetOmniboxText(dword _text)
{
strcpy(#editURL, _text);
address_box.flags=0;
DrawOmnibox();
}
stop: stop:

209
programs/cmm/browser/tabs.h Normal file
View File

@ -0,0 +1,209 @@
//===================================================//
// //
// MODULE //
// //
//===================================================//
#define TABS_MAX 5
TWebBrowser data[TABS_MAX+1];
_history tabstory[TABS_MAX+1];
struct TAB
{
int count;
signed int active;
bool add();
bool close();
void save_state();
void restore();
} tab = {1,0};
bool TAB::add()
{
if (count==TABS_MAX) return false;
save_state();
count++;
active = count-1;
history = tabstory[active];
return true;
}
bool TAB::close(int _tab_number)
{
int i;
if (count==1) return false;
for (i=_tab_number; i<=TABS_MAX; i++) {
data[i] = data[i+1];
tabstory[i] = tabstory[i+1];
}
if (_tab_number<active) && (active>0) active--;
if (active==count-1) && (active>0) active--;
count--;
return true;
}
void TAB::save_state()
{
tabstory[active] = history;
data[active] = WB1;
}
void TAB::restore(int _id)
{
tab.active = _id;
WB1 = data[_id];
history = tabstory[_id];
}
//===================================================//
// //
// WebView Actions //
// //
//===================================================//
#define DEFAULT_TABW 220
int tab_w = DEFAULT_TABW;
int GetTabWidth()
{
if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else
return Form.cwidth - TAB_H - 2 / tab.count;
}
void DrawTab(int _id)
{
#define CLOSE_S 13
dword bgcol, border_bottom_color;
char header_no_version[sizeof(TWebBrowser.header)];
char name[DEFAULT_TABW/6];
int xxx = _id * tab_w;
if (_id==tab.active) {
tab.save_state();
bgcol = system.color.work_light;
border_bottom_color = system.color.work_light;
} else {
bgcol=system.color.work;
border_bottom_color = system.color.work_graph;
}
if (data[_id].header) {
strncpy(#header_no_version, #data[_id].header, strlen(#data[_id].header)-sizeof(version)-2);
strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
}
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_dark);
DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, system.color.work_text, #name);
DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, system.color.work_dark);
WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, system.color.work_light, "x");
}
void DrawActiveTab()
{
if (tab_w == GetTabWidth()) DrawTab(tab.active);
else DrawTabsBar();
}
void DrawNewTabButton()
{
dword btn_light = MixColors(system.color.work_button, 0xFFFfff, 220);
dword btn_dark = MixColors(system.color.work_button, 0, 180);
int xxx = tab.count * tab_w;
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, system.color.work_graph);
DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, system.color.work_button);
DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+");
}
void DrawTabsBar()
{
dword i;
tab_w = GetTabWidth();
for (i=0; i<tab.count; i++) DrawTab(i);
DrawNewTabButton();
i = tab_w * i + TAB_H + 2;
DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(system.color.work_dark, system.color.work, 128));
DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, system.color.work_graph);
}
void EventTabClose(int _id)
{
DeleteButton(tab.count);
if (_id == tab.active) {
tab.close(_id);
tab.restore(tab.active);
WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
WB1.DrawPage();
SetOmniboxText(history.current());
} else {
tab.close(_id);
}
DrawTabsBar();
}
void EventCloseActiveTab()
{
EventTabClose(tab.active);
}
void EventTabClick(int _id)
{
if (_id>=tab.count) _id = 0;
if (_id==-1) _id = tab.count-1;
tab.save_state();
tab.restore(_id);
SetElementSizes();
if (!BrowserWidthChanged()) {
DrawTabsBar();
WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
WB1.DrawPage();
}
SetOmniboxText(history.current());
}
void EventOpenNewTab(dword _url)
{
tab.add();
OpenPage(_url);
DrawTabsBar();
}
void EventActivateNextTab()
{
EventTabClick(tab.active+1);
}
void EventActivatePreviousTab()
{
EventTabClick(tab.active-1);
}
:void DebugTabs()
{
debugln("\n\n\nHISTORY==========================");
history.add("history");
history.debug();
debugln("\n\n\nTABSTORY[0]======================");
tabstory[0].add("tabstory0");
tabstory[0].debug();
debugln("\n\n\nTABSTORY[1]======================");
tabstory[1].add("tabstory1");
tabstory[1].debug();
debugln("\n\n\n\n");
debugval("history.items.data_start", history.items.data_start);
debugval("tabstory[0].items.data_start", tabstory[0].items.data_start);
debugval("tabstory[1].items.data_start", tabstory[1].items.data_start);
debugln("\n\n\n\n");
}

View File

@ -1,4 +1,4 @@
char version[]="WebView 2.26"; char version[]="WebView 2.4";
#ifdef LANG_RUS #ifdef LANG_RUS
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0"; char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";

View File

@ -158,8 +158,8 @@ void SetElementSizes()
WB1.list.wheel_size = 7 * BASIC_LINE_H; WB1.list.wheel_size = 7 * BASIC_LINE_H;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
WB1.list.visible = WB1.list.h; WB1.list.visible = WB1.list.h;
if (WB1.list.w!=WB1.DrawBuf.bufw) { if (WB1.list.w!=DrawBuf.bufw) {
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700); DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
OpenPage(#current_path); OpenPage(#current_path);
} }
} }

View File

@ -20,7 +20,6 @@
?define T_TAKE_SCREENSHOT " ‘¤¥« âì áªà¨­è®â" ?define T_TAKE_SCREENSHOT " ‘¤¥« âì áªà¨­è®â"
?define T_SETTINGS "<EFBFBD> áâனª¨" ?define T_SETTINGS "<EFBFBD> áâனª¨"
?define T_EDITBOX_FRAME " <20>ãâì á®åà ­¥­¨ï áªà¨­è®â  " ?define T_EDITBOX_FRAME " <20>ãâì á®åà ­¥­¨ï áªà¨­è®â  "
?define T_MINIMIZE "‘¢¥à­ãâì ®ª­® ¯à¨ á­¨¬ª¥"
?define T_CONTINUOUS_SHOOTING "Continuous shooting" ?define T_CONTINUOUS_SHOOTING "Continuous shooting"
?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å" ?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
?define T_NO_DIR "'<27> ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E" ?define T_NO_DIR "'<27> ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
@ -29,7 +28,6 @@
?define T_TAKE_SCREENSHOT " Take a screenshot" ?define T_TAKE_SCREENSHOT " Take a screenshot"
?define T_SETTINGS "Settings" ?define T_SETTINGS "Settings"
?define T_EDITBOX_FRAME " Save path " ?define T_EDITBOX_FRAME " Save path "
?define T_MINIMIZE "Minimize window"
?define T_CONTINUOUS_SHOOTING "Continuous shooting" ?define T_CONTINUOUS_SHOOTING "Continuous shooting"
?define T_DELAY "Delay in seconds" ?define T_DELAY "Delay in seconds"
?define T_NO_DIR "'Directory does not exists!' -E" ?define T_NO_DIR "'Directory does not exists!' -E"
@ -59,7 +57,6 @@ edit_box edit_save = {250,25,100,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(save_path)-2,#save_path,0, 0b}; 0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
more_less_box delay = { 1, 0, 64, T_DELAY }; more_less_box delay = { 1, 0, 64, T_DELAY };
checkbox minimize = { T_MINIMIZE, true };
checkbox continuous_shooting = { T_CONTINUOUS_SHOOTING, true }; checkbox continuous_shooting = { T_CONTINUOUS_SHOOTING, true };
@ -136,11 +133,10 @@ void DrawMainContent()
} }
void EventTakeScreenshot() { void EventTakeScreenshot() {
if (minimize.checked) MinimizeWindow(); MinimizeWindow();
pause(delay.value*100); pause(delay.value*100);
CopyScreen(screenshot, 0, 0, screen.width, screen.height); CopyScreen(screenshot, 0, 0, screen.width, screen.height);
ActivateWindow(GetProcessSlot(Form.ID)); ActivateWindow(GetProcessSlot(Form.ID));
if (!minimize.checked) DrawMainContent();
EventSaveImageFile(); EventSaveImageFile();
} }
@ -150,7 +146,11 @@ void EventSaveImageFile()
char save_file_name[4096]; char save_file_name[4096];
do { do {
i++; i++;
sprintf(#save_file_name, "%s/screen_%i.png", #save_path_stable, i); //sprintf(, "%s/screen_%i.png", #save_path_stable, i);
strcpy(#save_file_name, #save_path_stable);
strcat(#save_file_name, "/screen_");
strcat(#save_file_name, itoa(i));
strcat(#save_file_name, ".png");
} while (file_exists(#save_file_name)); } while (file_exists(#save_file_name));
save_image(screenshot, screen.width, screen.height, #save_file_name); save_image(screenshot, screen.width, screen.height, #save_file_name);
} }
@ -171,7 +171,7 @@ void SettingsWindow()
case evKey: case evKey:
GetKeys(); GetKeys();
if (SCAN_CODE_ESC == key_scancode) ExitProcess(); if (SCAN_CODE_ESC == key_scancode) ExitProcess();
EAX= key_ascii << 8; EAX = key_editbox;
edit_box_key stdcall (#edit_save); edit_box_key stdcall (#edit_save);
break; break;
@ -197,7 +197,6 @@ void SettingsWindow()
} }
delay.click(id); delay.click(id);
minimize.click(id);
break; break;
case evReDraw: case evReDraw:
@ -209,8 +208,7 @@ void DrawSettingsWindow()
{ {
DefineAndDrawWindow(Form.left+100, Form.top-40, 400, 230, 0x34, system.color.work, T_SETTINGS, 0); DefineAndDrawWindow(Form.left+100, Form.top-40, 400, 230, 0x34, system.color.work, T_SETTINGS, 0);
GetProcessInfo(#Settings, SelfInfo); GetProcessInfo(#Settings, SelfInfo);
minimize.draw(15, 15); delay.draw(15, 30);
delay.draw(15, 45);
DrawFrame(15, 85, 360, 95, T_EDITBOX_FRAME); DrawFrame(15, 85, 360, 95, T_EDITBOX_FRAME);
DrawEditBoxPos(32, 110, #edit_save); DrawEditBoxPos(32, 110, #edit_save);
DrawStandartCaptButton(edit_save.left + edit_save.width + 15, edit_save.top-3, BTN_OD, "..."); DrawStandartCaptButton(edit_save.left + edit_save.width + 15, edit_save.top-3, BTN_OD, "...");

View File

@ -67,7 +67,10 @@ struct collection
:void collection::drop() { :void collection::drop() {
if (data_start) free(data_start); if (data_start) free(data_start);
data_size = data_start = element_offset[count] = count = 0; data_size = 0;
data_start = 0;
element_offset[count] = 0;
count = 0;
} }

View File

@ -51,4 +51,12 @@ inline fastcall void debugln( EDX)
debugln(#tmpch); debugln(#tmpch);
} }
:void debug_n(dword _text, _size)
{
dword res_text = malloc(_size);
strncpy(res_text, _text, _size-1);
debugln(res_text);
free(res_text);
}
#endif #endif

View File

@ -128,12 +128,26 @@ GETKEYII:
key_ascii = AH; key_ascii = AH;
$shr eax,16 $shr eax,16
key_scancode = AL; key_scancode = AL;
//get alt/shift/ctrl key status key_modifier = GetKeyModifier();
EAX = key_editbox;
}
// ECX is a mode: 1 - scancodes, 0 - ascii
inline fastcall SetKeyboardMode(ECX)
{
$mov eax,66
$mov ebx,1
//$mov ecx,?
$int 0x40
}
//get alt/shift/ctrl key status
inline fastcall dword GetKeyModifier()
{
$mov eax,66 $mov eax,66
$mov ebx,3 $mov ebx,3
$int 0x40 $int 0x40
key_modifier = EAX; key_modifier = EAX;
EAX = key_editbox;
} }
#endif #endif

View File

@ -3,6 +3,7 @@
struct _history { struct _history {
collection items; collection items;
int active; int active;
void clear();
int add(); int add();
int back(); int back();
int forward(); int forward();
@ -35,4 +36,10 @@ int _history::forward()
dword _history::current() dword _history::current()
{ {
return items.get(active-1); return items.get(active-1);
} }
:void _history::clear()
{
items.drop();
active=0;
}

View File

@ -356,7 +356,7 @@ void InitTWB() {
Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 12); Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 12);
WB1.list.column_max = WB1.list.w - 30 / 6; WB1.list.column_max = WB1.list.w - 30 / 6;
WB1.list.visible = WB1.list.h / WB1.list.item_h; WB1.list.visible = WB1.list.h / WB1.list.item_h;
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h); DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h);
WB1.list.first = WB1.list.count = 0; WB1.list.first = WB1.list.count = 0;
} }

View File

@ -1,4 +1,4 @@
#define MEMSIZE 1024*40 #define MEMSIZE 1024*20
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/clipboard.h" #include "../lib/clipboard.h"
@ -10,7 +10,6 @@
// // // //
//===================================================// //===================================================//
proc_info Form;
dword pick_active = true; dword pick_active = true;
dword picked_color = 0; dword picked_color = 0;
char picked_color_string[11]; char picked_color_string[11];
@ -32,19 +31,16 @@ char picked_color_string[11];
void main() void main()
{ {
int btn; int btn;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); proc_info Form;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP); SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
loop() switch(WaitEvent()) loop() switch(WaitEvent())
{ {
case evMouse: case evMouse:
mouse.get(); mouse.get();
if (mouse.x>0) && (mouse.x<FORM_W) && (mouse.y>0) && (mouse.y<FORM_H) {
if (mouse.x>0) && (mouse.x<FORM_W) && (mouse.y>0) && (mouse.y<FORM_H)
{
EventDragWindow(); EventDragWindow();
} } else if (pick_active) {
else if (pick_active)
{
picked_color = GetPixelColorFromScreen(mouse.x + Form.left, mouse.y + Form.top); picked_color = GetPixelColorFromScreen(mouse.x + Form.left, mouse.y + Form.top);
EventUpdateWindowContent(); EventUpdateWindowContent();
if (mouse.down) && (mouse.key&MOUSE_LEFT) pick_active = false; if (mouse.down) && (mouse.key&MOUSE_LEFT) pick_active = false;
@ -61,11 +57,12 @@ void main()
case evKey: case evKey:
GetKeys(); GetKeys();
if (key_scancode == SCAN_CODE_ESC) ExitProcess(); if (key_scancode == SCAN_CODE_ESC) ExitProcess();
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) if (key_scancode == SCAN_CODE_KEY_C) EventCopyHex();
if (key_scancode==SCAN_CODE_KEY_C) EventCopyHex();
break; break;
case evReDraw: case evReDraw:
DefineUnDragableWindow(215, 100, FORM_W, FORM_H);
GetProcessInfo(#Form, SelfInfo);
draw_window(); draw_window();
break; break;
} }
@ -73,18 +70,14 @@ void main()
void draw_window() void draw_window()
{ {
DefineDragableWindow(215, 100, FORM_W, FORM_H);
GetProcessInfo(#Form, SelfInfo);
DrawRectangle3D(0, 0, FORM_W, FORM_H, 0xCCCccc, 0x888888); DrawRectangle3D(0, 0, FORM_W, FORM_H, 0xCCCccc, 0x888888);
DrawRectangle3D(1, 1, FORM_W-2, FORM_H-2, 0xCCCccc, 0x888888); DrawRectangle3D(1, 1, FORM_W-2, FORM_H-2, 0xCCCccc, 0x888888);
DrawBar(2,2,FORM_W-3,FORM_H-3,0xFFFfff); DrawBar(2,2,FORM_W-3,FORM_H-3,0xFFFfff);
DrawRectangle(COLOR_BLOCK_X-2, COLOR_BLOCK_PADDING-2, COLOR_BLOCK_SIZE+3, COLOR_BLOCK_SIZE+3, 0xCBC6C5); DrawRectangle(COLOR_BLOCK_X-2, COLOR_BLOCK_PADDING-2, COLOR_BLOCK_SIZE+3, COLOR_BLOCK_SIZE+3, 0xCBC6C5);
DefineHiddenButton(0, 0, COLOR_BLOCK_X, skin_height, 476+BT_NOFRAME);
DefineHiddenButton(COLOR_BLOCK_X-1, COLOR_BLOCK_PADDING-1, COLOR_BLOCK_SIZE+1, COLOR_BLOCK_SIZE+1, BUTTON_ID_PICK); DefineHiddenButton(COLOR_BLOCK_X-1, COLOR_BLOCK_PADDING-1, COLOR_BLOCK_SIZE+1, COLOR_BLOCK_SIZE+1, BUTTON_ID_PICK);
DrawCopyButton(67, 11, 35, 14, 0x777777); DrawCopyButton(67, 11, 35, 14);
EventUpdateWindowContent(); EventUpdateWindowContent();
} }
@ -114,17 +107,17 @@ void EventUpdateWindowContent()
WriteTextWithBg(12,12, 0xD0, 0x000111, #picked_color_string+4, 0xFFFfff); WriteTextWithBg(12,12, 0xD0, 0x000111, #picked_color_string+4, 0xFFFfff);
WriteNumber(12,33, 0xD0, 0xff0000, 3, rgb.r); WriteNumber(12,33, 0xD0, 0xff0000, 3, rgb.r);
WriteNumber(43,33, 0xD0, 0x008000, 3, rgb.g); WriteNumber(44,33, 0xD0, 0x008000, 3, rgb.g);
WriteNumber(73,33, 0xD0, 0x0000ff, 3, rgb.b); WriteNumber(75,33, 0xD0, 0x0000ff, 3, rgb.b);
DrawBar(COLOR_BLOCK_X, COLOR_BLOCK_PADDING, COLOR_BLOCK_SIZE, COLOR_BLOCK_SIZE, picked_color); DrawBar(COLOR_BLOCK_X, COLOR_BLOCK_PADDING, COLOR_BLOCK_SIZE, COLOR_BLOCK_SIZE, picked_color);
} }
void DrawCopyButton(dword _x, _y, _w, _h, _color) void DrawCopyButton(dword _x, _y, _w, _h)
{ {
DefineHiddenButton(_x+1, _y+1, _w-2, _h-2, BUTTON_ID_COPY); DefineHiddenButton(_x+1, _y+1, _w-2, _h-2, BUTTON_ID_COPY);
DrawRectangle(_x, _y, _w, _h, _color); DrawRectangle(_x, _y, _w, _h, 0x777777);
WriteTextCenter(_x, _h-8/2 + _y, _w, _color, "Copy"); WriteText(_x+6, _h-8/2 + _y, 0x80, 0x555555, "Copy");
} }
void EventCopyHex() void EventCopyHex()

View File

@ -5,7 +5,7 @@ enum {
#define DRAW_PADDING 12 #define DRAW_PADDING 12
void Parcer(byte mode) void Parse(byte mode)
{ {
dword bufoff, buflen; dword bufoff, buflen;
byte ch; byte ch;
@ -51,14 +51,14 @@ void PreparePage()
{ {
list.w = Form.cwidth-scroll.size_x-1; list.w = Form.cwidth-scroll.size_x-1;
list.count=0; list.count=0;
Parcer(COUNT_BUF_HEIGHT); Parse(COUNT_BUF_HEIGHT);
//draw text in buffer //draw text in buffer
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, kfont.size.pt+6); list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, kfont.size.pt+6);
if (list.count < list.visible) list.count = list.visible; if (list.count < list.visible) list.count = list.visible;
kfont.size.height = list.count+1*list.item_h; kfont.size.height = list.count+1*list.item_h;
kfont.raw_size = 0; kfont.raw_size = 0;
Parcer(DRAW_BUF); Parse(DRAW_BUF);
if (list.count > list.visible * 10) DrawPage(); if (list.count > list.visible * 10) DrawPage();
//draw result //draw result