X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a8477e1341ac05a3ad7b908c04c8f50264dae87..a4de7e8ccf4bf69d150c29c9a3d53e5754c8b8a9:/src/common/wincmn.cpp diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index b62896002c..8f7143f57a 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -125,6 +125,9 @@ wxWindowBase::wxWindowBase() m_minHeight = m_maxHeight = wxDefaultSize.y; + // invalidiated cache value + m_bestSizeCache = wxDefaultSize; + // window are created enabled and visible by default m_isShown = m_isEnabled = true; @@ -142,6 +145,9 @@ wxWindowBase::wxWindowBase() m_hasBgCol = m_hasFgCol = m_hasFont = false; + m_inheritBgCol = + m_inheritFgCol = + m_inheritFont = false; // no style bits m_exStyle = @@ -482,7 +488,7 @@ void wxWindowBase::Fit() { if ( GetChildren().GetCount() > 0 ) { - SetClientSize(DoGetBestSize()); + SetClientSize(GetBestSize()); } //else: do nothing if we have no children } @@ -620,32 +626,36 @@ wxSize wxWindowBase::DoGetBestSize() const } } -void wxWindowBase::SetBestFittingSize(const wxSize& size) + +wxSize wxWindowBase::GetBestFittingSize() const { - // If the given size is incomplete then merge with the best size. - wxSize sizeBest; - if ( size.x == wxDefaultSize.x || size.y == wxDefaultSize.y ) + // merge the best size with the min size, giving priority to the min size + wxSize min = GetMinSize(); + if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) { - sizeBest = DoGetBestSize(); - if ( size.x != wxDefaultSize.x ) - sizeBest.x = size.x; - if ( size.y != wxDefaultSize.y ) - sizeBest.y = size.y; - } - else // have complete explicit size - { - sizeBest = size; + wxSize best = GetBestSize(); + if (min.x == wxDefaultCoord) min.x = best.x; + if (min.y == wxDefaultCoord) min.y = best.y; } + return min; +} - // Change the size if needed - if (GetSize() != sizeBest) - SetSize(sizeBest); - // don't shrink the control below its best size - m_minWidth = sizeBest.x; - m_minHeight = sizeBest.y; +void wxWindowBase::SetBestFittingSize(const wxSize& size) +{ + // Set the min size to the size passed in. This will usually either be + // wxDefaultSize or the size passed to this window's ctor/Create function. + SetMinSize(size); + + // Merge the size with the best size if needed + wxSize best = GetBestFittingSize(); + + // If the current size doesn't match then change it + if (GetSize() != best) + SetSize(best); } + // by default the origin is not shifted wxPoint wxWindowBase::GetClientAreaOrigin() const { @@ -935,17 +945,17 @@ void wxWindowBase::InheritAttributes() // 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 ) + if ( parent->m_inheritFont && !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 ) + if ( parent->m_inheritFgCol && !m_hasFgCol ) SetForegroundColour(parent->GetForegroundColour()); - if ( parent->m_hasBgCol && !m_hasBgCol ) + if ( parent->m_inheritBgCol && !m_hasBgCol ) SetBackgroundColour(parent->GetBackgroundColour()); } } @@ -1010,6 +1020,7 @@ bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) return false; m_hasBgCol = colour.Ok(); + m_inheritBgCol = m_hasBgCol; m_backgroundColour = colour; SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); return true; @@ -1021,6 +1032,7 @@ bool wxWindowBase::SetForegroundColour( const wxColour &colour ) return false; m_hasFgCol = colour.Ok(); + m_inheritFgCol = m_hasFgCol; m_foregroundColour = colour; SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); return true; @@ -1068,6 +1080,7 @@ bool wxWindowBase::SetFont(const wxFont& font) m_font = font; m_hasFont = font.Ok(); + m_inheritFont = m_hasFont; return true; } @@ -2395,7 +2408,7 @@ bool wxWindowBase::TryParent(wxEvent& event) } // ---------------------------------------------------------------------------- -// navigation +// keyboard navigation // ---------------------------------------------------------------------------- // Navigates in the specified direction. @@ -2411,6 +2424,36 @@ bool wxWindowBase::Navigate(int flags) return false; } +void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move) +{ + // check that we're not a top level window + wxCHECK_RET( GetParent(), + _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); + + // find the target window in the siblings list + wxWindowList& siblings = GetParent()->GetChildren(); + wxWindowList::compatibility_iterator i = siblings.Find(win); + wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") ); + + // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we + // can't just move the node around + wxWindow *self = (wxWindow *)this; + siblings.DeleteObject(self); + if ( move == MoveAfter ) + { + i = i->GetNext(); + } + + if ( i ) + { + siblings.Insert(i, self); + } + else // MoveAfter and win was the last sibling + { + siblings.Append(self); + } +} + // ---------------------------------------------------------------------------- // global functions // ----------------------------------------------------------------------------