From c8deafdfaa3bee6fc705720d85031cb2803ebbe4 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 12 Nov 2009 22:54:47 +0100 Subject: [PATCH] comdlg32: Create a 32-bit dialog for find/replace. --- dlls/comdlg32/finddlg16.c | 345 +++++++++----------------------------- 1 file changed, 83 insertions(+), 262 deletions(-) diff --git a/dlls/comdlg32/finddlg16.c b/dlls/comdlg32/finddlg16.c index f30bae80172..be36d6b6cf8 100644 --- a/dlls/comdlg32/finddlg16.c +++ b/dlls/comdlg32/finddlg16.c @@ -32,203 +32,16 @@ #include "commdlg.h" #include "wine/debug.h" #include "cderr.h" - -WINE_DEFAULT_DEBUG_CHANNEL(commdlg); - -#include "cdlg.h" #include "cdlg16.h" -struct FRPRIVATE -{ - HANDLE16 hDlgTmpl16; /* handle for resource 16 */ - HANDLE16 hResource16; /* handle for allocated resource 16 */ - HANDLE16 hGlobal16; /* 16 bits mem block (resources) */ - LPCVOID template; /* template for 32 bits resource */ - BOOL find; /* TRUE if find dialog, FALSE if replace dialog */ - FINDREPLACE16 *fr16; -}; - -#define LFRPRIVATE struct FRPRIVATE * - -BOOL16 CALLBACK FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, - LPARAM lParam); -BOOL16 CALLBACK ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, - LPARAM lParam); - -/*********************************************************************** - * FINDDLG_Get16BitsTemplate [internal] - * - * Get a template (FALSE if failure) when 16 bits dialogs are used - * by a 16 bits application - * FIXME : no test was done for the user-provided template cases - */ -static BOOL FINDDLG_Get16BitsTemplate(LFRPRIVATE lfr) -{ - LPFINDREPLACE16 fr16 = lfr->fr16; - - if (fr16->Flags & FR_ENABLETEMPLATEHANDLE) - { - lfr->template = GlobalLock16(fr16->hInstance); - if (!lfr->template) - { - COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE); - return FALSE; - } - } - else if (fr16->Flags & FR_ENABLETEMPLATE) - { - HANDLE16 hResInfo; - if (!(hResInfo = FindResource16(fr16->hInstance, - MapSL(fr16->lpTemplateName), - (LPSTR)RT_DIALOG))) - { - COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); - return FALSE; - } - if (!(lfr->hDlgTmpl16 = LoadResource16( fr16->hInstance, hResInfo ))) - { - COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); - return FALSE; - } - lfr->hResource16 = lfr->hDlgTmpl16; - lfr->template = LockResource16(lfr->hResource16); - if (!lfr->template) - { - FreeResource16(lfr->hResource16); - COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE); - return FALSE; - } - } - else - { /* get resource from (32 bits) own Wine resource; convert it to 16 */ - HRSRC hResInfo; - HGLOBAL hDlgTmpl32; - LPCVOID template32; - DWORD size; - HGLOBAL16 hGlobal16; - - if (!(hResInfo = FindResourceA(COMDLG32_hInstance, - lfr->find ? - MAKEINTRESOURCEA(FINDDLGORD):MAKEINTRESOURCEA(REPLACEDLGORD), - (LPSTR)RT_DIALOG))) - { - COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); - return FALSE; - } - if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) || - !(template32 = LockResource( hDlgTmpl32 ))) - { - COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); - return FALSE; - } - size = SizeofResource(COMDLG32_hInstance, hResInfo); - hGlobal16 = GlobalAlloc16(0, size); - if (!hGlobal16) - { - COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE); - ERR("alloc failure for %d bytes\n", size); - return FALSE; - } - lfr->template = GlobalLock16(hGlobal16); - if (!lfr->template) - { - COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE); - ERR("global lock failure for %x handle\n", hGlobal16); - GlobalFree16(hGlobal16); - return FALSE; - } - ConvertDialog32To16(template32, size, (LPVOID)lfr->template); - lfr->hDlgTmpl16 = hGlobal16; - lfr->hGlobal16 = hGlobal16; - } - return TRUE; -} - - -/*********************************************************************** - * FINDDLG_FreeResources [internal] - * - * Free resources allocated - */ -static void FINDDLG_FreeResources(LFRPRIVATE lfr) -{ - /* free resources */ - if (lfr->fr16->Flags & FR_ENABLETEMPLATEHANDLE) - GlobalUnlock16(lfr->fr16->hInstance); - if (lfr->hResource16) - { - GlobalUnlock16(lfr->hResource16); - FreeResource16(lfr->hResource16); - } - if (lfr->hGlobal16) - { - GlobalUnlock16(lfr->hGlobal16); - GlobalFree16(lfr->hGlobal16); - } -} - -/*********************************************************************** - * FindText (COMMDLG.11) - */ -HWND16 WINAPI FindText16( SEGPTR find ) -{ - HANDLE16 hInst; - HWND16 ret = 0; - FARPROC16 ptr; - LFRPRIVATE lfr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct FRPRIVATE)); - - if (!lfr) return 0; - lfr->fr16 = MapSL(find); - lfr->find = TRUE; - if (FINDDLG_Get16BitsTemplate(lfr)) - { - hInst = GetWindowLongPtrA( HWND_32(lfr->fr16->hwndOwner), GWLP_HINSTANCE); - ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 13); - ret = CreateDialogIndirectParam16( hInst, lfr->template, - lfr->fr16->hwndOwner, (DLGPROC16) ptr, find); - FINDDLG_FreeResources(lfr); - } - HeapFree(GetProcessHeap(), 0, lfr); - return ret; -} - - -/*********************************************************************** - * ReplaceText (COMMDLG.12) - */ -HWND16 WINAPI ReplaceText16( SEGPTR find ) -{ - HANDLE16 hInst; - HWND16 ret = 0; - FARPROC16 ptr; - LFRPRIVATE lfr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct FRPRIVATE)); - - if (!lfr) return 0; - /* - * FIXME : We should do error checking on the lpFind structure here - * and make CommDlgExtendedError() return the error condition. - */ - lfr->fr16 = MapSL(find); - lfr->find = FALSE; - if (FINDDLG_Get16BitsTemplate(lfr)) - { - hInst = GetWindowLongPtrA( HWND_32(lfr->fr16->hwndOwner), GWLP_HINSTANCE); - ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 14); - ret = CreateDialogIndirectParam16( hInst, lfr->template, - lfr->fr16->hwndOwner, (DLGPROC16) ptr, find); - - FINDDLG_FreeResources(lfr); - } - HeapFree(GetProcessHeap(), 0, lfr); - return ret; -} +WINE_DEFAULT_DEBUG_CHANNEL(commdlg); /*********************************************************************** * FINDDLG_WMInitDialog [internal] */ static LRESULT FINDDLG_WMInitDialog(HWND hWnd, LPARAM lParam, LPDWORD lpFlags, - LPCSTR lpstrFindWhat, BOOL fUnicode) + LPCSTR lpstrFindWhat) { SetWindowLongPtrW(hWnd, DWLP_USER, lParam); *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM); @@ -237,8 +50,7 @@ static LRESULT FINDDLG_WMInitDialog(HWND hWnd, LPARAM lParam, LPDWORD lpFlags, * FindNext (IDOK) button. Only after typing some text, the button should be * enabled. */ - if (fUnicode) SetDlgItemTextW(hWnd, edt1, (LPCWSTR)lpstrFindWhat); - else SetDlgItemTextA(hWnd, edt1, lpstrFindWhat); + SetDlgItemTextA(hWnd, edt1, lpstrFindWhat); CheckRadioButton(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1); if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) { EnableWindow(GetDlgItem(hWnd, rad1), FALSE); @@ -272,18 +84,15 @@ static LRESULT FINDDLG_WMInitDialog(HWND hWnd, LPARAM lParam, LPDWORD lpFlags, * FINDDLG_WMCommand [internal] */ static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, - HWND hwndOwner, LPDWORD lpFlags, - LPSTR lpstrFindWhat, WORD wFindWhatLen, - BOOL fUnicode) + HWND hwndOwner, LPDWORD lpFlags, + LPSTR lpstrFindWhat, WORD wFindWhatLen) { int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRINGA ); int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRINGA ); - switch (wParam) { + switch (LOWORD(wParam)) { case IDOK: - if (fUnicode) - GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2); - else GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); + GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); if (IsDlgButtonChecked(hWnd, rad2)) *lpFlags |= FR_DOWN; else *lpFlags &= ~FR_DOWN; @@ -314,26 +123,46 @@ static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, } +/*********************************************************************** + * find_text_dlgproc (internal) + */ +static INT_PTR CALLBACK find_text_dlgproc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) +{ + LPFINDREPLACE16 lpfr; + switch (wMsg) + { + case WM_INITDIALOG: + lpfr=MapSL(lParam); + return FINDDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags, MapSL(lpfr->lpstrFindWhat)); + case WM_COMMAND: + lpfr=MapSL(GetWindowLongPtrW(hWnd, DWLP_USER)); + return FINDDLG_WMCommand(hWnd, wParam, HWND_32(lpfr->hwndOwner), + &lpfr->Flags, MapSL(lpfr->lpstrFindWhat), + lpfr->wFindWhatLen); + } + return FALSE; +} + + +/*********************************************************************** + * FindText (COMMDLG.11) + */ +HWND16 WINAPI FindText16( SEGPTR find ) +{ + FINDREPLACE16 *fr16 = MapSL( find ); + + return HWND_16( CreateDialogParamA( GetModuleHandleA("comdlg32.dll"), MAKEINTRESOURCEA(FINDDLGORD), + HWND_32(fr16->hwndOwner), find_text_dlgproc, find )); +} + + /*********************************************************************** * FindTextDlgProc (COMMDLG.13) */ BOOL16 CALLBACK FindTextDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam) { - HWND hWnd = HWND_32(hWnd16); - LPFINDREPLACE16 lpfr; - switch (wMsg) { - case WM_INITDIALOG: - lpfr=MapSL(lParam); - return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags), - MapSL(lpfr->lpstrFindWhat), FALSE); - case WM_COMMAND: - lpfr=MapSL(GetWindowLongPtrW(hWnd, DWLP_USER)); - return FINDDLG_WMCommand(hWnd, wParam, HWND_32(lpfr->hwndOwner), - &lpfr->Flags, MapSL(lpfr->lpstrFindWhat), - lpfr->wFindWhatLen, FALSE); - } - return FALSE; + return find_text_dlgproc( HWND_32(hWnd16), wMsg, wParam, lParam ); } @@ -342,7 +171,7 @@ BOOL16 CALLBACK FindTextDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, */ static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, LPARAM lParam, LPDWORD lpFlags, LPCSTR lpstrFindWhat, - LPCSTR lpstrReplaceWith, BOOL fUnicode) + LPCSTR lpstrReplaceWith) { SetWindowLongPtrW(hWnd, DWLP_USER, lParam); *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM); @@ -351,15 +180,8 @@ static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, LPARAM lParam, * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be * enabled. */ - if (fUnicode) - { - SetDlgItemTextW(hWnd, edt1, (LPCWSTR)lpstrFindWhat); - SetDlgItemTextW(hWnd, edt2, (LPCWSTR)lpstrReplaceWith); - } else - { - SetDlgItemTextA(hWnd, edt1, lpstrFindWhat); - SetDlgItemTextA(hWnd, edt2, lpstrReplaceWith); - } + SetDlgItemTextA(hWnd, edt1, lpstrFindWhat); + SetDlgItemTextA(hWnd, edt2, lpstrReplaceWith); CheckDlgButton(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0); if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD)) EnableWindow(GetDlgItem(hWnd, chx1), FALSE); @@ -382,26 +204,18 @@ static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, LPARAM lParam, /*********************************************************************** * REPLACEDLG_WMCommand [internal] */ -static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, - HWND hwndOwner, LPDWORD lpFlags, - LPSTR lpstrFindWhat, WORD wFindWhatLen, - LPSTR lpstrReplaceWith, WORD wReplaceWithLen, - BOOL fUnicode) +static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM wParam, + HWND hwndOwner, LPDWORD lpFlags, + LPSTR lpstrFindWhat, WORD wFindWhatLen, + LPSTR lpstrReplaceWith, WORD wReplaceWithLen) { int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRINGA ); int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRINGA ); - switch (wParam) { + switch (LOWORD(wParam)) { case IDOK: - if (fUnicode) - { - GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2); - GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2); - } else - { - GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); - GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); - } + GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); + GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); if (IsDlgButtonChecked(hWnd, chx1)) *lpFlags |= FR_WHOLEWORD; else *lpFlags &= ~FR_WHOLEWORD; @@ -421,15 +235,8 @@ static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, DestroyWindow(hWnd); return TRUE; case psh1: - if (fUnicode) - { - GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2); - GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2); - } else - { - GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); - GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); - } + GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); + GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); if (IsDlgButtonChecked(hWnd, chx1)) *lpFlags |= FR_WHOLEWORD; else *lpFlags &= ~FR_WHOLEWORD; @@ -442,15 +249,8 @@ static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, GetWindowLongPtrW(hWnd, DWLP_USER) ); return TRUE; case psh2: - if (fUnicode) - { - GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2); - GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2); - } else - { - GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); - GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); - } + GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen); + GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen); if (IsDlgButtonChecked(hWnd, chx1)) *lpFlags |= FR_WHOLEWORD; else *lpFlags &= ~FR_WHOLEWORD; @@ -472,25 +272,46 @@ static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, /*********************************************************************** - * ReplaceTextDlgProc (COMMDLG.14) + * replace_text_dlgproc */ -BOOL16 CALLBACK ReplaceTextDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, - LPARAM lParam) +static INT_PTR CALLBACK replace_text_dlgproc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { - HWND hWnd = HWND_32(hWnd16); LPFINDREPLACE16 lpfr; - switch (wMsg) { + switch (wMsg) + { case WM_INITDIALOG: lpfr=MapSL(lParam); return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags, MapSL(lpfr->lpstrFindWhat), - MapSL(lpfr->lpstrReplaceWith), FALSE); + MapSL(lpfr->lpstrReplaceWith)); case WM_COMMAND: lpfr=MapSL(GetWindowLongPtrW(hWnd, DWLP_USER)); return REPLACEDLG_WMCommand(hWnd, wParam, HWND_32(lpfr->hwndOwner), &lpfr->Flags, MapSL(lpfr->lpstrFindWhat), lpfr->wFindWhatLen, MapSL(lpfr->lpstrReplaceWith), - lpfr->wReplaceWithLen, FALSE); + lpfr->wReplaceWithLen); } return FALSE; } + + +/*********************************************************************** + * ReplaceText (COMMDLG.12) + */ +HWND16 WINAPI ReplaceText16( SEGPTR find ) +{ + FINDREPLACE16 *fr16 = MapSL( find ); + + return HWND_16( CreateDialogParamA( GetModuleHandleA("comdlg32.dll"), MAKEINTRESOURCEA(REPLACEDLGORD), + HWND_32(fr16->hwndOwner), replace_text_dlgproc, find )); +} + + +/*********************************************************************** + * ReplaceTextDlgProc (COMMDLG.14) + */ +BOOL16 CALLBACK ReplaceTextDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam, + LPARAM lParam) +{ + return replace_text_dlgproc( HWND_32(hWnd16), wMsg, wParam, lParam ); +}