[16/18] comctl32: Taskdialog - Implement TDM_ENABLE_BUTTON and add tests

Fabian Maurer dark.shadow4 at web.de
Fri Feb 24 14:04:10 CST 2017


Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>

# Conflicts:
#	dlls/comctl32/tests/taskdialog.c
---
 dlls/comctl32/taskdialog.c       | 31 ++++++++++++-----
 dlls/comctl32/tests/taskdialog.c | 75 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 8 deletions(-)

diff --git a/dlls/comctl32/taskdialog.c b/dlls/comctl32/taskdialog.c
index fcfc1fb243..cf90d9a233 100644
--- a/dlls/comctl32/taskdialog.c
+++ b/dlls/comctl32/taskdialog.c
@@ -314,9 +314,19 @@ static HRESULT callback(taskdialog_info *dialog, UINT uNotification, WPARAM wPar
     return S_OK;
 }
 
+static void click_button(HWND hwndDlg, taskdialog_info *dialog, WORD command_id)
+{
+    HRESULT ret_callback = callback(dialog, TDN_BUTTON_CLICKED, command_id, 0);
+    if(ret_callback == S_OK)
+    {
+        EndDialog(hwndDlg, command_id);
+
+        callback(dialog, TDN_DESTROYED, 0, 0);
+    }
+}
+
 static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-    HRESULT ret_callback;
     taskdialog_info *dialog;
     const TASKDIALOGCONFIG *task_config;
 
@@ -377,14 +387,11 @@ static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
             if(HIWORD(wParam) == BN_CLICKED)
             {
                 WORD command_id = LOWORD(wParam);
+                HWND hwnd_control = GetDlgItem(hwndDlg, command_id);
 
-                ret_callback = callback(dialog, TDN_BUTTON_CLICKED, command_id, 0);
-                if(ret_callback == S_OK)
-                {
-                    EndDialog(hwndDlg, command_id);
+                if(IsWindowEnabled(hwnd_control))
+                    click_button(hwndDlg, dialog, command_id);
 
-                    callback(dialog, TDN_DESTROYED, 0, 0);
-                }
                 return TRUE;
             }
             break;
@@ -392,7 +399,15 @@ static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
         /* Custom messages*/
 
         case TDM_CLICK_BUTTON:
-            SendMessageA(hwndDlg, WM_COMMAND, MAKEWORD(wParam, BN_CLICKED), 0);
+            click_button(hwndDlg, dialog, wParam);
+            break;
+        case TDM_ENABLE_BUTTON:
+            {
+                HWND hwnd_control = GetDlgItem(hwndDlg, wParam);
+                if(!hwnd_control)
+                    break;
+                EnableWindow(hwnd_control, !!lParam);
+            }
             break;
     }
     return FALSE;
diff --git a/dlls/comctl32/tests/taskdialog.c b/dlls/comctl32/tests/taskdialog.c
index 725bcd1b9a..fc27f91ae8 100644
--- a/dlls/comctl32/tests/taskdialog.c
+++ b/dlls/comctl32/tests/taskdialog.c
@@ -112,6 +112,14 @@ static const message_data mes_button_clicked_retry[] = {
     { TDN_NO_MORE_MESSAGES }
 };
 
+static const message_data mes_button_clicked_cancel[] = {
+    { TDN_DIALOG_CONSTRUCTED, 0, 0 },
+    { TDN_CREATED, 0, 0 },
+    { TDN_BUTTON_CLICKED, IDCANCEL, 0 },
+    { TDN_DESTROYED, 0, 0 },
+    { TDN_NO_MORE_MESSAGES }
+};
+
 static const message_data mes_button_clicked_custom4[] = {
     { TDN_DIALOG_CONSTRUCTED, 0, 0 },
     { TDN_CREATED, 0, 0 },
@@ -134,6 +142,50 @@ static const message_send_data mes_send_3_click_button_ok[] = {
     { 0 }
 };
 
+static const message_send_data mes_send_click_cancel_retry[] = {
+    { TDM_CLICK_BUTTON, IDCANCEL, 0 },
+    { TDM_CLICK_BUTTON, IDRETRY, 0 },
+    { 0 }
+};
+
+static const message_send_data mes_send_disable_cancel_click_cancel_retry[] = {
+    { TDM_ENABLE_BUTTON, IDCANCEL, 0 },
+    { TDM_CLICK_BUTTON, IDCANCEL, 0 },
+    { TDM_CLICK_BUTTON, IDRETRY, 0 },
+    { 0 }
+};
+
+static const message_send_data mes_send_disable_test2[] = {
+    { TDM_ENABLE_BUTTON, ID_START_BUTTON, 0 },
+    { WM_LBUTTONDOWN, MK_LBUTTON, 0, "0" },
+    { WM_LBUTTONUP, 0, 0, "0" },
+    { WM_LBUTTONDOWN, MK_LBUTTON, 0, "4" },
+    { WM_LBUTTONUP, 0, 0, "4" },
+    { 0 }
+};
+
+static const message_send_data mes_send_disable_single1[] = {
+    { TDM_ENABLE_BUTTON, IDOK, 0 },
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { TDM_ENABLE_BUTTON, IDOK, 1 },
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { 0 }
+};
+
+static const message_send_data mes_send_disable_single2[] = {
+    { TDM_ENABLE_BUTTON, 0xff, 0 },
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { 0 }
+};
+
+static const message_send_data mes_send_disable_single3[] = {
+    { TDM_ENABLE_BUTTON, IDOK, 0 },
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { TDM_ENABLE_BUTTON, IDOK, 0xff },
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { 0 }
+};
+
 /* Our only way to get a button handle, since GetDlgItem and FindWindowEx don't work for the official taskdialog */
 
 static HWND taskdialog_child;
@@ -435,8 +487,31 @@ static void test_TaskDialogIndirect(void)
     info.nDefaultButton = ID_START_BUTTON + 4;
     run_test(&info, ID_START_BUTTON + 4, 0, 0, mes_button_clicked_custom4, mes_send_return);
 
+    info.nDefaultButton = 0; /* Not needed aynmore, reset it for future tests */
+
+    /* Test TDM_ENABLE_BUTTON */
+
+    /* Send click message to two active buttons too test if second is ignored */
+    run_test(&info, IDCANCEL, 0, 0, mes_button_clicked_cancel, mes_send_click_cancel_retry);
+
+    /* Send taskdialog click message for inactive button, then active */
+    run_test(&info, IDCANCEL, 0, 0, mes_button_clicked_cancel, mes_send_disable_cancel_click_cancel_retry);
 
+    /* Send mouse-down message to inactive button, then active */
+    run_test(&info, ID_START_BUTTON + 4, 0, 0, mes_button_clicked_custom4, mes_send_disable_test2);
+
+    info.cButtons = 0;
     buttons_destroy(info.cButtons, info.pButtons);
+    info.dwCommonButtons = TDCBF_OK_BUTTON;
+
+    /* Test with only OK button: disable, send return, enable, send return */
+    run_test(&info, IDOK, 0, 0, mes_button_clicked_ok, mes_send_disable_single1);
+
+    /* Send message to invalid control, see if our button gets disabled */
+    run_test(&info, IDOK, 0, 0, mes_button_clicked_ok, mes_send_disable_single2);
+
+    /* Send disable message that's not true or false */
+    run_test(&info, IDOK, 0, 0, mes_button_clicked_ok, mes_send_disable_single3);
 }
 
 START_TEST(taskdialog)
-- 
2.11.1




More information about the wine-patches mailing list