1 | /* $Id: windlg.cpp,v 1.36 2002-12-17 14:16:47 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 dialog apis for OS/2
|
---|
4 | *
|
---|
5 | * Copyright 1999 Sander van Leeuwen
|
---|
6 | *
|
---|
7 | * Parts based on Wine code (990815; window\dialog.c)
|
---|
8 | *
|
---|
9 | * Copyright 1993, 1994, 1996 Alexandre Julliard
|
---|
10 | *
|
---|
11 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #include <ctype.h>
|
---|
15 | #include <wchar.h>
|
---|
16 | #include <os2win.h>
|
---|
17 | #include <misc.h>
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <limits.h>
|
---|
22 | #include <errno.h>
|
---|
23 | #include "win32wbase.h"
|
---|
24 | #include "win32dlg.h"
|
---|
25 | #include <heapstring.h>
|
---|
26 | #include <win\drive.h>
|
---|
27 | #include <custombuild.h>
|
---|
28 |
|
---|
29 | #define DBG_LOCALLOG DBG_windlg
|
---|
30 | #include "dbglocal.h"
|
---|
31 |
|
---|
32 | static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
|
---|
33 | static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
|
---|
34 | static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len, INT id, BOOL win32, BOOL unicode, BOOL combo );
|
---|
35 |
|
---|
36 | //******************************************************************************
|
---|
37 | //******************************************************************************
|
---|
38 | HWND WIN32API CreateDialogParamA(HINSTANCE hInst, LPCSTR lpszTemplate,
|
---|
39 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
40 | LPARAM lParamInit)
|
---|
41 | {
|
---|
42 | HANDLE hrsrc = FindResourceA( hInst, lpszTemplate, RT_DIALOGA );
|
---|
43 |
|
---|
44 | if (!hrsrc) {
|
---|
45 | dprintf(("WARNING: CreateDialogParamA: Dialog %x not found!!", lpszTemplate));
|
---|
46 | return 0;
|
---|
47 | }
|
---|
48 |
|
---|
49 | return CreateDialogIndirectParamA(hInst, (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc),
|
---|
50 | hwndOwner, dlgproc, lParamInit);
|
---|
51 | }
|
---|
52 | //******************************************************************************
|
---|
53 | //******************************************************************************
|
---|
54 | HWND WIN32API CreateDialogParamW(HINSTANCE hInst, LPCWSTR lpszTemplate,
|
---|
55 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
56 | LPARAM lParamInit)
|
---|
57 | {
|
---|
58 | HANDLE hrsrc = FindResourceW( hInst, lpszTemplate, RT_DIALOGW );
|
---|
59 |
|
---|
60 | if (!hrsrc) {
|
---|
61 | dprintf(("WARNING: CreateDialogParamW: Dialog %x not found!!", lpszTemplate));
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 | return CreateDialogIndirectParamW(hInst, (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc),
|
---|
65 | hwndOwner, dlgproc, lParamInit);
|
---|
66 | }
|
---|
67 | //******************************************************************************
|
---|
68 | //******************************************************************************
|
---|
69 | HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hInst,
|
---|
70 | LPCVOID dlgtemplate,
|
---|
71 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
72 | LPARAM lParamInit)
|
---|
73 | {
|
---|
74 | Win32Dialog *dialog;
|
---|
75 |
|
---|
76 | dprintf(("CreateDialogIndirectParamA: %x %x %x %x %x", hInst, dlgtemplate, hwndOwner, dlgproc, lParamInit));
|
---|
77 |
|
---|
78 | if (!dlgtemplate) return 0;
|
---|
79 |
|
---|
80 | dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndOwner, dlgproc, lParamInit, FALSE);
|
---|
81 |
|
---|
82 | if(dialog == NULL)
|
---|
83 | {
|
---|
84 | dprintf(("Win32Dialog creation failed!!"));
|
---|
85 | return 0;
|
---|
86 | }
|
---|
87 | if(GetLastError() != 0)
|
---|
88 | {
|
---|
89 | dprintf(("Win32Dialog error found (%0x)!!", GetLastError()));
|
---|
90 | RELEASE_WNDOBJ(dialog);
|
---|
91 | delete dialog;
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 | HWND hwnd = dialog->getWindowHandle();
|
---|
95 | HOOK_CallOdinHookA(HODIN_POSTDIALOGCREATION, hwnd, 0);
|
---|
96 |
|
---|
97 | RELEASE_WNDOBJ(dialog);
|
---|
98 | return hwnd;
|
---|
99 | }
|
---|
100 | //******************************************************************************
|
---|
101 | //******************************************************************************
|
---|
102 | HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hInst,
|
---|
103 | LPCVOID dlgtemplate,
|
---|
104 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
105 | LPARAM lParamInit)
|
---|
106 | {
|
---|
107 | Win32Dialog *dialog;
|
---|
108 |
|
---|
109 | dprintf(("CreateDialogIndirectParamW: %x %x %x %x %x", hInst, dlgtemplate, hwndOwner, dlgproc, lParamInit));
|
---|
110 |
|
---|
111 | if (!dlgtemplate) return 0;
|
---|
112 |
|
---|
113 | dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndOwner, dlgproc, lParamInit, TRUE);
|
---|
114 |
|
---|
115 | if(dialog == NULL)
|
---|
116 | {
|
---|
117 | dprintf(("Win32Dialog creation failed!!"));
|
---|
118 | return 0;
|
---|
119 | }
|
---|
120 | if(GetLastError() != 0)
|
---|
121 | {
|
---|
122 | dprintf(("Win32Dialog error found!!"));
|
---|
123 | RELEASE_WNDOBJ(dialog);
|
---|
124 | delete dialog;
|
---|
125 | return 0;
|
---|
126 | }
|
---|
127 | HWND hwnd = dialog->getWindowHandle();
|
---|
128 |
|
---|
129 | HOOK_CallOdinHookA(HODIN_POSTDIALOGCREATION, hwnd, 0);
|
---|
130 |
|
---|
131 | RELEASE_WNDOBJ(dialog);
|
---|
132 | return hwnd;
|
---|
133 | }
|
---|
134 | //******************************************************************************
|
---|
135 | //******************************************************************************
|
---|
136 | INT WIN32API DialogBoxIndirectParamA(HINSTANCE hInst,
|
---|
137 | LPCVOID dlgtemplate,
|
---|
138 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
139 | LPARAM lParamInit)
|
---|
140 | {
|
---|
141 | INT result;
|
---|
142 | HWND hwnd = CreateDialogIndirectParamA(hInst, dlgtemplate, hwndOwner, dlgproc,
|
---|
143 | lParamInit);
|
---|
144 | if (hwnd)
|
---|
145 | {
|
---|
146 | Win32Dialog *dialog;
|
---|
147 |
|
---|
148 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
149 | if(!dialog || !dialog->IsDialog()) {
|
---|
150 | dprintf(("DialogBoxIndirectParamA, dialog %x not found", hwnd));
|
---|
151 | if(dialog) RELEASE_WNDOBJ(dialog);
|
---|
152 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
153 | return 0;
|
---|
154 | }
|
---|
155 | result = dialog->doDialogBox();
|
---|
156 | RELEASE_WNDOBJ(dialog);
|
---|
157 | return result;
|
---|
158 | }
|
---|
159 | return -1;
|
---|
160 | }
|
---|
161 | //******************************************************************************
|
---|
162 | //******************************************************************************
|
---|
163 | INT WIN32API DialogBoxIndirectParamW(HINSTANCE hInst, LPCVOID dlgtemplate,
|
---|
164 | HWND hwndOwner, DLGPROC dlgproc,
|
---|
165 | LPARAM lParamInit)
|
---|
166 | {
|
---|
167 | INT result;
|
---|
168 | HWND hwnd = CreateDialogIndirectParamW(hInst, dlgtemplate, hwndOwner, dlgproc,
|
---|
169 | lParamInit);
|
---|
170 | if (hwnd)
|
---|
171 | {
|
---|
172 | Win32Dialog *dialog;
|
---|
173 |
|
---|
174 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
175 | if(!dialog || !dialog->IsDialog()) {
|
---|
176 | dprintf(("DialogBoxIndirectParamW, dialog %x not found", hwnd));
|
---|
177 | if(dialog) RELEASE_WNDOBJ(dialog);
|
---|
178 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
179 | return 0;
|
---|
180 | }
|
---|
181 | result = dialog->doDialogBox();
|
---|
182 | RELEASE_WNDOBJ(dialog);
|
---|
183 | return result;
|
---|
184 | }
|
---|
185 | return -1;
|
---|
186 | }
|
---|
187 | //******************************************************************************
|
---|
188 | //******************************************************************************
|
---|
189 | int WIN32API DialogBoxParamA(HINSTANCE hInst, LPCSTR lpszTemplate, HWND hwndOwner,
|
---|
190 | DLGPROC dlgproc, LPARAM lParamInit)
|
---|
191 | {
|
---|
192 | INT result;
|
---|
193 | HWND hwnd = CreateDialogParamA( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
|
---|
194 |
|
---|
195 | if (hwnd)
|
---|
196 | {
|
---|
197 | Win32Dialog *dialog;
|
---|
198 |
|
---|
199 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
200 | if(!dialog || !dialog->IsDialog()) {
|
---|
201 | dprintf(("DialogBoxParamA, dialog %x not found", hwnd));
|
---|
202 | if(dialog) RELEASE_WNDOBJ(dialog);
|
---|
203 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
204 | return 0;
|
---|
205 | }
|
---|
206 | result = dialog->doDialogBox();
|
---|
207 | RELEASE_WNDOBJ(dialog);
|
---|
208 | return result;
|
---|
209 | }
|
---|
210 | return -1;
|
---|
211 | }
|
---|
212 | //******************************************************************************
|
---|
213 | //******************************************************************************
|
---|
214 | int WIN32API DialogBoxParamW(HINSTANCE hInst, LPCWSTR lpszTemplate, HWND hwndOwner,
|
---|
215 | DLGPROC dlgproc, LPARAM lParamInit)
|
---|
216 | {
|
---|
217 | INT result;
|
---|
218 | HWND hwnd = CreateDialogParamW( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
|
---|
219 |
|
---|
220 | if (hwnd)
|
---|
221 | {
|
---|
222 | Win32Dialog *dialog;
|
---|
223 |
|
---|
224 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
225 | if(!dialog || !dialog->IsDialog()) {
|
---|
226 | dprintf(("DialogBoxParamW, dialog %x not found", hwnd));
|
---|
227 | if(dialog) RELEASE_WNDOBJ(dialog);
|
---|
228 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
229 | return 0;
|
---|
230 | }
|
---|
231 | result = dialog->doDialogBox();
|
---|
232 | RELEASE_WNDOBJ(dialog);
|
---|
233 | return result;
|
---|
234 | }
|
---|
235 | return -1;
|
---|
236 | }
|
---|
237 | /***********************************************************************
|
---|
238 | * MapDialogRect32 (USER32.382)
|
---|
239 | */
|
---|
240 | BOOL WIN32API MapDialogRect(HWND hwndDlg, LPRECT rect)
|
---|
241 | {
|
---|
242 | Win32Dialog *dialog;
|
---|
243 | BOOL rc;
|
---|
244 | #ifdef DEBUG
|
---|
245 | RECT dlgRect = *rect;
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwndDlg);
|
---|
249 | if(!dialog || !dialog->IsDialog()) {
|
---|
250 | dprintf(("MapDialogRect, window %x not found", hwndDlg));
|
---|
251 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
252 | if(dialog) RELEASE_WNDOBJ(dialog);
|
---|
253 | return 0;
|
---|
254 | }
|
---|
255 | rc = dialog->MapDialogRect(rect);
|
---|
256 | dprintf(("USER32: MapDialogRect %x (%d,%d)(%d,%d) -> (%d,%d)(%d,%d)", hwndDlg, dlgRect.left, dlgRect.top, dlgRect.right, dlgRect.bottom, rect->left, rect->top, rect->right, rect->bottom));
|
---|
257 | RELEASE_WNDOBJ(dialog);
|
---|
258 | return rc;
|
---|
259 | }
|
---|
260 | //******************************************************************************
|
---|
261 | //******************************************************************************
|
---|
262 | UINT WIN32API IsDlgButtonChecked( HWND hwnd, UINT id)
|
---|
263 | {
|
---|
264 | dprintf(("USER32: IsDlgButtonChecked\n"));
|
---|
265 |
|
---|
266 | return (BOOL)SendDlgItemMessageA(hwnd, id,BM_GETCHECK,0,0);
|
---|
267 | }
|
---|
268 | /***********************************************************************
|
---|
269 | * DIALOG_GetNextTabItem
|
---|
270 | *
|
---|
271 | * Helper for GetNextDlgTabItem
|
---|
272 | */
|
---|
273 | static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
|
---|
274 | {
|
---|
275 | LONG dsStyle;
|
---|
276 | LONG exStyle;
|
---|
277 | UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
|
---|
278 | HWND retWnd = 0;
|
---|
279 | HWND hChildFirst = 0;
|
---|
280 |
|
---|
281 | if(!hwndCtrl)
|
---|
282 | {
|
---|
283 | hChildFirst = GetWindow(hwndDlg,GW_CHILD);
|
---|
284 | if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
|
---|
285 | }
|
---|
286 | #if 1
|
---|
287 | else if (IsChild( hwndMain, hwndCtrl ))
|
---|
288 | {
|
---|
289 | hChildFirst = GetWindow(hwndCtrl,wndSearch);
|
---|
290 | if(!hChildFirst)
|
---|
291 | {
|
---|
292 | if(GetParent(hwndCtrl) != hwndMain)
|
---|
293 | hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
|
---|
294 | else
|
---|
295 | {
|
---|
296 | if(fPrevious)
|
---|
297 | hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
|
---|
298 | else
|
---|
299 | hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
|
---|
300 | }
|
---|
301 | }
|
---|
302 | }
|
---|
303 | #else
|
---|
304 | else
|
---|
305 | {
|
---|
306 | HWND hParent = GetParent(hwndCtrl);
|
---|
307 | BOOL bValid = FALSE;
|
---|
308 | while( hParent)
|
---|
309 | {
|
---|
310 | if(hParent == hwndMain)
|
---|
311 | {
|
---|
312 | bValid = TRUE;
|
---|
313 | break;
|
---|
314 | }
|
---|
315 | hParent = GetParent(hParent);
|
---|
316 | }
|
---|
317 | if(bValid)
|
---|
318 | {
|
---|
319 | hChildFirst = GetWindow(hwndCtrl,wndSearch);
|
---|
320 | if(!hChildFirst)
|
---|
321 | {
|
---|
322 | if(GetParent(hwndCtrl) != hwndMain)
|
---|
323 | hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
|
---|
324 | else
|
---|
325 | {
|
---|
326 | if(fPrevious)
|
---|
327 | hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
|
---|
328 | else
|
---|
329 | hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
|
---|
330 | }
|
---|
331 | }
|
---|
332 | }
|
---|
333 | }
|
---|
334 | #endif
|
---|
335 | while(hChildFirst)
|
---|
336 | {
|
---|
337 | BOOL bCtrl = FALSE;
|
---|
338 | while(hChildFirst)
|
---|
339 | {
|
---|
340 | dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
|
---|
341 | exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
|
---|
342 | if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
|
---|
343 | {
|
---|
344 | bCtrl=TRUE;
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
|
---|
348 | break;
|
---|
349 | hChildFirst = GetWindow(hChildFirst,wndSearch);
|
---|
350 | }
|
---|
351 | if(hChildFirst)
|
---|
352 | {
|
---|
353 | if(bCtrl)
|
---|
354 | retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
|
---|
355 | else
|
---|
356 | retWnd = hChildFirst;
|
---|
357 | }
|
---|
358 | if(retWnd) break;
|
---|
359 | hChildFirst = GetWindow(hChildFirst,wndSearch);
|
---|
360 | }
|
---|
361 | if(!retWnd && hwndCtrl)
|
---|
362 | {
|
---|
363 | HWND hParent = GetParent(hwndCtrl);
|
---|
364 | while(hParent)
|
---|
365 | {
|
---|
366 | if(hParent == hwndMain) break;
|
---|
367 | retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
|
---|
368 | if(retWnd) break;
|
---|
369 | hParent = GetParent(hParent);
|
---|
370 | }
|
---|
371 | if(!retWnd)
|
---|
372 | retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
|
---|
373 | }
|
---|
374 | return retWnd;
|
---|
375 | }
|
---|
376 | //******************************************************************************
|
---|
377 | //******************************************************************************
|
---|
378 | HWND WIN32API GetNextDlgTabItem(HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
|
---|
379 | {
|
---|
380 | if(!IsWindow(hwndDlg)) {
|
---|
381 | dprintf(("GetNextDlgTabItem, window %x not found", hwndDlg));
|
---|
382 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
383 | return 0;
|
---|
384 | }
|
---|
385 | dprintf(("USER32: GetNextDlgTabItem %x %x %d", hwndDlg,hwndCtrl,fPrevious));
|
---|
386 | return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
|
---|
387 | }
|
---|
388 | //******************************************************************************
|
---|
389 | //Can be used for any parent-child pair
|
---|
390 | //NOTE: Returns ERROR_CONTROL_ID_NOT_FOUND when child with id not found
|
---|
391 | // Does not change last error if successful
|
---|
392 | //******************************************************************************
|
---|
393 | HWND WIN32API GetDlgItem(HWND hwnd, int id)
|
---|
394 | {
|
---|
395 | Win32BaseWindow *window;
|
---|
396 | HWND hwndDlgItem;
|
---|
397 |
|
---|
398 | window = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
399 | if(!window) {
|
---|
400 | dprintf(("GetDlgItem, window %x not found", hwnd));
|
---|
401 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
402 | return 0;
|
---|
403 | }
|
---|
404 | hwndDlgItem = window->FindWindowById(id);
|
---|
405 | RELEASE_WNDOBJ(window);
|
---|
406 | if(hwndDlgItem) {
|
---|
407 | dprintf(("USER32: GetDlgItem %x %d returned %x\n", hwnd, id, hwndDlgItem));
|
---|
408 | return hwndDlgItem;
|
---|
409 | }
|
---|
410 | dprintf(("USER32: GetDlgItem %x %d NOT FOUND!\n", hwnd, id));
|
---|
411 | SetLastError(ERROR_CONTROL_ID_NOT_FOUND); //verified in NT4, SP6
|
---|
412 | return 0;
|
---|
413 | }
|
---|
414 | //******************************************************************************
|
---|
415 | //******************************************************************************
|
---|
416 | int WIN32API GetDlgCtrlID(HWND hwnd)
|
---|
417 | {
|
---|
418 | Win32BaseWindow *dlgcontrol;
|
---|
419 | int ret;
|
---|
420 |
|
---|
421 | dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
422 | if(!dlgcontrol) {
|
---|
423 | dprintf(("GetDlgCtrlID, control %x not found", hwnd));
|
---|
424 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
425 | return 0;
|
---|
426 | }
|
---|
427 | ret = dlgcontrol->getWindowId();
|
---|
428 | RELEASE_WNDOBJ(dlgcontrol);
|
---|
429 | return ret;
|
---|
430 | }
|
---|
431 | //******************************************************************************
|
---|
432 | //******************************************************************************
|
---|
433 | BOOL WIN32API EndDialog(HWND hwnd, int retval)
|
---|
434 | {
|
---|
435 | Win32Dialog *dialog;
|
---|
436 | BOOL ret;
|
---|
437 |
|
---|
438 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
439 | if(!dialog || !dialog->IsDialog()) {
|
---|
440 | dprintf(("GetDlgItem, window %x not found", hwnd));
|
---|
441 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
442 | return 0;
|
---|
443 | }
|
---|
444 | ret = dialog->endDialog(retval);
|
---|
445 | RELEASE_WNDOBJ(dialog);
|
---|
446 | return ret;
|
---|
447 | }
|
---|
448 | //******************************************************************************
|
---|
449 | //******************************************************************************
|
---|
450 | BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
|
---|
451 | {
|
---|
452 | dprintf(("USER32: CheckDlgButton %x %d %d", hwnd, id, check));
|
---|
453 |
|
---|
454 | return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
|
---|
455 | }
|
---|
456 | //******************************************************************************
|
---|
457 | //******************************************************************************
|
---|
458 | BOOL WIN32API CheckRadioButton( HWND hDlg, UINT nIDFirstButton, UINT nIDLastButton, UINT nIDCheckButton)
|
---|
459 | {
|
---|
460 | dprintf(("USER32: CheckRadioButton %x %d %d %d", hDlg, nIDFirstButton, nIDLastButton, nIDCheckButton));
|
---|
461 |
|
---|
462 | //CB: check radio buttons in interval
|
---|
463 | if (nIDFirstButton > nIDLastButton)
|
---|
464 | {
|
---|
465 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
466 | return (FALSE);
|
---|
467 | }
|
---|
468 |
|
---|
469 | for (UINT x = nIDFirstButton;x <= nIDLastButton;x++)
|
---|
470 | {
|
---|
471 | SendDlgItemMessageA(hDlg,x,BM_SETCHECK,(x == nIDCheckButton) ? BST_CHECKED : BST_UNCHECKED,0);
|
---|
472 | }
|
---|
473 |
|
---|
474 | return (TRUE);
|
---|
475 | }
|
---|
476 | //******************************************************************************
|
---|
477 | //******************************************************************************
|
---|
478 | INT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
|
---|
479 | {
|
---|
480 | return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
|
---|
481 | }
|
---|
482 | //*****************************************************************************
|
---|
483 | //*****************************************************************************
|
---|
484 | INT WIN32API GetDlgItemTextW(HWND hwnd, int id, LPWSTR lpszName, UINT cch)
|
---|
485 | {
|
---|
486 | return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
|
---|
487 | }
|
---|
488 | //******************************************************************************
|
---|
489 | //******************************************************************************
|
---|
490 | BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL fSigned)
|
---|
491 | {
|
---|
492 | char str[20];
|
---|
493 |
|
---|
494 | dprintf(("USER32: SetDlgItemInt\n"));
|
---|
495 |
|
---|
496 | if (fSigned)
|
---|
497 | sprintf( str, "%d", (INT)uValue );
|
---|
498 | else sprintf( str, "%u", uValue );
|
---|
499 |
|
---|
500 | return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
|
---|
501 | }
|
---|
502 | //******************************************************************************
|
---|
503 | //******************************************************************************
|
---|
504 | BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
|
---|
505 | {
|
---|
506 | return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
|
---|
507 | }
|
---|
508 | //******************************************************************************
|
---|
509 | //******************************************************************************
|
---|
510 | BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
|
---|
511 | {
|
---|
512 | return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
|
---|
513 | }
|
---|
514 | //******************************************************************************
|
---|
515 | //******************************************************************************
|
---|
516 | UINT WIN32API GetDlgItemInt(HWND hwnd, INT id, BOOL *translated, BOOL fSigned)
|
---|
517 | {
|
---|
518 | char str[30];
|
---|
519 | char * endptr;
|
---|
520 | long result = 0;
|
---|
521 |
|
---|
522 | dprintf(("USER32: GetDlgItemInt %x %x %x %d", hwnd, id, translated, fSigned));
|
---|
523 | if (translated) *translated = FALSE;
|
---|
524 |
|
---|
525 | if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
|
---|
526 | return 0;
|
---|
527 |
|
---|
528 | if (fSigned)
|
---|
529 | {
|
---|
530 | result = strtol( str, &endptr, 10 );
|
---|
531 | if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
|
---|
532 | return 0;
|
---|
533 | if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
|
---|
534 | return 0;
|
---|
535 | }
|
---|
536 | else
|
---|
537 | {
|
---|
538 | result = strtoul( str, &endptr, 10 );
|
---|
539 | if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
|
---|
540 | return 0;
|
---|
541 | if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
|
---|
542 | }
|
---|
543 | if (translated) *translated = TRUE;
|
---|
544 | return (UINT)result;
|
---|
545 | }
|
---|
546 | //******************************************************************************
|
---|
547 | //Note: This implementation is correct, but it can't cope with z-order changes
|
---|
548 | // of dialog controls. That's ok, since Windows can't either.
|
---|
549 | //******************************************************************************
|
---|
550 | HWND WIN32API GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
|
---|
551 | {
|
---|
552 | HWND hwnd, retvalue;
|
---|
553 |
|
---|
554 | if(!IsWindow(hwndDlg) || (hwndCtrl && !IsWindow(hwndCtrl))) {
|
---|
555 | dprintf(("GetNextDlgGroupItem, window %x not found", hwnd));
|
---|
556 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
557 | return 0;
|
---|
558 | }
|
---|
559 | dprintf(("USER32: GetNextDlgGroupItem %x %x %d", hwndDlg, hwndCtrl, fPrevious));
|
---|
560 |
|
---|
561 | #define WIN_GetFullHandle(a) a
|
---|
562 |
|
---|
563 | hwndDlg = WIN_GetFullHandle( hwndDlg );
|
---|
564 | hwndCtrl = WIN_GetFullHandle( hwndCtrl );
|
---|
565 |
|
---|
566 | if(hwndCtrl)
|
---|
567 | {
|
---|
568 | /* if the hwndCtrl is the child of the control in the hwndDlg,
|
---|
569 | * then the hwndDlg has to be the parent of the hwndCtrl */
|
---|
570 | if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
|
---|
571 | hwndDlg = GetParent(hwndCtrl);
|
---|
572 | }
|
---|
573 |
|
---|
574 | if (hwndCtrl)
|
---|
575 | {
|
---|
576 | /* Make sure hwndCtrl is a top-level child */
|
---|
577 | HWND parent = GetParent( hwndCtrl );
|
---|
578 | while (parent && parent != hwndDlg) parent = GetParent(parent);
|
---|
579 | if (parent != hwndDlg) return 0;
|
---|
580 | }
|
---|
581 | else
|
---|
582 | {
|
---|
583 | /* No ctrl specified -> start from the beginning */
|
---|
584 | if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
|
---|
585 | if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
|
---|
586 | }
|
---|
587 |
|
---|
588 | retvalue = hwndCtrl;
|
---|
589 | hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
|
---|
590 | while (1)
|
---|
591 | {
|
---|
592 | if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
|
---|
593 | {
|
---|
594 | /* Wrap-around to the beginning of the group */
|
---|
595 | HWND tmp;
|
---|
596 |
|
---|
597 | hwnd = GetWindow( hwndDlg, GW_CHILD );
|
---|
598 | #ifdef __WIN32OS2__
|
---|
599 | if(!hwnd) break;
|
---|
600 | #endif
|
---|
601 | for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
|
---|
602 | {
|
---|
603 | if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
|
---|
604 | if (tmp == hwndCtrl) break;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | if (hwnd == hwndCtrl) break;
|
---|
608 | if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
|
---|
609 | {
|
---|
610 | retvalue = hwnd;
|
---|
611 | if (!fPrevious) break;
|
---|
612 | }
|
---|
613 | hwnd = GetWindow( hwnd, GW_HWNDNEXT );
|
---|
614 | }
|
---|
615 | return retvalue;
|
---|
616 | }
|
---|
617 | /***********************************************************************
|
---|
618 | * GetDialogBaseUnits (USER.243) (USER32.233)
|
---|
619 | */
|
---|
620 | DWORD WIN32API GetDialogBaseUnits(void)
|
---|
621 | {
|
---|
622 | return Win32Dialog::GetDialogBaseUnits();
|
---|
623 | }
|
---|
624 | //******************************************************************************
|
---|
625 | //******************************************************************************
|
---|
626 | /**********************************************************************
|
---|
627 | * DIALOG_DlgDirSelect
|
---|
628 | *
|
---|
629 | * Helper function for DlgDirSelect*
|
---|
630 | */
|
---|
631 | static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
|
---|
632 | INT id, BOOL unicode, BOOL combo )
|
---|
633 | {
|
---|
634 | char *buffer, *ptr;
|
---|
635 | INT item, size;
|
---|
636 | BOOL ret;
|
---|
637 | HWND listbox = GetDlgItem( hwnd, id );
|
---|
638 |
|
---|
639 | dprintf(("%04x '%s' %d\n", hwnd, str, id ));
|
---|
640 | if (!listbox) return FALSE;
|
---|
641 |
|
---|
642 | item = SendMessageA(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
|
---|
643 | if (item == LB_ERR) return FALSE;
|
---|
644 | size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
|
---|
645 | if (size == LB_ERR) return FALSE;
|
---|
646 |
|
---|
647 | if (!(buffer = (char *)HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
|
---|
648 |
|
---|
649 | SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
|
---|
650 |
|
---|
651 | if ((ret = (buffer[0] == '['))) /* drive or directory */
|
---|
652 | {
|
---|
653 | if (buffer[1] == '-') /* drive */
|
---|
654 | {
|
---|
655 | buffer[3] = ':';
|
---|
656 | buffer[4] = 0;
|
---|
657 | ptr = buffer + 2;
|
---|
658 | }
|
---|
659 | else
|
---|
660 | {
|
---|
661 | buffer[strlen(buffer)-1] = '\\';
|
---|
662 | ptr = buffer + 1;
|
---|
663 | }
|
---|
664 | }
|
---|
665 | else ptr = buffer;
|
---|
666 |
|
---|
667 | if (unicode)
|
---|
668 | {
|
---|
669 | if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
|
---|
670 | ((LPWSTR)str)[len-1] = 0;
|
---|
671 | }
|
---|
672 | else lstrcpynA( str, ptr, len );
|
---|
673 | HeapFree( GetProcessHeap(), 0, buffer );
|
---|
674 | dprintf(("Returning %d '%s'\n", ret, str ));
|
---|
675 | return ret;
|
---|
676 | }
|
---|
677 |
|
---|
678 |
|
---|
679 | /**********************************************************************
|
---|
680 | * DIALOG_DlgDirList
|
---|
681 | *
|
---|
682 | * Helper function for DlgDirList*
|
---|
683 | */
|
---|
684 | static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
|
---|
685 | INT idStatic, UINT attrib, BOOL combo )
|
---|
686 | {
|
---|
687 | HWND hwnd;
|
---|
688 | LPSTR orig_spec = spec;
|
---|
689 |
|
---|
690 | #define SENDMSG(msg,wparam,lparam) \
|
---|
691 | ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
|
---|
692 | : SendMessageA( hwnd, msg, wparam, lparam ))
|
---|
693 |
|
---|
694 | dprintf(("%04x '%s' %d %d %04x\n",
|
---|
695 | hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib ));
|
---|
696 |
|
---|
697 | /* If the path exists and is a directory, chdir to it */
|
---|
698 | if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
|
---|
699 | else
|
---|
700 | {
|
---|
701 | char *p, *p2;
|
---|
702 | p = spec;
|
---|
703 | if ((p2 = strrchr( p, '\\' ))) p = p2;
|
---|
704 | if ((p2 = strrchr( p, '/' ))) p = p2;
|
---|
705 | if (p != spec)
|
---|
706 | {
|
---|
707 | char sep = *p;
|
---|
708 | *p = 0;
|
---|
709 | if (!SetCurrentDirectoryA( spec ))
|
---|
710 | {
|
---|
711 | *p = sep; /* Restore the original spec */
|
---|
712 | return FALSE;
|
---|
713 | }
|
---|
714 | spec = p + 1;
|
---|
715 | }
|
---|
716 | }
|
---|
717 |
|
---|
718 | dprintf(( "mask=%s\n", spec ));
|
---|
719 |
|
---|
720 | if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
|
---|
721 | {
|
---|
722 | SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
|
---|
723 | if (attrib & DDL_DIRECTORY)
|
---|
724 | {
|
---|
725 | if (!(attrib & DDL_EXCLUSIVE))
|
---|
726 | {
|
---|
727 | if (SENDMSG( combo ? CB_DIR : LB_DIR,
|
---|
728 | attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
|
---|
729 | (LPARAM)spec ) == LB_ERR)
|
---|
730 | return FALSE;
|
---|
731 | }
|
---|
732 | if (SENDMSG( combo ? CB_DIR : LB_DIR,
|
---|
733 | (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
|
---|
734 | (LPARAM)"*.*" ) == LB_ERR)
|
---|
735 | return FALSE;
|
---|
736 | }
|
---|
737 | else
|
---|
738 | {
|
---|
739 | if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
|
---|
740 | (LPARAM)spec ) == LB_ERR)
|
---|
741 | return FALSE;
|
---|
742 | }
|
---|
743 | }
|
---|
744 |
|
---|
745 | if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
|
---|
746 | {
|
---|
747 | char temp[MAX_PATH];
|
---|
748 | GetCurrentDirectoryA( sizeof(temp), temp );
|
---|
749 | CharLowerA( temp );
|
---|
750 | /* Can't use PostMessage() here, because the string is on the stack */
|
---|
751 | SetDlgItemTextA( hDlg, idStatic, temp );
|
---|
752 | }
|
---|
753 |
|
---|
754 | if (orig_spec && (spec != orig_spec))
|
---|
755 | {
|
---|
756 | /* Update the original file spec */
|
---|
757 | char *p = spec;
|
---|
758 | while ((*orig_spec++ = *p++));
|
---|
759 | }
|
---|
760 |
|
---|
761 | return TRUE;
|
---|
762 | #undef SENDMSG
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | /**********************************************************************
|
---|
767 | * DIALOG_DlgDirListW
|
---|
768 | *
|
---|
769 | * Helper function for DlgDirList*W
|
---|
770 | */
|
---|
771 | static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
|
---|
772 | INT idStatic, UINT attrib, BOOL combo )
|
---|
773 | {
|
---|
774 | if (spec)
|
---|
775 | {
|
---|
776 | LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
|
---|
777 | INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
|
---|
778 | attrib, combo );
|
---|
779 | MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
|
---|
780 | HeapFree( GetProcessHeap(), 0, specA );
|
---|
781 | return ret;
|
---|
782 | }
|
---|
783 | return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
|
---|
784 | }
|
---|
785 |
|
---|
786 |
|
---|
787 | /**********************************************************************
|
---|
788 | * DlgDirSelectExA (USER32.@)
|
---|
789 | */
|
---|
790 | BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
|
---|
791 | {
|
---|
792 | return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE );
|
---|
793 | }
|
---|
794 |
|
---|
795 |
|
---|
796 | /**********************************************************************
|
---|
797 | * DlgDirSelectExW (USER32.@)
|
---|
798 | */
|
---|
799 | BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
|
---|
800 | {
|
---|
801 | return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, FALSE );
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | /**********************************************************************
|
---|
806 | * DlgDirSelectComboBoxExA (USER32.@)
|
---|
807 | */
|
---|
808 | BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
|
---|
809 | INT id )
|
---|
810 | {
|
---|
811 | return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, TRUE );
|
---|
812 | }
|
---|
813 |
|
---|
814 |
|
---|
815 | /**********************************************************************
|
---|
816 | * DlgDirSelectComboBoxExW (USER32.@)
|
---|
817 | */
|
---|
818 | BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
|
---|
819 | INT id)
|
---|
820 | {
|
---|
821 | return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE );
|
---|
822 | }
|
---|
823 |
|
---|
824 |
|
---|
825 | /**********************************************************************
|
---|
826 | * DlgDirListA (USER32.@)
|
---|
827 | */
|
---|
828 | INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
|
---|
829 | INT idStatic, UINT attrib )
|
---|
830 | {
|
---|
831 | return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
|
---|
832 | }
|
---|
833 |
|
---|
834 |
|
---|
835 | /**********************************************************************
|
---|
836 | * DlgDirListW (USER32.@)
|
---|
837 | */
|
---|
838 | INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
|
---|
839 | INT idStatic, UINT attrib )
|
---|
840 | {
|
---|
841 | return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
|
---|
842 | }
|
---|
843 |
|
---|
844 |
|
---|
845 | /**********************************************************************
|
---|
846 | * DlgDirListComboBoxA (USER32.@)
|
---|
847 | */
|
---|
848 | INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
|
---|
849 | INT idStatic, UINT attrib )
|
---|
850 | {
|
---|
851 | return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
|
---|
852 | }
|
---|
853 |
|
---|
854 |
|
---|
855 | /**********************************************************************
|
---|
856 | * DlgDirListComboBoxW (USER32.@)
|
---|
857 | */
|
---|
858 | INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
|
---|
859 | INT idStatic, UINT attrib )
|
---|
860 | {
|
---|
861 | return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
|
---|
862 | }
|
---|