moved SetBestSize() to .cpp file; set min size from it

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27072 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-05-03 12:33:31 +00:00
parent 2aaa050c33
commit 400a9e419b
2 changed files with 31 additions and 41 deletions

View File

@@ -93,7 +93,7 @@ struct WXDLLEXPORT wxVisualAttributes
// different window variants, on platforms like eg mac uses different // different window variants, on platforms like eg mac uses different
// rendering sizes // rendering sizes
enum wxWindowVariant enum wxWindowVariant
{ {
wxWINDOW_VARIANT_NORMAL, // Normal size wxWINDOW_VARIANT_NORMAL, // Normal size
wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal) wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal)
@@ -190,7 +190,7 @@ public:
// sets the window variant, calls internally DoSetVariant if variant has changed // sets the window variant, calls internally DoSetVariant if variant has changed
void SetWindowVariant( wxWindowVariant variant ) ; void SetWindowVariant( wxWindowVariant variant ) ;
wxWindowVariant GetWindowVariant() const { return m_windowVariant ; } wxWindowVariant GetWindowVariant() const { return m_windowVariant ; }
// window id uniquely identifies the window among its siblings unless // window id uniquely identifies the window among its siblings unless
// it is -1 which means "don't care" // it is -1 which means "don't care"
@@ -365,7 +365,7 @@ public:
// Override this method to control the values given to Sizers etc. // Override this method to control the values given to Sizers etc.
virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); }
virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); } virtual wxSize GetMinSize() const { return wxSize( m_minWidth, m_minHeight ); }
// Methods for accessing the virtual size of a window. For most // Methods for accessing the virtual size of a window. For most
// windows this is just the client area of the window, but for // windows this is just the client area of the window, but for
// some like scrolled windows it is more or less independent of // some like scrolled windows it is more or less independent of
@@ -453,7 +453,7 @@ public:
// not all windows/controls can do this without looking wrong. // not all windows/controls can do this without looking wrong.
virtual void ApplyParentThemeBackground(const wxColour& WXUNUSED(bg)) virtual void ApplyParentThemeBackground(const wxColour& WXUNUSED(bg))
{ /* do nothing */ } { /* do nothing */ }
// focus and keyboard handling // focus and keyboard handling
// --------------------------- // ---------------------------
@@ -1111,9 +1111,6 @@ protected:
wxAccessible* m_accessible; wxAccessible* m_accessible;
#endif #endif
// Initial window size, used as minimal size in Sizers
wxSize m_initialSize;
// Virtual size (scrolling) // Virtual size (scrolling)
wxSize m_virtualSize; wxSize m_virtualSize;
@@ -1121,7 +1118,7 @@ protected:
int m_minVirtualHeight; int m_minVirtualHeight;
int m_maxVirtualWidth; int m_maxVirtualWidth;
int m_maxVirtualHeight; int m_maxVirtualHeight;
wxWindowVariant m_windowVariant ; wxWindowVariant m_windowVariant ;
// override this to change the default (i.e. used when no style is // override this to change the default (i.e. used when no style is
@@ -1141,22 +1138,7 @@ protected:
// smarter SetSize / convenience function for expanding wxDefaultSize. // smarter SetSize / convenience function for expanding wxDefaultSize.
// Note that it does not influence the value returned by GetBestSize // Note that it does not influence the value returned by GetBestSize
// at all. // at all.
void SetBestSize(const wxSize& size) void SetBestSize(const wxSize& size);
{
// the size only needs to be changed if the current size is incomplete,
// i.e. one of the components was specified as default -- so if both
// were given, simply don't do anything
if ( size.x == -1 || size.y == -1 )
{
wxSize sizeBest = DoGetBestSize();
if ( size.x != -1 )
sizeBest.x = size.x;
if ( size.y != -1 )
sizeBest.y = size.y;
SetSize(sizeBest);
}
}
// more pure virtual functions // more pure virtual functions
// --------------------------- // ---------------------------

View File

@@ -115,8 +115,6 @@ wxWindowBase::wxWindowBase()
m_parent = (wxWindow *)NULL; m_parent = (wxWindow *)NULL;
m_windowId = wxID_ANY; m_windowId = wxID_ANY;
m_initialSize = wxDefaultSize;
// no constraints on the minimal window size // no constraints on the minimal window size
m_minWidth = m_minWidth =
m_minHeight = m_minHeight =
@@ -195,7 +193,7 @@ wxWindowBase::wxWindowBase()
bool wxWindowBase::CreateBase(wxWindowBase *parent, bool wxWindowBase::CreateBase(wxWindowBase *parent,
wxWindowID id, wxWindowID id,
const wxPoint& WXUNUSED(pos), const wxPoint& WXUNUSED(pos),
const wxSize& size, const wxSize& WXUNUSED(size),
long style, long style,
const wxValidator& wxVALIDATOR_PARAM(validator), const wxValidator& wxVALIDATOR_PARAM(validator),
const wxString& name) const wxString& name)
@@ -224,10 +222,6 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
SetWindowStyleFlag(style); SetWindowStyleFlag(style);
SetParent(parent); SetParent(parent);
// Save the size passed to the ctor (if any.) This will be used later as
// the minimal size if the window is added to a sizer.
m_initialSize = size;
#if wxUSE_VALIDATORS #if wxUSE_VALIDATORS
SetValidator(validator); SetValidator(validator);
#endif // wxUSE_VALIDATORS #endif // wxUSE_VALIDATORS
@@ -600,6 +594,27 @@ wxSize wxWindowBase::DoGetBestSize() const
} }
} }
void wxWindowBase::SetBestSize(const wxSize& size)
{
// the size only needs to be changed if the current size is incomplete,
// i.e. one of the components was specified as default -- so if both
// were given, simply don't do anything
if ( size.x == -1 || size.y == -1 )
{
wxSize sizeBest = DoGetBestSize();
if ( size.x != -1 )
sizeBest.x = size.x;
if ( size.y != -1 )
sizeBest.y = size.y;
SetSize(sizeBest);
// don't shrink the control below its best size
m_minWidth = sizeBest.x;
m_minHeight = sizeBest.y;
}
}
// by default the origin is not shifted // by default the origin is not shifted
wxPoint wxWindowBase::GetClientAreaOrigin() const wxPoint wxWindowBase::GetClientAreaOrigin() const
{ {
@@ -1628,7 +1643,7 @@ void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
sizer->SetSizeHints( (wxWindow*) this ); sizer->SetSizeHints( (wxWindow*) this );
} }
void wxWindowBase::SetContainingSizer(wxSizer* sizer) void wxWindowBase::SetContainingSizer(wxSizer* sizer)
{ {
// adding a window to a sizer twice is going to result in fatal and // adding a window to a sizer twice is going to result in fatal and
@@ -1637,17 +1652,10 @@ void wxWindowBase::SetContainingSizer(wxSizer* sizer)
// pointer; so try to detect this as early as possible // pointer; so try to detect this as early as possible
wxASSERT_MSG( !sizer || m_containingSizer != sizer, wxASSERT_MSG( !sizer || m_containingSizer != sizer,
_T("Adding a window to the same sizer twice?") ); _T("Adding a window to the same sizer twice?") );
m_containingSizer = sizer;
// If there was an initial size for this window, and if a minsize has not m_containingSizer = sizer;
// been set, then set the initial size as the minsize. This helps with
// sizer layout when a larger than GetBestSize size is needed for
// controls.
if (m_initialSize != wxDefaultSize && GetMinSize() == wxDefaultSize)
SetSizeHints(m_initialSize);
} }
#if wxUSE_CONSTRAINTS #if wxUSE_CONSTRAINTS
void wxWindowBase::SatisfyConstraints() void wxWindowBase::SatisfyConstraints()