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

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

DIALOG_IsAccelerator resync (Wine)

File size: 30.1 KB
Line 
1/* $Id: windlg.cpp,v 1.29 2001-11-30 18:45:51 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
446 dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
447 if(!dlgcontrol) {
448 dprintf(("GetDlgCtrlID, control %x not found", hwnd));
449 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
450 return 0;
451 }
452 dprintf(("USER32: GetDlgCtrlID %x", hwnd));
453 return dlgcontrol->getWindowId();
454}
455//******************************************************************************
456//******************************************************************************
457BOOL WIN32API EndDialog(HWND hwnd, int retval)
458{
459 Win32Dialog *dialog;
460
461 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
462 if(!dialog || !dialog->IsDialog()) {
463 dprintf(("GetDlgItem, window %x not found", hwnd));
464 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
465 return 0;
466 }
467 dprintf(("USER32: EndDialog %x %d", hwnd, retval));
468 return dialog->endDialog(retval);
469}
470//******************************************************************************
471//******************************************************************************
472BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
473{
474 dprintf(("USER32: CheckDlgButton %x %d %d", hwnd, id, check));
475
476 return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
477}
478//******************************************************************************
479//******************************************************************************
480BOOL WIN32API CheckRadioButton( HWND hDlg, UINT nIDFirstButton, UINT nIDLastButton, UINT nIDCheckButton)
481{
482 dprintf(("USER32: CheckRadioButton %x %d %d %d", hDlg, nIDFirstButton, nIDLastButton, nIDCheckButton));
483
484 //CB: check radio buttons in interval
485 if (nIDFirstButton > nIDLastButton)
486 {
487 SetLastError(ERROR_INVALID_PARAMETER);
488 return (FALSE);
489 }
490
491 for (UINT x = nIDFirstButton;x <= nIDLastButton;x++)
492 {
493 SendDlgItemMessageA(hDlg,x,BM_SETCHECK,(x == nIDCheckButton) ? BST_CHECKED : BST_UNCHECKED,0);
494 }
495
496 return (TRUE);
497}
498//******************************************************************************
499//******************************************************************************
500UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
501{
502 return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
503}
504//*****************************************************************************
505//*****************************************************************************
506UINT WIN32API GetDlgItemTextW(HWND hwnd, int id, LPWSTR lpszName, UINT cch)
507{
508 return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
509}
510//******************************************************************************
511//******************************************************************************
512BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL fSigned)
513{
514 char str[20];
515
516 dprintf(("USER32: SetDlgItemInt\n"));
517
518 if (fSigned)
519 sprintf( str, "%d", (INT)uValue );
520 else sprintf( str, "%u", uValue );
521
522 return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
523}
524//******************************************************************************
525//******************************************************************************
526BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
527{
528 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
529}
530//******************************************************************************
531//******************************************************************************
532BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
533{
534 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
535}
536//******************************************************************************
537//******************************************************************************
538UINT WIN32API GetDlgItemInt(HWND hwnd, INT id, BOOL *translated, BOOL fSigned)
539{
540 char str[30];
541 char * endptr;
542 long result = 0;
543
544 dprintf(("USER32: GetDlgItemInt %x %x %x %d", hwnd, id, translated, fSigned));
545 if (translated) *translated = FALSE;
546
547 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
548 return 0;
549
550 if (fSigned)
551 {
552 result = strtol( str, &endptr, 10 );
553 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
554 return 0;
555 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
556 return 0;
557 }
558 else
559 {
560 result = strtoul( str, &endptr, 10 );
561 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
562 return 0;
563 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
564 }
565 if (translated) *translated = TRUE;
566 return (UINT)result;
567}
568//******************************************************************************
569//******************************************************************************
570HWND WIN32API GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
571{
572 HWND hwnd, retvalue;
573
574 if(!IsWindow(hwndDlg) || (hwndCtrl && !IsWindow(hwndCtrl))) {
575 dprintf(("GetNextDlgGroupItem, window %x not found", hwnd));
576 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
577 return 0;
578 }
579 dprintf(("USER32: GetNextDlgGroupItem %x %x %d", hwndDlg, hwndCtrl, fPrevious));
580
581 #define WIN_GetFullHandle(a) a
582
583 hwndDlg = WIN_GetFullHandle( hwndDlg );
584 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
585
586 if(hwndCtrl)
587 {
588 /* if the hwndCtrl is the child of the control in the hwndDlg,
589 * then the hwndDlg has to be the parent of the hwndCtrl */
590 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
591 hwndDlg = GetParent(hwndCtrl);
592 }
593
594 if (hwndCtrl)
595 {
596 /* Make sure hwndCtrl is a top-level child */
597 HWND parent = GetParent( hwndCtrl );
598 while (parent && parent != hwndDlg) parent = GetParent(parent);
599 if (parent != hwndDlg) return 0;
600 }
601 else
602 {
603 /* No ctrl specified -> start from the beginning */
604 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
605 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
606 }
607
608 retvalue = hwndCtrl;
609 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
610 while (1)
611 {
612 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
613 {
614 /* Wrap-around to the beginning of the group */
615 HWND tmp;
616
617 hwnd = GetWindow( hwndDlg, GW_CHILD );
618#ifdef __WIN32OS2__
619 if(!hwnd) break;
620#endif
621 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
622 {
623 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
624 if (tmp == hwndCtrl) break;
625 }
626 }
627 if (hwnd == hwndCtrl) break;
628 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
629 {
630 retvalue = hwnd;
631 if (!fPrevious) break;
632 }
633 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
634 }
635 return retvalue;
636}
637/***********************************************************************
638 * GetDialogBaseUnits (USER.243) (USER32.233)
639 */
640DWORD WIN32API GetDialogBaseUnits(void)
641{
642 return Win32Dialog::GetDialogBaseUnits();
643}
644//******************************************************************************
645//******************************************************************************
646INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
647{
648 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
649}
650//******************************************************************************
651//******************************************************************************
652int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
653{
654 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
655}
656//******************************************************************************
657//******************************************************************************
658INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
659{
660 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
661}
662//******************************************************************************
663//******************************************************************************
664INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
665{
666 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
667}
668//******************************************************************************
669//******************************************************************************
670BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
671{
672 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
673}
674//******************************************************************************
675//******************************************************************************
676BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
677{
678 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
679}
680//******************************************************************************
681//******************************************************************************
682BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
683{
684 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
685}
686//******************************************************************************
687//******************************************************************************
688BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
689{
690 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
691}
692/**********************************************************************
693 * DIALOG_DlgDirSelect
694 *
695 * Helper function for DlgDirSelect*
696 */
697static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
698 INT id, BOOL win32, BOOL unicode,
699 BOOL combo )
700{
701 char *buffer, *ptr;
702 INT item, size;
703 BOOL ret;
704 HWND listbox = GetDlgItem( hwnd, id );
705
706 if (!listbox) return FALSE;
707
708 item = SendMessageA(listbox, combo ? CB_GETCURSEL
709 : LB_GETCURSEL, 0, 0 );
710 if (item == LB_ERR) return FALSE;
711 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
712 : LB_GETTEXTLEN, 0, 0 );
713 if (size == LB_ERR) return FALSE;
714
715 if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
716
717 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
718 item, (LPARAM)buffer );
719
720 if ((ret = (buffer[0] == '[')) != 0) /* drive or directory */
721 {
722 if (buffer[1] == '-') /* drive */
723 {
724 buffer[3] = ':';
725 buffer[4] = 0;
726 ptr = buffer + 2;
727 }
728 else
729 {
730 buffer[strlen(buffer)-1] = '\\';
731 ptr = buffer + 1;
732 }
733 }
734 else ptr = buffer;
735
736 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
737 else lstrcpynA( str, ptr, len );
738
739 free( buffer );
740 return ret;
741}
742
743
744/**********************************************************************
745 * DIALOG_DlgDirList
746 *
747 * Helper function for DlgDirList*
748 */
749static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
750 INT idStatic, UINT attrib, BOOL combo )
751{
752 int drive;
753 HWND hwnd;
754 LPSTR orig_spec = spec;
755
756#define SENDMSG(msg,wparam,lparam) \
757 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
758 : SendMessageA( hwnd, msg, wparam, lparam ))
759
760 if (spec && spec[0] && (spec[1] == ':'))
761 {
762 drive = _toupper( spec[0] ) - 'A';
763 spec += 2;
764 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
765 }
766 else drive = DRIVE_GetCurrentDrive();
767
768 /* If the path exists and is a directory, chdir to it */
769 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
770 else
771 {
772 char *p, *p2;
773 p = spec;
774 if ((p2 = strrchr( p, '\\' )) != 0) p = p2;
775 if ((p2 = strrchr( p, '/' )) != 0) p = p2;
776 if (p != spec)
777 {
778 char sep = *p;
779 *p = 0;
780 if (!DRIVE_Chdir( drive, spec ))
781 {
782 *p = sep; /* Restore the original spec */
783 return FALSE;
784 }
785 spec = p + 1;
786 }
787 }
788
789 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
790 {
791 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
792 if (attrib & DDL_DIRECTORY)
793 {
794 if (!(attrib & DDL_EXCLUSIVE))
795 {
796 if (SENDMSG( combo ? CB_DIR : LB_DIR,
797 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
798 (LPARAM)spec ) == LB_ERR)
799 return FALSE;
800 }
801 if (SENDMSG( combo ? CB_DIR : LB_DIR,
802 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
803 (LPARAM)"*.*" ) == LB_ERR)
804 return FALSE;
805 }
806 else
807 {
808 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
809 (LPARAM)spec ) == LB_ERR)
810 return FALSE;
811 }
812 }
813
814 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
815 {
816 char temp[512], curpath[512];
817 int drive = DRIVE_GetCurrentDrive();
818 strcpy( temp, "A:\\" );
819 temp[0] += drive;
820 lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive, sizeof(curpath)), sizeof(temp)-3 );
821 CharLowerA( temp );
822 /* Can't use PostMessage() here, because the string is on the stack */
823 SetDlgItemTextA( hDlg, idStatic, temp );
824 }
825
826 if (orig_spec && (spec != orig_spec))
827 {
828 /* Update the original file spec */
829 char *p = spec;
830 while ((*orig_spec++ = *p++) != 0);
831 }
832
833 return TRUE;
834#undef SENDMSG
835}
836
837
838/**********************************************************************
839 * DIALOG_DlgDirListW
840 *
841 * Helper function for DlgDirList*32W
842 */
843static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
844 INT idStatic, UINT attrib, BOOL combo )
845{
846 if (spec)
847 {
848 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
849 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
850 attrib, combo );
851 lstrcpyAtoW( spec, specA );
852 HeapFree( GetProcessHeap(), 0, specA );
853 return ret;
854 }
855 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
856}
857//******************************************************************************
858//******************************************************************************
859
Note: See TracBrowser for help on using the repository browser.