void VisualEditor::SetupWizard( PObjectBase obj, wxWindow *window, bool pageAdding ) { WizardPageSimple *wizpage = wxDynamicCast( window, WizardPageSimple ); if ( pageAdding ) { m_wizard->AddPage( wizpage ); m_wizard->Connect( wxID_ANY, wxFB_EVT_WIZARD_PAGE_CHANGED, WizardEventHandler( VisualEditor::OnWizardPageChanged ) ); } else { WizardEvent eventChanged( wxFB_EVT_WIZARD_PAGE_CHANGED, m_wizard->GetId(), false, wizpage ); eventChanged.SetInt( 1 ); wizpage->GetEventHandler()->ProcessEvent( eventChanged ); bool wizBmpOk = !obj->GetParent()->GetProperty( wxT("bitmap") )->IsNull(); bool pgeBmpOk = !obj->GetProperty( wxT("bitmap") )->IsNull(); wxBitmap wizBmp = obj->GetParent()->GetPropertyAsBitmap( wxT("bitmap") ); wxBitmap pgeBmp = obj->GetPropertyAsBitmap( wxT("bitmap") ); if ( pgeBmpOk && pgeBmp.IsOk() ) { m_wizard->SetBitmap( pgeBmp ); } else if ( wizBmpOk && wizBmp.IsOk() ) { m_wizard->SetBitmap( wizBmp ); } size_t selection = m_wizard->GetPageIndex( wizpage ); m_wizard->SetSelection( selection ); } }
wxObject* wxFBManager::GetParent( wxObject* wxobject ) { CHECK_VISUAL_EDITOR( NULL ) CHECK_WX_OBJECT( NULL ) PObjectBase obj = m_visualEdit->GetObjectBase( wxobject ); CHECK_OBJECT_BASE( NULL ) return m_visualEdit->GetWxObject( obj->GetParent() ); }
void DesignerWindow::DrawRectangle( wxDC& dc, const wxPoint& point, const wxSize& size, PObjectBase object ) { bool isSizer = ( object->GetObjectInfo()->IsSubclassOf( wxT("sizer") ) ); int min = ( isSizer ? 0 : 1 ); int border = object->GetParent()->GetPropertyAsInteger( wxT("border") ); if ( border == 0 ) { border = min; } int flag = object->GetParent()->GetPropertyAsInteger( wxT("flag") ); int topBorder = ( flag & wxTOP ) == 0 ? min : border; int bottomBorder = ( flag & wxBOTTOM ) == 0 ? min : border; int rightBorder = ( flag & wxRIGHT ) == 0 ? min : border; int leftBorder = ( flag & wxLEFT ) == 0 ? min : border; dc.DrawRectangle( point.x - leftBorder, point.y - topBorder, size.x + leftBorder + rightBorder, size.y + topBorder + bottomBorder ); }
void DesignerWindow::HighlightSelection( wxDC& dc ) { wxSize size; PObjectBase object = m_selObj.lock(); if ( m_selSizer ) { wxPoint point = m_selSizer->GetPosition(); size = m_selSizer->GetSize(); wxPen bluePen( *wxBLUE, 1, wxSOLID ); dc.SetPen( bluePen ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); PObjectBase sizerParent = object->FindNearAncestorByBaseClass( wxT("sizer") ); if ( sizerParent && sizerParent->GetParent() ) { DrawRectangle( dc, point, size, sizerParent ); } } if ( m_selItem ) { wxPoint point; bool shown; wxWindow* windowItem = wxDynamicCast( m_selItem, wxWindow ); wxSizer* sizerItem = wxDynamicCast( m_selItem, wxSizer ); if ( NULL != windowItem ) { point = windowItem->GetPosition(); size = windowItem->GetSize(); shown = windowItem->IsShown(); } else if ( NULL != sizerItem ) { point = sizerItem->GetPosition(); size = sizerItem->GetSize(); shown = true; } else { return; } if ( shown ) { wxPen redPen( *wxRED, 1, wxSOLID ); dc.SetPen( redPen ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); DrawRectangle( dc, point, size, object ); } } }
bool TemplateParser::ParseForm() { PObjectBase form (m_obj); PObjectBase parent(form->GetParent()); if ( !parent ) { return false; } // form is a form when grandparent is null PObjectBase grandparent = parent->GetParent(); while ( grandparent ) { form = parent; parent = grandparent; grandparent = grandparent->GetParent(); } PProperty property = GetRelatedProperty( form ); m_out << PropertyToCode( property ); return true; }
void VisualEditor::OnObjectSelected( wxFBObjectEvent &event ) { // It is only necessary to Create() if the selected object is on a different form if ( AppData()->GetSelectedForm() != m_form ) { Create(); } // Get the ObjectBase from the event PObjectBase obj = event.GetFBObject(); if ( !obj ) { // Strange... Debug::Print( wxT("The event object is NULL - why?") ); return; } // Make sure this is a visible object ObjectBaseMap::iterator it = m_baseobjects.find( obj.get() ); if ( m_baseobjects.end() == it ) { m_back->SetSelectedSizer( NULL ); m_back->SetSelectedItem( NULL ); m_back->SetSelectedObject( PObjectBase() ); m_back->SetSelectedPanel( NULL ); m_back->Refresh(); return; } // Save wxobject wxObject* item = it->second; int componentType = COMPONENT_TYPE_ABSTRACT; IComponent *comp = obj->GetObjectInfo()->GetComponent(); if ( comp ) { componentType = comp->GetComponentType(); // Fire selection event in plugin if ( !m_stopSelectedEvent ) { comp->OnSelected( item ); } } if ( componentType != COMPONENT_TYPE_WINDOW && componentType != COMPONENT_TYPE_SIZER ) { item = NULL; } // Fire selection event in plugin for all parents if ( !m_stopSelectedEvent ) { PObjectBase parent = obj->GetParent(); while ( parent ) { IComponent* parentComp = parent->GetObjectInfo()->GetComponent(); if ( parentComp ) { ObjectBaseMap::iterator parentIt = m_baseobjects.find( parent.get() ); if ( parentIt != m_baseobjects.end() ) { parentComp->OnSelected( parentIt->second ); } } parent = parent->GetParent(); } } // Look for the active panel - this is where the boxes will be drawn during OnPaint // This is the closest parent of type COMPONENT_TYPE_WINDOW PObjectBase nextParent = obj->GetParent(); while ( nextParent ) { IComponent* parentComp = nextParent->GetObjectInfo()->GetComponent(); if ( !parentComp ) { nextParent.reset(); break; } if ( parentComp->GetComponentType() == COMPONENT_TYPE_WINDOW ) { break; } nextParent = nextParent->GetParent(); } // Get the panel to draw on wxWindow* selPanel = NULL; if ( nextParent ) { it = m_baseobjects.find( nextParent.get() ); if ( m_baseobjects.end() == it ) { selPanel = m_back->GetFrameContentPanel(); } else { selPanel = wxDynamicCast( it->second, wxWindow ); } } else { selPanel = m_back->GetFrameContentPanel(); } // Find the first COMPONENT_TYPE_WINDOW or COMPONENT_TYPE_SIZER // If it is a sizer, save it wxSizer* sizer = NULL; PObjectBase nextObj = obj->GetParent(); while ( nextObj ) { IComponent* nextComp = nextObj->GetObjectInfo()->GetComponent(); if ( !nextComp ) { break; } if ( nextComp->GetComponentType() == COMPONENT_TYPE_SIZER ) { it = m_baseobjects.find( nextObj.get() ); if ( it != m_baseobjects.end() ) { sizer = wxDynamicCast( it->second, wxSizer ); } break; } else if ( nextComp->GetComponentType() == COMPONENT_TYPE_WINDOW ) { break; } nextObj = nextObj->GetParent(); } m_back->SetSelectedSizer( sizer ); m_back->SetSelectedItem( item ); m_back->SetSelectedObject( obj ); m_back->SetSelectedPanel( selPanel ); m_back->Refresh(); }
void VisualEditor::SetupWindow( PObjectBase obj, wxWindow* window ) { // All of the properties of the wxWindow object are applied in this function // Position /* Position does nothing in wxFB - this is pointless wxPoint pos; PProperty ppos = obj->GetProperty( wxT("pos") ); if ( ppos ) { pos = TypeConv::StringToPoint( ppos->GetValue() ); } */ // Size wxSize size = obj->GetPropertyAsSize( wxT("size") ); if ( size != wxDefaultSize ) { window->SetSize( size ); } // Minimum size wxSize minsize = obj->GetPropertyAsSize( wxT("minimum_size") ); if ( minsize != wxDefaultSize ) { window->SetMinSize( minsize ); } // Maximum size wxSize maxsize = obj->GetPropertyAsSize( wxT("maximum_size") ); if ( maxsize != wxDefaultSize ) { window->SetMaxSize( maxsize ); } // Font PProperty pfont = obj->GetProperty( wxT("font") ); if ( pfont && !pfont->GetValue().empty() ) { window->SetFont( TypeConv::StringToFont( pfont->GetValue() ) ); } // Foreground PProperty pfg_colour = obj->GetProperty( wxT("fg") ); if ( pfg_colour && !pfg_colour->GetValue().empty() ) { window->SetForegroundColour( TypeConv::StringToColour( pfg_colour->GetValue() ) ); } // Background PProperty pbg_colour = obj->GetProperty( wxT("bg") ); if ( pbg_colour && !pbg_colour->GetValue().empty() ) { window->SetBackgroundColour( TypeConv::StringToColour( pbg_colour->GetValue() ) ); } // Extra Style PProperty pextra_style = obj->GetProperty( wxT("window_extra_style") ); if ( pextra_style ) { window->SetExtraStyle( TypeConv::StringToInt( pextra_style->GetValue() ) ); } // Enabled PProperty penabled = obj->GetProperty( wxT("enabled") ); if ( penabled ) { window->Enable( ( penabled->GetValueAsInteger() !=0 ) ); } // Hidden PProperty phidden = obj->GetProperty( wxT("hidden") ); if ( phidden ) { window->Show( !phidden->GetValueAsInteger() ); } // Tooltip PProperty ptooltip = obj->GetProperty( wxT("tooltip") ); if ( ptooltip ) { window->SetToolTip( ptooltip->GetValueAsString() ); } //AUI wxString tname = obj->GetObjectInfo()->GetObjectType()->GetName(); if( m_auimgr && ( tname == wxT("widget") || tname == wxT("expanded_widget") || tname == wxT("container") || tname == wxT("notebook") || tname == wxT("auinotebook") || tname == wxT("choicebook") || tname == wxT("treelistctrl") || tname == wxT("splitter") ) ) { if( obj->GetParent()->GetObjectTypeName() == wxT("form") ) { SetupAui(obj, window); } } // Wizard else if ( obj->GetParent()->GetObjectTypeName() == wxT("wizard") ) { SetupWizard( obj, window, true ); } }
void DesignerWindow::HighlightSelection( wxDC& dc ) { // do not highlight if AUI is used in floating mode VisualEditor *editor = wxDynamicCast( GetParent(), VisualEditor ); if( editor && editor->m_auimgr ) { wxWindow *windowItem = wxDynamicCast( m_selItem, wxWindow ); while( windowItem ) { wxAuiPaneInfo info = editor->m_auimgr->GetPane( windowItem ); if( info.IsOk() ) { if( info.IsFloating() ) return; else break; } windowItem = windowItem->GetParent(); } } wxSize size; PObjectBase object = m_selObj.lock(); if ( m_selSizer ) { wxPoint point = m_selSizer->GetPosition(); size = m_selSizer->GetSize(); wxPen bluePen( *wxBLUE, 1, wxSOLID ); dc.SetPen( bluePen ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); PObjectBase sizerParent = object->FindNearAncestorByBaseClass( wxT("sizer") ); if( !sizerParent ) sizerParent = object->FindNearAncestorByBaseClass( wxT("gbsizer") ); if ( sizerParent && sizerParent->GetParent() ) { DrawRectangle( dc, point, size, sizerParent ); } } if ( m_selItem ) { wxPoint point; bool shown; wxWindow* windowItem = wxDynamicCast( m_selItem, wxWindow ); wxSizer* sizerItem = wxDynamicCast( m_selItem, wxSizer ); if ( NULL != windowItem ) { point = windowItem->GetPosition(); size = windowItem->GetSize(); shown = windowItem->IsShown(); } else if ( NULL != sizerItem ) { point = sizerItem->GetPosition(); size = sizerItem->GetSize(); shown = true; } else { return; } if ( shown ) { wxPen redPen( *wxRED, 1, wxSOLID ); dc.SetPen( redPen ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); DrawRectangle( dc, point, size, object ); } } }
void PHPCodeGenerator::GenConstruction(PObjectBase obj, bool is_widget ) { wxString type = obj->GetObjectTypeName(); PObjectInfo info = obj->GetObjectInfo(); if ( ObjectDatabase::HasCppProperties( type ) ) { m_source->WriteLn( GetCode( obj, wxT("construction") ) ); GenSettings( obj->GetObjectInfo(), obj ); bool isWidget = !info->IsSubclassOf( wxT("sizer") ); for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { PObjectBase child = obj->GetChild( i ); GenConstruction( child, isWidget ); if ( type == wxT("toolbar") ) { GenAddToolbar(child->GetObjectInfo(), child); } } if ( !isWidget ) // sizers { wxString afterAddChild = GetCode( obj, wxT( "after_addchild" ) ); if ( !afterAddChild.empty() ) { m_source->WriteLn( afterAddChild ); } m_source->WriteLn(); if (is_widget) { // the parent object is not a sizer. There is no template for // this so we'll make it manually. // It's not a good practice to embed templates into the source code, // because you will need to recompile... wxString _template = wxT("#wxparent $name->SetSizer( @$$name ); #nl") wxT("#wxparent $name->Layout();") wxT("#ifnull #parent $size") wxT("@{ #nl @$$name->Fit( #wxparent $name ); @}"); PHPTemplateParser parser( obj, _template, m_i18n, m_useRelativePath, m_basePath ); m_source->WriteLn(parser.ParseTemplate()); } } else if ( type == wxT("splitter") ) { // Generating the split switch ( obj->GetChildCount() ) { case 1: { PObjectBase sub1 = obj->GetChild(0)->GetChild(0); wxString _template = wxT("@$this->$name->Initialize( "); _template = _template + wxT("@$this->") + sub1->GetProperty( wxT("name") )->GetValue() + wxT(" );"); PHPTemplateParser parser( obj, _template, m_i18n, m_useRelativePath, m_basePath ); m_source->WriteLn(parser.ParseTemplate()); break; } case 2: { PObjectBase sub1,sub2; sub1 = obj->GetChild(0)->GetChild(0); sub2 = obj->GetChild(1)->GetChild(0); wxString _template; if ( obj->GetProperty( wxT("splitmode") )->GetValue() == wxT("wxSPLIT_VERTICAL") ) { _template = wxT("@$this->$name->SplitVertically( "); } else { _template = wxT("@$this->$name->SplitHorizontally( "); } _template = _template + wxT("@$this->") + sub1->GetProperty( wxT("name") )->GetValue() + wxT(", @$this->") + sub2->GetProperty( wxT("name") )->GetValue() + wxT(", $sashpos );"); PHPTemplateParser parser( obj, _template, m_i18n, m_useRelativePath, m_basePath ); m_source->WriteLn(parser.ParseTemplate()); break; } default: wxLogError( wxT("Missing subwindows for wxSplitterWindow widget.") ); break; } } else if ( type == wxT("menubar") || type == wxT("menu") || type == wxT("submenu") || type == wxT("toolbar") || type == wxT("ribbonbar") || type == wxT("listbook") || type == wxT("simplebook") || type == wxT("notebook") || type == wxT("auinotebook") || type == wxT("treelistctrl") || type == wxT("flatnotebook") || type == wxT("wizard") ) { wxString afterAddChild = GetCode( obj, wxT("after_addchild") ); if ( !afterAddChild.empty() ) { m_source->WriteLn( afterAddChild ); } m_source->WriteLn(); } } else if ( info->IsSubclassOf( wxT("sizeritembase") ) ) { // The child must be added to the sizer having in mind the // child object type (there are 3 different routines) GenConstruction( obj->GetChild(0), false ); PObjectInfo childInfo = obj->GetChild(0)->GetObjectInfo(); wxString temp_name; if ( childInfo->IsSubclassOf( wxT("wxWindow") ) || wxT("CustomControl") == childInfo->GetClassName() ) { temp_name = wxT("window_add"); } else if ( childInfo->IsSubclassOf( wxT("sizer") ) ) { temp_name = wxT("sizer_add"); } else if ( childInfo->GetClassName() == wxT("spacer") ) { temp_name = wxT("spacer_add"); } else { LogDebug( wxT("SizerItem child is not a Spacer and is not a subclass of wxWindow or of sizer.") ); return; } m_source->WriteLn( GetCode( obj, temp_name ) ); } else if ( type == wxT("notebookpage") || type == wxT("flatnotebookpage") || type == wxT("listbookpage") || type == wxT("simplebookpage") || type == wxT("choicebookpage") || type == wxT("auinotebookpage") ) { GenConstruction( obj->GetChild( 0 ), false ); m_source->WriteLn( GetCode( obj, wxT("page_add") ) ); GenSettings( obj->GetObjectInfo(), obj ); } else if ( type == wxT("treelistctrlcolumn") ) { m_source->WriteLn( GetCode( obj, wxT("column_add") ) ); GenSettings( obj->GetObjectInfo(), obj ); } else if ( type == wxT("tool") ) { // If loading bitmap from ICON resource, and size is not set, set size to toolbars bitmapsize // So hacky, yet so useful ... wxSize toolbarsize = obj->GetParent()->GetPropertyAsSize( _("bitmapsize") ); if ( wxDefaultSize != toolbarsize ) { PProperty prop = obj->GetProperty( _("bitmap") ); if ( prop ) { wxString oldVal = prop->GetValueAsString(); wxString path, source; wxSize toolsize; TypeConv::ParseBitmapWithResource( oldVal, &path, &source, &toolsize ); if ( wxT("Load From Icon Resource") == source && wxDefaultSize == toolsize ) { prop->SetValue( wxString::Format( wxT("%s; %s [%i; %i]"), path.c_str(), source.c_str(), toolbarsize.GetWidth(), toolbarsize.GetHeight() ) ); m_source->WriteLn( GetCode( obj, wxT("construction") ) ); prop->SetValue( oldVal ); return; } } } m_source->WriteLn( GetCode( obj, wxT("construction") ) ); } else { // Generate the children for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { GenConstruction( obj->GetChild( i ), false ); } } }