PObjectBase MenuEditor::GetMenubar(PObjectDatabase base) { // Disconnect all parent/child relationships in original objects for ( std::vector< WPObjectBase >::iterator it = m_originalItems.begin(); it != m_originalItems.end(); ++it ) { PObjectBase obj = it->lock(); if ( obj ) { obj->RemoveAllChildren(); obj->SetParent( PObjectBase() ); } } PObjectInfo info = base->GetObjectInfo( wxT("wxMenuBar" )); PObjectBase menubar = base->NewObject(info); long n = 0; while (n < m_menuList->GetItemCount()) { PObjectBase child = GetMenu(n, base, false); menubar->AddChild(child); child->SetParent(menubar); } return menubar; }
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; }
PObjectBase MenuEditor::GetMenu(long& n, PObjectDatabase base, bool isSubMenu) { // Get item from list control wxString label, shortcut, id, name, help, kind; PObjectBase menu; GetItem(n, label, shortcut, id, name, help, kind, &menu); bool createNew = true; if ( menu ) { createNew = ( menu->GetClassName() != (isSubMenu ? wxT("submenu") : wxT("wxMenu")) ); } // preserve original menu if the object types match // this preserves properties that are not exposed in the menu editor - like C++ scope if ( createNew ) { PObjectInfo info = base->GetObjectInfo(isSubMenu ? wxT("submenu") : wxT("wxMenu") ); menu = base->NewObject(info); } label.Trim(true); label.Trim(false); menu->GetProperty( wxT("label") )->SetValue(label); menu->GetProperty( wxT("name") )->SetValue(name); int ident = GetItemIdentation(n); n++; while (n < m_menuList->GetItemCount() && GetItemIdentation(n) > ident) { PObjectBase menuitem; GetItem(n, label, shortcut, id, name, help, kind, &menuitem); createNew = true; label.Trim(true); label.Trim(false); if (label == wxT("---")) { if ( menuitem ) { createNew = ( menuitem->GetClassName() != wxT("separator") ); } if ( createNew ) { PObjectInfo info = base->GetObjectInfo( wxT("separator") ); menuitem = base->NewObject(info); } menu->AddChild(menuitem); menuitem->SetParent(menu); n++; } else if (HasChildren(n)) { PObjectBase child = GetMenu(n, base); menu->AddChild(child); child->SetParent(menu); } else { if ( menuitem ) { createNew = ( menuitem->GetClassName() != wxT("wxMenuItem") ); } if ( createNew ) { PObjectInfo info = base->GetObjectInfo( wxT("wxMenuItem") ); menuitem = base->NewObject(info); } menuitem->GetProperty( wxT("label") )->SetValue(label); menuitem->GetProperty( wxT("shortcut") )->SetValue(shortcut); menuitem->GetProperty( wxT("name") )->SetValue(name); menuitem->GetProperty( wxT("help") )->SetValue(help); menuitem->GetProperty( wxT("id") )->SetValue(id); menuitem->GetProperty( wxT("kind") )->SetValue(kind); menu->AddChild(menuitem); menuitem->SetParent(menu); n++; } } return menu; }