Skip to main content
Inspiring
September 7, 2011
Question

How to create Popup context menus for a button

  • September 7, 2011
  • 1 reply
  • 1795 views

How to create  Popup context menus for a button,same as this:

This topic has been closed for replies.

1 reply

A. Patterson
Inspiring
September 7, 2011

Windows or Mac? On Windows, you have to add a line for your button that looks like this to the DIALOG resource section for your panel:

CONTROL         "Custom1",kThisIsTheButtonId,"ADM Popup Menu Type",WS_TABSTOP,118,92,19,16

The key bit is that (a) its CONTROL and (b) the class is "ADM Popup Menu Type". Its different for Mac, but its a pain so I won't go into that unless you need it.

Regardless of platform, after that, you do something like this (I'm using hte IADM* classes, but they're just wrappers):

// this assumes you're inside an IADMDialog derivitive, so I can use GetItem()

IADMItem button(GetItem(kThisIsTheButtonId));

IADMList list(button.GetList());

// this clears the list, but you only need to do this if you're updating it based on user interaction; ignore the next

// four lines if you're just setting your list once

const int count = list.NumberOfEntries();
   
for (int i = 0; i < count; i++) {
  list.RemoveEntry(0);
}

// end of clear code

IADMEntry entry(list.InsertEntry(0));

entry.SetText("Test item");

entry.SetID(0); // pick a value for when its clicked so you know what was clicked

// you can also use SetUserData() if you want to associate it with data

Lastly, you watch for the 'item changed notifier' as usual and look for kThisIsTheButtonId. If the the pop-up menu is clicked, you'll get that as your item ID. To figure out which menuitem was clicked though, you then do something like this:

IADMItem button(GetItem(kThisIsTheButtonId));
IADMList list(button.GetList());

ADMEntryRef entryRef = list.GetActiveEntry();

if (entryRef) {
  IADMEntry entry(entryRef);

  int clickedId = entry.GetID(); // here's how you tell

}

lyj2871Author
Inspiring
September 7, 2011

thank you