Beispiel #1
0
PObjectBase ObjectBase::FindNearAncestor(wxString type)
{
	PObjectBase result;
	PObjectBase parent = GetParent();
	if (parent)
	{
		if (parent->GetObjectTypeName() == type)
			result = parent;
		else
			result = parent->FindNearAncestor(type);
	}

	return result;
}
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
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;
}
Beispiel #4
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;
}
Beispiel #5
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();
}
Beispiel #6
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();
}
Beispiel #7
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 );
		}
	}
}