X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42cfa1842f59196416e016a151dc369d2b15a25d..a4de7e8ccf4bf69d150c29c9a3d53e5754c8b8a9:/src/common/wincmn.cpp diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 450132dc60..8f7143f57a 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 13/07/98 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) wxWidgets team // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -121,9 +121,12 @@ wxWindowBase::wxWindowBase() // no constraints on the minimal window size m_minWidth = + m_maxWidth = wxDefaultSize.x; m_minHeight = - m_maxWidth = - m_maxHeight = -1; + m_maxHeight = wxDefaultSize.y; + + // invalidiated cache value + m_bestSizeCache = wxDefaultSize; // window are created enabled and visible by default m_isShown = @@ -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 = @@ -180,9 +186,9 @@ wxWindowBase::wxWindowBase() m_virtualSize = wxDefaultSize; m_minVirtualWidth = + m_maxVirtualWidth = wxDefaultSize.x; m_minVirtualHeight = - m_maxVirtualWidth = - m_maxVirtualHeight = -1; + m_maxVirtualHeight = wxDefaultSize.y; m_windowVariant = wxWINDOW_VARIANT_NORMAL; @@ -215,7 +221,7 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, // ids are limited to 16 bits under MSW so if you care about portability, // it's not a good idea to use ids out of this range (and negative ids are - // reserved for wxWindows own usage) + // reserved for wxWidgets own usage) wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767), _T("invalid id value") ); @@ -432,8 +438,8 @@ void wxWindowBase::Centre(int direction) int width, height; GetSize(&width, &height); - int xNew = -1, - yNew = -1; + int xNew = wxDefaultPosition.x, + yNew = wxDefaultPosition.y; if ( direction & wxHORIZONTAL ) xNew = (widthParent - width)/2; @@ -482,7 +488,7 @@ void wxWindowBase::Fit() { if ( GetChildren().GetCount() > 0 ) { - SetClientSize(DoGetBestSize()); + SetClientSize(GetBestSize()); } //else: do nothing if we have no children } @@ -590,9 +596,9 @@ wxSize wxWindowBase::DoGetBestSize() const // if the window hadn't been positioned yet, assume that it is in // the origin - if ( wx == -1 ) + if ( wx == wxDefaultPosition.x ) wx = 0; - if ( wy == -1 ) + if ( wy == wxDefaultPosition.y ) wy = 0; win->GetSize(&ww, &wh); @@ -620,32 +626,36 @@ wxSize wxWindowBase::DoGetBestSize() const } } -void wxWindowBase::SetBestSize(const wxSize& size) + +wxSize wxWindowBase::GetBestFittingSize() const { - // If the given size is incomplete then merge with the best size. - wxSize sizeBest; - if ( size.x == -1 || size.y == -1 ) - { - sizeBest = DoGetBestSize(); - if ( size.x != -1 ) - sizeBest.x = size.x; - if ( size.y != -1 ) - sizeBest.y = size.y; - } - else // have complete explicit size + // 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 = 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); +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); - // don't shrink the control below its best size - m_minWidth = sizeBest.x; - m_minHeight = sizeBest.y; + // 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 { @@ -659,8 +669,8 @@ void wxWindowBase::SetSizeHints(int minW, int minH, { // setting min width greater than max width leads to infinite loops under // X11 and generally doesn't make any sense, so don't allow it - wxCHECK_RET( (minW == -1 || maxW == -1 || minW <= maxW) && - (minH == -1 || maxH == -1 || minH <= maxH), + wxCHECK_RET( (minW == wxDefaultSize.x || maxW == wxDefaultSize.x || minW <= maxW) && + (minH == wxDefaultSize.y || maxH == wxDefaultSize.y || minH <= maxH), _T("min width/height must be less than max width/height!") ); m_minWidth = minW; @@ -725,13 +735,13 @@ void wxWindowBase::SetVirtualSizeHints( int minW, int minH, void wxWindowBase::DoSetVirtualSize( int x, int y ) { - if ( m_minVirtualWidth != -1 && m_minVirtualWidth > x ) + if ( m_minVirtualWidth != wxDefaultSize.x && m_minVirtualWidth > x ) x = m_minVirtualWidth; - if ( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x ) + if ( m_maxVirtualWidth != wxDefaultSize.x && m_maxVirtualWidth < x ) x = m_maxVirtualWidth; - if ( m_minVirtualHeight != -1 && m_minVirtualHeight > y ) + if ( m_minVirtualHeight != wxDefaultSize.y && m_minVirtualHeight > y ) y = m_minVirtualHeight; - if ( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y ) + if ( m_maxVirtualHeight != wxDefaultSize.y && m_maxVirtualHeight < y ) y = m_maxVirtualHeight; m_virtualSize = wxSize(x, y); @@ -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()); } } @@ -974,17 +984,16 @@ wxColour wxWindowBase::GetBackgroundColour() const // we must return some valid colour to avoid redoing this every time // and also to avoid surprizing the applications written for older - // wxWindows versions where GetBackgroundColour() always returned + // wxWidgets versions where GetBackgroundColour() always returned // something -- so give them something even if it doesn't make sense // for this window (e.g. it has a themed background) if ( !colBg.Ok() ) colBg = GetClassDefaultAttributes().colBg; - // cache it for the next call - wxConstCast(this, wxWindowBase)->m_backgroundColour = colBg; + return colBg; } - - return m_backgroundColour; + else + return m_backgroundColour; } wxColour wxWindowBase::GetForegroundColour() const @@ -999,33 +1008,33 @@ wxColour wxWindowBase::GetForegroundColour() const if ( !colFg.Ok() ) colFg = GetClassDefaultAttributes().colFg; - wxConstCast(this, wxWindowBase)->m_foregroundColour = colFg; + return colFg; } - - return m_foregroundColour; + else + return m_foregroundColour; } bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) { - if ( !colour.Ok() || (colour == m_backgroundColour) ) + if ( colour == m_backgroundColour ) return false; + m_hasBgCol = colour.Ok(); + m_inheritBgCol = m_hasBgCol; m_backgroundColour = colour; - - m_hasBgCol = true; - + SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); return true; } bool wxWindowBase::SetForegroundColour( const wxColour &colour ) { - if ( !colour.Ok() || (colour == m_foregroundColour) ) + if (colour == m_foregroundColour ) return false; + m_hasFgCol = colour.Ok(); + m_inheritFgCol = m_hasFgCol; m_foregroundColour = colour; - - m_hasFgCol = true; - + SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); return true; } @@ -1044,7 +1053,7 @@ bool wxWindowBase::SetCursor(const wxCursor& cursor) return true; } -wxFont& wxWindowBase::DoGetFont() const +wxFont wxWindowBase::GetFont() const { // logic is the same as in GetBackgroundColour() if ( !m_font.Ok() ) @@ -1055,18 +1064,14 @@ wxFont& wxWindowBase::DoGetFont() const if ( !font.Ok() ) font = GetClassDefaultAttributes().font; - wxConstCast(this, wxWindowBase)->m_font = font; + return font; } - - // cast is here for non-const GetFont() convenience - return wxConstCast(this, wxWindowBase)->m_font; + else + return m_font; } bool wxWindowBase::SetFont(const wxFont& font) { - if ( !font.Ok() ) - return false; - if ( font == m_font ) { // no change @@ -1074,8 +1079,8 @@ bool wxWindowBase::SetFont(const wxFont& font) } m_font = font; - - m_hasFont = true; + m_hasFont = font.Ok(); + m_inheritFont = m_hasFont; return true; } @@ -1886,22 +1891,22 @@ void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) wxLayoutConstraints *constr = GetConstraints(); if ( constr ) { - if ( x != -1 ) + if ( x != wxDefaultPosition.x ) { constr->left.SetValue(x); constr->left.SetDone(true); } - if ( y != -1 ) + if ( y != wxDefaultPosition.y ) { constr->top.SetValue(y); constr->top.SetDone(true); } - if ( w != -1 ) + if ( w != wxDefaultSize.x ) { constr->width.SetValue(w); constr->width.SetDone(true); } - if ( h != -1 ) + if ( h != wxDefaultSize.y ) { constr->height.SetValue(h); constr->height.SetDone(true); @@ -1914,12 +1919,12 @@ void wxWindowBase::MoveConstraint(int x, int y) wxLayoutConstraints *constr = GetConstraints(); if ( constr ) { - if ( x != -1 ) + if ( x != wxDefaultPosition.x ) { constr->left.SetValue(x); constr->left.SetDone(true); } - if ( y != -1 ) + if ( y != wxDefaultPosition.y ) { constr->top.SetValue(y); constr->top.SetDone(true); @@ -2114,6 +2119,8 @@ void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) node = node->GetNext(); } + + Refresh(); } // the default action is to populate dialog with data when it's created, @@ -2167,7 +2174,7 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) wxMessageBox(wxString::Format( _T( - " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team" + " wxWidgets Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWidgets team" ), port.c_str(), wxMAJOR_VERSION, @@ -2181,7 +2188,7 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) __TDATE__, __TTIME__ ), - _T("wxWindows information"), + _T("wxWidgets information"), wxICON_INFORMATION | wxOK, (wxWindow *)this); } @@ -2400,6 +2407,53 @@ bool wxWindowBase::TryParent(wxEvent& event) return wxEvtHandler::TryParent(event); } +// ---------------------------------------------------------------------------- +// keyboard navigation +// ---------------------------------------------------------------------------- + +// Navigates in the specified direction. +bool wxWindowBase::Navigate(int flags) +{ + wxNavigationKeyEvent eventNav; + eventNav.SetFlags(flags); + eventNav.SetEventObject(this); + if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) + { + return true; + } + 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 // ---------------------------------------------------------------------------- @@ -2562,17 +2616,19 @@ wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) wxString title; - // If a child, leave wxWindows to call the function on the actual + // If a child, leave wxWidgets to call the function on the actual // child object. if (childId > 0) return wxACC_NOT_IMPLEMENTED; // This will eventually be replaced by specialised - // accessible classes, one for each kind of wxWindows + // accessible classes, one for each kind of wxWidgets // control or window. +#if wxUSE_BUTTON if (GetWindow()->IsKindOf(CLASSINFO(wxButton))) title = ((wxButton*) GetWindow())->GetLabel(); else +#endif title = GetWindow()->GetName(); if (!title.IsEmpty()) @@ -2723,7 +2779,7 @@ wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role) if (!GetWindow()) return wxACC_FAIL; - // If a child, leave wxWindows to call the function on the actual + // If a child, leave wxWidgets to call the function on the actual // child object. if (childId > 0) return wxACC_NOT_IMPLEMENTED; @@ -2755,7 +2811,7 @@ wxAccStatus wxWindowAccessible::GetState(int childId, long* state) if (!GetWindow()) return wxACC_FAIL; - // If a child, leave wxWindows to call the function on the actual + // If a child, leave wxWidgets to call the function on the actual // child object. if (childId > 0) return wxACC_NOT_IMPLEMENTED;