From 606cc0c2196f5934a7c48e89ab05da7d5e05081f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 16:05:07 +0000 Subject: Split up menu.c into generic and gui_window-specific files --- frontends/amiga/gui_menu.h | 153 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 frontends/amiga/gui_menu.h (limited to 'frontends/amiga/gui_menu.h') diff --git a/frontends/amiga/gui_menu.h b/frontends/amiga/gui_menu.h new file mode 100644 index 000000000..a9de69a46 --- /dev/null +++ b/frontends/amiga/gui_menu.h @@ -0,0 +1,153 @@ +/* + * Copyright 2008-2017 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AMIGA_GUI_MENU_H +#define AMIGA_GUI_MENU_H + +/** Maximum number of hotlist items (somewhat arbitrary value) */ +#define AMI_HOTLIST_ITEMS 200 + +/** Maximum number of ARexx menu items (somewhat arbitrary value) */ +#define AMI_MENU_AREXX_ITEMS 20 + +/** enum menu structure, has to be here as we need it below. */ +enum { + /* Project menu */ + M_PROJECT = 0, + M_NEWWIN, + M_NEWTAB, + M_BAR_P1, + M_OPEN, + M_SAVEAS, + M_SAVESRC, + M_SAVETXT, + M_SAVECOMP, + M_SAVEIFF, +#ifdef WITH_PDF_EXPORT + M_SAVEPDF, +#endif + M_BAR_P2, + M_PRINT, + M_BAR_P3, + M_CLOSETAB, + M_CLOSEWIN, + M_BAR_P4, + M_ABOUT, + M_BAR_P5, + M_QUIT, + /* Edit menu */ + M_EDIT, + M_CUT, + M_COPY, + M_PASTE, + M_BAR_E1, + M_SELALL, + M_CLEAR, + M_BAR_E2, + M_UNDO, + M_REDO, + /* Browser menu */ + M_BROWSER, + M_FIND, + M_BAR_B1, + M_HISTLOCL, + M_HISTGLBL, + M_BAR_B2, + M_COOKIES, + M_BAR_B3, + M_SCALE, + M_SCALEDEC, + M_SCALENRM, + M_SCALEINC, + M_IMAGES, + M_IMGFORE, + M_IMGBACK, + M_JS, + M_BAR_B4, + M_REDRAW, + /* Hotlist menu */ + M_HOTLIST, + M_HLADD, + M_HLSHOW, + M_BAR_H1, // 47 + AMI_MENU_HOTLIST, /* Where the hotlist entries start */ + AMI_MENU_HOTLIST_MAX = AMI_MENU_HOTLIST + AMI_HOTLIST_ITEMS, + /* Settings menu */ + M_PREFS, + M_PREDIT, + M_BAR_S1, + M_SNAPSHOT, + M_PRSAVE, + /* ARexx menu */ + M_AREXX, + M_AREXXEX, + M_BAR_A1, + AMI_MENU_AREXX, + AMI_MENU_AREXX_MAX = AMI_MENU_AREXX + AMI_MENU_AREXX_ITEMS +}; + +/* We can get away with AMI_MENU_MAX falling short as it is + * only used for freeing the UTF-8 converted menu labels */ +#define AMI_MENU_MAX AMI_MENU_AREXX + +struct gui_window; +struct gui_window_2; +struct hlcache_handle; + +ULONG ami_gui_menu_number(int item); +struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin); +void ami_gui_menu_free(struct gui_window_2 *gwin); + +void ami_gui_menu_update_checked(struct gui_window_2 *gwin); +void ami_gui_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c); + +/** + * Sets that an item linked to a toggle menu item has been changed. + */ +void ami_gui_menu_set_check_toggled(void); + +/** + * Gets if the menu needs updating because an item linked + * to a toggle menu item has been changed. + * NB: This also *clears* the state + * + * \return true if the menus need refreshing + */ +bool ami_gui_menu_get_check_toggled(void); + +/** + * Set checked state of a menu item + * almost generic, but not quite + */ +void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check); + +/** + * Set disabled state of a menu item + * almost generic, but not quite + */ +void ami_gui_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable); + + +/** + * Gets if NetSurf has been quit from the menu + * + * \return true if NetSurf has been quit + */ +bool ami_gui_menu_quit_selected(void); +#endif + -- cgit v1.2.3 From b78d6f458e5d5cb9c78d7430aacf10abd227eb32 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 17:51:55 +0000 Subject: Attempt hotlist menu refresh --- frontends/amiga/gui.c | 3 ++- frontends/amiga/gui.h | 2 +- frontends/amiga/gui_menu.c | 44 +++++++++++++++++++++++++++++++------------- frontends/amiga/gui_menu.h | 4 ++++ frontends/amiga/menu.c | 37 ++++++++++++++++++++++++++++++++++++- frontends/amiga/menu.h | 5 +++++ 6 files changed, 79 insertions(+), 16 deletions(-) (limited to 'frontends/amiga/gui_menu.h') diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index d660e9356..c6ca886f7 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -3327,6 +3327,8 @@ void ami_gui_hotlist_update_all(void) if(IsMinListEmpty(window_list)) return; + ami_gui_menu_refresh_hotlist(); + node = (struct nsObject *)GetHead((struct List *)window_list); do { @@ -3336,7 +3338,6 @@ void ami_gui_hotlist_update_all(void) if(node->Type == AMINS_WINDOW) { ami_gui_hotlist_toolbar_update(gwin); - //ami_gui_menu_refresh_hotlist(gwin); } } while((node = nnode)); } diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h index 77f6839e5..07ff922f7 100644 --- a/frontends/amiga/gui.h +++ b/frontends/amiga/gui.h @@ -134,7 +134,7 @@ struct gui_window_2 { int temp; bool redraw_scroll; bool new_content; - struct ami_menu_data *menu_data[AMI_MENU_AREXX_MAX + 1]; + struct ami_menu_data *menu_data[AMI_MENU_AREXX_MAX + 1]; /* only for GadTools menus */ ULONG hotlist_items; Object *restrict hotlist_toolbar_lab[AMI_GUI_TOOLBAR_MAX]; struct List hotlist_toolbar_list; diff --git a/frontends/amiga/gui_menu.c b/frontends/amiga/gui_menu.c index 6b33194cb..c453c64d8 100644 --- a/frontends/amiga/gui_menu.c +++ b/frontends/amiga/gui_menu.c @@ -80,8 +80,11 @@ #include "amiga/utf8.h" #include "amiga/schedule.h" +#ifdef __amigaos4__ static struct Menu *restrict gui_menu = NULL; static int gui_menu_count = 0; +struct ami_menu_data *gui_menu_data[AMI_MENU_AREXX_MAX + 1]; +#endif static bool ami_menu_check_toggled = false; static bool menu_quit = false; @@ -900,6 +903,12 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char static nserror ami_menu_scan(struct ami_menu_data **md) { + ami_menu_alloc_item(md, M_HLADD, NM_ITEM, "HotlistAdd", "B", "TBImages:list_favouriteadd", + ami_menu_item_hotlist_add, NULL, 0); + ami_menu_alloc_item(md, M_HLSHOW, NM_ITEM,"HotlistShowNS", "H", "TBImages:list_favourite", + ami_menu_item_hotlist_show, NULL, 0); + ami_menu_alloc_item(md, M_BAR_H1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); } @@ -1002,11 +1011,7 @@ static void ami_init_menulabs(struct ami_menu_data **md) ami_menu_item_browser_redraw, NULL, 0); ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_HLADD, NM_ITEM, "HotlistAdd", "B", "TBImages:list_favouriteadd", - ami_menu_item_hotlist_add, NULL, 0); - ami_menu_alloc_item(md, M_HLSHOW, NM_ITEM,"HotlistShowNS", "H", "TBImages:list_favourite", - ami_menu_item_hotlist_show, NULL, 0); - ami_menu_alloc_item(md, M_BAR_H1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + /* see ami_menu_scan for the rest of this menu */ ami_menu_alloc_item(md, M_PREFS, NM_TITLE, "Settings", NULL, NULL, NULL, NULL, 0); ami_menu_alloc_item(md, M_PREDIT, NM_ITEM, "SettingsEdit", NULL, "TBImages:list_prefs", @@ -1027,21 +1032,25 @@ static void ami_init_menulabs(struct ami_menu_data **md) struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ if(gui_menu != NULL) { gwin->imenu = gui_menu; gui_menu_count++; return gwin->imenu; } - } + ami_init_menulabs(gui_menu_data); + ami_menu_scan(gui_menu_data); + ami_menu_arexx_scan(gui_menu_data); + gwin->imenu = ami_menu_layout(gui_menu_data, AMI_MENU_AREXX_MAX); - ami_init_menulabs(gwin->menu_data); - ami_menu_scan(gwin->menu_data); - ami_menu_arexx_scan(gwin->menu_data); - gwin->imenu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX); - - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { gui_menu = gwin->imenu; gui_menu_count++; +#endif + } else { + ami_init_menulabs(gwin->menu_data); + ami_menu_scan(gwin->menu_data); + ami_menu_arexx_scan(gwin->menu_data); + gwin->imenu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX); } return gwin->imenu; @@ -1081,14 +1090,16 @@ static void ami_free_menulabs(struct ami_menu_data **md) void ami_gui_menu_free(struct gui_window_2 *gwin) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ gui_menu_count--; if(gui_menu_count == 0) { - ami_free_menulabs(gwin->menu_data); + ami_free_menulabs(gui_menu_data); // if we detach our menu from the window we need to do this manually DisposeObject((Object *)gui_menu); gui_menu = NULL; } +#endif } else { ami_free_menulabs(gwin->menu_data); FreeMenus(gwin->imenu); @@ -1100,3 +1111,10 @@ bool ami_gui_menu_quit_selected(void) return menu_quit; } +void ami_gui_menu_refresh_hotlist(void) +{ +#ifdef __amigaos4__ + ami_menu_refresh(gui_menu, gui_menu_data, M_HOTLIST, AMI_MENU_HOTLIST_MAX, ami_menu_scan); +#endif +} + diff --git a/frontends/amiga/gui_menu.h b/frontends/amiga/gui_menu.h index a9de69a46..16fc72040 100644 --- a/frontends/amiga/gui_menu.h +++ b/frontends/amiga/gui_menu.h @@ -142,6 +142,10 @@ void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check); */ void ami_gui_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable); +/** + * Refresh the Hotlist menu + */ +void ami_gui_menu_refresh_hotlist(void); /** * Gets if NetSurf has been quit from the menu diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 04c6eb07f..cfbbd8deb 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -80,7 +80,7 @@ bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) } /* menu creation code */ -static void ami_menu_free_lab_item(struct ami_menu_data **md, int i) +void ami_menu_free_lab_item(struct ami_menu_data **md, int i) { if(md[i] == NULL) return; if(md[i]->menulab && @@ -435,3 +435,38 @@ void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) } } +void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int menu_item, int max, + nserror (*cb)(struct ami_menu_data **md)) +{ +#ifdef __amigaos4__ + Object *restrict obj; + Object *restrict menu_item_obj; + int i; + + if(menu == NULL) return; + + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + /* find the address of the menu */ + menu_item_obj = (Object *)IDoMethod((Object *)menu, MM_FINDID, 0, menu_item); + + /* remove all children */ + while((obj = (Object *)IDoMethod(menu_item_obj, MM_NEXTCHILD, 0, NULL)) != NULL) { + IDoMethod(menu_item_obj, OM_REMMEMBER, obj); + /* do we need to disposeobject? */ + } + + /* free associated data */ + for(i = (menu_item + 1); i <= max; i++) { + if(md[i] == NULL) continue; + ami_menu_free_lab_item(md, i); + } + + /* get current data */ + cb(md); + + /* re-add items to menu */ + ami_menu_layout_mc_recursive(menu_item_obj, md, NM_ITEM, (menu_item + 1), max); + } +#endif +} + diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h index f8a3f1724..358faa486 100644 --- a/frontends/amiga/menu.h +++ b/frontends/amiga/menu.h @@ -45,6 +45,11 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, void *restrict func, void *restrict hookdata, UWORD flags); struct Menu *ami_menu_layout(struct ami_menu_data **md, int max); void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu); +void ami_menu_free_lab_item(struct ami_menu_data **md, int i); + +/* refresh a menu's children */ +void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int menu_item, int max, + nserror (*cb)(struct ami_menu_data **md)); /** * Get the selected state of a menu item -- cgit v1.2.3