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

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

IsWindowVisible bugfix

File size: 26.7 KB
Line 
1/* $Id: windlg.cpp,v 1.24 2001-07-23 19:16:41 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\n"));
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 hwnd, HWND hwndCtrl, BOOL fPrevious)
520{
521 Win32BaseWindow *window;
522
523 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
524 if(!window) {
525 dprintf(("GetNextDlgGroupItem, window %x not found", hwnd));
526 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
527 return 0;
528 }
529 dprintf(("USER32: GetNextDlgGroupItem\n"));
530 return window->getNextDlgGroupItem(hwndCtrl, fPrevious);
531}
532/***********************************************************************
533 * GetDialogBaseUnits (USER.243) (USER32.233)
534 */
535DWORD WIN32API GetDialogBaseUnits(void)
536{
537 return Win32Dialog::GetDialogBaseUnits();
538}
539//******************************************************************************
540//******************************************************************************
541INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
542{
543 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
544}
545//******************************************************************************
546//******************************************************************************
547int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
548{
549 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
550}
551//******************************************************************************
552//******************************************************************************
553INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
554{
555 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
556}
557//******************************************************************************
558//******************************************************************************
559INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
560{
561 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
562}
563//******************************************************************************
564//******************************************************************************
565BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
566{
567 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
568}
569//******************************************************************************
570//******************************************************************************
571BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
572{
573 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
574}
575//******************************************************************************
576//******************************************************************************
577BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
578{
579 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
580}
581//******************************************************************************
582//******************************************************************************
583BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
584{
585 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
586}
587/**********************************************************************
588 * DIALOG_DlgDirSelect
589 *
590 * Helper function for DlgDirSelect*
591 */
592static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
593 INT id, BOOL win32, BOOL unicode,
594 BOOL combo )
595{
596 char *buffer, *ptr;
597 INT item, size;
598 BOOL ret;
599 HWND listbox = GetDlgItem( hwnd, id );
600
601 if (!listbox) return FALSE;
602
603 item = SendMessageA(listbox, combo ? CB_GETCURSEL
604 : LB_GETCURSEL, 0, 0 );
605 if (item == LB_ERR) return FALSE;
606 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
607 : LB_GETTEXTLEN, 0, 0 );
608 if (size == LB_ERR) return FALSE;
609
610 if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
611
612 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
613 item, (LPARAM)buffer );
614
615 if ((ret = (buffer[0] == '[')) != 0) /* drive or directory */
616 {
617 if (buffer[1] == '-') /* drive */
618 {
619 buffer[3] = ':';
620 buffer[4] = 0;
621 ptr = buffer + 2;
622 }
623 else
624 {
625 buffer[strlen(buffer)-1] = '\\';
626 ptr = buffer + 1;
627 }
628 }
629 else ptr = buffer;
630
631 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
632 else lstrcpynA( str, ptr, len );
633
634 free( buffer );
635 return ret;
636}
637
638
639/**********************************************************************
640 * DIALOG_DlgDirList
641 *
642 * Helper function for DlgDirList*
643 */
644static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
645 INT idStatic, UINT attrib, BOOL combo )
646{
647 int drive;
648 HWND hwnd;
649 LPSTR orig_spec = spec;
650
651#define SENDMSG(msg,wparam,lparam) \
652 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
653 : SendMessageA( hwnd, msg, wparam, lparam ))
654
655 if (spec && spec[0] && (spec[1] == ':'))
656 {
657 drive = _toupper( spec[0] ) - 'A';
658 spec += 2;
659 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
660 }
661 else drive = DRIVE_GetCurrentDrive();
662
663 /* If the path exists and is a directory, chdir to it */
664 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
665 else
666 {
667 char *p, *p2;
668 p = spec;
669 if ((p2 = strrchr( p, '\\' )) != 0) p = p2;
670 if ((p2 = strrchr( p, '/' )) != 0) p = p2;
671 if (p != spec)
672 {
673 char sep = *p;
674 *p = 0;
675 if (!DRIVE_Chdir( drive, spec ))
676 {
677 *p = sep; /* Restore the original spec */
678 return FALSE;
679 }
680 spec = p + 1;
681 }
682 }
683
684 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
685 {
686 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
687 if (attrib & DDL_DIRECTORY)
688 {
689 if (!(attrib & DDL_EXCLUSIVE))
690 {
691 if (SENDMSG( combo ? CB_DIR : LB_DIR,
692 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
693 (LPARAM)spec ) == LB_ERR)
694 return FALSE;
695 }
696 if (SENDMSG( combo ? CB_DIR : LB_DIR,
697 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
698 (LPARAM)"*.*" ) == LB_ERR)
699 return FALSE;
700 }
701 else
702 {
703 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
704 (LPARAM)spec ) == LB_ERR)
705 return FALSE;
706 }
707 }
708
709 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
710 {
711 char temp[512], curpath[512];
712 int drive = DRIVE_GetCurrentDrive();
713 strcpy( temp, "A:\\" );
714 temp[0] += drive;
715 lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive, sizeof(curpath)), sizeof(temp)-3 );
716 CharLowerA( temp );
717 /* Can't use PostMessage() here, because the string is on the stack */
718 SetDlgItemTextA( hDlg, idStatic, temp );
719 }
720
721 if (orig_spec && (spec != orig_spec))
722 {
723 /* Update the original file spec */
724 char *p = spec;
725 while ((*orig_spec++ = *p++) != 0);
726 }
727
728 return TRUE;
729#undef SENDMSG
730}
731
732
733/**********************************************************************
734 * DIALOG_DlgDirListW
735 *
736 * Helper function for DlgDirList*32W
737 */
738static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
739 INT idStatic, UINT attrib, BOOL combo )
740{
741 if (spec)
742 {
743 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
744 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
745 attrib, combo );
746 lstrcpyAtoW( spec, specA );
747 HeapFree( GetProcessHeap(), 0, specA );
748 return ret;
749 }
750 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
751}
752//******************************************************************************
753//******************************************************************************
754
Note: See TracBrowser for help on using the repository browser.