From 87da6a8ad359a9a034f6acf6433396fe4c9fe24d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 9 Sep 2013 17:12:03 +0200 Subject: [PATCH] Fixed hanging up of menu loop when user never moves mouse cursor into popup menu area. --- common/tool/context_menu.cpp | 16 ++++++++++++---- include/tool/context_menu.h | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 0a38f5bb0c..a2247efe4d 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -44,7 +44,7 @@ public: if( type == wxEVT_MENU_HIGHLIGHT ) evt = TOOL_EVENT( TC_Command, TA_ContextMenuUpdate, aEvent.GetId() ); - else if ( type == wxEVT_COMMAND_MENU_SELECTED ) + else if( type == wxEVT_COMMAND_MENU_SELECTED ) evt = TOOL_EVENT( TC_Command, TA_ContextMenuChoice, aEvent.GetId() ); m_menu->m_tool->GetManager()->ProcessEvent( evt ); @@ -60,8 +60,15 @@ CONTEXT_MENU::CONTEXT_MENU() m_tool = NULL; m_menu = new wxMenu(); m_handler = new CMEventHandler( this ); - m_menu->Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); - m_menu->Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler ); + m_menu->Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), + NULL, m_handler ); + m_menu->Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), + NULL, m_handler ); + + // Workaround for the case when mouse cursor never reaches menu (it hangs up tools using menu) + wxMenuEvent menuEvent( wxEVT_MENU_HIGHLIGHT, 0, m_menu ); + m_menu->AddPendingEvent( menuEvent ); + m_titleSet = false; } @@ -75,6 +82,7 @@ CONTEXT_MENU::~CONTEXT_MENU() void CONTEXT_MENU::SetTitle( const wxString& aTitle ) { + // Unfortunately wxMenu::SetTitle() does nothing.. if( m_titleSet ) { m_menu->Delete( m_menu->FindItemByPosition( 0 ) ); // fixme: this is LAME! @@ -87,7 +95,7 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) } -void CONTEXT_MENU::Add ( const wxString& aItem, int aId ) +void CONTEXT_MENU::Add( const wxString& aItem, int aId ) { m_menu->Append( new wxMenuItem( m_menu, aId, aItem, wxEmptyString, wxITEM_NORMAL ) ); } diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index 909798534a..b62a55a041 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -44,7 +44,7 @@ public: ~CONTEXT_MENU(); void SetTitle( const wxString& aTitle ); - void Add ( const wxString& aItem, int aId ); + void Add( const wxString& aItem, int aId ); // fixme: unimplemented // void Add ( const TOOL_ACTION& aAction, int aId = -1 ); @@ -61,7 +61,7 @@ private: friend class TOOL_INTERACTIVE; - void setTool ( TOOL_INTERACTIVE* aTool ) + void setTool( TOOL_INTERACTIVE* aTool ) { m_tool = aTool; }