dialog: Move default focus assignment into SetFocus() handler

Zach Gorman zach at archetypeauction.com
Thu Sep 9 15:35:49 CDT 2004


The initial dialog focus should be established by the default
handler for SetFocus(), not in the dialog creation code.

This behavior is demonstrated by a user32.dll test in a separate
patch.

Details:
1) When WM_INITDIALOG returns FALSE, focus should be left at
   NULL (or whatever it was previously) and no internal focus
   HWND variable should be saved.
2) When SetFocus is called on a dialog and no internal focus
   HWND variable is currently saved for that dialog, the default
   message handler should re-assign focus to the first visible,
   non-disabled, WS_TABSTOP control in the dialog.


===================================================================
RCS file: /home/wine/wine/windows/dialog.c,v
retrieving revision 1.132
diff -u -r1.132 dialog.c
--- dialog.c	24 Aug 2004 02:26:40 -0000	1.132
+++ dialog.c	9 Sep 2004 20:26:23 -0000
@@ -657,32 +657,14 @@
 
     if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
     {
-        HWND hwndPreInitFocus;
-
         /* Send initialisation messages and set focus */
 
-	dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
-
-	hwndPreInitFocus = GetFocus();
-	if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
+        if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
         {
-            /* check where the focus is again,
-	     * some controls status might have changed in WM_INITDIALOG */
+            /* By returning TRUE, app has requested a default focus assignment */
             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
             if( dlgInfo->hwndFocus )
                 SetFocus( dlgInfo->hwndFocus );
-        }
-        else
-        {
-            /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
-               but the focus has not changed, set the focus where we expect it. */
-            if ((GetFocus() == hwndPreInitFocus) &&
-                (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
-            {
-                dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
-                if( dlgInfo->hwndFocus )
-                    SetFocus( dlgInfo->hwndFocus );
-            }
         }
 
 	if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))


===================================================================
RCS file: /home/wine/wine/windows/defdlg.c,v
retrieving revision 1.34
diff -u -r1.34 defdlg.c
--- defdlg.c	19 Aug 2004 01:03:12 -0000	1.34
+++ defdlg.c	9 Sep 2004 20:26:37 -0000
@@ -96,13 +96,16 @@
 
     if (IsIconic( hwnd )) return;
     if (!(infoPtr = DIALOG_get_info( hwnd, FALSE ))) return;
-    if (!IsWindow( infoPtr->hwndFocus )) return;
     /* Don't set the focus back to controls if EndDialog is already called.*/
-    if (!(infoPtr->flags & DF_END))
-    {
-        DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
-        return;
+    if (infoPtr->flags & DF_END) return;
+    if (!IsWindow(infoPtr->hwndFocus) || infoPtr->hwndFocus == hwnd) {
+        /* If no saved focus control exists, set focus to the first visible,
+           non-disabled, WS_TABSTOP control in the dialog */
+        infoPtr->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
+       if (!IsWindow( infoPtr->hwndFocus )) return;
     }
+    DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
+
     /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
        sometimes losing focus when receiving WM_SETFOCUS messages. */
 }




More information about the wine-patches mailing list