diff options
Diffstat (limited to 'amiga/menu.c')
-rw-r--r-- | amiga/menu.c | 115 |
1 files changed, 84 insertions, 31 deletions
diff --git a/amiga/menu.c b/amiga/menu.c index 43c8c188b..70028af68 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -35,8 +35,6 @@ #include <images/label.h> #include <proto/bitmap.h> #include <images/bitmap.h> -#include <proto/glyph.h> -#include <images/glyph.h> #include <reaction/reaction_macros.h> @@ -358,13 +356,34 @@ void ami_menu_free_glyphs(void) menu_glyphs_loaded = false; } +static int ami_menu_calc_item_width(struct gui_window_2 *gwin, int j, struct RastPort *rp) +{ + int space_width = TextLength(rp, " ", 1); + int item_size; + + item_size = TextLength(rp, gwin->menulab[j], strlen(gwin->menulab[j])); + item_size += space_width; + + if(gwin->menukey[j]) { + item_size += TextLength(rp, &gwin->menukey[j], 1); + item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY]; + /**TODO: take account of the size of other imagery too + */ + } + + return item_size; +} + + static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) { int i, j; - int txtlen = 0; + int txtlen = 0, subtxtlen = 0; + int left_posn; struct RastPort *rp = &scrn->RastPort; struct DrawInfo *dri = GetScreenDrawInfo(scrn); - + int space_width = TextLength(rp, " ", 1); + if(menu_glyphs_loaded == false) ami_menu_load_glyphs(dri); @@ -373,18 +392,10 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) if(gwin->menutype[i] == NM_TITLE) { j = i + 1; txtlen = 0; - int item_size = 0; do { if(gwin->menulab[j] != NM_BARLABEL) { if(gwin->menutype[j] == NM_ITEM) { - item_size = TextLength(rp, gwin->menulab[j], strlen(gwin->menulab[j])); - if(gwin->menukey[j]) { - item_size += TextLength(rp, &gwin->menukey[j], 1); - item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY]; - /**TODO: take account of the size of other imagery too - */ - } - + int item_size = ami_menu_calc_item_width(gwin, j, rp); if(item_size > txtlen) { txtlen = item_size; } @@ -399,32 +410,75 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) using label.image if there's a bitmap associated with the item. */ if((gwin->menuicon[i] != NULL) && (gwin->menulab[i] != NM_BARLABEL)) { int icon_width = 0; + Object *blank_space = NULL; Object *submenuarrow = NULL; Object *icon = BitMapObject, BITMAP_Screen, scrn, BITMAP_SourceFile, gwin->menuicon[i], BITMAP_Masking, TRUE, BitMapEnd; + + /* \todo make this scale the bitmap to these dimensions */ + SetAttrs(icon, + BITMAP_Width, 16, + BITMAP_Height, 16, + TAG_DONE); + GetAttr(IA_Width, icon, (ULONG *)&icon_width); - + + if(gwin->menutype[i] == NM_SUB) { + left_posn = subtxtlen; + } else { + left_posn = txtlen; + } + + left_posn = left_posn - + TextLength(rp, gwin->menulab[i], strlen(gwin->menulab[i])) - + icon_width - space_width; + if((gwin->menutype[i] == NM_ITEM) && (gwin->menutype[i+1] == NM_SUB)) { + left_posn -= menu_glyph_width[NSA_GLYPH_SUBMENU]; + submenuarrow = NewObject(NULL, "sysiclass", - SYSIA_Which, MENUSUB, - SYSIA_DrawInfo, dri, - IA_Left, txtlen - TextLength(rp, gwin->menulab[i], strlen(gwin->menulab[i])) - - menu_glyph_width[NSA_GLYPH_SUBMENU] - icon_width, + SYSIA_Which, MENUSUB, + SYSIA_DrawInfo, dri, + IA_Left, left_posn, TAG_DONE); + + j = i + 1; + subtxtlen = 0; + do { + if(gwin->menulab[j] != NM_BARLABEL) { + if(gwin->menutype[j] == NM_SUB) { + int item_size = ami_menu_calc_item_width(gwin, j, rp); + if(item_size > subtxtlen) { + subtxtlen = item_size; + } + } + } + j++; + } while((gwin->menutype[j] == NM_SUB)); } /**TODO: Checkmark/MX images and keyboard shortcuts */ + + if(gwin->menutype[i] == NM_SUB) { + blank_space = NewObject(NULL, "fillrectclass", + IA_Height, 0, + IA_Width, left_posn + icon_width, + TAG_DONE); + } gwin->menuobj[i] = LabelObject, LABEL_DrawInfo, dri, LABEL_DisposeImage, TRUE, LABEL_Image, icon, + LABEL_Text, " ", LABEL_Text, gwin->menulab[i], LABEL_DisposeImage, TRUE, + LABEL_Image, blank_space, + LABEL_DisposeImage, TRUE, LABEL_Image, submenuarrow, LabelEnd; @@ -478,14 +532,6 @@ struct NewMenu *ami_create_menu(struct gui_window_2 *gwin) if(nsoption_bool(background_images) == true) gwin->menu[M_IMGBACK].nm_Flags |= CHECKED; - /* Set up scheduler to refresh the hotlist menu */ - if(nsoption_int(menu_refresh) > 0) - { - ami_schedule(nsoption_int(menu_refresh) * 10, - (void *)ami_menu_refresh, - gwin); - } - return(gwin->menu); } @@ -551,7 +597,7 @@ void ami_menu_arexx_scan(struct gui_window_2 *gwin) static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder) { UBYTE type; - char *icon; + STRPTR icon; struct gui_window_2 *gw = (struct gui_window_2 *)userdata; if(item >= AMI_MENU_HOTLIST_MAX) return false; @@ -570,9 +616,10 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char } if(is_folder == true) { - icon = "icons/directory.png"; + icon = ASPrintf("icons/directory.png"); } else { - icon = "icons/content.png"; + icon = ami_gui_get_cache_favicon_name(url, true); + if (icon == NULL) icon = ASPrintf("icons/content.png"); } ami_menu_alloc_item(gw, item, type, title, @@ -580,6 +627,8 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char if((is_folder == true) && (type == NM_SUB)) gw->menu[item].nm_Flags = NM_ITEMDISABLED; + if(icon) FreeVec(icon); + return true; } @@ -844,8 +893,12 @@ static void ami_menu_item_edit_copy(struct Hook *hook, APTR window, struct Intui } else if(bm = content_get_bitmap(gwin->bw->current_content)) { - bm->url = (char *)nsurl_access(hlcache_handle_get_url(gwin->bw->current_content)); - bm->title = (char *)content_get_title(gwin->bw->current_content); + /** @todo It should be checked that the lifetime of + * the objects containing the values returned (and the + * constness cast away) is safe. + */ + bm->url = (char *)nsurl_access(browser_window_get_url(gwin->bw)); + bm->title = (char *)browser_window_get_title(gwin->bw); ami_easy_clipboard_bitmap(bm); } #ifdef WITH_NS_SVG |