From 034ba7c2f2077bbc4f20628971bf2b061031ff9f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 May 2013 16:35:48 +0100 Subject: [PATCH 1/6] Allow getting the node's icon --- desktop/tree.c | 11 +++++++++++ desktop/tree.h | 1 + 2 files changed, 12 insertions(+) diff --git a/desktop/tree.c b/desktop/tree.c index c62793e02..e12da8b0b 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -1551,6 +1551,17 @@ const char *tree_node_element_get_text(struct node_element *element) } +/** + * Returns the node element's icon + * + * \return the node element's icon + */ +struct bitmap *tree_node_element_get_icon(struct node_element *element) +{ + return element->bitmap; +} + + /** * Get the root node of a tree * diff --git a/desktop/tree.h b/desktop/tree.h index 00ac99984..20ade30c0 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -200,6 +200,7 @@ void tree_update_node_element(struct tree *tree, struct node_element *element, const char *text, void *bitmap); bool tree_update_element_text(struct tree *tree, struct node_element *element, char *text); const char *tree_node_element_get_text(struct node_element *element); +struct bitmap *tree_node_element_get_icon(struct node_element *element); struct node *tree_get_root(struct tree *tree); bool tree_is_edited(struct tree *tree); tree_drag_type tree_drag_status(struct tree *tree); From 36b40e219a8edc587d6a196af83c4b30a94f200b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 May 2013 16:38:03 +0100 Subject: [PATCH 2/6] Get URL node icon --- desktop/tree_url_node.c | 11 +++++++++++ desktop/tree_url_node.h | 1 + 2 files changed, 12 insertions(+) diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c index 938cd1d69..541636f56 100644 --- a/desktop/tree_url_node.c +++ b/desktop/tree_url_node.c @@ -339,6 +339,17 @@ const char *tree_url_node_get_url(struct node *node) return tree_node_element_get_text(element); } + +struct bitmap *tree_url_node_get_icon(struct node *node) +{ + struct node_element *element; + element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); + if (element == NULL) + return NULL; + return tree_node_element_get_icon(element); +} + + void tree_url_node_edit_title(struct tree *tree, struct node *node) { struct node_element *element; diff --git a/desktop/tree_url_node.h b/desktop/tree_url_node.h index 1f0231df1..bcbc19296 100644 --- a/desktop/tree_url_node.h +++ b/desktop/tree_url_node.h @@ -43,6 +43,7 @@ void tree_update_URL_node(struct tree *tree, struct node *node, nsurl *url, const struct url_data *data); const char *tree_url_node_get_title(struct node *node); const char *tree_url_node_get_url(struct node *node); +struct bitmap *tree_url_node_get_icon(struct node *node); void tree_url_node_edit_title(struct tree *tree, struct node *node); void tree_url_node_edit_url(struct tree *tree, struct node *node); From f16f2f2904bd554955dd601f4c404489cff3439f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 May 2013 16:39:29 +0100 Subject: [PATCH 3/6] Get hotlist icons to use in menu creation --- amiga/menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/amiga/menu.c b/amiga/menu.c index 105b70166..3153e4cbf 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -458,7 +458,8 @@ void ami_menu_scan_2(struct tree *tree, struct node *root, WORD *gen, if(*gen == 1) menu_type = NM_ITEM; if(*gen == 2) menu_type = NM_SUB; - ami_menu_alloc_item(gwin, *item, menu_type, tree_url_node_get_title(node), 0, NULL, + ami_menu_alloc_item(gwin, *item, menu_type, tree_url_node_get_title(node), + 0, tree_url_node_get_icon(node), ami_menu_item_hotlist_entries, (void *)tree_url_node_get_url(node)); if(tree_node_is_folder(node) && (!tree_node_get_child(node))) gwin->menu[*item].nm_Flags = NM_ITEMDISABLED; From 2bce0185fe219181312ac377e659790291931e36 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 May 2013 16:50:39 +0100 Subject: [PATCH 4/6] Create menus with icons when using gadtools 53.5+ (hotlist only currently) --- amiga/menu.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/amiga/menu.c b/amiga/menu.c index 3153e4cbf..e1683932f 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -64,17 +64,6 @@ #include "utils/messages.h" #include "utils/schedule.h" -#define IMAGE_MENU_ITEM(n, i, t) \ - gwin->menulab[n] = LabelObject, \ - LABEL_DrawInfo, dri, \ - LABEL_DisposeImage, TRUE, \ - LABEL_Image, BitMapObject, \ - BITMAP_Screen, scrn, \ - BITMAP_SourceFile, i, \ - BitMapEnd, \ - LABEL_Text, t, \ - LabelEnd; - BOOL menualreadyinit; const char * const netsurf_version; const char * const verdate; @@ -169,7 +158,31 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, gwin->menulab[num] = ami_utf8_easy(messages_get(label)); } } - + + if((GadToolsBase->LibNode.lib_Version > 53) || + ((GadToolsBase->LibNode.lib_Version == 53) && (GadToolsBase->LibNode.lib_Revision >= 5)) { + /* GadTools 53.5+ only. For now we will only create the menu + using label.image if there's a bitmap associated with the item. */ + if(bitmap != NULL) { + struct DrawInfo *dri = GetScreenDrawInfo(scrn); + struct BitMap *menu_icon = ami_bitmap_get_native(bitmap, 16, 16, NULL); + + gwin->menuobj[n] = LabelObject, + LABEL_DrawInfo, dri, + LABEL_DisposeImage, TRUE, + LABEL_Image, BitMapObject, + BITMAP_Screen, scrn, + BITMAP_BitMap, menu_icon, + BITMAP_Width, 16, + BITMAP_Height, 16, + BitMapEnd, + LABEL_Text, gwin->menulab[num], + LabelEnd; + + FreeScreenDrawInfo(scrn, dri); + } + } + if(key) gwin->menukey[num] = key; if(func) gwin->menu_hook[num].h_Entry = (HOOKFUNC)func; if(hookdata) gwin->menu_hook[num].h_Data = hookdata; @@ -178,7 +191,6 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, void ami_init_menulabs(struct gui_window_2 *gwin) { int i; - struct DrawInfo *dri = GetScreenDrawInfo(scrn); gwin->menutype = AllocVec(AMI_MENU_AREXX_MAX + 1, MEMF_PRIVATE | MEMF_CLEAR); @@ -290,8 +302,6 @@ void ami_init_menulabs(struct gui_window_2 *gwin) ami_menu_item_arexx_execute, NULL); ami_menu_alloc_item(gwin, M_BAR_A1, NM_ITEM, NM_BARLABEL, 0, NULL, NULL, NULL); gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END; - - FreeScreenDrawInfo(scrn, dri); } /* Menu refresh for hotlist */ From ddbc8c7f6350f9978cc50deae74ecb4c053d790e Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 18 May 2013 16:55:37 +0100 Subject: [PATCH 5/6] Fix build --- amiga/menu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/amiga/menu.c b/amiga/menu.c index e1683932f..811f648ae 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -159,15 +159,15 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, } } - if((GadToolsBase->LibNode.lib_Version > 53) || - ((GadToolsBase->LibNode.lib_Version == 53) && (GadToolsBase->LibNode.lib_Revision >= 5)) { + if((GadToolsBase->lib_Version > 53) || + ((GadToolsBase->lib_Version == 53) && (GadToolsBase->lib_Revision >= 5))) { /* GadTools 53.5+ only. For now we will only create the menu using label.image if there's a bitmap associated with the item. */ - if(bitmap != NULL) { + if(bm != NULL) { struct DrawInfo *dri = GetScreenDrawInfo(scrn); - struct BitMap *menu_icon = ami_bitmap_get_native(bitmap, 16, 16, NULL); + struct BitMap *menu_icon = ami_bitmap_get_native(bm, 16, 16, NULL); - gwin->menuobj[n] = LabelObject, + gwin->menuobj[num] = LabelObject, LABEL_DrawInfo, dri, LABEL_DisposeImage, TRUE, LABEL_Image, BitMapObject, From fe2a80fe109e0e8dc60957ded5a93b39f429e1f1 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 19 May 2013 10:09:40 +0100 Subject: [PATCH 6/6] If using image menus, change the type to reflect that --- amiga/menu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/amiga/menu.c b/amiga/menu.c index 811f648ae..0d1925b8c 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-9 Chris Young + * Copyright 2008-9,2013 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -179,6 +179,8 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, LABEL_Text, gwin->menulab[num], LabelEnd; + gwin->menutype[num] |= MENU_IMAGE; + FreeScreenDrawInfo(scrn, dri); } }