Intuition BOOPSI Menu support code

This forum is for general developer support questions.
Post Reply
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Intuition BOOPSI Menu support code

Post by mritter0 »

I updated my GadTools menu support code for the new Intuition BOOPSI Menus. Maybe someone will find this handy:

Code: Select all

VOID VARARGS68K
SAK_SetMenuAttrs(Object *MenuObj,...)
{
	va_list                         VarArgs;
	struct TagItem                  *TagList, *ThisTag;
	Object							*item=NULL;

	va_startlinear(VarArgs,MenuObj);
	TagList=(struct TagItem *)va_getlinearva(VarArgs,struct TagItem *);

	while((ThisTag=IUtility->NextTagItem(&TagList)))
	{
		switch(ThisTag->ti_Tag)
		{
			case MA_ID:
				item=(Object *)IIntuition->IDoMethod(MenuObj,MM_FINDID,0,(uint32)ThisTag->ti_Data);
				break;

			case MA_Label:
				if (item)
				{
					IIntuition->SetAttrs(item,
						MA_Label,							(STRPTR)ThisTag->ti_Data,
					TAG_END);
				}
				break;

			case MA_Disabled:
				if (item)
				{
					IIntuition->SetAttrs(item,
						MA_Disabled,						(BOOL)ThisTag->ti_Data,
					TAG_END);
				}
				break;

			case MA_Selected:
				if (item)
				{
					IIntuition->SetAttrs(item,
						MA_Selected,						(BOOL)ThisTag->ti_Data,
					TAG_END);
				}
				break;

			case MA_UserData:
				if (item)
				{
					IIntuition->SetAttrs(item,
						MA_UserData,						(uint32)ThisTag->ti_Data,
					TAG_END);
				}
				break;
		}
	}

	va_end(VarArgs);
}
This will allow you to set the flags for one or several menu items at once:

Code: Select all

	SAK_SetMenuAttrs(MenuStripObj,
		MA_ID,								MEN_PANELS_BOOKMARKS,
			MA_Label,							"New label text",
			MA_Disabled,						TRUE,
			MA_Selected,						TRUE,
			MA_UserData,						5000,

		MA_ID,								MEN_PANELS_NAVIGATION,
			MA_Label,							"New label text again",
			MA_Disabled,						TRUE,
			MA_Selected,						TRUE,
			MA_UserData,						5001,
	TAG_DONE);
Share any thoughts and/or improvements.
Last edited by mritter0 on Fri Sep 11, 2015 4:29 pm, edited 3 times in total.
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: Intuition BOOPSI Menu support code

Post by mritter0 »

Add and remove items:

Code: Select all

BOOL
SAK_AddMenuItem(Object *MenuObj,uint32 Parent,Object *AddItem)
{
	Object				*item;

	if ((item=(Object *)IIntuition->IDoMethod(MenuObj,MM_FINDID,0,Parent)))
	{
		IIntuition->SetAttrs(item,
			MA_AddChild,						AddItem,
		TAG_END);

		return(TRUE);
	}

	return(FALSE);
}


VOID
SAK_RemoveMenuItem(Object *MenuObj,uint32 ID)
{
	Object				*item;

	if ((item=(Object *)IIntuition->IDoMethod(MenuObj,MM_FINDID,0,ID)))
	{
		IIntuition->SetAttrs(MenuObj,
			MA_RemoveChild,						item,
		TAG_END);
		IIntuition->DisposeObject(item);
	}
}
Use like this:

Code: Select all

Object *AddItem;
AddItem=MItem("New item added"), MA_ID, 6000, MEnd;
SAK_AddMenuItem(MenuStripObj,MEN_GO_MENU,AddItem);


SAK_RemoveMenuItem(MenuStripObj,MEN_ABOUT);
Last edited by mritter0 on Thu Sep 10, 2015 11:09 pm, edited 1 time in total.
Workbench Explorer - A better way to browse drawers
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Intuition BOOPSI Menu support code

Post by trixie »

@mritter0
I updated my GadTools menu support code for the new Intuition BOOPSI Menus.
So where's the GadTools part? :-)
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: Intuition BOOPSI Menu support code

Post by mritter0 »

Maybe "replaced my GadTools code" with code for the new menus is better wording. I still have it if you want it.
Workbench Explorer - A better way to browse drawers
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Intuition BOOPSI Menu support code

Post by trixie »

@mritter0

Sorry I was just being cheeky :-) I'm glad we no longer need GadTools now that the Menu Class is in place.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Intuition BOOPSI Menu support code

Post by thomasrapp »

mritter0 wrote:

Code: Select all

	va_startlinear(VarArgs,MenuObj);
	TagList=(struct TagItem *)va_getlinearva(VarArgs,(struct TagItem *));
	va_end(VarArgs);

	while((ThisTag=IUtility->NextTagItem(&TagList)))
	{
I am not sure if this is legal usage of linear var args. I would put the va_end at the end of the function, otherwise the tag list could be destroyed while you use it.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: Intuition BOOPSI Menu support code

Post by salass00 »

As thomasrapp says I think the va_end() should be at the end of the function to be correct as now you are using the varargs still after calling va_end().

Also the FoundID variable seems completely unnecessary. Just initialize the item variable to NULL on function start and check if it's non-NULL in the same way you check FoundID now.
Post Reply