diff --git a/Makefile.sources b/Makefile.sources index 7be7a1f3a..a84c0b072 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -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 diff --git a/amiga/context_menu.c b/amiga/context_menu.c new file mode 100755 index 000000000..55ea2ed29 --- /dev/null +++ b/amiga/context_menu.c @@ -0,0 +1,143 @@ +/* + * Copyright 2008 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/context_menu.h" +#include "render/box.h" +#include "render/form.h" +#include +#include +#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; +} diff --git a/amiga/context_menu.h b/amiga/context_menu.h new file mode 100755 index 000000000..e244c7b50 --- /dev/null +++ b/amiga/context_menu.h @@ -0,0 +1,32 @@ +/* + * Copyright 2008 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_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 diff --git a/amiga/gui.c b/amiga/gui.c index dfd7496b4..6295dc154 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -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 @@ -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; }