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

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

Don't repaint groupbox in WM_SETFONT if control isn't visible

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