source: trunk/src/user32/windlg.cpp@ 6927

Last change on this file since 6927 was 6927, checked in by sandervl, 24 years ago

GetNextDlgGroupItem fix

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