2 * COMMDLG - Find & Replace Text Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
19 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(commdlg)
27 /***********************************************************************
28 * FindText16 (COMMDLG.11)
30 HWND16 WINAPI FindText16( SEGPTR find )
34 HANDLE hResInfo, hDlgTmpl;
35 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
38 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
39 * For now, only the standard dialog works.
41 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
42 FR_ENABLEHOOK)) FIXME(": unimplemented flag (ignored)\n");
43 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, MAKEINTRESOURCEA(FINDDLGORD), RT_DIALOGA)))
45 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
48 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
49 !(ptr = LockResource( hDlgTmpl )))
51 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
54 hInst = GetWindowLongA( lpFind->hwndOwner , GWL_HINSTANCE);
55 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
56 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
61 /***********************************************************************
62 * ReplaceText16 (COMMDLG.12)
64 HWND16 WINAPI ReplaceText16( SEGPTR find )
68 HANDLE hResInfo, hDlgTmpl;
69 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
72 * FIXME : We should do error checking on the lpFind structure here
73 * and make CommDlgExtendedError() return the error condition.
75 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
76 FR_ENABLEHOOK)) FIXME(": unimplemented flag (ignored)\n");
77 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, MAKEINTRESOURCEA(REPLACEDLGORD), RT_DIALOGA)))
79 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
82 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
83 !(ptr = LockResource( hDlgTmpl )))
85 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
88 hInst = GetWindowLongA( lpFind->hwndOwner , GWL_HINSTANCE);
89 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
90 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
95 /***********************************************************************
96 * FINDDLG_WMInitDialog [internal]
98 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, LPARAM lParam, LPDWORD lpFlags,
99 LPSTR lpstrFindWhat, BOOL fUnicode)
101 SetWindowLongA(hWnd, DWL_USER, lParam);
102 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
104 * FIXME : If the initial FindWhat string is empty, we should disable the
105 * FindNext (IDOK) button. Only after typing some text, the button should be
108 if (fUnicode) SetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat);
109 else SetDlgItemTextA(hWnd, edt1, lpstrFindWhat);
110 CheckRadioButton(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
111 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
112 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
113 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
115 if (*lpFlags & FR_HIDEUPDOWN) {
116 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
117 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
118 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
120 CheckDlgButton(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
121 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
122 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
123 if (*lpFlags & FR_HIDEWHOLEWORD)
124 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
125 CheckDlgButton(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
126 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
127 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
128 if (*lpFlags & FR_HIDEMATCHCASE)
129 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
130 if (!(*lpFlags & FR_SHOWHELP)) {
131 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
132 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
134 ShowWindow(hWnd, SW_SHOWNORMAL);
139 /***********************************************************************
140 * FINDDLG_WMCommand [internal]
142 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam,
143 HWND hwndOwner, LPDWORD lpFlags,
144 LPSTR lpstrFindWhat, WORD wFindWhatLen,
147 int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRING );
148 int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRING );
153 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
154 else GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
155 if (IsDlgButtonChecked(hWnd, rad2))
157 else *lpFlags &= ~FR_DOWN;
158 if (IsDlgButtonChecked(hWnd, chx1))
159 *lpFlags |= FR_WHOLEWORD;
160 else *lpFlags &= ~FR_WHOLEWORD;
161 if (IsDlgButtonChecked(hWnd, chx2))
162 *lpFlags |= FR_MATCHCASE;
163 else *lpFlags &= ~FR_MATCHCASE;
164 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
165 *lpFlags |= FR_FINDNEXT;
166 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
167 GetWindowLongA(hWnd, DWL_USER) );
170 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
171 *lpFlags |= FR_DIALOGTERM;
172 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
173 GetWindowLongA(hWnd, DWL_USER) );
177 /* FIXME : should lpfr structure be passed as an argument ??? */
178 SendMessageA(hwndOwner, uHelpMessage, 0, 0);
185 /***********************************************************************
186 * FindTextDlgProc16 (COMMDLG.13)
188 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
191 LPFINDREPLACE16 lpfr;
194 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
195 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
196 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
198 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLongA(hWnd, DWL_USER));
199 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
200 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
201 lpfr->wFindWhatLen, FALSE);
207 /***********************************************************************
208 * REPLACEDLG_WMInitDialog [internal]
210 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, LPARAM lParam,
211 LPDWORD lpFlags, LPSTR lpstrFindWhat,
212 LPSTR lpstrReplaceWith, BOOL fUnicode)
214 SetWindowLongA(hWnd, DWL_USER, lParam);
215 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
217 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
218 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
223 SetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat);
224 SetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
227 SetDlgItemTextA(hWnd, edt1, lpstrFindWhat);
228 SetDlgItemTextA(hWnd, edt2, lpstrReplaceWith);
230 CheckDlgButton(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
231 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
232 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
233 if (*lpFlags & FR_HIDEWHOLEWORD)
234 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
235 CheckDlgButton(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
236 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
237 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
238 if (*lpFlags & FR_HIDEMATCHCASE)
239 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
240 if (!(*lpFlags & FR_SHOWHELP)) {
241 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
242 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
244 ShowWindow(hWnd, SW_SHOWNORMAL);
249 /***********************************************************************
250 * REPLACEDLG_WMCommand [internal]
252 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam,
253 HWND hwndOwner, LPDWORD lpFlags,
254 LPSTR lpstrFindWhat, WORD wFindWhatLen,
255 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
258 int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRING );
259 int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRING );
265 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
266 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
269 GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
270 GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
272 if (IsDlgButtonChecked(hWnd, chx1))
273 *lpFlags |= FR_WHOLEWORD;
274 else *lpFlags &= ~FR_WHOLEWORD;
275 if (IsDlgButtonChecked(hWnd, chx2))
276 *lpFlags |= FR_MATCHCASE;
277 else *lpFlags &= ~FR_MATCHCASE;
278 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
279 *lpFlags |= FR_FINDNEXT;
280 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
281 GetWindowLongA(hWnd, DWL_USER) );
284 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
285 *lpFlags |= FR_DIALOGTERM;
286 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
287 GetWindowLongA(hWnd, DWL_USER) );
293 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
294 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
297 GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
298 GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
300 if (IsDlgButtonChecked(hWnd, chx1))
301 *lpFlags |= FR_WHOLEWORD;
302 else *lpFlags &= ~FR_WHOLEWORD;
303 if (IsDlgButtonChecked(hWnd, chx2))
304 *lpFlags |= FR_MATCHCASE;
305 else *lpFlags &= ~FR_MATCHCASE;
306 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
307 *lpFlags |= FR_REPLACE;
308 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
309 GetWindowLongA(hWnd, DWL_USER) );
314 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
315 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
318 GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
319 GetDlgItemTextA(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
321 if (IsDlgButtonChecked(hWnd, chx1))
322 *lpFlags |= FR_WHOLEWORD;
323 else *lpFlags &= ~FR_WHOLEWORD;
324 if (IsDlgButtonChecked(hWnd, chx2))
325 *lpFlags |= FR_MATCHCASE;
326 else *lpFlags &= ~FR_MATCHCASE;
327 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
328 *lpFlags |= FR_REPLACEALL;
329 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
330 GetWindowLongA(hWnd, DWL_USER) );
333 /* FIXME : should lpfr structure be passed as an argument ??? */
334 SendMessageA(hwndOwner, uHelpMessage, 0, 0);
341 /***********************************************************************
342 * ReplaceTextDlgProc16 (COMMDLG.14)
344 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
347 LPFINDREPLACE16 lpfr;
350 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
351 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
352 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
353 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
355 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLongA(hWnd, DWL_USER));
356 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
357 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
358 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
359 lpfr->wReplaceWithLen, FALSE);