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

Last change on this file since 5146 was 5146, checked in by sandervl, 25 years ago

activate, tab and ischild bugfixes

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