diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index 65731b722b..fa53e25620 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -194,13 +194,13 @@ protected: wxWindow* m_extraControl; - // returns true if control is created (if it already exists returns false) + // create and return the extra control using the given parent + wxWindow* CreateExtraControlWithParent(wxWindow* parent) const; + // returns true if control is created, also sets m_extraControl bool CreateExtraControl(); // return true if SetExtraControlCreator() was called bool HasExtraControlCreator() const { return m_extraControlCreator != NULL; } - // get the size of the extra control by creating and deleting it - wxSize GetExtraControlSize(); // Helper function for native file dialog usage where no wx events // are processed. void UpdateExtraControlUI(); diff --git a/src/common/fldlgcmn.cpp b/src/common/fldlgcmn.cpp index d57b4b8110..09e0edfefc 100644 --- a/src/common/fldlgcmn.cpp +++ b/src/common/fldlgcmn.cpp @@ -368,35 +368,24 @@ bool wxFileDialogBase::SetExtraControlCreator(ExtraControlCreatorFunction creato return SupportsExtraControl(); } +wxWindow* wxFileDialogBase::CreateExtraControlWithParent(wxWindow* parent) const +{ + if ( m_extraControlCreator ) + return (*m_extraControlCreator)(parent); + + // It's not an error to call this function if there are no extra controls + // to create, just do nothing in this case. + return NULL; +} + bool wxFileDialogBase::CreateExtraControl() { // We're not supposed to be called more than once normally, but just do // nothing if we had already created the custom controls somehow. - if ( m_extraControl ) - return true; + if ( !m_extraControl ) + m_extraControl = CreateExtraControlWithParent(this); - if ( m_extraControlCreator ) - { - m_extraControl = (*m_extraControlCreator)(this); - - return true; - } - - // It's not an error to call this function if there are no extra controls - // to create, just do nothing in this case. - return false; -} - -wxSize wxFileDialogBase::GetExtraControlSize() -{ - if ( !m_extraControlCreator ) - return wxDefaultSize; - - // create the extra control in an empty dialog just to find its size: this - // is not terribly efficient but we do need to know the size before - // creating the native dialog and this seems to be the only way - wxDialog dlg(NULL, wxID_ANY, wxString()); - return (*m_extraControlCreator)(&dlg)->GetSize(); + return m_extraControl != NULL; } void wxFileDialogBase::UpdateExtraControlUI() diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 94edf19a05..3f29a50584 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -1075,8 +1075,13 @@ int wxFileDialog::ShowCommFileDialog(WXHWND hWndParent) lpdt->x = 0; lpdt->y = 0; + // create the extra control in an empty dialog just to find its size: this + // is not terribly efficient but we do need to know the size before + // creating the native dialog and this seems to be the only way + wxDialog dlg(NULL, wxID_ANY, wxString()); + const wxSize extraSize = CreateExtraControlWithParent(&dlg)->GetSize(); + // convert the size of the extra controls to the dialog units - const wxSize extraSize = GetExtraControlSize(); const LONG baseUnits = ::GetDialogBaseUnits(); lpdt->cx = ::MulDiv(extraSize.x, 4, LOWORD(baseUnits)); lpdt->cy = ::MulDiv(extraSize.y, 8, HIWORD(baseUnits));