2 * COMMDLG - Find & Replace Text Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg
)
27 /***********************************************************************
28 * FindText16 (COMMDLG.11)
30 HWND16 WINAPI
FindText16( SEGPTR find
)
34 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
37 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
38 * For now, only the standard dialog works.
40 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
41 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
42 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
43 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
44 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
45 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
49 /***********************************************************************
50 * FindText32A (COMMDLG.6)
52 HWND WINAPI
FindTextA( LPFINDREPLACEA lpFind
)
58 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
59 * For now, only the standard dialog works.
61 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
62 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
63 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
64 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
65 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
66 (DLGPROC16
)FindTextDlgProcA
, (LPARAM
)lpFind
, WIN_PROC_32A
);
69 /***********************************************************************
70 * FindText32W (COMMDLG.7)
72 HWND WINAPI
FindTextW( LPFINDREPLACEW lpFind
)
78 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
79 * For now, only the standard dialog works.
81 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
82 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
83 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
84 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
85 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
86 (DLGPROC16
)FindTextDlgProcW
, (LPARAM
)lpFind
, WIN_PROC_32W
);
89 /***********************************************************************
90 * ReplaceText16 (COMMDLG.12)
92 HWND16 WINAPI
ReplaceText16( SEGPTR find
)
96 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
99 * FIXME : We should do error checking on the lpFind structure here
100 * and make CommDlgExtendedError() return the error condition.
102 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
103 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
104 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
105 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
106 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
107 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
111 /***********************************************************************
112 * ReplaceText32A (COMDLG32.19)
114 HWND WINAPI
ReplaceTextA( LPFINDREPLACEA lpFind
)
120 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
121 * For now, only the standard dialog works.
123 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
124 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
125 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
126 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
127 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
128 (DLGPROC16
)ReplaceTextDlgProcA
, (LPARAM
)lpFind
, WIN_PROC_32A
);
131 /***********************************************************************
132 * ReplaceText32W (COMDLG32.20)
134 HWND WINAPI
ReplaceTextW( LPFINDREPLACEW lpFind
)
140 * FIXME : We should do error checking on the lpFind structure here
141 * and make CommDlgExtendedError() return the error condition.
143 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
144 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
145 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
146 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
147 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
148 (DLGPROC16
)ReplaceTextDlgProcW
, (LPARAM
)lpFind
, WIN_PROC_32W
);
152 /***********************************************************************
153 * FINDDLG_WMInitDialog [internal]
155 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
, LPDWORD lpFlags
,
156 LPSTR lpstrFindWhat
, BOOL fUnicode
)
158 SetWindowLongA(hWnd
, DWL_USER
, lParam
);
159 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
161 * FIXME : If the initial FindWhat string is empty, we should disable the
162 * FindNext (IDOK) button. Only after typing some text, the button should be
165 if (fUnicode
) SetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
166 else SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
167 CheckRadioButton(hWnd
, rad1
, rad2
, (*lpFlags
& FR_DOWN
) ? rad2
: rad1
);
168 if (*lpFlags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
169 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
170 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
172 if (*lpFlags
& FR_HIDEUPDOWN
) {
173 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
174 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
175 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
177 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
178 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
179 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
180 if (*lpFlags
& FR_HIDEWHOLEWORD
)
181 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
182 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
183 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
184 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
185 if (*lpFlags
& FR_HIDEMATCHCASE
)
186 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
187 if (!(*lpFlags
& FR_SHOWHELP
)) {
188 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
189 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
191 ShowWindow(hWnd
, SW_SHOWNORMAL
);
196 /***********************************************************************
197 * FINDDLG_WMCommand [internal]
199 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
,
200 HWND hwndOwner
, LPDWORD lpFlags
,
201 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
204 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRING
);
205 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRING
);
210 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
211 else GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
212 if (IsDlgButtonChecked(hWnd
, rad2
))
214 else *lpFlags
&= ~FR_DOWN
;
215 if (IsDlgButtonChecked(hWnd
, chx1
))
216 *lpFlags
|= FR_WHOLEWORD
;
217 else *lpFlags
&= ~FR_WHOLEWORD
;
218 if (IsDlgButtonChecked(hWnd
, chx2
))
219 *lpFlags
|= FR_MATCHCASE
;
220 else *lpFlags
&= ~FR_MATCHCASE
;
221 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
222 *lpFlags
|= FR_FINDNEXT
;
223 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
224 GetWindowLongA(hWnd
, DWL_USER
) );
227 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
228 *lpFlags
|= FR_DIALOGTERM
;
229 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
230 GetWindowLongA(hWnd
, DWL_USER
) );
234 /* FIXME : should lpfr structure be passed as an argument ??? */
235 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
242 /***********************************************************************
243 * FindTextDlgProc16 (COMMDLG.13)
245 LRESULT WINAPI
FindTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
248 LPFINDREPLACE16 lpfr
;
251 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
252 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
253 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
), FALSE
);
255 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLongA(hWnd
, DWL_USER
));
256 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
257 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
258 lpfr
->wFindWhatLen
, FALSE
);
263 /***********************************************************************
266 LRESULT WINAPI
FindTextDlgProcA(HWND hWnd
, UINT wMsg
, WPARAM wParam
,
272 lpfr
=(LPFINDREPLACEA
)lParam
;
273 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
274 lpfr
->lpstrFindWhat
, FALSE
);
276 lpfr
=(LPFINDREPLACEA
)GetWindowLongA(hWnd
, DWL_USER
);
277 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
278 &lpfr
->Flags
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
284 /***********************************************************************
287 LRESULT WINAPI
FindTextDlgProcW(HWND hWnd
, UINT wMsg
, WPARAM wParam
,
293 lpfr
=(LPFINDREPLACEW
)lParam
;
294 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
295 (LPSTR
)lpfr
->lpstrFindWhat
, TRUE
);
297 lpfr
=(LPFINDREPLACEW
)GetWindowLongA(hWnd
, DWL_USER
);
298 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
299 &lpfr
->Flags
, (LPSTR
)lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
306 /***********************************************************************
307 * REPLACEDLG_WMInitDialog [internal]
309 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
,
310 LPDWORD lpFlags
, LPSTR lpstrFindWhat
,
311 LPSTR lpstrReplaceWith
, BOOL fUnicode
)
313 SetWindowLongA(hWnd
, DWL_USER
, lParam
);
314 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
316 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
317 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
322 SetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
323 SetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
);
326 SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
327 SetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
);
329 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
330 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
331 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
332 if (*lpFlags
& FR_HIDEWHOLEWORD
)
333 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
334 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
335 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
336 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
337 if (*lpFlags
& FR_HIDEMATCHCASE
)
338 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
339 if (!(*lpFlags
& FR_SHOWHELP
)) {
340 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
341 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
343 ShowWindow(hWnd
, SW_SHOWNORMAL
);
348 /***********************************************************************
349 * REPLACEDLG_WMCommand [internal]
351 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
,
352 HWND hwndOwner
, LPDWORD lpFlags
,
353 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
354 LPSTR lpstrReplaceWith
, WORD wReplaceWithLen
,
357 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRING
);
358 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRING
);
364 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
365 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
368 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
369 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
371 if (IsDlgButtonChecked(hWnd
, chx1
))
372 *lpFlags
|= FR_WHOLEWORD
;
373 else *lpFlags
&= ~FR_WHOLEWORD
;
374 if (IsDlgButtonChecked(hWnd
, chx2
))
375 *lpFlags
|= FR_MATCHCASE
;
376 else *lpFlags
&= ~FR_MATCHCASE
;
377 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
378 *lpFlags
|= FR_FINDNEXT
;
379 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
380 GetWindowLongA(hWnd
, DWL_USER
) );
383 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
384 *lpFlags
|= FR_DIALOGTERM
;
385 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
386 GetWindowLongA(hWnd
, DWL_USER
) );
392 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
393 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
396 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
397 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
399 if (IsDlgButtonChecked(hWnd
, chx1
))
400 *lpFlags
|= FR_WHOLEWORD
;
401 else *lpFlags
&= ~FR_WHOLEWORD
;
402 if (IsDlgButtonChecked(hWnd
, chx2
))
403 *lpFlags
|= FR_MATCHCASE
;
404 else *lpFlags
&= ~FR_MATCHCASE
;
405 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
406 *lpFlags
|= FR_REPLACE
;
407 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
408 GetWindowLongA(hWnd
, DWL_USER
) );
413 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
414 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
417 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
418 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
420 if (IsDlgButtonChecked(hWnd
, chx1
))
421 *lpFlags
|= FR_WHOLEWORD
;
422 else *lpFlags
&= ~FR_WHOLEWORD
;
423 if (IsDlgButtonChecked(hWnd
, chx2
))
424 *lpFlags
|= FR_MATCHCASE
;
425 else *lpFlags
&= ~FR_MATCHCASE
;
426 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
427 *lpFlags
|= FR_REPLACEALL
;
428 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
429 GetWindowLongA(hWnd
, DWL_USER
) );
432 /* FIXME : should lpfr structure be passed as an argument ??? */
433 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
440 /***********************************************************************
441 * ReplaceTextDlgProc16 (COMMDLG.14)
443 LRESULT WINAPI
ReplaceTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
446 LPFINDREPLACE16 lpfr
;
449 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
450 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
451 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
452 PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
), FALSE
);
454 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLongA(hWnd
, DWL_USER
));
455 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
456 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
457 lpfr
->wFindWhatLen
, PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
),
458 lpfr
->wReplaceWithLen
, FALSE
);
463 /***********************************************************************
464 * ReplaceTextDlgProc32A
466 LRESULT WINAPI
ReplaceTextDlgProcA(HWND hWnd
, UINT wMsg
, WPARAM wParam
,
472 lpfr
=(LPFINDREPLACEA
)lParam
;
473 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
474 lpfr
->lpstrFindWhat
, lpfr
->lpstrReplaceWith
, FALSE
);
476 lpfr
=(LPFINDREPLACEA
)GetWindowLongA(hWnd
, DWL_USER
);
477 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
478 &lpfr
->Flags
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
479 lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
, FALSE
);
484 /***********************************************************************
485 * ReplaceTextDlgProc32W
487 LRESULT WINAPI
ReplaceTextDlgProcW(HWND hWnd
, UINT wMsg
, WPARAM wParam
,
493 lpfr
=(LPFINDREPLACEW
)lParam
;
494 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
495 (LPSTR
)lpfr
->lpstrFindWhat
, (LPSTR
)lpfr
->lpstrReplaceWith
,
498 lpfr
=(LPFINDREPLACEW
)GetWindowLongA(hWnd
, DWL_USER
);
499 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
500 &lpfr
->Flags
, (LPSTR
)lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
501 (LPSTR
)lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
, TRUE
);