diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 57756e66fc..105e283d6b 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -114,8 +114,8 @@ CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu ) void CONTEXT_MENU::setupEvents() { - Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CONTEXT_MENU::onMenuEvent ), NULL, this ); - Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CONTEXT_MENU::onMenuEvent ), NULL, this ); + Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( CONTEXT_MENU::onMenuEvent ), NULL, this ); + Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( CONTEXT_MENU::onMenuEvent ), NULL, this ); } @@ -194,7 +194,7 @@ void CONTEXT_MENU::Clear() } -void CONTEXT_MENU::onMenuEvent( wxEvent& aEvent ) +void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) { OPT_TOOL_EVENT evt; @@ -219,7 +219,25 @@ void CONTEXT_MENU::onMenuEvent( wxEvent& aEvent ) } else { + // Under Linux, every submenu can have a separate event handler, under + // Windows all submenus are handled by the main menu. +#ifdef __WINDOWS__ + if( !evt ) { + // Try to find the submenu which holds the selected item + wxMenu*menu = NULL; + FindItem( m_selected, &menu ); + + if( menu ) + { + menu->ProcessEvent( aEvent ); + return; + } + + assert( false ); // The event should be handled above + } +#else evt = m_customHandler( aEvent ); +#endif /* else __WINDOWS__ */ // Handling non-action menu entries (e.g. items in clarification list) if( !evt ) diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index 72b69315d6..882fb3a365 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -95,12 +95,12 @@ public: } protected: - void setCustomEventHandler( boost::function aHandler ) + void setCustomEventHandler( boost::function aHandler ) { m_customHandler = aHandler; } - virtual OPT_TOOL_EVENT handleCustomEvent( const wxEvent& aEvent ) + virtual OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent ) { return OPT_TOOL_EVENT(); } @@ -116,7 +116,7 @@ private: void setupEvents(); ///> Event handler. - void onMenuEvent( wxEvent& aEvent ); + void onMenuEvent( wxMenuEvent& aEvent ); /** * Function setTool() @@ -144,7 +144,7 @@ private: std::map m_toolActions; /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. - boost::function m_customHandler; + boost::function m_customHandler; friend class TOOL_INTERACTIVE; }; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index db75478427..4b441474d4 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -152,7 +152,7 @@ public: } protected: - OPT_TOOL_EVENT handleCustomEvent( const wxEvent& aEvent ) + OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent ) { #if ID_POPUP_PCB_SELECT_VIASIZE1 < ID_POPUP_PCB_SELECT_WIDTH1 #error You have changed event ids order, it breaks code. Check the source code for more details. @@ -183,7 +183,7 @@ protected: bds.SetTrackWidthIndex( 0 ); } - else if( id > ID_POPUP_PCB_SELECT_VIASIZE1 ) // via size has changed + else if( id >= ID_POPUP_PCB_SELECT_VIASIZE1 ) // via size has changed { assert( id < ID_POPUP_PCB_SELECT_WIDTH_END_RANGE );