diff --git a/include/wx/generic/aboutdlgg.h b/include/wx/generic/aboutdlgg.h index 5183bb433a..e004b048fe 100644 --- a/include/wx/generic/aboutdlgg.h +++ b/include/wx/generic/aboutdlgg.h @@ -55,8 +55,12 @@ public: bool Create(const wxAboutDialogInfo& info, wxWindow* parent = nullptr); protected: - // this virtual method may be overridden to add some more controls to the - // dialog + // Return the parent to use for custom controls. + wxWindow* GetCustomControlParent() const { return m_contents; } + + // This virtual method may be overridden to add some more controls to the + // dialog. The controls should be created using GetCustomControlParent() as + // the parent and then passed to AddControl(). // // notice that for this to work you must call Create() from the derived // class ctor and not use the base class ctor directly as otherwise the @@ -87,7 +91,7 @@ private: #endif // !wxUSE_MODAL_ABOUT_DIALOG // The panel containing the dialog contents. - wxPanel *m_contents = nullptr; + wxWindow *m_contents = nullptr; wxSizer *m_sizerText = nullptr; }; diff --git a/interface/wx/generic/aboutdlgg.h b/interface/wx/generic/aboutdlgg.h index fc951e9b97..da993fabdb 100644 --- a/interface/wx/generic/aboutdlgg.h +++ b/interface/wx/generic/aboutdlgg.h @@ -71,8 +71,10 @@ protected: This virtual method may be overridden to add more controls to the dialog. - Use the protected AddControl(), AddText() and AddCollapsiblePane() - methods to add custom controls. + The custom controls should be created with GetCustomControlParent() as + parent and then can be passed to the protected AddControl() method. + AddText() and AddCollapsiblePane() methods can also be used to add + simple static custom controls. This method is called during the dialog creation and you don't need to call it, only to override it. @@ -106,6 +108,15 @@ protected: Add a wxCollapsiblePane containing the given text. */ void AddCollapsiblePane(const wxString& title, const wxString& text); + + /** + Return the parent to use for custom controls. + + See DoAddCustomControls(). + + @since 3.3.0 + */ + wxWindow* GetCustomControlParent() const; }; /** diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index ca4a090e09..26c896e24f 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -3486,9 +3486,11 @@ public: // add some custom controls virtual void DoAddCustomControls() override { - AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); + const auto parent = GetCustomControlParent(); + + AddControl(new wxStaticLine(parent), wxSizerFlags().Expand()); AddText("Some custom text"); - AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); + AddControl(new wxStaticLine(parent), wxSizerFlags().Expand()); } };