2015-09-03 02:24:04 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Intuition-based context menu operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-04-20 17:54:18 +03:00
|
|
|
#include <stdlib.h>
|
2015-09-03 21:57:04 +03:00
|
|
|
#include <proto/exec.h>
|
2015-09-03 02:24:04 +03:00
|
|
|
#include <proto/intuition.h>
|
2015-09-03 21:57:04 +03:00
|
|
|
|
|
|
|
#include <proto/bitmap.h>
|
2015-09-03 02:24:04 +03:00
|
|
|
#include <images/bitmap.h>
|
2015-09-03 21:57:04 +03:00
|
|
|
#include <proto/window.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
#include <intuition/menuclass.h>
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
2016-04-20 17:54:18 +03:00
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/nsurl.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-07-01 16:27:04 +03:00
|
|
|
#include "netsurf/keypress.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "desktop/browser_history.h"
|
2016-04-20 17:54:18 +03:00
|
|
|
#include "desktop/searchweb.h"
|
|
|
|
|
2015-09-05 01:59:22 +03:00
|
|
|
#include "amiga/bitmap.h"
|
2015-09-05 01:38:04 +03:00
|
|
|
#include "amiga/clipboard.h"
|
2015-09-03 02:24:04 +03:00
|
|
|
#include "amiga/ctxmenu.h"
|
2015-09-05 01:59:22 +03:00
|
|
|
#include "amiga/filetype.h"
|
2015-09-03 02:24:04 +03:00
|
|
|
#include "amiga/gui.h"
|
|
|
|
#include "amiga/libs.h"
|
2015-09-05 02:09:47 +03:00
|
|
|
#include "amiga/plugin_hack.h"
|
2015-09-03 21:57:04 +03:00
|
|
|
#include "amiga/theme.h"
|
|
|
|
#include "amiga/utf8.h"
|
2016-05-31 16:25:12 +03:00
|
|
|
#include "amiga/misc.h"
|
2015-09-03 02:24:04 +03:00
|
|
|
|
|
|
|
enum {
|
2015-09-05 01:59:22 +03:00
|
|
|
AMI_CTX_ID_NONE = 0,
|
2015-09-05 01:38:04 +03:00
|
|
|
|
2015-09-05 02:39:46 +03:00
|
|
|
/* Text selection */
|
|
|
|
AMI_CTX_ID_SELCOPY,
|
2016-01-14 22:09:16 +03:00
|
|
|
AMI_CTX_ID_WEBSEARCH,
|
2015-09-05 02:39:46 +03:00
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/* Links */
|
2015-09-03 21:57:04 +03:00
|
|
|
AMI_CTX_ID_URLOPENTAB,
|
2015-09-05 01:38:04 +03:00
|
|
|
AMI_CTX_ID_URLOPENWIN,
|
|
|
|
AMI_CTX_ID_URLDOWNLOAD,
|
|
|
|
AMI_CTX_ID_URLCOPY,
|
|
|
|
|
2015-09-05 01:59:22 +03:00
|
|
|
/* Objects */
|
|
|
|
AMI_CTX_ID_OBJSHOW,
|
|
|
|
AMI_CTX_ID_OBJCOPY,
|
2015-09-05 02:09:47 +03:00
|
|
|
AMI_CTX_ID_OBJCMD,
|
2015-09-05 01:59:22 +03:00
|
|
|
|
2015-09-05 02:22:46 +03:00
|
|
|
/* Frames */
|
|
|
|
AMI_CTX_ID_FRAMESHOW,
|
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/* History */
|
2015-09-04 02:26:52 +03:00
|
|
|
AMI_CTX_ID_HISTORY,
|
|
|
|
AMI_CTX_ID_HISTORY0,
|
2015-09-05 01:38:04 +03:00
|
|
|
AMI_CTX_ID_HISTORY9F = AMI_CTX_ID_HISTORY0 + 19,
|
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
/* Tabs */
|
|
|
|
AMI_CTX_ID_TABNEW,
|
2016-01-31 20:58:27 +03:00
|
|
|
AMI_CTX_ID_TABCLOSE_OTHER,
|
2015-09-05 03:41:56 +03:00
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
AMI_CTX_ID_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
static Object *ctxmenu_obj = NULL;
|
|
|
|
|
|
|
|
static struct Hook ctxmenu_item_hook[AMI_CTX_ID_MAX];
|
|
|
|
static char *ctxmenu_item_label[AMI_CTX_ID_MAX];
|
2015-09-05 03:41:56 +03:00
|
|
|
static char *ctxmenu_item_shortcut[AMI_CTX_ID_MAX];
|
2015-09-03 21:57:04 +03:00
|
|
|
static Object *ctxmenu_item_image[AMI_CTX_ID_MAX];
|
2015-09-03 02:24:04 +03:00
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/****************************
|
|
|
|
* Menu item hook functions *
|
|
|
|
****************************/
|
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
/** Menu functions - called automatically by RA_HandleInput **/
|
2015-09-05 02:39:46 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_selcopy, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin = (struct gui_window_2 *)hook->h_Data;
|
|
|
|
|
|
|
|
browser_window_key_press(gwin->gw->bw, NS_KEY_COPY_SELECTION);
|
|
|
|
browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION);
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:09:16 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_websearch, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
nserror ret = NSERROR_OK;
|
|
|
|
nsurl *url;
|
|
|
|
|
|
|
|
struct gui_window_2 *gwin = (struct gui_window_2 *)hook->h_Data;
|
2016-01-14 22:15:30 +03:00
|
|
|
char *sel = browser_window_get_selection(gwin->gw->bw);
|
2016-01-14 22:09:16 +03:00
|
|
|
|
|
|
|
ret = search_web_omni(sel, SEARCH_WEB_OMNI_SEARCHONLY, &url);
|
|
|
|
if (ret == NSERROR_OK) {
|
|
|
|
browser_window_navigate(gwin->gw->bw,
|
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
BW_NAVIGATE_HISTORY,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (ret != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user(messages_get_errorcode(ret), 0);
|
2016-01-14 22:09:16 +03:00
|
|
|
}
|
2016-01-14 22:15:30 +03:00
|
|
|
|
|
|
|
free(sel);
|
2016-01-14 22:09:16 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_urlopentab, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct browser_window *bw;
|
|
|
|
nsurl *url = (nsurl *)hook->h_Data;
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
nserror error = browser_window_create(BW_CREATE_CLONE | BW_CREATE_HISTORY | BW_CREATE_TAB,
|
|
|
|
url,
|
|
|
|
browser_window_get_url(gwin->gw->bw),
|
|
|
|
gwin->gw->bw,
|
|
|
|
&bw);
|
|
|
|
|
|
|
|
if (error != NSERROR_OK)
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user(messages_get_errorcode(error), 0);
|
2015-09-03 21:57:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HOOKF(void, ami_ctxmenu_item_urlopenwin, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct browser_window *bw;
|
|
|
|
nsurl *url = (nsurl *)hook->h_Data;
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
nserror error = browser_window_create(BW_CREATE_CLONE | BW_CREATE_HISTORY,
|
|
|
|
url,
|
|
|
|
browser_window_get_url(gwin->gw->bw),
|
|
|
|
gwin->gw->bw,
|
|
|
|
&bw);
|
|
|
|
|
|
|
|
if (error != NSERROR_OK)
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user(messages_get_errorcode(error), 0);
|
2015-09-03 21:57:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_urldownload, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
nsurl *url = (nsurl *)hook->h_Data;
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
|
|
|
|
browser_window_navigate(gwin->gw->bw,
|
|
|
|
url,
|
|
|
|
browser_window_get_url(gwin->gw->bw),
|
|
|
|
BW_NAVIGATE_DOWNLOAD,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
HOOKF(void, ami_ctxmenu_item_urlcopy, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
nsurl *url = (nsurl *)hook->h_Data;
|
|
|
|
ami_easy_clipboard(nsurl_access(url));
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:59:22 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_objshow, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
|
|
|
|
browser_window_navigate(gwin->gw->bw,
|
|
|
|
hlcache_handle_get_url(hook->h_Data),
|
|
|
|
browser_window_get_url(gwin->gw->bw),
|
|
|
|
BW_NAVIGATE_HISTORY,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
HOOKF(void, ami_ctxmenu_item_objcopy, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct bitmap *bm;
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
|
|
|
|
struct hlcache_handle *object = (struct hlcache_handle *)hook->h_Data;
|
|
|
|
if((bm = content_get_bitmap(object)))
|
|
|
|
{
|
2016-03-22 22:26:36 +03:00
|
|
|
ami_bitmap_set_url(bm, hlcache_handle_get_url(object));
|
|
|
|
ami_bitmap_set_title(bm, content_get_title(object));
|
2015-09-05 01:59:22 +03:00
|
|
|
ami_easy_clipboard_bitmap(bm);
|
|
|
|
}
|
|
|
|
#ifdef WITH_NS_SVG
|
|
|
|
else if(ami_mime_compare(object, "svg") == true)
|
|
|
|
{
|
|
|
|
ami_easy_clipboard_svg(object);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-05 02:09:47 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_objcmd, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
amiga_plugin_hack_execute((struct hlcache_handle *)hook->h_Data);
|
|
|
|
}
|
|
|
|
|
2015-09-05 02:22:46 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_frameshow, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
|
|
|
|
browser_window_navigate(gwin->gw->bw,
|
|
|
|
hlcache_handle_get_url(hook->h_Data),
|
|
|
|
browser_window_get_url(gwin->gw->bw),
|
|
|
|
BW_NAVIGATE_HISTORY,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
2015-09-05 02:09:47 +03:00
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
/** Hooks for clicktab context menu entries **/
|
|
|
|
HOOKF(void, ami_ctxmenu_item_tabnew, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
ami_gui_new_blank_tab(gwin);
|
|
|
|
}
|
|
|
|
|
2016-01-31 20:58:27 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_tabclose_other, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
ami_gui_close_inactive_tabs(gwin);
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/** Hook for history context menu entries **/
|
2015-09-04 02:26:52 +03:00
|
|
|
HOOKF(void, ami_ctxmenu_item_history, APTR, window, struct IntuiMessage *)
|
|
|
|
{
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
|
|
|
|
|
|
|
|
browser_window_history_go(gwin->gw->bw, (struct history_entry *)hook->h_Data, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/*************************
|
|
|
|
* Browser context menus *
|
|
|
|
*************************/
|
2015-09-03 21:57:04 +03:00
|
|
|
|
|
|
|
/** Add an initialised item to a context menu **/
|
|
|
|
static void ami_ctxmenu_add_item(Object *root_menu, int id, APTR data)
|
|
|
|
{
|
|
|
|
ctxmenu_item_hook[id].h_Data = data;
|
|
|
|
|
|
|
|
IDoMethod(root_menu, OM_ADDMEMBER, MStrip,
|
|
|
|
MA_Type, T_ITEM,
|
|
|
|
MA_ID, id,
|
2015-09-05 03:41:56 +03:00
|
|
|
MA_Label, ctxmenu_item_label[id],
|
|
|
|
MA_Key, ctxmenu_item_shortcut[id],
|
2015-09-03 21:57:04 +03:00
|
|
|
MA_Image, ctxmenu_item_image[id],
|
|
|
|
MA_UserData, &ctxmenu_item_hook[id],
|
|
|
|
MEnd);
|
|
|
|
}
|
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
/** Hook function called by Intuition, creates context menu structure **/
|
2015-09-03 21:57:04 +03:00
|
|
|
static uint32 ami_ctxmenu_hook_func(struct Hook *hook, struct Window *window, struct ContextMenuMsg *msg)
|
2015-09-03 02:24:04 +03:00
|
|
|
{
|
2015-09-03 21:57:04 +03:00
|
|
|
Object *root_menu;
|
|
|
|
bool ctxmenu_has_content = false;
|
|
|
|
struct gui_window_2 *gwin = hook->h_Data;
|
|
|
|
struct hlcache_handle *cc = browser_window_get_content(gwin->gw->bw);
|
|
|
|
struct browser_window_features ccdata;
|
|
|
|
int mx = window->MouseX;
|
|
|
|
int my = window->MouseY;
|
|
|
|
int x, y;
|
2016-01-14 22:15:30 +03:00
|
|
|
char *sel;
|
2015-09-03 02:24:04 +03:00
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
if(msg->State != CM_QUERY) return 0;
|
|
|
|
if(nsoption_bool(kiosk_mode) == true) return 0;
|
|
|
|
// check window is active
|
2015-09-03 02:24:04 +03:00
|
|
|
|
|
|
|
if(ctxmenu_obj != NULL) DisposeObject(ctxmenu_obj);
|
|
|
|
|
|
|
|
ctxmenu_obj = MStrip,
|
|
|
|
MA_Type, T_ROOT,
|
2015-09-03 21:57:04 +03:00
|
|
|
MA_AddChild, root_menu = MStrip,
|
2015-09-03 02:24:04 +03:00
|
|
|
MA_Type, T_MENU,
|
|
|
|
MA_Label, NULL, //"NetSurf",
|
2015-09-03 21:57:04 +03:00
|
|
|
MA_EmbeddedKey, FALSE,
|
|
|
|
MA_FreeImage, FALSE,
|
2015-09-03 02:24:04 +03:00
|
|
|
MEnd,
|
|
|
|
MEnd;
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
if(ami_mouse_to_ns_coords(gwin, &x, &y, mx, my) == false) {
|
|
|
|
/* Outside browser render area */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_window_get_features(gwin->gw->bw, x, y, &ccdata);
|
|
|
|
|
2015-09-05 02:39:46 +03:00
|
|
|
if((browser_window_can_select(gwin->gw->bw)) &&
|
2016-01-14 22:15:30 +03:00
|
|
|
((browser_window_get_editor_flags(gwin->gw->bw) & BW_EDITOR_CAN_COPY)) &&
|
|
|
|
(sel = browser_window_get_selection(gwin->gw->bw))) {
|
2015-09-05 02:39:46 +03:00
|
|
|
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_SELCOPY, gwin);
|
2016-01-14 22:09:16 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_WEBSEARCH, gwin);
|
2015-09-05 02:39:46 +03:00
|
|
|
|
|
|
|
ctxmenu_has_content = true;
|
2016-01-14 22:15:30 +03:00
|
|
|
free(sel);
|
2015-09-05 02:39:46 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
if(ccdata.link) {
|
2015-09-05 02:39:46 +03:00
|
|
|
if(ctxmenu_has_content == true)
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_NONE, NULL);
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLOPENTAB, ccdata.link);
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLOPENWIN, ccdata.link);
|
2015-09-05 01:38:04 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLDOWNLOAD, ccdata.link);
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLCOPY, ccdata.link);
|
2015-09-03 21:57:04 +03:00
|
|
|
ctxmenu_has_content = true;
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:59:22 +03:00
|
|
|
if(ccdata.object) {
|
2015-09-05 02:39:46 +03:00
|
|
|
if(ctxmenu_has_content == true)
|
2015-09-05 01:59:22 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_NONE, NULL);
|
|
|
|
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_OBJSHOW, ccdata.object);
|
2015-09-05 02:09:47 +03:00
|
|
|
|
|
|
|
if(content_get_type(ccdata.object) == CONTENT_IMAGE)
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_OBJCOPY, ccdata.object);
|
|
|
|
|
|
|
|
if(ami_mime_content_to_cmd(ccdata.object))
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_OBJCMD, ccdata.object);
|
2015-09-05 01:59:22 +03:00
|
|
|
|
|
|
|
ctxmenu_has_content = true;
|
|
|
|
}
|
|
|
|
|
2015-09-05 02:22:46 +03:00
|
|
|
if(ccdata.main && (ccdata.main != cc)) {
|
2015-09-05 02:39:46 +03:00
|
|
|
if(ctxmenu_has_content == true)
|
2015-09-05 02:22:46 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_NONE, NULL);
|
|
|
|
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_FRAMESHOW, ccdata.main);
|
2015-09-05 02:39:46 +03:00
|
|
|
|
|
|
|
ctxmenu_has_content = true;
|
2015-09-05 02:22:46 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
if(ctxmenu_has_content == true) {
|
|
|
|
msg->Menu = ctxmenu_obj;
|
|
|
|
ami_set_pointer(gwin, GUI_POINTER_DEFAULT, false);
|
|
|
|
}
|
2015-09-03 02:24:04 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-03 21:57:04 +03:00
|
|
|
/** Initial menu item creation **/
|
2015-09-05 03:41:56 +03:00
|
|
|
static void ami_ctxmenu_alloc_item(int id, const char *label, const char *key, const char *image, void *func)
|
2015-09-03 21:57:04 +03:00
|
|
|
{
|
2015-09-05 01:59:22 +03:00
|
|
|
if(label == ML_SEPARATOR) {
|
|
|
|
ctxmenu_item_label[id] = ML_SEPARATOR;
|
|
|
|
} else {
|
|
|
|
ctxmenu_item_label[id] = ami_utf8_easy(messages_get(label));
|
|
|
|
}
|
2015-09-03 21:57:04 +03:00
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
if(key != NULL) {
|
|
|
|
ctxmenu_item_shortcut[id] = strdup(key);
|
|
|
|
} else {
|
|
|
|
ctxmenu_item_shortcut[id] = NULL;
|
|
|
|
}
|
2015-09-05 02:39:46 +03:00
|
|
|
|
2015-09-04 02:26:52 +03:00
|
|
|
if(image != NULL) {
|
|
|
|
ctxmenu_item_image[id] = BitMapObj,
|
|
|
|
BITMAP_Screen, scrn,
|
|
|
|
BITMAP_SourceFile, image,
|
|
|
|
BITMAP_Masking, TRUE,
|
|
|
|
BitMapEnd;
|
|
|
|
|
|
|
|
SetAttrs(ctxmenu_item_image[id],
|
|
|
|
BITMAP_Width, 16,
|
|
|
|
BITMAP_Height, 16,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
2015-09-03 21:57:04 +03:00
|
|
|
|
|
|
|
ctxmenu_item_hook[id].h_Entry = func;
|
|
|
|
ctxmenu_item_hook[id].h_Data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
|
|
|
struct Hook *ami_ctxmenu_get_hook(APTR data)
|
|
|
|
{
|
|
|
|
return AllocSysObjectTags(ASOT_HOOK,
|
|
|
|
ASOHOOK_Entry, (HOOKFUNC)ami_ctxmenu_hook_func,
|
|
|
|
ASOHOOK_Data, data,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
2015-09-03 21:57:04 +03:00
|
|
|
void ami_ctxmenu_release_hook(struct Hook *hook)
|
2015-09-03 02:24:04 +03:00
|
|
|
{
|
2015-09-03 21:57:04 +03:00
|
|
|
FreeSysObject(ASOT_HOOK, hook);
|
2015-09-03 02:24:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
|
|
|
void ami_ctxmenu_free(void)
|
|
|
|
{
|
|
|
|
for(int i = 1; i < AMI_CTX_ID_MAX; i++) {
|
2015-09-05 03:41:56 +03:00
|
|
|
if((ctxmenu_item_label[i] != NULL) && (ctxmenu_item_label[i] != ML_SEPARATOR)) {
|
2015-09-03 21:57:04 +03:00
|
|
|
ami_utf8_free(ctxmenu_item_label[i]);
|
2015-09-05 03:41:56 +03:00
|
|
|
}
|
|
|
|
ctxmenu_item_label[i] = NULL;
|
|
|
|
|
|
|
|
if(ctxmenu_item_shortcut[i] != NULL) {
|
|
|
|
free(ctxmenu_item_shortcut[i]);
|
|
|
|
ctxmenu_item_shortcut[i] = NULL;
|
2015-09-03 02:24:04 +03:00
|
|
|
}
|
2015-09-03 21:57:04 +03:00
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
if(ctxmenu_item_image[i] != NULL) {
|
2015-09-03 21:57:04 +03:00
|
|
|
DisposeObject(ctxmenu_item_image[i]);
|
2015-09-03 02:24:04 +03:00
|
|
|
ctxmenu_item_image[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ctxmenu_obj != NULL) DisposeObject(ctxmenu_obj);
|
|
|
|
ctxmenu_obj = NULL;
|
|
|
|
}
|
2015-09-04 02:26:52 +03:00
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
|
|
|
void ami_ctxmenu_init(void)
|
|
|
|
{
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_NONE, ML_SEPARATOR, NULL, NULL, NULL);
|
2015-09-05 02:39:46 +03:00
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_SELCOPY, "CopyNS", "C", "TBImages:list_copy",
|
2015-09-05 02:39:46 +03:00
|
|
|
ami_ctxmenu_item_selcopy);
|
2016-01-14 22:09:16 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_WEBSEARCH, "SearchWeb", NULL, "TBImages:list_search",
|
|
|
|
ami_ctxmenu_item_websearch);
|
2015-09-05 01:59:22 +03:00
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENTAB, "LinkNewTab", NULL, "TBImages:list_tab",
|
2015-09-05 01:38:04 +03:00
|
|
|
ami_ctxmenu_item_urlopentab);
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENWIN, "LinkNewWin", NULL, "TBImages:list_app",
|
2015-09-05 01:38:04 +03:00
|
|
|
ami_ctxmenu_item_urlopenwin);
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLDOWNLOAD, "LinkDload", NULL, "TBImages:list_save",
|
2015-09-05 01:38:04 +03:00
|
|
|
ami_ctxmenu_item_urldownload);
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLCOPY, "CopyURL", NULL, "TBImages:list_copy",
|
2015-09-05 01:38:04 +03:00
|
|
|
ami_ctxmenu_item_urlcopy);
|
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_OBJSHOW, "ObjShow", NULL, "TBImages:list_preview",
|
2015-09-05 01:59:22 +03:00
|
|
|
ami_ctxmenu_item_objshow);
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_OBJCOPY, "CopyClip", NULL, "TBImages:list_copy",
|
2015-09-05 01:59:22 +03:00
|
|
|
ami_ctxmenu_item_objcopy);
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_OBJCMD, "ExternalApp", NULL, "TBImages:list_tool",
|
2015-09-05 02:09:47 +03:00
|
|
|
ami_ctxmenu_item_objcmd);
|
2015-09-05 01:59:22 +03:00
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_FRAMESHOW, "FrameOnly", NULL, "TBImages:list_preview",
|
2015-09-05 02:22:46 +03:00
|
|
|
ami_ctxmenu_item_frameshow);
|
|
|
|
|
2016-01-31 20:58:27 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_TABNEW, "NewTab", "T", "TBImages:list_tab",
|
2015-09-05 03:41:56 +03:00
|
|
|
ami_ctxmenu_item_tabnew);
|
2016-01-31 20:58:27 +03:00
|
|
|
ami_ctxmenu_alloc_item(AMI_CTX_ID_TABCLOSE_OTHER, "CloseInactive", "K", "TBImages:list_cancel",
|
|
|
|
ami_ctxmenu_item_tabclose_other);
|
2015-09-05 01:38:04 +03:00
|
|
|
}
|
2015-09-04 02:26:52 +03:00
|
|
|
|
2015-09-05 01:38:04 +03:00
|
|
|
/********************************
|
|
|
|
* History button context menus *
|
|
|
|
********************************/
|
2015-09-04 02:26:52 +03:00
|
|
|
|
|
|
|
/** Create menu entries from browser history **/
|
|
|
|
static bool ami_ctxmenu_history(int direction, struct gui_window_2 *gwin, const struct history_entry *entry)
|
|
|
|
{
|
|
|
|
Object *history_root;
|
|
|
|
int id = AMI_CTX_ID_HISTORY0 + gwin->temp;
|
|
|
|
if(direction == AMI_CTXMENU_HISTORY_FORWARD) id += 10;
|
|
|
|
|
|
|
|
if(gwin->temp >= 10) return false;
|
|
|
|
|
|
|
|
ctxmenu_item_hook[id].h_Entry = (HOOKFUNC)ami_ctxmenu_item_history;
|
|
|
|
ctxmenu_item_hook[id].h_Data = (APTR)entry;
|
|
|
|
|
|
|
|
history_root = (Object *)IDoMethod(gwin->history_ctxmenu[direction], MM_FINDID, 0, AMI_CTX_ID_HISTORY);
|
|
|
|
|
|
|
|
IDoMethod(history_root, OM_ADDMEMBER, MStrip,
|
|
|
|
MA_Type, T_ITEM,
|
|
|
|
MA_Label, browser_window_history_entry_get_title(entry),
|
|
|
|
MA_ID, id,
|
|
|
|
MA_Image, NULL,
|
|
|
|
MA_UserData, &ctxmenu_item_hook[id],
|
|
|
|
MEnd);
|
|
|
|
|
|
|
|
gwin->temp++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Callback for browser_window_history_enumerate **/
|
|
|
|
static bool ami_ctxmenu_history_back(const struct browser_window *bw,
|
|
|
|
int x0, int y0, int x1, int y1,
|
|
|
|
const struct history_entry *entry, void *user_data)
|
|
|
|
{
|
|
|
|
return ami_ctxmenu_history(AMI_CTXMENU_HISTORY_BACK, (struct gui_window_2 *)user_data, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Callback for browser_window_history_enumerate **/
|
|
|
|
static bool ami_ctxmenu_history_forward(const struct browser_window *bw,
|
|
|
|
int x0, int y0, int x1, int y1,
|
|
|
|
const struct history_entry *entry, void *user_data)
|
|
|
|
{
|
|
|
|
return ami_ctxmenu_history(AMI_CTXMENU_HISTORY_FORWARD, (struct gui_window_2 *)user_data, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
|
|
|
struct Menu *ami_ctxmenu_history_create(int direction, struct gui_window_2 *gwin)
|
|
|
|
{
|
|
|
|
Object *obj;
|
|
|
|
|
|
|
|
if(gwin->history_ctxmenu[direction] == NULL) {
|
|
|
|
if(ctxmenu_item_label[AMI_CTX_ID_HISTORY] == NULL)
|
|
|
|
ctxmenu_item_label[AMI_CTX_ID_HISTORY] = ami_utf8_easy(messages_get("History"));
|
|
|
|
|
|
|
|
gwin->history_ctxmenu[direction] = MStrip,
|
|
|
|
MA_Type, T_ROOT,
|
|
|
|
MA_AddChild, MStrip,
|
|
|
|
MA_Type, T_MENU,
|
|
|
|
MA_ID, AMI_CTX_ID_HISTORY,
|
|
|
|
MA_Label, ctxmenu_item_label[AMI_CTX_ID_HISTORY],
|
|
|
|
MA_EmbeddedKey, FALSE,
|
|
|
|
//MA_FreeImage, FALSE,
|
|
|
|
MEnd,
|
|
|
|
MEnd;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
obj = (Object *)IDoMethod(gwin->history_ctxmenu[direction],
|
|
|
|
MM_FINDID, 0, AMI_CTX_ID_HISTORY0 + i);
|
|
|
|
if(obj != NULL) IDoMethod(gwin->history_ctxmenu[direction], OM_REMMEMBER, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
gwin->temp = 0;
|
|
|
|
|
|
|
|
if(direction == AMI_CTXMENU_HISTORY_BACK) {
|
|
|
|
browser_window_history_enumerate_back(gwin->gw->bw, ami_ctxmenu_history_back, gwin);
|
|
|
|
} else {
|
|
|
|
browser_window_history_enumerate_forward(gwin->gw->bw, ami_ctxmenu_history_forward, gwin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (struct Menu *)gwin->history_ctxmenu[direction];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-05 03:41:56 +03:00
|
|
|
/**************************
|
|
|
|
* ClickTab context menus *
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
/** Exported interface documented in ctxmenu.h **/
|
|
|
|
struct Menu *ami_ctxmenu_clicktab_create(struct gui_window_2 *gwin)
|
|
|
|
{
|
|
|
|
Object *root_menu;
|
|
|
|
|
|
|
|
if(gwin->clicktab_ctxmenu != NULL) return (struct Menu *)gwin->clicktab_ctxmenu;
|
|
|
|
|
|
|
|
gwin->clicktab_ctxmenu = MStrip,
|
|
|
|
MA_Type, T_ROOT,
|
|
|
|
MA_AddChild, root_menu = MStrip,
|
|
|
|
MA_Type, T_MENU,
|
|
|
|
MA_Label, NULL,
|
|
|
|
MA_EmbeddedKey, FALSE,
|
|
|
|
MEnd,
|
|
|
|
MEnd;
|
|
|
|
|
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_TABNEW, gwin);
|
2016-01-31 20:58:27 +03:00
|
|
|
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_TABCLOSE_OTHER, gwin);
|
2015-09-05 03:41:56 +03:00
|
|
|
|
|
|
|
return (struct Menu *)gwin->clicktab_ctxmenu;
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:26:52 +03:00
|
|
|
|
2015-09-03 02:24:04 +03:00
|
|
|
#endif
|
|
|
|
|