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 INT_PTR CALLBACK
multi_edit_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
43 static int num_ok_commands
= 0;
48 HWND hedit
= GetDlgItem(hdlg
, 1000);
52 /* test cases related to bug 12319 */
54 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
55 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
58 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
59 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
62 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
63 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
64 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
67 /* test cases for pressing enter */
70 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
71 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
81 if (HIWORD(wparam
) != BN_CLICKED
)
84 switch (LOWORD(wparam
))
97 HWND hfocus
= GetFocus();
98 HWND hedit
= GetDlgItem(hdlg
, 1000);
99 HWND hedit2
= GetDlgItem(hdlg
, 1001);
100 HWND hedit3
= GetDlgItem(hdlg
, 1002);
102 if (wparam
!= 0xdeadbeef)
109 EndDialog(hdlg
, 1111);
110 else if (hfocus
== hedit2
)
111 EndDialog(hdlg
, 2222);
112 else if (hfocus
== hedit3
)
113 EndDialog(hdlg
, 3333);
115 EndDialog(hdlg
, 4444);
118 if ((hfocus
== hedit
) && (num_ok_commands
== 0))
124 EndDialog(hdlg
, 5555);
130 EndDialog(hdlg
, 333);
140 static INT_PTR CALLBACK
edit_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
146 HWND hedit
= GetDlgItem(hdlg
, 1000);
152 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
155 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
158 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
159 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
162 /* more test cases for WM_CHAR */
164 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
165 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
168 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
169 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
172 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
173 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
176 /* more test cases for WM_KEYDOWN + WM_CHAR */
178 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
179 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
180 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
183 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
184 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
185 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
188 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
189 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
190 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
193 /* multiple tab tests */
195 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
196 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
197 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 2);
200 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
201 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
202 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
203 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 2);
213 if (HIWORD(wparam
) != BN_CLICKED
)
216 switch (LOWORD(wparam
))
219 EndDialog(hdlg
, 111);
223 EndDialog(hdlg
, 222);
234 HWND hok
= GetDlgItem(hdlg
, IDOK
);
235 HWND hcancel
= GetDlgItem(hdlg
, IDCANCEL
);
236 HWND hedit
= GetDlgItem(hdlg
, 1000);
237 HWND hfocus
= GetFocus();
239 if (wparam
!= 0xdeadbeef)
245 len
= SendMessage(hedit
, WM_GETTEXTLENGTH
, 0, 0);
247 EndDialog(hdlg
, 444);
249 EndDialog(hdlg
, 555);
253 len
= SendMessage(hedit
, WM_GETTEXTLENGTH
, 0, 0);
254 if ((hfocus
== hok
) && len
== 0)
255 EndDialog(hdlg
, 444);
257 EndDialog(hdlg
, 555);
263 else if (hfocus
== hcancel
)
265 else if (hfocus
== hedit
)
272 EndDialog(hdlg
, 555);
278 EndDialog(hdlg
, 333);
288 static INT_PTR CALLBACK
edit_singleline_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
294 HWND hedit
= GetDlgItem(hdlg
, 1000);
298 /* test cases for WM_KEYDOWN */
300 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
303 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
306 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
307 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
310 /* test cases for WM_CHAR */
312 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
313 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
316 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
317 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
320 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
321 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
324 /* test cases for WM_KEYDOWN + WM_CHAR */
326 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
327 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
330 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
331 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
334 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
335 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
336 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
346 if (HIWORD(wparam
) != BN_CLICKED
)
349 switch (LOWORD(wparam
))
352 EndDialog(hdlg
, 111);
356 EndDialog(hdlg
, 222);
366 HWND hok
= GetDlgItem(hdlg
, IDOK
);
367 HWND hedit
= GetDlgItem(hdlg
, 1000);
368 HWND hfocus
= GetFocus();
369 int len
= SendMessage(hedit
, WM_GETTEXTLENGTH
, 0, 0);
371 if (wparam
!= 0xdeadbeef)
377 if ((hfocus
== hedit
) && len
== 0)
378 EndDialog(hdlg
, 444);
380 EndDialog(hdlg
, 555);
384 if ((hfocus
== hok
) && len
== 0)
385 EndDialog(hdlg
, 444);
387 EndDialog(hdlg
, 555);
397 EndDialog(hdlg
, 333);
407 static INT_PTR CALLBACK
edit_wantreturn_dialog_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
413 HWND hedit
= GetDlgItem(hdlg
, 1000);
417 /* test cases for WM_KEYDOWN */
419 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
422 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
423 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
426 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
427 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
430 /* test cases for WM_CHAR */
432 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
433 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
436 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
437 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 2);
440 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
441 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
444 /* test cases for WM_KEYDOWN + WM_CHAR */
446 PostMessage(hedit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
447 PostMessage(hedit
, WM_CHAR
, VK_ESCAPE
, 0x10001);
448 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 0);
451 PostMessage(hedit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
452 PostMessage(hedit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
453 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 2);
456 PostMessage(hedit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
457 PostMessage(hedit
, WM_CHAR
, VK_TAB
, 0xf0001);
458 PostMessage(hdlg
, WM_USER
, 0xdeadbeef, 1);
468 if (HIWORD(wparam
) != BN_CLICKED
)
471 switch (LOWORD(wparam
))
474 EndDialog(hdlg
, 111);
478 EndDialog(hdlg
, 222);
488 HWND hok
= GetDlgItem(hdlg
, IDOK
);
489 HWND hedit
= GetDlgItem(hdlg
, 1000);
490 HWND hfocus
= GetFocus();
491 int len
= SendMessage(hedit
, WM_GETTEXTLENGTH
, 0, 0);
493 if (wparam
!= 0xdeadbeef)
499 if ((hfocus
== hedit
) && len
== 0)
500 EndDialog(hdlg
, 444);
502 EndDialog(hdlg
, 555);
506 if ((hfocus
== hok
) && len
== 0)
507 EndDialog(hdlg
, 444);
509 EndDialog(hdlg
, 555);
513 if ((hfocus
== hedit
) && len
== 2)
514 EndDialog(hdlg
, 444);
516 EndDialog(hdlg
, 555);
526 EndDialog(hdlg
, 333);
536 static HINSTANCE hinst
;
538 static const char szEditTest2Class
[] = "EditTest2Class";
539 static const char szEditTest3Class
[] = "EditTest3Class";
540 static const char szEditTextPositionClass
[] = "EditTextPositionWindowClass";
542 static HWND
create_editcontrol (DWORD style
, DWORD exstyle
)
546 handle
= CreateWindowEx(exstyle
,
551 NULL
, NULL
, hinst
, NULL
);
553 if (winetest_interactive
)
554 ShowWindow (handle
, SW_SHOW
);
558 static HWND
create_child_editcontrol (DWORD style
, DWORD exstyle
)
568 assert(AdjustWindowRect(&rect
, WS_OVERLAPPEDWINDOW
, FALSE
));
570 parentWnd
= CreateWindowEx(0,
571 szEditTextPositionClass
,
574 CW_USEDEFAULT
, CW_USEDEFAULT
,
575 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
576 NULL
, NULL
, hinst
, NULL
);
579 editWnd
= CreateWindowEx(exstyle
,
584 parentWnd
, NULL
, hinst
, NULL
);
586 if (winetest_interactive
)
587 ShowWindow (parentWnd
, SW_SHOW
);
591 static void destroy_child_editcontrol (HWND hwndEdit
)
593 if (GetParent(hwndEdit
))
594 DestroyWindow(GetParent(hwndEdit
));
596 trace("Edit control has no parent!\n");
597 DestroyWindow(hwndEdit
);
601 static LONG
get_edit_style (HWND hwnd
)
603 return GetWindowLongA( hwnd
, GWL_STYLE
) & (
605 /* FIXME: not implemented
624 static void set_client_height(HWND Wnd
, unsigned Height
)
626 RECT ClientRect
, WindowRect
;
628 GetWindowRect(Wnd
, &WindowRect
);
629 GetClientRect(Wnd
, &ClientRect
);
630 SetWindowPos(Wnd
, NULL
, 0, 0,
631 WindowRect
.right
- WindowRect
.left
,
632 Height
+ (WindowRect
.bottom
- WindowRect
.top
) -
633 (ClientRect
.bottom
- ClientRect
.top
),
634 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
636 /* Workaround for a bug in Windows' edit control
638 GetWindowRect(Wnd
, &WindowRect
);
639 SetWindowPos(Wnd
, NULL
, 0, 0,
640 WindowRect
.right
- WindowRect
.left
+ 1,
641 WindowRect
.bottom
- WindowRect
.top
+ 1,
642 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
643 SetWindowPos(Wnd
, NULL
, 0, 0,
644 WindowRect
.right
- WindowRect
.left
,
645 WindowRect
.bottom
- WindowRect
.top
,
646 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
648 GetClientRect(Wnd
, &ClientRect
);
649 ok(ClientRect
.bottom
- ClientRect
.top
== Height
,
650 "The client height should be %d, but is %d\n",
651 Height
, ClientRect
.bottom
- ClientRect
.top
);
654 static void test_edit_control_1(void)
661 msMessage
.message
= WM_KEYDOWN
;
663 trace("EDIT: Single line\n");
664 hwEdit
= create_editcontrol(ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
665 r
= get_edit_style(hwEdit
);
666 ok(r
== (ES_AUTOVSCROLL
| ES_AUTOHSCROLL
), "Wrong style expected 0xc0 got: 0x%x\n", r
);
667 for (i
=0;i
<65535;i
++)
669 msMessage
.wParam
= i
;
670 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, (LPARAM
) &msMessage
);
671 ok(r
== (DLGC_WANTCHARS
| DLGC_HASSETSEL
| DLGC_WANTARROWS
),
672 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r
);
674 DestroyWindow (hwEdit
);
676 trace("EDIT: Single line want returns\n");
677 hwEdit
= create_editcontrol(ES_WANTRETURN
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
678 r
= get_edit_style(hwEdit
);
679 ok(r
== (ES_AUTOVSCROLL
| ES_AUTOHSCROLL
| ES_WANTRETURN
), "Wrong style expected 0x10c0 got: 0x%x\n", r
);
680 for (i
=0;i
<65535;i
++)
682 msMessage
.wParam
= i
;
683 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, (LPARAM
) &msMessage
);
684 ok(r
== (DLGC_WANTCHARS
| DLGC_HASSETSEL
| DLGC_WANTARROWS
),
685 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r
);
687 DestroyWindow (hwEdit
);
689 trace("EDIT: Multiline line\n");
690 hwEdit
= create_editcontrol(ES_MULTILINE
| WS_VSCROLL
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
691 r
= get_edit_style(hwEdit
);
692 ok(r
== (ES_AUTOHSCROLL
| ES_AUTOVSCROLL
| ES_MULTILINE
), "Wrong style expected 0xc4 got: 0x%x\n", r
);
693 for (i
=0;i
<65535;i
++)
695 msMessage
.wParam
= i
;
696 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, (LPARAM
) &msMessage
);
697 ok(r
== (DLGC_WANTCHARS
| DLGC_HASSETSEL
| DLGC_WANTALLKEYS
| DLGC_WANTARROWS
),
698 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r
);
700 DestroyWindow (hwEdit
);
702 trace("EDIT: Multi line want returns\n");
703 hwEdit
= create_editcontrol(ES_MULTILINE
| WS_VSCROLL
| ES_WANTRETURN
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
704 r
= get_edit_style(hwEdit
);
705 ok(r
== (ES_WANTRETURN
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
| ES_MULTILINE
), "Wrong style expected 0x10c4 got: 0x%x\n", r
);
706 for (i
=0;i
<65535;i
++)
708 msMessage
.wParam
= i
;
709 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, (LPARAM
) &msMessage
);
710 ok(r
== (DLGC_WANTCHARS
| DLGC_HASSETSEL
| DLGC_WANTALLKEYS
| DLGC_WANTARROWS
),
711 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r
);
713 DestroyWindow (hwEdit
);
716 /* WM_SETTEXT is implemented by selecting all text, and then replacing the
717 * selection. This test checks that the first 'select all' doesn't generate
718 * an UPDATE message which can escape and (via a handler) change the
719 * selection, which would cause WM_SETTEXT to break. This old bug
720 * was fixed 18-Mar-2005; we check here to ensure it doesn't regress.
722 static void test_edit_control_2(void)
725 char szLocalString
[MAXLEN
];
728 /* Create main and edit windows. */
729 hwndMain
= CreateWindow(szEditTest2Class
, "ET2", WS_OVERLAPPEDWINDOW
,
730 0, 0, 200, 200, NULL
, NULL
, hinst
, NULL
);
732 if (winetest_interactive
)
733 ShowWindow (hwndMain
, SW_SHOW
);
735 hwndET2
= CreateWindow("EDIT", NULL
,
736 WS_CHILD
|WS_BORDER
|ES_LEFT
|ES_AUTOHSCROLL
,
737 0, 0, 150, 50, /* important this not be 0 size. */
738 hwndMain
, (HMENU
) ID_EDITTEST2
, hinst
, NULL
);
740 if (winetest_interactive
)
741 ShowWindow (hwndET2
, SW_SHOW
);
743 trace("EDIT: SETTEXT atomicity\n");
744 /* Send messages to "type" in the word 'foo'. */
745 r
= SendMessage(hwndET2
, WM_CHAR
, 'f', 1);
746 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
747 r
= SendMessage(hwndET2
, WM_CHAR
, 'o', 1);
748 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
749 r
= SendMessage(hwndET2
, WM_CHAR
, 'o', 1);
750 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
751 /* 'foo' should have been changed to 'bar' by the UPDATE handler. */
752 GetWindowText(hwndET2
, szLocalString
, MAXLEN
);
753 ok(lstrcmp(szLocalString
, "bar")==0,
754 "Wrong contents of edit: %s\n", szLocalString
);
757 DestroyWindow (hwndET2
);
758 DestroyWindow (hwndMain
);
761 static void ET2_check_change(void) {
762 char szLocalString
[MAXLEN
];
763 /* This EN_UPDATE handler changes any 'foo' to 'bar'. */
764 GetWindowText(hwndET2
, szLocalString
, MAXLEN
);
765 if (lstrcmp(szLocalString
, "foo")==0) {
766 lstrcpy(szLocalString
, "bar");
767 SendMessage(hwndET2
, WM_SETTEXT
, 0, (LPARAM
) szLocalString
);
769 /* always leave the cursor at the end. */
770 SendMessage(hwndET2
, EM_SETSEL
, MAXLEN
- 1, MAXLEN
- 1);
772 static void ET2_OnCommand(HWND hwnd
, int id
, HWND hwndCtl
, UINT codeNotify
)
774 if (id
==ID_EDITTEST2
&& codeNotify
== EN_UPDATE
)
777 static LRESULT CALLBACK
ET2_WndProc(HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
781 ET2_OnCommand(hwnd
, LOWORD(wParam
), (HWND
)lParam
, HIWORD(wParam
));
784 return DefWindowProc(hwnd
, iMsg
, wParam
, lParam
);
787 static void zero_notify(void)
789 notifications
.en_change
= 0;
790 notifications
.en_maxtext
= 0;
791 notifications
.en_update
= 0;
794 #define test_notify(enchange, enmaxtext, enupdate) \
795 ok(notifications.en_change == enchange, "expected %d EN_CHANGE notifications, " \
796 "got %d\n", enchange, notifications.en_change); \
797 ok(notifications.en_maxtext == enmaxtext, "expected %d EN_MAXTEXT notifications, " \
798 "got %d\n", enmaxtext, notifications.en_maxtext); \
799 ok(notifications.en_update == enupdate, "expected %d EN_UPDATE notifications, " \
800 "got %d\n", enupdate, notifications.en_update)
803 static LRESULT CALLBACK
edit3_wnd_procA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
807 switch (HIWORD(wParam
)) {
809 notifications
.en_maxtext
++;
812 notifications
.en_update
++;
815 notifications
.en_change
++;
820 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
823 /* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
826 static void test_edit_control_3(void)
831 static const char *str
= "this is a long string.";
832 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.";
834 trace("EDIT: Test notifications\n");
836 hParent
= CreateWindowExA(0,
840 CW_USEDEFAULT
, CW_USEDEFAULT
, 10, 10,
841 NULL
, NULL
, NULL
, NULL
);
844 trace("EDIT: Single line, no ES_AUTOHSCROLL\n");
845 hWnd
= CreateWindowExA(0,
850 hParent
, NULL
, NULL
, NULL
);
854 SendMessageA(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)str
);
855 len
= SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
856 ok(lstrlenA(str
) > len
, "text should have been truncated\n");
857 test_notify(1, 1, 1);
859 SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)"");
861 SendMessageA(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)"a");
862 len
= SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
863 ok(1 == len
, "wrong text length, expected 1, got %d\n", len
);
864 test_notify(1, 0, 1);
867 SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)str
);
868 len
= SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
869 ok(lstrlenA(str
) == len
, "text shouldn't have been truncated\n");
870 test_notify(1, 0, 1);
872 len
= SendMessageA(hWnd
, EM_GETSEL
, 0, 0);
873 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
874 ok(HIWORD(len
)==0, "Unexpected end position for selection %d\n", HIWORD(len
));
875 SendMessage(hParent
, WM_SETFOCUS
, 0, (LPARAM
)hWnd
);
876 len
= SendMessageA(hWnd
, EM_GETSEL
, 0, 0);
877 ok(LOWORD(len
)==0, "Unexpected start position for selection %d\n", LOWORD(len
));
878 ok(HIWORD(len
)==0, "Unexpected end position for selection %d\n", HIWORD(len
));
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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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 RECT rc1
= { 10, 10, 11, 11};
1195 /* first show that a non-child won't do for this test */
1196 hWnd
= CreateWindowEx(0,
1201 NULL
, NULL
, NULL
, NULL
);
1203 /* size of non-child edit control is (much) bigger than requested */
1204 GetWindowRect( hWnd
, &rc
);
1205 ok( rc
.right
- rc
.left
> 20, "size of the window (%d) is smaller than expected\n",
1206 rc
.right
- rc
.left
);
1207 DestroyWindow(hWnd
);
1208 /* so create a parent, and give it edit controls children to test with */
1209 parentWnd
= CreateWindowEx(0,
1210 szEditTextPositionClass
,
1211 "Edit Test", WS_VISIBLE
|
1212 WS_OVERLAPPEDWINDOW
,
1213 CW_USEDEFAULT
, CW_USEDEFAULT
,
1215 NULL
, NULL
, hinst
, NULL
);
1217 ShowWindow( parentWnd
, SW_SHOW
);
1219 hWnd
= CreateWindowEx(0,
1221 str
, WS_VISIBLE
| WS_BORDER
|
1223 rc1
.left
, rc1
.top
, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
,
1224 parentWnd
, NULL
, NULL
, NULL
);
1226 GetClientRect( hWnd
, &rc
);
1227 ok( rc
.right
== rc1
.right
- rc1
.left
&& rc
.bottom
== rc1
.bottom
- rc1
.top
,
1228 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1229 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1230 len
= SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1231 ok(lstrlenA(str
) == len
, "text shouldn't have been truncated\n");
1232 DestroyWindow(hWnd
);
1234 hWnd
= CreateWindowEx(0,
1237 WS_CHILD
| ES_MULTILINE
,
1238 rc1
.left
, rc1
.top
, rc1
.right
- rc1
.left
, rc1
.bottom
- rc1
.top
,
1239 parentWnd
, NULL
, NULL
, NULL
);
1241 GetClientRect( hWnd
, &rc
);
1242 ok( rc
.right
== rc1
.right
- rc1
.left
&& rc
.bottom
== rc1
.bottom
- rc1
.top
,
1243 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1244 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1245 len
= SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1246 ok(lstrlenA(str
) == len
, "text shouldn't have been truncated\n");
1247 DestroyWindow(hWnd
);
1250 /* Test WM_GETTEXT processing
1251 * after destroy messages
1253 static void test_edit_control_6(void)
1255 static const char *str
= "test\r\ntest";
1260 hWnd
= CreateWindowEx(0,
1265 NULL
, NULL
, hinst
, NULL
);
1268 ret
= SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)str
);
1269 ok(ret
== TRUE
, "Expected %d, got %d\n", TRUE
, ret
);
1270 ret
= SendMessageA(hWnd
, WM_GETTEXT
, MAXLEN
, (LPARAM
)buf
);
1271 ok(ret
== lstrlen(str
), "Expected %s, got len %d\n", str
, ret
);
1272 ok(!lstrcmp(buf
, str
), "Expected %s, got %s\n", str
, buf
);
1274 ret
= SendMessageA(hWnd
, WM_DESTROY
, 0, 0);
1275 ok(ret
== 0, "Expected 0, got %d\n", ret
);
1276 ret
= SendMessageA(hWnd
, WM_GETTEXT
, MAXLEN
, (LPARAM
)buf
);
1277 ok(ret
== lstrlen(str
), "Expected %s, got len %d\n", str
, ret
);
1278 ok(!lstrcmp(buf
, str
), "Expected %s, got %s\n", str
, buf
);
1280 ret
= SendMessageA(hWnd
, WM_NCDESTROY
, 0, 0);
1281 ok(ret
== 0, "Expected 0, got %d\n", ret
);
1282 ret
= SendMessageA(hWnd
, WM_GETTEXT
, MAXLEN
, (LPARAM
)buf
);
1283 ok(ret
== 0, "Expected 0, got len %d\n", ret
);
1284 ok(!lstrcmp(buf
, ""), "Expected empty string, got %s\n", buf
);
1286 DestroyWindow(hWnd
);
1289 static void test_edit_control_limittext(void)
1294 /* Test default limit for single-line control */
1295 trace("EDIT: buffer limit for single-line\n");
1296 hwEdit
= create_editcontrol(ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
1297 r
= SendMessage(hwEdit
, EM_GETLIMITTEXT
, 0, 0);
1298 ok(r
== 30000, "Incorrect default text limit, expected 30000 got %u\n", r
);
1299 SendMessage(hwEdit
, EM_SETLIMITTEXT
, 0, 0);
1300 r
= SendMessage(hwEdit
, EM_GETLIMITTEXT
, 0, 0);
1301 /* Win9x+ME: 32766; WinNT: 2147483646UL */
1302 ok( (r
== 32766) || (r
== 2147483646UL),
1303 "got limit %u (expected 32766 or 2147483646)\n", r
);
1304 DestroyWindow(hwEdit
);
1306 /* Test default limit for multi-line control */
1307 trace("EDIT: buffer limit for multi-line\n");
1308 hwEdit
= create_editcontrol(ES_MULTILINE
| WS_VSCROLL
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
1309 r
= SendMessage(hwEdit
, EM_GETLIMITTEXT
, 0, 0);
1310 ok(r
== 30000, "Incorrect default text limit, expected 30000 got %u\n", r
);
1311 SendMessage(hwEdit
, EM_SETLIMITTEXT
, 0, 0);
1312 r
= SendMessage(hwEdit
, EM_GETLIMITTEXT
, 0, 0);
1313 /* Win9x+ME: 65535; WinNT: 4294967295UL */
1314 ok( (r
== 65535) || (r
== 4294967295UL),
1315 "got limit %u (expected 65535 or 4294967295)\n", r
);
1316 DestroyWindow(hwEdit
);
1319 /* Test EM_SCROLL */
1320 static void test_edit_control_scroll(void)
1322 static const char *single_line_str
= "a";
1323 static const char *multiline_str
= "Test\r\nText";
1327 /* Check the return value when EM_SCROLL doesn't scroll
1328 * anything. Should not return true unless any lines were actually
1330 hwEdit
= CreateWindow(
1333 WS_VSCROLL
| ES_MULTILINE
,
1335 NULL
, NULL
, hinst
, NULL
);
1339 ret
= SendMessage(hwEdit
, EM_SCROLL
, SB_PAGEDOWN
, 0);
1340 ok(!ret
, "Returned %x, expected 0.\n", ret
);
1342 ret
= SendMessage(hwEdit
, EM_SCROLL
, SB_PAGEUP
, 0);
1343 ok(!ret
, "Returned %x, expected 0.\n", ret
);
1345 ret
= SendMessage(hwEdit
, EM_SCROLL
, SB_LINEUP
, 0);
1346 ok(!ret
, "Returned %x, expected 0.\n", ret
);
1348 ret
= SendMessage(hwEdit
, EM_SCROLL
, SB_LINEDOWN
, 0);
1349 ok(!ret
, "Returned %x, expected 0.\n", ret
);
1351 DestroyWindow (hwEdit
);
1353 /* SB_PAGEDOWN while at the beginning of a buffer with few lines
1354 should not cause EM_SCROLL to return a negative value of
1355 scrolled lines that would put us "before" the beginning. */
1356 hwEdit
= CreateWindow(
1359 WS_VSCROLL
| ES_MULTILINE
,
1361 NULL
, NULL
, hinst
, NULL
);
1364 ret
= SendMessage(hwEdit
, EM_SCROLL
, SB_PAGEDOWN
, 0);
1365 ok(!ret
, "Returned %x, expected 0.\n", ret
);
1367 DestroyWindow (hwEdit
);
1370 static void test_margins(void)
1373 RECT old_rect
, new_rect
;
1374 INT old_left_margin
, old_right_margin
;
1375 DWORD old_margins
, new_margins
;
1377 hwEdit
= create_editcontrol(WS_BORDER
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, 0);
1379 old_margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1380 old_left_margin
= LOWORD(old_margins
);
1381 old_right_margin
= HIWORD(old_margins
);
1383 /* Check if setting the margins works */
1385 SendMessage(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
, MAKELONG(10, 0));
1386 new_margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1387 ok(LOWORD(new_margins
) == 10, "Wrong left margin: %d\n", LOWORD(new_margins
));
1388 ok(HIWORD(new_margins
) == old_right_margin
, "Wrong right margin: %d\n", HIWORD(new_margins
));
1390 SendMessage(hwEdit
, EM_SETMARGINS
, EC_RIGHTMARGIN
, MAKELONG(0, 10));
1391 new_margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1392 ok(LOWORD(new_margins
) == 10, "Wrong left margin: %d\n", LOWORD(new_margins
));
1393 ok(HIWORD(new_margins
) == 10, "Wrong right margin: %d\n", HIWORD(new_margins
));
1396 /* The size of the rectangle must decrease if we increase the margin */
1398 SendMessage(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(5, 5));
1399 SendMessage(hwEdit
, EM_GETRECT
, 0, (LPARAM
)&old_rect
);
1400 SendMessage(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(15, 20));
1401 SendMessage(hwEdit
, EM_GETRECT
, 0, (LPARAM
)&new_rect
);
1402 ok(new_rect
.left
== old_rect
.left
+ 10, "The left border of the rectangle is wrong\n");
1403 ok(new_rect
.right
== old_rect
.right
- 15, "The right border of the rectangle is wrong\n");
1404 ok(new_rect
.top
== old_rect
.top
, "The top border of the rectangle must not change\n");
1405 ok(new_rect
.bottom
== old_rect
.bottom
, "The bottom border of the rectangle must not change\n");
1408 /* If we set the margin to same value as the current margin,
1409 the rectangle must not change */
1411 SendMessage(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(10, 10));
1413 old_rect
.right
= 99;
1415 old_rect
.bottom
= 99;
1416 SendMessage(hwEdit
, EM_SETRECT
, 0, (LPARAM
)&old_rect
);
1417 SendMessage(hwEdit
, EM_GETRECT
, 0, (LPARAM
)&old_rect
);
1418 SendMessage(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(10, 10));
1419 SendMessage(hwEdit
, EM_GETRECT
, 0, (LPARAM
)&new_rect
);
1420 ok(new_rect
.left
== old_rect
.left
, "The left border of the rectangle has changed\n");
1421 ok(new_rect
.right
== old_rect
.right
, "The right border of the rectangle has changed\n");
1422 ok(new_rect
.top
== old_rect
.top
, "The top border of the rectangle has changed\n");
1423 ok(new_rect
.bottom
== old_rect
.bottom
, "The bottom border of the rectangle has changed\n");
1425 DestroyWindow (hwEdit
);
1428 static INT CALLBACK
find_font_proc(const LOGFONT
*elf
, const TEXTMETRIC
*ntm
, DWORD type
, LPARAM lParam
)
1433 static void test_margins_font_change(void)
1436 DWORD margins
, font_margins
;
1438 HFONT hfont
, hfont2
;
1441 if(EnumFontFamiliesA(hdc
, "Arial", find_font_proc
, 0))
1443 trace("Arial not found - skipping font change margin tests\n");
1449 hwEdit
= create_child_editcontrol(0, 0);
1451 SetWindowPos(hwEdit
, NULL
, 10, 10, 1000, 100, SWP_NOZORDER
| SWP_NOACTIVATE
);
1453 memset(&lf
, 0, sizeof(lf
));
1454 strcpy(lf
.lfFaceName
, "Arial");
1456 lf
.lfCharSet
= DEFAULT_CHARSET
;
1457 hfont
= CreateFontIndirectA(&lf
);
1459 hfont2
= CreateFontIndirectA(&lf
);
1461 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1462 font_margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1463 ok(LOWORD(font_margins
) != 0, "got %d\n", LOWORD(font_margins
));
1464 ok(HIWORD(font_margins
) != 0, "got %d\n", HIWORD(font_margins
));
1466 /* With 'small' edit controls, test that the margin doesn't get set */
1467 SetWindowPos(hwEdit
, NULL
, 10, 10, 16, 100, SWP_NOZORDER
| SWP_NOACTIVATE
);
1468 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0,0));
1469 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1470 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1471 ok(LOWORD(margins
) == 0 || broken(LOWORD(margins
) == LOWORD(font_margins
)), /* win95 */
1472 "got %d\n", LOWORD(margins
));
1473 ok(HIWORD(margins
) == 0 || broken(HIWORD(margins
) == HIWORD(font_margins
)), /* win95 */
1474 "got %d\n", HIWORD(margins
));
1476 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(1,0));
1477 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1478 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1479 ok(LOWORD(margins
) == 1 || broken(LOWORD(margins
) == LOWORD(font_margins
)), /* win95 */
1480 "got %d\n", LOWORD(margins
));
1481 ok(HIWORD(margins
) == 0 || broken(HIWORD(margins
) == HIWORD(font_margins
)), /* win95 */
1482 "got %d\n", HIWORD(margins
));
1484 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(1,1));
1485 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1486 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1487 ok(LOWORD(margins
) == 1 || broken(LOWORD(margins
) == LOWORD(font_margins
)), /* win95 */
1488 "got %d\n", LOWORD(margins
));
1489 ok(HIWORD(margins
) == 1 || broken(HIWORD(margins
) == HIWORD(font_margins
)), /* win95 */
1490 "got %d\n", HIWORD(margins
));
1492 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(EC_USEFONTINFO
,EC_USEFONTINFO
));
1493 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1494 ok(LOWORD(margins
) == 1 || broken(LOWORD(margins
) == LOWORD(font_margins
)), /* win95 */
1495 "got %d\n", LOWORD(margins
));
1496 ok(HIWORD(margins
) == 1 || broken(HIWORD(margins
) == HIWORD(font_margins
)), /* win95 */
1497 "got %d\n", HIWORD(margins
));
1499 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont2
, 0);
1500 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1501 ok(LOWORD(margins
) == 1 || broken(LOWORD(margins
) != 1 && LOWORD(margins
) != LOWORD(font_margins
)), /* win95 */
1502 "got %d\n", LOWORD(margins
));
1503 ok(HIWORD(margins
) == 1 || broken(HIWORD(margins
) != 1 && HIWORD(margins
) != HIWORD(font_margins
)), /* win95 */
1504 "got %d\n", HIWORD(margins
));
1506 /* Above a certain size threshold then the margin is updated */
1507 SetWindowPos(hwEdit
, NULL
, 10, 10, 1000, 100, SWP_NOZORDER
| SWP_NOACTIVATE
);
1508 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(1,0));
1509 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1510 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1511 ok(LOWORD(margins
) == LOWORD(font_margins
), "got %d\n", LOWORD(margins
));
1512 ok(HIWORD(margins
) == HIWORD(font_margins
), "got %d\n", HIWORD(margins
));
1514 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(1,1));
1515 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont
, 0);
1516 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1517 ok(LOWORD(margins
) == LOWORD(font_margins
), "got %d\n", LOWORD(margins
));
1518 ok(HIWORD(margins
) == HIWORD(font_margins
), "got %d\n", HIWORD(margins
));
1520 SendMessageA(hwEdit
, EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(EC_USEFONTINFO
,EC_USEFONTINFO
));
1521 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1522 ok(LOWORD(margins
) == LOWORD(font_margins
), "got %d\n", LOWORD(margins
));
1523 ok(HIWORD(margins
) == HIWORD(font_margins
), "got %d\n", HIWORD(margins
));
1524 SendMessageA(hwEdit
, WM_SETFONT
, (WPARAM
)hfont2
, 0);
1525 margins
= SendMessage(hwEdit
, EM_GETMARGINS
, 0, 0);
1526 ok(LOWORD(margins
) != LOWORD(font_margins
) || broken(LOWORD(margins
) == LOWORD(font_margins
)), /* win98 */
1527 "got %d\n", LOWORD(margins
));
1528 ok(HIWORD(margins
) != HIWORD(font_margins
), "got %d\n", HIWORD(margins
));
1530 SendMessageA(hwEdit
, WM_SETFONT
, 0, 0);
1532 DeleteObject(hfont2
);
1533 DeleteObject(hfont
);
1534 destroy_child_editcontrol(hwEdit
);
1538 #define edit_pos_ok(exp, got, txt) \
1539 ok(exp == got, "wrong " #txt " expected %d got %d\n", exp, got);
1541 #define check_pos(hwEdit, set_height, test_top, test_height, test_left) \
1545 set_client_height(hwEdit, set_height); \
1546 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &format_rect); \
1547 left_margin = LOWORD(SendMessage(hwEdit, EM_GETMARGINS, 0, 0)); \
1548 edit_pos_ok(test_top, format_rect.top, vertical position); \
1549 edit_pos_ok((int)test_height, format_rect.bottom - format_rect.top, height); \
1550 edit_pos_ok(test_left, format_rect.left - left_margin, left); \
1553 static void test_text_position_style(DWORD style
)
1556 HFONT font
, oldFont
;
1560 BOOL single_line
= !(style
& ES_MULTILINE
);
1562 b
= GetSystemMetrics(SM_CYBORDER
) + 1;
1567 /* Get a stock font for which we can determine the metrics */
1568 assert(font
= GetStockObject(SYSTEM_FONT
));
1569 assert(dc
= GetDC(NULL
));
1570 oldFont
= SelectObject(dc
, font
);
1571 assert(GetTextMetrics(dc
, &metrics
));
1572 SelectObject(dc
, oldFont
);
1573 ReleaseDC(NULL
, dc
);
1575 /* Windows' edit control has some bugs in multi-line mode:
1576 * - Sometimes the format rectangle doesn't get updated
1577 * (see workaround in set_client_height())
1578 * - If the height of the control is smaller than the height of a text
1579 * line, the format rectangle is still as high as a text line
1580 * (higher than the client rectangle) and the caret is not shown
1583 /* Edit controls that are in a parent window */
1585 hwEdit
= create_child_editcontrol(style
| WS_VISIBLE
, 0);
1586 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1588 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 0);
1589 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 0);
1590 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 0);
1591 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 0, metrics
.tmHeight
, 0);
1592 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 0, metrics
.tmHeight
, 0);
1593 destroy_child_editcontrol(hwEdit
);
1595 hwEdit
= create_child_editcontrol(style
| WS_BORDER
| WS_VISIBLE
, 0);
1596 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1598 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, b
);
1599 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, b
);
1600 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, b
);
1601 check_pos(hwEdit
, metrics
.tmHeight
+ bm
, 0, metrics
.tmHeight
, b
);
1602 check_pos(hwEdit
, metrics
.tmHeight
+ b2
, b
, metrics
.tmHeight
, b
);
1603 check_pos(hwEdit
, metrics
.tmHeight
+ b3
, b
, metrics
.tmHeight
, b
);
1604 destroy_child_editcontrol(hwEdit
);
1606 hwEdit
= create_child_editcontrol(style
| WS_VISIBLE
, WS_EX_CLIENTEDGE
);
1607 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1609 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 1);
1610 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 1);
1611 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 1);
1612 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 1, metrics
.tmHeight
, 1);
1613 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 1, metrics
.tmHeight
, 1);
1614 destroy_child_editcontrol(hwEdit
);
1616 hwEdit
= create_child_editcontrol(style
| WS_BORDER
| WS_VISIBLE
, WS_EX_CLIENTEDGE
);
1617 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1619 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 1);
1620 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 1);
1621 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 1);
1622 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 1, metrics
.tmHeight
, 1);
1623 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 1, metrics
.tmHeight
, 1);
1624 destroy_child_editcontrol(hwEdit
);
1627 /* Edit controls that are popup windows */
1629 hwEdit
= create_editcontrol(style
| WS_POPUP
, 0);
1630 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1632 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 0);
1633 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 0);
1634 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 0);
1635 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 0, metrics
.tmHeight
, 0);
1636 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 0, metrics
.tmHeight
, 0);
1637 DestroyWindow(hwEdit
);
1639 hwEdit
= create_editcontrol(style
| WS_POPUP
| WS_BORDER
, 0);
1640 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1642 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, b
);
1643 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, b
);
1644 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, b
);
1645 check_pos(hwEdit
, metrics
.tmHeight
+ bm
, 0, metrics
.tmHeight
, b
);
1646 check_pos(hwEdit
, metrics
.tmHeight
+ b2
, b
, metrics
.tmHeight
, b
);
1647 check_pos(hwEdit
, metrics
.tmHeight
+ b3
, b
, metrics
.tmHeight
, b
);
1648 DestroyWindow(hwEdit
);
1650 hwEdit
= create_editcontrol(style
| WS_POPUP
, WS_EX_CLIENTEDGE
);
1651 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1653 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 1);
1654 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 1);
1655 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 1);
1656 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 1, metrics
.tmHeight
, 1);
1657 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 1, metrics
.tmHeight
, 1);
1658 DestroyWindow(hwEdit
);
1660 hwEdit
= create_editcontrol(style
| WS_POPUP
| WS_BORDER
, WS_EX_CLIENTEDGE
);
1661 SendMessage(hwEdit
, WM_SETFONT
, (WPARAM
) font
, FALSE
);
1663 check_pos(hwEdit
, metrics
.tmHeight
- 1, 0, metrics
.tmHeight
- 1, 1);
1664 check_pos(hwEdit
, metrics
.tmHeight
, 0, metrics
.tmHeight
, 1);
1665 check_pos(hwEdit
, metrics
.tmHeight
+ 1, 0, metrics
.tmHeight
, 1);
1666 check_pos(hwEdit
, metrics
.tmHeight
+ 2, 1, metrics
.tmHeight
, 1);
1667 check_pos(hwEdit
, metrics
.tmHeight
+ 10, 1, metrics
.tmHeight
, 1);
1668 DestroyWindow(hwEdit
);
1671 static void test_text_position(void)
1673 trace("EDIT: Text position (Single line)\n");
1674 test_text_position_style(ES_AUTOHSCROLL
| ES_AUTOVSCROLL
);
1675 trace("EDIT: Text position (Multi line)\n");
1676 test_text_position_style(ES_MULTILINE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
);
1679 static void test_espassword(void)
1684 const char* password
= "secret";
1686 hwEdit
= create_editcontrol(ES_PASSWORD
, 0);
1687 r
= get_edit_style(hwEdit
);
1688 ok(r
== ES_PASSWORD
, "Wrong style expected 0x%x got: 0x%x\n", ES_PASSWORD
, r
);
1690 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) password
);
1691 ok(r
== TRUE
, "Expected: %d, got: %d\n", TRUE
, r
);
1693 /* select all, cut (ctrl-x) */
1694 SendMessage(hwEdit
, EM_SETSEL
, 0, -1);
1695 r
= SendMessage(hwEdit
, WM_CHAR
, 24, 0);
1696 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1699 r
= SendMessage(hwEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1700 ok(r
== strlen(password
), "Expected: %s, got len %d\n", password
, r
);
1701 ok(strcmp(buffer
, password
) == 0, "expected %s, got %s\n", password
, buffer
);
1703 r
= OpenClipboard(hwEdit
);
1704 ok(r
== TRUE
, "expected %d, got %d\n", TRUE
, r
);
1705 r
= EmptyClipboard();
1706 ok(r
== TRUE
, "expected %d, got %d\n", TRUE
, r
);
1707 r
= CloseClipboard();
1708 ok(r
== TRUE
, "expected %d, got %d\n", TRUE
, r
);
1710 /* select all, copy (ctrl-c) and paste (ctrl-v) */
1711 SendMessage(hwEdit
, EM_SETSEL
, 0, -1);
1712 r
= SendMessage(hwEdit
, WM_CHAR
, 3, 0);
1713 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1714 r
= SendMessage(hwEdit
, WM_CHAR
, 22, 0);
1715 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1719 r
= SendMessage(hwEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1720 ok(r
== 0, "Expected: 0, got: %d\n", r
);
1721 ok(strcmp(buffer
, "") == 0, "expected empty string, got %s\n", buffer
);
1723 DestroyWindow (hwEdit
);
1726 static void test_undo(void)
1732 const char* text
= "undo this";
1734 hwEdit
= create_editcontrol(0, 0);
1735 r
= get_edit_style(hwEdit
);
1736 ok(0 == r
, "Wrong style expected 0x%x got: 0x%x\n", 0, r
);
1739 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
1740 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1743 cpMin
= cpMax
= 0xdeadbeef;
1744 SendMessage(hwEdit
, EM_SETSEL
, 0, -1);
1745 r
= SendMessage(hwEdit
, EM_GETSEL
, (WPARAM
) &cpMin
, (LPARAM
) &cpMax
);
1746 ok((strlen(text
) << 16) == r
, "Unexpected length %d\n", r
);
1747 ok(0 == cpMin
, "Expected: %d, got %d\n", 0, cpMin
);
1748 ok(9 == cpMax
, "Expected: %d, got %d\n", 9, cpMax
);
1751 r
= SendMessage(hwEdit
, WM_CHAR
, 24, 0);
1752 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1756 r
= SendMessage(hwEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1757 ok(0 == r
, "Expected: %d, got len %d\n", 0, r
);
1758 ok(0 == strcmp(buffer
, ""), "expected %s, got %s\n", "", buffer
);
1761 r
= SendMessage(hwEdit
, WM_CHAR
, 26, 0);
1762 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1766 r
= SendMessage(hwEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1767 ok(strlen(text
) == r
, "Unexpected length %d\n", r
);
1768 ok(0 == strcmp(buffer
, text
), "expected %s, got %s\n", text
, buffer
);
1770 /* undo again (ctrl-z) */
1771 r
= SendMessage(hwEdit
, WM_CHAR
, 26, 0);
1772 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1776 r
= SendMessage(hwEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1777 ok(r
== 0, "Expected: %d, got len %d\n", 0, r
);
1778 ok(0 == strcmp(buffer
, ""), "expected %s, got %s\n", "", buffer
);
1780 DestroyWindow (hwEdit
);
1783 static void test_enter(void)
1790 hwEdit
= create_editcontrol(ES_MULTILINE
, 0);
1791 r
= get_edit_style(hwEdit
);
1792 ok(ES_MULTILINE
== r
, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE
, r
);
1795 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1796 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1798 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0);
1799 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1803 r
= SendMessage(hwEdit
, WM_GETTEXT
, 16, (LPARAM
) buffer
);
1804 ok(2 == r
, "Expected: %d, got len %d\n", 2, r
);
1805 ok(0 == strcmp(buffer
, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer
);
1807 DestroyWindow (hwEdit
);
1810 hwEdit
= create_editcontrol(0, 0);
1811 r
= get_edit_style(hwEdit
);
1812 ok(0 == r
, "Wrong style expected 0x%x got: 0x%x\n", 0, r
);
1815 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1816 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1818 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0);
1819 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1823 r
= SendMessage(hwEdit
, WM_GETTEXT
, 16, (LPARAM
) buffer
);
1824 ok(0 == r
, "Expected: %d, got len %d\n", 0, r
);
1825 ok(0 == strcmp(buffer
, ""), "expected \"\", got \"%s\"\n", buffer
);
1827 DestroyWindow (hwEdit
);
1829 /* single line with ES_WANTRETURN */
1830 hwEdit
= create_editcontrol(ES_WANTRETURN
, 0);
1831 r
= get_edit_style(hwEdit
);
1832 ok(ES_WANTRETURN
== r
, "Wrong style expected 0x%x got: 0x%x\n", ES_WANTRETURN
, r
);
1835 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1836 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1838 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0);
1839 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1843 r
= SendMessage(hwEdit
, WM_GETTEXT
, 16, (LPARAM
) buffer
);
1844 ok(0 == r
, "Expected: %d, got len %d\n", 0, r
);
1845 ok(0 == strcmp(buffer
, ""), "expected \"\", got \"%s\"\n", buffer
);
1847 DestroyWindow (hwEdit
);
1850 static void test_tab(void)
1857 hwEdit
= create_editcontrol(ES_MULTILINE
, 0);
1858 r
= get_edit_style(hwEdit
);
1859 ok(ES_MULTILINE
== r
, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE
, r
);
1862 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1863 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1865 r
= SendMessage(hwEdit
, WM_CHAR
, VK_TAB
, 0);
1866 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1870 r
= SendMessage(hwEdit
, WM_GETTEXT
, 16, (LPARAM
) buffer
);
1871 ok(1 == r
, "Expected: %d, got len %d\n", 1, r
);
1872 ok(0 == strcmp(buffer
, "\t"), "expected \"\\t\", got \"%s\"\n", buffer
);
1874 DestroyWindow (hwEdit
);
1877 hwEdit
= create_editcontrol(0, 0);
1878 r
= get_edit_style(hwEdit
);
1879 ok(0 == r
, "Wrong style expected 0x%x got: 0x%x\n", 0, r
);
1882 r
= SendMessage(hwEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1883 ok(TRUE
== r
, "Expected: %d, got: %d\n", TRUE
, r
);
1885 r
= SendMessage(hwEdit
, WM_CHAR
, VK_TAB
, 0);
1886 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
1890 r
= SendMessage(hwEdit
, WM_GETTEXT
, 16, (LPARAM
) buffer
);
1891 ok(0 == r
, "Expected: %d, got len %d\n", 0, r
);
1892 ok(0 == strcmp(buffer
, ""), "expected \"\", got \"%s\"\n", buffer
);
1894 DestroyWindow (hwEdit
);
1897 static void test_edit_dialog(void)
1901 /* from bug 11841 */
1902 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 0);
1903 ok(333 == r
, "Expected %d, got %d\n", 333, r
);
1904 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 1);
1905 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
1906 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 2);
1907 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1909 /* more tests for WM_CHAR */
1910 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 3);
1911 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1912 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 4);
1913 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1914 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 5);
1915 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1917 /* more tests for WM_KEYDOWN + WM_CHAR */
1918 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 6);
1919 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1920 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 7);
1921 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1922 r
= DialogBoxParam(hinst
, "EDIT_READONLY_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 8);
1923 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1925 /* tests with an editable edit control */
1926 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 0);
1927 ok(333 == r
, "Expected %d, got %d\n", 333, r
);
1928 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 1);
1929 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
1930 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 2);
1931 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1933 /* tests for WM_CHAR */
1934 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 3);
1935 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1936 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 4);
1937 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1938 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 5);
1939 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1941 /* tests for WM_KEYDOWN + WM_CHAR */
1942 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 6);
1943 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1944 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 7);
1945 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1946 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 8);
1947 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1949 /* multiple tab tests */
1950 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 9);
1951 ok(22 == r
, "Expected %d, got %d\n", 22, r
);
1952 r
= DialogBoxParam(hinst
, "EDIT_DIALOG", NULL
, (DLGPROC
)edit_dialog_proc
, 10);
1953 ok(33 == r
, "Expected %d, got %d\n", 33, r
);
1956 static void test_multi_edit_dialog(void)
1960 /* test for multiple edit dialogs (bug 12319) */
1961 r
= DialogBoxParam(hinst
, "MULTI_EDIT_DIALOG", NULL
, (DLGPROC
)multi_edit_dialog_proc
, 0);
1962 ok(2222 == r
, "Expected %d, got %d\n", 2222, r
);
1963 r
= DialogBoxParam(hinst
, "MULTI_EDIT_DIALOG", NULL
, (DLGPROC
)multi_edit_dialog_proc
, 1);
1964 ok(1111 == r
, "Expected %d, got %d\n", 1111, r
);
1965 r
= DialogBoxParam(hinst
, "MULTI_EDIT_DIALOG", NULL
, (DLGPROC
)multi_edit_dialog_proc
, 2);
1966 ok(2222 == r
, "Expected %d, got %d\n", 2222, r
);
1967 r
= DialogBoxParam(hinst
, "MULTI_EDIT_DIALOG", NULL
, (DLGPROC
)multi_edit_dialog_proc
, 3);
1968 ok(11 == r
, "Expected %d, got %d\n", 11, r
);
1971 static void test_wantreturn_edit_dialog(void)
1975 /* tests for WM_KEYDOWN */
1976 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 0);
1977 ok(333 == r
, "Expected %d, got %d\n", 333, r
);
1978 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 1);
1979 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1980 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 2);
1981 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1983 /* tests for WM_CHAR */
1984 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 3);
1985 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1986 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 4);
1987 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1988 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 5);
1989 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1991 /* tests for WM_KEYDOWN + WM_CHAR */
1992 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 6);
1993 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1994 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 7);
1995 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
1996 r
= DialogBoxParam(hinst
, "EDIT_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_wantreturn_dialog_proc
, 8);
1997 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2000 static void test_singleline_wantreturn_edit_dialog(void)
2004 /* tests for WM_KEYDOWN */
2005 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 0);
2006 ok(222 == r
, "Expected %d, got %d\n", 222, r
);
2007 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 1);
2008 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
2009 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 2);
2010 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2012 /* tests for WM_CHAR */
2013 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 3);
2014 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2015 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 4);
2016 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2017 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 5);
2018 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2020 /* tests for WM_KEYDOWN + WM_CHAR */
2021 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 6);
2022 ok(222 == r
, "Expected %d, got %d\n", 222, r
);
2023 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 7);
2024 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
2025 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 8);
2026 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2028 /* tests for WM_KEYDOWN */
2029 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 0);
2030 ok(222 == r
, "Expected %d, got %d\n", 222, r
);
2031 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 1);
2032 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
2033 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 2);
2034 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2036 /* tests for WM_CHAR */
2037 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 3);
2038 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2039 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 4);
2040 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2041 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 5);
2042 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2044 /* tests for WM_KEYDOWN + WM_CHAR */
2045 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 6);
2046 ok(222 == r
, "Expected %d, got %d\n", 222, r
);
2047 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 7);
2048 ok(111 == r
, "Expected %d, got %d\n", 111, r
);
2049 r
= DialogBoxParam(hinst
, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL
, (DLGPROC
)edit_singleline_dialog_proc
, 8);
2050 ok(444 == r
, "Expected %d, got %d\n", 444, r
);
2053 static int child_edit_wmkeydown_num_messages
= 0;
2054 static INT_PTR CALLBACK
child_edit_wmkeydown_proc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2063 child_edit_wmkeydown_num_messages
++;
2070 static void test_child_edit_wmkeydown(void)
2072 HWND hwEdit
, hwParent
;
2075 hwEdit
= create_child_editcontrol(0, 0);
2076 hwParent
= GetParent(hwEdit
);
2077 SetWindowLongPtr(hwParent
, GWLP_WNDPROC
, (LONG_PTR
)child_edit_wmkeydown_proc
);
2078 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
2079 ok(1 == r
, "expected 1, got %d\n", r
);
2080 ok(0 == child_edit_wmkeydown_num_messages
, "expected 0, got %d\n", child_edit_wmkeydown_num_messages
);
2081 destroy_child_editcontrol(hwEdit
);
2084 static BOOL
RegisterWindowClasses (void)
2088 WNDCLASSA text_position
;
2091 test2
.lpfnWndProc
= ET2_WndProc
;
2092 test2
.cbClsExtra
= 0;
2093 test2
.cbWndExtra
= 0;
2094 test2
.hInstance
= hinst
;
2096 test2
.hCursor
= LoadCursorA (NULL
, IDC_ARROW
);
2097 test2
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2098 test2
.lpszMenuName
= NULL
;
2099 test2
.lpszClassName
= szEditTest2Class
;
2100 if (!RegisterClassA(&test2
)) return FALSE
;
2103 test3
.lpfnWndProc
= edit3_wnd_procA
;
2104 test3
.cbClsExtra
= 0;
2105 test3
.cbWndExtra
= 0;
2106 test3
.hInstance
= hinst
;
2108 test3
.hCursor
= LoadCursorA(0, IDC_ARROW
);
2109 test3
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
2110 test3
.lpszMenuName
= NULL
;
2111 test3
.lpszClassName
= szEditTest3Class
;
2112 if (!RegisterClassA(&test3
)) return FALSE
;
2114 text_position
.style
= CS_HREDRAW
| CS_VREDRAW
;
2115 text_position
.cbClsExtra
= 0;
2116 text_position
.cbWndExtra
= 0;
2117 text_position
.hInstance
= hinst
;
2118 text_position
.hIcon
= NULL
;
2119 text_position
.hCursor
= LoadCursorA(NULL
, IDC_ARROW
);
2120 text_position
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
2121 text_position
.lpszMenuName
= NULL
;
2122 text_position
.lpszClassName
= szEditTextPositionClass
;
2123 text_position
.lpfnWndProc
= DefWindowProc
;
2124 if (!RegisterClassA(&text_position
)) return FALSE
;
2129 static void UnregisterWindowClasses (void)
2131 UnregisterClassA(szEditTest2Class
, hinst
);
2132 UnregisterClassA(szEditTest3Class
, hinst
);
2133 UnregisterClassA(szEditTextPositionClass
, hinst
);
2136 static void test_fontsize(void)
2142 char szLocalString
[MAXLEN
];
2144 memset(&lf
,0,sizeof(LOGFONTA
));
2145 strcpy(lf
.lfFaceName
,"Arial");
2146 lf
.lfHeight
= -300; /* taller than the edit box */
2148 hfont
= CreateFontIndirect(&lf
);
2150 trace("EDIT: Oversized font (Multi line)\n");
2151 hwEdit
= CreateWindow("EDIT", NULL
, ES_MULTILINE
|ES_AUTOHSCROLL
,
2152 0, 0, 150, 50, NULL
, NULL
, hinst
, NULL
);
2154 SendMessage(hwEdit
,WM_SETFONT
,(WPARAM
)hfont
,0);
2156 if (winetest_interactive
)
2157 ShowWindow (hwEdit
, SW_SHOW
);
2159 r
= SendMessage(hwEdit
, WM_CHAR
, 'A', 1);
2160 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
2161 r
= SendMessage(hwEdit
, WM_CHAR
, 'B', 1);
2162 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
2163 r
= SendMessage(hwEdit
, WM_CHAR
, 'C', 1);
2164 ok(1 == r
, "Expected: %d, got: %d\n", 1, r
);
2166 GetWindowText(hwEdit
, szLocalString
, MAXLEN
);
2167 ok(lstrcmp(szLocalString
, "ABC")==0,
2168 "Wrong contents of edit: %s\n", szLocalString
);
2170 r
= SendMessage(hwEdit
, EM_POSFROMCHAR
,0,0);
2171 ok(r
!= -1,"EM_POSFROMCHAR failed index 0\n");
2172 r
= SendMessage(hwEdit
, EM_POSFROMCHAR
,1,0);
2173 ok(r
!= -1,"EM_POSFROMCHAR failed index 1\n");
2174 r
= SendMessage(hwEdit
, EM_POSFROMCHAR
,2,0);
2175 ok(r
!= -1,"EM_POSFROMCHAR failed index 2\n");
2176 r
= SendMessage(hwEdit
, EM_POSFROMCHAR
,3,0);
2177 ok(r
== -1,"EM_POSFROMCHAR succeeded index 3\n");
2179 DestroyWindow (hwEdit
);
2180 DeleteObject(hfont
);
2183 struct dialog_mode_messages
2185 int wm_getdefid
, wm_close
, wm_command
, wm_nextdlgctl
;
2188 static struct dialog_mode_messages dm_messages
;
2190 static void zero_dm_messages(void)
2192 dm_messages
.wm_command
= 0;
2193 dm_messages
.wm_close
= 0;
2194 dm_messages
.wm_getdefid
= 0;
2195 dm_messages
.wm_nextdlgctl
= 0;
2198 #define test_dm_messages(wmcommand, wmclose, wmgetdefid, wmnextdlgctl) \
2199 ok(dm_messages.wm_command == wmcommand, "expected %d WM_COMMAND messages, " \
2200 "got %d\n", wmcommand, dm_messages.wm_command); \
2201 ok(dm_messages.wm_close == wmclose, "expected %d WM_CLOSE messages, " \
2202 "got %d\n", wmclose, dm_messages.wm_close); \
2203 ok(dm_messages.wm_getdefid == wmgetdefid, "expected %d WM_GETDIFID messages, " \
2204 "got %d\n", wmgetdefid, dm_messages.wm_getdefid);\
2205 ok(dm_messages.wm_nextdlgctl == wmnextdlgctl, "expected %d WM_NEXTDLGCTL messages, " \
2206 "got %d\n", wmnextdlgctl, dm_messages.wm_nextdlgctl)
2208 static LRESULT CALLBACK
dialog_mode_wnd_proc(HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2213 dm_messages
.wm_command
++;
2216 dm_messages
.wm_getdefid
++;
2217 return MAKELONG(ID_EDITTESTDBUTTON
, DC_HASDEFID
);
2219 dm_messages
.wm_nextdlgctl
++;
2222 dm_messages
.wm_close
++;
2226 return DefWindowProc(hwnd
, iMsg
, wParam
, lParam
);
2229 static void test_dialogmode(void)
2231 HWND hwEdit
, hwParent
, hwButton
;
2234 hwEdit
= create_child_editcontrol(ES_MULTILINE
, 0);
2236 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2237 ok(1 == r
, "expected 1, got %d\n", r
);
2238 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2239 ok(11 == len
, "expected 11, got %d\n", len
);
2241 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, 0);
2242 ok(0x8d == r
, "expected 0x8d, got 0x%x\n", r
);
2244 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2245 ok(1 == r
, "expected 1, got %d\n", r
);
2246 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2247 ok(13 == len
, "expected 13, got %d\n", len
);
2249 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, 0, (LPARAM
)&msg
);
2250 ok(0x8d == r
, "expected 0x8d, got 0x%x\n", r
);
2251 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2252 ok(1 == r
, "expected 1, got %d\n", r
);
2253 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2254 ok(13 == len
, "expected 13, got %d\n", len
);
2256 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2257 ok(1 == r
, "expected 1, got %d\n", r
);
2258 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2259 ok(13 == len
, "expected 13, got %d\n", len
);
2261 destroy_child_editcontrol(hwEdit
);
2263 hwEdit
= create_editcontrol(ES_MULTILINE
, 0);
2265 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2266 ok(1 == r
, "expected 1, got %d\n", r
);
2267 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2268 ok(11 == len
, "expected 11, got %d\n", len
);
2271 msg
.message
= WM_KEYDOWN
;
2272 msg
.wParam
= VK_BACK
;
2273 msg
.lParam
= 0xe0001;
2274 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, VK_BACK
, (LPARAM
)&msg
);
2275 ok(0x8d == r
, "expected 0x8d, got 0x%x\n", r
);
2277 r
= SendMessage(hwEdit
, WM_CHAR
, VK_RETURN
, 0x1c0001);
2278 ok(1 == r
, "expected 1, got %d\n", r
);
2279 len
= SendMessage(hwEdit
, WM_GETTEXTLENGTH
, 0, 0);
2280 ok(11 == len
, "expected 11, got %d\n", len
);
2282 DestroyWindow(hwEdit
);
2284 hwEdit
= create_child_editcontrol(0, 0);
2285 hwParent
= GetParent(hwEdit
);
2286 SetWindowLongPtr(hwParent
, GWLP_WNDPROC
, (LONG_PTR
)dialog_mode_wnd_proc
);
2289 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
2290 ok(1 == r
, "expected 1, got %d\n", r
);
2291 test_dm_messages(0, 0, 0, 0);
2294 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
2295 ok(1 == r
, "expected 1, got %d\n", r
);
2296 test_dm_messages(0, 0, 0, 0);
2300 msg
.message
= WM_KEYDOWN
;
2301 msg
.wParam
= VK_TAB
;
2302 msg
.lParam
= 0xf0001;
2303 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, VK_TAB
, (LPARAM
)&msg
);
2304 ok(0x89 == r
, "expected 0x89, got 0x%x\n", r
);
2305 test_dm_messages(0, 0, 0, 0);
2308 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
2309 ok(1 == r
, "expected 1, got %d\n", r
);
2310 test_dm_messages(0, 0, 0, 0);
2313 destroy_child_editcontrol(hwEdit
);
2315 hwEdit
= create_child_editcontrol(ES_MULTILINE
, 0);
2316 hwParent
= GetParent(hwEdit
);
2317 SetWindowLongPtr(hwParent
, GWLP_WNDPROC
, (LONG_PTR
)dialog_mode_wnd_proc
);
2319 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
2320 ok(1 == r
, "expected 1, got %d\n", r
);
2321 test_dm_messages(0, 0, 0, 0);
2325 msg
.message
= WM_KEYDOWN
;
2326 msg
.wParam
= VK_ESCAPE
;
2327 msg
.lParam
= 0x10001;
2328 r
= SendMessage(hwEdit
, WM_GETDLGCODE
, VK_ESCAPE
, (LPARAM
)&msg
);
2329 ok(0x8d == r
, "expected 0x8d, got 0x%x\n", r
);
2330 test_dm_messages(0, 0, 0, 0);
2333 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_ESCAPE
, 0x10001);
2334 ok(1 == r
, "expected 1, got %d\n", r
);
2335 test_dm_messages(0, 0, 0, 0);
2338 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_TAB
, 0xf0001);
2339 ok(1 == r
, "expected 1, got %d\n", r
);
2340 test_dm_messages(0, 0, 0, 1);
2343 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
2344 ok(1 == r
, "expected 1, got %d\n", r
);
2345 test_dm_messages(0, 0, 1, 0);
2348 hwButton
= CreateWindow("BUTTON", "OK", WS_VISIBLE
|WS_CHILD
|BS_PUSHBUTTON
,
2349 100, 100, 50, 20, hwParent
, (HMENU
)ID_EDITTESTDBUTTON
, hinst
, NULL
);
2350 ok(hwButton
!=NULL
, "CreateWindow failed with error code %d\n", GetLastError());
2352 r
= SendMessage(hwEdit
, WM_KEYDOWN
, VK_RETURN
, 0x1c0001);
2353 ok(1 == r
, "expected 1, got %d\n", r
);
2354 test_dm_messages(0, 0, 1, 1);
2357 DestroyWindow(hwButton
);
2358 destroy_child_editcontrol(hwEdit
);
2363 hinst
= GetModuleHandleA(NULL
);
2364 assert(RegisterWindowClasses());
2366 test_edit_control_1();
2367 test_edit_control_2();
2368 test_edit_control_3();
2369 test_edit_control_4();
2370 test_edit_control_5();
2371 test_edit_control_6();
2372 test_edit_control_limittext();
2373 test_edit_control_scroll();
2375 test_margins_font_change();
2376 test_text_position();
2382 test_multi_edit_dialog();
2383 test_wantreturn_edit_dialog();
2384 test_singleline_wantreturn_edit_dialog();
2385 test_child_edit_wmkeydown();
2389 UnregisterWindowClasses();