// 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
// no constraints on the minimal window size
m_minWidth =
+ m_maxWidth = wxDefaultSize.x;
m_minHeight =
- m_maxWidth =
- m_maxHeight = -1;
+ m_maxHeight = wxDefaultSize.y;
// window are created enabled and visible by default
m_isShown =
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;
// 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") );
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;
}
}
+// 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().GetCount() > 0 )
+ else if ( !GetChildren().empty()
+#ifdef __WXMAC__
+ && wxHasRealChildren(this)
+#endif
+ )
{
- // our minimal acceptable size is such that all our windows fit inside
+ // our minimal acceptable size is such that all our visible child windows fit inside
int maxX = 0,
maxY = 0;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
- if ( win->IsTopLevel()
+ if ( win->IsTopLevel() || ( ! win->IsShown() )
#if wxUSE_STATUSBAR
|| wxDynamicCast(win, wxStatusBar)
#endif // wxUSE_STATUSBAR
// 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);
return wxSize(maxX, maxY);
}
- else
+ else // ! has children
{
- // for a generic window there is no natural best size - just use the
- // current one
- return GetSize();
+ // for a generic window there is no natural best size - just use either the
+ // minimum size if there is one, or the current size
+ if ( GetMinSize().IsFullySpecified() )
+ return GetMinSize();
+ else
+ return GetSize();
}
}
+void wxWindowBase::SetBestSize(const wxSize& size)
+{
+ // If the given size is incomplete then merge with the best size.
+ wxSize sizeBest;
+ if ( size.x == wxDefaultSize.x || size.y == wxDefaultSize.y )
+ {
+ 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;
+ }
+
+ // 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;
+}
+
// 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);
// 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))
{
// 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() )
sizer->SetSizeHints( (wxWindow*) this );
}
+
+void wxWindowBase::SetContainingSizer(wxSizer* sizer)
+{
+ // adding a window to a sizer twice is going to result in fatal and
+ // hard to debug problems later because when deleting the second
+ // associated wxSizerItem we're going to dereference a dangling
+ // 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 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);
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);
}
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;