From 9d27caca75b18a36c257819b74081c185a53cfd6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 2 Jul 2015 11:40:33 +0200 Subject: [PATCH] More robust method of regaining keyboard focus (GAL). --- common/draw_panel_gal.cpp | 28 +++++++++++++++++++++------- include/class_draw_panel_gal.h | 5 +++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index b7dcebfcc2..c968fc5df8 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -60,6 +60,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view = NULL; m_painter = NULL; m_eventDispatcher = NULL; + m_lostFocus = false; SwitchBackend( aGalType ); SetBackgroundStyle( wxBG_STYLE_CUSTOM ); @@ -76,6 +77,7 @@ 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 ); + Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), NULL, this ); const wxEventType events[] = { @@ -153,13 +155,6 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) } -void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) -{ - wxPaintEvent redrawEvent; - wxPostEvent( this, redrawEvent ); -} - - void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect ) { if( m_pendingRefresh ) @@ -315,6 +310,12 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) { + if( m_lostFocus ) + { + SetFocus(); + m_lostFocus = false; + } + if( !m_eventDispatcher ) aEvent.Skip(); else @@ -329,3 +330,16 @@ void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent ) // Getting focus is necessary in order to receive key events properly SetFocus(); } + + +void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent ) +{ + m_lostFocus = true; +} + + +void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) +{ + wxPaintEvent redrawEvent; + wxPostEvent( this, redrawEvent ); +} diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 7a7e57baae..36e60a7892 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -155,6 +155,7 @@ protected: void onSize( wxSizeEvent& aEvent ); void onEvent( wxEvent& aEvent ); void onEnter( wxEvent& aEvent ); + void onLostFocus( wxFocusEvent& aEvent ); void onRefreshTimer( wxTimerEvent& aEvent ); static const int MinRefreshPeriod = 17; ///< 60 FPS. @@ -191,6 +192,10 @@ protected: /// Processes and forwards events to tools TOOL_DISPATCHER* m_eventDispatcher; + + /// Flag to indicate that focus should be regained on the next mouse event. It is a workaround + /// for cases when the panel loses keyboard focus, so it does not react to hotkeys anymore. + bool m_lostFocus; }; #endif