This handlers mustn't be deleted when a popup is dismissed since they can
be the ones doing the dismissing. Also, m_focus must point to the window with focus. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -192,14 +192,21 @@ wxPopupTransientWindow::wxPopupTransientWindow(wxWindow *parent, int style)
|
|||||||
|
|
||||||
wxPopupTransientWindow::~wxPopupTransientWindow()
|
wxPopupTransientWindow::~wxPopupTransientWindow()
|
||||||
{
|
{
|
||||||
PopHandlers();
|
if (m_handlerPopup && m_handlerPopup->GetNextHandler())
|
||||||
|
PopHandlers();
|
||||||
|
|
||||||
|
wxASSERT(!m_handlerFocus || !m_handlerFocus->GetNextHandler());
|
||||||
|
wxASSERT(!m_handlerPopup || !m_handlerPopup->GetNextHandler());
|
||||||
|
|
||||||
|
delete m_handlerFocus;
|
||||||
|
delete m_handlerPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxPopupTransientWindow::PopHandlers()
|
void wxPopupTransientWindow::PopHandlers()
|
||||||
{
|
{
|
||||||
if ( m_child )
|
if ( m_child )
|
||||||
{
|
{
|
||||||
if ( m_handlerPopup && !m_child->RemoveEventHandler(m_handlerPopup) )
|
if ( !m_child->RemoveEventHandler(m_handlerPopup) )
|
||||||
{
|
{
|
||||||
// something is very wrong and someone else probably deleted our
|
// something is very wrong and someone else probably deleted our
|
||||||
// handler - so don't risk deleting it second time
|
// handler - so don't risk deleting it second time
|
||||||
@@ -212,29 +219,14 @@ void wxPopupTransientWindow::PopHandlers()
|
|||||||
m_child = NULL;
|
m_child = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
if ( m_focus )
|
if ( m_focus )
|
||||||
{
|
{
|
||||||
if ( m_handlerFocus && !m_focus->RemoveEventHandler(m_handlerFocus) )
|
if ( !m_focus->RemoveEventHandler(m_handlerFocus) )
|
||||||
{
|
{
|
||||||
// see above
|
// see above
|
||||||
m_handlerFocus = NULL;
|
m_handlerFocus = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if ( m_handlerFocus && !RemoveEventHandler(m_handlerFocus) )
|
|
||||||
{
|
|
||||||
// see above
|
|
||||||
m_handlerFocus = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// delete the handlers, they'll be created as necessary in Popup()
|
|
||||||
delete m_handlerPopup;
|
|
||||||
m_handlerPopup = NULL;
|
|
||||||
delete m_handlerFocus;
|
|
||||||
m_handlerFocus = NULL;
|
|
||||||
|
|
||||||
m_focus = NULL;
|
m_focus = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,12 +244,12 @@ void wxPopupTransientWindow::Popup(wxWindow *winFocus)
|
|||||||
|
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
// There is is a problem if these are still valid
|
// There is is a problem if these are still in use
|
||||||
wxASSERT_MSG(!m_handlerPopup, wxT("Popup handler not deleted"));
|
wxASSERT(!m_handlerFocus || !m_handlerFocus->GetNextHandler());
|
||||||
wxASSERT_MSG(!m_handlerFocus, wxT("Focus handler not deleted"));
|
wxASSERT(!m_handlerPopup || !m_handlerPopup->GetNextHandler());
|
||||||
|
|
||||||
delete m_handlerPopup;
|
if (!m_handlerPopup)
|
||||||
m_handlerPopup = new wxPopupWindowHandler(this);
|
m_handlerPopup = new wxPopupWindowHandler(this);
|
||||||
|
|
||||||
m_child->PushEventHandler(m_handlerPopup);
|
m_child->PushEventHandler(m_handlerPopup);
|
||||||
|
|
||||||
@@ -269,20 +261,19 @@ void wxPopupTransientWindow::Popup(wxWindow *winFocus)
|
|||||||
// subclass the window which has the focus, and not winFocus passed in or
|
// subclass the window which has the focus, and not winFocus passed in or
|
||||||
// otherwise everything else breaks down
|
// otherwise everything else breaks down
|
||||||
m_focus = FindFocus();
|
m_focus = FindFocus();
|
||||||
|
#elif __WXGTK__
|
||||||
|
// GTK+ catches the activate events from the popup
|
||||||
|
// window, not the focus events from the child window
|
||||||
|
m_focus = this;
|
||||||
|
#endif
|
||||||
|
|
||||||
if ( m_focus )
|
if ( m_focus )
|
||||||
{
|
{
|
||||||
delete m_handlerFocus;
|
if (!m_handlerFocus)
|
||||||
m_handlerFocus = new wxPopupFocusHandler(this);
|
m_handlerFocus = new wxPopupFocusHandler(this);
|
||||||
|
|
||||||
m_focus->PushEventHandler(m_handlerFocus);
|
m_focus->PushEventHandler(m_handlerFocus);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// GTK+ catches the activate events from the popup
|
|
||||||
// window, not the focus events from the child window
|
|
||||||
delete m_handlerFocus;
|
|
||||||
m_handlerFocus = new wxPopupFocusHandler(this);
|
|
||||||
PushEventHandler(m_handlerFocus);
|
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
// catch destroy events, if you close a program with a popup shown in MSW
|
// catch destroy events, if you close a program with a popup shown in MSW
|
||||||
// you get a segfault if m_child or m_focus are deleted before this is
|
// you get a segfault if m_child or m_focus are deleted before this is
|
||||||
|
Reference in New Issue
Block a user