user32/tests: Run the tests again on Win95.
[wine.git] / dlls / user32 / tests / edit.c
blob9dd6fac2ddfbe98b0e4f685a851c0f8e4a2888d3
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
21 #include <assert.h>
22 #include <windows.h>
23 #include <commctrl.h>
25 #include "wine/test.h"
27 #ifndef ES_COMBO
28 #define ES_COMBO 0x200
29 #endif
31 #define ID_EDITTESTDBUTTON 0x123
32 #define ID_EDITTEST2 99
33 #define MAXLEN 200
35 struct edit_notify {
36 int en_change, en_maxtext, en_update;
39 static struct edit_notify notifications;
41 static BOOL (WINAPI *pEndMenu) (void);
43 static void init_function_pointers(void)
45 HMODULE hdll = GetModuleHandleA("user32");
47 pEndMenu = (void*)GetProcAddress(hdll, "EndMenu");
50 static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
52 static int num_ok_commands = 0;
53 switch (msg)
55 case WM_INITDIALOG:
57 HWND hedit = GetDlgItem(hdlg, 1000);
58 SetFocus(hedit);
59 switch (lparam)
61 /* test cases related to bug 12319 */
62 case 0:
63 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
64 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
65 break;
66 case 1:
67 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
68 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
69 break;
70 case 2:
71 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
72 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
73 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
74 break;
76 /* test cases for pressing enter */
77 case 3:
78 num_ok_commands = 0;
79 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
80 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
81 break;
83 default:
84 break;
86 break;
89 case WM_COMMAND:
90 if (HIWORD(wparam) != BN_CLICKED)
91 break;
93 switch (LOWORD(wparam))
95 case IDOK:
96 num_ok_commands++;
97 break;
99 default:
100 break;
102 break;
104 case WM_USER:
106 HWND hfocus = GetFocus();
107 HWND hedit = GetDlgItem(hdlg, 1000);
108 HWND hedit2 = GetDlgItem(hdlg, 1001);
109 HWND hedit3 = GetDlgItem(hdlg, 1002);
111 if (wparam != 0xdeadbeef)
112 break;
114 switch (lparam)
116 case 0:
117 if (hfocus == hedit)
118 EndDialog(hdlg, 1111);
119 else if (hfocus == hedit2)
120 EndDialog(hdlg, 2222);
121 else if (hfocus == hedit3)
122 EndDialog(hdlg, 3333);
123 else
124 EndDialog(hdlg, 4444);
125 break;
126 case 1:
127 if ((hfocus == hedit) && (num_ok_commands == 0))
128 EndDialog(hdlg, 11);
129 else
130 EndDialog(hdlg, 22);
131 break;
132 default:
133 EndDialog(hdlg, 5555);
135 break;
138 case WM_CLOSE:
139 EndDialog(hdlg, 333);
140 break;
142 default:
143 break;
146 return FALSE;
149 static INT_PTR CALLBACK edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
151 switch (msg)
153 case WM_INITDIALOG:
155 HWND hedit = GetDlgItem(hdlg, 1000);
156 SetFocus(hedit);
157 switch (lparam)
159 /* from bug 11841 */
160 case 0:
161 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
162 break;
163 case 1:
164 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
165 break;
166 case 2:
167 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
168 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
169 break;
171 /* more test cases for WM_CHAR */
172 case 3:
173 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
174 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
175 break;
176 case 4:
177 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
178 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
179 break;
180 case 5:
181 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
182 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
183 break;
185 /* more test cases for WM_KEYDOWN + WM_CHAR */
186 case 6:
187 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
188 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
189 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
190 break;
191 case 7:
192 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
193 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
194 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
195 break;
196 case 8:
197 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
198 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
199 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
200 break;
202 /* multiple tab tests */
203 case 9:
204 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
205 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
206 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
207 break;
208 case 10:
209 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
210 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
211 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
212 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
213 break;
215 default:
216 break;
218 break;
221 case WM_COMMAND:
222 if (HIWORD(wparam) != BN_CLICKED)
223 break;
225 switch (LOWORD(wparam))
227 case IDOK:
228 EndDialog(hdlg, 111);
229 break;
231 case IDCANCEL:
232 EndDialog(hdlg, 222);
233 break;
235 default:
236 break;
238 break;
240 case WM_USER:
242 int len;
243 HWND hok = GetDlgItem(hdlg, IDOK);
244 HWND hcancel = GetDlgItem(hdlg, IDCANCEL);
245 HWND hedit = GetDlgItem(hdlg, 1000);
246 HWND hfocus = GetFocus();
248 if (wparam != 0xdeadbeef)
249 break;
251 switch (lparam)
253 case 0:
254 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
255 if (len == 0)
256 EndDialog(hdlg, 444);
257 else
258 EndDialog(hdlg, 555);
259 break;
261 case 1:
262 len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
263 if ((hfocus == hok) && len == 0)
264 EndDialog(hdlg, 444);
265 else
266 EndDialog(hdlg, 555);
267 break;
269 case 2:
270 if (hfocus == hok)
271 EndDialog(hdlg, 11);
272 else if (hfocus == hcancel)
273 EndDialog(hdlg, 22);
274 else if (hfocus == hedit)
275 EndDialog(hdlg, 33);
276 else
277 EndDialog(hdlg, 44);
278 break;
280 default:
281 EndDialog(hdlg, 555);
283 break;
286 case WM_CLOSE:
287 EndDialog(hdlg, 333);
288 break;
290 default:
291 break;
294 return FALSE;
297 static INT_PTR CALLBACK edit_singleline_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
299 switch (msg)
301 case WM_INITDIALOG:
303 HWND hedit = GetDlgItem(hdlg, 1000);
304 SetFocus(hedit);
305 switch (lparam)
307 /* test cases for WM_KEYDOWN */
308 case 0:
309 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
310 break;
311 case 1:
312 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
313 break;
314 case 2:
315 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
316 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
317 break;
319 /* test cases for WM_CHAR */
320 case 3:
321 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
322 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
323 break;
324 case 4:
325 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
326 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
327 break;
328 case 5:
329 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
330 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
331 break;
333 /* test cases for WM_KEYDOWN + WM_CHAR */
334 case 6:
335 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
336 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
337 break;
338 case 7:
339 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
340 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
341 break;
342 case 8:
343 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
344 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
345 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
346 break;
348 default:
349 break;
351 break;
354 case WM_COMMAND:
355 if (HIWORD(wparam) != BN_CLICKED)
356 break;
358 switch (LOWORD(wparam))
360 case IDOK:
361 EndDialog(hdlg, 111);
362 break;
364 case IDCANCEL:
365 EndDialog(hdlg, 222);
366 break;
368 default:
369 break;
371 break;
373 case WM_USER:
375 HWND hok = GetDlgItem(hdlg, IDOK);
376 HWND hedit = GetDlgItem(hdlg, 1000);
377 HWND hfocus = GetFocus();
378 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
380 if (wparam != 0xdeadbeef)
381 break;
383 switch (lparam)
385 case 0:
386 if ((hfocus == hedit) && len == 0)
387 EndDialog(hdlg, 444);
388 else
389 EndDialog(hdlg, 555);
390 break;
392 case 1:
393 if ((hfocus == hok) && len == 0)
394 EndDialog(hdlg, 444);
395 else
396 EndDialog(hdlg, 555);
397 break;
399 default:
400 EndDialog(hdlg, 55);
402 break;
405 case WM_CLOSE:
406 EndDialog(hdlg, 333);
407 break;
409 default:
410 break;
413 return FALSE;
416 static INT_PTR CALLBACK edit_wantreturn_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
418 switch (msg)
420 case WM_INITDIALOG:
422 HWND hedit = GetDlgItem(hdlg, 1000);
423 SetFocus(hedit);
424 switch (lparam)
426 /* test cases for WM_KEYDOWN */
427 case 0:
428 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
429 break;
430 case 1:
431 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
432 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
433 break;
434 case 2:
435 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
436 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
437 break;
439 /* test cases for WM_CHAR */
440 case 3:
441 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
442 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
443 break;
444 case 4:
445 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
446 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
447 break;
448 case 5:
449 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
450 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
451 break;
453 /* test cases for WM_KEYDOWN + WM_CHAR */
454 case 6:
455 PostMessage(hedit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
456 PostMessage(hedit, WM_CHAR, VK_ESCAPE, 0x10001);
457 PostMessage(hdlg, WM_USER, 0xdeadbeef, 0);
458 break;
459 case 7:
460 PostMessage(hedit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
461 PostMessage(hedit, WM_CHAR, VK_RETURN, 0x1c0001);
462 PostMessage(hdlg, WM_USER, 0xdeadbeef, 2);
463 break;
464 case 8:
465 PostMessage(hedit, WM_KEYDOWN, VK_TAB, 0xf0001);
466 PostMessage(hedit, WM_CHAR, VK_TAB, 0xf0001);
467 PostMessage(hdlg, WM_USER, 0xdeadbeef, 1);
468 break;
470 default:
471 break;
473 break;
476 case WM_COMMAND:
477 if (HIWORD(wparam) != BN_CLICKED)
478 break;
480 switch (LOWORD(wparam))
482 case IDOK:
483 EndDialog(hdlg, 111);
484 break;
486 case IDCANCEL:
487 EndDialog(hdlg, 222);
488 break;
490 default:
491 break;
493 break;
495 case WM_USER:
497 HWND hok = GetDlgItem(hdlg, IDOK);
498 HWND hedit = GetDlgItem(hdlg, 1000);
499 HWND hfocus = GetFocus();
500 int len = SendMessage(hedit, WM_GETTEXTLENGTH, 0, 0);
502 if (wparam != 0xdeadbeef)
503 break;
505 switch (lparam)
507 case 0:
508 if ((hfocus == hedit) && len == 0)
509 EndDialog(hdlg, 444);
510 else
511 EndDialog(hdlg, 555);
512 break;
514 case 1:
515 if ((hfocus == hok) && len == 0)
516 EndDialog(hdlg, 444);
517 else
518 EndDialog(hdlg, 555);
519 break;
521 case 2:
522 if ((hfocus == hedit) && len == 2)
523 EndDialog(hdlg, 444);
524 else
525 EndDialog(hdlg, 555);
526 break;
528 default:
529 EndDialog(hdlg, 55);
531 break;
534 case WM_CLOSE:
535 EndDialog(hdlg, 333);
536 break;
538 default:
539 break;
542 return FALSE;
545 static HINSTANCE hinst;
546 static HWND hwndET2;
547 static const char szEditTest2Class[] = "EditTest2Class";
548 static const char szEditTest3Class[] = "EditTest3Class";
549 static const char szEditTest4Class[] = "EditTest4Class";
550 static const char szEditTextPositionClass[] = "EditTextPositionWindowClass";
552 static HWND create_editcontrol (DWORD style, DWORD exstyle)
554 HWND handle;
556 handle = CreateWindowEx(exstyle,
557 "EDIT",
558 "Test Text",
559 style,
560 10, 10, 300, 300,
561 NULL, NULL, hinst, NULL);
562 assert (handle);
563 if (winetest_interactive)
564 ShowWindow (handle, SW_SHOW);
565 return handle;
568 static HWND create_child_editcontrol (DWORD style, DWORD exstyle)
570 HWND parentWnd;
571 HWND editWnd;
572 RECT rect;
574 rect.left = 0;
575 rect.top = 0;
576 rect.right = 300;
577 rect.bottom = 300;
578 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
580 parentWnd = CreateWindowEx(0,
581 szEditTextPositionClass,
582 "Edit Test",
583 WS_OVERLAPPEDWINDOW,
584 CW_USEDEFAULT, CW_USEDEFAULT,
585 rect.right - rect.left, rect.bottom - rect.top,
586 NULL, NULL, hinst, NULL);
587 assert(parentWnd);
589 editWnd = CreateWindowEx(exstyle,
590 "EDIT",
591 "Test Text",
592 WS_CHILD | style,
593 0, 0, 300, 300,
594 parentWnd, NULL, hinst, NULL);
595 assert(editWnd);
596 if (winetest_interactive)
597 ShowWindow (parentWnd, SW_SHOW);
598 return editWnd;
601 static void destroy_child_editcontrol (HWND hwndEdit)
603 if (GetParent(hwndEdit))
604 DestroyWindow(GetParent(hwndEdit));
605 else {
606 trace("Edit control has no parent!\n");
607 DestroyWindow(hwndEdit);
611 static LONG get_edit_style (HWND hwnd)
613 return GetWindowLongA( hwnd, GWL_STYLE ) & (
614 ES_LEFT |
615 /* FIXME: not implemented
616 ES_CENTER |
617 ES_RIGHT |
618 ES_OEMCONVERT |
620 ES_MULTILINE |
621 ES_UPPERCASE |
622 ES_LOWERCASE |
623 ES_PASSWORD |
624 ES_AUTOVSCROLL |
625 ES_AUTOHSCROLL |
626 ES_NOHIDESEL |
627 ES_COMBO |
628 ES_READONLY |
629 ES_WANTRETURN |
630 ES_NUMBER
634 static void set_client_height(HWND Wnd, unsigned Height)
636 RECT ClientRect, WindowRect;
638 GetWindowRect(Wnd, &WindowRect);
639 GetClientRect(Wnd, &ClientRect);
640 SetWindowPos(Wnd, NULL, 0, 0,
641 WindowRect.right - WindowRect.left,
642 Height + (WindowRect.bottom - WindowRect.top) -
643 (ClientRect.bottom - ClientRect.top),
644 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
646 /* Workaround for a bug in Windows' edit control
647 (multi-line mode) */
648 GetWindowRect(Wnd, &WindowRect);
649 SetWindowPos(Wnd, NULL, 0, 0,
650 WindowRect.right - WindowRect.left + 1,
651 WindowRect.bottom - WindowRect.top + 1,
652 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
653 SetWindowPos(Wnd, NULL, 0, 0,
654 WindowRect.right - WindowRect.left,
655 WindowRect.bottom - WindowRect.top,
656 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
658 GetClientRect(Wnd, &ClientRect);
659 ok(ClientRect.bottom - ClientRect.top == Height,
660 "The client height should be %d, but is %d\n",
661 Height, ClientRect.bottom - ClientRect.top);
664 static void test_edit_control_1(void)
666 HWND hwEdit;
667 MSG msMessage;
668 int i;
669 LONG r;
671 msMessage.message = WM_KEYDOWN;
673 trace("EDIT: Single line\n");
674 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
675 r = get_edit_style(hwEdit);
676 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%x\n", r);
677 for (i=0;i<65535;i++)
679 msMessage.wParam = i;
680 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
681 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
682 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
684 DestroyWindow (hwEdit);
686 trace("EDIT: Single line want returns\n");
687 hwEdit = create_editcontrol(ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
688 r = get_edit_style(hwEdit);
689 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%x\n", r);
690 for (i=0;i<65535;i++)
692 msMessage.wParam = i;
693 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
694 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
695 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %x\n", r);
697 DestroyWindow (hwEdit);
699 trace("EDIT: Multiline line\n");
700 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
701 r = get_edit_style(hwEdit);
702 ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%x\n", r);
703 for (i=0;i<65535;i++)
705 msMessage.wParam = i;
706 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
707 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
708 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
710 DestroyWindow (hwEdit);
712 trace("EDIT: Multi line want returns\n");
713 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
714 r = get_edit_style(hwEdit);
715 ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%x\n", r);
716 for (i=0;i<65535;i++)
718 msMessage.wParam = i;
719 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
720 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
721 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %x\n", r);
723 DestroyWindow (hwEdit);
726 /* WM_SETTEXT is implemented by selecting all text, and then replacing the
727 * selection. This test checks that the first 'select all' doesn't generate
728 * an UPDATE message which can escape and (via a handler) change the
729 * selection, which would cause WM_SETTEXT to break. This old bug
730 * was fixed 18-Mar-2005; we check here to ensure it doesn't regress.
732 static void test_edit_control_2(void)
734 HWND hwndMain;
735 char szLocalString[MAXLEN];
736 LONG r;
738 /* Create main and edit windows. */
739 hwndMain = CreateWindow(szEditTest2Class, "ET2", WS_OVERLAPPEDWINDOW,
740 0, 0, 200, 200, NULL, NULL, hinst, NULL);
741 assert(hwndMain);
742 if (winetest_interactive)
743 ShowWindow (hwndMain, SW_SHOW);
745 hwndET2 = CreateWindow("EDIT", NULL,
746 WS_CHILD|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL,
747 0, 0, 150, 50, /* important this not be 0 size. */
748 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
749 assert(hwndET2);
750 if (winetest_interactive)
751 ShowWindow (hwndET2, SW_SHOW);
753 trace("EDIT: SETTEXT atomicity\n");
754 /* Send messages to "type" in the word 'foo'. */
755 r = SendMessage(hwndET2, WM_CHAR, 'f', 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 r = SendMessage(hwndET2, WM_CHAR, 'o', 1);
760 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
761 /* 'foo' should have been changed to 'bar' by the UPDATE handler. */
762 GetWindowText(hwndET2, szLocalString, MAXLEN);
763 ok(lstrcmp(szLocalString, "bar")==0,
764 "Wrong contents of edit: %s\n", szLocalString);
766 /* OK, done! */
767 DestroyWindow (hwndET2);
768 DestroyWindow (hwndMain);
771 static void ET2_check_change(void) {
772 char szLocalString[MAXLEN];
773 /* This EN_UPDATE handler changes any 'foo' to 'bar'. */
774 GetWindowText(hwndET2, szLocalString, MAXLEN);
775 if (lstrcmp(szLocalString, "foo")==0) {
776 lstrcpy(szLocalString, "bar");
777 SendMessage(hwndET2, WM_SETTEXT, 0, (LPARAM) szLocalString);
779 /* always leave the cursor at the end. */
780 SendMessage(hwndET2, EM_SETSEL, MAXLEN - 1, MAXLEN - 1);
782 static void ET2_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
784 if (id==ID_EDITTEST2 && codeNotify == EN_UPDATE)
785 ET2_check_change();
787 static LRESULT CALLBACK ET2_WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
789 switch (iMsg) {
790 case WM_COMMAND:
791 ET2_OnCommand(hwnd, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
792 break;
794 return DefWindowProc(hwnd, iMsg, wParam, lParam);
797 static void zero_notify(void)
799 notifications.en_change = 0;
800 notifications.en_maxtext = 0;
801 notifications.en_update = 0;
804 #define test_notify(enchange, enmaxtext, enupdate) \
805 ok(notifications.en_change == enchange, "expected %d EN_CHANGE notifications, " \
806 "got %d\n", enchange, notifications.en_change); \
807 ok(notifications.en_maxtext == enmaxtext, "expected %d EN_MAXTEXT notifications, " \
808 "got %d\n", enmaxtext, notifications.en_maxtext); \
809 ok(notifications.en_update == enupdate, "expected %d EN_UPDATE notifications, " \
810 "got %d\n", enupdate, notifications.en_update)
813 static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
815 switch (msg) {
816 case WM_COMMAND:
817 switch (HIWORD(wParam)) {
818 case EN_MAXTEXT:
819 notifications.en_maxtext++;
820 break;
821 case EN_UPDATE:
822 notifications.en_update++;
823 break;
824 case EN_CHANGE:
825 notifications.en_change++;
826 break;
828 break;
830 return DefWindowProcA(hWnd, msg, wParam, lParam);
833 /* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
834 * to these messages.
836 static void test_edit_control_3(void)
838 HWND hWnd;
839 HWND hParent;
840 int len;
841 static const char *str = "this is a long string.";
842 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.";
844 trace("EDIT: Test notifications\n");
846 hParent = CreateWindowExA(0,
847 szEditTest3Class,
848 NULL,
850 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10,
851 NULL, NULL, NULL, NULL);
852 assert(hParent);
854 trace("EDIT: Single line, no ES_AUTOHSCROLL\n");
855 hWnd = CreateWindowExA(0,
856 "EDIT",
857 NULL,
859 10, 10, 50, 50,
860 hParent, NULL, NULL, NULL);
861 assert(hWnd);
863 zero_notify();
864 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
865 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
866 ok(lstrlenA(str) > len, "text should have been truncated\n");
867 test_notify(1, 1, 1);
869 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
870 zero_notify();
871 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
872 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
873 ok(1 == len, "wrong text length, expected 1, got %d\n", len);
874 test_notify(1, 0, 1);
876 zero_notify();
877 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
878 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
879 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
880 test_notify(1, 0, 1);
882 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
883 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
884 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
885 SendMessage(hParent, WM_SETFOCUS, 0, (LPARAM)hWnd);
886 len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
887 ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
888 ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
890 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
892 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
893 zero_notify();
894 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
895 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
896 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
897 test_notify(1, 1, 1);
899 zero_notify();
900 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
901 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
902 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
903 test_notify(1, 0, 1);
905 DestroyWindow(hWnd);
907 trace("EDIT: Single line, ES_AUTOHSCROLL\n");
908 hWnd = CreateWindowExA(0,
909 "EDIT",
910 NULL,
911 ES_AUTOHSCROLL,
912 10, 10, 50, 50,
913 hParent, NULL, NULL, NULL);
914 assert(hWnd);
916 zero_notify();
917 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
918 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
919 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
920 test_notify(1, 0, 1);
922 zero_notify();
923 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
924 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
925 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
926 test_notify(1, 0, 1);
928 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
930 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
931 zero_notify();
932 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
933 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
934 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
935 test_notify(1, 1, 1);
937 zero_notify();
938 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
939 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
940 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
941 test_notify(1, 0, 1);
943 DestroyWindow(hWnd);
945 trace("EDIT: Multline, no ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
946 hWnd = CreateWindowExA(0,
947 "EDIT",
948 NULL,
949 ES_MULTILINE,
950 10, 10, 50, 50,
951 hParent, NULL, NULL, NULL);
952 assert(hWnd);
954 zero_notify();
955 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
956 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
957 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
958 test_notify(1, 1, 1);
960 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
961 zero_notify();
962 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
963 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
964 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
965 test_notify(1, 0, 1);
967 zero_notify();
968 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
969 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
970 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
971 test_notify(0, 0, 0);
973 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
975 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
976 zero_notify();
977 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str);
978 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
979 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
980 test_notify(1, 1, 1);
982 zero_notify();
983 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
984 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
985 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
986 test_notify(0, 0, 0);
988 DestroyWindow(hWnd);
990 trace("EDIT: Multline, ES_AUTOHSCROLL, no ES_AUTOVSCROLL\n");
991 hWnd = CreateWindowExA(0,
992 "EDIT",
993 NULL,
994 ES_MULTILINE | ES_AUTOHSCROLL,
995 10, 10, 50, 50,
996 hParent, NULL, NULL, NULL);
997 assert(hWnd);
999 zero_notify();
1000 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1001 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1002 ok(0 == len, "text should have been truncated, expected 0, got %d\n", len);
1003 test_notify(1, 1, 1);
1005 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1006 zero_notify();
1007 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)"a");
1008 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1009 ok(1 == SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0), "wrong text length, expected 1, got %d\n", len);
1010 test_notify(1, 0, 1);
1012 zero_notify();
1013 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1014 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1015 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1016 test_notify(0, 0, 0);
1018 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1020 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1021 zero_notify();
1022 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1023 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1024 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1025 test_notify(1, 1, 1);
1027 zero_notify();
1028 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1029 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1030 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1031 test_notify(0, 0, 0);
1033 DestroyWindow(hWnd);
1035 trace("EDIT: Multline, ES_AUTOHSCROLL and ES_AUTOVSCROLL\n");
1036 hWnd = CreateWindowExA(0,
1037 "EDIT",
1038 NULL,
1039 ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
1040 10, 10, 50, 50,
1041 hParent, NULL, NULL, NULL);
1042 assert(hWnd);
1044 zero_notify();
1045 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1046 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1047 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1048 test_notify(1, 0, 1);
1050 zero_notify();
1051 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1052 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1053 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1054 test_notify(0, 0, 0);
1056 SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
1058 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
1059 zero_notify();
1060 SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
1061 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1062 ok(5 == len, "text should have been truncated to limit, expected 5, got %d\n", len);
1063 test_notify(1, 1, 1);
1065 zero_notify();
1066 SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
1067 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1068 ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
1069 test_notify(0, 0, 0);
1071 DestroyWindow(hWnd);
1074 /* Test EM_CHARFROMPOS and EM_POSFROMCHAR
1076 static void test_edit_control_4(void)
1078 HWND hwEdit;
1079 int lo, hi, mid;
1080 int ret;
1081 int i;
1083 trace("EDIT: Test EM_CHARFROMPOS and EM_POSFROMCHAR\n");
1084 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1085 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1086 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1087 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1088 mid = lo + (hi - lo) / 2;
1090 for (i = lo; i < mid; i++) {
1091 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1092 ok(0 == ret, "expected 0 got %d\n", ret);
1094 for (i = mid; i <= hi; i++) {
1095 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1096 ok(1 == ret, "expected 1 got %d\n", ret);
1098 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1099 ok(-1 == ret, "expected -1 got %d\n", ret);
1100 DestroyWindow(hwEdit);
1102 hwEdit = create_editcontrol(ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1103 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1104 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1105 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1106 mid = lo + (hi - lo) / 2;
1108 for (i = lo; i < mid; i++) {
1109 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1110 ok(0 == ret, "expected 0 got %d\n", ret);
1112 for (i = mid; i <= hi; i++) {
1113 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1114 ok(1 == ret, "expected 1 got %d\n", ret);
1116 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1117 ok(-1 == ret, "expected -1 got %d\n", ret);
1118 DestroyWindow(hwEdit);
1120 hwEdit = create_editcontrol(ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1121 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1122 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1123 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1124 mid = lo + (hi - lo) / 2;
1126 for (i = lo; i < mid; i++) {
1127 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1128 ok(0 == ret, "expected 0 got %d\n", ret);
1130 for (i = mid; i <= hi; i++) {
1131 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1132 ok(1 == ret, "expected 1 got %d\n", ret);
1134 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1135 ok(-1 == ret, "expected -1 got %d\n", ret);
1136 DestroyWindow(hwEdit);
1138 hwEdit = create_editcontrol(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1139 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1140 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1141 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1142 mid = lo + (hi - lo) / 2 +1;
1144 for (i = lo; i < mid; i++) {
1145 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1146 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1148 for (i = mid; i <= hi; i++) {
1149 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1150 ok(1 == ret, "expected 1 got %d\n", ret);
1152 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1153 ok(-1 == ret, "expected -1 got %d\n", ret);
1154 DestroyWindow(hwEdit);
1156 hwEdit = create_editcontrol(ES_MULTILINE | ES_RIGHT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1157 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1158 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1159 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1160 mid = lo + (hi - lo) / 2 +1;
1162 for (i = lo; i < mid; i++) {
1163 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1164 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1166 for (i = mid; i <= hi; i++) {
1167 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1168 ok(1 == ret, "expected 1 got %d\n", ret);
1170 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1171 ok(-1 == ret, "expected -1 got %d\n", ret);
1172 DestroyWindow(hwEdit);
1174 hwEdit = create_editcontrol(ES_MULTILINE | ES_CENTER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1175 SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) "aa");
1176 lo = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 0, 0));
1177 hi = LOWORD(SendMessage(hwEdit, EM_POSFROMCHAR, 1, 0));
1178 mid = lo + (hi - lo) / 2 +1;
1180 for (i = lo; i < mid; i++) {
1181 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1182 ok((0 == ret || 1 == ret /* Vista */), "expected 0 or 1 got %d\n", ret);
1184 for (i = mid; i <= hi; i++) {
1185 ret = LOWORD(SendMessage(hwEdit, EM_CHARFROMPOS, 0, i));
1186 ok(1 == ret, "expected 1 got %d\n", ret);
1188 ret = SendMessage(hwEdit, EM_POSFROMCHAR, 2, 0);
1189 ok(-1 == ret, "expected -1 got %d\n", ret);
1190 DestroyWindow(hwEdit);
1193 /* Test if creating edit control without ES_AUTOHSCROLL and ES_AUTOVSCROLL
1194 * truncates text that doesn't fit.
1196 static void test_edit_control_5(void)
1198 static const char *str = "test\r\ntest";
1199 HWND parentWnd;
1200 HWND hWnd;
1201 int len;
1202 RECT rc1 = { 10, 10, 11, 11};
1203 RECT rc;
1205 /* first show that a non-child won't do for this test */
1206 hWnd = CreateWindowEx(0,
1207 "EDIT",
1208 str,
1210 10, 10, 1, 1,
1211 NULL, NULL, NULL, NULL);
1212 assert(hWnd);
1213 /* size of non-child edit control is (much) bigger than requested */
1214 GetWindowRect( hWnd, &rc);
1215 ok( rc.right - rc.left > 20, "size of the window (%d) is smaller than expected\n",
1216 rc.right - rc.left);
1217 DestroyWindow(hWnd);
1218 /* so create a parent, and give it edit controls children to test with */
1219 parentWnd = CreateWindowEx(0,
1220 szEditTextPositionClass,
1221 "Edit Test", WS_VISIBLE |
1222 WS_OVERLAPPEDWINDOW,
1223 CW_USEDEFAULT, CW_USEDEFAULT,
1224 250, 250,
1225 NULL, NULL, hinst, NULL);
1226 assert(parentWnd);
1227 ShowWindow( parentWnd, SW_SHOW);
1228 /* single line */
1229 hWnd = CreateWindowEx(0,
1230 "EDIT",
1231 str, WS_VISIBLE | WS_BORDER |
1232 WS_CHILD,
1233 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1234 parentWnd, NULL, NULL, NULL);
1235 assert(hWnd);
1236 GetClientRect( hWnd, &rc);
1237 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1238 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1239 rc.left, rc.top, rc.right, rc.bottom);
1240 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1241 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1242 DestroyWindow(hWnd);
1243 /* multi line */
1244 hWnd = CreateWindowEx(0,
1245 "EDIT",
1246 str,
1247 WS_CHILD | ES_MULTILINE,
1248 rc1.left, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top,
1249 parentWnd, NULL, NULL, NULL);
1250 assert(hWnd);
1251 GetClientRect( hWnd, &rc);
1252 ok( rc.right == rc1.right - rc1.left && rc.bottom == rc1.bottom - rc1.top,
1253 "Client rectangle not the expected size (%d,%d,%d,%d)\n",
1254 rc.left, rc.top, rc.right, rc.bottom);
1255 len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
1256 ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
1257 DestroyWindow(hWnd);
1260 /* Test WM_GETTEXT processing
1261 * after destroy messages
1263 static void test_edit_control_6(void)
1265 static const char *str = "test\r\ntest";
1266 char buf[MAXLEN];
1267 LONG ret;
1268 HWND hWnd;
1270 hWnd = CreateWindowEx(0,
1271 "EDIT",
1272 "Test",
1274 10, 10, 1, 1,
1275 NULL, NULL, hinst, NULL);
1276 assert(hWnd);
1278 ret = SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str);
1279 ok(ret == TRUE, "Expected %d, got %d\n", TRUE, ret);
1280 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1281 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1282 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1283 buf[0] = 0;
1284 ret = SendMessageA(hWnd, WM_DESTROY, 0, 0);
1285 ok(ret == 0, "Expected 0, got %d\n", ret);
1286 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1287 ok(ret == lstrlen(str), "Expected %s, got len %d\n", str, ret);
1288 ok(!lstrcmp(buf, str), "Expected %s, got %s\n", str, buf);
1289 buf[0] = 0;
1290 ret = SendMessageA(hWnd, WM_NCDESTROY, 0, 0);
1291 ok(ret == 0, "Expected 0, got %d\n", ret);
1292 ret = SendMessageA(hWnd, WM_GETTEXT, MAXLEN, (LPARAM)buf);
1293 ok(ret == 0, "Expected 0, got len %d\n", ret);
1294 ok(!lstrcmp(buf, ""), "Expected empty string, got %s\n", buf);
1296 DestroyWindow(hWnd);
1299 static void test_edit_control_limittext(void)
1301 HWND hwEdit;
1302 DWORD r;
1304 /* Test default limit for single-line control */
1305 trace("EDIT: buffer limit for single-line\n");
1306 hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1307 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1308 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1309 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1310 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1311 /* Win9x+ME: 32766; WinNT: 2147483646UL */
1312 ok( (r == 32766) || (r == 2147483646UL),
1313 "got limit %u (expected 32766 or 2147483646)\n", r);
1314 DestroyWindow(hwEdit);
1316 /* Test default limit for multi-line control */
1317 trace("EDIT: buffer limit for multi-line\n");
1318 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1319 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1320 ok(r == 30000, "Incorrect default text limit, expected 30000 got %u\n", r);
1321 SendMessage(hwEdit, EM_SETLIMITTEXT, 0, 0);
1322 r = SendMessage(hwEdit, EM_GETLIMITTEXT, 0, 0);
1323 /* Win9x+ME: 65535; WinNT: 4294967295UL */
1324 ok( (r == 65535) || (r == 4294967295UL),
1325 "got limit %u (expected 65535 or 4294967295)\n", r);
1326 DestroyWindow(hwEdit);
1329 /* Test EM_SCROLL */
1330 static void test_edit_control_scroll(void)
1332 static const char *single_line_str = "a";
1333 static const char *multiline_str = "Test\r\nText";
1334 HWND hwEdit;
1335 LONG ret;
1337 /* Check the return value when EM_SCROLL doesn't scroll
1338 * anything. Should not return true unless any lines were actually
1339 * scrolled. */
1340 hwEdit = CreateWindow(
1341 "EDIT",
1342 single_line_str,
1343 WS_VSCROLL | ES_MULTILINE,
1344 1, 1, 100, 100,
1345 NULL, NULL, hinst, NULL);
1347 assert(hwEdit);
1349 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1350 ok(!ret, "Returned %x, expected 0.\n", ret);
1352 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEUP, 0);
1353 ok(!ret, "Returned %x, expected 0.\n", ret);
1355 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEUP, 0);
1356 ok(!ret, "Returned %x, expected 0.\n", ret);
1358 ret = SendMessage(hwEdit, EM_SCROLL, SB_LINEDOWN, 0);
1359 ok(!ret, "Returned %x, expected 0.\n", ret);
1361 DestroyWindow (hwEdit);
1363 /* SB_PAGEDOWN while at the beginning of a buffer with few lines
1364 should not cause EM_SCROLL to return a negative value of
1365 scrolled lines that would put us "before" the beginning. */
1366 hwEdit = CreateWindow(
1367 "EDIT",
1368 multiline_str,
1369 WS_VSCROLL | ES_MULTILINE,
1370 0, 0, 100, 100,
1371 NULL, NULL, hinst, NULL);
1372 assert(hwEdit);
1374 ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
1375 ok(!ret, "Returned %x, expected 0.\n", ret);
1377 DestroyWindow (hwEdit);
1380 static void test_margins(void)
1382 HWND hwEdit;
1383 RECT old_rect, new_rect;
1384 INT old_left_margin, old_right_margin;
1385 DWORD old_margins, new_margins;
1387 hwEdit = create_editcontrol(WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
1389 old_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1390 old_left_margin = LOWORD(old_margins);
1391 old_right_margin = HIWORD(old_margins);
1393 /* Check if setting the margins works */
1395 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(10, 0));
1396 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1397 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1398 ok(HIWORD(new_margins) == old_right_margin, "Wrong right margin: %d\n", HIWORD(new_margins));
1400 SendMessage(hwEdit, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, 10));
1401 new_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1402 ok(LOWORD(new_margins) == 10, "Wrong left margin: %d\n", LOWORD(new_margins));
1403 ok(HIWORD(new_margins) == 10, "Wrong right margin: %d\n", HIWORD(new_margins));
1406 /* The size of the rectangle must decrease if we increase the margin */
1408 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5));
1409 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1410 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(15, 20));
1411 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1412 ok(new_rect.left == old_rect.left + 10, "The left border of the rectangle is wrong\n");
1413 ok(new_rect.right == old_rect.right - 15, "The right border of the rectangle is wrong\n");
1414 ok(new_rect.top == old_rect.top, "The top border of the rectangle must not change\n");
1415 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle must not change\n");
1418 /* If we set the margin to same value as the current margin,
1419 the rectangle must not change */
1421 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1422 old_rect.left = 1;
1423 old_rect.right = 99;
1424 old_rect.top = 1;
1425 old_rect.bottom = 99;
1426 SendMessage(hwEdit, EM_SETRECT, 0, (LPARAM)&old_rect);
1427 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&old_rect);
1428 SendMessage(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10));
1429 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM)&new_rect);
1430 ok(new_rect.left == old_rect.left, "The left border of the rectangle has changed\n");
1431 ok(new_rect.right == old_rect.right, "The right border of the rectangle has changed\n");
1432 ok(new_rect.top == old_rect.top, "The top border of the rectangle has changed\n");
1433 ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n");
1435 DestroyWindow (hwEdit);
1438 static INT CALLBACK find_font_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
1440 return 0;
1443 static void test_margins_font_change(void)
1445 HWND hwEdit;
1446 DWORD margins, font_margins;
1447 LOGFONT lf;
1448 HFONT hfont, hfont2;
1449 HDC hdc = GetDC(0);
1451 if(EnumFontFamiliesA(hdc, "Arial", find_font_proc, 0))
1453 trace("Arial not found - skipping font change margin tests\n");
1454 ReleaseDC(0, hdc);
1455 return;
1457 ReleaseDC(0, hdc);
1459 hwEdit = create_child_editcontrol(0, 0);
1461 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1463 memset(&lf, 0, sizeof(lf));
1464 strcpy(lf.lfFaceName, "Arial");
1465 lf.lfHeight = 16;
1466 lf.lfCharSet = DEFAULT_CHARSET;
1467 hfont = CreateFontIndirectA(&lf);
1468 lf.lfHeight = 30;
1469 hfont2 = CreateFontIndirectA(&lf);
1471 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1472 font_margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1473 ok(LOWORD(font_margins) != 0, "got %d\n", LOWORD(font_margins));
1474 ok(HIWORD(font_margins) != 0, "got %d\n", HIWORD(font_margins));
1476 /* With 'small' edit controls, test that the margin doesn't get set */
1477 SetWindowPos(hwEdit, NULL, 10, 10, 16, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1478 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0,0));
1479 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1480 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1481 ok(LOWORD(margins) == 0 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1482 "got %d\n", LOWORD(margins));
1483 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1484 "got %d\n", HIWORD(margins));
1486 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1487 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1488 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1489 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1490 "got %d\n", LOWORD(margins));
1491 ok(HIWORD(margins) == 0 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1492 "got %d\n", HIWORD(margins));
1494 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1495 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1496 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1497 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1498 "got %d\n", LOWORD(margins));
1499 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1500 "got %d\n", HIWORD(margins));
1502 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1503 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1504 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) == LOWORD(font_margins)), /* win95 */
1505 "got %d\n", LOWORD(margins));
1506 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) == HIWORD(font_margins)), /* win95 */
1507 "got %d\n", HIWORD(margins));
1509 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1510 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1511 ok(LOWORD(margins) == 1 || broken(LOWORD(margins) != 1 && LOWORD(margins) != LOWORD(font_margins)), /* win95 */
1512 "got %d\n", LOWORD(margins));
1513 ok(HIWORD(margins) == 1 || broken(HIWORD(margins) != 1 && HIWORD(margins) != HIWORD(font_margins)), /* win95 */
1514 "got %d\n", HIWORD(margins));
1516 /* Above a certain size threshold then the margin is updated */
1517 SetWindowPos(hwEdit, NULL, 10, 10, 1000, 100, SWP_NOZORDER | SWP_NOACTIVATE);
1518 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0));
1519 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1520 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1521 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1522 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1524 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1));
1525 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, 0);
1526 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1527 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1528 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1530 SendMessageA(hwEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO));
1531 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1532 ok(LOWORD(margins) == LOWORD(font_margins), "got %d\n", LOWORD(margins));
1533 ok(HIWORD(margins) == HIWORD(font_margins), "got %d\n", HIWORD(margins));
1534 SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont2, 0);
1535 margins = SendMessage(hwEdit, EM_GETMARGINS, 0, 0);
1536 ok(LOWORD(margins) != LOWORD(font_margins) || broken(LOWORD(margins) == LOWORD(font_margins)), /* win98 */
1537 "got %d\n", LOWORD(margins));
1538 ok(HIWORD(margins) != HIWORD(font_margins), "got %d\n", HIWORD(margins));
1540 SendMessageA(hwEdit, WM_SETFONT, 0, 0);
1542 DeleteObject(hfont2);
1543 DeleteObject(hfont);
1544 destroy_child_editcontrol(hwEdit);
1548 #define edit_pos_ok(exp, got, txt) \
1549 ok(exp == got, "wrong " #txt " expected %d got %d\n", exp, got);
1551 #define check_pos(hwEdit, set_height, test_top, test_height, test_left) \
1552 do { \
1553 RECT format_rect; \
1554 int left_margin; \
1555 set_client_height(hwEdit, set_height); \
1556 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &format_rect); \
1557 left_margin = LOWORD(SendMessage(hwEdit, EM_GETMARGINS, 0, 0)); \
1558 edit_pos_ok(test_top, format_rect.top, vertical position); \
1559 edit_pos_ok((int)test_height, format_rect.bottom - format_rect.top, height); \
1560 edit_pos_ok(test_left, format_rect.left - left_margin, left); \
1561 } while(0)
1563 static void test_text_position_style(DWORD style)
1565 HWND hwEdit;
1566 HFONT font, oldFont;
1567 HDC dc;
1568 TEXTMETRIC metrics;
1569 INT b, bm, b2, b3;
1570 BOOL single_line = !(style & ES_MULTILINE);
1572 b = GetSystemMetrics(SM_CYBORDER) + 1;
1573 b2 = 2 * b;
1574 b3 = 3 * b;
1575 bm = b2 - 1;
1577 /* Get a stock font for which we can determine the metrics */
1578 assert(font = GetStockObject(SYSTEM_FONT));
1579 assert(dc = GetDC(NULL));
1580 oldFont = SelectObject(dc, font);
1581 assert(GetTextMetrics(dc, &metrics));
1582 SelectObject(dc, oldFont);
1583 ReleaseDC(NULL, dc);
1585 /* Windows' edit control has some bugs in multi-line mode:
1586 * - Sometimes the format rectangle doesn't get updated
1587 * (see workaround in set_client_height())
1588 * - If the height of the control is smaller than the height of a text
1589 * line, the format rectangle is still as high as a text line
1590 * (higher than the client rectangle) and the caret is not shown
1593 /* Edit controls that are in a parent window */
1595 hwEdit = create_child_editcontrol(style | WS_VISIBLE, 0);
1596 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1597 if (single_line)
1598 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1599 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1600 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1601 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1602 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1603 destroy_child_editcontrol(hwEdit);
1605 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, 0);
1606 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1607 if (single_line)
1608 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1609 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1610 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1611 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1612 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1613 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1614 destroy_child_editcontrol(hwEdit);
1616 hwEdit = create_child_editcontrol(style | WS_VISIBLE, WS_EX_CLIENTEDGE);
1617 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1618 if (single_line)
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);
1626 hwEdit = create_child_editcontrol(style | WS_BORDER | WS_VISIBLE, WS_EX_CLIENTEDGE);
1627 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1628 if (single_line)
1629 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1630 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1631 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1632 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1633 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1634 destroy_child_editcontrol(hwEdit);
1637 /* Edit controls that are popup windows */
1639 hwEdit = create_editcontrol(style | WS_POPUP, 0);
1640 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1641 if (single_line)
1642 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 0);
1643 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 0);
1644 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 0);
1645 check_pos(hwEdit, metrics.tmHeight + 2, 0, metrics.tmHeight , 0);
1646 check_pos(hwEdit, metrics.tmHeight + 10, 0, metrics.tmHeight , 0);
1647 DestroyWindow(hwEdit);
1649 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, 0);
1650 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1651 if (single_line)
1652 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, b);
1653 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , b);
1654 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , b);
1655 check_pos(hwEdit, metrics.tmHeight + bm, 0, metrics.tmHeight , b);
1656 check_pos(hwEdit, metrics.tmHeight + b2, b, metrics.tmHeight , b);
1657 check_pos(hwEdit, metrics.tmHeight + b3, b, metrics.tmHeight , b);
1658 DestroyWindow(hwEdit);
1660 hwEdit = create_editcontrol(style | WS_POPUP, WS_EX_CLIENTEDGE);
1661 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1662 if (single_line)
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);
1670 hwEdit = create_editcontrol(style | WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
1671 SendMessage(hwEdit, WM_SETFONT, (WPARAM) font, FALSE);
1672 if (single_line)
1673 check_pos(hwEdit, metrics.tmHeight - 1, 0, metrics.tmHeight - 1, 1);
1674 check_pos(hwEdit, metrics.tmHeight , 0, metrics.tmHeight , 1);
1675 check_pos(hwEdit, metrics.tmHeight + 1, 0, metrics.tmHeight , 1);
1676 check_pos(hwEdit, metrics.tmHeight + 2, 1, metrics.tmHeight , 1);
1677 check_pos(hwEdit, metrics.tmHeight + 10, 1, metrics.tmHeight , 1);
1678 DestroyWindow(hwEdit);
1681 static void test_text_position(void)
1683 trace("EDIT: Text position (Single line)\n");
1684 test_text_position_style(ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1685 trace("EDIT: Text position (Multi line)\n");
1686 test_text_position_style(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL);
1689 static void test_espassword(void)
1691 HWND hwEdit;
1692 LONG r;
1693 char buffer[1024];
1694 const char* password = "secret";
1696 hwEdit = create_editcontrol(ES_PASSWORD, 0);
1697 r = get_edit_style(hwEdit);
1698 ok(r == ES_PASSWORD, "Wrong style expected 0x%x got: 0x%x\n", ES_PASSWORD, r);
1699 /* set text */
1700 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) password);
1701 ok(r == TRUE, "Expected: %d, got: %d\n", TRUE, r);
1703 /* select all, cut (ctrl-x) */
1704 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1705 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1706 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1708 /* get text */
1709 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1710 ok(r == strlen(password), "Expected: %s, got len %d\n", password, r);
1711 ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
1713 r = OpenClipboard(hwEdit);
1714 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1715 r = EmptyClipboard();
1716 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1717 r = CloseClipboard();
1718 ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
1720 /* select all, copy (ctrl-c) and paste (ctrl-v) */
1721 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1722 r = SendMessage(hwEdit, WM_CHAR, 3, 0);
1723 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1724 r = SendMessage(hwEdit, WM_CHAR, 22, 0);
1725 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1727 /* get text */
1728 buffer[0] = 0;
1729 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1730 ok(r == 0, "Expected: 0, got: %d\n", r);
1731 ok(strcmp(buffer, "") == 0, "expected empty string, got %s\n", buffer);
1733 DestroyWindow (hwEdit);
1736 static void test_undo(void)
1738 HWND hwEdit;
1739 LONG r;
1740 DWORD cpMin, cpMax;
1741 char buffer[1024];
1742 const char* text = "undo this";
1744 hwEdit = create_editcontrol(0, 0);
1745 r = get_edit_style(hwEdit);
1746 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1748 /* set text */
1749 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) text);
1750 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1752 /* select all, */
1753 cpMin = cpMax = 0xdeadbeef;
1754 SendMessage(hwEdit, EM_SETSEL, 0, -1);
1755 r = SendMessage(hwEdit, EM_GETSEL, (WPARAM) &cpMin, (LPARAM) &cpMax);
1756 ok((strlen(text) << 16) == r, "Unexpected length %d\n", r);
1757 ok(0 == cpMin, "Expected: %d, got %d\n", 0, cpMin);
1758 ok(9 == cpMax, "Expected: %d, got %d\n", 9, cpMax);
1760 /* cut (ctrl-x) */
1761 r = SendMessage(hwEdit, WM_CHAR, 24, 0);
1762 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1764 /* get text */
1765 buffer[0] = 0;
1766 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1767 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1768 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1770 /* undo (ctrl-z) */
1771 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1772 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1774 /* get text */
1775 buffer[0] = 0;
1776 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1777 ok(strlen(text) == r, "Unexpected length %d\n", r);
1778 ok(0 == strcmp(buffer, text), "expected %s, got %s\n", text, buffer);
1780 /* undo again (ctrl-z) */
1781 r = SendMessage(hwEdit, WM_CHAR, 26, 0);
1782 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1784 /* get text */
1785 buffer[0] = 0;
1786 r = SendMessage(hwEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
1787 ok(r == 0, "Expected: %d, got len %d\n", 0, r);
1788 ok(0 == strcmp(buffer, ""), "expected %s, got %s\n", "", buffer);
1790 DestroyWindow (hwEdit);
1793 static void test_enter(void)
1795 HWND hwEdit;
1796 LONG r;
1797 char buffer[16];
1799 /* multiline */
1800 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1801 r = get_edit_style(hwEdit);
1802 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1804 /* set text */
1805 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1806 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1808 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1809 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1811 /* get text */
1812 buffer[0] = 0;
1813 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1814 ok(2 == r, "Expected: %d, got len %d\n", 2, r);
1815 ok(0 == strcmp(buffer, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer);
1817 DestroyWindow (hwEdit);
1819 /* single line */
1820 hwEdit = create_editcontrol(0, 0);
1821 r = get_edit_style(hwEdit);
1822 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1824 /* set text */
1825 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1826 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1828 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1829 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1831 /* get text */
1832 buffer[0] = 0;
1833 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1834 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1835 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1837 DestroyWindow (hwEdit);
1839 /* single line with ES_WANTRETURN */
1840 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
1841 r = get_edit_style(hwEdit);
1842 ok(ES_WANTRETURN == r, "Wrong style expected 0x%x got: 0x%x\n", ES_WANTRETURN, r);
1844 /* set text */
1845 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1846 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1848 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
1849 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1851 /* get text */
1852 buffer[0] = 0;
1853 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1854 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1855 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1857 DestroyWindow (hwEdit);
1860 static void test_tab(void)
1862 HWND hwEdit;
1863 LONG r;
1864 char buffer[16];
1866 /* multiline */
1867 hwEdit = create_editcontrol(ES_MULTILINE, 0);
1868 r = get_edit_style(hwEdit);
1869 ok(ES_MULTILINE == r, "Wrong style expected 0x%x got: 0x%x\n", ES_MULTILINE, r);
1871 /* set text */
1872 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1873 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1875 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1876 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1878 /* get text */
1879 buffer[0] = 0;
1880 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1881 ok(1 == r, "Expected: %d, got len %d\n", 1, r);
1882 ok(0 == strcmp(buffer, "\t"), "expected \"\\t\", got \"%s\"\n", buffer);
1884 DestroyWindow (hwEdit);
1886 /* single line */
1887 hwEdit = create_editcontrol(0, 0);
1888 r = get_edit_style(hwEdit);
1889 ok(0 == r, "Wrong style expected 0x%x got: 0x%x\n", 0, r);
1891 /* set text */
1892 r = SendMessage(hwEdit , WM_SETTEXT, 0, (LPARAM) "");
1893 ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
1895 r = SendMessage(hwEdit, WM_CHAR, VK_TAB, 0);
1896 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
1898 /* get text */
1899 buffer[0] = 0;
1900 r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
1901 ok(0 == r, "Expected: %d, got len %d\n", 0, r);
1902 ok(0 == strcmp(buffer, ""), "expected \"\", got \"%s\"\n", buffer);
1904 DestroyWindow (hwEdit);
1907 static void test_edit_dialog(void)
1909 int r;
1911 /* from bug 11841 */
1912 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1913 ok(333 == r, "Expected %d, got %d\n", 333, r);
1914 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1915 ok(111 == r, "Expected %d, got %d\n", 111, r);
1916 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1917 ok(444 == r, "Expected %d, got %d\n", 444, r);
1919 /* more tests for WM_CHAR */
1920 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1921 ok(444 == r, "Expected %d, got %d\n", 444, r);
1922 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1923 ok(444 == r, "Expected %d, got %d\n", 444, r);
1924 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1925 ok(444 == r, "Expected %d, got %d\n", 444, r);
1927 /* more tests for WM_KEYDOWN + WM_CHAR */
1928 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1929 ok(444 == r, "Expected %d, got %d\n", 444, r);
1930 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1931 ok(444 == r, "Expected %d, got %d\n", 444, r);
1932 r = DialogBoxParam(hinst, "EDIT_READONLY_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1933 ok(444 == r, "Expected %d, got %d\n", 444, r);
1935 /* tests with an editable edit control */
1936 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 0);
1937 ok(333 == r, "Expected %d, got %d\n", 333, r);
1938 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 1);
1939 ok(111 == r, "Expected %d, got %d\n", 111, r);
1940 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 2);
1941 ok(444 == r, "Expected %d, got %d\n", 444, r);
1943 /* tests for WM_CHAR */
1944 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 3);
1945 ok(444 == r, "Expected %d, got %d\n", 444, r);
1946 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 4);
1947 ok(444 == r, "Expected %d, got %d\n", 444, r);
1948 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 5);
1949 ok(444 == r, "Expected %d, got %d\n", 444, r);
1951 /* tests for WM_KEYDOWN + WM_CHAR */
1952 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 6);
1953 ok(444 == r, "Expected %d, got %d\n", 444, r);
1954 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 7);
1955 ok(444 == r, "Expected %d, got %d\n", 444, r);
1956 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 8);
1957 ok(444 == r, "Expected %d, got %d\n", 444, r);
1959 /* multiple tab tests */
1960 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 9);
1961 ok(22 == r, "Expected %d, got %d\n", 22, r);
1962 r = DialogBoxParam(hinst, "EDIT_DIALOG", NULL, (DLGPROC)edit_dialog_proc, 10);
1963 ok(33 == r, "Expected %d, got %d\n", 33, r);
1966 static void test_multi_edit_dialog(void)
1968 int r;
1970 /* test for multiple edit dialogs (bug 12319) */
1971 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 0);
1972 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1973 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 1);
1974 ok(1111 == r, "Expected %d, got %d\n", 1111, r);
1975 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 2);
1976 ok(2222 == r, "Expected %d, got %d\n", 2222, r);
1977 r = DialogBoxParam(hinst, "MULTI_EDIT_DIALOG", NULL, (DLGPROC)multi_edit_dialog_proc, 3);
1978 ok(11 == r, "Expected %d, got %d\n", 11, r);
1981 static void test_wantreturn_edit_dialog(void)
1983 int r;
1985 /* tests for WM_KEYDOWN */
1986 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 0);
1987 ok(333 == r, "Expected %d, got %d\n", 333, r);
1988 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 1);
1989 ok(444 == r, "Expected %d, got %d\n", 444, r);
1990 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 2);
1991 ok(444 == r, "Expected %d, got %d\n", 444, r);
1993 /* tests for WM_CHAR */
1994 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 3);
1995 ok(444 == r, "Expected %d, got %d\n", 444, r);
1996 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 4);
1997 ok(444 == r, "Expected %d, got %d\n", 444, r);
1998 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 5);
1999 ok(444 == r, "Expected %d, got %d\n", 444, r);
2001 /* tests for WM_KEYDOWN + WM_CHAR */
2002 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 6);
2003 ok(444 == r, "Expected %d, got %d\n", 444, r);
2004 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 7);
2005 ok(444 == r, "Expected %d, got %d\n", 444, r);
2006 r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 8);
2007 ok(444 == r, "Expected %d, got %d\n", 444, r);
2010 static void test_singleline_wantreturn_edit_dialog(void)
2012 int r;
2014 /* tests for WM_KEYDOWN */
2015 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
2016 ok(222 == r, "Expected %d, got %d\n", 222, r);
2017 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
2018 ok(111 == r, "Expected %d, got %d\n", 111, r);
2019 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
2020 ok(444 == r, "Expected %d, got %d\n", 444, r);
2022 /* tests for WM_CHAR */
2023 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
2024 ok(444 == r, "Expected %d, got %d\n", 444, r);
2025 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
2026 ok(444 == r, "Expected %d, got %d\n", 444, r);
2027 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
2028 ok(444 == r, "Expected %d, got %d\n", 444, r);
2030 /* tests for WM_KEYDOWN + WM_CHAR */
2031 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
2032 ok(222 == r, "Expected %d, got %d\n", 222, r);
2033 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
2034 ok(111 == r, "Expected %d, got %d\n", 111, r);
2035 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
2036 ok(444 == r, "Expected %d, got %d\n", 444, r);
2038 /* tests for WM_KEYDOWN */
2039 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 0);
2040 ok(222 == r, "Expected %d, got %d\n", 222, r);
2041 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 1);
2042 ok(111 == r, "Expected %d, got %d\n", 111, r);
2043 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 2);
2044 ok(444 == r, "Expected %d, got %d\n", 444, r);
2046 /* tests for WM_CHAR */
2047 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 3);
2048 ok(444 == r, "Expected %d, got %d\n", 444, r);
2049 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 4);
2050 ok(444 == r, "Expected %d, got %d\n", 444, r);
2051 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 5);
2052 ok(444 == r, "Expected %d, got %d\n", 444, r);
2054 /* tests for WM_KEYDOWN + WM_CHAR */
2055 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 6);
2056 ok(222 == r, "Expected %d, got %d\n", 222, r);
2057 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 7);
2058 ok(111 == r, "Expected %d, got %d\n", 111, r);
2059 r = DialogBoxParam(hinst, "EDIT_SINGLELINE_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_singleline_dialog_proc, 8);
2060 ok(444 == r, "Expected %d, got %d\n", 444, r);
2063 static int child_edit_wmkeydown_num_messages = 0;
2064 static INT_PTR CALLBACK child_edit_wmkeydown_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
2066 switch (msg)
2068 case WM_DESTROY:
2069 case WM_NCDESTROY:
2070 break;
2072 default:
2073 child_edit_wmkeydown_num_messages++;
2074 break;
2077 return FALSE;
2080 static void test_child_edit_wmkeydown(void)
2082 HWND hwEdit, hwParent;
2083 int r;
2085 hwEdit = create_child_editcontrol(0, 0);
2086 hwParent = GetParent(hwEdit);
2087 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)child_edit_wmkeydown_proc);
2088 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2089 ok(1 == r, "expected 1, got %d\n", r);
2090 ok(0 == child_edit_wmkeydown_num_messages, "expected 0, got %d\n", child_edit_wmkeydown_num_messages);
2091 destroy_child_editcontrol(hwEdit);
2094 static int got_en_setfocus = 0;
2095 static int got_wm_capturechanged = 0;
2097 static LRESULT CALLBACK edit4_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2099 switch (msg) {
2100 case WM_COMMAND:
2101 switch (HIWORD(wParam)) {
2102 case EN_SETFOCUS:
2103 got_en_setfocus = 1;
2104 break;
2106 break;
2107 case WM_CAPTURECHANGED:
2108 if (hWnd != (HWND)lParam)
2110 got_wm_capturechanged = 1;
2111 pEndMenu();
2113 break;
2115 return DefWindowProcA(hWnd, msg, wParam, lParam);
2118 static void test_contextmenu_focus(void)
2120 HWND hwndMain, hwndEdit;
2122 hwndMain = CreateWindow(szEditTest4Class, "ET4", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
2123 0, 0, 200, 200, NULL, NULL, hinst, NULL);
2124 assert(hwndMain);
2126 hwndEdit = CreateWindow("EDIT", NULL,
2127 WS_CHILD|WS_BORDER|WS_VISIBLE|ES_LEFT|ES_AUTOHSCROLL,
2128 0, 0, 150, 50, /* important this not be 0 size. */
2129 hwndMain, (HMENU) ID_EDITTEST2, hinst, NULL);
2130 assert(hwndEdit);
2132 SetFocus(NULL);
2134 SetCapture(hwndMain);
2136 SendMessage(hwndEdit, WM_CONTEXTMENU, (WPARAM)hwndEdit, MAKEWORD(10, 10));
2138 ok(got_en_setfocus, "edit box didn't get focused\n");
2140 ok(got_wm_capturechanged, "main window capture did not change\n");
2142 DestroyWindow (hwndEdit);
2143 DestroyWindow (hwndMain);
2146 static BOOL RegisterWindowClasses (void)
2148 WNDCLASSA test2;
2149 WNDCLASSA test3;
2150 WNDCLASSA test4;
2151 WNDCLASSA text_position;
2153 test2.style = 0;
2154 test2.lpfnWndProc = ET2_WndProc;
2155 test2.cbClsExtra = 0;
2156 test2.cbWndExtra = 0;
2157 test2.hInstance = hinst;
2158 test2.hIcon = NULL;
2159 test2.hCursor = LoadCursorA (NULL, IDC_ARROW);
2160 test2.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2161 test2.lpszMenuName = NULL;
2162 test2.lpszClassName = szEditTest2Class;
2163 if (!RegisterClassA(&test2)) return FALSE;
2165 test3.style = 0;
2166 test3.lpfnWndProc = edit3_wnd_procA;
2167 test3.cbClsExtra = 0;
2168 test3.cbWndExtra = 0;
2169 test3.hInstance = hinst;
2170 test3.hIcon = 0;
2171 test3.hCursor = LoadCursorA(0, IDC_ARROW);
2172 test3.hbrBackground = GetStockObject(WHITE_BRUSH);
2173 test3.lpszMenuName = NULL;
2174 test3.lpszClassName = szEditTest3Class;
2175 if (!RegisterClassA(&test3)) return FALSE;
2177 test4.style = 0;
2178 test4.lpfnWndProc = edit4_wnd_procA;
2179 test4.cbClsExtra = 0;
2180 test4.cbWndExtra = 0;
2181 test4.hInstance = hinst;
2182 test4.hIcon = NULL;
2183 test4.hCursor = LoadCursorA (NULL, IDC_ARROW);
2184 test4.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2185 test4.lpszMenuName = NULL;
2186 test4.lpszClassName = szEditTest4Class;
2187 if (!RegisterClassA(&test4)) return FALSE;
2189 text_position.style = CS_HREDRAW | CS_VREDRAW;
2190 text_position.cbClsExtra = 0;
2191 text_position.cbWndExtra = 0;
2192 text_position.hInstance = hinst;
2193 text_position.hIcon = NULL;
2194 text_position.hCursor = LoadCursorA(NULL, IDC_ARROW);
2195 text_position.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2196 text_position.lpszMenuName = NULL;
2197 text_position.lpszClassName = szEditTextPositionClass;
2198 text_position.lpfnWndProc = DefWindowProc;
2199 if (!RegisterClassA(&text_position)) return FALSE;
2201 return TRUE;
2204 static void UnregisterWindowClasses (void)
2206 UnregisterClassA(szEditTest2Class, hinst);
2207 UnregisterClassA(szEditTest3Class, hinst);
2208 UnregisterClassA(szEditTest4Class, hinst);
2209 UnregisterClassA(szEditTextPositionClass, hinst);
2212 static void test_fontsize(void)
2214 HWND hwEdit;
2215 HFONT hfont;
2216 LOGFONT lf;
2217 LONG r;
2218 char szLocalString[MAXLEN];
2220 memset(&lf,0,sizeof(LOGFONTA));
2221 strcpy(lf.lfFaceName,"Arial");
2222 lf.lfHeight = -300; /* taller than the edit box */
2223 lf.lfWeight = 500;
2224 hfont = CreateFontIndirect(&lf);
2226 trace("EDIT: Oversized font (Multi line)\n");
2227 hwEdit= CreateWindow("EDIT", NULL, ES_MULTILINE|ES_AUTOHSCROLL,
2228 0, 0, 150, 50, NULL, NULL, hinst, NULL);
2230 SendMessage(hwEdit,WM_SETFONT,(WPARAM)hfont,0);
2232 if (winetest_interactive)
2233 ShowWindow (hwEdit, SW_SHOW);
2235 r = SendMessage(hwEdit, WM_CHAR, 'A', 1);
2236 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2237 r = SendMessage(hwEdit, WM_CHAR, 'B', 1);
2238 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2239 r = SendMessage(hwEdit, WM_CHAR, 'C', 1);
2240 ok(1 == r, "Expected: %d, got: %d\n", 1, r);
2242 GetWindowText(hwEdit, szLocalString, MAXLEN);
2243 ok(lstrcmp(szLocalString, "ABC")==0,
2244 "Wrong contents of edit: %s\n", szLocalString);
2246 r = SendMessage(hwEdit, EM_POSFROMCHAR,0,0);
2247 ok(r != -1,"EM_POSFROMCHAR failed index 0\n");
2248 r = SendMessage(hwEdit, EM_POSFROMCHAR,1,0);
2249 ok(r != -1,"EM_POSFROMCHAR failed index 1\n");
2250 r = SendMessage(hwEdit, EM_POSFROMCHAR,2,0);
2251 ok(r != -1,"EM_POSFROMCHAR failed index 2\n");
2252 r = SendMessage(hwEdit, EM_POSFROMCHAR,3,0);
2253 ok(r == -1,"EM_POSFROMCHAR succeeded index 3\n");
2255 DestroyWindow (hwEdit);
2256 DeleteObject(hfont);
2259 struct dialog_mode_messages
2261 int wm_getdefid, wm_close, wm_command, wm_nextdlgctl;
2264 static struct dialog_mode_messages dm_messages;
2266 static void zero_dm_messages(void)
2268 dm_messages.wm_command = 0;
2269 dm_messages.wm_close = 0;
2270 dm_messages.wm_getdefid = 0;
2271 dm_messages.wm_nextdlgctl = 0;
2274 #define test_dm_messages(wmcommand, wmclose, wmgetdefid, wmnextdlgctl) \
2275 ok(dm_messages.wm_command == wmcommand, "expected %d WM_COMMAND messages, " \
2276 "got %d\n", wmcommand, dm_messages.wm_command); \
2277 ok(dm_messages.wm_close == wmclose, "expected %d WM_CLOSE messages, " \
2278 "got %d\n", wmclose, dm_messages.wm_close); \
2279 ok(dm_messages.wm_getdefid == wmgetdefid, "expected %d WM_GETDIFID messages, " \
2280 "got %d\n", wmgetdefid, dm_messages.wm_getdefid);\
2281 ok(dm_messages.wm_nextdlgctl == wmnextdlgctl, "expected %d WM_NEXTDLGCTL messages, " \
2282 "got %d\n", wmnextdlgctl, dm_messages.wm_nextdlgctl)
2284 static LRESULT CALLBACK dialog_mode_wnd_proc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
2286 switch (iMsg)
2288 case WM_COMMAND:
2289 dm_messages.wm_command++;
2290 break;
2291 case DM_GETDEFID:
2292 dm_messages.wm_getdefid++;
2293 return MAKELONG(ID_EDITTESTDBUTTON, DC_HASDEFID);
2294 case WM_NEXTDLGCTL:
2295 dm_messages.wm_nextdlgctl++;
2296 break;
2297 case WM_CLOSE:
2298 dm_messages.wm_close++;
2299 break;
2302 return DefWindowProc(hwnd, iMsg, wParam, lParam);
2305 static void test_dialogmode(void)
2307 HWND hwEdit, hwParent, hwButton;
2308 MSG msg= {0};
2309 int len, r;
2310 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2312 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2313 ok(1 == r, "expected 1, got %d\n", r);
2314 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2315 ok(11 == len, "expected 11, got %d\n", len);
2317 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, 0);
2318 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2320 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2321 ok(1 == r, "expected 1, got %d\n", r);
2322 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2323 ok(13 == len, "expected 13, got %d\n", len);
2325 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
2326 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2327 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2328 ok(1 == r, "expected 1, got %d\n", r);
2329 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2330 ok(13 == len, "expected 13, got %d\n", len);
2332 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2333 ok(1 == r, "expected 1, got %d\n", r);
2334 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2335 ok(13 == len, "expected 13, got %d\n", len);
2337 destroy_child_editcontrol(hwEdit);
2339 hwEdit = create_editcontrol(ES_MULTILINE, 0);
2341 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2342 ok(1 == r, "expected 1, got %d\n", r);
2343 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2344 ok(11 == len, "expected 11, got %d\n", len);
2346 msg.hwnd = hwEdit;
2347 msg.message = WM_KEYDOWN;
2348 msg.wParam = VK_BACK;
2349 msg.lParam = 0xe0001;
2350 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_BACK, (LPARAM)&msg);
2351 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2353 r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0x1c0001);
2354 ok(1 == r, "expected 1, got %d\n", r);
2355 len = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0);
2356 ok(11 == len, "expected 11, got %d\n", len);
2358 DestroyWindow(hwEdit);
2360 hwEdit = create_child_editcontrol(0, 0);
2361 hwParent = GetParent(hwEdit);
2362 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2364 zero_dm_messages();
2365 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2366 ok(1 == r, "expected 1, got %d\n", r);
2367 test_dm_messages(0, 0, 0, 0);
2368 zero_dm_messages();
2370 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2371 ok(1 == r, "expected 1, got %d\n", r);
2372 test_dm_messages(0, 0, 0, 0);
2373 zero_dm_messages();
2375 msg.hwnd = hwEdit;
2376 msg.message = WM_KEYDOWN;
2377 msg.wParam = VK_TAB;
2378 msg.lParam = 0xf0001;
2379 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_TAB, (LPARAM)&msg);
2380 ok(0x89 == r, "expected 0x89, got 0x%x\n", r);
2381 test_dm_messages(0, 0, 0, 0);
2382 zero_dm_messages();
2384 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2385 ok(1 == r, "expected 1, got %d\n", r);
2386 test_dm_messages(0, 0, 0, 0);
2387 zero_dm_messages();
2389 destroy_child_editcontrol(hwEdit);
2391 hwEdit = create_child_editcontrol(ES_MULTILINE, 0);
2392 hwParent = GetParent(hwEdit);
2393 SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)dialog_mode_wnd_proc);
2395 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2396 ok(1 == r, "expected 1, got %d\n", r);
2397 test_dm_messages(0, 0, 0, 0);
2398 zero_dm_messages();
2400 msg.hwnd = hwEdit;
2401 msg.message = WM_KEYDOWN;
2402 msg.wParam = VK_ESCAPE;
2403 msg.lParam = 0x10001;
2404 r = SendMessage(hwEdit, WM_GETDLGCODE, VK_ESCAPE, (LPARAM)&msg);
2405 ok(0x8d == r, "expected 0x8d, got 0x%x\n", r);
2406 test_dm_messages(0, 0, 0, 0);
2407 zero_dm_messages();
2409 r = SendMessage(hwEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
2410 ok(1 == r, "expected 1, got %d\n", r);
2411 test_dm_messages(0, 0, 0, 0);
2412 zero_dm_messages();
2414 r = SendMessage(hwEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
2415 ok(1 == r, "expected 1, got %d\n", r);
2416 test_dm_messages(0, 0, 0, 1);
2417 zero_dm_messages();
2419 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2420 ok(1 == r, "expected 1, got %d\n", r);
2421 test_dm_messages(0, 0, 1, 0);
2422 zero_dm_messages();
2424 hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
2425 100, 100, 50, 20, hwParent, (HMENU)ID_EDITTESTDBUTTON, hinst, NULL);
2426 ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
2428 r = SendMessage(hwEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
2429 ok(1 == r, "expected 1, got %d\n", r);
2430 test_dm_messages(0, 0, 1, 1);
2431 zero_dm_messages();
2433 DestroyWindow(hwButton);
2434 destroy_child_editcontrol(hwEdit);
2437 START_TEST(edit)
2439 init_function_pointers();
2441 hinst = GetModuleHandleA(NULL);
2442 assert(RegisterWindowClasses());
2444 test_edit_control_1();
2445 test_edit_control_2();
2446 test_edit_control_3();
2447 test_edit_control_4();
2448 test_edit_control_5();
2449 test_edit_control_6();
2450 test_edit_control_limittext();
2451 test_edit_control_scroll();
2452 test_margins();
2453 test_margins_font_change();
2454 test_text_position();
2455 test_espassword();
2456 test_undo();
2457 test_enter();
2458 test_tab();
2459 test_edit_dialog();
2460 test_multi_edit_dialog();
2461 test_wantreturn_edit_dialog();
2462 test_singleline_wantreturn_edit_dialog();
2463 test_child_edit_wmkeydown();
2464 test_fontsize();
2465 test_dialogmode();
2466 if (pEndMenu)
2467 test_contextmenu_focus();
2468 else
2469 win_skip("EndMenu is not available\n");
2471 UnregisterWindowClasses();