Use EventFilter strategy on GTK; leave FocusLost for MSW & OSX.

This commit is contained in:
Jeff Young 2018-09-27 20:42:59 +01:00
parent 136525b870
commit 453dadbc3c
1 changed files with 43 additions and 7 deletions

View File

@ -48,6 +48,38 @@ wxDEFINE_EVENT( NET_SELECTED, wxCommandEvent );
#define NO_NET _( "<no net>" )
class POPUP_EVENTFILTER : public wxEventFilter
{
public:
POPUP_EVENTFILTER( wxDialog* aPopup ) :
m_popup( aPopup )
{
wxEvtHandler::AddFilter( this );
}
~POPUP_EVENTFILTER() override
{
wxEvtHandler::RemoveFilter( this );
}
int FilterEvent( wxEvent& aEvent ) override
{
// Click outside popup cancels
if( aEvent.GetEventType() == wxEVT_LEFT_DOWN
&& !m_popup->GetScreenRect().Contains( wxGetMousePosition() ) )
{
m_popup->EndModal( wxID_CANCEL );
return Event_Processed;
}
return Event_Skip;
}
private:
wxDialog* m_popup;
};
class NET_SELECTOR_POPUP : public wxDialog
{
public:
@ -112,6 +144,8 @@ public:
// to catch mouse and key events outside our window.
int ShowModal() override
{
POPUP_EVENTFILTER filter( this );
Show( true );
while( !m_retCode )
@ -188,6 +222,7 @@ protected:
onMouseMoved( screenPos );
}
#ifndef __WXGTK__
// Check for loss of focus. This will indicate that a window manager processed
// an activate event without fully involving wxWidgets (and thus our EventFilter
// never got notified of the click).
@ -197,6 +232,7 @@ protected:
if( m_initialized && focus != this && focus != m_netListBox && focus != m_filterCtrl )
EndModal( wxID_CANCEL );
#endif
}
// Hot-track the mouse (for focus and listbox selection)