4 * Copyright 1993, 1994, 1996 Alexandre Julliard
17 #include "wine/winuser16.h"
18 #include "wine/winbase16.h"
27 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(dialog);
32 /* Dialog control information */
69 /* Radio button group */
77 /* Dialog base units */
78 static WORD xBaseUnit = 0, yBaseUnit = 0;
80 /***********************************************************************
81 * DIALOG_GetCharSizeFromDC
84 * Calculates the *true* average size of English characters in the
85 * specified font as oppposed to the one returned by GetTextMetrics.
87 * Latest: the X font driver will now compute a proper average width
88 * so this code can be removed
90 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
94 pSize->cx = xBaseUnit;
95 pSize->cy = yBaseUnit;
100 memset(&tm,0,sizeof(tm));
101 if (hFont) hFontPrev = SelectFont(hDC,hFont);
102 if (GetTextMetricsA(hDC,&tm))
104 pSize->cx = tm.tmAveCharWidth;
105 pSize->cy = tm.tmHeight;
107 /* if variable width font */
108 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
111 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
113 /* Calculate a true average as opposed to the one returned
114 * by tmAveCharWidth. This works better when dealing with
115 * proportional spaced fonts and (more important) that's
116 * how Microsoft's dialog creation code calculates the size
119 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
122 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
130 /* Use the text metrics */
131 TRACE("Using tm: %ldx%ld (dlg: %dx%d) (%s)\n", tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
132 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
133 pSize->cx = tm.tmAveCharWidth;
134 pSize->cy = tm.tmHeight;
136 /* select the original font */
137 if (hFontPrev) SelectFont(hDC,hFontPrev);
142 /***********************************************************************
145 * A convenient variant of DIALOG_GetCharSizeFromDC.
147 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
150 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
155 /***********************************************************************
158 * Initialisation of the dialog manager.
160 BOOL DIALOG_Init(void)
165 /* Calculate the dialog base units */
167 if (!(hdc = CreateDC16( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
168 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size )) return FALSE;
173 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
178 /***********************************************************************
179 * DIALOG_GetControl16
181 * Return the class and text of the control pointed to by ptr,
182 * fill the header structure and return a pointer to the next control.
184 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
186 static char buffer[10];
189 info->x = GET_WORD(p); p += sizeof(WORD);
190 info->y = GET_WORD(p); p += sizeof(WORD);
191 info->cx = GET_WORD(p); p += sizeof(WORD);
192 info->cy = GET_WORD(p); p += sizeof(WORD);
193 info->id = GET_WORD(p); p += sizeof(WORD);
194 info->style = GET_DWORD(p); p += sizeof(DWORD);
201 case 0x80: strcpy( buffer, "BUTTON" ); break;
202 case 0x81: strcpy( buffer, "EDIT" ); break;
203 case 0x82: strcpy( buffer, "STATIC" ); break;
204 case 0x83: strcpy( buffer, "LISTBOX" ); break;
205 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
206 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
207 default: buffer[0] = '\0'; break;
209 info->className = buffer;
218 int_id = ((BYTE)*p == 0xff);
221 /* Integer id, not documented (?). Only works for SS_ICON controls */
222 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
227 info->windowName = p;
231 info->data = (LPVOID)(*p ? p + 1 : NULL); /* FIXME: should be a segptr */
235 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
236 info->className, LOWORD(info->windowName),
237 info->id, info->x, info->y, info->cx, info->cy,
238 info->style, (DWORD)info->data);
240 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
241 info->className, info->windowName,
242 info->id, info->x, info->y, info->cx, info->cy,
243 info->style, (DWORD)info->data);
249 /***********************************************************************
250 * DIALOG_GetControl32
252 * Return the class and text of the control pointed to by ptr,
253 * fill the header structure and return a pointer to the next control.
255 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
260 info->helpId = GET_DWORD(p); p += 2;
261 info->exStyle = GET_DWORD(p); p += 2;
262 info->style = GET_DWORD(p); p += 2;
267 info->style = GET_DWORD(p); p += 2;
268 info->exStyle = GET_DWORD(p); p += 2;
270 info->x = GET_WORD(p); p++;
271 info->y = GET_WORD(p); p++;
272 info->cx = GET_WORD(p); p++;
273 info->cy = GET_WORD(p); p++;
277 /* id is a DWORD for DIALOGEX */
278 info->id = GET_DWORD(p);
283 info->id = GET_WORD(p);
287 if (GET_WORD(p) == 0xffff)
289 static const WCHAR class_names[6][10] =
291 { 'B','u','t','t','o','n', }, /* 0x80 */
292 { 'E','d','i','t', }, /* 0x81 */
293 { 'S','t','a','t','i','c', }, /* 0x82 */
294 { 'L','i','s','t','B','o','x', }, /* 0x83 */
295 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
296 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
298 WORD id = GET_WORD(p+1);
299 if ((id >= 0x80) && (id <= 0x85))
300 info->className = (LPCSTR)class_names[id - 0x80];
303 info->className = NULL;
304 ERR("Unknown built-in class id %04x\n", id );
310 info->className = (LPCSTR)p;
311 p += lstrlenW( (LPCWSTR)p ) + 1;
314 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
316 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
321 info->windowName = (LPCSTR)p;
322 p += lstrlenW( (LPCWSTR)p ) + 1;
325 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
326 debugstr_w( (LPCWSTR)info->className ),
327 debugres_w( (LPCWSTR)info->windowName ),
328 info->id, info->x, info->y, info->cx, info->cy,
329 info->style, info->exStyle, info->helpId );
333 if (TRACE_ON(dialog))
335 WORD i, count = GET_WORD(p) / sizeof(WORD);
338 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
342 info->data = (LPVOID)(p + 1);
343 p += GET_WORD(p) / sizeof(WORD);
345 else info->data = NULL;
348 /* Next control is on dword boundary */
349 return (const WORD *)((((int)p) + 3) & ~3);
353 /***********************************************************************
354 * DIALOG_CreateControls
356 * Create the control windows for a dialog.
358 static BOOL DIALOG_CreateControls( WND *pWnd, LPCSTR template,
359 const DLG_TEMPLATE *dlgTemplate,
360 HINSTANCE hInst, BOOL win32 )
362 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
363 DLG_CONTROL_INFO info;
364 HWND hwndCtrl, hwndDefButton = 0;
365 INT items = dlgTemplate->nbItems;
372 HINSTANCE16 instance;
373 template = DIALOG_GetControl16( template, &info );
374 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
375 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
377 if (!dlgInfo->hDialogHeap)
379 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
380 if (!dlgInfo->hDialogHeap)
382 ERR("Insufficient memory to create heap for edit control\n" );
385 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
387 instance = dlgInfo->hDialogHeap;
389 else instance = (HINSTANCE16)hInst;
391 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
392 info.className, info.windowName,
393 info.style | WS_CHILD,
394 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
395 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
396 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
397 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
398 pWnd->hwndSelf, (HMENU16)info.id,
399 instance, info.data );
403 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
404 dlgTemplate->dialogEx );
405 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
406 (LPCWSTR)info.className,
407 (LPCWSTR)info.windowName,
408 info.style | WS_CHILD,
409 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
410 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
411 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
412 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
413 pWnd->hwndSelf, (HMENU)info.id,
416 if (!hwndCtrl) return FALSE;
418 /* Send initialisation messages to the control */
419 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
420 (WPARAM)dlgInfo->hUserFont, 0 );
421 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
423 /* If there's already a default push-button, set it back */
424 /* to normal and use this one instead. */
426 SendMessageA( hwndDefButton, BM_SETSTYLE,
427 BS_PUSHBUTTON,FALSE );
428 hwndDefButton = hwndCtrl;
429 dlgInfo->idResult = GetWindowWord( hwndCtrl, GWW_ID );
437 /***********************************************************************
438 * DIALOG_ParseTemplate16
440 * Fill a DLG_TEMPLATE structure from the dialog template, and return
441 * a pointer to the first control.
443 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
445 result->style = GET_DWORD(p); p += sizeof(DWORD);
447 result->nbItems = (unsigned char) *p++;
448 result->x = GET_WORD(p); p += sizeof(WORD);
449 result->y = GET_WORD(p); p += sizeof(WORD);
450 result->cx = GET_WORD(p); p += sizeof(WORD);
451 result->cy = GET_WORD(p); p += sizeof(WORD);
452 TRACE("DIALOG %d, %d, %d, %d\n",
453 result->x, result->y, result->cx, result->cy );
454 TRACE(" STYLE %08lx\n", result->style );
456 /* Get the menu name */
461 result->menuName = 0;
465 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
467 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
470 result->menuName = p;
471 TRACE(" MENU '%s'\n", p );
476 /* Get the class name */
480 result->className = p;
481 TRACE(" CLASS '%s'\n", result->className );
483 else result->className = DIALOG_CLASS_ATOM;
486 /* Get the window caption */
490 TRACE(" CAPTION '%s'\n", result->caption );
492 /* Get the font name */
494 if (result->style & DS_SETFONT)
496 result->pointSize = GET_WORD(p);
498 result->faceName = p;
500 TRACE(" FONT %d,'%s'\n",
501 result->pointSize, result->faceName );
507 /***********************************************************************
508 * DIALOG_ParseTemplate32
510 * Fill a DLG_TEMPLATE structure from the dialog template, and return
511 * a pointer to the first control.
513 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
515 const WORD *p = (const WORD *)template;
517 result->style = GET_DWORD(p); p += 2;
518 if (result->style == 0xffff0001) /* DIALOGEX resource */
520 result->dialogEx = TRUE;
521 result->helpId = GET_DWORD(p); p += 2;
522 result->exStyle = GET_DWORD(p); p += 2;
523 result->style = GET_DWORD(p); p += 2;
527 result->dialogEx = FALSE;
529 result->exStyle = GET_DWORD(p); p += 2;
531 result->nbItems = GET_WORD(p); p++;
532 result->x = GET_WORD(p); p++;
533 result->y = GET_WORD(p); p++;
534 result->cx = GET_WORD(p); p++;
535 result->cy = GET_WORD(p); p++;
536 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
537 result->dialogEx ? "EX" : "", result->x, result->y,
538 result->cx, result->cy, result->helpId );
539 TRACE(" STYLE 0x%08lx\n", result->style );
540 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
542 /* Get the menu name */
547 result->menuName = NULL;
551 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
553 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
556 result->menuName = (LPCSTR)p;
557 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
558 p += lstrlenW( (LPCWSTR)p ) + 1;
562 /* Get the class name */
567 result->className = DIALOG_CLASS_ATOM;
571 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
573 TRACE(" CLASS %04x\n", LOWORD(result->className) );
576 result->className = (LPCSTR)p;
577 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
578 p += lstrlenW( (LPCWSTR)p ) + 1;
582 /* Get the window caption */
584 result->caption = (LPCSTR)p;
585 p += lstrlenW( (LPCWSTR)p ) + 1;
586 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
588 /* Get the font name */
590 if (result->style & DS_SETFONT)
592 result->pointSize = GET_WORD(p);
594 if (result->dialogEx)
596 result->weight = GET_WORD(p); p++;
597 result->italic = LOBYTE(GET_WORD(p)); p++;
601 result->weight = FW_DONTCARE;
602 result->italic = FALSE;
604 result->faceName = (LPCSTR)p;
605 p += lstrlenW( (LPCWSTR)p ) + 1;
606 TRACE(" FONT %d, %s, %d, %s\n",
607 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
608 result->weight, result->italic ? "TRUE" : "FALSE" );
611 /* First control is on dword boundary */
612 return (LPCSTR)((((int)p) + 3) & ~3);
616 /***********************************************************************
617 * DIALOG_CreateIndirect
619 HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
620 BOOL win32Template, HWND owner,
621 DLGPROC16 dlgProc, LPARAM param,
622 WINDOWPROCTYPE procType )
629 DLG_TEMPLATE template;
630 DIALOGINFO * dlgInfo;
631 WORD xUnit = xBaseUnit;
632 WORD yUnit = yBaseUnit;
634 /* Parse dialog template */
636 if (!dlgTemplate) return 0;
638 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
640 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
644 if (template.menuName)
648 LPSTR str = SEGPTR_STRDUP( template.menuName );
649 hMenu = LoadMenu16( hInst, SEGPTR_GET(str) );
652 else hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
655 /* Create custom font if needed */
657 if (template.style & DS_SETFONT)
659 /* The font height must be negative as it is a point size */
660 /* and must be converted to pixels first */
661 /* (see CreateFont() documentation in the Windows SDK). */
663 int pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
667 hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
668 template.italic, FALSE, FALSE,
669 DEFAULT_CHARSET, 0, 0,
670 PROOF_QUALITY, FF_DONTCARE,
671 (LPCWSTR)template.faceName );
673 hFont = CreateFont16( -pixels, 0, 0, 0, FW_DONTCARE,
675 DEFAULT_CHARSET, 0, 0,
676 PROOF_QUALITY, FF_DONTCARE,
681 DIALOG_GetCharSize(hFont,&charSize);
685 TRACE("units = %d,%d\n", xUnit, yUnit );
688 /* Create dialog main window */
690 rect.left = rect.top = 0;
691 rect.right = MulDiv(template.cx, xUnit, 4);
692 rect.bottom = MulDiv(template.cy, yUnit, 8);
693 if (template.style & DS_MODALFRAME)
694 template.exStyle |= WS_EX_DLGMODALFRAME;
695 AdjustWindowRectEx( &rect, template.style,
696 hMenu ? TRUE : FALSE , template.exStyle );
697 rect.right -= rect.left;
698 rect.bottom -= rect.top;
700 if ((INT16)template.x == CW_USEDEFAULT16)
702 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
706 if (template.style & DS_CENTER)
708 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
709 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
713 rect.left += MulDiv(template.x, xUnit, 4);
714 rect.top += MulDiv(template.y, yUnit, 8);
716 if ( !(template.style & WS_CHILD) )
720 if( !(template.style & DS_ABSALIGN) )
721 ClientToScreen( owner, (POINT *)&rect );
723 /* try to fit it into the desktop */
725 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
726 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
727 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
728 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
729 if( rect.left < 0 ) rect.left = 0;
730 if( rect.top < 0 ) rect.top = 0;
735 hwnd = CreateWindowEx16(template.exStyle, template.className,
736 template.caption, template.style & ~WS_VISIBLE,
737 rect.left, rect.top, rect.right, rect.bottom,
738 owner, hMenu, hInst, NULL );
740 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
741 (LPCWSTR)template.caption,
742 template.style & ~WS_VISIBLE,
743 rect.left, rect.top, rect.right, rect.bottom,
744 owner, hMenu, hInst, NULL );
748 if (hFont) DeleteObject( hFont );
749 if (hMenu) DestroyMenu( hMenu );
752 wndPtr = WIN_FindWndPtr( hwnd );
753 wndPtr->flags |= WIN_ISDIALOG;
754 wndPtr->helpContext = template.helpId;
756 /* Initialise dialog extra data */
758 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
759 WINPROC_SetProc( &dlgInfo->dlgProc, (WNDPROC16)dlgProc, procType, WIN_PROC_WINDOW );
760 dlgInfo->hUserFont = hFont;
761 dlgInfo->hMenu = hMenu;
762 dlgInfo->xBaseUnit = xUnit;
763 dlgInfo->yBaseUnit = yUnit;
764 dlgInfo->msgResult = 0;
765 dlgInfo->idResult = 0;
767 dlgInfo->hDialogHeap = 0;
769 if (dlgInfo->hUserFont)
770 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
772 /* Create controls */
774 if (DIALOG_CreateControls( wndPtr, dlgTemplate, &template,
775 hInst, win32Template ))
777 HWND hwndPreInitFocus;
779 /* Send initialisation messages and set focus */
781 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
783 hwndPreInitFocus = GetFocus();
784 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
785 SetFocus( dlgInfo->hwndFocus );
788 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
789 but the focus has not changed, set the focus where we expect it. */
790 if ( GetFocus() == hwndPreInitFocus )
791 SetFocus( dlgInfo->hwndFocus );
794 if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE))
796 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
797 UpdateWindow( hwnd );
799 WIN_ReleaseWndPtr(wndPtr);
802 WIN_ReleaseWndPtr(wndPtr);
803 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
808 /***********************************************************************
809 * CreateDialog16 (USER.89)
811 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
812 HWND16 owner, DLGPROC16 dlgProc )
814 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
818 /***********************************************************************
819 * CreateDialogParam16 (USER.241)
821 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
822 HWND16 owner, DLGPROC16 dlgProc,
830 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
831 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
833 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOG16 ))) return 0;
834 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
835 if (!(data = LockResource16( hmem ))) hwnd = 0;
836 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
838 FreeResource16( hmem );
842 /***********************************************************************
843 * CreateDialogParam32A (USER32.73)
845 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
846 HWND owner, DLGPROC dlgProc,
849 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
850 if (!hrsrc) return 0;
851 return CreateDialogIndirectParamA( hInst,
852 (LPVOID)LoadResource(hInst, hrsrc),
853 owner, dlgProc, param );
857 /***********************************************************************
858 * CreateDialogParam32W (USER32.74)
860 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
861 HWND owner, DLGPROC dlgProc,
864 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
865 if (!hrsrc) return 0;
866 return CreateDialogIndirectParamW( hInst,
867 (LPVOID)LoadResource(hInst, hrsrc),
868 owner, dlgProc, param );
872 /***********************************************************************
873 * CreateDialogIndirect16 (USER.219)
875 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
876 HWND16 owner, DLGPROC16 dlgProc )
878 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
882 /***********************************************************************
883 * CreateDialogIndirectParam16 (USER.242)
885 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
887 HWND16 owner, DLGPROC16 dlgProc,
890 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
891 dlgProc, param, WIN_PROC_16 );
895 /***********************************************************************
896 * CreateDialogIndirectParam32A (USER32.69)
898 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
900 HWND owner, DLGPROC dlgProc,
903 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
904 (DLGPROC16)dlgProc, param, WIN_PROC_32A );
907 /***********************************************************************
908 * CreateDialogIndirectParam32AorW (USER32.71)
910 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
912 HWND owner, DLGPROC dlgProc,
914 { FIXME("assume WIN_PROC_32W\n");
915 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
916 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
919 /***********************************************************************
920 * CreateDialogIndirectParam32W (USER32.72)
922 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
924 HWND owner, DLGPROC dlgProc,
927 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
928 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
932 /***********************************************************************
935 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
938 DIALOGINFO * dlgInfo;
942 /* Owner must be a top-level window */
943 owner = WIN_GetTopParent( owner );
944 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
945 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
947 if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */
949 EnableWindow( owner, FALSE );
950 ShowWindow( hwnd, SW_SHOW );
951 while (MSG_InternalGetMessage(QMSG_WIN32A, &msg, hwnd, owner, MSGF_DIALOGBOX,
952 PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
954 if (!IsDialogMessageA( hwnd, &msg))
956 TranslateMessage( &msg );
957 DispatchMessageA( &msg );
959 if (dlgInfo->flags & DF_END) break;
961 EnableWindow( owner, TRUE );
963 retval = dlgInfo->idResult;
964 WIN_ReleaseWndPtr(wndPtr);
965 DestroyWindow( hwnd );
970 /***********************************************************************
971 * DialogBox16 (USER.87)
973 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
974 HWND16 owner, DLGPROC16 dlgProc )
976 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
980 /***********************************************************************
981 * DialogBoxParam16 (USER.239)
983 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
984 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
986 HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
987 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
992 /***********************************************************************
993 * DialogBoxParam32A (USER32.139)
995 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
996 HWND owner, DLGPROC dlgProc, LPARAM param )
998 HWND hwnd = CreateDialogParamA( hInst, name, owner, dlgProc, param );
999 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1004 /***********************************************************************
1005 * DialogBoxParam32W (USER32.140)
1007 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1008 HWND owner, DLGPROC dlgProc, LPARAM param )
1010 HWND hwnd = CreateDialogParamW( hInst, name, owner, dlgProc, param );
1011 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1016 /***********************************************************************
1017 * DialogBoxIndirect16 (USER.218)
1019 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1020 HWND16 owner, DLGPROC16 dlgProc )
1022 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1026 /***********************************************************************
1027 * DialogBoxIndirectParam16 (USER.240)
1029 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1030 HWND16 owner, DLGPROC16 dlgProc,
1036 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1037 hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param );
1038 GlobalUnlock16( dlgTemplate );
1039 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
1044 /***********************************************************************
1045 * DialogBoxIndirectParam32A (USER32.136)
1047 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1048 HWND owner, DLGPROC dlgProc,
1051 HWND hwnd = CreateDialogIndirectParamA( hInstance, template,
1052 owner, dlgProc, param );
1053 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1058 /***********************************************************************
1059 * DialogBoxIndirectParam32W (USER32.138)
1061 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1062 HWND owner, DLGPROC dlgProc,
1065 HWND hwnd = CreateDialogIndirectParamW( hInstance, template,
1066 owner, dlgProc, param );
1067 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1071 /***********************************************************************
1072 * DialogBoxIndirectParamAorW (USER32.138)
1074 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1075 HWND owner, DLGPROC dlgProc,
1076 LPARAM param, DWORD x )
1079 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1080 hInstance, template, owner, dlgProc, param, x);
1081 hwnd = CreateDialogIndirectParamW( hInstance, template,
1082 owner, dlgProc, param );
1083 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1087 /***********************************************************************
1088 * EndDialog16 (USER.88)
1090 BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
1092 return EndDialog( hwnd, retval );
1096 /***********************************************************************
1097 * EndDialog32 (USER32.173)
1099 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1101 WND * wndPtr = WIN_FindWndPtr( hwnd );
1102 DIALOGINFO * dlgInfo;
1105 TRACE("%04x %d\n", hwnd, retval );
1109 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1110 return TRUE; /* the sun is shining even for buggy apps */
1113 if ((dlgInfo = (DIALOGINFO *)wndPtr->wExtra))
1115 dlgInfo->idResult = retval;
1116 dlgInfo->flags |= DF_END;
1120 hOwner = WIN_GetTopParent( wndPtr->owner->hwndSelf );
1122 /* Enable the owner first */
1123 if (hOwner && !IsWindowEnabled(hOwner))
1124 EnableWindow( hOwner, TRUE );
1126 /* Windows sets the focus to the dialog itself in EndDialog */
1128 if (IsChild(hwnd, GetFocus()))
1129 SetFocus(wndPtr->hwndSelf);
1131 /* Don't have to send a ShowWindow(SW_HIDE), just do
1132 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1134 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1135 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1137 WIN_ReleaseWndPtr(wndPtr);
1143 /***********************************************************************
1144 * DIALOG_IsAccelerator
1146 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1148 HWND hwndControl = hwnd;
1151 BOOL RetVal = FALSE;
1156 wndPtr = WIN_FindWndPtr( hwndControl );
1157 if ( (wndPtr != NULL) &&
1158 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
1160 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1161 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1162 (wndPtr->text!=NULL))
1164 /* find the accelerator key */
1165 LPSTR p = wndPtr->text - 2;
1168 p = strchr( p + 2, '&' );
1170 while (p != NULL && p[1] == '&');
1172 /* and check if it's the one we're looking for */
1173 if (p != NULL && toupper( p[1] ) == toupper( vKey ) )
1175 if ((dlgCode & DLGC_STATIC) ||
1176 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
1178 /* set focus to the control */
1179 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1181 /* and bump it on to next */
1182 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1184 else if (dlgCode & DLGC_BUTTON)
1186 /* send BM_CLICK message to the control */
1187 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1191 WIN_ReleaseWndPtr(wndPtr);
1195 hwndNext = GetWindow( hwndControl, GW_CHILD );
1201 WIN_ReleaseWndPtr(wndPtr);
1204 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1206 while (!hwndNext && hwndControl)
1208 hwndControl = GetParent( hwndControl );
1209 if (hwndControl == hwndDlg)
1211 if(hwnd==hwndDlg){ /* prevent endless loop */
1215 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1219 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1222 hwndControl = hwndNext;
1224 while (hwndControl && (hwndControl != hwnd));
1230 /***********************************************************************
1231 * DIALOG_IsDialogMessage
1233 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1234 UINT message, WPARAM wParam,
1235 LPARAM lParam, BOOL *translate,
1236 BOOL *dispatch, INT dlgCode )
1238 *translate = *dispatch = FALSE;
1240 if (message == WM_PAINT)
1242 /* Apparently, we have to handle this one as well */
1247 /* Only the key messages get special processing */
1248 if ((message != WM_KEYDOWN) &&
1249 (message != WM_SYSCHAR) &&
1250 (message != WM_CHAR))
1253 if (dlgCode & DLGC_WANTMESSAGE)
1255 *translate = *dispatch = TRUE;
1265 if (!(dlgCode & DLGC_WANTTAB))
1267 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1268 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1277 if (!(dlgCode & DLGC_WANTARROWS))
1279 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1281 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1282 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
1288 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1289 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1294 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
1295 if (HIWORD(dw) == DC_HASDEFID)
1297 SendMessageA( hwndDlg, WM_COMMAND,
1298 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1299 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1303 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1304 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1311 break; /* case WM_KEYDOWN */
1314 if (dlgCode & DLGC_WANTCHARS) break;
1318 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
1320 /* don't translate or dispatch */
1326 /* If we get here, the message has not been treated specially */
1327 /* and can be sent to its destination window. */
1333 /***********************************************************************
1334 * IsDialogMessage16 (USER.90)
1336 BOOL16 WINAPI WIN16_IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1338 LPMSG16 msg = PTR_SEG_TO_LIN(msg16);
1339 BOOL ret, translate, dispatch;
1342 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1345 if ((msg->message == WM_KEYDOWN) ||
1346 (msg->message == WM_SYSCHAR) ||
1347 (msg->message == WM_CHAR))
1349 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1351 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1352 msg->wParam, msg->lParam,
1353 &translate, &dispatch, dlgCode );
1354 if (translate) TranslateMessage16( msg );
1355 if (dispatch) DispatchMessage16( msg );
1360 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
1362 LPMSG16 msg16 = SEGPTR_NEW(MSG16);
1366 ret = WIN16_IsDialogMessage16( hwndDlg, SEGPTR_GET(msg16) );
1371 /***********************************************************************
1372 * IsDialogMessage32A (USER32.342)
1374 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1376 BOOL ret, translate, dispatch;
1379 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1382 if ((msg->message == WM_KEYDOWN) ||
1383 (msg->message == WM_SYSCHAR) ||
1384 (msg->message == WM_CHAR))
1386 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1388 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1389 msg->wParam, msg->lParam,
1390 &translate, &dispatch, dlgCode );
1391 if (translate) TranslateMessage( msg );
1392 if (dispatch) DispatchMessageA( msg );
1397 /***********************************************************************
1398 * IsDialogMessage32W (USER32.343)
1400 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1402 BOOL ret, translate, dispatch;
1405 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1408 if ((msg->message == WM_KEYDOWN) ||
1409 (msg->message == WM_SYSCHAR) ||
1410 (msg->message == WM_CHAR))
1412 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1414 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1415 msg->wParam, msg->lParam,
1416 &translate, &dispatch, dlgCode );
1417 if (translate) TranslateMessage( msg );
1418 if (dispatch) DispatchMessageW( msg );
1423 /****************************************************************
1424 * GetDlgCtrlID16 (USER.277)
1426 INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
1428 WND *wndPtr = WIN_FindWndPtr(hwnd);
1431 if (!wndPtr) return 0;
1433 retvalue = wndPtr->wIDmenu;
1434 WIN_ReleaseWndPtr(wndPtr);
1439 /****************************************************************
1440 * GetDlgCtrlID32 (USER32.234)
1442 INT WINAPI GetDlgCtrlID( HWND hwnd )
1445 WND *wndPtr = WIN_FindWndPtr(hwnd);
1446 if (!wndPtr) return 0;
1447 retvalue = wndPtr->wIDmenu;
1448 WIN_ReleaseWndPtr(wndPtr);
1453 /***********************************************************************
1454 * GetDlgItem16 (USER.91)
1456 HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
1460 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1461 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1462 if (pWnd->wIDmenu == (UINT16)id)
1464 HWND16 retvalue = pWnd->hwndSelf;
1465 WIN_ReleaseWndPtr(pWnd);
1472 /***********************************************************************
1473 * GetDlgItem32 (USER32.235)
1475 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1479 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1480 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1481 if (pWnd->wIDmenu == (UINT16)id)
1483 HWND retvalue = pWnd->hwndSelf;
1484 WIN_ReleaseWndPtr(pWnd);
1491 /*******************************************************************
1492 * SendDlgItemMessage16 (USER.101)
1494 LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1495 WPARAM16 wParam, LPARAM lParam )
1497 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
1498 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1503 /*******************************************************************
1504 * SendDlgItemMessage32A (USER32.452)
1506 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1507 WPARAM wParam, LPARAM lParam )
1509 HWND hwndCtrl = GetDlgItem( hwnd, id );
1510 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1515 /*******************************************************************
1516 * SendDlgItemMessage32W (USER32.453)
1518 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1519 WPARAM wParam, LPARAM lParam )
1521 HWND hwndCtrl = GetDlgItem( hwnd, id );
1522 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1527 /*******************************************************************
1528 * SetDlgItemText16 (USER.92)
1530 void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1532 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1536 /*******************************************************************
1537 * SetDlgItemText32A (USER32.478)
1539 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1541 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1545 /*******************************************************************
1546 * SetDlgItemText32W (USER32.479)
1548 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1550 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1554 /***********************************************************************
1555 * GetDlgItemText16 (USER.93)
1557 INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1559 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1564 /***********************************************************************
1565 * GetDlgItemText32A (USER32.237)
1567 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1569 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1574 /***********************************************************************
1575 * GetDlgItemText32W (USER32.238)
1577 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1579 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1584 /*******************************************************************
1585 * SetDlgItemInt16 (USER.94)
1587 void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1589 SetDlgItemInt( hwnd, (UINT)(UINT16)id, value, fSigned );
1593 /*******************************************************************
1594 * SetDlgItemInt32 (USER32.477)
1596 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1601 if (fSigned) sprintf( str, "%d", (INT)value );
1602 else sprintf( str, "%u", value );
1603 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1608 /***********************************************************************
1609 * GetDlgItemInt16 (USER.95)
1611 UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1617 if (translated) *translated = FALSE;
1618 result = GetDlgItemInt( hwnd, (UINT)(UINT16)id, &ok, fSigned );
1622 if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
1626 if (result > 65535) return 0;
1628 if (translated) *translated = TRUE;
1629 return (UINT16)result;
1633 /***********************************************************************
1634 * GetDlgItemInt32 (USER32.236)
1636 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1643 if (translated) *translated = FALSE;
1644 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1648 result = strtol( str, &endptr, 10 );
1649 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1651 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1656 result = strtoul( str, &endptr, 10 );
1657 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1659 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1661 if (translated) *translated = TRUE;
1662 return (UINT)result;
1666 /***********************************************************************
1667 * CheckDlgButton16 (USER.97)
1669 BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
1671 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1676 /***********************************************************************
1677 * CheckDlgButton32 (USER32.45)
1679 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1681 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1686 /***********************************************************************
1687 * IsDlgButtonChecked16 (USER.98)
1689 UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
1691 return (UINT16)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1695 /***********************************************************************
1696 * IsDlgButtonChecked32 (USER32.344)
1698 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1700 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1704 /***********************************************************************
1705 * CheckRadioButton16 (USER.96)
1707 BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
1708 UINT16 lastID, UINT16 checkID )
1710 return CheckRadioButton( hwndDlg, firstID, lastID, checkID );
1714 /***********************************************************************
1717 * Callback function used to check/uncheck radio buttons that fall
1718 * within a specific range of IDs.
1720 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1722 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1723 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1725 if ((lChildID >= lpRadioGroup->firstID) &&
1726 (lChildID <= lpRadioGroup->lastID))
1728 if (lChildID == lpRadioGroup->checkID)
1730 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1734 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1742 /***********************************************************************
1743 * CheckRadioButton32 (USER32.48)
1745 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1746 UINT lastID, UINT checkID )
1748 RADIOGROUP radioGroup;
1750 /* perform bounds checking for a radio button group */
1751 radioGroup.firstID = min(min(firstID, lastID), checkID);
1752 radioGroup.lastID = max(max(firstID, lastID), checkID);
1753 radioGroup.checkID = checkID;
1755 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1756 (LPARAM)&radioGroup);
1760 /***********************************************************************
1761 * GetDialogBaseUnits (USER.243) (USER32.233)
1763 DWORD WINAPI GetDialogBaseUnits(void)
1765 return MAKELONG( xBaseUnit, yBaseUnit );
1769 /***********************************************************************
1770 * MapDialogRect16 (USER.103)
1772 void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1774 DIALOGINFO * dlgInfo;
1775 WND * wndPtr = WIN_FindWndPtr( hwnd );
1776 if (!wndPtr) return;
1777 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1778 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1779 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1780 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1781 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1782 WIN_ReleaseWndPtr(wndPtr);
1786 /***********************************************************************
1787 * MapDialogRect32 (USER32.382)
1789 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1791 DIALOGINFO * dlgInfo;
1792 WND * wndPtr = WIN_FindWndPtr( hwnd );
1793 if (!wndPtr) return FALSE;
1794 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1795 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1796 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1797 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1798 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1799 WIN_ReleaseWndPtr(wndPtr);
1804 /***********************************************************************
1805 * GetNextDlgGroupItem16 (USER.227)
1807 HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1810 return (HWND16)GetNextDlgGroupItem( hwndDlg, hwndCtrl, fPrevious );
1814 /***********************************************************************
1815 * GetNextDlgGroupItem32 (USER32.275)
1817 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl,
1828 /* if the hwndCtrl is the child of the control in the hwndDlg then the hwndDlg has to be the parent of the hwndCtrl */
1829 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1830 hwndDlg = GetParent(hwndCtrl);
1833 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1836 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
1841 /* Make sure hwndCtrl is a top-level child */
1842 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
1843 WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
1844 if (pWndCtrl->parent != pWndDlg)
1852 /* No ctrl specified -> start from the beginning */
1853 if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
1859 while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
1862 pWndLast = WIN_LockWndPtr(pWndCtrl);
1863 pWnd = WIN_LockWndPtr(pWndCtrl->next);
1867 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
1869 /* Wrap-around to the beginning of the group */
1872 WIN_UpdateWndPtr( &pWnd, pWndDlg->child );
1873 for ( pWndTemp = WIN_LockWndPtr( pWnd );
1875 WIN_UpdateWndPtr( &pWndTemp, pWndTemp->next) )
1877 if (pWndTemp->dwStyle & WS_GROUP) WIN_UpdateWndPtr( &pWnd, pWndTemp );
1878 if (pWndTemp == pWndCtrl) break;
1880 WIN_ReleaseWndPtr( pWndTemp );
1882 if (pWnd == pWndCtrl) break;
1883 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
1885 WIN_UpdateWndPtr(&pWndLast,pWnd);
1886 if (!fPrevious) break;
1888 WIN_UpdateWndPtr(&pWnd,pWnd->next);
1890 retvalue = pWndLast->hwndSelf;
1892 WIN_ReleaseWndPtr(pWndLast);
1893 WIN_ReleaseWndPtr(pWnd);
1895 WIN_ReleaseWndPtr(pWndCtrl);
1896 WIN_ReleaseWndPtr(pWndDlg);
1902 /***********************************************************************
1903 * GetNextDlgTabItem16 (USER.228)
1905 HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1908 return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
1911 /***********************************************************************
1912 * DIALOG_GetNextTabItem
1914 * Helper for GetNextDlgTabItem
1916 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1920 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1922 HWND hChildFirst = 0;
1926 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1927 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1931 HWND hParent = GetParent(hwndCtrl);
1932 BOOL bValid = FALSE;
1935 if(hParent == hwndMain)
1940 hParent = GetParent(hParent);
1944 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1947 if(GetParent(hwndCtrl) != hwndMain)
1948 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1952 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1954 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1964 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1965 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1966 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1971 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1973 hChildFirst = GetWindow(hChildFirst,wndSearch);
1978 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
1980 retWnd = hChildFirst;
1983 hChildFirst = GetWindow(hChildFirst,wndSearch);
1985 if(!retWnd && hwndCtrl)
1987 HWND hParent = GetParent(hwndCtrl);
1990 if(hParent == hwndMain) break;
1991 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1993 hParent = GetParent(hParent);
1996 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
2001 /***********************************************************************
2002 * GetNextDlgTabItem32 (USER32.276)
2004 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
2007 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
2010 /**********************************************************************
2011 * DIALOG_DlgDirSelect
2013 * Helper function for DlgDirSelect*
2015 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
2016 INT id, BOOL win32, BOOL unicode,
2022 HWND listbox = GetDlgItem( hwnd, id );
2024 TRACE("%04x '%s' %d\n", hwnd, str, id );
2025 if (!listbox) return FALSE;
2028 item = SendMessageA(listbox, combo ? CB_GETCURSEL
2029 : LB_GETCURSEL, 0, 0 );
2030 if (item == LB_ERR) return FALSE;
2031 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
2032 : LB_GETTEXTLEN, 0, 0 );
2033 if (size == LB_ERR) return FALSE;
2037 item = SendMessageA(listbox, combo ? CB_GETCURSEL16
2038 : LB_GETCURSEL16, 0, 0 );
2039 if (item == LB_ERR) return FALSE;
2040 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN16
2041 : LB_GETTEXTLEN16, 0, 0 );
2042 if (size == LB_ERR) return FALSE;
2045 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
2048 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
2049 item, (LPARAM)buffer );
2051 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
2052 item, (LPARAM)SEGPTR_GET(buffer) );
2054 if ((ret = (buffer[0] == '['))) /* drive or directory */
2056 if (buffer[1] == '-') /* drive */
2064 buffer[strlen(buffer)-1] = '\\';
2070 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
2071 else lstrcpynA( str, ptr, len );
2072 SEGPTR_FREE( buffer );
2073 TRACE("Returning %d '%s'\n", ret, str );
2078 /**********************************************************************
2081 * Helper function for DlgDirList*
2083 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2084 INT idStatic, UINT attrib, BOOL combo )
2088 LPSTR orig_spec = spec;
2090 #define SENDMSG(msg,wparam,lparam) \
2091 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2092 : SendMessageA( hwnd, msg, wparam, lparam ))
2094 TRACE("%04x '%s' %d %d %04x\n",
2095 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2097 if (spec && spec[0] && (spec[1] == ':'))
2099 drive = toupper( spec[0] ) - 'A';
2101 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
2103 else drive = DRIVE_GetCurrentDrive();
2105 /* If the path exists and is a directory, chdir to it */
2106 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
2111 if ((p2 = strrchr( p, '\\' ))) p = p2;
2112 if ((p2 = strrchr( p, '/' ))) p = p2;
2117 if (!DRIVE_Chdir( drive, spec ))
2119 *p = sep; /* Restore the original spec */
2126 TRACE("path=%c:\\%s mask=%s\n",
2127 'A' + drive, DRIVE_GetDosCwd(drive), spec );
2129 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2131 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2132 if (attrib & DDL_DIRECTORY)
2134 if (!(attrib & DDL_EXCLUSIVE))
2136 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2137 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2138 (LPARAM)spec ) == LB_ERR)
2141 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2142 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2143 (LPARAM)"*.*" ) == LB_ERR)
2148 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2149 (LPARAM)spec ) == LB_ERR)
2154 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2157 int drive = DRIVE_GetCurrentDrive();
2158 strcpy( temp, "A:\\" );
2160 lstrcpynA( temp + 3, DRIVE_GetDosCwd(drive), sizeof(temp)-3 );
2162 /* Can't use PostMessage() here, because the string is on the stack */
2163 SetDlgItemTextA( hDlg, idStatic, temp );
2166 if (orig_spec && (spec != orig_spec))
2168 /* Update the original file spec */
2170 while ((*orig_spec++ = *p++));
2178 /**********************************************************************
2179 * DIALOG_DlgDirListW
2181 * Helper function for DlgDirList*32W
2183 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2184 INT idStatic, UINT attrib, BOOL combo )
2188 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2189 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2191 lstrcpyAtoW( spec, specA );
2192 HeapFree( GetProcessHeap(), 0, specA );
2195 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2199 /**********************************************************************
2200 * DlgDirSelect (USER.99)
2202 BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
2204 return DlgDirSelectEx16( hwnd, str, 128, id );
2208 /**********************************************************************
2209 * DlgDirSelectComboBox (USER.194)
2211 BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
2213 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
2217 /**********************************************************************
2218 * DlgDirSelectEx16 (USER.422)
2220 BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
2222 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
2226 /**********************************************************************
2227 * DlgDirSelectEx32A (USER32.149)
2229 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2231 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
2235 /**********************************************************************
2236 * DlgDirSelectEx32W (USER32.150)
2238 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2240 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
2244 /**********************************************************************
2245 * DlgDirSelectComboBoxEx16 (USER.423)
2247 BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
2250 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
2254 /**********************************************************************
2255 * DlgDirSelectComboBoxEx32A (USER32.147)
2257 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2260 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
2264 /**********************************************************************
2265 * DlgDirSelectComboBoxEx32W (USER32.148)
2267 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2270 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
2274 /**********************************************************************
2275 * DlgDirList16 (USER.100)
2277 INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
2278 INT16 idStatic, UINT16 attrib )
2280 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2284 /**********************************************************************
2285 * DlgDirList32A (USER32.143)
2287 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2288 INT idStatic, UINT attrib )
2290 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2294 /**********************************************************************
2295 * DlgDirList32W (USER32.146)
2297 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2298 INT idStatic, UINT attrib )
2300 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2304 /**********************************************************************
2305 * DlgDirListComboBox16 (USER.195)
2307 INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
2308 INT16 idStatic, UINT16 attrib )
2310 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2314 /**********************************************************************
2315 * DlgDirListComboBox32A (USER32.144)
2317 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2318 INT idStatic, UINT attrib )
2320 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2324 /**********************************************************************
2325 * DlgDirListComboBox32W (USER32.145)
2327 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2328 INT idStatic, UINT attrib )
2330 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );