From 2d44b7e3c2b20b35d529b685cf6849a322a79b2d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 11:22:43 +0200 Subject: [PATCH] Reduced number of switched events, allowing to use VIEW_CONTROLS, even if there is no extra event dispatcher. --- common/draw_panel_gal.cpp | 86 +++++++++++++++++++++------------ common/tool/tool_dispatcher.cpp | 2 - include/class_draw_panel_gal.h | 1 + 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index e960accb9b..4bf7835371 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -73,6 +73,20 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + const wxEventType events[] = + { + wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK, + wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK, + wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK, + wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE + }; + + BOOST_FOREACH( wxEventType eventType, events ) + { + Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), + NULL, m_eventDispatcher ); + } + // Set up timer that prevents too frequent redraw commands m_refreshTimer.SetOwner( this ); m_pendingRefresh = false; @@ -171,46 +185,43 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher ) { m_eventDispatcher = aEventDispatcher; - const wxEventType events[] = - { - wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK, - wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK, - wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK, - wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE - }; - - const wxEventType commands[] = - { #if wxCHECK_VERSION( 3, 0, 0 ) - wxEVT_TOOL -#else - wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_TOOL_CLICKED -#endif - }; - if( m_eventDispatcher ) { - BOOST_FOREACH( wxEventType eventType, events ) - Connect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ), - NULL, m_eventDispatcher ); - - BOOST_FOREACH( wxEventType eventType, commands ) - m_parent->Connect( eventType, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ); + m_parent->Connect( wxEVT_TOOL, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ); } else { // While loops are used to be sure, that we are removing all event handlers - BOOST_FOREACH( wxEventType eventType, events ) - while( Disconnect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ), - NULL, m_eventDispatcher ) ); - - BOOST_FOREACH( wxEventType eventType, commands ) - while( m_parent->Disconnect( eventType, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ) ); + while( m_parent->Disconnect( wxEVT_TOOL, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ) ); } +#else + if( m_eventDispatcher ) + { + m_parent->Connect( wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ); + + m_parent->Connect( wxEVT_COMMAND_TOOL_CLICKED, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ); + } + else + { + // While loops are used to be sure, that we are removing all event handlers + while( m_parent->Disconnect( wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ) ); + + while( m_parent->Disconnect( wxEVT_COMMAND_TOOL_CLICKED, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ) ); + } +#endif } @@ -292,6 +303,17 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) } +void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) +{ + if( !m_eventDispatcher ) + aEvent.Skip(); + else + m_eventDispatcher->DispatchWxEvent( aEvent ); + + Refresh(); +} + + void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent ) { // Getting focus is necessary in order to receive key events properly diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 7a3320460b..89c09a16ec 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -281,8 +281,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) if( evt ) m_toolMgr->ProcessEvent( *evt ); - static_cast( m_toolMgr->GetEditFrame() )->GetGalCanvas()->Refresh(); - // pass the event to the GUI, it might still be interested in it aEvent.Skip(); } diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 66793adf04..6d9dae1bba 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -147,6 +147,7 @@ public: protected: void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onSize( wxSizeEvent& aEvent ); + void onEvent( wxEvent& aEvent ); void onEnter( wxEvent& aEvent ); void onRefreshTimer( wxTimerEvent& aEvent );