git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33538
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// remove our event handlers
void PopHandlers();
// remove our event handlers
void PopHandlers();
+ // get alerted when child gets deleted from under us
+ void OnDestroy(wxWindowDestroyEvent& event);
+
// the child of this popup if any
wxWindow *m_child;
// the child of this popup if any
wxWindow *m_child;
class wxPopupWindowHandler : public wxEvtHandler
{
public:
class wxPopupWindowHandler : public wxEvtHandler
{
public:
- wxPopupWindowHandler(wxPopupTransientWindow *popup) { m_popup = popup; }
+ wxPopupWindowHandler(wxPopupTransientWindow *popup) : m_popup(popup) {}
+ ~wxPopupWindowHandler();
protected:
// event handlers
protected:
// event handlers
class wxPopupFocusHandler : public wxEvtHandler
{
public:
class wxPopupFocusHandler : public wxEvtHandler
{
public:
- wxPopupFocusHandler(wxPopupTransientWindow *popup)
- {
- m_popup = popup;
- }
+ wxPopupFocusHandler(wxPopupTransientWindow *popup) : m_popup(popup) {}
+ ~wxPopupFocusHandler();
protected:
void OnKillFocus(wxFocusEvent& event);
protected:
void OnKillFocus(wxFocusEvent& event);
+ // There is is a problem if these are still valid
+ wxASSERT_MSG(!m_handlerPopup, wxT("Popup handler not deleted"));
+ wxASSERT_MSG(!m_handlerFocus, wxT("Focus handler not deleted"));
+
delete m_handlerPopup;
m_handlerPopup = new wxPopupWindowHandler(this);
delete m_handlerPopup;
m_handlerPopup = new wxPopupWindowHandler(this);
PushEventHandler(m_handlerFocus);
#endif // __WXMSW__
PushEventHandler(m_handlerFocus);
#endif // __WXMSW__
+ // 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
+ m_child->Connect(wxEVT_DESTROY,
+ wxWindowDestroyEventHandler(wxPopupTransientWindow::OnDestroy),
+ NULL, this);
+ m_focus->Connect(wxEVT_DESTROY,
+ wxWindowDestroyEventHandler(wxPopupTransientWindow::OnDestroy),
+ NULL, this);
}
bool wxPopupTransientWindow::Show( bool show )
}
bool wxPopupTransientWindow::Show( bool show )
+void wxPopupTransientWindow::OnDestroy(wxWindowDestroyEvent& event)
+{
+ if (event.GetEventObject() == m_child)
+ m_child = NULL;
+ if (event.GetEventObject() == m_focus)
+ m_focus = NULL;
+}
+
#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
// ----------------------------------------------------------------------------
#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxPopupWindowHandler
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxPopupWindowHandler
// ----------------------------------------------------------------------------
+wxPopupWindowHandler::~wxPopupWindowHandler()
+{
+ if (m_popup && (m_popup->m_handlerPopup == this))
+ m_popup->m_handlerPopup = NULL;
+}
void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event)
{
void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event)
{
// ----------------------------------------------------------------------------
// wxPopupFocusHandler
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxPopupFocusHandler
// ----------------------------------------------------------------------------
+wxPopupFocusHandler::~wxPopupFocusHandler()
+{
+ if (m_popup && (m_popup->m_handlerFocus == this))
+ m_popup->m_handlerFocus = NULL;
+}
void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
{
void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
{