IObject* wxFBManager::GetIObject( wxObject* wxobject ) { CHECK_VISUAL_EDITOR( NULL ) CHECK_WX_OBJECT( NULL ) PObjectBase obj = m_visualEdit->GetObjectBase( wxobject ); CHECK_OBJECT_BASE( NULL ) return obj.get(); }
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(); }
/** * 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(); }
/** * 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(); } }
/** * 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(); }