X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2654f7e423bb773ca52c8b465c6ec9abfa398e45..207e624382313a5081d4af16dc76778d6cbb03a4:/src/common/wincmn.cpp?ds=sidebyside diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 14d868fdd8..d15660c398 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -110,7 +110,6 @@ END_EVENT_TABLE() // the default initialization wxWindowBase::wxWindowBase() -: m_bestSize(wxDefaultSize) { // no window yet, no parent nor children m_parent = (wxWindow *)NULL; @@ -194,7 +193,7 @@ wxWindowBase::wxWindowBase() 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) @@ -223,6 +222,14 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, 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 @@ -537,7 +544,7 @@ wxSize wxWindowBase::DoGetBestSize() const 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, @@ -584,20 +591,11 @@ wxSize wxWindowBase::DoGetBestSize() const 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(); } } @@ -880,6 +878,31 @@ bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) // 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)) {