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
22 * PURPOSE: Dialog Manager
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
33 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
35 /* MACROS/DEFINITIONS ********************************************************/
38 #define DF_DIALOGACTIVE 0x4000 // ReactOS
39 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
40 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
41 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
42 #define GET_WORD(ptr) (*(WORD *)(ptr))
43 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
46 /* INTERNAL STRUCTS **********************************************************/
48 /* Dialog info structure */
51 HWND hwndFocus
; /* Current control with focus */
52 HFONT hUserFont
; /* Dialog font */
53 HMENU hMenu
; /* Dialog menu */
54 UINT xBaseUnit
; /* Dialog units (depends on the font) */
56 INT idResult
; /* EndDialog() result / default pushbutton ID */
57 UINT flags
; /* EndDialog() called for this dialog */
60 /* Dialog control information */
73 BOOL windowNameFree
; // ReactOS
98 /* CheckRadioButton structure */
107 /*********************************************************************
108 * dialog class descriptor
110 const struct builtin_class_descr DIALOG_builtin_class
=
112 WC_DIALOG
, /* name */
113 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
114 DefDlgProcA
, /* procA */
115 DefDlgProcW
, /* procW */
116 DLGWINDOWEXTRA
, /* extra */
117 (LPCWSTR
) IDC_ARROW
, /* cursor */
122 /* INTERNAL FUNCTIONS ********************************************************/
124 /***********************************************************************
127 * Get the DIALOGINFO structure of a window, allocating it if needed
128 * and 'create' is TRUE.
132 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
137 pWindow
= ValidateHwnd( hWnd
);
143 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
145 if (!dlgInfo
&& create
)
147 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
149 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
152 dlgInfo
->idResult
= IDOK
;
153 SETDLGINFO( hWnd
, dlgInfo
);
163 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
165 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
171 /***********************************************************************
172 * DIALOG_GetControl32
174 * Return the class and text of the control pointed to by ptr,
175 * fill the header structure and return a pointer to the next control.
177 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
182 info
->helpId
= GET_DWORD(p
); p
+= 2;
183 info
->exStyle
= GET_DWORD(p
); p
+= 2;
184 info
->style
= GET_DWORD(p
); p
+= 2;
189 info
->style
= GET_DWORD(p
); p
+= 2;
190 info
->exStyle
= GET_DWORD(p
); p
+= 2;
192 info
->x
= GET_WORD(p
); p
++;
193 info
->y
= GET_WORD(p
); p
++;
194 info
->cx
= GET_WORD(p
); p
++;
195 info
->cy
= GET_WORD(p
); p
++;
199 /* id is a DWORD for DIALOGEX */
200 info
->id
= GET_DWORD(p
);
205 info
->id
= GET_WORD(p
);
209 if (GET_WORD(p
) == 0xffff)
211 static const WCHAR class_names
[6][10] =
213 { 'B','u','t','t','o','n', }, /* 0x80 */
214 { 'E','d','i','t', }, /* 0x81 */
215 { 'S','t','a','t','i','c', }, /* 0x82 */
216 { 'L','i','s','t','B','o','x', }, /* 0x83 */
217 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
218 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
220 WORD id
= GET_WORD(p
+1);
221 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
222 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
225 info
->className
= class_names
[id
];
229 info
->className
= NULL
;
230 /* FIXME: load other classes here? */
231 ERR("Unknown built-in class id %04x\n", id
);
237 info
->className
= (LPCWSTR
)p
;
238 p
+= strlenW( info
->className
) + 1;
241 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
243 //// ReactOS Rev 6478
244 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
245 if (info
->windowName
!= NULL
)
247 wsprintf((LPWSTR
)info
->windowName
, L
"#%u", GET_WORD(p
+ 1));
248 info
->windowNameFree
= TRUE
;
252 info
->windowNameFree
= FALSE
;
258 info
->windowName
= (LPCWSTR
)p
;
259 info
->windowNameFree
= FALSE
;
260 p
+= strlenW( info
->windowName
) + 1;
263 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
264 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
265 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
266 info
->style
, info
->exStyle
, info
->helpId
);
271 p
+= GET_WORD(p
) / sizeof(WORD
);
273 else info
->data
= NULL
;
276 /* Next control is on dword boundary */
277 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
281 /***********************************************************************
282 * DIALOG_CreateControls32
284 * Create the control windows for a dialog.
286 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
287 HINSTANCE hInst
, BOOL unicode
)
289 DIALOGINFO
* dlgInfo
;
290 DLG_CONTROL_INFO info
;
291 HWND hwndCtrl
, hwndDefButton
= 0;
292 INT items
= dlgTemplate
->nbItems
;
294 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
299 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
300 dlgTemplate
->dialogEx
);
301 info
.style
&= ~WS_POPUP
;
302 info
.style
|= WS_CHILD
;
304 if (info
.style
& WS_BORDER
)
306 info
.style
&= ~WS_BORDER
;
307 info
.exStyle
|= WS_EX_CLIENTEDGE
;
312 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
313 info
.className
, info
.windowName
,
314 info
.style
| WS_CHILD
,
315 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
316 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
317 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
318 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
319 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
320 hInst
, (LPVOID
)info
.data
);
324 LPSTR
class = (LPSTR
)info
.className
;
325 LPSTR caption
= (LPSTR
)info
.windowName
;
327 if (!IS_INTRESOURCE(class))
329 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
330 class = HeapAlloc( GetProcessHeap(), 0, len
);
332 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
334 if (!IS_INTRESOURCE(caption
))
336 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
337 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
339 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
342 if (class != NULL
&& caption
!= NULL
)
344 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
345 class, caption
, info
.style
| WS_CHILD
,
346 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
347 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
348 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
349 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
350 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
351 hInst
, (LPVOID
)info
.data
);
355 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
356 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
359 if (info
.windowNameFree
)
361 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
366 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
367 debugstr_w(info
.windowName
));
368 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
372 /* Send initialisation messages to the control */
373 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
374 (WPARAM
)dlgInfo
->hUserFont
, 0 );
375 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
377 /* If there's already a default push-button, set it back */
378 /* to normal and use this one instead. */
380 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
381 hwndDefButton
= hwndCtrl
;
382 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
390 /***********************************************************************
391 * DIALOG_IsAccelerator
393 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
395 HWND hwndControl
= hwnd
;
402 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
403 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
405 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
406 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
407 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
409 /* find the accelerator key */
410 LPWSTR p
= buffer
- 2;
414 p
= strchrW( p
+ 2, '&' );
416 while (p
!= NULL
&& p
[1] == '&');
418 /* and check if it's the one we're looking for */
419 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
421 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
423 /* set focus to the control */
424 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
425 /* and bump it on to next */
426 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
428 else if (dlgCode
& DLGC_BUTTON
)
430 /* send BM_CLICK message to the control */
431 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
436 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
440 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
442 while (!hwndNext
&& hwndControl
)
444 hwndControl
= GetParent( hwndControl
);
445 if (hwndControl
== hwndDlg
)
447 if(hwnd
==hwndDlg
) /* prevent endless loop */
452 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
455 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
457 hwndControl
= hwndNext
;
459 while (hwndControl
&& (hwndControl
!= hwnd
));
464 /***********************************************************************
465 * DIALOG_FindMsgDestination
467 * The messages that IsDialogMessage sends may not go to the dialog
468 * calling IsDialogMessage if that dialog is a child, and it has the
469 * DS_CONTROL style set.
470 * We propagate up until we hit one that does not have DS_CONTROL, or
471 * whose parent is not a dialog.
473 * This is undocumented behaviour.
475 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
477 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
480 HWND hParent
= GetParent(hwndDlg
);
483 if (!IsWindow(hParent
)) break;
485 pWnd
= ValidateHwnd(hParent
);
486 // FIXME: Use pWnd->fnid == FNID_DESKTOP
487 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
489 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
500 /***********************************************************************
503 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
505 DIALOGINFO
* dlgInfo
;
511 pWnd
= ValidateHwnd(hwnd
);
512 if (!pWnd
) return -1;
514 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
517 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
521 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
525 /* ShowWindow the first time the queue goes empty */
526 ShowWindow( hwnd
, SW_SHOWNORMAL
);
529 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
531 /* No message present -> send ENTERIDLE and wait */
532 SendMessageW( owner
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
534 GetMessageW( &msg
, 0, 0, 0 );
537 if (msg
.message
== WM_QUIT
)
539 PostQuitMessage( msg
.wParam
);
540 if (!IsWindow( hwnd
)) return 0;
545 * If the user is pressing Ctrl+C, send a WM_COPY message.
546 * Guido Pola, CORE-4829, Is there another way to check if the Dialog is a MessageBox?
548 if (msg
.message
== WM_KEYDOWN
&&
549 pWnd
->state
& WNDS_MSGBOX
&& // Yes!
550 GetForegroundWindow() == hwnd
)
552 if (msg
.wParam
== L
'C' && GetKeyState(VK_CONTROL
) < 0)
553 SendMessageW(hwnd
, WM_COPY
, 0, 0);
556 if (!IsWindow( hwnd
)) return 0;
557 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
559 TranslateMessage( &msg
);
560 DispatchMessageW( &msg
);
562 if (!IsWindow( hwnd
)) return 0;
563 if (dlgInfo
->flags
& DF_END
) break;
565 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
567 ShowWindow( hwnd
, SW_SHOWNORMAL
);
572 retval
= dlgInfo
->idResult
;
573 DestroyWindow( hwnd
);
577 /***********************************************************************
578 * DIALOG_ParseTemplate32
580 * Fill a DLG_TEMPLATE structure from the dialog template, and return
581 * a pointer to the first control.
583 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
585 const WORD
*p
= (const WORD
*)template;
589 dlgver
= GET_WORD(p
); p
++;
590 signature
= GET_WORD(p
); p
++;
592 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
594 result
->dialogEx
= TRUE
;
595 result
->helpId
= GET_DWORD(p
); p
+= 2;
596 result
->exStyle
= GET_DWORD(p
); p
+= 2;
597 result
->style
= GET_DWORD(p
); p
+= 2;
601 result
->style
= GET_DWORD(p
- 2);
602 result
->dialogEx
= FALSE
;
604 result
->exStyle
= GET_DWORD(p
); p
+= 2;
606 result
->nbItems
= GET_WORD(p
); p
++;
607 result
->x
= GET_WORD(p
); p
++;
608 result
->y
= GET_WORD(p
); p
++;
609 result
->cx
= GET_WORD(p
); p
++;
610 result
->cy
= GET_WORD(p
); p
++;
611 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
612 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
613 result
->cx
, result
->cy
, result
->helpId
);
614 TRACE(" STYLE 0x%08x\n", result
->style
);
615 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
617 /* Get the menu name */
622 result
->menuName
= NULL
;
626 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
628 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
631 result
->menuName
= (LPCWSTR
)p
;
632 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
633 p
+= strlenW( result
->menuName
) + 1;
637 /* Get the class name */
642 result
->className
= WC_DIALOG
;
646 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
648 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
651 result
->className
= (LPCWSTR
)p
;
652 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
653 p
+= strlenW( result
->className
) + 1;
657 /* Get the window caption */
659 result
->caption
= (LPCWSTR
)p
;
660 p
+= strlenW( result
->caption
) + 1;
661 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
663 /* Get the font name */
665 result
->pointSize
= 0;
666 result
->faceName
= NULL
;
667 result
->weight
= FW_DONTCARE
;
668 result
->italic
= FALSE
;
670 if (result
->style
& DS_SETFONT
)
672 result
->pointSize
= GET_WORD(p
);
675 /* If pointSize is 0x7fff, it means that we need to use the font
676 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
677 * italic, and facename from the dialog template.
679 if (result
->pointSize
== 0x7fff)
681 /* We could call SystemParametersInfo here, but then we'd have
682 * to convert from pixel size to point size (which can be
685 TRACE(" FONT: Using message box font\n");
689 if (result
->dialogEx
)
691 result
->weight
= GET_WORD(p
); p
++;
692 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
694 result
->faceName
= (LPCWSTR
)p
;
695 p
+= strlenW( result
->faceName
) + 1;
697 TRACE(" FONT %d, %s, %d, %s\n",
698 result
->pointSize
, debugstr_w( result
->faceName
),
699 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
703 /* First control is on dword boundary */
704 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
707 /***********************************************************************
710 * Set the focus to a control of the dialog, selecting the text if
711 * the control is an edit dialog that has DLGC_HASSETSEL.
713 static void DEFDLG_SetFocus( HWND hwndCtrl
)
715 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
716 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
717 SetFocus( hwndCtrl
);
721 /***********************************************************************
724 static void DEFDLG_SaveFocus( HWND hwnd
)
727 HWND hwndFocus
= GetFocus();
729 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
730 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
731 infoPtr
->hwndFocus
= hwndFocus
;
732 /* Remove default button */
736 /***********************************************************************
737 * DEFDLG_RestoreFocus
739 static void DEFDLG_RestoreFocus( HWND hwnd
, BOOL justActivate
)
743 if (IsIconic( hwnd
)) return;
744 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
745 /* Don't set the focus back to controls if EndDialog is already called.*/
746 if (infoPtr
->flags
& DF_END
) return;
747 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
748 if (justActivate
) return;
749 /* If no saved focus control exists, set focus to the first visible,
750 non-disabled, WS_TABSTOP control in the dialog */
751 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
752 /* If there are no WS_TABSTOP controls, set focus to the first visible,
753 non-disabled control in the dialog */
754 if (!infoPtr
->hwndFocus
) infoPtr
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
755 if (!IsWindow( infoPtr
->hwndFocus
)) return;
758 SetFocus( infoPtr
->hwndFocus
);
760 DEFDLG_SetFocus( infoPtr
->hwndFocus
);
762 infoPtr
->hwndFocus
= NULL
;
765 /***********************************************************************
766 * DIALOG_CreateIndirect
767 * Creates a dialog box window
769 * modal = TRUE if we are called from a modal dialog box.
770 * (it's more compatible to do it here, as under Windows the owner
771 * is never disabled if the dialog fails because of an invalid template)
773 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
774 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
775 BOOL unicode
, HWND
*modal_owner
)
781 DLG_TEMPLATE
template;
782 DIALOGINFO
* dlgInfo
= NULL
;
783 DWORD units
= GetDialogBaseUnits();
784 HWND disabled_owner
= NULL
;
788 UINT xBaseUnit
= LOWORD(units
);
789 UINT yBaseUnit
= HIWORD(units
);
791 /* Parse dialog template */
793 if (!dlgTemplate
) return 0;
794 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
798 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
800 /* Create custom font if needed */
802 if (template.style
& DS_SETFONT
)
806 if (template.pointSize
== 0x7fff)
808 /* We get the message font from the non-client metrics */
809 NONCLIENTMETRICSW ncMetrics
;
811 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
812 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
813 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
815 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
820 /* We convert the size to pixels and then make it -ve. This works
821 * for both +ve and -ve template.pointSize */
822 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
823 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
824 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
825 PROOF_QUALITY
, FF_DONTCARE
,
832 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
833 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
836 xBaseUnit
= charSize
.cx
;
837 yBaseUnit
= charSize
.cy
;
839 SelectObject( dc
, hOldFont
);
842 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
845 /* Create dialog main window */
847 SetRect(&rect
, 0, 0, MulDiv(template.cx
, xBaseUnit
, 4), MulDiv(template.cy
, yBaseUnit
, 8));
848 if (template.style
& DS_CONTROL
)
849 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
850 template.style
|= DS_3DLOOK
;
851 if (template.style
& DS_MODALFRAME
)
852 template.exStyle
|= WS_EX_DLGMODALFRAME
;
853 if ((template.style
& DS_CONTROL
) || !(template.style
& WS_CHILD
))
854 template.exStyle
|= WS_EX_CONTROLPARENT
;
855 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
858 size
.cx
= rect
.right
- rect
.left
;
859 size
.cy
= rect
.bottom
- rect
.top
;
861 if (template.x
== CW_USEDEFAULT16
)
863 pos
.x
= pos
.y
= CW_USEDEFAULT
;
867 HMONITOR monitor
= 0;
868 MONITORINFO mon_info
;
870 mon_info
.cbSize
= sizeof(mon_info
);
871 if (template.style
& DS_CENTER
)
873 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
874 GetMonitorInfoW( monitor
, &mon_info
);
875 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
876 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
878 else if (template.style
& DS_CENTERMOUSE
)
880 GetCursorPos( &pos
);
881 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
882 GetMonitorInfoW( monitor
, &mon_info
);
886 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
887 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
889 // REACTOS : Need an owner to be passed!!!
891 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
)) && owner
) ClientToScreen( owner
, &pos
);
893 if ( !(template.style
& WS_CHILD
) )
897 /* try to fit it into the desktop */
901 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
902 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
903 GetMonitorInfoW( monitor
, &mon_info
);
905 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
907 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
909 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
910 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
914 if (modal_owner
&& owner
)
918 * Owner needs to be top level window. We need to duplicate the logic from server,
919 * because we need to disable it before creating dialog window. Note that we do that
920 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
923 while ((GetWindowLongW( owner
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
925 parent
= GetParent( owner
);
926 if (!parent
|| parent
== GetDesktopWindow()) break;
929 ////// Wine'ie babies need to fix your code!!!! CORE-11633
930 if (!parent
) parent
= GetAncestor( owner
, GA_ROOT
);
936 if (IsWindowEnabled( owner
))
938 disabled_owner
= owner
;
939 EnableWindow( disabled_owner
, FALSE
);
942 *modal_owner
= owner
;
947 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
948 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
949 owner
, hMenu
, hInst
, NULL
);
953 LPCSTR
class = (LPCSTR
)template.className
;
954 LPCSTR caption
= (LPCSTR
)template.caption
;
955 LPSTR class_tmp
= NULL
;
956 LPSTR caption_tmp
= NULL
;
958 if (!IS_INTRESOURCE(class))
960 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
961 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
962 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
965 if (!IS_INTRESOURCE(caption
))
967 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
968 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
969 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
970 caption
= caption_tmp
;
972 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
973 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
974 owner
, hMenu
, hInst
, NULL
);
975 HeapFree( GetProcessHeap(), 0, class_tmp
);
976 HeapFree( GetProcessHeap(), 0, caption_tmp
);
981 if (hUserFont
) DeleteObject( hUserFont
);
982 if (hMenu
) DestroyMenu( hMenu
);
983 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
987 /* moved this from the top of the method to here as DIALOGINFO structure
988 will be valid only after WM_CREATE message has been handled in DefDlgProc
989 All the members of the structure get filled here using temp variables */
990 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
994 if (hUserFont
) DeleteObject( hUserFont
);
995 if (hMenu
) DestroyMenu( hMenu
);
996 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1000 dlgInfo
->hwndFocus
= 0;
1001 dlgInfo
->hUserFont
= hUserFont
;
1002 dlgInfo
->hMenu
= hMenu
;
1003 dlgInfo
->xBaseUnit
= xBaseUnit
;
1004 dlgInfo
->yBaseUnit
= yBaseUnit
;
1005 dlgInfo
->flags
= flags
;
1007 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1009 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1010 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1012 if (dlgProc
&& dlgInfo
->hUserFont
)
1013 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1015 /* Create controls */
1017 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1019 /* Send initialisation messages and set focus */
1023 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1024 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1025 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1026 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1028 /* By returning TRUE, app has requested a default focus assignment.
1029 * WM_INITDIALOG may have changed the tab order, so find the first
1030 * tabstop control again. */
1031 focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1032 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1035 if (SendMessageW( focus
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
1036 SendMessageW( focus
, EM_SETSEL
, 0, MAXLONG
);
1040 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1041 //// This now breaks test_SaveRestoreFocus.
1042 //DEFDLG_SaveFocus( hwnd );
1045 //// ReactOS Rev 30613 & 30644
1046 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1047 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1049 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1051 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1052 UpdateWindow( hwnd
);
1053 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1057 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1058 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1059 if( IsWindow(hwnd
) )
1061 DestroyWindow( hwnd
);
1064 { ERR("DIALOG_CreateIndirect 1\n");
1065 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD
) && // Rule #1.
1066 !NtUserQueryWindow(owner
, QUERY_WINDOW_FOREGROUND
) )
1067 { ERR("DIALOG_CreateIndirect SFW\n");
1068 SetForegroundWindow(owner
);
1077 /***********************************************************************
1078 * DEFDLG_FindDefButton
1080 * Find the current default push-button.
1082 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1084 HWND hwndChild
, hwndTmp
;
1086 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1089 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1092 /* Recurse into WS_EX_CONTROLPARENT controls */
1093 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1095 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1096 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1097 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1100 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1106 /***********************************************************************
1109 * Set the default button id.
1111 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1113 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1114 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1115 INT old_id
= dlgInfo
->idResult
;
1117 dlgInfo
->idResult
= wParam
;
1119 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1120 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1121 return FALSE
; /* Destination is not a push button */
1123 /* Make sure the old default control is a valid push button ID */
1124 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1125 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1126 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1127 if (hwndOld
&& hwndOld
!= hwndNew
)
1128 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1132 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1133 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1139 /***********************************************************************
1140 * DEFDLG_SetDefButton
1142 * Set the new default button to be hwndNew.
1144 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1146 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1147 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1150 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1151 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1154 * Need to draw only default push button rectangle.
1155 * Since the next control is not a push button, need to draw the push
1156 * button rectangle for the default control.
1159 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1162 /* Make sure the old default control is a valid push button ID */
1163 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1164 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1165 if (hwndOld
&& hwndOld
!= hwndNew
)
1166 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1170 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1171 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1177 /***********************************************************************
1180 * Implementation of DefDlgProc(). Only handle messages that need special
1181 * handling for dialogs.
1183 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1184 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1190 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1194 HDC hdc
= (HDC
)wParam
;
1195 GetClientRect( hwnd
, &rect
);
1196 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1197 FillRect( hdc
, &rect
, brush
);
1203 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1205 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1206 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1207 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1208 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1209 NtUserxSetDialogPointer( hwnd
, 0 );
1211 /* Window clean-up */
1212 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1215 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1216 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1221 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1222 // if WA_CLICK/ACTIVE ? set dialog is active.
1223 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1224 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1226 if (wParam
) DEFDLG_RestoreFocus( hwnd
, TRUE
);
1227 else DEFDLG_SaveFocus( hwnd
);
1231 DEFDLG_RestoreFocus( hwnd
, FALSE
);
1235 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1236 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1240 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1243 if (dlgInfo
->idResult
)
1244 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1245 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1246 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1253 HWND hwndDest
= (HWND
)wParam
;
1255 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1256 if (hwndDest
) DEFDLG_SetFocus( hwndDest
);
1257 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1261 case WM_ENTERMENULOOP
:
1262 case WM_LBUTTONDOWN
:
1263 case WM_NCLBUTTONDOWN
:
1265 HWND hwndFocus
= GetFocus();
1268 /* always make combo box hide its listbox control */
1269 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1270 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1273 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1276 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1279 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1280 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1286 /***********************************************************************
1289 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1291 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1294 if (fResult
) return fResult
;
1296 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1297 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1299 if ( msg
== WM_COMPAREITEM
||
1300 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1301 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1304 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1307 /***********************************************************************
1308 * DIALOG_GetNextTabItem
1310 * Helper for GetNextDlgTabItem
1312 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1316 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1318 HWND hChildFirst
= 0;
1322 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1323 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1325 else if (IsChild( hwndMain
, hwndCtrl
))
1327 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1330 if(GetParent(hwndCtrl
) != hwndMain
)
1331 /* i.e. if we are not at the top level of the recursion */
1332 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1334 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1340 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1341 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1342 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1345 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1346 if (retWnd
) return (retWnd
);
1348 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1350 return (hChildFirst
);
1352 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1356 HWND hParent
= GetParent(hwndCtrl
);
1359 if(hParent
== hwndMain
) break;
1360 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1362 hParent
= GetParent(hParent
);
1365 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1367 return retWnd
? retWnd
: hwndCtrl
;
1371 /**********************************************************************
1372 * DIALOG_DlgDirListW
1374 * Helper function for DlgDirList*W
1376 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1377 INT idStatic
, UINT attrib
, BOOL combo
)
1380 LPWSTR orig_spec
= spec
;
1381 WCHAR any
[] = {'*','.','*',0};
1383 #define SENDMSG(msg,wparam,lparam) \
1384 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1385 : SendMessageW( hwnd, msg, wparam, lparam ))
1387 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1389 /* If the path exists and is a directory, chdir to it */
1390 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1395 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1396 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1397 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1402 if (!SetCurrentDirectoryW( spec
))
1404 *p
= sep
; /* Restore the original spec */
1411 TRACE( "mask=%s\n", spec
);
1413 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1415 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1417 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1418 if (attrib
& DDL_DIRECTORY
)
1420 if (!(attrib
& DDL_EXCLUSIVE
))
1422 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1423 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1426 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1427 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1432 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1436 /* Convert path specification to uppercase */
1437 if (spec
) CharUpperW(spec
);
1439 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1441 WCHAR temp
[MAX_PATH
];
1442 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1444 /* Can't use PostMessage() here, because the string is on the stack */
1445 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1448 if (orig_spec
&& (spec
!= orig_spec
))
1450 /* Update the original file spec */
1452 while ((*orig_spec
++ = *p
++));
1460 /**********************************************************************
1461 * DIALOG_DlgDirListA
1463 * Helper function for DlgDirList*A
1465 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1466 INT idStatic
, UINT attrib
, BOOL combo
)
1470 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1471 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1474 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1475 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1476 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1477 HeapFree( GetProcessHeap(), 0, specW
);
1480 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1483 /**********************************************************************
1484 * DIALOG_DlgDirSelect
1486 * Helper function for DlgDirSelect*
1488 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1489 INT id
, BOOL unicode
, BOOL combo
)
1491 WCHAR
*buffer
, *ptr
;
1494 HWND listbox
= GetDlgItem( hwnd
, id
);
1496 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1497 if (!listbox
) return FALSE
;
1499 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1500 if (item
== LB_ERR
) return FALSE
;
1502 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1503 if (size
== LB_ERR
) return FALSE
;
1505 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1507 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1509 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1511 if (buffer
[1] == '-') /* drive */
1519 buffer
[strlenW(buffer
)-1] = '\\';
1525 /* Filenames without a dot extension must have one tacked at the end */
1526 if (strchrW(buffer
, '.') == NULL
)
1528 buffer
[strlenW(buffer
)+1] = '\0';
1529 buffer
[strlenW(buffer
)] = '.';
1536 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1537 ((LPSTR
)str
)[len
-1] = 0;
1539 else lstrcpynW( str
, ptr
, len
);
1540 HeapFree( GetProcessHeap(), 0, buffer
);
1541 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1546 /* FUNCTIONS *****************************************************************/
1553 CreateDialogIndirectParamAorW(
1554 HINSTANCE hInstance
,
1555 LPCDLGTEMPLATE lpTemplate
,
1557 DLGPROC lpDialogFunc
,
1562 * This function might be obsolete since I don't think it is exported by NT
1563 * Also wine has one more parameter identifying weather it should call
1564 * the function with unicode or not
1566 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, NULL
);
1575 CreateDialogIndirectParamA(
1576 HINSTANCE hInstance
,
1577 LPCDLGTEMPLATE lpTemplate
,
1579 DLGPROC lpDialogFunc
,
1582 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, DLG_ISANSI
);
1591 CreateDialogIndirectParamW(
1592 HINSTANCE hInstance
,
1593 LPCDLGTEMPLATE lpTemplate
,
1595 DLGPROC lpDialogFunc
,
1598 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, 0);
1608 HINSTANCE hInstance
,
1609 LPCSTR lpTemplateName
,
1611 DLGPROC lpDialogFunc
,
1617 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1618 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1619 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1629 HINSTANCE hInstance
,
1630 LPCWSTR lpTemplateName
,
1632 DLGPROC lpDialogFunc
,
1638 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1639 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1640 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1655 DIALOGINFO
*dlgInfo
;
1657 BOOL result
= FALSE
;
1659 /* Perform DIALOGINFO initialization if not done */
1660 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1662 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1664 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1666 /* Call dialog procedure */
1667 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1670 if (!result
&& IsWindow(hDlg
))
1672 /* callback didn't process this message */
1686 case WM_ENTERMENULOOP
:
1687 case WM_LBUTTONDOWN
:
1688 case WM_NCLBUTTONDOWN
:
1689 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1692 case WM_COMPAREITEM
:
1697 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1700 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, TRUE
);
1715 DIALOGINFO
*dlgInfo
;
1717 BOOL result
= FALSE
;
1719 /* Perform DIALOGINFO initialization if not done */
1720 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1722 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1724 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1726 /* Call dialog procedure */
1727 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1730 if (!result
&& IsWindow(hDlg
))
1732 /* callback didn't process this message */
1746 case WM_ENTERMENULOOP
:
1747 case WM_LBUTTONDOWN
:
1748 case WM_NCLBUTTONDOWN
:
1749 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1752 case WM_COMPAREITEM
:
1757 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1760 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, FALSE
);
1769 DialogBoxIndirectParamAorW(
1770 HINSTANCE hInstance
,
1771 LPCDLGTEMPLATE hDialogTemplate
,
1773 DLGPROC lpDialogFunc
,
1778 * This function might be obsolete since I don't think it is exported by NT
1779 * Also wine has one more parameter identifying weather it should call
1780 * the function with unicode or not
1782 HWND hWnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, &hWndParent
);
1783 if (hWnd
) return DIALOG_DoDialogBox( hWnd
, hWndParent
);
1793 DialogBoxIndirectParamA(
1794 HINSTANCE hInstance
,
1795 LPCDLGTEMPLATE hDialogTemplate
,
1797 DLGPROC lpDialogFunc
,
1800 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, DLG_ISANSI
);
1809 DialogBoxIndirectParamW(
1810 HINSTANCE hInstance
,
1811 LPCDLGTEMPLATE hDialogTemplate
,
1813 DLGPROC lpDialogFunc
,
1816 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, 0);
1826 HINSTANCE hInstance
,
1827 LPCSTR lpTemplateName
,
1829 DLGPROC lpDialogFunc
,
1835 //// ReactOS rev 33532
1836 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
)) ||
1837 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1839 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1842 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1844 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1847 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, &hWndParent
);
1848 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1859 HINSTANCE hInstance
,
1860 LPCWSTR lpTemplateName
,
1862 DLGPROC lpDialogFunc
,
1868 //// ReactOS rev 33532
1869 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
)) ||
1870 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1872 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1875 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1877 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1880 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, &hWndParent
);
1881 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1898 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1907 DlgDirListComboBoxA(
1914 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1923 DlgDirListComboBoxW(
1930 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1946 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1955 DlgDirSelectComboBoxExA(
1961 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, FALSE
, TRUE
);
1970 DlgDirSelectComboBoxExW(
1976 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, TRUE
, TRUE
);
1991 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
2006 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
2011 * @implemented Modified for ReactOS. Do not Port Sync!!!
2019 DIALOGINFO
* dlgInfo
;
2023 TRACE("%p %ld\n", hwnd
, retval
);
2025 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2027 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2030 wasActive
= (hwnd
== GetActiveWindow());
2031 dlgInfo
->idResult
= retval
;
2032 dlgInfo
->flags
|= DF_END
;
2034 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
2036 owner
= GetAncestor( hwnd
, GA_PARENT
);
2039 owner
= GetWindow( hwnd
, GW_OWNER
);
2042 EnableWindow( owner
, TRUE
);
2044 /* Windows sets the focus to the dialog itself in EndDialog */
2046 if (wasActive
&& IsChild(hwnd
, GetFocus()))
2049 /* Don't have to send a ShowWindow(SW_HIDE), just do
2050 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2052 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2053 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2055 if (wasActive
&& owner
)
2057 /* If this dialog was given an owner then set the focus to that owner. */
2058 SetActiveWindow(owner
);
2060 else if (hwnd
== GetActiveWindow()) // Check it again!
2062 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS
);
2065 /* unblock dialog loop */
2066 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2076 GetDialogBaseUnits(VOID
)
2085 if ((hdc
= GetDC(0)))
2087 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2088 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2089 ReleaseDC( 0, hdc
);
2104 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2121 if (!hDlg
) return 0;
2123 list
= WIN_ListChildren(hDlg
);
2124 if (!list
) return 0;
2126 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2128 HeapFree(GetProcessHeap(), 0, list
);
2129 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2147 LONG_PTR result
= 0;
2149 if (lpTranslated
) *lpTranslated
= FALSE
;
2150 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2154 result
= strtol( str
, &endptr
, 10 );
2155 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2157 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)))
2162 result
= strtoul( str
, &endptr
, 10 );
2163 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2165 if (result
== ULONG_MAX
) return 0;
2167 if (lpTranslated
) *lpTranslated
= TRUE
;
2168 return (UINT
)result
;
2183 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2184 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2185 if ( nMaxCount
) lpString
[0] = '\0';
2201 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2202 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2203 if ( nMaxCount
) lpString
[0] = '\0';
2212 GetNextDlgGroupItem(
2217 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2219 BOOL fSkipping
=FALSE
;
2221 if (hDlg
== hCtl
) hCtl
= NULL
;
2222 if (!hCtl
&& bPrevious
) return 0;
2224 /* if the hwndCtrl is the child of the control in the hwndDlg,
2225 * then the hwndDlg has to be the parent of the hwndCtrl */
2229 if (!IsChild (hDlg
, hCtl
)) return 0;
2230 /* Make sure hwndCtrl is a top-level child */
2235 /* No ctrl specified -> start from the beginning */
2236 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2237 /* MSDN is wrong. fPrevious does not result in the last child */
2239 /* No ctrl specified -> start from the beginning */
2240 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2242 /* MSDN is wrong. fPrevious does not result in the last child */
2244 /* Maybe that first one is valid. If so then we don't want to skip it*/
2245 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2252 /* Always go forward around the group and list of controls; for the
2253 * previous control keep track; for the next break when you find one
2257 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
2262 /* Climb out until there is a next sibling of the ancestor or we
2263 * reach the top (in which case we loop back to the start)
2265 if (hDlg
== GetParent (hwnd
))
2267 /* Wrap around to the beginning of the list, within the same
2268 * group. (Once only)
2270 if (fLooped
) goto end
;
2272 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2276 hwnd
= GetParent (hwnd
);
2277 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2282 /* Wander down the leading edge of controlparents */
2283 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2284 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2285 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2287 /* Question. If the control is a control parent but either has no
2288 * children or is not visible/enabled then if it has a WS_GROUP does
2289 * it count? For that matter does it count anyway?
2290 * I believe it doesn't count.
2293 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2295 hwndLastGroup
= hwnd
;
2298 /* Look for the beginning of the group */
2305 if (!fSkipping
) break;
2306 if (hwndLastGroup
== hwnd
) break;
2307 hwnd
= hwndLastGroup
;
2313 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2317 if (!bPrevious
) break;
2337 pWindow
= ValidateHwnd( hDlg
);
2338 if (!pWindow
) return NULL
;
2341 pWindow
= ValidateHwnd( hCtl
);
2342 if (!pWindow
) return NULL
;
2345 /* Undocumented but tested under Win2000 and WinME */
2346 if (hDlg
== hCtl
) hCtl
= NULL
;
2348 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2349 * NB GetLastError returns whatever was set before the function was
2352 if (!hCtl
&& bPrevious
) return 0;
2354 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2365 return IsDialogMessageW(hDlg
, lpMsg
);
2369 /***********************************************************************
2370 * DIALOG_FixOneChildOnChangeFocus
2372 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2375 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2378 /* If a default pushbutton then no longer default */
2379 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2380 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2384 /***********************************************************************
2385 * DIALOG_FixChildrenOnChangeFocus
2387 * Following the change of focus that occurs for example after handling
2388 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2389 * children may be required.
2391 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2393 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2394 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2395 /* Windows does ask for this. I don't know why yet */
2397 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2399 /* If the button that is getting the focus WAS flagged as the default
2400 * pushbutton then ask the dialog what it thinks the default is and
2401 * set that in the default style.
2403 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2405 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2406 if (HIWORD(def_id
) == DC_HASDEFID
)
2409 def_id
= LOWORD(def_id
);
2410 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2413 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2414 /* I know that if it is a button then it should already be a
2415 * UNDEFPUSHBUTTON, since we have just told the buttons to
2416 * change style. But maybe they ignored our request
2418 if ((dlgcode_def
& DLGC_BUTTON
) &&
2419 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2421 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2426 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2428 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2429 /* I wonder why it doesn't send a DM_SETDEFID */
2433 /***********************************************************************
2436 * A recursive version of GetDlgItem
2439 * The HWND for a Child ID.
2441 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2444 HWND
*list
= WIN_ListChildren( hwndDlg
);
2447 if (!list
) return 0;
2449 for (i
= 0; list
[i
]; i
++)
2451 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2457 /* Recurse into every child */
2458 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2461 HeapFree( GetProcessHeap(), 0, list
);
2477 if (!IsWindow( hDlg
))
2480 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2482 if (hDlg
== GetDesktopWindow()) return FALSE
;
2483 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2485 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2487 switch(lpMsg
->message
)
2490 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2491 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2493 switch(lpMsg
->wParam
)
2496 if (!(dlgCode
& DLGC_WANTTAB
))
2498 BOOL fIsDialog
= TRUE
;
2499 WND
*pWnd
= ValidateHwnd(hDlg
);
2501 if (pWnd
&& TestWindowProcess(pWnd
))
2503 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2506 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2508 /* I am not sure under which circumstances the TAB is handled
2509 * each way. All I do know is that it does not always simply
2510 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2511 * do so but I presume someone has)
2514 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2517 /* It would appear that GetNextDlgTabItem can handle being
2518 * passed hwndDlg rather than NULL but that is undocumented
2519 * so let's do it properly
2521 HWND hwndFocus
= GetFocus();
2522 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2523 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2524 GetKeyState (VK_SHIFT
) & 0x8000);
2527 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2528 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2529 if (dlgCode
& DLGC_HASSETSEL
)
2531 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2532 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2536 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2537 length
= strlenW (buffer
);
2538 HeapFree (GetProcessHeap(), 0, buffer
);
2539 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2542 SetFocus (hwndNext
);
2543 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2556 if (!(dlgCode
& DLGC_WANTARROWS
))
2558 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2559 HWND hwndNext
= GetNextDlgGroupItem( hDlg
, lpMsg
->hwnd
, fPrevious
);
2560 if (hwndNext
&& SendMessageW( hwndNext
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
) == (DLGC_BUTTON
| DLGC_RADIOBUTTON
))
2562 SetFocus( hwndNext
);
2563 if ((GetWindowLongW( hwndNext
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
&&
2564 SendMessageW( hwndNext
, BM_GETCHECK
, 0, 0 ) != BST_CHECKED
)
2565 SendMessageW( hwndNext
, BM_CLICK
, 1, 0 );
2568 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2575 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2582 if ((GetFocus() == lpMsg
->hwnd
) &&
2583 (SendMessageW (lpMsg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2585 SendMessageW (hDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(lpMsg
->hwnd
),BN_CLICKED
), (LPARAM
)lpMsg
->hwnd
);
2587 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2589 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2590 if (!hwndDef
|| IsWindowEnabled(hwndDef
))
2591 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2595 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2604 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2605 * It does NOT get sent in the test program I have
2607 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2608 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2609 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2613 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2615 /* don't translate or dispatch */
2621 /* If the ALT key is being pressed display the keyboard cues */
2622 if ( HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
&&
2623 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2624 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2628 /* If the ALT key is being pressed display the keyboard cues */
2629 if ( lpMsg
->wParam
== SC_KEYMENU
&&
2630 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2632 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2637 TranslateMessage( lpMsg
);
2638 DispatchMessageW( lpMsg
);
2652 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2665 DIALOGINFO
* dlgInfo
;
2666 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2667 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2668 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2669 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2670 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2680 SendDlgItemMessageA(
2688 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2689 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2690 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2700 SendDlgItemMessageW(
2708 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2709 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2710 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2728 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2729 else sprintf( str
, "%u", uValue
);
2730 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2745 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2746 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2761 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2762 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2777 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2781 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2783 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2784 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2786 if((lChildID
>= lpRadioGroup
->firstID
) &&
2787 (lChildID
<= lpRadioGroup
->lastID
))
2789 if (lChildID
== lpRadioGroup
->checkID
)
2791 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2795 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2813 RADIOGROUP radioGroup
;
2815 radioGroup
.firstID
= nIDFirstButton
;
2816 radioGroup
.lastID
= nIDLastButton
;
2817 radioGroup
.checkID
= nIDCheckButton
;
2819 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);