void PHPCodeGenerator::GenConstructor( PObjectBase class_obj, const EventVector &events ) { m_source->WriteLn(); // generate function definition m_source->WriteLn( GetCode( class_obj, wxT("cons_def") ) ); m_source->Indent(); m_source->WriteLn( GetCode( class_obj, wxT("cons_call") ) ); m_source->WriteLn(); wxString settings = GetCode( class_obj, wxT("settings") ); if ( !settings.IsEmpty() ) { m_source->WriteLn( settings ); } for ( unsigned int i = 0; i < class_obj->GetChildCount(); i++ ) { GenConstruction( class_obj->GetChild( i ), true ); } wxString afterAddChild = GetCode( class_obj, wxT("after_addchild") ); if ( !afterAddChild.IsEmpty() ) { m_source->WriteLn( afterAddChild ); } GenEvents( class_obj, events ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); m_source->WriteLn( wxT("") ); if ( class_obj->GetObjectTypeName() == wxT("wizard") && class_obj->GetChildCount() > 0 ) { m_source->WriteLn( wxT("function AddPage($page){") ); m_source->Indent(); m_source->WriteLn( wxT("if(count($this->m_pages) > 0){") ); m_source->Indent(); m_source->WriteLn( wxT("$previous_page = $this->m_pages[count($this->m_pages)-1];") ); m_source->WriteLn( wxT("$page->SetPrev($previous_page);") ); m_source->WriteLn( wxT("$previous_page->SetNext($page);") ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); m_source->WriteLn( wxT("$this->m_pages[] = $page;") ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); } }
void PHPCodeGenerator::GenDestruction( PObjectBase obj ) { wxString _template; PCodeInfo code_info = obj->GetObjectInfo()->GetCodeInfo( wxT( "PHP" ) ); if ( code_info ) { _template = code_info->GetTemplate( wxT( "destruction" ) ); if ( !_template.empty() ) { PHPTemplateParser parser( obj, _template, m_i18n, m_useRelativePath, m_basePath ); wxString code = parser.ParseTemplate(); if ( !code.empty() ) { m_source->WriteLn( code ); } } } // Process child widgets for ( unsigned int i = 0; i < obj->GetChildCount() ; i++ ) { PObjectBase child = obj->GetChild( i ); GenDestruction( child ); } }
void PHPCodeGenerator::FindMacros( PObjectBase obj, std::vector<wxString>* macros ) { // iterate through all of the properties of all objects, add the macros // to the vector unsigned int i; for ( i = 0; i < obj->GetPropertyCount(); i++ ) { PProperty prop = obj->GetProperty( i ); if ( prop->GetType() == PT_MACRO ) { wxString value = prop->GetValue(); if( value.IsEmpty() ) continue; // Skip wx IDs if ( ( ! value.Contains( wxT("XRCID" ) ) ) && ( m_predMacros.end() == m_predMacros.find( value ) ) ) { if ( macros->end() == std::find( macros->begin(), macros->end(), value ) ) { macros->push_back( value ); } } } } for ( i = 0; i < obj->GetChildCount(); i++ ) { FindMacros( obj->GetChild( i ), macros ); } }
void PHPCodeGenerator::GenObjectIncludes( PObjectBase project, std::vector< wxString >* includes, std::set< wxString >* templates ) { // Fill the set PCodeInfo code_info = project->GetObjectInfo()->GetCodeInfo( wxT("PHP") ); if (code_info) { PHPTemplateParser parser( project, code_info->GetTemplate( wxT("include") ), m_i18n, m_useRelativePath, m_basePath ); wxString include = parser.ParseTemplate(); if ( !include.empty() ) { if ( templates->insert( include ).second ) { AddUniqueIncludes( include, includes ); } } } // Call GenIncludes on all children as well for ( unsigned int i = 0; i < project->GetChildCount(); i++ ) { GenObjectIncludes( project->GetChild(i), includes, templates ); } // Generate includes for base classes GenBaseIncludes( project->GetObjectInfo(), project, includes, templates ); }
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); } } }
void PHPCodeGenerator::GetGenEventHandlers( PObjectBase obj ) { GenDefinedEventHandlers( obj->GetObjectInfo(), obj ); for (unsigned int i = 0; i < obj->GetChildCount() ; i++) { PObjectBase child = obj->GetChild(i); GetGenEventHandlers(child); } }
size_t wxFBManager::GetChildCount( wxObject* wxobject ) { CHECK_VISUAL_EDITOR( 0 ) CHECK_WX_OBJECT( 0 ) PObjectBase obj = m_visualEdit->GetObjectBase( wxobject ); CHECK_OBJECT_BASE( 0 ) return obj->GetChildCount(); }
void CppCodeGenerator::GenConstructor(PObjectBase class_obj) { m_source->WriteLn(GetCode(class_obj,"cons_def")); m_source->WriteLn("{"); m_source->Indent(); for (unsigned int i=0; i<class_obj->GetChildCount() ; i++) GenConstruction(class_obj->GetChild(i),true); m_source->Unindent(); m_source->WriteLn("}"); m_source->WriteLn(""); }
void PHPCodeGenerator::FindDependencies( PObjectBase obj, std::set< PObjectInfo >& info_set ) { unsigned int ch_count = obj->GetChildCount(); if (ch_count > 0) { unsigned int i; for (i = 0; i<ch_count; i++) { PObjectBase child = obj->GetChild(i); info_set.insert(child->GetObjectInfo()); FindDependencies(child, info_set); } } }
void PHPCodeGenerator::FindEventHandlers(PObjectBase obj, EventVector &events) { unsigned int i; for (i=0; i < obj->GetEventCount(); i++) { PEvent event = obj->GetEvent(i); if (!event->GetValue().IsEmpty()) events.push_back(event); } for (i=0; i < obj->GetChildCount(); i++) { PObjectBase child = obj->GetChild(i); FindEventHandlers(child,events); } }
wxObject* wxFBManager::GetChild( wxObject* wxobject, size_t childIndex ) { CHECK_VISUAL_EDITOR( NULL ) CHECK_WX_OBJECT( NULL ) PObjectBase obj = m_visualEdit->GetObjectBase( wxobject ); CHECK_OBJECT_BASE( NULL ) if ( childIndex >= obj->GetChildCount() ) { return NULL; } return m_visualEdit->GetWxObject( obj->GetChild( childIndex ) ); }
void CppCodeGenerator::FindMacros(PObjectBase obj, set<string> ¯o_set) { // recorre cada propiedad de cada objeto identificando aquellas // que sean macros, en cuyo caso la añade al conjunto. unsigned int i; for (i=0; i<obj->GetPropertyCount(); i++) { PProperty prop = obj->GetProperty(i); if (prop->GetType() == PT_MACRO) macro_set.insert(prop->GetValue()); } for (i=0; i<obj->GetChildCount(); i++) { FindMacros(obj->GetChild(i),macro_set); } }
bool CppCodeGenerator::GenerateCode(PObjectBase project) { m_header->Clear(); m_source->Clear(); string date(__DATE__); string time(__TIME__); string code_header ( "///////////////////////////////////////////////////////////////////////////\n" "// C++ code generated with wxFormBuilder (version " __DATE__ ")\n" "// http://wxformbuilder.software-libre.org/\n" "//\n" "// PLEASE DO \"NOT\" EDIT THIS FILE!\n" "///////////////////////////////////////////////////////////////////////////\n"); m_header->WriteLn(code_header); m_source->WriteLn(code_header); string file = project->GetProperty("file")->GetValue(); m_header->WriteLn("#ifndef __" + file + "__"); m_header->WriteLn("#define __" + file + "__"); m_source->WriteLn("#include \""+file+".h\""); GenIncludes(project); GenDefines(project); for (unsigned int i=0; i<project->GetChildCount(); i++) { GenClassDeclaration(project->GetChild(i)); GenConstructor(project->GetChild(i)); } m_header->WriteLn("#endif //__" + file + "__"); m_header->WriteLn(""); return true; }
void CppCodeGenerator::GenIncludes(PObjectBase project) { m_header->WriteLn("#include <wx/wx.h>"); // almacenaremos todos los objetos diferentes que se encuentran en el // proyecto para luego generar los includes. set<PObjectInfo> info_set; // buscamos todas las dependencias for (unsigned int i=0; i<project->GetChildCount(); i++) FindDependencies(project->GetChild(i), info_set); // generamos los includes set<PObjectInfo>::iterator it; for (it = info_set.begin() ; it != info_set.end() ; it++) { PCodeInfo code_info = (*it)->GetCodeInfo("C++"); string include = code_info->GetTemplate("include"); if (include != "") m_header->WriteLn(include); } m_header->WriteLn(""); }
void CppCodeGenerator::GenAttributeDeclaration(PObjectBase obj, Permission perm) { if (obj->GetObjectType() == T_WIDGET || obj->GetObjectType() == T_COMPONENT) { string perm_str = obj->GetProperty("permission")->GetValue(); if ((perm == P_PUBLIC && perm_str == "public") || (perm == P_PROTECTED && perm_str == "protected") || (perm == P_PRIVATE && perm_str == "private")) { // generamos la declaración string code = GetCode(obj,"declaration"); m_header->WriteLn(code); } } // recursivamente generamos los demás atributos for (unsigned int i = 0; i < obj->GetChildCount() ; i++) { PObjectBase child = obj->GetChild(i); GenAttributeDeclaration(child,perm); } }
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 CppCodeGenerator::GenConstruction(PObjectBase obj, bool is_widget) { ObjectType type = obj->GetObjectType(); switch (type) { case T_WIDGET: { // comprobamos si no se ha declarado como atributo de clase // en cuyo caso lo declaramos en el constructor string perm_str = obj->GetProperty("permission")->GetValue(); if (perm_str == "none") m_source->WriteLn(GetCode(obj,"declaration")); m_source->WriteLn(GetCode(obj,"construction")); GenSettings(obj->GetObjectInfo(), obj); for (unsigned int i=0; i<obj->GetChildCount() ; i++) GenConstruction(obj->GetChild(i),true); } break; case T_SIZER: { m_source->WriteLn(GetCode(obj,"declaration")); m_source->WriteLn(GetCode(obj,"construction")); GenSettings(obj->GetObjectInfo(), obj); for (unsigned int i=0; i<obj->GetChildCount() ; i++) GenConstruction(obj->GetChild(i),false); if (is_widget) { // hay que hacer un SetSizer, pero // no hay una plantilla para esta operación :-( // No conviene empotrar plantillas en la aplicación, ya que // para hacer cambios hay que recompilar el código (sin que // sirva de precedente, vamos a hacerlo aquí) string _template = "#wxparent $name->SetSizer($name);\n" "#wxparent $name->SetAutoLayout(true);\n" "#wxparent $name->Layout();"; CppTemplateParser parser(obj,_template); m_source->WriteLn(parser.ParseTemplate()); } } break; case T_SPACER: // nada que hacer break; case T_SIZERITEM: { // El hijo, hay que añadirlo al sizer teniendo en cuenta el tipo // del objeto hijo (hay 3 rutinas diferentes) GenConstruction(obj->GetChild(0),false); ObjectType child_type = obj->GetChild(0)->GetObjectType(); string temp_name; switch (child_type) { case T_WIDGET: temp_name = "window_add"; break; case T_SIZER: temp_name = "sizer_add"; break; case T_SPACER: temp_name = "spacer_add"; break; default: assert(false); break; } m_source->WriteLn(GetCode(obj,temp_name)); } break; default: break; } }
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(); }
/** * Generates wxObjects from ObjectBase * * @param obj ObjectBase to generate. * @param parent wxWindow parent, necessary to instantiate a widget. * @param parentObject ObjectBase parent - not always the same as the wxparent (e.g. an abstract component). */ void VisualEditor::Generate( PObjectBase obj, wxWindow* wxparent, wxObject* parentObject ) { // Get Component PObjectInfo obj_info = obj->GetObjectInfo(); IComponent* comp = obj_info->GetComponent(); if ( NULL == comp ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s not found!"), obj->GetClassName().c_str() ) ); } // Create Object wxObject* createdObject = comp->Create( obj.get(), wxparent ); wxWindow* createdWindow = NULL; wxSizer* createdSizer = NULL; switch ( comp->GetComponentType() ) { case COMPONENT_TYPE_WINDOW: createdWindow = wxDynamicCast( createdObject, wxWindow ); if ( NULL == createdWindow ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a window component, but this is not a wxWindow!"), obj->GetClassName().c_str() ) ); } SetupWindow( obj, createdWindow ); // Push event handler in order to respond to Paint and Mouse events createdWindow->PushEventHandler( new VObjEvtHandler( createdWindow, obj ) ); break; case COMPONENT_TYPE_SIZER: createdSizer = wxDynamicCast( createdObject, wxSizer ); if ( NULL == createdSizer ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a sizer component, but this is not a wxSizer!"), obj->GetClassName().c_str() ) ); } SetupSizer( obj, createdSizer ); break; default: break; } // Associate the wxObject* with the PObjectBase m_wxobjects.insert( wxObjectMap::value_type( createdObject, obj ) ); m_baseobjects.insert( ObjectBaseMap::value_type( obj.get(), createdObject ) ); // New wxparent for the window's children wxWindow* new_wxparent = ( createdWindow ? createdWindow : wxparent ); // Recursively generate the children for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { Generate( obj->GetChild( i ), new_wxparent, createdObject ); } comp->OnCreated( createdObject, new_wxparent ); // If the created object is a sizer and the parent object is a window, set the sizer to the window if ( ( createdSizer != NULL && NULL != wxDynamicCast( parentObject, wxWindow ) ) || ( NULL == parentObject && createdSizer != NULL ) ) { wxparent->SetSizer( createdSizer ); if ( parentObject ) createdSizer->SetSizeHints( wxparent ); wxparent->SetAutoLayout(true); wxparent->Layout(); } }
bool XrcCodeGenerator::GenerateCode( PObjectBase project ) { m_cw->Clear(); m_contextMenus.clear(); ticpp::Document doc; ticpp::Declaration decl( "1.0", "UTF-8", "yes" ); doc.LinkEndChild( &decl ); ticpp::Element element( "resource" ); element.SetAttribute( "xmlns", "http://www.wxwindows.org/wxxrc" ); element.SetAttribute( "version", "2.3.0.1" ); // If project is not actually a "Project", generate it if ( project->GetClassName() == wxT("Project") ) { for( unsigned int i = 0; i < project->GetChildCount(); i++ ) { ticpp::Element* child = GetElement( project->GetChild( i ) ); if ( child ) { element.LinkEndChild( child ); delete child; } } } else { ticpp::Element* child = GetElement( project ); if ( child ) { element.LinkEndChild( child ); delete child; } } // generate context menus as top-level menus for( std::vector<ticpp::Element*>::iterator it = m_contextMenus.begin(); it != m_contextMenus.end(); ++it ) { element.LinkEndChild( *it ); delete *it; } doc.LinkEndChild( &element ); TiXmlPrinter printer; printer.SetIndent( "\t" ); #if defined( __WXMSW__ ) printer.SetLineBreak( "\r\n" ); #elif defined( __WXMAC__ ) printer.SetLineBreak( "\r" ); #else printer.SetLineBreak( "\n" ); #endif doc.Accept( &printer ); const std::string& xrcFile = printer.Str(); m_cw->Write( _WXSTR( xrcFile ) ); return true; }
ticpp::Element* XrcCodeGenerator::GetElement( PObjectBase obj, ticpp::Element* parent ) { ticpp::Element *element = NULL; IComponent *comp = obj->GetObjectInfo()->GetComponent(); if ( comp ) element = comp->ExportToXrc( obj.get() ); if ( element ) { std::string class_name = element->GetAttribute( "class" ); if ( class_name == "__dummyitem__" ) { delete element; element = NULL; if ( obj->GetChildCount() > 0 ) element = GetElement( obj->GetChild( 0 ) ); return element; } else if ( class_name == "spacer" ) { // Dirty hack to replace the containing sizeritem with the spacer if ( parent ) { parent->SetAttribute( "class", "spacer" ); for ( ticpp::Node* child = element->FirstChild( false ); child; child = child->NextSibling( false ) ) { parent->LinkEndChild( child->Clone().release() ); } delete element; return NULL; } } else if ( class_name == "wxFrame" ) { // Dirty hack to prevent sizer generation directly under a wxFrame // If there is a sizer, the size property of the wxFrame is ignored // when loading the xrc file at runtime if ( obj->GetPropertyAsInteger( _("xrc_skip_sizer") ) ) { for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { ticpp::Element* aux = NULL; PObjectBase child = obj->GetChild( i ); if ( child->GetObjectInfo()->IsSubclassOf( wxT("sizer") ) ) { if ( child->GetChildCount() == 1 ) { PObjectBase sizeritem = child->GetChild( 0 ); if ( sizeritem ) { aux = GetElement( sizeritem->GetChild( 0 ), element ); } } } if ( !aux ) { aux = GetElement( child, element ); } if ( aux ) { element->LinkEndChild( aux ); delete aux; } } return element; } } else if( class_name == "wxMenu" ) { // Do not generate context menus assigned to forms or widgets std::string parent_name = parent->GetAttribute( "class" ); if( (parent_name != "wxMenuBar") && (parent_name != "wxMenu") ) { // insert context menu into vector for delayed processing (context menus will be generated as top-level menus) for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { ticpp::Element *aux = GetElement( obj->GetChild( i ), element ); if ( aux ) { element->LinkEndChild( aux ); delete aux; } } m_contextMenus.push_back( element ); return NULL; } } for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { ticpp::Element *aux = GetElement( obj->GetChild( i ), element ); if ( aux ) { element->LinkEndChild( aux ); delete aux; } } } else { // The componenet does not XRC element = new ticpp::Element( "object" ); element->SetAttribute( "class", "unknown" ); element->SetAttribute( "name", _STDSTR( obj->GetPropertyAsString( _( "name" ) ) ) ); } return element; }
bool PHPCodeGenerator::GenerateCode( PObjectBase project ) { if (!project) { wxLogError(wxT("There is no project to generate code")); return false; } m_i18n = false; PProperty i18nProperty = project->GetProperty( wxT("internationalize") ); if (i18nProperty && i18nProperty->GetValueAsInteger()) m_i18n = true; m_disconnectEvents = ( project->GetPropertyAsInteger( wxT("disconnect_php_events") ) != 0 ); m_source->Clear(); // Insert php preamble wxString code = GetCode( project, wxT("php_preamble") ); if ( !code.empty() ) { m_source->WriteLn( code ); m_source->WriteLn( wxEmptyString ); } code = ( wxT("/*\n") wxT(" * PHP code generated with wxFormBuilder (version ") wxT(__DATE__) wxT(")\n") wxT(" * http://www.wxformbuilder.org/\n") wxT(" *\n") wxT(" * PLEASE DO *NOT* EDIT THIS FILE!\n") wxT(" */\n") ); m_source->WriteLn( code ); PProperty propFile = project->GetProperty( wxT("file") ); if (!propFile) { wxLogError( wxT("Missing \"file\" property on Project Object") ); return false; } wxString file = propFile->GetValue(); if ( file.empty() ) { file = wxT("noname"); } // Generate the subclass sets std::set< wxString > subclasses; std::vector< wxString > headerIncludes; GenSubclassSets( project, &subclasses, &headerIncludes ); // Generating in the .h header file those include from components dependencies. std::set< wxString > templates; GenIncludes(project, &headerIncludes, &templates ); // Write the include lines std::vector<wxString>::iterator include_it; for ( include_it = headerIncludes.begin(); include_it != headerIncludes.end(); ++include_it ) { m_source->WriteLn( *include_it ); } if ( !headerIncludes.empty() ) { m_source->WriteLn( wxT("") ); } // Write internationalization support if( m_i18n ) { //PHP gettext already implements this function //m_source->WriteLn( wxT("function _(){ /*TODO: Implement this function on wxPHP*/ }") ); //m_source->WriteLn( wxT("") ); } // Generating "defines" for macros GenDefines( project ); wxString eventHandlerPostfix; PProperty eventKindProp = project->GetProperty( wxT("skip_php_events") ); if( eventKindProp->GetValueAsInteger() ) { eventHandlerPostfix = wxT("$event->Skip();"); } else eventHandlerPostfix = wxT(""); PProperty disconnectMode = project->GetProperty( wxT("disconnect_mode") ); m_disconnecMode = disconnectMode->GetValueAsString(); for ( unsigned int i = 0; i < project->GetChildCount(); i++ ) { PObjectBase child = project->GetChild( i ); EventVector events; FindEventHandlers( child, events ); //GenClassDeclaration( child, useEnum, classDecoration, events, eventHandlerPrefix, eventHandlerPostfix ); GenClassDeclaration( child, false, wxT(""), events, eventHandlerPostfix ); } code = GetCode( project, wxT("php_epilogue") ); if( !code.empty() ) m_source->WriteLn( code ); return true; }
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 ); } } }
void PHPCodeGenerator::GenSubclassSets( PObjectBase obj, std::set< wxString >* subclasses, std::vector< wxString >* headerIncludes ) { // Call GenSubclassForwardDeclarations on all children as well for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { GenSubclassSets( obj->GetChild( i ), subclasses, headerIncludes ); } // Fill the set PProperty subclass = obj->GetProperty( wxT("subclass") ); if ( subclass ) { std::map< wxString, wxString > children; subclass->SplitParentProperty( &children ); std::map< wxString, wxString >::iterator name; name = children.find( wxT("name") ); if ( children.end() == name ) { // No name, so do nothing return; } wxString nameVal = name->second; if ( nameVal.empty() ) { // No name, so do nothing return; } // Now get the header std::map< wxString, wxString >::iterator header; header = children.find( wxT("header") ); if ( children.end() == header ) { // No header, so do nothing return; } wxString headerVal = header->second; if ( headerVal.empty() ) { // No header, so do nothing return; } // Got a header PObjectInfo info = obj->GetObjectInfo(); if ( !info ) { return; } PObjectPackage pkg = info->GetPackage(); if ( !pkg ) { return; } wxString include = wxT("include_once ") + headerVal + wxT(";"); std::vector< wxString >::iterator it = std::find( headerIncludes->begin(), headerIncludes->end(), include ); if ( headerIncludes->end() == it ) { headerIncludes->push_back( include ); } } }