Move GetExtraControlSize() hack from wxFileDialogBase to MSW code
The hack with creating a dummy dialog just to get the size of the extra controls is only used in wxMSW, so move it to MSW-specific file from the common code. To allow doing this there, add CreateExtraControlWithParent() helper, which is still not really used anywhere else than in wxMSW, but at least doesn't do anything particularly ugly and doesn't really penalize the common code for wxMSW sins. No real changes.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user