From 606cc0c2196f5934a7c48e89ab05da7d5e05081f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 15 Jan 2017 16:05:07 +0000 Subject: [PATCH] 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 | 1081 +------------------------------- frontends/amiga/menu.h | 134 +--- 12 files changed, 1298 insertions(+), 1196 deletions(-) create mode 100644 frontends/amiga/gui_menu.c create mode 100644 frontends/amiga/gui_menu.h 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; -}; +#define NSA_MAX_HOTLIST_MENU_LEN 100 -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]; 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); - } - } - - 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_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_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_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_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 + * Get the selected 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 - */ -bool ami_menu_quit_selected(void); +bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg); #endif