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

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

SetFocus fix

File size: 28.4 KB
Line 
1/* $Id: windlg.cpp,v 1.27 2001-10-17 14:30:10 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 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
555 }
556
557 retvalue = hwndCtrl;
558 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
559 while (1)
560 {
561 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
562 {
563 /* Wrap-around to the beginning of the group */
564 HWND tmp;
565
566 hwnd = GetWindow( hwndDlg, GW_CHILD );
567#ifdef __WIN32OS2__
568 if(!hwnd) break;
569#endif
570 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
571 {
572 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
573 if (tmp == hwndCtrl) break;
574 }
575 }
576 if (hwnd == hwndCtrl) break;
577 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
578 {
579 retvalue = hwnd;
580 if (!fPrevious) break;
581 }
582 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
583 }
584 return retvalue;
585}
586/***********************************************************************
587 * GetDialogBaseUnits (USER.243) (USER32.233)
588 */
589DWORD WIN32API GetDialogBaseUnits(void)
590{
591 return Win32Dialog::GetDialogBaseUnits();
592}
593//******************************************************************************
594//******************************************************************************
595INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
596{
597 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
598}
599//******************************************************************************
600//******************************************************************************
601int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
602{
603 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
604}
605//******************************************************************************
606//******************************************************************************
607INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
608{
609 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
610}
611//******************************************************************************
612//******************************************************************************
613INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
614{
615 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
616}
617//******************************************************************************
618//******************************************************************************
619BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
620{
621 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
622}
623//******************************************************************************
624//******************************************************************************
625BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
626{
627 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
628}
629//******************************************************************************
630//******************************************************************************
631BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
632{
633 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
634}
635//******************************************************************************
636//******************************************************************************
637BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
638{
639 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
640}
641/**********************************************************************
642 * DIALOG_DlgDirSelect
643 *
644 * Helper function for DlgDirSelect*
645 */
646static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
647 INT id, BOOL win32, BOOL unicode,
648 BOOL combo )
649{
650 char *buffer, *ptr;
651 INT item, size;
652 BOOL ret;
653 HWND listbox = GetDlgItem( hwnd, id );
654
655 if (!listbox) return FALSE;
656
657 item = SendMessageA(listbox, combo ? CB_GETCURSEL
658 : LB_GETCURSEL, 0, 0 );
659 if (item == LB_ERR) return FALSE;
660 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
661 : LB_GETTEXTLEN, 0, 0 );
662 if (size == LB_ERR) return FALSE;
663
664 if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
665
666 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
667 item, (LPARAM)buffer );
668
669 if ((ret = (buffer[0] == '[')) != 0) /* drive or directory */
670 {
671 if (buffer[1] == '-') /* drive */
672 {
673 buffer[3] = ':';
674 buffer[4] = 0;
675 ptr = buffer + 2;
676 }
677 else
678 {
679 buffer[strlen(buffer)-1] = '\\';
680 ptr = buffer + 1;
681 }
682 }
683 else ptr = buffer;
684
685 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
686 else lstrcpynA( str, ptr, len );
687
688 free( buffer );
689 return ret;
690}
691
692
693/**********************************************************************
694 * DIALOG_DlgDirList
695 *
696 * Helper function for DlgDirList*
697 */
698static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
699 INT idStatic, UINT attrib, BOOL combo )
700{
701 int drive;
702 HWND hwnd;
703 LPSTR orig_spec = spec;
704
705#define SENDMSG(msg,wparam,lparam) \
706 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
707 : SendMessageA( hwnd, msg, wparam, lparam ))
708
709 if (spec && spec[0] && (spec[1] == ':'))
710 {
711 drive = _toupper( spec[0] ) - 'A';
712 spec += 2;
713 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
714 }
715 else drive = DRIVE_GetCurrentDrive();
716
717 /* If the path exists and is a directory, chdir to it */
718 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
719 else
720 {
721 char *p, *p2;
722 p = spec;
723 if ((p2 = strrchr( p, '\\' )) != 0) p = p2;
724 if ((p2 = strrchr( p, '/' )) != 0) p = p2;
725 if (p != spec)
726 {
727 char sep = *p;
728 *p = 0;
729 if (!DRIVE_Chdir( drive, spec ))
730 {
731 *p = sep; /* Restore the original spec */
732 return FALSE;
733 }
734 spec = p + 1;
735 }
736 }
737
738 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
739 {
740 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
741 if (attrib & DDL_DIRECTORY)
742 {
743 if (!(attrib & DDL_EXCLUSIVE))
744 {
745 if (SENDMSG( combo ? CB_DIR : LB_DIR,
746 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
747 (LPARAM)spec ) == LB_ERR)
748 return FALSE;
749 }
750 if (SENDMSG( combo ? CB_DIR : LB_DIR,
751 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
752 (LPARAM)"*.*" ) == LB_ERR)
753 return FALSE;
754 }
755 else
756 {
757 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
758 (LPARAM)spec ) == LB_ERR)
759 return FALSE;
760 }
761 }
762
763 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
764 {
765 char temp[512], curpath[512];
766 int drive = DRIVE_GetCurrentDrive();
767 strcpy( temp, "A:\\" );
768 temp[0] += drive;
769 lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive, sizeof(curpath)), sizeof(temp)-3 );
770 CharLowerA( temp );
771 /* Can't use PostMessage() here, because the string is on the stack */
772 SetDlgItemTextA( hDlg, idStatic, temp );
773 }
774
775 if (orig_spec && (spec != orig_spec))
776 {
777 /* Update the original file spec */
778 char *p = spec;
779 while ((*orig_spec++ = *p++) != 0);
780 }
781
782 return TRUE;
783#undef SENDMSG
784}
785
786
787/**********************************************************************
788 * DIALOG_DlgDirListW
789 *
790 * Helper function for DlgDirList*32W
791 */
792static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
793 INT idStatic, UINT attrib, BOOL combo )
794{
795 if (spec)
796 {
797 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
798 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
799 attrib, combo );
800 lstrcpyAtoW( spec, specA );
801 HeapFree( GetProcessHeap(), 0, specA );
802 return ret;
803 }
804 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
805}
806//******************************************************************************
807//******************************************************************************
808
Note: See TracBrowser for help on using the repository browser.