2 * COMMDLG - Find & Replace Text Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg
)
28 /***********************************************************************
29 * FindText16 (COMMDLG.11)
31 HWND16 WINAPI
FindText16( SEGPTR find
)
35 HANDLE hResInfo
, hDlgTmpl
;
36 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
39 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
40 * For now, only the standard dialog works.
42 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
43 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
44 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, MAKEINTRESOURCEA(FINDDLGORD
), RT_DIALOGA
)))
46 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
49 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
50 !(ptr
= LockResource( hDlgTmpl
)))
52 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
55 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
56 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
57 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
62 /***********************************************************************
63 * ReplaceText16 (COMMDLG.12)
65 HWND16 WINAPI
ReplaceText16( SEGPTR find
)
69 HANDLE hResInfo
, hDlgTmpl
;
70 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
73 * FIXME : We should do error checking on the lpFind structure here
74 * and make CommDlgExtendedError() return the error condition.
76 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
77 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
78 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, MAKEINTRESOURCEA(REPLACEDLGORD
), RT_DIALOGA
)))
80 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
83 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
84 !(ptr
= LockResource( hDlgTmpl
)))
86 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
89 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
90 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
91 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
96 /***********************************************************************
97 * FINDDLG_WMInitDialog [internal]
99 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
, LPDWORD lpFlags
,
100 LPSTR lpstrFindWhat
, BOOL fUnicode
)
102 SetWindowLongA(hWnd
, DWL_USER
, lParam
);
103 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
105 * FIXME : If the initial FindWhat string is empty, we should disable the
106 * FindNext (IDOK) button. Only after typing some text, the button should be
109 if (fUnicode
) SetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
110 else SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
111 CheckRadioButton(hWnd
, rad1
, rad2
, (*lpFlags
& FR_DOWN
) ? rad2
: rad1
);
112 if (*lpFlags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
113 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
114 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
116 if (*lpFlags
& FR_HIDEUPDOWN
) {
117 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
118 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
119 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
121 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
122 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
123 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
124 if (*lpFlags
& FR_HIDEWHOLEWORD
)
125 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
126 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
127 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
128 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
129 if (*lpFlags
& FR_HIDEMATCHCASE
)
130 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
131 if (!(*lpFlags
& FR_SHOWHELP
)) {
132 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
133 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
135 ShowWindow(hWnd
, SW_SHOWNORMAL
);
140 /***********************************************************************
141 * FINDDLG_WMCommand [internal]
143 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
,
144 HWND hwndOwner
, LPDWORD lpFlags
,
145 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
148 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRING
);
149 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRING
);
154 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
155 else GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
156 if (IsDlgButtonChecked(hWnd
, rad2
))
158 else *lpFlags
&= ~FR_DOWN
;
159 if (IsDlgButtonChecked(hWnd
, chx1
))
160 *lpFlags
|= FR_WHOLEWORD
;
161 else *lpFlags
&= ~FR_WHOLEWORD
;
162 if (IsDlgButtonChecked(hWnd
, chx2
))
163 *lpFlags
|= FR_MATCHCASE
;
164 else *lpFlags
&= ~FR_MATCHCASE
;
165 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
166 *lpFlags
|= FR_FINDNEXT
;
167 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
168 GetWindowLongA(hWnd
, DWL_USER
) );
171 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
172 *lpFlags
|= FR_DIALOGTERM
;
173 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
174 GetWindowLongA(hWnd
, DWL_USER
) );
178 /* FIXME : should lpfr structure be passed as an argument ??? */
179 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
186 /***********************************************************************
187 * FindTextDlgProc16 (COMMDLG.13)
189 LRESULT WINAPI
FindTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
192 LPFINDREPLACE16 lpfr
;
195 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
196 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
197 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
), FALSE
);
199 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLongA(hWnd
, DWL_USER
));
200 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
201 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
202 lpfr
->wFindWhatLen
, FALSE
);
208 /***********************************************************************
209 * REPLACEDLG_WMInitDialog [internal]
211 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
,
212 LPDWORD lpFlags
, LPSTR lpstrFindWhat
,
213 LPSTR lpstrReplaceWith
, BOOL fUnicode
)
215 SetWindowLongA(hWnd
, DWL_USER
, lParam
);
216 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
218 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
219 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
224 SetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
225 SetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
);
228 SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
229 SetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
);
231 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
232 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
233 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
234 if (*lpFlags
& FR_HIDEWHOLEWORD
)
235 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
236 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
237 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
238 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
239 if (*lpFlags
& FR_HIDEMATCHCASE
)
240 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
241 if (!(*lpFlags
& FR_SHOWHELP
)) {
242 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
243 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
245 ShowWindow(hWnd
, SW_SHOWNORMAL
);
250 /***********************************************************************
251 * REPLACEDLG_WMCommand [internal]
253 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
,
254 HWND hwndOwner
, LPDWORD lpFlags
,
255 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
256 LPSTR lpstrReplaceWith
, WORD wReplaceWithLen
,
259 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRING
);
260 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRING
);
266 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
267 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
270 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
271 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
273 if (IsDlgButtonChecked(hWnd
, chx1
))
274 *lpFlags
|= FR_WHOLEWORD
;
275 else *lpFlags
&= ~FR_WHOLEWORD
;
276 if (IsDlgButtonChecked(hWnd
, chx2
))
277 *lpFlags
|= FR_MATCHCASE
;
278 else *lpFlags
&= ~FR_MATCHCASE
;
279 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
280 *lpFlags
|= FR_FINDNEXT
;
281 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
282 GetWindowLongA(hWnd
, DWL_USER
) );
285 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
286 *lpFlags
|= FR_DIALOGTERM
;
287 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
288 GetWindowLongA(hWnd
, DWL_USER
) );
294 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
295 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
298 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
299 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
301 if (IsDlgButtonChecked(hWnd
, chx1
))
302 *lpFlags
|= FR_WHOLEWORD
;
303 else *lpFlags
&= ~FR_WHOLEWORD
;
304 if (IsDlgButtonChecked(hWnd
, chx2
))
305 *lpFlags
|= FR_MATCHCASE
;
306 else *lpFlags
&= ~FR_MATCHCASE
;
307 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
308 *lpFlags
|= FR_REPLACE
;
309 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
310 GetWindowLongA(hWnd
, DWL_USER
) );
315 GetDlgItemTextW(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
316 GetDlgItemTextW(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
319 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
320 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
322 if (IsDlgButtonChecked(hWnd
, chx1
))
323 *lpFlags
|= FR_WHOLEWORD
;
324 else *lpFlags
&= ~FR_WHOLEWORD
;
325 if (IsDlgButtonChecked(hWnd
, chx2
))
326 *lpFlags
|= FR_MATCHCASE
;
327 else *lpFlags
&= ~FR_MATCHCASE
;
328 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
329 *lpFlags
|= FR_REPLACEALL
;
330 SendMessageA(hwndOwner
, uFindReplaceMessage
, 0,
331 GetWindowLongA(hWnd
, DWL_USER
) );
334 /* FIXME : should lpfr structure be passed as an argument ??? */
335 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
342 /***********************************************************************
343 * ReplaceTextDlgProc16 (COMMDLG.14)
345 LRESULT WINAPI
ReplaceTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
348 LPFINDREPLACE16 lpfr
;
351 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
352 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
353 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
354 PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
), FALSE
);
356 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLongA(hWnd
, DWL_USER
));
357 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
358 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
359 lpfr
->wFindWhatLen
, PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
),
360 lpfr
->wReplaceWithLen
, FALSE
);