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)
740 char szLocalString[MAXLEN];
743 /* Create main and edit windows. */
744 hwndMain = CreateWindow(szEditTest2Class, "ET2", WS_OVERLAPPEDWINDOW,
745 0, 0, 200, 200, NULL, NULL, hinst, NULL);
747 if (winetest_interactive)
748 ShowWindow (hwndMain, SW_SHOW);
750 hwndET2 = CreateWindow("EDIT", NULL,
751 WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
752 0, 0, 150, 50, /* important this not be 0 size. */
753 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
755 if (winetest_interactive)
756 ShowWindow (hwndET2, SW_SHOW);
758 trace("EDIT: SETTEXT atomicity\n");
759 /* Send messages to "type" in the word 'foo'. */
760 r = SendMessage(hwndET2, WM_CHAR, 'f', 1);
761 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
762 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
763 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
764 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
765 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
766 /* 'foo' should have been changed to 'bar' by the UPDATE handler. */
767 GetWindowText(hwndET2, szLocalString, MAXLEN);
768 ok(lstrcmp(szLocalString, "bar")==0,
769 "Wrong contents of edit: %s\n", szLocalString);
772 DestroyWindow (hwndET2);
773 DestroyWindow (hwndMain);
776 static void ET2_check_change(void) {
777 char szLocalString[MAXLEN];
778 /* This EN_UPDATE handler changes any 'foo' to 'bar'. */
779 GetWindowText(hwndET2, szLocalString, MAXLEN);
780 if (lstrcmp(szLocalString, "foo")==0) {
781 lstrcpy(szLocalString, "bar");
782 SendMessage(hwndET2, WM_SETTEXT, 0, (LPARAM) szLocalString);
784 /* always leave the cursor at the end. */
785 SendMessage(hwndET2, EM_SETSEL, MAXLEN - 1, MAXLEN - 1);
787 static void ET2_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
789 if (id==ID_EDITTEST2 && codeNotify == EN_UPDATE)
792 static LRESULT CALLBACK ET2_WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
796 ET2_OnCommand(hwnd, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
799 return DefWindowProc(hwnd, iMsg, wParam, lParam);
802 static void zero_notify(void)
804 notifications.en_change = 0;
805 notifications.en_maxtext = 0;
806 notifications.en_update = 0;
809 #define test_notify(enchange, enmaxtext, enupdate) \
810 ok(notifications.en_change == enchange, "expected %d EN_CHANGE notifications, " \
811 "got %d\n", enchange, notifications.en_change); \
812 ok(notifications.en_maxtext == enmaxtext, "expected %d EN_MAXTEXT notifications, " \
813 "got %d\n", enmaxtext, notifications.en_maxtext); \
814 ok(notifications.en_update == enupdate, "expected %d EN_UPDATE notifications, " \
815 "got %d\n", enupdate, notifications.en_update)
818 static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
822 switch (HIWORD(wParam)) {
824 notifications.en_maxtext++;
827 notifications.en_update++;
830 notifications.en_change++;
835 return DefWindowProcA(hWnd, msg, wParam, lParam);
838 /* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
841 static void test_edit_control_3(void)
847 static const char *str = "this is a long string.";
848 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.";
851 dpi = GetDeviceCaps(hDC, LOGPIXELSY);
852 ReleaseDC(NULL, hDC);
854 trace("EDIT: Test notifications\n");
856 hParent = CreateWindowExA(0,
860 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10,
861 NULL, NULL, NULL, NULL);
864 trace("EDIT: Single line, no ES_AUTOHSCROLL\n");
865 hWnd = CreateWindowExA(0,
870 hParent, NULL, NULL, NULL);
874 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
875 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
876 ok(lstrlenA(str) > len, "text should have been truncated\n");
877 test_notify(1, 1, 1);
879 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
881 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
882 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
883 ok(1 == len, "wrong text length, expected 1, got %d\n", len);
884 test_notify(1, 0, 1);
887 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
888 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
889 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
890 test_notify(1, 0, 1);
892 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
893 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
894 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
895 SendMessage(hParent, WM_SETFOCUS, 0, (LPARAM)hWnd);
896 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
897 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
898 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
900 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
902 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
904 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
905 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
906 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
907 test_notify(1, 1, 1);
910 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
911 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
912 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
913 test_notify(1, 0, 1);
917 trace("EDIT: Single line, ES_AUTOHSCROLL\n");
918 hWnd = CreateWindowExA(0,
923 hParent, NULL, NULL, NULL);
927 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
928 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
929 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
930 test_notify(1, 0, 1);
933 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
934 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
935 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
936 test_notify(1, 0, 1);
938 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
940 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
942 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
943 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
944 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
945 test_notify(1, 1, 1);
948 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
949 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
950 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
951 test_notify(1, 0, 1);
955 trace("EDIT: Multline, no ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
956 hWnd = CreateWindowExA(0,
960 10, 10, (50 * dpi) / 96, (50 * dpi) / 96,
961 hParent, NULL, NULL, NULL);
965 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
966 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
967 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
968 test_notify(1, 1, 1);
970 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
972 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
973 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
974 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
975 test_notify(1, 0, 1);
978 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
979 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
980 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
981 test_notify(0, 0, 0);
983 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
985 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
987 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
988 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
989 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
990 test_notify(1, 1, 1);
993 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
994 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
995 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
996 test_notify(0, 0, 0);
1000 trace("EDIT: Multline, ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
1001 hWnd = CreateWindowExA(0,
1004 ES_MULTILINE | ES_AUTOHSCROLL,
1005 10, 10, (50 * dpi) / 96, (50 * dpi) / 96,
1006 hParent, NULL, NULL, NULL);
1010 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1011 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1012 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
1013 test_notify(1, 1, 1);
1015 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1017 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
1018 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1019 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
1020 test_notify(1, 0, 1);
1023 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1024 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1025 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1026 test_notify(0, 0, 0);
1028 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1030 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1032 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1033 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1034 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1035 test_notify(1, 1, 1);
1038 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1039 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1040 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1041 test_notify(0, 0, 0);
1043 DestroyWindow(hWnd);
1045 trace("EDIT: Multline, ES_AUTOHSCROLL and ES_AUTOVSCROLL\n");
1046 hWnd = CreateWindowExA(0,
1049 ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
1051 hParent, NULL, NULL, NULL);
1055 SendMessageA(hWnd, EM_REPLACESEL, 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(1, 0, 1);
1061 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1062 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1063 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1064 test_notify(0, 0, 0);
1066 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1068 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1070 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1071 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1072 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1073 test_notify(1, 1, 1);
1076 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1077 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1078 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1079 test_notify(0, 0, 0);
1081 DestroyWindow(hWnd);
1084 /* Test EM_CHARFROMPOS and EM_POSFROMCHAR
1086 static void test_edit_control_4(void)
1093 trace("EDIT: Test EM_CHARFROMPOS and EM_POSFROMCHAR\n");
1094 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1095 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1096 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1097 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1098 mid = lo + (hi - lo) / 2;
1100 for (i = lo; i < mid; i++) {
1101 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1102 ok(0 == ret, "expected 0 got %d\n", ret);
1104 for (i = mid; i <= hi; i++) {
1105 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1106 ok(1 == ret, "expected 1 got %d\n", ret);
1108 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1109 ok(-1 == ret, "expected -1 got %d\n", ret);
1110 DestroyWindow(hwEdit);
1112 hwEdit = create_editcontrol(ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1113 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1114 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1115 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1116 mid = lo + (hi - lo) / 2;
1118 for (i = lo; i < mid; i++) {
1119 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1120 ok(0 == ret, "expected 0 got %d\n", ret);
1122 for (i = mid; i <= hi; i++) {
1123 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1124 ok(1 == ret, "expected 1 got %d\n", ret);
1126 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1127 ok(-1 == ret, "expected -1 got %d\n", ret);
1128 DestroyWindow(hwEdit);
1130 hwEdit = create_editcontrol(ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1131 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1132 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1133 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1134 mid = lo + (hi - lo) / 2;
1136 for (i = lo; i < mid; i++) {
1137 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1138 ok(0 == ret, "expected 0 got %d\n", ret);
1140 for (i = mid; i <= hi; i++) {
1141 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1142 ok(1 == ret, "expected 1 got %d\n", ret);
1144 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1145 ok(-1 == ret, "expected -1 got %d\n", ret);
1146 DestroyWindow(hwEdit);
1148 hwEdit = create_editcontrol(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1149 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1150 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1151 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1152 mid = lo + (hi - lo) / 2 +1;
1154 for (i = lo; i < mid; i++) {
1155 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1156 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1158 for (i = mid; i <= hi; i++) {
1159 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1160 ok(1 == ret, "expected 1 got %d\n", ret);
1162 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1163 ok(-1 == ret, "expected -1 got %d\n", ret);
1164 DestroyWindow(hwEdit);
1166 hwEdit = create_editcontrol(ES_MULTILINE | ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1167 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1168 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1169 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1170 mid = lo + (hi - lo) / 2 +1;
1172 for (i = lo; i < mid; i++) {
1173 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1174 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1176 for (i = mid; i <= hi; i++) {
1177 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1178 ok(1 == ret, "expected 1 got %d\n", ret);
1180 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1181 ok(-1 == ret, "expected -1 got %d\n", ret);
1182 DestroyWindow(hwEdit);
1184 hwEdit = create_editcontrol(ES_MULTILINE | ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1185 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1186 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1187 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1188 mid = lo + (hi - lo) / 2 +1;
1190 for (i = lo; i < mid; i++) {
1191 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1192 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1194 for (i = mid; i <= hi; i++) {
1195 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1196 ok(1 == ret, "expected 1 got %d\n", ret);
1198 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1199 ok(-1 == ret, "expected -1 got %d\n", ret);
1200 DestroyWindow(hwEdit);
1203 /* Test if creating edit control without ES_AUTOHSCROLL and ES_AUTOVSCROLL
1204 * truncates text that doesn't fit.
1206 static void test_edit_control_5(void)
1208 static const char *str = "test\r\ntest";
1212 RECT rc1 = { 10, 10, 11, 11};
1215 /* first show that a non-child won't do for this test */
1216 hWnd = CreateWindowEx(0,
1221 NULL, NULL, NULL, NULL);
1223 /* size of non-child edit control is (much) bigger than requested */
1224 GetWindowRect( hWnd, &rc);
1225 ok( rc.right - rc.left > 20, "size of the window (%d) is smaller than expected\n",
1226 rc.right - rc.left);
1227 DestroyWindow(hWnd);
1228 /* so create a parent, and give it edit controls children to test with */
1229 parentWnd = CreateWindowEx(0,
1230 szEditTextPositionClass,
1231 "Edit Test", WS_VISIBLE |
1232 WS_OVERLAPPEDWINDOW,
1233 CW_USEDEFAULT, CW_USEDEFAULT,
1235 NULL, NULL, hinst, NULL);
1237 ShowWindow( parentWnd, SW_SHOW);
1239 hWnd = CreateWindowEx(0,
1241 str, WS_VISIBLE | WS_BORDER |
1243 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1244 parentWnd, NULL, NULL, NULL);
1246 GetClientRect( hWnd, &rc);
1247 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1248 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1249 rc.left, rc.top, rc.right, rc.bottom);
1250 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1251 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1252 DestroyWindow(hWnd);
1254 hWnd = CreateWindowEx(0,
1257 WS_CHILD | ES_MULTILINE,
1258 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1259 parentWnd, NULL, NULL, NULL);
1261 GetClientRect( hWnd, &rc);
1262 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1263 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1264 rc.left, rc.top, rc.right, rc.bottom);
1265 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1266 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1267 DestroyWindow(hWnd);
1270 /* Test WM_GETTEXT processing
1271 * after destroy messages
1273 static void test_edit_control_6(void)
1275 static const char *str = "test\r\ntest";
1280 hWnd = CreateWindowEx(0,
1285 NULL, NULL, hinst, NULL);
1288 ret = SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
1289 ok(ret == TRUE, "Expected %d, got %d\n", TRUE, ret);
1290 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1291 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1292 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1294 ret = SendMessageA(hWnd, WM_DESTROY, 0, 0);
1295 ok(ret == 0, "Expected 0, got %d\n", ret);
1296 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1297 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1298 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1300 ret = SendMessageA(hWnd, WM_NCDESTROY, 0, 0);
1301 ok(ret == 0, "Expected 0, got %d\n", ret);
1302 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1303 ok(ret == 0, "Expected 0, got len %d\n", ret);
1304 ok(!lstrcmp(buf, ""), "Expected empty string, got %s\n", buf);
1306 DestroyWindow(hWnd);
1309 static void test_edit_control_limittext(void)
1314 /* Test default limit for single-line control */
1315 trace("EDIT: buffer limit for single-line\n");
1316 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1317 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1318 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1319 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1320 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1321 /* Win9x+ME: 32766; WinNT: 2147483646UL */
1322 ok( (r == 32766) || (r == 2147483646UL),
1323 "got limit %u (expected 32766 or 2147483646)\n", r);
1324 DestroyWindow(hwEdit);
1326 /* Test default limit for multi-line control */
1327 trace("EDIT: buffer limit for multi-line\n");
1328 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1329 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1330 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1331 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1332 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1333 /* Win9x+ME: 65535; WinNT: 4294967295UL */
1334 ok( (r == 65535) || (r == 4294967295UL),
1335 "got limit %u (expected 65535 or 4294967295)\n", r);
1336 DestroyWindow(hwEdit);
1339 /* Test EM_SCROLL */
1340 static void test_edit_control_scroll(void)
1342 static const char *single_line_str = "a";
1343 static const char *multiline_str = "Test\r\nText";
1347 /* Check the return value when EM_SCROLL doesn't scroll
1348 * anything. Should not return true unless any lines were actually
1350 hwEdit = CreateWindow(
1353 WS_VSCROLL | ES_MULTILINE,
1355 NULL, NULL, hinst, NULL);
1359 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1360 ok(!ret, "Returned %x, expected 0.\n", ret);
1362 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEUP, 0);
1363 ok(!ret, "Returned %x, expected 0.\n", ret);
1365 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEUP, 0);
1366 ok(!ret, "Returned %x, expected 0.\n", ret);
1368 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEDOWN, 0);
1369 ok(!ret, "Returned %x, expected 0.\n", ret);
1371 DestroyWindow (hwEdit);
1373 /* SB_PAGEDOWN while at the beginning of a buffer with few lines
1374 should not cause EM_SCROLL to return a negative value of
1375 scrolled lines that would put us "before" the beginning. */
1376 hwEdit = CreateWindow(
1379 WS_VSCROLL | ES_MULTILINE,
1381 NULL, NULL, hinst, NULL);
1384 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1385 ok(!ret, "Returned %x, expected 0.\n", ret);
1387 DestroyWindow (hwEdit);
1390 static void test_margins(void)
1393 RECT old_rect, new_rect;
1394 INT old_right_margin;
1395 DWORD old_margins, new_margins;
1397 hwEdit = create_editcontrol(WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1399 old_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1400 old_right_margin = HIWORD(old_margins);
1402 /* Check if setting the margins works */
1404 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(10, 0));
1405 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1406 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1407 ok(HIWORD(new_margins) == old_right_margin, "Wrong right margin: %d\n", HIWORD(new_margins));
1409 SendMessage(hwEdit, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, 10));
1410 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1411 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1412 ok(HIWORD(new_margins) == 10, "Wrong right margin: %d\n", HIWORD(new_margins));
1415 /* The size of the rectangle must decrease if we increase the margin */
1417 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5));
1418 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1419 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(15, 20));
1420 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1421 ok(new_rect.left == old_rect.left + 10, "The left border of the rectangle is wrong\n");
1422 ok(new_rect.right == old_rect.right - 15, "The right border of the rectangle is wrong\n");
1423 ok(new_rect.top == old_rect.top, "The top border of the rectangle must not change\n");
1424 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle must not change\n");
1427 /* If we set the margin to same value as the current margin,
1428 the rectangle must not change */
1430 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1432 old_rect.right = 99;
1434 old_rect.bottom = 99;
1435 SendMessage(hwEdit, EM_SETRECT, 0, (LPARAM)&old_rect);
1436 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1437 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1438 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1439 ok(new_rect.left == old_rect.left, "The left border of the rectangle has changed\n");
1440 ok(new_rect.right == old_rect.right, "The right border of the rectangle has changed\n");
1441 ok(new_rect.top == old_rect.top, "The top border of the rectangle has changed\n");
1442 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n");
1444 DestroyWindow (hwEdit);
1447 static INT CALLBACK find_font_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
1452 static void test_margins_font_change(void)
1455 DWORD margins, font_margins;
1457 HFONT hfont, hfont2;
1460 if(EnumFontFamiliesA(hdc, "Arial", find_font_proc, 0))
1462 trace("Arial not found - skipping font change margin tests\n");
1468 hwEdit = create_child_editcontrol(0, 0);
1470 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1472 memset(&lf, 0, sizeof(lf));
1473 strcpy(lf.lfFaceName, "Arial");
1475 lf.lfCharSet = DEFAULT_CHARSET;
1476 hfont = CreateFontIndirectA(&lf);
1478 hfont2 = CreateFontIndirectA(&lf);
1480 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1481 font_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1482 ok(LOWORD(font_margins) != 0, "got %d\n", LOWORD(font_margins));
1483 ok(HIWORD(font_margins) != 0, "got %d\n", HIWORD(font_margins));
1485 /* With 'small' edit controls, test that the margin doesn't get set */
1486 SetWindowPos(hwEdit, NULL, 10, 10, 16, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1487 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0,0));
1488 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1489 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1490 ok(LOWORD(margins) == 0 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1491 "got %d\n", LOWORD(margins));
1492 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1493 "got %d\n", HIWORD(margins));
1495 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1496 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1497 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1498 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1499 "got %d\n", LOWORD(margins));
1500 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1501 "got %d\n", HIWORD(margins));
1503 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1504 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1505 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1506 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1507 "got %d\n", LOWORD(margins));
1508 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1509 "got %d\n", HIWORD(margins));
1511 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1512 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1513 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1514 "got %d\n", LOWORD(margins));
1515 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1516 "got %d\n", HIWORD(margins));
1518 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1519 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1520 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) != 1 && LOWORD(margins) != LOWORD(font_margins)), /* win95 */
1521 "got %d\n", LOWORD(margins));
1522 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) != 1 && HIWORD(margins) != HIWORD(font_margins)), /* win95 */
1523 "got %d\n", HIWORD(margins));
1525 /* Above a certain size threshold then the margin is updated */
1526 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1527 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1528 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1529 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1530 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1531 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1533 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1534 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1535 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1536 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1537 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1539 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1540 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1541 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1542 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1543 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1544 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1545 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1546 ok(LOWORD(margins) != LOWORD(font_margins) || broken(LOWORD(margins) == LOWORD(font_margins)), /* win98 */
1547 "got %d\n", LOWORD(margins));
1548 ok(HIWORD(margins) != HIWORD(font_margins), "got %d\n", HIWORD(margins));
1550 SendMessageA(hwEdit, WM_SETFONT, 0, 0);
1552 DeleteObject(hfont2);
1553 DeleteObject(hfont);
1554 destroy_child_editcontrol(hwEdit);
1558 #define edit_pos_ok(exp, got, txt) \
1559 ok(exp == got, "wrong " #txt " expected %d got %d\n", exp, got);
1561 #define check_pos(hwEdit, set_height, test_top, test_height, test_left) \
1565 set_client_height(hwEdit, set_height); \
1566 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &format_rect); \
1567 left_margin = LOWORD(SendMessage(hwEdit, EM_GETMARGINS, 0, 0)); \
1568 edit_pos_ok(test_top, format_rect.top, vertical position); \
1569 edit_pos_ok((int)test_height, format_rect.bottom - format_rect.top, height); \
1570 edit_pos_ok(test_left, format_rect.left - left_margin, left); \
1573 static void test_text_position_style(DWORD style)
1576 HFONT font, oldFont;
1580 BOOL xb, single_line = !(style & ES_MULTILINE);
1582 b = GetSystemMetrics(SM_CYBORDER) + 1;
1587 /* Get a stock font for which we can determine the metrics */
1588 font = GetStockObject(SYSTEM_FONT);
1589 ok (font != NULL, "GetStockObjcet SYSTEM_FONT failed\n");
1591 ok (dc != NULL, "GetDC() failed\n");
1592 oldFont = SelectObject(dc, font);
1593 xb = GetTextMetrics(dc, &metrics);
1594 ok (xb, "GetTextMetrics failed\n");
1595 SelectObject(dc, oldFont);
1596 ReleaseDC(NULL, dc);
1598 /* Windows' edit control has some bugs in multi-line mode:
1599 * - Sometimes the format rectangle doesn't get updated
1600 * (see workaround in set_client_height())
1601 * - If the height of the control is smaller than the height of a text
1602 * line, the format rectangle is still as high as a text line
1603 * (higher than the client rectangle) and the caret is not shown
1606 /* Edit controls that are in a parent window */
1608 hwEdit = create_child_editcontrol(style | WS_VISIBLE, 0);
1609 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1611 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1612 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1613 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1614 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1615 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1616 destroy_child_editcontrol(hwEdit);
1618 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, 0);
1619 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1621 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1622 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1623 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1624 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1625 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1626 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1627 destroy_child_editcontrol(hwEdit);
1629 hwEdit = create_child_editcontrol(style | WS_VISIBLE, WS_EX_CLIENTEDGE);
1630 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1632 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1633 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1634 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1635 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1636 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1637 destroy_child_editcontrol(hwEdit);
1639 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, WS_EX_CLIENTEDGE);
1640 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1642 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1643 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1644 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1645 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1646 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1647 destroy_child_editcontrol(hwEdit);
1650 /* Edit controls that are popup windows */
1652 hwEdit = create_editcontrol(style | WS_POPUP, 0);
1653 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1655 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1656 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1657 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1658 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1659 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1660 DestroyWindow(hwEdit);
1662 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, 0);
1663 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1665 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1666 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1667 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1668 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1669 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1670 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1671 DestroyWindow(hwEdit);
1673 hwEdit = create_editcontrol(style | WS_POPUP, WS_EX_CLIENTEDGE);
1674 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1676 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1677 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1678 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1679 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1680 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1681 DestroyWindow(hwEdit);
1683 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
1684 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1686 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1687 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1688 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1689 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1690 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1691 DestroyWindow(hwEdit);
1694 static void test_text_position(void)
1696 trace("EDIT: Text position (Single line)\n");
1697 test_text_position_style(ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1698 trace("EDIT: Text position (Multi line)\n");
1699 test_text_position_style(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1702 static void test_espassword(void)
1707 const char* password = "secret";
1709 hwEdit = create_editcontrol(ES_PASSWORD, 0);
1710 r = get_edit_style(hwEdit);
1711 ok(r == ES_PASSWORD, "Wrong style expected 0x%x got: 0x%x\n", ES_PASSWORD, r);
1713 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) password);
1714 ok(r == TRUE, "Expected: %d, got: %d\n", TRUE, r);
1716 /* select all, cut (ctrl-x) */
1717 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1718 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1719 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1722 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1723 ok(r == strlen(password), "Expected: %s, got len %d\n", password, r);
1724 ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
1726 r = OpenClipboard(hwEdit);
1727 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1728 r = EmptyClipboard();
1729 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1730 r = CloseClipboard();
1731 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1733 /* select all, copy (ctrl-c) and paste (ctrl-v) */
1734 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1735 r = SendMessage(hwEdit, WM_CHAR, 3, 0);
1736 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1737 r = SendMessage(hwEdit, WM_CHAR, 22, 0);
1738 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1742 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1743 ok(r == 0, "Expected: 0, got: %d\n", r);
1744 ok(strcmp(buffer, "") == 0, "expected empty string, got %s\n", buffer);
1746 DestroyWindow (hwEdit);
1749 static void test_undo(void)
1755 const char* text = "undo this";
1757 hwEdit = create_editcontrol(0, 0);
1758 r = get_edit_style(hwEdit);
1759 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1762 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) text);
1763 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1766 cpMin = cpMax = 0xdeadbeef;
1767 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1768 r = SendMessage(hwEdit, EM_GETSEL, (WPARAM) &cpMin, (LPARAM) &cpMax);
1769 ok((strlen(text) << 16) == r, "Unexpected length %d\n", r);
1770 ok(0 == cpMin, "Expected: %d, got %d\n", 0, cpMin);
1771 ok(9 == cpMax, "Expected: %d, got %d\n", 9, cpMax);
1774 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1775 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1779 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1780 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1781 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1784 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1785 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1789 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1790 ok(strlen(text) == r, "Unexpected length %d\n", r);
1791 ok(0 == strcmp(buffer, text), "expected %s, got %s\n", text, buffer);
1793 /* undo again (ctrl-z) */
1794 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1795 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1799 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1800 ok(r == 0, "Expected: %d, got len %d\n", 0, r);
1801 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1803 DestroyWindow (hwEdit);
1806 static void test_enter(void)
1813 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1814 r = get_edit_style(hwEdit);
1815 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1818 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1819 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1821 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1822 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1826 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1827 ok(2 == r, "Expected: %d, got len %d\n", 2, r);
1828 ok(0 == strcmp(buffer, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer);
1830 DestroyWindow (hwEdit);
1833 hwEdit = create_editcontrol(0, 0);
1834 r = get_edit_style(hwEdit);
1835 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1838 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1839 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1841 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1842 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1846 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1847 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1848 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1850 DestroyWindow (hwEdit);
1852 /* single line with ES_WANTRETURN */
1853 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
1854 r = get_edit_style(hwEdit);
1855 ok(ES_WANTRETURN == r, "Wrong style expected 0x%x got: 0x%x\n", ES_WANTRETURN, r);
1858 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1859 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1861 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1862 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1866 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1867 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1868 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1870 DestroyWindow (hwEdit);
1873 static void test_tab(void)
1880 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1881 r = get_edit_style(hwEdit);
1882 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1885 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1886 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1888 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1889 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1893 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1894 ok(1 == r, "Expected: %d, got len %d\n", 1, r);
1895 ok(0 == strcmp(buffer, "\t"), "expected \"\\t\", got \"%s\"\n", buffer);
1897 DestroyWindow (hwEdit);
1900 hwEdit = create_editcontrol(0, 0);
1901 r = get_edit_style(hwEdit);
1902 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1905 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1906 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1908 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1909 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1913 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1914 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1915 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1917 DestroyWindow (hwEdit);
1920 static void test_edit_dialog(void)
1924 /* from bug 11841 */
1925 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1926 ok(333 == r, "Expected %d, got %d\n", 333, r);
1927 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1928 ok(111 == r, "Expected %d, got %d\n", 111, r);
1929 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1930 ok(444 == r, "Expected %d, got %d\n", 444, r);
1932 /* more tests for WM_CHAR */
1933 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1934 ok(444 == r, "Expected %d, got %d\n", 444, r);
1935 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1936 ok(444 == r, "Expected %d, got %d\n", 444, r);
1937 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1938 ok(444 == r, "Expected %d, got %d\n", 444, r);
1940 /* more tests for WM_KEYDOWN + WM_CHAR */
1941 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1942 ok(444 == r, "Expected %d, got %d\n", 444, r);
1943 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1944 ok(444 == r, "Expected %d, got %d\n", 444, r);
1945 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1946 ok(444 == r, "Expected %d, got %d\n", 444, r);
1948 /* tests with an editable edit control */
1949 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1950 ok(333 == r, "Expected %d, got %d\n", 333, r);
1951 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1952 ok(111 == r, "Expected %d, got %d\n", 111, r);
1953 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1954 ok(444 == r, "Expected %d, got %d\n", 444, r);
1956 /* tests for WM_CHAR */
1957 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1958 ok(444 == r, "Expected %d, got %d\n", 444, r);
1959 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1960 ok(444 == r, "Expected %d, got %d\n", 444, r);
1961 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1962 ok(444 == r, "Expected %d, got %d\n", 444, r);
1964 /* tests for WM_KEYDOWN + WM_CHAR */
1965 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1966 ok(444 == r, "Expected %d, got %d\n", 444, r);
1967 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1968 ok(444 == r, "Expected %d, got %d\n", 444, r);
1969 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1970 ok(444 == r, "Expected %d, got %d\n", 444, r);
1972 /* multiple tab tests */
1973 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 9);
1974 ok(22 == r, "Expected %d, got %d\n", 22, r);
1975 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 10);
1976 ok(33 == r, "Expected %d, got %d\n", 33, r);
1979 static void test_multi_edit_dialog(void)
1983 /* test for multiple edit dialogs (bug 12319) */
1984 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 0);
1985 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1986 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 1);
1987 ok(1111 == r, "Expected %d, got %d\n", 1111, r);
1988 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 2);
1989 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1990 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 3);
1991 ok(11 == r, "Expected %d, got %d\n", 11, r);
1994 static void test_wantreturn_edit_dialog(void)
1998 /* tests for WM_KEYDOWN */
1999 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 0);
2000 ok(333 == r, "Expected %d, got %d\n", 333, r);
2001 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 1);
2002 ok(444 == r, "Expected %d, got %d\n", 444, r);
2003 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 2);
2004 ok(444 == r, "Expected %d, got %d\n", 444, r);
2006 /* tests for WM_CHAR */
2007 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 3);
2008 ok(444 == r, "Expected %d, got %d\n", 444, r);
2009 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 4);
2010 ok(444 == r, "Expected %d, got %d\n", 444, r);
2011 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 5);
2012 ok(444 == r, "Expected %d, got %d\n", 444, r);
2014 /* tests for WM_KEYDOWN + WM_CHAR */
2015 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 6);
2016 ok(444 == r, "Expected %d, got %d\n", 444, r);
2017 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 7);
2018 ok(444 == r, "Expected %d, got %d\n", 444, r);
2019 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 8);
2020 ok(444 == r, "Expected %d, got %d\n", 444, r);
2023 static void test_singleline_wantreturn_edit_dialog(void)
2027 /* tests for WM_KEYDOWN */
2028 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
2029 ok(222 == r, "Expected %d, got %d\n", 222, r);
2030 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
2031 ok(111 == r, "Expected %d, got %d\n", 111, r);
2032 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
2033 ok(444 == r, "Expected %d, got %d\n", 444, r);
2035 /* tests for WM_CHAR */
2036 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
2037 ok(444 == r, "Expected %d, got %d\n", 444, r);
2038 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
2039 ok(444 == r, "Expected %d, got %d\n", 444, r);
2040 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
2041 ok(444 == r, "Expected %d, got %d\n", 444, r);
2043 /* tests for WM_KEYDOWN + WM_CHAR */
2044 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
2045 ok(222 == r, "Expected %d, got %d\n", 222, r);
2046 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
2047 ok(111 == r, "Expected %d, got %d\n", 111, r);
2048 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
2049 ok(444 == r, "Expected %d, got %d\n", 444, r);
2051 /* tests for WM_KEYDOWN */
2052 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
2053 ok(222 == r, "Expected %d, got %d\n", 222, r);
2054 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
2055 ok(111 == r, "Expected %d, got %d\n", 111, r);
2056 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
2057 ok(444 == r, "Expected %d, got %d\n", 444, r);
2059 /* tests for WM_CHAR */
2060 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
2061 ok(444 == r, "Expected %d, got %d\n", 444, r);
2062 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
2063 ok(444 == r, "Expected %d, got %d\n", 444, r);
2064 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
2065 ok(444 == r, "Expected %d, got %d\n", 444, r);
2067 /* tests for WM_KEYDOWN + WM_CHAR */
2068 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
2069 ok(222 == r, "Expected %d, got %d\n", 222, r);
2070 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
2071 ok(111 == r, "Expected %d, got %d\n", 111, r);
2072 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
2073 ok(444 == r, "Expected %d, got %d\n", 444, r);
2076 static int child_edit_wmkeydown_num_messages = 0;
2077 static INT_PTR CALLBACK child_edit_wmkeydown_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
2086 child_edit_wmkeydown_num_messages++;
2093 static void test_child_edit_wmkeydown(void)
2095 HWND hwEdit, hwParent;
2098 hwEdit = create_child_editcontrol(0, 0);
2099 hwParent = GetParent(hwEdit);
2100 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)child_edit_wmkeydown_proc);
2101 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2102 ok(1 == r, "expected 1, got %d\n", r);
2103 ok(0 == child_edit_wmkeydown_num_messages, "expected 0, got %d\n", child_edit_wmkeydown_num_messages);
2104 destroy_child_editcontrol(hwEdit);
2107 static int got_en_setfocus = 0;
2108 static int got_wm_capturechanged = 0;
2110 static LRESULT CALLBACK edit4_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2114 switch (HIWORD(wParam)) {
2116 got_en_setfocus = 1;
2120 case WM_CAPTURECHANGED:
2121 if (hWnd != (HWND)lParam)
2123 got_wm_capturechanged = 1;
2128 return DefWindowProcA(hWnd, msg, wParam, lParam);
2131 static void test_contextmenu_focus(void)
2133 HWND hwndMain, hwndEdit;
2135 hwndMain = CreateWindow(szEditTest4Class, "ET4", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
2136 0, 0, 200, 200, NULL, NULL, hinst, NULL);
2139 hwndEdit = CreateWindow("EDIT", NULL,
2140 WS_CHILD|WS_BORDER|WS_VISIBLE|ES_LEFT|ES_AUTOHSCROLL,
2141 0, 0, 150, 50, /* important this not be 0 size. */
2142 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
2147 SetCapture(hwndMain);
2149 SendMessage(hwndEdit, WM_CONTEXTMENU, (WPARAM)hwndEdit, MAKEWORD(10, 10));
2151 ok(got_en_setfocus, "edit box didn't get focused\n");
2153 ok(got_wm_capturechanged, "main window capture did not change\n");
2155 DestroyWindow (hwndEdit);
2156 DestroyWindow (hwndMain);
2159 static BOOL RegisterWindowClasses (void)
2164 WNDCLASSA text_position;
2167 test2.lpfnWndProc = ET2_WndProc;
2168 test2.cbClsExtra = 0;
2169 test2.cbWndExtra = 0;
2170 test2.hInstance = hinst;
2172 test2.hCursor = LoadCursorA (NULL, IDC_ARROW);
2173 test2.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2174 test2.lpszMenuName = NULL;
2175 test2.lpszClassName = szEditTest2Class;
2176 if (!RegisterClassA(&test2)) return FALSE;
2179 test3.lpfnWndProc = edit3_wnd_procA;
2180 test3.cbClsExtra = 0;
2181 test3.cbWndExtra = 0;
2182 test3.hInstance = hinst;
2184 test3.hCursor = LoadCursorA(0, IDC_ARROW);
2185 test3.hbrBackground = GetStockObject(WHITE_BRUSH);
2186 test3.lpszMenuName = NULL;
2187 test3.lpszClassName = szEditTest3Class;
2188 if (!RegisterClassA(&test3)) return FALSE;
2191 test4.lpfnWndProc = edit4_wnd_procA;
2192 test4.cbClsExtra = 0;
2193 test4.cbWndExtra = 0;
2194 test4.hInstance = hinst;
2196 test4.hCursor = LoadCursorA (NULL, IDC_ARROW);
2197 test4.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2198 test4.lpszMenuName = NULL;
2199 test4.lpszClassName = szEditTest4Class;
2200 if (!RegisterClassA(&test4)) return FALSE;
2202 text_position.style = CS_HREDRAW | CS_VREDRAW;
2203 text_position.cbClsExtra = 0;
2204 text_position.cbWndExtra = 0;
2205 text_position.hInstance = hinst;
2206 text_position.hIcon = NULL;
2207 text_position.hCursor = LoadCursorA(NULL, IDC_ARROW);
2208 text_position.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2209 text_position.lpszMenuName = NULL;
2210 text_position.lpszClassName = szEditTextPositionClass;
2211 text_position.lpfnWndProc = DefWindowProc;
2212 if (!RegisterClassA(&text_position)) return FALSE;
2217 static void UnregisterWindowClasses (void)
2219 UnregisterClassA(szEditTest2Class, hinst);
2220 UnregisterClassA(szEditTest3Class, hinst);
2221 UnregisterClassA(szEditTest4Class, hinst);
2222 UnregisterClassA(szEditTextPositionClass, hinst);
2225 static void test_fontsize(void)
2232 char szLocalString[MAXLEN];
2236 dpi = GetDeviceCaps(hDC, LOGPIXELSY);
2237 ReleaseDC(NULL, hDC);
2239 memset(&lf,0,sizeof(LOGFONTA));
2240 strcpy(lf.lfFaceName,"Arial");
2241 lf.lfHeight = -300; /* taller than the edit box */
2243 hfont = CreateFontIndirect(&lf);
2245 trace("EDIT: Oversized font (Multi line)\n");
2246 hwEdit= CreateWindow("EDIT", NULL, ES_MULTILINE|ES_AUTOHSCROLL,
2247 0, 0, (150 * dpi) / 96, (50 * dpi) / 96, NULL, NULL,
2250 SendMessage(hwEdit,WM_SETFONT,(WPARAM)hfont,0);
2252 if (winetest_interactive)
2253 ShowWindow (hwEdit, SW_SHOW);
2255 r = SendMessage(hwEdit, WM_CHAR, 'A', 1);
2256 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2257 r = SendMessage(hwEdit, WM_CHAR, 'B', 1);
2258 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2259 r = SendMessage(hwEdit, WM_CHAR, 'C', 1);
2260 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2262 GetWindowText(hwEdit, szLocalString, MAXLEN);
2263 ok(lstrcmp(szLocalString, "ABC")==0,
2264 "Wrong contents of edit: %s\n", szLocalString);
2266 r = SendMessage(hwEdit, EM_POSFROMCHAR,0,0);
2267 ok(r != -1,"EM_POSFROMCHAR failed index 0\n");
2268 r = SendMessage(hwEdit, EM_POSFROMCHAR,1,0);
2269 ok(r != -1,"EM_POSFROMCHAR failed index 1\n");
2270 r = SendMessage(hwEdit, EM_POSFROMCHAR,2,0);
2271 ok(r != -1,"EM_POSFROMCHAR failed index 2\n");
2272 r = SendMessage(hwEdit, EM_POSFROMCHAR,3,0);
2273 ok(r == -1,"EM_POSFROMCHAR succeeded index 3\n");
2275 DestroyWindow (hwEdit);
2276 DeleteObject(hfont);
2279 struct dialog_mode_messages
2281 int wm_getdefid, wm_close, wm_command, wm_nextdlgctl;
2284 static struct dialog_mode_messages dm_messages;
2286 static void zero_dm_messages(void)
2288 dm_messages.wm_command = 0;
2289 dm_messages.wm_close = 0;
2290 dm_messages.wm_getdefid = 0;
2291 dm_messages.wm_nextdlgctl = 0;
2294 #define test_dm_messages(wmcommand, wmclose, wmgetdefid, wmnextdlgctl) \
2295 ok(dm_messages.wm_command == wmcommand, "expected %d WM_COMMAND messages, " \
2296 "got %d\n", wmcommand, dm_messages.wm_command); \
2297 ok(dm_messages.wm_close == wmclose, "expected %d WM_CLOSE messages, " \
2298 "got %d\n", wmclose, dm_messages.wm_close); \
2299 ok(dm_messages.wm_getdefid == wmgetdefid, "expected %d WM_GETDIFID messages, " \
2300 "got %d\n", wmgetdefid, dm_messages.wm_getdefid);\
2301 ok(dm_messages.wm_nextdlgctl == wmnextdlgctl, "expected %d WM_NEXTDLGCTL messages, " \
2302 "got %d\n", wmnextdlgctl, dm_messages.wm_nextdlgctl)
2304 static LRESULT CALLBACK dialog_mode_wnd_proc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
2309 dm_messages.wm_command++;
2312 dm_messages.wm_getdefid++;
2313 return MAKELONG(ID_EDITTESTDBUTTON, DC_HASDEFID);
2315 dm_messages.wm_nextdlgctl++;
2318 dm_messages.wm_close++;
2322 return DefWindowProc(hwnd, iMsg, wParam, lParam);
2325 static void test_dialogmode(void)
2327 HWND hwEdit, hwParent, hwButton;
2330 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2332 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2333 ok(1 == r, "expected 1, got %d\n", r);
2334 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2335 ok(11 == len, "expected 11, got %d\n", len);
2337 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, 0);
2338 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2340 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2341 ok(1 == r, "expected 1, got %d\n", r);
2342 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2343 ok(13 == len, "expected 13, got %d\n", len);
2345 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
2346 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2347 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2348 ok(1 == r, "expected 1, got %d\n", r);
2349 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2350 ok(13 == len, "expected 13, got %d\n", len);
2352 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2353 ok(1 == r, "expected 1, got %d\n", r);
2354 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2355 ok(13 == len, "expected 13, got %d\n", len);
2357 destroy_child_editcontrol(hwEdit);
2359 hwEdit = create_editcontrol(ES_MULTILINE, 0);
2361 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2362 ok(1 == r, "expected 1, got %d\n", r);
2363 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2364 ok(11 == len, "expected 11, got %d\n", len);
2367 msg.message = WM_KEYDOWN;
2368 msg.wParam = VK_BACK;
2369 msg.lParam = 0xe0001;
2370 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_BACK, (LPARAM)&msg);
2371 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2373 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2374 ok(1 == r, "expected 1, got %d\n", r);
2375 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2376 ok(11 == len, "expected 11, got %d\n", len);
2378 DestroyWindow(hwEdit);
2380 hwEdit = create_child_editcontrol(0, 0);
2381 hwParent = GetParent(hwEdit);
2382 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2385 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2386 ok(1 == r, "expected 1, got %d\n", r);
2387 test_dm_messages(0, 0, 0, 0);
2390 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2391 ok(1 == r, "expected 1, got %d\n", r);
2392 test_dm_messages(0, 0, 0, 0);
2396 msg.message = WM_KEYDOWN;
2397 msg.wParam = VK_TAB;
2398 msg.lParam = 0xf0001;
2399 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_TAB, (LPARAM)&msg);
2400 ok(0x89 == r, "expected 0x89, got 0x%x\n", r);
2401 test_dm_messages(0, 0, 0, 0);
2404 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2405 ok(1 == r, "expected 1, got %d\n", r);
2406 test_dm_messages(0, 0, 0, 0);
2409 destroy_child_editcontrol(hwEdit);
2411 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2412 hwParent = GetParent(hwEdit);
2413 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2415 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2416 ok(1 == r, "expected 1, got %d\n", r);
2417 test_dm_messages(0, 0, 0, 0);
2421 msg.message = WM_KEYDOWN;
2422 msg.wParam = VK_ESCAPE;
2423 msg.lParam = 0x10001;
2424 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_ESCAPE, (LPARAM)&msg);
2425 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2426 test_dm_messages(0, 0, 0, 0);
2429 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2430 ok(1 == r, "expected 1, got %d\n", r);
2431 test_dm_messages(0, 0, 0, 0);
2434 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2435 ok(1 == r, "expected 1, got %d\n", r);
2436 test_dm_messages(0, 0, 0, 1);
2439 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2440 ok(1 == r, "expected 1, got %d\n", r);
2441 test_dm_messages(0, 0, 1, 0);
2444 hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
2445 100, 100, 50, 20, hwParent, (HMENU)ID_EDITTESTDBUTTON, hinst, NULL);
2446 ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
2448 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2449 ok(1 == r, "expected 1, got %d\n", r);
2450 test_dm_messages(0, 0, 1, 1);
2453 DestroyWindow(hwButton);
2454 destroy_child_editcontrol(hwEdit);
2461 init_function_pointers();
2463 hinst = GetModuleHandleA(NULL);
2464 b = RegisterWindowClasses();
2465 ok (b, "RegisterWindowClasses failed\n");
2468 test_edit_control_1();
2469 test_edit_control_2();
2470 test_edit_control_3();
2471 test_edit_control_4();
2472 test_edit_control_5();
2473 test_edit_control_6();
2474 test_edit_control_limittext();
2475 test_edit_control_scroll();
2477 test_margins_font_change();
2478 test_text_position();
2484 test_multi_edit_dialog();
2485 test_wantreturn_edit_dialog();
2486 test_singleline_wantreturn_edit_dialog();
2487 test_child_edit_wmkeydown();
2491 test_contextmenu_focus();
2493 win_skip("EndMenu is not available\n");
2495 UnregisterWindowClasses();