2008-08-25 17:32:26 +04:00
|
|
|
/*
|
2017-01-03 22:27:40 +03:00
|
|
|
* Copyright 2008-9, 2013, 2017 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-08-25 17:32:26 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-19 00:11:00 +03:00
|
|
|
#include "amiga/os3support.h"
|
|
|
|
|
2010-07-24 23:57:27 +04:00
|
|
|
#include <string.h>
|
2016-04-20 17:54:18 +03:00
|
|
|
#include <stdlib.h>
|
2010-07-24 23:57:27 +04:00
|
|
|
|
2011-03-16 22:23:24 +03:00
|
|
|
#include <proto/gadtools.h>
|
2017-01-15 19:05:07 +03:00
|
|
|
#include <proto/graphics.h>
|
2010-07-24 23:57:27 +04:00
|
|
|
#include <proto/intuition.h>
|
2011-03-16 22:23:24 +03:00
|
|
|
|
2010-07-24 23:57:27 +04:00
|
|
|
#include <libraries/gadtools.h>
|
2017-01-09 22:06:09 +03:00
|
|
|
#ifdef __amigaos4__
|
|
|
|
#include <intuition/menuclass.h>
|
|
|
|
#endif
|
2011-02-24 02:15:12 +03:00
|
|
|
|
2011-03-16 22:23:24 +03:00
|
|
|
#include <classes/window.h>
|
2011-02-24 02:15:12 +03:00
|
|
|
#include <proto/label.h>
|
|
|
|
#include <images/label.h>
|
|
|
|
#include <proto/bitmap.h>
|
|
|
|
#include <images/bitmap.h>
|
|
|
|
|
|
|
|
#include <reaction/reaction_macros.h>
|
2010-07-24 23:57:27 +04:00
|
|
|
|
2016-02-29 21:10:45 +03:00
|
|
|
#include "utils/log.h"
|
2017-01-15 19:10:23 +03:00
|
|
|
#include "utils/messages.h"
|
2014-10-13 18:08:16 +04:00
|
|
|
|
2011-03-16 22:23:24 +03:00
|
|
|
#include "amiga/gui.h"
|
2015-01-26 03:05:01 +03:00
|
|
|
#include "amiga/libs.h"
|
2011-03-16 22:23:24 +03:00
|
|
|
#include "amiga/menu.h"
|
|
|
|
#include "amiga/utf8.h"
|
2008-10-26 15:25:26 +03:00
|
|
|
|
2013-08-20 22:39:18 +04:00
|
|
|
enum {
|
|
|
|
NSA_GLYPH_SUBMENU,
|
|
|
|
NSA_GLYPH_AMIGAKEY,
|
|
|
|
NSA_GLYPH_CHECKMARK,
|
|
|
|
NSA_GLYPH_MX,
|
|
|
|
NSA_GLYPH_MAX
|
|
|
|
};
|
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
#define NSA_MAX_HOTLIST_MENU_LEN 100
|
2017-01-15 17:55:15 +03:00
|
|
|
|
2016-07-09 02:44:35 +03:00
|
|
|
static Object *restrict menu_glyph[NSA_GLYPH_MAX];
|
2016-06-02 02:44:20 +03:00
|
|
|
static int menu_glyph_width[NSA_GLYPH_MAX];
|
|
|
|
static bool menu_glyphs_loaded = false;
|
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg)
|
2017-01-15 00:04:51 +03:00
|
|
|
{
|
|
|
|
bool checked = false;
|
|
|
|
|
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
ULONG state;
|
|
|
|
struct ExtIntuiMessage *emsg = (struct ExtIntuiMessage *)msg;
|
|
|
|
|
2017-01-15 02:47:00 +03:00
|
|
|
state = IDoMethod((Object *)menu, MM_GETSTATE, 0, emsg->eim_LongCode, MS_CHECKED);
|
2017-01-15 00:04:51 +03:00
|
|
|
if(state & MS_CHECKED) checked = true;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
if(ItemAddress(menu, msg->Code)->Flags & CHECKED) checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return checked;
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
/* menu creation code */
|
2017-01-15 20:51:55 +03:00
|
|
|
void ami_menu_free_lab_item(struct ami_menu_data **md, int i)
|
2017-01-15 19:05:07 +03:00
|
|
|
{
|
|
|
|
if(md[i] == NULL) return;
|
|
|
|
if(md[i]->menulab &&
|
|
|
|
(md[i]->menulab != NM_BARLABEL) &&
|
|
|
|
(md[i]->menulab != ML_SEPARATOR)) {
|
|
|
|
if(md[i]->menutype & MENU_IMAGE) {
|
|
|
|
if(md[i]->menuobj) DisposeObject(md[i]->menuobj);
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
ami_utf8_free(md[i]->menulab);
|
2014-07-02 02:16:24 +04:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
if(md[i]->menukey != NULL) free(md[i]->menukey);
|
2014-07-01 21:29:10 +04:00
|
|
|
|
2017-01-15 19:05:07 +03:00
|
|
|
md[i]->menulab = NULL;
|
|
|
|
md[i]->menuobj = NULL;
|
|
|
|
md[i]->menukey = NULL;
|
|
|
|
md[i]->menutype = 0;
|
|
|
|
free(md[i]);
|
2017-01-15 23:01:49 +03:00
|
|
|
md[i] = NULL;
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
2008-08-25 17:32:26 +04:00
|
|
|
|
2017-01-05 21:50:38 +03:00
|
|
|
static void ami_menu_free_labs(struct ami_menu_data **md, int max)
|
2017-01-03 22:27:40 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-01-08 04:29:50 +03:00
|
|
|
for(i = 0; i <= max; i++) {
|
2017-01-15 19:05:07 +03:00
|
|
|
ami_menu_free_lab_item(md, i);
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
2012-04-29 19:59:37 +04:00
|
|
|
}
|
2008-10-05 17:17:18 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
|
2017-01-15 02:47:00 +03:00
|
|
|
const char *restrict label, const char *restrict key, const char *restrict icon,
|
2017-01-03 22:27:40 +03:00
|
|
|
void *restrict func, void *restrict hookdata, UWORD flags)
|
2012-04-29 19:59:37 +04:00
|
|
|
{
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num] = calloc(1, sizeof(struct ami_menu_data));
|
|
|
|
md[num]->menutype = type;
|
|
|
|
md[num]->flags = flags;
|
|
|
|
|
|
|
|
if(type == NM_END) return;
|
2009-08-23 19:59:41 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) {
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menulab = NM_BARLABEL;
|
2017-01-15 03:22:37 +03:00
|
|
|
icon = NULL;
|
2017-01-03 22:27:40 +03:00
|
|
|
} else { /* horrid non-generic stuff */
|
2017-01-15 23:01:49 +03:00
|
|
|
if((num >= AMI_MENU_AREXX) && (num < AMI_MENU_AREXX_MAX)) {
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menulab = strdup(label);
|
2015-02-24 02:16:34 +03:00
|
|
|
} else {
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menulab = ami_utf8_easy(messages_get(label));
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
|
|
|
}
|
2015-09-03 02:24:04 +03:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menuicon = NULL;
|
2017-01-15 02:47:00 +03:00
|
|
|
if(key) md[num]->menukey = strdup(key);
|
2017-01-03 22:27:40 +03:00
|
|
|
if(func) md[num]->menu_hook.h_Entry = (HOOKFUNC)func;
|
|
|
|
if(hookdata) md[num]->menu_hook.h_Data = hookdata;
|
2008-11-16 02:54:09 +03:00
|
|
|
|
2015-08-17 20:15:29 +03:00
|
|
|
#ifdef __amigaos4__
|
2017-01-15 23:01:49 +03:00
|
|
|
char menu_icon[1024];
|
|
|
|
|
2015-08-17 20:15:29 +03:00
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
|
|
|
|
if(icon) {
|
|
|
|
if(ami_locate_resource(menu_icon, icon) == true) {
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menuicon = (char *)strdup(menu_icon);
|
2015-08-17 20:15:29 +03:00
|
|
|
} else {
|
|
|
|
/* If the requested icon can't be found, put blank space in instead */
|
2017-01-03 22:27:40 +03:00
|
|
|
md[num]->menuicon = (char *)strdup(NSA_SPACE);
|
2015-08-17 20:15:29 +03:00
|
|
|
}
|
2015-06-16 21:36:09 +03:00
|
|
|
}
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
2015-08-17 20:15:29 +03:00
|
|
|
#endif
|
2012-04-29 19:59:37 +04:00
|
|
|
}
|
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
static void ami_menu_load_glyphs(struct DrawInfo *dri)
|
2012-04-29 19:59:37 +04:00
|
|
|
{
|
2015-02-24 02:16:34 +03:00
|
|
|
#ifdef __amigaos4__
|
2015-08-17 20:15:29 +03:00
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
|
|
|
|
for(int i = 0; i < NSA_GLYPH_MAX; i++)
|
|
|
|
menu_glyph[i] = NULL;
|
|
|
|
|
|
|
|
menu_glyph[NSA_GLYPH_SUBMENU] = NewObject(NULL, "sysiclass",
|
|
|
|
SYSIA_Which, MENUSUB,
|
|
|
|
SYSIA_DrawInfo, dri,
|
|
|
|
TAG_DONE);
|
|
|
|
menu_glyph[NSA_GLYPH_AMIGAKEY] = NewObject(NULL, "sysiclass",
|
|
|
|
SYSIA_Which, AMIGAKEY,
|
|
|
|
SYSIA_DrawInfo, dri,
|
|
|
|
TAG_DONE);
|
|
|
|
GetAttr(IA_Width, menu_glyph[NSA_GLYPH_SUBMENU],
|
|
|
|
(ULONG *)&menu_glyph_width[NSA_GLYPH_SUBMENU]);
|
|
|
|
GetAttr(IA_Width, menu_glyph[NSA_GLYPH_AMIGAKEY],
|
|
|
|
(ULONG *)&menu_glyph_width[NSA_GLYPH_AMIGAKEY]);
|
2015-02-24 02:16:34 +03:00
|
|
|
|
2015-08-17 20:15:29 +03:00
|
|
|
menu_glyphs_loaded = true;
|
|
|
|
}
|
2009-05-19 11:23:56 +04:00
|
|
|
#endif
|
2012-04-29 19:59:37 +04:00
|
|
|
}
|
2008-09-04 02:02:41 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
void ami_menu_free_glyphs(void)
|
2012-04-29 19:59:37 +04:00
|
|
|
{
|
2015-02-24 02:16:34 +03:00
|
|
|
#ifdef __amigaos4__
|
2015-08-17 20:15:29 +03:00
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
|
|
|
|
int i;
|
|
|
|
if(menu_glyphs_loaded == false) return;
|
|
|
|
|
|
|
|
for(i = 0; i < NSA_GLYPH_MAX; i++) {
|
|
|
|
if(menu_glyph[i]) DisposeObject(menu_glyph[i]);
|
|
|
|
menu_glyph[i] = NULL;
|
|
|
|
};
|
2015-02-24 02:16:34 +03:00
|
|
|
|
2015-08-17 20:15:29 +03:00
|
|
|
menu_glyphs_loaded = false;
|
|
|
|
}
|
2015-02-24 02:16:34 +03:00
|
|
|
#endif
|
2012-04-29 19:59:37 +04:00
|
|
|
}
|
2008-09-04 02:02:41 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
static int ami_menu_calc_item_width(struct ami_menu_data **md, int j, struct RastPort *rp)
|
2012-04-29 19:59:37 +04:00
|
|
|
{
|
2015-02-24 02:16:34 +03:00
|
|
|
int space_width = TextLength(rp, " ", 1);
|
|
|
|
int item_size;
|
2008-09-04 02:02:41 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
item_size = TextLength(rp, md[j]->menulab, strlen(md[j]->menulab));
|
2015-02-24 02:16:34 +03:00
|
|
|
item_size += space_width;
|
2008-12-14 02:23:24 +03:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[j]->menukey) {
|
2017-01-15 02:47:00 +03:00
|
|
|
item_size += TextLength(rp, md[j]->menukey, 1);
|
2015-02-24 02:16:34 +03:00
|
|
|
item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
|
|
|
|
/**TODO: take account of the size of other imagery too
|
|
|
|
*/
|
2015-06-16 21:36:09 +03:00
|
|
|
} else {
|
|
|
|
/* assume worst case - it doesn't really matter if we make menus wider */
|
|
|
|
item_size += TextLength(rp, "M", 1);
|
|
|
|
item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
|
|
|
|
}
|
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[j]->menuicon) {
|
2015-06-16 21:36:09 +03:00
|
|
|
item_size += 16;
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
2009-03-07 23:52:08 +03:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
return item_size;
|
2012-04-29 19:59:37 +04:00
|
|
|
}
|
2008-10-13 22:00:44 +04:00
|
|
|
|
2017-01-09 22:06:09 +03:00
|
|
|
#ifdef __amigaos4__
|
2017-01-15 02:47:00 +03:00
|
|
|
static int ami_menu_layout_mc_recursive(Object *menu_parent, struct ami_menu_data **md, int level, int i, int max)
|
2017-01-09 22:06:09 +03:00
|
|
|
{
|
2017-01-15 02:47:00 +03:00
|
|
|
int j;
|
2017-01-09 22:06:09 +03:00
|
|
|
Object *menu_item = menu_parent;
|
|
|
|
|
2017-01-15 02:47:00 +03:00
|
|
|
for(j = i; j < max; j++) {
|
2017-01-09 22:06:09 +03:00
|
|
|
/* skip empty entries */
|
2017-01-15 02:47:00 +03:00
|
|
|
if(md[j] == NULL) continue;
|
|
|
|
if(md[j]->menutype == NM_IGNORE) continue;
|
|
|
|
|
|
|
|
if(md[j]->menutype == level) {
|
|
|
|
if(md[j]->menulab == NM_BARLABEL)
|
|
|
|
md[j]->menulab = ML_SEPARATOR;
|
|
|
|
|
|
|
|
if(level == NM_TITLE) {
|
|
|
|
menu_item = NewObject(NULL, "menuclass",
|
|
|
|
MA_Type, T_MENU,
|
2017-01-17 01:24:05 +03:00
|
|
|
MA_ID, j,
|
2017-01-15 02:47:00 +03:00
|
|
|
MA_Label, md[j]->menulab,
|
|
|
|
TAG_DONE);
|
|
|
|
} else {
|
|
|
|
menu_item = NewObject(NULL, "menuclass",
|
|
|
|
MA_Type, T_ITEM,
|
|
|
|
MA_ID, j,
|
|
|
|
MA_Label, md[j]->menulab,
|
|
|
|
MA_Image,
|
|
|
|
BitMapObj,
|
|
|
|
IA_Scalable, TRUE,
|
|
|
|
BITMAP_Screen, scrn,
|
|
|
|
BITMAP_SourceFile, md[j]->menuicon,
|
|
|
|
BITMAP_Masking, TRUE,
|
|
|
|
BitMapEnd,
|
|
|
|
MA_Key, md[j]->menukey,
|
|
|
|
MA_UserData, &md[j]->menu_hook, /* NB: Intentionally UserData */
|
|
|
|
MA_Disabled, (md[j]->flags & NM_ITEMDISABLED),
|
|
|
|
MA_Selected, (md[j]->flags & CHECKED),
|
|
|
|
MA_Toggle, (md[j]->flags & MENUTOGGLE),
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
2017-01-15 23:15:10 +03:00
|
|
|
//LOG("Adding item %p ID %d (%s) to parent %p", menu_item, j, md[j]->menulab, menu_parent);
|
2017-01-09 22:06:09 +03:00
|
|
|
IDoMethod(menu_parent, OM_ADDMEMBER, menu_item);
|
2017-01-15 02:47:00 +03:00
|
|
|
continue;
|
|
|
|
} else if (md[j]->menutype > level) {
|
|
|
|
j = ami_menu_layout_mc_recursive(menu_item, md, md[j]->menutype, j, max);
|
2017-01-09 22:06:09 +03:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-15 02:47:00 +03:00
|
|
|
return (j - 1);
|
2017-01-09 22:06:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct Menu *ami_menu_layout_mc(struct ami_menu_data **md, int max)
|
|
|
|
{
|
|
|
|
Object *menu_root = NewObject(NULL, "menuclass",
|
|
|
|
MA_Type, T_ROOT,
|
2017-01-15 03:22:37 +03:00
|
|
|
MA_EmbeddedKey, FALSE,
|
2017-01-09 22:06:09 +03:00
|
|
|
TAG_DONE);
|
|
|
|
|
2017-01-15 02:47:00 +03:00
|
|
|
ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, 0, max);
|
2017-01-09 22:06:09 +03:00
|
|
|
|
|
|
|
return (struct Menu *)menu_root;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct Menu *ami_menu_layout_gt(struct ami_menu_data **md, int max)
|
2013-10-01 21:51:27 +04:00
|
|
|
{
|
2015-02-24 02:16:34 +03:00
|
|
|
int i, j;
|
2015-06-16 20:44:52 +03:00
|
|
|
int txtlen = 0;
|
2016-01-15 22:58:24 +03:00
|
|
|
int left_posn = 0;
|
2017-01-03 22:27:40 +03:00
|
|
|
struct NewMenu *nm;
|
|
|
|
struct Menu *imenu = NULL;
|
|
|
|
struct VisualInfo *vi;
|
2015-02-24 02:16:34 +03:00
|
|
|
struct RastPort *rp = &scrn->RastPort;
|
|
|
|
struct DrawInfo *dri = GetScreenDrawInfo(scrn);
|
|
|
|
int space_width = TextLength(rp, " ", 1);
|
2013-10-01 21:51:27 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
if(menu_glyphs_loaded == false)
|
|
|
|
ami_menu_load_glyphs(dri);
|
2013-10-01 21:51:27 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
nm = calloc(1, sizeof(struct NewMenu) * (max + 1));
|
|
|
|
if(nm == NULL) return NULL;
|
|
|
|
|
|
|
|
for(i = 0; i < max; i++) {
|
|
|
|
if(md[i] == NULL) {
|
|
|
|
nm[i].nm_Type = NM_IGNORE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(md[i]->menutype == NM_TITLE) {
|
2015-02-24 02:16:34 +03:00
|
|
|
j = i + 1;
|
|
|
|
txtlen = 0;
|
|
|
|
do {
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[j]->menulab != NM_BARLABEL) {
|
|
|
|
if(md[j]->menutype == NM_ITEM) {
|
|
|
|
int item_size = ami_menu_calc_item_width(md, j, rp);
|
2015-02-24 02:16:34 +03:00
|
|
|
if(item_size > txtlen) {
|
|
|
|
txtlen = item_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j++;
|
2017-01-03 22:27:40 +03:00
|
|
|
} while((j <= max) && (md[j] != NULL) && (md[j]->menutype != NM_TITLE) && (md[j]->menutype != 0));
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
|
|
|
#ifdef __amigaos4__
|
2015-06-20 20:09:44 +03:00
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
|
|
|
|
/* GadTools 53.7+ only. For now we will only create the menu
|
2015-02-24 02:16:34 +03:00
|
|
|
using label.image if there's a bitmap associated with the item. */
|
2017-01-03 22:27:40 +03:00
|
|
|
if((md[i]->menuicon != NULL) && (md[i]->menulab != NM_BARLABEL)) {
|
2015-02-24 02:16:34 +03:00
|
|
|
int icon_width = 0;
|
2016-07-09 02:44:35 +03:00
|
|
|
Object *restrict submenuarrow = NULL;
|
|
|
|
Object *restrict icon = BitMapObj,
|
2015-06-21 21:24:46 +03:00
|
|
|
IA_Scalable, TRUE,
|
2015-02-24 02:16:34 +03:00
|
|
|
BITMAP_Screen, scrn,
|
2017-01-03 22:27:40 +03:00
|
|
|
BITMAP_SourceFile, md[i]->menuicon,
|
2015-02-24 02:16:34 +03:00
|
|
|
BITMAP_Masking, TRUE,
|
|
|
|
BitMapEnd;
|
2013-10-01 21:51:27 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
/* \todo make this scale the bitmap to these dimensions */
|
|
|
|
SetAttrs(icon,
|
|
|
|
BITMAP_Width, 16,
|
|
|
|
BITMAP_Height, 16,
|
|
|
|
TAG_DONE);
|
2013-10-01 21:51:27 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
GetAttr(IA_Width, icon, (ULONG *)&icon_width);
|
2009-06-21 02:29:43 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[i]->menutype != NM_SUB) {
|
2015-02-24 02:16:34 +03:00
|
|
|
left_posn = txtlen;
|
|
|
|
}
|
2009-08-31 01:43:14 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
left_posn = left_posn -
|
2017-01-03 22:27:40 +03:00
|
|
|
TextLength(rp, md[i]->menulab, strlen(md[i]->menulab)) -
|
2015-02-24 02:16:34 +03:00
|
|
|
icon_width - space_width;
|
2008-10-13 22:00:44 +04:00
|
|
|
|
2017-01-12 21:32:06 +03:00
|
|
|
if((md[i]->menutype == NM_ITEM) && md[i+1] && (md[i+1]->menutype == NM_SUB)) {
|
2015-02-24 02:16:34 +03:00
|
|
|
left_posn -= menu_glyph_width[NSA_GLYPH_SUBMENU];
|
2011-03-24 22:34:59 +03:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
submenuarrow = NewObject(NULL, "sysiclass",
|
|
|
|
SYSIA_Which, MENUSUB,
|
|
|
|
SYSIA_DrawInfo, dri,
|
|
|
|
IA_Left, left_posn,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
2008-09-04 02:02:41 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
md[i]->menuobj = LabelObj,
|
2015-02-24 02:16:34 +03:00
|
|
|
LABEL_MenuMode, TRUE,
|
|
|
|
LABEL_DrawInfo, dri,
|
|
|
|
LABEL_DisposeImage, TRUE,
|
|
|
|
LABEL_Image, icon,
|
|
|
|
LABEL_Text, " ",
|
2017-01-03 22:27:40 +03:00
|
|
|
LABEL_Text, md[i]->menulab,
|
2015-02-24 02:16:34 +03:00
|
|
|
LABEL_DisposeImage, TRUE,
|
|
|
|
LABEL_Image, submenuarrow,
|
|
|
|
LabelEnd;
|
2012-12-15 18:21:15 +04:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[i]->menuobj) md[i]->menutype |= MENU_IMAGE;
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-03 22:27:40 +03:00
|
|
|
nm[i].nm_Type = md[i]->menutype;
|
2015-02-24 02:16:34 +03:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[i]->menuobj)
|
|
|
|
nm[i].nm_Label = (void *)md[i]->menuobj;
|
2015-02-24 02:16:34 +03:00
|
|
|
else
|
2017-01-03 22:27:40 +03:00
|
|
|
nm[i].nm_Label = md[i]->menulab;
|
2012-12-15 18:39:01 +04:00
|
|
|
|
2017-01-15 02:47:00 +03:00
|
|
|
if((md[i]->menukey) && (strlen(md[i]->menukey) > 1)) {
|
|
|
|
nm[i].nm_CommKey = md[i]->menukey;
|
|
|
|
}
|
2017-01-03 22:27:40 +03:00
|
|
|
nm[i].nm_Flags = md[i]->flags;
|
|
|
|
if(md[i]->menu_hook.h_Entry) nm[i].nm_UserData = &md[i]->menu_hook;
|
2015-08-17 00:51:32 +03:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
if(md[i]->menuicon) {
|
|
|
|
free(md[i]->menuicon);
|
|
|
|
md[i]->menuicon = NULL;
|
2015-02-24 02:16:34 +03:00
|
|
|
}
|
|
|
|
}
|
2012-12-15 18:39:01 +04:00
|
|
|
|
2015-02-24 02:16:34 +03:00
|
|
|
FreeScreenDrawInfo(scrn, dri);
|
2017-01-03 22:27:40 +03:00
|
|
|
|
|
|
|
vi = GetVisualInfo(scrn, TAG_DONE);
|
|
|
|
imenu = CreateMenus(nm, TAG_DONE);
|
|
|
|
LayoutMenus(imenu, vi,
|
|
|
|
GTMN_NewLookMenus, TRUE, TAG_DONE);
|
|
|
|
free(nm);
|
|
|
|
FreeVisualInfo(vi); /* Not using GadTools after layout so shouldn't need this */
|
2015-02-24 02:16:34 +03:00
|
|
|
|
2017-01-03 22:27:40 +03:00
|
|
|
return imenu;
|
2012-12-15 18:21:15 +04:00
|
|
|
}
|
|
|
|
|
2017-01-09 22:06:09 +03:00
|
|
|
struct Menu *ami_menu_layout(struct ami_menu_data **md, int max)
|
|
|
|
{
|
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
return ami_menu_layout_mc(md, max);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
return ami_menu_layout_gt(md, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-05 21:50:38 +03:00
|
|
|
void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu)
|
|
|
|
{
|
|
|
|
ami_menu_free_labs(md, max);
|
2017-01-09 22:06:09 +03:00
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
|
|
|
|
DisposeObject((Object *)imenu); // if we detach our menu from the window we need to do this manually
|
|
|
|
} else {
|
|
|
|
FreeMenus(imenu);
|
|
|
|
}
|
2017-01-05 21:50:38 +03:00
|
|
|
}
|
|
|
|
|
2017-01-15 20:51:55 +03:00
|
|
|
void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int menu_item, int max,
|
|
|
|
nserror (*cb)(struct ami_menu_data **md))
|
|
|
|
{
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
Object *restrict obj;
|
|
|
|
Object *restrict menu_item_obj;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(menu == NULL) return;
|
|
|
|
|
|
|
|
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
|
|
|
|
/* find the address of the menu */
|
|
|
|
menu_item_obj = (Object *)IDoMethod((Object *)menu, MM_FINDID, 0, menu_item);
|
2017-01-17 01:28:02 +03:00
|
|
|
|
2017-01-15 20:51:55 +03:00
|
|
|
/* remove all children */
|
|
|
|
while((obj = (Object *)IDoMethod(menu_item_obj, MM_NEXTCHILD, 0, NULL)) != NULL) {
|
|
|
|
IDoMethod(menu_item_obj, OM_REMMEMBER, obj);
|
2017-01-15 23:01:49 +03:00
|
|
|
DisposeObject(obj);
|
2017-01-15 20:51:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free associated data */
|
|
|
|
for(i = (menu_item + 1); i <= max; i++) {
|
|
|
|
if(md[i] == NULL) continue;
|
|
|
|
ami_menu_free_lab_item(md, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get current data */
|
|
|
|
cb(md);
|
|
|
|
|
|
|
|
/* re-add items to menu */
|
|
|
|
ami_menu_layout_mc_recursive(menu_item_obj, md, NM_ITEM, (menu_item + 1), max);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|