Disable the owner of a modal dialog box just before creating the

dialog window.
This commit is contained in:
Gerard Patel 2000-08-21 03:31:39 +00:00 committed by Alexandre Julliard
parent 242d23e9a3
commit f314e5e76b
3 changed files with 104 additions and 32 deletions

View file

@ -360,7 +360,7 @@ static INT PROPSHEET_DoDialogBox( HWND hwnd, HWND owner)
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1; if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
dlgInfo = (DIALOGINFO *)wndPtr->wExtra; dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */ if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
{ {
EnableWindow( owner, FALSE ); EnableWindow( owner, FALSE );
ShowWindow( hwnd, SW_SHOW ); ShowWindow( hwnd, SW_SHOW );

View file

@ -37,6 +37,7 @@ typedef struct
#include "poppack.h" #include "poppack.h"
#define DF_END 0x0001 #define DF_END 0x0001
#define DF_OWNERENABLED 0x0002
extern BOOL DIALOG_Init(void); extern BOOL DIALOG_Init(void);

View file

@ -79,6 +79,45 @@ typedef struct
/* Dialog base units */ /* Dialog base units */
static WORD xBaseUnit = 0, yBaseUnit = 0; static WORD xBaseUnit = 0, yBaseUnit = 0;
/***********************************************************************
* DIALOG_EnableOwner
*
* Helper function for modal dialogs to enable again the
* owner of the dialog box.
*/
void DIALOG_EnableOwner( HWND hOwner, BOOL ownerWasEnabled)
{
/* Owner must be a top-level window */
if (hOwner)
hOwner = WIN_GetTopParent( hOwner );
if (!hOwner) return;
if (ownerWasEnabled)
EnableWindow( hOwner, TRUE );
}
/***********************************************************************
* DIALOG_DisableOwner
*
* Helper function for modal dialogs to disable the
* owner of the dialog box. Returns TRUE if owner was enabled.
*/
BOOL DIALOG_DisableOwner( HWND hOwner )
{
/* Owner must be a top-level window */
if (hOwner)
hOwner = WIN_GetTopParent( hOwner );
if (!hOwner) return FALSE;
if (IsWindowEnabled( hOwner ))
{
EnableWindow( hOwner, FALSE );
return TRUE;
}
else
return FALSE;
}
/*********************************************************************** /***********************************************************************
* DIALOG_GetCharSizeFromDC * DIALOG_GetCharSizeFromDC
* *
@ -626,11 +665,16 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
/*********************************************************************** /***********************************************************************
* DIALOG_CreateIndirect * DIALOG_CreateIndirect
* Creates a dialog box window
*
* modal = TRUE if we are called from a modal dialog box.
* (it's more compatible to do it here, as under Windows the owner
* is never disabled if the dialog fails because of an invalid template)
*/ */
static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate, static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
BOOL win32Template, HWND owner, BOOL win32Template, HWND owner,
DLGPROC16 dlgProc, LPARAM param, DLGPROC16 dlgProc, LPARAM param,
WINDOWPROCTYPE procType ) WINDOWPROCTYPE procType, BOOL modal )
{ {
HMENU16 hMenu = 0; HMENU16 hMenu = 0;
HFONT16 hFont = 0; HFONT16 hFont = 0;
@ -641,6 +685,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
DIALOGINFO * dlgInfo; DIALOGINFO * dlgInfo;
WORD xUnit = xBaseUnit; WORD xUnit = xBaseUnit;
WORD yUnit = yBaseUnit; WORD yUnit = yBaseUnit;
BOOL ownerEnabled = TRUE;
/* Parse dialog template */ /* Parse dialog template */
@ -744,6 +789,9 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
} }
} }
if (modal)
ownerEnabled = DIALOG_DisableOwner( owner );
if (!win32Template) if (!win32Template)
hwnd = CreateWindowEx16(template.exStyle, template.className, hwnd = CreateWindowEx16(template.exStyle, template.className,
template.caption, template.style & ~WS_VISIBLE, template.caption, template.style & ~WS_VISIBLE,
@ -760,6 +808,8 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
{ {
if (hFont) DeleteObject( hFont ); if (hFont) DeleteObject( hFont );
if (hMenu) DestroyMenu( hMenu ); if (hMenu) DestroyMenu( hMenu );
if (modal)
DIALOG_EnableOwner(owner, ownerEnabled);
return 0; return 0;
} }
wndPtr = WIN_FindWndPtr( hwnd ); wndPtr = WIN_FindWndPtr( hwnd );
@ -776,7 +826,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
dlgInfo->yBaseUnit = yUnit; dlgInfo->yBaseUnit = yUnit;
dlgInfo->msgResult = 0; dlgInfo->msgResult = 0;
dlgInfo->idResult = 0; dlgInfo->idResult = 0;
dlgInfo->flags = 0; dlgInfo->flags = ownerEnabled ? DF_OWNERENABLED: 0;
dlgInfo->hDialogHeap = 0; dlgInfo->hDialogHeap = 0;
if (dlgInfo->hUserFont) if (dlgInfo->hUserFont)
@ -821,6 +871,8 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
} }
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
if( IsWindow(hwnd) ) DestroyWindow( hwnd ); if( IsWindow(hwnd) ) DestroyWindow( hwnd );
if (modal)
DIALOG_EnableOwner(owner, ownerEnabled);
return 0; return 0;
} }
@ -908,7 +960,7 @@ HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
LPARAM param ) LPARAM param )
{ {
return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner, return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
dlgProc, param, WIN_PROC_16 ); dlgProc, param, WIN_PROC_16, FALSE );
} }
@ -921,7 +973,7 @@ HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
LPARAM param ) LPARAM param )
{ {
return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner, return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
(DLGPROC16)dlgProc, param, WIN_PROC_32A ); (DLGPROC16)dlgProc, param, WIN_PROC_32A, FALSE );
} }
/*********************************************************************** /***********************************************************************
@ -933,7 +985,7 @@ HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
LPARAM param ) LPARAM param )
{ FIXME("assume WIN_PROC_32W\n"); { FIXME("assume WIN_PROC_32W\n");
return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner, return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
(DLGPROC16)dlgProc, param, WIN_PROC_32W ); (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
} }
/*********************************************************************** /***********************************************************************
@ -945,7 +997,7 @@ HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
LPARAM param ) LPARAM param )
{ {
return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner, return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
(DLGPROC16)dlgProc, param, WIN_PROC_32W ); (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
} }
@ -958,17 +1010,15 @@ static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
DIALOGINFO * dlgInfo; DIALOGINFO * dlgInfo;
MSG msg; MSG msg;
INT retval; INT retval;
HWND ownerMsg = WIN_GetTopParent( owner );
/* Owner must be a top-level window */
owner = WIN_GetTopParent( owner );
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1; if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
dlgInfo = (DIALOGINFO *)wndPtr->wExtra; dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */ if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
{ {
EnableWindow( owner, FALSE );
ShowWindow( hwnd, SW_SHOW ); ShowWindow( hwnd, SW_SHOW );
while (MSG_InternalGetMessage(QMSG_WIN32A, &msg, hwnd, owner, MSGF_DIALOGBOX, while (MSG_InternalGetMessage(QMSG_WIN32A, &msg, hwnd, ownerMsg, MSGF_DIALOGBOX,
PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL )) PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
{ {
if (!IsDialogMessageA( hwnd, &msg)) if (!IsDialogMessageA( hwnd, &msg))
@ -978,8 +1028,8 @@ static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
} }
if (dlgInfo->flags & DF_END) break; if (dlgInfo->flags & DF_END) break;
} }
EnableWindow( owner, TRUE );
} }
DIALOG_EnableOwner( owner, (dlgInfo->flags & DF_OWNERENABLED) );
retval = dlgInfo->idResult; retval = dlgInfo->idResult;
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
DestroyWindow( hwnd ); DestroyWindow( hwnd );
@ -1003,9 +1053,22 @@ INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template, INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
HWND16 owner, DLGPROC16 dlgProc, LPARAM param ) HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
{ {
HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param); HWND16 hwnd = 0;
if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner ); HRSRC16 hRsrc;
return -1; HGLOBAL16 hmem;
LPCVOID data;
int ret = -1;
if (!(hRsrc = FindResource16( hInst, template, RT_DIALOG16 ))) return 0;
if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
if (!(data = LockResource16( hmem ))) hwnd = 0;
else hwnd = DIALOG_CreateIndirect( hInst, data, FALSE, owner,
dlgProc, param, WIN_PROC_16, TRUE );
if (hwnd)
ret =(INT16)DIALOG_DoDialogBox( hwnd, owner );
if (data) GlobalUnlock16( hmem );
FreeResource16( hmem );
return ret;
} }
@ -1015,7 +1078,12 @@ INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name, INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
HWND owner, DLGPROC dlgProc, LPARAM param ) HWND owner, DLGPROC dlgProc, LPARAM param )
{ {
HWND hwnd = CreateDialogParamA( hInst, name, owner, dlgProc, param ); HWND hwnd;
HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
if (!hrsrc) return 0;
hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
TRUE, owner,
(DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
if (hwnd) return DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1027,7 +1095,12 @@ INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name, INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
HWND owner, DLGPROC dlgProc, LPARAM param ) HWND owner, DLGPROC dlgProc, LPARAM param )
{ {
HWND hwnd = CreateDialogParamW( hInst, name, owner, dlgProc, param ); HWND hwnd;
HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
if (!hrsrc) return 0;
hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
TRUE, owner,
(DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
if (hwnd) return DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1054,9 +1127,10 @@ INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
LPCVOID ptr; LPCVOID ptr;
if (!(ptr = GlobalLock16( dlgTemplate ))) return -1; if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param ); hwnd = DIALOG_CreateIndirect( hInst, ptr, FALSE, owner,
dlgProc, param, WIN_PROC_16, TRUE );
GlobalUnlock16( dlgTemplate ); GlobalUnlock16( dlgTemplate );
if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1068,8 +1142,8 @@ INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
HWND owner, DLGPROC dlgProc, HWND owner, DLGPROC dlgProc,
LPARAM param ) LPARAM param )
{ {
HWND hwnd = CreateDialogIndirectParamA( hInstance, template, HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
owner, dlgProc, param ); (DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
if (hwnd) return DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1082,8 +1156,8 @@ INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
HWND owner, DLGPROC dlgProc, HWND owner, DLGPROC dlgProc,
LPARAM param ) LPARAM param )
{ {
HWND hwnd = CreateDialogIndirectParamW( hInstance, template, HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
owner, dlgProc, param ); (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
if (hwnd) return DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1098,8 +1172,8 @@ INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
HWND hwnd; HWND hwnd;
FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n", FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
hInstance, template, owner, dlgProc, param, x); hInstance, template, owner, dlgProc, param, x);
hwnd = CreateDialogIndirectParamW( hInstance, template, hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
owner, dlgProc, param ); (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
if (hwnd) return DIALOG_DoDialogBox( hwnd, owner ); if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
return -1; return -1;
} }
@ -1119,8 +1193,8 @@ BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
BOOL WINAPI EndDialog( HWND hwnd, INT retval ) BOOL WINAPI EndDialog( HWND hwnd, INT retval )
{ {
WND * wndPtr = WIN_FindWndPtr( hwnd ); WND * wndPtr = WIN_FindWndPtr( hwnd );
BOOL wasEnabled = TRUE;
DIALOGINFO * dlgInfo; DIALOGINFO * dlgInfo;
HWND hOwner = 0;
TRACE("%04x %d\n", hwnd, retval ); TRACE("%04x %d\n", hwnd, retval );
@ -1134,14 +1208,11 @@ BOOL WINAPI EndDialog( HWND hwnd, INT retval )
{ {
dlgInfo->idResult = retval; dlgInfo->idResult = retval;
dlgInfo->flags |= DF_END; dlgInfo->flags |= DF_END;
wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
} }
if(wndPtr->owner) if(wndPtr->owner)
hOwner = WIN_GetTopParent( wndPtr->owner->hwndSelf ); DIALOG_EnableOwner( wndPtr->owner->hwndSelf, wasEnabled );
/* Enable the owner first */
if (hOwner && !IsWindowEnabled(hOwner))
EnableWindow( hOwner, TRUE );
/* Windows sets the focus to the dialog itself in EndDialog */ /* Windows sets the focus to the dialog itself in EndDialog */