2008-10-21 22:04:27 +04:00
|
|
|
/*
|
2009-01-11 00:26:22 +03:00
|
|
|
* Copyright 2008-9 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-10-21 22:04:27 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-07 02:17:17 +03:00
|
|
|
#ifdef __amigaos4__
|
2008-10-21 22:04:27 +04:00
|
|
|
#include <proto/popupmenu.h>
|
2011-01-07 02:17:17 +03:00
|
|
|
#endif
|
2008-10-21 22:04:27 +04:00
|
|
|
#include <proto/intuition.h>
|
2011-02-10 01:16:11 +03:00
|
|
|
#include <proto/asl.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
|
|
|
|
#include "amiga/context_menu.h"
|
2008-10-21 22:04:27 +04:00
|
|
|
#include "amiga/utf8.h"
|
2008-10-25 20:37:08 +04:00
|
|
|
#include "amiga/options.h"
|
|
|
|
#include "amiga/clipboard.h"
|
2009-05-16 18:50:30 +04:00
|
|
|
#include "amiga/bitmap.h"
|
2009-05-19 11:23:56 +04:00
|
|
|
#include "amiga/iff_dr2d.h"
|
2011-02-10 01:16:11 +03:00
|
|
|
#include "desktop/textinput.h"
|
|
|
|
#include "desktop/selection.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2008-10-21 22:04:27 +04:00
|
|
|
|
|
|
|
uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved);
|
2011-02-10 01:16:11 +03:00
|
|
|
bool ami_context_menu_copy_selection(const char *text, size_t length, struct box *box,
|
|
|
|
void *handle, const char *whitespace_text, size_t whitespace_length);
|
2008-10-21 22:04:27 +04:00
|
|
|
|
2008-10-25 20:37:08 +04:00
|
|
|
char *ctxmenulab[CMID_LAST];
|
|
|
|
|
2011-02-10 01:16:11 +03:00
|
|
|
struct ami_context_menu_selection
|
|
|
|
{
|
|
|
|
char text[1024];
|
|
|
|
int length;
|
|
|
|
};
|
|
|
|
|
2008-10-25 20:37:08 +04:00
|
|
|
void ami_context_menu_init(void)
|
|
|
|
{
|
|
|
|
ctxmenulab[CMID_SELECTFILE] = ami_utf8_easy((char *)messages_get("SelectFile"));
|
|
|
|
ctxmenulab[CMID_COPYURL] = ami_utf8_easy((char *)messages_get("CopyURL"));
|
|
|
|
ctxmenulab[CMID_SHOWOBJ] = ami_utf8_easy((char *)messages_get("ObjShow"));
|
|
|
|
ctxmenulab[CMID_COPYOBJ] = ami_utf8_easy((char *)messages_get("CopyURL"));
|
2009-05-16 18:50:30 +04:00
|
|
|
ctxmenulab[CMID_CLIPOBJ] = ami_utf8_easy((char *)messages_get("CopyClip"));
|
|
|
|
ctxmenulab[CMID_SAVEOBJ] = ami_utf8_easy((char *)messages_get("SaveAs"));
|
|
|
|
ctxmenulab[CMID_SAVEIFFOBJ] = ami_utf8_easy((char *)messages_get("SaveIFF"));
|
|
|
|
|
2009-02-01 02:45:25 +03:00
|
|
|
ctxmenulab[CMID_SAVEURL] = ami_utf8_easy((char *)messages_get("LinkDload"));
|
2008-12-14 02:26:10 +03:00
|
|
|
ctxmenulab[CMID_URLOPENWIN] = ami_utf8_easy((char *)messages_get("LinkNewWin"));
|
|
|
|
ctxmenulab[CMID_URLOPENTAB] = ami_utf8_easy((char *)messages_get("LinkNewTab"));
|
2008-10-25 20:37:08 +04:00
|
|
|
|
2010-07-24 20:39:37 +04:00
|
|
|
ctxmenulab[CMID_SELCUT] = ami_utf8_easy((char *)messages_get("CutNS"));
|
2009-01-16 22:13:07 +03:00
|
|
|
ctxmenulab[CMID_SELCOPY] = ami_utf8_easy((char *)messages_get("CopyNS"));
|
2010-07-24 20:39:37 +04:00
|
|
|
ctxmenulab[CMID_SELPASTE] = ami_utf8_easy((char *)messages_get("PasteNS"));
|
2009-01-16 22:13:07 +03:00
|
|
|
ctxmenulab[CMID_SELALL] = ami_utf8_easy((char *)messages_get("SelectAllNS"));
|
2010-07-24 20:39:37 +04:00
|
|
|
ctxmenulab[CMID_SELCLEAR] = ami_utf8_easy((char *)messages_get("ClearNS"));
|
2011-02-10 01:16:11 +03:00
|
|
|
ctxmenulab[CMID_SELSEARCH] = ami_utf8_easy((char *)messages_get("SearchWeb"));
|
2009-01-16 22:13:07 +03:00
|
|
|
|
2008-10-25 20:37:08 +04:00
|
|
|
ctxmenulab[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object"));
|
|
|
|
ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link"));
|
2009-01-16 22:13:07 +03:00
|
|
|
ctxmenulab[CMSUB_SEL] = ami_utf8_easy((char *)messages_get("Selection"));
|
2008-10-25 20:37:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_context_menu_free(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<CMID_LAST;i++)
|
|
|
|
{
|
|
|
|
ami_utf8_free(ctxmenulab[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 22:04:27 +04:00
|
|
|
void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y)
|
|
|
|
{
|
2010-03-28 19:51:05 +04:00
|
|
|
struct hlcache_handle *cc = gwin->bw->current_content;
|
2010-03-21 22:29:33 +03:00
|
|
|
struct box *curbox;
|
2008-10-21 22:04:27 +04:00
|
|
|
int box_x=0;
|
|
|
|
int box_y=0;
|
2009-04-01 21:26:39 +04:00
|
|
|
bool menuhascontent = false;
|
2008-10-21 22:04:27 +04:00
|
|
|
|
2010-03-21 22:29:33 +03:00
|
|
|
if(!cc) return;
|
2010-03-28 19:51:05 +04:00
|
|
|
if(content_get_type(cc) != CONTENT_HTML) return;
|
2008-10-21 22:04:27 +04:00
|
|
|
|
|
|
|
if(gwin->objects[OID_MENU]) DisposeObject(gwin->objects[OID_MENU]);
|
|
|
|
|
|
|
|
gwin->popuphook.h_Entry = ami_context_menu_hook;
|
|
|
|
gwin->popuphook.h_Data = gwin;
|
|
|
|
|
|
|
|
gwin->objects[OID_MENU] = NewObject( POPUPMENU_GetClass(), NULL,
|
|
|
|
PMA_MenuHandler, &gwin->popuphook,
|
|
|
|
TAG_DONE);
|
|
|
|
|
2010-03-28 19:51:05 +04:00
|
|
|
curbox = html_get_box_tree(gwin->bw->current_content);
|
2010-03-21 22:29:33 +03:00
|
|
|
|
2008-10-21 22:04:27 +04:00
|
|
|
while(curbox = box_at_point(curbox,x,y,&box_x,&box_y,&cc))
|
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
if (curbox->style && css_computed_visibility(curbox->style) == CSS_VISIBILITY_HIDDEN) continue;
|
2008-10-21 22:04:27 +04:00
|
|
|
|
|
|
|
if(curbox->href)
|
|
|
|
{
|
|
|
|
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
|
|
|
|
NewObject(POPUPMENU_GetItemClass(), NULL,
|
2008-10-25 20:37:08 +04:00
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMSUB_URL],
|
|
|
|
PMSIMPLESUB,
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_URLOPENWIN],
|
|
|
|
PMIA_ID,CMID_URLOPENWIN,
|
|
|
|
PMIA_UserData,curbox->href,
|
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_URLOPENTAB],
|
|
|
|
PMIA_ID,CMID_URLOPENTAB,
|
|
|
|
PMIA_UserData,curbox->href,
|
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_COPYURL],
|
|
|
|
PMIA_ID,CMID_COPYURL,
|
|
|
|
PMIA_UserData,curbox->href,
|
|
|
|
TAG_DONE),
|
2009-02-01 02:45:25 +03:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SAVEURL],
|
|
|
|
PMIA_ID,CMID_SAVEURL,
|
|
|
|
PMIA_UserData,curbox->href,
|
|
|
|
TAG_DONE),
|
2008-10-21 22:04:27 +04:00
|
|
|
TAG_DONE),
|
2008-10-25 20:37:08 +04:00
|
|
|
TAG_DONE),
|
2008-10-21 22:04:27 +04:00
|
|
|
~0);
|
2009-04-01 21:26:39 +04:00
|
|
|
|
|
|
|
menuhascontent = true;
|
2008-10-21 22:04:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curbox->object)
|
|
|
|
{
|
|
|
|
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
|
|
|
|
NewObject(POPUPMENU_GetItemClass(), NULL,
|
2008-10-25 20:37:08 +04:00
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMSUB_OBJECT],
|
|
|
|
PMSIMPLESUB,
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SHOWOBJ],
|
|
|
|
PMIA_ID,CMID_SHOWOBJ,
|
2010-03-28 19:51:05 +04:00
|
|
|
PMIA_UserData, content_get_url(curbox->object),
|
2008-10-25 20:37:08 +04:00
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_COPYOBJ],
|
|
|
|
PMIA_ID,CMID_COPYOBJ,
|
2010-03-28 19:51:05 +04:00
|
|
|
PMIA_UserData, content_get_url(curbox->object),
|
2008-10-25 20:37:08 +04:00
|
|
|
TAG_DONE),
|
2009-05-16 18:50:30 +04:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_CLIPOBJ],
|
|
|
|
PMIA_ID,CMID_CLIPOBJ,
|
|
|
|
PMIA_UserData,curbox->object,
|
|
|
|
TAG_DONE),
|
2008-12-14 02:26:10 +03:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SAVEOBJ],
|
|
|
|
PMIA_ID,CMID_SAVEOBJ,
|
|
|
|
PMIA_UserData,curbox->object,
|
|
|
|
TAG_DONE),
|
2009-05-16 18:50:30 +04:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SAVEIFFOBJ],
|
|
|
|
PMIA_ID,CMID_SAVEIFFOBJ,
|
|
|
|
PMIA_UserData,curbox->object,
|
|
|
|
TAG_DONE),
|
2008-10-21 22:04:27 +04:00
|
|
|
TAG_DONE),
|
2008-10-25 20:37:08 +04:00
|
|
|
TAG_DONE),
|
2008-10-21 22:04:27 +04:00
|
|
|
~0);
|
2009-04-01 21:26:39 +04:00
|
|
|
|
|
|
|
menuhascontent = true;
|
2008-10-21 22:04:27 +04:00
|
|
|
}
|
|
|
|
|
2009-01-16 22:13:07 +03:00
|
|
|
if(curbox->text)
|
|
|
|
{
|
2010-07-24 20:39:37 +04:00
|
|
|
BOOL disabled_readonly = selection_read_only(gwin->bw->sel);
|
|
|
|
BOOL disabled_noselection = !selection_defined(gwin->bw->sel);
|
|
|
|
|
2009-01-16 22:13:07 +03:00
|
|
|
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
|
|
|
|
NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMSUB_SEL],
|
2010-07-24 20:39:37 +04:00
|
|
|
PMIA_SubMenu, NewObject(POPUPMENU_GetClass(), NULL,
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCUT],
|
|
|
|
PMIA_ID,CMID_SELCUT,
|
|
|
|
PMIA_Disabled, disabled_noselection && disabled_readonly,
|
|
|
|
TAG_DONE),
|
2009-01-16 22:13:07 +03:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCOPY],
|
|
|
|
PMIA_ID,CMID_SELCOPY,
|
2010-07-24 20:39:37 +04:00
|
|
|
PMIA_Disabled, disabled_noselection,
|
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELPASTE],
|
|
|
|
PMIA_ID,CMID_SELPASTE,
|
|
|
|
PMIA_Disabled, (gwin->bw->window->c_h == 0),
|
2009-01-16 22:13:07 +03:00
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELALL],
|
|
|
|
PMIA_ID,CMID_SELALL,
|
|
|
|
//PMIA_UserData,curbox->href,
|
|
|
|
TAG_DONE),
|
2010-07-24 20:39:37 +04:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCLEAR],
|
2010-08-08 13:23:34 +04:00
|
|
|
PMIA_ID,CMID_SELCLEAR,
|
2010-07-24 20:39:37 +04:00
|
|
|
PMIA_Disabled, disabled_noselection,
|
|
|
|
TAG_DONE),
|
2011-02-10 01:16:11 +03:00
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, ~0,
|
|
|
|
TAG_DONE),
|
|
|
|
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
|
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELSEARCH],
|
|
|
|
PMIA_ID,CMID_SELSEARCH,
|
|
|
|
PMIA_Disabled, disabled_noselection,
|
|
|
|
TAG_DONE),
|
2009-01-16 22:13:07 +03:00
|
|
|
TAG_DONE),
|
|
|
|
TAG_DONE),
|
|
|
|
~0);
|
2009-04-01 21:26:39 +04:00
|
|
|
|
|
|
|
menuhascontent = true;
|
2009-01-16 22:13:07 +03:00
|
|
|
}
|
|
|
|
|
2008-10-21 22:04:27 +04:00
|
|
|
if (curbox->gadget)
|
|
|
|
{
|
|
|
|
switch (curbox->gadget->type)
|
|
|
|
{
|
|
|
|
case GADGET_FILE:
|
|
|
|
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
|
|
|
|
NewObject(POPUPMENU_GetItemClass(), NULL,
|
2008-10-25 20:37:08 +04:00
|
|
|
PMIA_Title, (ULONG)ctxmenulab[CMID_SELECTFILE],
|
2008-10-21 22:04:27 +04:00
|
|
|
PMIA_ID,CMID_SELECTFILE,
|
2008-10-25 20:37:08 +04:00
|
|
|
PMIA_UserData,curbox,
|
2008-10-21 22:04:27 +04:00
|
|
|
TAG_DONE),
|
|
|
|
~0);
|
2009-04-01 21:26:39 +04:00
|
|
|
|
|
|
|
menuhascontent = true;
|
2008-10-21 22:04:27 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 21:26:39 +04:00
|
|
|
if(!menuhascontent) return;
|
|
|
|
|
2008-10-21 22:04:27 +04:00
|
|
|
gui_window_set_pointer(gwin->bw->window,GUI_POINTER_DEFAULT);
|
|
|
|
IDoMethod(gwin->objects[OID_MENU],PM_OPEN,gwin->win);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved)
|
|
|
|
{
|
|
|
|
int32 itemid = 0;
|
|
|
|
struct gui_window_2 *gwin = hook->h_Data;
|
|
|
|
APTR userdata = NULL;
|
2008-10-25 20:37:08 +04:00
|
|
|
struct browser_window *bw;
|
2010-03-28 19:51:05 +04:00
|
|
|
struct hlcache_handle *object;
|
|
|
|
char *source_data;
|
|
|
|
ULONG source_size;
|
|
|
|
struct bitmap *bm;
|
2008-10-21 22:04:27 +04:00
|
|
|
|
|
|
|
if(GetAttrs(item,PMIA_ID,&itemid,
|
|
|
|
PMIA_UserData,&userdata,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
switch(itemid)
|
|
|
|
{
|
|
|
|
case CMID_SELECTFILE:
|
2008-10-25 20:37:08 +04:00
|
|
|
if(AslRequestTags(filereq,
|
|
|
|
ASLFR_TitleText,messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen,scrn,
|
|
|
|
ASLFR_DoSaveMode,FALSE,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
struct box *box = userdata;
|
|
|
|
char *utf8_fn;
|
|
|
|
char fname[1024];
|
|
|
|
int x,y;
|
|
|
|
|
|
|
|
strlcpy(&fname,filereq->fr_Drawer,1024);
|
|
|
|
AddPart(fname,filereq->fr_File,1024);
|
|
|
|
|
|
|
|
if(utf8_from_local_encoding(fname,0,&utf8_fn) != UTF8_CONVERT_OK)
|
|
|
|
{
|
|
|
|
warn_user("NoMemory","");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(box->gadget->value);
|
|
|
|
box->gadget->value = utf8_fn;
|
|
|
|
|
|
|
|
box_coords(box, (int *)&x, (int *)&y);
|
|
|
|
gui_window_redraw(gwin->bw->window,x,y,
|
|
|
|
x + box->width,
|
|
|
|
y + box->height);
|
|
|
|
}
|
2008-10-21 22:04:27 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMID_COPYURL:
|
2008-10-25 20:37:08 +04:00
|
|
|
case CMID_COPYOBJ:
|
|
|
|
ami_easy_clipboard((char *)userdata);
|
2008-10-21 22:04:27 +04:00
|
|
|
break;
|
|
|
|
|
2008-10-25 20:37:08 +04:00
|
|
|
case CMID_URLOPENWIN:
|
2010-03-28 19:51:05 +04:00
|
|
|
bw = browser_window_create(userdata, gwin->bw,
|
|
|
|
content_get_url(gwin->bw->current_content), true, false);
|
2008-10-25 20:37:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMID_URLOPENTAB:
|
2010-03-28 19:51:05 +04:00
|
|
|
bw = browser_window_create(userdata, gwin->bw,
|
|
|
|
content_get_url(gwin->bw->current_content), true, true);
|
2008-10-21 22:04:27 +04:00
|
|
|
break;
|
|
|
|
|
2009-02-01 02:45:25 +03:00
|
|
|
case CMID_SAVEURL:
|
2010-03-28 19:51:05 +04:00
|
|
|
browser_window_download(gwin->bw, userdata,
|
|
|
|
content_get_url(gwin->bw->current_content));
|
2009-02-01 02:45:25 +03:00
|
|
|
break;
|
|
|
|
|
2008-10-25 20:37:08 +04:00
|
|
|
case CMID_SHOWOBJ:
|
2010-03-28 19:51:05 +04:00
|
|
|
browser_window_go(gwin->bw, userdata,
|
|
|
|
content_get_url(gwin->bw->current_content), true);
|
2008-10-21 22:04:27 +04:00
|
|
|
break;
|
2008-12-14 02:26:10 +03:00
|
|
|
|
2009-05-16 18:50:30 +04:00
|
|
|
case CMID_CLIPOBJ:
|
2010-03-28 19:51:05 +04:00
|
|
|
object = (struct hlcache_handle *)userdata;
|
|
|
|
if((bm = content_get_bitmap(object)))
|
2009-05-19 11:23:56 +04:00
|
|
|
{
|
2010-03-28 19:51:05 +04:00
|
|
|
bm->url = content_get_url(object);
|
|
|
|
bm->title = content_get_title(object);
|
|
|
|
ami_easy_clipboard_bitmap(bm);
|
2009-05-19 11:23:56 +04:00
|
|
|
}
|
|
|
|
#ifdef WITH_NS_SVG
|
2010-03-28 19:51:05 +04:00
|
|
|
else if(content_get_type(object) == CONTENT_SVG)
|
2009-05-19 11:23:56 +04:00
|
|
|
{
|
|
|
|
ami_easy_clipboard_svg(object);
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-16 18:50:30 +04:00
|
|
|
break;
|
|
|
|
|
2008-12-14 02:26:10 +03:00
|
|
|
case CMID_SAVEOBJ:
|
2010-03-28 19:51:05 +04:00
|
|
|
object = (struct hlcache_handle *)userdata;
|
2008-12-14 02:26:10 +03:00
|
|
|
|
2009-01-11 00:26:22 +03:00
|
|
|
if(AslRequestTags(savereq,
|
2008-12-14 02:26:10 +03:00
|
|
|
ASLFR_TitleText,messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen,scrn,
|
2010-03-28 19:51:05 +04:00
|
|
|
ASLFR_InitialFile,FilePart(content_get_url(object)),
|
2008-12-14 02:26:10 +03:00
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
BPTR fh = 0;
|
|
|
|
char fname[1024];
|
2009-01-11 00:26:22 +03:00
|
|
|
strlcpy(&fname,savereq->fr_Drawer,1024);
|
|
|
|
AddPart(fname,savereq->fr_File,1024);
|
2008-12-14 02:26:10 +03:00
|
|
|
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
|
|
|
|
if(fh = FOpen(fname,MODE_NEWFILE,0))
|
|
|
|
{
|
2010-03-28 19:51:05 +04:00
|
|
|
if((source_data = content_get_source_data(object, &source_size)))
|
|
|
|
FWrite(fh, source_data, 1, source_size);
|
|
|
|
|
2008-12-14 02:26:10 +03:00
|
|
|
FClose(fh);
|
2010-03-28 19:51:05 +04:00
|
|
|
SetComment(fname, content_get_url(object));
|
2008-12-14 02:26:10 +03:00
|
|
|
}
|
|
|
|
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
2009-01-16 22:13:07 +03:00
|
|
|
|
2009-05-16 18:50:30 +04:00
|
|
|
case CMID_SAVEIFFOBJ:
|
2010-03-28 19:51:05 +04:00
|
|
|
object = (struct hlcache_handle *)userdata;
|
2009-05-16 18:50:30 +04:00
|
|
|
|
|
|
|
if(AslRequestTags(savereq,
|
|
|
|
ASLFR_TitleText,messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen,scrn,
|
2010-03-28 19:51:05 +04:00
|
|
|
ASLFR_InitialFile,FilePart(content_get_url(object)),
|
2009-05-16 18:50:30 +04:00
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
BPTR fh = 0;
|
|
|
|
char fname[1024];
|
2010-03-28 19:51:05 +04:00
|
|
|
|
2009-05-16 18:50:30 +04:00
|
|
|
strlcpy(&fname,savereq->fr_Drawer,1024);
|
|
|
|
AddPart(fname,savereq->fr_File,1024);
|
2010-03-28 19:51:05 +04:00
|
|
|
if((bm = content_get_bitmap(object)))
|
2009-05-19 11:23:56 +04:00
|
|
|
{
|
2010-03-28 19:51:05 +04:00
|
|
|
bm->url = content_get_url(object);
|
|
|
|
bm->title = content_get_title(object);
|
|
|
|
bitmap_save(bm, fname, 0);
|
2009-05-19 11:23:56 +04:00
|
|
|
}
|
|
|
|
#ifdef WITH_NS_SVG
|
2010-03-28 19:51:05 +04:00
|
|
|
else if(content_get_type(object) == CONTENT_SVG)
|
2009-05-19 11:23:56 +04:00
|
|
|
{
|
|
|
|
ami_save_svg(object,fname);
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-28 19:51:05 +04:00
|
|
|
SetComment(fname, content_get_url(object));
|
2009-05-16 18:50:30 +04:00
|
|
|
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-07-24 20:39:37 +04:00
|
|
|
case CMID_SELCUT:
|
|
|
|
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
|
|
|
|
break;
|
|
|
|
|
2009-01-16 22:13:07 +03:00
|
|
|
case CMID_SELCOPY:
|
2009-02-01 16:01:46 +03:00
|
|
|
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
|
|
|
|
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
|
2009-01-16 22:13:07 +03:00
|
|
|
break;
|
|
|
|
|
2010-07-24 20:39:37 +04:00
|
|
|
case CMID_SELPASTE:
|
|
|
|
browser_window_key_press(gwin->bw, KEY_PASTE);
|
|
|
|
break;
|
|
|
|
|
2009-01-16 22:13:07 +03:00
|
|
|
case CMID_SELALL:
|
2009-02-01 16:01:46 +03:00
|
|
|
browser_window_key_press(gwin->bw, KEY_SELECT_ALL);
|
2010-08-08 13:23:34 +04:00
|
|
|
gui_start_selection(gwin->bw->window);
|
2009-01-16 22:13:07 +03:00
|
|
|
break;
|
2010-07-24 20:39:37 +04:00
|
|
|
|
|
|
|
case CMID_SELCLEAR:
|
|
|
|
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
|
|
|
|
break;
|
2011-02-10 01:16:11 +03:00
|
|
|
|
|
|
|
case CMID_SELSEARCH:
|
|
|
|
{
|
|
|
|
struct ami_context_menu_selection *sel;
|
|
|
|
char *url;
|
|
|
|
|
|
|
|
sel = AllocVec(sizeof(struct ami_context_menu_selection),
|
|
|
|
MEMF_PRIVATE | MEMF_CLEAR);
|
|
|
|
|
|
|
|
if(sel)
|
|
|
|
{
|
|
|
|
selection_traverse(gwin->bw->sel, ami_context_menu_copy_selection,
|
|
|
|
sel);
|
|
|
|
url = search_web_from_term(sel->text);
|
|
|
|
browser_window_go(gwin->bw, url, NULL, true);
|
|
|
|
|
|
|
|
FreeVec(sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-10-21 22:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemid;
|
|
|
|
}
|
2011-02-10 01:16:11 +03:00
|
|
|
|
|
|
|
bool ami_context_menu_copy_selection(const char *text, size_t length, struct box *box,
|
|
|
|
void *handle, const char *whitespace_text, size_t whitespace_length)
|
|
|
|
{
|
|
|
|
struct ami_context_menu_selection *sel = handle;
|
|
|
|
int len = length;
|
|
|
|
|
|
|
|
if((length + (sel->length)) > (sizeof(sel->text)))
|
|
|
|
len = sizeof(sel->text) - (sel->length);
|
|
|
|
|
|
|
|
if(len <= 0) return false;
|
|
|
|
|
|
|
|
memcpy((sel->text) + (sel->length), text, len);
|
|
|
|
sel->length += len;
|
|
|
|
|
|
|
|
sel->text[sel->length] = '\0';
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|