iKebab897
iKebab897

Reputation: 83

Call button click function from grandchild

I'm creating my first C++ wxWidgets application. I'm trying to create some kind of split button where the options are displayed in a grid. I have a custom button class which, when right-clicked on, opens a custom wxPopupTransientWindow that contains other buttons. When I click on the buttons in the popup, I want to simulate a left click on the main button. I'm trying to achieve this through events, but I'm kinda confused.

void expandButton::mouseReleased(wxMouseEvent& evt)
{
    if (pressed) {
        pressed = false;
        paintNow();

        wxWindow* mBtn = this->GetGrandParent();
        mBtn->SetLabel(this->GetLabel());
        mBtn->Refresh();

        wxCommandEvent event(wxEVT_BUTTON);
        event.SetId(GetId());
        event.SetEventObject(mBtn);
        mBtn-> //make it process the event somehow?

        wxPopupTransientWindow* popup = wxDynamicCast(this->GetParent(), wxPopupTransientWindow);
        popup->Dismiss();
    }
}

What is the best way to do this?

Upvotes: 0

Views: 216

Answers (1)

VZ.
VZ.

Reputation: 22688

You should do mBtn->ProcessWindowEvent() which is a shorter synonym for mBtn->GetEventHandler()->ProcessEvent() already mentioned in the comments.

Note that, generally speaking, you're not supposed to create wxEVT_BUTTON events from your own code. In this particular case and with current (and all past) version(s) of wxWidgets it will work, but a cleaner, and guaranteed to also work with the future versions, solution would be define your own custom event and generate it instead.

Upvotes: 1

Related Questions