X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df2f507bee0a33986f5292806d78024072e896fd..e78d4a23c27aa9b5e826d56c76c80d46d67812c1:/src/common/wincmn.cpp diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index f1b4b5ef7c..5922d27f4a 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -47,9 +47,10 @@ #if wxUSE_CONSTRAINTS #include "wx/layout.h" - #include "wx/sizer.h" #endif // wxUSE_CONSTRAINTS +#include "wx/sizer.h" + #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif // wxUSE_DRAG_AND_DROP @@ -151,10 +152,11 @@ void wxWindowBase::InitBase() // no constraints whatsoever m_constraints = (wxLayoutConstraints *) NULL; m_constraintsInvolvedIn = (wxWindowList *) NULL; +#endif // wxUSE_CONSTRAINTS + m_windowSizer = (wxSizer *) NULL; m_containingSizer = (wxSizer *) NULL; m_autoLayout = FALSE; -#endif // wxUSE_CONSTRAINTS #if wxUSE_DRAG_AND_DROP m_dropTarget = (wxDropTarget *)NULL; @@ -172,6 +174,12 @@ void wxWindowBase::InitBase() m_hasCustomPalette = FALSE; #endif // wxUSE_PALETTE + m_virtualSize = wxDefaultSize; + m_minVirtualWidth = -1; + m_minVirtualHeight = -1; + m_maxVirtualWidth = -1; + m_maxVirtualHeight = -1; + // Whether we're using the current theme for this window (wxGTK only for now) m_themeEnabled = FALSE; } @@ -258,14 +266,14 @@ wxWindowBase::~wxWindowBase() m_constraints = NULL; } +#endif // wxUSE_CONSTRAINTS + if ( m_containingSizer ) m_containingSizer->Remove((wxWindow*)this); if ( m_windowSizer ) delete m_windowSizer; -#endif // wxUSE_CONSTRAINTS - #if wxUSE_DRAG_AND_DROP if ( m_dropTarget ) delete m_dropTarget; @@ -405,18 +413,18 @@ void wxWindowBase::Centre(int direction) wxRect rect = wxGetClientDisplayRect(); wxSize size (rect.width,rect.height); -#ifndef __WXMGL__ // FIXME - temporary dirty hack!! - if (posParent.x >= 0) // if parent is on the main display -#endif + // NB: in wxMSW, negative position may not neccessary mean "out of screen", + // but it may mean that the window is placed on other than the main + // display. Therefore we only make sure centered window is on the main display + // if the parent is at least partially present here. + if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display { if (xNew < 0) xNew = 0; else if (xNew+width > size.x) xNew = size.x-width-1; } -#ifndef __WXMGL__ // FIXME - temporary dirty hack!! - if (posParent.y >= 0) // if parent is on the main display -#endif + if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display { if (yNew+height > size.y) yNew = size.y-height-1; @@ -520,6 +528,40 @@ void wxWindowBase::SetSizeHints(int minW, int minH, m_maxHeight = maxH; } +void wxWindowBase::SetVirtualSizeHints( int minW, int minH, + int maxW, int maxH ) +{ + m_minVirtualWidth = minW; + m_maxVirtualWidth = maxW; + m_minVirtualHeight = minH; + m_maxVirtualHeight = maxH; + + SetVirtualSize( GetClientSize() ); +} + +void wxWindowBase::DoSetVirtualSize( int x, int y ) +{ + if( m_minVirtualWidth != -1 && m_minVirtualWidth > x ) x = m_minVirtualWidth; + if( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x ) x = m_maxVirtualWidth; + if( m_minVirtualHeight != -1 && m_minVirtualHeight > y ) y = m_minVirtualHeight; + if( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y ) y = m_maxVirtualHeight; + + m_virtualSize.SetWidth( x ); + m_virtualSize.SetHeight( y ); +} + +wxSize wxWindowBase::DoGetVirtualSize() const +{ + wxSize s( GetClientSize() ); + + if( m_virtualSize.GetWidth() != -1 ) + s.SetWidth( m_virtualSize.GetWidth() ); + if( m_virtualSize.GetHeight() != -1 ) + s.SetHeight( m_virtualSize.GetHeight() ); + + return s; +} + // ---------------------------------------------------------------------------- // show/hide/enable/disable the window // ---------------------------------------------------------------------------- @@ -1181,12 +1223,21 @@ void wxWindowBase::DeleteRelatedConstraints() m_constraintsInvolvedIn = (wxWindowList *) NULL; } } +#endif -void wxWindowBase::SetSizer(wxSizer *sizer) +void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) { - if (m_windowSizer) delete m_windowSizer; + if (m_windowSizer && deleteOld) delete m_windowSizer; m_windowSizer = sizer; + + SetAutoLayout( sizer != 0 ); +} + +void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) +{ + SetSizer( sizer, deleteOld ); + sizer->SetSizeHints( (wxWindow*) this ); } bool wxWindowBase::Layout() @@ -1195,10 +1246,10 @@ bool wxWindowBase::Layout() if ( GetSizer() ) { int w, h; - GetClientSize(&w, &h); - + GetVirtualSize(&w, &h); GetSizer()->SetDimension( 0, 0, w, h ); } +#if wxUSE_CONSTRAINTS else { wxLayoutConstraints *constr = GetConstraints(); @@ -1222,11 +1273,12 @@ bool wxWindowBase::Layout() DoPhase(2); // Layout grand children SetConstraintSizes(); // Recursively set the real window sizes } +#endif return TRUE; } - +#if wxUSE_CONSTRAINTS // Do a phase of evaluating constraints: the default behaviour. wxSizers may // do a similar thing, but also impose their own 'constraints' and order the // evaluation differently. @@ -1432,7 +1484,21 @@ void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const GetClientSize(w, h); } -void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) +void wxWindowBase::GetPositionConstraint(int *x, int *y) const +{ + wxLayoutConstraints *constr = GetConstraints(); + if ( constr ) + { + *x = constr->left.GetValue(); + *y = constr->top.GetValue(); + } + else + GetPosition(x, y); +} + +#endif // wxUSE_CONSTRAINTS + +void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const { // don't do it for the dialogs/frames - they float independently of their // parent @@ -1448,21 +1514,6 @@ void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) } } - -void wxWindowBase::GetPositionConstraint(int *x, int *y) const -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - *x = constr->left.GetValue(); - *y = constr->top.GetValue(); - } - else - GetPosition(x, y); -} - -#endif // wxUSE_CONSTRAINTS - // ---------------------------------------------------------------------------- // do Update UI processing for child controls // ---------------------------------------------------------------------------- @@ -1744,3 +1795,15 @@ void wxWindowBase::ReleaseMouse() GetCapture()); } +// ---------------------------------------------------------------------------- +// global functions +// ---------------------------------------------------------------------------- + +wxWindow* wxGetTopLevelParent(wxWindow *win) +{ + while ( win && !win->IsTopLevel() ) + win = win->GetParent(); + + return win; +} +