// the default initialization
wxWindowBase::wxWindowBase()
-: m_bestSize(wxDefaultSize)
{
// no window yet, no parent nor children
m_parent = (wxWindow *)NULL;
bool wxWindowBase::CreateBase(wxWindowBase *parent,
wxWindowID id,
const wxPoint& WXUNUSED(pos),
- const wxSize& WXUNUSED(size),
+ const wxSize& size,
long style,
const wxValidator& wxVALIDATOR_PARAM(validator),
const wxString& name)
SetWindowStyleFlag(style);
SetParent(parent);
+ // Set the minsize to be the size passed to the ctor (if any) for
+ // non-TLWs. This is so items used in a sizer will use this explicitly
+ // set size for layout, instead of falling back the (probably smaller)
+ // bestsize.
+ if (! IsTopLevel())
+ SetSizeHints(size);
+
+
#if wxUSE_VALIDATORS
SetValidator(validator);
#endif // wxUSE_VALIDATORS
return wxSize(maxX, maxY);
}
#endif // wxUSE_CONSTRAINTS
- else if ( GetChildren().GetCount() > 0 )
+ else if ( !GetChildren().empty() )
{
// our minimal acceptable size is such that all our windows fit inside
int maxX = 0,
return wxSize(maxX, maxY);
}
- else
+ else // has children
{
- // Windows which don't implement DoGetBestSize and aren't parents.
- // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
-
- // If you get the following message you should do one of two things
- // 1. Do what it says (best)
- // 2. m_bestSize = GetSize() at end of Create() (hack)
- if(m_bestSize == wxDefaultSize)
- {
- wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
- wxConstCast(this,wxWindowBase)->m_bestSize = GetSize();
- }
- return m_bestSize;
+ // for a generic window there is no natural best size - just use the
+ // current size
+ return GetSize();
}
}
// colours, fonts &c
// ----------------------------------------------------------------------------
+void wxWindowBase::InheritAttributes()
+{
+ const wxWindowBase * const parent = GetParent();
+ if ( !parent )
+ return;
+
+ // we only inherit attributes which had been explicitly set for the parent
+ // which ensures that this only happens if the user really wants it and
+ // not by default which wouldn't make any sense in modern GUIs where the
+ // controls don't all use the same fonts (nor colours)
+ if ( parent->m_hasFont && !m_hasFont )
+ SetFont(parent->GetFont());
+
+ // in addition, there is a possibility to explicitly forbid inheriting
+ // colours at each class level by overriding ShouldInheritColours()
+ if ( ShouldInheritColours() )
+ {
+ if ( parent->m_hasFgCol && !m_hasFgCol )
+ SetForegroundColour(parent->GetForegroundColour());
+
+ if ( parent->m_hasBgCol && !m_hasBgCol )
+ SetBackgroundColour(parent->GetBackgroundColour());
+ }
+}
+
/* static */ wxVisualAttributes
wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{