2 * COMMDLG - 16 bits Find & Replace Text Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/winbase16.h"
29 #include "wine/winuser16.h"
33 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
40 /***********************************************************************
41 * FINDDLG_WMInitDialog [internal]
43 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
, LPDWORD lpFlags
,
46 SetWindowLongPtrW(hWnd
, DWLP_USER
, lParam
);
47 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
49 * FIXME : If the initial FindWhat string is empty, we should disable the
50 * FindNext (IDOK) button. Only after typing some text, the button should be
53 SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
54 CheckRadioButton(hWnd
, rad1
, rad2
, (*lpFlags
& FR_DOWN
) ? rad2
: rad1
);
55 if (*lpFlags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
56 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
57 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
59 if (*lpFlags
& FR_HIDEUPDOWN
) {
60 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
61 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
62 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
64 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
65 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
66 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
67 if (*lpFlags
& FR_HIDEWHOLEWORD
)
68 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
69 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
70 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
71 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
72 if (*lpFlags
& FR_HIDEMATCHCASE
)
73 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
74 if (!(*lpFlags
& FR_SHOWHELP
)) {
75 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
76 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
78 ShowWindow(hWnd
, SW_SHOWNORMAL
);
83 /***********************************************************************
84 * FINDDLG_WMCommand [internal]
86 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
,
87 HWND hwndOwner
, LPDWORD lpFlags
,
88 LPSTR lpstrFindWhat
, WORD wFindWhatLen
)
90 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRINGA
);
91 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRINGA
);
93 switch (LOWORD(wParam
)) {
95 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
96 if (IsDlgButtonChecked(hWnd
, rad2
))
98 else *lpFlags
&= ~FR_DOWN
;
99 if (IsDlgButtonChecked(hWnd
, chx1
))
100 *lpFlags
|= FR_WHOLEWORD
;
101 else *lpFlags
&= ~FR_WHOLEWORD
;
102 if (IsDlgButtonChecked(hWnd
, chx2
))
103 *lpFlags
|= FR_MATCHCASE
;
104 else *lpFlags
&= ~FR_MATCHCASE
;
105 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
106 *lpFlags
|= FR_FINDNEXT
;
107 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
108 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
111 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
112 *lpFlags
|= FR_DIALOGTERM
;
113 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
114 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
118 /* FIXME : should lpfr structure be passed as an argument ??? */
119 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
126 /***********************************************************************
127 * find_text_dlgproc (internal)
129 static INT_PTR CALLBACK
find_text_dlgproc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
131 LPFINDREPLACE16 lpfr
;
136 return FINDDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
, MapSL(lpfr
->lpstrFindWhat
));
138 lpfr
=MapSL(GetWindowLongPtrW(hWnd
, DWLP_USER
));
139 return FINDDLG_WMCommand(hWnd
, wParam
, HWND_32(lpfr
->hwndOwner
),
140 &lpfr
->Flags
, MapSL(lpfr
->lpstrFindWhat
),
147 /***********************************************************************
148 * FindText (COMMDLG.11)
150 HWND16 WINAPI
FindText16( SEGPTR find
)
152 FINDREPLACE16
*fr16
= MapSL( find
);
154 return HWND_16( CreateDialogParamA( GetModuleHandleA("comdlg32.dll"), MAKEINTRESOURCEA(FINDDLGORD
),
155 HWND_32(fr16
->hwndOwner
), find_text_dlgproc
, find
));
159 /***********************************************************************
160 * FindTextDlgProc (COMMDLG.13)
162 BOOL16 CALLBACK
FindTextDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
165 return find_text_dlgproc( HWND_32(hWnd16
), wMsg
, wParam
, lParam
);
169 /***********************************************************************
170 * REPLACEDLG_WMInitDialog [internal]
172 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, LPARAM lParam
,
173 LPDWORD lpFlags
, LPCSTR lpstrFindWhat
,
174 LPCSTR lpstrReplaceWith
)
176 SetWindowLongPtrW(hWnd
, DWLP_USER
, lParam
);
177 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
179 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
180 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
183 SetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
);
184 SetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
);
185 CheckDlgButton(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
186 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
187 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
188 if (*lpFlags
& FR_HIDEWHOLEWORD
)
189 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
190 CheckDlgButton(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
191 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
192 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
193 if (*lpFlags
& FR_HIDEMATCHCASE
)
194 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
195 if (!(*lpFlags
& FR_SHOWHELP
)) {
196 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
197 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
199 ShowWindow(hWnd
, SW_SHOWNORMAL
);
204 /***********************************************************************
205 * REPLACEDLG_WMCommand [internal]
207 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM wParam
,
208 HWND hwndOwner
, LPDWORD lpFlags
,
209 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
210 LPSTR lpstrReplaceWith
, WORD wReplaceWithLen
)
212 int uFindReplaceMessage
= RegisterWindowMessageA( FINDMSGSTRINGA
);
213 int uHelpMessage
= RegisterWindowMessageA( HELPMSGSTRINGA
);
215 switch (LOWORD(wParam
)) {
217 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
218 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
219 if (IsDlgButtonChecked(hWnd
, chx1
))
220 *lpFlags
|= FR_WHOLEWORD
;
221 else *lpFlags
&= ~FR_WHOLEWORD
;
222 if (IsDlgButtonChecked(hWnd
, chx2
))
223 *lpFlags
|= FR_MATCHCASE
;
224 else *lpFlags
&= ~FR_MATCHCASE
;
225 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
226 *lpFlags
|= FR_FINDNEXT
;
227 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
228 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
231 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
232 *lpFlags
|= FR_DIALOGTERM
;
233 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
234 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
238 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
239 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
240 if (IsDlgButtonChecked(hWnd
, chx1
))
241 *lpFlags
|= FR_WHOLEWORD
;
242 else *lpFlags
&= ~FR_WHOLEWORD
;
243 if (IsDlgButtonChecked(hWnd
, chx2
))
244 *lpFlags
|= FR_MATCHCASE
;
245 else *lpFlags
&= ~FR_MATCHCASE
;
246 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
247 *lpFlags
|= FR_REPLACE
;
248 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
249 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
252 GetDlgItemTextA(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
253 GetDlgItemTextA(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
254 if (IsDlgButtonChecked(hWnd
, chx1
))
255 *lpFlags
|= FR_WHOLEWORD
;
256 else *lpFlags
&= ~FR_WHOLEWORD
;
257 if (IsDlgButtonChecked(hWnd
, chx2
))
258 *lpFlags
|= FR_MATCHCASE
;
259 else *lpFlags
&= ~FR_MATCHCASE
;
260 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
261 *lpFlags
|= FR_REPLACEALL
;
262 SendMessageW( hwndOwner
, uFindReplaceMessage
, 0,
263 GetWindowLongPtrW(hWnd
, DWLP_USER
) );
266 /* FIXME : should lpfr structure be passed as an argument ??? */
267 SendMessageA(hwndOwner
, uHelpMessage
, 0, 0);
274 /***********************************************************************
275 * replace_text_dlgproc
277 static INT_PTR CALLBACK
replace_text_dlgproc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
279 LPFINDREPLACE16 lpfr
;
284 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
285 MapSL(lpfr
->lpstrFindWhat
),
286 MapSL(lpfr
->lpstrReplaceWith
));
288 lpfr
=MapSL(GetWindowLongPtrW(hWnd
, DWLP_USER
));
289 return REPLACEDLG_WMCommand(hWnd
, wParam
, HWND_32(lpfr
->hwndOwner
),
290 &lpfr
->Flags
, MapSL(lpfr
->lpstrFindWhat
),
291 lpfr
->wFindWhatLen
, MapSL(lpfr
->lpstrReplaceWith
),
292 lpfr
->wReplaceWithLen
);
298 /***********************************************************************
299 * ReplaceText (COMMDLG.12)
301 HWND16 WINAPI
ReplaceText16( SEGPTR find
)
303 FINDREPLACE16
*fr16
= MapSL( find
);
305 return HWND_16( CreateDialogParamA( GetModuleHandleA("comdlg32.dll"), MAKEINTRESOURCEA(REPLACEDLGORD
),
306 HWND_32(fr16
->hwndOwner
), replace_text_dlgproc
, find
));
310 /***********************************************************************
311 * ReplaceTextDlgProc (COMMDLG.14)
313 BOOL16 CALLBACK
ReplaceTextDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
316 return replace_text_dlgproc( HWND_32(hWnd16
), wMsg
, wParam
, lParam
);
320 /***********************************************************************
321 * CommDlgExtendedError (COMMDLG.26)
323 DWORD WINAPI
CommDlgExtendedError16(void)
325 return CommDlgExtendedError();