How to hook wxEVT_SHOW for a wxPanel child of a wxDialog

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Gabriele Giuseppini
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Oct 12, 2018 6:12 pm

How to hook wxEVT_SHOW for a wxPanel child of a wxDialog

Post by Gabriele Giuseppini » Thu Jan 31, 2019 9:06 pm

Dear all,

I have a dialog that contains a custom control of mine, derived from wxScrolled<wxPanel>. I would like the custom control to be notified of it being shown when the parent dialog is shown, but it seems that wxEVT_SHOW is not fired.

The custom control registers its own handlers for wxEVT_SHOW and wxEVT_SIZE in the constructor, as follows:

Code: Select all

        
        
class ShipPreviewPanel : public wxScrolled<wxPanel>
{
	...
}        

ShipPreviewPanel::ShipPreviewPanel(wxWindow* parent)
    : wxScrolled<wxPanel>(
        parent,
        wxID_ANY,
        wxDefaultPosition,
        wxDefaultSize,
        wxBORDER_SIMPLE | wxVSCROLL)
{
    ...
    Bind(wxEVT_SHOW, &ShipPreviewPanel::OnShow, this, this->GetId());
    Bind(wxEVT_SIZE, &ShipPreviewPanel::OnResized, this, this->GetId());
    ...
}
The parent dialog later on shows "itself" as follows:

Code: Select all

std::optional<std::filesystem::path> ShipLoadDialog::Open()
{
    this->Show();
}
At this moment I can see that my custom control's OnResized handler is invoked, but OnShow is never invoked, not even when the parent wxDialog is closed. Yet the custom control is definitely visible.

In all of this I am assuming that child controls of a dialog would fire wxEVT_SHOW whenever they become visible, e.g. when the parent dialog becomes visible itself. Is my assumption incorrect? How are wxEVT_SHOW events fired and propagated?

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 689
Joined: Mon Apr 30, 2012 11:07 pm

Re: How to hook wxEVT_SHOW for a wxPanel child of a wxDialog

Post by Manolo » Fri Feb 01, 2019 1:13 am

In all of this I am assuming that child controls of a dialog would fire wxEVT_SHOW whenever they become visible
False.
From wxShowEvent docs
The event is triggered by calls to wxWindow::Show(), and any user action showing a previously hidden window or vice versa.
For example, the event is triggered when in your code you call myframe->Show(). But that event is not fired for the children of that frame (or any other wxTopLevelWindow).

What it's really fired for any control is the size-event. And currently you handle it. Perhaps you may want to handle also the paint-event.

Gabriele Giuseppini
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Oct 12, 2018 6:12 pm

Re: How to hook wxEVT_SHOW for a wxPanel child of a wxDialog

Post by Gabriele Giuseppini » Fri Feb 01, 2019 7:10 am

Clear, thanks for the clarification.

Post Reply