4 * Copyright 1993, 1994, 1996 Alexandre Julliard
23 #include "wine/winuser16.h"
24 #include "wine/winbase16.h"
25 #include "wine/unicode.h"
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(dialog);
35 /* Dialog control information */
72 /* Radio button group */
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 */
99 /***********************************************************************
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 */
109 hOwner = GetAncestor( hOwner, GA_ROOT );
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 */
125 hOwner = GetAncestor( hOwner, GA_ROOT );
126 if (!hOwner) return FALSE;
127 if (IsWindowEnabled( hOwner ))
129 EnableWindow( hOwner, 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;
150 pSize->cx = xBaseUnit;
151 pSize->cy = yBaseUnit;
154 /* select the font */
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)
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
175 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
178 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
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);
199 /***********************************************************************
202 * A convenient variant of DIALOG_GetCharSizeFromDC.
204 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
207 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
212 /***********************************************************************
215 * Initialisation of the dialog manager.
217 BOOL DIALOG_Init(void)
222 /* Calculate the dialog base units */
224 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
226 ERR("Could not create Display DC\n");
230 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size ))
233 ERR("Could not initialize base dialog units\n");
241 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
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];
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);
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;
286 int_id = ((BYTE)*p == 0xff);
289 /* Integer id, not documented (?). Only works for SS_ICON controls */
290 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
295 info->windowName = p;
299 if (*p) info->data = p + 1;
300 else info->data = NULL;
305 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %p\n",
306 info->className, LOWORD(info->windowName),
307 info->id, info->x, info->y, info->cx, info->cy,
308 info->style, info->data );
310 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %p\n",
311 info->className, info->windowName,
312 info->id, info->x, info->y, info->cx, info->cy,
313 info->style, info->data );
319 /***********************************************************************
320 * DIALOG_GetControl32
322 * Return the class and text of the control pointed to by ptr,
323 * fill the header structure and return a pointer to the next control.
325 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
330 info->helpId = GET_DWORD(p); p += 2;
331 info->exStyle = GET_DWORD(p); p += 2;
332 info->style = GET_DWORD(p); p += 2;
337 info->style = GET_DWORD(p); p += 2;
338 info->exStyle = GET_DWORD(p); p += 2;
340 info->x = GET_WORD(p); p++;
341 info->y = GET_WORD(p); p++;
342 info->cx = GET_WORD(p); p++;
343 info->cy = GET_WORD(p); p++;
347 /* id is a DWORD for DIALOGEX */
348 info->id = GET_DWORD(p);
353 info->id = GET_WORD(p);
357 if (GET_WORD(p) == 0xffff)
359 static const WCHAR class_names[6][10] =
361 { 'B','u','t','t','o','n', }, /* 0x80 */
362 { 'E','d','i','t', }, /* 0x81 */
363 { 'S','t','a','t','i','c', }, /* 0x82 */
364 { 'L','i','s','t','B','o','x', }, /* 0x83 */
365 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
366 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
368 WORD id = GET_WORD(p+1);
369 if ((id >= 0x80) && (id <= 0x85))
370 info->className = (LPCSTR)class_names[id - 0x80];
373 info->className = NULL;
374 ERR("Unknown built-in class id %04x\n", id );
380 info->className = (LPCSTR)p;
381 p += strlenW( (LPCWSTR)p ) + 1;
384 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
386 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
391 info->windowName = (LPCSTR)p;
392 p += strlenW( (LPCWSTR)p ) + 1;
395 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
396 debugstr_w( (LPCWSTR)info->className ),
397 debugres_w( (LPCWSTR)info->windowName ),
398 info->id, info->x, info->y, info->cx, info->cy,
399 info->style, info->exStyle, info->helpId );
403 if (TRACE_ON(dialog))
405 WORD i, count = GET_WORD(p) / sizeof(WORD);
408 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
413 p += GET_WORD(p) / sizeof(WORD);
415 else info->data = NULL;
418 /* Next control is on dword boundary */
419 return (const WORD *)((((int)p) + 3) & ~3);
423 /***********************************************************************
424 * DIALOG_CreateControls
426 * Create the control windows for a dialog.
428 static BOOL DIALOG_CreateControls( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
429 HINSTANCE hInst, BOOL win32 )
431 DIALOGINFO *dlgInfo = DIALOG_get_info( hwnd );
432 DLG_CONTROL_INFO info;
433 HWND hwndCtrl, hwndDefButton = 0;
434 INT items = dlgTemplate->nbItems;
441 HINSTANCE16 instance;
444 template = DIALOG_GetControl16( template, &info );
445 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
446 !(GetWindowLongW( hwnd, GWL_STYLE ) & DS_LOCALEDIT))
448 if (!dlgInfo->hDialogHeap)
450 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
451 if (!dlgInfo->hDialogHeap)
453 ERR("Insufficient memory to create heap for edit control\n" );
456 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
458 instance = dlgInfo->hDialogHeap;
460 else instance = (HINSTANCE16)hInst;
462 segptr = MapLS( info.data );
463 hwndCtrl = WIN_Handle32( CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
464 info.className, info.windowName,
465 info.style | WS_CHILD,
466 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
467 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
468 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
469 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
470 WIN_Handle16(hwnd), (HMENU16)info.id,
471 instance, (LPVOID)segptr ));
476 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
477 dlgTemplate->dialogEx );
479 if (info.style & WS_BORDER)
481 info.style &= ~WS_BORDER;
482 info.exStyle |= WS_EX_CLIENTEDGE;
484 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
485 (LPCWSTR)info.className,
486 (LPCWSTR)info.windowName,
487 info.style | WS_CHILD,
488 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
489 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
490 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
491 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
492 hwnd, (HMENU)info.id,
493 hInst, (LPVOID)info.data );
495 if (!hwndCtrl) return FALSE;
497 /* Send initialisation messages to the control */
498 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
499 (WPARAM)dlgInfo->hUserFont, 0 );
500 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
502 /* If there's already a default push-button, set it back */
503 /* to normal and use this one instead. */
505 SendMessageA( hwndDefButton, BM_SETSTYLE,
506 BS_PUSHBUTTON,FALSE );
507 hwndDefButton = hwndCtrl;
508 dlgInfo->idResult = GetWindowLongA( hwndCtrl, GWL_ID );
516 /***********************************************************************
517 * DIALOG_ParseTemplate16
519 * Fill a DLG_TEMPLATE structure from the dialog template, and return
520 * a pointer to the first control.
522 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
524 result->style = GET_DWORD(p); p += sizeof(DWORD);
526 result->nbItems = (unsigned char) *p++;
527 result->x = GET_WORD(p); p += sizeof(WORD);
528 result->y = GET_WORD(p); p += sizeof(WORD);
529 result->cx = GET_WORD(p); p += sizeof(WORD);
530 result->cy = GET_WORD(p); p += sizeof(WORD);
531 TRACE("DIALOG %d, %d, %d, %d\n",
532 result->x, result->y, result->cx, result->cy );
533 TRACE(" STYLE %08lx\n", result->style );
535 /* Get the menu name */
540 result->menuName = 0;
544 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
546 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
549 result->menuName = p;
550 TRACE(" MENU '%s'\n", p );
555 /* Get the class name */
559 result->className = p;
560 TRACE(" CLASS '%s'\n", result->className );
562 else result->className = DIALOG_CLASS_ATOM;
565 /* Get the window caption */
569 TRACE(" CAPTION '%s'\n", result->caption );
571 /* Get the font name */
573 if (result->style & DS_SETFONT)
575 result->pointSize = GET_WORD(p);
577 result->faceName = p;
579 TRACE(" FONT %d,'%s'\n",
580 result->pointSize, result->faceName );
586 /***********************************************************************
587 * DIALOG_ParseTemplate32
589 * Fill a DLG_TEMPLATE structure from the dialog template, and return
590 * a pointer to the first control.
592 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
594 const WORD *p = (const WORD *)template;
596 result->style = GET_DWORD(p); p += 2;
597 if (result->style == 0xffff0001) /* DIALOGEX resource */
599 result->dialogEx = TRUE;
600 result->helpId = GET_DWORD(p); p += 2;
601 result->exStyle = GET_DWORD(p); p += 2;
602 result->style = GET_DWORD(p); p += 2;
606 result->dialogEx = FALSE;
608 result->exStyle = GET_DWORD(p); p += 2;
610 result->nbItems = GET_WORD(p); p++;
611 result->x = GET_WORD(p); p++;
612 result->y = GET_WORD(p); p++;
613 result->cx = GET_WORD(p); p++;
614 result->cy = GET_WORD(p); p++;
615 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
616 result->dialogEx ? "EX" : "", result->x, result->y,
617 result->cx, result->cy, result->helpId );
618 TRACE(" STYLE 0x%08lx\n", result->style );
619 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
621 /* Get the menu name */
626 result->menuName = NULL;
630 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
632 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
635 result->menuName = (LPCSTR)p;
636 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
637 p += strlenW( (LPCWSTR)p ) + 1;
641 /* Get the class name */
646 result->className = DIALOG_CLASS_ATOM;
650 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
652 TRACE(" CLASS %04x\n", LOWORD(result->className) );
655 result->className = (LPCSTR)p;
656 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
657 p += strlenW( (LPCWSTR)p ) + 1;
661 /* Get the window caption */
663 result->caption = (LPCSTR)p;
664 p += strlenW( (LPCWSTR)p ) + 1;
665 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
667 /* Get the font name */
669 if (result->style & DS_SETFONT)
671 result->pointSize = GET_WORD(p);
673 if (result->dialogEx)
675 result->weight = GET_WORD(p); p++;
676 result->italic = LOBYTE(GET_WORD(p)); p++;
680 result->weight = FW_DONTCARE;
681 result->italic = FALSE;
683 result->faceName = (LPCSTR)p;
684 p += strlenW( (LPCWSTR)p ) + 1;
685 TRACE(" FONT %d, %s, %d, %s\n",
686 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
687 result->weight, result->italic ? "TRUE" : "FALSE" );
690 /* First control is on dword boundary */
691 return (LPCSTR)((((int)p) + 3) & ~3);
695 /***********************************************************************
696 * DIALOG_CreateIndirect
697 * Creates a dialog box window
699 * modal = TRUE if we are called from a modal dialog box.
700 * (it's more compatible to do it here, as under Windows the owner
701 * is never disabled if the dialog fails because of an invalid template)
703 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
704 HWND owner, DLGPROC dlgProc, LPARAM param,
705 WINDOWPROCTYPE procType, BOOL modal )
710 DLG_TEMPLATE template;
711 DIALOGINFO * dlgInfo;
712 BOOL ownerEnabled = TRUE;
713 BOOL win32Template = (procType != WIN_PROC_16);
715 /* Parse dialog template */
717 if (!dlgTemplate) return 0;
719 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
721 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
723 /* Initialise dialog extra data */
725 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
726 dlgInfo->hwndFocus = 0;
727 dlgInfo->hUserFont = 0;
729 dlgInfo->xBaseUnit = xBaseUnit;
730 dlgInfo->yBaseUnit = yBaseUnit;
731 dlgInfo->idResult = 0;
733 dlgInfo->hDialogHeap = 0;
737 if (template.menuName)
739 if (!win32Template) dlgInfo->hMenu = LoadMenu16( hInst, template.menuName );
740 else dlgInfo->hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
743 /* Create custom font if needed */
745 if (template.style & DS_SETFONT)
747 /* The font height must be negative as it is a point size */
748 /* and must be converted to pixels first */
749 /* (see CreateFont() documentation in the Windows SDK). */
752 if (((short)template.pointSize) < 0)
753 pixels = -((short)template.pointSize);
757 pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
761 dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
762 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
763 PROOF_QUALITY, FF_DONTCARE,
764 (LPCWSTR)template.faceName );
766 dlgInfo->hUserFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
767 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
768 PROOF_QUALITY, FF_DONTCARE, template.faceName );
769 if (dlgInfo->hUserFont)
772 if (DIALOG_GetCharSize( dlgInfo->hUserFont, &charSize ))
774 dlgInfo->xBaseUnit = charSize.cx;
775 dlgInfo->yBaseUnit = charSize.cy;
778 TRACE("units = %d,%d\n", dlgInfo->xBaseUnit, dlgInfo->yBaseUnit );
781 /* Create dialog main window */
783 rect.left = rect.top = 0;
784 rect.right = MulDiv(template.cx, dlgInfo->xBaseUnit, 4);
785 rect.bottom = MulDiv(template.cy, dlgInfo->yBaseUnit, 8);
786 if (template.style & DS_MODALFRAME)
787 template.exStyle |= WS_EX_DLGMODALFRAME;
788 AdjustWindowRectEx( &rect, template.style, (dlgInfo->hMenu != 0), template.exStyle );
789 rect.right -= rect.left;
790 rect.bottom -= rect.top;
792 if ((INT16)template.x == CW_USEDEFAULT16)
794 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
798 if (template.style & DS_CENTER)
800 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
801 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
805 rect.left += MulDiv(template.x, dlgInfo->xBaseUnit, 4);
806 rect.top += MulDiv(template.y, dlgInfo->yBaseUnit, 8);
808 if ( !(template.style & WS_CHILD) )
812 if( !(template.style & DS_ABSALIGN) )
813 ClientToScreen( owner, (POINT *)&rect );
815 /* try to fit it into the desktop */
817 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
818 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
819 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
820 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
821 if( rect.left < 0 ) rect.left = 0;
822 if( rect.top < 0 ) rect.top = 0;
828 ownerEnabled = DIALOG_DisableOwner( owner );
829 if (ownerEnabled) dlgInfo->flags |= DF_OWNERENABLED;
833 hwnd = WIN_Handle32( CreateWindowEx16(template.exStyle, template.className,
834 template.caption, template.style & ~WS_VISIBLE,
835 rect.left, rect.top, rect.right, rect.bottom,
836 WIN_Handle16(owner), dlgInfo->hMenu, hInst, NULL ));
838 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
839 (LPCWSTR)template.caption,
840 template.style & ~WS_VISIBLE,
841 rect.left, rect.top, rect.right, rect.bottom,
842 owner, dlgInfo->hMenu, hInst, NULL );
846 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
847 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
848 if (modal && (dlgInfo->flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
849 HeapFree( GetProcessHeap(), 0, dlgInfo );
852 wndPtr = WIN_GetPtr( hwnd );
853 wndPtr->flags |= WIN_ISDIALOG;
854 WIN_ReleasePtr( wndPtr );
856 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
857 SetWindowLongW( hwnd, DWL_WINE_DIALOGINFO, (LONG)dlgInfo );
860 case WIN_PROC_16: SetWindowLong16( WIN_Handle16(hwnd), DWL_DLGPROC, (LONG)dlgProc ); break;
861 case WIN_PROC_32A: SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
862 case WIN_PROC_32W: SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc ); break;
866 if (dlgInfo->hUserFont)
867 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
869 /* Create controls */
871 if (DIALOG_CreateControls( hwnd, dlgTemplate, &template,
872 hInst, win32Template ))
874 HWND hwndPreInitFocus;
876 /* Send initialisation messages and set focus */
878 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
880 hwndPreInitFocus = GetFocus();
881 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
883 /* check where the focus is again,
884 * some controls status might have changed in WM_INITDIALOG */
885 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
886 if( dlgInfo->hwndFocus )
887 SetFocus( dlgInfo->hwndFocus );
891 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
892 but the focus has not changed, set the focus where we expect it. */
893 if ((GetFocus() == hwndPreInitFocus) &&
894 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
896 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
897 if( dlgInfo->hwndFocus )
898 SetFocus( dlgInfo->hwndFocus );
902 if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
904 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
908 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
909 if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
914 /***********************************************************************
915 * CreateDialog (USER.89)
917 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
918 HWND16 owner, DLGPROC16 dlgProc )
920 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
924 /***********************************************************************
925 * CreateDialogParam (USER.241)
927 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
928 HWND16 owner, DLGPROC16 dlgProc,
936 TRACE("%04x,%s,%04x,%08lx,%ld\n",
937 hInst, debugres_a(dlgTemplate), owner, (DWORD)dlgProc, param );
939 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOGA ))) return 0;
940 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
941 if (!(data = LockResource16( hmem ))) hwnd = 0;
942 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
944 FreeResource16( hmem );
948 /***********************************************************************
949 * CreateDialogParamA (USER32.@)
951 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
952 HWND owner, DLGPROC dlgProc,
955 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
956 if (!hrsrc) return 0;
957 return CreateDialogIndirectParamA( hInst,
958 (LPVOID)LoadResource(hInst, hrsrc),
959 owner, dlgProc, param );
963 /***********************************************************************
964 * CreateDialogParamW (USER32.@)
966 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
967 HWND owner, DLGPROC dlgProc,
970 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
971 if (!hrsrc) return 0;
972 return CreateDialogIndirectParamW( hInst,
973 (LPVOID)LoadResource(hInst, hrsrc),
974 owner, dlgProc, param );
978 /***********************************************************************
979 * CreateDialogIndirect (USER.219)
981 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
982 HWND16 owner, DLGPROC16 dlgProc )
984 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
988 /***********************************************************************
989 * CreateDialogIndirectParam (USER.242)
990 * CreateDialogIndirectParam16 (USER32.@)
992 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
994 HWND16 owner, DLGPROC16 dlgProc,
997 return WIN_Handle16( DIALOG_CreateIndirect( hInst, dlgTemplate, WIN_Handle32(owner),
998 (DLGPROC)dlgProc, param, WIN_PROC_16, FALSE ));
1002 /***********************************************************************
1003 * CreateDialogIndirectParamA (USER32.@)
1005 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
1006 LPCVOID dlgTemplate,
1007 HWND owner, DLGPROC dlgProc,
1010 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32A, FALSE );
1013 /***********************************************************************
1014 * CreateDialogIndirectParamAorW (USER32.@)
1016 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
1017 LPCVOID dlgTemplate,
1018 HWND owner, DLGPROC dlgProc,
1020 { FIXME("assume WIN_PROC_32W\n");
1021 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1024 /***********************************************************************
1025 * CreateDialogIndirectParamW (USER32.@)
1027 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
1028 LPCVOID dlgTemplate,
1029 HWND owner, DLGPROC dlgProc,
1032 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner, dlgProc, param, WIN_PROC_32W, FALSE );
1036 /***********************************************************************
1037 * DIALOG_DoDialogBox
1039 static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
1041 DIALOGINFO * dlgInfo;
1044 HWND ownerMsg = GetAncestor( owner, GA_ROOT );
1046 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return -1;
1048 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
1050 ShowWindow( hwnd, SW_SHOW );
1053 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
1055 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
1057 /* No message present -> send ENTERIDLE and wait */
1058 SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
1059 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1062 else if (!GetMessageW( &msg, 0, 0, 0 )) break;
1064 if (CallMsgFilterW( &msg, MSGF_DIALOGBOX )) continue;
1066 if (!IsWindow( hwnd )) return -1;
1067 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
1069 TranslateMessage( &msg );
1070 DispatchMessageW( &msg );
1072 if (dlgInfo->flags & DF_END) break;
1075 if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
1076 retval = dlgInfo->idResult;
1077 DestroyWindow( hwnd );
1082 /***********************************************************************
1083 * DialogBox (USER.87)
1085 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
1086 HWND16 owner, DLGPROC16 dlgProc )
1088 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1092 /***********************************************************************
1093 * DialogBoxParam (USER.239)
1095 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, LPCSTR template,
1096 HWND16 owner16, DLGPROC16 dlgProc, LPARAM param )
1104 if (!(hRsrc = FindResource16( hInst, template, RT_DIALOGA ))) return 0;
1105 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
1106 if ((data = LockResource16( hmem )))
1108 HWND owner = WIN_Handle32(owner16);
1109 hwnd = DIALOG_CreateIndirect( hInst, data, owner,
1110 (DLGPROC)dlgProc, param, WIN_PROC_16, TRUE );
1111 if (hwnd) ret = DIALOG_DoDialogBox( hwnd, owner );
1112 GlobalUnlock16( hmem );
1114 FreeResource16( hmem );
1119 /***********************************************************************
1120 * DialogBoxParamA (USER32.@)
1122 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1123 HWND owner, DLGPROC dlgProc, LPARAM param )
1126 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
1127 if (!hrsrc) return 0;
1128 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1129 owner, dlgProc, param, WIN_PROC_32A, TRUE );
1130 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1135 /***********************************************************************
1136 * DialogBoxParamW (USER32.@)
1138 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1139 HWND owner, DLGPROC dlgProc, LPARAM param )
1142 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
1143 if (!hrsrc) return 0;
1144 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1145 owner, dlgProc, param, WIN_PROC_32W, TRUE );
1146 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1151 /***********************************************************************
1152 * DialogBoxIndirect (USER.218)
1154 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1155 HWND16 owner, DLGPROC16 dlgProc )
1157 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1161 /***********************************************************************
1162 * DialogBoxIndirectParam (USER.240)
1163 * DialogBoxIndirectParam16 (USER32.@)
1165 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1166 HWND16 owner16, DLGPROC16 dlgProc,
1169 HWND hwnd, owner = WIN_Handle32( owner16 );
1172 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1173 hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, (DLGPROC)dlgProc,
1174 param, WIN_PROC_16, TRUE );
1175 GlobalUnlock16( dlgTemplate );
1176 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1181 /***********************************************************************
1182 * DialogBoxIndirectParamA (USER32.@)
1184 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1185 HWND owner, DLGPROC dlgProc,
1188 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1189 dlgProc, param, WIN_PROC_32A, TRUE );
1190 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1195 /***********************************************************************
1196 * DialogBoxIndirectParamW (USER32.@)
1198 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1199 HWND owner, DLGPROC dlgProc,
1202 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, owner,
1203 dlgProc, param, WIN_PROC_32W, TRUE );
1204 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1208 /***********************************************************************
1209 * DialogBoxIndirectParamAorW (USER32.@)
1211 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1212 HWND owner, DLGPROC dlgProc,
1213 LPARAM param, DWORD x )
1216 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1217 hInstance, template, owner, dlgProc, param, x);
1218 hwnd = DIALOG_CreateIndirect( hInstance, template, owner, dlgProc, param, WIN_PROC_32W, TRUE );
1219 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1223 /***********************************************************************
1224 * EndDialog (USER32.@)
1226 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1228 BOOL wasEnabled = TRUE;
1229 DIALOGINFO * dlgInfo;
1232 TRACE("%04x %d\n", hwnd, retval );
1234 if (!(dlgInfo = DIALOG_get_info( hwnd )))
1236 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1239 dlgInfo->idResult = retval;
1240 dlgInfo->flags |= DF_END;
1241 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1243 if (wasEnabled && (owner = GetWindow( hwnd, GW_OWNER )))
1244 DIALOG_EnableOwner( owner );
1246 /* Windows sets the focus to the dialog itself in EndDialog */
1248 if (IsChild(hwnd, GetFocus()))
1251 /* Don't have to send a ShowWindow(SW_HIDE), just do
1252 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1254 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1255 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1257 /* unblock dialog loop */
1258 PostMessageA(hwnd, WM_NULL, 0, 0);
1263 /***********************************************************************
1264 * DIALOG_IsAccelerator
1266 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1268 HWND hwndControl = hwnd;
1275 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
1276 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
1278 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1279 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1280 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1282 /* find the accelerator key */
1283 LPWSTR p = buffer - 2;
1289 p = strchrW( p + 2, '&' );
1291 while (p != NULL && p[1] == '&');
1293 /* and check if it's the one we're looking for */
1294 MultiByteToWideChar(CP_ACP, 0, &a_char, 1, &w_char, 1);
1295 if (p != NULL && toupperW( p[1] ) == toupperW( w_char ) )
1297 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
1299 /* set focus to the control */
1300 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
1301 /* and bump it on to next */
1302 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1304 else if (dlgCode & DLGC_BUTTON)
1306 /* send BM_CLICK message to the control */
1307 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1312 hwndNext = GetWindow( hwndControl, GW_CHILD );
1316 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1318 while (!hwndNext && hwndControl)
1320 hwndControl = GetParent( hwndControl );
1321 if (hwndControl == hwndDlg)
1323 if(hwnd==hwndDlg) /* prevent endless loop */
1328 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1331 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1333 hwndControl = hwndNext;
1335 while (hwndControl && (hwndControl != hwnd));
1340 /***********************************************************************
1341 * DIALOG_FindMsgDestination
1343 * The messages that IsDialogMessage sends may not go to the dialog
1344 * calling IsDialogMessage if that dialog is a child, and it has the
1345 * DS_CONTROL style set.
1346 * We propagate up until we hit one that does not have DS_CONTROL, or
1347 * whose parent is not a dialog.
1349 * This is undocumented behaviour.
1351 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1353 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1356 HWND hParent = GetParent(hwndDlg);
1357 if (!hParent) break;
1359 pParent = WIN_FindWndPtr(hParent);
1360 if (!pParent) break;
1362 if (!(pParent->flags & WIN_ISDIALOG))
1364 WIN_ReleaseWndPtr(pParent);
1367 WIN_ReleaseWndPtr(pParent);
1375 /***********************************************************************
1376 * DIALOG_IsDialogMessage
1378 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1379 UINT message, WPARAM wParam,
1380 LPARAM lParam, BOOL *translate,
1381 BOOL *dispatch, INT dlgCode )
1383 *translate = *dispatch = FALSE;
1385 if (message == WM_PAINT)
1387 /* Apparently, we have to handle this one as well */
1392 /* Only the key messages get special processing */
1393 if ((message != WM_KEYDOWN) &&
1394 (message != WM_SYSKEYDOWN) &&
1395 (message != WM_SYSCHAR) &&
1396 (message != WM_CHAR))
1399 if (dlgCode & DLGC_WANTMESSAGE)
1401 *translate = *dispatch = TRUE;
1405 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1413 if (!(dlgCode & DLGC_WANTTAB))
1415 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1416 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1425 if (!(dlgCode & DLGC_WANTARROWS))
1427 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1429 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1430 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1436 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1437 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1442 DWORD dw = SendMessageW( hwndDlg, DM_GETDEFID, 0, 0 );
1443 if (HIWORD(dw) == DC_HASDEFID)
1445 SendMessageA( hwndDlg, WM_COMMAND,
1446 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1447 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1451 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1452 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1459 break; /* case WM_KEYDOWN */
1462 if (dlgCode & DLGC_WANTCHARS) break;
1466 if (DIALOG_IsAccelerator( WIN_GetFullHandle(hwnd), hwndDlg, wParam ))
1468 /* don't translate or dispatch */
1478 /* If we get here, the message has not been treated specially */
1479 /* and can be sent to its destination window. */
1485 /***********************************************************************
1486 * IsDialogMessage (USER.90)
1488 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1490 LPMSG16 msg = MapSL(msg16);
1491 BOOL ret, translate, dispatch;
1494 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1497 if ((msg->message == WM_KEYDOWN) ||
1498 (msg->message == WM_CHAR))
1500 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1502 ret = DIALOG_IsDialogMessage( WIN_Handle32(msg->hwnd), WIN_Handle32(hwndDlg),
1503 msg->message, msg->wParam, msg->lParam,
1504 &translate, &dispatch, dlgCode );
1505 if (translate) TranslateMessage16( msg );
1506 if (dispatch) DispatchMessage16( msg );
1511 /***********************************************************************
1512 * IsDialogMessage (USER32.@)
1513 * IsDialogMessageA (USER32.@)
1515 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1517 BOOL ret, translate, dispatch;
1520 hwndDlg = WIN_GetFullHandle( hwndDlg );
1521 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1524 if ((msg->message == WM_KEYDOWN) ||
1525 (msg->message == WM_CHAR))
1527 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1529 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1530 msg->wParam, msg->lParam,
1531 &translate, &dispatch, dlgCode );
1532 if (translate) TranslateMessage( msg );
1533 if (dispatch) DispatchMessageA( msg );
1538 /***********************************************************************
1539 * IsDialogMessageW (USER32.@)
1541 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1543 BOOL ret, translate, dispatch;
1546 hwndDlg = WIN_GetFullHandle( hwndDlg );
1547 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1550 if ((msg->message == WM_KEYDOWN) ||
1551 (msg->message == WM_CHAR))
1553 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1555 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1556 msg->wParam, msg->lParam,
1557 &translate, &dispatch, dlgCode );
1558 if (translate) TranslateMessage( msg );
1559 if (dispatch) DispatchMessageW( msg );
1564 /***********************************************************************
1565 * GetDlgCtrlID (USER32.@)
1567 INT WINAPI GetDlgCtrlID( HWND hwnd )
1569 return GetWindowLongW( hwnd, GWL_ID );
1573 /***********************************************************************
1574 * GetDlgItem (USER32.@)
1576 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1579 HWND *list = WIN_ListChildren( hwndDlg );
1582 if (!list) return 0;
1584 for (i = 0; list[i]; i++) if (GetWindowLongW( list[i], GWL_ID ) == id) break;
1586 HeapFree( GetProcessHeap(), 0, list );
1591 /*******************************************************************
1592 * SendDlgItemMessageA (USER32.@)
1594 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1595 WPARAM wParam, LPARAM lParam )
1597 HWND hwndCtrl = GetDlgItem( hwnd, id );
1598 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1603 /*******************************************************************
1604 * SendDlgItemMessageW (USER32.@)
1606 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1607 WPARAM wParam, LPARAM lParam )
1609 HWND hwndCtrl = GetDlgItem( hwnd, id );
1610 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1615 /*******************************************************************
1616 * SetDlgItemTextA (USER32.@)
1618 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1620 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1624 /*******************************************************************
1625 * SetDlgItemTextW (USER32.@)
1627 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1629 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1633 /***********************************************************************
1634 * GetDlgItemTextA (USER32.@)
1636 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1638 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1643 /***********************************************************************
1644 * GetDlgItemTextW (USER32.@)
1646 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1648 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1653 /*******************************************************************
1654 * SetDlgItemInt (USER32.@)
1656 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1661 if (fSigned) sprintf( str, "%d", (INT)value );
1662 else sprintf( str, "%u", value );
1663 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1668 /***********************************************************************
1669 * GetDlgItemInt (USER32.@)
1671 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1678 if (translated) *translated = FALSE;
1679 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1683 result = strtol( str, &endptr, 10 );
1684 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1686 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1691 result = strtoul( str, &endptr, 10 );
1692 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1694 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1696 if (translated) *translated = TRUE;
1697 return (UINT)result;
1701 /***********************************************************************
1702 * CheckDlgButton (USER32.@)
1704 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1706 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1711 /***********************************************************************
1712 * IsDlgButtonChecked (USER32.@)
1714 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1716 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1720 /***********************************************************************
1723 * Callback function used to check/uncheck radio buttons that fall
1724 * within a specific range of IDs.
1726 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1728 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1729 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1731 if ((lChildID >= lpRadioGroup->firstID) &&
1732 (lChildID <= lpRadioGroup->lastID))
1734 if (lChildID == lpRadioGroup->checkID)
1736 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1740 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1748 /***********************************************************************
1749 * CheckRadioButton (USER32.@)
1751 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1752 UINT lastID, UINT checkID )
1754 RADIOGROUP radioGroup;
1756 /* perform bounds checking for a radio button group */
1757 radioGroup.firstID = min(min(firstID, lastID), checkID);
1758 radioGroup.lastID = max(max(firstID, lastID), checkID);
1759 radioGroup.checkID = checkID;
1761 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1762 (LPARAM)&radioGroup);
1766 /***********************************************************************
1767 * GetDialogBaseUnits (USER.243)
1768 * GetDialogBaseUnits (USER32.@)
1770 DWORD WINAPI GetDialogBaseUnits(void)
1772 return MAKELONG( xBaseUnit, yBaseUnit );
1776 /***********************************************************************
1777 * MapDialogRect (USER32.@)
1779 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1781 DIALOGINFO * dlgInfo;
1782 if (!(dlgInfo = DIALOG_get_info( hwnd ))) return FALSE;
1783 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1784 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1785 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1786 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1791 /***********************************************************************
1792 * GetNextDlgGroupItem (USER32.@)
1794 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1796 HWND hwnd, retvalue;
1798 hwndDlg = WIN_GetFullHandle( hwndDlg );
1799 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1803 /* if the hwndCtrl is the child of the control in the hwndDlg,
1804 * then the hwndDlg has to be the parent of the hwndCtrl */
1805 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1806 hwndDlg = GetParent(hwndCtrl);
1811 /* Make sure hwndCtrl is a top-level child */
1812 HWND parent = GetParent( hwndCtrl );
1813 while (parent && parent != hwndDlg) parent = GetParent(parent);
1814 if (parent != hwndDlg) return 0;
1818 /* No ctrl specified -> start from the beginning */
1819 if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
1820 if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
1823 retvalue = hwndCtrl;
1824 hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
1827 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
1829 /* Wrap-around to the beginning of the group */
1832 hwnd = GetWindow( hwndDlg, GW_CHILD );
1833 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
1835 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
1836 if (tmp == hwndCtrl) break;
1839 if (hwnd == hwndCtrl) break;
1840 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1843 if (!fPrevious) break;
1845 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
1851 /***********************************************************************
1852 * DIALOG_GetNextTabItem
1854 * Helper for GetNextDlgTabItem
1856 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1860 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1862 HWND hChildFirst = 0;
1866 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1867 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1869 else if (IsChild( hwndMain, hwndCtrl ))
1871 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1874 if(GetParent(hwndCtrl) != hwndMain)
1875 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1879 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1881 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1891 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1892 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1893 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1898 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1900 hChildFirst = GetWindow(hChildFirst,wndSearch);
1905 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
1907 retWnd = hChildFirst;
1910 hChildFirst = GetWindow(hChildFirst,wndSearch);
1912 if(!retWnd && hwndCtrl)
1914 HWND hParent = GetParent(hwndCtrl);
1917 if(hParent == hwndMain) break;
1918 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1920 hParent = GetParent(hParent);
1923 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
1928 /***********************************************************************
1929 * GetNextDlgTabItem (USER32.@)
1931 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1934 hwndDlg = WIN_GetFullHandle( hwndDlg );
1935 hwndCtrl = WIN_GetFullHandle( hwndCtrl );
1936 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
1939 /**********************************************************************
1940 * DIALOG_DlgDirSelect
1942 * Helper function for DlgDirSelect*
1944 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
1945 INT id, BOOL unicode, BOOL combo )
1950 HWND listbox = GetDlgItem( hwnd, id );
1952 TRACE("%04x '%s' %d\n", hwnd, str, id );
1953 if (!listbox) return FALSE;
1955 item = SendMessageA(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1956 if (item == LB_ERR) return FALSE;
1957 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, 0, 0 );
1958 if (size == LB_ERR) return FALSE;
1960 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size+1 ))) return FALSE;
1962 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1964 if ((ret = (buffer[0] == '['))) /* drive or directory */
1966 if (buffer[1] == '-') /* drive */
1974 buffer[strlen(buffer)-1] = '\\';
1982 if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
1983 ((LPWSTR)str)[len-1] = 0;
1985 else lstrcpynA( str, ptr, len );
1986 HeapFree( GetProcessHeap(), 0, buffer );
1987 TRACE("Returning %d '%s'\n", ret, str );
1992 /**********************************************************************
1995 * Helper function for DlgDirList*
1997 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
1998 INT idStatic, UINT attrib, BOOL combo )
2001 LPSTR orig_spec = spec;
2003 #define SENDMSG(msg,wparam,lparam) \
2004 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2005 : SendMessageA( hwnd, msg, wparam, lparam ))
2007 TRACE("%04x '%s' %d %d %04x\n",
2008 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2010 /* If the path exists and is a directory, chdir to it */
2011 if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
2016 if ((p2 = strrchr( p, '\\' ))) p = p2;
2017 if ((p2 = strrchr( p, '/' ))) p = p2;
2022 if (!SetCurrentDirectoryA( spec ))
2024 *p = sep; /* Restore the original spec */
2031 TRACE( "mask=%s\n", spec );
2033 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2035 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2036 if (attrib & DDL_DIRECTORY)
2038 if (!(attrib & DDL_EXCLUSIVE))
2040 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2041 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2042 (LPARAM)spec ) == LB_ERR)
2045 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2046 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2047 (LPARAM)"*.*" ) == LB_ERR)
2052 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2053 (LPARAM)spec ) == LB_ERR)
2058 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2060 char temp[MAX_PATH];
2061 GetCurrentDirectoryA( sizeof(temp), temp );
2063 /* Can't use PostMessage() here, because the string is on the stack */
2064 SetDlgItemTextA( hDlg, idStatic, temp );
2067 if (orig_spec && (spec != orig_spec))
2069 /* Update the original file spec */
2071 while ((*orig_spec++ = *p++));
2079 /**********************************************************************
2080 * DIALOG_DlgDirListW
2082 * Helper function for DlgDirList*W
2084 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2085 INT idStatic, UINT attrib, BOOL combo )
2089 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2090 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2092 MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
2093 HeapFree( GetProcessHeap(), 0, specA );
2096 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2100 /**********************************************************************
2101 * DlgDirSelectExA (USER32.@)
2103 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2105 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE );
2109 /**********************************************************************
2110 * DlgDirSelectExW (USER32.@)
2112 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2114 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, FALSE );
2118 /**********************************************************************
2119 * DlgDirSelectComboBoxExA (USER32.@)
2121 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2124 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, TRUE );
2128 /**********************************************************************
2129 * DlgDirSelectComboBoxExW (USER32.@)
2131 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2134 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE );
2138 /**********************************************************************
2139 * DlgDirListA (USER32.@)
2141 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2142 INT idStatic, UINT attrib )
2144 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2148 /**********************************************************************
2149 * DlgDirListW (USER32.@)
2151 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2152 INT idStatic, UINT attrib )
2154 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2158 /**********************************************************************
2159 * DlgDirListComboBoxA (USER32.@)
2161 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2162 INT idStatic, UINT attrib )
2164 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2168 /**********************************************************************
2169 * DlgDirListComboBoxW (USER32.@)
2171 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2172 INT idStatic, UINT attrib )
2174 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );