Implement GetTextExtentPointI and add support for ETO_GLYPH_INDEX.
[wine] / dlls / commdlg / finddlg32.c
1 /*
2  *  Common Dialog Boxes interface (32 bit)
3  *  Find/Replace
4  *
5  * Copyright 1998,1999 Bertho A. Stultiens
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <string.h>
23 #include "winbase.h"
24 #include "windef.h"
25 #include "winnls.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "commdlg.h"
29 #include "cderr.h"
30 #include "dlgs.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
34
35 #include "cdlg.h"
36
37
38 /*-----------------------------------------------------------------------*/
39
40 static UINT             FindReplaceMessage;
41 static UINT             HelpMessage;
42
43 #define FR_MASK (FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD | FR_REPLACEALL | FR_REPLACE | FR_FINDNEXT | FR_DIALOGTERM)
44 /* CRITICAL_SECTION COMDLG32_CritSect; */
45
46 /* Notes:
47  * MS uses a critical section at a few locations. However, I fail to
48  * see the reason for this. Their comdlg32.dll has a few race conditions
49  * but _not_ at those places that are protected with the mutex (there are
50  * globals that seem to hold info for the wndproc).
51  *
52  * FindText[AW]/ReplaceText[AW]
53  * The find/replace calls are passed a structure that is _not_ used
54  * internally. There is a local copy that holds the running info to
55  * be able to combine xxxA and xxxW calls. The passed pointer is
56  * returned upon sendmessage. Apps wont break this way when they rely
57  * on the original pointer. This will work as long as the sizes of
58  * FINDREPLACEA == FINDREPLACEW. The local copy will also prevent
59  * the app to see the wine-specific extra flags to distinguish between
60  * A/W and Find/Replace.
61  */
62
63
64 /***********************************************************************
65  *      COMDLG32_FR_GetFlags                    [internal]
66  * Returns the button state that needs to be reported to the caller.
67  *      RETURNS
68  *              Current state of check and radio buttons
69  */
70 static DWORD COMDLG32_FR_GetFlags(HWND hDlgWnd)
71 {
72         DWORD flags = 0;
73         if(IsDlgButtonChecked(hDlgWnd, rad2) == BST_CHECKED)
74                 flags |= FR_DOWN;
75         if(IsDlgButtonChecked(hDlgWnd, chx1) == BST_CHECKED)
76                 flags |= FR_WHOLEWORD;
77         if(IsDlgButtonChecked(hDlgWnd, chx2) == BST_CHECKED)
78                 flags |= FR_MATCHCASE;
79         return flags;
80 }
81
82 /***********************************************************************
83  *      COMDLG32_FR_HandleWMCommand             [internal]
84  * Handle WM_COMMAND messages...
85  */
86 static void COMDLG32_FR_HandleWMCommand(HWND hDlgWnd, COMDLG32_FR_Data *pData, int Id, int NotifyCode)
87 {
88         DWORD flag;
89
90         pData->user_fr.fra->Flags &= ~FR_MASK;  /* Clear return flags */
91         if(pData->fr.Flags & FR_WINE_REPLACE)   /* Replace always goes down... */
92                 pData->user_fr.fra->Flags |= FR_DOWN;
93
94         if(NotifyCode == BN_CLICKED)
95         {
96                 switch(Id)
97                 {
98                 case IDOK: /* Find Next */
99                         if(GetDlgItemTextA(hDlgWnd, edt1, pData->fr.lpstrFindWhat, pData->fr.wFindWhatLen) > 0)
100                         {
101                                 pData->user_fr.fra->Flags |= COMDLG32_FR_GetFlags(hDlgWnd) | FR_FINDNEXT;
102                                 if(pData->fr.Flags & FR_WINE_UNICODE)
103                                 {
104                                     MultiByteToWideChar( CP_ACP, 0, pData->fr.lpstrFindWhat, -1,
105                                                          pData->user_fr.frw->lpstrFindWhat,
106                                                          0x7fffffff );
107                                 }
108                                 else
109                                 {
110                                         strcpy(pData->user_fr.fra->lpstrFindWhat, pData->fr.lpstrFindWhat);
111                                 }
112                                 SendMessageA(pData->fr.hwndOwner, FindReplaceMessage, 0, (LPARAM)pData->user_fr.fra);
113                         }
114                         break;
115
116                 case IDCANCEL:
117                         pData->user_fr.fra->Flags |= COMDLG32_FR_GetFlags(hDlgWnd) | FR_DIALOGTERM;
118                         SendMessageA(pData->fr.hwndOwner, FindReplaceMessage, 0, (LPARAM)pData->user_fr.fra);
119                         DestroyWindow(hDlgWnd);
120                         break;
121
122                 case psh2: /* Replace All */
123                         flag = FR_REPLACEALL;
124                         goto Replace;
125
126                 case psh1: /* Replace */
127                         flag = FR_REPLACE;
128 Replace:
129                         if((pData->fr.Flags & FR_WINE_REPLACE)
130                         && GetDlgItemTextA(hDlgWnd, edt1, pData->fr.lpstrFindWhat, pData->fr.wFindWhatLen) > 0)
131                         {
132                                 pData->fr.lpstrReplaceWith[0] = 0; /* In case the next GetDlgItemText Fails */
133                                 GetDlgItemTextA(hDlgWnd, edt2, pData->fr.lpstrReplaceWith, pData->fr.wReplaceWithLen);
134                                 pData->user_fr.fra->Flags |= COMDLG32_FR_GetFlags(hDlgWnd) | flag;
135                                 if(pData->fr.Flags & FR_WINE_UNICODE)
136                                 {
137                                     MultiByteToWideChar( CP_ACP, 0, pData->fr.lpstrFindWhat, -1,
138                                                          pData->user_fr.frw->lpstrFindWhat,
139                                                          0x7fffffff );
140                                     MultiByteToWideChar( CP_ACP, 0, pData->fr.lpstrReplaceWith, -1,
141                                                          pData->user_fr.frw->lpstrReplaceWith,
142                                                          0x7fffffff );
143                                 }
144                                 else
145                                 {
146                                         strcpy(pData->user_fr.fra->lpstrFindWhat, pData->fr.lpstrFindWhat);
147                                         strcpy(pData->user_fr.fra->lpstrReplaceWith, pData->fr.lpstrReplaceWith);
148                                 }
149                                 SendMessageA(pData->fr.hwndOwner, FindReplaceMessage, 0, (LPARAM)pData->user_fr.fra);
150                         }
151                         break;
152
153                 case pshHelp:
154                         pData->user_fr.fra->Flags |= COMDLG32_FR_GetFlags(hDlgWnd);
155                         SendMessageA(pData->fr.hwndOwner, HelpMessage, (WPARAM)hDlgWnd, (LPARAM)pData->user_fr.fra);
156                         break;
157                 }
158         }
159         else if(NotifyCode == EN_CHANGE && Id == edt1)
160         {
161                 BOOL enable = SendDlgItemMessageA(hDlgWnd, edt1, WM_GETTEXTLENGTH, 0, 0) > 0;
162                 EnableWindow(GetDlgItem(hDlgWnd, IDOK), enable);
163                 if(pData->fr.Flags & FR_WINE_REPLACE)
164                 {
165                         EnableWindow(GetDlgItem(hDlgWnd, psh1), enable);
166                         EnableWindow(GetDlgItem(hDlgWnd, psh2), enable);
167                 }
168         }
169 }
170
171 /***********************************************************************
172  *      COMDLG32_FindReplaceDlgProc             [internal]
173  * [Find/Replace]Text32[A/W] window procedure.
174  */
175 static BOOL CALLBACK COMDLG32_FindReplaceDlgProc(HWND hDlgWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
176 {
177         COMDLG32_FR_Data *pdata = (COMDLG32_FR_Data *)GetPropA(hDlgWnd, (LPSTR)COMDLG32_Atom);
178         BOOL retval = TRUE;;
179
180         if(iMsg == WM_INITDIALOG)
181         {
182                 pdata = (COMDLG32_FR_Data *)lParam;
183                 if(!SetPropA(hDlgWnd, (LPSTR)COMDLG32_Atom, (HANDLE)pdata))
184                 {
185                         ERR("Could not Set prop; invent a gracefull exit?...\n");
186                         DestroyWindow(hDlgWnd);
187                         return FALSE;
188                 }
189                 SendDlgItemMessageA(hDlgWnd, edt1, EM_SETLIMITTEXT, (WPARAM)pdata->fr.wFindWhatLen, 0);
190                 SendDlgItemMessageA(hDlgWnd, edt1, WM_SETTEXT, 0, (LPARAM)pdata->fr.lpstrFindWhat);
191                 if(pdata->fr.Flags & FR_WINE_REPLACE)
192                 {
193                         SendDlgItemMessageA(hDlgWnd, edt2, EM_SETLIMITTEXT, (WPARAM)pdata->fr.wReplaceWithLen, 0);
194                         SendDlgItemMessageA(hDlgWnd, edt2, WM_SETTEXT, 0, (LPARAM)pdata->fr.lpstrReplaceWith);
195                 }
196
197                 if(!(pdata->fr.Flags & FR_SHOWHELP))
198                         ShowWindow(GetDlgItem(hDlgWnd, pshHelp), SW_HIDE);
199                 if(pdata->fr.Flags & FR_HIDEUPDOWN)
200                 {
201                         ShowWindow(GetDlgItem(hDlgWnd, rad1), SW_HIDE);
202                         ShowWindow(GetDlgItem(hDlgWnd, rad2), SW_HIDE);
203                         ShowWindow(GetDlgItem(hDlgWnd, grp1), SW_HIDE);
204                 }
205                 else if(pdata->fr.Flags & FR_NOUPDOWN)
206                 {
207                         EnableWindow(GetDlgItem(hDlgWnd, rad1), FALSE);
208                         EnableWindow(GetDlgItem(hDlgWnd, rad2), FALSE);
209                         EnableWindow(GetDlgItem(hDlgWnd, grp1), FALSE);
210                 }
211                 else
212                 {
213                         SendDlgItemMessageA(hDlgWnd, rad1, BM_SETCHECK, pdata->fr.Flags & FR_DOWN ? 0 : BST_CHECKED, 0);
214                         SendDlgItemMessageA(hDlgWnd, rad2, BM_SETCHECK, pdata->fr.Flags & FR_DOWN ? BST_CHECKED : 0, 0);
215                 }
216
217                 if(pdata->fr.Flags & FR_HIDEMATCHCASE)
218                         ShowWindow(GetDlgItem(hDlgWnd, chx2), SW_HIDE);
219                 else if(pdata->fr.Flags & FR_NOMATCHCASE)
220                         EnableWindow(GetDlgItem(hDlgWnd, chx2), FALSE);
221                 else
222                         SendDlgItemMessageA(hDlgWnd, chx2, BM_SETCHECK, pdata->fr.Flags & FR_MATCHCASE ? BST_CHECKED : 0, 0);
223
224                 if(pdata->fr.Flags & FR_HIDEWHOLEWORD)
225                         ShowWindow(GetDlgItem(hDlgWnd, chx1), SW_HIDE);
226                 else if(pdata->fr.Flags & FR_NOWHOLEWORD)
227                         EnableWindow(GetDlgItem(hDlgWnd, chx1), FALSE);
228                 else
229                         SendDlgItemMessageA(hDlgWnd, chx1, BM_SETCHECK, pdata->fr.Flags & FR_WHOLEWORD ? BST_CHECKED : 0, 0);
230
231                 /* We did the init here, now call the hook if requested */
232
233                 /* We do not do ShowWindow if hook exists and is FALSE  */
234                 /*   per MSDN Article Q96135                            */
235                 if((pdata->fr.Flags & FR_ENABLEHOOK)
236                      && ! pdata->fr.lpfnHook(hDlgWnd, iMsg, wParam, (LPARAM) &pdata->fr))
237                         return TRUE;
238                 ShowWindow(hDlgWnd, SW_SHOWNORMAL);
239                 UpdateWindow(hDlgWnd);
240                 return TRUE;
241         }
242
243         if(pdata && (pdata->fr.Flags & FR_ENABLEHOOK))
244         {
245                 retval = pdata->fr.lpfnHook(hDlgWnd, iMsg, wParam, lParam);
246         }
247         else
248                 retval = FALSE;
249
250         if(pdata && !retval)
251         {
252                 retval = TRUE;
253                 switch(iMsg)
254                 {
255                 case WM_COMMAND:
256                         COMDLG32_FR_HandleWMCommand(hDlgWnd, pdata, LOWORD(wParam), HIWORD(wParam));
257                         break;
258
259                 case WM_CLOSE:
260                         COMDLG32_FR_HandleWMCommand(hDlgWnd, pdata, IDCANCEL, BN_CLICKED);
261                         break;
262
263                 case WM_HELP:
264                         /* Heeeeelp! */
265                         FIXME("Got WM_HELP. Who is gonna supply it?\n");
266                         break;
267
268                 case WM_CONTEXTMENU:
269                         /* Heeeeelp! */
270                         FIXME("Got WM_CONTEXTMENU. Who is gonna supply it?\n");
271                         break;
272                 /* FIXME: Handle F1 help */
273
274                 default:
275                         retval = FALSE; /* We did not handle the message */
276                 }
277         }
278
279         /* WM_DESTROY is a special case.
280          * We need to ensure that the allocated memory is freed just before
281          * the dialog is killed. We also need to remove the added prop.
282          */
283         if(iMsg == WM_DESTROY)
284         {
285                 RemovePropA(hDlgWnd, (LPSTR)COMDLG32_Atom);
286                 HeapFree(GetProcessHeap(), 0, pdata);
287         }
288
289         return retval;
290 }
291
292 /***********************************************************************
293  *      COMDLG32_FR_CheckPartial                [internal]
294  * Check various fault conditions in the supplied parameters that
295  * cause an extended error to be reported.
296  *      RETURNS
297  *              TRUE: Success
298  *              FALSE: Failure
299  */
300 static BOOL COMDLG32_FR_CheckPartial(
301         LPFINDREPLACEA pfr,     /* [in] Find structure */
302         BOOL Replace            /* [in] True if called as replace */
303 ) {
304         if(!pfr)
305         {
306                 COMDLG32_SetCommDlgExtendedError(CDERR_GENERALCODES);
307                 return FALSE;
308         }
309
310         if(pfr->lStructSize != sizeof(FINDREPLACEA))
311         {
312                 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
313                 return FALSE;
314         }
315
316         if(!IsWindow(pfr->hwndOwner))
317         {
318                 COMDLG32_SetCommDlgExtendedError(CDERR_DIALOGFAILURE);
319                 return FALSE;
320         }
321
322         if((pfr->wFindWhatLen < 1 || !pfr->lpstrFindWhat)
323         ||(Replace && (pfr->wReplaceWithLen < 1 || !pfr->lpstrReplaceWith)))
324         {
325                 COMDLG32_SetCommDlgExtendedError(FRERR_BUFFERLENGTHZERO);
326                 return FALSE;
327         }
328
329         if((FindReplaceMessage = RegisterWindowMessageA(FINDMSGSTRINGA)) == 0)
330         {
331                 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
332                 return FALSE;
333         }
334         if((HelpMessage = RegisterWindowMessageA(HELPMSGSTRINGA)) == 0)
335         {
336                 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
337                 return FALSE;
338         }
339
340         if((pfr->Flags & FR_ENABLEHOOK) && !pfr->lpfnHook)
341         {
342                 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
343                 return FALSE;
344         }
345
346         if((pfr->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE)) && !pfr->hInstance)
347         {
348                 COMDLG32_SetCommDlgExtendedError(CDERR_NOHINSTANCE);
349                 return FALSE;
350         }
351
352         if((pfr->Flags & FR_ENABLETEMPLATE) && !pfr->lpTemplateName)
353         {
354                 COMDLG32_SetCommDlgExtendedError(CDERR_NOTEMPLATE);
355                 return FALSE;
356         }
357
358         return TRUE;
359 }
360
361 /***********************************************************************
362  *      COMDLG32_FR_DoFindReplace               [internal]
363  * Actual load and creation of the Find/Replace dialog.
364  *      RETURNS
365  *              Window handle to created dialog:Success
366  *              NULL:Failure
367  */
368 static HWND COMDLG32_FR_DoFindReplace(
369         COMDLG32_FR_Data *pdata /* [in] Internal data structure */
370 ) {
371         HWND hdlgwnd = 0;
372         HGLOBAL loadrc;
373         DWORD error;
374         LPDLGTEMPLATEW rcs;
375
376         TRACE("hInst=%08x, Flags=%08lx\n", pdata->fr.hInstance, pdata->fr.Flags);
377
378         if(!(pdata->fr.Flags & FR_ENABLETEMPLATEHANDLE))
379         {
380                 HMODULE hmod = COMDLG32_hInstance;
381                 HRSRC htemplate;
382                 if(pdata->fr.Flags & FR_ENABLETEMPLATE)
383                 {
384                         hmod = (HMODULE)pdata->fr.hInstance;
385                         if(pdata->fr.Flags & FR_WINE_UNICODE)
386                         {
387                                 htemplate = FindResourceW(hmod, (LPWSTR)pdata->fr.lpTemplateName, (LPWSTR)RT_DIALOGA);
388                         }
389                         else
390                         {
391                                 htemplate = FindResourceA(hmod, pdata->fr.lpTemplateName, (LPCSTR)RT_DIALOGA);
392                         }
393                 }
394                 else
395                 {
396                         int rcid = pdata->fr.Flags & FR_WINE_REPLACE ? REPLACEDLGORD
397                                                                      : FINDDLGORD;
398                         htemplate = FindResourceA(hmod, MAKEINTRESOURCEA(rcid), (LPCSTR)RT_DIALOGA);
399                 }
400                 if(!htemplate)
401                 {
402                         error = CDERR_FINDRESFAILURE;
403                         goto cleanup;
404                 }
405
406                 loadrc = LoadResource(hmod, htemplate);
407         }
408         else
409         {
410                 loadrc = (HGLOBAL)pdata->fr.hInstance;
411         }
412
413         if(!loadrc)
414         {
415                 error = CDERR_LOADRESFAILURE;
416                 goto cleanup;
417         }
418
419         if((rcs = (LPDLGTEMPLATEW)LockResource(loadrc)) == NULL)
420         {
421                 error = CDERR_LOCKRESFAILURE;
422                 goto cleanup;
423         }
424
425         hdlgwnd = CreateDialogIndirectParamA(COMDLG32_hInstance,
426                                              rcs,
427                                              pdata->fr.hwndOwner,
428                                              (DLGPROC)COMDLG32_FindReplaceDlgProc,
429                                              (LPARAM)pdata);
430         if(!hdlgwnd)
431         {
432                 error = CDERR_DIALOGFAILURE;
433 cleanup:
434                 COMDLG32_SetCommDlgExtendedError(error);
435                 HeapFree(GetProcessHeap(), 0, pdata);
436         }
437         return hdlgwnd;
438 }
439
440 /***********************************************************************
441  *      FindTextA                               [COMDLG32.@]
442  *      RETURNS
443  *              Window handle to created dialog: Success
444  *              NULL: Failure
445  */
446 HWND WINAPI FindTextA(
447         LPFINDREPLACEA pfr      /* [in] Find/replace structure*/
448 ) {
449         COMDLG32_FR_Data *pdata;
450
451         TRACE("LPFINDREPLACE=%p\n", pfr);
452
453         if(!COMDLG32_FR_CheckPartial(pfr, FALSE))
454                 return 0;
455
456         if((pdata = (COMDLG32_FR_Data *)COMDLG32_AllocMem(sizeof(COMDLG32_FR_Data))) == NULL)
457                 return 0; /* Error has been set */
458
459         pdata->user_fr.fra = pfr;
460         pdata->fr = *pfr;
461         return COMDLG32_FR_DoFindReplace(pdata);
462 }
463
464 /***********************************************************************
465  *      ReplaceTextA                            [COMDLG32.@]
466  *      RETURNS
467  *              Window handle to created dialog: Success
468  *              NULL: Failure
469  */
470 HWND WINAPI ReplaceTextA(
471         LPFINDREPLACEA pfr      /* [in] Find/replace structure*/
472 ) {
473         COMDLG32_FR_Data *pdata;
474
475         TRACE("LPFINDREPLACE=%p\n", pfr);
476
477         if(!COMDLG32_FR_CheckPartial(pfr, TRUE))
478                 return 0;
479
480         if((pdata = (COMDLG32_FR_Data *)COMDLG32_AllocMem(sizeof(COMDLG32_FR_Data))) == NULL)
481                 return 0; /* Error has been set */
482
483         pdata->user_fr.fra = pfr;
484         pdata->fr = *pfr;
485         pdata->fr.Flags |= FR_WINE_REPLACE;
486         return COMDLG32_FR_DoFindReplace(pdata);
487 }
488
489 /***********************************************************************
490  *      FindTextW                               [COMDLG32.@]
491  *      RETURNS
492  *              Window handle to created dialog: Success
493  *              NULL: Failure
494  */
495 HWND WINAPI FindTextW(
496         LPFINDREPLACEW pfr      /* [in] Find/replace structure*/
497 ) {
498         COMDLG32_FR_Data *pdata;
499         DWORD len;
500
501         TRACE("LPFINDREPLACE=%p\n", pfr);
502
503         if(!COMDLG32_FR_CheckPartial((LPFINDREPLACEA)pfr, FALSE))
504                 return 0;
505
506         len = WideCharToMultiByte( CP_ACP, 0, pfr->lpstrFindWhat, pfr->wFindWhatLen,
507                                    NULL, 0, NULL, NULL );
508         if((pdata = (COMDLG32_FR_Data *)COMDLG32_AllocMem(sizeof(COMDLG32_FR_Data) + len)) == NULL)
509             return 0; /* Error has been set */
510
511         pdata->user_fr.frw = pfr;
512         pdata->fr = *(LPFINDREPLACEA)pfr;       /* FINDREPLACEx have same size */
513         pdata->fr.Flags |= FR_WINE_UNICODE;
514         pdata->fr.lpstrFindWhat = (LPSTR)(pdata + 1);  /* Set string pointer */
515         WideCharToMultiByte( CP_ACP, 0, pfr->lpstrFindWhat, pfr->wFindWhatLen,
516                              pdata->fr.lpstrFindWhat, len, NULL, NULL );
517         return COMDLG32_FR_DoFindReplace(pdata);
518 }
519
520 /***********************************************************************
521  *      ReplaceTextW                            [COMDLG32.@]
522  *      RETURNS
523  *              Window handle to created dialog: Success
524  *              NULL: Failure
525  */
526 HWND WINAPI ReplaceTextW(
527         LPFINDREPLACEW pfr      /* [in] Find/replace structure*/
528 ) {
529         COMDLG32_FR_Data *pdata;
530         DWORD len1, len2;
531
532         TRACE("LPFINDREPLACE=%p\n", pfr);
533
534         if(!COMDLG32_FR_CheckPartial((LPFINDREPLACEA)pfr, FALSE))
535                 return 0;
536
537         len1 = WideCharToMultiByte( CP_ACP, 0, pfr->lpstrFindWhat, pfr->wFindWhatLen,
538                                     NULL, 0, NULL, NULL );
539         len2 = WideCharToMultiByte( CP_ACP, 0, pfr->lpstrReplaceWith, pfr->wReplaceWithLen,
540                                     NULL, 0, NULL, NULL );
541         if((pdata = (COMDLG32_FR_Data *)COMDLG32_AllocMem(sizeof(COMDLG32_FR_Data)
542                                                           + len1 + len2)) == NULL)
543             return 0; /* Error has been set */
544
545         pdata->user_fr.frw = pfr;
546         pdata->fr = *(LPFINDREPLACEA)pfr;       /* FINDREPLACEx have same size */
547         pdata->fr.Flags |= FR_WINE_REPLACE | FR_WINE_UNICODE;
548         pdata->fr.lpstrFindWhat = (LPSTR)(pdata + 1);  /* Set string pointer */
549         pdata->fr.lpstrReplaceWith = pdata->fr.lpstrFindWhat + len1;
550
551         WideCharToMultiByte( CP_ACP, 0, pfr->lpstrFindWhat, pfr->wFindWhatLen,
552                              pdata->fr.lpstrFindWhat, len1, NULL, NULL );
553         WideCharToMultiByte( CP_ACP, 0, pfr->lpstrReplaceWith, pfr->wReplaceWithLen,
554                              pdata->fr.lpstrReplaceWith, len2, NULL, NULL );
555         return COMDLG32_FR_DoFindReplace(pdata);
556 }
557
558