2020-04-10 18:19:52 +02:00
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// MODULE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
#define TABS_MAX 5
|
|
|
|
|
2020-12-28 20:20:59 +01:00
|
|
|
TWebBrowser tabdata[TABS_MAX+1]=0;
|
2020-05-23 13:26:58 +02:00
|
|
|
_history tabstory[TABS_MAX+1]=0;
|
2020-04-10 18:19:52 +02:00
|
|
|
|
|
|
|
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;
|
2020-04-14 19:38:31 +02:00
|
|
|
for (i=_tab_number; i<TABS_MAX; i++) {
|
2020-12-28 20:20:59 +01:00
|
|
|
tabdata[i] = tabdata[i+1];
|
2020-04-10 18:19:52 +02:00
|
|
|
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;
|
2020-12-28 20:20:59 +01:00
|
|
|
tabdata[active] = WB1;
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TAB::restore(int _id)
|
|
|
|
{
|
|
|
|
tab.active = _id;
|
2020-12-28 20:20:59 +01:00
|
|
|
WB1 = tabdata[_id];
|
2020-04-10 18:19:52 +02:00
|
|
|
history = tabstory[_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// WebView Actions //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
|
|
|
#define DEFAULT_TABW 220
|
|
|
|
int tab_w = DEFAULT_TABW;
|
|
|
|
|
|
|
|
int GetTabWidth()
|
|
|
|
{
|
2020-04-11 17:49:11 +02:00
|
|
|
if (tab.count == TABS_MAX) return Form.cwidth / tab.count;
|
2020-04-10 18:19:52 +02:00
|
|
|
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();
|
2022-01-09 07:36:16 +01:00
|
|
|
bgcol = sc.light;
|
|
|
|
border_bottom_color = sc.light;
|
2020-04-10 18:19:52 +02:00
|
|
|
} else {
|
2020-04-18 01:52:24 +02:00
|
|
|
bgcol=sc.work;
|
2022-01-09 07:36:16 +01:00
|
|
|
border_bottom_color = sc.line;
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
2020-12-28 20:20:59 +01:00
|
|
|
if (tabdata[_id].header) {
|
|
|
|
strncpy(#header_no_version, #tabdata[_id].header, strlen(#tabdata[_id].header)-sizeof(version)-2);
|
2020-04-10 18:19:52 +02:00
|
|
|
strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
|
|
|
|
}
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.dark);
|
2020-04-10 18:19:52 +02:00
|
|
|
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);
|
2020-04-18 01:52:24 +02:00
|
|
|
WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, sc.work_text, #name);
|
2020-04-10 18:19:52 +02:00
|
|
|
|
|
|
|
DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, sc.dark);
|
|
|
|
WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, sc.light, "x");
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawActiveTab()
|
|
|
|
{
|
|
|
|
if (tab_w == GetTabWidth()) DrawTab(tab.active);
|
|
|
|
else DrawTabsBar();
|
|
|
|
}
|
|
|
|
|
2020-04-11 23:17:55 +02:00
|
|
|
int DrawNewTabButton()
|
2020-04-10 18:19:52 +02:00
|
|
|
{
|
2020-04-18 01:52:24 +02:00
|
|
|
dword btn_light = MixColors(sc.button, 0xFFFfff, 220);
|
|
|
|
dword btn_dark = MixColors(sc.button, 0, 180);
|
2020-04-10 18:19:52 +02:00
|
|
|
int xxx = tab.count * tab_w;
|
2020-04-11 17:49:11 +02:00
|
|
|
|
|
|
|
if (tab.count < TABS_MAX) {
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.line);
|
2020-04-18 01:52:24 +02:00
|
|
|
DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, sc.button);
|
2020-04-11 17:49:11 +02:00
|
|
|
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);
|
2020-04-18 01:52:24 +02:00
|
|
|
WriteText(xxx+7, TOOLBAR_H+2, 0x90, sc.button_text, "+");
|
2020-04-11 23:17:55 +02:00
|
|
|
return xxx + TAB_H + 2;
|
|
|
|
} else {
|
|
|
|
return xxx;
|
2020-04-11 17:49:11 +02:00
|
|
|
}
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawTabsBar()
|
|
|
|
{
|
|
|
|
dword i;
|
|
|
|
tab_w = GetTabWidth();
|
2020-04-16 08:39:58 +02:00
|
|
|
for (i=0; i<tab.count; i++) DrawTab(i);
|
2020-04-11 23:17:55 +02:00
|
|
|
i = DrawNewTabButton();
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(sc.dark, sc.work, 128));
|
|
|
|
DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, sc.line);
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventTabClose(int _id)
|
|
|
|
{
|
2020-04-16 08:39:58 +02:00
|
|
|
DeleteButton(TAB_ID + tab.count-1);
|
2020-04-10 18:19:52 +02:00
|
|
|
if (_id == tab.active) {
|
|
|
|
tab.close(_id);
|
|
|
|
tab.restore(tab.active);
|
2020-12-20 14:28:50 +01:00
|
|
|
SetElementSizes();
|
2021-01-02 13:45:42 +01:00
|
|
|
WB1.Reparse();
|
2020-04-10 18:19:52 +02:00
|
|
|
WB1.DrawPage();
|
|
|
|
SetOmniboxText(history.current());
|
|
|
|
} else {
|
|
|
|
tab.close(_id);
|
|
|
|
}
|
|
|
|
DrawTabsBar();
|
2020-12-29 11:31:45 +01:00
|
|
|
DrawStatusBar(NULL);
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-12-20 14:28:50 +01:00
|
|
|
DrawTabsBar();
|
|
|
|
SetElementSizes();
|
2021-01-02 13:45:42 +01:00
|
|
|
WB1.Reparse();
|
2020-12-20 14:28:50 +01:00
|
|
|
WB1.DrawPage();
|
2020-04-10 18:19:52 +02:00
|
|
|
SetOmniboxText(history.current());
|
2020-12-29 11:31:45 +01:00
|
|
|
DrawStatusBar(NULL);
|
2020-04-10 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventOpenNewTab(dword _url)
|
|
|
|
{
|
|
|
|
tab.add();
|
|
|
|
OpenPage(_url);
|
|
|
|
DrawTabsBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventActivateNextTab()
|
|
|
|
{
|
|
|
|
EventTabClick(tab.active+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventActivatePreviousTab()
|
|
|
|
{
|
|
|
|
EventTabClick(tab.active-1);
|
|
|
|
}
|
|
|
|
|