Lei Zhang : user32: Improve cut/copy/paste behavior of password edit
boxes.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Jun 14 07:47:05 CDT 2007
Module: wine
Branch: master
Commit: 7dd98bb993b886922b07954a3956f32763ea58c1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=7dd98bb993b886922b07954a3956f32763ea58c1
Author: Lei Zhang <thestig at google.com>
Date: Wed Jun 13 17:22:49 2007 -0700
user32: Improve cut/copy/paste behavior of password edit boxes.
---
dlls/user32/edit.c | 10 +++++++-
dlls/user32/tests/edit.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c
index 3f2282f..fbc5a00 100644
--- a/dlls/user32/edit.c
+++ b/dlls/user32/edit.c
@@ -4021,14 +4021,15 @@ static void EDIT_WM_Char(EDITSTATE *es, WCHAR c)
}
break;
case 0x03: /* ^C */
- SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
+ if (!(es->style & ES_PASSWORD))
+ SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
break;
case 0x16: /* ^V */
if (!(es->style & ES_READONLY))
SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
break;
case 0x18: /* ^X */
- if (!(es->style & ES_READONLY))
+ if (!((es->style & ES_READONLY) || (es->style & ES_PASSWORD)))
SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
break;
@@ -4949,6 +4950,11 @@ static void EDIT_WM_Paste(EDITSTATE *es)
EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE);
GlobalUnlock(hsrc);
}
+ else if (es->style & ES_PASSWORD) {
+ /* clear selected text in password edit box even with empty clipboard */
+ const WCHAR empty_strW[] = { 0 };
+ EDIT_EM_ReplaceSel(es, TRUE, empty_strW, TRUE, TRUE);
+ }
CloseClipboard();
}
diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c
index ee61085..2bdf0ed 100644
--- a/dlls/user32/tests/edit.c
+++ b/dlls/user32/tests/edit.c
@@ -1003,6 +1003,53 @@ static void test_text_position(void)
test_text_position_style(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL);
}
+static void test_espassword(void)
+{
+ HWND hwEdit;
+ MSG msMessage;
+ LONG r;
+ char buffer[1024];
+ const char* password = "secret";
+
+ msMessage.message = WM_KEYDOWN;
+
+ hwEdit = create_editcontrol(ES_PASSWORD, 0);
+ r = get_edit_style(hwEdit);
+ ok(r == ES_PASSWORD, "Wrong style expected 0x%x got: 0x%x\n", ES_PASSWORD, r);
+ /* set text */
+ r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) password);
+ ok(r == TRUE, "Expected: %d, got: %d\n", TRUE, r);
+
+ /* select all, cut (ctrl-x) */
+ SendMessage(hwEdit, EM_SETSEL, 0, -1);
+ SendMessage(hwEdit, WM_CHAR, 24, 0);
+
+ /* get text */
+ r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
+ ok(r == strlen(password), "Expected: %d, got: %d\n", strlen(password), r);
+ ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
+
+ r = OpenClipboard(hwEdit);
+ ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
+ r = EmptyClipboard();
+ ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
+ r = CloseClipboard();
+ ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
+
+ /* select all, copy (ctrl-c) and paste (ctrl-v) */
+ SendMessage(hwEdit, EM_SETSEL, 0, -1);
+ SendMessage(hwEdit, WM_CHAR, 3, 0);
+ SendMessage(hwEdit, WM_CHAR, 22, 0);
+
+ /* get text */
+ buffer[0] = 0;
+ r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
+ ok(r == 0, "Expected: 0, got: %d\n", r);
+ ok(strcmp(buffer, "") == 0, "expected empty string, got %s\n", buffer);
+
+ DestroyWindow (hwEdit);
+}
+
static BOOL RegisterWindowClasses (void)
{
WNDCLASSA test2;
@@ -1068,6 +1115,7 @@ START_TEST(edit)
test_margins();
test_margins_font_change();
test_text_position();
+ test_espassword();
UnregisterWindowClasses();
}
More information about the wine-cvs
mailing list