From a86f2c8dd35c0cd8ba2f87097a68ad32373c28b5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 6 Jan 2017 18:27:09 +0000 Subject: Migrate global history to corewindow --- frontends/amiga/cookies.c | 2 +- frontends/amiga/file.c | 3 + frontends/amiga/file.h | 4 +- frontends/amiga/gui.c | 7 +- frontends/amiga/history.c | 405 ++++++++++++++++++++++++++++++++++++++++++++-- frontends/amiga/history.h | 16 +- frontends/amiga/menu.c | 2 +- 7 files changed, 409 insertions(+), 30 deletions(-) mode change 100755 => 100644 frontends/amiga/history.c mode change 100755 => 100644 frontends/amiga/history.h (limited to 'frontends') diff --git a/frontends/amiga/cookies.c b/frontends/amiga/cookies.c index 18ca425ec..f428881a4 100644 --- a/frontends/amiga/cookies.c +++ b/frontends/amiga/cookies.c @@ -258,7 +258,7 @@ static void ami_cookies_menulabs(struct ami_menu_data **md) ami_menu_alloc_item(md, AMI_COOKIE_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", 0, "TBImages:list_hold", ami_cookies_menu_item_project_snapshot, NULL, 0); ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_CLOSE, NM_ITEM, "CloseWindow", 0, "TBImages:list_cancel", + ami_menu_alloc_item(md, AMI_COOKIE_M_CLOSE, NM_ITEM, "CloseWindow", 'K', "TBImages:list_cancel", ami_cookies_menu_item_project_close, NULL, 0); ami_menu_alloc_item(md, AMI_COOKIE_M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL, 0); diff --git a/frontends/amiga/file.c b/frontends/amiga/file.c index 04f8e8aca..0fd43781d 100644 --- a/frontends/amiga/file.c +++ b/frontends/amiga/file.c @@ -46,6 +46,9 @@ static struct Hook aslhookfunc; +struct FileRequester *filereq; +struct FileRequester *savereq; + HOOKF(ULONG, ami_file_asl_mime_hook, struct FileRequester *, fr, struct AnchorPathOld *) { char fname[1024]; diff --git a/frontends/amiga/file.h b/frontends/amiga/file.h index 29a76c477..9120fff61 100644 --- a/frontends/amiga/file.h +++ b/frontends/amiga/file.h @@ -21,8 +21,8 @@ struct hlcache_object; struct selection; struct gui_window_2; -struct FileRequester *filereq; -struct FileRequester *savereq; +extern struct FileRequester *filereq; +extern struct FileRequester *savereq; enum { AMINS_SAVE_SOURCE, diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index 9fce6813f..7c92a40d7 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -547,6 +547,11 @@ static void ami_set_screen_defaults(struct Screen *screen) nsoption_default_set_int(cookies_window_xsize, width); nsoption_default_set_int(cookies_window_ysize, height); + nsoption_default_set_int(history_window_ypos, top); + nsoption_default_set_int(history_window_xpos, left); + nsoption_default_set_int(history_window_xsize, width); + nsoption_default_set_int(history_window_ysize, height); + nsoption_default_set_int(window_x, 0); nsoption_default_set_int(window_y, screen->BarHeight + 1); nsoption_default_set_int(window_width, screen->Width); @@ -1014,7 +1019,6 @@ static void gui_init2(int argc, char** argv) /**/ ami_hotlist_initialise(nsoption_charp(hotlist_file)); - ami_global_history_initialise(); search_web_select_provider(nsoption_int(search_provider)); if (notalreadyrunning && @@ -3038,7 +3042,6 @@ static void gui_quit(void) urldb_save(nsoption_charp(url_file)); urldb_save_cookies(nsoption_charp(cookie_file)); ami_hotlist_free(nsoption_charp(hotlist_file)); - ami_global_history_free(); #ifdef __amigaos4__ if(IApplication && ami_appid) UnregisterApplication(ami_appid, NULL); diff --git a/frontends/amiga/history.c b/frontends/amiga/history.c old mode 100755 new mode 100644 index 2287c7069..0fea42042 --- a/frontends/amiga/history.c +++ b/frontends/amiga/history.c @@ -1,5 +1,5 @@ /* - * Copyright 2008, 2009 Chris Young + * Copyright 2017 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,28 +16,405 @@ * along with this program. If not, see . */ +/** + * \file + * Implementation of Amiga global history viewer using core windows. + */ + +#include +#include #include -#include +#include + +#include +#include +#include + +#include +#include +#include -#include "utils/errors.h" -#include "netsurf/mouse.h" -#include "netsurf/window.h" +#include +#include "desktop/global_history.h" +#include "netsurf/keypress.h" +#include "netsurf/plotters.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/nsoption.h" + +#include "amiga/corewindow.h" +#include "amiga/file.h" #include "amiga/history.h" -#include "amiga/tree.h" -#include "amiga/tree.h" +#include "amiga/libs.h" +#include "amiga/theme.h" +#include "amiga/utf8.h" + +enum { + /* Project menu */ + AMI_HISTORY_M_PROJECT = 0, + AMI_HISTORY_M_EXPORT, + AMI_HISTORY_M_BAR_P1, + AMI_HISTORY_M_EXPAND, + AMI_HISTORY_M_EXPAND_ALL, + AMI_HISTORY_M_EXPAND_FOLDERS, + AMI_HISTORY_M_EXPAND_LINKS, + AMI_HISTORY_M_COLLAPSE, + AMI_HISTORY_M_COLLAPSE_ALL, + AMI_HISTORY_M_COLLAPSE_FOLDERS, + AMI_HISTORY_M_COLLAPSE_LINKS, + AMI_HISTORY_M_BAR_P2, + AMI_HISTORY_M_SNAPSHOT, + AMI_HISTORY_M_BAR_P3, + AMI_HISTORY_M_CLOSE, + /* Edit menu */ + AMI_HISTORY_M_EDIT, + AMI_HISTORY_M_SELECTALL, + AMI_HISTORY_M_CLEAR, + AMI_HISTORY_M_BAR_E1, + AMI_HISTORY_M_DELETE, + AMI_HISTORY_M_LAST +}; + +/** + * Amiga history viewer window context + */ +struct ami_history_global_window { + /** Amiga core window context */ + struct ami_corewindow core; + + struct ami_menu_data *menu_data[AMI_HISTORY_M_LAST + 1]; + struct Menu *imenu; /* Intuition menu */ +}; + +static struct ami_history_global_window *history_window = NULL; + + +static void +ami_history_global_menu_free(struct ami_history_global_window *history_win) +{ + SetAttrs(history_win->core.objects[GID_CW_WIN], + WINDOW_MenuStrip, NULL, + TAG_DONE); + + ami_menu_free_menu(history_win->menu_data, AMI_HISTORY_M_LAST, history_win->imenu); +} + +/** + * destroy a previously created history view + */ +static void +ami_history_global_destroy(struct ami_corewindow *ami_cw) +{ + nserror res; + + if(history_window == NULL) + return; + + res = global_history_fini(); + if (res == NSERROR_OK) { + ami_history_global_menu_free(history_window); + res = ami_corewindow_fini(&history_window->core); /* closes the window for us, frees history_win */ + history_window = NULL; + } +} + + +/** + * callback for mouse action for history viewer on core window + * + * \param ami_cw The Amiga core window structure. + * \param mouse_state netsurf mouse state on event + * \param x location of event + * \param y location of event + * \return NSERROR_OK on success otherwise apropriate error code + */ +static nserror +ami_history_global_mouse(struct ami_corewindow *ami_cw, + browser_mouse_state mouse_state, + int x, int y) +{ + global_history_mouse_action(mouse_state, x, y); + + return NSERROR_OK; +} + +/** + * callback for keypress for history viewer on core window + * + * \param ami_cw The Amiga core window structure. + * \param nskey The netsurf key code + * \return NSERROR_OK on success otherwise apropriate error code + */ +static nserror +ami_history_global_key(struct ami_corewindow *ami_cw, uint32_t nskey) +{ + if (global_history_keypress(nskey)) { + return NSERROR_OK; + } + return NSERROR_NOT_IMPLEMENTED; +} + +/** + * callback on draw event for history viewer on core window + * + * \param ami_cw The Amiga core window structure. + * \param r The rectangle of the window that needs updating. + * \param ctx The drawing context + * \return NSERROR_OK on success otherwise apropriate error code + */ +static nserror +ami_history_global_draw(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx) +{ + global_history_redraw(x, y, r, ctx); + + return NSERROR_OK; +} + +/** + * menu stuff + */ + + /* menu hook functions */ +HOOKF(void, ami_history_global_menu_item_project_export, APTR, window, struct IntuiMessage *) +{ + char fname[1024]; + struct ami_corewindow *ami_cw; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&ami_cw); + + if(AslRequestTags(savereq, + ASLFR_Window, ami_cw->win, + ASLFR_SleepWindow, TRUE, + ASLFR_TitleText, messages_get("NetSurf"), + ASLFR_Screen, scrn, + ASLFR_InitialFile, "history.html", + TAG_DONE)) { + strlcpy(fname, savereq->fr_Drawer, 1024); + AddPart(fname, savereq->fr_File, 1024); + ami_update_pointer(ami_cw->win, GUI_POINTER_WAIT); + global_history_export(fname, NULL); + ami_update_pointer(ami_cw->win, GUI_POINTER_DEFAULT); + } +} + +HOOKF(void, ami_history_global_menu_item_project_expand_all, APTR, window, struct IntuiMessage *) +{ + global_history_expand(false); +} + +HOOKF(void, ami_history_global_menu_item_project_expand_folders, APTR, window, struct IntuiMessage *) +{ + global_history_expand(true); +} + +HOOKF(void, ami_history_global_menu_item_project_expand_links, APTR, window, struct IntuiMessage *) +{ + global_history_expand(false); +} -struct treeview_window *global_history_window = NULL; +HOOKF(void, ami_history_global_menu_item_project_collapse_all, APTR, window, struct IntuiMessage *) +{ + global_history_contract(true); +} + +HOOKF(void, ami_history_global_menu_item_project_collapse_folders, APTR, window, struct IntuiMessage *) +{ + global_history_contract(true); +} -void ami_global_history_initialise(void) +HOOKF(void, ami_history_global_menu_item_project_collapse_links, APTR, window, struct IntuiMessage *) { - global_history_window = ami_tree_create(TREE_HISTORY, NULL); + global_history_contract(false); +} - if(!global_history_window) return; +HOOKF(void, ami_history_global_menu_item_project_snapshot, APTR, window, struct IntuiMessage *) +{ + struct ami_corewindow *ami_cw; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&ami_cw); + + nsoption_set_int(history_window_ypos, ami_cw->win->TopEdge); + nsoption_set_int(history_window_xpos, ami_cw->win->LeftEdge); + nsoption_set_int(history_window_xsize, ami_cw->win->Width); + nsoption_set_int(history_window_ysize, ami_cw->win->Height); +} + +HOOKF(void, ami_history_global_menu_item_project_close, APTR, window, struct IntuiMessage *) +{ + struct ami_corewindow *ami_cw; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&ami_cw); + + ami_cw->close_window = true; } -void ami_global_history_free() +HOOKF(void, ami_history_global_menu_item_edit_select_all, APTR, window, struct IntuiMessage *) { - ami_tree_destroy(global_history_window); - global_history_window = NULL; + global_history_keypress(NS_KEY_SELECT_ALL); +} + +HOOKF(void, ami_history_global_menu_item_edit_clear, APTR, window, struct IntuiMessage *) +{ + global_history_keypress(NS_KEY_CLEAR_SELECTION); +} + +HOOKF(void, ami_history_global_menu_item_edit_delete, APTR, window, struct IntuiMessage *) +{ + global_history_keypress(NS_KEY_DELETE_LEFT); +} + + +/* menu setup */ + +static void ami_history_global_menulabs(struct ami_menu_data **md) +{ + ami_menu_alloc_item(md, AMI_HISTORY_M_PROJECT, NM_TITLE, "Tree", 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPORT, NM_ITEM, "TreeExport", 'S', "TBImages:list_save", + ami_history_global_menu_item_project_export, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND, NM_ITEM, "Expand", 0, "TBImages:list_folderunfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_ALL, NM_SUB, "All", '+', NULL, + ami_history_global_menu_item_project_expand_all, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_FOLDERS, NM_SUB, "Folders", 0, NULL, + ami_history_global_menu_item_project_expand_folders, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_LINKS, NM_SUB, "Links", 0, NULL, + ami_history_global_menu_item_project_expand_links, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE, NM_ITEM, "Collapse", 0, "TBImages:list_folderfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_ALL, NM_SUB, "All", '-', NULL, + ami_history_global_menu_item_project_collapse_all, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_FOLDERS, NM_SUB, "Folders", 0, NULL, + ami_history_global_menu_item_project_collapse_folders, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_LINKS, NM_SUB, "Links", 0, NULL, + ami_history_global_menu_item_project_collapse_links, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", 0, "TBImages:list_hold", + ami_history_global_menu_item_project_snapshot, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_CLOSE, NM_ITEM, "CloseWindow", 'K', "TBImages:list_cancel", + ami_history_global_menu_item_project_close, NULL, 0); + + ami_menu_alloc_item(md, AMI_HISTORY_M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_SELECTALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE, + ami_history_global_menu_item_edit_select_all, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE, + ami_history_global_menu_item_edit_clear, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_DELETE, NM_ITEM, "TreeDelete", 0, "TBImages:list_delete", + ami_history_global_menu_item_edit_delete, NULL, 0); + + ami_menu_alloc_item(md, AMI_HISTORY_M_LAST, NM_END, NULL, 0, NULL, NULL, NULL, 0); } + +static struct Menu * +ami_history_global_menu_create(struct ami_history_global_window *history_win) +{ + ami_history_global_menulabs(history_win->menu_data); + history_win->imenu = ami_menu_layout(history_win->menu_data, AMI_HISTORY_M_LAST); + if(history_win->imenu == NULL) return NULL; + + return history_win->imenu; +} + + +static nserror +ami_history_global_create_window(struct ami_history_global_window *history_win) +{ + struct ami_corewindow *ami_cw = (struct ami_corewindow *)&history_win->core; + + ami_cw->objects[GID_CW_WIN] = WindowObj, + WA_ScreenTitle, ami_gui_get_screen_title(), + WA_Title, ami_cw->wintitle, + WA_Activate, TRUE, + WA_DepthGadget, TRUE, + WA_DragBar, TRUE, + WA_CloseGadget, TRUE, + WA_SizeGadget, TRUE, + WA_SizeBRight, TRUE, + WA_Top, nsoption_int(history_window_ypos), + WA_Left, nsoption_int(history_window_xpos), + WA_Width, nsoption_int(history_window_xsize), + WA_Height, nsoption_int(history_window_ysize), + WA_PubScreen, scrn, + WA_ReportMouse, TRUE, + WA_IDCMP, IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE | + IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE | + IDCMP_EXTENDEDMOUSE | IDCMP_SIZEVERIFY, + WINDOW_IDCMPHook, &ami_cw->idcmp_hook, + WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE, + WINDOW_SharedPort, sport, + WINDOW_HorizProp, 1, + WINDOW_VertProp, 1, + WINDOW_UserData, history_win, + WINDOW_MenuStrip, ami_history_global_menu_create(history_win), + WINDOW_MenuUserData, WGUD_HOOK, + WINDOW_IconifyGadget, FALSE, + WINDOW_Position, WPOS_CENTERSCREEN, + WINDOW_ParentGroup, ami_cw->objects[GID_CW_MAIN] = LayoutVObj, + LAYOUT_AddChild, ami_cw->objects[GID_CW_DRAW] = SpaceObj, + GA_ID, GID_CW_DRAW, + SPACE_Transparent, TRUE, + SPACE_BevelStyle, BVS_DISPLAY, + GA_RelVerify, TRUE, + SpaceEnd, + EndGroup, + EndWindow; + + if(ami_cw->objects[GID_CW_WIN] == NULL) { + return NSERROR_NOMEM; + } + + return NSERROR_OK; +} + +/* exported interface documented in amiga/cookies.h */ +nserror ami_history_global_present(void) +{ + struct ami_history_global_window *ncwin; + nserror res; + + if(history_window != NULL) { + //windowtofront() + return NSERROR_OK; + } + + ncwin = calloc(1, sizeof(struct ami_history_global_window)); + if (ncwin == NULL) { + return NSERROR_NOMEM; + } + + ncwin->core.wintitle = ami_utf8_easy((char *)messages_get("GlobalHistory")); + + res = ami_history_global_create_window(ncwin); + if (res != NSERROR_OK) { + LOG("SSL UI builder init failed"); + ami_utf8_free(ncwin->core.wintitle); + free(ncwin); + return res; + } + + /* initialise Amiga core window */ + ncwin->core.draw = ami_history_global_draw; + ncwin->core.key = ami_history_global_key; + ncwin->core.mouse = ami_history_global_mouse; + ncwin->core.close = ami_history_global_destroy; + ncwin->core.event = NULL; + + res = ami_corewindow_init(&ncwin->core); + if (res != NSERROR_OK) { + ami_utf8_free(ncwin->core.wintitle); + DisposeObject(ncwin->core.objects[GID_CW_WIN]); + free(ncwin); + return res; + } + + res = global_history_init(ncwin->core.cb_table, (struct core_window *)ncwin); + if (res != NSERROR_OK) { + ami_utf8_free(ncwin->core.wintitle); + DisposeObject(ncwin->core.objects[GID_CW_WIN]); + free(ncwin); + return res; + } + + history_window = ncwin; + + return NSERROR_OK; +} + diff --git a/frontends/amiga/history.h b/frontends/amiga/history.h old mode 100755 new mode 100644 index 47e00ed10..67ab670b7 --- a/frontends/amiga/history.h +++ b/frontends/amiga/history.h @@ -1,5 +1,5 @@ /* - * Copyright 2008,2009 Chris Young + * Copyright 2017 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,14 +16,10 @@ * along with this program. If not, see . */ -#ifndef AMIGA_HISTORY_H -#define AMIGA_HISTORY_H -#include "amiga/desktop-tree.h" +#ifndef AMIGA_HISTORY_GLOBAL_H +#define AMIGA_HISTORY_GLOBAL_H -#define GLOBAL_HISTORY_RECENT_URLS 16 - -void ami_global_history_initialise(void); -void ami_global_history_free(void); - -extern struct treeview_window *global_history_window; +/** Open the global history viewer */ +nserror ami_history_global_present(void); #endif + diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index d88139d9f..83cfaa7df 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -362,7 +362,7 @@ HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessag HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) { - ami_tree_open(global_history_window,AMI_TREE_HISTORY); + ami_history_global_present(); } HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) -- cgit v1.2.3