void MenuEditor::AddChild(long& n, int ident, PObjectBase obj) { for (unsigned int i = 0; i < obj->GetChildCount(); i++) { PObjectBase childObj = obj->GetChild(i); if (childObj->GetClassName() == wxT("wxMenuItem") ) { InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + childObj->GetPropertyAsString(wxT("label")), childObj->GetPropertyAsString(wxT("shortcut")), childObj->GetPropertyAsString(wxT("id")), childObj->GetPropertyAsString(wxT("name")), childObj->GetPropertyAsString(wxT("help")), childObj->GetPropertyAsString(wxT("kind")), childObj); } else if (childObj->GetClassName() == wxT("separator") ) { InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + wxT("---"), wxT(""), wxT(""), wxT(""), wxT(""), wxT(""), childObj); } else { InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + childObj->GetPropertyAsString(wxT("label")), wxT(""), childObj->GetPropertyAsString(wxT("id")), childObj->GetPropertyAsString(wxT("name")), childObj->GetPropertyAsString(wxT("help")), wxT(""), childObj); AddChild(n, ident + 1, childObj); } } }
PObjectBase XrcLoader::GetObject( ticpp::Element *xrcObj, PObjectBase parent ) { // First, create the object by the name, the modify the properties std::string className = xrcObj->GetAttribute( "class" ); if ( parent->GetObjectTypeName() == wxT( "project" ) ) { if ( className == "wxBitmap" ) { PProperty bitmapsProp = parent->GetProperty( _( "bitmaps" ) ); if ( bitmapsProp ) { wxString value = bitmapsProp->GetValue(); wxString text = _WXSTR( xrcObj->GetText() ); text.Replace( wxT( "\'" ), wxT( "\'\'" ), true ); value << wxT( "\'" ) << text << wxT( "\' " ); bitmapsProp->SetValue( value ); return PObjectBase(); } } if ( className == "wxIcon" ) { PProperty iconsProp = parent->GetProperty( _( "icons" ) ); if ( iconsProp ) { wxString value = iconsProp->GetValue(); wxString text = _WXSTR( xrcObj->GetText() ); text.Replace( wxT( "\'" ), wxT( "\'\'" ), true ); value << wxT( "\'" ) << text << wxT( "\' " ); iconsProp->SetValue( value ); return PObjectBase(); } } // Forms wxPanel, wxFrame, wxDialog are stored internally as Panel, Frame, and Dialog // to prevent conflicts with wxPanel as a container className = className.substr( 2, className.size() - 2 ); } // Well, this is not nice. wxMenu class name is ambiguous, so we'll get the // correct class by the context. If the parent of a wxMenu is another wxMenu // then the class name will be "submenu" else if ( className == "wxMenu" && ( parent->GetClassName() == wxT( "wxMenu" ) || parent->GetClassName() == wxT( "submenu" ) ) ) { className = "submenu"; } // "separator" is also ambiguous - could be a toolbar separator or a menu separator else if ( className == "separator" ) { if ( parent->GetClassName() == wxT( "wxToolBar" ) ) { className = "toolSeparator"; } } // replace "spacer" with "sizeritem" so it will be imported as a "sizeritem" // "sizeritem" is ambiguous - could also be a grid bag sizeritem else if ( className == "spacer" || className == "sizeritem" ) { if ( parent->GetClassName() == wxT( "wxGridBagSizer" ) ) { className = "gbsizeritem"; } else { className = "sizeritem"; } } PObjectBase object; PObjectInfo objInfo = m_objDb->GetObjectInfo( _WXSTR( className ) ); if ( objInfo ) { IComponent *comp = objInfo->GetComponent(); if ( !comp ) { wxLogError( _("No component found for class \"%s\", found on line %i."), _WXSTR( className ).c_str(), xrcObj->Row() ); } else { ticpp::Element *fbObj = comp->ImportFromXrc( xrcObj ); if ( !fbObj ) { wxLogError( _("ImportFromXrc returned NULL for class \"%s\", found on line %i."), _WXSTR( className ).c_str(), xrcObj->Row() ); } else { object = m_objDb->CreateObject( fbObj, parent ); if ( !object ) { // Unable to create the object and add it to the parent - probably needs a sizer PObjectBase newsizer = m_objDb->CreateObject( "wxBoxSizer", parent ); if ( newsizer ) { // It is possible the CreateObject returns an "item" containing the object, e.g. SizerItem or SplitterItem // If that is the case, reassign "object" to the actual object PObjectBase sizer = newsizer; if ( sizer->GetChildCount() > 0 ) { sizer = sizer->GetChild( 0 ); } if ( sizer ) { object = m_objDb->CreateObject( fbObj, sizer ); if ( object ) { parent->AddChild( newsizer ); newsizer->SetParent( parent ); } } } } if ( !object ) { wxLogError( wxT( "CreateObject failed for class \"%s\", with parent \"%s\", found on line %i" ), _WXSTR( className ).c_str(), parent->GetClassName().c_str(), xrcObj->Row() ); } else { // It is possible the CreateObject returns an "item" containing the object, e.g. SizerItem or SplitterItem // If that is the case, reassign "object" to the actual object if ( object && object->GetChildCount() > 0 ) object = object->GetChild( 0 ); if ( object ) { // Recursively import the children ticpp::Element *element = xrcObj->FirstChildElement( "object", false ); while ( element ) { GetObject( element, object ); element = element->NextSiblingElement( "object", false ); } } } } } } else { // Create a wxPanel to represent unknown classes object = m_objDb->CreateObject( "wxPanel", parent ); if ( object ) { parent->AddChild( object ); object->SetParent( parent ); wxLogError( wxT( "Unknown class \"%s\" found on line %i, replaced with a wxPanel" ), _WXSTR( className ).c_str(), xrcObj->Row() ); } else { wxString msg( wxString::Format( wxT( "Unknown class \"%s\" found on line %i, and could not replace with a wxPanel as child of \"%s:%s\"" ), _WXSTR( className ).c_str(), xrcObj->Row(), parent->GetPropertyAsString( wxT( "name" ) ).c_str(), parent->GetClassName().c_str() ) ); wxLogError( msg ); } } return object; }
void DesignerWindow::SetFrameWidgets(PObjectBase menubar, wxWindow *toolbar, wxWindow *statusbar) { wxWindow *contentPanel = GetFrameContentPanel(); Menubar *mbWidget = NULL; if ( menubar ) { mbWidget = new Menubar(contentPanel, -1); for ( unsigned int i = 0; i < menubar->GetChildCount(); i++ ) { PObjectBase menu = menubar->GetChild( i ); wxMenu *menuWidget = GetMenuFromObject( menu ); mbWidget->AppendMenu( menu->GetPropertyAsString( wxT("label") ), menuWidget ); } } wxSizer *mainSizer = contentPanel->GetSizer(); contentPanel->SetSizer( NULL, false ); wxSizer *dummySizer = new wxBoxSizer( wxVERTICAL ); if ( mbWidget ) { dummySizer->Add(mbWidget, 0, wxEXPAND | wxTOP | wxBOTTOM, 0); dummySizer->Add(new wxStaticLine(contentPanel, -1), 0, wxEXPAND | wxALL, 0); } wxSizer* contentSizer = dummySizer; if (toolbar) { if ( (toolbar->GetWindowStyle() & wxTB_VERTICAL) != 0 ) { wxSizer* horiz = new wxBoxSizer( wxHORIZONTAL ); horiz->Add(toolbar, 0, wxEXPAND | wxALL, 0); wxSizer* vert = new wxBoxSizer( wxVERTICAL ); horiz->Add( vert, 1, wxEXPAND, 0 ); dummySizer->Add( horiz, 1, wxEXPAND, 0); contentSizer = vert; } else { dummySizer->Add(toolbar, 0, wxEXPAND | wxALL, 0); } } if (mainSizer) { contentSizer->Add(mainSizer, 1, wxEXPAND | wxALL, 0); if ( mainSizer->GetChildren().IsEmpty() ) { // Sizers do not expand if they are empty mainSizer->AddStretchSpacer(1); } } else contentSizer->AddStretchSpacer(1); if (statusbar) { contentSizer->Add(statusbar, 0, wxEXPAND | wxALL, 0); } contentPanel->SetSizer(dummySizer, false); contentPanel->Layout(); }
wxMenu* DesignerWindow::GetMenuFromObject(PObjectBase menu) { int lastMenuId = wxID_HIGHEST + 1; wxMenu* menuWidget = new wxMenu(); for ( unsigned int j = 0; j < menu->GetChildCount(); j++ ) { PObjectBase menuItem = menu->GetChild( j ); if ( menuItem->GetObjectTypeName() == wxT("submenu") ) { menuWidget->Append( lastMenuId++, menuItem->GetPropertyAsString( wxT("label") ), GetMenuFromObject( menuItem ) ); } else if ( menuItem->GetClassName() == wxT("separator") ) { menuWidget->AppendSeparator(); } else { wxString label = menuItem->GetPropertyAsString( wxT("label") ); wxString shortcut = menuItem->GetPropertyAsString( wxT("shortcut") ); if ( !shortcut.IsEmpty() ) { label = label + wxChar('\t') + shortcut; } wxMenuItem *item = new wxMenuItem( menuWidget, lastMenuId++, label, menuItem->GetPropertyAsString( wxT("help") ), ( wxItemKind ) menuItem->GetPropertyAsInteger( wxT("kind") ) ); if ( !menuItem->GetProperty( wxT("bitmap") )->IsNull() ) { wxBitmap unchecked = wxNullBitmap; if ( !menuItem->GetProperty( wxT("unchecked_bitmap") )->IsNull() ) { unchecked = menuItem->GetPropertyAsBitmap( wxT("unchecked_bitmap") ); } #ifdef __WXMSW__ item->SetBitmaps( menuItem->GetPropertyAsBitmap( wxT("bitmap") ), unchecked ); #elif defined( __WXGTK__ ) item->SetBitmap( menuItem->GetPropertyAsBitmap( wxT("bitmap") ) ); #endif } else { if ( !menuItem->GetProperty( wxT("unchecked_bitmap") )->IsNull() ) { #ifdef __WXMSW__ item->SetBitmaps( wxNullBitmap, menuItem->GetPropertyAsBitmap( wxT("unchecked_bitmap") ) ); #endif } } menuWidget->Append( item ); if ( item->GetKind() == wxITEM_CHECK && menuItem->GetPropertyAsInteger( wxT("checked") ) ) { item->Check( true ); } item->Enable( ( menuItem->GetPropertyAsInteger( wxT("enabled") ) != 0 ) ); } } return menuWidget; }
void VisualEditor::SetupAui( PObjectBase obj, wxWindow* window ) { wxAuiPaneInfo info; // check whether the object contains AUI info... if( !obj->GetProperty( wxT("aui_name") ) ) return; wxString name = obj->GetPropertyAsString( wxT("aui_name") ); if( name != wxT("") ) info.Name( name ); if( obj->GetPropertyAsInteger( wxT("center_pane") )) info.CenterPane(); if( obj->GetPropertyAsInteger( wxT("default_pane") )) info.DefaultPane(); if( !obj->IsNull(wxT("caption"))) info.Caption(obj->GetPropertyAsString(wxT("caption"))); info.CaptionVisible( obj->GetPropertyAsInteger( wxT("caption_visible") ) ); info.CloseButton( obj->GetPropertyAsInteger( wxT("close_button") ) ); info.MaximizeButton( obj->GetPropertyAsInteger( wxT("maximize_button") ) ); info.MinimizeButton( obj->GetPropertyAsInteger( wxT("minimize_button") ) ); info.PinButton( obj->GetPropertyAsInteger( wxT("pin_button") ) ); info.PaneBorder( obj->GetPropertyAsInteger( wxT("pane_border") ) ); info.Gripper(obj->GetPropertyAsInteger( wxT("gripper") )); info.BottomDockable( obj->GetPropertyAsInteger( wxT("BottomDockable") ) ); info.TopDockable( obj->GetPropertyAsInteger( wxT("TopDockable") ) ); info.LeftDockable( obj->GetPropertyAsInteger( wxT("LeftDockable") ) ); info.RightDockable( obj->GetPropertyAsInteger( wxT("RightDockable") ) ); if( !obj->IsNull(wxT("dock")) ) { if( obj->GetPropertyAsString( wxT("dock") ) == wxT("Dock")) { info.Dock(); if( !obj->IsNull(wxT("docking")) ) { if( obj->GetPropertyAsString(wxT("docking")) == wxT("Bottom") ) info.Bottom(); else if( obj->GetPropertyAsString(wxT("docking")) == wxT("Top") ) info.Top(); else if( obj->GetPropertyAsString(wxT("docking")) == wxT("Center") ) info.Center(); else if( obj->GetPropertyAsString(wxT("docking")) == wxT("Right") ) info.Right(); } } else { info.Float(); info.FloatingPosition( obj->GetPropertyAsPoint( wxT("pane_position") ) ); } } if( !obj->IsNull(wxT("resize")) ) { if( obj->GetPropertyAsString( wxT("resize") ) == wxT("Resizable")) info.Resizable(); else info.Fixed(); } info.DockFixed( obj->GetPropertyAsInteger( wxT("dock_fixed") ) ); info.Movable( obj->GetPropertyAsInteger( wxT("moveable") )); info.Floatable(obj->GetPropertyAsInteger( wxT("floatable") )); if( !obj->GetProperty( wxT("pane_size" ) )->IsNull() ) info.FloatingSize( obj->GetPropertyAsSize( wxT("pane_size") )); if( !obj->GetProperty( wxT("best_size" ) )->IsNull() ) info.BestSize( obj->GetPropertyAsSize( wxT("best_size") ) ); if( !obj->GetProperty( wxT("min_size" ) )->IsNull() ) info.MinSize( obj->GetPropertyAsSize( wxT("min_size") ) ); if( !obj->GetProperty( wxT("max_size" ) )->IsNull() ) info.MaxSize( obj->GetPropertyAsSize( wxT("max_size") ) ); if( obj->GetPropertyAsInteger( wxT("toolbar_pane") ) ) info.ToolbarPane(); if( !obj->IsNull( wxT("aui_position") ) ) info.Position( obj->GetPropertyAsInteger( wxT("aui_position") )); if( !obj->IsNull( wxT("aui_row") ) ) info.Row( obj->GetPropertyAsInteger( wxT("aui_row") )); if( !obj->IsNull( wxT("aui_layer") ) ) info.Layer( obj->GetPropertyAsInteger( wxT("aui_layer") )); if( !obj->GetPropertyAsInteger( wxT("show") ) ) info.Hide(); m_auimgr->AddPane( window, info ); }
void PHPCodeGenerator::GenerateInheritedClass( PObjectBase userClasses, PObjectBase form ) { if (!userClasses) { wxLogError(wxT("There is no object to generate inherited class")); return; } if ( wxT("UserClasses") != userClasses->GetClassName() ) { wxLogError(wxT("This not a UserClasses object")); return; } wxString type = userClasses->GetPropertyAsString( wxT("type") ); // Start file wxString code = GetCode( userClasses, wxT("file_comment") ); m_source->WriteLn( code ); m_source->WriteLn( wxEmptyString ); code = GetCode( userClasses, wxT("source_include") ); m_source->WriteLn( code ); m_source->WriteLn( wxEmptyString ); code = GetCode( userClasses, wxT("class_decl") ); m_source->WriteLn( code ); m_source->Indent(); code = GetCode( userClasses, type + wxT("_cons_def") ); m_source->WriteLn( code ); // Do events EventVector events; FindEventHandlers( form, events ); if ( events.size() > 0 ) { code = GetCode( userClasses, wxT("event_handler_comment") ); m_source->WriteLn( code ); std::set<wxString> generatedHandlers; for ( size_t i = 0; i < events.size(); i++ ) { PEvent event = events[i]; if ( generatedHandlers.find( event->GetValue() ) == generatedHandlers.end() ) { m_source->WriteLn( wxString::Format( wxT("function %s( event ){"), event->GetValue().c_str() ) ); m_source->Indent(); m_source->WriteLn( wxString::Format( wxT("// TODO: Implement %s"), event->GetValue().c_str() ) ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); m_source->WriteLn( wxEmptyString ); generatedHandlers.insert(event->GetValue()); } } m_source->WriteLn( wxEmptyString ); } m_source->Unindent(); }