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