wxMenu and wxUpdateUIEvent

Patrik Mueller paddi.m at gmx.net
Wed Feb 13 14:27:26 PST 2008


Hi,

found a solution...

Greets,

Patrik

Patrik Mueller schrieb:
> Hi,
> 
> I'm a newbie with wxWidgets - so I have a problem:
> 
> I have derived a class fromwxMenu (code attached at the end of this 
> question. The connection for the selection of a wxMenuItem is ok - but I 
> don't receive an update event. Where's my mistake?
> 
> Thanks in advance,
> 
> Patrik
> 
> 
> 
> #pragma once
> #ifndef WX_PRECOMP
> #include "wx/wx.h"
> #endif
> 
> #include "Im_Entity3D.h"
> 
> class Im_Entity3DMenu : public wxMenu
> {
> public:
>     void SetEntity(Im_Entity3DPtr theEntity);
>     void BuildItems();
>     Im_Entity3DMenu();
>     virtual ~Im_Entity3DMenu(void);
> protected:
>     void SetPointStyle( wxCommandEvent& event );
>     void SetCheckPointStyle(wxUpdateUIEvent& event);
>     void SetBoxStyle( wxCommandEvent& event );
>     void SetCheckBoxStyle(wxUpdateUIEvent& event);
>     void SetWireframeStyle( wxCommandEvent& event );
>     void SetCheckWireframeStyle(wxUpdateUIEvent& event);
>     void SetShadedStyle( wxCommandEvent& event );
>     void SetCheckShadedStyle(wxUpdateUIEvent& event);
>     void ChangeMaterial( wxCommandEvent& event );
>     void ChangeLayer( wxCommandEvent& event );
>     void SetVisibility( wxCommandEvent& event );
>     void SetCheckVisibility(wxUpdateUIEvent& event);
>     void RenameEntity( wxCommandEvent& event );
>     void DeleteEntity( wxCommandEvent& event );
>     void Triangulate( wxCommandEvent& event );
>     void ToShape( wxCommandEvent& event );
>     void Decimate( wxCommandEvent& event );
>     void Smooth( wxCommandEvent& event );
> protected:
>     wxMenu* m_appearance;
>     wxMenu* m_viewstyle;
>     wxMenu* m_actions;
>     Im_Entity3DPtr m_entity;
> 
> };
> 
> 
> #include "Im_Entity3DMenu.h"
> 
> #include "Im_Group3D.h"
> #include "Im_Mesh.h"
> #include "Im_Shape3D.h"
> 
> Im_Entity3DMenu::Im_Entity3DMenu() : wxMenu()
> {
> }
> 
> Im_Entity3DMenu::~Im_Entity3DMenu(void)
> {
>     if (m_entity)
>     {
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetPointStyle));
>         Disconnect( wxID_ANY, wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckPointStyle));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetBoxStyle));
>         Disconnect( wxID_ANY, wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckBoxStyle));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetWireframeStyle));
>         Disconnect( wxID_ANY, wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckWireframeStyle));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetShadedStyle));
>         Disconnect( wxID_ANY, wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckShadedStyle));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::ChangeMaterial));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetVisibility));
>         Disconnect( wxID_ANY, wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckVisibility));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::RenameEntity));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::DeleteEntity));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Triangulate));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::ToShape));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Decimate));
>         Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Smooth));
>     }
> }
> 
> void Im_Entity3DMenu::SetEntity(Im_Entity3DPtr theEntity)
> {
>     m_entity = theEntity;
> }
> 
> void Im_Entity3DMenu::BuildItems()
> {
>     if (m_entity)
>     {
>         Im_Group3DPtr tmpGroup = 
> boost::dynamic_pointer_cast<Im_Group3D>(m_entity);
>         Im_MeshPtr tmpMesh = 
> boost::dynamic_pointer_cast<Im_Mesh>(m_entity);
>         Im_Shape3DPtr tmpShape = 
> boost::dynamic_pointer_cast<Im_Shape3D>(m_entity);
> 
>         m_appearance = new wxMenu();
>         m_viewstyle = new wxMenu();
>        
>         wxMenuItem* m_points;
>         m_points = new wxMenuItem( m_viewstyle, wxID_ANY, wxString( 
> _("Points") ) , wxEmptyString, wxITEM_CHECK  );
>         m_viewstyle->Append( m_points );
>        
>         wxMenuItem* m_box;
>         m_box = new wxMenuItem( m_viewstyle, wxID_ANY, wxString( 
> _("Box") ) , wxEmptyString, wxITEM_CHECK  );
>         m_viewstyle->Append( m_box );
>        
>         wxMenuItem* m_wireframe;
>         m_wireframe = new wxMenuItem( m_viewstyle, wxID_ANY, wxString( 
> _("Wire frame") ) , wxEmptyString, wxITEM_CHECK  );
>         m_viewstyle->Append( m_wireframe );
>        
>         wxMenuItem* m_shaded;
>         m_shaded = new wxMenuItem( m_viewstyle, wxID_ANY, wxString( 
> _("Shaded") ) , wxEmptyString, wxITEM_CHECK  );
>         m_viewstyle->Append( m_shaded );
>        
>         m_appearance->Append( -1, _("View style"), m_viewstyle );
>        
>         if (!tmpGroup)
>         {
>             wxMenuItem* m_material;
>             m_material = new wxMenuItem( m_appearance, wxID_ANY, 
> wxString( _("Material...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_appearance->Append( m_material );
> 
>             Connect( m_material->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::ChangeMaterial));
>         }
> 
>         wxMenuItem* m_layer;
>         m_layer = new wxMenuItem( m_appearance, wxID_ANY, wxString( 
> _("Layer...") ) , wxEmptyString, wxITEM_NORMAL );
>         m_appearance->Append( m_layer );
> 
>         wxMenuItem* m_visible;
>         m_visible = new wxMenuItem( m_appearance, wxID_ANY, wxString( 
> _("Visible") ) , wxEmptyString, wxITEM_CHECK  );
>         m_appearance->Append( m_visible );
>         Append( -1, _("Appearance"), m_appearance );
>        
>         m_actions = new wxMenu();
>         wxMenuItem* m_rename;
>         m_rename = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Rename...") ) , wxEmptyString, wxITEM_NORMAL );
>         m_actions->Append( m_rename );
>        
>         wxMenuItem* m_delete;
>         m_delete = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Delete...") ) , wxEmptyString, wxITEM_NORMAL );
>         m_actions->Append( m_delete );
>        
>         if (tmpGroup)
>         {
>             wxMenuItem* m_import;
>             m_import = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Import...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_actions->Append( m_import );
>         }
> 
>         wxMenuItem* m_export;
>         m_export = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Export...") ) , wxEmptyString, wxITEM_NORMAL );
>         m_actions->Append( m_export );
> 
>         if (tmpShape)
>         {
>             wxMenuItem* triangulate;
>             triangulate = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Triangulate...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_actions->Append( triangulate );
>             Connect( triangulate->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Triangulate));
>         }
> 
>         if (tmpMesh)
>         {
>             wxMenuItem* m_toshape;
>             m_toshape = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("To shape...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_actions->Append( m_toshape );
>            
>             wxMenuItem* m_decimate;
>             m_decimate = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Decimate...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_actions->Append( m_decimate );
>            
>             wxMenuItem* m_smooth;
>             m_smooth = new wxMenuItem( m_actions, wxID_ANY, wxString( 
> _("Smooth...") ) , wxEmptyString, wxITEM_NORMAL );
>             m_actions->Append( m_smooth );
> 
>             Connect( m_toshape->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::ToShape));
>             Connect( m_decimate->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Decimate));
>             Connect( m_smooth->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::Smooth));
> 
>         }       
>         Append( -1, _("Actions"), m_actions );
> 
>         Connect( m_points->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetPointStyle));
>         Connect( m_points->GetId(), wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckPointStyle));
>         Connect( m_box->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetBoxStyle));
>         Connect( m_box->GetId(), wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckBoxStyle));
>         Connect( m_wireframe->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetWireframeStyle));
>         Connect( m_wireframe->GetId(), wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckWireframeStyle));
>         Connect( m_shaded->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetShadedStyle));
>         Connect( m_shaded->GetId(), wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckShadedStyle));
>         Connect( m_visible->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::SetVisibility));
>         Connect( m_visible->GetId(), wxEVT_UPDATE_UI, 
> wxUpdateUIEventHandler(Im_Entity3DMenu::SetCheckVisibility));
>         Connect( m_layer->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::ChangeLayer));
> 
>         Connect( m_rename->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::RenameEntity));
>         Connect( m_delete->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
> wxCommandEventHandler(Im_Entity3DMenu::DeleteEntity));
> 
>     }
> }
> 
> void Im_Entity3DMenu::SetCheckVisibility( wxUpdateUIEvent& event )
> {
>     event.Check(m_entity->GetIsVisible());
> }
> 
> void Im_Entity3DMenu::SetCheckPointStyle( wxUpdateUIEvent& event )
> {
>     event.Check(Im_Entity3D::Im_Points == m_entity->GetDisplayMode());
> }
> 
> void Im_Entity3DMenu::SetCheckBoxStyle( wxUpdateUIEvent& event )
> {
>     event.Check(Im_Entity3D::Im_Box == m_entity->GetDisplayMode());
> }
> 
> void Im_Entity3DMenu::SetCheckWireframeStyle( wxUpdateUIEvent& event )
> {
>     event.Check(Im_Entity3D::Im_WireFrame == m_entity->GetDisplayMode());
> }
> 
> void Im_Entity3DMenu::SetCheckShadedStyle( wxUpdateUIEvent& event )
> {
>     event.Check(Im_Entity3D::Im_Shading == m_entity->GetDisplayMode());
> }
> 
> void Im_Entity3DMenu::SetPointStyle( wxCommandEvent& event )
> {
>     wxMessageBox(L"SetPointStyle",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::SetBoxStyle( wxCommandEvent& event )
> {
>     wxMessageBox(L"SetBoxStyle",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::SetWireframeStyle( wxCommandEvent& event )
> {
>     wxMessageBox(L"SetWireframeStyle",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::SetShadedStyle( wxCommandEvent& event )
> {
>     wxMessageBox(L"SetShadedStyle",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::ChangeMaterial( wxCommandEvent& event )
> {
>     wxMessageBox(L"ChangeMaterial",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::ChangeLayer( wxCommandEvent& event )
> {
>     wxMessageBox(L"ChangeLayer",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::SetVisibility( wxCommandEvent& event )
> {
>     wxMessageBox(L"SetVisibility",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::RenameEntity( wxCommandEvent& event )
> {
>     wxMessageBox(L"RenameEntity",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::DeleteEntity( wxCommandEvent& event )
> {
>     wxMessageBox(L"DeleteEntity",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::Triangulate( wxCommandEvent& event )
> {
>     wxMessageBox(L"Triangulate",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::ToShape( wxCommandEvent& event )
> {
>     wxMessageBox(L"ToShape",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::Decimate( wxCommandEvent& event )
> {
>     wxMessageBox(L"Decimate",L"Im_Entity3DMenu");
> }
> 
> void Im_Entity3DMenu::Smooth( wxCommandEvent& event )
> {
>     wxMessageBox(L"Smooth",L"Im_Entity3DMenu");
> }





More information about the wx-users mailing list