4 * Copyright 1993, 1994, 1996 Alexandre Julliard
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
37 #include "wine/winuser16.h"
38 #include "wine/winbase16.h"
39 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
49 /* Dialog control information */
86 /* Radio button group */
94 /* Dialog base units */
95 static WORD xBaseUnit = 0, yBaseUnit = 0;
98 /*********************************************************************
99 * dialog class descriptor
101 const struct builtin_class_descr DIALOG_builtin_class =
103 DIALOG_CLASS_ATOM, /* name */
104 CS_GLOBALCLASS | CS_SAVEBITS, /* style */
105 DefDlgProcA, /* procA */
106 DefDlgProcW, /* procW */
107 DLGWINDOWEXTRA, /* extra */
108 IDC_ARROWA, /* cursor */
113 /***********************************************************************
116 * Helper function for modal dialogs to enable again the
117 * owner of the dialog box.
119 void DIALOG_EnableOwner( HWND hOwner )
121 /* Owner must be a top-level window */
123 hOwner = GetAncestor( hOwner, GA_ROOT );
125 EnableWindow( hOwner, TRUE );
129 /***********************************************************************
130 * DIALOG_DisableOwner
132 * Helper function for modal dialogs to disable the
133 * owner of the dialog box. Returns TRUE if owner was enabled.
135 BOOL DIALOG_DisableOwner( HWND hOwner )
137 /* Owner must be a top-level window */
139 hOwner = GetAncestor( hOwner, GA_ROOT );
140 if (!hOwner) return FALSE;
141 if (IsWindowEnabled( hOwner ))
143 EnableWindow( hOwner, FALSE );
150 /***********************************************************************
151 * DIALOG_GetCharSizeFromDC
153 * Despite most of MSDN insisting that the horizontal base unit is
154 * tmAveCharWidth it isn't. Knowledge base article Q145994
155 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
156 * says that we should take the average of the 52 English upper and lower
159 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
162 char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
166 pSize->cx = xBaseUnit;
167 pSize->cy = yBaseUnit;
169 if(!hDC) return FALSE;
171 if(hFont) hFontPrev = SelectFont(hDC, hFont);
172 if(!GetTextMetricsA(hDC, &tm)) return FALSE;
173 if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
175 pSize->cy = tm.tmHeight;
176 pSize->cx = (sz.cx / 26 + 1) / 2;
178 if (hFontPrev) SelectFont(hDC, hFontPrev);
180 TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy);
184 /***********************************************************************
187 * A convenient variant of DIALOG_GetCharSizeFromDC.
189 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
192 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
197 /***********************************************************************
200 * Initialisation of the dialog manager.
202 BOOL DIALOG_Init(void)
207 /* Calculate the dialog base units */
209 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
211 ERR("Could not create Display DC\n");
215 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size ))
218 ERR("Could not initialize base dialog units\n");
226 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
231 /***********************************************************************
232 * DIALOG_GetControl16
234 * Return the class and text of the control pointed to by ptr,
235 * fill the header structure and return a pointer to the next control.
237 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
239 static char buffer[10];
242 info->x = GET_WORD(p); p += sizeof(WORD);
243 info->y = GET_WORD(p); p += sizeof(WORD);
244 info->cx = GET_WORD(p); p += sizeof(WORD);
245 info->cy = GET_WORD(p); p += sizeof(WORD);
246 info->id = GET_WORD(p); p += sizeof(WORD);
247 info->style = GET_DWORD(p); p += sizeof(DWORD);
254 case 0x80: strcpy( buffer, "BUTTON" ); break;
255 case 0x81: strcpy( buffer, "EDIT" ); break;
256 case 0x82: strcpy( buffer, "STATIC" ); break;
257 case 0x83: strcpy( buffer, "LISTBOX" ); break;
258 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
259 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
260 default: buffer[0] = '\0'; break;
262 info->className = buffer;
271 int_id = ((BYTE)*p == 0xff);
274 /* Integer id, not documented (?). Only works for SS_ICON controls */
275 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
280 info->windowName = p;
284 if (*p) info->data = p + 1;
285 else info->data = NULL;
290 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %p\n",
291 info->className, LOWORD(info->windowName),
292 info->id, info->x, info->y, info->cx, info->cy,
293 info->style, info->data );
295 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %p\n",
296 info->className, info->windowName,
297 info->id, info->x, info->y, info->cx, info->cy,
298 info->style, info->data );
304 /***********************************************************************
305 * DIALOG_GetControl32
307 * Return the class and text of the control pointed to by ptr,
308 * fill the header structure and return a pointer to the next control.
310 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
315 info->helpId = GET_DWORD(p); p += 2;
316 info->exStyle = GET_DWORD(p); p += 2;
317 info->style = GET_DWORD(p); p += 2;
322 info->style = GET_DWORD(p); p += 2;
323 info->exStyle = GET_DWORD(p); p += 2;
325 info->x = GET_WORD(p); p++;
326 info->y = GET_WORD(p); p++;
327 info->cx = GET_WORD(p); p++;
328 info->cy = GET_WORD(p); p++;
332 /* id is a DWORD for DIALOGEX */
333 info->id = GET_DWORD(p);
338 info->id = GET_WORD(p);
342 if (GET_WORD(p) == 0xffff)
344 static const WCHAR class_names[6][10] =
346 { 'B','u','t','t','o','n', }, /* 0x80 */
347 { 'E','d','i','t', }, /* 0x81 */
348 { 'S','t','a','t','i','c', }, /* 0x82 */
349 { 'L','i','s','t','B','o','x', }, /* 0x83 */
350 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
351 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
353 WORD id = GET_WORD(p+1);
354 if ((id >= 0x80) && (id <= 0x85))
355 info->className = (LPCSTR)class_names[id - 0x80];
358 info->className = NULL;
359 ERR("Unknown built-in class id %04x\n", id );
365 info->className = (LPCSTR)p;
366 p += strlenW( (LPCWSTR)p ) + 1;
369 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
371 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
376 info->windowName = (LPCSTR)p;
377 p += strlenW( (LPCWSTR)p ) + 1;
380 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
381 debugstr_w( (LPCWSTR)info->className ),
382 debugres_w( (LPCWSTR)info->windowName ),
383 info->id, info->x, info->y, info->cx, info->cy,
384 info->style, info->exStyle, info->helpId );
388 if (TRACE_ON(dialog))
390 WORD i, count = GET_WORD(p) / sizeof(WORD);
393 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
398 p += GET_WORD(p) / sizeof(WORD);
400 else info->data = NULL;
403 /* Next control is on dword boundary */
404 return (const WORD *)((((int)p) + 3) & ~3);
408 /***********************************************************************
409 * DIALOG_CreateControls
411 * Create the control windows for a dialog.
413 static BOOL DIALOG_CreateControls( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
414 HINSTANCE hInst, BOOL win32 )
416 DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd );
417 DLG_CONTROL_INFO info;
418 HWND hwndCtrl, hwndDefButton = 0;
419 INT items = dlgTemplate->nbItems;
426 HINSTANCE16 instance;
429 template = DIALOG_GetControl16( template, &info );
430 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
431 !(GetWindowLongW( hwnd, GWL_STYLE ) & DS_LOCALEDIT))
433 if (!dlgInfo->hDialogHeap)
435 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
436 if (!dlgInfo->hDialogHeap)
438 ERR("Insufficient memory to create heap for edit control\n" );
441 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
443 instance = dlgInfo->hDialogHeap;
445 else instance = (HINSTANCE16)hInst;
447 segptr = MapLS( info.data );
448 hwndCtrl = WIN_Handle32( CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
449 info.className, info.windowName,
450 info.style | WS_CHILD,
451 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
452 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
453 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
454 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
455 WIN_Handle16(hwnd), (HMENU16)info.id,
456 instance, (LPVOID)segptr ));
461 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
462 dlgTemplate->dialogEx );
464 if (info.style & WS_BORDER)
466 info.style &= ~WS_BORDER;
467 info.exStyle |= WS_EX_CLIENTEDGE;
469 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
470 (LPCWSTR)info.className,
471 (LPCWSTR)info.windowName,
472 info.style | WS_CHILD,
473 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
474 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
475 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
476 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
477 hwnd, (HMENU)info.id,
478 hInst, (LPVOID)info.data );
480 if (!hwndCtrl) return FALSE;
482 /* Send initialisation messages to the control */
483 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
484 (WPARAM)dlgInfo->hUserFont, 0 );
485 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
487 /* If there's already a default push-button, set it back */
488 /* to normal and use this one instead. */
490 SendMessageA( hwndDefButton, BM_SETSTYLE,
491 BS_PUSHBUTTON,FALSE );
492 hwndDefButton = hwndCtrl;
493 dlgInfo->idResult = GetWindowLongA( hwndCtrl, GWL_ID );
501 /***********************************************************************
502 * DIALOG_ParseTemplate16
504 * Fill a DLG_TEMPLATE structure from the dialog template, and return
505 * a pointer to the first control.
507 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
509 result->style = GET_DWORD(p); p += sizeof(DWORD);
511 result->nbItems = (unsigned char) *p++;
512 result->x = GET_WORD(p); p += sizeof(WORD);
513 result->y = GET_WORD(p); p += sizeof(WORD);
514 result->cx = GET_WORD(p); p += sizeof(WORD);
515 result->cy = GET_WORD(p); p += sizeof(WORD);
516 TRACE("DIALOG %d, %d, %d, %d\n",
517 result->x, result->y, result->cx, result->cy );
518 TRACE(" STYLE %08lx\n", result->style );
520 /* Get the menu name */
525 result->menuName = 0;
529 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
531 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
534 result->menuName = p;
535 TRACE(" MENU '%s'\n", p );
540 /* Get the class name */
544 result->className = p;
545 TRACE(" CLASS '%s'\n", result->className );
547 else result->className = DIALOG_CLASS_ATOM;
550 /* Get the window caption */
554 TRACE(" CAPTION '%s'\n", result->caption );
556 /* Get the font name */
558 if (result->style & DS_SETFONT)
560 result->pointSize = GET_WORD(p);
562 result->faceName = p;
564 TRACE(" FONT %d,'%s'\n",
565 result->pointSize, result->faceName );
571 /***********************************************************************
572 * DIALOG_ParseTemplate32
574 * Fill a DLG_TEMPLATE structure from the dialog template, and return
575 * a pointer to the first control.
577 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
579 const WORD *p = (const WORD *)template;
581 result->style = GET_DWORD(p); p += 2;
582 if (result->style == 0xffff0001) /* DIALOGEX resource */
584 result->dialogEx = TRUE;
585 result->helpId = GET_DWORD(p); p += 2;
586 result->exStyle = GET_DWORD(p); p += 2;
587 result->style = GET_DWORD(p); p += 2;
591 result->dialogEx = FALSE;
593 result->exStyle = GET_DWORD(p); p += 2;
595 result->nbItems = GET_WORD(p); p++;
596 result->x = GET_WORD(p); p++;
597 result->y = GET_WORD(p); p++;
598 result->cx = GET_WORD(p); p++;
599 result->cy = GET_WORD(p); p++;
600 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
601 result->dialogEx ? "EX" : "", result->x, result->y,
602 result->cx, result->cy, result->helpId );
603 TRACE(" STYLE 0x%08lx\n", result->style );
604 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
606 /* Get the menu name */
611 result->menuName = NULL;
615 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
617 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
620 result->menuName = (LPCSTR)p;
621 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
622 p += strlenW( (LPCWSTR)p ) + 1;
626 /* Get the class name */
631 result->className = DIALOG_CLASS_ATOM;
635 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
637 TRACE(" CLASS %04x\n", LOWORD(result->className) );
640 result->className = (LPCSTR)p;
641 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
642 p += strlenW( (LPCWSTR)p ) + 1;
646 /* Get the window caption */
648 result->caption = (LPCSTR)p;
649 p += strlenW( (LPCWSTR)p ) + 1;
650 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
652 /* Get the font name */
654 if (result->style & DS_SETFONT)
656 result->pointSize = GET_WORD(p);
658 if (result->dialogEx)
660 result->weight = GET_WORD(p); p++;
661 result->italic = LOBYTE(GET_WORD(p)); p++;
665 result->weight = FW_DONTCARE;
666 result->italic = FALSE;
668 result->faceName = (LPCSTR)p;
669 p += strlenW( (LPCWSTR)p ) + 1;
670 TRACE(" FONT %d, %s, %d, %s\n",
671 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
672 result->weight, result->italic ? "TRUE" : "FALSE" );
675 /* First control is on dword boundary */
676 return (LPCSTR)((((int)p) + 3) & ~3);
680 /***********************************************************************
681 * DIALOG_CreateIndirect
682 * Creates a dialog box window
684 * modal = TRUE if we are called from a modal dialog box.
685 * (it's more compatible to do it here, as under Windows the owner
686 * is never disabled if the dialog fails because of an invalid template)
688 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
689 HWND owner, DLGPROC dlgProc, LPARAM param,
690 WINDOWPROCTYPE procType, BOOL modal )
695 DLG_TEMPLATE template;
696 DIALOGINFO * dlgInfo;
697 BOOL ownerEnabled = TRUE;
698 BOOL win32Template = (procType != WIN_PROC_16);
700 /* Parse dialog template */
702 if (!dlgTemplate) return 0;
704 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
706 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
708 /* Initialise dialog extra data */
710 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
711 dlgInfo->hwndFocus = 0;
712 dlgInfo->hUserFont = 0;
714 dlgInfo->xBaseUnit = xBaseUnit;
715 dlgInfo->yBaseUnit = yBaseUnit;
716 dlgInfo->idResult = 0;
718 dlgInfo->hDialogHeap = 0;
722 if (template.menuName)
724 if (!win32Template) dlgInfo->hMenu = LoadMenu16( hInst, template.menuName );
725 else dlgInfo->hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
728 /* Create custom font if needed */
730 if (template.style & DS_SETFONT)
732 /* We convert the size to pixels and then make it -ve. This works
733 * for both +ve and -ve template.pointSize */
737 pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
740 dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
741 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
742 PROOF_QUALITY, FF_DONTCARE,
743 (LPCWSTR)template.faceName );
745 dlgInfo->hUserFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
746 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
747 PROOF_QUALITY, FF_DONTCARE, template.faceName );
748 if (dlgInfo->hUserFont)
751 if (DIALOG_GetCharSize( dlgInfo->hUserFont, &charSize ))
753 dlgInfo->xBaseUnit = charSize.cx;
754 dlgInfo->yBaseUnit = charSize.cy;
757 TRACE("units = %d,%d\n", dlgInfo->xBaseUnit, dlgInfo->yBaseUnit );
760 /* Create dialog main window */
762 rect.left = rect.top = 0;
763 rect.right = MulDiv(template.cx, dlgInfo->xBaseUnit, 4);
764 rect.bottom = MulDiv(template.cy, dlgInfo->yBaseUnit, 8);
765 if (template.style & DS_MODALFRAME)
766 template.exStyle |= WS_EX_DLGMODALFRAME;
767 AdjustWindowRectEx( &rect, template.style, (dlgInfo->hMenu != 0), template.exStyle );
768 rect.right -= rect.left;
769 rect.bottom -= rect.top;
771 if ((INT16)template.x == CW_USEDEFAULT16)
773 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
777 if (template.style & DS_CENTER)
779 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
780 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
784 rect.left += MulDiv(template.x, dlgInfo->xBaseUnit, 4);
785 rect.top += MulDiv(template.y, dlgInfo->yBaseUnit, 8);
787 if ( !(template.style & WS_CHILD) )
791 if( !(template.style & DS_ABSALIGN) )
792 ClientToScreen( owner, (POINT *)&rect );
794 /* try to fit it into the desktop */
796 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
797 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
798 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
799 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
800 if( rect.left < 0 ) rect.left = 0;
801 if( rect.top < 0 ) rect.top = 0;
807 ownerEnabled = DIALOG_DisableOwner( owner );
808 if (ownerEnabled) dlgInfo->flags |= DF_OWNERENABLED;
812 hwnd = WIN_Handle32( CreateWindowEx16(template.exStyle, template.className,
813 template.caption, template.style & ~WS_VISIBLE,
814 rect.left, rect.top, rect.right, rect.bottom,
815 WIN_Handle16(owner), dlgInfo->hMenu, hInst, NULL ));
817 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
818 (LPCWSTR)template.caption,
819 template.style & ~WS_VISIBLE,
820 rect.left, rect.top, rect.right, rect.bottom,
821 owner, dlgInfo->hMenu, hInst, NULL );
825 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
826 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
827 if (modal && (dlgInfo->flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
828 HeapFree( GetProcessHeap(), 0, dlgInfo );
831 wndPtr = WIN_GetPtr( hwnd );
832 wndPtr->flags |= WIN_ISDIALOG;
833 WIN_ReleasePtr( wndPtr );
835 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
836 SetWindowLongW( hwnd, DWL_WINE_DIALOGINFO, (LONG)dlgInfo );
839 case WIN_PROC_16: SetWindowLong16( WIN_Handle16(hwnd), DWL_DLGPROC, (LONG)dlgProc ); break;
840 case WIN_PROC_32A: SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
841 case WIN_PROC_32W: SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
845 if (dlgInfo->hUserFont)
846 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
848 /* Create controls */
850 if (DIALOG_CreateControls( hwnd, dlgTemplate, &template,
851 hInst, win32Template ))
853 HWND hwndPreInitFocus;
855 /* Send initialisation messages and set focus */
857 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
859 hwndPreInitFocus = GetFocus();
860 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
862 /* check where the focus is again,
863 * some controls status might have changed in WM_INITDIALOG */
864 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
865 if( dlgInfo->hwndFocus )
866 SetFocus( dlgInfo->hwndFocus );
870 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
871 but the focus has not changed, set the focus where we expect it. */
872 if ((GetFocus() == hwndPreInitFocus) &&
873 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
875 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
876 if( dlgInfo->hwndFocus )
877 SetFocus( dlgInfo->hwndFocus );
881 if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
883 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
887 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
888 if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
893 /***********************************************************************
894 * CreateDialog (USER.89)
896 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
897 HWND16 owner, DLGPROC16 dlgProc )
899 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
903 /***********************************************************************
904 * CreateDialogParam (USER.241)
906 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
907 HWND16 owner, DLGPROC16 dlgProc,
915 TRACE("%04x,%s,%04x,%08lx,%ld\n",
916 hInst, debugres_a(dlgTemplate), owner, (DWORD)dlgProc, param );
918 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOGA ))) return 0;
919 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
920 if (!(data = LockResource16( hmem ))) hwnd = 0;
921 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
923 FreeResource16( hmem );
927 /***********************************************************************
928 * CreateDialogParamA (USER32.@)
930 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
931 HWND owner, DLGPROC dlgProc,
934 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
935 if (!hrsrc) return 0;
936 return CreateDialogIndirectParamA( hInst,
937 (LPVOID)LoadResource(hInst, hrsrc),
938 owner, dlgProc, param );
942 /***********************************************************************
943 * CreateDialogParamW (USER32.@)
945 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
946 HWND owner, DLGPROC dlgProc,
949 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
950 if (!hrsrc) return 0;
951 return CreateDialogIndirectParamW( hInst,
952 (LPVOID)LoadResource(hInst, hrsrc),
953 owner, dlgProc, param );
957 /***********************************************************************
958 * CreateDialogIndirect (USER.219)
960 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
961 HWND16 owner, DLGPROC16 dlgProc )
963 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
967 /***********************************************************************
968 * CreateDialogIndirectParam (USER.242)
969 * CreateDialogIndirectParam16 (USER32.@)
971 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
973 HWND16 owner, DLGPROC16 dlgProc,
976 return WIN_Handle16( DIALOG_CreateIndirect( hInst, dlgTemplate, WIN_Handle32(owner),
977 (DLGPROC)dlgProc, param, WIN_PROC_16, FALSE ));
981 /***********************************************************************
982 * CreateDialogIndirectParamA (USER32.@)
984 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
986 HWND owner, DLGPROC dlgProc,
989 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32A, FALSE );
992 /***********************************************************************
993 * CreateDialogIndirectParamAorW (USER32.@)
995 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
997 HWND owner, DLGPROC dlgProc,
999 { FIXME("assume WIN_PROC_32W\n");
1000 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1003 /***********************************************************************
1004 * CreateDialogIndirectParamW (USER32.@)
1006 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
1007 LPCVOID dlgTemplate,
1008 HWND owner, DLGPROC dlgProc,
1011 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1015 /***********************************************************************
1016 * DIALOG_DoDialogBox
1018 static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
1020 DIALOGINFO * dlgInfo;
1023 HWND ownerMsg = GetAncestor( owner, GA_ROOT );
1025 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return -1;
1027 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
1029 ShowWindow( hwnd, SW_SHOW );
1032 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
1034 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
1036 /* No message present -> send ENTERIDLE and wait */
1037 SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
1038 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1041 else if (!GetMessageW( &msg, 0, 0, 0 )) break;
1043 if (CallMsgFilterW( &msg, MSGF_DIALOGBOX )) continue;
1045 if (!IsWindow( hwnd )) return -1;
1046 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
1048 TranslateMessage( &msg );
1049 DispatchMessageW( &msg );
1051 if (dlgInfo->flags & DF_END) break;
1054 if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
1055 retval = dlgInfo->idResult;
1056 DestroyWindow( hwnd );
1061 /***********************************************************************
1062 * DialogBox (USER.87)
1064 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
1065 HWND16 owner, DLGPROC16 dlgProc )
1067 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1071 /***********************************************************************
1072 * DialogBoxParam (USER.239)
1074 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, LPCSTR template,
1075 HWND16 owner16, DLGPROC16 dlgProc, LPARAM param )
1083 if (!(hRsrc = FindResource16( hInst, template, RT_DIALOGA ))) return 0;
1084 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
1085 if ((data = LockResource16( hmem )))
1087 HWND owner = WIN_Handle32(owner16);
1088 hwnd = DIALOG_CreateIndirect( hInst, data, owner,
1089 (DLGPROC)dlgProc, param, WIN_PROC_16, TRUE );
1090 if (hwnd) ret = DIALOG_DoDialogBox( hwnd, owner );
1091 GlobalUnlock16( hmem );
1093 FreeResource16( hmem );
1098 /***********************************************************************
1099 * DialogBoxParamA (USER32.@)
1101 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1102 HWND owner, DLGPROC dlgProc, LPARAM param )
1105 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
1106 if (!hrsrc) return 0;
1107 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1108 owner, dlgProc, param, WIN_PROC_32A, TRUE );
1109 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1114 /***********************************************************************
1115 * DialogBoxParamW (USER32.@)
1117 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1118 HWND owner, DLGPROC dlgProc, LPARAM param )
1121 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
1122 if (!hrsrc) return 0;
1123 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1124 owner, dlgProc, param, WIN_PROC_32W, TRUE );
1125 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1130 /***********************************************************************
1131 * DialogBoxIndirect (USER.218)
1133 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1134 HWND16 owner, DLGPROC16 dlgProc )
1136 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1140 /***********************************************************************
1141 * DialogBoxIndirectParam (USER.240)
1142 * DialogBoxIndirectParam16 (USER32.@)
1144 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1145 HWND16 owner16, DLGPROC16 dlgProc,
1148 HWND hwnd, owner = WIN_Handle32( owner16 );
1151 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1152 hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, (DLGPROC)dlgProc,
1153 param, WIN_PROC_16, TRUE );
1154 GlobalUnlock16( dlgTemplate );
1155 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1160 /***********************************************************************
1161 * DialogBoxIndirectParamA (USER32.@)
1163 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1164 HWND owner, DLGPROC dlgProc,
1167 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1168 dlgProc, param, WIN_PROC_32A, TRUE );
1169 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1174 /***********************************************************************
1175 * DialogBoxIndirectParamW (USER32.@)
1177 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1178 HWND owner, DLGPROC dlgProc,
1181 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1182 dlgProc, param, WIN_PROC_32W, TRUE );
1183 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1187 /***********************************************************************
1188 * DialogBoxIndirectParamAorW (USER32.@)
1190 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1191 HWND owner, DLGPROC dlgProc,
1192 LPARAM param, DWORD x )
1195 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1196 hInstance, template, owner, dlgProc, param, x);
1197 hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, WIN_PROC_32W, TRUE );
1198 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1202 /***********************************************************************
1203 * EndDialog (USER32.@)
1205 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1207 BOOL wasEnabled = TRUE;
1208 DIALOGINFO * dlgInfo;
1211 TRACE("%04x %d\n", hwnd, retval );
1213 if (!(dlgInfo = DIALOG_get_info( hwnd )))
1215 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1218 dlgInfo->idResult = retval;
1219 dlgInfo->flags |= DF_END;
1220 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1222 if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
1223 DIALOG_EnableOwner( owner );
1225 /* Windows sets the focus to the dialog itself in EndDialog */
1227 if (IsChild(hwnd, GetFocus()))
1230 /* Don't have to send a ShowWindow(SW_HIDE), just do
1231 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1233 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1234 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1236 /* unblock dialog loop */
1237 PostMessageA(hwnd, WM_NULL, 0, 0);
1242 /***********************************************************************
1243 * DIALOG_IsAccelerator
1245 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1247 HWND hwndControl = hwnd;
1254 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
1255 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
1257 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1258 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1259 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1261 /* find the accelerator key */
1262 LPWSTR p = buffer - 2;
1268 p = strchrW( p + 2, '&' );
1270 while (p != NULL && p[1] == '&');
1272 /* and check if it's the one we're looking for */
1273 MultiByteToWideChar(CP_ACP, 0, &a_char, 1, &w_char, 1);
1274 if (p != NULL && toupperW( p[1] ) == toupperW( w_char ) )
1276 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
1278 /* set focus to the control */
1279 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
1280 /* and bump it on to next */
1281 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1283 else if (dlgCode & DLGC_BUTTON)
1285 /* send BM_CLICK message to the control */
1286 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1291 hwndNext = GetWindow( hwndControl, GW_CHILD );
1295 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1297 while (!hwndNext && hwndControl)
1299 hwndControl = GetParent( hwndControl );
1300 if (hwndControl == hwndDlg)
1302 if(hwnd==hwndDlg) /* prevent endless loop */
1307 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1310 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1312 hwndControl = hwndNext;
1314 while (hwndControl && (hwndControl != hwnd));
1319 /***********************************************************************
1320 * DIALOG_FindMsgDestination
1322 * The messages that IsDialogMessage sends may not go to the dialog
1323 * calling IsDialogMessage if that dialog is a child, and it has the
1324 * DS_CONTROL style set.
1325 * We propagate up until we hit one that does not have DS_CONTROL, or
1326 * whose parent is not a dialog.
1328 * This is undocumented behaviour.
1330 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1332 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1335 HWND hParent = GetParent(hwndDlg);
1336 if (!hParent) break;
1338 pParent = WIN_FindWndPtr(hParent);
1339 if (!pParent) break;
1341 if (!(pParent->flags & WIN_ISDIALOG))
1343 WIN_ReleaseWndPtr(pParent);
1346 WIN_ReleaseWndPtr(pParent);
1354 /***********************************************************************
1355 * DIALOG_IsDialogMessage
1357 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1358 UINT message, WPARAM wParam,
1359 LPARAM lParam, BOOL *translate,
1360 BOOL *dispatch, INT dlgCode )
1362 *translate = *dispatch = FALSE;
1364 if (message == WM_PAINT)
1366 /* Apparently, we have to handle this one as well */
1371 /* Only the key messages get special processing */
1372 if ((message != WM_KEYDOWN) &&
1373 (message != WM_SYSKEYDOWN) &&
1374 (message != WM_SYSCHAR) &&
1375 (message != WM_CHAR))
1378 if (dlgCode & DLGC_WANTMESSAGE)
1380 *translate = *dispatch = TRUE;
1384 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1392 if (!(dlgCode & DLGC_WANTTAB))
1394 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1395 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1404 if (!(dlgCode & DLGC_WANTARROWS))
1406 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1408 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1409 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1415 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1416 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1421 DWORD dw = SendMessageW( hwndDlg, DM_GETDEFID, 0, 0 );
1422 if (HIWORD(dw) == DC_HASDEFID)
1424 SendMessageA( hwndDlg, WM_COMMAND,
1425 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1426 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1430 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1431 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1438 break; /* case WM_KEYDOWN */
1441 if (dlgCode & DLGC_WANTCHARS) break;
1445 if (DIALOG_IsAccelerator( WIN_GetFullHandle(hwnd), hwndDlg, wParam ))
1447 /* don't translate or dispatch */
1457 /* If we get here, the message has not been treated specially */
1458 /* and can be sent to its destination window. */
1464 /***********************************************************************
1465 * IsDialogMessage (USER.90)
1467 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1469 LPMSG16 msg = MapSL(msg16);
1470 BOOL ret, translate, dispatch;
1473 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1476 if ((msg->message == WM_KEYDOWN) ||
1477 (msg->message == WM_CHAR))
1479 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1481 ret = DIALOG_IsDialogMessage( WIN_Handle32(msg->hwnd), WIN_Handle32(hwndDlg),
1482 msg->message, msg->wParam, msg->lParam,
1483 &translate, &dispatch, dlgCode );
1484 if (translate) TranslateMessage16( msg );
1485 if (dispatch) DispatchMessage16( msg );
1490 /***********************************************************************
1491 * IsDialogMessage (USER32.@)
1492 * IsDialogMessageA (USER32.@)
1494 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1496 BOOL ret, translate, dispatch;
1499 hwndDlg = WIN_GetFullHandle( hwndDlg );
1500 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1503 if ((msg->message == WM_KEYDOWN) ||
1504 (msg->message == WM_CHAR))
1506 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1508 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1509 msg->wParam, msg->lParam,
1510 &translate, &dispatch, dlgCode );
1511 if (translate) TranslateMessage( msg );
1512 if (dispatch) DispatchMessageA( msg );
1517 /***********************************************************************
1518 * IsDialogMessageW (USER32.@)
1520 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1522 BOOL ret, translate, dispatch;
1525 hwndDlg = WIN_GetFullHandle( hwndDlg );
1526 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1529 if ((msg->message == WM_KEYDOWN) ||
1530 (msg->message == WM_CHAR))
1532 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1534 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1535 msg->wParam, msg->lParam,
1536 &translate, &dispatch, dlgCode );
1537 if (translate) TranslateMessage( msg );
1538 if (dispatch) DispatchMessageW( msg );
1543 /***********************************************************************
1544 * GetDlgCtrlID (USER32.@)
1546 INT WINAPI GetDlgCtrlID( HWND hwnd )
1548 return GetWindowLongW( hwnd, GWL_ID );
1552 /***********************************************************************
1553 * GetDlgItem (USER32.@)
1555 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1558 HWND *list = WIN_ListChildren( hwndDlg );
1561 if (!list) return 0;
1563 for (i = 0; list[i]; i++) if (GetWindowLongW( list[i], GWL_ID ) == id) break;
1565 HeapFree( GetProcessHeap(), 0, list );
1570 /*******************************************************************
1571 * SendDlgItemMessageA (USER32.@)
1573 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1574 WPARAM wParam, LPARAM lParam )
1576 HWND hwndCtrl = GetDlgItem( hwnd, id );
1577 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1582 /*******************************************************************
1583 * SendDlgItemMessageW (USER32.@)
1585 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1586 WPARAM wParam, LPARAM lParam )
1588 HWND hwndCtrl = GetDlgItem( hwnd, id );
1589 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1594 /*******************************************************************
1595 * SetDlgItemTextA (USER32.@)
1597 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1599 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1603 /*******************************************************************
1604 * SetDlgItemTextW (USER32.@)
1606 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1608 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1612 /***********************************************************************
1613 * GetDlgItemTextA (USER32.@)
1615 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1617 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1622 /***********************************************************************
1623 * GetDlgItemTextW (USER32.@)
1625 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1627 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1632 /*******************************************************************
1633 * SetDlgItemInt (USER32.@)
1635 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1640 if (fSigned) sprintf( str, "%d", (INT)value );
1641 else sprintf( str, "%u", value );
1642 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1647 /***********************************************************************
1648 * GetDlgItemInt (USER32.@)
1650 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1657 if (translated) *translated = FALSE;
1658 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1662 result = strtol( str, &endptr, 10 );
1663 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1665 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1670 result = strtoul( str, &endptr, 10 );
1671 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1673 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1675 if (translated) *translated = TRUE;
1676 return (UINT)result;
1680 /***********************************************************************
1681 * CheckDlgButton (USER32.@)
1683 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1685 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1690 /***********************************************************************
1691 * IsDlgButtonChecked (USER32.@)
1693 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1695 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1699 /***********************************************************************
1702 * Callback function used to check/uncheck radio buttons that fall
1703 * within a specific range of IDs.
1705 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1707 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1708 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1710 if ((lChildID >= lpRadioGroup->firstID) &&
1711 (lChildID <= lpRadioGroup->lastID))
1713 if (lChildID == lpRadioGroup->checkID)
1715 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1719 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1727 /***********************************************************************
1728 * CheckRadioButton (USER32.@)
1730 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1731 UINT lastID, UINT checkID )
1733 RADIOGROUP radioGroup;
1735 /* perform bounds checking for a radio button group */
1736 radioGroup.firstID = min(min(firstID, lastID), checkID);
1737 radioGroup.lastID = max(max(firstID, lastID), checkID);
1738 radioGroup.checkID = checkID;
1740 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1741 (LPARAM)&radioGroup);
1745 /***********************************************************************
1746 * GetDialogBaseUnits (USER.243)
1747 * GetDialogBaseUnits (USER32.@)
1749 DWORD WINAPI GetDialogBaseUnits(void)
1751 return MAKELONG( xBaseUnit, yBaseUnit );
1755 /***********************************************************************
1756 * MapDialogRect (USER32.@)
1758 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1760 DIALOGINFO * dlgInfo;
1761 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return FALSE;
1762 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1763 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1764 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1765 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1770 /***********************************************************************
1771 * GetNextDlgGroupItem (USER32.@)
1773 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1775 HWND hwnd, retvalue;
1777 hwndDlg = WIN_GetFullHandle( hwndDlg );
1778 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1782 /* if the hwndCtrl is the child of the control in the hwndDlg,
1783 * then the hwndDlg has to be the parent of the hwndCtrl */
1784 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1785 hwndDlg = GetParent(hwndCtrl);
1790 /* Make sure hwndCtrl is a top-level child */
1791 HWND parent = GetParent( hwndCtrl );
1792 while (parent && parent != hwndDlg) parent = GetParent(parent);
1793 if (parent != hwndDlg) return 0;
1797 /* No ctrl specified -> start from the beginning */
1798 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1799 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
1802 retvalue = hwndCtrl;
1803 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
1806 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
1808 /* Wrap-around to the beginning of the group */
1811 hwnd = GetWindow( hwndDlg, GW_CHILD );
1812 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
1814 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
1815 if (tmp == hwndCtrl) break;
1818 if (hwnd == hwndCtrl) break;
1819 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1822 if (!fPrevious) break;
1824 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
1830 /***********************************************************************
1831 * DIALOG_GetNextTabItem
1833 * Helper for GetNextDlgTabItem
1835 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1839 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1841 HWND hChildFirst = 0;
1845 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1846 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1848 else if (IsChild( hwndMain, hwndCtrl ))
1850 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1853 if(GetParent(hwndCtrl) != hwndMain)
1854 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1858 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1860 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1870 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1871 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1872 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1877 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1879 hChildFirst = GetWindow(hChildFirst,wndSearch);
1884 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
1886 retWnd = hChildFirst;
1889 hChildFirst = GetWindow(hChildFirst,wndSearch);
1891 if(!retWnd && hwndCtrl)
1893 HWND hParent = GetParent(hwndCtrl);
1896 if(hParent == hwndMain) break;
1897 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1899 hParent = GetParent(hParent);
1902 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
1907 /***********************************************************************
1908 * GetNextDlgTabItem (USER32.@)
1910 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1913 hwndDlg = WIN_GetFullHandle( hwndDlg );
1914 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1915 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1918 /**********************************************************************
1919 * DIALOG_DlgDirSelect
1921 * Helper function for DlgDirSelect*
1923 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
1924 INT id, BOOL unicode, BOOL combo )
1929 HWND listbox = GetDlgItem( hwnd, id );
1931 TRACE("%04x '%s' %d\n", hwnd, str, id );
1932 if (!listbox) return FALSE;
1934 item = SendMessageA(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1935 if (item == LB_ERR) return FALSE;
1936 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1937 if (size == LB_ERR) return FALSE;
1939 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1941 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1943 if ((ret = (buffer[0] == '['))) /* drive or directory */
1945 if (buffer[1] == '-') /* drive */
1953 buffer[strlen(buffer)-1] = '\\';
1961 if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
1962 ((LPWSTR)str)[len-1] = 0;
1964 else lstrcpynA( str, ptr, len );
1965 HeapFree( GetProcessHeap(), 0, buffer );
1966 TRACE("Returning %d '%s'\n", ret, str );
1971 /**********************************************************************
1974 * Helper function for DlgDirList*
1976 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
1977 INT idStatic, UINT attrib, BOOL combo )
1980 LPSTR orig_spec = spec;
1982 #define SENDMSG(msg,wparam,lparam) \
1983 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1984 : SendMessageA( hwnd, msg, wparam, lparam ))
1986 TRACE("%04x '%s' %d %d %04x\n",
1987 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
1989 /* If the path exists and is a directory, chdir to it */
1990 if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
1995 if ((p2 = strrchr( p, '\\' ))) p = p2;
1996 if ((p2 = strrchr( p, '/' ))) p = p2;
2001 if (!SetCurrentDirectoryA( spec ))
2003 *p = sep; /* Restore the original spec */
2010 TRACE( "mask=%s\n", spec );
2012 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2014 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2015 if (attrib & DDL_DIRECTORY)
2017 if (!(attrib & DDL_EXCLUSIVE))
2019 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2020 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2021 (LPARAM)spec ) == LB_ERR)
2024 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2025 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2026 (LPARAM)"*.*" ) == LB_ERR)
2031 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2032 (LPARAM)spec ) == LB_ERR)
2037 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2039 char temp[MAX_PATH];
2040 GetCurrentDirectoryA( sizeof(temp), temp );
2042 /* Can't use PostMessage() here, because the string is on the stack */
2043 SetDlgItemTextA( hDlg, idStatic, temp );
2046 if (orig_spec && (spec != orig_spec))
2048 /* Update the original file spec */
2050 while ((*orig_spec++ = *p++));
2058 /**********************************************************************
2059 * DIALOG_DlgDirListW
2061 * Helper function for DlgDirList*W
2063 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2064 INT idStatic, UINT attrib, BOOL combo )
2068 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2069 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2071 MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
2072 HeapFree( GetProcessHeap(), 0, specA );
2075 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2079 /**********************************************************************
2080 * DlgDirSelectExA (USER32.@)
2082 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2084 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE );
2088 /**********************************************************************
2089 * DlgDirSelectExW (USER32.@)
2091 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2093 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, FALSE );
2097 /**********************************************************************
2098 * DlgDirSelectComboBoxExA (USER32.@)
2100 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2103 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, TRUE );
2107 /**********************************************************************
2108 * DlgDirSelectComboBoxExW (USER32.@)
2110 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2113 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE );
2117 /**********************************************************************
2118 * DlgDirListA (USER32.@)
2120 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2121 INT idStatic, UINT attrib )
2123 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2127 /**********************************************************************
2128 * DlgDirListW (USER32.@)
2130 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2131 INT idStatic, UINT attrib )
2133 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2137 /**********************************************************************
2138 * DlgDirListComboBoxA (USER32.@)
2140 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2141 INT idStatic, UINT attrib )
2143 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2147 /**********************************************************************
2148 * DlgDirListComboBoxW (USER32.@)
2150 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2151 INT idStatic, UINT attrib )
2153 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );