From 87115b23c26a6587bf7eb2b7313c045a99f1a86f Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 14 Aug 2004 00:44:08 +0000 Subject: [PATCH] WM_NEXTDLGCTL should not change the default button ID (based on a patch by Krishna Murthy). --- dlls/user/tests/dialog.c | 6 ++--- windows/defdlg.c | 62 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/dlls/user/tests/dialog.c b/dlls/user/tests/dialog.c index 19967a99e77..52dcd8e4b06 100644 --- a/dlls/user/tests/dialog.c +++ b/dlls/user/tests/dialog.c @@ -588,7 +588,7 @@ static void WM_NEXTDLGCTLTest(void) * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL" */ dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0); - todo_wine ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n"); + ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n"); /* * Check whether the style of the button which got the focus, changed to BS_DEFPUSHBUTTON and @@ -621,7 +621,7 @@ static void WM_NEXTDLGCTLTest(void) */ if ( IDCANCEL == (LOWORD(dwVal)) ) { - todo_wine ok ( ((GetWindowLong( g_hwndTestDlgBut2, GWL_STYLE)) & BS_DEFPUSHBUTTON), + ok ( ((GetWindowLong( g_hwndTestDlgBut2, GWL_STYLE)) & BS_DEFPUSHBUTTON), "Button2 style not set to BS_DEFPUSHBUTTON\n" ); ok ( !((GetWindowLong( g_hwndTestDlgBut1, GWL_STYLE)) & BS_DEFPUSHBUTTON), @@ -638,7 +638,7 @@ static void WM_NEXTDLGCTLTest(void) * Check whether the default button ID got changed by sending message "WM_NEXTDLGCTL" */ dwVal = DefDlgProcA(g_hwndTestDlg, DM_GETDEFID, 0, 0); - todo_wine ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n"); + ok ( IDCANCEL == (LOWORD(dwVal)), "WM_NEXTDLGCTL changed default button\n"); } } diff --git a/windows/defdlg.c b/windows/defdlg.c index 0d9f1f0440b..def5b8af7b8 100644 --- a/windows/defdlg.c +++ b/windows/defdlg.c @@ -127,14 +127,15 @@ static HWND DEFDLG_FindDefButton( HWND hwndDlg ) /*********************************************************************** - * DEFDLG_SetDefButton + * DEFDLG_SetDefId * - * Set the new default button to be hwndNew. + * Set the default button id. */ -static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo, WPARAM wParam ) +static BOOL DEFDLG_SetDefId( HWND hwndDlg, DIALOGINFO *dlgInfo, WPARAM wParam) { DWORD dlgcode=0; /* initialize just to avoid a warning */ - HWND hwndNew = GetDlgItem(hwndDlg, wParam); + HWND hwndOld, hwndNew = GetDlgItem(hwndDlg, wParam); + INT old_id = dlgInfo->idResult; dlgInfo->idResult = wParam; if (hwndNew && @@ -142,15 +143,54 @@ static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo, WPARAM wPara & (DLGC_UNDEFPUSHBUTTON | DLGC_BUTTON))) return FALSE; /* Destination is not a push button */ - if (dlgInfo->idResult) /* There's already a default pushbutton */ + /* Make sure the old default control is a valid push button ID */ + hwndOld = GetDlgItem( hwndDlg, old_id ); + if (!hwndOld || !(SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)) + hwndOld = DEFDLG_FindDefButton( hwndDlg ); + if (hwndOld && hwndOld != hwndNew) + SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE ); + + if (hwndNew) { - HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult ); - if (hwndOld && (SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)) - SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE ); + if(dlgcode & DLGC_UNDEFPUSHBUTTON) + SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); } + return TRUE; +} + + +/*********************************************************************** + * DEFDLG_SetDefButton + * + * Set the new default button to be hwndNew. + */ +static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo, HWND hwndNew ) +{ + DWORD dlgcode=0; /* initialize just to avoid a warning */ + HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult ); + + if (hwndNew && + !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 )) + & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON))) + { + /** + * Need to draw only default push button rectangle. + * Since the next control is not a push button, need to draw the push + * button rectangle for the default control. + */ + hwndNew = hwndOld; + dlgcode = SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ); + } + + /* Make sure the old default control is a valid push button ID */ + if (!hwndOld || !(SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)) + hwndOld = DEFDLG_FindDefButton( hwndDlg ); + if (hwndOld && hwndOld != hwndNew) + SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE ); + if (hwndNew) { - if(dlgcode==DLGC_UNDEFPUSHBUTTON) + if(dlgcode & DLGC_UNDEFPUSHBUTTON) SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); } return TRUE; @@ -214,7 +254,7 @@ static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam, case DM_SETDEFID: if (dlgInfo && !(dlgInfo->flags & DF_END)) - DEFDLG_SetDefButton( hwnd, dlgInfo, wParam ); + DEFDLG_SetDefId( hwnd, dlgInfo, wParam ); return 1; case DM_GETDEFID: @@ -235,7 +275,7 @@ static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam, if (!lParam) hwndDest = GetNextDlgTabItem(hwnd, GetFocus(), wParam); if (hwndDest) DEFDLG_SetFocus( hwnd, hwndDest ); - DEFDLG_SetDefButton( hwnd, dlgInfo, GetDlgCtrlID(hwndDest) ); + DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest ); } return 0; -- 2.11.4.GIT