Initial context menus. Five possible options (copy link to clipboard, download link,

show object, save object and select file for upload), only one implemented at the
moment.  Menu structure/strings need some thought and tidy-up (with object and URL
options in their own sub-menus?)

svn path=/trunk/netsurf/; revision=5612
This commit is contained in:
Chris Young 2008-10-21 18:04:27 +00:00
parent 8f5266e61e
commit 5624bf590d
4 changed files with 186 additions and 4 deletions

View File

@ -90,7 +90,7 @@ S_DEBUG := $(addprefix debug/,$(S_DEBUG))
S_AMIGA := compat.c gui.c tree.c history.c hotlist.c schedule.c \
thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \
plotters.c object.c menu.c save_pdf.c arexx.c version.c \
cookies.c
cookies.c context_menu.c
S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# S_FRAMEBUFFER are sources purely for the framebuffer build

143
amiga/context_menu.c Executable file
View File

@ -0,0 +1,143 @@
/*
* Copyright 2008 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/>.
*/
#include "amiga/context_menu.h"
#include "render/box.h"
#include "render/form.h"
#include <proto/popupmenu.h>
#include <proto/intuition.h>
#include "amiga/utf8.h"
#include "utils/messages.h"
uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved);
void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y)
{
struct box *curbox = gwin->bw->current_content->data.html.layout;
struct content *cc = gwin->bw->current_content;
int box_x=0;
int box_y=0;
if(cc->type != CONTENT_HTML) return;
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);
while(curbox = box_at_point(curbox,x,y,&box_x,&box_y,&cc))
{
if (curbox->style && curbox->style->visibility == CSS_VISIBILITY_HIDDEN) continue;
if(curbox->href)
{
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ami_utf8_easy((char *)messages_get("CopyURL")),
PMIA_ID,CMID_COPYURL,
PMIA_UserData,curbox->href,
TAG_DONE),
~0);
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ami_utf8_easy((char *)messages_get("SaveURL")),
PMIA_ID,CMID_SAVEURL,
PMIA_UserData,curbox->href,
TAG_DONE),
~0);
}
if (curbox->object)
{
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ami_utf8_easy((char *)messages_get("ObjShow")),
PMIA_ID,CMID_SHOWOBJ,
PMIA_UserData,curbox->object->url,
TAG_DONE),
~0);
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ami_utf8_easy((char *)messages_get("ObjSave")),
PMIA_ID,CMID_SAVEOBJ,
PMIA_UserData,curbox->object->url,
TAG_DONE),
~0);
}
if (curbox->gadget)
{
switch (curbox->gadget->type)
{
case GADGET_FILE:
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ami_utf8_easy((char *)messages_get("SelectFile")),
PMIA_ID,CMID_SELECTFILE,
PMIA_UserData,curbox->gadget,
TAG_DONE),
~0);
break;
}
}
}
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;
if(GetAttrs(item,PMIA_ID,&itemid,
PMIA_UserData,&userdata,
TAG_DONE))
{
switch(itemid)
{
case CMID_SELECTFILE:
printf("select file - gadget %lx\n",userdata);
break;
case CMID_COPYURL:
printf("add to clipboard: %s\n",userdata);
break;
case CMID_SHOWOBJ:
browser_window_go(gwin->bw,userdata,NULL,true);
break;
case CMID_SAVEOBJ:
case CMID_SAVEURL:
printf("download: %s\n",userdata);
break;
}
}
return itemid;
}

32
amiga/context_menu.h Executable file
View File

@ -0,0 +1,32 @@
/*
* Copyright 2008 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/>.
*/
#ifndef AMIGA_CONTEXT_MENU_H
#define AMIGA_CONTEXT_MENU_H
#include "amiga/gui.h"
enum {
CMID_SELECTFILE,
CMID_COPYURL,
CMID_SAVEURL,
CMID_SHOWOBJ,
CMID_SAVEOBJ
};
void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y);
#endif

View File

@ -66,6 +66,8 @@
#include "amiga/arexx.h"
#include "amiga/hotlist.h"
#include "amiga/history.h"
#include "amiga/context_menu.h"
#include "amiga/cookies.h"
#ifdef WITH_HUBBUB
#include <hubbub/hubbub.h>
@ -145,6 +147,7 @@ void ami_scroller_hook(struct Hook *,Object *,struct IntuiMessage *);
uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved);
void ami_do_redraw(struct gui_window_2 *g);
void ami_init_mouse_pointers(void);
void ami_switch_tab(struct gui_window_2 *gwin,bool redraw);
#ifdef WITH_HUBBUB
static void *myrealloc(void *ptr, size_t len, void *pw);
#endif
@ -566,6 +569,10 @@ void ami_handle_msg(void)
browser_window_mouse_click(gwin->bw,BROWSER_MOUSE_PRESS_2 | gwin->key_state,x,y);
gwin->mouse_state=BROWSER_MOUSE_PRESS_2;
break;
case MENUDOWN:
ami_context_menu_show(gwin,x,y);
break;
}
}
@ -2569,12 +2576,14 @@ void gui_create_form_select_menu(struct browser_window *bw,
struct form_option *opt = control->data.select.items;
ULONG i = 0;
if(gwin->shared->objects[OID_MENU]) DisposeObject(gwin->shared->objects[OID_MENU]);
gwin->shared->popuphook.h_Entry = ami_popup_hook;
gwin->shared->popuphook.h_Data = gwin;
gwin->shared->control = control;
gwin->shared->objects[OID_MENU] = PMMENU(messages_get("NetSurf")),
gwin->shared->objects[OID_MENU] = PMMENU(ami_utf8_easy(control->name)),
PMA_MenuHandler, &gwin->shared->popuphook,End;
while(opt)
@ -2634,8 +2643,6 @@ uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved)
browser_window_form_select(gwin->shared->bw,gwin->shared->control,itemid);
}
// DisposeObject(gwin->objects[OID_MENU]);
return itemid;
}