X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/eb5e4d9ac1527441fe107460c7fee93092175a3e..9ffdd8cf3c7aa760bec29050688487bb01806b83:/src/msw/fdrepdlg.cpp diff --git a/src/msw/fdrepdlg.cpp b/src/msw/fdrepdlg.cpp index 5cc89364cd..1c2006f35d 100644 --- a/src/msw/fdrepdlg.cpp +++ b/src/msw/fdrepdlg.cpp @@ -4,7 +4,7 @@ // Author: Markus Greither and Vadim Zeitlin // Modified by: // Created: 23/03/2001 -// RCS-ID: +// RCS-ID: $Id$ // Copyright: (c) Markus Greither // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "mswfdrepdlg.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -31,29 +27,26 @@ #if wxUSE_FINDREPLDLG #ifndef WX_PRECOMP + #include "wx/msw/wrapcdlg.h" #include "wx/intl.h" #include "wx/log.h" #endif -#include "wx/msw/private.h" - -#if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__) - #include -#endif - #include "wx/fdrepdlg.h" +#include "wx/msw/mslu.h" + // ---------------------------------------------------------------------------- // functions prototypes // ---------------------------------------------------------------------------- -LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, - WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, + WPARAM wParam, LPARAM lParam); -UINT CALLBACK wxFindReplaceDialogHookProc(HWND hwnd, - UINT uiMsg, - WPARAM wParam, - LPARAM lParam); +UINT_PTR CALLBACK wxFindReplaceDialogHookProc(HWND hwnd, + UINT uiMsg, + WPARAM wParam, + LPARAM lParam); // ---------------------------------------------------------------------------- // wxWin macros @@ -82,7 +75,7 @@ public: FINDREPLACE *GetPtrFindReplace() { return &m_findReplace; } // set/query the "closed by user" flag - void SetClosedByUser() { m_wasClosedByUser = TRUE; } + void SetClosedByUser() { m_wasClosedByUser = true; } bool WasClosedByUser() const { return m_wasClosedByUser; } private: @@ -97,11 +90,13 @@ private: // the find replace data used by the dialog FINDREPLACE m_findReplace; - // TRUE if the user closed us, FALSE otherwise + // 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; @@ -131,7 +126,7 @@ wxFindReplaceDialogImpl::wxFindReplaceDialogImpl(wxFindReplaceDialog *dialog, m_hwndOwner = NULL; m_oldParentWndProc = NULL; - m_wasClosedByUser = FALSE; + m_wasClosedByUser = false; wxZeroMemory(m_findReplace); @@ -176,7 +171,7 @@ void wxFindReplaceDialogImpl::InitString(const wxString& str, *ppStr = new wxChar[len]; wxStrcpy(*ppStr, str); - *pLen = len; + *pLen = (WORD)len; } void wxFindReplaceDialogImpl::InitFindWhat(const wxString& str) @@ -197,17 +192,14 @@ 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 - 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; - (void)::SetWindowLong(hwnd, GWL_USERDATA, (LONG)oldParentWndProc); - - // and set the new one - (void)::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)wxFindReplaceWindowProc); - } + wxCHECK_RET( wxGetWindowProc(hwnd) != &wxFindReplaceWindowProc, + _T("can't have more than one find dialog currently") ); + + // set the new one and save the old as user data to allow access to it + // from wxFindReplaceWindowProc + m_oldParentWndProc = wxSetWindowProc(hwnd, wxFindReplaceWindowProc); + + wxSetWindowUserData(hwnd, (void *)m_oldParentWndProc); } wxFindReplaceDialogImpl::~wxFindReplaceDialogImpl() @@ -217,7 +209,8 @@ wxFindReplaceDialogImpl::~wxFindReplaceDialogImpl() if ( m_hwndOwner ) { - ::SetWindowLong(m_hwndOwner, GWL_WNDPROC, (LONG)m_oldParentWndProc); + // undo subclassing + wxSetWindowProc(m_hwndOwner, m_oldParentWndProc); } } @@ -225,18 +218,42 @@ wxFindReplaceDialogImpl::~wxFindReplaceDialogImpl() // Window Proc for handling RegisterWindowMessage(FINDMSGSTRING) // ---------------------------------------------------------------------------- -LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, +LRESULT CALLBACK wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, WPARAM wParam, LPARAM lParam) { +#if wxUSE_UNICODE_MSLU + static unsigned long s_lastMsgFlags = 0; + + // This flag helps us to identify the bogus ANSI message + // sent by UNICOWS.DLL (see below) + // while we're sending our message to the dialog + // we ignore possible messages sent in between + static bool s_blockMsg = false; +#endif // wxUSE_UNICODE_MSLU + if ( nMsg == wxFindReplaceDialogImpl::GetFindDialogMessage() ) { FINDREPLACE *pFR = (FINDREPLACE *)lParam; + +#if wxUSE_UNICODE_MSLU + // This is a hack for a MSLU problem: Versions up to 1.0.4011 + // of UNICOWS.DLL send the correct UNICODE item after button press + // and a bogus ANSI mode item right after this, so lets ignore + // the second bogus message + if ( wxUsingUnicowsDll() && s_lastMsgFlags == pFR->Flags ) + { + s_lastMsgFlags = 0; + return 0; + } + s_lastMsgFlags = pFR->Flags; +#endif // wxUSE_UNICODE_MSLU + wxFindReplaceDialog *dialog = (wxFindReplaceDialog *)pFR->lCustData; // map flags from Windows wxEventType evtType; - bool replace = FALSE; + bool replace = false; if ( pFR->Flags & FR_DIALOGTERM ) { // we have to notify the dialog that it's being closed by user and @@ -254,13 +271,13 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, { evtType = wxEVT_COMMAND_FIND_REPLACE; - replace = TRUE; + replace = true; } else if ( pFR->Flags & FR_REPLACEALL ) { evtType = wxEVT_COMMAND_FIND_REPLACE_ALL; - replace = TRUE; + replace = true; } else { @@ -286,10 +303,22 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, event.SetReplaceString(pFR->lpstrReplaceWith); } +#if wxUSE_UNICODE_MSLU + s_blockMsg = true; +#endif // wxUSE_UNICODE_MSLU + dialog->Send(event); + +#if wxUSE_UNICODE_MSLU + s_blockMsg = false; +#endif // wxUSE_UNICODE_MSLU } +#if wxUSE_UNICODE_MSLU + else if ( !s_blockMsg ) + s_lastMsgFlags = 0; +#endif // wxUSE_UNICODE_MSLU - WNDPROC wndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_USERDATA); + WNDPROC wndProc = (WNDPROC)wxGetWindowUserData(hwnd); // sanity check wxASSERT_MSG( wndProc != wxFindReplaceWindowProc, @@ -302,10 +331,11 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg, // Find/replace dialog hook proc // ---------------------------------------------------------------------------- -UINT CALLBACK wxFindReplaceDialogHookProc(HWND hwnd, - UINT uiMsg, - WPARAM WXUNUSED(wParam), - LPARAM lParam) +UINT_PTR CALLBACK +wxFindReplaceDialogHookProc(HWND hwnd, + UINT uiMsg, + WPARAM WXUNUSED(wParam), + LPARAM lParam) { if ( uiMsg == WM_INITDIALOG ) { @@ -335,7 +365,7 @@ void wxFindReplaceDialog::Init() m_FindReplaceData = NULL; // as we're created in the hidden state, bring the internal flag in sync - m_isShown = FALSE; + m_isShown = false; } wxFindReplaceDialog::wxFindReplaceDialog(wxWindow *parent, @@ -367,7 +397,7 @@ wxFindReplaceDialog::~wxFindReplaceDialog() delete m_impl; // prevent the base class dtor from trying to hide us! - m_isShown = FALSE; + m_isShown = false; // and from destroying our window [again] m_hWnd = (WXHWND)NULL; @@ -397,7 +427,7 @@ bool wxFindReplaceDialog::Show(bool show) if ( !wxWindowBase::Show(show) ) { // visibility status didn't change - return FALSE; + return false; } // do we already have the dialog window? @@ -406,16 +436,16 @@ bool wxFindReplaceDialog::Show(bool show) // yes, just use it (void)::ShowWindow(GetHwnd(), show ? SW_SHOW : SW_HIDE); - return TRUE; + return true; } if ( !show ) { // well, it doesn't exist which is as good as being hidden - return TRUE; + return true; } - wxCHECK_MSG( m_FindReplaceData, FALSE, _T("call Create() first!") ); + wxCHECK_MSG( m_FindReplaceData, false, _T("call Create() first!") ); wxASSERT_MSG( !m_impl, _T("why don't we have the window then?") ); @@ -445,7 +475,7 @@ bool wxFindReplaceDialog::Show(bool show) delete m_impl; m_impl = NULL; - return FALSE; + return false; } // subclass parent window in order to get FINDMSGSTRING message @@ -458,7 +488,7 @@ bool wxFindReplaceDialog::Show(bool show) m_hWnd = (WXHWND)hwnd; - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -511,4 +541,3 @@ void wxFindReplaceDialog::DoGetClientSize(int *width, int *height) const } #endif // wxUSE_FINDREPLDLG -