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

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

customization updates

File size: 29.6 KB
Line 
1/* $Id: windlg.cpp,v 1.28 2001-10-28 15:24:16 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 else
313 {
314 HWND hParent = GetParent(hwndCtrl);
315 BOOL bValid = FALSE;
316 while( hParent)
317 {
318 if(hParent == hwndMain)
319 {
320 bValid = TRUE;
321 break;
322 }
323 hParent = GetParent(hParent);
324 }
325 if(bValid)
326 {
327 hChildFirst = GetWindow(hwndCtrl,wndSearch);
328 if(!hChildFirst)
329 {
330 if(GetParent(hwndCtrl) != hwndMain)
331 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
332 else
333 {
334 if(fPrevious)
335 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
336 else
337 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
338 }
339 }
340 }
341 }
342 while(hChildFirst)
343 {
344 BOOL bCtrl = FALSE;
345 while(hChildFirst)
346 {
347 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
348 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
349 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
350 {
351 bCtrl=TRUE;
352 break;
353 }
354 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
355 break;
356 hChildFirst = GetWindow(hChildFirst,wndSearch);
357 }
358 if(hChildFirst)
359 {
360 if(bCtrl)
361 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
362 else
363 retWnd = hChildFirst;
364 }
365 if(retWnd) break;
366 hChildFirst = GetWindow(hChildFirst,wndSearch);
367 }
368 if(!retWnd && hwndCtrl)
369 {
370 HWND hParent = GetParent(hwndCtrl);
371 while(hParent)
372 {
373 if(hParent == hwndMain) break;
374 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
375 if(retWnd) break;
376 hParent = GetParent(hParent);
377 }
378 if(!retWnd)
379 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
380 }
381 return retWnd;
382}
383//******************************************************************************
384//******************************************************************************
385HWND WIN32API GetNextDlgTabItem(HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
386{
387 if(!IsWindow(hwndDlg)) {
388 dprintf(("GetNextDlgTabItem, window %x not found", hwndDlg));
389 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
390 return 0;
391 }
392 dprintf(("USER32: GetNextDlgTabItem %x %x %d", hwndDlg,hwndCtrl,fPrevious));
393 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
394}
395//******************************************************************************
396//Can be used for any parent-child pair
397//NOTE: Returns ERROR_CONTROL_ID_NOT_FOUND when child with id not found
398// Does not change last error if successful
399//******************************************************************************
400HWND WIN32API GetDlgItem(HWND hwnd, int id)
401{
402 Win32BaseWindow *window;
403 HWND hwndDlgItem;
404
405 window = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
406 if(!window) {
407 dprintf(("GetDlgItem, window %x not found", hwnd));
408 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
409 return 0;
410 }
411 hwndDlgItem = window->FindWindowById(id);
412 RELEASE_WNDOBJ(window);
413 if(hwndDlgItem) {
414 dprintf(("USER32: GetDlgItem %x %d returned %x\n", hwnd, id, hwndDlgItem));
415 return hwndDlgItem;
416 }
417 dprintf(("USER32: GetDlgItem %x %d NOT FOUND!\n", hwnd, id));
418 SetLastError(ERROR_CONTROL_ID_NOT_FOUND); //verified in NT4, SP6
419 return 0;
420}
421//******************************************************************************
422//******************************************************************************
423int WIN32API GetDlgCtrlID(HWND hwnd)
424{
425 Win32BaseWindow *dlgcontrol;
426
427 dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
428 if(!dlgcontrol) {
429 dprintf(("GetDlgCtrlID, control %x not found", hwnd));
430 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
431 return 0;
432 }
433 dprintf(("USER32: GetDlgCtrlID %x", hwnd));
434 return dlgcontrol->getWindowId();
435}
436//******************************************************************************
437//******************************************************************************
438BOOL WIN32API EndDialog(HWND hwnd, int retval)
439{
440 Win32Dialog *dialog;
441
442 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
443 if(!dialog || !dialog->IsDialog()) {
444 dprintf(("GetDlgItem, window %x not found", hwnd));
445 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
446 return 0;
447 }
448 dprintf(("USER32: EndDialog %x %d", hwnd, retval));
449 return dialog->endDialog(retval);
450}
451//******************************************************************************
452//******************************************************************************
453BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
454{
455 dprintf(("USER32: CheckDlgButton %x %d %d", hwnd, id, check));
456
457 return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
458}
459//******************************************************************************
460//******************************************************************************
461BOOL WIN32API CheckRadioButton( HWND hDlg, UINT nIDFirstButton, UINT nIDLastButton, UINT nIDCheckButton)
462{
463 dprintf(("USER32: CheckRadioButton %x %d %d %d", hDlg, nIDFirstButton, nIDLastButton, nIDCheckButton));
464
465 //CB: check radio buttons in interval
466 if (nIDFirstButton > nIDLastButton)
467 {
468 SetLastError(ERROR_INVALID_PARAMETER);
469 return (FALSE);
470 }
471
472 for (UINT x = nIDFirstButton;x <= nIDLastButton;x++)
473 {
474 SendDlgItemMessageA(hDlg,x,BM_SETCHECK,(x == nIDCheckButton) ? BST_CHECKED : BST_UNCHECKED,0);
475 }
476
477 return (TRUE);
478}
479//******************************************************************************
480//******************************************************************************
481UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
482{
483 return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
484}
485//*****************************************************************************
486//*****************************************************************************
487UINT WIN32API GetDlgItemTextW(HWND hwnd, int id, LPWSTR lpszName, UINT cch)
488{
489 return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
490}
491//******************************************************************************
492//******************************************************************************
493BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL fSigned)
494{
495 char str[20];
496
497 dprintf(("USER32: SetDlgItemInt\n"));
498
499 if (fSigned)
500 sprintf( str, "%d", (INT)uValue );
501 else sprintf( str, "%u", uValue );
502
503 return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
504}
505//******************************************************************************
506//******************************************************************************
507BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
508{
509 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
510}
511//******************************************************************************
512//******************************************************************************
513BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
514{
515 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
516}
517//******************************************************************************
518//******************************************************************************
519UINT WIN32API GetDlgItemInt(HWND hwnd, INT id, BOOL *translated, BOOL fSigned)
520{
521 char str[30];
522 char * endptr;
523 long result = 0;
524
525 dprintf(("USER32: GetDlgItemInt %x %x %x %d", hwnd, id, translated, fSigned));
526 if (translated) *translated = FALSE;
527
528 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
529 return 0;
530
531 if (fSigned)
532 {
533 result = strtol( str, &endptr, 10 );
534 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
535 return 0;
536 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
537 return 0;
538 }
539 else
540 {
541 result = strtoul( str, &endptr, 10 );
542 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
543 return 0;
544 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
545 }
546 if (translated) *translated = TRUE;
547 return (UINT)result;
548}
549//******************************************************************************
550//******************************************************************************
551HWND WIN32API GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
552{
553 HWND hwnd, retvalue;
554
555 if(!IsWindow(hwndDlg) || (hwndCtrl && !IsWindow(hwndCtrl))) {
556 dprintf(("GetNextDlgGroupItem, window %x not found", hwnd));
557 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
558 return 0;
559 }
560 dprintf(("USER32: GetNextDlgGroupItem %x %x %d", hwndDlg, hwndCtrl, fPrevious));
561
562 #define WIN_GetFullHandle(a) a
563
564 hwndDlg = WIN_GetFullHandle( hwndDlg );
565 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
566
567 if(hwndCtrl)
568 {
569 /* if the hwndCtrl is the child of the control in the hwndDlg,
570 * then the hwndDlg has to be the parent of the hwndCtrl */
571 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
572 hwndDlg = GetParent(hwndCtrl);
573 }
574
575 if (hwndCtrl)
576 {
577 /* Make sure hwndCtrl is a top-level child */
578 HWND parent = GetParent( hwndCtrl );
579 while (parent && parent != hwndDlg) parent = GetParent(parent);
580 if (parent != hwndDlg) return 0;
581 }
582 else
583 {
584 /* No ctrl specified -> start from the beginning */
585 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
586 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
587 }
588
589 retvalue = hwndCtrl;
590 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
591 while (1)
592 {
593 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
594 {
595 /* Wrap-around to the beginning of the group */
596 HWND tmp;
597
598 hwnd = GetWindow( hwndDlg, GW_CHILD );
599#ifdef __WIN32OS2__
600 if(!hwnd) break;
601#endif
602 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
603 {
604 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
605 if (tmp == hwndCtrl) break;
606 }
607 }
608 if (hwnd == hwndCtrl) break;
609 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
610 {
611 retvalue = hwnd;
612 if (!fPrevious) break;
613 }
614 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
615 }
616 return retvalue;
617}
618/***********************************************************************
619 * GetDialogBaseUnits (USER.243) (USER32.233)
620 */
621DWORD WIN32API GetDialogBaseUnits(void)
622{
623 return Win32Dialog::GetDialogBaseUnits();
624}
625//******************************************************************************
626//******************************************************************************
627INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
628{
629 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
630}
631//******************************************************************************
632//******************************************************************************
633int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
634{
635 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
636}
637//******************************************************************************
638//******************************************************************************
639INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
640{
641 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
642}
643//******************************************************************************
644//******************************************************************************
645INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
646{
647 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
648}
649//******************************************************************************
650//******************************************************************************
651BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
652{
653 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
654}
655//******************************************************************************
656//******************************************************************************
657BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
658{
659 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
660}
661//******************************************************************************
662//******************************************************************************
663BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
664{
665 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
666}
667//******************************************************************************
668//******************************************************************************
669BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
670{
671 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
672}
673/**********************************************************************
674 * DIALOG_DlgDirSelect
675 *
676 * Helper function for DlgDirSelect*
677 */
678static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
679 INT id, BOOL win32, BOOL unicode,
680 BOOL combo )
681{
682 char *buffer, *ptr;
683 INT item, size;
684 BOOL ret;
685 HWND listbox = GetDlgItem( hwnd, id );
686
687 if (!listbox) return FALSE;
688
689 item = SendMessageA(listbox, combo ? CB_GETCURSEL
690 : LB_GETCURSEL, 0, 0 );
691 if (item == LB_ERR) return FALSE;
692 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
693 : LB_GETTEXTLEN, 0, 0 );
694 if (size == LB_ERR) return FALSE;
695
696 if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
697
698 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
699 item, (LPARAM)buffer );
700
701 if ((ret = (buffer[0] == '[')) != 0) /* drive or directory */
702 {
703 if (buffer[1] == '-') /* drive */
704 {
705 buffer[3] = ':';
706 buffer[4] = 0;
707 ptr = buffer + 2;
708 }
709 else
710 {
711 buffer[strlen(buffer)-1] = '\\';
712 ptr = buffer + 1;
713 }
714 }
715 else ptr = buffer;
716
717 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
718 else lstrcpynA( str, ptr, len );
719
720 free( buffer );
721 return ret;
722}
723
724
725/**********************************************************************
726 * DIALOG_DlgDirList
727 *
728 * Helper function for DlgDirList*
729 */
730static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
731 INT idStatic, UINT attrib, BOOL combo )
732{
733 int drive;
734 HWND hwnd;
735 LPSTR orig_spec = spec;
736
737#define SENDMSG(msg,wparam,lparam) \
738 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
739 : SendMessageA( hwnd, msg, wparam, lparam ))
740
741 if (spec && spec[0] && (spec[1] == ':'))
742 {
743 drive = _toupper( spec[0] ) - 'A';
744 spec += 2;
745 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
746 }
747 else drive = DRIVE_GetCurrentDrive();
748
749 /* If the path exists and is a directory, chdir to it */
750 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
751 else
752 {
753 char *p, *p2;
754 p = spec;
755 if ((p2 = strrchr( p, '\\' )) != 0) p = p2;
756 if ((p2 = strrchr( p, '/' )) != 0) p = p2;
757 if (p != spec)
758 {
759 char sep = *p;
760 *p = 0;
761 if (!DRIVE_Chdir( drive, spec ))
762 {
763 *p = sep; /* Restore the original spec */
764 return FALSE;
765 }
766 spec = p + 1;
767 }
768 }
769
770 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
771 {
772 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
773 if (attrib & DDL_DIRECTORY)
774 {
775 if (!(attrib & DDL_EXCLUSIVE))
776 {
777 if (SENDMSG( combo ? CB_DIR : LB_DIR,
778 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
779 (LPARAM)spec ) == LB_ERR)
780 return FALSE;
781 }
782 if (SENDMSG( combo ? CB_DIR : LB_DIR,
783 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
784 (LPARAM)"*.*" ) == LB_ERR)
785 return FALSE;
786 }
787 else
788 {
789 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
790 (LPARAM)spec ) == LB_ERR)
791 return FALSE;
792 }
793 }
794
795 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
796 {
797 char temp[512], curpath[512];
798 int drive = DRIVE_GetCurrentDrive();
799 strcpy( temp, "A:\\" );
800 temp[0] += drive;
801 lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive, sizeof(curpath)), sizeof(temp)-3 );
802 CharLowerA( temp );
803 /* Can't use PostMessage() here, because the string is on the stack */
804 SetDlgItemTextA( hDlg, idStatic, temp );
805 }
806
807 if (orig_spec && (spec != orig_spec))
808 {
809 /* Update the original file spec */
810 char *p = spec;
811 while ((*orig_spec++ = *p++) != 0);
812 }
813
814 return TRUE;
815#undef SENDMSG
816}
817
818
819/**********************************************************************
820 * DIALOG_DlgDirListW
821 *
822 * Helper function for DlgDirList*32W
823 */
824static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
825 INT idStatic, UINT attrib, BOOL combo )
826{
827 if (spec)
828 {
829 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
830 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
831 attrib, combo );
832 lstrcpyAtoW( spec, specA );
833 HeapFree( GetProcessHeap(), 0, specA );
834 return ret;
835 }
836 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
837}
838//******************************************************************************
839//******************************************************************************
840
Note: See TracBrowser for help on using the repository browser.