- move async activation into the server
[wine/dcerpc.git] / windows / dialog.c
blobd86b66bb196c0682092b84043ff2426a8a1337c1
1 /*
2 * Dialog functions
4 * Copyright 1993, 1994, 1996 Alexandre Julliard
5 */
7 #include "config.h"
8 #include "wine/port.h"
10 #include <ctype.h>
11 #include <errno.h>
12 #include <limits.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
17 #include "windef.h"
18 #include "winnls.h"
19 #include "winbase.h"
20 #include "wingdi.h"
21 #include "winuser.h"
22 #include "windowsx.h"
23 #include "wine/winuser16.h"
24 #include "wine/winbase16.h"
25 #include "wine/unicode.h"
26 #include "controls.h"
27 #include "heap.h"
28 #include "win.h"
29 #include "user.h"
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(dialog);
35 /* Dialog control information */
36 typedef struct
38 DWORD style;
39 DWORD exStyle;
40 DWORD helpId;
41 INT16 x;
42 INT16 y;
43 INT16 cx;
44 INT16 cy;
45 UINT id;
46 LPCSTR className;
47 LPCSTR windowName;
48 LPVOID data;
49 } DLG_CONTROL_INFO;
51 /* Dialog template */
52 typedef struct
54 DWORD style;
55 DWORD exStyle;
56 DWORD helpId;
57 UINT16 nbItems;
58 INT16 x;
59 INT16 y;
60 INT16 cx;
61 INT16 cy;
62 LPCSTR menuName;
63 LPCSTR className;
64 LPCSTR caption;
65 WORD pointSize;
66 WORD weight;
67 BOOL italic;
68 LPCSTR faceName;
69 BOOL dialogEx;
70 } DLG_TEMPLATE;
72 /* Radio button group */
73 typedef struct
75 UINT firstID;
76 UINT lastID;
77 UINT checkID;
78 } RADIOGROUP;
80 /* Dialog base units */
81 static WORD xBaseUnit = 0, yBaseUnit = 0;
84 /*********************************************************************
85 * dialog class descriptor
87 const struct builtin_class_descr DIALOG_builtin_class =
89 DIALOG_CLASS_ATOM, /* name */
90 CS_GLOBALCLASS | CS_SAVEBITS, /* style */
91 DefDlgProcA, /* procA */
92 DefDlgProcW, /* procW */
93 DLGWINDOWEXTRA, /* extra */
94 IDC_ARROWA, /* cursor */
95 0 /* brush */
99 /***********************************************************************
100 * DIALOG_EnableOwner
102 * Helper function for modal dialogs to enable again the
103 * owner of the dialog box.
105 void DIALOG_EnableOwner( HWND hOwner )
107 /* Owner must be a top-level window */
108 if (hOwner)
109 hOwner = GetAncestor( hOwner, GA_ROOT );
110 if (!hOwner) return;
111 EnableWindow( hOwner, TRUE );
115 /***********************************************************************
116 * DIALOG_DisableOwner
118 * Helper function for modal dialogs to disable the
119 * owner of the dialog box. Returns TRUE if owner was enabled.
121 BOOL DIALOG_DisableOwner( HWND hOwner )
123 /* Owner must be a top-level window */
124 if (hOwner)
125 hOwner = GetAncestor( hOwner, GA_ROOT );
126 if (!hOwner) return FALSE;
127 if (IsWindowEnabled( hOwner ))
129 EnableWindow( hOwner, FALSE );
130 return TRUE;
132 else
133 return FALSE;
136 /***********************************************************************
137 * DIALOG_GetCharSizeFromDC
140 * Calculates the *true* average size of English characters in the
141 * specified font as oppposed to the one returned by GetTextMetrics.
143 * Latest: the X font driver will now compute a proper average width
144 * so this code can be removed
146 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
148 BOOL Success = FALSE;
149 HFONT hFontPrev = 0;
150 pSize->cx = xBaseUnit;
151 pSize->cy = yBaseUnit;
152 if ( hDC )
154 /* select the font */
155 TEXTMETRICA tm;
156 memset(&tm,0,sizeof(tm));
157 if (hFont) hFontPrev = SelectFont(hDC,hFont);
158 if (GetTextMetricsA(hDC,&tm))
160 pSize->cx = tm.tmAveCharWidth;
161 pSize->cy = tm.tmHeight;
163 /* if variable width font */
164 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
166 SIZE total;
167 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
169 /* Calculate a true average as opposed to the one returned
170 * by tmAveCharWidth. This works better when dealing with
171 * proportional spaced fonts and (more important) that's
172 * how Microsoft's dialog creation code calculates the size
173 * of the font
175 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
177 /* round up */
178 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
179 Success = TRUE;
182 else
184 Success = TRUE;
186 /* Use the text metrics */
187 TRACE("Using tm: %ldx%ld (dlg: %ld x %ld) (%s)\n",
188 tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
189 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
190 pSize->cx = tm.tmAveCharWidth;
191 pSize->cy = tm.tmHeight;
193 /* select the original font */
194 if (hFontPrev) SelectFont(hDC,hFontPrev);
196 return (Success);
199 /***********************************************************************
200 * DIALOG_GetCharSize
202 * A convenient variant of DIALOG_GetCharSizeFromDC.
204 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
206 HDC hDC = GetDC(0);
207 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
208 ReleaseDC(0, hDC);
209 return Success;
212 /***********************************************************************
213 * DIALOG_Init
215 * Initialisation of the dialog manager.
217 BOOL DIALOG_Init(void)
219 HDC hdc;
220 SIZE size;
222 /* Calculate the dialog base units */
224 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
226 ERR("Could not create Display DC\n");
227 return FALSE;
230 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size ))
232 DeleteDC( hdc );
233 ERR("Could not initialize base dialog units\n");
234 return FALSE;
237 DeleteDC( hdc );
238 xBaseUnit = size.cx;
239 yBaseUnit = size.cy;
241 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
242 return TRUE;
246 /***********************************************************************
247 * DIALOG_GetControl16
249 * Return the class and text of the control pointed to by ptr,
250 * fill the header structure and return a pointer to the next control.
252 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
254 static char buffer[10];
255 int int_id;
257 info->x = GET_WORD(p); p += sizeof(WORD);
258 info->y = GET_WORD(p); p += sizeof(WORD);
259 info->cx = GET_WORD(p); p += sizeof(WORD);
260 info->cy = GET_WORD(p); p += sizeof(WORD);
261 info->id = GET_WORD(p); p += sizeof(WORD);
262 info->style = GET_DWORD(p); p += sizeof(DWORD);
263 info->exStyle = 0;
265 if (*p & 0x80)
267 switch((BYTE)*p)
269 case 0x80: strcpy( buffer, "BUTTON" ); break;
270 case 0x81: strcpy( buffer, "EDIT" ); break;
271 case 0x82: strcpy( buffer, "STATIC" ); break;
272 case 0x83: strcpy( buffer, "LISTBOX" ); break;
273 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
274 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
275 default: buffer[0] = '\0'; break;
277 info->className = buffer;
278 p++;
280 else
282 info->className = p;
283 p += strlen(p) + 1;
286 int_id = ((BYTE)*p == 0xff);
287 if (int_id)
289 /* Integer id, not documented (?). Only works for SS_ICON controls */
290 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
291 p += 3;
293 else
295 info->windowName = p;
296 p += strlen(p) + 1;
299 if (*p)
301 /* Additional CTLDATA available for this control. */
302 info->data = SEGPTR_ALLOC(*p);
303 memcpy( info->data, p + 1, *p );
305 else info->data = NULL;
307 p += *p + 1;
309 if(int_id)
310 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
311 info->className, LOWORD(info->windowName),
312 info->id, info->x, info->y, info->cx, info->cy,
313 info->style, (DWORD)SEGPTR_GET(info->data) );
314 else
315 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
316 info->className, info->windowName,
317 info->id, info->x, info->y, info->cx, info->cy,
318 info->style, (DWORD)SEGPTR_GET(info->data) );
320 return p;
324 /***********************************************************************
325 * DIALOG_GetControl32
327 * Return the class and text of the control pointed to by ptr,
328 * fill the header structure and return a pointer to the next control.
330 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
331 BOOL dialogEx )
333 if (dialogEx)
335 info->helpId = GET_DWORD(p); p += 2;
336 info->exStyle = GET_DWORD(p); p += 2;
337 info->style = GET_DWORD(p); p += 2;
339 else
341 info->helpId = 0;
342 info->style = GET_DWORD(p); p += 2;
343 info->exStyle = GET_DWORD(p); p += 2;
345 info->x = GET_WORD(p); p++;
346 info->y = GET_WORD(p); p++;
347 info->cx = GET_WORD(p); p++;
348 info->cy = GET_WORD(p); p++;
350 if (dialogEx)
352 /* id is a DWORD for DIALOGEX */
353 info->id = GET_DWORD(p);
354 p += 2;
356 else
358 info->id = GET_WORD(p);
359 p++;
362 if (GET_WORD(p) == 0xffff)
364 static const WCHAR class_names[6][10] =
366 { 'B','u','t','t','o','n', }, /* 0x80 */
367 { 'E','d','i','t', }, /* 0x81 */
368 { 'S','t','a','t','i','c', }, /* 0x82 */
369 { 'L','i','s','t','B','o','x', }, /* 0x83 */
370 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
371 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
373 WORD id = GET_WORD(p+1);
374 if ((id >= 0x80) && (id <= 0x85))
375 info->className = (LPCSTR)class_names[id - 0x80];
376 else
378 info->className = NULL;
379 ERR("Unknown built-in class id %04x\n", id );
381 p += 2;
383 else
385 info->className = (LPCSTR)p;
386 p += strlenW( (LPCWSTR)p ) + 1;
389 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
391 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
392 p += 2;
394 else
396 info->windowName = (LPCSTR)p;
397 p += strlenW( (LPCWSTR)p ) + 1;
400 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
401 debugstr_w( (LPCWSTR)info->className ),
402 debugres_w( (LPCWSTR)info->windowName ),
403 info->id, info->x, info->y, info->cx, info->cy,
404 info->style, info->exStyle, info->helpId );
406 if (GET_WORD(p))
408 if (TRACE_ON(dialog))
410 WORD i, count = GET_WORD(p) / sizeof(WORD);
411 TRACE(" BEGIN\n");
412 TRACE(" ");
413 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
414 DPRINTF("\n");
415 TRACE(" END\n" );
417 info->data = (LPVOID)(p + 1);
418 p += GET_WORD(p) / sizeof(WORD);
420 else info->data = NULL;
421 p++;
423 /* Next control is on dword boundary */
424 return (const WORD *)((((int)p) + 3) & ~3);
428 /***********************************************************************
429 * DIALOG_CreateControls
431 * Create the control windows for a dialog.
433 static BOOL DIALOG_CreateControls( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
434 HINSTANCE hInst, BOOL win32 )
436 DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd );
437 DLG_CONTROL_INFO info;
438 HWND hwndCtrl, hwndDefButton = 0;
439 INT items = dlgTemplate->nbItems;
441 TRACE(" BEGIN\n" );
442 while (items--)
444 if (!win32)
446 HINSTANCE16 instance;
447 template = DIALOG_GetControl16( template, &info );
448 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
449 !(GetWindowLongW( hwnd, GWL_STYLE ) & DS_LOCALEDIT))
451 if (!dlgInfo->hDialogHeap)
453 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
454 if (!dlgInfo->hDialogHeap)
456 ERR("Insufficient memory to create heap for edit control\n" );
457 continue;
459 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
461 instance = dlgInfo->hDialogHeap;
463 else instance = (HINSTANCE16)hInst;
465 hwndCtrl = WIN_Handle32( CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
466 info.className, info.windowName,
467 info.style | WS_CHILD,
468 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
469 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
470 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
471 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
472 WIN_Handle16(hwnd), (HMENU16)info.id,
473 instance, (LPVOID)SEGPTR_GET(info.data) ));
475 if (info.data) SEGPTR_FREE(info.data);
477 else
479 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
480 dlgTemplate->dialogEx );
481 /* Is this it? */
482 if (info.style & WS_BORDER)
484 info.style &= ~WS_BORDER;
485 info.exStyle |= WS_EX_CLIENTEDGE;
487 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
488 (LPCWSTR)info.className,
489 (LPCWSTR)info.windowName,
490 info.style | WS_CHILD,
491 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
492 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
493 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
494 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
495 hwnd, (HMENU)info.id,
496 hInst, info.data );
498 if (!hwndCtrl) return FALSE;
500 /* Send initialisation messages to the control */
501 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
502 (WPARAM)dlgInfo->hUserFont, 0 );
503 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
505 /* If there's already a default push-button, set it back */
506 /* to normal and use this one instead. */
507 if (hwndDefButton)
508 SendMessageA( hwndDefButton, BM_SETSTYLE,
509 BS_PUSHBUTTON,FALSE );
510 hwndDefButton = hwndCtrl;
511 dlgInfo->idResult = GetWindowLongA( hwndCtrl, GWL_ID );
514 TRACE(" END\n" );
515 return TRUE;
519 /***********************************************************************
520 * DIALOG_ParseTemplate16
522 * Fill a DLG_TEMPLATE structure from the dialog template, and return
523 * a pointer to the first control.
525 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
527 result->style = GET_DWORD(p); p += sizeof(DWORD);
528 result->exStyle = 0;
529 result->nbItems = (unsigned char) *p++;
530 result->x = GET_WORD(p); p += sizeof(WORD);
531 result->y = GET_WORD(p); p += sizeof(WORD);
532 result->cx = GET_WORD(p); p += sizeof(WORD);
533 result->cy = GET_WORD(p); p += sizeof(WORD);
534 TRACE("DIALOG %d, %d, %d, %d\n",
535 result->x, result->y, result->cx, result->cy );
536 TRACE(" STYLE %08lx\n", result->style );
538 /* Get the menu name */
540 switch( (BYTE)*p )
542 case 0:
543 result->menuName = 0;
544 p++;
545 break;
546 case 0xff:
547 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
548 p += 3;
549 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
550 break;
551 default:
552 result->menuName = p;
553 TRACE(" MENU '%s'\n", p );
554 p += strlen(p) + 1;
555 break;
558 /* Get the class name */
560 if (*p)
562 result->className = p;
563 TRACE(" CLASS '%s'\n", result->className );
565 else result->className = DIALOG_CLASS_ATOM;
566 p += strlen(p) + 1;
568 /* Get the window caption */
570 result->caption = p;
571 p += strlen(p) + 1;
572 TRACE(" CAPTION '%s'\n", result->caption );
574 /* Get the font name */
576 if (result->style & DS_SETFONT)
578 result->pointSize = GET_WORD(p);
579 p += sizeof(WORD);
580 result->faceName = p;
581 p += strlen(p) + 1;
582 TRACE(" FONT %d,'%s'\n",
583 result->pointSize, result->faceName );
585 return p;
589 /***********************************************************************
590 * DIALOG_ParseTemplate32
592 * Fill a DLG_TEMPLATE structure from the dialog template, and return
593 * a pointer to the first control.
595 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
597 const WORD *p = (const WORD *)template;
599 result->style = GET_DWORD(p); p += 2;
600 if (result->style == 0xffff0001) /* DIALOGEX resource */
602 result->dialogEx = TRUE;
603 result->helpId = GET_DWORD(p); p += 2;
604 result->exStyle = GET_DWORD(p); p += 2;
605 result->style = GET_DWORD(p); p += 2;
607 else
609 result->dialogEx = FALSE;
610 result->helpId = 0;
611 result->exStyle = GET_DWORD(p); p += 2;
613 result->nbItems = GET_WORD(p); p++;
614 result->x = GET_WORD(p); p++;
615 result->y = GET_WORD(p); p++;
616 result->cx = GET_WORD(p); p++;
617 result->cy = GET_WORD(p); p++;
618 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
619 result->dialogEx ? "EX" : "", result->x, result->y,
620 result->cx, result->cy, result->helpId );
621 TRACE(" STYLE 0x%08lx\n", result->style );
622 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
624 /* Get the menu name */
626 switch(GET_WORD(p))
628 case 0x0000:
629 result->menuName = NULL;
630 p++;
631 break;
632 case 0xffff:
633 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
634 p += 2;
635 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
636 break;
637 default:
638 result->menuName = (LPCSTR)p;
639 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
640 p += strlenW( (LPCWSTR)p ) + 1;
641 break;
644 /* Get the class name */
646 switch(GET_WORD(p))
648 case 0x0000:
649 result->className = DIALOG_CLASS_ATOM;
650 p++;
651 break;
652 case 0xffff:
653 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
654 p += 2;
655 TRACE(" CLASS %04x\n", LOWORD(result->className) );
656 break;
657 default:
658 result->className = (LPCSTR)p;
659 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
660 p += strlenW( (LPCWSTR)p ) + 1;
661 break;
664 /* Get the window caption */
666 result->caption = (LPCSTR)p;
667 p += strlenW( (LPCWSTR)p ) + 1;
668 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
670 /* Get the font name */
672 if (result->style & DS_SETFONT)
674 result->pointSize = GET_WORD(p);
675 p++;
676 if (result->dialogEx)
678 result->weight = GET_WORD(p); p++;
679 result->italic = LOBYTE(GET_WORD(p)); p++;
681 else
683 result->weight = FW_DONTCARE;
684 result->italic = FALSE;
686 result->faceName = (LPCSTR)p;
687 p += strlenW( (LPCWSTR)p ) + 1;
688 TRACE(" FONT %d, %s, %d, %s\n",
689 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
690 result->weight, result->italic ? "TRUE" : "FALSE" );
693 /* First control is on dword boundary */
694 return (LPCSTR)((((int)p) + 3) & ~3);
698 /***********************************************************************
699 * DIALOG_CreateIndirect
700 * Creates a dialog box window
702 * modal = TRUE if we are called from a modal dialog box.
703 * (it's more compatible to do it here, as under Windows the owner
704 * is never disabled if the dialog fails because of an invalid template)
706 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
707 HWND owner, DLGPROC dlgProc, LPARAM param,
708 WINDOWPROCTYPE procType, BOOL modal )
710 HWND hwnd;
711 RECT rect;
712 WND * wndPtr;
713 DLG_TEMPLATE template;
714 DIALOGINFO * dlgInfo;
715 BOOL ownerEnabled = TRUE;
716 BOOL win32Template = (procType != WIN_PROC_16);
718 /* Parse dialog template */
720 if (!dlgTemplate) return 0;
721 if (win32Template)
722 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
723 else
724 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
726 /* Initialise dialog extra data */
728 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
729 dlgInfo->hwndFocus = 0;
730 dlgInfo->hUserFont = 0;
731 dlgInfo->hMenu = 0;
732 dlgInfo->xBaseUnit = xBaseUnit;
733 dlgInfo->yBaseUnit = yBaseUnit;
734 dlgInfo->idResult = 0;
735 dlgInfo->flags = 0;
736 dlgInfo->hDialogHeap = 0;
738 /* Load menu */
740 if (template.menuName)
742 if (!win32Template) dlgInfo->hMenu = LoadMenu16( hInst, template.menuName );
743 else dlgInfo->hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
746 /* Create custom font if needed */
748 if (template.style & DS_SETFONT)
750 /* The font height must be negative as it is a point size */
751 /* and must be converted to pixels first */
752 /* (see CreateFont() documentation in the Windows SDK). */
753 HDC dc;
754 int pixels;
755 if (((short)template.pointSize) < 0)
756 pixels = -((short)template.pointSize);
757 else
759 dc = GetDC(0);
760 pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
761 ReleaseDC(0, dc);
763 if (win32Template)
764 dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
765 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
766 PROOF_QUALITY, FF_DONTCARE,
767 (LPCWSTR)template.faceName );
768 else
769 dlgInfo->hUserFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
770 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
771 PROOF_QUALITY, FF_DONTCARE, template.faceName );
772 if (dlgInfo->hUserFont)
774 SIZE charSize;
775 if (DIALOG_GetCharSize( dlgInfo->hUserFont, &charSize ))
777 dlgInfo->xBaseUnit = charSize.cx;
778 dlgInfo->yBaseUnit = charSize.cy;
781 TRACE("units = %d,%d\n", dlgInfo->xBaseUnit, dlgInfo->yBaseUnit );
784 /* Create dialog main window */
786 rect.left = rect.top = 0;
787 rect.right = MulDiv(template.cx, dlgInfo->xBaseUnit, 4);
788 rect.bottom = MulDiv(template.cy, dlgInfo->yBaseUnit, 8);
789 if (template.style & DS_MODALFRAME)
790 template.exStyle |= WS_EX_DLGMODALFRAME;
791 AdjustWindowRectEx( &rect, template.style, (dlgInfo->hMenu != 0), template.exStyle );
792 rect.right -= rect.left;
793 rect.bottom -= rect.top;
795 if ((INT16)template.x == CW_USEDEFAULT16)
797 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
799 else
801 if (template.style & DS_CENTER)
803 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
804 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
806 else
808 rect.left += MulDiv(template.x, dlgInfo->xBaseUnit, 4);
809 rect.top += MulDiv(template.y, dlgInfo->yBaseUnit, 8);
811 if ( !(template.style & WS_CHILD) )
813 INT16 dX, dY;
815 if( !(template.style & DS_ABSALIGN) )
816 ClientToScreen( owner, (POINT *)&rect );
818 /* try to fit it into the desktop */
820 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
821 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
822 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
823 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
824 if( rect.left < 0 ) rect.left = 0;
825 if( rect.top < 0 ) rect.top = 0;
829 if (modal)
831 ownerEnabled = DIALOG_DisableOwner( owner );
832 if (ownerEnabled) dlgInfo->flags |= DF_OWNERENABLED;
835 if (!win32Template)
836 hwnd = WIN_Handle32( CreateWindowEx16(template.exStyle, template.className,
837 template.caption, template.style & ~WS_VISIBLE,
838 rect.left, rect.top, rect.right, rect.bottom,
839 WIN_Handle16(owner), dlgInfo->hMenu, hInst, NULL ));
840 else
841 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
842 (LPCWSTR)template.caption,
843 template.style & ~WS_VISIBLE,
844 rect.left, rect.top, rect.right, rect.bottom,
845 owner, dlgInfo->hMenu, hInst, NULL );
847 if (!hwnd)
849 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
850 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
851 if (modal && (dlgInfo->flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
852 HeapFree( GetProcessHeap(), 0, dlgInfo );
853 return 0;
855 wndPtr = WIN_GetPtr( hwnd );
856 wndPtr->flags |= WIN_ISDIALOG;
857 WIN_ReleasePtr( wndPtr );
859 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
860 SetWindowLongW( hwnd, DWL_WINE_DIALOGINFO, (LONG)dlgInfo );
861 switch(procType)
863 case WIN_PROC_16: SetWindowLong16( WIN_Handle16(hwnd), DWL_DLGPROC, (LONG)dlgProc ); break;
864 case WIN_PROC_32A: SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
865 case WIN_PROC_32W: SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
866 default: break;
869 if (dlgInfo->hUserFont)
870 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
872 /* Create controls */
874 if (DIALOG_CreateControls( hwnd, dlgTemplate, &template,
875 hInst, win32Template ))
877 HWND hwndPreInitFocus;
879 /* Send initialisation messages and set focus */
881 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
883 hwndPreInitFocus = GetFocus();
884 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
886 /* check where the focus is again,
887 * some controls status might have changed in WM_INITDIALOG */
888 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
889 if( dlgInfo->hwndFocus )
890 SetFocus( dlgInfo->hwndFocus );
892 else
894 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
895 but the focus has not changed, set the focus where we expect it. */
896 if ((GetFocus() == hwndPreInitFocus) &&
897 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
899 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
900 if( dlgInfo->hwndFocus )
901 SetFocus( dlgInfo->hwndFocus );
905 if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
907 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
909 return hwnd;
911 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
912 if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
913 return 0;
917 /***********************************************************************
918 * CreateDialog (USER.89)
920 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
921 HWND16 owner, DLGPROC16 dlgProc )
923 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
927 /***********************************************************************
928 * CreateDialogParam (USER.241)
930 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
931 HWND16 owner, DLGPROC16 dlgProc,
932 LPARAM param )
934 HWND16 hwnd = 0;
935 HRSRC16 hRsrc;
936 HGLOBAL16 hmem;
937 LPCVOID data;
939 TRACE("%04x,%s,%04x,%08lx,%ld\n",
940 hInst, debugres_a(dlgTemplate), owner, (DWORD)dlgProc, param );
942 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOGA ))) return 0;
943 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
944 if (!(data = LockResource16( hmem ))) hwnd = 0;
945 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
946 dlgProc, param );
947 FreeResource16( hmem );
948 return hwnd;
951 /***********************************************************************
952 * CreateDialogParamA (USER32.@)
954 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
955 HWND owner, DLGPROC dlgProc,
956 LPARAM param )
958 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
959 if (!hrsrc) return 0;
960 return CreateDialogIndirectParamA( hInst,
961 (LPVOID)LoadResource(hInst, hrsrc),
962 owner, dlgProc, param );
966 /***********************************************************************
967 * CreateDialogParamW (USER32.@)
969 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
970 HWND owner, DLGPROC dlgProc,
971 LPARAM param )
973 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
974 if (!hrsrc) return 0;
975 return CreateDialogIndirectParamW( hInst,
976 (LPVOID)LoadResource(hInst, hrsrc),
977 owner, dlgProc, param );
981 /***********************************************************************
982 * CreateDialogIndirect (USER.219)
984 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
985 HWND16 owner, DLGPROC16 dlgProc )
987 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
991 /***********************************************************************
992 * CreateDialogIndirectParam (USER.242)
993 * CreateDialogIndirectParam16 (USER32.@)
995 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
996 LPCVOID dlgTemplate,
997 HWND16 owner, DLGPROC16 dlgProc,
998 LPARAM param )
1000 return WIN_Handle16( DIALOG_CreateIndirect( hInst, dlgTemplate, WIN_Handle32(owner),
1001 (DLGPROC)dlgProc, param, WIN_PROC_16, FALSE ));
1005 /***********************************************************************
1006 * CreateDialogIndirectParamA (USER32.@)
1008 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
1009 LPCVOID dlgTemplate,
1010 HWND owner, DLGPROC dlgProc,
1011 LPARAM param )
1013 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32A, FALSE );
1016 /***********************************************************************
1017 * CreateDialogIndirectParamAorW (USER32.@)
1019 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
1020 LPCVOID dlgTemplate,
1021 HWND owner, DLGPROC dlgProc,
1022 LPARAM param )
1023 { FIXME("assume WIN_PROC_32W\n");
1024 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1027 /***********************************************************************
1028 * CreateDialogIndirectParamW (USER32.@)
1030 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
1031 LPCVOID dlgTemplate,
1032 HWND owner, DLGPROC dlgProc,
1033 LPARAM param )
1035 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1039 /***********************************************************************
1040 * DIALOG_DoDialogBox
1042 static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
1044 DIALOGINFO * dlgInfo;
1045 MSG msg;
1046 INT retval;
1047 HWND ownerMsg = GetAncestor( owner, GA_ROOT );
1049 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return -1;
1051 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
1053 ShowWindow( hwnd, SW_SHOW );
1054 for (;;)
1056 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
1058 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
1060 /* No message present -> send ENTERIDLE and wait */
1061 SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
1062 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1065 else if (!GetMessageW( &msg, 0, 0, 0 )) break;
1067 if (CallMsgFilterW( &msg, MSGF_DIALOGBOX )) continue;
1069 if (!IsWindow( hwnd )) return -1;
1070 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
1072 TranslateMessage( &msg );
1073 DispatchMessageW( &msg );
1075 if (dlgInfo->flags & DF_END) break;
1078 if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
1079 retval = dlgInfo->idResult;
1080 DestroyWindow( hwnd );
1081 return retval;
1085 /***********************************************************************
1086 * DialogBox (USER.87)
1088 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
1089 HWND16 owner, DLGPROC16 dlgProc )
1091 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1095 /***********************************************************************
1096 * DialogBoxParam (USER.239)
1098 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, LPCSTR template,
1099 HWND16 owner16, DLGPROC16 dlgProc, LPARAM param )
1101 HWND hwnd = 0;
1102 HRSRC16 hRsrc;
1103 HGLOBAL16 hmem;
1104 LPCVOID data;
1105 int ret = -1;
1107 if (!(hRsrc = FindResource16( hInst, template, RT_DIALOGA ))) return 0;
1108 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
1109 if ((data = LockResource16( hmem )))
1111 HWND owner = WIN_Handle32(owner16);
1112 hwnd = DIALOG_CreateIndirect( hInst, data, owner,
1113 (DLGPROC)dlgProc, param, WIN_PROC_16, TRUE );
1114 if (hwnd) ret = DIALOG_DoDialogBox( hwnd, owner );
1115 GlobalUnlock16( hmem );
1117 FreeResource16( hmem );
1118 return ret;
1122 /***********************************************************************
1123 * DialogBoxParamA (USER32.@)
1125 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1126 HWND owner, DLGPROC dlgProc, LPARAM param )
1128 HWND hwnd;
1129 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
1130 if (!hrsrc) return 0;
1131 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1132 owner, dlgProc, param, WIN_PROC_32A, TRUE );
1133 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1134 return -1;
1138 /***********************************************************************
1139 * DialogBoxParamW (USER32.@)
1141 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1142 HWND owner, DLGPROC dlgProc, LPARAM param )
1144 HWND hwnd;
1145 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
1146 if (!hrsrc) return 0;
1147 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1148 owner, dlgProc, param, WIN_PROC_32W, TRUE );
1149 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1150 return -1;
1154 /***********************************************************************
1155 * DialogBoxIndirect (USER.218)
1157 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1158 HWND16 owner, DLGPROC16 dlgProc )
1160 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1164 /***********************************************************************
1165 * DialogBoxIndirectParam (USER.240)
1166 * DialogBoxIndirectParam16 (USER32.@)
1168 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1169 HWND16 owner16, DLGPROC16 dlgProc,
1170 LPARAM param )
1172 HWND hwnd, owner = WIN_Handle32( owner16 );
1173 LPCVOID ptr;
1175 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1176 hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, (DLGPROC)dlgProc,
1177 param, WIN_PROC_16, TRUE );
1178 GlobalUnlock16( dlgTemplate );
1179 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1180 return -1;
1184 /***********************************************************************
1185 * DialogBoxIndirectParamA (USER32.@)
1187 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1188 HWND owner, DLGPROC dlgProc,
1189 LPARAM param )
1191 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1192 dlgProc, param, WIN_PROC_32A, TRUE );
1193 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1194 return -1;
1198 /***********************************************************************
1199 * DialogBoxIndirectParamW (USER32.@)
1201 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1202 HWND owner, DLGPROC dlgProc,
1203 LPARAM param )
1205 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1206 dlgProc, param, WIN_PROC_32W, TRUE );
1207 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1208 return -1;
1211 /***********************************************************************
1212 * DialogBoxIndirectParamAorW (USER32.@)
1214 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1215 HWND owner, DLGPROC dlgProc,
1216 LPARAM param, DWORD x )
1218 HWND hwnd;
1219 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1220 hInstance, template, owner, dlgProc, param, x);
1221 hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, WIN_PROC_32W, TRUE );
1222 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1223 return -1;
1226 /***********************************************************************
1227 * EndDialog (USER32.@)
1229 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1231 BOOL wasEnabled = TRUE;
1232 DIALOGINFO * dlgInfo;
1233 HWND owner;
1235 TRACE("%04x %d\n", hwnd, retval );
1237 if (!(dlgInfo = DIALOG_get_info( hwnd )))
1239 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1240 return FALSE;
1242 dlgInfo->idResult = retval;
1243 dlgInfo->flags |= DF_END;
1244 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1246 if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
1247 DIALOG_EnableOwner( owner );
1249 /* Windows sets the focus to the dialog itself in EndDialog */
1251 if (IsChild(hwnd, GetFocus()))
1252 SetFocus( hwnd );
1254 /* Don't have to send a ShowWindow(SW_HIDE), just do
1255 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1257 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1258 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1260 /* unblock dialog loop */
1261 PostMessageA(hwnd, WM_NULL, 0, 0);
1262 return TRUE;
1266 /***********************************************************************
1267 * DIALOG_IsAccelerator
1269 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1271 HWND hwndControl = hwnd;
1272 HWND hwndNext;
1273 INT dlgCode;
1274 WCHAR buffer[128];
1278 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
1279 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
1281 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1282 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1283 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1285 /* find the accelerator key */
1286 LPWSTR p = buffer - 2;
1287 char a_char = vKey;
1288 WCHAR w_char = 0;
1292 p = strchrW( p + 2, '&' );
1294 while (p != NULL && p[1] == '&');
1296 /* and check if it's the one we're looking for */
1297 MultiByteToWideChar(CP_ACP, 0, &a_char, 1, &w_char, 1);
1298 if (p != NULL && toupperW( p[1] ) == toupperW( w_char ) )
1300 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
1302 /* set focus to the control */
1303 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
1304 /* and bump it on to next */
1305 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1307 else if (dlgCode & DLGC_BUTTON)
1309 /* send BM_CLICK message to the control */
1310 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1312 return TRUE;
1315 hwndNext = GetWindow( hwndControl, GW_CHILD );
1317 else hwndNext = 0;
1319 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1321 while (!hwndNext && hwndControl)
1323 hwndControl = GetParent( hwndControl );
1324 if (hwndControl == hwndDlg)
1326 if(hwnd==hwndDlg) /* prevent endless loop */
1328 hwndNext=hwnd;
1329 break;
1331 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1333 else
1334 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1336 hwndControl = hwndNext;
1338 while (hwndControl && (hwndControl != hwnd));
1340 return FALSE;
1343 /***********************************************************************
1344 * DIALOG_FindMsgDestination
1346 * The messages that IsDialogMessage sends may not go to the dialog
1347 * calling IsDialogMessage if that dialog is a child, and it has the
1348 * DS_CONTROL style set.
1349 * We propagate up until we hit one that does not have DS_CONTROL, or
1350 * whose parent is not a dialog.
1352 * This is undocumented behaviour.
1354 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1356 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1358 WND *pParent;
1359 HWND hParent = GetParent(hwndDlg);
1360 if (!hParent) break;
1362 pParent = WIN_FindWndPtr(hParent);
1363 if (!pParent) break;
1365 if (!(pParent->flags & WIN_ISDIALOG))
1367 WIN_ReleaseWndPtr(pParent);
1368 break;
1370 WIN_ReleaseWndPtr(pParent);
1372 hwndDlg = hParent;
1375 return hwndDlg;
1378 /***********************************************************************
1379 * DIALOG_IsDialogMessage
1381 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1382 UINT message, WPARAM wParam,
1383 LPARAM lParam, BOOL *translate,
1384 BOOL *dispatch, INT dlgCode )
1386 *translate = *dispatch = FALSE;
1388 if (message == WM_PAINT)
1390 /* Apparently, we have to handle this one as well */
1391 *dispatch = TRUE;
1392 return TRUE;
1395 /* Only the key messages get special processing */
1396 if ((message != WM_KEYDOWN) &&
1397 (message != WM_SYSKEYDOWN) &&
1398 (message != WM_SYSCHAR) &&
1399 (message != WM_CHAR))
1400 return FALSE;
1402 if (dlgCode & DLGC_WANTMESSAGE)
1404 *translate = *dispatch = TRUE;
1405 return TRUE;
1408 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1410 switch(message)
1412 case WM_KEYDOWN:
1413 switch(wParam)
1415 case VK_TAB:
1416 if (!(dlgCode & DLGC_WANTTAB))
1418 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1419 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1420 return TRUE;
1422 break;
1424 case VK_RIGHT:
1425 case VK_DOWN:
1426 case VK_LEFT:
1427 case VK_UP:
1428 if (!(dlgCode & DLGC_WANTARROWS))
1430 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1431 HWND hwndNext =
1432 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1433 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1434 return TRUE;
1436 break;
1438 case VK_ESCAPE:
1439 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1440 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1441 return TRUE;
1443 case VK_RETURN:
1445 DWORD dw = SendMessageW( hwndDlg, DM_GETDEFID, 0, 0 );
1446 if (HIWORD(dw) == DC_HASDEFID)
1448 SendMessageA( hwndDlg, WM_COMMAND,
1449 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1450 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1452 else
1454 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1455 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1459 return TRUE;
1461 *translate = TRUE;
1462 break; /* case WM_KEYDOWN */
1464 case WM_CHAR:
1465 if (dlgCode & DLGC_WANTCHARS) break;
1466 /* drop through */
1468 case WM_SYSCHAR:
1469 if (DIALOG_IsAccelerator( WIN_GetFullHandle(hwnd), hwndDlg, wParam ))
1471 /* don't translate or dispatch */
1472 return TRUE;
1474 break;
1476 case WM_SYSKEYDOWN:
1477 *translate = TRUE;
1478 break;
1481 /* If we get here, the message has not been treated specially */
1482 /* and can be sent to its destination window. */
1483 *dispatch = TRUE;
1484 return TRUE;
1488 /***********************************************************************
1489 * IsDialogMessage (USER.90)
1491 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1493 LPMSG16 msg = MapSL(msg16);
1494 BOOL ret, translate, dispatch;
1495 INT dlgCode = 0;
1497 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1498 return FALSE;
1500 if ((msg->message == WM_KEYDOWN) ||
1501 (msg->message == WM_CHAR))
1503 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1505 ret = DIALOG_IsDialogMessage( WIN_Handle32(msg->hwnd), WIN_Handle32(hwndDlg),
1506 msg->message, msg->wParam, msg->lParam,
1507 &translate, &dispatch, dlgCode );
1508 if (translate) TranslateMessage16( msg );
1509 if (dispatch) DispatchMessage16( msg );
1510 return ret;
1514 /***********************************************************************
1515 * IsDialogMessage (USER32.@)
1516 * IsDialogMessageA (USER32.@)
1518 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1520 BOOL ret, translate, dispatch;
1521 INT dlgCode = 0;
1523 hwndDlg = WIN_GetFullHandle( hwndDlg );
1524 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1525 return FALSE;
1527 if ((msg->message == WM_KEYDOWN) ||
1528 (msg->message == WM_CHAR))
1530 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1532 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1533 msg->wParam, msg->lParam,
1534 &translate, &dispatch, dlgCode );
1535 if (translate) TranslateMessage( msg );
1536 if (dispatch) DispatchMessageA( msg );
1537 return ret;
1541 /***********************************************************************
1542 * IsDialogMessageW (USER32.@)
1544 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1546 BOOL ret, translate, dispatch;
1547 INT dlgCode = 0;
1549 hwndDlg = WIN_GetFullHandle( hwndDlg );
1550 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1551 return FALSE;
1553 if ((msg->message == WM_KEYDOWN) ||
1554 (msg->message == WM_CHAR))
1556 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1558 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1559 msg->wParam, msg->lParam,
1560 &translate, &dispatch, dlgCode );
1561 if (translate) TranslateMessage( msg );
1562 if (dispatch) DispatchMessageW( msg );
1563 return ret;
1567 /***********************************************************************
1568 * GetDlgCtrlID (USER32.@)
1570 INT WINAPI GetDlgCtrlID( HWND hwnd )
1572 return GetWindowLongW( hwnd, GWL_ID );
1576 /***********************************************************************
1577 * GetDlgItem (USER32.@)
1579 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1581 int i;
1582 HWND *list = WIN_ListChildren( hwndDlg );
1583 HWND ret = 0;
1585 if (!list) return 0;
1587 for (i = 0; list[i]; i++) if (GetWindowLongW( list[i], GWL_ID ) == id) break;
1588 ret = list[i];
1589 HeapFree( GetProcessHeap(), 0, list );
1590 return ret;
1594 /*******************************************************************
1595 * SendDlgItemMessageA (USER32.@)
1597 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1598 WPARAM wParam, LPARAM lParam )
1600 HWND hwndCtrl = GetDlgItem( hwnd, id );
1601 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1602 else return 0;
1606 /*******************************************************************
1607 * SendDlgItemMessageW (USER32.@)
1609 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1610 WPARAM wParam, LPARAM lParam )
1612 HWND hwndCtrl = GetDlgItem( hwnd, id );
1613 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1614 else return 0;
1618 /*******************************************************************
1619 * SetDlgItemTextA (USER32.@)
1621 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1623 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1627 /*******************************************************************
1628 * SetDlgItemTextW (USER32.@)
1630 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1632 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1636 /***********************************************************************
1637 * GetDlgItemTextA (USER32.@)
1639 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1641 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1642 len, (LPARAM)str );
1646 /***********************************************************************
1647 * GetDlgItemTextW (USER32.@)
1649 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1651 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1652 len, (LPARAM)str );
1656 /*******************************************************************
1657 * SetDlgItemInt (USER32.@)
1659 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1660 BOOL fSigned )
1662 char str[20];
1664 if (fSigned) sprintf( str, "%d", (INT)value );
1665 else sprintf( str, "%u", value );
1666 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1667 return TRUE;
1671 /***********************************************************************
1672 * GetDlgItemInt (USER32.@)
1674 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1675 BOOL fSigned )
1677 char str[30];
1678 char * endptr;
1679 long result = 0;
1681 if (translated) *translated = FALSE;
1682 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1683 return 0;
1684 if (fSigned)
1686 result = strtol( str, &endptr, 10 );
1687 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1688 return 0;
1689 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1690 return 0;
1692 else
1694 result = strtoul( str, &endptr, 10 );
1695 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1696 return 0;
1697 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1699 if (translated) *translated = TRUE;
1700 return (UINT)result;
1704 /***********************************************************************
1705 * CheckDlgButton (USER32.@)
1707 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1709 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1710 return TRUE;
1714 /***********************************************************************
1715 * IsDlgButtonChecked (USER32.@)
1717 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1719 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1723 /***********************************************************************
1724 * CheckRB
1726 * Callback function used to check/uncheck radio buttons that fall
1727 * within a specific range of IDs.
1729 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1731 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1732 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1734 if ((lChildID >= lpRadioGroup->firstID) &&
1735 (lChildID <= lpRadioGroup->lastID))
1737 if (lChildID == lpRadioGroup->checkID)
1739 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1741 else
1743 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1747 return TRUE;
1751 /***********************************************************************
1752 * CheckRadioButton (USER32.@)
1754 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1755 UINT lastID, UINT checkID )
1757 RADIOGROUP radioGroup;
1759 /* perform bounds checking for a radio button group */
1760 radioGroup.firstID = min(min(firstID, lastID), checkID);
1761 radioGroup.lastID = max(max(firstID, lastID), checkID);
1762 radioGroup.checkID = checkID;
1764 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1765 (LPARAM)&radioGroup);
1769 /***********************************************************************
1770 * GetDialogBaseUnits (USER.243)
1771 * GetDialogBaseUnits (USER32.@)
1773 DWORD WINAPI GetDialogBaseUnits(void)
1775 return MAKELONG( xBaseUnit, yBaseUnit );
1779 /***********************************************************************
1780 * MapDialogRect (USER32.@)
1782 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1784 DIALOGINFO * dlgInfo;
1785 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return FALSE;
1786 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1787 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1788 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1789 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1790 return TRUE;
1794 /***********************************************************************
1795 * GetNextDlgGroupItem (USER32.@)
1797 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1799 HWND hwnd, retvalue;
1801 hwndDlg = WIN_GetFullHandle( hwndDlg );
1802 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1804 if(hwndCtrl)
1806 /* if the hwndCtrl is the child of the control in the hwndDlg,
1807 * then the hwndDlg has to be the parent of the hwndCtrl */
1808 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1809 hwndDlg = GetParent(hwndCtrl);
1812 if (hwndCtrl)
1814 /* Make sure hwndCtrl is a top-level child */
1815 HWND parent = GetParent( hwndCtrl );
1816 while (parent && parent != hwndDlg) parent = GetParent(parent);
1817 if (parent != hwndDlg) return 0;
1819 else
1821 /* No ctrl specified -> start from the beginning */
1822 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1823 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
1826 retvalue = hwndCtrl;
1827 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
1828 while (1)
1830 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
1832 /* Wrap-around to the beginning of the group */
1833 HWND tmp;
1835 hwnd = GetWindow( hwndDlg, GW_CHILD );
1836 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
1838 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
1839 if (tmp == hwndCtrl) break;
1842 if (hwnd == hwndCtrl) break;
1843 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1845 retvalue = hwnd;
1846 if (!fPrevious) break;
1848 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
1850 return retvalue;
1854 /***********************************************************************
1855 * DIALOG_GetNextTabItem
1857 * Helper for GetNextDlgTabItem
1859 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1861 LONG dsStyle;
1862 LONG exStyle;
1863 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1864 HWND retWnd = 0;
1865 HWND hChildFirst = 0;
1867 if(!hwndCtrl)
1869 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1870 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1872 else if (IsChild( hwndMain, hwndCtrl ))
1874 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1875 if(!hChildFirst)
1877 if(GetParent(hwndCtrl) != hwndMain)
1878 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1879 else
1881 if(fPrevious)
1882 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1883 else
1884 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1889 while(hChildFirst)
1891 BOOL bCtrl = FALSE;
1892 while(hChildFirst)
1894 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1895 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1896 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1898 bCtrl=TRUE;
1899 break;
1901 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1902 break;
1903 hChildFirst = GetWindow(hChildFirst,wndSearch);
1905 if(hChildFirst)
1907 if(bCtrl)
1908 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
1909 else
1910 retWnd = hChildFirst;
1912 if(retWnd) break;
1913 hChildFirst = GetWindow(hChildFirst,wndSearch);
1915 if(!retWnd && hwndCtrl)
1917 HWND hParent = GetParent(hwndCtrl);
1918 while(hParent)
1920 if(hParent == hwndMain) break;
1921 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1922 if(retWnd) break;
1923 hParent = GetParent(hParent);
1925 if(!retWnd)
1926 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
1928 return retWnd;
1931 /***********************************************************************
1932 * GetNextDlgTabItem (USER32.@)
1934 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1935 BOOL fPrevious )
1937 hwndDlg = WIN_GetFullHandle( hwndDlg );
1938 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1939 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1942 /**********************************************************************
1943 * DIALOG_DlgDirSelect
1945 * Helper function for DlgDirSelect*
1947 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
1948 INT id, BOOL unicode, BOOL combo )
1950 char *buffer, *ptr;
1951 INT item, size;
1952 BOOL ret;
1953 HWND listbox = GetDlgItem( hwnd, id );
1955 TRACE("%04x '%s' %d\n", hwnd, str, id );
1956 if (!listbox) return FALSE;
1958 item = SendMessageA(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1959 if (item == LB_ERR) return FALSE;
1960 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1961 if (size == LB_ERR) return FALSE;
1963 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1965 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1967 if ((ret = (buffer[0] == '['))) /* drive or directory */
1969 if (buffer[1] == '-') /* drive */
1971 buffer[3] = ':';
1972 buffer[4] = 0;
1973 ptr = buffer + 2;
1975 else
1977 buffer[strlen(buffer)-1] = '\\';
1978 ptr = buffer + 1;
1981 else ptr = buffer;
1983 if (unicode)
1985 if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
1986 ((LPWSTR)str)[len-1] = 0;
1988 else lstrcpynA( str, ptr, len );
1989 HeapFree( GetProcessHeap(), 0, buffer );
1990 TRACE("Returning %d '%s'\n", ret, str );
1991 return ret;
1995 /**********************************************************************
1996 * DIALOG_DlgDirList
1998 * Helper function for DlgDirList*
2000 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2001 INT idStatic, UINT attrib, BOOL combo )
2003 HWND hwnd;
2004 LPSTR orig_spec = spec;
2006 #define SENDMSG(msg,wparam,lparam) \
2007 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2008 : SendMessageA( hwnd, msg, wparam, lparam ))
2010 TRACE("%04x '%s' %d %d %04x\n",
2011 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2013 /* If the path exists and is a directory, chdir to it */
2014 if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
2015 else
2017 char *p, *p2;
2018 p = spec;
2019 if ((p2 = strrchr( p, '\\' ))) p = p2;
2020 if ((p2 = strrchr( p, '/' ))) p = p2;
2021 if (p != spec)
2023 char sep = *p;
2024 *p = 0;
2025 if (!SetCurrentDirectoryA( spec ))
2027 *p = sep; /* Restore the original spec */
2028 return FALSE;
2030 spec = p + 1;
2034 TRACE( "mask=%s\n", spec );
2036 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2038 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2039 if (attrib & DDL_DIRECTORY)
2041 if (!(attrib & DDL_EXCLUSIVE))
2043 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2044 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2045 (LPARAM)spec ) == LB_ERR)
2046 return FALSE;
2048 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2049 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2050 (LPARAM)"*.*" ) == LB_ERR)
2051 return FALSE;
2053 else
2055 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2056 (LPARAM)spec ) == LB_ERR)
2057 return FALSE;
2061 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2063 char temp[MAX_PATH];
2064 GetCurrentDirectoryA( sizeof(temp), temp );
2065 CharLowerA( temp );
2066 /* Can't use PostMessage() here, because the string is on the stack */
2067 SetDlgItemTextA( hDlg, idStatic, temp );
2070 if (orig_spec && (spec != orig_spec))
2072 /* Update the original file spec */
2073 char *p = spec;
2074 while ((*orig_spec++ = *p++));
2077 return TRUE;
2078 #undef SENDMSG
2082 /**********************************************************************
2083 * DIALOG_DlgDirListW
2085 * Helper function for DlgDirList*W
2087 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2088 INT idStatic, UINT attrib, BOOL combo )
2090 if (spec)
2092 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2093 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2094 attrib, combo );
2095 MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
2096 HeapFree( GetProcessHeap(), 0, specA );
2097 return ret;
2099 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2103 /**********************************************************************
2104 * DlgDirSelectExA (USER32.@)
2106 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2108 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE );
2112 /**********************************************************************
2113 * DlgDirSelectExW (USER32.@)
2115 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2117 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, FALSE );
2121 /**********************************************************************
2122 * DlgDirSelectComboBoxExA (USER32.@)
2124 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2125 INT id )
2127 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, TRUE );
2131 /**********************************************************************
2132 * DlgDirSelectComboBoxExW (USER32.@)
2134 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2135 INT id)
2137 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE );
2141 /**********************************************************************
2142 * DlgDirListA (USER32.@)
2144 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2145 INT idStatic, UINT attrib )
2147 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2151 /**********************************************************************
2152 * DlgDirListW (USER32.@)
2154 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2155 INT idStatic, UINT attrib )
2157 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2161 /**********************************************************************
2162 * DlgDirListComboBoxA (USER32.@)
2164 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2165 INT idStatic, UINT attrib )
2167 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2171 /**********************************************************************
2172 * DlgDirListComboBoxW (USER32.@)
2174 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2175 INT idStatic, UINT attrib )
2177 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );