Search code examples
c++togglewxwidgetsribbontogglebutton

How to get the state of a toggleButton in a ribbon in wxWidgets?


I'm building a UI using wxWidgets in windows platform with C++. I have a toggle button in the ribbon. I initialize the button as follows:

m_cell_bar->AddToggleButton(RIBBON_CELLSELECTMODE, wxT("Cell Select"), wxBitmap(selectcell_xpm), wxEmptyString);

To fulfill the purpose of using a toggle button, I need to assign different events from unchecked->checked and checked->unchecked events. If it was a normal toggle button I would use:

buttonid->GetValue()

But it's not.. So how can I reach the state?

Thanks...


Solution

  • It doesn't look like they provide a method for getting the checked state of a button (I'm working with 2.9.2). However it looks like you can get it using code like this (I've not tried this, just looked through the wx code):

    wxRibbonButtonBarButtonBase* button = m_cell_bar->AddToggleButton(RIBBON_CELLSELECTMODE, wxT("Cell Select"), wxBitmap(selectcell_xpm), wxEmptyString);
    // Store the "button" pointer for use later
    // ...
    // Sometime later
    if((button->state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED) == 0)
    {
        // Not checked
    }
    else
    {
        // Checked
    }