I have a menustrip created through GadTools. The individual menu items are referenced by IDs:
enum { MID_OPEN=1, MID_SAVE, MID_ABOUT, MID_QUIT };
which I pass in the nm_UserData field of the NewMenu structure.
During the course of the program, I need to enable or disable certain menu items, depending on program state. I know there is OnMenu() and OffMenu(), and how to use the ITEMNUM() macro to extract the appropriate menu number from the IDCMP_MENUPICK message.
However, I need to change the menu item state regardless of user menu selections, ie. with no IDCMP_MENUPICK messages involved. How do I get the correct menu number to pass as an argument to OnMenu() / OffMenu()? Let's say I want to disable the first two items, referenced by MID_OPEN and MID_SAVE.
Hi trixie,
Do you know what order your menus are in? If so, you can construct the MenuNumber manually using information in the Menu chapter of the RKRM.
ie) It is a 16-bit value with the bits assigned as follows:
Bit 15-11: Sub-Item number.
Bit 10-5: Menu Item number.
Bit 4-0: Menu number.
So, to select the Copy item from the Edit menu in a menu such as the one below:
The number for Doggy-Paddle would be 0x0042 using the same formula.
Hope that helps.
Oops, sorry. I made a small (but vital) mistake. If there is no subitem/item/menu selected, then all bits for that particular part are set to 1.
So, the copy menuitem is actually:
SUB=%11111 ITEM=%000001 MENU=%00001, or 0xF821 when combined into the expected 16-bit value.
This is because there is no sub-item.
@steady
Thanks for the reply.
The thing is, I do have access to all the menu structures, and I currently handle item enabling/disabling by setting the appropriate flag in struct MenuItem. It works but it feels so low-level this direct structure manipulation! Gadtools has spared us from menu structure filling and linking - I can't believe we're still stuck with the old Intuition stuff when it comes to item enabling and disabling!
High time someone grabbed this project I suggested over at OpenAmiga.org.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
All right, I found my answers in SDK:Examples/ReAction/os4examples/Menus/Intuition/menus.c. It appears I cannot use my menu IDs passed in nm_UserData as I wanted, but at least it's a way that requires no direct manipulation of the menu structures. So I consider it a problem solved.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
I guess you're talking about the FULLMENUNUM macro. I didn't see that but it is a nicer way to achieve the same thing.
Glad you got it resolved.
Yes, the solution was to use the FULLMENUNUM() macro, which however needed a different use of menu IDs.
Previously I used a single enum of menu IDs (see the first post in this thread) that I stored in the nm_UserData field of the NewMenu structure. Then, in the input event loop, I identified the selected menu choices using the GTMENUITEM_USERDATA() macro.
However, to be able to use OnMenu() and OffMenu() the way I wanted, I had to do it differently. I needed an enum for all menus in the strip, such as this
and a number of enums corresponding to the number of menus above:
This of course required a change in the event loop, because I could no longer use the menu user data. It now looks like this:
All this is a little longer and more complicated than using the user data but the added benefit is that I can now turn on/off any menu item from any part of the code:
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2