wxGBSizerItem* GetGBSizerItem( IObject* sizeritem, const wxGBPosition& position, const wxGBSpan& span, wxObject* child ) { IObject* childObj = GetManager()->GetIObject( child ); if ( _("spacer") == childObj->GetClassName() ) { return new wxGBSizerItem( childObj->GetPropertyAsInteger( _("width") ), childObj->GetPropertyAsInteger( _("height") ), position, span, sizeritem->GetPropertyAsInteger(_("flag")), sizeritem->GetPropertyAsInteger(_("border")), NULL ); } // Add the child ( window or sizer ) to the sizer wxWindow* windowChild = wxDynamicCast( child, wxWindow ); wxSizer* sizerChild = wxDynamicCast( child, wxSizer ); if ( windowChild != NULL ) { return new wxGBSizerItem( windowChild, position, span, sizeritem->GetPropertyAsInteger(_("flag")), sizeritem->GetPropertyAsInteger(_("border")), NULL ); } else if ( sizerChild != NULL ) { return new wxGBSizerItem( sizerChild, position, span, sizeritem->GetPropertyAsInteger(_("flag")), sizeritem->GetPropertyAsInteger(_("border")), NULL ); } else { wxLogError( wxT("The GBSizerItem component's child is not a wxWindow or a wxSizer or a Spacer - this should not be possible!") ); return NULL; } }
void OnCreated( wxObject* wxobject, wxWindow* /*wxparent*/ ) { // Get parent sizer wxObject* parent = GetManager()->GetParent( wxobject ); wxSizer* sizer = wxDynamicCast( parent, wxSizer ); if ( NULL == sizer ) { wxLogError( wxT("The parent of a SizerItem is either missing or not a wxSizer - this should not be possible!") ); return; } // Get child window wxObject* child = GetManager()->GetChild( wxobject, 0 ); if ( NULL == child ) { wxLogError( wxT("The SizerItem component has no child - this should not be possible!") ); return; } // Get IObject for property access IObject* obj = GetManager()->GetIObject( wxobject ); IObject* childObj = GetManager()->GetIObject( child ); // Add the spacer if ( _("spacer") == childObj->GetClassName() ) { sizer->Add( childObj->GetPropertyAsInteger( _("width") ), childObj->GetPropertyAsInteger( _("height") ), obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")), obj->GetPropertyAsInteger(_("border")) ); return; } // Add the child ( window or sizer ) to the sizer wxWindow* windowChild = wxDynamicCast( child, wxWindow ); wxSizer* sizerChild = wxDynamicCast( child, wxSizer ); if ( windowChild != NULL ) { sizer->Add( windowChild, obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")), obj->GetPropertyAsInteger(_("border"))); } else if ( sizerChild != NULL ) { sizer->Add( sizerChild, obj->GetPropertyAsInteger(_("proportion")), obj->GetPropertyAsInteger(_("flag")), obj->GetPropertyAsInteger(_("border"))); } else { wxLogError( wxT("The SizerItem component's child is not a wxWindow or a wxSizer or a spacer - this should not be possible!") ); } }
void OnCreated( wxObject* wxobject, wxWindow* /*wxparent*/ ) { // For storing objects whose postion needs to be determined std::vector< std::pair< wxObject*, wxGBSizerItem* > > newObjects; wxGBPosition lastPosition( 0, 0 ); // Get sizer wxGridBagSizer* sizer = wxDynamicCast( wxobject, wxGridBagSizer ); if ( NULL == sizer ) { wxLogError( wxT("This should be a wxGridBagSizer!") ); return; } // Add the children IManager* manager = GetManager(); size_t count = manager->GetChildCount( wxobject ); if ( 0 == count ) { // wxGridBagSizer gets upset sometimes without children sizer->Add( 0, 0, wxGBPosition( 0, 0 ) ); return; } for ( size_t i = 0; i < count; ++i ) { // Should be a GBSizerItem wxObject* wxsizerItem = manager->GetChild( wxobject, i ); IObject* isizerItem = manager->GetIObject( wxsizerItem ); // Get the location of the item wxGBSpan span( isizerItem->GetPropertyAsInteger( _("rowspan") ), isizerItem->GetPropertyAsInteger( _("colspan") ) ); int column = isizerItem->GetPropertyAsInteger( _("column") ); if ( column < 0 ) { // Needs to be auto positioned after the other children are added wxGBSizerItem* item = GetGBSizerItem( isizerItem, lastPosition, span, manager->GetChild( wxsizerItem, 0 ) ); if ( item != NULL ) { newObjects.push_back( std::pair< wxObject*, wxGBSizerItem* >( wxsizerItem, item ) ); } continue; } wxGBPosition position( isizerItem->GetPropertyAsInteger( _("row") ), column ); // Check for intersection if ( sizer->CheckForIntersection( position, span ) ) { continue; } lastPosition = position; // Add the child to the sizer wxGBSizerItem* item = GetGBSizerItem( isizerItem, position, span, manager->GetChild( wxsizerItem, 0 ) ); if ( item != NULL ) { sizer->Add( item ); } } std::vector< std::pair< wxObject*, wxGBSizerItem* > >::iterator it; for ( it = newObjects.begin(); it != newObjects.end(); ++it ) { wxGBPosition position = it->second->GetPos(); wxGBSpan span = it->second->GetSpan(); int column = position.GetCol(); while ( sizer->CheckForIntersection( position, span ) ) { column++; position.SetCol( column ); } it->second->SetPos( position ); sizer->Add( it->second ); GetManager()->ModifyProperty( it->first, _("row"), wxString::Format( wxT("%i"), position.GetRow() ), false ); GetManager()->ModifyProperty( it->first, _("column"), wxString::Format( wxT("%i"), column ), false ); } }