Fix parent of extra control not being a wxFileDialogBase on macOS

A wxEVT_UPDATE_UI handler expects the parent of the extra control panel
to be at least a wxFileDialogBase. However with wxMac when showing file
types the extra control gets reparented and has the panel containing
file type controls as a parent.

Fix by not reparenting in case the extra control itself already is
a panel, and then instead use the extra control as a container for
the file type controls.
This commit is contained in:
Dimitri Schoolwerth
2021-02-13 01:24:21 +01:00
parent 40422db37d
commit f048a03ea6

View File

@@ -246,16 +246,25 @@ void wxFileDialog::ShowWindowModal()
}
// Create a panel with the file type drop down list
// If extra controls need to be added (see wxFileDialog::SetExtraControlCreator), add
// them to the panel as well
// Returns the newly created wxPanel
// Fill a new or existing panel with the file type drop down list.
// If extra controls need to be added (see wxFileDialog::SetExtraControlCreator),
// use that as a panel if possible, otherwise add them to a new panel.
// Returns a newly created wxPanel or extracontrol if it's suitable as a filter
// panel.
wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol)
{
wxPanel *extrapanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
// Try to use extracontrol as a filter panel instead of creating a new one
// and then reparenting extracontrol. Reparenting is less desired as user
// code may expect the parent to be a wxFileDialog as on other platforms.
const bool useExtraControlAsPanel = extracontrol &&
wxDynamicCast(extracontrol, wxPanel) != NULL;
wxWindow* extrapanel = useExtraControlAsPanel
? extracontrol
: static_cast<wxWindow*>(new wxPanel(this));
wxBoxSizer *verticalSizer = new wxBoxSizer(wxVERTICAL);
extrapanel->SetSizer(verticalSizer);
// the file type control
{
@@ -278,13 +287,29 @@ wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol)
if(extracontrol)
{
wxBoxSizer *horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
verticalSizer->Add(horizontalSizer, 0, wxEXPAND, 0);
// Either use an extra control's existing sizer or the extra control
// itself, to be in the vertical sizer.
extracontrol->Reparent(extrapanel);
horizontalSizer->Add(extracontrol);
wxSizer* existingSizer = extracontrol->GetSizer();
if ( useExtraControlAsPanel && existingSizer )
{
// Move extra control's sizer to verticalSizer.
extracontrol->SetSizer(NULL, /* deleteOld = */ false);
verticalSizer->Add(existingSizer);
}
else
{
wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
verticalSizer->Add(horizontalSizer, 0, wxEXPAND, 0);
if ( !useExtraControlAsPanel )
extracontrol->Reparent(extrapanel);
horizontalSizer->Add(extracontrol);
}
}
extrapanel->SetSizer(verticalSizer);
verticalSizer->Layout();
verticalSizer->SetSizeHints(extrapanel);
return extrapanel;