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

Last change on this file since 8266 was 8132, checked in by sandervl, 23 years ago

customization updates

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