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; }
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; } // highlight parent toolbar instead of its children PObjectBase toolbar = obj->FindNearAncestor( wxT("toolbar") ); if( !toolbar ) toolbar = obj->FindNearAncestor( wxT("toolbar_form") ); if( toolbar ) obj = toolbar; // 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 ( obj->GetObjectInfo()->GetObjectTypeName() == wxT("wizardpagesimple") ) { ObjectBaseMap::iterator pageIt = m_baseobjects.find( obj.get() ); WizardPageSimple* wizpage = wxDynamicCast( pageIt->second, WizardPageSimple ); SetupWizard( obj, wizpage ); } 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() ) { if ( parent->GetObjectInfo()->GetObjectTypeName() == wxT("wizardpagesimple") ) { WizardPageSimple* wizpage = wxDynamicCast( parentIt->second, WizardPageSimple ); SetupWizard( parent, wizpage ); } 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(); }