X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/761989ffb536ab51e977142aa018064ef32b539b..0fe5e8fea017ecb73f8aaa8ceb745feb269b3f79:/src/msw/fdrepdlg.cpp diff --git a/src/msw/fdrepdlg.cpp b/src/msw/fdrepdlg.cpp index ca6e4e533f..5cc89364cd 100644 --- a/src/msw/fdrepdlg.cpp +++ b/src/msw/fdrepdlg.cpp @@ -1,8 +1,8 @@ ///////////////////////////////////////////////////////////////////////////// // Name: src/msw/fdrepdlg.cpp // Purpose: wxFindReplaceDialog class -// Author: Markus Greither -// Modified by: 31.07.01: VZ: integrated into wxWindows +// Author: Markus Greither and Vadim Zeitlin +// Modified by: // Created: 23/03/2001 // RCS-ID: // Copyright: (c) Markus Greither @@ -18,7 +18,7 @@ // ---------------------------------------------------------------------------- #ifdef __GNUG__ - #pragma implementation "fdrepdlg.h" + #pragma implementation "mswfdrepdlg.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -61,14 +61,6 @@ UINT CALLBACK wxFindReplaceDialogHookProc(HWND hwnd, IMPLEMENT_DYNAMIC_CLASS(wxFindReplaceDialog, wxDialog) -IMPLEMENT_DYNAMIC_CLASS(wxFindDialogEvent, wxCommandEvent) - -DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_NEXT) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE_ALL) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_CLOSE) - // ---------------------------------------------------------------------------- // wxFindReplaceDialogImpl: the internals of wxFindReplaceDialog // ---------------------------------------------------------------------------- @@ -89,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); @@ -101,6 +97,9 @@ 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; }; @@ -132,6 +131,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 @@ -196,10 +197,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; @@ -239,6 +239,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 ) @@ -281,16 +286,7 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, event.SetReplaceString(pFR->lpstrReplaceWith); } - // TODO: should we copy the strings to dialog->GetData() as well? - - if ( !dialog->GetEventHandler()->ProcessEvent(event) ) - { - // the event is not propagated upwards to the parent automatically - // because the dialog is a top level window, so do it manually as - // in 9 cases of 10 the message must be processed by the dialog - // owner and not the dialog itself - (void)dialog->GetParent()->GetEventHandler()->ProcessEvent(event); - } + dialog->Send(event); } WNDPROC wndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_USERDATA); @@ -325,15 +321,6 @@ UINT CALLBACK wxFindReplaceDialogHookProc(HWND hwnd, return 0; } -// ---------------------------------------------------------------------------- -// wxFindReplaceData -// ---------------------------------------------------------------------------- - -void wxFindReplaceData::Init() -{ - m_Flags = 0; -} - // ============================================================================ // wxFindReplaceDialog implementation // ============================================================================ @@ -355,7 +342,7 @@ wxFindReplaceDialog::wxFindReplaceDialog(wxWindow *parent, wxFindReplaceData *data, const wxString &title, int flags) - : m_FindReplaceData(data) + : wxFindReplaceDialogBase(parent, data, title, flags) { Init(); @@ -364,14 +351,26 @@ 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 - m_hWnd = NULL; + // and from destroying our window [again] + m_hWnd = (WXHWND)NULL; } bool wxFindReplaceDialog::Create(wxWindow *parent, @@ -389,16 +388,6 @@ bool wxFindReplaceDialog::Create(wxWindow *parent, return parent != NULL; } -// ---------------------------------------------------------------------------- -// wxFindReplaceDialog data access -// ---------------------------------------------------------------------------- - -void wxFindReplaceDialog::SetData(wxFindReplaceData *data) -{ - delete m_FindReplaceData; - m_FindReplaceData = data; -} - // ---------------------------------------------------------------------------- // wxFindReplaceData show/hide // ----------------------------------------------------------------------------