X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/44d5b352ae4bd753dd5d6d79e70f08816efae4af..eaa6418668bef80dda53dc139935882f9fa8356a:/src/msw/fdrepdlg.cpp diff --git a/src/msw/fdrepdlg.cpp b/src/msw/fdrepdlg.cpp index 0d34834244..27eb2be03d 100644 --- a/src/msw/fdrepdlg.cpp +++ b/src/msw/fdrepdlg.cpp @@ -81,6 +81,10 @@ public: // only for passing to ::FindText or ::ReplaceText FINDREPLACE *GetPtrFindReplace() { return &m_findReplace; } + // set/query the "closed by user" flag + void SetClosedByUser() { m_wasClosedByUser = TRUE; } + bool WasClosedByUser() const { return m_wasClosedByUser; } + private: void InitString(const wxString& str, LPTSTR *ppStr, WORD *pLen); @@ -93,8 +97,13 @@ private: // the find replace data used by the dialog FINDREPLACE m_findReplace; + // TRUE if the user closed us, FALSE otherwise + bool m_wasClosedByUser; + // registered Message for Dialog static UINT ms_msgFindDialog; + + DECLARE_NO_COPY_CLASS(wxFindReplaceDialogImpl) }; UINT wxFindReplaceDialogImpl::ms_msgFindDialog = 0; @@ -124,6 +133,8 @@ wxFindReplaceDialogImpl::wxFindReplaceDialogImpl(wxFindReplaceDialog *dialog, m_hwndOwner = NULL; m_oldParentWndProc = NULL; + m_wasClosedByUser = FALSE; + wxZeroMemory(m_findReplace); // translate the flags: first the dialog creation flags @@ -188,10 +199,9 @@ void wxFindReplaceDialogImpl::SubclassDialog(HWND hwnd) // check that we don't subclass the parent twice: this would be a bad idea // as then we'd have infinite recursion in wxFindReplaceWindowProc - WNDPROC oldParentWndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_WNDPROC); - - if ( oldParentWndProc != wxFindReplaceWindowProc ) + if ( !wxCheckWindowWndProc((WXHWND)hwnd, (WXFARPROC)wxFindReplaceWindowProc) ) { + WNDPROC oldParentWndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_WNDPROC); // save old wnd proc elsewhere to access it from // wxFindReplaceWindowProc m_oldParentWndProc = oldParentWndProc; @@ -231,6 +241,11 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, bool replace = FALSE; if ( pFR->Flags & FR_DIALOGTERM ) { + // we have to notify the dialog that it's being closed by user and + // not deleted programmatically as it behaves differently in these + // 2 cases + dialog->GetImpl()->SetClosedByUser(); + evtType = wxEVT_COMMAND_FIND_CLOSE; } else if ( pFR->Flags & FR_FINDNEXT ) @@ -338,13 +353,25 @@ wxFindReplaceDialog::wxFindReplaceDialog(wxWindow *parent, wxFindReplaceDialog::~wxFindReplaceDialog() { + // the dialog might have been already deleted if the user closed it + // manually but in this case we should have got a notification about it and + // the flagmust have been set + if ( !m_impl->WasClosedByUser() ) + { + // if it wasn't, delete the dialog ourselves + if ( !::DestroyWindow(GetHwnd()) ) + { + wxLogLastError(_T("DestroyWindow(find dialog)")); + } + } + // unsubclass the parent delete m_impl; // prevent the base class dtor from trying to hide us! m_isShown = FALSE; - // and from destroying our window + // and from destroying our window [again] m_hWnd = (WXHWND)NULL; }