Beispiel #1
0
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("");
}
Beispiel #2
0
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("}") );
	}
}
Beispiel #3
0
void CppCodeGenerator::GenConstructor(shared_ptr<ObjectBase> class_obj)
{
	m_source->WriteLn( wxT("") );
	m_source->WriteLn( GetCode( class_obj, wxT("cons_def") ) );
	m_source->WriteLn( wxT("{") );
	m_source->Indent();

	wxString settings = GetCode( class_obj, wxT("settings") );
	if ( !settings.empty() )
	{
		m_source->WriteLn( settings );
	}

	for ( unsigned int i = 0; i < class_obj->GetChildCount(); i++ )
	{
		GenConstruction( class_obj->GetChild( i ), true );
	}

	m_source->Unindent();
	m_source->WriteLn( wxT("}") );
}
Beispiel #4
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;
  }
}
Beispiel #5
0
void CppCodeGenerator::GenConstruction(shared_ptr<ObjectBase> obj, bool is_widget)
{
	wxString type = obj->GetObjectTypeName();

	if (type == wxT("notebook")			||
		type == wxT("flatnotebook")		||
		type == wxT("listbook")			||
		type == wxT("choicebook")		||
		type == wxT("widget")			||
		type == wxT("expanded_widget")	||
		type == wxT("statusbar")			||
		type == wxT("container")			||
		type == wxT("menubar")			||
		type == wxT("toolbar")			||
		type == wxT("splitter")
		)
	{
		// comprobamos si no se ha declarado como atributo de clase
		// en cuyo caso lo declaramos en el constructor

		wxString perm_str = obj->GetProperty( wxT("permission") )->GetValue();
		if ( perm_str == wxT("none") )
		{
			m_source->WriteLn( GetCode( obj, wxT("declaration") ) );
		}

		m_source->WriteLn( GetCode( obj, wxT("construction") ) );
		GenSettings( obj->GetObjectInfo(), obj );

		for ( unsigned int i = 0; i < obj->GetChildCount(); i++ )
		{
			shared_ptr< ObjectBase > child = obj->GetChild( i );
			GenConstruction( child, true );

			if ( type == wxT("toolbar") )
			{
				GenAddToolbar(child->GetObjectInfo(), child);
			}
		}

		if ( type == wxT("splitter") )
		{
			// generamos el split
			if (obj->GetChildCount() == 2)
			{
				shared_ptr<ObjectBase> 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("$name->SplitVertically(");
				}
				else
				{
					_template = wxT("$name->SplitHorizontally(");
				}

				_template = _template + sub1->GetProperty( wxT("name") )->GetValue() +
					wxT(",") + sub2->GetProperty( wxT("name") )->GetValue() + wxT(",$sashpos);");

				CppTemplateParser parser(obj,_template);
				parser.UseRelativePath(m_useRelativePath, m_basePath);
				parser.UseI18n(m_i18n);
				m_source->WriteLn(parser.ParseTemplate());
			}
			else
				wxLogError( wxT("Missing subwindows for wxSplitterWindow widget.") );
		}


		if (type == wxT("menubar") || type == wxT("toolbar") || type == wxT("listbook") ||
			type == wxT("notebook") || type == wxT("flatnotebook") )
		{
			wxString afterAddChild = GetCode( obj, wxT("after_addchild") );
			if ( !afterAddChild.empty() )
			{
				m_source->WriteLn( afterAddChild );
			}
			m_source->WriteLn( wxT("") );
		}

	}
	else if ( type == wxT("sizer") )
	{
		m_source->WriteLn( GetCode( obj, wxT("declaration") ) );
		m_source->WriteLn( GetCode( obj, wxT("construction") ) );
		GenSettings( obj->GetObjectInfo(), obj );

		for ( unsigned int i = 0; i < obj->GetChildCount(); i++ )
		{
			GenConstruction(obj->GetChild(i),false);
		}

		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 );\n")
									wxT("#wxparent $name->Layout();");


			CppTemplateParser parser(obj,_template);
			parser.UseRelativePath(m_useRelativePath, m_basePath);
			parser.UseI18n(m_i18n);
			m_source->WriteLn(parser.ParseTemplate());
		}
	}
	else if ( type == wxT("menu") || type == wxT("submenu") )
	{
		m_source->WriteLn( GetCode( obj, wxT("declaration") ) );
		m_source->WriteLn( GetCode( obj, wxT("construction") ) );

		for ( unsigned int i = 0; i < obj->GetChildCount(); i++ )
		{
			GenConstruction( obj->GetChild(i), false );
		}

		m_source->WriteLn( GetCode( obj, wxT("menu_add") ) );

	}
	else if ( type == wxT("spacer") )
	{
		// En lugar de modelar un "spacer" como un objeto que se incluye en
		// un sizer item, los vamos a considerar un como un tipo de
		// de "sizeritem" capaz de existir por sí solo. De esta forma será
		// más facil la exportación XRC.
		m_source->WriteLn( GetCode( obj, wxT("spacer_add") ) );
	}
	else if ( type == wxT("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);

		wxString child_type = obj->GetChild(0)->GetObjectTypeName();
		wxString temp_name;
		if (child_type == wxT("notebook")		||
			child_type == wxT("flatnotebook")	||
			child_type == wxT("listbook")		||
			child_type == wxT("choicebook")		||
			child_type == wxT("widget")			||
			child_type == wxT("expanded_widget")	||
			child_type == wxT("statusbar")		||
			child_type == wxT("container")		||
			child_type == wxT("splitter")
			)
		{
			temp_name = wxT("window_add");
		}
		else if ( child_type == wxT("sizer") )
		{
			temp_name = wxT("sizer_add");
		}
		else
		{
			assert( false );
		}

		m_source->WriteLn( GetCode( obj, temp_name ) );
	}
	else if (	type == wxT("notebookpage")		||
				type == wxT("flatnotebookpage")	||
				type == wxT("listbookpage")		||
				type == wxT("choicebookpage")
			)
	{
		GenConstruction( obj->GetChild( 0 ), false );
		m_source->WriteLn( GetCode( obj, wxT("page_add") ) );
		GenSettings( obj->GetObjectInfo(), obj );
	}
	else if ( type == wxT("menuitem") )
	{
		m_source->WriteLn( GetCode( obj, wxT("construction") ) );
		m_source->WriteLn( GetCode( obj, wxT("menuitem_add") ) );
		GenSettings( obj->GetObjectInfo(), obj );
	}
	else if ( type == wxT("tool") )
	{
		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 );
		}
	}
}
Beispiel #6
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 );
		}
	}
}