From 439deddba14f509fa0be90beff07481643178b69 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 9 Jan 2017 19:06:09 +0000 Subject: Attempt to construct menu using menuclass --- frontends/amiga/menu.c | 100 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 8 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 88a875ec1..fc42dc9fd 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -33,6 +33,9 @@ #endif #include +#ifdef __amigaos4__ +#include +#endif #include #include @@ -853,8 +856,60 @@ static int ami_menu_calc_item_width(struct ami_menu_data **md, int j, struct Ras return item_size; } +#ifdef __amigaos4__ +static void ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_data **md, int level, int *i, int max) +{ + Object *menu_item = menu_parent; + ULONG item_type = T_ITEM; + + if(level == NM_TITLE) { + item_type = T_MENU; + } + + while(*i <= max) { + /* skip empty entries */ + if(md[*i] == NULL) continue; + if(md[*i]->menutype == NM_IGNORE) continue; + + if(md[*i]->menutype == level) { + menu_item = NewObject(NULL, "menuclass", + MA_Type, item_type, + MA_ID, *i, + MA_Label, md[*i]->menulab, + MA_Image, md[*i]->menuicon, + MA_Key, &md[*i]->menukey, + MA_PickHook, &md[*i]->menu_hook, + MA_Disabled, (md[*i]->flags & NM_ITEMDISABLED), + MA_Selected, (md[*i]->flags & CHECKED), + MA_Toggle, (md[*i]->flags & MENUTOGGLE), + TAG_DONE); + IDoMethod(menu_parent, OM_ADDMEMBER, menu_item); + } else if (md[*i]->menutype > level) { + ami_menu_layout_mc_recursive(menu_item, md, md[*i]->menutype, i, max); + } else { + break; + } + *i++; + } + return; +} + +static struct Menu *ami_menu_layout_mc(struct ami_menu_data **md, int max) +{ + int i = 0; -struct Menu *ami_menu_layout(struct ami_menu_data **md, int max) + Object *menu_root = NewObject(NULL, "menuclass", + MA_Type, T_ROOT, + MA_FreeImage, FALSE, + TAG_DONE); + + ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, &i, max); + + return (struct Menu *)menu_root; +} +#endif + +static struct Menu *ami_menu_layout_gt(struct ami_menu_data **md, int max) { int i, j; int txtlen = 0; @@ -977,15 +1032,34 @@ struct Menu *ami_menu_layout(struct ami_menu_data **md, int max) return imenu; } +struct Menu *ami_menu_layout(struct ami_menu_data **md, int max) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ + return ami_menu_layout_mc(md, max); +#endif + } else { + return ami_menu_layout_gt(md, max); + } +} + void ami_menu_free(struct gui_window_2 *gwin) { - FreeMenus(gwin->imenu); + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + DisposeObject((Object *)gwin->imenu); // if we detach our menu from the window we need to do this manually + } else { + FreeMenus(gwin->imenu); + } } void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) { ami_menu_free_labs(md, max); - FreeMenus(imenu); + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + DisposeObject((Object *)imenu); // if we detach our menu from the window we need to do this manually + } else { + FreeMenus(imenu); + } } struct Menu *ami_menu_create(struct gui_window_2 *gwin) @@ -1066,9 +1140,12 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char type = NM_SUB; break; default: - /* entries not at level 1 or 2 are not able to be added - * \todo construct menus using menuclass instead! */ - return false; + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + type = NM_SUB + (level - 2); + } else { + /* entries not at level 1 or 2 are not able to be added */ + return false; + } break; } @@ -1079,8 +1156,10 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char if (icon == NULL) icon = ASPrintf("icons/content.png"); } - if((is_folder == true) && (type == NM_SUB)) { - flags = NM_ITEMDISABLED; + if(!LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + if((is_folder == true) && (type == NM_SUB)) { + flags = NM_ITEMDISABLED; + } } ami_menu_alloc_item(md, item, type, title, @@ -1098,6 +1177,11 @@ static nserror ami_menu_scan(struct ami_menu_data **md) void ami_menu_update_checked(struct gui_window_2 *gwin) { + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + //needs re-writing for MenuClass + return; + } + struct Menu *menustrip; GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); -- cgit v1.2.3 From 0d9023148d2a34bd908aac38e44d449359b03438 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 12 Jan 2017 18:46:48 +0000 Subject: Our hook function needs to be in UserData, not PickHook, for window.class reasons. --- frontends/amiga/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index fc42dc9fd..97debb686 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -878,7 +878,7 @@ static void ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_da MA_Label, md[*i]->menulab, MA_Image, md[*i]->menuicon, MA_Key, &md[*i]->menukey, - MA_PickHook, &md[*i]->menu_hook, + MA_UserData, &md[*i]->menu_hook, /* NB: Intentionally UserData */ MA_Disabled, (md[*i]->flags & NM_ITEMDISABLED), MA_Selected, (md[*i]->flags & CHECKED), MA_Toggle, (md[*i]->flags & MENUTOGGLE), -- cgit v1.2.3 From 313aaabdde2e6f0bb1f0dfe571b77261cc697a95 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 14 Jan 2017 20:51:51 +0000 Subject: Replace OnMenu/OffMenu with MenuClass compatible abstraction --- frontends/amiga/clipboard.c | 6 +- frontends/amiga/gui.c | 18 ++--- frontends/amiga/menu.c | 183 ++++++++++++++++++++++++++++++++++++-------- frontends/amiga/menu.h | 23 ++---- 4 files changed, 164 insertions(+), 66 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/clipboard.c b/frontends/amiga/clipboard.c index 9489110b7..0fc98416d 100644 --- a/frontends/amiga/clipboard.c +++ b/frontends/amiga/clipboard.c @@ -89,11 +89,11 @@ void gui_start_selection(struct gui_window *g) if(!g->shared->win) return; if(nsoption_bool(kiosk_mode) == true) return; - OnMenu(g->shared->win, AMI_MENU_CLEAR); - OnMenu(g->shared->win, AMI_MENU_COPY); + ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_COPY, false); + ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_CLEAR, false); if (browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) - OnMenu(g->shared->win, AMI_MENU_CUT); + ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_CUT, false); } static char *ami_clipboard_cat_collection(struct CollectionItem *ci, LONG codeset, size_t *text_length) diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index 6627e8705..cb0f2fa89 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -1206,16 +1206,12 @@ static void ami_update_buttons(struct gui_window_2 *gwin) if(!browser_window_reload_available(gwin->gw->bw)) reload=TRUE; - if(nsoption_bool(kiosk_mode) == false) - { - if(gwin->tabs <= 1) - { + if(nsoption_bool(kiosk_mode) == false) { + if(gwin->tabs <= 1) { tabclose=TRUE; - OffMenu(gwin->win,AMI_MENU_CLOSETAB); - } - else - { - OnMenu(gwin->win,AMI_MENU_CLOSETAB); + ami_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, true); + } else { + ami_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, false); } } @@ -5262,7 +5258,7 @@ static void gui_window_place_caret(struct gui_window *g, int x, int y, int heigh g->c_h = height; if((nsoption_bool(kiosk_mode) == false)) - OnMenu(g->shared->win, AMI_MENU_PASTE); + ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, false); } static void gui_window_remove_caret(struct gui_window *g) @@ -5271,7 +5267,7 @@ static void gui_window_remove_caret(struct gui_window *g) if(g->c_h == 0) return; if((nsoption_bool(kiosk_mode) == false)) - OffMenu(g->shared->win, AMI_MENU_PASTE); + ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, true); ami_do_redraw_limits(g, g->bw, false, g->c_x, g->c_y, g->c_x + g->c_w + 1, g->c_y + g->c_h + 1); diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 3595f9606..3d2f293b9 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -1175,6 +1175,120 @@ static nserror ami_menu_scan(struct ami_menu_data **md) return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); } +#ifdef __amigaos4__ +void ami_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, bool disable) +{ + ULONG disable_state = MS_DISABLED; + + if(disable == false) { + disable_state = 0; + } + + IDoMethod(menu, MM_SETSTATE, 0, item, MS_DISABLED, disable_state); +} +#endif + +static ULONG ami_menu_number(int item) +{ + /* horrible, horrible, horrible */ + ULONG menu_num; + + switch(item) { + case M_SAVETXT: + menu_num = FULLMENUNUM(0,4,1); + break; + + case M_SAVECOMP: + menu_num = FULLMENUNUM(0,4,2); + break; + + case M_SAVEIFF: + menu_num = FULLMENUNUM(0,4,3); + break; +#ifdef WITH_PDF_EXPORT: + case M_SAVEPDF: + menu_num = FULLMENUNUM(0,4,4); + break; +#endif + case M_CLOSETAB: + menu_num = FULLMENUNUM(0,8,0); + break; + + case M_CUT: + menu_num = FULLMENUNUM(1,0,0); + break; + + case M_COPY: + menu_num = FULLMENUNUM(1,1,0); + break; + + case M_PASTE: + menu_num = FULLMENUNUM(1,2,0); + break; + + case M_SELALL: + menu_num = FULLMENUNUM(1,4,0); + break; + + case M_CLEAR: + menu_num = FULLMENUNUM(1,5,0); + break; + + case M_UNDO: + menu_num = FULLMENUNUM(1,8,0); + break; + + case M_REDO: + menu_num = FULLMENUNUM(1,9,0); + break; + + case M_FIND: + menu_num = FULLMENUNUM(2,0,0); + break; + + case M_IMGFORE: + menu_num = FULLMENUNUM(2,8,0); + break; + + case M_IMGBACK: + menu_num = FULLMENUNUM(2,8,1); + break; + + case M_JS: + menu_num = FULLMENUNUM(2,9,0); + break; + + default: + LOG("WARNING: Unrecognised menu item %d", item); + menu_num = 0; + break; + } + + return menu_num; +} + +static void ami_menu_set_disabled_gt(struct Window *win, struct Menu *menu, int item, bool disable) +{ + ULONG menu_num = ami_menu_number(item); + + if(disable == false) { + OnMenu(win, menu_num); + } else { + OffMenu(win, menu_num); + } +} + +void ami_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ + return ami_menu_set_disabled_mc(win, menu, item, disable); +#endif + } else { + return ami_menu_set_disabled_gt(win, menu, item, disable); + } +} + void ami_menu_update_checked(struct gui_window_2 *gwin) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { @@ -1187,26 +1301,26 @@ void ami_menu_update_checked(struct gui_window_2 *gwin) GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); if(!menustrip) return; if(nsoption_bool(enable_javascript) == true) { - if((ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; + if((ItemAddress(menustrip, ami_menu_number(M_JS))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_menu_number(M_JS))->Flags ^= CHECKED; } else { - if(ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED; + if(ItemAddress(menustrip, ami_menu_number(M_JS))->Flags & CHECKED) + ItemAddress(menustrip, ami_menu_number(M_JS))->Flags ^= CHECKED; } if(nsoption_bool(foreground_images) == true) { - if((ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; + if((ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags ^= CHECKED; } else { - if(ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= CHECKED; + if(ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags & CHECKED) + ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags ^= CHECKED; } if(nsoption_bool(background_images) == true) { - if((ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) == 0) - ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; + if((ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags ^= CHECKED; } else { - if(ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) - ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= CHECKED; + if(ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags & CHECKED) + ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags ^= CHECKED; } ResetMenuStrip(gwin->win, menustrip); @@ -1220,10 +1334,10 @@ void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c) if(content_get_type(c) <= CONTENT_CSS) { - OnMenu(win,AMI_MENU_SAVEAS_TEXT); - OnMenu(win,AMI_MENU_SAVEAS_COMPLETE); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, false); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, false); #ifdef WITH_PDF_EXPORT - OnMenu(win,AMI_MENU_SAVEAS_PDF); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, false); #endif #if 0 if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) { @@ -1244,28 +1358,29 @@ void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c) else OffMenu(win,AMI_MENU_PASTE); #else - OnMenu(win,AMI_MENU_CUT); - OnMenu(win,AMI_MENU_COPY); - OnMenu(win,AMI_MENU_PASTE); - OnMenu(win,AMI_MENU_CLEAR); + ami_menu_set_disabled(win, g->shared->imenu, M_CUT, false); + ami_menu_set_disabled(win, g->shared->imenu, M_COPY, false); + ami_menu_set_disabled(win, g->shared->imenu, M_PASTE, false); + ami_menu_set_disabled(win, g->shared->imenu, M_CLEAR, false); #endif - OnMenu(win,AMI_MENU_SELECTALL); - OnMenu(win,AMI_MENU_FIND); - OffMenu(win,AMI_MENU_SAVEAS_IFF); + ami_menu_set_disabled(win, g->shared->imenu, M_SELALL, false); + ami_menu_set_disabled(win, g->shared->imenu, M_FIND, false); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); } else { - OffMenu(win,AMI_MENU_CUT); - OffMenu(win,AMI_MENU_PASTE); - OffMenu(win,AMI_MENU_CLEAR); + ami_menu_set_disabled(win, g->shared->imenu, M_CUT, true); + ami_menu_set_disabled(win, g->shared->imenu, M_PASTE, true); + ami_menu_set_disabled(win, g->shared->imenu, M_CLEAR, true); - OffMenu(win,AMI_MENU_SAVEAS_TEXT); - OffMenu(win,AMI_MENU_SAVEAS_COMPLETE); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, true); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, true); #ifdef WITH_PDF_EXPORT - OffMenu(win,AMI_MENU_SAVEAS_PDF); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, true); #endif - OffMenu(win,AMI_MENU_SELECTALL); - OffMenu(win,AMI_MENU_FIND); + + ami_menu_set_disabled(win, g->shared->imenu, M_SELALL, true); + ami_menu_set_disabled(win, g->shared->imenu, M_FIND, true); #ifdef WITH_NS_SVG if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true)) @@ -1273,13 +1388,13 @@ void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c) if(content_get_bitmap(c)) #endif { - OnMenu(win,AMI_MENU_COPY); - OnMenu(win,AMI_MENU_SAVEAS_IFF); + ami_menu_set_disabled(win, g->shared->imenu, M_COPY, false); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, false); } else { - OffMenu(win,AMI_MENU_COPY); - OffMenu(win,AMI_MENU_SAVEAS_IFF); + ami_menu_set_disabled(win, g->shared->imenu, M_COPY, true); + ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); } } } diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h index ad0e96d93..43f7e1e60 100644 --- a/frontends/amiga/menu.h +++ b/frontends/amiga/menu.h @@ -115,24 +115,6 @@ enum { * only used for freeing the UTF-8 converted menu labels */ #define AMI_MENU_MAX AMI_MENU_AREXX -/* The Intuition menu numbers of some menus we might need to modify */ -#define AMI_MENU_SAVEAS_TEXT FULLMENUNUM(0,4,1) -#define AMI_MENU_SAVEAS_COMPLETE FULLMENUNUM(0,4,2) -#define AMI_MENU_SAVEAS_IFF FULLMENUNUM(0,4,3) -#define AMI_MENU_SAVEAS_PDF FULLMENUNUM(0,4,4) -#define AMI_MENU_CLOSETAB FULLMENUNUM(0,8,0) -#define AMI_MENU_CUT FULLMENUNUM(1,0,0) -#define AMI_MENU_COPY FULLMENUNUM(1,1,0) -#define AMI_MENU_PASTE FULLMENUNUM(1,2,0) -#define AMI_MENU_SELECTALL FULLMENUNUM(1,4,0) -#define AMI_MENU_CLEAR FULLMENUNUM(1,5,0) -#define AMI_MENU_UNDO FULLMENUNUM(1,8,0) -#define AMI_MENU_REDO FULLMENUNUM(1,9,0) -#define AMI_MENU_FIND FULLMENUNUM(2,0,0) -#define AMI_MENU_FOREIMG FULLMENUNUM(2,8,0) -#define AMI_MENU_BACKIMG FULLMENUNUM(2,8,1) -#define AMI_MENU_JS FULLMENUNUM(2,9,0) - struct gui_window; struct gui_window_2; @@ -154,6 +136,11 @@ void ami_menu_update_checked(struct gui_window_2 *gwin); void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c); void ami_menu_free(struct gui_window_2 *gwin); +/** + * Set disabled state of a menu item + */ +void ami_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable); + /** * Sets that an item linked to a toggle menu item has been changed. */ -- cgit v1.2.3 From e4d6d9a972736bbea70eb0af62a430e77cc05ee5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 14 Jan 2017 21:04:51 +0000 Subject: Get selected state with MenuClass compatible abstraction --- frontends/amiga/menu.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 3d2f293b9..175fe1529 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -111,6 +111,25 @@ const char * const verdate; static nserror ami_menu_scan(struct ami_menu_data **md); void ami_menu_arexx_scan(struct ami_menu_data **md); +static bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) +{ + bool checked = false; + + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ + ULONG state; + struct ExtIntuiMessage *emsg = (struct ExtIntuiMessage *)msg; + + state = IDoMethod(menu, MM_GETSTATE, 0, emsg->eim_LongCode, MS_CHECKED); + if(state & MS_CHECKED) checked = true; +#endif + } else { + if(ItemAddress(menu, msg->Code)->Flags & CHECKED) checked = true; + } + + return checked; +} + void ami_menu_set_check_toggled(void) { ami_menu_check_toggled = true; @@ -378,8 +397,8 @@ HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) bool checked = false; GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; - + checked = ami_menu_get_selected(menustrip, msg); + nsoption_set_bool(foreground_images, checked); ami_menu_set_check_toggled(); } @@ -390,7 +409,7 @@ HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) bool checked = false; GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; + checked = ami_menu_get_selected(menustrip, msg); nsoption_set_bool(background_images, checked); ami_menu_set_check_toggled(); @@ -402,7 +421,7 @@ HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) bool checked = false; GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true; + checked = ami_menu_get_selected(menustrip, msg); nsoption_set_bool(enable_javascript, checked); ami_menu_set_check_toggled(); -- cgit v1.2.3 From b6f7ea536cececaa07fb2c46c129675d91167177 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 14 Jan 2017 23:47:00 +0000 Subject: Fix MenuClass menu creation --- frontends/amiga/cookies.c | 38 ++++---- frontends/amiga/history.c | 42 ++++---- frontends/amiga/hotlist.c | 50 +++++----- frontends/amiga/menu.c | 237 +++++++++++++++++++++++++--------------------- frontends/amiga/menu.h | 2 +- 5 files changed, 197 insertions(+), 172 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/cookies.c b/frontends/amiga/cookies.c index 74c89cbbe..17933d54d 100644 --- a/frontends/amiga/cookies.c +++ b/frontends/amiga/cookies.c @@ -239,38 +239,38 @@ HOOKF(void, ami_cookies_menu_item_edit_delete, APTR, window, struct IntuiMessage static void ami_cookies_menulabs(struct ami_menu_data **md) { - ami_menu_alloc_item(md, AMI_COOKIE_M_PROJECT, NM_TITLE, "Tree", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND, NM_ITEM, "Expand", 0, "TBImages:list_folderunfold", NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_ALL, NM_SUB, "All", '+', NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_PROJECT, NM_TITLE, "Tree", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND, NM_ITEM, "Expand", NULL, "TBImages:list_folderunfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_ALL, NM_SUB, "All", "+", NULL, ami_cookies_menu_item_project_expand_all, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_DOMAINS, NM_SUB, "Domains", 0, NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_DOMAINS, NM_SUB, "Domains", NULL, NULL, ami_cookies_menu_item_project_expand_domains, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_COOKIES, NM_SUB, "Cookies", 0, NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_COOKIES, NM_SUB, "Cookies", NULL, NULL, ami_cookies_menu_item_project_expand_cookies, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE, NM_ITEM, "Collapse", 0, "TBImages:list_folderfold", NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_ALL, NM_SUB, "All", '-', NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE, NM_ITEM, "Collapse", NULL, "TBImages:list_folderfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_ALL, NM_SUB, "All", "-", NULL, ami_cookies_menu_item_project_collapse_all, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_DOMAINS, NM_SUB, "Domains", 0, NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_DOMAINS, NM_SUB, "Domains", NULL, NULL, ami_cookies_menu_item_project_collapse_domains, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_COOKIES, NM_SUB, "Cookies", 0, NULL, + ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_COOKIES, NM_SUB, "Cookies", NULL, NULL, ami_cookies_menu_item_project_collapse_cookies, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", 0, "TBImages:list_hold", + ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", NULL, "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", 'K', "TBImages:list_cancel", + ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + 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); - ami_menu_alloc_item(md, AMI_COOKIE_M_SELECTALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE, + ami_menu_alloc_item(md, AMI_COOKIE_M_EDIT, NM_TITLE, "Edit", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_SELECTALL, NM_ITEM, "SelectAllNS", "A", NSA_SPACE, ami_cookies_menu_item_edit_select_all, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE, + ami_menu_alloc_item(md, AMI_COOKIE_M_CLEAR, NM_ITEM, "ClearNS", NULL, NSA_SPACE, ami_cookies_menu_item_edit_clear, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_DELETE, NM_ITEM, "TreeDelete", 0, "TBImages:list_delete", + ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_DELETE, NM_ITEM, "TreeDelete", "Del", "TBImages:list_delete", ami_cookies_menu_item_edit_delete, NULL, 0); - ami_menu_alloc_item(md, AMI_COOKIE_M_LAST, NM_END, NULL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_COOKIE_M_LAST, NM_END, NULL, NULL, NULL, NULL, NULL, 0); } static struct Menu * diff --git a/frontends/amiga/history.c b/frontends/amiga/history.c index b2a3cc02a..a1c6bf66a 100644 --- a/frontends/amiga/history.c +++ b/frontends/amiga/history.c @@ -308,41 +308,41 @@ HOOKF(void, ami_history_global_menu_item_edit_delete, APTR, window, struct Intui 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_menu_alloc_item(md, AMI_HISTORY_M_PROJECT, NM_TITLE, "Tree", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND, NM_ITEM, "Expand", NULL, "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_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_FOLDERS, NM_SUB, "Folders", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_LINKS, NM_SUB, "Links", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE, NM_ITEM, "Collapse", NULL, "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_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_FOLDERS, NM_SUB, "Folders", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_LINKS, NM_SUB, "Links", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", NULL, "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_menu_alloc_item(md, AMI_HISTORY_M_BAR_P3, NM_ITEM, NM_BARLABEL, NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_EDIT, NM_TITLE, "Edit", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_CLEAR, NM_ITEM, "ClearNS", NULL, 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_menu_alloc_item(md, AMI_HISTORY_M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HISTORY_M_DELETE, NM_ITEM, "TreeDelete", "Del", "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); + ami_menu_alloc_item(md, AMI_HISTORY_M_LAST, NM_END, NULL, NULL, NULL, NULL, NULL, 0); } static struct Menu * diff --git a/frontends/amiga/hotlist.c b/frontends/amiga/hotlist.c index 8aa181b50..6d6f7ce58 100644 --- a/frontends/amiga/hotlist.c +++ b/frontends/amiga/hotlist.c @@ -404,49 +404,49 @@ HOOKF(void, ami_hotlist_menu_item_edit_delete, APTR, window, struct IntuiMessage static void ami_hotlist_menulabs(struct ami_menu_data **md) { - ami_menu_alloc_item(md, AMI_HOTLIST_M_PROJECT, NM_TITLE, "Tree", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPORT, NM_ITEM, "TreeExport", 'S', "TBImages:list_save", + ami_menu_alloc_item(md, AMI_HOTLIST_M_PROJECT, NM_TITLE, "Tree", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPORT, NM_ITEM, "TreeExport", "S", "TBImages:list_save", ami_hotlist_menu_item_project_export, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND, NM_ITEM, "Expand", 0, "TBImages:list_folderunfold", NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_ALL, NM_SUB, "All", '+', NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND, NM_ITEM, "Expand", NULL, "TBImages:list_folderunfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_ALL, NM_SUB, "All", "+", NULL, ami_hotlist_menu_item_project_expand_all, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_FOLDERS, NM_SUB, "Folders", 0, NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_FOLDERS, NM_SUB, "Folders", NULL, NULL, ami_hotlist_menu_item_project_expand_folders, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_LINKS, NM_SUB, "Links", 0, NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_LINKS, NM_SUB, "Links", NULL, NULL, ami_hotlist_menu_item_project_expand_links, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE, NM_ITEM, "Collapse", 0, "TBImages:list_folderfold", NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_ALL, NM_SUB, "All", '-', NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE, NM_ITEM, "Collapse", NULL, "TBImages:list_folderfold", NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_ALL, NM_SUB, "All", "-", NULL, ami_hotlist_menu_item_project_collapse_all, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_FOLDERS, NM_SUB, "Folders", 0, NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_FOLDERS, NM_SUB, "Folders", NULL, NULL, ami_hotlist_menu_item_project_collapse_folders, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_LINKS, NM_SUB, "Links", 0, NULL, + ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_LINKS, NM_SUB, "Links", NULL, NULL, ami_hotlist_menu_item_project_collapse_links, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", 0, "TBImages:list_hold", + ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_SNAPSHOT, NM_ITEM, "SnapshotWindow", NULL, "TBImages:list_hold", ami_hotlist_menu_item_project_snapshot, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_CLOSE, NM_ITEM, "CloseWindow", 'K', "TBImages:list_cancel", + ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_CLOSE, NM_ITEM, "CloseWindow", "K", "TBImages:list_cancel", ami_hotlist_menu_item_project_close, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT, NM_TITLE, "Edit", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWFOLDER, NM_ITEM, "TreeNewFolder", 'N', "TBImages:list_drawer", + ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWFOLDER, NM_ITEM, "TreeNewFolder", "N", "TBImages:list_drawer", ami_hotlist_menu_item_edit_newfolder, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWLINK, NM_ITEM, "TreeNewLink", 0, "TBImages:list_favouriteadd", + ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWLINK, NM_ITEM, "TreeNewLink", NULL, "TBImages:list_favouriteadd", ami_hotlist_menu_item_edit_newlink, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT_EDIT, NM_ITEM, "TreeEdit", 'E', "TBImages:list_edit", + ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT_EDIT, NM_ITEM, "TreeEdit", "E", "TBImages:list_edit", ami_hotlist_menu_item_edit_edit, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_SELECTALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE, + ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_SELECTALL, NM_ITEM, "SelectAllNS", "A", NSA_SPACE, ami_hotlist_menu_item_edit_select_all, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE, + ami_menu_alloc_item(md, AMI_HOTLIST_M_CLEAR, NM_ITEM, "ClearNS", NULL, NSA_SPACE, ami_hotlist_menu_item_edit_clear, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_DELETE, NM_ITEM, "TreeDelete", 0, "TBImages:list_delete", + ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_DELETE, NM_ITEM, "TreeDelete", "Del", "TBImages:list_delete", ami_hotlist_menu_item_edit_delete, NULL, 0); - ami_menu_alloc_item(md, AMI_HOTLIST_M_LAST, NM_END, NULL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_HOTLIST_M_LAST, NM_END, NULL, NULL, NULL, NULL, NULL, 0); } static struct Menu * diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 175fe1529..253ab3c2e 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -92,7 +92,7 @@ enum { struct ami_menu_data { char *restrict menulab; Object *restrict menuobj; - char menukey; + char *restrict menukey; char *restrict menuicon; struct Hook menu_hook; UBYTE menutype; @@ -120,7 +120,7 @@ static bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) ULONG state; struct ExtIntuiMessage *emsg = (struct ExtIntuiMessage *)msg; - state = IDoMethod(menu, MM_GETSTATE, 0, emsg->eim_LongCode, MS_CHECKED); + state = IDoMethod((Object *)menu, MM_GETSTATE, 0, emsg->eim_LongCode, MS_CHECKED); if(state & MS_CHECKED) checked = true; #endif } else { @@ -571,7 +571,9 @@ static void ami_menu_free_labs(struct ami_menu_data **md, int max) for(i = 0; i <= max; i++) { if(md[i] == NULL) continue; - if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) { + if(md[i]->menulab && + (md[i]->menulab != NM_BARLABEL) && + (md[i]->menulab != ML_SEPARATOR)) { if(md[i]->menutype & MENU_IMAGE) { if(md[i]->menuobj) DisposeObject(md[i]->menuobj); } @@ -579,9 +581,11 @@ static void ami_menu_free_labs(struct ami_menu_data **md, int max) ami_utf8_free(md[i]->menulab); } + if(md[i]->menukey != NULL) free(md[i]->menukey); + md[i]->menulab = NULL; md[i]->menuobj = NULL; - md[i]->menukey = 0; + md[i]->menukey = NULL; md[i]->menutype = 0; free(md[i]); } @@ -593,7 +597,9 @@ void ami_free_menulabs(struct ami_menu_data **md) for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { if(md[i] == NULL) continue; - if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) { + if(md[i]->menulab && + (md[i]->menulab != NM_BARLABEL) && + (md[i]->menulab != ML_SEPARATOR)) { if(md[i]->menutype & MENU_IMAGE) { if(md[i]->menuobj) DisposeObject(md[i]->menuobj); } @@ -606,16 +612,18 @@ void ami_free_menulabs(struct ami_menu_data **md) } } + if(md[i]->menukey != NULL) free(md[i]->menukey); + md[i]->menulab = NULL; md[i]->menuobj = NULL; - md[i]->menukey = 0; + md[i]->menukey = NULL; md[i]->menutype = 0; free(md[i]); } } void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, - const char *restrict label, char key, const char *restrict icon, + const char *restrict label, const char *restrict key, const char *restrict icon, void *restrict func, void *restrict hookdata, UWORD flags) { char menu_icon[1024]; @@ -641,7 +649,7 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, } md[num]->menuicon = NULL; - if(key) md[num]->menukey = key; + if(key) md[num]->menukey = strdup(key); if(func) md[num]->menu_hook.h_Entry = (HOOKFUNC)func; if(hookdata) md[num]->menu_hook.h_Data = hookdata; @@ -673,111 +681,111 @@ static void ami_init_menulabs(struct ami_menu_data **md) if(nsoption_bool(background_images) == true) imgback_flags |= CHECKED; - ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_NEWWIN, NM_ITEM, "NewWindowNS", 'N', "TBImages:list_app", + ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_NEWWIN, NM_ITEM, "NewWindowNS", "N", "TBImages:list_app", ami_menu_item_project_newwin, NULL, 0); - ami_menu_alloc_item(md, M_NEWTAB, NM_ITEM, "NewTab", 'T', "TBImages:list_tab", + ami_menu_alloc_item(md, M_NEWTAB, NM_ITEM, "NewTab", "T", "TBImages:list_tab", ami_menu_item_project_newtab, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_OPEN, NM_ITEM, "OpenFile", 'O', "TBImages:list_folder_misc", + ami_menu_alloc_item(md, M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_OPEN, NM_ITEM, "OpenFile", "O", "TBImages:list_folder_misc", ami_menu_item_project_open, NULL, 0); - ami_menu_alloc_item(md, M_SAVEAS, NM_ITEM, "SaveAsNS", 0, "TBImages:list_saveas", NULL, NULL, 0); - ami_menu_alloc_item(md, M_SAVESRC, NM_SUB, "Source", 'S', NULL, + ami_menu_alloc_item(md, M_SAVEAS, NM_ITEM, "SaveAsNS", NULL, "TBImages:list_saveas", NULL, NULL, 0); + ami_menu_alloc_item(md, M_SAVESRC, NM_SUB, "Source", "S", NULL, ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 0); - ami_menu_alloc_item(md, M_SAVETXT, NM_SUB, "TextNS", 0, NULL, + ami_menu_alloc_item(md, M_SAVETXT, NM_SUB, "TextNS", NULL, NULL, ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0); - ami_menu_alloc_item(md, M_SAVECOMP, NM_SUB, "SaveCompNS", 0, NULL, + ami_menu_alloc_item(md, M_SAVECOMP, NM_SUB, "SaveCompNS", NULL, NULL, ami_menu_item_project_save, (void *)AMINS_SAVE_COMPLETE, 0); #ifdef WITH_PDF_EXPORT - ami_menu_alloc_item(md, M_SAVEPDF, NM_SUB, "PDFNS", 0, NULL, + ami_menu_alloc_item(md, M_SAVEPDF, NM_SUB, "PDFNS", NULL, NULL, ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0); #endif - ami_menu_alloc_item(md, M_SAVEIFF, NM_SUB, "IFF", 0, NULL, + ami_menu_alloc_item(md, M_SAVEIFF, NM_SUB, "IFF", NULL, NULL, ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0); - ami_menu_alloc_item(md, M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_PRINT, NM_ITEM, "PrintNS", 'P', "TBImages:list_print", + ami_menu_alloc_item(md, M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_PRINT, NM_ITEM, "PrintNS", "P", "TBImages:list_print", ami_menu_item_project_print, NULL, NM_ITEMDISABLED); - ami_menu_alloc_item(md, M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab", 'K', "TBImages:list_remove", + ami_menu_alloc_item(md, M_BAR_P3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab", "K", "TBImages:list_remove", ami_menu_item_project_closetab, NULL, 0); - ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow", 0, "TBImages:list_cancel", + ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow", NULL, "TBImages:list_cancel", ami_menu_item_project_closewin, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_ABOUT, NM_ITEM, "About", '?', "TBImages:list_info", + ami_menu_alloc_item(md, M_BAR_P4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_ABOUT, NM_ITEM, "About", "?", "TBImages:list_info", ami_menu_item_project_about, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P5, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_QUIT, NM_ITEM, "Quit", 'Q', "TBImages:list_warning", + ami_menu_alloc_item(md, M_BAR_P5, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_QUIT, NM_ITEM, "Quit", "Q", "TBImages:list_warning", ami_menu_item_project_quit, NULL, 0); - ami_menu_alloc_item(md, M_EDIT, NM_TITLE, "Edit", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_CUT, NM_ITEM, "CutNS", 'X', "TBImages:list_cut", + ami_menu_alloc_item(md, M_EDIT, NM_TITLE, "Edit", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_CUT, NM_ITEM, "CutNS", "X", "TBImages:list_cut", ami_menu_item_edit_cut, NULL, 0); - ami_menu_alloc_item(md, M_COPY, NM_ITEM, "CopyNS", 'C', "TBImages:list_copy", + ami_menu_alloc_item(md, M_COPY, NM_ITEM, "CopyNS", "C", "TBImages:list_copy", ami_menu_item_edit_copy, NULL, 0); - ami_menu_alloc_item(md, M_PASTE, NM_ITEM, "PasteNS", 'V', "TBImages:list_paste", + ami_menu_alloc_item(md, M_PASTE, NM_ITEM, "PasteNS", "V", "TBImages:list_paste", ami_menu_item_edit_paste, NULL, 0); - ami_menu_alloc_item(md, M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SELALL, NM_ITEM, "SelectAllNS", 'A', NSA_SPACE, + ami_menu_alloc_item(md, M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SELALL, NM_ITEM, "SelectAllNS", "A", NSA_SPACE, ami_menu_item_edit_selectall, NULL, 0); - ami_menu_alloc_item(md, M_CLEAR, NM_ITEM, "ClearNS", 0, NSA_SPACE, + ami_menu_alloc_item(md, M_CLEAR, NM_ITEM, "ClearNS", NULL, NSA_SPACE, ami_menu_item_edit_clearsel, NULL, 0); - ami_menu_alloc_item(md, M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_UNDO, NM_ITEM, "Undo", 'Z', "TBImages:list_undo", + ami_menu_alloc_item(md, M_BAR_E2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_UNDO, NM_ITEM, "Undo", "Z", "TBImages:list_undo", ami_menu_item_edit_undo, NULL, 0); - ami_menu_alloc_item(md, M_REDO, NM_ITEM, "Redo", 'Y', "TBImages:list_redo", + ami_menu_alloc_item(md, M_REDO, NM_ITEM, "Redo", "Y", "TBImages:list_redo", ami_menu_item_edit_redo, NULL, 0); - ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_FIND, NM_ITEM, "FindTextNS", 'F', "TBImages:list_search", + ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_FIND, NM_ITEM, "FindTextNS", "F", "TBImages:list_search", ami_menu_item_browser_find, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS", 0, "TBImages:list_history", + ami_menu_alloc_item(md, M_BAR_B1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS", NULL, "TBImages:list_history", ami_menu_item_browser_localhistory, NULL, 0); - ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS", 0, "TBImages:list_history", + ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS", NULL, "TBImages:list_history", ami_menu_item_browser_globalhistory, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B2, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_COOKIES, NM_ITEM, "ShowCookiesNS", 0, "TBImages:list_internet", + ami_menu_alloc_item(md, M_BAR_B2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_COOKIES, NM_ITEM, "ShowCookiesNS",NULL, "TBImages:list_internet", ami_menu_item_browser_cookies, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B3, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SCALE, NM_ITEM, "ScaleNS", 0, "TBImages:list_preview", NULL, NULL, 0); - ami_menu_alloc_item(md, M_SCALEDEC, NM_SUB, "ScaleDec", '-', "TBImages:list_zoom_out", + ami_menu_alloc_item(md, M_BAR_B3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SCALE, NM_ITEM, "ScaleNS", NULL, "TBImages:list_preview", NULL, NULL, 0); + ami_menu_alloc_item(md, M_SCALEDEC, NM_SUB, "ScaleDec", "-", "TBImages:list_zoom_out", ami_menu_item_browser_scale_decrease, NULL, 0); - ami_menu_alloc_item(md, M_SCALENRM, NM_SUB, "ScaleNorm", '=', "TBImages:list_zoom_100", + ami_menu_alloc_item(md, M_SCALENRM, NM_SUB, "ScaleNorm", "=", "TBImages:list_zoom_100", ami_menu_item_browser_scale_normal, NULL, 0); - ami_menu_alloc_item(md, M_SCALEINC, NM_SUB, "ScaleInc", '+', "TBImages:list_zoom_in", + ami_menu_alloc_item(md, M_SCALEINC, NM_SUB, "ScaleInc", "+", "TBImages:list_zoom_in", ami_menu_item_browser_scale_increase, NULL, 0); - ami_menu_alloc_item(md, M_IMAGES, NM_ITEM, "Images", 0, "TBImages:list_image", NULL, NULL, 0); - ami_menu_alloc_item(md, M_IMGFORE, NM_SUB, "ForeImg", 0, NULL, + ami_menu_alloc_item(md, M_IMAGES, NM_ITEM, "Images", NULL, "TBImages:list_image", NULL, NULL, 0); + ami_menu_alloc_item(md, M_IMGFORE, NM_SUB, "ForeImg", NULL, NULL, ami_menu_item_browser_foreimg, NULL, imgfore_flags); - ami_menu_alloc_item(md, M_IMGBACK, NM_SUB, "BackImg", 0, NULL, + ami_menu_alloc_item(md, M_IMGBACK, NM_SUB, "BackImg", NULL, NULL, ami_menu_item_browser_backimg, NULL, imgback_flags); - ami_menu_alloc_item(md, M_JS, NM_ITEM, "EnableJS", 0, NULL, + ami_menu_alloc_item(md, M_JS, NM_ITEM, "EnableJS", NULL, NULL, ami_menu_item_browser_enablejs, NULL, js_flags); - ami_menu_alloc_item(md, M_BAR_B4, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_REDRAW, NM_ITEM, "Redraw", 0, "TBImages:list_wand", + ami_menu_alloc_item(md, M_BAR_B4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_REDRAW, NM_ITEM, "Redraw", NULL, "TBImages:list_wand", ami_menu_item_browser_redraw, NULL, 0); - ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_HLADD, NM_ITEM, "HotlistAdd", 'B', "TBImages:list_favouriteadd", + 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_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, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_BAR_H1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_PREFS, NM_TITLE, "Settings", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_PREDIT, NM_ITEM, "SettingsEdit", 0, "TBImages:list_prefs", + 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", ami_menu_item_settings_edit, NULL, 0); - ami_menu_alloc_item(md, M_BAR_S1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, "TBImages:list_hold", + ami_menu_alloc_item(md, M_BAR_S1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",NULL, "TBImages:list_hold", ami_menu_item_settings_snapshot, NULL, 0); - ami_menu_alloc_item(md, M_PRSAVE, NM_ITEM, "SettingsSave", 0, "TBImages:list_use", + ami_menu_alloc_item(md, M_PRSAVE, NM_ITEM, "SettingsSave", NULL, "TBImages:list_use", ami_menu_item_settings_save, NULL, 0); - ami_menu_alloc_item(md, M_AREXX, NM_TITLE, "ARexx", 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_AREXXEX, NM_ITEM, "ARexxExecute",'E', "TBImages:list_arexx", + ami_menu_alloc_item(md, M_AREXX, NM_TITLE, "ARexx", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_AREXXEX, NM_ITEM, "ARexxExecute", "E", "TBImages:list_arexx", ami_menu_item_arexx_execute, NULL, 0); - ami_menu_alloc_item(md, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX, NM_END, NULL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_BAR_A1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX, NM_END, NULL, NULL, NULL, NULL, NULL, 0); } /* Menu refresh for hotlist */ @@ -858,7 +866,7 @@ static int ami_menu_calc_item_width(struct ami_menu_data **md, int j, struct Ras item_size += space_width; if(md[j]->menukey) { - item_size += TextLength(rp, &md[j]->menukey, 1); + item_size += TextLength(rp, md[j]->menukey, 1); item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY]; /**TODO: take account of the size of other imagery too */ @@ -876,53 +884,68 @@ static int ami_menu_calc_item_width(struct ami_menu_data **md, int j, struct Ras } #ifdef __amigaos4__ -static void ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_data **md, int level, int *i, int max) +static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_data **md, int level, int i, int max) { + int j; Object *menu_item = menu_parent; - ULONG item_type = T_ITEM; - - if(level == NM_TITLE) { - item_type = T_MENU; - } - while(*i <= max) { + for(j = i; j < max; j++) { + LOG("%d/%d", j, max); /* skip empty entries */ - if(md[*i] == NULL) continue; - if(md[*i]->menutype == NM_IGNORE) continue; - - if(md[*i]->menutype == level) { - menu_item = NewObject(NULL, "menuclass", - MA_Type, item_type, - MA_ID, *i, - MA_Label, md[*i]->menulab, - MA_Image, md[*i]->menuicon, - MA_Key, &md[*i]->menukey, - MA_UserData, &md[*i]->menu_hook, /* NB: Intentionally UserData */ - MA_Disabled, (md[*i]->flags & NM_ITEMDISABLED), - MA_Selected, (md[*i]->flags & CHECKED), - MA_Toggle, (md[*i]->flags & MENUTOGGLE), - TAG_DONE); + if(md[j] == NULL) continue; + if(md[j]->menutype == NM_IGNORE) continue; + + if(md[j]->menutype == level) { + if(md[j]->menulab == NM_BARLABEL) + md[j]->menulab = ML_SEPARATOR; + + if(level == NM_TITLE) { + menu_item = NewObject(NULL, "menuclass", + MA_Type, T_MENU, + MA_Label, md[j]->menulab, + TAG_DONE); + } else { + menu_item = NewObject(NULL, "menuclass", + MA_Type, T_ITEM, + MA_ID, j, + MA_Label, md[j]->menulab, + MA_Image, + BitMapObj, + IA_Scalable, TRUE, + BITMAP_Screen, scrn, + BITMAP_SourceFile, md[j]->menuicon, + BITMAP_Masking, TRUE, + BitMapEnd, + MA_Key, md[j]->menukey, + MA_UserData, &md[j]->menu_hook, /* NB: Intentionally UserData */ + MA_Disabled, (md[j]->flags & NM_ITEMDISABLED), + MA_Selected, (md[j]->flags & CHECKED), + MA_Toggle, (md[j]->flags & MENUTOGGLE), + TAG_DONE); + } + + LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent); IDoMethod(menu_parent, OM_ADDMEMBER, menu_item); - } else if (md[*i]->menutype > level) { - ami_menu_layout_mc_recursive(menu_item, md, md[*i]->menutype, i, max); + continue; + } else if (md[j]->menutype > level) { +LOG("rec"); + j = ami_menu_layout_mc_recursive(menu_item, md, md[j]->menutype, j, max); } else { +LOG("brk"); break; } - *i++; } - return; + return (j - 1); } static struct Menu *ami_menu_layout_mc(struct ami_menu_data **md, int max) { - int i = 0; - Object *menu_root = NewObject(NULL, "menuclass", MA_Type, T_ROOT, MA_FreeImage, FALSE, TAG_DONE); - ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, &i, max); + ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, 0, max); return (struct Menu *)menu_root; } @@ -1029,7 +1052,9 @@ static struct Menu *ami_menu_layout_gt(struct ami_menu_data **md, int max) else nm[i].nm_Label = md[i]->menulab; - if(md[i]->menukey) nm[i].nm_CommKey = &md[i]->menukey; + if((md[i]->menukey) && (strlen(md[i]->menukey) > 1)) { + nm[i].nm_CommKey = md[i]->menukey; + } nm[i].nm_Flags = md[i]->flags; if(md[i]->menu_hook.h_Entry) nm[i].nm_UserData = &md[i]->menu_hook; @@ -1125,7 +1150,7 @@ void ami_menu_arexx_scan(struct ami_menu_data **md) else menu_lab = ead->ed_Name; - ami_menu_alloc_item(md, item, NM_ITEM, menu_lab, 0, NSA_SPACE, + ami_menu_alloc_item(md, item, NM_ITEM, menu_lab, NULL, NSA_SPACE, ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name), 0); item++; @@ -1139,7 +1164,7 @@ void ami_menu_arexx_scan(struct ami_menu_data **md) UnLock(lock); } - ami_menu_alloc_item(md, item, NM_END, NULL, 0, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, item, NM_END, NULL, NULL, NULL, NULL, NULL, 0); } static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) @@ -1182,7 +1207,7 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char } ami_menu_alloc_item(md, item, type, title, - 0, icon, ami_menu_item_hotlist_entries, (void *)url, flags); + NULL, icon, ami_menu_item_hotlist_entries, (void *)url, flags); if(icon) FreeVec(icon); @@ -1195,7 +1220,7 @@ static nserror ami_menu_scan(struct ami_menu_data **md) } #ifdef __amigaos4__ -void ami_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, bool disable) +static void ami_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, bool disable) { ULONG disable_state = MS_DISABLED; @@ -1203,7 +1228,7 @@ void ami_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, b disable_state = 0; } - IDoMethod(menu, MM_SETSTATE, 0, item, MS_DISABLED, disable_state); + IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_DISABLED, disable_state); } #endif @@ -1224,7 +1249,7 @@ static ULONG ami_menu_number(int item) case M_SAVEIFF: menu_num = FULLMENUNUM(0,4,3); break; -#ifdef WITH_PDF_EXPORT: +#ifdef WITH_PDF_EXPORT case M_SAVEPDF: menu_num = FULLMENUNUM(0,4,4); break; diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h index 43f7e1e60..35a0ac735 100644 --- a/frontends/amiga/menu.h +++ b/frontends/amiga/menu.h @@ -123,7 +123,7 @@ void ami_menu_free_glyphs(void); /* generic menu alloc/free/layout */ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, - const char *restrict label, char key, const char *restrict icon, + const char *restrict label, const char *restrict key, const char *restrict icon, 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); -- cgit v1.2.3 From 24fed9d51ccf3e786e59983ae84b4f13e68b0ea4 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 00:22:37 +0000 Subject: Remove excess logging and fix user-added hotlist separator bars --- frontends/amiga/menu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 253ab3c2e..cfb3429bc 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -636,6 +636,7 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) { md[num]->menulab = NM_BARLABEL; + icon = NULL; } else { /* horrid non-generic stuff */ if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) { utf8_from_local_encoding(label, @@ -890,7 +891,6 @@ static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_dat Object *menu_item = menu_parent; for(j = i; j < max; j++) { - LOG("%d/%d", j, max); /* skip empty entries */ if(md[j] == NULL) continue; if(md[j]->menutype == NM_IGNORE) continue; @@ -924,14 +924,11 @@ static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_dat TAG_DONE); } - LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent); IDoMethod(menu_parent, OM_ADDMEMBER, menu_item); continue; } else if (md[j]->menutype > level) { -LOG("rec"); j = ami_menu_layout_mc_recursive(menu_item, md, md[j]->menutype, j, max); } else { -LOG("brk"); break; } } @@ -942,7 +939,7 @@ static struct Menu *ami_menu_layout_mc(struct ami_menu_data **md, int max) { Object *menu_root = NewObject(NULL, "menuclass", MA_Type, T_ROOT, - MA_FreeImage, FALSE, + MA_EmbeddedKey, FALSE, TAG_DONE); ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, 0, max); @@ -1109,7 +1106,7 @@ void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) struct Menu *ami_menu_create(struct gui_window_2 *gwin) { ami_init_menulabs(gwin->menu_data); - ami_menu_scan(gwin->menu_data); //\todo this needs to be MenuClass created + 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); -- cgit v1.2.3 From 52f98c9fb2b3dc04412ad25b7c24fa8cf357e78d Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 14:55:15 +0000 Subject: Share menuclass object with all browser windows --- frontends/amiga/gui.c | 1 - frontends/amiga/menu.c | 28 ++++++++++++++++++++++++++-- frontends/amiga/menu.h | 1 - 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index cb0f2fa89..8b389a041 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -4603,7 +4603,6 @@ static void gui_window_destroy(struct gui_window *g) DisposeObject((Object *)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_BACK]); DisposeObject((Object *)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_FORWARD]); ami_ctxmenu_release_hook(g->shared->ctxmenu_hook); - ami_free_menulabs(g->shared->menu_data); ami_menu_free(g->shared); free(g->shared->wintitle); diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index cfb3429bc..8a3ca8dc3 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -99,6 +99,9 @@ struct ami_menu_data { UWORD flags; }; +static struct Menu *restrict gui_menu = NULL; +static int gui_menu_count = 0; + static bool menu_quit = false; static bool ami_menu_check_toggled = false; static Object *restrict menu_glyph[NSA_GLYPH_MAX]; @@ -591,7 +594,7 @@ static void ami_menu_free_labs(struct ami_menu_data **md, int max) } } -void ami_free_menulabs(struct ami_menu_data **md) +static void ami_free_menulabs(struct ami_menu_data **md) { int i; @@ -1087,8 +1090,16 @@ struct Menu *ami_menu_layout(struct ami_menu_data **md, int max) void ami_menu_free(struct gui_window_2 *gwin) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - DisposeObject((Object *)gwin->imenu); // if we detach our menu from the window we need to do this manually + gui_menu_count--; + + if(gui_menu_count == 0) { + ami_free_menulabs(gwin->menu_data); + // if we detach our menu from the window we need to do this manually + DisposeObject((Object *)gui_menu); + gui_menu = NULL; + } } else { + ami_free_menulabs(gwin->menu_data); FreeMenus(gwin->imenu); } } @@ -1105,11 +1116,24 @@ void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) struct Menu *ami_menu_create(struct gui_window_2 *gwin) { + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + if(gui_menu != NULL) { + gwin->imenu = gui_menu; + gui_menu_count++; + return gwin->imenu; + } + } + 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++; + } + return gwin->imenu; } diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h index 35a0ac735..1bb13c472 100644 --- a/frontends/amiga/menu.h +++ b/frontends/amiga/menu.h @@ -129,7 +129,6 @@ 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); /* specific to browser windows */ -void ami_free_menulabs(struct ami_menu_data **md); struct Menu *ami_menu_create(struct gui_window_2 *gwin); void ami_menu_refresh(struct gui_window_2 *gwin); void ami_menu_update_checked(struct gui_window_2 *gwin); -- cgit v1.2.3 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/Makefile | 2 +- frontends/amiga/clipboard.c | 8 +- frontends/amiga/cookies.c | 1 + frontends/amiga/gui.c | 24 +- frontends/amiga/gui.h | 2 +- frontends/amiga/gui_menu.c | 1084 +++++++++++++++++++++++++++++++++++++++++ frontends/amiga/gui_menu.h | 153 ++++++ frontends/amiga/gui_options.c | 3 +- frontends/amiga/history.c | 1 + frontends/amiga/hotlist.c | 1 + frontends/amiga/menu.c | 1069 +--------------------------------------- frontends/amiga/menu.h | 134 +---- 12 files changed, 1292 insertions(+), 1190 deletions(-) create mode 100644 frontends/amiga/gui_menu.c create mode 100644 frontends/amiga/gui_menu.h (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/Makefile b/frontends/amiga/Makefile index 985a085fc..f57b4ef8a 100644 --- a/frontends/amiga/Makefile +++ b/frontends/amiga/Makefile @@ -46,7 +46,7 @@ S_FRONTEND := gui.c history.c hotlist.c schedule.c file.c \ stringview/stringview.c stringview/urlhistory.c rtg.c \ agclass/amigaguide_class.c os3support.c font_diskfont.c \ selectmenu.c hash/xxhash.c font_cache.c font_bullet.c \ - nsoption.c corewindow.c + nsoption.c corewindow.c gui_menu.c # This is the final source build list # Note this is deliberately *not* expanded here as common and image diff --git a/frontends/amiga/clipboard.c b/frontends/amiga/clipboard.c index 0fc98416d..27b801540 100644 --- a/frontends/amiga/clipboard.c +++ b/frontends/amiga/clipboard.c @@ -44,7 +44,7 @@ #include "amiga/gui.h" #include "amiga/iff_cset.h" #include "amiga/iff_dr2d.h" -#include "amiga/menu.h" +#include "amiga/gui_menu.h" #include "amiga/utf8.h" #define ID_UTF8 MAKE_ID('U','T','F','8') @@ -89,11 +89,11 @@ void gui_start_selection(struct gui_window *g) if(!g->shared->win) return; if(nsoption_bool(kiosk_mode) == true) return; - ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_COPY, false); - ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_CLEAR, false); + ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_COPY, false); + ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_CLEAR, false); if (browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) - ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_CUT, false); + ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_CUT, false); } static char *ami_clipboard_cat_collection(struct CollectionItem *ci, LONG codeset, size_t *text_length) diff --git a/frontends/amiga/cookies.c b/frontends/amiga/cookies.c index 17933d54d..877805cda 100644 --- a/frontends/amiga/cookies.c +++ b/frontends/amiga/cookies.c @@ -43,6 +43,7 @@ #include "amiga/cookies.h" #include "amiga/corewindow.h" #include "amiga/libs.h" +#include "amiga/menu.h" #include "amiga/utf8.h" enum { diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index 8b389a041..d660e9356 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -1209,9 +1209,9 @@ static void ami_update_buttons(struct gui_window_2 *gwin) if(nsoption_bool(kiosk_mode) == false) { if(gwin->tabs <= 1) { tabclose=TRUE; - ami_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, true); + ami_gui_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, true); } else { - ami_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, false); + ami_gui_menu_set_disabled(gwin->win, gwin->imenu, M_CLOSETAB, false); } } @@ -1637,7 +1637,7 @@ static void ami_gui_menu_update_all(void) if(node->Type == AMINS_WINDOW) { - ami_menu_update_checked(gwin); + ami_gui_menu_update_checked(gwin); } } while((node = nnode)); } @@ -1964,11 +1964,11 @@ static BOOL ami_handle_msg(void) } } while((node = nnode)); - if(ami_menu_quit_selected() == true) { + if(ami_gui_menu_quit_selected() == true) { ami_quit_netsurf(); } - if(ami_menu_get_check_toggled() == true) { + if(ami_gui_menu_get_check_toggled() == true) { ami_gui_menu_update_all(); } @@ -2903,7 +2903,7 @@ void ami_switch_tab(struct gui_window_2 *gwin, bool redraw) ami_plot_release_pens(gwin->shared_pens); ami_update_buttons(gwin); - ami_menu_update_disabled(gwin->gw, browser_window_get_content(gwin->gw->bw)); + ami_gui_menu_update_disabled(gwin->gw, browser_window_get_content(gwin->gw->bw)); if(redraw) { @@ -3336,7 +3336,7 @@ void ami_gui_hotlist_update_all(void) if(node->Type == AMINS_WINDOW) { ami_gui_hotlist_toolbar_update(gwin); - ami_menu_refresh(gwin); + //ami_gui_menu_refresh_hotlist(gwin); } } while((node = nnode)); } @@ -3985,7 +3985,7 @@ gui_window_create(struct browser_window *bw, iconifygadget = TRUE; LOG("Creating menu"); - struct Menu *menu = ami_menu_create(g->shared); + struct Menu *menu = ami_gui_menu_create(g->shared); NewList(&g->shared->tab_list); g->tab_node = AllocClickTabNode(TNA_Text,messages_get("NetSurf"), @@ -4603,7 +4603,7 @@ static void gui_window_destroy(struct gui_window *g) DisposeObject((Object *)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_BACK]); DisposeObject((Object *)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_FORWARD]); ami_ctxmenu_release_hook(g->shared->ctxmenu_hook); - ami_menu_free(g->shared); + ami_gui_menu_free(g->shared); free(g->shared->wintitle); ami_utf8_free(g->shared->status); @@ -5257,7 +5257,7 @@ static void gui_window_place_caret(struct gui_window *g, int x, int y, int heigh g->c_h = height; if((nsoption_bool(kiosk_mode) == false)) - ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, false); + ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, false); } static void gui_window_remove_caret(struct gui_window *g) @@ -5266,7 +5266,7 @@ static void gui_window_remove_caret(struct gui_window *g) if(g->c_h == 0) return; if((nsoption_bool(kiosk_mode) == false)) - ami_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, true); + ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_PASTE, true); ami_do_redraw_limits(g, g->bw, false, g->c_x, g->c_y, g->c_x + g->c_w + 1, g->c_y + g->c_h + 1); @@ -5290,7 +5290,7 @@ static void gui_window_new_content(struct gui_window *g) g->shared->oldv = 0; g->favicon = NULL; ami_plot_release_pens(g->shared->shared_pens); - ami_menu_update_disabled(g, c); + ami_gui_menu_update_disabled(g, c); ami_gui_update_hotlist_button(g->shared); ami_gui_scroller_update(g->shared); } diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h index a176df100..77f6839e5 100644 --- a/frontends/amiga/gui.h +++ b/frontends/amiga/gui.h @@ -28,7 +28,7 @@ #include "netsurf/window.h" #include "netsurf/mouse.h" -#include "amiga/menu.h" +#include "amiga/gui_menu.h" #include "amiga/object.h" #include "amiga/os3support.h" diff --git a/frontends/amiga/gui_menu.c b/frontends/amiga/gui_menu.c new file mode 100644 index 000000000..791182b7a --- /dev/null +++ b/frontends/amiga/gui_menu.c @@ -0,0 +1,1084 @@ +/* + * Copyright 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 . + */ + +#include "amiga/os3support.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#ifdef __amigaos4__ +#include +#include /* Needed for ExAll() */ +#endif + +#include +#ifdef __amigaos4__ +#include +#endif + +#include +#include +#include +#include +#include + +#include + +#include "utils/nsoption.h" +#include "utils/messages.h" +#include "utils/log.h" +#include "utils/utils.h" +#include "utils/nsurl.h" +#include "netsurf/browser_window.h" +#include "netsurf/mouse.h" +#include "netsurf/window.h" +#include "netsurf/content.h" +#include "netsurf/keypress.h" +#include "desktop/hotlist.h" +#include "desktop/version.h" + +#include "amiga/arexx.h" +#include "amiga/bitmap.h" +#include "amiga/clipboard.h" +#include "amiga/cookies.h" +#include "amiga/file.h" +#include "amiga/filetype.h" +#include "amiga/gui.h" +#include "amiga/gui_menu.h" +#include "amiga/gui_options.h" +#include "amiga/history.h" +#include "amiga/history_local.h" +#include "amiga/hotlist.h" +#include "amiga/libs.h" +#include "amiga/menu.h" +#include "amiga/misc.h" +#include "amiga/nsoption.h" +#include "amiga/print.h" +#include "amiga/search.h" +#include "amiga/theme.h" +#include "amiga/utf8.h" +#include "amiga/schedule.h" + +static struct Menu *restrict gui_menu = NULL; +static int gui_menu_count = 0; + +static bool ami_menu_check_toggled = false; +static bool menu_quit = false; + +const char * const netsurf_version; +const char * const verdate; + +static nserror ami_menu_scan(struct ami_menu_data **md); +void ami_menu_arexx_scan(struct ami_menu_data **md); + +/* + * The below functions are called automatically by window.class when menu items are selected. + */ + +HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *) +{ + nsurl *url; + nserror error; + + error = nsurl_create(nsoption_charp(homepage_url), &url); + if (error == NSERROR_OK) { + error = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + amiga_warn_user(messages_get_errorcode(error), 0); + } +} + +HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + ami_gui_new_blank_tab(gwin); +} + +HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_file_open(gwin); +} + +HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + ULONG type = (ULONG)hook->h_Data; + + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw)); +} + +HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_destroy(gwin->gw->bw); +} + +HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + gwin->closed = true; +} + +HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_set_pointer(gwin, GUI_POINTER_WAIT, false); + ami_print_ui(browser_window_get_content(gwin->gw->bw)); + ami_reset_pointer(gwin); +} + +HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + char *temp, *temp2; + int sel; + nsurl *url = NULL; + nserror error = NSERROR_OK; + + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_set_pointer(gwin, GUI_POINTER_WAIT, false); + + temp = ASPrintf("%s|%s|%s", messages_get("OK"), + messages_get("HelpCredits"), + messages_get("HelpLicence")); + + temp2 = ami_utf8_easy(temp); + FreeVec(temp); +#ifdef __amigaos4__ + sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, + TDR_TitleString, messages_get("NetSurf"), + TDR_Window, gwin->win, + TDR_GadgetString, temp2, + TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", + TDR_Arg1,netsurf_version, + TDR_Arg2,verdate, + TAG_DONE); +#else + struct EasyStruct about_req = { + sizeof(struct EasyStruct), + 0, + "NetSurf", + "NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", + temp2, + }; + + sel = EasyRequest(gwin->win, &about_req, NULL, netsurf_version, verdate); +#endif + free(temp2); + + if(sel == 2) { + error = nsurl_create("about:credits", &url); + } else if(sel == 0) { + error = nsurl_create("about:licence", &url); + } + + if(url) { + if (error == NSERROR_OK) { + error = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (error != NSERROR_OK) { + amiga_warn_user(messages_get_errorcode(error), 0); + } + } + + ami_reset_pointer(gwin); +} + +HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *) +{ + menu_quit = true; +} + +HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_CUT_SELECTION); +} + +HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *) +{ + struct bitmap *bm; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + if(browser_window_can_select(gwin->gw->bw)) { + browser_window_key_press(gwin->gw->bw, NS_KEY_COPY_SELECTION); + browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION); + } + else if((bm = content_get_bitmap(browser_window_get_content(gwin->gw->bw)))) { + /** @todo It should be checked that the lifetime of + * the objects containing the values returned (and the + * constness cast away) is safe. + */ + ami_bitmap_set_url(bm, browser_window_get_url(gwin->gw->bw)); + ami_bitmap_set_title(bm, browser_window_get_title(gwin->gw->bw)); + ami_easy_clipboard_bitmap(bm); + } +#ifdef WITH_NS_SVG + else if(ami_mime_compare(browser_window_get_content(gwin->gw->bw), "svg") == true) { + ami_easy_clipboard_svg(browser_window_get_content(gwin->gw->bw)); + } +#endif +} + +HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_PASTE); +} + +HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_SELECT_ALL); + gui_start_selection(gwin->gw); +} + +HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION); +} + +HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_UNDO); +} + +HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + browser_window_key_press(gwin->gw->bw, NS_KEY_REDO); +} + +HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_search_open(gwin->gw); +} + +HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_history_open(gwin->gw); +} + +HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) +{ + ami_history_global_present(); +} + +HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) +{ + ami_cookies_present(); +} + +HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) +{ + struct Menu *menustrip; + bool checked = false; + + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + checked = ami_menu_get_selected(menustrip, msg); + + nsoption_set_bool(foreground_images, checked); + ami_gui_menu_set_check_toggled(); +} + +HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) +{ + struct Menu *menustrip; + bool checked = false; + + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + checked = ami_menu_get_selected(menustrip, msg); + + nsoption_set_bool(background_images, checked); + ami_gui_menu_set_check_toggled(); +} + +HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) +{ + struct Menu *menustrip; + bool checked = false; + + GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); + checked = ami_menu_get_selected(menustrip, msg); + + nsoption_set_bool(enable_javascript, checked); + ami_gui_menu_set_check_toggled(); +} + +HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1); +} + +HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_gui_set_scale(gwin->gw, 1.0); +} + +HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1); +} + +HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + ami_schedule_redraw(gwin, true); + gwin->new_content = true; +} + +HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *) +{ + struct browser_window *bw; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + bw = gwin->gw->bw; + + if (bw == NULL || browser_window_has_content(bw) == false) + return; + + hotlist_add_url(browser_window_get_url(bw)); + ami_gui_update_hotlist_button(gwin); +} + +HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *) +{ + ami_hotlist_present(); +} + +HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *) +{ + nsurl *url = hook->h_Data; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + if(url == NULL) return; + + browser_window_navigate(gwin->gw->bw, + url, + NULL, + BW_NAVIGATE_HISTORY, + NULL, + NULL, + NULL); +} + +HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *) +{ + ami_gui_opts_open(); +} + +HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage *) +{ + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + nsoption_set_int(window_x, gwin->win->LeftEdge); + nsoption_set_int(window_y, gwin->win->TopEdge); + nsoption_set_int(window_width, gwin->win->Width); + nsoption_set_int(window_height, gwin->win->Height); +} + +HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *) +{ + ami_nsoption_write(); +} + +HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *) +{ + char *temp; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + if(AslRequestTags(filereq, + ASLFR_Window, gwin->win, + ASLFR_SleepWindow, TRUE, + ASLFR_TitleText, messages_get("NetSurf"), + ASLFR_Screen, scrn, + ASLFR_DoSaveMode, FALSE, + ASLFR_InitialDrawer, nsoption_charp(arexx_dir), + ASLFR_InitialPattern, "#?.nsrx", + TAG_DONE)) { + if((temp = malloc(1024))) { + strlcpy(temp, filereq->fr_Drawer, 1024); + AddPart(temp, filereq->fr_File, 1024); + ami_arexx_execute(temp); + free(temp); + } + } +} + +HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *) +{ + char *script = hook->h_Data; + char *temp; + struct gui_window_2 *gwin; + GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + + if(script) { + if((temp = malloc(1024))) { + BPTR lock; + if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { + DevNameFromLock(lock, temp, 1024, DN_FULLPATH); + AddPart(temp, script, 1024); + ami_arexx_execute(temp); + free(temp); + UnLock(lock); + } + } + } +} + +/* normal GUI-specific menu functions */ + +ULONG ami_gui_menu_number(int item) +{ + /* horrible, horrible, horrible */ + ULONG menu_num; + + switch(item) { + case M_SAVETXT: + menu_num = FULLMENUNUM(0,4,1); + break; + + case M_SAVECOMP: + menu_num = FULLMENUNUM(0,4,2); + break; + + case M_SAVEIFF: + menu_num = FULLMENUNUM(0,4,3); + break; +#ifdef WITH_PDF_EXPORT + case M_SAVEPDF: + menu_num = FULLMENUNUM(0,4,4); + break; +#endif + case M_CLOSETAB: + menu_num = FULLMENUNUM(0,8,0); + break; + + case M_CUT: + menu_num = FULLMENUNUM(1,0,0); + break; + + case M_COPY: + menu_num = FULLMENUNUM(1,1,0); + break; + + case M_PASTE: + menu_num = FULLMENUNUM(1,2,0); + break; + + case M_SELALL: + menu_num = FULLMENUNUM(1,4,0); + break; + + case M_CLEAR: + menu_num = FULLMENUNUM(1,5,0); + break; + + case M_UNDO: + menu_num = FULLMENUNUM(1,8,0); + break; + + case M_REDO: + menu_num = FULLMENUNUM(1,9,0); + break; + + case M_FIND: + menu_num = FULLMENUNUM(2,0,0); + break; + + case M_IMGFORE: + menu_num = FULLMENUNUM(2,8,0); + break; + + case M_IMGBACK: + menu_num = FULLMENUNUM(2,8,1); + break; + + case M_JS: + menu_num = FULLMENUNUM(2,9,0); + break; + + default: + LOG("WARNING: Unrecognised menu item %d", item); + menu_num = 0; + break; + } + + return menu_num; +} + +#ifdef __amigaos4__ +static void ami_gui_menu_set_checked_mc(struct Menu *menu, int item, bool check) +{ + ULONG check_state = MS_CHECKED; + + if(check == false) { + check_state = 0; + } + + IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_CHECKED, check_state); +} +#endif + +static void ami_gui_menu_set_checked_gt(struct Menu *menu, int item, bool check) +{ + if(check == true) { + if((ItemAddress(menu, ami_gui_menu_number(item))->Flags & CHECKED) == 0) + ItemAddress(menu, ami_gui_menu_number(item))->Flags ^= CHECKED; + } else { + if(ItemAddress(menu, ami_gui_menu_number(item))->Flags & CHECKED) + ItemAddress(menu, ami_gui_menu_number(item))->Flags ^= CHECKED; + } +} + +void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ + return ami_gui_menu_set_checked_mc(menu, item, check); +#endif + } else { + return ami_gui_menu_set_checked_gt(menu, item, check); + } +} + +#ifdef __amigaos4__ +static void ami_gui_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, bool disable) +{ + ULONG disable_state = MS_DISABLED; + + if(disable == false) { + disable_state = 0; + } + + IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_DISABLED, disable_state); +} +#endif + +static void ami_gui_menu_set_disabled_gt(struct Window *win, struct Menu *menu, int item, bool disable) +{ + ULONG menu_num = ami_gui_menu_number(item); + + if(disable == false) { + OnMenu(win, menu_num); + } else { + OffMenu(win, menu_num); + } +} + +void ami_gui_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { +#ifdef __amigaos4__ + return ami_gui_menu_set_disabled_mc(win, menu, item, disable); +#endif + } else { + return ami_gui_menu_set_disabled_gt(win, menu, item, disable); + } +} + + +void ami_gui_menu_update_checked(struct gui_window_2 *gwin) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + //needs re-writing for MenuClass + return; + } + + struct Menu *menustrip; + + GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); + if(!menustrip) return; + if(nsoption_bool(enable_javascript) == true) { + if((ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags & CHECKED) + ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags ^= CHECKED; + } + if(nsoption_bool(foreground_images) == true) { + if((ItemAddress(menustrip, ami_gui_menu_number(M_IMGFORE))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_gui_menu_number(M_IMGFORE))->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, ami_gui_menu_number(M_IMGFORE))->Flags & CHECKED) + ItemAddress(menustrip, ami_gui_menu_number(M_IMGFORE))->Flags ^= CHECKED; + } + + if(nsoption_bool(background_images) == true) { + if((ItemAddress(menustrip, ami_gui_menu_number(M_IMGBACK))->Flags & CHECKED) == 0) + ItemAddress(menustrip, ami_gui_menu_number(M_IMGBACK))->Flags ^= CHECKED; + } else { + if(ItemAddress(menustrip, ami_gui_menu_number(M_IMGBACK))->Flags & CHECKED) + ItemAddress(menustrip, ami_gui_menu_number(M_IMGBACK))->Flags ^= CHECKED; + } + + ResetMenuStrip(gwin->win, menustrip); +} + +void ami_gui_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c) +{ + struct Window *win = g->shared->win; + + if(nsoption_bool(kiosk_mode) == true) return; + + if(content_get_type(c) <= CONTENT_CSS) + { + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, false); +#ifdef WITH_PDF_EXPORT + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, false); +#endif +#if 0 + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) { + OnMenu(win,AMI_MENU_COPY); + OnMenu(win,AMI_MENU_CLEAR); + } else { + OffMenu(win,AMI_MENU_COPY); + OffMenu(win,AMI_MENU_CLEAR); + } + + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) + OnMenu(win,AMI_MENU_CUT); + else + OffMenu(win,AMI_MENU_CUT); + + if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE) + OnMenu(win,AMI_MENU_PASTE); + else + OffMenu(win,AMI_MENU_PASTE); +#else + ami_gui_menu_set_disabled(win, g->shared->imenu, M_CUT, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_COPY, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_PASTE, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_CLEAR, false); +#endif + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SELALL, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_FIND, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); + } + else + { + ami_gui_menu_set_disabled(win, g->shared->imenu, M_CUT, true); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_PASTE, true); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_CLEAR, true); + + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, true); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, true); +#ifdef WITH_PDF_EXPORT + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, true); +#endif + + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SELALL, true); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_FIND, true); + +#ifdef WITH_NS_SVG + if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true)) +#else + if(content_get_bitmap(c)) +#endif + { + ami_gui_menu_set_disabled(win, g->shared->imenu, M_COPY, false); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, false); + } + else + { + ami_gui_menu_set_disabled(win, g->shared->imenu, M_COPY, true); + ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); + } + } +} + +void ami_gui_menu_set_check_toggled(void) +{ + ami_menu_check_toggled = true; +} + +bool ami_gui_menu_get_check_toggled(void) +{ + bool check_toggled = ami_menu_check_toggled; + ami_menu_check_toggled = false; + return check_toggled; +} + +void ami_menu_arexx_scan(struct ami_menu_data **md) +{ + /**\todo Rewrite this to not use ExAll() **/ + int item = AMI_MENU_AREXX; + BPTR lock = 0; + UBYTE *buffer; + struct ExAllControl *ctrl; + char matchpatt[16]; + LONG cont; + struct ExAllData *ead; + char *menu_lab; + + if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { + if((buffer = malloc(1024))) { + if((ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL))) { + ctrl->eac_LastKey = 0; + + if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { + ctrl->eac_MatchString = (char *)&matchpatt; + } + + do { + cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); + if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; + if(!ctrl->eac_Entries) continue; + + for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { + if(item >= AMI_MENU_AREXX_MAX) continue; + if(EAD_IS_FILE(ead)) { + if(ead->ed_Comment[0] != '\0') + menu_lab = ead->ed_Comment; + else + menu_lab = ead->ed_Name; + + ami_menu_alloc_item(md, item, NM_ITEM, menu_lab, NULL, NSA_SPACE, + ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name), 0); + + item++; + } + } + } while(cont); + FreeDosObject(DOS_EXALLCONTROL,ctrl); + } + free(buffer); + } + UnLock(lock); + } + + ami_menu_alloc_item(md, item, NM_END, NULL, NULL, NULL, NULL, NULL, 0); +} + +static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) +{ + UBYTE type; + STRPTR icon; + UWORD flags = 0; + struct ami_menu_data **md = (struct ami_menu_data **)userdata; + + if(item >= AMI_MENU_HOTLIST_MAX) return false; + + switch(level) { + case 1: + type = NM_ITEM; + break; + case 2: + type = NM_SUB; + break; + default: + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + type = NM_SUB + (level - 2); + } else { + /* entries not at level 1 or 2 are not able to be added */ + return false; + } + break; + } + + if(is_folder == true) { + icon = ASPrintf("icons/directory.png"); + } else { + icon = ami_gui_get_cache_favicon_name(url, true); + if (icon == NULL) icon = ASPrintf("icons/content.png"); + } + + if(!LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + if((is_folder == true) && (type == NM_SUB)) { + flags = NM_ITEMDISABLED; + } + } + + ami_menu_alloc_item(md, item, type, title, + NULL, icon, ami_menu_item_hotlist_entries, (void *)url, flags); + + if(icon) FreeVec(icon); + + return true; +} + +static nserror ami_menu_scan(struct ami_menu_data **md) +{ + return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); +} + +static void ami_init_menulabs(struct ami_menu_data **md) +{ + UWORD js_flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(enable_javascript) == true) + js_flags |= CHECKED; + + UWORD imgfore_flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(foreground_images) == true) + imgfore_flags |= CHECKED; + + UWORD imgback_flags = CHECKIT | MENUTOGGLE; + if(nsoption_bool(background_images) == true) + imgback_flags |= CHECKED; + + ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_NEWWIN, NM_ITEM, "NewWindowNS", "N", "TBImages:list_app", + ami_menu_item_project_newwin, NULL, 0); + ami_menu_alloc_item(md, M_NEWTAB, NM_ITEM, "NewTab", "T", "TBImages:list_tab", + ami_menu_item_project_newtab, NULL, 0); + ami_menu_alloc_item(md, M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_OPEN, NM_ITEM, "OpenFile", "O", "TBImages:list_folder_misc", + ami_menu_item_project_open, NULL, 0); + ami_menu_alloc_item(md, M_SAVEAS, NM_ITEM, "SaveAsNS", NULL, "TBImages:list_saveas", NULL, NULL, 0); + ami_menu_alloc_item(md, M_SAVESRC, NM_SUB, "Source", "S", NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 0); + ami_menu_alloc_item(md, M_SAVETXT, NM_SUB, "TextNS", NULL, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0); + ami_menu_alloc_item(md, M_SAVECOMP, NM_SUB, "SaveCompNS", NULL, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_COMPLETE, 0); +#ifdef WITH_PDF_EXPORT + ami_menu_alloc_item(md, M_SAVEPDF, NM_SUB, "PDFNS", NULL, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0); +#endif + ami_menu_alloc_item(md, M_SAVEIFF, NM_SUB, "IFF", NULL, NULL, + ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0); + ami_menu_alloc_item(md, M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_PRINT, NM_ITEM, "PrintNS", "P", "TBImages:list_print", + ami_menu_item_project_print, NULL, NM_ITEMDISABLED); + ami_menu_alloc_item(md, M_BAR_P3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab", "K", "TBImages:list_remove", + ami_menu_item_project_closetab, NULL, 0); + ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow", NULL, "TBImages:list_cancel", + ami_menu_item_project_closewin, NULL, 0); + ami_menu_alloc_item(md, M_BAR_P4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_ABOUT, NM_ITEM, "About", "?", "TBImages:list_info", + ami_menu_item_project_about, NULL, 0); + ami_menu_alloc_item(md, M_BAR_P5, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_QUIT, NM_ITEM, "Quit", "Q", "TBImages:list_warning", + ami_menu_item_project_quit, NULL, 0); + + ami_menu_alloc_item(md, M_EDIT, NM_TITLE, "Edit", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_CUT, NM_ITEM, "CutNS", "X", "TBImages:list_cut", + ami_menu_item_edit_cut, NULL, 0); + ami_menu_alloc_item(md, M_COPY, NM_ITEM, "CopyNS", "C", "TBImages:list_copy", + ami_menu_item_edit_copy, NULL, 0); + ami_menu_alloc_item(md, M_PASTE, NM_ITEM, "PasteNS", "V", "TBImages:list_paste", + ami_menu_item_edit_paste, NULL, 0); + ami_menu_alloc_item(md, M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SELALL, NM_ITEM, "SelectAllNS", "A", NSA_SPACE, + ami_menu_item_edit_selectall, NULL, 0); + ami_menu_alloc_item(md, M_CLEAR, NM_ITEM, "ClearNS", NULL, NSA_SPACE, + ami_menu_item_edit_clearsel, NULL, 0); + ami_menu_alloc_item(md, M_BAR_E2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_UNDO, NM_ITEM, "Undo", "Z", "TBImages:list_undo", + ami_menu_item_edit_undo, NULL, 0); + ami_menu_alloc_item(md, M_REDO, NM_ITEM, "Redo", "Y", "TBImages:list_redo", + ami_menu_item_edit_redo, NULL, 0); + + ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_FIND, NM_ITEM, "FindTextNS", "F", "TBImages:list_search", + ami_menu_item_browser_find, NULL, 0); + ami_menu_alloc_item(md, M_BAR_B1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS", NULL, "TBImages:list_history", + ami_menu_item_browser_localhistory, NULL, 0); + ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS", NULL, "TBImages:list_history", + ami_menu_item_browser_globalhistory, NULL, 0); + ami_menu_alloc_item(md, M_BAR_B2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_COOKIES, NM_ITEM, "ShowCookiesNS",NULL, "TBImages:list_internet", + ami_menu_item_browser_cookies, NULL, 0); + ami_menu_alloc_item(md, M_BAR_B3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SCALE, NM_ITEM, "ScaleNS", NULL, "TBImages:list_preview", NULL, NULL, 0); + ami_menu_alloc_item(md, M_SCALEDEC, NM_SUB, "ScaleDec", "-", "TBImages:list_zoom_out", + ami_menu_item_browser_scale_decrease, NULL, 0); + ami_menu_alloc_item(md, M_SCALENRM, NM_SUB, "ScaleNorm", "=", "TBImages:list_zoom_100", + ami_menu_item_browser_scale_normal, NULL, 0); + ami_menu_alloc_item(md, M_SCALEINC, NM_SUB, "ScaleInc", "+", "TBImages:list_zoom_in", + ami_menu_item_browser_scale_increase, NULL, 0); + ami_menu_alloc_item(md, M_IMAGES, NM_ITEM, "Images", NULL, "TBImages:list_image", NULL, NULL, 0); + ami_menu_alloc_item(md, M_IMGFORE, NM_SUB, "ForeImg", NULL, NULL, + ami_menu_item_browser_foreimg, NULL, imgfore_flags); + ami_menu_alloc_item(md, M_IMGBACK, NM_SUB, "BackImg", NULL, NULL, + ami_menu_item_browser_backimg, NULL, imgback_flags); + ami_menu_alloc_item(md, M_JS, NM_ITEM, "EnableJS", NULL, NULL, + ami_menu_item_browser_enablejs, NULL, js_flags); + ami_menu_alloc_item(md, M_BAR_B4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_REDRAW, NM_ITEM, "Redraw", NULL, "TBImages:list_wand", + 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); + + 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", + ami_menu_item_settings_edit, NULL, 0); + ami_menu_alloc_item(md, M_BAR_S1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",NULL, "TBImages:list_hold", + ami_menu_item_settings_snapshot, NULL, 0); + ami_menu_alloc_item(md, M_PRSAVE, NM_ITEM, "SettingsSave", NULL, "TBImages:list_use", + ami_menu_item_settings_save, NULL, 0); + + ami_menu_alloc_item(md, M_AREXX, NM_TITLE, "ARexx", NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, M_AREXXEX, NM_ITEM, "ARexxExecute", "E", "TBImages:list_arexx", + ami_menu_item_arexx_execute, NULL, 0); + ami_menu_alloc_item(md, M_BAR_A1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); + ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX, NM_END, NULL, NULL, NULL, NULL, NULL, 0); +} + +struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + if(gui_menu != NULL) { + gwin->imenu = gui_menu; + gui_menu_count++; + return gwin->imenu; + } + } + + 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++; + } + + return gwin->imenu; +} + +static void ami_free_menulabs(struct ami_menu_data **md) +{ + int i; + + for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { + if(md[i] == NULL) continue; + if(md[i]->menulab && + (md[i]->menulab != NM_BARLABEL) && + (md[i]->menulab != ML_SEPARATOR)) { + if(md[i]->menutype & MENU_IMAGE) { + if(md[i]->menuobj) DisposeObject(md[i]->menuobj); + } + + ami_utf8_free(md[i]->menulab); + + if(i >= AMI_MENU_AREXX) { + if(md[i]->menu_hook.h_Data) free(md[i]->menu_hook.h_Data); + md[i]->menu_hook.h_Data = NULL; + } + } + + if(md[i]->menukey != NULL) free(md[i]->menukey); + + md[i]->menulab = NULL; + md[i]->menuobj = NULL; + md[i]->menukey = NULL; + md[i]->menutype = 0; + free(md[i]); + } +} + +void ami_gui_menu_free(struct gui_window_2 *gwin) +{ + if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { + gui_menu_count--; + + if(gui_menu_count == 0) { + ami_free_menulabs(gwin->menu_data); + // if we detach our menu from the window we need to do this manually + DisposeObject((Object *)gui_menu); + gui_menu = NULL; + } + } else { + ami_free_menulabs(gwin->menu_data); + FreeMenus(gwin->imenu); + } +} + +bool ami_gui_menu_quit_selected(void) +{ + return menu_quit; +} + 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 + diff --git a/frontends/amiga/gui_options.c b/frontends/amiga/gui_options.c index 698735bdc..b349e43c1 100755 --- a/frontends/amiga/gui_options.c +++ b/frontends/amiga/gui_options.c @@ -70,6 +70,7 @@ #include "amiga/font.h" #include "amiga/font_bullet.h" #include "amiga/gui.h" +#include "amiga/gui_menu.h" #include "amiga/gui_options.h" #include "amiga/help.h" #include "amiga/libs.h" @@ -2066,7 +2067,7 @@ static void ami_gui_opts_use(bool save) ami_font_savescanner(); /* just in case it has changed and been used only */ } - ami_menu_set_check_toggled(); + ami_gui_menu_set_check_toggled(); ami_update_pointer(gow->win, GUI_POINTER_DEFAULT); } diff --git a/frontends/amiga/history.c b/frontends/amiga/history.c index a1c6bf66a..12c306a9b 100644 --- a/frontends/amiga/history.c +++ b/frontends/amiga/history.c @@ -49,6 +49,7 @@ #include "amiga/file.h" #include "amiga/history.h" #include "amiga/libs.h" +#include "amiga/menu.h" #include "amiga/theme.h" #include "amiga/utf8.h" diff --git a/frontends/amiga/hotlist.c b/frontends/amiga/hotlist.c index 6d6f7ce58..008e45a24 100644 --- a/frontends/amiga/hotlist.c +++ b/frontends/amiga/hotlist.c @@ -49,6 +49,7 @@ #include "amiga/file.h" #include "amiga/hotlist.h" #include "amiga/libs.h" +#include "amiga/menu.h" #include "amiga/theme.h" #include "amiga/utf8.h" diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 8a3ca8dc3..6e33d5e05 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -21,16 +21,9 @@ #include #include -#include -#include -#include #include +#include #include -#include -#ifdef __amigaos4__ -#include -#include /* Needed for ExAll() */ -#endif #include #ifdef __amigaos4__ @@ -45,41 +38,13 @@ #include -#include "utils/nsoption.h" -#include "utils/messages.h" #include "utils/log.h" #include "utils/utils.h" -#include "utils/nsurl.h" -#include "netsurf/browser_window.h" -#include "netsurf/mouse.h" -#include "netsurf/window.h" -#include "netsurf/content.h" -#include "netsurf/keypress.h" -#include "desktop/hotlist.h" -#include "desktop/version.h" -#include "amiga/arexx.h" -#include "amiga/bitmap.h" -#include "amiga/clipboard.h" -#include "amiga/cookies.h" -#include "amiga/file.h" -#include "amiga/filetype.h" #include "amiga/gui.h" -#include "amiga/gui_options.h" -#include "amiga/history.h" -#include "amiga/history_local.h" -#include "amiga/hotlist.h" #include "amiga/libs.h" #include "amiga/menu.h" -#include "amiga/misc.h" -#include "amiga/nsoption.h" -#include "amiga/print.h" -#include "amiga/search.h" -#include "amiga/theme.h" #include "amiga/utf8.h" -#include "amiga/schedule.h" - -#define NSA_MAX_HOTLIST_MENU_LEN 100 enum { NSA_GLYPH_SUBMENU, @@ -89,32 +54,13 @@ enum { NSA_GLYPH_MAX }; -struct ami_menu_data { - char *restrict menulab; - Object *restrict menuobj; - char *restrict menukey; - char *restrict menuicon; - struct Hook menu_hook; - UBYTE menutype; - UWORD flags; -}; - -static struct Menu *restrict gui_menu = NULL; -static int gui_menu_count = 0; +#define NSA_MAX_HOTLIST_MENU_LEN 100 -static bool menu_quit = false; -static bool ami_menu_check_toggled = false; static Object *restrict menu_glyph[NSA_GLYPH_MAX]; static int menu_glyph_width[NSA_GLYPH_MAX]; static bool menu_glyphs_loaded = false; -const char * const netsurf_version; -const char * const verdate; - -static nserror ami_menu_scan(struct ami_menu_data **md); -void ami_menu_arexx_scan(struct ami_menu_data **md); - -static bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) +bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) { bool checked = false; @@ -133,495 +79,35 @@ static bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg) return checked; } -void ami_menu_set_check_toggled(void) -{ - ami_menu_check_toggled = true; -} - -bool ami_menu_get_check_toggled(void) -{ - bool check_toggled = ami_menu_check_toggled; - ami_menu_check_toggled = false; - return check_toggled; -} - -bool ami_menu_quit_selected(void) -{ - return menu_quit; -} - -/* - * The below functions are called automatically by window.class when menu items are selected. - */ - -HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *) -{ - nsurl *url; - nserror error; - - error = nsurl_create(nsoption_charp(homepage_url), &url); - if (error == NSERROR_OK) { - error = browser_window_create(BW_CREATE_HISTORY, - url, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - amiga_warn_user(messages_get_errorcode(error), 0); - } -} - -HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - ami_gui_new_blank_tab(gwin); -} - -HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_file_open(gwin); -} - -HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - ULONG type = (ULONG)hook->h_Data; - - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw)); -} - -HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_destroy(gwin->gw->bw); -} - -HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - gwin->closed = true; -} - -HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_set_pointer(gwin, GUI_POINTER_WAIT, false); - ami_print_ui(browser_window_get_content(gwin->gw->bw)); - ami_reset_pointer(gwin); -} - -HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - char *temp, *temp2; - int sel; - nsurl *url = NULL; - nserror error = NSERROR_OK; - - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_set_pointer(gwin, GUI_POINTER_WAIT, false); - - temp = ASPrintf("%s|%s|%s", messages_get("OK"), - messages_get("HelpCredits"), - messages_get("HelpLicence")); - - temp2 = ami_utf8_easy(temp); - FreeVec(temp); -#ifdef __amigaos4__ - sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO, - TDR_TitleString, messages_get("NetSurf"), - TDR_Window, gwin->win, - TDR_GadgetString, temp2, - TDR_FormatString,"NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", - TDR_Arg1,netsurf_version, - TDR_Arg2,verdate, - TAG_DONE); -#else - struct EasyStruct about_req = { - sizeof(struct EasyStruct), - 0, - "NetSurf", - "NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org", - temp2, - }; - - sel = EasyRequest(gwin->win, &about_req, NULL, netsurf_version, verdate); -#endif - free(temp2); - - if(sel == 2) { - error = nsurl_create("about:credits", &url); - } else if(sel == 0) { - error = nsurl_create("about:licence", &url); - } - - if(url) { - if (error == NSERROR_OK) { - error = browser_window_create(BW_CREATE_HISTORY, - url, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - if (error != NSERROR_OK) { - amiga_warn_user(messages_get_errorcode(error), 0); +/* menu creation code */ +static void ami_menu_free_lab_item(struct ami_menu_data **md, int i) +{ + if(md[i] == NULL) return; + if(md[i]->menulab && + (md[i]->menulab != NM_BARLABEL) && + (md[i]->menulab != ML_SEPARATOR)) { + if(md[i]->menutype & MENU_IMAGE) { + if(md[i]->menuobj) DisposeObject(md[i]->menuobj); } - } - ami_reset_pointer(gwin); -} - -HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *) -{ - menu_quit = true; -} - -HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, NS_KEY_CUT_SELECTION); -} - -HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *) -{ - struct bitmap *bm; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - if(browser_window_can_select(gwin->gw->bw)) { - browser_window_key_press(gwin->gw->bw, NS_KEY_COPY_SELECTION); - browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION); - } - else if((bm = content_get_bitmap(browser_window_get_content(gwin->gw->bw)))) { - /** @todo It should be checked that the lifetime of - * the objects containing the values returned (and the - * constness cast away) is safe. - */ - ami_bitmap_set_url(bm, browser_window_get_url(gwin->gw->bw)); - ami_bitmap_set_title(bm, browser_window_get_title(gwin->gw->bw)); - ami_easy_clipboard_bitmap(bm); - } -#ifdef WITH_NS_SVG - else if(ami_mime_compare(browser_window_get_content(gwin->gw->bw), "svg") == true) { - ami_easy_clipboard_svg(browser_window_get_content(gwin->gw->bw)); + ami_utf8_free(md[i]->menulab); } -#endif -} - -HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, NS_KEY_PASTE); -} -HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, NS_KEY_SELECT_ALL); - gui_start_selection(gwin->gw); -} - -HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); + if(md[i]->menukey != NULL) free(md[i]->menukey); - browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION); + md[i]->menulab = NULL; + md[i]->menuobj = NULL; + md[i]->menukey = NULL; + md[i]->menutype = 0; + free(md[i]); } -HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, NS_KEY_UNDO); -} - -HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - browser_window_key_press(gwin->gw->bw, NS_KEY_REDO); -} - -HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_search_open(gwin->gw); -} - -HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_history_open(gwin->gw); -} - -HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct IntuiMessage *) -{ - ami_history_global_present(); -} - -HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *) -{ - ami_cookies_present(); -} - -HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *) -{ - struct Menu *menustrip; - bool checked = false; - - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - checked = ami_menu_get_selected(menustrip, msg); - - nsoption_set_bool(foreground_images, checked); - ami_menu_set_check_toggled(); -} - -HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *) -{ - struct Menu *menustrip; - bool checked = false; - - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - checked = ami_menu_get_selected(menustrip, msg); - - nsoption_set_bool(background_images, checked); - ami_menu_set_check_toggled(); -} - -HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage *) -{ - struct Menu *menustrip; - bool checked = false; - - GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip); - checked = ami_menu_get_selected(menustrip, msg); - - nsoption_set_bool(enable_javascript, checked); - ami_menu_set_check_toggled(); -} - -HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1); -} - -HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_gui_set_scale(gwin->gw, 1.0); -} - -HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1); -} - -HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - ami_schedule_redraw(gwin, true); - gwin->new_content = true; -} - -HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *) -{ - struct browser_window *bw; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - bw = gwin->gw->bw; - - if (bw == NULL || browser_window_has_content(bw) == false) - return; - - hotlist_add_url(browser_window_get_url(bw)); - ami_gui_update_hotlist_button(gwin); -} - -HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *) -{ - ami_hotlist_present(); -} - -HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *) -{ - nsurl *url = hook->h_Data; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - if(url == NULL) return; - - browser_window_navigate(gwin->gw->bw, - url, - NULL, - BW_NAVIGATE_HISTORY, - NULL, - NULL, - NULL); -} - -HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *) -{ - ami_gui_opts_open(); -} - -HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage *) -{ - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - nsoption_set_int(window_x, gwin->win->LeftEdge); - nsoption_set_int(window_y, gwin->win->TopEdge); - nsoption_set_int(window_width, gwin->win->Width); - nsoption_set_int(window_height, gwin->win->Height); -} - -HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *) -{ - ami_nsoption_write(); -} - -HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *) -{ - char *temp; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - if(AslRequestTags(filereq, - ASLFR_Window, gwin->win, - ASLFR_SleepWindow, TRUE, - ASLFR_TitleText, messages_get("NetSurf"), - ASLFR_Screen, scrn, - ASLFR_DoSaveMode, FALSE, - ASLFR_InitialDrawer, nsoption_charp(arexx_dir), - ASLFR_InitialPattern, "#?.nsrx", - TAG_DONE)) { - if((temp = malloc(1024))) { - strlcpy(temp, filereq->fr_Drawer, 1024); - AddPart(temp, filereq->fr_File, 1024); - ami_arexx_execute(temp); - free(temp); - } - } -} - -HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *) -{ - char *script = hook->h_Data; - char *temp; - struct gui_window_2 *gwin; - GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin); - - if(script) { - if((temp = malloc(1024))) { - BPTR lock; - if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { - DevNameFromLock(lock, temp, 1024, DN_FULLPATH); - AddPart(temp, script, 1024); - ami_arexx_execute(temp); - free(temp); - UnLock(lock); - } - } - } -} - - -/* menu creation code */ static void ami_menu_free_labs(struct ami_menu_data **md, int max) { int i; for(i = 0; i <= max; i++) { - if(md[i] == NULL) continue; - if(md[i]->menulab && - (md[i]->menulab != NM_BARLABEL) && - (md[i]->menulab != ML_SEPARATOR)) { - if(md[i]->menutype & MENU_IMAGE) { - if(md[i]->menuobj) DisposeObject(md[i]->menuobj); - } - - ami_utf8_free(md[i]->menulab); - } - - if(md[i]->menukey != NULL) free(md[i]->menukey); - - md[i]->menulab = NULL; - md[i]->menuobj = NULL; - md[i]->menukey = NULL; - md[i]->menutype = 0; - free(md[i]); - } -} - -static void ami_free_menulabs(struct ami_menu_data **md) -{ - int i; - - for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { - if(md[i] == NULL) continue; - if(md[i]->menulab && - (md[i]->menulab != NM_BARLABEL) && - (md[i]->menulab != ML_SEPARATOR)) { - if(md[i]->menutype & MENU_IMAGE) { - if(md[i]->menuobj) DisposeObject(md[i]->menuobj); - } - - ami_utf8_free(md[i]->menulab); - - if(i >= AMI_MENU_AREXX) { - if(md[i]->menu_hook.h_Data) free(md[i]->menu_hook.h_Data); - md[i]->menu_hook.h_Data = NULL; - } - } - - if(md[i]->menukey != NULL) free(md[i]->menukey); - - md[i]->menulab = NULL; - md[i]->menuobj = NULL; - md[i]->menukey = NULL; - md[i]->menutype = 0; - free(md[i]); + ami_menu_free_lab_item(md, i); } } @@ -671,154 +157,6 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, #endif } -static void ami_init_menulabs(struct ami_menu_data **md) -{ - UWORD js_flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(enable_javascript) == true) - js_flags |= CHECKED; - - UWORD imgfore_flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(foreground_images) == true) - imgfore_flags |= CHECKED; - - UWORD imgback_flags = CHECKIT | MENUTOGGLE; - if(nsoption_bool(background_images) == true) - imgback_flags |= CHECKED; - - ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_NEWWIN, NM_ITEM, "NewWindowNS", "N", "TBImages:list_app", - ami_menu_item_project_newwin, NULL, 0); - ami_menu_alloc_item(md, M_NEWTAB, NM_ITEM, "NewTab", "T", "TBImages:list_tab", - ami_menu_item_project_newtab, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_OPEN, NM_ITEM, "OpenFile", "O", "TBImages:list_folder_misc", - ami_menu_item_project_open, NULL, 0); - ami_menu_alloc_item(md, M_SAVEAS, NM_ITEM, "SaveAsNS", NULL, "TBImages:list_saveas", NULL, NULL, 0); - ami_menu_alloc_item(md, M_SAVESRC, NM_SUB, "Source", "S", NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 0); - ami_menu_alloc_item(md, M_SAVETXT, NM_SUB, "TextNS", NULL, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0); - ami_menu_alloc_item(md, M_SAVECOMP, NM_SUB, "SaveCompNS", NULL, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_COMPLETE, 0); -#ifdef WITH_PDF_EXPORT - ami_menu_alloc_item(md, M_SAVEPDF, NM_SUB, "PDFNS", NULL, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0); -#endif - ami_menu_alloc_item(md, M_SAVEIFF, NM_SUB, "IFF", NULL, NULL, - ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0); - ami_menu_alloc_item(md, M_BAR_P2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_PRINT, NM_ITEM, "PrintNS", "P", "TBImages:list_print", - ami_menu_item_project_print, NULL, NM_ITEMDISABLED); - ami_menu_alloc_item(md, M_BAR_P3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab", "K", "TBImages:list_remove", - ami_menu_item_project_closetab, NULL, 0); - ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow", NULL, "TBImages:list_cancel", - ami_menu_item_project_closewin, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_ABOUT, NM_ITEM, "About", "?", "TBImages:list_info", - ami_menu_item_project_about, NULL, 0); - ami_menu_alloc_item(md, M_BAR_P5, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_QUIT, NM_ITEM, "Quit", "Q", "TBImages:list_warning", - ami_menu_item_project_quit, NULL, 0); - - ami_menu_alloc_item(md, M_EDIT, NM_TITLE, "Edit", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_CUT, NM_ITEM, "CutNS", "X", "TBImages:list_cut", - ami_menu_item_edit_cut, NULL, 0); - ami_menu_alloc_item(md, M_COPY, NM_ITEM, "CopyNS", "C", "TBImages:list_copy", - ami_menu_item_edit_copy, NULL, 0); - ami_menu_alloc_item(md, M_PASTE, NM_ITEM, "PasteNS", "V", "TBImages:list_paste", - ami_menu_item_edit_paste, NULL, 0); - ami_menu_alloc_item(md, M_BAR_E1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SELALL, NM_ITEM, "SelectAllNS", "A", NSA_SPACE, - ami_menu_item_edit_selectall, NULL, 0); - ami_menu_alloc_item(md, M_CLEAR, NM_ITEM, "ClearNS", NULL, NSA_SPACE, - ami_menu_item_edit_clearsel, NULL, 0); - ami_menu_alloc_item(md, M_BAR_E2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_UNDO, NM_ITEM, "Undo", "Z", "TBImages:list_undo", - ami_menu_item_edit_undo, NULL, 0); - ami_menu_alloc_item(md, M_REDO, NM_ITEM, "Redo", "Y", "TBImages:list_redo", - ami_menu_item_edit_redo, NULL, 0); - - ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_FIND, NM_ITEM, "FindTextNS", "F", "TBImages:list_search", - ami_menu_item_browser_find, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS", NULL, "TBImages:list_history", - ami_menu_item_browser_localhistory, NULL, 0); - ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS", NULL, "TBImages:list_history", - ami_menu_item_browser_globalhistory, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B2, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_COOKIES, NM_ITEM, "ShowCookiesNS",NULL, "TBImages:list_internet", - ami_menu_item_browser_cookies, NULL, 0); - ami_menu_alloc_item(md, M_BAR_B3, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SCALE, NM_ITEM, "ScaleNS", NULL, "TBImages:list_preview", NULL, NULL, 0); - ami_menu_alloc_item(md, M_SCALEDEC, NM_SUB, "ScaleDec", "-", "TBImages:list_zoom_out", - ami_menu_item_browser_scale_decrease, NULL, 0); - ami_menu_alloc_item(md, M_SCALENRM, NM_SUB, "ScaleNorm", "=", "TBImages:list_zoom_100", - ami_menu_item_browser_scale_normal, NULL, 0); - ami_menu_alloc_item(md, M_SCALEINC, NM_SUB, "ScaleInc", "+", "TBImages:list_zoom_in", - ami_menu_item_browser_scale_increase, NULL, 0); - ami_menu_alloc_item(md, M_IMAGES, NM_ITEM, "Images", NULL, "TBImages:list_image", NULL, NULL, 0); - ami_menu_alloc_item(md, M_IMGFORE, NM_SUB, "ForeImg", NULL, NULL, - ami_menu_item_browser_foreimg, NULL, imgfore_flags); - ami_menu_alloc_item(md, M_IMGBACK, NM_SUB, "BackImg", NULL, NULL, - ami_menu_item_browser_backimg, NULL, imgback_flags); - ami_menu_alloc_item(md, M_JS, NM_ITEM, "EnableJS", NULL, NULL, - ami_menu_item_browser_enablejs, NULL, js_flags); - ami_menu_alloc_item(md, M_BAR_B4, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_REDRAW, NM_ITEM, "Redraw", NULL, "TBImages:list_wand", - 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); - - 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", - ami_menu_item_settings_edit, NULL, 0); - ami_menu_alloc_item(md, M_BAR_S1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",NULL, "TBImages:list_hold", - ami_menu_item_settings_snapshot, NULL, 0); - ami_menu_alloc_item(md, M_PRSAVE, NM_ITEM, "SettingsSave", NULL, "TBImages:list_use", - ami_menu_item_settings_save, NULL, 0); - - ami_menu_alloc_item(md, M_AREXX, NM_TITLE, "ARexx", NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, M_AREXXEX, NM_ITEM, "ARexxExecute", "E", "TBImages:list_arexx", - ami_menu_item_arexx_execute, NULL, 0); - ami_menu_alloc_item(md, M_BAR_A1, NM_ITEM, NM_BARLABEL, NULL, NULL, NULL, NULL, 0); - ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX, NM_END, NULL, NULL, NULL, NULL, NULL, 0); -} - -/* Menu refresh for hotlist */ -void ami_menu_refresh(struct gui_window_2 *gwin) -{ - return; /**\todo fix this after migrating to menuclass */ - - struct Menu *menu; - - LOG("Clearing MenuStrip"); - SetAttrs(gwin->objects[OID_MAIN], - WINDOW_MenuStrip, NULL, - TAG_DONE); - - LOG("Freeing menu"); - ami_menu_free(gwin); - - LOG("Freeing menu labels"); - ami_free_menulabs(gwin->menu_data); - - LOG("Creating new menu"); - menu = ami_menu_create(gwin); - - LOG("Attaching MenuStrip %p to %p", menu, gwin->objects[OID_MAIN]); - SetAttrs(gwin->objects[OID_MAIN], - WINDOW_MenuStrip, menu, - TAG_DONE); -} - static void ami_menu_load_glyphs(struct DrawInfo *dri) { #ifdef __amigaos4__ @@ -1087,23 +425,6 @@ struct Menu *ami_menu_layout(struct ami_menu_data **md, int max) } } -void ami_menu_free(struct gui_window_2 *gwin) -{ - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - gui_menu_count--; - - if(gui_menu_count == 0) { - ami_free_menulabs(gwin->menu_data); - // if we detach our menu from the window we need to do this manually - DisposeObject((Object *)gui_menu); - gui_menu = NULL; - } - } else { - ami_free_menulabs(gwin->menu_data); - FreeMenus(gwin->imenu); - } -} - void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) { ami_menu_free_labs(md, max); @@ -1114,353 +435,3 @@ void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu) } } -struct Menu *ami_menu_create(struct gui_window_2 *gwin) -{ - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - if(gui_menu != NULL) { - gwin->imenu = gui_menu; - gui_menu_count++; - return gwin->imenu; - } - } - - 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++; - } - - return gwin->imenu; -} - -void ami_menu_arexx_scan(struct ami_menu_data **md) -{ - /**\todo Rewrite this to not use ExAll() **/ - int item = AMI_MENU_AREXX; - BPTR lock = 0; - UBYTE *buffer; - struct ExAllControl *ctrl; - char matchpatt[16]; - LONG cont; - struct ExAllData *ead; - char *menu_lab; - - if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) { - if((buffer = malloc(1024))) { - if((ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL))) { - ctrl->eac_LastKey = 0; - - if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { - ctrl->eac_MatchString = (char *)&matchpatt; - } - - do { - cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); - if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; - if(!ctrl->eac_Entries) continue; - - for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { - if(item >= AMI_MENU_AREXX_MAX) continue; - if(EAD_IS_FILE(ead)) { - if(ead->ed_Comment[0] != '\0') - menu_lab = ead->ed_Comment; - else - menu_lab = ead->ed_Name; - - ami_menu_alloc_item(md, item, NM_ITEM, menu_lab, NULL, NSA_SPACE, - ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name), 0); - - item++; - } - } - } while(cont); - FreeDosObject(DOS_EXALLCONTROL,ctrl); - } - free(buffer); - } - UnLock(lock); - } - - ami_menu_alloc_item(md, item, NM_END, NULL, NULL, NULL, NULL, NULL, 0); -} - -static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) -{ - UBYTE type; - STRPTR icon; - UWORD flags = 0; - struct ami_menu_data **md = (struct ami_menu_data **)userdata; - - if(item >= AMI_MENU_HOTLIST_MAX) return false; - - switch(level) { - case 1: - type = NM_ITEM; - break; - case 2: - type = NM_SUB; - break; - default: - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - type = NM_SUB + (level - 2); - } else { - /* entries not at level 1 or 2 are not able to be added */ - return false; - } - break; - } - - if(is_folder == true) { - icon = ASPrintf("icons/directory.png"); - } else { - icon = ami_gui_get_cache_favicon_name(url, true); - if (icon == NULL) icon = ASPrintf("icons/content.png"); - } - - if(!LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - if((is_folder == true) && (type == NM_SUB)) { - flags = NM_ITEMDISABLED; - } - } - - ami_menu_alloc_item(md, item, type, title, - NULL, icon, ami_menu_item_hotlist_entries, (void *)url, flags); - - if(icon) FreeVec(icon); - - return true; -} - -static nserror ami_menu_scan(struct ami_menu_data **md) -{ - return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add); -} - -#ifdef __amigaos4__ -static void ami_menu_set_disabled_mc(struct Window *win, struct Menu *menu, int item, bool disable) -{ - ULONG disable_state = MS_DISABLED; - - if(disable == false) { - disable_state = 0; - } - - IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_DISABLED, disable_state); -} -#endif - -static ULONG ami_menu_number(int item) -{ - /* horrible, horrible, horrible */ - ULONG menu_num; - - switch(item) { - case M_SAVETXT: - menu_num = FULLMENUNUM(0,4,1); - break; - - case M_SAVECOMP: - menu_num = FULLMENUNUM(0,4,2); - break; - - case M_SAVEIFF: - menu_num = FULLMENUNUM(0,4,3); - break; -#ifdef WITH_PDF_EXPORT - case M_SAVEPDF: - menu_num = FULLMENUNUM(0,4,4); - break; -#endif - case M_CLOSETAB: - menu_num = FULLMENUNUM(0,8,0); - break; - - case M_CUT: - menu_num = FULLMENUNUM(1,0,0); - break; - - case M_COPY: - menu_num = FULLMENUNUM(1,1,0); - break; - - case M_PASTE: - menu_num = FULLMENUNUM(1,2,0); - break; - - case M_SELALL: - menu_num = FULLMENUNUM(1,4,0); - break; - - case M_CLEAR: - menu_num = FULLMENUNUM(1,5,0); - break; - - case M_UNDO: - menu_num = FULLMENUNUM(1,8,0); - break; - - case M_REDO: - menu_num = FULLMENUNUM(1,9,0); - break; - - case M_FIND: - menu_num = FULLMENUNUM(2,0,0); - break; - - case M_IMGFORE: - menu_num = FULLMENUNUM(2,8,0); - break; - - case M_IMGBACK: - menu_num = FULLMENUNUM(2,8,1); - break; - - case M_JS: - menu_num = FULLMENUNUM(2,9,0); - break; - - default: - LOG("WARNING: Unrecognised menu item %d", item); - menu_num = 0; - break; - } - - return menu_num; -} - -static void ami_menu_set_disabled_gt(struct Window *win, struct Menu *menu, int item, bool disable) -{ - ULONG menu_num = ami_menu_number(item); - - if(disable == false) { - OnMenu(win, menu_num); - } else { - OffMenu(win, menu_num); - } -} - -void ami_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable) -{ - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { -#ifdef __amigaos4__ - return ami_menu_set_disabled_mc(win, menu, item, disable); -#endif - } else { - return ami_menu_set_disabled_gt(win, menu, item, disable); - } -} - -void ami_menu_update_checked(struct gui_window_2 *gwin) -{ - if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { - //needs re-writing for MenuClass - return; - } - - struct Menu *menustrip; - - GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip); - if(!menustrip) return; - if(nsoption_bool(enable_javascript) == true) { - if((ItemAddress(menustrip, ami_menu_number(M_JS))->Flags & CHECKED) == 0) - ItemAddress(menustrip, ami_menu_number(M_JS))->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, ami_menu_number(M_JS))->Flags & CHECKED) - ItemAddress(menustrip, ami_menu_number(M_JS))->Flags ^= CHECKED; - } - if(nsoption_bool(foreground_images) == true) { - if((ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags & CHECKED) == 0) - ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags & CHECKED) - ItemAddress(menustrip, ami_menu_number(M_IMGFORE))->Flags ^= CHECKED; - } - - if(nsoption_bool(background_images) == true) { - if((ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags & CHECKED) == 0) - ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags ^= CHECKED; - } else { - if(ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags & CHECKED) - ItemAddress(menustrip, ami_menu_number(M_IMGBACK))->Flags ^= CHECKED; - } - - ResetMenuStrip(gwin->win, menustrip); -} - -void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c) -{ - struct Window *win = g->shared->win; - - if(nsoption_bool(kiosk_mode) == true) return; - - if(content_get_type(c) <= CONTENT_CSS) - { - ami_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, false); - ami_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, false); -#ifdef WITH_PDF_EXPORT - ami_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, false); -#endif -#if 0 - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) { - OnMenu(win,AMI_MENU_COPY); - OnMenu(win,AMI_MENU_CLEAR); - } else { - OffMenu(win,AMI_MENU_COPY); - OffMenu(win,AMI_MENU_CLEAR); - } - - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT) - OnMenu(win,AMI_MENU_CUT); - else - OffMenu(win,AMI_MENU_CUT); - - if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE) - OnMenu(win,AMI_MENU_PASTE); - else - OffMenu(win,AMI_MENU_PASTE); -#else - ami_menu_set_disabled(win, g->shared->imenu, M_CUT, false); - ami_menu_set_disabled(win, g->shared->imenu, M_COPY, false); - ami_menu_set_disabled(win, g->shared->imenu, M_PASTE, false); - ami_menu_set_disabled(win, g->shared->imenu, M_CLEAR, false); -#endif - ami_menu_set_disabled(win, g->shared->imenu, M_SELALL, false); - ami_menu_set_disabled(win, g->shared->imenu, M_FIND, false); - ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); - } - else - { - ami_menu_set_disabled(win, g->shared->imenu, M_CUT, true); - ami_menu_set_disabled(win, g->shared->imenu, M_PASTE, true); - ami_menu_set_disabled(win, g->shared->imenu, M_CLEAR, true); - - ami_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, true); - ami_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, true); -#ifdef WITH_PDF_EXPORT - ami_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, true); -#endif - - ami_menu_set_disabled(win, g->shared->imenu, M_SELALL, true); - ami_menu_set_disabled(win, g->shared->imenu, M_FIND, true); - -#ifdef WITH_NS_SVG - if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == true)) -#else - if(content_get_bitmap(c)) -#endif - { - ami_menu_set_disabled(win, g->shared->imenu, M_COPY, false); - ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, false); - } - else - { - ami_menu_set_disabled(win, g->shared->imenu, M_COPY, true); - ami_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, true); - } - } -} - diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h index 1bb13c472..f8a3f1724 100644 --- a/frontends/amiga/menu.h +++ b/frontends/amiga/menu.h @@ -1,5 +1,5 @@ /* - * Copyright 2008,2009,2013 Chris Young + * Copyright 2017 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -23,101 +23,19 @@ #include #include -struct hlcache_handle; -struct ami_menu_data; +struct ami_menu_data { + char *restrict menulab; + Object *restrict menuobj; + char *restrict menukey; + char *restrict menuicon; + struct Hook menu_hook; + UBYTE menutype; + UWORD flags; +}; /** empty space */ #define NSA_SPACE "blankspace.png" -/** Maximum number of hotlist items (somewhat arbitrary value) */ -#define AMI_HOTLIST_ITEMS 60 - -/** 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; - /* cleanup */ void ami_menu_free_glyphs(void); @@ -128,37 +46,9 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, 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); -/* specific to browser windows */ -struct Menu *ami_menu_create(struct gui_window_2 *gwin); -void ami_menu_refresh(struct gui_window_2 *gwin); -void ami_menu_update_checked(struct gui_window_2 *gwin); -void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c); -void ami_menu_free(struct gui_window_2 *gwin); - -/** - * Set disabled state of a menu item - */ -void ami_menu_set_disabled(struct Window *win, struct Menu *menu, int item, bool disable); - -/** - * Sets that an item linked to a toggle menu item has been changed. - */ -void ami_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_menu_get_check_toggled(void); - -/** - * Gets if NetSurf has been quit from the menu - * - * \return true if NetSurf has been quit + * Get the selected state of a menu item */ -bool ami_menu_quit_selected(void); +bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg); #endif -- cgit v1.2.3 From 8e7603e6a263eb765df4886a321537f209d88245 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 16:10:23 +0000 Subject: Update JS menu check state when prefs option is toggled --- frontends/amiga/gui_menu.c | 8 ++++++++ frontends/amiga/gui_options.c | 4 +++- frontends/amiga/menu.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/gui_menu.c b/frontends/amiga/gui_menu.c index 791182b7a..3f053a571 100644 --- a/frontends/amiga/gui_menu.c +++ b/frontends/amiga/gui_menu.c @@ -598,12 +598,20 @@ static void ami_gui_menu_set_checked_mc(struct Menu *menu, int item, bool check) check_state = 0; } + if(menu == NULL) { + menu = gui_menu; + } + IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_CHECKED, check_state); } #endif static void ami_gui_menu_set_checked_gt(struct Menu *menu, int item, bool check) { + if(menu == NULL) { + return; + } + if(check == true) { if((ItemAddress(menu, ami_gui_menu_number(item))->Flags & CHECKED) == 0) ItemAddress(menu, ami_gui_menu_number(item))->Flags ^= CHECKED; diff --git a/frontends/amiga/gui_options.c b/frontends/amiga/gui_options.c index b349e43c1..78dea5820 100755 --- a/frontends/amiga/gui_options.c +++ b/frontends/amiga/gui_options.c @@ -1727,7 +1727,9 @@ static void ami_gui_opts_use(bool save) } else { nsoption_set_bool(enable_javascript, false); } - + + ami_gui_menu_set_checked(NULL, M_JS, nsoption_bool(enable_javascript)); + GetAttr(GA_Selected,gow->objects[GID_OPTS_DONOTTRACK],(ULONG *)&data); if (data) { nsoption_set_bool(do_not_track, true); diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 6e33d5e05..04c6eb07f 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -39,7 +39,7 @@ #include #include "utils/log.h" -#include "utils/utils.h" +#include "utils/messages.h" #include "amiga/gui.h" #include "amiga/libs.h" -- 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/menu.c') 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 From 9e814fd0f0f03584debb43b6d8acf144bd8675a2 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 20:01:49 +0000 Subject: minor menu fixes --- frontends/amiga/gui.c | 3 +-- frontends/amiga/gui_menu.c | 3 +++ frontends/amiga/menu.c | 14 ++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c index c6ca886f7..b2a489e72 100644 --- a/frontends/amiga/gui.c +++ b/frontends/amiga/gui.c @@ -3335,8 +3335,7 @@ void ami_gui_hotlist_update_all(void) nnode=(struct nsObject *)GetSucc((struct Node *)node); gwin = node->objstruct; - if(node->Type == AMINS_WINDOW) - { + if(node->Type == AMINS_WINDOW) { ami_gui_hotlist_toolbar_update(gwin); } } while((node = nnode)); diff --git a/frontends/amiga/gui_menu.c b/frontends/amiga/gui_menu.c index c453c64d8..6b9b2075d 100644 --- a/frontends/amiga/gui_menu.c +++ b/frontends/amiga/gui_menu.c @@ -1084,6 +1084,7 @@ static void ami_free_menulabs(struct ami_menu_data **md) md[i]->menukey = NULL; md[i]->menutype = 0; free(md[i]); + md[i] = NULL; } } @@ -1093,6 +1094,8 @@ void ami_gui_menu_free(struct gui_window_2 *gwin) #ifdef __amigaos4__ gui_menu_count--; + SetAttrs(gwin->objects[OID_MAIN], WINDOW_MenuStrip, NULL, TAG_DONE); + if(gui_menu_count == 0) { ami_free_menulabs(gui_menu_data); // if we detach our menu from the window we need to do this manually diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index cfbbd8deb..91acce72d 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -100,6 +100,7 @@ void ami_menu_free_lab_item(struct ami_menu_data **md, int i) md[i]->menukey = NULL; md[i]->menutype = 0; free(md[i]); + md[i] = NULL; } static void ami_menu_free_labs(struct ami_menu_data **md, int max) @@ -115,8 +116,6 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, const char *restrict label, const char *restrict key, const char *restrict icon, void *restrict func, void *restrict hookdata, UWORD flags) { - char menu_icon[1024]; - md[num] = calloc(1, sizeof(struct ami_menu_data)); md[num]->menutype = type; md[num]->flags = flags; @@ -127,11 +126,7 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, md[num]->menulab = NM_BARLABEL; icon = NULL; } else { /* horrid non-generic stuff */ - if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) { - utf8_from_local_encoding(label, - (strlen(label) < NSA_MAX_HOTLIST_MENU_LEN) ? strlen(label) : NSA_MAX_HOTLIST_MENU_LEN, - (char **)&md[num]->menulab); - } else if((num >= AMI_MENU_AREXX) && (num < AMI_MENU_AREXX_MAX)) { + if((num >= AMI_MENU_AREXX) && (num < AMI_MENU_AREXX_MAX)) { md[num]->menulab = strdup(label); } else { md[num]->menulab = ami_utf8_easy(messages_get(label)); @@ -144,6 +139,8 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type, if(hookdata) md[num]->menu_hook.h_Data = hookdata; #ifdef __amigaos4__ + char menu_icon[1024]; + if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) { if(icon) { if(ami_locate_resource(menu_icon, icon) == true) { @@ -265,6 +262,7 @@ static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_dat TAG_DONE); } + LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent); IDoMethod(menu_parent, OM_ADDMEMBER, menu_item); continue; } else if (md[j]->menutype > level) { @@ -452,7 +450,7 @@ void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int menu_ite /* 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? */ + DisposeObject(obj); } /* free associated data */ -- cgit v1.2.3 From d871be3ea00ef74ab28b936526768bbf121e3eb0 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 20:15:10 +0000 Subject: Update documentaton --- frontends/amiga/dist/NetSurf.guide | 4 ++-- frontends/amiga/menu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'frontends/amiga/menu.c') diff --git a/frontends/amiga/dist/NetSurf.guide b/frontends/amiga/dist/NetSurf.guide index 754cdbeb9..512a264e6 100755 --- a/frontends/amiga/dist/NetSurf.guide +++ b/frontends/amiga/dist/NetSurf.guide @@ -285,11 +285,11 @@ Items from the hotlist can be added to the Hotlist menu as follows: Select Hotlist => Show hotlist... -Items in the "Hotlist menu" folder node, up to a maximum (currently) of 40 items, will be added to the Hotlist menu, within the limits of the Intuition menu system. +Items in the "Hotlist menu" folder node, up to a maximum (currently) of 200 items, will be added to the Hotlist menu, within the limits of the Intuition menu system. Items in folders within the Menu folder node will be converted to subitems in the menu. -Folders more than one level down in the heirarchy will become menu items with no action. Items deeper will not be included in the menu at all (until we switch to using menuclass). +When using a version of AmigaOS older than OS4.1FE, folders more than one level down in the heirarchy will become menu items with no action. Items deeper will not be included in the menu at all. Folders with no items in them will show up disabled in the menu. If they are named "--" they will be displayed as separator bars. diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c index 91acce72d..2d2ec4e30 100644 --- a/frontends/amiga/menu.c +++ b/frontends/amiga/menu.c @@ -262,7 +262,7 @@ static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_dat TAG_DONE); } - LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent); + //LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent); IDoMethod(menu_parent, OM_ADDMEMBER, menu_item); continue; } else if (md[j]->menutype > level) { -- cgit v1.2.3