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