示例#1
0
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 );
}
示例#2
0
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 );
	}
}
示例#3
0
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);
	}
}
示例#4
0
string CppCodeGenerator::GetCode(PObjectBase obj, string name)
{
  string _template;
  PCodeInfo code_info = obj->GetObjectInfo()->GetCodeInfo("C++");
  _template = code_info->GetTemplate(name);
  
  CppTemplateParser parser(obj,_template);
  string code = parser.ParseTemplate();

  return code;
}
示例#5
0
bool ObjectBase::AddChild (PObjectBase obj)
{
	bool result = false;
	if (ChildTypeOk(obj->GetObjectInfo()->GetObjectType()))
		//if (ChildTypeOk(obj->GetObjectTypeName()))
	{
		m_children.push_back(obj);
		result = true;
	}

	return result;
}
示例#6
0
bool ObjectBase::AddChild (unsigned int idx, PObjectBase obj)
{
	bool result = false;
	if (ChildTypeOk(obj->GetObjectInfo()->GetObjectType()) && idx <= m_children.size())
		//if (ChildTypeOk(obj->GetObjectTypeName()) && idx <= m_children.size())
	{
		m_children.insert(m_children.begin() + idx,obj);
		result = true;
	}

	return result;
}
示例#7
0
void DesignerWindow::DrawRectangle( wxDC& dc, const wxPoint& point, const wxSize& size, PObjectBase object )
{
    bool isSizer = ( object->GetObjectInfo()->IsSubclassOf( wxT("sizer") ) || object->GetObjectInfo()->IsSubclassOf( wxT("gbsizer") ) );
    int min = ( isSizer ? 0 : 1 );

    int border = object->GetParent()->GetPropertyAsInteger( wxT("border") );
    if ( border == 0 )
    {
        border = min;
    }

    int flag = object->GetParent()->GetPropertyAsInteger( wxT("flag") );
    int topBorder = 	( flag & wxTOP ) 	== 0 ? min : border;
    int bottomBorder = 	( flag & wxBOTTOM ) == 0 ? min : border;
    int rightBorder = 	( flag & wxRIGHT ) 	== 0 ? min : border;
    int leftBorder = 	( flag & wxLEFT ) 	== 0 ? min : border;

    dc.DrawRectangle( 	point.x - leftBorder,
                        point.y - topBorder,
                        size.x + leftBorder + rightBorder,
                        size.y + topBorder + bottomBorder );
}
示例#8
0
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);
		}
	}
}
示例#9
0
PObjectBase ObjectBase::FindNearAncestorByBaseClass(wxString type)
{
	PObjectBase result;
	PObjectBase parent = GetParent();
	if (parent)
	{
		if ( parent->GetObjectInfo()->IsSubclassOf( type ) )
			result = parent;
		else
			result = parent->FindNearAncestorByBaseClass( type );
	}

	return result;
}
示例#10
0
void VisualEditor::ClearComponents( wxWindow* parent )
{
    wxLogNull stopTheLogging;
    const wxWindowList& children = parent->GetChildren();
    for ( wxWindowList::const_reverse_iterator child = children.rbegin(); child != children.rend(); ++child )
    {
        ClearComponents( *child );

        PObjectBase obj = GetObjectBase( *child );
        if ( obj )
        {
            PObjectInfo obj_info = obj->GetObjectInfo();
            IComponent* comp = obj_info->GetComponent();
            if ( comp )
            {
                comp->Cleanup( *child );
            }
        }
    }
}
示例#11
0
wxString PHPCodeGenerator::GetCode(PObjectBase obj, wxString name, bool silent)
{
	wxString _template;
	PCodeInfo code_info = obj->GetObjectInfo()->GetCodeInfo( wxT("PHP") );

	if (!code_info)
	{
		if( !silent )
		{
			wxString msg( wxString::Format( wxT("Missing \"%s\" template for \"%s\" class. Review your XML object description"),
				name.c_str(), obj->GetClassName().c_str() ) );
			wxLogError(msg);
		}
		return wxT("");
	}

	_template = code_info->GetTemplate(name);

	PHPTemplateParser parser( obj, _template, m_i18n, m_useRelativePath, m_basePath );
	wxString code = parser.ParseTemplate();

	return code;
}
示例#12
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;
  }
}
示例#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() );
			}
		}
	}
}
示例#14
0
void VisualEditor::OnObjectSelected( wxFBObjectEvent &event )
{
	// It is only necessary to Create() if the selected object is on a different form
	if ( AppData()->GetSelectedForm() != m_form )
	{
		Create();
	}

	// Get the ObjectBase from the event
	PObjectBase obj = event.GetFBObject();
	if ( !obj )
	{
		// Strange...
		Debug::Print( wxT("The event object is NULL - why?") );
		return;
	}

	// Make sure this is a visible object
	ObjectBaseMap::iterator it = m_baseobjects.find( obj.get() );
	if ( m_baseobjects.end() == it )
	{
		m_back->SetSelectedSizer( NULL );
		m_back->SetSelectedItem( NULL );
		m_back->SetSelectedObject( PObjectBase() );
		m_back->SetSelectedPanel( NULL );
		m_back->Refresh();
		return;
	}

	// Save wxobject
	wxObject* item = it->second;

	int componentType = COMPONENT_TYPE_ABSTRACT;
	IComponent *comp = obj->GetObjectInfo()->GetComponent();
	if ( comp )
	{
		componentType = comp->GetComponentType();

		// Fire selection event in plugin
		if ( !m_stopSelectedEvent )
		{
			comp->OnSelected( item );
		}
	}

	if ( componentType != COMPONENT_TYPE_WINDOW && componentType != COMPONENT_TYPE_SIZER )
	{
		item = NULL;
	}

	// Fire selection event in plugin for all parents
	if ( !m_stopSelectedEvent )
	{
		PObjectBase parent = obj->GetParent();
		while ( parent )
		{
			IComponent* parentComp = parent->GetObjectInfo()->GetComponent();
			if ( parentComp )
			{
				ObjectBaseMap::iterator parentIt = m_baseobjects.find( parent.get() );
				if ( parentIt != m_baseobjects.end() )
				{
					parentComp->OnSelected( parentIt->second );
				}
			}
			parent = parent->GetParent();
		}
	}

	// Look for the active panel - this is where the boxes will be drawn during OnPaint
	// This is the closest parent of type COMPONENT_TYPE_WINDOW
	PObjectBase nextParent = obj->GetParent();
	while ( nextParent )
	{
		IComponent* parentComp = nextParent->GetObjectInfo()->GetComponent();
		if ( !parentComp )
		{
			nextParent.reset();
			break;
		}

		if ( parentComp->GetComponentType() == COMPONENT_TYPE_WINDOW )
		{
			break;
		}

		nextParent = nextParent->GetParent();
	}

	// Get the panel to draw on
	wxWindow* selPanel = NULL;
	if ( nextParent )
	{
		it = m_baseobjects.find( nextParent.get() );
		if ( m_baseobjects.end() == it )
		{
			selPanel = m_back->GetFrameContentPanel();
		}
		else
		{
			selPanel = wxDynamicCast( it->second, wxWindow );
		}
	}
	else
	{
		selPanel = m_back->GetFrameContentPanel();
	}

	// Find the first COMPONENT_TYPE_WINDOW or COMPONENT_TYPE_SIZER
	// If it is a sizer, save it
	wxSizer* sizer = NULL;
	PObjectBase nextObj = obj->GetParent();
	while ( nextObj )
	{
		IComponent* nextComp = nextObj->GetObjectInfo()->GetComponent();
		if ( !nextComp )
		{
			break;
		}

		if ( nextComp->GetComponentType() == COMPONENT_TYPE_SIZER )
		{
			it = m_baseobjects.find( nextObj.get() );
			if ( it != m_baseobjects.end() )
			{
				sizer = wxDynamicCast( it->second, wxSizer );
			}
			break;
		}
		else if ( nextComp->GetComponentType() == COMPONENT_TYPE_WINDOW )
		{
			break;
		}

		nextObj = nextObj->GetParent();
	}

  m_back->SetSelectedSizer( sizer );
	m_back->SetSelectedItem( item );
	m_back->SetSelectedObject( obj );
	m_back->SetSelectedPanel( selPanel );
	m_back->Refresh();
}
示例#15
0
/**
* 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();
	}
}
示例#16
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 );
    }
}
示例#17
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 );
		}
	}
}
示例#18
0
文件: xrccg.cpp 项目: noriter/wxfb
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;
}
示例#19
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 );
                }
            }
        }
    }

}
示例#20
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 );
		}
	}
}