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