Intuition BOOPSI Menu support code

This forum is for general developer support questions.

Intuition BOOPSI Menu support code

Postby mritter0 » Thu Sep 10, 2015 9:47 pm

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 5:29 pm, edited 3 times in total.
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 210
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Intuition BOOPSI Menu support code

Postby mritter0 » Thu Sep 10, 2015 10:35 pm

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 Fri Sep 11, 2015 12:09 am, edited 1 time in total.
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 210
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Intuition BOOPSI Menu support code

Postby trixie » Thu Sep 10, 2015 11:01 pm

@mritter0

I updated my GadTools menu support code for the new Intuition BOOPSI Menus.

So where's the GadTools part? :-)
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 371
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: Intuition BOOPSI Menu support code

Postby mritter0 » Thu Sep 10, 2015 11:53 pm

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
mritter0
 
Posts: 210
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Intuition BOOPSI Menu support code

Postby trixie » Fri Sep 11, 2015 8:29 am

@mritter0

Sorry I was just being cheeky :-) I'm glad we no longer need GadTools now that the Menu Class is in place.
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 371
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: Intuition BOOPSI Menu support code

Postby thomasrapp » Fri Sep 11, 2015 9:47 am

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
thomasrapp
 
Posts: 253
Joined: Sun Jun 19, 2011 12:22 am

Re: Intuition BOOPSI Menu support code

Postby salass00 » Fri Sep 11, 2015 10:02 am

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.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 502
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron