Exemplo n.º 1
0
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 );
	}
}
Exemplo n.º 2
0
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 );
    }
}
Exemplo n.º 3
0
void TemplateParser::ParseLuaTable()
{
	PObjectBase project = PObjectBase(new ObjectBase(*AppData()->GetProjectData()));
	PProperty propNs= project->GetProperty( wxT( "ui_table" ) );
	if ( propNs )
	{
		wxString strTableName = propNs->GetValueAsString();
		if(strTableName.length() <= 0)
			strTableName = wxT("UI");
		m_out <<strTableName + wxT(".");
	}
}
Exemplo n.º 4
0
void CppCodeGenerator::FindMacros(PObjectBase obj, set<string> &macro_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);
  }
}
Exemplo n.º 5
0
void CppCodeGenerator::GenClassDeclaration(PObjectBase class_obj)
{
  string class_name = class_obj->GetProperty("name")->GetValue();

  m_header->WriteLn("/**");
  m_header->WriteLn(" * Class " + class_name);
  m_header->WriteLn(" */");

  m_header->WriteLn("class " + class_name + " : " + GetCode(class_obj,"base"));
  m_header->WriteLn("{");
  m_header->Indent();
  
  // private
  m_header->WriteLn("private:");
  m_header->Indent();  
  GenAttributeDeclaration(class_obj,P_PRIVATE);
  m_header->Unindent();
  m_header->WriteLn("");
  
  // protected
  m_header->WriteLn("protected:");
  m_header->Indent();  
  GenAttributeDeclaration(class_obj,P_PROTECTED);
  m_header->Unindent();
  m_header->WriteLn("");  
  
  // public
  m_header->WriteLn("public:");
  m_header->Indent();  
  GenAttributeDeclaration(class_obj,P_PUBLIC);
  m_header->WriteLn("");
    
  // dentro de public también incluimos el constructor
  m_header->WriteLn(GetCode(class_obj,"cons_decl"));  
  m_header->Unindent();
  m_header->WriteLn("");

    
  m_header->Unindent();
  m_header->WriteLn("};");
  m_header->WriteLn("");
}
Exemplo n.º 6
0
void VisualEditor::OnResizeBackPanel (wxCommandEvent &) //(wxSashEvent &event)
{
	/*wxRect rect(event.GetDragRect());
	Debug::Print("VisualEditor::OnResizeBackPanel [%d,%d,%d,%d]",rect.x,rect.y,rect.width, rect.height);
	m_back->SetSize(rect.width,rect.height);
	m_back->Layout();*/

	PObjectBase form (AppData()->GetSelectedForm());

	if (form)
	{
		PProperty prop(form->GetProperty( wxT("size") ));
		if (prop)
		{
			wxString value(TypeConv::PointToString(wxPoint(m_back->GetSize().x, m_back->GetSize().y)));
			AppData()->ModifyProperty(prop, value);
		}
	}

	//event.Skip();
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
void PHPCodeGenerator::GenClassDeclaration(PObjectBase class_obj, bool use_enum, const wxString& classDecoration, const EventVector &events, const wxString& eventHandlerPostfix)
{
	PProperty propName = class_obj->GetProperty( wxT("name") );
	if ( !propName )
	{
		wxLogError(wxT("Missing \"name\" property on \"%s\" class. Review your XML object description"),
			class_obj->GetClassName().c_str());
		return;
	}

	wxString class_name = propName->GetValue();
	if ( class_name.empty() )
	{
		wxLogError( wxT("Object name can not be null") );
		return;
	}

	m_source->WriteLn( wxT("/*") );
	m_source->WriteLn( wxT(" * Class ") + class_name);
	m_source->WriteLn( wxT(" */") );
	m_source->WriteLn( );

	m_source->WriteLn( wxT("class ") + classDecoration + class_name + wxT(" extends ") + GetCode( class_obj, wxT("base") ).Trim() + wxT(" {") );
	m_source->Indent();

	// The constructor is also included within public
	GenConstructor( class_obj, events );
	GenDestructor( class_obj, events );

	m_source->WriteLn( wxT("") );

	// event handlers
	GenVirtualEventHandlers(events, eventHandlerPostfix);
	GetGenEventHandlers( class_obj );

	m_source->Unindent();
	m_source->WriteLn( wxT("}") );
	m_source->WriteLn( wxT("") );
}
Exemplo n.º 9
0
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);
  }
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
int MyApp::OnRun()
{
    // Using a space so the initial 'w' will not be capitalized in wxLogGUI dialogs
    wxApp::SetAppName( wxT( " wxFormBuilder" ) );

    // Creating the wxConfig manually so there will be no space
    // The old config (if any) is returned, delete it
    delete wxConfigBase::Set( new wxConfig( wxT("wxFormBuilder") ) );

    // Get the data directory
    wxStandardPathsBase& stdPaths = wxStandardPaths::Get();
    wxString dataDir = stdPaths.GetDataDir();
    dataDir.Replace( GetAppName().c_str(), wxT("wxformbuilder") );

    // Log to stderr while working on the command line
    delete wxLog::SetActiveTarget( new wxLogStderr );

    // Message output to the same as the log target
    delete wxMessageOutput::Set( new wxMessageOutputLog );

    // Parse command line
    wxCmdLineParser parser( s_cmdLineDesc, argc, argv );
    if ( 0 != parser.Parse() )
    {
        return 1;
    }

    // Get project to load
    wxString projectToLoad = wxEmptyString;
    if ( parser.GetParamCount() > 0 )
    {
        projectToLoad = parser.GetParam();
    }

    bool justGenerate = false;
    wxString language;
    bool hasLanguage = parser.Found( wxT("l"), &language );
    if ( parser.Found( wxT("g") ) )
    {
        if ( projectToLoad.empty() )
        {
            wxLogError( _("You must pass a path to a project file. Nothing to generate.") );
            return 2;
        }

        if ( hasLanguage )
        {
            if ( language.empty() )
            {
                wxLogError( _("Empty language option. Nothing generated.") );
                return 3;
            }
            language.Replace( wxT(","), wxT("|"), true );
        }

        // generate code
        justGenerate = true;
    }
    else
    {
        delete wxLog::SetActiveTarget( new wxLogGui );
    }

    // Create singleton AppData - wait to initialize until sure that this is not the second
    // instance of a project file.
    AppDataCreate( dataDir );

    // Make passed project name absolute
    try
    {
        if ( !projectToLoad.empty() )
        {
            wxFileName projectPath( projectToLoad );
            if ( !projectPath.IsOk() )
            {
                THROW_WXFBEX( wxT("This path is invalid: ") << projectToLoad );
            }

            if ( !projectPath.IsAbsolute() )
            {
                if ( !projectPath.MakeAbsolute() )
                {
                    THROW_WXFBEX( wxT("Could not make path absolute: ") << projectToLoad );
                }
            }
            projectToLoad = projectPath.GetFullPath();
        }
    }
    catch ( wxFBException& ex )
    {
        wxLogError( ex.what() );
    }

    // If the project is already loaded in another instance, switch to that instance and quit
    if ( !projectToLoad.empty() && !justGenerate )
    {
        if ( ::wxFileExists( projectToLoad ) )
        {
            if ( !AppData()->VerifySingleInstance( projectToLoad ) )
            {
                return 4;
            }
        }
    }

    // Init handlers
    wxInitAllImageHandlers();
    wxXmlResource::Get()->InitAllHandlers();
#if wxVERSION_NUMBER >= 2905
    wxXmlResource::Get()->AddHandler(new wxAuiNotebookXmlHandler);
#endif

    // Init AppData
    try
    {
        AppDataInit();
    }
    catch( wxFBException& ex )
    {
        wxLogError( _("Error loading application: %s\nwxFormBuilder cannot continue."),	ex.what() );
        wxLog::FlushActive();
        return 5;
    }

    wxSystemOptions::SetOption( wxT( "msw.remap" ), 0 );
    wxSystemOptions::SetOption( wxT( "msw.staticbox.optimized-paint" ), 0 );

    m_frame = NULL;

#ifndef __WXFB_DEBUG__
    wxBitmap bitmap;
    std::unique_ptr< cbSplashScreen > splash;
    if ( !justGenerate )
    {
        if ( bitmap.LoadFile( dataDir + wxFILE_SEP_PATH + wxT( "resources" ) + wxFILE_SEP_PATH + wxT( "splash.png" ), wxBITMAP_TYPE_PNG ) )
        {
            splash = std::unique_ptr< cbSplashScreen >( new cbSplashScreen( bitmap, -1, 0, wxNewId() ) );
        }
    }
#endif

    wxYield();

    // Read size and position from config file
    wxConfigBase *config = wxConfigBase::Get();
    config->SetPath( wxT("/mainframe") );
    int x, y, w, h;
    x = y = w = h = -1;
    config->Read( wxT( "PosX" ), &x );
    config->Read( wxT( "PosY" ), &y );
    config->Read( wxT( "SizeW" ), &w );
    config->Read( wxT( "SizeH" ), &h );

    long style = config->Read( wxT("style"), wxFB_WIDE_GUI );
    if ( style != wxFB_CLASSIC_GUI )
    {
        style = wxFB_WIDE_GUI;
    }

    config->SetPath( wxT("/") );

    m_frame = new MainFrame( NULL ,-1, (int)style, wxPoint( x, y ), wxSize( w, h ) );
    if ( !justGenerate )
    {
        m_frame->Show( TRUE );
        SetTopWindow( m_frame );

#ifndef __WXFB_DEBUG__
        // turn off the splash screen
        delete splash.release();
#endif

#ifdef __WXFB_DEBUG__
        wxLogWindow* log = dynamic_cast< wxLogWindow* >( AppData()->GetDebugLogTarget() );
        if ( log )
        {
            m_frame->AddChild( log->GetFrame() );
        }
#endif //__WXFB_DEBUG__
    }

    // This is not necessary for wxFB to work. However, Windows sets the Current Working Directory
    // to the directory from which a .fbp file was opened, if opened from Windows Explorer.
    // This puts an unneccessary lock on the directory.
    // This changes the CWD to the already locked app directory as a workaround
#ifdef __WXMSW__
    ::wxSetWorkingDirectory( dataDir );
#endif

    if ( !projectToLoad.empty() )
    {
        if ( AppData()->LoadProject( projectToLoad, justGenerate ) )
        {
            if ( justGenerate )
            {
                if ( hasLanguage )
                {
                    PObjectBase project = AppData()->GetProjectData();
                    PProperty codeGen = project->GetProperty( _("code_generation") );
                    if ( codeGen )
                    {
                        codeGen->SetValue( language );
                    }
                }
                AppData()->GenerateCode( false, true );
                return 0;
            }
            else
            {
                m_frame->InsertRecentProject( projectToLoad );
                return wxApp::OnRun();
            }
        }
        else
        {
            wxLogError( wxT("Unable to load project: %s"), projectToLoad.c_str() );
        }
    }

    if ( justGenerate )
    {
        return 6;
    }

    AppData()->NewProject();

#ifdef __WXMAC__
    // document to open on startup
    if(!m_mac_file_name.IsEmpty())
    {
        if ( AppData()->LoadProject( m_mac_file_name ) )
            m_frame->InsertRecentProject( m_mac_file_name );
    }
#endif

    return wxApp::OnRun();
}
Exemplo n.º 12
0
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 );
		}
	}
}
Exemplo n.º 13
0
void PHPCodeGenerator::GenEvents( PObjectBase class_obj, const EventVector &events, bool disconnect )
{
	if ( events.empty() )
	{
		return;
	}

	if( disconnect )
	{
		m_source->WriteLn( wxT("// Disconnect Events") );
	}
	else
	{
		m_source->WriteLn();
		m_source->WriteLn( wxT("// Connect Events") );
	}

	PProperty propName = class_obj->GetProperty( wxT("name") );
	if ( !propName )
	{
		wxLogError(wxT("Missing \"name\" property on \"%s\" class. Review your XML object description"),
			class_obj->GetClassName().c_str());
		return;
	}

	wxString class_name = propName->GetValue();
	if ( class_name.empty() )
	{
		wxLogError( wxT("Object name cannot be null") );
		return;
	}

	wxString base_class;
	wxString handlerName;

	PProperty propSubclass = class_obj->GetProperty( wxT("subclass") );
	if ( propSubclass )
	{
		wxString subclass = propSubclass->GetChildFromParent( wxT("name") );
		if ( !subclass.empty() )
		{
			base_class = subclass;
		}
	}

	if ( base_class.empty() )
		base_class = wxT("wx") + class_obj->GetClassName();

	if ( events.size() > 0 )
	{
		for ( size_t i = 0; i < events.size(); i++ )
		{
			PEvent event = events[i];

			handlerName = event->GetValue();

			wxString templateName = wxString::Format( wxT("connect_%s"), event->GetName().c_str() );

			PObjectBase obj = event->GetObject();
			if ( !GenEventEntry( obj, obj->GetObjectInfo(), templateName, handlerName, disconnect ) )
			{
				wxLogError( wxT("Missing \"evt_%s\" template for \"%s\" class. Review your XML object description"),
					templateName.c_str(), class_name.c_str() );
			}
		}
	}
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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() );
	}
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
PProperty TemplateParser::GetRelatedProperty( PObjectBase relative )
{
	ignore_whitespaces();
	wxString propname = ParsePropertyName();
	return relative->GetProperty( propname );
}
Exemplo n.º 18
0
void VisualEditor::ScanPanes( wxWindow* parent)
{
    bool updateNeeded;

    wxLogNull stopTheLogging;
    const wxWindowList& children = parent->GetChildren();
    for ( wxWindowList::const_reverse_iterator child = children.rbegin(); child != children.rend(); ++child )
    {
        ScanPanes(*child);

        PObjectBase obj = GetObjectBase( *child );

        if ( obj )
        {
            updateNeeded = false;

            PObjectInfo obj_info = obj->GetObjectInfo();
            wxString cname = obj_info->GetObjectType()->GetName();

            if( cname == wxT("widget") ||
                    cname == wxT("expanded_widget") ||
                    cname == wxT("toolbar") ||
                    cname == wxT("container") )
            {
                wxAuiPaneInfo inf = m_auimgr->GetPane(*child);
                if(inf.IsOk())
                {
                    // scan position and docking mode
                    if( !obj->GetPropertyAsInteger( wxT("center_pane") ) )
                    {
                        wxString dock;
                        if( inf.IsDocked())
                        {
                            wxString dockDir;
                            switch(inf.dock_direction)
                            {
                            case 1:
                                dockDir = wxT("Top");
                                break;

                            case 2:
                                dockDir = wxT("Right");
                                break;

                            case 3:
                                dockDir = wxT("Bottom");
                                break;

                            case 4:
                                dockDir = wxT("Left");
                                break;

                            case 5:
                                dockDir = wxT("Center");
                                break;

                            default:
                                dockDir = wxT("Left");
                                break;
                            }
                            PProperty pdock = obj->GetProperty( wxT("docking") );

                            if( pdock->GetValue() != dockDir )
                            {
                                pdock->SetValue( dockDir );
                                updateNeeded = true;
                            }

                            dock = wxT("Dock");
                        }
                        else
                        {
                            // scan "floating position"
                            wxPoint pos = inf.floating_pos;
                            if ( pos.x != -1 && pos.y != -1 )
                            {
                                PProperty pposition = obj->GetProperty( wxT("pane_position") );
                                if( pposition->GetValue() != TypeConv::PointToString( pos ) )
                                {
                                    pposition->SetValue( TypeConv::PointToString( pos ) );
                                    updateNeeded = true;
                                }
                            }

                            // scan "floating size"
                            wxSize paneSize = inf.floating_size;
                            if ( paneSize.x != -1 && paneSize.y != -1 )
                            {
                                PProperty psize = obj->GetProperty( wxT("pane_size") );

                                if( psize->GetValue() != TypeConv::SizeToString( paneSize ) )
                                {
                                    psize->SetValue( TypeConv::SizeToString( paneSize )  );
                                    obj->GetProperty( wxT("resize") )->SetValue( wxT("Resizable") );

                                    updateNeeded = true;
                                }
                            }

                            dock = wxT("Float");
                        }
                        PProperty pfloat = obj->GetProperty(wxT("dock") );
                        if( pfloat->GetValue() != dock )
                        {
                            pfloat->SetValue( dock );
                            updateNeeded = true;
                        }

                        // scan "best size"
                        /*wxSize bestSize = inf.best_size;
                        if ( bestSize.x != -1 && bestSize.y != -1 )
                        {
                        	PProperty psize = obj->GetProperty( wxT("best_size") );

                        	if( psize->GetValue() != TypeConv::SizeToString( bestSize ) )
                        	{
                        		psize->SetValue( TypeConv::SizeToString( bestSize )  );
                        		obj->GetProperty( wxT("resize") )->SetValue( wxT("Resizable") );

                        		updateNeeded = true;
                        	}
                        }*/

                        // scan "row" and "layer"
                        PProperty prop = obj->GetProperty(wxT("aui_row") );
                        if( obj->GetPropertyAsInteger( wxT("aui_row") ) != inf.dock_row )
                        {
                            prop->SetValue( inf.dock_row );
                            updateNeeded = true;
                        }
                        prop = obj->GetProperty(wxT("aui_layer") );
                        if( obj->GetPropertyAsInteger( wxT("aui_layer") ) != inf.dock_layer )
                        {
                            prop->SetValue( inf.dock_layer );
                            updateNeeded = true;
                        }
                    }

                    // scan "show" property
                    PProperty pshow = obj->GetProperty(wxT("show") );
                    if( obj->GetPropertyAsInteger( wxT("show") ) != (int) inf.IsShown() )
                    {
                        pshow->SetValue( inf.IsShown() );
                        updateNeeded = true;
                    }

                    if( updateNeeded ) AppData()->SelectObject( obj, true, true );
                }
            }
        }
    }

}
Exemplo n.º 19
0
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 );
    }
}
Exemplo n.º 20
0
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;
  }
}
Exemplo n.º 21
0
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 );
}
Exemplo n.º 22
0
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;
}
Exemplo n.º 23
0
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 );
		}
	}
}