Add wxGenericAboutDialog::GetCustomControlParent()

This function should be used to get the parent for the custom controls
instead of relying on them being reparented under it by the code added
in the last commit.

Change the type of m_contents to be wxWindow and not wxPanel as it
doesn't really matter, but wxPanel is not fully declared in this header
while wxWindow is.
This commit is contained in:
Vadim Zeitlin 2023-06-20 17:50:20 +01:00
parent 6e0198fffb
commit d5ef9d4387
3 changed files with 24 additions and 7 deletions

View file

@ -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;
};

View file

@ -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;
};
/**

View file

@ -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());
}
};