diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2015-09-04 00:26:52 +0100 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2015-09-04 00:26:52 +0100 |
commit | 41f219192c6a9ee34a14d0cb149946eff9eeec50 (patch) | |
tree | 989c9448246342cc761fad523d15abe4d653a58f /amiga/ctxmenu.c | |
parent | cdaae7b30e22373b99117438a15e062e8749688d (diff) | |
download | netsurf-41f219192c6a9ee34a14d0cb149946eff9eeec50.tar.gz netsurf-41f219192c6a9ee34a14d0cb149946eff9eeec50.tar.bz2 |
Create back/forward context menu using menuclass
Reconstructs itself periodically as it cannot be created on demand
Diffstat (limited to 'amiga/ctxmenu.c')
-rw-r--r-- | amiga/ctxmenu.c | 144 |
1 files changed, 130 insertions, 14 deletions
diff --git a/amiga/ctxmenu.c b/amiga/ctxmenu.c index bf16e21b0..1fe34baad 100644 --- a/amiga/ctxmenu.c +++ b/amiga/ctxmenu.c @@ -41,6 +41,7 @@ #include "amiga/utf8.h" #include "desktop/browser.h" +#include "desktop/browser_history.h" #include "desktop/mouse.h" #include "utils/log.h" @@ -52,6 +53,27 @@ enum { AMI_CTX_ID_URLOPEN, AMI_CTX_ID_URLOPENWIN, AMI_CTX_ID_URLOPENTAB, + AMI_CTX_ID_HISTORY, + AMI_CTX_ID_HISTORY0, + AMI_CTX_ID_HISTORY1, + AMI_CTX_ID_HISTORY2, + AMI_CTX_ID_HISTORY3, + AMI_CTX_ID_HISTORY4, + AMI_CTX_ID_HISTORY5, + AMI_CTX_ID_HISTORY6, + AMI_CTX_ID_HISTORY7, + AMI_CTX_ID_HISTORY8, + AMI_CTX_ID_HISTORY9, + AMI_CTX_ID_HISTORY0F, + AMI_CTX_ID_HISTORY1F, + AMI_CTX_ID_HISTORY2F, + AMI_CTX_ID_HISTORY3F, + AMI_CTX_ID_HISTORY4F, + AMI_CTX_ID_HISTORY5F, + AMI_CTX_ID_HISTORY6F, + AMI_CTX_ID_HISTORY7F, + AMI_CTX_ID_HISTORY8F, + AMI_CTX_ID_HISTORY9F, AMI_CTX_ID_MAX }; @@ -62,11 +84,6 @@ static char *ctxmenu_item_label[AMI_CTX_ID_MAX]; static Object *ctxmenu_item_image[AMI_CTX_ID_MAX]; /** Menu functions - called automatically by RA_HandleInput **/ -HOOKF(void, ami_ctxmenu_item_test, APTR, window, struct IntuiMessage *) -{ - printf("testing\n"); -} - HOOKF(void, ami_ctxmenu_item_urlopentab, APTR, window, struct IntuiMessage *) { struct browser_window *bw; @@ -101,6 +118,16 @@ HOOKF(void, ami_ctxmenu_item_urlopenwin, APTR, window, struct IntuiMessage *) warn_user(messages_get_errorcode(error), 0); } +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); +} + + /** Add an initialised item to a context menu **/ static void ami_ctxmenu_add_item(Object *root_menu, int id, APTR data) @@ -169,16 +196,19 @@ static uint32 ami_ctxmenu_hook_func(struct Hook *hook, struct Window *window, st static void ami_ctxmenu_alloc_item(int id, const char *label, const char *image, void *func) { ctxmenu_item_label[id] = ami_utf8_easy(messages_get(label)); - 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); + 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); + } ctxmenu_item_hook[id].h_Entry = func; ctxmenu_item_hook[id].h_Data = 0; @@ -224,5 +254,91 @@ void ami_ctxmenu_free(void) if(ctxmenu_obj != NULL) DisposeObject(ctxmenu_obj); ctxmenu_obj = NULL; } + + + +/** 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]; +} + + + #endif |