X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/997c728048635b416eec7360ba809251dedb14a4..6d325d81bc739bf545df5c00183fc7d5880b8a43:/src/common/wincmn.cpp diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 6b6b35ab28..7c4c0ce62c 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 ///////////////////////////////////////////////////////////////////////////// @@ -47,6 +47,10 @@ #include "wx/dcclient.h" #endif //WX_PRECOMP +#if defined(__WXMAC__) && wxUSE_SCROLLBAR + #include "wx/scrolbar.h" +#endif + #if wxUSE_CONSTRAINTS #include "wx/layout.h" #endif // wxUSE_CONSTRAINTS @@ -115,13 +119,14 @@ wxWindowBase::wxWindowBase() m_parent = (wxWindow *)NULL; m_windowId = wxID_ANY; - m_initialSize = wxDefaultSize; - // 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 = @@ -178,9 +183,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; @@ -195,7 +200,7 @@ wxWindowBase::wxWindowBase() bool wxWindowBase::CreateBase(wxWindowBase *parent, wxWindowID id, const wxPoint& WXUNUSED(pos), - const wxSize& size, + const wxSize& WXUNUSED(size), long style, const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) @@ -213,7 +218,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") ); @@ -224,10 +229,6 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, SetWindowStyleFlag(style); SetParent(parent); - // Save the size passed to the ctor (if any.) This will be used later as - // the minimal size if the window is added to a sizer. - m_initialSize = size; - #if wxUSE_VALIDATORS SetValidator(validator); #endif // wxUSE_VALIDATORS @@ -434,8 +435,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; @@ -484,7 +485,7 @@ void wxWindowBase::Fit() { if ( GetChildren().GetCount() > 0 ) { - SetClientSize(DoGetBestSize()); + SetClientSize(GetBestSize()); } //else: do nothing if we have no children } @@ -498,6 +499,24 @@ void wxWindowBase::FitInside() } } +// On Mac, scrollbars are explicitly children. +#ifdef __WXMAC__ +static bool wxHasRealChildren(const wxWindowBase* win) +{ + int realChildCount = 0; + + for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *win = node->GetData(); + if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar))) + realChildCount ++; + } + return (realChildCount > 0); +} +#endif + // return the size best suited for the current window wxSize wxWindowBase::DoGetBestSize() const { @@ -542,7 +561,11 @@ wxSize wxWindowBase::DoGetBestSize() const return wxSize(maxX, maxY); } #endif // wxUSE_CONSTRAINTS - else if ( !GetChildren().empty() ) + else if ( !GetChildren().empty() +#ifdef __WXMAC__ + && wxHasRealChildren(this) +#endif + ) { // our minimal acceptable size is such that all our visible child windows fit inside int maxX = 0, @@ -570,9 +593,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); @@ -600,6 +623,36 @@ wxSize wxWindowBase::DoGetBestSize() const } } + +wxSize wxWindowBase::GetBestFittingSize() const +{ + // merge the best size with the min size, giving priority to the min size + wxSize min = GetMinSize(); + if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) + { + wxSize best = GetBestSize(); + if (min.x == wxDefaultCoord) min.x = best.x; + if (min.y == wxDefaultCoord) min.y = best.y; + } + return min; +} + + +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 { @@ -613,8 +666,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; @@ -679,13 +732,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); @@ -928,17 +981,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 @@ -953,33 +1005,31 @@ 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_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_foregroundColour = colour; - - m_hasFgCol = true; - + SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); return true; } @@ -998,7 +1048,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() ) @@ -1009,18 +1059,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 @@ -1028,8 +1074,7 @@ bool wxWindowBase::SetFont(const wxFont& font) } m_font = font; - - m_hasFont = true; + m_hasFont = font.Ok(); return true; } @@ -1628,7 +1673,7 @@ void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) sizer->SetSizeHints( (wxWindow*) this ); } - + void wxWindowBase::SetContainingSizer(wxSizer* sizer) { // adding a window to a sizer twice is going to result in fatal and @@ -1637,17 +1682,10 @@ void wxWindowBase::SetContainingSizer(wxSizer* sizer) // 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); + m_containingSizer = sizer; } - + #if wxUSE_CONSTRAINTS void wxWindowBase::SatisfyConstraints() @@ -1847,22 +1885,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); @@ -1875,12 +1913,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); @@ -2075,6 +2113,8 @@ void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) node = node->GetNext(); } + + Refresh(); } // the default action is to populate dialog with data when it's created, @@ -2128,7 +2168,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, @@ -2142,7 +2182,7 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) __TDATE__, __TTIME__ ), - _T("wxWindows information"), + _T("wxWidgets information"), wxICON_INFORMATION | wxOK, (wxWindow *)this); } @@ -2361,6 +2401,23 @@ bool wxWindowBase::TryParent(wxEvent& event) return wxEvtHandler::TryParent(event); } +// ---------------------------------------------------------------------------- +// 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; +} + // ---------------------------------------------------------------------------- // global functions // ---------------------------------------------------------------------------- @@ -2523,17 +2580,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()) @@ -2684,7 +2743,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; @@ -2716,7 +2775,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;