tags:

views:

201

answers:

1

I'm using a popup menu with wxTaskBarIcon on windows (wxWidgets-2.8.9). If I fill popup menu with radio items, they do not change state when clicked. First item in popup menu list is marked as selected. But selecting any other item does not change this.

Currently there is no item click event handler (application is more like UI prototype). Should i manually update item check status in this handler or it is still framework duty?

+1  A: 

You should use EVT_UPDATE_UI(yourCommandID, yourEventHandler) for checking/unchecking and enabling/disabling menu items. In your UpdateUI event handler you should specify cases when your item is enabled E.g. you have radiobutton group with commands ID_RADIO_1 and ID_RADIO_2 and they should be checked depending on condition bool m_SomeConditionVariable then you should create 2 event handlers for them like

void OnRadio1UpdateUI(wxUpdateUIEvent & event)
{
    event.Checked(m_SomeConditionVariable == true);
}

void OnRadio2UpdateUI(wxUpdateUIEvent & event)
{
    event.Checked(m_SomeConditionVariable == false);
}

and in this case first radio item will be checked only when variable is false and second will be checked when variable is true.

You can use also calculated condition instaed of storing variable e.g.

void OnRadio2UpdateUI(wxUpdateUIEvent & event)
{
    // Item will be enabled only when text control has non-empty value
    event.Enabled(!m_SomeTextCtrl->GetValue().Trim().IsEmpty());
}
T-Rex
There is one problem. I suppose to form this radioitem group (it is in submenu) dynamically (it is kind of timeouts list read from somewhere on startup).
jonny
You can add event handlers to your wxForm dynamically by using Connect() method. When you create you rmenu items, you can use wxNewId() for creating identifiers and then connect event handlers with these identifiers.After popup menu closed you have to disconnect these event handlers.
T-Rex