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 ((Success
= GetTextMetricsA(hDC
,&tm
)))
160 pSize
->cx
= tm
.tmAveCharWidth
;
161 pSize
->cy
= tm
.tmHeight
;
162 TRACE("Using tm: %ldx%ld (dlg: %ld x %ld) (%s)\n",
163 tm
.tmAveCharWidth
, tm
.tmHeight
, pSize
->cx
, pSize
->cy
,
164 tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
? "variable" : "fixed");
166 /* select the original font */
167 if (hFontPrev
) SelectFont(hDC
,hFontPrev
);
172 /***********************************************************************
175 * A convenient variant of DIALOG_GetCharSizeFromDC.
177 static BOOL
DIALOG_GetCharSize( HFONT hFont
, SIZE
* pSize
)
180 BOOL Success
= DIALOG_GetCharSizeFromDC( hDC
, hFont
, pSize
);
185 /***********************************************************************
188 * Initialisation of the dialog manager.
190 BOOL
DIALOG_Init(void)
195 /* Calculate the dialog base units */
197 if (!(hdc
= CreateDCA( "DISPLAY", NULL
, NULL
, NULL
)))
199 ERR("Could not create Display DC\n");
203 if (!DIALOG_GetCharSizeFromDC( hdc
, 0, &size
))
206 ERR("Could not initialize base dialog units\n");
214 TRACE("base units = %d,%d\n", xBaseUnit
, yBaseUnit
);
219 /***********************************************************************
220 * DIALOG_GetControl16
222 * Return the class and text of the control pointed to by ptr,
223 * fill the header structure and return a pointer to the next control.
225 static LPCSTR
DIALOG_GetControl16( LPCSTR p
, DLG_CONTROL_INFO
*info
)
227 static char buffer
[10];
230 info
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
231 info
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
232 info
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
233 info
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
234 info
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
235 info
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
242 case 0x80: strcpy( buffer
, "BUTTON" ); break;
243 case 0x81: strcpy( buffer
, "EDIT" ); break;
244 case 0x82: strcpy( buffer
, "STATIC" ); break;
245 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
246 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
247 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
248 default: buffer
[0] = '\0'; break;
250 info
->className
= buffer
;
259 int_id
= ((BYTE
)*p
== 0xff);
262 /* Integer id, not documented (?). Only works for SS_ICON controls */
263 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+1);
268 info
->windowName
= p
;
272 if (*p
) info
->data
= p
+ 1;
273 else info
->data
= NULL
;
278 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %p\n",
279 info
->className
, LOWORD(info
->windowName
),
280 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
281 info
->style
, info
->data
);
283 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %p\n",
284 info
->className
, info
->windowName
,
285 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
286 info
->style
, info
->data
);
292 /***********************************************************************
293 * DIALOG_GetControl32
295 * Return the class and text of the control pointed to by ptr,
296 * fill the header structure and return a pointer to the next control.
298 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
303 info
->helpId
= GET_DWORD(p
); p
+= 2;
304 info
->exStyle
= GET_DWORD(p
); p
+= 2;
305 info
->style
= GET_DWORD(p
); p
+= 2;
310 info
->style
= GET_DWORD(p
); p
+= 2;
311 info
->exStyle
= GET_DWORD(p
); p
+= 2;
313 info
->x
= GET_WORD(p
); p
++;
314 info
->y
= GET_WORD(p
); p
++;
315 info
->cx
= GET_WORD(p
); p
++;
316 info
->cy
= GET_WORD(p
); p
++;
320 /* id is a DWORD for DIALOGEX */
321 info
->id
= GET_DWORD(p
);
326 info
->id
= GET_WORD(p
);
330 if (GET_WORD(p
) == 0xffff)
332 static const WCHAR class_names
[6][10] =
334 { 'B','u','t','t','o','n', }, /* 0x80 */
335 { 'E','d','i','t', }, /* 0x81 */
336 { 'S','t','a','t','i','c', }, /* 0x82 */
337 { 'L','i','s','t','B','o','x', }, /* 0x83 */
338 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
339 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
341 WORD id
= GET_WORD(p
+1);
342 if ((id
>= 0x80) && (id
<= 0x85))
343 info
->className
= (LPCSTR
)class_names
[id
- 0x80];
346 info
->className
= NULL
;
347 ERR("Unknown built-in class id %04x\n", id
);
353 info
->className
= (LPCSTR
)p
;
354 p
+= strlenW( (LPCWSTR
)p
) + 1;
357 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
359 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+ 1);
364 info
->windowName
= (LPCSTR
)p
;
365 p
+= strlenW( (LPCWSTR
)p
) + 1;
368 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
369 debugstr_w( (LPCWSTR
)info
->className
),
370 debugres_w( (LPCWSTR
)info
->windowName
),
371 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
372 info
->style
, info
->exStyle
, info
->helpId
);
376 if (TRACE_ON(dialog
))
378 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
381 for (i
= 0; i
< count
; i
++) DPRINTF( "%04x,", GET_WORD(p
+i
+1) );
386 p
+= GET_WORD(p
) / sizeof(WORD
);
388 else info
->data
= NULL
;
391 /* Next control is on dword boundary */
392 return (const WORD
*)((((int)p
) + 3) & ~3);
396 /***********************************************************************
397 * DIALOG_CreateControls
399 * Create the control windows for a dialog.
401 static BOOL
DIALOG_CreateControls( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
402 HINSTANCE hInst
, BOOL win32
)
404 DIALOGINFO
*dlgInfo
= DIALOG_get_info( hwnd
);
405 DLG_CONTROL_INFO info
;
406 HWND hwndCtrl
, hwndDefButton
= 0;
407 INT items
= dlgTemplate
->nbItems
;
414 HINSTANCE16 instance
;
417 template = DIALOG_GetControl16( template, &info
);
418 if (HIWORD(info
.className
) && !strcmp( info
.className
, "EDIT") &&
419 !(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_LOCALEDIT
))
421 if (!dlgInfo
->hDialogHeap
)
423 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
424 if (!dlgInfo
->hDialogHeap
)
426 ERR("Insufficient memory to create heap for edit control\n" );
429 LocalInit16(dlgInfo
->hDialogHeap
, 0, 0xffff);
431 instance
= dlgInfo
->hDialogHeap
;
433 else instance
= (HINSTANCE16
)hInst
;
435 segptr
= MapLS( info
.data
);
436 hwndCtrl
= WIN_Handle32( CreateWindowEx16( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
437 info
.className
, info
.windowName
,
438 info
.style
| WS_CHILD
,
439 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
440 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
441 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
442 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
443 WIN_Handle16(hwnd
), (HMENU16
)info
.id
,
444 instance
, (LPVOID
)segptr
));
449 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
450 dlgTemplate
->dialogEx
);
452 if (info
.style
& WS_BORDER
)
454 info
.style
&= ~WS_BORDER
;
455 info
.exStyle
|= WS_EX_CLIENTEDGE
;
457 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
458 (LPCWSTR
)info
.className
,
459 (LPCWSTR
)info
.windowName
,
460 info
.style
| WS_CHILD
,
461 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
462 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
463 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
464 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
465 hwnd
, (HMENU
)info
.id
,
466 hInst
, (LPVOID
)info
.data
);
468 if (!hwndCtrl
) return FALSE
;
470 /* Send initialisation messages to the control */
471 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
472 (WPARAM
)dlgInfo
->hUserFont
, 0 );
473 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
475 /* If there's already a default push-button, set it back */
476 /* to normal and use this one instead. */
478 SendMessageA( hwndDefButton
, BM_SETSTYLE
,
479 BS_PUSHBUTTON
,FALSE
);
480 hwndDefButton
= hwndCtrl
;
481 dlgInfo
->idResult
= GetWindowLongA( hwndCtrl
, GWL_ID
);
489 /***********************************************************************
490 * DIALOG_ParseTemplate16
492 * Fill a DLG_TEMPLATE structure from the dialog template, and return
493 * a pointer to the first control.
495 static LPCSTR
DIALOG_ParseTemplate16( LPCSTR p
, DLG_TEMPLATE
* result
)
497 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
499 result
->nbItems
= (unsigned char) *p
++;
500 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
501 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
502 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
503 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
504 TRACE("DIALOG %d, %d, %d, %d\n",
505 result
->x
, result
->y
, result
->cx
, result
->cy
);
506 TRACE(" STYLE %08lx\n", result
->style
);
508 /* Get the menu name */
513 result
->menuName
= 0;
517 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
519 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
522 result
->menuName
= p
;
523 TRACE(" MENU '%s'\n", p
);
528 /* Get the class name */
532 result
->className
= p
;
533 TRACE(" CLASS '%s'\n", result
->className
);
535 else result
->className
= DIALOG_CLASS_ATOM
;
538 /* Get the window caption */
542 TRACE(" CAPTION '%s'\n", result
->caption
);
544 /* Get the font name */
546 if (result
->style
& DS_SETFONT
)
548 result
->pointSize
= GET_WORD(p
);
550 result
->faceName
= p
;
552 TRACE(" FONT %d,'%s'\n",
553 result
->pointSize
, result
->faceName
);
559 /***********************************************************************
560 * DIALOG_ParseTemplate32
562 * Fill a DLG_TEMPLATE structure from the dialog template, and return
563 * a pointer to the first control.
565 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
567 const WORD
*p
= (const WORD
*)template;
569 result
->style
= GET_DWORD(p
); p
+= 2;
570 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
572 result
->dialogEx
= TRUE
;
573 result
->helpId
= GET_DWORD(p
); p
+= 2;
574 result
->exStyle
= GET_DWORD(p
); p
+= 2;
575 result
->style
= GET_DWORD(p
); p
+= 2;
579 result
->dialogEx
= FALSE
;
581 result
->exStyle
= GET_DWORD(p
); p
+= 2;
583 result
->nbItems
= GET_WORD(p
); p
++;
584 result
->x
= GET_WORD(p
); p
++;
585 result
->y
= GET_WORD(p
); p
++;
586 result
->cx
= GET_WORD(p
); p
++;
587 result
->cy
= GET_WORD(p
); p
++;
588 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
589 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
590 result
->cx
, result
->cy
, result
->helpId
);
591 TRACE(" STYLE 0x%08lx\n", result
->style
);
592 TRACE(" EXSTYLE 0x%08lx\n", result
->exStyle
);
594 /* Get the menu name */
599 result
->menuName
= NULL
;
603 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
605 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
608 result
->menuName
= (LPCSTR
)p
;
609 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR
)p
));
610 p
+= strlenW( (LPCWSTR
)p
) + 1;
614 /* Get the class name */
619 result
->className
= DIALOG_CLASS_ATOM
;
623 result
->className
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
625 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
628 result
->className
= (LPCSTR
)p
;
629 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR
)p
));
630 p
+= strlenW( (LPCWSTR
)p
) + 1;
634 /* Get the window caption */
636 result
->caption
= (LPCSTR
)p
;
637 p
+= strlenW( (LPCWSTR
)p
) + 1;
638 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR
)result
->caption
) );
640 /* Get the font name */
642 if (result
->style
& DS_SETFONT
)
644 result
->pointSize
= GET_WORD(p
);
646 if (result
->dialogEx
)
648 result
->weight
= GET_WORD(p
); p
++;
649 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
653 result
->weight
= FW_DONTCARE
;
654 result
->italic
= FALSE
;
656 result
->faceName
= (LPCSTR
)p
;
657 p
+= strlenW( (LPCWSTR
)p
) + 1;
658 TRACE(" FONT %d, %s, %d, %s\n",
659 result
->pointSize
, debugstr_w( (LPCWSTR
)result
->faceName
),
660 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
663 /* First control is on dword boundary */
664 return (LPCSTR
)((((int)p
) + 3) & ~3);
668 /***********************************************************************
669 * DIALOG_CreateIndirect
670 * Creates a dialog box window
672 * modal = TRUE if we are called from a modal dialog box.
673 * (it's more compatible to do it here, as under Windows the owner
674 * is never disabled if the dialog fails because of an invalid template)
676 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCSTR dlgTemplate
,
677 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
678 WINDOWPROCTYPE procType
, BOOL modal
)
683 DLG_TEMPLATE
template;
684 DIALOGINFO
* dlgInfo
;
685 BOOL ownerEnabled
= TRUE
;
686 BOOL win32Template
= (procType
!= WIN_PROC_16
);
688 /* Parse dialog template */
690 if (!dlgTemplate
) return 0;
692 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
694 dlgTemplate
= DIALOG_ParseTemplate16( dlgTemplate
, &template );
696 /* Initialise dialog extra data */
698 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo
) ))) return 0;
699 dlgInfo
->hwndFocus
= 0;
700 dlgInfo
->hUserFont
= 0;
702 dlgInfo
->xBaseUnit
= xBaseUnit
;
703 dlgInfo
->yBaseUnit
= yBaseUnit
;
704 dlgInfo
->idResult
= 0;
706 dlgInfo
->hDialogHeap
= 0;
710 if (template.menuName
)
712 if (!win32Template
) dlgInfo
->hMenu
= LoadMenu16( hInst
, template.menuName
);
713 else dlgInfo
->hMenu
= LoadMenuW( hInst
, (LPCWSTR
)template.menuName
);
716 /* Create custom font if needed */
718 if (template.style
& DS_SETFONT
)
720 /* The font height must be negative as it is a point size */
721 /* and must be converted to pixels first */
722 /* (see CreateFont() documentation in the Windows SDK). */
725 if (((short)template.pointSize
) < 0)
726 pixels
= -((short)template.pointSize
);
730 pixels
= template.pointSize
* GetDeviceCaps(dc
, LOGPIXELSY
)/72;
734 dlgInfo
->hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
735 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
736 PROOF_QUALITY
, FF_DONTCARE
,
737 (LPCWSTR
)template.faceName
);
739 dlgInfo
->hUserFont
= CreateFontA( -pixels
, 0, 0, 0, FW_DONTCARE
,
740 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
741 PROOF_QUALITY
, FF_DONTCARE
, template.faceName
);
742 if (dlgInfo
->hUserFont
)
745 if (DIALOG_GetCharSize( dlgInfo
->hUserFont
, &charSize
))
747 dlgInfo
->xBaseUnit
= charSize
.cx
;
748 dlgInfo
->yBaseUnit
= charSize
.cy
;
751 TRACE("units = %d,%d\n", dlgInfo
->xBaseUnit
, dlgInfo
->yBaseUnit
);
754 /* Create dialog main window */
756 rect
.left
= rect
.top
= 0;
757 rect
.right
= MulDiv(template.cx
, dlgInfo
->xBaseUnit
, 4);
758 rect
.bottom
= MulDiv(template.cy
, dlgInfo
->yBaseUnit
, 8);
759 if (template.style
& DS_MODALFRAME
)
760 template.exStyle
|= WS_EX_DLGMODALFRAME
;
761 AdjustWindowRectEx( &rect
, template.style
, (dlgInfo
->hMenu
!= 0), template.exStyle
);
762 rect
.right
-= rect
.left
;
763 rect
.bottom
-= rect
.top
;
765 if ((INT16
)template.x
== CW_USEDEFAULT16
)
767 rect
.left
= rect
.top
= win32Template
? CW_USEDEFAULT
: CW_USEDEFAULT16
;
771 if (template.style
& DS_CENTER
)
773 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
774 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
778 rect
.left
+= MulDiv(template.x
, dlgInfo
->xBaseUnit
, 4);
779 rect
.top
+= MulDiv(template.y
, dlgInfo
->yBaseUnit
, 8);
781 if ( !(template.style
& WS_CHILD
) )
785 if( !(template.style
& DS_ABSALIGN
) )
786 ClientToScreen( owner
, (POINT
*)&rect
);
788 /* try to fit it into the desktop */
790 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
791 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
792 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
793 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
794 if( rect
.left
< 0 ) rect
.left
= 0;
795 if( rect
.top
< 0 ) rect
.top
= 0;
801 ownerEnabled
= DIALOG_DisableOwner( owner
);
802 if (ownerEnabled
) dlgInfo
->flags
|= DF_OWNERENABLED
;
806 hwnd
= WIN_Handle32( CreateWindowEx16(template.exStyle
, template.className
,
807 template.caption
, template.style
& ~WS_VISIBLE
,
808 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
809 WIN_Handle16(owner
), dlgInfo
->hMenu
, hInst
, NULL
));
811 hwnd
= CreateWindowExW(template.exStyle
, (LPCWSTR
)template.className
,
812 (LPCWSTR
)template.caption
,
813 template.style
& ~WS_VISIBLE
,
814 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
815 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
819 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
820 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
821 if (modal
&& (dlgInfo
->flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
822 HeapFree( GetProcessHeap(), 0, dlgInfo
);
825 wndPtr
= WIN_GetPtr( hwnd
);
826 wndPtr
->flags
|= WIN_ISDIALOG
;
827 WIN_ReleasePtr( wndPtr
);
829 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
830 SetWindowLongW( hwnd
, DWL_WINE_DIALOGINFO
, (LONG
)dlgInfo
);
833 case WIN_PROC_16
: SetWindowLong16( WIN_Handle16(hwnd
), DWL_DLGPROC
, (LONG
)dlgProc
); break;
834 case WIN_PROC_32A
: SetWindowLongA( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
); break;
835 case WIN_PROC_32W
: SetWindowLongW( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
); break;
839 if (dlgInfo
->hUserFont
)
840 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
842 /* Create controls */
844 if (DIALOG_CreateControls( hwnd
, dlgTemplate
, &template,
845 hInst
, win32Template
))
847 HWND hwndPreInitFocus
;
849 /* Send initialisation messages and set focus */
851 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
853 hwndPreInitFocus
= GetFocus();
854 if (SendMessageA( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
856 /* check where the focus is again,
857 * some controls status might have changed in WM_INITDIALOG */
858 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
859 if( dlgInfo
->hwndFocus
)
860 SetFocus( dlgInfo
->hwndFocus
);
864 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
865 but the focus has not changed, set the focus where we expect it. */
866 if ((GetFocus() == hwndPreInitFocus
) &&
867 (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
869 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
870 if( dlgInfo
->hwndFocus
)
871 SetFocus( dlgInfo
->hwndFocus
);
875 if (template.style
& WS_VISIBLE
&& !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
877 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
881 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
882 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
887 /***********************************************************************
888 * CreateDialog (USER.89)
890 HWND16 WINAPI
CreateDialog16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
891 HWND16 owner
, DLGPROC16 dlgProc
)
893 return CreateDialogParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
897 /***********************************************************************
898 * CreateDialogParam (USER.241)
900 HWND16 WINAPI
CreateDialogParam16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
901 HWND16 owner
, DLGPROC16 dlgProc
,
909 TRACE("%04x,%s,%04x,%08lx,%ld\n",
910 hInst
, debugres_a(dlgTemplate
), owner
, (DWORD
)dlgProc
, param
);
912 if (!(hRsrc
= FindResource16( hInst
, dlgTemplate
, RT_DIALOGA
))) return 0;
913 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
914 if (!(data
= LockResource16( hmem
))) hwnd
= 0;
915 else hwnd
= CreateDialogIndirectParam16( hInst
, data
, owner
,
917 FreeResource16( hmem
);
921 /***********************************************************************
922 * CreateDialogParamA (USER32.@)
924 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
,
925 HWND owner
, DLGPROC dlgProc
,
928 HANDLE hrsrc
= FindResourceA( hInst
, name
, RT_DIALOGA
);
929 if (!hrsrc
) return 0;
930 return CreateDialogIndirectParamA( hInst
,
931 (LPVOID
)LoadResource(hInst
, hrsrc
),
932 owner
, dlgProc
, param
);
936 /***********************************************************************
937 * CreateDialogParamW (USER32.@)
939 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
,
940 HWND owner
, DLGPROC dlgProc
,
943 HANDLE hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
944 if (!hrsrc
) return 0;
945 return CreateDialogIndirectParamW( hInst
,
946 (LPVOID
)LoadResource(hInst
, hrsrc
),
947 owner
, dlgProc
, param
);
951 /***********************************************************************
952 * CreateDialogIndirect (USER.219)
954 HWND16 WINAPI
CreateDialogIndirect16( HINSTANCE16 hInst
, LPCVOID dlgTemplate
,
955 HWND16 owner
, DLGPROC16 dlgProc
)
957 return CreateDialogIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0);
961 /***********************************************************************
962 * CreateDialogIndirectParam (USER.242)
963 * CreateDialogIndirectParam16 (USER32.@)
965 HWND16 WINAPI
CreateDialogIndirectParam16( HINSTANCE16 hInst
,
967 HWND16 owner
, DLGPROC16 dlgProc
,
970 return WIN_Handle16( DIALOG_CreateIndirect( hInst
, dlgTemplate
, WIN_Handle32(owner
),
971 (DLGPROC
)dlgProc
, param
, WIN_PROC_16
, FALSE
));
975 /***********************************************************************
976 * CreateDialogIndirectParamA (USER32.@)
978 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
,
980 HWND owner
, DLGPROC dlgProc
,
983 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32A
, FALSE
);
986 /***********************************************************************
987 * CreateDialogIndirectParamAorW (USER32.@)
989 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
,
991 HWND owner
, DLGPROC dlgProc
,
993 { FIXME("assume WIN_PROC_32W\n");
994 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32W
, FALSE
);
997 /***********************************************************************
998 * CreateDialogIndirectParamW (USER32.@)
1000 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
,
1001 LPCVOID dlgTemplate
,
1002 HWND owner
, DLGPROC dlgProc
,
1005 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, WIN_PROC_32W
, FALSE
);
1009 /***********************************************************************
1010 * DIALOG_DoDialogBox
1012 static INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
1014 DIALOGINFO
* dlgInfo
;
1017 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
1019 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return -1;
1021 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
1023 ShowWindow( hwnd
, SW_SHOW
);
1026 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
1028 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
1030 /* No message present -> send ENTERIDLE and wait */
1031 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
1032 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1035 else if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1037 if (CallMsgFilterW( &msg
, MSGF_DIALOGBOX
)) continue;
1039 if (!IsWindow( hwnd
)) return -1;
1040 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
1042 TranslateMessage( &msg
);
1043 DispatchMessageW( &msg
);
1045 if (dlgInfo
->flags
& DF_END
) break;
1048 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
1049 retval
= dlgInfo
->idResult
;
1050 DestroyWindow( hwnd
);
1055 /***********************************************************************
1056 * DialogBox (USER.87)
1058 INT16 WINAPI
DialogBox16( HINSTANCE16 hInst
, LPCSTR dlgTemplate
,
1059 HWND16 owner
, DLGPROC16 dlgProc
)
1061 return DialogBoxParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1065 /***********************************************************************
1066 * DialogBoxParam (USER.239)
1068 INT16 WINAPI
DialogBoxParam16( HINSTANCE16 hInst
, LPCSTR
template,
1069 HWND16 owner16
, DLGPROC16 dlgProc
, LPARAM param
)
1077 if (!(hRsrc
= FindResource16( hInst
, template, RT_DIALOGA
))) return 0;
1078 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
1079 if ((data
= LockResource16( hmem
)))
1081 HWND owner
= WIN_Handle32(owner16
);
1082 hwnd
= DIALOG_CreateIndirect( hInst
, data
, owner
,
1083 (DLGPROC
)dlgProc
, param
, WIN_PROC_16
, TRUE
);
1084 if (hwnd
) ret
= DIALOG_DoDialogBox( hwnd
, owner
);
1085 GlobalUnlock16( hmem
);
1087 FreeResource16( hmem
);
1092 /***********************************************************************
1093 * DialogBoxParamA (USER32.@)
1095 INT WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
1096 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
1099 HANDLE hrsrc
= FindResourceA( hInst
, name
, RT_DIALOGA
);
1100 if (!hrsrc
) return 0;
1101 hwnd
= DIALOG_CreateIndirect( hInst
, (LPVOID
)LoadResource(hInst
, hrsrc
),
1102 owner
, dlgProc
, param
, WIN_PROC_32A
, TRUE
);
1103 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1108 /***********************************************************************
1109 * DialogBoxParamW (USER32.@)
1111 INT WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
1112 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
1115 HANDLE hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
1116 if (!hrsrc
) return 0;
1117 hwnd
= DIALOG_CreateIndirect( hInst
, (LPVOID
)LoadResource(hInst
, hrsrc
),
1118 owner
, dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1119 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1124 /***********************************************************************
1125 * DialogBoxIndirect (USER.218)
1127 INT16 WINAPI
DialogBoxIndirect16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1128 HWND16 owner
, DLGPROC16 dlgProc
)
1130 return DialogBoxIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1134 /***********************************************************************
1135 * DialogBoxIndirectParam (USER.240)
1136 * DialogBoxIndirectParam16 (USER32.@)
1138 INT16 WINAPI
DialogBoxIndirectParam16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1139 HWND16 owner16
, DLGPROC16 dlgProc
,
1142 HWND hwnd
, owner
= WIN_Handle32( owner16
);
1145 if (!(ptr
= GlobalLock16( dlgTemplate
))) return -1;
1146 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, (DLGPROC
)dlgProc
,
1147 param
, WIN_PROC_16
, TRUE
);
1148 GlobalUnlock16( dlgTemplate
);
1149 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1154 /***********************************************************************
1155 * DialogBoxIndirectParamA (USER32.@)
1157 INT WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCVOID
template,
1158 HWND owner
, DLGPROC dlgProc
,
1161 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
,
1162 dlgProc
, param
, WIN_PROC_32A
, TRUE
);
1163 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1168 /***********************************************************************
1169 * DialogBoxIndirectParamW (USER32.@)
1171 INT WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCVOID
template,
1172 HWND owner
, DLGPROC dlgProc
,
1175 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
,
1176 dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1177 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1181 /***********************************************************************
1182 * DialogBoxIndirectParamAorW (USER32.@)
1184 INT WINAPI
DialogBoxIndirectParamAorW(HINSTANCE hInstance
, LPCVOID
template,
1185 HWND owner
, DLGPROC dlgProc
,
1186 LPARAM param
, DWORD x
)
1189 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1190 hInstance
, template, owner
, dlgProc
, param
, x
);
1191 hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
, dlgProc
, param
, WIN_PROC_32W
, TRUE
);
1192 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1196 /***********************************************************************
1197 * EndDialog (USER32.@)
1199 BOOL WINAPI
EndDialog( HWND hwnd
, INT retval
)
1201 BOOL wasEnabled
= TRUE
;
1202 DIALOGINFO
* dlgInfo
;
1205 TRACE("%04x %d\n", hwnd
, retval
);
1207 if (!(dlgInfo
= DIALOG_get_info( hwnd
)))
1209 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd
);
1212 dlgInfo
->idResult
= retval
;
1213 dlgInfo
->flags
|= DF_END
;
1214 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
1216 if (wasEnabled
&& (owner
= GetWindow( hwnd
, GW_OWNER
)))
1217 DIALOG_EnableOwner( owner
);
1219 /* Windows sets the focus to the dialog itself in EndDialog */
1221 if (IsChild(hwnd
, GetFocus()))
1224 /* Don't have to send a ShowWindow(SW_HIDE), just do
1225 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1227 SetWindowPos(hwnd
, (HWND
)0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
1228 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1230 /* unblock dialog loop */
1231 PostMessageA(hwnd
, WM_NULL
, 0, 0);
1236 /***********************************************************************
1237 * DIALOG_IsAccelerator
1239 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM vKey
)
1241 HWND hwndControl
= hwnd
;
1248 DWORD style
= GetWindowLongW( hwndControl
, GWL_STYLE
);
1249 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
1251 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1252 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
1253 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1255 /* find the accelerator key */
1256 LPWSTR p
= buffer
- 2;
1262 p
= strchrW( p
+ 2, '&' );
1264 while (p
!= NULL
&& p
[1] == '&');
1266 /* and check if it's the one we're looking for */
1267 MultiByteToWideChar(CP_ACP
, 0, &a_char
, 1, &w_char
, 1);
1268 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( w_char
) )
1270 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
1272 /* set focus to the control */
1273 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
1274 /* and bump it on to next */
1275 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
1277 else if (dlgCode
& DLGC_BUTTON
)
1279 /* send BM_CLICK message to the control */
1280 SendMessageA( hwndControl
, BM_CLICK
, 0, 0 );
1285 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
1289 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1291 while (!hwndNext
&& hwndControl
)
1293 hwndControl
= GetParent( hwndControl
);
1294 if (hwndControl
== hwndDlg
)
1296 if(hwnd
==hwndDlg
) /* prevent endless loop */
1301 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
1304 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1306 hwndControl
= hwndNext
;
1308 while (hwndControl
&& (hwndControl
!= hwnd
));
1313 /***********************************************************************
1314 * DIALOG_FindMsgDestination
1316 * The messages that IsDialogMessage sends may not go to the dialog
1317 * calling IsDialogMessage if that dialog is a child, and it has the
1318 * DS_CONTROL style set.
1319 * We propagate up until we hit one that does not have DS_CONTROL, or
1320 * whose parent is not a dialog.
1322 * This is undocumented behaviour.
1324 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
1326 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
1329 HWND hParent
= GetParent(hwndDlg
);
1330 if (!hParent
) break;
1332 pParent
= WIN_FindWndPtr(hParent
);
1333 if (!pParent
) break;
1335 if (!(pParent
->flags
& WIN_ISDIALOG
))
1337 WIN_ReleaseWndPtr(pParent
);
1340 WIN_ReleaseWndPtr(pParent
);
1348 /***********************************************************************
1349 * DIALOG_IsDialogMessage
1351 static BOOL
DIALOG_IsDialogMessage( HWND hwnd
, HWND hwndDlg
,
1352 UINT message
, WPARAM wParam
,
1353 LPARAM lParam
, BOOL
*translate
,
1354 BOOL
*dispatch
, INT dlgCode
)
1356 *translate
= *dispatch
= FALSE
;
1358 if (message
== WM_PAINT
)
1360 /* Apparently, we have to handle this one as well */
1365 /* Only the key messages get special processing */
1366 if ((message
!= WM_KEYDOWN
) &&
1367 (message
!= WM_SYSKEYDOWN
) &&
1368 (message
!= WM_SYSCHAR
) &&
1369 (message
!= WM_CHAR
))
1372 if (dlgCode
& DLGC_WANTMESSAGE
)
1374 *translate
= *dispatch
= TRUE
;
1378 hwndDlg
= DIALOG_FindMsgDestination(hwndDlg
);
1386 if (!(dlgCode
& DLGC_WANTTAB
))
1388 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
,
1389 (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1398 if (!(dlgCode
& DLGC_WANTARROWS
))
1400 BOOL fPrevious
= (wParam
== VK_LEFT
|| wParam
== VK_UP
);
1402 GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1403 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
1409 SendMessageA( hwndDlg
, WM_COMMAND
, IDCANCEL
,
1410 (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1415 DWORD dw
= SendMessageW( hwndDlg
, DM_GETDEFID
, 0, 0 );
1416 if (HIWORD(dw
) == DC_HASDEFID
)
1418 SendMessageA( hwndDlg
, WM_COMMAND
,
1419 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1420 (LPARAM
)GetDlgItem(hwndDlg
, LOWORD(dw
)));
1424 SendMessageA( hwndDlg
, WM_COMMAND
, IDOK
,
1425 (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1432 break; /* case WM_KEYDOWN */
1435 if (dlgCode
& DLGC_WANTCHARS
) break;
1439 if (DIALOG_IsAccelerator( WIN_GetFullHandle(hwnd
), hwndDlg
, wParam
))
1441 /* don't translate or dispatch */
1451 /* If we get here, the message has not been treated specially */
1452 /* and can be sent to its destination window. */
1458 /***********************************************************************
1459 * IsDialogMessage (USER.90)
1461 BOOL16 WINAPI
IsDialogMessage16( HWND16 hwndDlg
, SEGPTR msg16
)
1463 LPMSG16 msg
= MapSL(msg16
);
1464 BOOL ret
, translate
, dispatch
;
1467 if ((hwndDlg
!= msg
->hwnd
) && !IsChild16( hwndDlg
, msg
->hwnd
))
1470 if ((msg
->message
== WM_KEYDOWN
) ||
1471 (msg
->message
== WM_CHAR
))
1473 dlgCode
= SendMessage16( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg16
);
1475 ret
= DIALOG_IsDialogMessage( WIN_Handle32(msg
->hwnd
), WIN_Handle32(hwndDlg
),
1476 msg
->message
, msg
->wParam
, msg
->lParam
,
1477 &translate
, &dispatch
, dlgCode
);
1478 if (translate
) TranslateMessage16( msg
);
1479 if (dispatch
) DispatchMessage16( msg
);
1484 /***********************************************************************
1485 * IsDialogMessage (USER32.@)
1486 * IsDialogMessageA (USER32.@)
1488 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG msg
)
1490 BOOL ret
, translate
, dispatch
;
1493 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1494 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1497 if ((msg
->message
== WM_KEYDOWN
) ||
1498 (msg
->message
== WM_CHAR
))
1500 dlgCode
= SendMessageA( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1502 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1503 msg
->wParam
, msg
->lParam
,
1504 &translate
, &dispatch
, dlgCode
);
1505 if (translate
) TranslateMessage( msg
);
1506 if (dispatch
) DispatchMessageA( msg
);
1511 /***********************************************************************
1512 * IsDialogMessageW (USER32.@)
1514 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1516 BOOL ret
, translate
, dispatch
;
1519 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1520 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1523 if ((msg
->message
== WM_KEYDOWN
) ||
1524 (msg
->message
== WM_CHAR
))
1526 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1528 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1529 msg
->wParam
, msg
->lParam
,
1530 &translate
, &dispatch
, dlgCode
);
1531 if (translate
) TranslateMessage( msg
);
1532 if (dispatch
) DispatchMessageW( msg
);
1537 /***********************************************************************
1538 * GetDlgCtrlID (USER32.@)
1540 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1542 return GetWindowLongW( hwnd
, GWL_ID
);
1546 /***********************************************************************
1547 * GetDlgItem (USER32.@)
1549 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1552 HWND
*list
= WIN_ListChildren( hwndDlg
);
1555 if (!list
) return 0;
1557 for (i
= 0; list
[i
]; i
++) if (GetWindowLongW( list
[i
], GWL_ID
) == id
) break;
1559 HeapFree( GetProcessHeap(), 0, list
);
1564 /*******************************************************************
1565 * SendDlgItemMessageA (USER32.@)
1567 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1568 WPARAM wParam
, LPARAM lParam
)
1570 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1571 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1576 /*******************************************************************
1577 * SendDlgItemMessageW (USER32.@)
1579 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1580 WPARAM wParam
, LPARAM lParam
)
1582 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1583 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1588 /*******************************************************************
1589 * SetDlgItemTextA (USER32.@)
1591 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1593 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1597 /*******************************************************************
1598 * SetDlgItemTextW (USER32.@)
1600 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1602 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1606 /***********************************************************************
1607 * GetDlgItemTextA (USER32.@)
1609 INT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, UINT len
)
1611 return (INT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1616 /***********************************************************************
1617 * GetDlgItemTextW (USER32.@)
1619 INT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, UINT len
)
1621 return (INT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1626 /*******************************************************************
1627 * SetDlgItemInt (USER32.@)
1629 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1634 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1635 else sprintf( str
, "%u", value
);
1636 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1641 /***********************************************************************
1642 * GetDlgItemInt (USER32.@)
1644 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1651 if (translated
) *translated
= FALSE
;
1652 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1656 result
= strtol( str
, &endptr
, 10 );
1657 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1659 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1664 result
= strtoul( str
, &endptr
, 10 );
1665 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1667 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1669 if (translated
) *translated
= TRUE
;
1670 return (UINT
)result
;
1674 /***********************************************************************
1675 * CheckDlgButton (USER32.@)
1677 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1679 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1684 /***********************************************************************
1685 * IsDlgButtonChecked (USER32.@)
1687 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, UINT id
)
1689 return (UINT
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1693 /***********************************************************************
1696 * Callback function used to check/uncheck radio buttons that fall
1697 * within a specific range of IDs.
1699 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1701 LONG lChildID
= GetWindowLongA(hwndChild
, GWL_ID
);
1702 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1704 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1705 (lChildID
<= lpRadioGroup
->lastID
))
1707 if (lChildID
== lpRadioGroup
->checkID
)
1709 SendMessageA(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1713 SendMessageA(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1721 /***********************************************************************
1722 * CheckRadioButton (USER32.@)
1724 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, UINT firstID
,
1725 UINT lastID
, UINT checkID
)
1727 RADIOGROUP radioGroup
;
1729 /* perform bounds checking for a radio button group */
1730 radioGroup
.firstID
= min(min(firstID
, lastID
), checkID
);
1731 radioGroup
.lastID
= max(max(firstID
, lastID
), checkID
);
1732 radioGroup
.checkID
= checkID
;
1734 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1735 (LPARAM
)&radioGroup
);
1739 /***********************************************************************
1740 * GetDialogBaseUnits (USER.243)
1741 * GetDialogBaseUnits (USER32.@)
1743 DWORD WINAPI
GetDialogBaseUnits(void)
1745 return MAKELONG( xBaseUnit
, yBaseUnit
);
1749 /***********************************************************************
1750 * MapDialogRect (USER32.@)
1752 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1754 DIALOGINFO
* dlgInfo
;
1755 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return FALSE
;
1756 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1757 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1758 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1759 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1764 /***********************************************************************
1765 * GetNextDlgGroupItem (USER32.@)
1767 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1769 HWND hwnd
, retvalue
;
1771 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1772 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1776 /* if the hwndCtrl is the child of the control in the hwndDlg,
1777 * then the hwndDlg has to be the parent of the hwndCtrl */
1778 if(GetParent(hwndCtrl
) != hwndDlg
&& GetParent(GetParent(hwndCtrl
)) == hwndDlg
)
1779 hwndDlg
= GetParent(hwndCtrl
);
1784 /* Make sure hwndCtrl is a top-level child */
1785 HWND parent
= GetParent( hwndCtrl
);
1786 while (parent
&& parent
!= hwndDlg
) parent
= GetParent(parent
);
1787 if (parent
!= hwndDlg
) return 0;
1791 /* No ctrl specified -> start from the beginning */
1792 if (!(hwndCtrl
= GetWindow( hwndDlg
, GW_CHILD
))) return 0;
1793 if (fPrevious
) hwndCtrl
= GetWindow( hwndCtrl
, GW_HWNDLAST
);
1796 retvalue
= hwndCtrl
;
1797 hwnd
= GetWindow( hwndCtrl
, GW_HWNDNEXT
);
1800 if (!hwnd
|| (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_GROUP
))
1802 /* Wrap-around to the beginning of the group */
1805 hwnd
= GetWindow( hwndDlg
, GW_CHILD
);
1806 for (tmp
= hwnd
; tmp
; tmp
= GetWindow( tmp
, GW_HWNDNEXT
) )
1808 if (GetWindowLongW( tmp
, GWL_STYLE
) & WS_GROUP
) hwnd
= tmp
;
1809 if (tmp
== hwndCtrl
) break;
1812 if (hwnd
== hwndCtrl
) break;
1813 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
1816 if (!fPrevious
) break;
1818 hwnd
= GetWindow( hwnd
, GW_HWNDNEXT
);
1824 /***********************************************************************
1825 * DIALOG_GetNextTabItem
1827 * Helper for GetNextDlgTabItem
1829 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1833 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1835 HWND hChildFirst
= 0;
1839 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1840 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1842 else if (IsChild( hwndMain
, hwndCtrl
))
1844 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1847 if(GetParent(hwndCtrl
) != hwndMain
)
1848 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1852 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDLAST
);
1854 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDFIRST
);
1864 dsStyle
= GetWindowLongA(hChildFirst
,GWL_STYLE
);
1865 exStyle
= GetWindowLongA(hChildFirst
,GWL_EXSTYLE
);
1866 if( (dsStyle
& DS_CONTROL
|| exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1871 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1873 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1878 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,(HWND
)NULL
,fPrevious
);
1880 retWnd
= hChildFirst
;
1883 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1885 if(!retWnd
&& hwndCtrl
)
1887 HWND hParent
= GetParent(hwndCtrl
);
1890 if(hParent
== hwndMain
) break;
1891 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1893 hParent
= GetParent(hParent
);
1896 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,(HWND
)NULL
,fPrevious
);
1901 /***********************************************************************
1902 * GetNextDlgTabItem (USER32.@)
1904 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1907 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1908 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1909 return DIALOG_GetNextTabItem(hwndDlg
,hwndDlg
,hwndCtrl
,fPrevious
);
1912 /**********************************************************************
1913 * DIALOG_DlgDirSelect
1915 * Helper function for DlgDirSelect*
1917 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1918 INT id
, BOOL unicode
, BOOL combo
)
1923 HWND listbox
= GetDlgItem( hwnd
, id
);
1925 TRACE("%04x '%s' %d\n", hwnd
, str
, id
);
1926 if (!listbox
) return FALSE
;
1928 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1929 if (item
== LB_ERR
) return FALSE
;
1930 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, 0, 0 );
1931 if (size
== LB_ERR
) return FALSE
;
1933 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
+1 ))) return FALSE
;
1935 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1937 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1939 if (buffer
[1] == '-') /* drive */
1947 buffer
[strlen(buffer
)-1] = '\\';
1955 if (len
> 0 && !MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, (LPWSTR
)str
, len
))
1956 ((LPWSTR
)str
)[len
-1] = 0;
1958 else lstrcpynA( str
, ptr
, len
);
1959 HeapFree( GetProcessHeap(), 0, buffer
);
1960 TRACE("Returning %d '%s'\n", ret
, str
);
1965 /**********************************************************************
1968 * Helper function for DlgDirList*
1970 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
1971 INT idStatic
, UINT attrib
, BOOL combo
)
1974 LPSTR orig_spec
= spec
;
1976 #define SENDMSG(msg,wparam,lparam) \
1977 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1978 : SendMessageA( hwnd, msg, wparam, lparam ))
1980 TRACE("%04x '%s' %d %d %04x\n",
1981 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
1983 /* If the path exists and is a directory, chdir to it */
1984 if (!spec
|| !spec
[0] || SetCurrentDirectoryA( spec
)) spec
= "*.*";
1989 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
1990 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
1995 if (!SetCurrentDirectoryA( spec
))
1997 *p
= sep
; /* Restore the original spec */
2004 TRACE( "mask=%s\n", spec
);
2006 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
2008 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
2009 if (attrib
& DDL_DIRECTORY
)
2011 if (!(attrib
& DDL_EXCLUSIVE
))
2013 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2014 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
2015 (LPARAM
)spec
) == LB_ERR
)
2018 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2019 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
2020 (LPARAM
)"*.*" ) == LB_ERR
)
2025 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
2026 (LPARAM
)spec
) == LB_ERR
)
2031 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
2033 char temp
[MAX_PATH
];
2034 GetCurrentDirectoryA( sizeof(temp
), temp
);
2036 /* Can't use PostMessage() here, because the string is on the stack */
2037 SetDlgItemTextA( hDlg
, idStatic
, temp
);
2040 if (orig_spec
&& (spec
!= orig_spec
))
2042 /* Update the original file spec */
2044 while ((*orig_spec
++ = *p
++));
2052 /**********************************************************************
2053 * DIALOG_DlgDirListW
2055 * Helper function for DlgDirList*W
2057 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2058 INT idStatic
, UINT attrib
, BOOL combo
)
2062 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
2063 INT ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
2065 MultiByteToWideChar( CP_ACP
, 0, specA
, -1, spec
, 0x7fffffff );
2066 HeapFree( GetProcessHeap(), 0, specA
);
2069 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
2073 /**********************************************************************
2074 * DlgDirSelectExA (USER32.@)
2076 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
2078 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
);
2082 /**********************************************************************
2083 * DlgDirSelectExW (USER32.@)
2085 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
2087 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, FALSE
);
2091 /**********************************************************************
2092 * DlgDirSelectComboBoxExA (USER32.@)
2094 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
2097 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, TRUE
);
2101 /**********************************************************************
2102 * DlgDirSelectComboBoxExW (USER32.@)
2104 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
2107 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
);
2111 /**********************************************************************
2112 * DlgDirListA (USER32.@)
2114 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
2115 INT idStatic
, UINT attrib
)
2117 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2121 /**********************************************************************
2122 * DlgDirListW (USER32.@)
2124 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2125 INT idStatic
, UINT attrib
)
2127 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2131 /**********************************************************************
2132 * DlgDirListComboBoxA (USER32.@)
2134 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
2135 INT idStatic
, UINT attrib
)
2137 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2141 /**********************************************************************
2142 * DlgDirListComboBoxW (USER32.@)
2144 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
2145 INT idStatic
, UINT attrib
)
2147 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);