+// check for flags conflicts
+static const int SIZER_FLAGS_MASK =
+ wxADD_FLAG(wxCENTRE,
+ wxADD_FLAG(wxHORIZONTAL,
+ wxADD_FLAG(wxVERTICAL,
+ wxADD_FLAG(wxLEFT,
+ wxADD_FLAG(wxRIGHT,
+ wxADD_FLAG(wxUP,
+ wxADD_FLAG(wxDOWN,
+ wxADD_FLAG(wxALIGN_NOT,
+ wxADD_FLAG(wxALIGN_CENTER_HORIZONTAL,
+ wxADD_FLAG(wxALIGN_RIGHT,
+ wxADD_FLAG(wxALIGN_BOTTOM,
+ wxADD_FLAG(wxALIGN_CENTER_VERTICAL,
+ wxADD_FLAG(wxFIXED_MINSIZE,
+ wxADD_FLAG(wxRESERVE_SPACE_EVEN_IF_HIDDEN,
+ wxADD_FLAG(wxSTRETCH_NOT,
+ wxADD_FLAG(wxSHRINK,
+ wxADD_FLAG(wxGROW,
+ wxADD_FLAG(wxSHAPED,
+ 0))))))))))))))))));
+
+#define ASSERT_VALID_SIZER_FLAGS(f) wxASSERT_VALID_FLAGS(f, SIZER_FLAGS_MASK)
+
+
m_proportion = flags.GetProportion();
m_flag = flags.GetFlags();
m_border = flags.GetBorderInPixels();
m_proportion = flags.GetProportion();
m_flag = flags.GetFlags();
m_border = flags.GetBorderInPixels();
- // The size that come here will be including borders. Child items should get it
- // without borders.
- if( size>0 )
- {
- if( direction==wxHORIZONTAL )
- {
- if (m_flag & wxWEST)
- size -= m_border;
- if (m_flag & wxEAST)
- size -= m_border;
- }
- else if( direction==wxVERTICAL )
- {
- if (m_flag & wxNORTH)
- size -= m_border;
- if (m_flag & wxSOUTH)
- size -= m_border;
- }
- }
-
+ // The size that come here will be including borders. Child items should get it
+ // without borders.
+ if( size>0 )
+ {
+ if( direction==wxHORIZONTAL )
+ {
+ if (m_flag & wxWEST)
+ size -= m_border;
+ if (m_flag & wxEAST)
+ size -= m_border;
+ }
+ else if( direction==wxVERTICAL )
+ {
+ if (m_flag & wxNORTH)
+ size -= m_border;
+ if (m_flag & wxSOUTH)
+ size -= m_border;
+ }
+ }
+
bool didUse = false;
// Pass the information along to the held object
if (IsSizer())
{
didUse = GetSizer()->InformFirstDirection(direction,size,availableOtherDir);
if (didUse)
bool didUse = false;
// Pass the information along to the held object
if (IsSizer())
{
didUse = GetSizer()->InformFirstDirection(direction,size,availableOtherDir);
if (didUse)
}
else if (IsWindow())
{
didUse = GetWindow()->InformFirstDirection(direction,size,availableOtherDir);
if (didUse)
m_minSize = m_window->GetEffectiveMinSize();
}
else if (IsWindow())
{
didUse = GetWindow()->InformFirstDirection(direction,size,availableOtherDir);
if (didUse)
m_minSize = m_window->GetEffectiveMinSize();
-
- // This information is useful for items with wxSHAPED flag, since
- // we can request an optimal min size for such an item. Even if
- // we overwrite the m_minSize member here, we can read it back from
- // the owned window (happens automatically).
- if( (m_flag & wxSHAPED) && (m_flag & wxEXPAND) && direction )
- {
- if( !wxIsNullDouble(m_ratio) )
- {
- wxCHECK_MSG( (m_proportion==0), false, _T("Shaped item, non-zero proportion in wxSizerItem::InformFirstDirection()") );
- if( direction==wxHORIZONTAL && !wxIsNullDouble(m_ratio) )
- {
- // Clip size so that we don't take too much
- if( availableOtherDir>=0 && int(size/m_ratio)-m_minSize.y>availableOtherDir )
- size = int((availableOtherDir+m_minSize.y)*m_ratio);
- m_minSize = wxSize(size,int(size/m_ratio));
- }
- else if( direction==wxVERTICAL )
- {
- // Clip size so that we don't take too much
- if( availableOtherDir>=0 && int(size*m_ratio)-m_minSize.x>availableOtherDir )
- size = int((availableOtherDir+m_minSize.x)/m_ratio);
- m_minSize = wxSize(int(size*m_ratio),size);
- }
- didUse = true;
- }
- }
- }
-
+
+ // This information is useful for items with wxSHAPED flag, since
+ // we can request an optimal min size for such an item. Even if
+ // we overwrite the m_minSize member here, we can read it back from
+ // the owned window (happens automatically).
+ if( (m_flag & wxSHAPED) && (m_flag & wxEXPAND) && direction )
+ {
+ if( !wxIsNullDouble(m_ratio) )
+ {
+ wxCHECK_MSG( (m_proportion==0), false, _T("Shaped item, non-zero proportion in wxSizerItem::InformFirstDirection()") );
+ if( direction==wxHORIZONTAL && !wxIsNullDouble(m_ratio) )
+ {
+ // Clip size so that we don't take too much
+ if( availableOtherDir>=0 && int(size/m_ratio)-m_minSize.y>availableOtherDir )
+ size = int((availableOtherDir+m_minSize.y)*m_ratio);
+ m_minSize = wxSize(size,int(size/m_ratio));
+ }
+ else if( direction==wxVERTICAL )
+ {
+ // Clip size so that we don't take too much
+ if( availableOtherDir>=0 && int(size*m_ratio)-m_minSize.x>availableOtherDir )
+ size = int((availableOtherDir+m_minSize.x)/m_ratio);
+ m_minSize = wxSize(int(size*m_ratio),size);
+ }
+ didUse = true;
+ }
+ }
+ }
+
- else // normal situation
- {
- // limit the window to the size of the display it is on
- int disp = wxDisplay::GetFromWindow(window);
- if ( disp == wxNOT_FOUND )
- {
- // or, if we don't know which one it is, of the main one
- disp = 0;
- }
- sizeMax = wxDisplay(disp).GetClientArea().GetSize();
+ // limit the window to the size of the display it is on
+ int disp = wxDisplay::GetFromWindow(window);
+ if ( disp == wxNOT_FOUND )
+ {
+ // or, if we don't know which one it is, of the main one
+ disp = 0;
+ return window->ClientToWindowSize(ComputeFittingClientSize(window));
+}
+
+wxSize wxSizer::Fit( wxWindow *window )
+{
+ wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
+
+ // set client size
+ window->SetClientSize(ComputeFittingClientSize(window));
+
+ // return entire size
+ return window->GetSize();
- wxSize size = Fit( window );
+ // This is equivalent to calling Fit(), except that we need to set
+ // the size hints _in between_ the two steps performed by Fit
+ // (1. ComputeFittingClientSize, 2. SetClientSize). That's because
+ // otherwise SetClientSize() could have no effect if there already are
+ // size hints in effect that forbid requested client size.
- window->SetSizeHints( size.x,
- size.y,
- window->GetMaxWidth(),
- window->GetMaxHeight() );
+ const wxSize clientSize = ComputeFittingClientSize(window);
+
+ window->SetMinClientSize(clientSize);
+ window->SetClientSize(clientSize);
- wxSize size( window->GetVirtualSize() );
- window->SetVirtualSizeHints( size.x,
- size.y,
- window->GetMaxWidth(),
- window->GetMaxHeight() );
-}
-
-wxSize wxSizer::GetMaxWindowSize( wxWindow *window ) const
-{
- return window->GetMaxSize();
-}
-
-wxSize wxSizer::GetMinWindowSize( wxWindow *window )
-{
- wxSize minSize( GetMinSize() );
- wxSize size( window->GetSize() );
- wxSize client_size( window->GetClientSize() );
-
- return wxSize( minSize.x+size.x-client_size.x,
- minSize.y+size.y-client_size.y );
// TODO on mac we need a function that determines how much free space this
// min size contains, in order to make sure that we have 20 pixels of free
// space around the controls
wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const
{
// TODO on mac we need a function that determines how much free space this
// min size contains, in order to make sure that we have 20 pixels of free
// space around the controls
wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const
{
- wxSize maxSize( window->GetMaxSize() );
-
- if ( maxSize != wxDefaultSize )
- {
- wxSize size( window->GetSize() );
- wxSize client_size( window->GetClientSize() );
-
- return wxSize( maxSize.x + client_size.x - size.x,
- maxSize.y + client_size.y - size.y );
- }
- else
- return wxDefaultSize;
+ return window->WindowToClientSize(window->GetMaxSize());
// a chance to adjust to that (we give it width component)
node = m_children.GetFirst();
bool didChangeMinSize = false;
// a chance to adjust to that (we give it width component)
node = m_children.GetFirst();
bool didChangeMinSize = false;
{
wxSizerItem *item = node->GetData();
didChangeMinSize |= item->InformFirstDirection( wxHORIZONTAL, w, -1 );
{
wxSizerItem *item = node->GetData();
didChangeMinSize |= item->InformFirstDirection( wxHORIZONTAL, w, -1 );
// made a separate function, since it's reused in AdjustForGrowables.
FindWidthsAndHeights(nrows,ncols);
// made a separate function, since it's reused in AdjustForGrowables.
FindWidthsAndHeights(nrows,ncols);
// Inform child items about the size in minor direction, that can
// change how much free space we have in major dir and how to distribute it.
int majorMinSum = 0;
// Inform child items about the size in minor direction, that can
// change how much free space we have in major dir and how to distribute it.
int majorMinSum = 0;
wxSize szMinPrev = item->GetMinSizeWithBorder();
item->InformFirstDirection(m_orient^wxBOTH,totalMinorSize,delta);
wxSize szMin = item->GetMinSizeWithBorder();
wxSize szMinPrev = item->GetMinSizeWithBorder();
item->InformFirstDirection(m_orient^wxBOTH,totalMinorSize,delta);
wxSize szMin = item->GetMinSizeWithBorder();
- // Since we passed available space along to the item, it should not
- // take too much ,so delat should not become negative.
- delta -= deltaChange;
+ // Since we passed available space along to the item, it should not
+ // take too much, so delta should not become negative.
+ delta -= deltaChange;
}
// And update our min size
SizeInMajorDir(m_minSize) = majorMinSum;
// might have a new delta now
}
// And update our min size
SizeInMajorDir(m_minSize) = majorMinSum;
// might have a new delta now
- SizeInMajorDir(m_minSize) += SizeInMajorDir(sizeMinThis);
- if ( SizeInMinorDir(sizeMinThis) > SizeInMinorDir(m_minSize) )
- SizeInMinorDir(m_minSize) = SizeInMinorDir(sizeMinThis);
+ const wxSize sizeMinThis = item->CalcMin();
+ SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis);
+ if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_minSize) )
+ SizeInMinorDir(m_minSize) = GetSizeInMinorDir(sizeMinThis);
// (which might be extended)
struct wxPropHolder : public wxObject
{
wxPropHolder( ) : m_item(0), m_propOld(0) { }
void Init( wxSizerItem *item, int propOld ) { m_item=item; m_propOld=propOld; }
// (which might be extended)
struct wxPropHolder : public wxObject
{
wxPropHolder( ) : m_item(0), m_propOld(0) { }
void Init( wxSizerItem *item, int propOld ) { m_item=item; m_propOld=propOld; }
IMPLEMENT_DYNAMIC_CLASS(wxWrapSizer, wxBoxSizer);
wxWrapSizer::wxWrapSizer( int orient, int flags )
IMPLEMENT_DYNAMIC_CLASS(wxWrapSizer, wxBoxSizer);
wxWrapSizer::wxWrapSizer( int orient, int flags )
- wxSizerItem *psi = m_rows.GetItem( (size_t)ix );
-
- // Restore proportion for last item on line (if item has not been deleted)
- wxPropHolder *pph = (wxPropHolder*)psi->GetUserData();
- if( pph && GetChildren().Find(pph->m_item) )
- pph->m_item->SetProportion(pph->m_propOld);
-
+ wxSizerItem *psi = m_rows.GetItem( (size_t)ix );
+
+ // Restore proportion for last item on line (if item has not been deleted)
+ wxPropHolder *pph = (wxPropHolder*)psi->GetUserData();
+ if( pph && GetChildren().Find(pph->m_item) )
+ pph->m_item->SetProportion(pph->m_propOld);
+
wxSizer *psz = psi->GetSizer();
wxASSERT( psz );
wxSizerItemList &sl = psz->GetChildren();
while( sl.GetLast() )
sl.Erase( sl.GetLast() );
}
wxSizer *psz = psi->GetSizer();
wxASSERT( psz );
wxSizerItemList &sl = psz->GetChildren();
while( sl.GetLast() )
sl.Erase( sl.GetLast() );
}
// Now put our child items into child sizers instead
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
wxSizerItem *item = NULL, *itemLast=NULL;
// Now put our child items into child sizers instead
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
wxSizerItem *item = NULL, *itemLast=NULL;
// Get a new empty sizer to insert into
if( (int)m_rows.GetChildren().GetCount()<=m_n_line )
m_rows.Add( new wxBoxSizer(GetOrientation()), 1, wxEXPAND );
// Get a new empty sizer to insert into
if( (int)m_rows.GetChildren().GetCount()<=m_n_line )
m_rows.Add( new wxBoxSizer(GetOrientation()), 1, wxEXPAND );
- // If item is a window, it now has a pointer to the child sizer,
- // which is wrong. Set it to point to us.
+ // If item is a window, it now has a pointer to the child sizer,
+ // which is wrong. Set it to point to us.
while( (int)m_rows.GetChildren().GetCount()>m_n_line )
m_rows.Remove( m_n_line );
// Now do layout on row sizer
m_rows.SetDimension( m_position.x, m_position.y, m_size.x, m_size.y );
while( (int)m_rows.GetChildren().GetCount()>m_n_line )
m_rows.Remove( m_n_line );
// Now do layout on row sizer
m_rows.SetDimension( m_position.x, m_position.y, m_size.x, m_size.y );