[RESEND] user: Select entire text if DLGC_HASSETSEL set

Stefan Siebert stefan.siebert at web.de
Wed Aug 16 04:36:05 CDT 2006


Hello,

this is a resend. Please let me know if there's anything wrong with this 
patch.

This patch fixes bug 5820 (http://bugs.winehq.org/show_bug.cgi?id=5820)
DIALOG_CreateIndirect was missing DLGC_HASSETSEL implementation on
initialization. WM_GETDLGCODE was only queried after a TAB or Mouse 
click to the control, but not if it gets the focus on initialization.

Changelog: user/dialog.c - DIALOG_CreateIndirect - Select entire text if
WM_GETDLGCODE returns DLGC_HASSETSEL

---
Stefan Siebert



-------------- next part --------------
diff --git a/dlls/user/dialog.c b/dlls/user/dialog.c
old mode 100644
new mode 100755
index 6eaa942..1d8bed0
--- a/dlls/user/dialog.c
+++ b/dlls/user/dialog.c
@@ -450,6 +450,35 @@ static LPCSTR DIALOG_ParseTemplate32( LP
 
 
 /***********************************************************************
+ *      DIALOG_SelectTextIfHasSetSel
+ *
+ * Selects the entire text in an edit control if WM_GETDLGCODE returns
+ * DLGC_HASSETSEL
+ */
+ 
+static void DIALOG_SelectTextIfHasSetSel( HWND hwndEdit )
+{
+    MSG msg;
+    LRESULT dlgCode;
+    
+    dlgCode = SendMessageW (hwndEdit, WM_GETDLGCODE, msg.wParam, (LPARAM)&msg);
+    if (dlgCode & DLGC_HASSETSEL)
+    {
+        INT maxlen = 1 + SendMessageW (hwndEdit, WM_GETTEXTLENGTH, 0, 0);
+        WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
+        if (buffer)
+        {
+            INT length;
+            SendMessageW (hwndEdit, WM_GETTEXT, maxlen, (LPARAM) buffer);
+            length = strlenW (buffer);
+            HeapFree (GetProcessHeap(), 0, buffer);
+            SendMessageW (hwndEdit, EM_SETSEL, 0, length);
+        }
+    }
+}
+
+
+/***********************************************************************
  *           DIALOG_CreateIndirect
  *       Creates a dialog box window
  *
@@ -640,7 +669,10 @@ static HWND DIALOG_CreateIndirect( HINST
             /* By returning TRUE, app has requested a default focus assignment */
             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
             if( dlgInfo->hwndFocus )
+            {
+                DIALOG_SelectTextIfHasSetSel(dlgInfo->hwndFocus);   
                 SetFocus( dlgInfo->hwndFocus );
+            }
         }
 
         if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
@@ -1100,21 +1132,7 @@ BOOL WINAPI IsDialogMessageW( HWND hwndD
                             GetKeyState (VK_SHIFT) & 0x8000);
                     if (hwndNext)
                     {
-                        dlgCode = SendMessageW (hwndNext, WM_GETDLGCODE,
-                                msg->wParam, (LPARAM)msg);
-                        if (dlgCode & DLGC_HASSETSEL)
-                        {
-                            INT maxlen = 1 + SendMessageW (hwndNext, WM_GETTEXTLENGTH, 0, 0);
-                            WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
-                            if (buffer)
-                            {
-                                INT length;
-                                SendMessageW (hwndNext, WM_GETTEXT, maxlen, (LPARAM) buffer);
-                                length = strlenW (buffer);
-                                HeapFree (GetProcessHeap(), 0, buffer);
-                                SendMessageW (hwndNext, EM_SETSEL, 0, length);
-                            }
-                        }
+                        DIALOG_SelectTextIfHasSetSel(hwndNext);
                         SetFocus (hwndNext);
                         DIALOG_FixChildrenOnChangeFocus (hwndDlg, hwndNext);
                     }



More information about the wine-patches mailing list