+ best = wxSize(maxX, maxY);
+ }
+ else // ! has children
+ {
+ wxSize size = GetMinSize();
+ if ( !size.IsFullySpecified() )
+ {
+ // if the window doesn't define its best size we assume that it can
+ // be arbitrarily small -- usually this is not the case, of course,
+ // but we have no way to know what the limit is, it should really
+ // override DoGetBestClientSize() itself to tell us
+ size.SetDefaults(wxSize(1, 1));
+ }
+
+ // return as-is, unadjusted by the client size difference.
+ return size;
+ }
+
+ // Add any difference between size and client size
+ wxSize diff = GetSize() - GetClientSize();
+ best.x += wxMax(0, diff.x);
+ best.y += wxMax(0, diff.y);
+
+ return best;
+}
+
+// helper of GetWindowBorderSize(): as many ports don't implement support for
+// wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
+// fallbacks in this case
+static int wxGetMetricOrDefault(wxSystemMetric what, const wxWindowBase* win)
+{
+ int rc = wxSystemSettings::GetMetric(
+ what, static_cast<wxWindow*>(const_cast<wxWindowBase*>(win)));
+ if ( rc == -1 )
+ {
+ switch ( what )
+ {
+ case wxSYS_BORDER_X:
+ case wxSYS_BORDER_Y:
+ // 2D border is by default 1 pixel wide
+ rc = 1;
+ break;
+
+ case wxSYS_EDGE_X:
+ case wxSYS_EDGE_Y:
+ // 3D borders are by default 2 pixels
+ rc = 2;
+ break;
+
+ default:
+ wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
+ rc = 0;
+ }
+ }
+
+ return rc;
+}
+
+wxSize wxWindowBase::GetWindowBorderSize() const
+{
+ wxSize size;
+
+ switch ( GetBorder() )
+ {
+ case wxBORDER_NONE:
+ // nothing to do, size is already (0, 0)
+ break;
+
+ case wxBORDER_SIMPLE:
+ case wxBORDER_STATIC:
+ size.x = wxGetMetricOrDefault(wxSYS_BORDER_X, this);
+ size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y, this);
+ break;
+
+ case wxBORDER_SUNKEN:
+ case wxBORDER_RAISED:
+ size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X, this),
+ wxGetMetricOrDefault(wxSYS_BORDER_X, this));
+ size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y, this),
+ wxGetMetricOrDefault(wxSYS_BORDER_Y, this));
+ break;
+
+ case wxBORDER_DOUBLE:
+ size.x = wxGetMetricOrDefault(wxSYS_EDGE_X, this) +
+ wxGetMetricOrDefault(wxSYS_BORDER_X, this);
+ size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y, this) +
+ wxGetMetricOrDefault(wxSYS_BORDER_Y, this);
+ break;
+
+ default:
+ wxFAIL_MSG(wxT("Unknown border style."));
+ break;
+ }
+
+ // we have borders on both sides
+ return size*2;
+}
+
+bool
+wxWindowBase::InformFirstDirection(int direction,
+ int size,
+ int availableOtherDir)
+{
+ return GetSizer() && GetSizer()->InformFirstDirection(direction,
+ size,
+ availableOtherDir);
+}
+
+wxSize wxWindowBase::GetEffectiveMinSize() 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;
+}
+
+wxSize wxWindowBase::DoGetBorderSize() const
+{
+ // there is one case in which we can implement it for all ports easily
+ if ( GetBorder() == wxBORDER_NONE )
+ return wxSize(0, 0);
+
+ // otherwise use the difference between the real size and the client size
+ // as a fallback: notice that this is incorrect in general as client size
+ // also doesn't take the scrollbars into account
+ return GetSize() - GetClientSize();
+}
+
+wxSize wxWindowBase::GetBestSize() const
+{
+ if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() )
+ return m_bestSizeCache;
+
+ // call DoGetBestClientSize() first, if a derived class overrides it wants
+ // it to be used
+ wxSize size = DoGetBestClientSize();
+ if ( size != wxDefaultSize )
+ size += DoGetBorderSize();
+ else
+ size = DoGetBestSize();
+
+ // Ensure that the best size is at least as large as min size.
+ size.IncTo(GetMinSize());
+
+ // And not larger than max size.
+ size.DecToIfSpecified(GetMaxSize());
+
+ // Finally cache result and return.
+ CacheBestSize(size);
+ return size;
+}
+
+int wxWindowBase::GetBestHeight(int width) const
+{
+ const int height = DoGetBestClientHeight(width);
+
+ return height == wxDefaultCoord
+ ? GetBestSize().y
+ : height + DoGetBorderSize().y;
+}
+
+int wxWindowBase::GetBestWidth(int height) const
+{
+ const int width = DoGetBestClientWidth(height);
+
+ return width == wxDefaultCoord
+ ? GetBestSize().x
+ : width + DoGetBorderSize().x;
+}
+
+void wxWindowBase::SetMinSize(const wxSize& minSize)
+{
+ m_minWidth = minSize.x;
+ m_minHeight = minSize.y;
+
+ InvalidateBestSize();
+}
+
+void wxWindowBase::SetMaxSize(const wxSize& maxSize)
+{
+ m_maxWidth = maxSize.x;
+ m_maxHeight = maxSize.y;
+
+ InvalidateBestSize();
+}
+
+void wxWindowBase::SetInitialSize(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 = GetEffectiveMinSize();
+
+ // 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
+{
+ return wxPoint(0,0);
+}
+
+wxSize wxWindowBase::ClientToWindowSize(const wxSize& size) const
+{
+ const wxSize diff(GetSize() - GetClientSize());
+
+ return wxSize(size.x == -1 ? -1 : size.x + diff.x,
+ size.y == -1 ? -1 : size.y + diff.y);
+}
+
+wxSize wxWindowBase::WindowToClientSize(const wxSize& size) const
+{
+ const wxSize diff(GetSize() - GetClientSize());
+
+ return wxSize(size.x == -1 ? -1 : size.x - diff.x,
+ size.y == -1 ? -1 : size.y - diff.y);
+}
+
+void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
+{
+ if ( m_windowVariant != variant )
+ {
+ m_windowVariant = variant;
+
+ DoSetWindowVariant(variant);
+ }
+}
+
+void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
+{
+ // adjust the font height to correspond to our new variant (notice that
+ // we're only called if something really changed)
+ wxFont font = GetFont();
+ int size = font.GetPointSize();
+ switch ( variant )
+ {
+ case wxWINDOW_VARIANT_NORMAL:
+ break;
+
+ case wxWINDOW_VARIANT_SMALL:
+ size = wxRound(size * 3.0 / 4.0);
+ break;
+
+ case wxWINDOW_VARIANT_MINI:
+ size = wxRound(size * 2.0 / 3.0);
+ break;
+
+ case wxWINDOW_VARIANT_LARGE:
+ size = wxRound(size * 5.0 / 4.0);
+ break;
+
+ default:
+ wxFAIL_MSG(wxT("unexpected window variant"));
+ break;
+ }
+
+ font.SetPointSize(size);
+ SetFont(font);
+}
+
+void wxWindowBase::DoSetSizeHints( int minW, int minH,
+ int maxW, int maxH,
+ int WXUNUSED(incW), int WXUNUSED(incH) )
+{
+ wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
+ (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
+ wxT("min width/height must be less than max width/height!") );
+
+ m_minWidth = minW;
+ m_maxWidth = maxW;
+ m_minHeight = minH;
+ m_maxHeight = maxH;
+}
+
+
+#if WXWIN_COMPATIBILITY_2_8
+void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW), int WXUNUSED(minH),
+ int WXUNUSED(maxW), int WXUNUSED(maxH))
+{
+}
+
+void wxWindowBase::SetVirtualSizeHints(const wxSize& WXUNUSED(minsize),
+ const wxSize& WXUNUSED(maxsize))
+{
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
+void wxWindowBase::DoSetVirtualSize( int x, int y )
+{
+ m_virtualSize = wxSize(x, y);
+}
+
+wxSize wxWindowBase::DoGetVirtualSize() const
+{
+ // we should use the entire client area so if it is greater than our
+ // virtual size, expand it to fit (otherwise if the window is big enough we
+ // wouldn't be using parts of it)
+ wxSize size = GetClientSize();
+ if ( m_virtualSize.x > size.x )
+ size.x = m_virtualSize.x;
+
+ if ( m_virtualSize.y >= size.y )
+ size.y = m_virtualSize.y;
+
+ return size;
+}
+
+void wxWindowBase::DoGetScreenPosition(int *x, int *y) const
+{
+ // screen position is the same as (0, 0) in client coords for non TLWs (and
+ // TLWs override this method)
+ if ( x )
+ *x = 0;
+ if ( y )
+ *y = 0;
+
+ ClientToScreen(x, y);
+}
+
+void wxWindowBase::SendSizeEvent(int flags)
+{
+ wxSizeEvent event(GetSize(), GetId());
+ event.SetEventObject(this);
+ if ( flags & wxSEND_EVENT_POST )
+ wxPostEvent(GetEventHandler(), event);
+ else
+ HandleWindowEvent(event);
+}
+
+void wxWindowBase::SendSizeEventToParent(int flags)
+{
+ wxWindow * const parent = GetParent();
+ if ( parent && !parent->IsBeingDeleted() )
+ parent->SendSizeEvent(flags);
+}
+
+bool wxWindowBase::HasScrollbar(int orient) const
+{
+ // if scrolling in the given direction is disabled, we can't have the
+ // corresponding scrollbar no matter what
+ if ( !CanScroll(orient) )
+ return false;
+
+ const wxSize sizeVirt = GetVirtualSize();
+ const wxSize sizeClient = GetClientSize();
+
+ return orient == wxHORIZONTAL ? sizeVirt.x > sizeClient.x
+ : sizeVirt.y > sizeClient.y;
+}
+
+// ----------------------------------------------------------------------------
+// show/hide/enable/disable the window
+// ----------------------------------------------------------------------------
+
+bool wxWindowBase::Show(bool show)
+{
+ if ( show != m_isShown )
+ {
+ m_isShown = show;