Aelia: add status bar, code update

git-svn-id: svn://kolibrios.org@7293 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-05-24 18:47:42 +00:00
parent 58d62b7c76
commit 5220da9d33
7 changed files with 166 additions and 77 deletions

View File

@ -19,6 +19,12 @@
#include "../lib/patterns/http_downloader.h" #include "../lib/patterns/http_downloader.h"
#include "../browser/download_manager.h" #include "../browser/download_manager.h"
llist list;
#include "link.h"
#include "canvas.h"
#include "favicon.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" };
@ -27,6 +33,7 @@ char accept_language[]= "Accept-Language: ru\n";
#define TOOLBAR_H 36 #define TOOLBAR_H 36
#define TOOLBAR_ICON_WIDTH 26 #define TOOLBAR_ICON_WIDTH 26
#define TOOLBAR_ICON_HEIGHT 24 #define TOOLBAR_ICON_HEIGHT 24
#define STATUSBAR_H 15
#define DEFAULT_EDITOR "/sys/tinypad" #define DEFAULT_EDITOR "/sys/tinypad"
#define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt" #define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt"
@ -39,7 +46,6 @@ char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
#define UML 4096*2 #define UML 4096*2
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
llist list;
proc_info Form; proc_info Form;
char title[4196]; char title[4196];
@ -55,14 +61,13 @@ enum {
SANDWICH SANDWICH
}; };
char address[UML]="http://"; char address[UML];
edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,NULL,2,19,19}; edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,NULL,2,19,19};
#include "favicon.h" bool debug_mode=false;
#include "ini.h" #include "ini.h"
#include "gui.h" #include "gui.h"
#include "link.h"
#include "canvas.h"
#include "prepare_page.h" #include "prepare_page.h"
//#include "special.h" //#include "special.h"
@ -88,7 +93,7 @@ void main()
kfont.init(DEFAULT_FONT); kfont.init(DEFAULT_FONT);
Libimg_LoadImage(#skin, abspath("toolbar.png")); Libimg_LoadImage(#skin, abspath("toolbar.png"));
list.no_selection = true; list.no_selection = true;
SetEventMask(10000000000000000000000001100111b); SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
loop() loop()
{ {
switch(WaitEvent()) switch(WaitEvent())
@ -102,6 +107,9 @@ void main()
case evButton: case evButton:
HandleButtonEvent(); HandleButtonEvent();
break; break;
case evNetwork:
HandleNetworkEvent();
break;
case evReDraw: case evReDraw:
draw_window(); draw_window();
if (menu.list.cur_y>=10) && (menu.list.cur_y<20) { if (menu.list.cur_y>=10) && (menu.list.cur_y<20) {
@ -163,11 +171,37 @@ void HandleButtonEvent()
void HandleKeyEvent() void HandleKeyEvent()
{ {
GetKeys(); GetKeys();
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
switch (key_scancode) switch (key_scancode)
{ {
case 059: case SCAN_CODE_UP:
EventMagnifyPlus();
return;
case SCAN_CODE_DOWN:
EventMagnifyMinus();
return;
case SCAN_CODE_KEY_O:
EventOpenDialog();
return;
case SCAN_CODE_KEY_E:
EventRunEdit();
return;
case SCAN_CODE_KEY_H:
EventShowHistory();
return;
case SCAN_CODE_TAB:
EventChangeEncoding();
return;
}
}
switch (key_scancode)
{
case SCAN_CODE_F1:
EventShowInfo(); EventShowInfo();
return; return;
case SCAN_CODE_F12:
EventChangeDebugMode();
return;
case SCAN_CODE_ENTER: case SCAN_CODE_ENTER:
EventOpenAddress(#address); EventOpenAddress(#address);
return; return;
@ -177,34 +211,11 @@ void HandleKeyEvent()
return; return;
} }
} }
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { if (list.ProcessKey(key_scancode)) && (! address_box.flags & 0b10) {
switch (key_scancode)
{
case 024: //O
EventOpenDialog();
break;
case SCAN_CODE_UP:
EventMagnifyPlus();
break;
case SCAN_CODE_DOWN:
EventMagnifyMinus();
break;
case 018: //E
EventRunEdit();
break;
case 035: //H
EventShowHistory();
break;
case SCAN_CODE_TAB:
EventChangeEncoding();
break;
}
}
if (list.ProcessKey(key_scancode)) {
DrawPage(); DrawPage();
return; return;
} }
if (key_ascii != 0x0d) if (key_ascii != ASCII_KEY_ENTER)
&& (key_ascii != ASCII_KEY_PGDN) && (key_ascii != ASCII_KEY_PGDN)
&& (key_ascii != ASCII_KEY_PGUP) { && (key_ascii != ASCII_KEY_PGUP) {
EAX = key_editbox; EAX = key_editbox;
@ -218,19 +229,25 @@ void HandleMouseEvent()
edit_box_mouse stdcall (#address_box); edit_box_mouse stdcall (#address_box);
mouse.get(); mouse.get();
list.wheel_size = 7; list.wheel_size = 7;
if (link.hover()) {
if (link.active == -1) { if (link.hover(mouse.x, mouse.y)) {
debugln("unhovered"); if (-1 == link.active) {
DrawStatusBar( " " ); //just clean status bar
} }
else { else {
debugln(link.text.get(link.active)); DrawStatusBar( link.get_active_url() );
debugln(link.url.get(link.active));
} }
} }
if (mouse.key&MOUSE_LEFT) && (mouse.up) {
if (-1 != link.active) EventOpenAddress( link.get_active_url() );
}
if (list.MouseScroll(mouse.vert)) { if (list.MouseScroll(mouse.vert)) {
DrawPage(); DrawPage();
return; return;
} }
scrollbar_v_mouse (#scroll); scrollbar_v_mouse (#scroll);
if (list.first != scroll.position) { if (list.first != scroll.position) {
list.first = scroll.position; list.first = scroll.position;
@ -238,6 +255,39 @@ void HandleMouseEvent()
} }
} }
void HandleNetworkEvent()
{
char favicon_address[UML];
if (downloader.state == STATE_IN_PROGRESS) {
downloader.MonitorProgress();
if (downloader.httpd.content_length>0)
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*
downloader.httpd.content_received/downloader.httpd.content_length);
else
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
}
if (downloader.state == STATE_COMPLETED)
{
if (!strncmp(downloader.url,"http://gate.aspero.pro/",22)) {
strcpy(#address,downloader.url + 29);
}
else {
strcpy(#address,downloader.url);
}
downloader.Stop();
DrawAddressBox();
io.buffer_data = downloader.bufpointer;
/*
get_absolute_url(#favicon_address, #address, "/favicon.ico");
favicon.get(#favicon_address);
*/
PostOpenPageActions();
}
}
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -250,7 +300,7 @@ void EventOpenDialog()
void EventOpenAddress(dword _new_address) void EventOpenAddress(dword _new_address)
{ {
char temp[UML]; char temp[UML];
char favicon_address[UML]; char getUrl[UML];
if (!ESBYTE[_new_address]) return; if (!ESBYTE[_new_address]) return;
debugln("===================================="); debugln("====================================");
debug("address: "); debug("address: ");
@ -277,41 +327,36 @@ char favicon_address[UML];
if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home; if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about; if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory(); if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
PostOpenPageActions();
} }
// - local file // - local file
else if (check_is_the_adress_local(#address)==true) { else if (check_is_the_adress_local(#address)==true) {
debugln("this is local address"); debugln("this is local address");
io.read(#address); io.read(#address);
PostOpenPageActions();
} }
// - url // - url
else { else {
debugln("this is url"); debugln("this is url");
if (strncmp(#address,"http://",7)!=0) { if (!strncmp(#address,"https://",8)) {
sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #address);
}
else if (!strncmp(#address,"http://",7)) {
strlcpy(#getUrl, #address, UML);
}
else {
strcpy(#temp, "http://"); strcpy(#temp, "http://");
strlcpy(#temp, #address, UML); strlcpy(#temp, #address, UML);
strlcpy(#address, #temp, UML); strlcpy(#address, #temp, UML);
DrawAddressBox(); DrawAddressBox();
strlcpy(#getUrl, #address, UML);
} }
if (!downloader.Start(#address)) { downloader.Start(#getUrl);
downloader.Stop();
} else {
while (downloader.state!=STATE_COMPLETED)
{
downloader.MonitorProgress();
if (downloader.httpd.content_length>0)
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*
downloader.httpd.content_received/downloader.httpd.content_length);
else
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
}
strcpy(#address,downloader.url);
DrawAddressBox();
io.buffer_data = downloader.bufpointer;
get_absolute_url(#favicon_address, #address, "/favicon.ico");
favicon.get(#favicon_address);
}
} }
}
void PostOpenPageActions()
{
if (!io.buffer_data) { if (!io.buffer_data) {
debugln("page not found"); debugln("page not found");
io.buffer_data = #buidin_page_not_found; io.buffer_data = #buidin_page_not_found;
@ -327,7 +372,6 @@ char favicon_address[UML];
*/ */
list.KeyHome(); list.KeyHome();
list.ClearList();
PreparePage(); PreparePage();
} }
@ -405,6 +449,14 @@ void EventShowDownloader()
} }
} }
void EventChangeDebugMode()
{
debug_mode ^= 1;
if (debug_mode) notify("'Debug mode ON'-I");
else notify("'Debug mode OFF'-I");
return;
}
/* ------------------------------------------- */ /* ------------------------------------------- */
@ -417,6 +469,11 @@ void draw_window()
if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; }
if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
system.color.get();
list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
Form.cheight-TOOLBAR_H-STATUSBAR_H, kfont.size.pt+4);
DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1); DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece); DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
@ -448,6 +505,7 @@ void draw_window()
} }
DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
DrawStatusBar(NULL);
} }
void DrawPage() void DrawPage()
@ -473,3 +531,19 @@ void DrawAddressBox()
DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff); DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff);
} }
PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, NULL, 0};
void DrawStatusBar(dword _status_text)
{
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, system.color.work);
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, 0x8C8C8C);
if (_status_text) {
status_text.start_x = 7;
status_text.start_y = Form.cheight - STATUSBAR_H + 3;
status_text.area_size_x = Form.cwidth - status_text.start_x -3;
status_text.font_color = system.color.work_text;
status_text.text_pointer = _status_text;
PathShow_prepare stdcall(#status_text);
PathShow_draw stdcall(#status_text);
}
}

View File

@ -47,9 +47,9 @@ enum {
STEP_5_STOP = 100, STEP_5_STOP = 100,
}; };
void DrawProgress(int percent) void DrawProgress(dword percent)
{ {
int progress_width; dword progress_width;
if (percent<100) { if (percent<100) {
progress_width = address_box.width+5*percent/100; progress_width = address_box.width+5*percent/100;
DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0x72B7EA); DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0x72B7EA);

View File

@ -9,9 +9,10 @@ struct _link
collection url; collection url;
void clear(); void clear();
void add(); void add();
dword get_active_url();
void draw_underline();
int hover(); int hover();
int active; int active;
void draw_underline();
} link; } link;
void _link::clear() void _link::clear()
@ -33,25 +34,30 @@ void _link::add(int _xx, _yy, _ww, _hh, dword _textt, _urll )
count++; count++;
} }
void _link::draw_underline(dword i, color) dword _link::get_active_url()
{ {
DrawBar(x[i]+list.x, -list.first*list.item_h+y[i]+list.y+h[i]-1, w[i], 1, color); return url.get(active);
} }
int _link::hover() void _link::draw_underline(dword i, color)
{
DrawBar(x[i]+list.x, -list.first*list.item_h+y[i]+list.y+h[i]-2, w[i], 1, color);
}
int _link::hover(dword mouse_x, mouse_y)
{ {
int i; int i;
int new_active = -1; int new_active = -1;
int link_start_y = list.first*list.item_h; int link_start_y = list.first*list.item_h;
mouse.x = mouse.x - list.x; mouse_x -= list.x;
mouse.y = mouse.y - list.y; mouse_y -= list.y;
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
if(y[i] > link_start_y) && (y[i] < link_start_y+list.h) { if(y[i] > link_start_y) && (y[i] < link_start_y+list.h) {
// debugln( sprintf(#param, "mx:%i my:%i x[i]:%i y[i]:%i", mx, my, x[i], y[i]) ); // debugln( sprintf(#param, "mx:%i my:%i x[i]:%i y[i]:%i", mx, my, x[i], y[i]) );
if (mouse.x > x[i]) if (mouse_x > x[i])
&& (mouse.x < x[i]+w[i]) && (mouse_x < x[i]+w[i])
&& (mouse.y > y[i]-link_start_y) && (mouse_y > y[i]-link_start_y)
&& (mouse.y < h[i]-link_start_y+link.y[i]) { && (mouse_y < h[i]-link_start_y+link.y[i]) {
new_active = i; new_active = i;
break; break;
} }

View File

@ -40,7 +40,7 @@ struct _tag {
bool opens; bool opens;
dword param; dword attribute;
dword value; dword value;
void parse(); void parse();
@ -245,8 +245,6 @@ void _dom::set_style()
DrawTitle(#title); DrawTitle(#title);
} }
if (tag.nameis("h1")) || (tag.nameis("/h1")) || if (tag.nameis("h1")) || (tag.nameis("/h1")) ||
(tag.nameis("h2")) || (tag.nameis("/h2")) || (tag.nameis("h2")) || (tag.nameis("/h2")) ||
(tag.nameis("h3")) || (tag.nameis("/h3")) { (tag.nameis("h3")) || (tag.nameis("/h3")) {
@ -283,7 +281,7 @@ void _dom::apply_text()
kfont.bold = style.bold; kfont.bold = style.bold;
canvas.write_text(draw.x, draw.y, style.color, text.start); canvas.write_text(draw.x, draw.y, style.color, text.start);
if (style.a) { if (style.a) {
canvas.draw_hor_line(draw.x, draw.y + list.item_h-1, kfont.get_label_width(text.start), style.color); canvas.draw_hor_line(draw.x, draw.y + list.item_h-2, kfont.get_label_width(text.start), style.color);
link.add(draw.x, draw.y, kfont.get_label_width(text.start), list.item_h, text.start, "http://kolibrios.org"); link.add(draw.x, draw.y, kfont.get_label_width(text.start), list.item_h, text.start, "http://kolibrios.org");
} }
} }
@ -333,7 +331,7 @@ void _dom::parse()
void PreparePage() void PreparePage()
{ {
_dom dom; _dom dom;
list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, kfont.size.pt+4);
strcpy(#title, history.current()+strrchr(history.current(),'/')); strcpy(#title, history.current()+strrchr(history.current(),'/'));
ChangeCharset(charsets[encoding], "CP866", io.buffer_data); ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
link.clear(); link.clear();

View File

@ -302,7 +302,7 @@ void ProcessEvent(dword id__)
} }
OpenPage(); OpenPage();
return; return;
case 063: //F5 case SCAN_CODE_F5:
IF(address_box.flags & 0b10) return; IF(address_box.flags & 0b10) return;
case REFRESH_BUTTON: case REFRESH_BUTTON:
if (http.transfer > 0) if (http.transfer > 0)

View File

@ -41,6 +41,15 @@
#define SCAN_CODE_PLUS 013 #define SCAN_CODE_PLUS 013
#define SCAN_CODE_F1 059 #define SCAN_CODE_F1 059
#define SCAN_CODE_F2 060
#define SCAN_CODE_F3 061
#define SCAN_CODE_F4 062
#define SCAN_CODE_F5 063
#define SCAN_CODE_F6 064
#define SCAN_CODE_F7 065
#define SCAN_CODE_F8 066
#define SCAN_CODE_F9 067
#define SCAN_CODE_F10 068
#define SCAN_CODE_F11 087 #define SCAN_CODE_F11 087
#define SCAN_CODE_F12 088 #define SCAN_CODE_F12 088
@ -48,6 +57,7 @@
#define SCAN_CODE_KEY_C 046 #define SCAN_CODE_KEY_C 046
#define SCAN_CODE_KEY_E 018 #define SCAN_CODE_KEY_E 018
#define SCAN_CODE_KEY_F 033 #define SCAN_CODE_KEY_F 033
#define SCAN_CODE_KEY_H 035
#define SCAN_CODE_KEY_I 023 #define SCAN_CODE_KEY_I 023
#define SCAN_CODE_KEY_L 038 #define SCAN_CODE_KEY_L 038
#define SCAN_CODE_KEY_M 050 #define SCAN_CODE_KEY_M 050

View File

@ -97,6 +97,7 @@ dword DOWNLOADER::Start(dword _url)
url = _url; url = _url;
state = STATE_IN_PROGRESS; state = STATE_IN_PROGRESS;
httpd.get(url); httpd.get(url);
if (!httpd.transfer) Stop();
return httpd.transfer; return httpd.transfer;
} }