Built-in dlls now have resources attached via the PE-header like
[wine.git] / dlls / commdlg / finddlg.c
blobd7f70d8190590697ee1f3bf3c3ea1ff62903d872
1 /*
2 * COMMDLG - Find & Replace Text Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "winbase.h"
12 #include "wine/winbase16.h"
13 #include "win.h"
14 #include "message.h"
15 #include "commdlg.h"
16 #include "resource.h"
17 #include "dialog.h"
18 #include "dlgs.h"
19 #include "module.h"
20 #include "debug.h"
21 #include "winproc.h"
22 #include "cderr.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg)
26 #include "cdlg.h"
28 /***********************************************************************
29 * FindText16 (COMMDLG.11)
31 HWND16 WINAPI FindText16( SEGPTR find )
33 HANDLE16 hInst;
34 LPCVOID ptr;
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);
47 return FALSE;
49 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
50 !(ptr = LockResource( hDlgTmpl )))
52 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
53 return FALSE;
55 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
56 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
57 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
58 find, WIN_PROC_16 );
62 /***********************************************************************
63 * ReplaceText16 (COMMDLG.12)
65 HWND16 WINAPI ReplaceText16( SEGPTR find )
67 HANDLE16 hInst;
68 LPCVOID ptr;
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);
81 return FALSE;
83 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
84 !(ptr = LockResource( hDlgTmpl )))
86 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
87 return FALSE;
89 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
90 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
91 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
92 find, WIN_PROC_16 );
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
107 * enabled.
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);
136 return TRUE;
140 /***********************************************************************
141 * FINDDLG_WMCommand [internal]
143 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam,
144 HWND hwndOwner, LPDWORD lpFlags,
145 LPSTR lpstrFindWhat, WORD wFindWhatLen,
146 BOOL fUnicode)
148 int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRING );
149 int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRING );
151 switch (wParam) {
152 case IDOK:
153 if (fUnicode)
154 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
155 else GetDlgItemTextA(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
156 if (IsDlgButtonChecked(hWnd, rad2))
157 *lpFlags |= FR_DOWN;
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) );
169 return TRUE;
170 case IDCANCEL:
171 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
172 *lpFlags |= FR_DIALOGTERM;
173 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
174 GetWindowLongA(hWnd, DWL_USER) );
175 DestroyWindow(hWnd);
176 return TRUE;
177 case pshHelp:
178 /* FIXME : should lpfr structure be passed as an argument ??? */
179 SendMessageA(hwndOwner, uHelpMessage, 0, 0);
180 return TRUE;
182 return FALSE;
186 /***********************************************************************
187 * FindTextDlgProc16 (COMMDLG.13)
189 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
190 LPARAM lParam)
192 LPFINDREPLACE16 lpfr;
193 switch (wMsg) {
194 case WM_INITDIALOG:
195 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
196 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
197 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
198 case WM_COMMAND:
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);
204 return 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
220 * enabled.
222 if (fUnicode)
224 SetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat);
225 SetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
226 } else
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);
246 return TRUE;
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,
257 BOOL fUnicode)
259 int uFindReplaceMessage = RegisterWindowMessageA( FINDMSGSTRING );
260 int uHelpMessage = RegisterWindowMessageA( HELPMSGSTRING );
262 switch (wParam) {
263 case IDOK:
264 if (fUnicode)
266 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
267 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
268 } else
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) );
283 return TRUE;
284 case IDCANCEL:
285 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
286 *lpFlags |= FR_DIALOGTERM;
287 SendMessageA(hwndOwner, uFindReplaceMessage, 0,
288 GetWindowLongA(hWnd, DWL_USER) );
289 DestroyWindow(hWnd);
290 return TRUE;
291 case psh1:
292 if (fUnicode)
294 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
295 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
296 } else
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) );
311 return TRUE;
312 case psh2:
313 if (fUnicode)
315 GetDlgItemTextW(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
316 GetDlgItemTextW(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
317 } else
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) );
332 return TRUE;
333 case pshHelp:
334 /* FIXME : should lpfr structure be passed as an argument ??? */
335 SendMessageA(hwndOwner, uHelpMessage, 0, 0);
336 return TRUE;
338 return FALSE;
342 /***********************************************************************
343 * ReplaceTextDlgProc16 (COMMDLG.14)
345 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
346 LPARAM lParam)
348 LPFINDREPLACE16 lpfr;
349 switch (wMsg) {
350 case WM_INITDIALOG:
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);
355 case WM_COMMAND:
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);
362 return FALSE;