Re: [gtkmm] Access CheckMenuItem after inserted into menu?

Thanks Bryan, a bit of playing around and that worked. What I have done is create an array:
    struct {
        CheckMenuItem *item;
        const char *str;
    } data[MAX_CITEMS];

At run time I open the configuration file, and load in the items, filling in the array as you have suggested. Then when one of the items is changed I simply go through the array, and can identify exactly which items are currently set. It is actually a better solution than I expected to find.


Bryan Forbes wrote:

I had this problem trying to implement a message in a status bar when the user moves
his/her mouse over the menu item (yeah, I reimplemented something from libgnomeuimm... oh
well), but I found a solution that I've adapted to your problem:

1. Make some pointers to Gtk::CheckMenuItem (the number depends on how many
CheckMenuElems you have and/or how many you want to access.  For our example, we'll use
m_abc, m_def, and m_ghi (remember, this is in your class):

Gtk::CheckMenuItem *m_abc, *m_def, *m_ghi;

2. After push_back'ing the CheckMenuElems into the menu, assign one of your pointers the
address (I think) of the back method of menulist. Here's an example using your code:

    ClassTest::ClassTest() : somelabel("fred") {
      /* Construct the popup menu */
      Menu::MenuList &menulist = popup.items();
              SigC::slot(*this, &ClassTest::ChangeLabel)));
          m_abc = &menulist.back();
              SigC::slot(*this, &ClassTest::ChangeLabel)));
          m_def = &menulist.back();
              SigC::slot(*this, &ClassTest::ChangeLabel)));
          m_ghi = &menulist.back();
          /* ... could be any number of elements added ... */

3. Now access the check menu items by dereferencing them (->)


Disclaimer: I've only used this to check if the menu item (Gtk::MenuItem) has the mouse
over it, so this should work (given my limited experience) with Gtk::CheckMenuItem. I
hope this helps.  If I'm wrong, someone please correct me :).


> <original message snipped>

Damian (Winter)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]