[PATCH 3/3] user32: If a dialog has no tab-accessible controls, set focus to first control (with tests)

Alex Henrie alexhenrie24 at gmail.com
Fri Dec 2 01:37:01 CST 2011


Fixes bug 22848, "Notepad++: Ctrl+tab doesn't work properly".

The MSDN specification for this behavior can be found in the last sentence of
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644995%28v=vs.85%29.aspx#wm_initdialog

---
 dlls/user32/dialog.c          |    2 ++
 dlls/user32/tests/dialog.c    |   28 ++++++++++++++++++++++++++--
 dlls/user32/tests/resource.rc |    8 ++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c
index b9e739a..c6b2455 100644
--- a/dlls/user32/dialog.c
+++ b/dlls/user32/dialog.c
@@ -695,6 +695,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
         if (dlgProc)
         {
             HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
+            if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
             if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) &&
                 ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
             {
@@ -702,6 +703,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
                  * WM_INITDIALOG may have changed the tab order, so find the first
                  * tabstop control again. */
                 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
+                if (!dlgInfo->hwndFocus) dlgInfo->hwndFocus = GetNextDlgGroupItem( hwnd, 0, FALSE );
                 if( dlgInfo->hwndFocus )
                     SetFocus( dlgInfo->hwndFocus );
             }
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index fa14b36..404aeee 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -832,8 +832,7 @@ static void test_initial_focus(void)
 {
     /* Test 1:
      * This test intentionally returns FALSE in response to WM_INITDIALOG
-     * without setting focus to a control. This is not allowed according to
-     * MSDN, but it is exactly what MFC's CFormView does.
+     * without setting focus to a control. This is what MFC's CFormView does.
      *
      * Since the WM_INITDIALOG handler returns FALSE without setting the focus,
      * the focus should initially be NULL. Later, when we manually set focus to
@@ -915,6 +914,31 @@ static void test_initial_focus(void)
 
         DestroyWindow(hDlg);
     }
+
+    /* Test 4:
+     * If the dialog has no tab-accessible controls, set focus to first control */
+    {
+        HWND hDlg;
+        HRSRC hResource;
+        HANDLE hTemplate;
+        DLGTEMPLATE* pTemplate;
+        HWND hLabel;
+
+        hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG_2", RT_DIALOG);
+        hTemplate = LoadResource(g_hinst, hResource);
+        pTemplate = LockResource(hTemplate);
+
+        hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusDlgWinProc, 0);
+        g_hwndInitialFocusT1 = GetFocus();
+        hLabel = GetDlgItem(hDlg, 200);
+        ok (hDlg != 0, "Failed to create test dialog.\n");
+
+        ok ((g_hwndInitialFocusT1 == hLabel),
+            "Focus should have been set to the first control, expected (%p) got (%p).\n",
+            hLabel, g_hwndInitialFocusT1);
+
+        DestroyWindow(hDlg);
+    }
 }
 
 static void test_GetDlgItemText(void)
diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc
index cce1478..be47038 100644
--- a/dlls/user32/tests/resource.rc
+++ b/dlls/user32/tests/resource.rc
@@ -99,6 +99,14 @@ FONT 8, "MS Shell Dlg"
   EDITTEXT                200,4,4,50,14
 }
 
+FOCUS_TEST_DIALOG_2 DIALOG 0, 0, 60, 30
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Test dialog"
+FONT 8, "MS Shell Dlg"
+{
+  LTEXT "Hello world",    200,4,4,50,14
+}
+
 IDD_DIALOG DIALOG  0, 0, 186, 95
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Dialog"
-- 
1.7.4.1





More information about the wine-patches mailing list