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_EDITTEST2 99
35 int en_change, en_maxtext, en_update;
38 static struct edit_notify notifications;
40 static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
42 static int num_ok_commands = 0;
47 HWND hedit = GetDlgItem(hdlg, 1000);
51 /* test cases related to bug 12319 */
53 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
54 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
57 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
58 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
61 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
62 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
63 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
66 /* test cases for pressing enter */
69 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
70 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
80 if (HIWORD(wparam) != BN_CLICKED)
83 switch (LOWORD(wparam))
96 HWND hfocus = GetFocus();
97 HWND hedit = GetDlgItem(hdlg, 1000);
98 HWND hedit2 = GetDlgItem(hdlg, 1001);
99 HWND hedit3 = GetDlgItem(hdlg, 1002);
101 if (wparam != 0xdeadbeef)
108 EndDialog(hdlg, 1111);
109 else if (hfocus == hedit2)
110 EndDialog(hdlg, 2222);
111 else if (hfocus == hedit3)
112 EndDialog(hdlg, 3333);
114 EndDialog(hdlg, 4444);
117 if ((hfocus == hedit) && (num_ok_commands == 0))
123 EndDialog(hdlg, 5555);
129 EndDialog(hdlg, 333);
139 static INT_PTR CALLBACK edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
145 HWND hedit = GetDlgItem(hdlg, 1000);
151 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
154 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
157 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
158 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
161 /* more test cases for WM_CHAR */
163 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
164 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
167 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
168 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
171 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
172 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
175 /* more test cases for WM_KEYDOWN + WM_CHAR */
177 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
178 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
179 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
182 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
183 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
184 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
187 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
188 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
189 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
192 /* multiple tab tests */
194 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
195 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
196 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
199 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
200 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
201 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
202 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
212 if (HIWORD(wparam) != BN_CLICKED)
215 switch (LOWORD(wparam))
218 EndDialog(hdlg, 111);
222 EndDialog(hdlg, 222);
233 HWND hok = GetDlgItem(hdlg, IDOK);
234 HWND hcancel = GetDlgItem(hdlg, IDCANCEL);
235 HWND hedit = GetDlgItem(hdlg, 1000);
236 HWND hfocus = GetFocus();
238 if (wparam != 0xdeadbeef)
244 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
246 EndDialog(hdlg, 444);
248 EndDialog(hdlg, 555);
252 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
253 if ((hfocus == hok) && len == 0)
254 EndDialog(hdlg, 444);
256 EndDialog(hdlg, 555);
262 else if (hfocus == hcancel)
264 else if (hfocus == hedit)
271 EndDialog(hdlg, 555);
277 EndDialog(hdlg, 333);
287 static INT_PTR CALLBACK edit_singleline_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
293 HWND hedit = GetDlgItem(hdlg, 1000);
297 /* test cases for WM_KEYDOWN */
299 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
302 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
303 /* needed so the test does not wait for user input */
304 PostMessage(hdlg, WM_USER, 0xfeedbeef, 0);
307 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
308 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
311 /* test cases for WM_CHAR */
313 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
314 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
317 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
318 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
321 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
322 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
325 /* test cases for WM_KEYDOWN + WM_CHAR */
327 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
328 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
331 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
332 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
333 /* needed so the test does not wait for user input */
334 PostMessage(hdlg, WM_USER, 0xfeedbeef, 0);
337 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
338 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
339 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
349 if (HIWORD(wparam) != BN_CLICKED)
352 switch (LOWORD(wparam))
355 EndDialog(hdlg, 111);
359 EndDialog(hdlg, 222);
369 HWND hok = GetDlgItem(hdlg, IDOK);
370 HWND hedit = GetDlgItem(hdlg, 1000);
371 HWND hfocus = GetFocus();
372 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
374 if (wparam == 0xfeedbeef)
379 if (wparam != 0xdeadbeef)
385 if ((hfocus == hedit) && len == 0)
386 EndDialog(hdlg, 444);
388 EndDialog(hdlg, 555);
392 if ((hfocus == hok) && len == 0)
393 EndDialog(hdlg, 444);
395 EndDialog(hdlg, 555);
405 EndDialog(hdlg, 333);
415 static INT_PTR CALLBACK edit_wantreturn_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
421 HWND hedit = GetDlgItem(hdlg, 1000);
425 /* test cases for WM_KEYDOWN */
427 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
430 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
431 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
434 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
435 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
438 /* test cases for WM_CHAR */
440 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
441 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
444 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
445 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
448 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
449 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
452 /* test cases for WM_KEYDOWN + WM_CHAR */
454 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
455 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
456 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
459 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
460 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
461 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
464 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
465 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
466 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
476 if (HIWORD(wparam) != BN_CLICKED)
479 switch (LOWORD(wparam))
482 EndDialog(hdlg, 111);
486 EndDialog(hdlg, 222);
496 HWND hok = GetDlgItem(hdlg, IDOK);
497 HWND hedit = GetDlgItem(hdlg, 1000);
498 HWND hfocus = GetFocus();
499 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
501 if (wparam != 0xdeadbeef)
507 if ((hfocus == hedit) && len == 0)
508 EndDialog(hdlg, 444);
510 EndDialog(hdlg, 555);
514 if ((hfocus == hok) && len == 0)
515 EndDialog(hdlg, 444);
517 EndDialog(hdlg, 555);
521 if ((hfocus == hedit) && len == 2)
522 EndDialog(hdlg, 444);
524 EndDialog(hdlg, 555);
534 EndDialog(hdlg, 333);
544 static HINSTANCE hinst;
546 static const char szEditTest2Class[] = "EditTest2Class";
547 static const char szEditTest3Class[] = "EditTest3Class";
548 static const char szEditTextPositionClass[] = "EditTextPositionWindowClass";
550 static HWND create_editcontrol (DWORD style, DWORD exstyle)
554 handle = CreateWindowEx(exstyle,
559 NULL, NULL, hinst, NULL);
561 if (winetest_interactive)
562 ShowWindow (handle, SW_SHOW);
566 static HWND create_child_editcontrol (DWORD style, DWORD exstyle)
576 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
578 parentWnd = CreateWindowEx(0,
579 szEditTextPositionClass,
582 CW_USEDEFAULT, CW_USEDEFAULT,
583 rect.right - rect.left, rect.bottom - rect.top,
584 NULL, NULL, hinst, NULL);
587 editWnd = CreateWindowEx(exstyle,
592 parentWnd, NULL, hinst, NULL);
594 if (winetest_interactive)
595 ShowWindow (parentWnd, SW_SHOW);
599 static void destroy_child_editcontrol (HWND hwndEdit)
601 if (GetParent(hwndEdit))
602 DestroyWindow(GetParent(hwndEdit));
604 trace("Edit control has no parent!\n");
605 DestroyWindow(hwndEdit);
609 static LONG get_edit_style (HWND hwnd)
611 return GetWindowLongA( hwnd, GWL_STYLE ) & (
613 /* FIXME: not implemented
632 static void set_client_height(HWND Wnd, unsigned Height)
634 RECT ClientRect, WindowRect;
636 GetWindowRect(Wnd, &WindowRect);
637 GetClientRect(Wnd, &ClientRect);
638 SetWindowPos(Wnd, NULL, 0, 0,
639 WindowRect.right - WindowRect.left,
640 Height + (WindowRect.bottom - WindowRect.top) -
641 (ClientRect.bottom - ClientRect.top),
642 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
644 /* Workaround for a bug in Windows' edit control
646 GetWindowRect(Wnd, &WindowRect);
647 SetWindowPos(Wnd, NULL, 0, 0,
648 WindowRect.right - WindowRect.left + 1,
649 WindowRect.bottom - WindowRect.top + 1,
650 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
651 SetWindowPos(Wnd, NULL, 0, 0,
652 WindowRect.right - WindowRect.left,
653 WindowRect.bottom - WindowRect.top,
654 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
656 GetClientRect(Wnd, &ClientRect);
657 ok(ClientRect.bottom - ClientRect.top == Height,
658 "The client height should be %ld, but is %ld\n",
659 (long)Height, (long)(ClientRect.bottom - ClientRect.top));
662 static void test_edit_control_1(void)
669 msMessage.message = WM_KEYDOWN;
671 trace("EDIT: Single line\n");
672 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
673 r = get_edit_style(hwEdit);
674 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%x\n", r);
675 for (i=0;i<65535;i++)
677 msMessage.wParam = i;
678 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
679 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
680 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
682 DestroyWindow (hwEdit);
684 trace("EDIT: Single line want returns\n");
685 hwEdit = create_editcontrol(ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
686 r = get_edit_style(hwEdit);
687 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%x\n", r);
688 for (i=0;i<65535;i++)
690 msMessage.wParam = i;
691 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
692 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
693 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
695 DestroyWindow (hwEdit);
697 trace("EDIT: Multiline line\n");
698 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
699 r = get_edit_style(hwEdit);
700 ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%x\n", r);
701 for (i=0;i<65535;i++)
703 msMessage.wParam = i;
704 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
705 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
706 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
708 DestroyWindow (hwEdit);
710 trace("EDIT: Multi line want returns\n");
711 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
712 r = get_edit_style(hwEdit);
713 ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%x\n", r);
714 for (i=0;i<65535;i++)
716 msMessage.wParam = i;
717 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
718 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
719 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
721 DestroyWindow (hwEdit);
724 /* WM_SETTEXT is implemented by selecting all text, and then replacing the
725 * selection. This test checks that the first 'select all' doesn't generate
726 * an UPDATE message which can escape and (via a handler) change the
727 * selection, which would cause WM_SETTEXT to break. This old bug
728 * was fixed 18-Mar-2005; we check here to ensure it doesn't regress.
730 static void test_edit_control_2(void)
733 char szLocalString[MAXLEN];
736 /* Create main and edit windows. */
737 hwndMain = CreateWindow(szEditTest2Class, "ET2", WS_OVERLAPPEDWINDOW,
738 0, 0, 200, 200, NULL, NULL, hinst, NULL);
740 if (winetest_interactive)
741 ShowWindow (hwndMain, SW_SHOW);
743 hwndET2 = CreateWindow("EDIT", NULL,
744 WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
745 0, 0, 150, 50, /* important this not be 0 size. */
746 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
748 if (winetest_interactive)
749 ShowWindow (hwndET2, SW_SHOW);
751 trace("EDIT: SETTEXT atomicity\n");
752 /* Send messages to "type" in the word 'foo'. */
753 r = SendMessage(hwndET2, WM_CHAR, 'f', 1);
754 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
755 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
756 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
757 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
758 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
759 /* 'foo' should have been changed to 'bar' by the UPDATE handler. */
760 GetWindowText(hwndET2, szLocalString, MAXLEN);
761 ok(lstrcmp(szLocalString, "bar")==0,
762 "Wrong contents of edit: %s\n", szLocalString);
765 DestroyWindow (hwndET2);
766 DestroyWindow (hwndMain);
769 static void ET2_check_change(void) {
770 char szLocalString[MAXLEN];
771 /* This EN_UPDATE handler changes any 'foo' to 'bar'. */
772 GetWindowText(hwndET2, szLocalString, MAXLEN);
773 if (lstrcmp(szLocalString, "foo")==0) {
774 lstrcpy(szLocalString, "bar");
775 SendMessage(hwndET2, WM_SETTEXT, 0, (LPARAM) szLocalString);
777 /* always leave the cursor at the end. */
778 SendMessage(hwndET2, EM_SETSEL, MAXLEN - 1, MAXLEN - 1);
780 static void ET2_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
782 if (id==ID_EDITTEST2 && codeNotify == EN_UPDATE)
785 static LRESULT CALLBACK ET2_WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
789 ET2_OnCommand(hwnd, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
792 return DefWindowProc(hwnd, iMsg, wParam, lParam);
795 static void zero_notify(void)
797 notifications.en_change = 0;
798 notifications.en_maxtext = 0;
799 notifications.en_update = 0;
802 #define test_notify(enchange, enmaxtext, enupdate) \
803 ok(notifications.en_change == enchange, "expected %d EN_CHANGE notifications, " \
804 "got %d\n", enchange, notifications.en_change); \
805 ok(notifications.en_maxtext == enmaxtext, "expected %d EN_MAXTEXT notifications, " \
806 "got %d\n", enmaxtext, notifications.en_maxtext); \
807 ok(notifications.en_update == enupdate, "expected %d EN_UPDATE notifications, " \
808 "got %d\n", enupdate, notifications.en_update)
811 static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
815 switch (HIWORD(wParam)) {
817 notifications.en_maxtext++;
820 notifications.en_update++;
823 notifications.en_change++;
828 return DefWindowProcA(hWnd, msg, wParam, lParam);
831 /* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
834 static void test_edit_control_3(void)
839 static const char *str = "this is a long string.";
840 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.";
842 trace("EDIT: Test notifications\n");
844 hParent = CreateWindowExA(0,
848 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10,
849 NULL, NULL, NULL, NULL);
852 trace("EDIT: Single line, no ES_AUTOHSCROLL\n");
853 hWnd = CreateWindowExA(0,
858 hParent, NULL, NULL, NULL);
862 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
863 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
864 ok(lstrlenA(str) > len, "text should have been truncated\n");
865 test_notify(1, 1, 1);
867 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
869 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
870 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
871 ok(1 == len, "wrong text length, expected 1, got %d\n", len);
872 test_notify(1, 0, 1);
875 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
876 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
877 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
878 test_notify(1, 0, 1);
880 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
882 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
884 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
885 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
886 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
887 test_notify(1, 1, 1);
890 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
891 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
892 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
893 test_notify(1, 0, 1);
897 trace("EDIT: Single line, ES_AUTOHSCROLL\n");
898 hWnd = CreateWindowExA(0,
903 hParent, NULL, NULL, NULL);
907 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
908 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
909 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
910 test_notify(1, 0, 1);
913 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
914 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
915 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
916 test_notify(1, 0, 1);
918 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
920 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
922 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
923 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
924 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
925 test_notify(1, 1, 1);
928 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
929 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
930 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
931 test_notify(1, 0, 1);
935 trace("EDIT: Multline, no ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
936 hWnd = CreateWindowExA(0,
941 hParent, NULL, NULL, NULL);
945 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
946 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
947 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
948 test_notify(1, 1, 1);
950 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
952 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
953 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
954 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
955 test_notify(1, 0, 1);
958 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
959 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
960 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
961 test_notify(0, 0, 0);
963 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
965 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
967 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
968 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
969 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
970 test_notify(1, 1, 1);
973 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
974 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
975 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
976 test_notify(0, 0, 0);
980 trace("EDIT: Multline, ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
981 hWnd = CreateWindowExA(0,
984 ES_MULTILINE | ES_AUTOHSCROLL,
986 hParent, NULL, NULL, NULL);
990 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
991 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
992 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
993 test_notify(1, 1, 1);
995 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
997 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
998 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
999 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
1000 test_notify(1, 0, 1);
1003 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1004 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1005 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1006 test_notify(0, 0, 0);
1008 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1010 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1012 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1013 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1014 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1015 test_notify(1, 1, 1);
1018 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1019 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1020 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1021 test_notify(0, 0, 0);
1023 DestroyWindow(hWnd);
1025 trace("EDIT: Multline, ES_AUTOHSCROLL and ES_AUTOVSCROLL\n");
1026 hWnd = CreateWindowExA(0,
1029 ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
1031 hParent, NULL, NULL, NULL);
1035 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1036 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1037 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1038 test_notify(1, 0, 1);
1041 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1042 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1043 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1044 test_notify(0, 0, 0);
1046 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1048 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1050 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1051 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1052 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1053 test_notify(1, 1, 1);
1056 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1057 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1058 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1059 test_notify(0, 0, 0);
1061 DestroyWindow(hWnd);
1064 /* Test EM_CHARFROMPOS and EM_POSFROMCHAR
1066 static void test_edit_control_4(void)
1073 trace("EDIT: Test EM_CHARFROMPOS and EM_POSFROMCHAR\n");
1074 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1075 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1076 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1077 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1078 mid = lo + (hi - lo) / 2;
1080 for (i = lo; i < mid; i++) {
1081 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1082 ok(0 == ret, "expected 0 got %d\n", ret);
1084 for (i = mid; i <= hi; i++) {
1085 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1086 ok(1 == ret, "expected 1 got %d\n", ret);
1088 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1089 ok(-1 == ret, "expected -1 got %d\n", ret);
1090 DestroyWindow(hwEdit);
1092 hwEdit = create_editcontrol(ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1093 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1094 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1095 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1096 mid = lo + (hi - lo) / 2;
1098 for (i = lo; i < mid; i++) {
1099 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1100 ok(0 == ret, "expected 0 got %d\n", ret);
1102 for (i = mid; i <= hi; i++) {
1103 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1104 ok(1 == ret, "expected 1 got %d\n", ret);
1106 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1107 ok(-1 == ret, "expected -1 got %d\n", ret);
1108 DestroyWindow(hwEdit);
1110 hwEdit = create_editcontrol(ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1111 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1112 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1113 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1114 mid = lo + (hi - lo) / 2;
1116 for (i = lo; i < mid; i++) {
1117 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1118 ok(0 == ret, "expected 0 got %d\n", ret);
1120 for (i = mid; i <= hi; i++) {
1121 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1122 ok(1 == ret, "expected 1 got %d\n", ret);
1124 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1125 ok(-1 == ret, "expected -1 got %d\n", ret);
1126 DestroyWindow(hwEdit);
1128 hwEdit = create_editcontrol(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1129 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1130 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1131 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1132 mid = lo + (hi - lo) / 2 +1;
1134 for (i = lo; i < mid; i++) {
1135 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1136 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1138 for (i = mid; i <= hi; i++) {
1139 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1140 ok(1 == ret, "expected 1 got %d\n", ret);
1142 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1143 ok(-1 == ret, "expected -1 got %d\n", ret);
1144 DestroyWindow(hwEdit);
1146 hwEdit = create_editcontrol(ES_MULTILINE | ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1147 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1148 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1149 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1150 mid = lo + (hi - lo) / 2 +1;
1152 for (i = lo; i < mid; i++) {
1153 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1154 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1156 for (i = mid; i <= hi; i++) {
1157 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1158 ok(1 == ret, "expected 1 got %d\n", ret);
1160 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1161 ok(-1 == ret, "expected -1 got %d\n", ret);
1162 DestroyWindow(hwEdit);
1164 hwEdit = create_editcontrol(ES_MULTILINE | ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1165 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1166 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1167 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1168 mid = lo + (hi - lo) / 2 +1;
1170 for (i = lo; i < mid; i++) {
1171 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1172 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1174 for (i = mid; i <= hi; i++) {
1175 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, (LPARAM) i));
1176 ok(1 == ret, "expected 1 got %d\n", ret);
1178 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1179 ok(-1 == ret, "expected -1 got %d\n", ret);
1180 DestroyWindow(hwEdit);
1183 /* Test if creating edit control without ES_AUTOHSCROLL and ES_AUTOVSCROLL
1184 * truncates text that doesn't fit.
1186 static void test_edit_control_5(void)
1188 static const char *str = "test\r\ntest";
1192 hWnd = CreateWindowEx(0,
1197 NULL, NULL, NULL, NULL);
1200 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1201 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1202 DestroyWindow(hWnd);
1204 hWnd = CreateWindowEx(0,
1209 NULL, NULL, NULL, NULL);
1212 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1213 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1214 DestroyWindow(hWnd);
1217 static void test_edit_control_limittext(void)
1222 /* Test default limit for single-line control */
1223 trace("EDIT: buffer limit for single-line\n");
1224 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1225 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1226 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1227 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1228 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1229 /* Win9x+ME: 32766; WinNT: 2147483646UL */
1230 ok( (r == 32766) || (r == 2147483646UL),
1231 "got limit %u (expected 32766 or 2147483646)\n", r);
1232 DestroyWindow(hwEdit);
1234 /* Test default limit for multi-line control */
1235 trace("EDIT: buffer limit for multi-line\n");
1236 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1237 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1238 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1239 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1240 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1241 /* Win9x+ME: 65535; WinNT: 4294967295UL */
1242 ok( (r == 65535) || (r == 4294967295UL),
1243 "got limit %u (expected 65535 or 4294967295)\n", r);
1244 DestroyWindow(hwEdit);
1247 static void test_margins(void)
1250 RECT old_rect, new_rect;
1251 INT old_left_margin, old_right_margin;
1252 DWORD old_margins, new_margins;
1254 hwEdit = create_editcontrol(WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1256 old_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1257 old_left_margin = LOWORD(old_margins);
1258 old_right_margin = HIWORD(old_margins);
1260 /* Check if setting the margins works */
1262 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(10, 0));
1263 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1264 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1265 ok(HIWORD(new_margins) == old_right_margin, "Wrong right margin: %d\n", HIWORD(new_margins));
1267 SendMessage(hwEdit, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, 10));
1268 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1269 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1270 ok(HIWORD(new_margins) == 10, "Wrong right margin: %d\n", HIWORD(new_margins));
1273 /* The size of the rectangle must decrease if we increase the margin */
1275 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5));
1276 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1277 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(15, 20));
1278 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1279 ok(new_rect.left == old_rect.left + 10, "The left border of the rectangle is wrong\n");
1280 ok(new_rect.right == old_rect.right - 15, "The right border of the rectangle is wrong\n");
1281 ok(new_rect.top == old_rect.top, "The top border of the rectangle must not change\n");
1282 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle must not change\n");
1285 /* If we set the margin to same value as the current margin,
1286 the rectangle must not change */
1288 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1290 old_rect.right = 99;
1292 old_rect.bottom = 99;
1293 SendMessage(hwEdit, EM_SETRECT, 0, (LPARAM)&old_rect);
1294 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1295 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1296 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1297 ok(new_rect.left == old_rect.left, "The left border of the rectangle has changed\n");
1298 ok(new_rect.right == old_rect.right, "The right border of the rectangle has changed\n");
1299 ok(new_rect.top == old_rect.top, "The top border of the rectangle has changed\n");
1300 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n");
1302 DestroyWindow (hwEdit);
1305 static INT CALLBACK find_font_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
1310 static void test_margins_font_change(void)
1313 DWORD margins, font_margins;
1315 HFONT hfont, hfont2;
1318 if(EnumFontFamiliesA(hdc, "Arial", find_font_proc, 0))
1320 trace("Arial not found - skipping font change margin tests\n");
1326 hwEdit = create_child_editcontrol(0, 0);
1328 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1330 memset(&lf, 0, sizeof(lf));
1331 strcpy(lf.lfFaceName, "Arial");
1333 lf.lfCharSet = DEFAULT_CHARSET;
1334 hfont = CreateFontIndirectA(&lf);
1336 hfont2 = CreateFontIndirectA(&lf);
1338 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1339 font_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1340 ok(LOWORD(font_margins) != 0, "got %d\n", LOWORD(font_margins));
1341 ok(HIWORD(font_margins) != 0, "got %d\n", HIWORD(font_margins));
1343 /* With 'small' edit controls, test that the margin doesn't get set */
1344 SetWindowPos(hwEdit, NULL, 10, 10, 16, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1345 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0,0));
1346 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1347 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1348 ok(LOWORD(margins) == 0, "got %d\n", LOWORD(margins));
1349 ok(HIWORD(margins) == 0, "got %d\n", HIWORD(margins));
1351 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1352 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1353 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1354 ok(LOWORD(margins) == 1, "got %d\n", LOWORD(margins));
1355 ok(HIWORD(margins) == 0, "got %d\n", HIWORD(margins));
1357 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1358 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1359 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1360 ok(LOWORD(margins) == 1, "got %d\n", LOWORD(margins));
1361 ok(HIWORD(margins) == 1, "got %d\n", HIWORD(margins));
1363 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1364 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1365 ok(LOWORD(margins) == 1, "got %d\n", LOWORD(margins));
1366 ok(HIWORD(margins) == 1, "got %d\n", HIWORD(margins));
1367 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1368 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1369 ok(LOWORD(margins) == 1, "got %d\n", LOWORD(margins));
1370 ok(HIWORD(margins) == 1, "got %d\n", HIWORD(margins));
1372 /* Above a certain size threshold then the margin is updated */
1373 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1374 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1375 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1376 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1377 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1378 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1380 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1381 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1382 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1383 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1384 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1386 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1387 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1388 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1389 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1390 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1391 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1392 ok(LOWORD(margins) != LOWORD(font_margins), "got %d\n", LOWORD(margins));
1393 ok(HIWORD(margins) != HIWORD(font_margins), "got %d\n", HIWORD(margins));
1395 SendMessageA(hwEdit, WM_SETFONT, 0, 0);
1397 DeleteObject(hfont2);
1398 DeleteObject(hfont);
1399 destroy_child_editcontrol(hwEdit);
1403 #define edit_pos_ok(exp, got, txt) \
1404 ok(exp == got, "wrong " #txt " expected %d got %d\n", exp, got);
1406 #define check_pos(hwEdit, set_height, test_top, test_height, test_left) \
1410 set_client_height(hwEdit, set_height); \
1411 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &format_rect); \
1412 left_margin = LOWORD(SendMessage(hwEdit, EM_GETMARGINS, 0, 0)); \
1413 edit_pos_ok(test_top, format_rect.top, vertical position); \
1414 edit_pos_ok((int)test_height, format_rect.bottom - format_rect.top, height); \
1415 edit_pos_ok(test_left, format_rect.left - left_margin, left); \
1418 static void test_text_position_style(DWORD style)
1421 HFONT font, oldFont;
1425 BOOL single_line = !(style & ES_MULTILINE);
1427 b = GetSystemMetrics(SM_CYBORDER) + 1;
1432 /* Get a stock font for which we can determine the metrics */
1433 assert(font = GetStockObject(SYSTEM_FONT));
1434 assert(dc = GetDC(NULL));
1435 oldFont = SelectObject(dc, font);
1436 assert(GetTextMetrics(dc, &metrics));
1437 SelectObject(dc, oldFont);
1438 ReleaseDC(NULL, dc);
1440 /* Windows' edit control has some bugs in multi-line mode:
1441 * - Sometimes the format rectangle doesn't get updated
1442 * (see workaround in set_client_height())
1443 * - If the height of the control is smaller than the height of a text
1444 * line, the format rectangle is still as high as a text line
1445 * (higher than the client rectangle) and the caret is not shown
1448 /* Edit controls that are in a parent window */
1450 hwEdit = create_child_editcontrol(style | WS_VISIBLE, 0);
1451 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1453 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1454 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1455 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1456 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1457 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1458 destroy_child_editcontrol(hwEdit);
1460 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, 0);
1461 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1463 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1464 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1465 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1466 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1467 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1468 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1469 destroy_child_editcontrol(hwEdit);
1471 hwEdit = create_child_editcontrol(style | WS_VISIBLE, WS_EX_CLIENTEDGE);
1472 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1474 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1475 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1476 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1477 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1478 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1479 destroy_child_editcontrol(hwEdit);
1481 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, WS_EX_CLIENTEDGE);
1482 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1484 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1485 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1486 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1487 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1488 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1489 destroy_child_editcontrol(hwEdit);
1492 /* Edit controls that are popup windows */
1494 hwEdit = create_editcontrol(style | WS_POPUP, 0);
1495 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1497 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1498 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1499 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1500 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1501 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1502 DestroyWindow(hwEdit);
1504 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, 0);
1505 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1507 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1508 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1509 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1510 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1511 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1512 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1513 DestroyWindow(hwEdit);
1515 hwEdit = create_editcontrol(style | WS_POPUP, WS_EX_CLIENTEDGE);
1516 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1518 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1519 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1520 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1521 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1522 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1523 DestroyWindow(hwEdit);
1525 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
1526 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, (LPARAM) FALSE);
1528 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1529 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1530 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1531 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1532 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1533 DestroyWindow(hwEdit);
1536 static void test_text_position(void)
1538 trace("EDIT: Text position (Single line)\n");
1539 test_text_position_style(ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1540 trace("EDIT: Text position (Multi line)\n");
1541 test_text_position_style(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1544 static void test_espassword(void)
1549 const char* password = "secret";
1551 hwEdit = create_editcontrol(ES_PASSWORD, 0);
1552 r = get_edit_style(hwEdit);
1553 ok(r == ES_PASSWORD, "Wrong style expected 0x%x got: 0x%x\n", ES_PASSWORD, r);
1555 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) password);
1556 ok(r == TRUE, "Expected: %d, got: %d\n", TRUE, r);
1558 /* select all, cut (ctrl-x) */
1559 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1560 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1561 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1564 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1565 ok(r == strlen(password), "Expected: %s, got len %d\n", password, r);
1566 ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
1568 r = OpenClipboard(hwEdit);
1569 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1570 r = EmptyClipboard();
1571 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1572 r = CloseClipboard();
1573 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1575 /* select all, copy (ctrl-c) and paste (ctrl-v) */
1576 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1577 r = SendMessage(hwEdit, WM_CHAR, 3, 0);
1578 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1579 r = SendMessage(hwEdit, WM_CHAR, 22, 0);
1580 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1584 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1585 ok(r == 0, "Expected: 0, got: %d\n", r);
1586 ok(strcmp(buffer, "") == 0, "expected empty string, got %s\n", buffer);
1588 DestroyWindow (hwEdit);
1591 static void test_undo(void)
1597 const char* text = "undo this";
1599 hwEdit = create_editcontrol(0, 0);
1600 r = get_edit_style(hwEdit);
1601 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1604 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) text);
1605 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1608 cpMin = cpMax = 0xdeadbeef;
1609 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1610 r = SendMessage(hwEdit, EM_GETSEL, (WPARAM) &cpMin, (LPARAM) &cpMax);
1611 ok((strlen(text) << 16) == r, "Unexpected length %d\n", r);
1612 ok(0 == cpMin, "Expected: %d, got %d\n", 0, cpMin);
1613 ok(9 == cpMax, "Expected: %d, got %d\n", 9, cpMax);
1616 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1617 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1621 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1622 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1623 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1626 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1627 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1631 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1632 ok(strlen(text) == r, "Unexpected length %d\n", r);
1633 ok(0 == strcmp(buffer, text), "expected %s, got %s\n", text, buffer);
1635 /* undo again (ctrl-z) */
1636 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1637 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1641 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1642 ok(r == 0, "Expected: %d, got len %d\n", 0, r);
1643 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1645 DestroyWindow (hwEdit);
1648 static void test_enter(void)
1655 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1656 r = get_edit_style(hwEdit);
1657 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1660 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1661 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1663 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1664 todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1668 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1670 ok(2 == r, "Expected: %d, got len %d\n", 2, r);
1671 ok(0 == strcmp(buffer, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer);
1674 DestroyWindow (hwEdit);
1677 hwEdit = create_editcontrol(0, 0);
1678 r = get_edit_style(hwEdit);
1679 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1682 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1683 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1685 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1686 todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1690 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1691 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1692 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1694 DestroyWindow (hwEdit);
1696 /* single line with ES_WANTRETURN */
1697 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
1698 r = get_edit_style(hwEdit);
1699 ok(ES_WANTRETURN == r, "Wrong style expected 0x%x got: 0x%x\n", ES_WANTRETURN, r);
1702 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1703 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1705 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1706 todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1710 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1711 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1712 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1714 DestroyWindow (hwEdit);
1717 static void test_tab(void)
1724 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1725 r = get_edit_style(hwEdit);
1726 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1729 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1730 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1732 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1733 todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1737 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1739 ok(1 == r, "Expected: %d, got len %d\n", 1, r);
1740 ok(0 == strcmp(buffer, "\t"), "expected \"\\t\", got \"%s\"\n", buffer);
1743 DestroyWindow (hwEdit);
1746 hwEdit = create_editcontrol(0, 0);
1747 r = get_edit_style(hwEdit);
1748 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1751 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1752 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1754 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1755 todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1759 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1760 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1761 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1763 DestroyWindow (hwEdit);
1766 static void test_edit_dialog(void)
1770 /* from bug 11841 */
1771 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1772 ok(333 == r, "Expected %d, got %d\n", 333, r);
1773 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1774 ok(111 == r, "Expected %d, got %d\n", 111, r);
1775 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1776 ok(444 == r, "Expected %d, got %d\n", 444, r);
1778 /* more tests for WM_CHAR */
1779 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1780 ok(444 == r, "Expected %d, got %d\n", 444, r);
1781 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1782 ok(444 == r, "Expected %d, got %d\n", 444, r);
1783 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1784 ok(444 == r, "Expected %d, got %d\n", 444, r);
1786 /* more tests for WM_KEYDOWN + WM_CHAR */
1787 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1788 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1789 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1790 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1791 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1792 ok(444 == r, "Expected %d, got %d\n", 444, r);
1794 /* tests with an editable edit control */
1795 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1796 ok(333 == r, "Expected %d, got %d\n", 333, r);
1797 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1798 ok(111 == r, "Expected %d, got %d\n", 111, r);
1799 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1800 ok(444 == r, "Expected %d, got %d\n", 444, r);
1802 /* tests for WM_CHAR */
1803 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1804 ok(444 == r, "Expected %d, got %d\n", 444, r);
1805 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1806 ok(444 == r, "Expected %d, got %d\n", 444, r);
1807 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1808 ok(444 == r, "Expected %d, got %d\n", 444, r);
1810 /* tests for WM_KEYDOWN + WM_CHAR */
1811 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1812 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1813 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1814 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1815 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1816 ok(444 == r, "Expected %d, got %d\n", 444, r);
1818 /* multiple tab tests */
1819 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 9);
1820 ok(22 == r, "Expected %d, got %d\n", 22, r);
1821 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 10);
1822 ok(33 == r, "Expected %d, got %d\n", 33, r);
1825 static void test_multi_edit_dialog(void)
1829 /* test for multiple edit dialogs (bug 12319) */
1830 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 0);
1831 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1832 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 1);
1833 ok(1111 == r, "Expected %d, got %d\n", 1111, r);
1834 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 2);
1835 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1836 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 3);
1837 ok(11 == r, "Expected %d, got %d\n", 11, r);
1840 static void test_wantreturn_edit_dialog(void)
1844 /* tests for WM_KEYDOWN */
1845 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 0);
1846 ok(333 == r, "Expected %d, got %d\n", 333, r);
1847 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 1);
1848 ok(444 == r, "Expected %d, got %d\n", 444, r);
1849 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 2);
1850 ok(444 == r, "Expected %d, got %d\n", 444, r);
1852 /* tests for WM_CHAR */
1853 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 3);
1854 ok(444 == r, "Expected %d, got %d\n", 444, r);
1855 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 4);
1856 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1857 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 5);
1858 ok(444 == r, "Expected %d, got %d\n", 444, r);
1860 /* tests for WM_KEYDOWN + WM_CHAR */
1861 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 6);
1862 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1863 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 7);
1864 todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
1865 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 8);
1866 ok(444 == r, "Expected %d, got %d\n", 444, r);
1869 static void test_singleline_wantreturn_edit_dialog(void)
1873 /* tests for WM_KEYDOWN */
1874 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
1875 todo_wine ok(222 == r, "Expected %d, got %d\n", 222, r);
1876 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
1877 ok(111 == r, "Expected %d, got %d\n", 111, r);
1878 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
1879 ok(444 == r, "Expected %d, got %d\n", 444, r);
1881 /* tests for WM_CHAR */
1882 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
1883 ok(444 == r, "Expected %d, got %d\n", 444, r);
1884 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
1885 ok(444 == r, "Expected %d, got %d\n", 444, r);
1886 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
1887 ok(444 == r, "Expected %d, got %d\n", 444, r);
1889 /* tests for WM_KEYDOWN + WM_CHAR */
1890 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
1891 todo_wine ok(222 == r, "Expected %d, got %d\n", 222, r);
1892 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
1893 ok(111 == r, "Expected %d, got %d\n", 111, r);
1894 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
1895 ok(444 == r, "Expected %d, got %d\n", 444, r);
1897 /* tests for WM_KEYDOWN */
1898 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
1899 todo_wine ok(222 == r, "Expected %d, got %d\n", 222, r);
1900 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
1901 todo_wine ok(111 == r, "Expected %d, got %d\n", 111, r);
1902 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
1903 ok(444 == r, "Expected %d, got %d\n", 444, r);
1905 /* tests for WM_CHAR */
1906 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
1907 ok(444 == r, "Expected %d, got %d\n", 444, r);
1908 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
1909 ok(444 == r, "Expected %d, got %d\n", 444, r);
1910 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
1911 ok(444 == r, "Expected %d, got %d\n", 444, r);
1913 /* tests for WM_KEYDOWN + WM_CHAR */
1914 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
1915 todo_wine ok(222 == r, "Expected %d, got %d\n", 222, r);
1916 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
1917 todo_wine ok(111 == r, "Expected %d, got %d\n", 111, r);
1918 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
1919 ok(444 == r, "Expected %d, got %d\n", 444, r);
1922 static BOOL RegisterWindowClasses (void)
1926 WNDCLASSA text_position;
1929 test2.lpfnWndProc = ET2_WndProc;
1930 test2.cbClsExtra = 0;
1931 test2.cbWndExtra = 0;
1932 test2.hInstance = hinst;
1934 test2.hCursor = LoadCursorA (NULL, IDC_ARROW);
1935 test2.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1936 test2.lpszMenuName = NULL;
1937 test2.lpszClassName = szEditTest2Class;
1938 if (!RegisterClassA(&test2)) return FALSE;
1941 test3.lpfnWndProc = edit3_wnd_procA;
1942 test3.cbClsExtra = 0;
1943 test3.cbWndExtra = 0;
1944 test3.hInstance = hinst;
1946 test3.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1947 test3.hbrBackground = GetStockObject(WHITE_BRUSH);
1948 test3.lpszMenuName = NULL;
1949 test3.lpszClassName = szEditTest3Class;
1950 if (!RegisterClassA(&test3)) return FALSE;
1952 text_position.style = CS_HREDRAW | CS_VREDRAW;
1953 text_position.cbClsExtra = 0;
1954 text_position.cbWndExtra = 0;
1955 text_position.hInstance = hinst;
1956 text_position.hIcon = NULL;
1957 text_position.hCursor = LoadCursorA(NULL, IDC_ARROW);
1958 text_position.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1959 text_position.lpszMenuName = NULL;
1960 text_position.lpszClassName = szEditTextPositionClass;
1961 text_position.lpfnWndProc = DefWindowProc;
1962 if (!RegisterClassA(&text_position)) return FALSE;
1967 static void UnregisterWindowClasses (void)
1969 UnregisterClassA(szEditTest2Class, hinst);
1970 UnregisterClassA(szEditTest3Class, hinst);
1971 UnregisterClassA(szEditTextPositionClass, hinst);
1976 hinst = GetModuleHandleA(NULL);
1977 assert(RegisterWindowClasses());
1979 test_edit_control_1();
1980 test_edit_control_2();
1981 test_edit_control_3();
1982 test_edit_control_4();
1983 test_edit_control_5();
1984 test_edit_control_limittext();
1986 test_margins_font_change();
1987 test_text_position();
1993 test_multi_edit_dialog();
1994 test_wantreturn_edit_dialog();
1995 test_singleline_wantreturn_edit_dialog();
1997 UnregisterWindowClasses();