More robust method of regaining keyboard focus (GAL).

This commit is contained in:
Maciej Suminski 2015-07-02 11:40:33 +02:00
parent d3e276387d
commit 9d27caca75
2 changed files with 26 additions and 7 deletions

View File

@ -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 );
}

View File

@ -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