3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/dialog.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * Steven Edwards (Steven_Ed4153@yahoo.com)
27 * 07-26-2003 Code ported from wine
28 * 09-05-2001 CSH Created
31 /* INCLUDES ******************************************************************/
35 #include <wine/debug.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
38 /* MACROS/DEFINITIONS ********************************************************/
41 #define DF_DIALOGACTIVE 0x4000 // ReactOS
42 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
43 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
44 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
45 #define GET_WORD(ptr) (*(WORD *)(ptr))
46 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
49 /* INTERNAL STRUCTS **********************************************************/
51 /* Dialog info structure */
54 HWND hwndFocus
; /* Current control with focus */
55 HFONT hUserFont
; /* Dialog font */
56 HMENU hMenu
; /* Dialog menu */
57 UINT xBaseUnit
; /* Dialog units (depends on the font) */
59 INT idResult
; /* EndDialog() result / default pushbutton ID */
60 UINT flags
; /* EndDialog() called for this dialog */
63 /* Dialog control information */
76 BOOL windowNameFree
; // ReactOS
101 /* CheckRadioButton structure */
110 /*********************************************************************
111 * dialog class descriptor
113 const struct builtin_class_descr DIALOG_builtin_class
=
115 WC_DIALOG
, /* name */
116 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
117 DefDlgProcA
, /* procA */
118 DefDlgProcW
, /* procW */
119 DLGWINDOWEXTRA
, /* extra */
120 (LPCWSTR
) IDC_ARROW
, /* cursor */
125 /* INTERNAL FUNCTIONS ********************************************************/
127 /***********************************************************************
130 * Get the DIALOGINFO structure of a window, allocating it if needed
131 * and 'create' is TRUE.
135 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
140 pWindow
= ValidateHwnd( hWnd
);
146 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
148 if (!dlgInfo
&& create
)
150 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
152 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
155 dlgInfo
->idResult
= IDOK
;
156 SETDLGINFO( hWnd
, dlgInfo
);
166 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
168 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
174 /***********************************************************************
175 * DIALOG_GetControl32
177 * Return the class and text of the control pointed to by ptr,
178 * fill the header structure and return a pointer to the next control.
180 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
185 info
->helpId
= GET_DWORD(p
); p
+= 2;
186 info
->exStyle
= GET_DWORD(p
); p
+= 2;
187 info
->style
= GET_DWORD(p
); p
+= 2;
192 info
->style
= GET_DWORD(p
); p
+= 2;
193 info
->exStyle
= GET_DWORD(p
); p
+= 2;
195 info
->x
= GET_WORD(p
); p
++;
196 info
->y
= GET_WORD(p
); p
++;
197 info
->cx
= GET_WORD(p
); p
++;
198 info
->cy
= GET_WORD(p
); p
++;
202 /* id is a DWORD for DIALOGEX */
203 info
->id
= GET_DWORD(p
);
208 info
->id
= GET_WORD(p
);
212 if (GET_WORD(p
) == 0xffff)
214 static const WCHAR class_names
[6][10] =
216 { 'B','u','t','t','o','n', }, /* 0x80 */
217 { 'E','d','i','t', }, /* 0x81 */
218 { 'S','t','a','t','i','c', }, /* 0x82 */
219 { 'L','i','s','t','B','o','x', }, /* 0x83 */
220 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
221 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
223 WORD id
= GET_WORD(p
+1);
224 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
225 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
228 info
->className
= class_names
[id
];
232 info
->className
= NULL
;
233 /* FIXME: load other classes here? */
234 ERR("Unknown built-in class id %04x\n", id
);
240 info
->className
= (LPCWSTR
)p
;
241 p
+= strlenW( info
->className
) + 1;
244 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
246 //// ReactOS Rev 6478
247 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
248 if (info
->windowName
!= NULL
)
250 wsprintf((LPWSTR
)info
->windowName
, L
"#%u", GET_WORD(p
+ 1));
251 info
->windowNameFree
= TRUE
;
255 info
->windowNameFree
= FALSE
;
261 info
->windowName
= (LPCWSTR
)p
;
262 info
->windowNameFree
= FALSE
;
263 p
+= strlenW( info
->windowName
) + 1;
266 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
267 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
268 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
269 info
->style
, info
->exStyle
, info
->helpId
);
274 p
+= GET_WORD(p
) / sizeof(WORD
);
276 else info
->data
= NULL
;
279 /* Next control is on dword boundary */
280 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
284 /***********************************************************************
285 * DIALOG_CreateControls32
287 * Create the control windows for a dialog.
289 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
290 HINSTANCE hInst
, BOOL unicode
)
292 DIALOGINFO
* dlgInfo
;
293 DLG_CONTROL_INFO info
;
294 HWND hwndCtrl
, hwndDefButton
= 0;
295 INT items
= dlgTemplate
->nbItems
;
297 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
302 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
303 dlgTemplate
->dialogEx
);
304 info
.style
&= ~WS_POPUP
;
305 info
.style
|= WS_CHILD
;
307 if (info
.style
& WS_BORDER
)
309 info
.style
&= ~WS_BORDER
;
310 info
.exStyle
|= WS_EX_CLIENTEDGE
;
315 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
316 info
.className
, info
.windowName
,
317 info
.style
| WS_CHILD
,
318 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
319 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
320 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
321 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
322 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
323 hInst
, (LPVOID
)info
.data
);
327 LPSTR
class = (LPSTR
)info
.className
;
328 LPSTR caption
= (LPSTR
)info
.windowName
;
330 if (!IS_INTRESOURCE(class))
332 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
333 class = HeapAlloc( GetProcessHeap(), 0, len
);
335 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
337 if (!IS_INTRESOURCE(caption
))
339 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
340 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
342 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
345 if (class != NULL
&& caption
!= NULL
)
347 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
348 class, caption
, info
.style
| WS_CHILD
,
349 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
350 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
351 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
352 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
353 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
354 hInst
, (LPVOID
)info
.data
);
358 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
359 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
362 if (info
.windowNameFree
)
364 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
369 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
370 debugstr_w(info
.windowName
));
371 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
375 /* Send initialisation messages to the control */
376 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
377 (WPARAM
)dlgInfo
->hUserFont
, 0 );
378 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
380 /* If there's already a default push-button, set it back */
381 /* to normal and use this one instead. */
383 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
384 hwndDefButton
= hwndCtrl
;
385 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
393 /***********************************************************************
394 * DIALOG_IsAccelerator
396 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
398 HWND hwndControl
= hwnd
;
405 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
406 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
408 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
409 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
410 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
412 /* find the accelerator key */
413 LPWSTR p
= buffer
- 2;
417 p
= strchrW( p
+ 2, '&' );
419 while (p
!= NULL
&& p
[1] == '&');
421 /* and check if it's the one we're looking for */
422 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
424 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
426 /* set focus to the control */
427 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
428 /* and bump it on to next */
429 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
431 else if (dlgCode
& DLGC_BUTTON
)
433 /* send BM_CLICK message to the control */
434 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
439 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
443 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
445 while (!hwndNext
&& hwndControl
)
447 hwndControl
= GetParent( hwndControl
);
448 if (hwndControl
== hwndDlg
)
450 if(hwnd
==hwndDlg
) /* prevent endless loop */
455 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
458 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
460 hwndControl
= hwndNext
;
462 while (hwndControl
&& (hwndControl
!= hwnd
));
467 /***********************************************************************
468 * DIALOG_FindMsgDestination
470 * The messages that IsDialogMessage sends may not go to the dialog
471 * calling IsDialogMessage if that dialog is a child, and it has the
472 * DS_CONTROL style set.
473 * We propagate up until we hit one that does not have DS_CONTROL, or
474 * whose parent is not a dialog.
476 * This is undocumented behaviour.
478 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
480 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
483 HWND hParent
= GetParent(hwndDlg
);
486 if (!IsWindow(hParent
)) break;
488 pWnd
= ValidateHwnd(hParent
);
489 // FIXME: Use pWnd->fnid == FNID_DESKTOP
490 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
492 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
503 /***********************************************************************
506 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
508 DIALOGINFO
* dlgInfo
;
514 pWnd
= ValidateHwnd(hwnd
);
515 if (!pWnd
) return -1;
517 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
520 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
524 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
528 /* ShowWindow the first time the queue goes empty */
529 ShowWindow( hwnd
, SW_SHOWNORMAL
);
532 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
534 /* No message present -> send ENTERIDLE and wait */
535 SendMessageW( owner
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
537 GetMessageW( &msg
, 0, 0, 0 );
540 if (msg
.message
== WM_QUIT
)
542 PostQuitMessage( msg
.wParam
);
543 if (!IsWindow( hwnd
)) return 0;
548 * If the user is pressing Ctrl+C, send a WM_COPY message.
549 * Guido Pola, CORE-4829, Is there another way to check if the Dialog is a MessageBox?
551 if (msg
.message
== WM_KEYDOWN
&&
552 pWnd
->state
& WNDS_MSGBOX
&& // Yes!
553 GetForegroundWindow() == hwnd
)
555 if (msg
.wParam
== L
'C' && GetKeyState(VK_CONTROL
) < 0)
556 SendMessageW(hwnd
, WM_COPY
, 0, 0);
559 if (!IsWindow( hwnd
)) return 0;
560 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
562 TranslateMessage( &msg
);
563 DispatchMessageW( &msg
);
565 if (!IsWindow( hwnd
)) return 0;
566 if (dlgInfo
->flags
& DF_END
) break;
568 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
570 ShowWindow( hwnd
, SW_SHOWNORMAL
);
575 retval
= dlgInfo
->idResult
;
576 DestroyWindow( hwnd
);
580 /***********************************************************************
581 * DIALOG_ParseTemplate32
583 * Fill a DLG_TEMPLATE structure from the dialog template, and return
584 * a pointer to the first control.
586 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
588 const WORD
*p
= (const WORD
*)template;
592 dlgver
= GET_WORD(p
); p
++;
593 signature
= GET_WORD(p
); p
++;
595 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
597 result
->dialogEx
= TRUE
;
598 result
->helpId
= GET_DWORD(p
); p
+= 2;
599 result
->exStyle
= GET_DWORD(p
); p
+= 2;
600 result
->style
= GET_DWORD(p
); p
+= 2;
604 result
->style
= GET_DWORD(p
- 2);
605 result
->dialogEx
= FALSE
;
607 result
->exStyle
= GET_DWORD(p
); p
+= 2;
609 result
->nbItems
= GET_WORD(p
); p
++;
610 result
->x
= GET_WORD(p
); p
++;
611 result
->y
= GET_WORD(p
); p
++;
612 result
->cx
= GET_WORD(p
); p
++;
613 result
->cy
= GET_WORD(p
); p
++;
614 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
615 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
616 result
->cx
, result
->cy
, result
->helpId
);
617 TRACE(" STYLE 0x%08x\n", result
->style
);
618 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
620 /* Get the menu name */
625 result
->menuName
= NULL
;
629 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
631 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
634 result
->menuName
= (LPCWSTR
)p
;
635 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
636 p
+= strlenW( result
->menuName
) + 1;
640 /* Get the class name */
645 result
->className
= WC_DIALOG
;
649 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
651 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
654 result
->className
= (LPCWSTR
)p
;
655 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
656 p
+= strlenW( result
->className
) + 1;
660 /* Get the window caption */
662 result
->caption
= (LPCWSTR
)p
;
663 p
+= strlenW( result
->caption
) + 1;
664 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
666 /* Get the font name */
668 result
->pointSize
= 0;
669 result
->faceName
= NULL
;
670 result
->weight
= FW_DONTCARE
;
671 result
->italic
= FALSE
;
673 if (result
->style
& DS_SETFONT
)
675 result
->pointSize
= GET_WORD(p
);
678 /* If pointSize is 0x7fff, it means that we need to use the font
679 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
680 * italic, and facename from the dialog template.
682 if (result
->pointSize
== 0x7fff)
684 /* We could call SystemParametersInfo here, but then we'd have
685 * to convert from pixel size to point size (which can be
688 TRACE(" FONT: Using message box font\n");
692 if (result
->dialogEx
)
694 result
->weight
= GET_WORD(p
); p
++;
695 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
697 result
->faceName
= (LPCWSTR
)p
;
698 p
+= strlenW( result
->faceName
) + 1;
700 TRACE(" FONT %d, %s, %d, %s\n",
701 result
->pointSize
, debugstr_w( result
->faceName
),
702 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
706 /* First control is on dword boundary */
707 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
710 /***********************************************************************
713 * Set the focus to a control of the dialog, selecting the text if
714 * the control is an edit dialog that has DLGC_HASSETSEL.
716 static void DEFDLG_SetFocus( HWND hwndCtrl
)
718 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
719 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
720 SetFocus( hwndCtrl
);
724 /***********************************************************************
727 static void DEFDLG_SaveFocus( HWND hwnd
)
730 HWND hwndFocus
= GetFocus();
732 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
733 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
734 infoPtr
->hwndFocus
= hwndFocus
;
735 /* Remove default button */
739 /***********************************************************************
740 * DEFDLG_RestoreFocus
742 static void DEFDLG_RestoreFocus( HWND hwnd
, BOOL justActivate
)
746 if (IsIconic( hwnd
)) return;
747 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
748 /* Don't set the focus back to controls if EndDialog is already called.*/
749 if (infoPtr
->flags
& DF_END
) return;
750 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
751 if (justActivate
) return;
752 /* If no saved focus control exists, set focus to the first visible,
753 non-disabled, WS_TABSTOP control in the dialog */
754 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
755 /* If there are no WS_TABSTOP controls, set focus to the first visible,
756 non-disabled control in the dialog */
757 if (!infoPtr
->hwndFocus
) infoPtr
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
758 if (!IsWindow( infoPtr
->hwndFocus
)) return;
761 SetFocus( infoPtr
->hwndFocus
);
763 DEFDLG_SetFocus( infoPtr
->hwndFocus
);
765 infoPtr
->hwndFocus
= NULL
;
768 /***********************************************************************
769 * DIALOG_CreateIndirect
770 * Creates a dialog box window
772 * modal = TRUE if we are called from a modal dialog box.
773 * (it's more compatible to do it here, as under Windows the owner
774 * is never disabled if the dialog fails because of an invalid template)
776 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
777 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
778 BOOL unicode
, HWND
*modal_owner
)
784 DLG_TEMPLATE
template;
785 DIALOGINFO
* dlgInfo
= NULL
;
786 DWORD units
= GetDialogBaseUnits();
787 HWND disabled_owner
= NULL
;
791 UINT xBaseUnit
= LOWORD(units
);
792 UINT yBaseUnit
= HIWORD(units
);
794 /* Parse dialog template */
796 if (!dlgTemplate
) return 0;
797 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
801 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
803 /* Create custom font if needed */
805 if (template.style
& DS_SETFONT
)
809 if (template.pointSize
== 0x7fff)
811 /* We get the message font from the non-client metrics */
812 NONCLIENTMETRICSW ncMetrics
;
814 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
815 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
816 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
818 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
823 /* We convert the size to pixels and then make it -ve. This works
824 * for both +ve and -ve template.pointSize */
825 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
826 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
827 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
828 PROOF_QUALITY
, FF_DONTCARE
,
835 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
836 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
839 xBaseUnit
= charSize
.cx
;
840 yBaseUnit
= charSize
.cy
;
842 SelectObject( dc
, hOldFont
);
845 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
848 /* Create dialog main window */
850 SetRect(&rect
, 0, 0, MulDiv(template.cx
, xBaseUnit
, 4), MulDiv(template.cy
, yBaseUnit
, 8));
851 if (template.style
& DS_CONTROL
)
852 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
853 template.style
|= DS_3DLOOK
;
854 if (template.style
& DS_MODALFRAME
)
855 template.exStyle
|= WS_EX_DLGMODALFRAME
;
856 if ((template.style
& DS_CONTROL
) || !(template.style
& WS_CHILD
))
857 template.exStyle
|= WS_EX_CONTROLPARENT
;
858 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
861 size
.cx
= rect
.right
- rect
.left
;
862 size
.cy
= rect
.bottom
- rect
.top
;
864 if (template.x
== CW_USEDEFAULT16
)
866 pos
.x
= pos
.y
= CW_USEDEFAULT
;
870 HMONITOR monitor
= 0;
871 MONITORINFO mon_info
;
873 mon_info
.cbSize
= sizeof(mon_info
);
874 if (template.style
& DS_CENTER
)
876 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
877 GetMonitorInfoW( monitor
, &mon_info
);
878 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
879 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
881 else if (template.style
& DS_CENTERMOUSE
)
883 GetCursorPos( &pos
);
884 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
885 GetMonitorInfoW( monitor
, &mon_info
);
889 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
890 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
892 // REACTOS : Need an owner to be passed!!!
894 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
)) && owner
) ClientToScreen( owner
, &pos
);
896 if ( !(template.style
& WS_CHILD
) )
900 /* try to fit it into the desktop */
904 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
905 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
906 GetMonitorInfoW( monitor
, &mon_info
);
908 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
910 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
912 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
913 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
917 if (modal_owner
&& owner
)
921 * Owner needs to be top level window. We need to duplicate the logic from server,
922 * because we need to disable it before creating dialog window. Note that we do that
923 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
926 while ((GetWindowLongW( owner
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
928 parent
= GetParent( owner
);
929 if (!parent
|| parent
== GetDesktopWindow()) break;
932 ////// Wine'ie babies need to fix your code!!!! CORE-11633
937 if (IsWindowEnabled( owner
))
939 disabled_owner
= owner
;
940 EnableWindow( disabled_owner
, FALSE
);
943 *modal_owner
= owner
;
948 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
949 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
950 owner
, hMenu
, hInst
, NULL
);
954 LPCSTR
class = (LPCSTR
)template.className
;
955 LPCSTR caption
= (LPCSTR
)template.caption
;
956 LPSTR class_tmp
= NULL
;
957 LPSTR caption_tmp
= NULL
;
959 if (!IS_INTRESOURCE(class))
961 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
962 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
963 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
966 if (!IS_INTRESOURCE(caption
))
968 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
969 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
970 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
971 caption
= caption_tmp
;
973 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
974 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
975 owner
, hMenu
, hInst
, NULL
);
976 HeapFree( GetProcessHeap(), 0, class_tmp
);
977 HeapFree( GetProcessHeap(), 0, caption_tmp
);
982 if (hUserFont
) DeleteObject( hUserFont
);
983 if (hMenu
) DestroyMenu( hMenu
);
984 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
988 /* moved this from the top of the method to here as DIALOGINFO structure
989 will be valid only after WM_CREATE message has been handled in DefDlgProc
990 All the members of the structure get filled here using temp variables */
991 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
995 if (hUserFont
) DeleteObject( hUserFont
);
996 if (hMenu
) DestroyMenu( hMenu
);
997 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1001 dlgInfo
->hwndFocus
= 0;
1002 dlgInfo
->hUserFont
= hUserFont
;
1003 dlgInfo
->hMenu
= hMenu
;
1004 dlgInfo
->xBaseUnit
= xBaseUnit
;
1005 dlgInfo
->yBaseUnit
= yBaseUnit
;
1006 dlgInfo
->flags
= flags
;
1008 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1010 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1011 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1013 if (dlgProc
&& dlgInfo
->hUserFont
)
1014 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1016 /* Create controls */
1018 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1020 /* Send initialisation messages and set focus */
1024 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1025 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1026 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1027 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1029 /* By returning TRUE, app has requested a default focus assignment.
1030 * WM_INITDIALOG may have changed the tab order, so find the first
1031 * tabstop control again. */
1032 focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1033 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1036 if (SendMessageW( focus
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
1037 SendMessageW( focus
, EM_SETSEL
, 0, MAXLONG
);
1041 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1042 //// This now breaks test_SaveRestoreFocus.
1043 //DEFDLG_SaveFocus( hwnd );
1046 //// ReactOS Rev 30613 & 30644
1047 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1048 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1050 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1052 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1053 UpdateWindow( hwnd
);
1054 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1058 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1059 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1060 if( IsWindow(hwnd
) )
1062 DestroyWindow( hwnd
);
1065 { ERR("DIALOG_CreateIndirect 1\n");
1066 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD
) && // Rule #1.
1067 !NtUserQueryWindow(owner
, QUERY_WINDOW_FOREGROUND
) )
1068 { ERR("DIALOG_CreateIndirect SFW\n");
1069 SetForegroundWindow(owner
);
1078 /***********************************************************************
1079 * DEFDLG_FindDefButton
1081 * Find the current default push-button.
1083 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1085 HWND hwndChild
, hwndTmp
;
1087 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1090 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1093 /* Recurse into WS_EX_CONTROLPARENT controls */
1094 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1096 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1097 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1098 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1101 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1107 /***********************************************************************
1110 * Set the default button id.
1112 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1114 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1115 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1116 INT old_id
= dlgInfo
->idResult
;
1118 dlgInfo
->idResult
= wParam
;
1120 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1121 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1122 return FALSE
; /* Destination is not a push button */
1124 /* Make sure the old default control is a valid push button ID */
1125 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1126 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1127 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1128 if (hwndOld
&& hwndOld
!= hwndNew
)
1129 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1133 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1134 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1140 /***********************************************************************
1141 * DEFDLG_SetDefButton
1143 * Set the new default button to be hwndNew.
1145 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1147 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1148 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1151 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1152 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1155 * Need to draw only default push button rectangle.
1156 * Since the next control is not a push button, need to draw the push
1157 * button rectangle for the default control.
1160 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1163 /* Make sure the old default control is a valid push button ID */
1164 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1165 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1166 if (hwndOld
&& hwndOld
!= hwndNew
)
1167 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1171 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1172 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1178 /***********************************************************************
1181 * Implementation of DefDlgProc(). Only handle messages that need special
1182 * handling for dialogs.
1184 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1185 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1191 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1195 HDC hdc
= (HDC
)wParam
;
1196 GetClientRect( hwnd
, &rect
);
1197 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1198 FillRect( hdc
, &rect
, brush
);
1204 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1206 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1207 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1208 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1209 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1210 NtUserxSetDialogPointer( hwnd
, 0 );
1212 /* Window clean-up */
1213 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1216 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1217 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1222 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1223 // if WA_CLICK/ACTIVE ? set dialog is active.
1224 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1225 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1227 if (wParam
) DEFDLG_RestoreFocus( hwnd
, TRUE
);
1228 else DEFDLG_SaveFocus( hwnd
);
1232 DEFDLG_RestoreFocus( hwnd
, FALSE
);
1236 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1237 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1241 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1244 if (dlgInfo
->idResult
)
1245 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1246 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1247 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1254 HWND hwndDest
= (HWND
)wParam
;
1256 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1257 if (hwndDest
) DEFDLG_SetFocus( hwndDest
);
1258 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1262 case WM_ENTERMENULOOP
:
1263 case WM_LBUTTONDOWN
:
1264 case WM_NCLBUTTONDOWN
:
1266 HWND hwndFocus
= GetFocus();
1269 /* always make combo box hide its listbox control */
1270 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1271 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1274 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1277 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1280 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1281 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1287 /***********************************************************************
1290 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1292 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1295 if (fResult
) return fResult
;
1297 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1298 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1300 if ( msg
== WM_COMPAREITEM
||
1301 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1302 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1305 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1308 /***********************************************************************
1309 * DIALOG_GetNextTabItem
1311 * Helper for GetNextDlgTabItem
1313 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1317 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1319 HWND hChildFirst
= 0;
1323 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1324 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1326 else if (IsChild( hwndMain
, hwndCtrl
))
1328 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1331 if(GetParent(hwndCtrl
) != hwndMain
)
1332 /* i.e. if we are not at the top level of the recursion */
1333 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1335 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1341 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1342 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1343 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1346 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1347 if (retWnd
) return (retWnd
);
1349 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1351 return (hChildFirst
);
1353 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1357 HWND hParent
= GetParent(hwndCtrl
);
1360 if(hParent
== hwndMain
) break;
1361 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1363 hParent
= GetParent(hParent
);
1366 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1368 return retWnd
? retWnd
: hwndCtrl
;
1372 /**********************************************************************
1373 * DIALOG_DlgDirListW
1375 * Helper function for DlgDirList*W
1377 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1378 INT idStatic
, UINT attrib
, BOOL combo
)
1381 LPWSTR orig_spec
= spec
;
1382 WCHAR any
[] = {'*','.','*',0};
1384 #define SENDMSG(msg,wparam,lparam) \
1385 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1386 : SendMessageW( hwnd, msg, wparam, lparam ))
1388 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1390 /* If the path exists and is a directory, chdir to it */
1391 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1396 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1397 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1398 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1403 if (!SetCurrentDirectoryW( spec
))
1405 *p
= sep
; /* Restore the original spec */
1412 TRACE( "mask=%s\n", spec
);
1414 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1416 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1418 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1419 if (attrib
& DDL_DIRECTORY
)
1421 if (!(attrib
& DDL_EXCLUSIVE
))
1423 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1424 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1427 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1428 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1433 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1437 /* Convert path specification to uppercase */
1438 if (spec
) CharUpperW(spec
);
1440 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1442 WCHAR temp
[MAX_PATH
];
1443 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1445 /* Can't use PostMessage() here, because the string is on the stack */
1446 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1449 if (orig_spec
&& (spec
!= orig_spec
))
1451 /* Update the original file spec */
1453 while ((*orig_spec
++ = *p
++));
1461 /**********************************************************************
1462 * DIALOG_DlgDirListA
1464 * Helper function for DlgDirList*A
1466 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1467 INT idStatic
, UINT attrib
, BOOL combo
)
1471 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1472 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1475 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1476 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1477 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1478 HeapFree( GetProcessHeap(), 0, specW
);
1481 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1484 /**********************************************************************
1485 * DIALOG_DlgDirSelect
1487 * Helper function for DlgDirSelect*
1489 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1490 INT id
, BOOL unicode
, BOOL combo
)
1492 WCHAR
*buffer
, *ptr
;
1495 HWND listbox
= GetDlgItem( hwnd
, id
);
1497 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1498 if (!listbox
) return FALSE
;
1500 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1501 if (item
== LB_ERR
) return FALSE
;
1503 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1504 if (size
== LB_ERR
) return FALSE
;
1506 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1508 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1510 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1512 if (buffer
[1] == '-') /* drive */
1520 buffer
[strlenW(buffer
)-1] = '\\';
1526 /* Filenames without a dot extension must have one tacked at the end */
1527 if (strchrW(buffer
, '.') == NULL
)
1529 buffer
[strlenW(buffer
)+1] = '\0';
1530 buffer
[strlenW(buffer
)] = '.';
1537 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1538 ((LPSTR
)str
)[len
-1] = 0;
1540 else lstrcpynW( str
, ptr
, len
);
1541 HeapFree( GetProcessHeap(), 0, buffer
);
1542 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1547 /* FUNCTIONS *****************************************************************/
1554 CreateDialogIndirectParamAorW(
1555 HINSTANCE hInstance
,
1556 LPCDLGTEMPLATE lpTemplate
,
1558 DLGPROC lpDialogFunc
,
1563 * This function might be obsolete since I don't think it is exported by NT
1564 * Also wine has one more parameter identifying weather it should call
1565 * the function with unicode or not
1567 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, NULL
);
1576 CreateDialogIndirectParamA(
1577 HINSTANCE hInstance
,
1578 LPCDLGTEMPLATE lpTemplate
,
1580 DLGPROC lpDialogFunc
,
1583 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, DLG_ISANSI
);
1592 CreateDialogIndirectParamW(
1593 HINSTANCE hInstance
,
1594 LPCDLGTEMPLATE lpTemplate
,
1596 DLGPROC lpDialogFunc
,
1599 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, 0);
1609 HINSTANCE hInstance
,
1610 LPCSTR lpTemplateName
,
1612 DLGPROC lpDialogFunc
,
1618 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1619 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1620 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1630 HINSTANCE hInstance
,
1631 LPCWSTR lpTemplateName
,
1633 DLGPROC lpDialogFunc
,
1639 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1640 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1641 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1656 DIALOGINFO
*dlgInfo
;
1658 BOOL result
= FALSE
;
1660 /* Perform DIALOGINFO initialization if not done */
1661 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1663 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1665 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1667 /* Call dialog procedure */
1668 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1671 if (!result
&& IsWindow(hDlg
))
1673 /* callback didn't process this message */
1687 case WM_ENTERMENULOOP
:
1688 case WM_LBUTTONDOWN
:
1689 case WM_NCLBUTTONDOWN
:
1690 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1693 case WM_COMPAREITEM
:
1698 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1701 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, TRUE
);
1716 DIALOGINFO
*dlgInfo
;
1718 BOOL result
= FALSE
;
1720 /* Perform DIALOGINFO initialization if not done */
1721 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1723 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1725 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1727 /* Call dialog procedure */
1728 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1731 if (!result
&& IsWindow(hDlg
))
1733 /* callback didn't process this message */
1747 case WM_ENTERMENULOOP
:
1748 case WM_LBUTTONDOWN
:
1749 case WM_NCLBUTTONDOWN
:
1750 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1753 case WM_COMPAREITEM
:
1758 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1761 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, FALSE
);
1770 DialogBoxIndirectParamAorW(
1771 HINSTANCE hInstance
,
1772 LPCDLGTEMPLATE hDialogTemplate
,
1774 DLGPROC lpDialogFunc
,
1779 * This function might be obsolete since I don't think it is exported by NT
1780 * Also wine has one more parameter identifying weather it should call
1781 * the function with unicode or not
1783 HWND hWnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, &hWndParent
);
1784 if (hWnd
) return DIALOG_DoDialogBox( hWnd
, hWndParent
);
1794 DialogBoxIndirectParamA(
1795 HINSTANCE hInstance
,
1796 LPCDLGTEMPLATE hDialogTemplate
,
1798 DLGPROC lpDialogFunc
,
1801 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, DLG_ISANSI
);
1810 DialogBoxIndirectParamW(
1811 HINSTANCE hInstance
,
1812 LPCDLGTEMPLATE hDialogTemplate
,
1814 DLGPROC lpDialogFunc
,
1817 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, 0);
1827 HINSTANCE hInstance
,
1828 LPCSTR lpTemplateName
,
1830 DLGPROC lpDialogFunc
,
1836 //// ReactOS rev 33532
1837 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
)) ||
1838 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1840 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1843 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1845 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1848 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, &hWndParent
);
1849 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1860 HINSTANCE hInstance
,
1861 LPCWSTR lpTemplateName
,
1863 DLGPROC lpDialogFunc
,
1869 //// ReactOS rev 33532
1870 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
)) ||
1871 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1873 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1876 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1878 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1881 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, &hWndParent
);
1882 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1899 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1908 DlgDirListComboBoxA(
1915 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1924 DlgDirListComboBoxW(
1931 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1947 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1956 DlgDirSelectComboBoxExA(
1962 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, FALSE
, TRUE
);
1971 DlgDirSelectComboBoxExW(
1977 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, TRUE
, TRUE
);
1992 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
2007 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
2012 * @implemented Modified for ReactOS. Do not Port Sync!!!
2020 DIALOGINFO
* dlgInfo
;
2024 TRACE("%p %ld\n", hwnd
, retval
);
2026 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2028 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2031 wasActive
= (hwnd
== GetActiveWindow());
2032 dlgInfo
->idResult
= retval
;
2033 dlgInfo
->flags
|= DF_END
;
2035 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
2037 owner
= GetAncestor( hwnd
, GA_PARENT
);
2040 owner
= GetWindow( hwnd
, GW_OWNER
);
2043 EnableWindow( owner
, TRUE
);
2045 /* Windows sets the focus to the dialog itself in EndDialog */
2047 if (wasActive
&& IsChild(hwnd
, GetFocus()))
2050 /* Don't have to send a ShowWindow(SW_HIDE), just do
2051 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2053 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2054 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2056 if (wasActive
&& owner
)
2058 /* If this dialog was given an owner then set the focus to that owner. */
2059 SetActiveWindow(owner
);
2061 else if (hwnd
== GetActiveWindow()) // Check it again!
2063 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS
);
2066 /* unblock dialog loop */
2067 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2077 GetDialogBaseUnits(VOID
)
2086 if ((hdc
= GetDC(0)))
2088 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2089 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2090 ReleaseDC( 0, hdc
);
2105 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2122 if (!hDlg
) return 0;
2124 list
= WIN_ListChildren(hDlg
);
2125 if (!list
) return 0;
2127 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2129 HeapFree(GetProcessHeap(), 0, list
);
2130 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2148 LONG_PTR result
= 0;
2150 if (lpTranslated
) *lpTranslated
= FALSE
;
2151 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2155 result
= strtol( str
, &endptr
, 10 );
2156 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2158 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)))
2163 result
= strtoul( str
, &endptr
, 10 );
2164 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2166 if (result
== ULONG_MAX
) return 0;
2168 if (lpTranslated
) *lpTranslated
= TRUE
;
2169 return (UINT
)result
;
2184 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2185 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2186 if ( nMaxCount
) lpString
[0] = '\0';
2202 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2203 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2204 if ( nMaxCount
) lpString
[0] = '\0';
2213 GetNextDlgGroupItem(
2218 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2220 BOOL fSkipping
=FALSE
;
2222 if (hDlg
== hCtl
) hCtl
= NULL
;
2223 if (!hCtl
&& bPrevious
) return 0;
2225 /* if the hwndCtrl is the child of the control in the hwndDlg,
2226 * then the hwndDlg has to be the parent of the hwndCtrl */
2230 if (!IsChild (hDlg
, hCtl
)) return 0;
2231 /* Make sure hwndCtrl is a top-level child */
2236 /* No ctrl specified -> start from the beginning */
2237 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2238 /* MSDN is wrong. fPrevious does not result in the last child */
2240 /* No ctrl specified -> start from the beginning */
2241 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2243 /* MSDN is wrong. fPrevious does not result in the last child */
2245 /* Maybe that first one is valid. If so then we don't want to skip it*/
2246 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2253 /* Always go forward around the group and list of controls; for the
2254 * previous control keep track; for the next break when you find one
2258 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
2263 /* Climb out until there is a next sibling of the ancestor or we
2264 * reach the top (in which case we loop back to the start)
2266 if (hDlg
== GetParent (hwnd
))
2268 /* Wrap around to the beginning of the list, within the same
2269 * group. (Once only)
2271 if (fLooped
) goto end
;
2273 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2277 hwnd
= GetParent (hwnd
);
2278 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2283 /* Wander down the leading edge of controlparents */
2284 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2285 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2286 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2288 /* Question. If the control is a control parent but either has no
2289 * children or is not visible/enabled then if it has a WS_GROUP does
2290 * it count? For that matter does it count anyway?
2291 * I believe it doesn't count.
2294 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2296 hwndLastGroup
= hwnd
;
2299 /* Look for the beginning of the group */
2306 if (!fSkipping
) break;
2307 if (hwndLastGroup
== hwnd
) break;
2308 hwnd
= hwndLastGroup
;
2314 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2318 if (!bPrevious
) break;
2338 pWindow
= ValidateHwnd( hDlg
);
2339 if (!pWindow
) return NULL
;
2342 pWindow
= ValidateHwnd( hCtl
);
2343 if (!pWindow
) return NULL
;
2346 /* Undocumented but tested under Win2000 and WinME */
2347 if (hDlg
== hCtl
) hCtl
= NULL
;
2349 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2350 * NB GetLastError returns whatever was set before the function was
2353 if (!hCtl
&& bPrevious
) return 0;
2355 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2366 return IsDialogMessageW(hDlg
, lpMsg
);
2370 /***********************************************************************
2371 * DIALOG_FixOneChildOnChangeFocus
2373 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2376 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2379 /* If a default pushbutton then no longer default */
2380 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2381 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2385 /***********************************************************************
2386 * DIALOG_FixChildrenOnChangeFocus
2388 * Following the change of focus that occurs for example after handling
2389 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2390 * children may be required.
2392 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2394 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2395 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2396 /* Windows does ask for this. I don't know why yet */
2398 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2400 /* If the button that is getting the focus WAS flagged as the default
2401 * pushbutton then ask the dialog what it thinks the default is and
2402 * set that in the default style.
2404 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2406 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2407 if (HIWORD(def_id
) == DC_HASDEFID
)
2410 def_id
= LOWORD(def_id
);
2411 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2414 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2415 /* I know that if it is a button then it should already be a
2416 * UNDEFPUSHBUTTON, since we have just told the buttons to
2417 * change style. But maybe they ignored our request
2419 if ((dlgcode_def
& DLGC_BUTTON
) &&
2420 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2422 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2427 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2429 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2430 /* I wonder why it doesn't send a DM_SETDEFID */
2434 /***********************************************************************
2437 * A recursive version of GetDlgItem
2440 * The HWND for a Child ID.
2442 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2445 HWND
*list
= WIN_ListChildren( hwndDlg
);
2448 if (!list
) return 0;
2450 for (i
= 0; list
[i
]; i
++)
2452 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2458 /* Recurse into every child */
2459 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2462 HeapFree( GetProcessHeap(), 0, list
);
2478 if (!IsWindow( hDlg
))
2481 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2483 if (hDlg
== GetDesktopWindow()) return FALSE
;
2484 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2486 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2488 switch(lpMsg
->message
)
2491 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2492 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2494 switch(lpMsg
->wParam
)
2497 if (!(dlgCode
& DLGC_WANTTAB
))
2499 BOOL fIsDialog
= TRUE
;
2500 WND
*pWnd
= ValidateHwnd(hDlg
);
2502 if (pWnd
&& TestWindowProcess(pWnd
))
2504 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2507 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2509 /* I am not sure under which circumstances the TAB is handled
2510 * each way. All I do know is that it does not always simply
2511 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2512 * do so but I presume someone has)
2515 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2518 /* It would appear that GetNextDlgTabItem can handle being
2519 * passed hwndDlg rather than NULL but that is undocumented
2520 * so let's do it properly
2522 HWND hwndFocus
= GetFocus();
2523 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2524 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2525 GetKeyState (VK_SHIFT
) & 0x8000);
2528 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2529 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2530 if (dlgCode
& DLGC_HASSETSEL
)
2532 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2533 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2537 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2538 length
= strlenW (buffer
);
2539 HeapFree (GetProcessHeap(), 0, buffer
);
2540 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2543 SetFocus (hwndNext
);
2544 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2557 if (!(dlgCode
& DLGC_WANTARROWS
))
2559 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2560 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2561 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2568 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2575 if ((GetFocus() == lpMsg
->hwnd
) &&
2576 (SendMessageW (lpMsg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2578 SendMessageW (hDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(lpMsg
->hwnd
),BN_CLICKED
), (LPARAM
)lpMsg
->hwnd
);
2580 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2582 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2583 if (!hwndDef
|| IsWindowEnabled(hwndDef
))
2584 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2588 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2597 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2598 * It does NOT get sent in the test program I have
2600 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2601 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2602 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2606 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2608 /* don't translate or dispatch */
2614 /* If the ALT key is being pressed display the keyboard cues */
2615 if ( HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
&&
2616 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2617 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2621 /* If the ALT key is being pressed display the keyboard cues */
2622 if ( lpMsg
->wParam
== SC_KEYMENU
&&
2623 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2625 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2630 TranslateMessage( lpMsg
);
2631 DispatchMessageW( lpMsg
);
2645 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2658 DIALOGINFO
* dlgInfo
;
2659 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2660 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2661 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2662 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2663 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2673 SendDlgItemMessageA(
2681 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2682 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2683 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2693 SendDlgItemMessageW(
2701 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2702 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2703 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2721 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2722 else sprintf( str
, "%u", uValue
);
2723 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2738 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2739 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2754 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2755 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2770 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2774 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2776 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2777 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2779 if((lChildID
>= lpRadioGroup
->firstID
) &&
2780 (lChildID
<= lpRadioGroup
->lastID
))
2782 if (lChildID
== lpRadioGroup
->checkID
)
2784 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2788 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2806 RADIOGROUP radioGroup
;
2808 radioGroup
.firstID
= nIDFirstButton
;
2809 radioGroup
.lastID
= nIDLastButton
;
2810 radioGroup
.checkID
= nIDCheckButton
;
2812 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);