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

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

Fixed reference count leaks

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