[2/2] user32: Preselect all editbox text when combo gets focus

Jason Edmeades jason.edmeades at googlemail.com
Sun Jan 24 15:05:57 CST 2010


-------------- next part --------------
From d7a5fe57ac2d5ee71eab0160d588efb3ee539b1c Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason.edmeades at googlemail.com>
Date: Sun, 24 Jan 2010 12:56:11 -0800
Subject: [PATCH] user32/combo: Select all text when control receives focus for first time

As per the tests submitted previously, it would appear the edit control
for a combo box selects all the text the first time it receives focus.
---
 dlls/user32/combo.c       |   10 ++++++++--
 dlls/user32/controls.h    |    1 +
 dlls/user32/tests/combo.c |    8 ++++----
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/dlls/user32/combo.c b/dlls/user32/combo.c
index 85e372a..d31f17e 100644
--- a/dlls/user32/combo.c
+++ b/dlls/user32/combo.c
@@ -1910,8 +1910,14 @@ LRESULT ComboWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
 	case WM_GETFONT:
 		return  (LRESULT)lphc->hFont;
 	case WM_SETFOCUS:
-		if( lphc->wState & CBF_EDIT )
-		    SetFocus( lphc->hWndEdit );
+               if( lphc->wState & CBF_EDIT ) {
+                   SetFocus( lphc->hWndEdit );
+                   /* The first time focus is received, select all the text */
+                   if( !(lphc->wState & CBF_BEENFOCUSED) ) {
+                       SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, -1);
+                       lphc->wState |= CBF_BEENFOCUSED;
+                   }
+               }
 		else
 		    COMBO_SetFocus( lphc );
 		return  TRUE;
diff --git a/dlls/user32/controls.h b/dlls/user32/controls.h
index 8275ee5..2054922 100644
--- a/dlls/user32/controls.h
+++ b/dlls/user32/controls.h
@@ -199,6 +199,7 @@ extern INT SCROLL_SetNCSbState( HWND hwnd, int vMin, int vMax, int vPos,
 #define CBF_SELCHANGE           0x0400
 #define CBF_NOEDITNOTIFY        0x1000
 #define CBF_NOLBSELECT          0x2000  /* do not change current selection */
+#define CBF_BEENFOCUSED         0x4000  /* has it ever had focus           */
 #define CBF_EUI                 0x8000
 
 /* combo state struct */
diff --git a/dlls/user32/tests/combo.c b/dlls/user32/tests/combo.c
index b0f7488..bee685c 100644
--- a/dlls/user32/tests/combo.c
+++ b/dlls/user32/tests/combo.c
@@ -449,13 +449,13 @@ static void test_editselection(void)
     SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
     len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
     ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
-    todo_wine ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
+    ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
 
     /* Now emulate a key press */
     edit[0] = 0x00;
     SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001);
     SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
-    todo_wine ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit);
+    ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit);
 
     len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
     ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len));
@@ -489,7 +489,7 @@ static void test_editselection(void)
     SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
     len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
     ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
-    todo_wine ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
+    ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
 
     /* Now change the selection to the apparently invalid start -1, end -1 and
        show it means no selection (ie start -1) but cursor at end              */
@@ -497,7 +497,7 @@ static void test_editselection(void)
     edit[0] = 0x00;
     SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001);
     SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
-    todo_wine ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit);
+    ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit);
     DestroyWindow(hCombo);
 }
 
-- 
1.6.0.4


More information about the wine-patches mailing list