Ejemplo n.º 1
0
void MenuEditor::AddChild(long& n, int ident, PObjectBase obj)
{
    for (unsigned int i = 0; i < obj->GetChildCount(); i++)
    {
        PObjectBase childObj = obj->GetChild(i);
        if (childObj->GetClassName() == wxT("wxMenuItem") )
        {
            InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + childObj->GetPropertyAsString(wxT("label")),
                childObj->GetPropertyAsString(wxT("shortcut")),
                childObj->GetPropertyAsString(wxT("id")),
                childObj->GetPropertyAsString(wxT("name")),
                childObj->GetPropertyAsString(wxT("help")),
                childObj->GetPropertyAsString(wxT("kind")),
                childObj);
        }
        else if (childObj->GetClassName() == wxT("separator") )
        {
            InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + wxT("---"), wxT(""), wxT(""), wxT(""), wxT(""), wxT(""), childObj);
        }
        else
        {
            InsertItem(n++, wxString(wxChar(' '), ident * IDENTATION) + childObj->GetPropertyAsString(wxT("label")),
                wxT(""),
                childObj->GetPropertyAsString(wxT("id")),
                childObj->GetPropertyAsString(wxT("name")),
                childObj->GetPropertyAsString(wxT("help")),
                wxT(""),
                childObj);
            AddChild(n, ident + 1, childObj);
        }
    }
}
Ejemplo n.º 2
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("") );
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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();
	}
}
Ejemplo n.º 7
0
/**
* Crea la vista preliminar borrando la previa.
*/
void VisualEditor::Create()
{
	if ( IsShown() )
	{
		Freeze(); // Prevent flickering
	}

	// Delete objects which had no parent
	DeleteAbstractObjects();

	// Clear selections, delete objects
	m_back->SetSelectedItem(NULL);
	m_back->SetSelectedSizer(NULL);
	m_back->SetSelectedObject(PObjectBase());
	ClearComponents( m_back->GetFrameContentPanel() );
	m_back->GetFrameContentPanel()->DestroyChildren();
	m_back->GetFrameContentPanel()->SetSizer( NULL ); // *!*

	// Clear all associations between ObjectBase and wxObjects
	m_wxobjects.clear();
	m_baseobjects.clear();

	m_form = AppData()->GetSelectedForm();
	if ( m_form )
	{
		m_back->Show(true);

		// --- [1] Configure the size of the form ---------------------------

		// Get size properties
		wxSize minSize( m_form->GetPropertyAsSize( wxT("minimum_size") ) );
		m_back->SetMinSize( minSize );

		wxSize maxSize( m_form->GetPropertyAsSize( wxT("maximum_size") ) );
		m_back->SetMaxSize( maxSize );

		wxSize size( m_form->GetPropertyAsSize( wxT("size") ) );

		// Determine necessary size for back panel
		wxSize backSize = size;
		if ( backSize.GetWidth() < minSize.GetWidth() && backSize.GetWidth() != wxDefaultCoord )
		{
			backSize.SetWidth( minSize.GetWidth() );
		}
		if ( backSize.GetHeight() < minSize.GetHeight() && backSize.GetHeight() != wxDefaultCoord )
		{
			backSize.SetHeight( minSize.GetHeight() );
		}
		if ( backSize.GetWidth() > maxSize.GetWidth() && maxSize.GetWidth() != wxDefaultCoord )
		{
			backSize.SetWidth( maxSize.GetWidth() );
		}
		if ( backSize.GetHeight() > maxSize.GetHeight() && maxSize.GetHeight() != wxDefaultCoord )
		{
			backSize.SetHeight( maxSize.GetHeight() );
		}

		// Modify size property to match
		if ( size != backSize )
		{
			PProperty psize = m_form->GetProperty( wxT("size") );
			if ( psize )
			{
				AppData()->ModifyProperty( psize, TypeConv::SizeToString( backSize ) );
			}
		}

		// --- [2] Set the color of the form -------------------------------
		PProperty background( m_form->GetProperty( wxT("bg") ) );
		if ( background && !background->GetValue().empty() )
		{
			m_back->GetFrameContentPanel()->SetBackgroundColour( TypeConv::StringToColour( background->GetValue() ) );
		}
		else
		{
			if ( m_form->GetClassName() == wxT("Frame") )
			{
				m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE ) );
			}
			else
			{
				m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
			}
		}


		// --- [3] Title bar Setup
		if (  m_form->GetClassName() == wxT("Frame") || m_form->GetClassName() == wxT("Dialog") )
		{
			m_back->SetTitle( m_form->GetPropertyAsString( wxT("title") ) );
			long style = m_form->GetPropertyAsInteger( wxT("style") );
			m_back->SetTitleStyle( style );
			m_back->ShowTitleBar( (style & wxCAPTION) != 0 );
		}
		else
		  m_back->ShowTitleBar(false);

		// --- [4] Create the components of the form -------------------------

		// Used to save frame objects for later display
		PObjectBase menubar;
		wxWindow* statusbar = NULL;
		wxWindow* toolbar = NULL;

		for ( unsigned int i = 0; i < m_form->GetChildCount(); i++ )
		{
			PObjectBase child = m_form->GetChild( i );

			if (child->GetObjectTypeName() == wxT("menubar") )
			{
				// Create the menubar later
				menubar = child;
			}
			else
			{
				// Recursively generate the ObjectTree
				try
				{
				  // we have to put the content frame panel as parentObject in order
				  // to SetSizeHints be called.
					Generate( child, m_back->GetFrameContentPanel(), m_back->GetFrameContentPanel() );
				}
				catch ( wxFBException& ex )
				{
					wxLogError ( ex.what() );
				}
			}

			// Attach the status bar (if any) to the frame
			if ( child->GetClassName() == wxT("wxStatusBar") )
			{
				ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
				statusbar = wxDynamicCast( it->second, wxStatusBar );
			}

			// Attach the toolbar (if any) to the frame
			if (child->GetClassName() == wxT("wxToolBar") )
			{
				ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
				toolbar = wxDynamicCast( it->second, wxToolBar );
			}
		}

		if ( menubar || statusbar || toolbar )
		{
			m_back->SetFrameWidgets( menubar, toolbar, statusbar );
		}

		m_back->Layout();

		if ( backSize.GetHeight() == wxDefaultCoord || backSize.GetWidth() == wxDefaultCoord )
		{
		    m_back->GetSizer()->Fit( m_back );
			m_back->SetSize( m_back->GetBestSize() );
		}

		// Set size after fitting so if only one dimesion is -1, it still fits that dimension
		m_back->SetSize( backSize );

		PProperty enabled( m_form->GetProperty( wxT("enabled") ) );
		if ( enabled )
		{
			m_back->Enable( TypeConv::StringToInt( enabled->GetValue() ) != 0 );
		}

		PProperty hidden( m_form->GetProperty( wxT("hidden") ) );
		if ( hidden )
		{
			m_back->Show( TypeConv::StringToInt( hidden->GetValue() ) == 0 );
		}
	}
	else
	{
		// There is no form to display
		m_back->Show(false);
	}

	if ( IsShown() )
	{
		Thaw();
	}

	UpdateVirtualSize();
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
void MenuEditor::Populate(PObjectBase obj)
{
    assert(obj && obj->GetClassName() == wxT("wxMenuBar") );
    long n = 0;
    AddChild(n, 0, obj);
}
Ejemplo n.º 10
0
/**
* Crea la vista preliminar borrando la previa.
*/
void VisualEditor::Create()
{
#if wxVERSION_NUMBER < 2900 && !defined(__WXGTK__ )
    if ( IsShown() )
    {
        Freeze();   // Prevent flickering on wx 2.8,
        // Causes problems on wx 2.9 in wxGTK (e.g. wxNoteBook objects)
    }
#endif
    // Delete objects which had no parent
    DeleteAbstractObjects();

    // Clear selections, delete objects
    m_back->SetSelectedItem(NULL);
    m_back->SetSelectedSizer(NULL);
    m_back->SetSelectedObject(PObjectBase());

    ClearAui();
    ClearWizard();
    ClearComponents( m_back->GetFrameContentPanel() );

    m_back->GetFrameContentPanel()->DestroyChildren();
    m_back->GetFrameContentPanel()->SetSizer( NULL ); // *!*

    // Clear all associations between ObjectBase and wxObjects
    m_wxobjects.clear();
    m_baseobjects.clear();

    if( IsShown() )
    {
        m_form = AppData()->GetSelectedForm();
        if ( m_form )
        {
            m_back->Show(true);

            // --- [1] Configure the size of the form ---------------------------

            // Get size properties
            wxSize minSize( m_form->GetPropertyAsSize( wxT("minimum_size") ) );
            m_back->SetMinSize( minSize );

            wxSize maxSize( m_form->GetPropertyAsSize( wxT("maximum_size") ) );
            m_back->SetMaxSize( maxSize );

            wxSize size( m_form->GetPropertyAsSize( wxT("size") ) );

            // Determine necessary size for back panel
            wxSize backSize = size;
            if ( backSize.GetWidth() < minSize.GetWidth() && backSize.GetWidth() != wxDefaultCoord )
            {
                backSize.SetWidth( minSize.GetWidth() );
            }
            if ( backSize.GetHeight() < minSize.GetHeight() && backSize.GetHeight() != wxDefaultCoord )
            {
                backSize.SetHeight( minSize.GetHeight() );
            }
            if ( backSize.GetWidth() > maxSize.GetWidth() && maxSize.GetWidth() != wxDefaultCoord )
            {
                backSize.SetWidth( maxSize.GetWidth() );
            }
            if ( backSize.GetHeight() > maxSize.GetHeight() && maxSize.GetHeight() != wxDefaultCoord )
            {
                backSize.SetHeight( maxSize.GetHeight() );
            }

            // Modify size property to match
            if ( size != backSize )
            {
                PProperty psize = m_form->GetProperty( wxT("size") );
                if ( psize )
                {
                    AppData()->ModifyProperty( psize, TypeConv::SizeToString( backSize ) );
                }
            }

            // --- [2] Set the color of the form -------------------------------
            PProperty background( m_form->GetProperty( wxT("bg") ) );
            if ( background && !background->GetValue().empty() )
            {
                m_back->GetFrameContentPanel()->SetBackgroundColour( TypeConv::StringToColour( background->GetValue() ) );
            }
            else
            {
                if ( m_form->GetClassName() == wxT("Frame") )
                {
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE ) );
                }
                else
                {
#ifdef __WXGTK__
                    wxVisualAttributes attribs = wxToolBar::GetClassDefaultAttributes();
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( attribs.colBg );
#else
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
#endif
                }
            }

            // --- [3] Title bar Setup
            if (  m_form->GetClassName() == wxT("Frame")  ||
                    m_form->GetClassName() == wxT("Dialog") ||
                    m_form->GetClassName() == wxT("Wizard") )
            {
                m_back->SetTitle( m_form->GetPropertyAsString( wxT("title") ) );
                long style = m_form->GetPropertyAsInteger( wxT("style") );
                m_back->SetTitleStyle( style );
                m_back->ShowTitleBar( (style & wxCAPTION) != 0 );
            }
            else
                m_back->ShowTitleBar(false);

            // --- AUI
            if(  m_form->GetObjectTypeName() == wxT("form") )
            {
                if(  m_form->GetPropertyAsInteger( wxT("aui_managed") ) == 1)
                {
                    m_auipanel = new wxPanel( m_back->GetFrameContentPanel() );
                    m_auimgr = new wxAuiManager( m_auipanel, m_form->GetPropertyAsInteger( wxT("aui_manager_style") ) );
                }
            }

            // --- Wizard
            if ( m_form->GetClassName() == wxT("Wizard") )
            {
                m_wizard = new Wizard( m_back->GetFrameContentPanel() );

                bool showbutton = false;
                PProperty pextra_style = m_form->GetProperty( wxT("extra_style") );
                if ( pextra_style )
                {
                    showbutton = pextra_style->GetValue().Contains( wxT("wxWIZARD_EX_HELPBUTTON") );
                }

                m_wizard->ShowHelpButton( showbutton );

                if ( !m_form->GetProperty( wxT("bitmap") )->IsNull() )
                {
                    wxBitmap bmp = m_form->GetPropertyAsBitmap( wxT("bitmap") );
                    if ( bmp.IsOk() )
                    {
                        m_wizard->SetBitmap( bmp );
                    }
                }
            }

            // --- [4] Create the components of the form -------------------------

            // Used to save frame objects for later display
            PObjectBase menubar;
            wxWindow* statusbar = NULL;
            wxWindow* toolbar = NULL;

            for ( unsigned int i = 0; i < m_form->GetChildCount(); i++ )
            {
                PObjectBase child = m_form->GetChild( i );

                if( !menubar && (m_form->GetObjectTypeName() == wxT("menubar_form")) )
                {
                    // main form acts as a menubar
                    menubar = m_form;
                }
                else if (child->GetObjectTypeName() == wxT("menubar") )
                {
                    // Create the menubar later
                    menubar = child;
                }
                else if( !toolbar && (m_form->GetObjectTypeName() == wxT("toolbar_form")) )
                {
                    Generate( m_form, m_back->GetFrameContentPanel(), m_back->GetFrameContentPanel() );

                    ObjectBaseMap::iterator it = m_baseobjects.find( m_form.get() );
                    toolbar = wxDynamicCast( it->second, wxToolBar );

                    break;
                }
                else
                {
                    // Recursively generate the ObjectTree
                    try
                    {
                        // we have to put the content frame panel as parentObject in order
                        // to SetSizeHints be called.
                        if( m_auipanel )
                        {
                            Generate( child, m_auipanel, m_auipanel );
                        }
                        else if( m_wizard )
                        {
                            Generate( child, m_wizard, m_wizard );
                        }
                        else
                            Generate( child, m_back->GetFrameContentPanel(), m_back->GetFrameContentPanel() );

                    }
                    catch ( wxFBException& ex )
                    {
                        wxLogError ( ex.what() );
                    }
                }

                // Attach the toolbar (if any) to the frame
                if (child->GetClassName() == wxT("wxToolBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    toolbar = wxDynamicCast( it->second, wxToolBar );
                }
                else if (child->GetClassName() == wxT("wxAuiToolBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    toolbar = wxDynamicCast( it->second, wxAuiToolBar );
                }

                // Attach the status bar (if any) to the frame
                if ( child->GetClassName() == wxT("wxStatusBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    statusbar = wxDynamicCast( it->second, wxStatusBar );
                }

                // Add toolbar(s) to AuiManager and update content
                if( m_auimgr && toolbar )
                {
                    SetupAui( GetObjectBase( toolbar ), toolbar );
                    toolbar = NULL;
                }
            }

            if ( menubar || statusbar || toolbar || m_auipanel || m_wizard )
            {
                if( m_auimgr )
                {
                    m_back->SetFrameWidgets( menubar, NULL, statusbar, m_auipanel );
                }
                else if( m_wizard )
                {
                    m_back->SetFrameWidgets( menubar, NULL, NULL, m_wizard );
                }
                else
                    m_back->SetFrameWidgets( menubar, toolbar, statusbar, m_auipanel );
            }

            m_back->Layout();

            if ( backSize.GetHeight() == wxDefaultCoord || backSize.GetWidth() == wxDefaultCoord )
            {
                m_back->GetSizer()->Fit( m_back );
                m_back->SetSize( m_back->GetBestSize() );
            }

            // Set size after fitting so if only one dimesion is -1, it still fits that dimension
            m_back->SetSize( backSize );

            if( m_auimgr ) m_auimgr->Update();
            else
                m_back->Refresh();

            PProperty enabled( m_form->GetProperty( wxT("enabled") ) );
            if ( enabled )
            {
                m_back->Enable( TypeConv::StringToInt( enabled->GetValue() ) != 0 );
            }

            PProperty hidden( m_form->GetProperty( wxT("hidden") ) );
            if ( hidden )
            {
                m_back->Show( TypeConv::StringToInt( hidden->GetValue() ) == 0 );
            }
        }
        else
        {
            // There is no form to display
            m_back->Show(false);
            Refresh();
        }
#if wxVERSION_NUMBER < 2900 && !defined(__WXGTK__)
        Thaw();
#endif
    }

    UpdateVirtualSize();
}
Ejemplo n.º 11
0
bool XrcCodeGenerator::GenerateCode( PObjectBase project )
{
    m_cw->Clear();
    m_contextMenus.clear();

    ticpp::Document doc;
    ticpp::Declaration decl( "1.0", "UTF-8", "yes" );
    doc.LinkEndChild( &decl );

    ticpp::Element element( "resource" );
    element.SetAttribute( "xmlns", "http://www.wxwindows.org/wxxrc" );
    element.SetAttribute( "version", "2.3.0.1" );

    // If project is not actually a "Project", generate it
    if ( project->GetClassName() == wxT("Project") )
    {
        for( unsigned int i = 0; i < project->GetChildCount(); i++ )
        {
            ticpp::Element* child = GetElement( project->GetChild( i ) );
            if ( child )
            {
                element.LinkEndChild( child );
                delete child;
            }
        }
    }
    else
    {
        ticpp::Element* child = GetElement( project );
        if ( child )
        {
            element.LinkEndChild( child );
            delete child;
        }
    }

    // generate context menus as top-level menus
    for( std::vector<ticpp::Element*>::iterator it = m_contextMenus.begin(); it != m_contextMenus.end(); ++it )
    {
        element.LinkEndChild( *it );
        delete *it;
    }

    doc.LinkEndChild( &element );

    TiXmlPrinter printer;
    printer.SetIndent( "\t" );

#if defined( __WXMSW__ )
    printer.SetLineBreak( "\r\n" );
#elif defined( __WXMAC__ )
    printer.SetLineBreak( "\r" );
#else
    printer.SetLineBreak( "\n" );
#endif

    doc.Accept( &printer );
    const std::string& xrcFile = printer.Str();

    m_cw->Write( _WXSTR( xrcFile ) );

    return true;

}
Ejemplo n.º 12
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() );
			}
		}
	}
}
Ejemplo n.º 13
0
void PHPCodeGenerator::GenerateInheritedClass( PObjectBase userClasses, PObjectBase form )
{
	if (!userClasses)
	{
		wxLogError(wxT("There is no object to generate inherited class"));
		return;
	}

	if ( wxT("UserClasses") != userClasses->GetClassName() )
	{
		wxLogError(wxT("This not a UserClasses object"));
		return;
	}

	wxString type = userClasses->GetPropertyAsString( wxT("type") );

	// Start file
	wxString code = GetCode( userClasses, wxT("file_comment") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxEmptyString );

	code = GetCode( userClasses, wxT("source_include") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxEmptyString );

	code = GetCode( userClasses, wxT("class_decl") );
	m_source->WriteLn( code );
	m_source->Indent();

	code = GetCode( userClasses, type + wxT("_cons_def") );
	m_source->WriteLn( code );

	// Do events
	EventVector events;
	FindEventHandlers( form, events );

	if ( events.size() > 0 )
	{
		code = GetCode( userClasses, wxT("event_handler_comment") );
		m_source->WriteLn( code );

		std::set<wxString> generatedHandlers;
		for ( size_t i = 0; i < events.size(); i++ )
		{
			PEvent event = events[i];
			if ( generatedHandlers.find( event->GetValue() ) == generatedHandlers.end() )
			{
				m_source->WriteLn( wxString::Format( wxT("function %s( event ){"),  event->GetValue().c_str() ) );
				m_source->Indent();
				m_source->WriteLn( wxString::Format( wxT("// TODO: Implement %s"), event->GetValue().c_str() ) );
				m_source->Unindent();
				m_source->WriteLn( wxT("}") );
				m_source->WriteLn( wxEmptyString );
				generatedHandlers.insert(event->GetValue());
			}
		}
		m_source->WriteLn( wxEmptyString );
	}

	m_source->Unindent();
}