// Modified by:
// Created: 13/07/98
// RCS-ID: $Id$
-// Copyright: (c) wxWindows team
+// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#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
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 =
m_hasBgCol =
m_hasFgCol =
m_hasFont = false;
+ m_inheritBgCol =
+ m_inheritFgCol =
+ m_inheritFont = false;
// no style bits
m_exStyle =
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;
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)
// 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") );
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
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;
{
if ( GetChildren().GetCount() > 0 )
{
- SetClientSize(DoGetBestSize());
+ SetClientSize(GetBestSize());
}
//else: do nothing if we have no children
}
}
}
+// 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
{
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,
// 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);
}
}
+
+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
{
{
// 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;
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);
// 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());
}
}
// 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
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;
}
return true;
}
-wxFont& wxWindowBase::DoGetFont() const
+wxFont wxWindowBase::GetFont() const
{
// logic is the same as in GetBackgroundColour()
if ( !m_font.Ok() )
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
}
m_font = font;
-
- m_hasFont = true;
+ m_hasFont = font.Ok();
+ m_inheritFont = m_hasFont;
return true;
}
sizer->SetSizeHints( (wxWindow*) this );
}
-
+
void wxWindowBase::SetContainingSizer(wxSizer* sizer)
{
// adding a window to a sizer twice is going to result in fatal and
// 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()
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);
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);
node = node->GetNext();
}
+
+ Refresh();
}
// the default action is to populate dialog with data when it's created,
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,
__TDATE__,
__TTIME__
),
- _T("wxWindows information"),
+ _T("wxWidgets information"),
wxICON_INFORMATION | wxOK,
(wxWindow *)this);
}
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
// ----------------------------------------------------------------------------
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())
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;
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;