icons in popupmenus

I have seen this argument again and again over the years, but it seems without solution.
is there a reliable and cross platform way to have icons, or personalize in some way popupmenu and menu elements?

thank you

 Giulio

Well, it’s not an argument, but the native Xojo popupmenu’s don’t have a Icon property, I guess due to the native controls not having them.

You have to build your own subclass from a Canvas control, which is a little frustrating because you have to rebuild all the subtle functionality that goes into popupmenus. Usually there’s always that “one little thing” you miss and your users can tell.

Being part of REAL/Xojo for over 10 years I’ve always been surprised that none of the handful of 3rd party developers or just a well-meaning user hasn’t posted THE PopupMenuWithIcons class that “everyone” uses. AFAIK everyone thus far has written their own. (Unless I’m wrong, please correct.)

The nice thing, though, about creating your own is that you can reuse this in your own ListBox subclass, where you can put this popupmenu in a cell.

Creating your own basically means having internal graphics that represent Mac and Windows popupmenu styles. You implement "infinite length. You create an internal MenuItem and use Icons on that, and make sure it pulls down when you click on the arrows. Then you handle the menu selections. There are a lot of subtleties, like the width of the menuitem (which I don’t think I ever solved), autoselection of the “selection” item, and other things. But it’s pretty easy - perhaps that’s why there’s never been the ultimate custom control donated or sold.

(There is a discussion, not so much argument, about whether this should be in Xojo natively, but I think Xojo Corp. has established what level they are going to provide within the native framework. The way I see it, you get what you get, and if you don’t get it you can make your own, and once you’ve done it, you’re done.)

Lastly, and I’m not sure it’s worth mentioning, I’m using 2011r3 REAL still and the Windows side has a bug where icons screw up the look on top-level menus (not context-style though). This may be fixed in Xojo, I don’t know.

I don’t get this as I have no problems inserting icons in popup menu’s:

[code] dim aMenuItem as new MenuItem
dim bMenuItem as new MenuItem
aMenuItem.Text = “Expand all rows”
amenuItem.Icon = nodeinsertnext

base.Append( aMenuItem )
base.Append( new MenuItem( MenuItem.TextSeparator ) )
bMenuItem.Text = “Close al rows”
bMenuItem.Icon = nodeinsertkopie
base.Append( bMenuItem )[/code]

While it’s true that the PopupMenu cannot display icons, it’s easy to fake. In PopupMenu’s MouseDown event, set up a new MenuItem (as Alexander suggested above) and do MenuItem.Popup(thePopupMenu.GlobalX, thePopupMenu.GlobalY). Use the value returned from MenuItem.Popup to set the text in your popup menu.

It’s really quite elegant and visually similar to the regular popup menu. Note that you must calculate GlobalX and GlobalY for your popup; this is not provided by the framework.

[quote=58370:@Alexander van der Linden]I don’t get this as I have no problems inserting icons in popup menu’s:

[code] dim aMenuItem as new MenuItem
dim bMenuItem as new MenuItem
aMenuItem.Text = “Expand all rows”
amenuItem.Icon = nodeinsertnext

base.Append( aMenuItem )
base.Append( new MenuItem( MenuItem.TextSeparator ) )
bMenuItem.Text = “Close al rows”
bMenuItem.Icon = nodeinsertkopie
base.Append( bMenuItem )[/code][/quote]

Giulio talks about a Popupmenu, your code is from a contextual menu.

Here an experiment, a fake PopupMenu with icons.

Download Example

Icons can be added to Cocoa via either the Retina Kit, MacOSLib or MBS.

As for Windows… I’ll probably be exploring this for a future application.

thank you all for your suggestions,
I was hoping on a ‘native’ solution, since I have a need to add only few cusomized popupmenus in a project that is already developed and deployed to my customer ( both windows and mac os X ), and that has dozens of popupmenus everywhere, so I would incur in a not consistent interface ( popupmenus looking different graphically ), or a BIG redesign of all the stuff…
interesting solutions, indeed!

thanks

As Sam mentioned, this can be done with MacOSLib. Here is a quick and dirty example. This would work if your customer uses Macs. Maybe try windows functionality suite for Windows?

That seems to work if you want a 32x32 icon… I played with it. and could not get it to go beyond that…
I need to have full drawing control over the entire “cell”… (ie. there would be no text)
same thing could be done with a contextual menu