Reduced number of switched events, allowing to use VIEW_CONTROLS, even if there is no extra event dispatcher.

This commit is contained in:
Maciej Suminski 2014-07-09 11:22:43 +02:00
parent 0fc93666c6
commit 2f7706e8cd
3 changed files with 55 additions and 34 deletions

View File

@ -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_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), 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 // Set up timer that prevents too frequent redraw commands
m_refreshTimer.SetOwner( this ); m_refreshTimer.SetOwner( this );
m_pendingRefresh = false; m_pendingRefresh = false;
@ -171,46 +185,43 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher )
{ {
m_eventDispatcher = 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 ) #if wxCHECK_VERSION( 3, 0, 0 )
wxEVT_TOOL
#else
wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_TOOL_CLICKED
#endif
};
if( m_eventDispatcher ) if( m_eventDispatcher )
{ {
BOOST_FOREACH( wxEventType eventType, events ) m_parent->Connect( wxEVT_TOOL,
Connect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ), wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ); NULL, m_eventDispatcher );
BOOST_FOREACH( wxEventType eventType, commands )
m_parent->Connect( eventType,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher );
} }
else else
{ {
// While loops are used to be sure, that we are removing all event handlers // While loops are used to be sure, that we are removing all event handlers
BOOST_FOREACH( wxEventType eventType, events ) while( m_parent->Disconnect( wxEVT_TOOL,
while( Disconnect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ), wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) ); NULL, m_eventDispatcher ) );
BOOST_FOREACH( wxEventType eventType, commands )
while( m_parent->Disconnect( eventType,
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 ) void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent )
{ {
// Getting focus is necessary in order to receive key events properly // Getting focus is necessary in order to receive key events properly

View File

@ -281,8 +281,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
if( evt ) if( evt )
m_toolMgr->ProcessEvent( *evt ); m_toolMgr->ProcessEvent( *evt );
static_cast<PCB_BASE_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->Refresh();
// pass the event to the GUI, it might still be interested in it // pass the event to the GUI, it might still be interested in it
aEvent.Skip(); aEvent.Skip();
} }

View File

@ -147,6 +147,7 @@ public:
protected: protected:
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
void onEvent( wxEvent& aEvent );
void onEnter( wxEvent& aEvent ); void onEnter( wxEvent& aEvent );
void onRefreshTimer( wxTimerEvent& aEvent ); void onRefreshTimer( wxTimerEvent& aEvent );