Discussion:
Dynamic menus
Alec Teal
2014-09-24 23:03:03 UTC
Permalink
Hey,

I've been thinking about asking this for a while and I've not found a
solution so here it goes:

What's the nicest way to create a dynamic menu (suppose I right click
and I want some options to show), I don't really want to map wxStrings
to some sort of data object and the ability to associate an integer of
my choice with menu items would be great!

I thought I saw a patch for this in 2.9.x somewhere but I can't find nor
use this. It's also not that nice.

So what's the policy? I've also checked the wxBook I've thought about
creating a menu and a special event handler object but it still seems a
rather large task.

Thanks,

Alec

Oh also I'd love it to work with 2.8 stuff but 3.0 stuff is good too!
Please update the wxWidgets book, I love that on my shelf, I've seen the
authors on here somewhere - I'm getting off topic!

Alec
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
David Connet
2014-09-24 23:17:37 UTC
Permalink
I've done it in a context menu where I bring up a list of user created items.

Basically, I created a wxMenu,
int id = baseId (a constant with a "good" starting number, mine's 100)

for (some_start; some_end; ++some_thing, ++id)

bind id to callback funciton
menu->AppendCheckItem(id, "my string")
parent->PopupMenu(menu, point);
id = baseId
for (some_start; some_end; ++some_thing, ++id)

unbind id

The callback function takes event.GetId()-baseId and uses that. (that value is basically an offset into a vector)

An MRU list of files is another example of a dynamic menu.

Dave
________________________________
Sent: Wednesday, September 24, 2014 4:03 PM
Subject: Dynamic menus
Hey,
I've been thinking about asking this for a while and I've not found a
What's the nicest way to create a dynamic menu (suppose I right click
and I want some options to show), I don't really want to map wxStrings
to some sort of data object and the ability to associate an integer of
my choice with menu items would be great!
I thought I saw a patch for this in 2.9.x somewhere but I can't find nor
use this. It's also not that nice.
So what's the policy? I've also checked the wxBook I've thought about
creating a menu and a special event handler object but it still seems a
rather large task.
Thanks,
Alec
Oh also I'd love it to work with 2.8 stuff but 3.0 stuff is good too!
Please update the wxWidgets book, I love that on my shelf, I've seen the
authors on here somewhere - I'm getting off topic!
Alec
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Alec Teal
2014-09-25 10:56:38 UTC
Permalink
While I am happy for the response I still don't feel safe using IDs like
that, I did think of pre-allocating (then binding to an ID range) a
swath of IDs but it doesn't mesh nicely with the usual menu.

To quote "another level of indirection solves every problem", I may have
dynamic menus but probably not dynamic menus of menus, having something
like MY_DYNAMIC_MENU as an ID then some integer data element would be a
perfect solution because it's elegant, it can be used in existing menus,
wont require messing with event handlers.

Anything like this?

Alec
Post by David Connet
I've done it in a context menu where I bring up a list of user created items.
Basically, I created a wxMenu,
int id = baseId (a constant with a "good" starting number, mine's 100)
for (some_start; some_end; ++some_thing, ++id)
bind id to callback funciton
menu->AppendCheckItem(id, "my string")
parent->PopupMenu(menu, point);
id = baseId
for (some_start; some_end; ++some_thing, ++id)
unbind id
The callback function takes event.GetId()-baseId and uses that. (that
value is basically an offset into a vector)
An MRU list of files is another example of a dynamic menu.
Dave
------------------------------------------------------------------------
*Sent:* Wednesday, September 24, 2014 4:03 PM
*Subject:* Dynamic menus
Hey,
I've been thinking about asking this for a while and I've not found a
What's the nicest way to create a dynamic menu (suppose I right click
and I want some options to show), I don't really want to map wxStrings
to some sort of data object and the ability to associate an integer of
my choice with menu items would be great!
I thought I saw a patch for this in 2.9.x somewhere but I can't find nor
use this. It's also not that nice.
So what's the policy? I've also checked the wxBook I've thought about
creating a menu and a special event handler object but it still seems a
rather large task.
Thanks,
Alec
Oh also I'd love it to work with 2.8 stuff but 3.0 stuff is good too!
Please update the wxWidgets book, I love that on my shelf, I've seen the
authors on here somewhere - I'm getting off topic!
Alec
--
Please read http://www.wxwidgets.org/support/mlhowto.htm
<http://www.wxwidgets.org/support/mlhowto.htm>before posting.
To unsubscribe, send email to
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...