1 /* Unit test suite for edit control.
3 * Copyright 2004 Vitaliy Margolen
4 * Copyright 2005 C. Scott Ananian
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
28 #define ES_COMBO 0x200
31 #define ID_EDITTESTDBUTTON 0x123
32 #define ID_EDITTEST2 99
36 int en_change, en_maxtext, en_update;
39 static struct edit_notify notifications;
41 static BOOL (WINAPI *pEndMenu) (void);
43 static void init_function_pointers(void)
45 HMODULE hdll = GetModuleHandleA("user32");
47 pEndMenu = (void*)GetProcAddress(hdll, "EndMenu");
50 static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
52 static int num_ok_commands = 0;
57 HWND hedit = GetDlgItem(hdlg, 1000);
61 /* test cases related to bug 12319 */
63 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
64 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
67 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
68 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
71 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
72 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
73 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
76 /* test cases for pressing enter */
79 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
80 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
90 if (HIWORD(wparam) != BN_CLICKED)
93 switch (LOWORD(wparam))
106 HWND hfocus = GetFocus();
107 HWND hedit = GetDlgItem(hdlg, 1000);
108 HWND hedit2 = GetDlgItem(hdlg, 1001);
109 HWND hedit3 = GetDlgItem(hdlg, 1002);
111 if (wparam != 0xdeadbeef)
118 EndDialog(hdlg, 1111);
119 else if (hfocus == hedit2)
120 EndDialog(hdlg, 2222);
121 else if (hfocus == hedit3)
122 EndDialog(hdlg, 3333);
124 EndDialog(hdlg, 4444);
127 if ((hfocus == hedit) && (num_ok_commands == 0))
133 EndDialog(hdlg, 5555);
139 EndDialog(hdlg, 333);
149 static INT_PTR CALLBACK edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
155 HWND hedit = GetDlgItem(hdlg, 1000);
161 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
164 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
167 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
168 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
171 /* more test cases for WM_CHAR */
173 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
174 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
177 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
178 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
181 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
182 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
185 /* more test cases for WM_KEYDOWN + WM_CHAR */
187 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
188 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
189 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
192 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
193 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
194 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
197 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
198 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
199 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
202 /* multiple tab tests */
204 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
205 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
206 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
209 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
210 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
211 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
212 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
222 if (HIWORD(wparam) != BN_CLICKED)
225 switch (LOWORD(wparam))
228 EndDialog(hdlg, 111);
232 EndDialog(hdlg, 222);
243 HWND hok = GetDlgItem(hdlg, IDOK);
244 HWND hcancel = GetDlgItem(hdlg, IDCANCEL);
245 HWND hedit = GetDlgItem(hdlg, 1000);
246 HWND hfocus = GetFocus();
248 if (wparam != 0xdeadbeef)
254 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
256 EndDialog(hdlg, 444);
258 EndDialog(hdlg, 555);
262 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
263 if ((hfocus == hok) && len == 0)
264 EndDialog(hdlg, 444);
266 EndDialog(hdlg, 555);
272 else if (hfocus == hcancel)
274 else if (hfocus == hedit)
281 EndDialog(hdlg, 555);
287 EndDialog(hdlg, 333);
297 static INT_PTR CALLBACK edit_singleline_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
303 HWND hedit = GetDlgItem(hdlg, 1000);
307 /* test cases for WM_KEYDOWN */
309 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
312 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
315 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
316 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
319 /* test cases for WM_CHAR */
321 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
322 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
325 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
326 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
329 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
330 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
333 /* test cases for WM_KEYDOWN + WM_CHAR */
335 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
336 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
339 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
340 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
343 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
344 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
345 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
355 if (HIWORD(wparam) != BN_CLICKED)
358 switch (LOWORD(wparam))
361 EndDialog(hdlg, 111);
365 EndDialog(hdlg, 222);
375 HWND hok = GetDlgItem(hdlg, IDOK);
376 HWND hedit = GetDlgItem(hdlg, 1000);
377 HWND hfocus = GetFocus();
378 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
380 if (wparam != 0xdeadbeef)
386 if ((hfocus == hedit) && len == 0)
387 EndDialog(hdlg, 444);
389 EndDialog(hdlg, 555);
393 if ((hfocus == hok) && len == 0)
394 EndDialog(hdlg, 444);
396 EndDialog(hdlg, 555);
406 EndDialog(hdlg, 333);
416 static INT_PTR CALLBACK edit_wantreturn_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
422 HWND hedit = GetDlgItem(hdlg, 1000);
426 /* test cases for WM_KEYDOWN */
428 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
431 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
432 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
435 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
436 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
439 /* test cases for WM_CHAR */
441 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
442 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
445 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
446 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
449 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
450 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
453 /* test cases for WM_KEYDOWN + WM_CHAR */
455 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
456 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
457 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
460 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
461 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
462 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
465 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
466 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
467 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
477 if (HIWORD(wparam) != BN_CLICKED)
480 switch (LOWORD(wparam))
483 EndDialog(hdlg, 111);
487 EndDialog(hdlg, 222);
497 HWND hok = GetDlgItem(hdlg, IDOK);
498 HWND hedit = GetDlgItem(hdlg, 1000);
499 HWND hfocus = GetFocus();
500 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
502 if (wparam != 0xdeadbeef)
508 if ((hfocus == hedit) && len == 0)
509 EndDialog(hdlg, 444);
511 EndDialog(hdlg, 555);
515 if ((hfocus == hok) && len == 0)
516 EndDialog(hdlg, 444);
518 EndDialog(hdlg, 555);
522 if ((hfocus == hedit) && len == 2)
523 EndDialog(hdlg, 444);
525 EndDialog(hdlg, 555);
535 EndDialog(hdlg, 333);
545 static HINSTANCE hinst;
547 static const char szEditTest2Class[] = "EditTest2Class";
548 static const char szEditTest3Class[] = "EditTest3Class";
549 static const char szEditTest4Class[] = "EditTest4Class";
550 static const char szEditTextPositionClass[] = "EditTextPositionWindowClass";
552 static HWND create_editcontrol (DWORD style, DWORD exstyle)
556 handle = CreateWindowEx(exstyle,
561 NULL, NULL, hinst, NULL);
562 ok (handle != NULL, "CreateWindow EDIT Control failed\n");
564 if (winetest_interactive)
565 ShowWindow (handle, SW_SHOW);
569 static HWND create_child_editcontrol (DWORD style, DWORD exstyle)
580 b = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
581 ok(b, "AdjustWindowRect failed\n");
583 parentWnd = CreateWindowEx(0,
584 szEditTextPositionClass,
587 CW_USEDEFAULT, CW_USEDEFAULT,
588 rect.right - rect.left, rect.bottom - rect.top,
589 NULL, NULL, hinst, NULL);
590 ok (parentWnd != NULL, "CreateWindow EDIT Test failed\n");
593 editWnd = CreateWindowEx(exstyle,
598 parentWnd, NULL, hinst, NULL);
599 ok (editWnd != NULL, "CreateWindow EDIT Test Text failed\n");
601 if (winetest_interactive)
602 ShowWindow (parentWnd, SW_SHOW);
606 static void destroy_child_editcontrol (HWND hwndEdit)
608 if (GetParent(hwndEdit))
609 DestroyWindow(GetParent(hwndEdit));
611 trace("Edit control has no parent!\n");
612 DestroyWindow(hwndEdit);
616 static LONG get_edit_style (HWND hwnd)
618 return GetWindowLongA( hwnd, GWL_STYLE ) & (
620 /* FIXME: not implemented
639 static void set_client_height(HWND Wnd, unsigned Height)
641 RECT ClientRect, WindowRect;
643 GetWindowRect(Wnd, &WindowRect);
644 GetClientRect(Wnd, &ClientRect);
645 SetWindowPos(Wnd, NULL, 0, 0,
646 WindowRect.right - WindowRect.left,
647 Height + (WindowRect.bottom - WindowRect.top) -
648 (ClientRect.bottom - ClientRect.top),
649 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
651 /* Workaround for a bug in Windows' edit control
653 GetWindowRect(Wnd, &WindowRect);
654 SetWindowPos(Wnd, NULL, 0, 0,
655 WindowRect.right - WindowRect.left + 1,
656 WindowRect.bottom - WindowRect.top + 1,
657 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
658 SetWindowPos(Wnd, NULL, 0, 0,
659 WindowRect.right - WindowRect.left,
660 WindowRect.bottom - WindowRect.top,
661 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
663 GetClientRect(Wnd, &ClientRect);
664 ok(ClientRect.bottom - ClientRect.top == Height,
665 "The client height should be %d, but is %d\n",
666 Height, ClientRect.bottom - ClientRect.top);
669 static void test_edit_control_1(void)
676 msMessage.message = WM_KEYDOWN;
678 trace("EDIT: Single line\n");
679 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
680 r = get_edit_style(hwEdit);
681 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%x\n", r);
682 for (i=0;i<65535;i++)
684 msMessage.wParam = i;
685 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
686 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
687 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
689 DestroyWindow (hwEdit);
691 trace("EDIT: Single line want returns\n");
692 hwEdit = create_editcontrol(ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
693 r = get_edit_style(hwEdit);
694 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%x\n", r);
695 for (i=0;i<65535;i++)
697 msMessage.wParam = i;
698 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
699 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
700 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
702 DestroyWindow (hwEdit);
704 trace("EDIT: Multiline line\n");
705 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
706 r = get_edit_style(hwEdit);
707 ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%x\n", r);
708 for (i=0;i<65535;i++)
710 msMessage.wParam = i;
711 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
712 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
713 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
715 DestroyWindow (hwEdit);
717 trace("EDIT: Multi line want returns\n");
718 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
719 r = get_edit_style(hwEdit);
720 ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%x\n", r);
721 for (i=0;i<65535;i++)
723 msMessage.wParam = i;
724 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
725 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
726 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
728 DestroyWindow (hwEdit);
731 /* WM_SETTEXT is implemented by selecting all text, and then replacing the
732 * selection. This test checks that the first 'select all' doesn't generate
733 * an UPDATE message which can escape and (via a handler) change the
734 * selection, which would cause WM_SETTEXT to break. This old bug
735 * was fixed 18-Mar-2005; we check here to ensure it doesn't regress.
737 static void test_edit_control_2(void)
739 HWND hwndMain, phwnd;
740 char szLocalString[MAXLEN];
741 LONG r, w = 150, h = 50;
744 /* Create main and edit windows. */
745 hwndMain = CreateWindow(szEditTest2Class, "ET2", WS_OVERLAPPEDWINDOW,
746 0, 0, 200, 200, NULL, NULL, hinst, NULL);
748 if (winetest_interactive)
749 ShowWindow (hwndMain, SW_SHOW);
751 hwndET2 = CreateWindow("EDIT", NULL,
752 WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
753 0, 0, w, h, /* important this not be 0 size. */
754 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
756 if (winetest_interactive)
757 ShowWindow (hwndET2, SW_SHOW);
759 trace("EDIT: SETTEXT atomicity\n");
760 /* Send messages to "type" in the word 'foo'. */
761 r = SendMessage(hwndET2, WM_CHAR, 'f', 1);
762 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
763 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
764 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
765 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
766 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
767 /* 'foo' should have been changed to 'bar' by the UPDATE handler. */
768 GetWindowText(hwndET2, szLocalString, MAXLEN);
769 ok(lstrcmp(szLocalString, "bar")==0,
770 "Wrong contents of edit: %s\n", szLocalString);
772 /* try setting the caret before it's visible */
773 r = SetCaretPos(0, 0);
774 todo_wine ok(0 == r, "SetCaretPos succeeded unexpectedly, expected: 0, got: %d\n", r);
775 phwnd = SetFocus(hwndET2);
776 ok(phwnd != NULL, "SetFocus failed unexpectedly, expected non-zero, got NULL\n");
777 r = SetCaretPos(0, 0);
778 ok(1 == r, "SetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
779 r = GetCaretPos(&cpos);
780 ok(1 == r, "GetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
781 ok(cpos.x == 0 && cpos.y == 0, "Wrong caret position, expected: (0,0), got: (%d,%d)\n", cpos.x, cpos.y);
782 r = SetCaretPos(-1, -1);
783 ok(1 == r, "SetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
784 r = GetCaretPos(&cpos);
785 ok(1 == r, "GetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
786 ok(cpos.x == -1 && cpos.y == -1, "Wrong caret position, expected: (-1,-1), got: (%d,%d)\n", cpos.x, cpos.y);
787 r = SetCaretPos(w << 1, h << 1);
788 ok(1 == r, "SetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
789 r = GetCaretPos(&cpos);
790 ok(1 == r, "GetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
791 ok(cpos.x == (w << 1) && cpos.y == (h << 1), "Wrong caret position, expected: (%d,%d), got: (%d,%d)\n", w << 1, h << 1, cpos.x, cpos.y);
792 r = SetCaretPos(w, h);
793 ok(1 == r, "SetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
794 r = GetCaretPos(&cpos);
795 ok(1 == r, "GetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
796 ok(cpos.x == w && cpos.y == h, "Wrong caret position, expected: (%d,%d), got: (%d,%d)\n", w, h, cpos.x, cpos.y);
797 r = SetCaretPos(w - 1, h - 1);
798 ok(1 == r, "SetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
799 r = GetCaretPos(&cpos);
800 ok(1 == r, "GetCaretPos failed unexpectedly, expected: 1, got: %d\n", r);
801 ok(cpos.x == (w - 1) && cpos.y == (h - 1), "Wrong caret position, expected: (%d,%d), got: (%d,%d)\n", w - 1, h - 1, cpos.x, cpos.y);
804 DestroyWindow (hwndET2);
805 DestroyWindow (hwndMain);
808 static void ET2_check_change(void) {
809 char szLocalString[MAXLEN];
810 /* This EN_UPDATE handler changes any 'foo' to 'bar'. */
811 GetWindowText(hwndET2, szLocalString, MAXLEN);
812 if (lstrcmp(szLocalString, "foo")==0) {
813 lstrcpy(szLocalString, "bar");
814 SendMessage(hwndET2, WM_SETTEXT, 0, (LPARAM) szLocalString);
816 /* always leave the cursor at the end. */
817 SendMessage(hwndET2, EM_SETSEL, MAXLEN - 1, MAXLEN - 1);
819 static void ET2_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
821 if (id==ID_EDITTEST2 && codeNotify == EN_UPDATE)
824 static LRESULT CALLBACK ET2_WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
828 ET2_OnCommand(hwnd, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
831 return DefWindowProc(hwnd, iMsg, wParam, lParam);
834 static void zero_notify(void)
836 notifications.en_change = 0;
837 notifications.en_maxtext = 0;
838 notifications.en_update = 0;
841 #define test_notify(enchange, enmaxtext, enupdate) \
842 ok(notifications.en_change == enchange, "expected %d EN_CHANGE notifications, " \
843 "got %d\n", enchange, notifications.en_change); \
844 ok(notifications.en_maxtext == enmaxtext, "expected %d EN_MAXTEXT notifications, " \
845 "got %d\n", enmaxtext, notifications.en_maxtext); \
846 ok(notifications.en_update == enupdate, "expected %d EN_UPDATE notifications, " \
847 "got %d\n", enupdate, notifications.en_update)
850 static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
854 switch (HIWORD(wParam)) {
856 notifications.en_maxtext++;
859 notifications.en_update++;
862 notifications.en_change++;
867 return DefWindowProcA(hWnd, msg, wParam, lParam);
870 /* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
873 static void test_edit_control_3(void)
879 static const char *str = "this is a long string.";
880 static const char *str2 = "this is a long string.\r\nthis is a long string.\r\nthis is a long string.\r\nthis is a long string.";
883 dpi = GetDeviceCaps(hDC, LOGPIXELSY);
884 ReleaseDC(NULL, hDC);
886 trace("EDIT: Test notifications\n");
888 hParent = CreateWindowExA(0,
892 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10,
893 NULL, NULL, NULL, NULL);
896 trace("EDIT: Single line, no ES_AUTOHSCROLL\n");
897 hWnd = CreateWindowExA(0,
902 hParent, NULL, NULL, NULL);
906 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
907 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
908 ok(lstrlenA(str) > len, "text should have been truncated\n");
909 test_notify(1, 1, 1);
911 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
913 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
914 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
915 ok(1 == len, "wrong text length, expected 1, got %d\n", len);
916 test_notify(1, 0, 1);
919 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
920 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
921 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
922 test_notify(1, 0, 1);
924 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
925 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
926 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
927 SendMessage(hParent, WM_SETFOCUS, 0, (LPARAM)hWnd);
928 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
929 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
930 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
932 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
934 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
936 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
937 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
938 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
939 test_notify(1, 1, 1);
942 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
943 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
944 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
945 test_notify(1, 0, 1);
949 trace("EDIT: Single line, ES_AUTOHSCROLL\n");
950 hWnd = CreateWindowExA(0,
955 hParent, NULL, NULL, NULL);
959 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
960 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
961 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
962 test_notify(1, 0, 1);
965 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
966 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
967 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
968 test_notify(1, 0, 1);
970 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
972 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
974 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
975 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
976 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
977 test_notify(1, 1, 1);
980 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
981 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
982 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
983 test_notify(1, 0, 1);
987 trace("EDIT: Multline, no ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
988 hWnd = CreateWindowExA(0,
992 10, 10, (50 * dpi) / 96, (50 * dpi) / 96,
993 hParent, NULL, NULL, NULL);
997 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
998 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
999 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
1000 test_notify(1, 1, 1);
1002 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1004 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
1005 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1006 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
1007 test_notify(1, 0, 1);
1010 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
1011 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1012 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1013 test_notify(0, 0, 0);
1015 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1017 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1019 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
1020 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1021 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1022 test_notify(1, 1, 1);
1025 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
1026 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1027 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1028 test_notify(0, 0, 0);
1030 DestroyWindow(hWnd);
1032 trace("EDIT: Multline, ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
1033 hWnd = CreateWindowExA(0,
1036 ES_MULTILINE | ES_AUTOHSCROLL,
1037 10, 10, (50 * dpi) / 96, (50 * dpi) / 96,
1038 hParent, NULL, NULL, NULL);
1042 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1043 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1044 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
1045 test_notify(1, 1, 1);
1047 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1049 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
1050 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1051 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
1052 test_notify(1, 0, 1);
1055 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1056 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1057 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1058 test_notify(0, 0, 0);
1060 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1062 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1064 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1065 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1066 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1067 test_notify(1, 1, 1);
1070 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1071 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1072 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1073 test_notify(0, 0, 0);
1075 DestroyWindow(hWnd);
1077 trace("EDIT: Multline, ES_AUTOHSCROLL and ES_AUTOVSCROLL\n");
1078 hWnd = CreateWindowExA(0,
1081 ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
1083 hParent, NULL, NULL, NULL);
1087 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1088 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1089 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1090 test_notify(1, 0, 1);
1093 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1094 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1095 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1096 test_notify(0, 0, 0);
1098 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1100 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1102 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1103 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1104 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1105 test_notify(1, 1, 1);
1108 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1109 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1110 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1111 test_notify(0, 0, 0);
1113 DestroyWindow(hWnd);
1116 /* Test EM_CHARFROMPOS and EM_POSFROMCHAR
1118 static void test_edit_control_4(void)
1125 trace("EDIT: Test EM_CHARFROMPOS and EM_POSFROMCHAR\n");
1126 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1127 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1128 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1129 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1130 mid = lo + (hi - lo) / 2;
1132 for (i = lo; i < mid; i++) {
1133 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1134 ok(0 == ret, "expected 0 got %d\n", ret);
1136 for (i = mid; i <= hi; i++) {
1137 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1138 ok(1 == ret, "expected 1 got %d\n", ret);
1140 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1141 ok(-1 == ret, "expected -1 got %d\n", ret);
1142 DestroyWindow(hwEdit);
1144 hwEdit = create_editcontrol(ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1145 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1146 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1147 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1148 mid = lo + (hi - lo) / 2;
1150 for (i = lo; i < mid; i++) {
1151 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1152 ok(0 == ret, "expected 0 got %d\n", ret);
1154 for (i = mid; i <= hi; i++) {
1155 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1156 ok(1 == ret, "expected 1 got %d\n", ret);
1158 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1159 ok(-1 == ret, "expected -1 got %d\n", ret);
1160 DestroyWindow(hwEdit);
1162 hwEdit = create_editcontrol(ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1163 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1164 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1165 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1166 mid = lo + (hi - lo) / 2;
1168 for (i = lo; i < mid; i++) {
1169 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1170 ok(0 == ret, "expected 0 got %d\n", ret);
1172 for (i = mid; i <= hi; i++) {
1173 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1174 ok(1 == ret, "expected 1 got %d\n", ret);
1176 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1177 ok(-1 == ret, "expected -1 got %d\n", ret);
1178 DestroyWindow(hwEdit);
1180 hwEdit = create_editcontrol(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1181 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1182 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1183 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1184 mid = lo + (hi - lo) / 2 +1;
1186 for (i = lo; i < mid; i++) {
1187 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1188 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1190 for (i = mid; i <= hi; i++) {
1191 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1192 ok(1 == ret, "expected 1 got %d\n", ret);
1194 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1195 ok(-1 == ret, "expected -1 got %d\n", ret);
1196 DestroyWindow(hwEdit);
1198 hwEdit = create_editcontrol(ES_MULTILINE | ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1199 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1200 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1201 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1202 mid = lo + (hi - lo) / 2 +1;
1204 for (i = lo; i < mid; i++) {
1205 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1206 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1208 for (i = mid; i <= hi; i++) {
1209 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1210 ok(1 == ret, "expected 1 got %d\n", ret);
1212 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1213 ok(-1 == ret, "expected -1 got %d\n", ret);
1214 DestroyWindow(hwEdit);
1216 hwEdit = create_editcontrol(ES_MULTILINE | ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1217 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1218 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1219 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1220 mid = lo + (hi - lo) / 2 +1;
1222 for (i = lo; i < mid; i++) {
1223 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1224 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1226 for (i = mid; i <= hi; i++) {
1227 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1228 ok(1 == ret, "expected 1 got %d\n", ret);
1230 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1231 ok(-1 == ret, "expected -1 got %d\n", ret);
1232 DestroyWindow(hwEdit);
1235 /* Test if creating edit control without ES_AUTOHSCROLL and ES_AUTOVSCROLL
1236 * truncates text that doesn't fit.
1238 static void test_edit_control_5(void)
1240 static const char *str = "test\r\ntest";
1244 RECT rc1 = { 10, 10, 11, 11};
1247 /* first show that a non-child won't do for this test */
1248 hWnd = CreateWindowEx(0,
1253 NULL, NULL, NULL, NULL);
1255 /* size of non-child edit control is (much) bigger than requested */
1256 GetWindowRect( hWnd, &rc);
1257 ok( rc.right - rc.left > 20, "size of the window (%d) is smaller than expected\n",
1258 rc.right - rc.left);
1259 DestroyWindow(hWnd);
1260 /* so create a parent, and give it edit controls children to test with */
1261 parentWnd = CreateWindowEx(0,
1262 szEditTextPositionClass,
1263 "Edit Test", WS_VISIBLE |
1264 WS_OVERLAPPEDWINDOW,
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1267 NULL, NULL, hinst, NULL);
1269 ShowWindow( parentWnd, SW_SHOW);
1271 hWnd = CreateWindowEx(0,
1273 str, WS_VISIBLE | WS_BORDER |
1275 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1276 parentWnd, NULL, NULL, NULL);
1278 GetClientRect( hWnd, &rc);
1279 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1280 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1281 rc.left, rc.top, rc.right, rc.bottom);
1282 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1283 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1284 DestroyWindow(hWnd);
1286 hWnd = CreateWindowEx(0,
1289 WS_CHILD | ES_MULTILINE,
1290 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1291 parentWnd, NULL, NULL, NULL);
1293 GetClientRect( hWnd, &rc);
1294 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1295 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1296 rc.left, rc.top, rc.right, rc.bottom);
1297 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1298 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1299 DestroyWindow(hWnd);
1302 /* Test WM_GETTEXT processing
1303 * after destroy messages
1305 static void test_edit_control_6(void)
1307 static const char *str = "test\r\ntest";
1312 hWnd = CreateWindowEx(0,
1317 NULL, NULL, hinst, NULL);
1320 ret = SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
1321 ok(ret == TRUE, "Expected %d, got %d\n", TRUE, ret);
1322 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1323 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1324 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1326 ret = SendMessageA(hWnd, WM_DESTROY, 0, 0);
1327 ok(ret == 0, "Expected 0, got %d\n", ret);
1328 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1329 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1330 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1332 ret = SendMessageA(hWnd, WM_NCDESTROY, 0, 0);
1333 ok(ret == 0, "Expected 0, got %d\n", ret);
1334 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1335 ok(ret == 0, "Expected 0, got len %d\n", ret);
1336 ok(!lstrcmp(buf, ""), "Expected empty string, got %s\n", buf);
1338 DestroyWindow(hWnd);
1341 static void test_edit_control_limittext(void)
1346 /* Test default limit for single-line control */
1347 trace("EDIT: buffer limit for single-line\n");
1348 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1349 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1350 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1351 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1352 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1353 ok( r == 2147483646, "got limit %u (expected 2147483646)\n", r);
1354 DestroyWindow(hwEdit);
1356 /* Test default limit for multi-line control */
1357 trace("EDIT: buffer limit for multi-line\n");
1358 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1359 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1360 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1361 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1362 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1363 ok( r == 4294967295U, "got limit %u (expected 4294967295)\n", r);
1364 DestroyWindow(hwEdit);
1367 /* Test EM_SCROLL */
1368 static void test_edit_control_scroll(void)
1370 static const char *single_line_str = "a";
1371 static const char *multiline_str = "Test\r\nText";
1375 /* Check the return value when EM_SCROLL doesn't scroll
1376 * anything. Should not return true unless any lines were actually
1378 hwEdit = CreateWindow(
1381 WS_VSCROLL | ES_MULTILINE,
1383 NULL, NULL, hinst, NULL);
1387 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1388 ok(!ret, "Returned %x, expected 0.\n", ret);
1390 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEUP, 0);
1391 ok(!ret, "Returned %x, expected 0.\n", ret);
1393 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEUP, 0);
1394 ok(!ret, "Returned %x, expected 0.\n", ret);
1396 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEDOWN, 0);
1397 ok(!ret, "Returned %x, expected 0.\n", ret);
1399 DestroyWindow (hwEdit);
1401 /* SB_PAGEDOWN while at the beginning of a buffer with few lines
1402 should not cause EM_SCROLL to return a negative value of
1403 scrolled lines that would put us "before" the beginning. */
1404 hwEdit = CreateWindow(
1407 WS_VSCROLL | ES_MULTILINE,
1409 NULL, NULL, hinst, NULL);
1412 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1413 ok(!ret, "Returned %x, expected 0.\n", ret);
1415 DestroyWindow (hwEdit);
1418 static void test_margins(void)
1421 RECT old_rect, new_rect;
1422 INT old_right_margin;
1423 DWORD old_margins, new_margins;
1425 hwEdit = create_editcontrol(WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1427 old_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1428 old_right_margin = HIWORD(old_margins);
1430 /* Check if setting the margins works */
1432 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(10, 0));
1433 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1434 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1435 ok(HIWORD(new_margins) == old_right_margin, "Wrong right margin: %d\n", HIWORD(new_margins));
1437 SendMessage(hwEdit, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, 10));
1438 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1439 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1440 ok(HIWORD(new_margins) == 10, "Wrong right margin: %d\n", HIWORD(new_margins));
1443 /* The size of the rectangle must decrease if we increase the margin */
1445 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5));
1446 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1447 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(15, 20));
1448 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1449 ok(new_rect.left == old_rect.left + 10, "The left border of the rectangle is wrong\n");
1450 ok(new_rect.right == old_rect.right - 15, "The right border of the rectangle is wrong\n");
1451 ok(new_rect.top == old_rect.top, "The top border of the rectangle must not change\n");
1452 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle must not change\n");
1455 /* If we set the margin to same value as the current margin,
1456 the rectangle must not change */
1458 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1460 old_rect.right = 99;
1462 old_rect.bottom = 99;
1463 SendMessage(hwEdit, EM_SETRECT, 0, (LPARAM)&old_rect);
1464 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1465 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1466 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1467 ok(new_rect.left == old_rect.left, "The left border of the rectangle has changed\n");
1468 ok(new_rect.right == old_rect.right, "The right border of the rectangle has changed\n");
1469 ok(new_rect.top == old_rect.top, "The top border of the rectangle has changed\n");
1470 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n");
1472 DestroyWindow (hwEdit);
1475 static INT CALLBACK find_font_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
1480 static void test_margins_font_change(void)
1483 DWORD margins, font_margins;
1485 HFONT hfont, hfont2;
1488 if(EnumFontFamiliesA(hdc, "Arial", find_font_proc, 0))
1490 trace("Arial not found - skipping font change margin tests\n");
1496 hwEdit = create_child_editcontrol(0, 0);
1498 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1500 memset(&lf, 0, sizeof(lf));
1501 strcpy(lf.lfFaceName, "Arial");
1503 lf.lfCharSet = DEFAULT_CHARSET;
1504 hfont = CreateFontIndirectA(&lf);
1506 hfont2 = CreateFontIndirectA(&lf);
1508 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1509 font_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1510 ok(LOWORD(font_margins) != 0, "got %d\n", LOWORD(font_margins));
1511 ok(HIWORD(font_margins) != 0, "got %d\n", HIWORD(font_margins));
1513 /* With 'small' edit controls, test that the margin doesn't get set */
1514 SetWindowPos(hwEdit, NULL, 10, 10, 16, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1515 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0,0));
1516 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1517 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1518 ok(LOWORD(margins) == 0 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1519 "got %d\n", LOWORD(margins));
1520 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1521 "got %d\n", HIWORD(margins));
1523 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1524 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1525 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1526 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1527 "got %d\n", LOWORD(margins));
1528 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1529 "got %d\n", HIWORD(margins));
1531 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1532 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1533 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1534 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1535 "got %d\n", LOWORD(margins));
1536 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1537 "got %d\n", HIWORD(margins));
1539 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1540 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1541 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1542 "got %d\n", LOWORD(margins));
1543 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1544 "got %d\n", HIWORD(margins));
1546 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1547 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1548 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) != 1 && LOWORD(margins) != LOWORD(font_margins)), /* win95 */
1549 "got %d\n", LOWORD(margins));
1550 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) != 1 && HIWORD(margins) != HIWORD(font_margins)), /* win95 */
1551 "got %d\n", HIWORD(margins));
1553 /* Above a certain size threshold then the margin is updated */
1554 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1555 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1556 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1557 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1558 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1559 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1561 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1562 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1563 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1564 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1565 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1567 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1568 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1569 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1570 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1571 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1572 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1573 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1574 ok(LOWORD(margins) != LOWORD(font_margins) || broken(LOWORD(margins) == LOWORD(font_margins)), /* win98 */
1575 "got %d\n", LOWORD(margins));
1576 ok(HIWORD(margins) != HIWORD(font_margins), "got %d\n", HIWORD(margins));
1578 SendMessageA(hwEdit, WM_SETFONT, 0, 0);
1580 DeleteObject(hfont2);
1581 DeleteObject(hfont);
1582 destroy_child_editcontrol(hwEdit);
1586 #define edit_pos_ok(exp, got, txt) \
1587 ok(exp == got, "wrong " #txt " expected %d got %d\n", exp, got);
1589 #define check_pos(hwEdit, set_height, test_top, test_height, test_left) \
1593 set_client_height(hwEdit, set_height); \
1594 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &format_rect); \
1595 left_margin = LOWORD(SendMessage(hwEdit, EM_GETMARGINS, 0, 0)); \
1596 edit_pos_ok(test_top, format_rect.top, vertical position); \
1597 edit_pos_ok((int)test_height, format_rect.bottom - format_rect.top, height); \
1598 edit_pos_ok(test_left, format_rect.left - left_margin, left); \
1601 static void test_text_position_style(DWORD style)
1604 HFONT font, oldFont;
1608 BOOL xb, single_line = !(style & ES_MULTILINE);
1610 b = GetSystemMetrics(SM_CYBORDER) + 1;
1615 /* Get a stock font for which we can determine the metrics */
1616 font = GetStockObject(SYSTEM_FONT);
1617 ok (font != NULL, "GetStockObjcet SYSTEM_FONT failed\n");
1619 ok (dc != NULL, "GetDC() failed\n");
1620 oldFont = SelectObject(dc, font);
1621 xb = GetTextMetrics(dc, &metrics);
1622 ok (xb, "GetTextMetrics failed\n");
1623 SelectObject(dc, oldFont);
1624 ReleaseDC(NULL, dc);
1626 /* Windows' edit control has some bugs in multi-line mode:
1627 * - Sometimes the format rectangle doesn't get updated
1628 * (see workaround in set_client_height())
1629 * - If the height of the control is smaller than the height of a text
1630 * line, the format rectangle is still as high as a text line
1631 * (higher than the client rectangle) and the caret is not shown
1634 /* Edit controls that are in a parent window */
1636 hwEdit = create_child_editcontrol(style | WS_VISIBLE, 0);
1637 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1639 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1640 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1641 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1642 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1643 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1644 destroy_child_editcontrol(hwEdit);
1646 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, 0);
1647 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1649 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1650 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1651 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1652 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1653 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1654 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1655 destroy_child_editcontrol(hwEdit);
1657 hwEdit = create_child_editcontrol(style | WS_VISIBLE, WS_EX_CLIENTEDGE);
1658 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1660 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1661 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1662 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1663 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1664 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1665 destroy_child_editcontrol(hwEdit);
1667 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, WS_EX_CLIENTEDGE);
1668 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1670 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1671 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1672 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1673 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1674 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1675 destroy_child_editcontrol(hwEdit);
1678 /* Edit controls that are popup windows */
1680 hwEdit = create_editcontrol(style | WS_POPUP, 0);
1681 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1683 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1684 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1685 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1686 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1687 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1688 DestroyWindow(hwEdit);
1690 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, 0);
1691 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1693 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1694 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1695 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1696 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1697 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1698 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1699 DestroyWindow(hwEdit);
1701 hwEdit = create_editcontrol(style | WS_POPUP, WS_EX_CLIENTEDGE);
1702 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1704 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1705 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1706 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1707 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1708 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1709 DestroyWindow(hwEdit);
1711 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
1712 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1714 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1715 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1716 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1717 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1718 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1719 DestroyWindow(hwEdit);
1722 static void test_text_position(void)
1724 trace("EDIT: Text position (Single line)\n");
1725 test_text_position_style(ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1726 trace("EDIT: Text position (Multi line)\n");
1727 test_text_position_style(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1730 static void test_espassword(void)
1735 const char* password = "secret";
1737 hwEdit = create_editcontrol(ES_PASSWORD, 0);
1738 r = get_edit_style(hwEdit);
1739 ok(r == ES_PASSWORD, "Wrong style expected ES_PASSWORD got: 0x%x\n", r);
1741 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) password);
1742 ok(r == TRUE, "Expected: %d, got: %d\n", TRUE, r);
1744 /* select all, cut (ctrl-x) */
1745 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1746 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1747 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1750 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1751 ok(r == strlen(password), "Expected: %s, got len %d\n", password, r);
1752 ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
1754 r = OpenClipboard(hwEdit);
1755 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1756 r = EmptyClipboard();
1757 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1758 r = CloseClipboard();
1759 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1761 /* select all, copy (ctrl-c) and paste (ctrl-v) */
1762 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1763 r = SendMessage(hwEdit, WM_CHAR, 3, 0);
1764 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1765 r = SendMessage(hwEdit, WM_CHAR, 22, 0);
1766 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1770 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1771 ok(r == 0, "Expected: 0, got: %d\n", r);
1772 ok(strcmp(buffer, "") == 0, "expected empty string, got %s\n", buffer);
1774 DestroyWindow (hwEdit);
1777 static void test_undo(void)
1783 const char* text = "undo this";
1785 hwEdit = create_editcontrol(0, 0);
1786 r = get_edit_style(hwEdit);
1787 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1790 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) text);
1791 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1794 cpMin = cpMax = 0xdeadbeef;
1795 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1796 r = SendMessage(hwEdit, EM_GETSEL, (WPARAM) &cpMin, (LPARAM) &cpMax);
1797 ok((strlen(text) << 16) == r, "Unexpected length %d\n", r);
1798 ok(0 == cpMin, "Expected: %d, got %d\n", 0, cpMin);
1799 ok(9 == cpMax, "Expected: %d, got %d\n", 9, cpMax);
1802 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1803 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1807 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1808 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1809 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1812 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1813 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1817 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1818 ok(strlen(text) == r, "Unexpected length %d\n", r);
1819 ok(0 == strcmp(buffer, text), "expected %s, got %s\n", text, buffer);
1821 /* undo again (ctrl-z) */
1822 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1823 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1827 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1828 ok(r == 0, "Expected: %d, got len %d\n", 0, r);
1829 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1831 DestroyWindow (hwEdit);
1834 static void test_enter(void)
1841 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1842 r = get_edit_style(hwEdit);
1843 ok(ES_MULTILINE == r, "Wrong style expected ES_MULTILINE got: 0x%x\n", r);
1846 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1847 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1849 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1850 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1854 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1855 ok(2 == r, "Expected: %d, got len %d\n", 2, r);
1856 ok(0 == strcmp(buffer, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer);
1858 DestroyWindow (hwEdit);
1861 hwEdit = create_editcontrol(0, 0);
1862 r = get_edit_style(hwEdit);
1863 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1866 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1867 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1869 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1870 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1874 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1875 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1876 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1878 DestroyWindow (hwEdit);
1880 /* single line with ES_WANTRETURN */
1881 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
1882 r = get_edit_style(hwEdit);
1883 ok(ES_WANTRETURN == r, "Wrong style expected ES_WANTRETURN got: 0x%x\n", r);
1886 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1887 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1889 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1890 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1894 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1895 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1896 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1898 DestroyWindow (hwEdit);
1901 static void test_tab(void)
1908 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1909 r = get_edit_style(hwEdit);
1910 ok(ES_MULTILINE == r, "Wrong style expected ES_MULTILINE got: 0x%x\n", r);
1913 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1914 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1916 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1917 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1921 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1922 ok(1 == r, "Expected: %d, got len %d\n", 1, r);
1923 ok(0 == strcmp(buffer, "\t"), "expected \"\\t\", got \"%s\"\n", buffer);
1925 DestroyWindow (hwEdit);
1928 hwEdit = create_editcontrol(0, 0);
1929 r = get_edit_style(hwEdit);
1930 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1933 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1934 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1936 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1937 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1941 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1942 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1943 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1945 DestroyWindow (hwEdit);
1948 static void test_edit_dialog(void)
1952 /* from bug 11841 */
1953 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 0);
1954 ok(333 == r, "Expected %d, got %d\n", 333, r);
1955 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 1);
1956 ok(111 == r, "Expected %d, got %d\n", 111, r);
1957 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 2);
1958 ok(444 == r, "Expected %d, got %d\n", 444, r);
1960 /* more tests for WM_CHAR */
1961 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 3);
1962 ok(444 == r, "Expected %d, got %d\n", 444, r);
1963 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 4);
1964 ok(444 == r, "Expected %d, got %d\n", 444, r);
1965 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 5);
1966 ok(444 == r, "Expected %d, got %d\n", 444, r);
1968 /* more tests for WM_KEYDOWN + WM_CHAR */
1969 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 6);
1970 ok(444 == r, "Expected %d, got %d\n", 444, r);
1971 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 7);
1972 ok(444 == r, "Expected %d, got %d\n", 444, r);
1973 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, edit_dialog_proc, 8);
1974 ok(444 == r, "Expected %d, got %d\n", 444, r);
1976 /* tests with an editable edit control */
1977 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 0);
1978 ok(333 == r, "Expected %d, got %d\n", 333, r);
1979 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 1);
1980 ok(111 == r, "Expected %d, got %d\n", 111, r);
1981 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 2);
1982 ok(444 == r, "Expected %d, got %d\n", 444, r);
1984 /* tests for WM_CHAR */
1985 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 3);
1986 ok(444 == r, "Expected %d, got %d\n", 444, r);
1987 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 4);
1988 ok(444 == r, "Expected %d, got %d\n", 444, r);
1989 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 5);
1990 ok(444 == r, "Expected %d, got %d\n", 444, r);
1992 /* tests for WM_KEYDOWN + WM_CHAR */
1993 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 6);
1994 ok(444 == r, "Expected %d, got %d\n", 444, r);
1995 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 7);
1996 ok(444 == r, "Expected %d, got %d\n", 444, r);
1997 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 8);
1998 ok(444 == r, "Expected %d, got %d\n", 444, r);
2000 /* multiple tab tests */
2001 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 9);
2002 ok(22 == r, "Expected %d, got %d\n", 22, r);
2003 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, edit_dialog_proc, 10);
2004 ok(33 == r, "Expected %d, got %d\n", 33, r);
2007 static void test_multi_edit_dialog(void)
2011 /* test for multiple edit dialogs (bug 12319) */
2012 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, multi_edit_dialog_proc, 0);
2013 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
2014 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, multi_edit_dialog_proc, 1);
2015 ok(1111 == r, "Expected %d, got %d\n", 1111, r);
2016 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, multi_edit_dialog_proc, 2);
2017 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
2018 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, multi_edit_dialog_proc, 3);
2019 ok(11 == r, "Expected %d, got %d\n", 11, r);
2022 static void test_wantreturn_edit_dialog(void)
2026 /* tests for WM_KEYDOWN */
2027 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 0);
2028 ok(333 == r, "Expected %d, got %d\n", 333, r);
2029 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 1);
2030 ok(444 == r, "Expected %d, got %d\n", 444, r);
2031 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 2);
2032 ok(444 == r, "Expected %d, got %d\n", 444, r);
2034 /* tests for WM_CHAR */
2035 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 3);
2036 ok(444 == r, "Expected %d, got %d\n", 444, r);
2037 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 4);
2038 ok(444 == r, "Expected %d, got %d\n", 444, r);
2039 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 5);
2040 ok(444 == r, "Expected %d, got %d\n", 444, r);
2042 /* tests for WM_KEYDOWN + WM_CHAR */
2043 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 6);
2044 ok(444 == r, "Expected %d, got %d\n", 444, r);
2045 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 7);
2046 ok(444 == r, "Expected %d, got %d\n", 444, r);
2047 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, edit_wantreturn_dialog_proc, 8);
2048 ok(444 == r, "Expected %d, got %d\n", 444, r);
2051 static void test_singleline_wantreturn_edit_dialog(void)
2055 /* tests for WM_KEYDOWN */
2056 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 0);
2057 ok(222 == r, "Expected %d, got %d\n", 222, r);
2058 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 1);
2059 ok(111 == r, "Expected %d, got %d\n", 111, r);
2060 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 2);
2061 ok(444 == r, "Expected %d, got %d\n", 444, r);
2063 /* tests for WM_CHAR */
2064 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 3);
2065 ok(444 == r, "Expected %d, got %d\n", 444, r);
2066 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 4);
2067 ok(444 == r, "Expected %d, got %d\n", 444, r);
2068 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 5);
2069 ok(444 == r, "Expected %d, got %d\n", 444, r);
2071 /* tests for WM_KEYDOWN + WM_CHAR */
2072 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 6);
2073 ok(222 == r, "Expected %d, got %d\n", 222, r);
2074 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 7);
2075 ok(111 == r, "Expected %d, got %d\n", 111, r);
2076 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, edit_singleline_dialog_proc, 8);
2077 ok(444 == r, "Expected %d, got %d\n", 444, r);
2079 /* tests for WM_KEYDOWN */
2080 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 0);
2081 ok(222 == r, "Expected %d, got %d\n", 222, r);
2082 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 1);
2083 ok(111 == r, "Expected %d, got %d\n", 111, r);
2084 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 2);
2085 ok(444 == r, "Expected %d, got %d\n", 444, r);
2087 /* tests for WM_CHAR */
2088 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 3);
2089 ok(444 == r, "Expected %d, got %d\n", 444, r);
2090 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 4);
2091 ok(444 == r, "Expected %d, got %d\n", 444, r);
2092 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 5);
2093 ok(444 == r, "Expected %d, got %d\n", 444, r);
2095 /* tests for WM_KEYDOWN + WM_CHAR */
2096 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 6);
2097 ok(222 == r, "Expected %d, got %d\n", 222, r);
2098 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 7);
2099 ok(111 == r, "Expected %d, got %d\n", 111, r);
2100 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, edit_singleline_dialog_proc, 8);
2101 ok(444 == r, "Expected %d, got %d\n", 444, r);
2104 static int child_edit_wmkeydown_num_messages = 0;
2105 static INT_PTR CALLBACK child_edit_wmkeydown_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
2114 child_edit_wmkeydown_num_messages++;
2121 static void test_child_edit_wmkeydown(void)
2123 HWND hwEdit, hwParent;
2126 hwEdit = create_child_editcontrol(0, 0);
2127 hwParent = GetParent(hwEdit);
2128 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)child_edit_wmkeydown_proc);
2129 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2130 ok(1 == r, "expected 1, got %d\n", r);
2131 ok(0 == child_edit_wmkeydown_num_messages, "expected 0, got %d\n", child_edit_wmkeydown_num_messages);
2132 destroy_child_editcontrol(hwEdit);
2135 static int got_en_setfocus = 0;
2136 static int got_wm_capturechanged = 0;
2138 static LRESULT CALLBACK edit4_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2142 switch (HIWORD(wParam)) {
2144 got_en_setfocus = 1;
2148 case WM_CAPTURECHANGED:
2149 if (hWnd != (HWND)lParam)
2151 got_wm_capturechanged = 1;
2156 return DefWindowProcA(hWnd, msg, wParam, lParam);
2159 static void test_contextmenu_focus(void)
2161 HWND hwndMain, hwndEdit;
2163 hwndMain = CreateWindow(szEditTest4Class, "ET4", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
2164 0, 0, 200, 200, NULL, NULL, hinst, NULL);
2167 hwndEdit = CreateWindow("EDIT", NULL,
2168 WS_CHILD|WS_BORDER|WS_VISIBLE|ES_LEFT|ES_AUTOHSCROLL,
2169 0, 0, 150, 50, /* important this not be 0 size. */
2170 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
2175 SetCapture(hwndMain);
2177 SendMessage(hwndEdit, WM_CONTEXTMENU, (WPARAM)hwndEdit, MAKEWORD(10, 10));
2179 ok(got_en_setfocus, "edit box didn't get focused\n");
2181 ok(got_wm_capturechanged, "main window capture did not change\n");
2183 DestroyWindow (hwndEdit);
2184 DestroyWindow (hwndMain);
2187 static BOOL RegisterWindowClasses (void)
2192 WNDCLASSA text_position;
2195 test2.lpfnWndProc = ET2_WndProc;
2196 test2.cbClsExtra = 0;
2197 test2.cbWndExtra = 0;
2198 test2.hInstance = hinst;
2200 test2.hCursor = LoadCursorA (NULL, IDC_ARROW);
2201 test2.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2202 test2.lpszMenuName = NULL;
2203 test2.lpszClassName = szEditTest2Class;
2204 if (!RegisterClassA(&test2)) return FALSE;
2207 test3.lpfnWndProc = edit3_wnd_procA;
2208 test3.cbClsExtra = 0;
2209 test3.cbWndExtra = 0;
2210 test3.hInstance = hinst;
2212 test3.hCursor = LoadCursorA(0, IDC_ARROW);
2213 test3.hbrBackground = GetStockObject(WHITE_BRUSH);
2214 test3.lpszMenuName = NULL;
2215 test3.lpszClassName = szEditTest3Class;
2216 if (!RegisterClassA(&test3)) return FALSE;
2219 test4.lpfnWndProc = edit4_wnd_procA;
2220 test4.cbClsExtra = 0;
2221 test4.cbWndExtra = 0;
2222 test4.hInstance = hinst;
2224 test4.hCursor = LoadCursorA (NULL, IDC_ARROW);
2225 test4.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2226 test4.lpszMenuName = NULL;
2227 test4.lpszClassName = szEditTest4Class;
2228 if (!RegisterClassA(&test4)) return FALSE;
2230 text_position.style = CS_HREDRAW | CS_VREDRAW;
2231 text_position.cbClsExtra = 0;
2232 text_position.cbWndExtra = 0;
2233 text_position.hInstance = hinst;
2234 text_position.hIcon = NULL;
2235 text_position.hCursor = LoadCursorA(NULL, IDC_ARROW);
2236 text_position.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2237 text_position.lpszMenuName = NULL;
2238 text_position.lpszClassName = szEditTextPositionClass;
2239 text_position.lpfnWndProc = DefWindowProc;
2240 if (!RegisterClassA(&text_position)) return FALSE;
2245 static void UnregisterWindowClasses (void)
2247 UnregisterClassA(szEditTest2Class, hinst);
2248 UnregisterClassA(szEditTest3Class, hinst);
2249 UnregisterClassA(szEditTest4Class, hinst);
2250 UnregisterClassA(szEditTextPositionClass, hinst);
2253 static void test_fontsize(void)
2260 char szLocalString[MAXLEN];
2264 dpi = GetDeviceCaps(hDC, LOGPIXELSY);
2265 ReleaseDC(NULL, hDC);
2267 memset(&lf,0,sizeof(LOGFONTA));
2268 strcpy(lf.lfFaceName,"Arial");
2269 lf.lfHeight = -300; /* taller than the edit box */
2271 hfont = CreateFontIndirect(&lf);
2273 trace("EDIT: Oversized font (Multi line)\n");
2274 hwEdit= CreateWindow("EDIT", NULL, ES_MULTILINE|ES_AUTOHSCROLL,
2275 0, 0, (150 * dpi) / 96, (50 * dpi) / 96, NULL, NULL,
2278 SendMessage(hwEdit,WM_SETFONT,(WPARAM)hfont,0);
2280 if (winetest_interactive)
2281 ShowWindow (hwEdit, SW_SHOW);
2283 r = SendMessage(hwEdit, WM_CHAR, 'A', 1);
2284 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2285 r = SendMessage(hwEdit, WM_CHAR, 'B', 1);
2286 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2287 r = SendMessage(hwEdit, WM_CHAR, 'C', 1);
2288 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2290 GetWindowText(hwEdit, szLocalString, MAXLEN);
2291 ok(lstrcmp(szLocalString, "ABC")==0,
2292 "Wrong contents of edit: %s\n", szLocalString);
2294 r = SendMessage(hwEdit, EM_POSFROMCHAR,0,0);
2295 ok(r != -1,"EM_POSFROMCHAR failed index 0\n");
2296 r = SendMessage(hwEdit, EM_POSFROMCHAR,1,0);
2297 ok(r != -1,"EM_POSFROMCHAR failed index 1\n");
2298 r = SendMessage(hwEdit, EM_POSFROMCHAR,2,0);
2299 ok(r != -1,"EM_POSFROMCHAR failed index 2\n");
2300 r = SendMessage(hwEdit, EM_POSFROMCHAR,3,0);
2301 ok(r == -1,"EM_POSFROMCHAR succeeded index 3\n");
2303 DestroyWindow (hwEdit);
2304 DeleteObject(hfont);
2307 struct dialog_mode_messages
2309 int wm_getdefid, wm_close, wm_command, wm_nextdlgctl;
2312 static struct dialog_mode_messages dm_messages;
2314 static void zero_dm_messages(void)
2316 dm_messages.wm_command = 0;
2317 dm_messages.wm_close = 0;
2318 dm_messages.wm_getdefid = 0;
2319 dm_messages.wm_nextdlgctl = 0;
2322 #define test_dm_messages(wmcommand, wmclose, wmgetdefid, wmnextdlgctl) \
2323 ok(dm_messages.wm_command == wmcommand, "expected %d WM_COMMAND messages, " \
2324 "got %d\n", wmcommand, dm_messages.wm_command); \
2325 ok(dm_messages.wm_close == wmclose, "expected %d WM_CLOSE messages, " \
2326 "got %d\n", wmclose, dm_messages.wm_close); \
2327 ok(dm_messages.wm_getdefid == wmgetdefid, "expected %d WM_GETDIFID messages, " \
2328 "got %d\n", wmgetdefid, dm_messages.wm_getdefid);\
2329 ok(dm_messages.wm_nextdlgctl == wmnextdlgctl, "expected %d WM_NEXTDLGCTL messages, " \
2330 "got %d\n", wmnextdlgctl, dm_messages.wm_nextdlgctl)
2332 static LRESULT CALLBACK dialog_mode_wnd_proc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
2337 dm_messages.wm_command++;
2340 dm_messages.wm_getdefid++;
2341 return MAKELONG(ID_EDITTESTDBUTTON, DC_HASDEFID);
2343 dm_messages.wm_nextdlgctl++;
2346 dm_messages.wm_close++;
2350 return DefWindowProc(hwnd, iMsg, wParam, lParam);
2353 static void test_dialogmode(void)
2355 HWND hwEdit, hwParent, hwButton;
2358 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2360 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2361 ok(1 == r, "expected 1, got %d\n", r);
2362 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2363 ok(11 == len, "expected 11, got %d\n", len);
2365 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, 0);
2366 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2368 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2369 ok(1 == r, "expected 1, got %d\n", r);
2370 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2371 ok(13 == len, "expected 13, got %d\n", len);
2373 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
2374 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2375 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2376 ok(1 == r, "expected 1, got %d\n", r);
2377 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2378 ok(13 == len, "expected 13, got %d\n", len);
2380 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2381 ok(1 == r, "expected 1, got %d\n", r);
2382 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2383 ok(13 == len, "expected 13, got %d\n", len);
2385 destroy_child_editcontrol(hwEdit);
2387 hwEdit = create_editcontrol(ES_MULTILINE, 0);
2389 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2390 ok(1 == r, "expected 1, got %d\n", r);
2391 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2392 ok(11 == len, "expected 11, got %d\n", len);
2395 msg.message = WM_KEYDOWN;
2396 msg.wParam = VK_BACK;
2397 msg.lParam = 0xe0001;
2398 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_BACK, (LPARAM)&msg);
2399 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2401 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2402 ok(1 == r, "expected 1, got %d\n", r);
2403 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2404 ok(11 == len, "expected 11, got %d\n", len);
2406 DestroyWindow(hwEdit);
2408 hwEdit = create_child_editcontrol(0, 0);
2409 hwParent = GetParent(hwEdit);
2410 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2413 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2414 ok(1 == r, "expected 1, got %d\n", r);
2415 test_dm_messages(0, 0, 0, 0);
2418 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2419 ok(1 == r, "expected 1, got %d\n", r);
2420 test_dm_messages(0, 0, 0, 0);
2424 msg.message = WM_KEYDOWN;
2425 msg.wParam = VK_TAB;
2426 msg.lParam = 0xf0001;
2427 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_TAB, (LPARAM)&msg);
2428 ok(0x89 == r, "expected 0x89, got 0x%x\n", r);
2429 test_dm_messages(0, 0, 0, 0);
2432 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2433 ok(1 == r, "expected 1, got %d\n", r);
2434 test_dm_messages(0, 0, 0, 0);
2437 destroy_child_editcontrol(hwEdit);
2439 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2440 hwParent = GetParent(hwEdit);
2441 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2443 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2444 ok(1 == r, "expected 1, got %d\n", r);
2445 test_dm_messages(0, 0, 0, 0);
2449 msg.message = WM_KEYDOWN;
2450 msg.wParam = VK_ESCAPE;
2451 msg.lParam = 0x10001;
2452 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_ESCAPE, (LPARAM)&msg);
2453 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2454 test_dm_messages(0, 0, 0, 0);
2457 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2458 ok(1 == r, "expected 1, got %d\n", r);
2459 test_dm_messages(0, 0, 0, 0);
2462 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2463 ok(1 == r, "expected 1, got %d\n", r);
2464 test_dm_messages(0, 0, 0, 1);
2467 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2468 ok(1 == r, "expected 1, got %d\n", r);
2469 test_dm_messages(0, 0, 1, 0);
2472 hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
2473 100, 100, 50, 20, hwParent, (HMENU)ID_EDITTESTDBUTTON, hinst, NULL);
2474 ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
2476 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2477 ok(1 == r, "expected 1, got %d\n", r);
2478 test_dm_messages(0, 0, 1, 1);
2481 DestroyWindow(hwButton);
2482 destroy_child_editcontrol(hwEdit);
2489 init_function_pointers();
2491 hinst = GetModuleHandleA(NULL);
2492 b = RegisterWindowClasses();
2493 ok (b, "RegisterWindowClasses failed\n");
2496 test_edit_control_1();
2497 test_edit_control_2();
2498 test_edit_control_3();
2499 test_edit_control_4();
2500 test_edit_control_5();
2501 test_edit_control_6();
2502 test_edit_control_limittext();
2503 test_edit_control_scroll();
2505 test_margins_font_change();
2506 test_text_position();
2512 test_multi_edit_dialog();
2513 test_wantreturn_edit_dialog();
2514 test_singleline_wantreturn_edit_dialog();
2515 test_child_edit_wmkeydown();
2519 test_contextmenu_focus();
2521 win_skip("EndMenu is not available\n");
2523 UnregisterWindowClasses();