How to know when an popupmenu is aborted?

5 posts / 0 new
Last post
alfkil
alfkil's picture
Offline
Last seen: 4 months 1 week ago
Joined: 2011-05-10 22:02
How to know when an popupmenu is aborted?

Forget me for being such a noob on ReAction matters. But how on earth do you know when the user aborts the popupmenu without selecting an item? Apparently the MenuHandlerFunc is not called and I don't know enough about boopsi matters to figure out how to know such things otherwise.

jabirulo
jabirulo's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: 2013-05-30 00:53
Hi, I use

Hi, I use popupmenu(item).class in KeymapSwitcher and here is piece of code to "control" items:

  1. ...
  2. Object *chooseMenu;
  3. struct Hook *MenuHandler;
  4. ...
  5. MenuHandler = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
  6. ASOHOOK_Entry, MenuHandlerFunc,
  7. ASOHOOK_Data, Self,
  8. TAG_DONE);
  9.  
  10. chooseMenu = IIntuition->NewObject(PopupMenuClass, NULL,// "popupmenu.class",
  11. PMA_MenuHandler,MenuHandler, TAG_DONE);
  12.  
  13. ...
  14. IIntuition->IDoMethod(chooseMenu, PM_OPEN, dd->win); // show PopUp Menu
  15.  
  16. IIntuition->DisposeObject(chooseMenu);
  17. IExec->FreeSysObject(ASOT_HOOK, MenuHandler);
  18. }
  19.  
  20.  
  21. uint32 MenuHandlerFunc(struct Hook *hook, Object *o, APTR reserved)
  22. {
  23. struct DockyIFace *Self = (struct DockyIFace *)hook->h_Data;
  24. struct DockyData *dd = (struct DockyData *)((uint32)Self - Self->Data.NegativeSize);
  25. uint32 item_ID = 0;
  26.  
  27. if( IIntuition->GetAttr(PMIA_ID, o, &item_ID) )
  28. {
  29. switch(item_ID)
  30. {
  31. case MENU_OPT1:
  32. ...
  33. case MENU_PREFS:
  34. PrefsWindow_NP(Self, dd);
  35. break;
  36. }
  37. }
  38.  
  39. return(0);
  40. }

When no option is choosed I simple 'DisposeObject()', if an item is choosed it goes thru 'switch(item_ID)' code and ends (again to 'DisposeObject()').

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

alfkil
alfkil's picture
Offline
Last seen: 4 months 1 week ago
Joined: 2011-05-10 22:02
Ok, I must have confused

Ok, I must have confused another problem with the one I was having, as my code looks pretty much exactly like yours. For some reason, I must have believed, that the call to IDoMethod was asynchronous and thus was commited to the additional belief, that I needed a signal from the MenuHandlerFunc to get what I wanted. Although, if you actually need to know, if the user aborts, then I don't see any way to get that information. Which is perhaps.... strange...

jabirulo
jabirulo's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: 2013-05-30 00:53
Didn't try, but myabe if you

Didn't try, but myabe if you set a variable to return 0xFF (or whatever you want) in case no itemID matches or something alike then you'll know it popupmenu was "aborted/cancelled" or "used".

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

AND
AND's picture
Offline
Last seen: 7 years 7 months ago
Joined: 2011-01-20 12:22
You can check the result of

You can check the result of the IDoMethod call, like described in the popupmenu autodocs.
It is returning NULL, if the user did not select anything (which means that the popupmenu was aborted). Oterhwise it will return the popupmenuitem object.

uint32 result = IDoMethodA(APTR obj, struct pmOpen *msg);

FUNCTION
This method is used to open a popup menu.

INPUTS
obj - popupmenu object pointer
msg - pointer to fully initialized struct pmOpen
(see )

RESULT
The popupmenuitem object selected by the user or NULL
for nothing selected.

Off course the MenuHandlerFunc is not called, if the selection was aborted. So it is all pretty straight forward.

Log in or register to post comments