WebView: use /lib/patterts/history.h instead own realization

git-svn-id: svn://kolibrios.org@5978 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-16 22:44:42 +00:00
parent 35b817fff3
commit c455cae71e
5 changed files with 25 additions and 88 deletions

View File

@ -62,7 +62,6 @@ char attr[1200];
char val[4096];
char anchor[256]=0;
#include "..\TWB\history.h"
#include "..\TWB\links.h"
#include "..\TWB\colors.h"
#include "..\TWB\unicode_tags.h"

View File

@ -1,65 +0,0 @@
struct path_string {
char Item[sizeof(URL)];
int was_first;
};
#define MAX_HISTORY_NUM 40
path_string history_list[MAX_HISTORY_NUM];
struct UrlsHistory {
int links_count;
int cur_y;
dword CurrentUrl();
dword GetUrl();
dword GetFirstLine();
void AddUrl();
byte GoBack();
byte GoForward();
} BrowserHistory;
dword UrlsHistory::CurrentUrl() {
return #history_list[cur_y].Item;
}
dword UrlsHistory::GetUrl(int id) {
return #history_list[id].Item;
}
dword UrlsHistory::GetFirstLine(int id) {
return history_list[id].was_first;
}
void UrlsHistory::AddUrl() {
int i;
if (links_count>0) && (!strcmp(#URL,#history_list[cur_y].Item)) return;
if (cur_y>=MAX_HISTORY_NUM-1)
{
cur_y/=2;
for (i=0; i<cur_y; i++;)
{
strlcpy(#history_list[i].Item, #history_list[MAX_HISTORY_NUM-i].Item, sizeof(URL));
}
}
cur_y++;
// history_list[i].was_first = WB1.list.first;
strlcpy(#history_list[cur_y].Item, #URL, sizeof(URL));
links_count=cur_y;
}
byte UrlsHistory::GoBack() {
if (cur_y<=1) return 0;
cur_y--;
strlcpy(#URL, #history_list[cur_y].Item, sizeof(URL));
// stroka = history_list[cur_y].was_first;
return 1;
}
byte UrlsHistory::GoForward() {
if (cur_y==links_count) return 0;
cur_y++;
strlcpy(#URL, #history_list[cur_y].Item, sizeof(URL));
return 1;
}

View File

@ -129,11 +129,11 @@ void LinksArray::GetAbsoluteURL(dword in_URL)
IF (!strcmpn(in_URL,"./", 2)) in_URL+=2;
if (!http_transfer)
{
strcpy(#newurl, BrowserHistory.CurrentUrl());
strcpy(#newurl, History.current());
}
else
{
strcpy(#newurl, #history_list[BrowserHistory.cur_y-1].Item);
strcpy(#newurl, History.items.get(History.active-2));
}
if (ESBYTE[in_URL] == '/') //remove everything after site domain name

View File

@ -13,6 +13,7 @@
#include "..\lib\draw_buf.h"
#include "..\lib\list_box.h"
#include "..\lib\cursor.h"
#include "..\lib\collection.h"
//*.obj libraries
#include "..\lib\obj\box_lib.h"
#include "..\lib\obj\libio_lib.h"
@ -21,6 +22,7 @@
#include "..\lib\obj\iconv.h"
//useful patterns
#include "..\lib\patterns\libimg_load_skin.h"
#include "..\lib\patterns\history.h"
char homepage[] = FROM "html\\homepage.htm";
@ -214,14 +216,14 @@ void main()
http_free stdcall (http_transfer);
http_transfer=0;
PageLinks.GetAbsoluteURL(#URL);
BrowserHistory.cur_y--;
History.back();
strcpy(#editURL, #URL);
DrawEditBox();
OpenPage();
}
else
{
BrowserHistory.AddUrl();
History.add(#URL);
ESI = http_transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
@ -277,12 +279,16 @@ void Scan(dword id__)
{
case SCAN_CODE_BS:
case BACK_BUTTON:
if (!BrowserHistory.GoBack()) return;
OpenPage();
if (History.back()) {
strcpy(#URL, History.current());
OpenPage();
}
return;
case FORWARD_BUTTON:
if (!BrowserHistory.GoForward()) return;
OpenPage();
if (History.forward()) {
strcpy(#URL, History.current());
OpenPage();
}
return;
case GOTOURL_BUTTON:
case SCAN_CODE_ENTER:
@ -387,7 +393,7 @@ void OpenPage()
StopLoading();
souce_mode = false;
strcpy(#editURL, #URL);
BrowserHistory.AddUrl();
History.add(#URL);
if (!strncmp(#URL,"WebView:",8))
{
SetPageDefaults();
@ -448,7 +454,6 @@ void ShowPage()
{
WB1.Prepare();
}
//if (!header) strcpy(#header, #version);
if (!strcmp(#version, #header)) DrawTitle(#header);
}
@ -486,7 +491,7 @@ void ClickLink()
if (http_transfer > 0)
{
StopLoading();
BrowserHistory.cur_y--;
History.back();
}
strcpy(#URL, PageLinks.GetURL(PageLinks.active));
@ -494,7 +499,7 @@ void ClickLink()
if (URL[0] == '#')
{
strcpy(#anchor, #URL+strrchr(#URL, '#'));
strcpy(#URL, BrowserHistory.CurrentUrl());
strcpy(#URL, History.current());
WB1.list.first=WB1.list.count-WB1.list.visible;
ShowPage();
return;
@ -518,15 +523,15 @@ void ClickLink()
CreateThread(#Downloader,#downloader_stak+4092);
}
else RunProgram("@open", #URL);
strcpy(#editURL, BrowserHistory.CurrentUrl());
strcpy(#URL, BrowserHistory.CurrentUrl());
strcpy(#editURL, History.current());
strcpy(#URL, History.current());
return;
}
if (!strncmp(#URL,"mailto:", 7))
{
notify(#URL);
strcpy(#editURL, BrowserHistory.CurrentUrl());
strcpy(#URL, BrowserHistory.CurrentUrl());
strcpy(#editURL, History.current());
strcpy(#URL, History.current());
return;
}
OpenPage();

View File

@ -5,17 +5,15 @@ ShowHistory()
int t;
free(history_pointer);
history_pointer = malloc(64000);
history_pointer = malloc(History.items.data_size+256);
strcat(history_pointer, "<html><head><title>History</title></head><body><h1>History</h1>");
strcat(history_pointer, "<h2>Visited pages</h2><blockquote><br>");
for (i=1; i<BrowserHistory.links_count; i++)
for (i=1; i<History.items.count; i++)
{
// t = BrowserHistory.GetFirstLine(i);
// strcat(history_pointer, itoa(t));
strcat(history_pointer, " <a href='");
strcat(history_pointer, BrowserHistory.GetUrl(i));
strcat(history_pointer, History.items.get(i));
strcat(history_pointer, "'>");
strcat(history_pointer, BrowserHistory.GetUrl(i));
strcat(history_pointer, History.items.get(i));
strcat(history_pointer, "</a><br>");
}
strcat(history_pointer, "</blockquote><h2>Cached images</h2>");