Keep track of the initial size that the window was created with, and

when the window is added to a sizer use that size with SetSizeHints.
This is to fix problems resulting from the previous change where
SetSizeHints was called with the initial size from CreateBase.

Also, Patch [ 934677 ] wxWindowBase::DoGetBestSize() should exclude hidden windows


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26777 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-04-14 22:40:14 +00:00
parent dd05f81195
commit 1ebfafde51
2 changed files with 31 additions and 20 deletions

View File

@@ -931,17 +931,7 @@ public:
wxSizer *GetSizer() const { return m_windowSizer; } wxSizer *GetSizer() const { return m_windowSizer; }
// Track if this window is a member of a sizer // Track if this window is a member of a sizer
void SetContainingSizer(wxSizer* sizer) void SetContainingSizer(wxSizer* sizer);
{
// adding a window to a sizer twice is going to result in fatal and
// hard to debug problems later because when deleting the second
// associated wxSizerItem we're going to dereference a dangling
// pointer; so try to detect this as early as possible
wxASSERT_MSG( !sizer || m_containingSizer != sizer,
_T("Adding a window to the same sizer twice?") );
m_containingSizer = sizer;
}
wxSizer *GetContainingSizer() const { return m_containingSizer; } wxSizer *GetContainingSizer() const { return m_containingSizer; }
// accessibility // accessibility
@@ -1121,6 +1111,9 @@ 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;

View File

@@ -115,6 +115,8 @@ 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 =
@@ -222,13 +224,9 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
SetWindowStyleFlag(style); SetWindowStyleFlag(style);
SetParent(parent); SetParent(parent);
// Set the minsize to be the size passed to the ctor (if any) for // Save the size passed to the ctor (if any.) This will be used later as
// non-TLWs. This is so items used in a sizer will use this explicitly // the minimal size if the window is added to a sizer.
// set size for layout, instead of falling back the (probably smaller) m_initialSize = size;
// bestsize.
if (! IsTopLevel())
SetSizeHints(size);
#if wxUSE_VALIDATORS #if wxUSE_VALIDATORS
SetValidator(validator); SetValidator(validator);
@@ -546,7 +544,7 @@ wxSize wxWindowBase::DoGetBestSize() const
#endif // wxUSE_CONSTRAINTS #endif // wxUSE_CONSTRAINTS
else if ( !GetChildren().empty() ) else if ( !GetChildren().empty() )
{ {
// our minimal acceptable size is such that all our windows fit inside // our minimal acceptable size is such that all our visible child windows fit inside
int maxX = 0, int maxX = 0,
maxY = 0; maxY = 0;
@@ -555,7 +553,7 @@ wxSize wxWindowBase::DoGetBestSize() const
node = node->GetNext() ) node = node->GetNext() )
{ {
wxWindow *win = node->GetData(); wxWindow *win = node->GetData();
if ( win->IsTopLevel() if ( win->IsTopLevel() || ( ! win->IsShown() )
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
|| wxDynamicCast(win, wxStatusBar) || wxDynamicCast(win, wxStatusBar)
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
@@ -1627,6 +1625,26 @@ void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
sizer->SetSizeHints( (wxWindow*) this ); sizer->SetSizeHints( (wxWindow*) this );
} }
void wxWindowBase::SetContainingSizer(wxSizer* sizer)
{
// adding a window to a sizer twice is going to result in fatal and
// hard to debug problems later because when deleting the second
// associated wxSizerItem we're going to dereference a dangling
// pointer; so try to detect this as early as possible
wxASSERT_MSG( !sizer || m_containingSizer != sizer,
_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
// 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()