Windows with WS_EX_TOOLWINDOW style should not have min/max buttons.
[wine] / windows / dialog.c
1 /*
2  * Dialog functions
3  *
4  * Copyright 1993, 1994, 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <ctype.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winnls.h"
37 #include "wine/winuser16.h"
38 #include "wine/unicode.h"
39 #include "controls.h"
40 #include "win.h"
41 #include "winpos.h"
42 #include "user.h"
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
46
47
48   /* Dialog control information */
49 typedef struct
50 {
51     DWORD      style;
52     DWORD      exStyle;
53     DWORD      helpId;
54     INT16      x;
55     INT16      y;
56     INT16      cx;
57     INT16      cy;
58     UINT       id;
59     LPCWSTR    className;
60     LPCWSTR    windowName;
61     LPCVOID    data;
62 } DLG_CONTROL_INFO;
63
64   /* Dialog template */
65 typedef struct
66 {
67     DWORD      style;
68     DWORD      exStyle;
69     DWORD      helpId;
70     UINT16     nbItems;
71     INT16      x;
72     INT16      y;
73     INT16      cx;
74     INT16      cy;
75     LPCWSTR    menuName;
76     LPCWSTR    className;
77     LPCWSTR    caption;
78     INT16      pointSize;
79     WORD       weight;
80     BOOL       italic;
81     LPCWSTR    faceName;
82     BOOL       dialogEx;
83 } DLG_TEMPLATE;
84
85   /* Radio button group */
86 typedef struct
87 {
88     UINT firstID;
89     UINT lastID;
90     UINT checkID;
91 } RADIOGROUP;
92
93
94 /*********************************************************************
95  * dialog class descriptor
96  */
97 const struct builtin_class_descr DIALOG_builtin_class =
98 {
99     DIALOG_CLASS_ATOMA,  /* name */
100     CS_SAVEBITS | CS_DBLCLKS, /* style  */
101     DefDlgProcA,        /* procA */
102     DefDlgProcW,        /* procW */
103     DLGWINDOWEXTRA,     /* extra */
104     IDC_ARROW,          /* cursor */
105     0                   /* brush */
106 };
107
108
109 /***********************************************************************
110  *           DIALOG_EnableOwner
111  *
112  * Helper function for modal dialogs to enable again the
113  * owner of the dialog box.
114  */
115 void DIALOG_EnableOwner( HWND hOwner )
116 {
117     /* Owner must be a top-level window */
118     if (hOwner)
119         hOwner = GetAncestor( hOwner, GA_ROOT );
120     if (!hOwner) return;
121     EnableWindow( hOwner, TRUE );
122 }
123
124
125 /***********************************************************************
126  *           DIALOG_DisableOwner
127  *
128  * Helper function for modal dialogs to disable the
129  * owner of the dialog box. Returns TRUE if owner was enabled.
130  */
131 BOOL DIALOG_DisableOwner( HWND hOwner )
132 {
133     /* Owner must be a top-level window */
134     if (hOwner)
135         hOwner = GetAncestor( hOwner, GA_ROOT );
136     if (!hOwner) return FALSE;
137     if (IsWindowEnabled( hOwner ))
138     {
139         EnableWindow( hOwner, FALSE );
140         return TRUE;
141     }
142     else
143         return FALSE;
144 }
145
146 /***********************************************************************
147  *           DIALOG_GetCharSize
148  *
149  * Despite most of MSDN insisting that the horizontal base unit is
150  * tmAveCharWidth it isn't.  Knowledge base article Q145994
151  * "HOWTO: Calculate Dialog Units When Not Using the System Font",
152  * says that we should take the average of the 52 English upper and lower
153  * case characters.
154  */
155 BOOL DIALOG_GetCharSize( HDC hDC, HFONT hFont, SIZE * pSize )
156 {
157     HFONT hFontPrev = 0;
158     const char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
159     SIZE sz;
160     TEXTMETRICA tm;
161
162     if(!hDC) return FALSE;
163
164     if(hFont) hFontPrev = SelectObject(hDC, hFont);
165     if(!GetTextMetricsA(hDC, &tm)) return FALSE;
166     if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
167
168     pSize->cy = tm.tmHeight;
169     pSize->cx = (sz.cx / 26 + 1) / 2;
170
171     if (hFontPrev) SelectObject(hDC, hFontPrev);
172
173     TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy);
174     return TRUE;
175 }
176
177
178 /***********************************************************************
179  *           DIALOG_GetControl32
180  *
181  * Return the class and text of the control pointed to by ptr,
182  * fill the header structure and return a pointer to the next control.
183  */
184 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
185                                         BOOL dialogEx )
186 {
187     if (dialogEx)
188     {
189         info->helpId  = GET_DWORD(p); p += 2;
190         info->exStyle = GET_DWORD(p); p += 2;
191         info->style   = GET_DWORD(p); p += 2;
192     }
193     else
194     {
195         info->helpId  = 0;
196         info->style   = GET_DWORD(p); p += 2;
197         info->exStyle = GET_DWORD(p); p += 2;
198     }
199     info->x       = GET_WORD(p); p++;
200     info->y       = GET_WORD(p); p++;
201     info->cx      = GET_WORD(p); p++;
202     info->cy      = GET_WORD(p); p++;
203
204     if (dialogEx)
205     {
206         /* id is a DWORD for DIALOGEX */
207         info->id = GET_DWORD(p);
208         p += 2;
209     }
210     else
211     {
212         info->id = GET_WORD(p);
213         p++;
214     }
215
216     if (GET_WORD(p) == 0xffff)
217     {
218         static const WCHAR class_names[6][10] =
219         {
220             { 'B','u','t','t','o','n', },             /* 0x80 */
221             { 'E','d','i','t', },                     /* 0x81 */
222             { 'S','t','a','t','i','c', },             /* 0x82 */
223             { 'L','i','s','t','B','o','x', },         /* 0x83 */
224             { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
225             { 'C','o','m','b','o','B','o','x', }      /* 0x85 */
226         };
227         WORD id = GET_WORD(p+1);
228         /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
229         if ((id >= 0x80) && (id <= 0x85)) id -= 0x80;
230         if (id <= 5)
231             info->className = class_names[id];
232         else
233         {
234             info->className = NULL;
235             ERR("Unknown built-in class id %04x\n", id );
236         }
237         p += 2;
238     }
239     else
240     {
241         info->className = (LPCWSTR)p;
242         p += strlenW( info->className ) + 1;
243     }
244
245     if (GET_WORD(p) == 0xffff)  /* Is it an integer id? */
246     {
247         info->windowName = (LPCWSTR)(UINT)GET_WORD(p + 1);
248         p += 2;
249     }
250     else
251     {
252         info->windowName = (LPCWSTR)p;
253         p += strlenW( info->windowName ) + 1;
254     }
255
256     TRACE("    %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
257           debugstr_w( info->className ), debugstr_w( info->windowName ),
258           info->id, info->x, info->y, info->cx, info->cy,
259           info->style, info->exStyle, info->helpId );
260
261     if (GET_WORD(p))
262     {
263         if (TRACE_ON(dialog))
264         {
265             WORD i, count = GET_WORD(p) / sizeof(WORD);
266             TRACE("  BEGIN\n");
267             TRACE("    ");
268             for (i = 0; i < count; i++) TRACE( "%04x,", GET_WORD(p+i+1) );
269             TRACE("\n");
270             TRACE("  END\n" );
271         }
272         info->data = p + 1;
273         p += GET_WORD(p) / sizeof(WORD);
274     }
275     else info->data = NULL;
276     p++;
277
278     /* Next control is on dword boundary */
279     return (const WORD *)((((int)p) + 3) & ~3);
280 }
281
282
283 /***********************************************************************
284  *           DIALOG_CreateControls32
285  *
286  * Create the control windows for a dialog.
287  */
288 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
289                                      HINSTANCE hInst, BOOL unicode )
290 {
291     DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd, TRUE );
292     DLG_CONTROL_INFO info;
293     HWND hwndCtrl, hwndDefButton = 0;
294     INT items = dlgTemplate->nbItems;
295
296     TRACE(" BEGIN\n" );
297     while (items--)
298     {
299         template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
300                                                 dlgTemplate->dialogEx );
301         /* Is this it? */
302         if (info.style & WS_BORDER)
303         {
304             info.style &= ~WS_BORDER;
305             info.exStyle |= WS_EX_CLIENTEDGE;
306         }
307         if (unicode)
308         {
309             hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
310                                         info.className, info.windowName,
311                                         info.style | WS_CHILD,
312                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
313                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
314                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
315                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
316                                         hwnd, (HMENU)info.id,
317                                         hInst, (LPVOID)info.data );
318         }
319         else
320         {
321             LPSTR class = (LPSTR)info.className;
322             LPSTR caption = (LPSTR)info.windowName;
323
324             if (HIWORD(class))
325             {
326                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
327                 class = HeapAlloc( GetProcessHeap(), 0, len );
328                 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
329             }
330             if (HIWORD(caption))
331             {
332                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
333                 caption = HeapAlloc( GetProcessHeap(), 0, len );
334                 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
335             }
336             hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
337                                         class, caption, info.style | WS_CHILD,
338                                         MulDiv(info.x, dlgInfo->xBaseUnit, 4),
339                                         MulDiv(info.y, dlgInfo->yBaseUnit, 8),
340                                         MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
341                                         MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
342                                         hwnd, (HMENU)info.id,
343                                         hInst, (LPVOID)info.data );
344             if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
345             if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
346         }
347         if (!hwndCtrl)
348         {
349             if (dlgTemplate->style & DS_NOFAILCREATE) continue;
350             return FALSE;
351         }
352
353             /* Send initialisation messages to the control */
354         if (dlgInfo->hUserFont) SendMessageW( hwndCtrl, WM_SETFONT,
355                                              (WPARAM)dlgInfo->hUserFont, 0 );
356         if (SendMessageW(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
357         {
358               /* If there's already a default push-button, set it back */
359               /* to normal and use this one instead. */
360             if (hwndDefButton)
361                 SendMessageW( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
362             hwndDefButton = hwndCtrl;
363             dlgInfo->idResult = GetWindowLongPtrA( hwndCtrl, GWLP_ID );
364         }
365     }
366     TRACE(" END\n" );
367     return TRUE;
368 }
369
370
371 /***********************************************************************
372  *           DIALOG_ParseTemplate32
373  *
374  * Fill a DLG_TEMPLATE structure from the dialog template, and return
375  * a pointer to the first control.
376  */
377 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
378 {
379     const WORD *p = (const WORD *)template;
380
381     result->style = GET_DWORD(p); p += 2;
382     if (result->style == 0xffff0001)  /* DIALOGEX resource */
383     {
384         result->dialogEx = TRUE;
385         result->helpId   = GET_DWORD(p); p += 2;
386         result->exStyle  = GET_DWORD(p); p += 2;
387         result->style    = GET_DWORD(p); p += 2;
388     }
389     else
390     {
391         result->dialogEx = FALSE;
392         result->helpId   = 0;
393         result->exStyle  = GET_DWORD(p); p += 2;
394     }
395     result->nbItems = GET_WORD(p); p++;
396     result->x       = GET_WORD(p); p++;
397     result->y       = GET_WORD(p); p++;
398     result->cx      = GET_WORD(p); p++;
399     result->cy      = GET_WORD(p); p++;
400     TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
401            result->dialogEx ? "EX" : "", result->x, result->y,
402            result->cx, result->cy, result->helpId );
403     TRACE(" STYLE 0x%08lx\n", result->style );
404     TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
405
406     /* Get the menu name */
407
408     switch(GET_WORD(p))
409     {
410     case 0x0000:
411         result->menuName = NULL;
412         p++;
413         break;
414     case 0xffff:
415         result->menuName = (LPCWSTR)(UINT)GET_WORD( p + 1 );
416         p += 2;
417         TRACE(" MENU %04x\n", LOWORD(result->menuName) );
418         break;
419     default:
420         result->menuName = (LPCWSTR)p;
421         TRACE(" MENU %s\n", debugstr_w(result->menuName) );
422         p += strlenW( result->menuName ) + 1;
423         break;
424     }
425
426     /* Get the class name */
427
428     switch(GET_WORD(p))
429     {
430     case 0x0000:
431         result->className = DIALOG_CLASS_ATOMW;
432         p++;
433         break;
434     case 0xffff:
435         result->className = (LPCWSTR)(UINT)GET_WORD( p + 1 );
436         p += 2;
437         TRACE(" CLASS %04x\n", LOWORD(result->className) );
438         break;
439     default:
440         result->className = (LPCWSTR)p;
441         TRACE(" CLASS %s\n", debugstr_w( result->className ));
442         p += strlenW( result->className ) + 1;
443         break;
444     }
445
446     /* Get the window caption */
447
448     result->caption = (LPCWSTR)p;
449     p += strlenW( result->caption ) + 1;
450     TRACE(" CAPTION %s\n", debugstr_w( result->caption ) );
451
452     /* Get the font name */
453
454     if (result->style & DS_SETFONT)
455     {
456         result->pointSize = GET_WORD(p);
457         p++;
458         if (result->dialogEx)
459         {
460             result->weight = GET_WORD(p); p++;
461             result->italic = LOBYTE(GET_WORD(p)); p++;
462         }
463         else
464         {
465             result->weight = FW_DONTCARE;
466             result->italic = FALSE;
467         }
468         result->faceName = (LPCWSTR)p;
469         p += strlenW( result->faceName ) + 1;
470         TRACE(" FONT %d, %s, %d, %s\n",
471               result->pointSize, debugstr_w( result->faceName ),
472               result->weight, result->italic ? "TRUE" : "FALSE" );
473     }
474
475     /* First control is on dword boundary */
476     return (LPCSTR)((((int)p) + 3) & ~3);
477 }
478
479
480 /***********************************************************************
481  *           DIALOG_CreateIndirect
482  *       Creates a dialog box window
483  *
484  *       modal = TRUE if we are called from a modal dialog box.
485  *       (it's more compatible to do it here, as under Windows the owner
486  *       is never disabled if the dialog fails because of an invalid template)
487  */
488 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
489                                    HWND owner, DLGPROC dlgProc, LPARAM param,
490                                    BOOL unicode, BOOL modal )
491 {
492     HWND hwnd;
493     RECT rect;
494     DLG_TEMPLATE template;
495     DIALOGINFO * dlgInfo = NULL;
496     DWORD units = GetDialogBaseUnits();
497     BOOL ownerEnabled = TRUE;
498     HMENU hMenu = 0;
499     HFONT hUserFont = 0;
500     UINT flags = 0;
501     UINT xBaseUnit = LOWORD(units);
502     UINT yBaseUnit = HIWORD(units);
503
504       /* Parse dialog template */
505
506     if (!dlgTemplate) return 0;
507     dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
508
509       /* Load menu */
510
511     if (template.menuName) hMenu = LoadMenuW( hInst, template.menuName );
512
513       /* Create custom font if needed */
514
515     if (template.style & DS_SETFONT)
516     {
517           /* We convert the size to pixels and then make it -ve.  This works
518            * for both +ve and -ve template.pointSize */
519         HDC dc;
520         int pixels;
521         dc = GetDC(0);
522         pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
523         hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
524                                           template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
525                                           PROOF_QUALITY, FF_DONTCARE,
526                                           template.faceName );
527         if (hUserFont)
528         {
529             SIZE charSize;
530             if (DIALOG_GetCharSize( dc, hUserFont, &charSize ))
531             {
532                 xBaseUnit = charSize.cx;
533                 yBaseUnit = charSize.cy;
534             }
535         }
536         ReleaseDC(0, dc);
537         TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
538     }
539
540     /* Create dialog main window */
541
542     rect.left = rect.top = 0;
543     rect.right = MulDiv(template.cx, xBaseUnit, 4);
544     rect.bottom =  MulDiv(template.cy, yBaseUnit, 8);
545     if (template.style & WS_CHILD)
546         template.style &= ~(WS_CAPTION|WS_SYSMENU);
547     if (template.style & DS_MODALFRAME)
548         template.exStyle |= WS_EX_DLGMODALFRAME;
549     if (template.style & DS_CONTROL)
550         template.exStyle |= WS_EX_CONTROLPARENT;
551     AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
552     rect.right -= rect.left;
553     rect.bottom -= rect.top;
554
555     if (template.x == CW_USEDEFAULT16)
556     {
557         rect.left = rect.top = CW_USEDEFAULT;
558     }
559     else
560     {
561         if (template.style & DS_CENTER)
562         {
563             rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
564             rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
565         }
566         else
567         {
568             rect.left += MulDiv(template.x, xBaseUnit, 4);
569             rect.top += MulDiv(template.y, yBaseUnit, 8);
570         }
571         if ( !(template.style & WS_CHILD) )
572         {
573             INT dX, dY;
574
575             if( !(template.style & DS_ABSALIGN) )
576                 ClientToScreen( owner, (POINT *)&rect );
577
578             /* try to fit it into the desktop */
579
580             if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
581                  - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
582             if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
583                  - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
584             if( rect.left < 0 ) rect.left = 0;
585             if( rect.top < 0 ) rect.top = 0;
586         }
587     }
588
589     if (modal)
590     {
591         ownerEnabled = DIALOG_DisableOwner( owner );
592         if (ownerEnabled) flags |= DF_OWNERENABLED;
593     }
594
595     if (unicode)
596     {
597         hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
598                                template.style & ~WS_VISIBLE,
599                                rect.left, rect.top, rect.right, rect.bottom,
600                                owner, hMenu, hInst, NULL );
601     }
602     else
603     {
604         LPSTR class = (LPSTR)template.className;
605         LPSTR caption = (LPSTR)template.caption;
606
607         if (HIWORD(class))
608         {
609             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
610             class = HeapAlloc( GetProcessHeap(), 0, len );
611             WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
612         }
613         if (HIWORD(caption))
614         {
615             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
616             caption = HeapAlloc( GetProcessHeap(), 0, len );
617             WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
618         }
619         hwnd = CreateWindowExA(template.exStyle, class, caption,
620                                template.style & ~WS_VISIBLE,
621                                rect.left, rect.top, rect.right, rect.bottom,
622                                owner, hMenu, hInst, NULL );
623         if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
624         if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
625     }
626
627     if (!hwnd)
628     {
629         if (hUserFont) DeleteObject( hUserFont );
630         if (hMenu) DestroyMenu( hMenu );
631         if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
632         return 0;
633     }
634    
635     /* moved this from the top of the method to here as DIALOGINFO structure
636     will be valid only after WM_CREATE message has been handled in DefDlgProc
637     All the members of the structure get filled here using temp variables */
638     dlgInfo = DIALOG_get_info( hwnd, TRUE );
639     dlgInfo->hwndFocus   = 0;
640     dlgInfo->hUserFont   = hUserFont;
641     dlgInfo->hMenu       = hMenu;
642     dlgInfo->xBaseUnit   = xBaseUnit;
643     dlgInfo->yBaseUnit   = yBaseUnit;
644     dlgInfo->idResult    = 0;
645     dlgInfo->flags       = flags;
646     dlgInfo->hDialogHeap = 0;
647     
648     if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
649
650     if (unicode) SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc );
651     else SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc );
652
653     if (dlgInfo->hUserFont)
654         SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
655
656     /* Create controls */
657
658     if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
659     {
660         /* Send initialisation messages and set focus */
661
662         if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
663         {
664             /* By returning TRUE, app has requested a default focus assignment */
665             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
666             if( dlgInfo->hwndFocus )
667                 SetFocus( dlgInfo->hwndFocus );
668         }
669
670         if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
671         {
672            ShowWindow( hwnd, SW_SHOWNORMAL );   /* SW_SHOW doesn't always work */
673         }
674         return hwnd;
675     }
676     if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
677     if( IsWindow(hwnd) ) DestroyWindow( hwnd );
678     return 0;
679 }
680
681
682 /***********************************************************************
683  *              CreateDialogParamA (USER32.@)
684  */
685 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name, HWND owner,
686                                 DLGPROC dlgProc, LPARAM param )
687 {
688     HRSRC hrsrc;
689     LPCDLGTEMPLATEA ptr;
690
691     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
692     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
693     return CreateDialogIndirectParamA( hInst, ptr, owner, dlgProc, param );
694 }
695
696
697 /***********************************************************************
698  *              CreateDialogParamW (USER32.@)
699  */
700 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name, HWND owner,
701                                 DLGPROC dlgProc, LPARAM param )
702 {
703     HRSRC hrsrc;
704     LPCDLGTEMPLATEA ptr;
705
706     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
707     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
708     return CreateDialogIndirectParamW( hInst, ptr, owner, dlgProc, param );
709 }
710
711
712 /***********************************************************************
713  *              CreateDialogIndirectParamAorW (USER32.@)
714  */
715 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst, LPCVOID dlgTemplate,
716                                            HWND owner, DLGPROC dlgProc, LPARAM param,
717                                            DWORD flags )
718 {
719     return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, !flags, FALSE );
720 }
721
722 /***********************************************************************
723  *              CreateDialogIndirectParamA (USER32.@)
724  */
725 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst, LPCDLGTEMPLATEA dlgTemplate,
726                                         HWND owner, DLGPROC dlgProc, LPARAM param )
727 {
728     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 2 );
729 }
730
731 /***********************************************************************
732  *              CreateDialogIndirectParamW (USER32.@)
733  */
734 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst, LPCDLGTEMPLATEW dlgTemplate,
735                                         HWND owner, DLGPROC dlgProc, LPARAM param )
736 {
737     return CreateDialogIndirectParamAorW( hInst, dlgTemplate, owner, dlgProc, param, 0 );
738 }
739
740
741 /***********************************************************************
742  *           DIALOG_DoDialogBox
743  */
744 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
745 {
746     DIALOGINFO * dlgInfo;
747     MSG msg;
748     INT retval;
749     HWND ownerMsg = GetAncestor( owner, GA_ROOT );
750     BOOL bFirstEmpty;
751
752     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE ))) return -1;
753
754     bFirstEmpty = TRUE;
755     if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
756     {
757         for (;;)
758         {
759             if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
760             {
761                 if (bFirstEmpty)
762                 {
763                     /* ShowWindow the first time the queue goes empty */
764                     ShowWindow( hwnd, SW_SHOWNORMAL );
765                     bFirstEmpty = FALSE;
766                 }
767                 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
768                {
769                     /* No message present -> send ENTERIDLE and wait */
770                     SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
771                 }
772                 if (!GetMessageW( &msg, 0, 0, 0 )) break;
773             }
774
775             if (!IsWindow( hwnd )) return -1;
776             if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
777             {
778                 TranslateMessage( &msg );
779                 DispatchMessageW( &msg );
780             }
781             if (dlgInfo->flags & DF_END) break;
782         }
783     }
784     if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
785     retval = dlgInfo->idResult;
786     DestroyWindow( hwnd );
787     return retval;
788 }
789
790
791 /***********************************************************************
792  *              DialogBoxParamA (USER32.@)
793  */
794 INT_PTR WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
795                                 HWND owner, DLGPROC dlgProc, LPARAM param )
796 {
797     HWND hwnd;
798     HRSRC hrsrc;
799     LPCDLGTEMPLATEA ptr;
800
801     if (!(hrsrc = FindResourceA( hInst, name, (LPSTR)RT_DIALOG ))) return 0;
802     if (!(ptr = (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc))) return 0;
803     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, FALSE, TRUE );
804     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
805     return -1;
806 }
807
808
809 /***********************************************************************
810  *              DialogBoxParamW (USER32.@)
811  */
812 INT_PTR WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
813                                 HWND owner, DLGPROC dlgProc, LPARAM param )
814 {
815     HWND hwnd;
816     HRSRC hrsrc;
817     LPCDLGTEMPLATEW ptr;
818
819     if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
820     if (!(ptr = (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc))) return 0;
821     hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, TRUE, TRUE );
822     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
823     return -1;
824 }
825
826
827 /***********************************************************************
828  *              DialogBoxIndirectParamAorW (USER32.@)
829  */
830 INT_PTR WINAPI DialogBoxIndirectParamAorW( HINSTANCE hInstance, LPCVOID template,
831                                            HWND owner, DLGPROC dlgProc,
832                                            LPARAM param, DWORD flags )
833 {
834     HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, !flags, TRUE );
835     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
836     return -1;
837 }
838
839 /***********************************************************************
840  *              DialogBoxIndirectParamA (USER32.@)
841  */
842 INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCDLGTEMPLATEA template,
843                                        HWND owner, DLGPROC dlgProc, LPARAM param )
844 {
845     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 2 );
846 }
847
848
849 /***********************************************************************
850  *              DialogBoxIndirectParamW (USER32.@)
851  */
852 INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCDLGTEMPLATEW template,
853                                        HWND owner, DLGPROC dlgProc, LPARAM param )
854 {
855     return DialogBoxIndirectParamAorW( hInstance, template, owner, dlgProc, param, 0 );
856 }
857
858 /***********************************************************************
859  *              EndDialog (USER32.@)
860  */
861 BOOL WINAPI EndDialog( HWND hwnd, INT_PTR retval )
862 {
863     BOOL wasEnabled = TRUE;
864     DIALOGINFO * dlgInfo;
865     HWND owner;
866
867     TRACE("%p %d\n", hwnd, retval );
868
869     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE )))
870     {
871         ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
872         return FALSE;
873     }
874     dlgInfo->idResult = retval;
875     dlgInfo->flags |= DF_END;
876     wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
877
878     if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
879         DIALOG_EnableOwner( owner );
880
881     /* Windows sets the focus to the dialog itself in EndDialog */
882
883     if (IsChild(hwnd, GetFocus()))
884        SetFocus( hwnd );
885
886     /* Don't have to send a ShowWindow(SW_HIDE), just do
887        SetWindowPos with SWP_HIDEWINDOW as done in Windows */
888
889     SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
890                  | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
891
892     if (hwnd == GetActiveWindow()) WINPOS_ActivateOtherWindow( hwnd );
893
894     /* unblock dialog loop */
895     PostMessageA(hwnd, WM_NULL, 0, 0);
896     return TRUE;
897 }
898
899
900 /***********************************************************************
901  *           DIALOG_IsAccelerator
902  */
903 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
904 {
905     HWND hwndControl = hwnd;
906     HWND hwndNext;
907     INT dlgCode;
908     WCHAR buffer[128];
909
910     do
911     {
912         DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
913         if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
914         {
915             dlgCode = SendMessageW( hwndControl, WM_GETDLGCODE, 0, 0 );
916             if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
917                  GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
918             {
919                 /* find the accelerator key */
920                 LPWSTR p = buffer - 2;
921
922                 do
923                 {
924                     p = strchrW( p + 2, '&' );
925                 }
926                 while (p != NULL && p[1] == '&');
927
928                 /* and check if it's the one we're looking for */
929                 if (p != NULL && toupperW( p[1] ) == toupperW( wParam ) )
930                 {
931                     if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
932                     {
933                         /* set focus to the control */
934                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
935                         /* and bump it on to next */
936                         SendMessageW( hwndDlg, WM_NEXTDLGCTL, 0, 0);
937                     }
938                     else if (dlgCode & DLGC_BUTTON)
939                     {
940                         /* send BM_CLICK message to the control */
941                         SendMessageW( hwndControl, BM_CLICK, 0, 0 );
942                     }
943                     return TRUE;
944                 }
945             }
946             hwndNext = GetWindow( hwndControl, GW_CHILD );
947         }
948         else hwndNext = 0;
949
950         if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
951
952         while (!hwndNext && hwndControl)
953         {
954             hwndControl = GetParent( hwndControl );
955             if (hwndControl == hwndDlg)
956             {
957                 if(hwnd==hwndDlg)   /* prevent endless loop */
958                 {
959                     hwndNext=hwnd;
960                     break;
961                 }
962                 hwndNext = GetWindow( hwndDlg, GW_CHILD );
963             }
964             else
965                 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
966         }
967         hwndControl = hwndNext;
968     }
969     while (hwndControl && (hwndControl != hwnd));
970
971     return FALSE;
972 }
973
974 /***********************************************************************
975  *           DIALOG_FindMsgDestination
976  *
977  * The messages that IsDialogMessage sends may not go to the dialog
978  * calling IsDialogMessage if that dialog is a child, and it has the
979  * DS_CONTROL style set.
980  * We propagate up until we hit one that does not have DS_CONTROL, or
981  * whose parent is not a dialog.
982  *
983  * This is undocumented behaviour.
984  */
985 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
986 {
987     while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
988     {
989         WND *pParent;
990         HWND hParent = GetParent(hwndDlg);
991         if (!hParent) break;
992
993         pParent = WIN_FindWndPtr(hParent);
994         if (!pParent) break;
995
996         if (!(pParent->flags & WIN_ISDIALOG))
997         {
998             WIN_ReleaseWndPtr(pParent);
999             break;
1000         }
1001         WIN_ReleaseWndPtr(pParent);
1002
1003         hwndDlg = hParent;
1004     }
1005
1006     return hwndDlg;
1007 }
1008
1009 /***********************************************************************
1010  *              DIALOG_FixOneChildOnChangeFocus
1011  *
1012  * Callback helper for DIALOG_FixChildrenOnChangeFocus
1013  */
1014
1015 static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
1016         LPARAM lParam)
1017 {
1018     /* If a default pushbutton then no longer default */
1019     if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
1020         SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
1021     return TRUE;
1022 }
1023
1024 /***********************************************************************
1025  *              DIALOG_FixChildrenOnChangeFocus
1026  *
1027  * Following the change of focus that occurs for example after handling
1028  * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
1029  * children may be required.
1030  */
1031 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
1032 {
1033     INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
1034     /* INT dlgcode_dlg  = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
1035     /* Windows does ask for this.  I don't know why yet */
1036
1037     EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
1038
1039     /* If the button that is getting the focus WAS flagged as the default
1040      * pushbutton then ask the dialog what it thinks the default is and
1041      * set that in the default style.
1042      */
1043     if (dlgcode_next & DLGC_DEFPUSHBUTTON)
1044     {
1045         DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
1046         if (HIWORD(def_id) == DC_HASDEFID)
1047         {
1048             HWND hwndDef;
1049             def_id = LOWORD(def_id);
1050             hwndDef = GetDlgItem (hwndDlg, def_id);
1051             if (hwndDef)
1052             {
1053                 INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
1054                 /* I know that if it is a button then it should already be a
1055                  * UNDEFPUSHBUTTON, since we have just told the buttons to 
1056                  * change style.  But maybe they ignored our request
1057                  */
1058                 if ((dlgcode_def & DLGC_BUTTON) &&
1059                         (dlgcode_def &  DLGC_UNDEFPUSHBUTTON))
1060                 {
1061                     SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1062                 }
1063             }
1064         }
1065     }
1066     else
1067     {
1068         SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
1069         /* I wonder why it doesn't send a DM_SETDEFID */
1070     }
1071 }
1072
1073 /***********************************************************************
1074  *              IsDialogMessageW (USER32.@)
1075  */
1076 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1077 {
1078     INT dlgCode = 0;
1079
1080     if (CallMsgFilterW( msg, MSGF_DIALOGBOX )) return TRUE;
1081
1082     hwndDlg = WIN_GetFullHandle( hwndDlg );
1083     if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
1084
1085     hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1086
1087     switch(msg->message)
1088     {
1089     case WM_KEYDOWN:
1090         dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1091         if (dlgCode & DLGC_WANTMESSAGE) break;
1092
1093         switch(msg->wParam)
1094         {
1095         case VK_TAB:
1096             if (!(dlgCode & DLGC_WANTTAB))
1097             {
1098                 BOOL fIsDialog = TRUE;
1099                 WND *pWnd = WIN_GetPtr( hwndDlg );
1100
1101                 if (pWnd && pWnd != WND_OTHER_PROCESS)
1102                 {
1103                     fIsDialog = (pWnd->flags & WIN_ISDIALOG) != 0;
1104                     WIN_ReleasePtr(pWnd);
1105                 }
1106
1107                 /* I am not sure under which circumstances the TAB is handled
1108                  * each way.  All I do know is that it does not always simply
1109                  * send WM_NEXTDLGCTL.  (Personally I have never yet seen it
1110                  * do so but I presume someone has)
1111                  */
1112                 if (fIsDialog)
1113                     SendMessageW( hwndDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1114                 else
1115                 {
1116                     /* It would appear that GetNextDlgTabItem can handle being
1117                      * passed hwndDlg rather than NULL but that is undocumented
1118                      * so let's do it properly
1119                      */
1120                     HWND hwndFocus = GetFocus();
1121                     HWND hwndNext = GetNextDlgTabItem (hwndDlg,
1122                             hwndFocus == hwndDlg ? NULL : hwndFocus,
1123                             GetKeyState (VK_SHIFT) & 0x8000);
1124                     if (hwndNext)
1125                     {
1126                         dlgCode = SendMessageW (hwndNext, WM_GETDLGCODE,
1127                                 msg->wParam, (LPARAM)msg);
1128                         if (dlgCode & DLGC_HASSETSEL)
1129                         {
1130                             INT maxlen = 1 + SendMessageW (hwndNext, WM_GETTEXTLENGTH, 0, 0);
1131                             WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
1132                             if (buffer)
1133                             {
1134                                 INT length;
1135                                 SendMessageW (hwndNext, WM_GETTEXT, maxlen, (LPARAM) buffer);
1136                                 length = strlenW (buffer);
1137                                 HeapFree (GetProcessHeap(), 0, buffer);
1138                                 SendMessageW (hwndNext, EM_SETSEL, 0, length);
1139                             }
1140                         }
1141                         SetFocus (hwndNext);
1142                         DIALOG_FixChildrenOnChangeFocus (hwndDlg, hwndNext);
1143                     }
1144                     else
1145                         return FALSE;
1146                 }
1147                 return TRUE;
1148             }
1149             break;
1150
1151         case VK_RIGHT:
1152         case VK_DOWN:
1153         case VK_LEFT:
1154         case VK_UP:
1155             if (!(dlgCode & DLGC_WANTARROWS))
1156             {
1157                 BOOL fPrevious = (msg->wParam == VK_LEFT || msg->wParam == VK_UP);
1158                 HWND hwndNext = GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1159                 SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1160                 return TRUE;
1161             }
1162             break;
1163
1164         case VK_CANCEL:
1165         case VK_ESCAPE:
1166             SendMessageW( hwndDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1167             return TRUE;
1168
1169         case VK_EXECUTE:
1170         case VK_RETURN:
1171             {
1172                 DWORD dw;
1173                 if ((GetFocus() == msg->hwnd) &&
1174                     (SendMessageW (msg->hwnd, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1175                 {
1176                     SendMessageW (hwndDlg, WM_COMMAND, MAKEWPARAM (GetDlgCtrlID(msg->hwnd),BN_CLICKED), (LPARAM)msg->hwnd); 
1177                 }
1178                 else if (DC_HASDEFID == HIWORD(dw = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0)))
1179                 {
1180                     SendMessageW( hwndDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1181                                     (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1182                 }
1183                 else
1184                 {
1185                     SendMessageW( hwndDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1186
1187                 }
1188             }
1189             return TRUE;
1190         }
1191         break;
1192
1193     case WM_CHAR:
1194         /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
1195          * It does NOT get sent in the test program I have
1196          */
1197         dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, msg->wParam, (LPARAM)msg );
1198         if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
1199         if (msg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
1200         /* drop through */
1201
1202     case WM_SYSCHAR:
1203         if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg->hwnd), hwndDlg, msg->wParam ))
1204         {
1205             /* don't translate or dispatch */
1206             return TRUE;
1207         }
1208         break;
1209     }
1210
1211     TranslateMessage( msg );
1212     DispatchMessageW( msg );
1213     return TRUE;
1214 }
1215
1216
1217 /***********************************************************************
1218  *              GetDlgCtrlID (USER32.@)
1219  */
1220 INT WINAPI GetDlgCtrlID( HWND hwnd )
1221 {
1222     return GetWindowLongPtrW( hwnd, GWLP_ID );
1223 }
1224
1225
1226 /***********************************************************************
1227  *              GetDlgItem (USER32.@)
1228  */
1229 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1230 {
1231     int i;
1232     HWND *list = WIN_ListChildren( hwndDlg );
1233     HWND ret = 0;
1234
1235     if (!list) return 0;
1236
1237     for (i = 0; list[i]; i++) if (GetWindowLongPtrW( list[i], GWLP_ID ) == id) break;
1238     ret = list[i];
1239     HeapFree( GetProcessHeap(), 0, list );
1240     return ret;
1241 }
1242
1243
1244 /*******************************************************************
1245  *              SendDlgItemMessageA (USER32.@)
1246  */
1247 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1248                                       WPARAM wParam, LPARAM lParam )
1249 {
1250     HWND hwndCtrl = GetDlgItem( hwnd, id );
1251     if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1252     else return 0;
1253 }
1254
1255
1256 /*******************************************************************
1257  *              SendDlgItemMessageW (USER32.@)
1258  */
1259 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1260                                       WPARAM wParam, LPARAM lParam )
1261 {
1262     HWND hwndCtrl = GetDlgItem( hwnd, id );
1263     if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1264     else return 0;
1265 }
1266
1267
1268 /*******************************************************************
1269  *              SetDlgItemTextA (USER32.@)
1270  */
1271 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1272 {
1273     return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1274 }
1275
1276
1277 /*******************************************************************
1278  *              SetDlgItemTextW (USER32.@)
1279  */
1280 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1281 {
1282     return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1283 }
1284
1285
1286 /***********************************************************************
1287  *              GetDlgItemTextA (USER32.@)
1288  */
1289 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1290 {
1291     return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1292                                          len, (LPARAM)str );
1293 }
1294
1295
1296 /***********************************************************************
1297  *              GetDlgItemTextW (USER32.@)
1298  */
1299 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1300 {
1301     return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1302                                          len, (LPARAM)str );
1303 }
1304
1305
1306 /*******************************************************************
1307  *              SetDlgItemInt (USER32.@)
1308  */
1309 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1310                              BOOL fSigned )
1311 {
1312     char str[20];
1313
1314     if (fSigned) sprintf( str, "%d", (INT)value );
1315     else sprintf( str, "%u", value );
1316     SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1317     return TRUE;
1318 }
1319
1320
1321 /***********************************************************************
1322  *              GetDlgItemInt (USER32.@)
1323  */
1324 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1325                                BOOL fSigned )
1326 {
1327     char str[30];
1328     char * endptr;
1329     long result = 0;
1330
1331     if (translated) *translated = FALSE;
1332     if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1333         return 0;
1334     if (fSigned)
1335     {
1336         result = strtol( str, &endptr, 10 );
1337         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
1338             return 0;
1339         if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1340             return 0;
1341     }
1342     else
1343     {
1344         result = strtoul( str, &endptr, 10 );
1345         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
1346             return 0;
1347         if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1348     }
1349     if (translated) *translated = TRUE;
1350     return (UINT)result;
1351 }
1352
1353
1354 /***********************************************************************
1355  *              CheckDlgButton (USER32.@)
1356  */
1357 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1358 {
1359     SendDlgItemMessageW( hwnd, id, BM_SETCHECK, check, 0 );
1360     return TRUE;
1361 }
1362
1363
1364 /***********************************************************************
1365  *              IsDlgButtonChecked (USER32.@)
1366  */
1367 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1368 {
1369     return (UINT)SendDlgItemMessageW( hwnd, id, BM_GETCHECK, 0, 0 );
1370 }
1371
1372
1373 /***********************************************************************
1374  *           CheckRB
1375  *
1376  * Callback function used to check/uncheck radio buttons that fall
1377  * within a specific range of IDs.
1378  */
1379 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1380 {
1381     LONG lChildID = GetWindowLongPtrW(hwndChild, GWLP_ID);
1382     RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1383
1384     if ((lChildID >= lpRadioGroup->firstID) &&
1385         (lChildID <= lpRadioGroup->lastID))
1386     {
1387         if (lChildID == lpRadioGroup->checkID)
1388         {
1389             SendMessageW(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1390         }
1391         else
1392         {
1393             SendMessageW(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1394         }
1395     }
1396
1397     return TRUE;
1398 }
1399
1400
1401 /***********************************************************************
1402  *              CheckRadioButton (USER32.@)
1403  */
1404 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1405                               UINT lastID, UINT checkID )
1406 {
1407     RADIOGROUP radioGroup;
1408
1409     radioGroup.firstID = firstID;
1410     radioGroup.lastID = lastID;
1411     radioGroup.checkID = checkID;
1412
1413     return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1414                             (LPARAM)&radioGroup);
1415 }
1416
1417
1418 /***********************************************************************
1419  *              GetDialogBaseUnits (USER.243)
1420  *              GetDialogBaseUnits (USER32.@)
1421  */
1422 DWORD WINAPI GetDialogBaseUnits(void)
1423 {
1424     static DWORD units;
1425
1426     if (!units)
1427     {
1428         HDC hdc;
1429         SIZE size;
1430
1431         if ((hdc = GetDC(0)))
1432         {
1433             if (DIALOG_GetCharSize( hdc, 0, &size )) units = MAKELONG( size.cx, size.cy );
1434             ReleaseDC( 0, hdc );
1435         }
1436         TRACE("base units = %d,%d\n", LOWORD(units), HIWORD(units) );
1437     }
1438     return units;
1439 }
1440
1441
1442 /***********************************************************************
1443  *              MapDialogRect (USER32.@)
1444  */
1445 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1446 {
1447     DIALOGINFO * dlgInfo;
1448     if (!(dlgInfo = DIALOG_get_info( hwnd, FALSE ))) return FALSE;
1449     rect->left   = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1450     rect->right  = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1451     rect->top    = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1452     rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1453     return TRUE;
1454 }
1455
1456
1457 /***********************************************************************
1458  *              GetNextDlgGroupItem (USER32.@)
1459  *
1460  * Corrections to MSDN documentation
1461  *
1462  * (Under Windows 2000 at least, where hwndDlg is not actually a dialog)
1463  * 1. hwndCtrl can be hwndDlg in which case it behaves as for NULL
1464  * 2. Prev of NULL or hwndDlg fails
1465  */
1466 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1467 {
1468     HWND hwnd, hwndNext, retvalue, hwndLastGroup = 0;
1469     BOOL fLooped=FALSE;
1470     BOOL fSkipping=FALSE;
1471
1472     hwndDlg = WIN_GetFullHandle( hwndDlg );
1473     hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1474
1475     if (hwndDlg == hwndCtrl) hwndCtrl = NULL;
1476     if (!hwndCtrl && fPrevious) return 0;
1477
1478     if (hwndCtrl)
1479     {
1480         if (!IsChild (hwndDlg, hwndCtrl)) return 0;
1481     }
1482     else
1483     {
1484         /* No ctrl specified -> start from the beginning */
1485         if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1486         /* MSDN is wrong. fPrevious does not result in the last child */
1487
1488         /* Maybe that first one is valid.  If so then we don't want to skip it*/
1489         if ((GetWindowLongW( hwndCtrl, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1490         {
1491             return hwndCtrl;
1492         }
1493     }
1494
1495     /* Always go forward around the group and list of controls; for the 
1496      * previous control keep track; for the next break when you find one
1497      */
1498     retvalue = hwndCtrl;
1499     hwnd = hwndCtrl;
1500     while (hwndNext = GetWindow (hwnd, GW_HWNDNEXT),
1501            1)
1502     {
1503         while (!hwndNext)
1504         {
1505             /* Climb out until there is a next sibling of the ancestor or we
1506              * reach the top (in which case we loop back to the start)
1507              */
1508             if (hwndDlg == GetParent (hwnd))
1509             {
1510                 /* Wrap around to the beginning of the list, within the same
1511                  * group. (Once only)
1512                  */
1513                 if (fLooped) goto end;
1514                 fLooped = TRUE;
1515                 hwndNext = GetWindow (hwndDlg, GW_CHILD);
1516             }
1517             else
1518             {
1519                 hwnd = GetParent (hwnd);
1520                 hwndNext = GetWindow (hwnd, GW_HWNDNEXT);
1521             }
1522         }
1523         hwnd = hwndNext;
1524
1525         /* Wander down the leading edge of controlparents */
1526         while ( (GetWindowLongW (hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
1527                 ((GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) &&
1528                 (hwndNext = GetWindow (hwnd, GW_CHILD)))
1529             hwnd = hwndNext;
1530         /* Question.  If the control is a control parent but either has no
1531          * children or is not visible/enabled then if it has a WS_GROUP does
1532          * it count?  For that matter does it count anyway?
1533          * I believe it doesn't count.
1534          */
1535
1536         if ((GetWindowLongW (hwnd, GWL_STYLE) & WS_GROUP))
1537         {
1538             hwndLastGroup = hwnd;
1539             if (!fSkipping)
1540             {
1541                 /* Look for the beginning of the group */
1542                 fSkipping = TRUE;
1543             }
1544         }
1545
1546         if (hwnd == hwndCtrl)
1547         {
1548             if (!fSkipping) break;
1549             if (hwndLastGroup == hwnd) break;
1550             hwnd = hwndLastGroup;
1551             fSkipping = FALSE;
1552             fLooped = FALSE;
1553         }
1554
1555         if (!fSkipping &&
1556             (GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE|WS_DISABLED)) ==
1557              WS_VISIBLE)
1558         {
1559             retvalue = hwnd;
1560             if (!fPrevious) break;
1561         }
1562     }
1563 end:
1564     return retvalue;
1565 }
1566
1567
1568 /***********************************************************************
1569  *           DIALOG_GetNextTabItem
1570  *
1571  * Recursive helper for GetNextDlgTabItem
1572  */
1573 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1574 {
1575     LONG dsStyle;
1576     LONG exStyle;
1577     UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1578     HWND retWnd = 0;
1579     HWND hChildFirst = 0;
1580
1581     if(!hwndCtrl)
1582     {
1583         hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1584         if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1585     }
1586     else if (IsChild( hwndMain, hwndCtrl ))
1587     {
1588         hChildFirst = GetWindow(hwndCtrl,wndSearch);
1589         if(!hChildFirst)
1590         {
1591             if(GetParent(hwndCtrl) != hwndMain)
1592                 /* i.e. if we are not at the top level of the recursion */
1593                 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1594             else
1595                 hChildFirst = GetWindow(hwndCtrl, fPrevious ? GW_HWNDLAST : GW_HWNDFIRST);
1596         }
1597     }
1598
1599     while(hChildFirst)
1600     {
1601         dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1602         exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1603         if( (exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1604         {
1605             HWND retWnd;
1606             retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1607             if (retWnd) return (retWnd);
1608         }
1609         else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1610         {
1611             return (hChildFirst);
1612         }
1613         hChildFirst = GetWindow(hChildFirst,wndSearch);
1614     }
1615     if(hwndCtrl)
1616     {
1617         HWND hParent = GetParent(hwndCtrl);
1618         while(hParent)
1619         {
1620             if(hParent == hwndMain) break;
1621             retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1622             if(retWnd) break;
1623             hParent = GetParent(hParent);
1624         }
1625         if(!retWnd)
1626             retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1627     }
1628     return retWnd ? retWnd : hwndCtrl;
1629 }
1630
1631 /***********************************************************************
1632  *              GetNextDlgTabItem (USER32.@)
1633  */
1634 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1635                                    BOOL fPrevious )
1636 {
1637     hwndDlg = WIN_GetFullHandle( hwndDlg );
1638     hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1639
1640     /* Undocumented but tested under Win2000 and WinME */
1641     if (hwndDlg == hwndCtrl) hwndCtrl = NULL;
1642
1643     /* Contrary to MSDN documentation, tested under Win2000 and WinME
1644      * NB GetLastError returns whatever was set before the function was
1645      * called.
1646      */
1647     if (!hwndCtrl && fPrevious) return 0;
1648
1649     return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1650 }
1651
1652 /**********************************************************************
1653  *           DIALOG_DlgDirSelect
1654  *
1655  * Helper function for DlgDirSelect*
1656  */
1657 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPWSTR str, INT len,
1658                                  INT id, BOOL unicode, BOOL combo )
1659 {
1660     WCHAR *buffer, *ptr;
1661     INT item, size;
1662     BOOL ret;
1663     HWND listbox = GetDlgItem( hwnd, id );
1664
1665     TRACE("%p '%s' %d\n", hwnd, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str), id );
1666     if (!listbox) return FALSE;
1667
1668     item = SendMessageW(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1669     if (item == LB_ERR) return FALSE;
1670
1671     size = SendMessageW(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1672     if (size == LB_ERR) return FALSE;
1673
1674     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1675
1676     SendMessageW( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1677
1678     if ((ret = (buffer[0] == '[')))  /* drive or directory */
1679     {
1680         if (buffer[1] == '-')  /* drive */
1681         {
1682             buffer[3] = ':';
1683             buffer[4] = 0;
1684             ptr = buffer + 2;
1685         }
1686         else
1687         {
1688             buffer[strlenW(buffer)-1] = '\\';
1689             ptr = buffer + 1;
1690         }
1691     }
1692     else ptr = buffer;
1693
1694     if (!unicode)
1695     {
1696         if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, ptr, -1, (LPSTR)str, len, 0, 0 ))
1697             ((LPSTR)str)[len-1] = 0;
1698     }
1699     else lstrcpynW( str, ptr, len );
1700     HeapFree( GetProcessHeap(), 0, buffer );
1701     TRACE("Returning %d '%s'\n", ret, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str) );
1702     return ret;
1703 }
1704
1705
1706 /**********************************************************************
1707  *          DIALOG_DlgDirListW
1708  *
1709  * Helper function for DlgDirList*W
1710  */
1711 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1712                                INT idStatic, UINT attrib, BOOL combo )
1713 {
1714     HWND hwnd;
1715     LPWSTR orig_spec = spec;
1716     WCHAR any[] = {'*','.','*',0};
1717
1718 #define SENDMSG(msg,wparam,lparam) \
1719     ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1720                              : SendMessageW( hwnd, msg, wparam, lparam ))
1721
1722     TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib );
1723
1724     /* If the path exists and is a directory, chdir to it */
1725     if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any;
1726     else
1727     {
1728         WCHAR *p, *p2;
1729         p = spec;
1730         if ((p2 = strrchrW( p, '\\' ))) p = p2;
1731         if ((p2 = strrchrW( p, '/' ))) p = p2;
1732         if (p != spec)
1733         {
1734             WCHAR sep = *p;
1735             *p = 0;
1736             if (!SetCurrentDirectoryW( spec ))
1737             {
1738                 *p = sep;  /* Restore the original spec */
1739                 return FALSE;
1740             }
1741             spec = p + 1;
1742         }
1743     }
1744
1745     TRACE( "mask=%s\n", debugstr_w(spec) );
1746
1747     if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1748     {
1749         SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1750         if (attrib & DDL_DIRECTORY)
1751         {
1752             if (!(attrib & DDL_EXCLUSIVE))
1753             {
1754                 if (SENDMSG( combo ? CB_DIR : LB_DIR,
1755                              attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1756                              (LPARAM)spec ) == LB_ERR)
1757                     return FALSE;
1758             }
1759             if (SENDMSG( combo ? CB_DIR : LB_DIR,
1760                        (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1761                          (LPARAM)any ) == LB_ERR)
1762                 return FALSE;
1763         }
1764         else
1765         {
1766             if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
1767                          (LPARAM)spec ) == LB_ERR)
1768                 return FALSE;
1769         }
1770     }
1771
1772     if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1773     {
1774         WCHAR temp[MAX_PATH];
1775         GetCurrentDirectoryW( sizeof(temp)/sizeof(WCHAR), temp );
1776         CharLowerW( temp );
1777         /* Can't use PostMessage() here, because the string is on the stack */
1778         SetDlgItemTextW( hDlg, idStatic, temp );
1779     }
1780
1781     if (orig_spec && (spec != orig_spec))
1782     {
1783         /* Update the original file spec */
1784         WCHAR *p = spec;
1785         while ((*orig_spec++ = *p++));
1786     }
1787
1788     return TRUE;
1789 #undef SENDMSG
1790 }
1791
1792
1793 /**********************************************************************
1794  *          DIALOG_DlgDirListA
1795  *
1796  * Helper function for DlgDirList*A
1797  */
1798 static INT DIALOG_DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1799                                INT idStatic, UINT attrib, BOOL combo )
1800 {
1801     if (spec)
1802     {
1803         INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
1804         LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1805         MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
1806         ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
1807         WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );
1808         HeapFree( GetProcessHeap(), 0, specW );
1809         return ret;
1810     }
1811     return DIALOG_DlgDirListW( hDlg, NULL, idLBox, idStatic, attrib, combo );
1812 }
1813
1814
1815 /**********************************************************************
1816  *              DlgDirSelectExA (USER32.@)
1817  */
1818 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
1819 {
1820     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, FALSE );
1821 }
1822
1823
1824 /**********************************************************************
1825  *              DlgDirSelectExW (USER32.@)
1826  */
1827 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
1828 {
1829     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE );
1830 }
1831
1832
1833 /**********************************************************************
1834  *              DlgDirSelectComboBoxExA (USER32.@)
1835  */
1836 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
1837                                          INT id )
1838 {
1839     return DIALOG_DlgDirSelect( hwnd, (LPWSTR)str, len, id, FALSE, TRUE );
1840 }
1841
1842
1843 /**********************************************************************
1844  *              DlgDirSelectComboBoxExW (USER32.@)
1845  */
1846 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
1847                                          INT id)
1848 {
1849     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, TRUE );
1850 }
1851
1852
1853 /**********************************************************************
1854  *              DlgDirListA (USER32.@)
1855  */
1856 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1857                             INT idStatic, UINT attrib )
1858 {
1859     return DIALOG_DlgDirListA( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1860 }
1861
1862
1863 /**********************************************************************
1864  *              DlgDirListW (USER32.@)
1865  */
1866 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1867                             INT idStatic, UINT attrib )
1868 {
1869     return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1870 }
1871
1872
1873 /**********************************************************************
1874  *              DlgDirListComboBoxA (USER32.@)
1875  */
1876 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
1877                                     INT idStatic, UINT attrib )
1878 {
1879     return DIALOG_DlgDirListA( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1880 }
1881
1882
1883 /**********************************************************************
1884  *              DlgDirListComboBoxW (USER32.@)
1885  */
1886 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
1887                                     INT idStatic, UINT attrib )
1888 {
1889     return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1890 }