2 * Unit test suite for rich edit control
4 * Copyright 2006 Google (Thomas Kho)
5 * Copyright 2007 Matt Finnicum
6 * Copyright 2007 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include <wine/test.h>
36 static CHAR string1
[MAX_PATH
], string2
[MAX_PATH
], string3
[MAX_PATH
];
38 #define ok_w3(format, szString1, szString2, szString3) \
39 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
40 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
41 WideCharToMultiByte(CP_ACP, 0, szString3, -1, string3, MAX_PATH, NULL, NULL); \
42 ok(!lstrcmpW(szString3, szString1) || !lstrcmpW(szString3, szString2), \
43 format, string1, string2, string3);
45 static HMODULE hmoduleRichEdit
;
47 static int is_win9x
= 0;
49 static HWND
new_window(LPCTSTR lpClassName
, DWORD dwStyle
, HWND parent
) {
51 hwnd
= CreateWindow(lpClassName
, NULL
, dwStyle
|WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
52 |WS_VISIBLE
, 0, 0, 200, 60, parent
, NULL
,
53 hmoduleRichEdit
, NULL
);
54 ok(hwnd
!= NULL
, "class: %s, error: %d\n", lpClassName
, (int) GetLastError());
58 static HWND
new_richedit(HWND parent
) {
59 return new_window(RICHEDIT_CLASS
, ES_MULTILINE
, parent
);
62 /* Keeps the window reponsive for the deley_time in seconds.
63 * This is useful for debugging a test to see what is happening. */
64 static void keep_responsive(time_t delay_time
)
69 /* The message pump uses PeekMessage() to empty the queue and then
70 * sleeps for 50ms before retrying the queue. */
71 end
= time(NULL
) + delay_time
;
72 while (time(NULL
) < end
) {
73 if (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
74 TranslateMessage(&msg
);
75 DispatchMessage(&msg
);
82 static void processPendingMessages(void)
85 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
86 TranslateMessage(&msg
);
87 DispatchMessage(&msg
);
91 static void pressKeyWithModifier(HWND hwnd
, BYTE mod_vk
, BYTE vk
)
93 BYTE mod_scan_code
= MapVirtualKey(mod_vk
, MAPVK_VK_TO_VSC
);
94 BYTE scan_code
= MapVirtualKey(vk
, MAPVK_VK_TO_VSC
);
96 keybd_event(mod_vk
, mod_scan_code
, 0, 0);
97 keybd_event(vk
, scan_code
, 0, 0);
98 keybd_event(vk
, scan_code
, KEYEVENTF_KEYUP
, 0);
99 keybd_event(mod_vk
, mod_scan_code
, KEYEVENTF_KEYUP
, 0);
100 processPendingMessages();
103 static void simulate_typing_characters(HWND hwnd
, const char* szChars
)
107 while (*szChars
!= '\0') {
108 SendMessageA(hwnd
, WM_KEYDOWN
, *szChars
, 1);
109 ret
= SendMessageA(hwnd
, WM_CHAR
, *szChars
, 1);
110 ok(ret
== 0, "WM_CHAR('%c') ret=%d\n", *szChars
, ret
);
111 SendMessageA(hwnd
, WM_KEYUP
, *szChars
, 1);
116 static BOOL
hold_key(int vk
)
121 result
= GetKeyboardState(key_state
);
122 ok(result
, "GetKeyboardState failed.\n");
123 if (!result
) return FALSE
;
124 key_state
[vk
] |= 0x80;
125 result
= SetKeyboardState(key_state
);
126 ok(result
, "SetKeyboardState failed.\n");
130 static BOOL
release_key(int vk
)
135 result
= GetKeyboardState(key_state
);
136 ok(result
, "GetKeyboardState failed.\n");
137 if (!result
) return FALSE
;
138 key_state
[vk
] &= ~0x80;
139 result
= SetKeyboardState(key_state
);
140 ok(result
, "SetKeyboardState failed.\n");
144 static const char haystack
[] = "WINEWine wineWine wine WineWine";
156 struct find_s find_tests
[] = {
157 /* Find in empty text */
158 {0, -1, "foo", FR_DOWN
, -1},
159 {0, -1, "foo", 0, -1},
160 {0, -1, "", FR_DOWN
, -1},
161 {20, 5, "foo", FR_DOWN
, -1},
162 {5, 20, "foo", FR_DOWN
, -1}
165 struct find_s find_tests2
[] = {
167 {0, -1, "foo", FR_DOWN
| FR_MATCHCASE
, -1},
168 {5, 20, "WINE", FR_DOWN
| FR_MATCHCASE
, -1},
170 /* Subsequent finds */
171 {0, -1, "Wine", FR_DOWN
| FR_MATCHCASE
, 4},
172 {5, 31, "Wine", FR_DOWN
| FR_MATCHCASE
, 13},
173 {14, 31, "Wine", FR_DOWN
| FR_MATCHCASE
, 23},
174 {24, 31, "Wine", FR_DOWN
| FR_MATCHCASE
, 27},
177 {19, 20, "Wine", FR_MATCHCASE
, 13},
178 {10, 20, "Wine", FR_MATCHCASE
, 4},
179 {20, 10, "Wine", FR_MATCHCASE
, 13},
181 /* Case-insensitive */
182 {1, 31, "wInE", FR_DOWN
, 4},
183 {1, 31, "Wine", FR_DOWN
, 4},
185 /* High-to-low ranges */
186 {20, 5, "Wine", FR_DOWN
, -1},
187 {2, 1, "Wine", FR_DOWN
, -1},
188 {30, 29, "Wine", FR_DOWN
, -1},
189 {20, 5, "Wine", 0, 13},
192 {5, 10, "", FR_DOWN
, -1},
193 {10, 5, "", FR_DOWN
, -1},
194 {0, -1, "", FR_DOWN
, -1},
197 /* Whole-word search */
198 {0, -1, "wine", FR_DOWN
| FR_WHOLEWORD
, 18},
199 {0, -1, "win", FR_DOWN
| FR_WHOLEWORD
, -1},
200 {13, -1, "wine", FR_DOWN
| FR_WHOLEWORD
, 18},
201 {0, -1, "winewine", FR_DOWN
| FR_WHOLEWORD
, 0},
202 {10, -1, "winewine", FR_DOWN
| FR_WHOLEWORD
, 23},
203 {11, -1, "winewine", FR_WHOLEWORD
, 0},
204 {31, -1, "winewine", FR_WHOLEWORD
, 23},
207 {5, 200, "XXX", FR_DOWN
, -1},
208 {-20, 20, "Wine", FR_DOWN
, -1},
209 {-20, 20, "Wine", FR_DOWN
, -1},
210 {-15, -20, "Wine", FR_DOWN
, -1},
211 {1<<12, 1<<13, "Wine", FR_DOWN
, -1},
213 /* Check the case noted in bug 4479 where matches at end aren't recognized */
214 {23, 31, "Wine", FR_DOWN
| FR_MATCHCASE
, 23},
215 {27, 31, "Wine", FR_DOWN
| FR_MATCHCASE
, 27},
216 {27, 32, "Wine", FR_DOWN
| FR_MATCHCASE
, 27},
217 {13, 31, "WineWine", FR_DOWN
| FR_MATCHCASE
, 23},
218 {13, 32, "WineWine", FR_DOWN
| FR_MATCHCASE
, 23},
220 /* The backwards case of bug 4479; bounds look right
221 * Fails because backward find is wrong */
222 {19, 20, "WINE", FR_MATCHCASE
, 0},
223 {0, 20, "WINE", FR_MATCHCASE
, -1},
225 {0, -1, "wineWine wine", 0, -1},
228 static void check_EM_FINDTEXT(HWND hwnd
, const char *name
, struct find_s
*f
, int id
) {
231 memset(&ft
, 0, sizeof(ft
));
232 ft
.chrg
.cpMin
= f
->start
;
233 ft
.chrg
.cpMax
= f
->end
;
234 ft
.lpstrText
= f
->needle
;
235 findloc
= SendMessage(hwnd
, EM_FINDTEXT
, f
->flags
, (LPARAM
) &ft
);
236 ok(findloc
== f
->expected_loc
,
237 "EM_FINDTEXT(%s,%d) '%s' in range(%d,%d), flags %08x, got start at %d, expected %d\n",
238 name
, id
, f
->needle
, f
->start
, f
->end
, f
->flags
, findloc
, f
->expected_loc
);
241 static void check_EM_FINDTEXTEX(HWND hwnd
, const char *name
, struct find_s
*f
,
245 int expected_end_loc
;
247 memset(&ft
, 0, sizeof(ft
));
248 ft
.chrg
.cpMin
= f
->start
;
249 ft
.chrg
.cpMax
= f
->end
;
250 ft
.lpstrText
= f
->needle
;
251 findloc
= SendMessage(hwnd
, EM_FINDTEXTEX
, f
->flags
, (LPARAM
) &ft
);
252 ok(findloc
== f
->expected_loc
,
253 "EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, start at %d\n",
254 name
, id
, f
->needle
, f
->start
, f
->end
, f
->flags
, findloc
);
255 ok(ft
.chrgText
.cpMin
== f
->expected_loc
,
256 "EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, start at %d\n",
257 name
, id
, f
->needle
, f
->start
, f
->end
, f
->flags
, ft
.chrgText
.cpMin
);
258 expected_end_loc
= ((f
->expected_loc
== -1) ? -1
259 : f
->expected_loc
+ strlen(f
->needle
));
260 ok(ft
.chrgText
.cpMax
== expected_end_loc
,
261 "EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, end at %d, expected %d\n",
262 name
, id
, f
->needle
, f
->start
, f
->end
, f
->flags
, ft
.chrgText
.cpMax
, expected_end_loc
);
265 static void run_tests_EM_FINDTEXT(HWND hwnd
, const char *name
, struct find_s
*find
,
270 for (i
= 0; i
< num_tests
; i
++) {
271 check_EM_FINDTEXT(hwnd
, name
, &find
[i
], i
);
272 check_EM_FINDTEXTEX(hwnd
, name
, &find
[i
], i
);
276 static void test_EM_FINDTEXT(void)
278 HWND hwndRichEdit
= new_richedit(NULL
);
281 /* Empty rich edit control */
282 run_tests_EM_FINDTEXT(hwndRichEdit
, "1", find_tests
,
283 sizeof(find_tests
)/sizeof(struct find_s
));
285 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) haystack
);
288 run_tests_EM_FINDTEXT(hwndRichEdit
, "2", find_tests2
,
289 sizeof(find_tests2
)/sizeof(struct find_s
));
291 /* Setting a format on an arbitrary range should have no effect in search
292 results. This tests correct offset reporting across runs. */
293 cf2
.cbSize
= sizeof(CHARFORMAT2
);
294 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
296 cf2
.dwMask
= CFM_ITALIC
| cf2
.dwMask
;
297 cf2
.dwEffects
= CFE_ITALIC
^ cf2
.dwEffects
;
298 SendMessage(hwndRichEdit
, EM_SETSEL
, 6, 20);
299 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
301 /* Haystack text, again */
302 run_tests_EM_FINDTEXT(hwndRichEdit
, "2-bis", find_tests2
,
303 sizeof(find_tests2
)/sizeof(struct find_s
));
305 /* Yet another range */
306 cf2
.dwMask
= CFM_BOLD
| cf2
.dwMask
;
307 cf2
.dwEffects
= CFE_BOLD
^ cf2
.dwEffects
;
308 SendMessage(hwndRichEdit
, EM_SETSEL
, 11, 15);
309 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
311 /* Haystack text, again */
312 run_tests_EM_FINDTEXT(hwndRichEdit
, "2-bisbis", find_tests2
,
313 sizeof(find_tests2
)/sizeof(struct find_s
));
315 DestroyWindow(hwndRichEdit
);
318 static const struct getline_s
{
323 {0, 10, "foo bar\r"},
328 /* Buffer smaller than line length */
334 static void test_EM_GETLINE(void)
337 HWND hwndRichEdit
= new_richedit(NULL
);
338 static const int nBuf
= 1024;
339 char dest
[1024], origdest
[1024];
340 const char text
[] = "foo bar\n"
344 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
346 memset(origdest
, 0xBB, nBuf
);
347 for (i
= 0; i
< sizeof(gl
)/sizeof(struct getline_s
); i
++)
350 int expected_nCopied
= min(gl
[i
].buffer_len
, strlen(gl
[i
].text
));
351 int expected_bytes_written
= min(gl
[i
].buffer_len
, strlen(gl
[i
].text
));
352 memset(dest
, 0xBB, nBuf
);
353 *(WORD
*) dest
= gl
[i
].buffer_len
;
355 /* EM_GETLINE appends a "\r\0" to the end of the line
356 * nCopied counts up to and including the '\r' */
357 nCopied
= SendMessage(hwndRichEdit
, EM_GETLINE
, gl
[i
].line
, (LPARAM
) dest
);
358 ok(nCopied
== expected_nCopied
, "%d: %d!=%d\n", i
, nCopied
,
360 /* two special cases since a parameter is passed via dest */
361 if (gl
[i
].buffer_len
== 0)
362 ok(!dest
[0] && !dest
[1] && !strncmp(dest
+2, origdest
+2, nBuf
-2),
364 else if (gl
[i
].buffer_len
== 1)
365 ok(dest
[0] == gl
[i
].text
[0] && !dest
[1] &&
366 !strncmp(dest
+2, origdest
+2, nBuf
-2), "buffer_len=1\n");
369 /* Prepare hex strings of buffers to dump on failure. */
370 char expectedbuf
[1024];
371 char resultbuf
[1024];
374 for (j
= 0; j
< 32; j
++)
375 sprintf(resultbuf
+strlen(resultbuf
), "%02x", dest
[j
] & 0xFF);
376 expectedbuf
[0] = '\0';
377 for (j
= 0; j
< expected_bytes_written
; j
++) /* Written bytes */
378 sprintf(expectedbuf
+strlen(expectedbuf
), "%02x", gl
[i
].text
[j
] & 0xFF);
379 for (; j
< gl
[i
].buffer_len
; j
++) /* Ignored bytes */
380 sprintf(expectedbuf
+strlen(expectedbuf
), "??");
381 for (; j
< 32; j
++) /* Bytes after declared buffer size */
382 sprintf(expectedbuf
+strlen(expectedbuf
), "%02x", origdest
[j
] & 0xFF);
384 /* Test the part of the buffer that is expected to be written according
385 * to the MSDN documentation fo EM_GETLINE, which does not state that
386 * a NULL terminating character will be added unless no text is copied.
388 * Windows 95, 98 & NT do not append a NULL terminating character, but
389 * Windows 2000 and up do append a NULL terminating character if there
390 * is space in the buffer. The test will ignore this difference. */
391 ok(!strncmp(dest
, gl
[i
].text
, expected_bytes_written
),
392 "%d: expected_bytes_written=%d\n" "expected=0x%s\n" "but got= 0x%s\n",
393 i
, expected_bytes_written
, expectedbuf
, resultbuf
);
394 /* Test the part of the buffer after the declared length to make sure
395 * there are no buffer overruns. */
396 ok(!strncmp(dest
+ gl
[i
].buffer_len
, origdest
+ gl
[i
].buffer_len
,
397 nBuf
- gl
[i
].buffer_len
),
398 "%d: expected_bytes_written=%d\n" "expected=0x%s\n" "but got= 0x%s\n",
399 i
, expected_bytes_written
, expectedbuf
, resultbuf
);
403 DestroyWindow(hwndRichEdit
);
406 static void test_EM_LINELENGTH(void)
408 HWND hwndRichEdit
= new_richedit(NULL
);
414 int offset_test
[10][2] = {
429 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
431 for (i
= 0; i
< 10; i
++) {
432 result
= SendMessage(hwndRichEdit
, EM_LINELENGTH
, offset_test
[i
][0], 0);
433 ok(result
== offset_test
[i
][1], "Length of line at offset %d is %ld, expected %d\n",
434 offset_test
[i
][0], result
, offset_test
[i
][1]);
437 DestroyWindow(hwndRichEdit
);
440 static int get_scroll_pos_y(HWND hwnd
)
443 SendMessage(hwnd
, EM_GETSCROLLPOS
, 0, (LPARAM
) &p
);
444 ok(p
.x
!= -1 && p
.y
!= -1, "p.x:%d p.y:%d\n", p
.x
, p
.y
);
448 static void move_cursor(HWND hwnd
, LONG charindex
)
451 cr
.cpMax
= charindex
;
452 cr
.cpMin
= charindex
;
453 SendMessage(hwnd
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
456 static void line_scroll(HWND hwnd
, int amount
)
458 SendMessage(hwnd
, EM_LINESCROLL
, 0, amount
);
461 static void test_EM_SCROLLCARET(void)
464 const char text
[] = "aa\n"
465 "this is a long line of text that should be longer than the "
473 /* The richedit window height needs to be large enough vertically to fit in
474 * more than two lines of text, so the new_richedit function can't be used
475 * since a height of 60 was not large enough on some systems.
477 HWND hwndRichEdit
= CreateWindow(RICHEDIT_CLASS
, NULL
,
478 ES_MULTILINE
|WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
|WS_VISIBLE
,
479 0, 0, 200, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
480 ok(hwndRichEdit
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
482 /* Can't verify this */
483 SendMessage(hwndRichEdit
, EM_SCROLLCARET
, 0, 0);
485 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
487 /* Caret above visible window */
488 line_scroll(hwndRichEdit
, 3);
489 prevY
= get_scroll_pos_y(hwndRichEdit
);
490 SendMessage(hwndRichEdit
, EM_SCROLLCARET
, 0, 0);
491 curY
= get_scroll_pos_y(hwndRichEdit
);
492 ok(prevY
!= curY
, "%d == %d\n", prevY
, curY
);
494 /* Caret below visible window */
495 move_cursor(hwndRichEdit
, sizeof(text
) - 1);
496 line_scroll(hwndRichEdit
, -3);
497 prevY
= get_scroll_pos_y(hwndRichEdit
);
498 SendMessage(hwndRichEdit
, EM_SCROLLCARET
, 0, 0);
499 curY
= get_scroll_pos_y(hwndRichEdit
);
500 ok(prevY
!= curY
, "%d == %d\n", prevY
, curY
);
502 /* Caret in visible window */
503 move_cursor(hwndRichEdit
, sizeof(text
) - 2);
504 prevY
= get_scroll_pos_y(hwndRichEdit
);
505 SendMessage(hwndRichEdit
, EM_SCROLLCARET
, 0, 0);
506 curY
= get_scroll_pos_y(hwndRichEdit
);
507 ok(prevY
== curY
, "%d != %d\n", prevY
, curY
);
509 /* Caret still in visible window */
510 line_scroll(hwndRichEdit
, -1);
511 prevY
= get_scroll_pos_y(hwndRichEdit
);
512 SendMessage(hwndRichEdit
, EM_SCROLLCARET
, 0, 0);
513 curY
= get_scroll_pos_y(hwndRichEdit
);
514 ok(prevY
== curY
, "%d != %d\n", prevY
, curY
);
516 DestroyWindow(hwndRichEdit
);
519 static void test_EM_POSFROMCHAR(void)
521 HWND hwndRichEdit
= new_richedit(NULL
);
524 unsigned int height
= 0;
527 static const char text
[] = "aa\n"
528 "this is a long line of text that should be longer than the "
537 /* Fill the control to lines to ensure that most of them are offscreen */
538 for (i
= 0; i
< 50; i
++)
540 /* Do not modify the string; it is exactly 16 characters long. */
541 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 0);
542 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)"0123456789ABCDE\n");
546 Richedit 1.0 receives a POINTL* on wParam and character offset on lParam, returns void.
547 Richedit 2.0 receives character offset on wParam, ignores lParam, returns MAKELONG(x,y)
548 Richedit 3.0 accepts either of the above API conventions.
551 /* Testing Richedit 2.0 API format */
553 /* Testing start of lines. X-offset should be constant on all cases (native is 1).
554 Since all lines are identical and drawn with the same font,
555 they should have the same height... right?
557 for (i
= 0; i
< 50; i
++)
559 /* All the lines are 16 characters long */
560 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, i
* 16, 0);
563 ok(HIWORD(result
) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result
));
564 ok(LOWORD(result
) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
565 xpos
= LOWORD(result
);
569 ok(HIWORD(result
) > 0, "EM_POSFROMCHAR reports y=%d, expected > 0\n", HIWORD(result
));
570 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
571 height
= HIWORD(result
);
575 ok(HIWORD(result
) == i
* height
, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result
), i
* height
);
576 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
580 /* Testing position at end of text */
581 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 50 * 16, 0);
582 ok(HIWORD(result
) == 50 * height
, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result
), 50 * height
);
583 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
585 /* Testing position way past end of text */
586 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 55 * 16, 0);
587 ok(HIWORD(result
) == 50 * height
, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result
), 50 * height
);
588 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
590 /* Testing that vertical scrolling does, in fact, have an effect on EM_POSFROMCHAR */
591 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEDOWN
, 0); /* line down */
592 for (i
= 0; i
< 50; i
++)
594 /* All the lines are 16 characters long */
595 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, i
* 16, 0);
596 ok((signed short)(HIWORD(result
)) == (i
- 1) * height
,
597 "EM_POSFROMCHAR reports y=%hd, expected %d\n",
598 (signed short)(HIWORD(result
)), (i
- 1) * height
);
599 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
602 /* Testing position at end of text */
603 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 50 * 16, 0);
604 ok(HIWORD(result
) == (50 - 1) * height
, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result
), (50 - 1) * height
);
605 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
607 /* Testing position way past end of text */
608 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 55 * 16, 0);
609 ok(HIWORD(result
) == (50 - 1) * height
, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result
), (50 - 1) * height
);
610 ok(LOWORD(result
) == xpos
, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
612 /* Testing that horizontal scrolling does, in fact, have an effect on EM_POSFROMCHAR */
613 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
614 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEUP
, 0); /* line up */
616 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 0, 0);
617 ok(HIWORD(result
) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result
));
618 ok(LOWORD(result
) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result
));
619 xpos
= LOWORD(result
);
621 SendMessage(hwndRichEdit
, WM_HSCROLL
, SB_LINERIGHT
, 0);
622 result
= SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, 0, 0);
623 ok(HIWORD(result
) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result
));
624 ok((signed short)(LOWORD(result
)) < xpos
,
625 "EM_POSFROMCHAR reports x=%hd, expected value less than %d\n",
626 (signed short)(LOWORD(result
)), xpos
);
627 SendMessage(hwndRichEdit
, WM_HSCROLL
, SB_LINELEFT
, 0);
629 /* Test around end of text that doesn't end in a newline. */
630 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "12345678901234");
631 SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, (WPARAM
)&pt
,
632 SendMessage(hwndRichEdit
, WM_GETTEXTLENGTH
, 0, 0)-1);
633 ok(pt
.x
> 1, "pt.x = %d\n", pt
.x
);
635 SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, (WPARAM
)&pt
,
636 SendMessage(hwndRichEdit
, WM_GETTEXTLENGTH
, 0, 0));
637 ok(pt
.x
> xpos
, "pt.x = %d\n", pt
.x
);
639 SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, (WPARAM
)&pt
,
640 SendMessage(hwndRichEdit
, WM_GETTEXTLENGTH
, 0, 0)+1);
641 ok(pt
.x
== xpos
, "pt.x = %d\n", pt
.x
);
643 /* Try a negative position. */
644 SendMessage(hwndRichEdit
, EM_POSFROMCHAR
, (WPARAM
)&pt
, -1);
645 ok(pt
.x
== 1, "pt.x = %d\n", pt
.x
);
647 DestroyWindow(hwndRichEdit
);
650 static void test_EM_SETCHARFORMAT(void)
652 HWND hwndRichEdit
= new_richedit(NULL
);
655 int tested_effects
[] = {
669 /* Invalid flags, CHARFORMAT2 structure blanked out */
670 memset(&cf2
, 0, sizeof(cf2
));
671 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) 0xfffffff0,
673 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
675 /* A valid flag, CHARFORMAT2 structure blanked out */
676 memset(&cf2
, 0, sizeof(cf2
));
677 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
679 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
681 /* A valid flag, CHARFORMAT2 structure blanked out */
682 memset(&cf2
, 0, sizeof(cf2
));
683 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
685 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
687 /* A valid flag, CHARFORMAT2 structure blanked out */
688 memset(&cf2
, 0, sizeof(cf2
));
689 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_WORD
,
691 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
693 /* A valid flag, CHARFORMAT2 structure blanked out */
694 memset(&cf2
, 0, sizeof(cf2
));
695 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
,
697 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
699 /* Invalid flags, CHARFORMAT2 structure minimally filled */
700 memset(&cf2
, 0, sizeof(cf2
));
701 cf2
.cbSize
= sizeof(CHARFORMAT2
);
702 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) 0xfffffff0,
704 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
705 rc
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
706 ok(rc
== FALSE
, "Should not be able to undo here.\n");
707 SendMessage(hwndRichEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
709 /* A valid flag, CHARFORMAT2 structure minimally filled */
710 memset(&cf2
, 0, sizeof(cf2
));
711 cf2
.cbSize
= sizeof(CHARFORMAT2
);
712 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
714 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
715 rc
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
716 ok(rc
== FALSE
, "Should not be able to undo here.\n");
717 SendMessage(hwndRichEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
719 /* A valid flag, CHARFORMAT2 structure minimally filled */
720 memset(&cf2
, 0, sizeof(cf2
));
721 cf2
.cbSize
= sizeof(CHARFORMAT2
);
722 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
724 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
725 rc
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
726 ok(rc
== FALSE
, "Should not be able to undo here.\n");
727 SendMessage(hwndRichEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
729 /* A valid flag, CHARFORMAT2 structure minimally filled */
730 memset(&cf2
, 0, sizeof(cf2
));
731 cf2
.cbSize
= sizeof(CHARFORMAT2
);
732 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_WORD
,
734 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
735 rc
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
736 todo_wine
ok(rc
== TRUE
, "Should not be able to undo here.\n");
737 SendMessage(hwndRichEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
739 /* A valid flag, CHARFORMAT2 structure minimally filled */
740 memset(&cf2
, 0, sizeof(cf2
));
741 cf2
.cbSize
= sizeof(CHARFORMAT2
);
742 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
,
744 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
745 rc
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
746 todo_wine
ok(rc
== TRUE
, "Should not be able to undo here.\n");
747 SendMessage(hwndRichEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
749 cf2
.cbSize
= sizeof(CHARFORMAT2
);
750 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
753 /* Test state of modify flag before and after valid EM_SETCHARFORMAT */
754 cf2
.cbSize
= sizeof(CHARFORMAT2
);
755 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
757 cf2
.dwMask
= CFM_ITALIC
| cf2
.dwMask
;
758 cf2
.dwEffects
= CFE_ITALIC
^ cf2
.dwEffects
;
760 /* wParam==0 is default char format, does not set modify */
761 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
762 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
763 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
764 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, 0, (LPARAM
) &cf2
);
765 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
766 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
767 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
769 /* wParam==SCF_SELECTION sets modify if nonempty selection */
770 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
771 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
772 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
773 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
774 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
775 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
776 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
778 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
779 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
780 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
781 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
782 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
783 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
784 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
785 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
786 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
787 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
788 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
789 ok(rc
== -1, "Text not marked as modified, expected modified! (%d)\n", rc
);
791 /* wParam==SCF_ALL sets modify regardless of whether text is present */
792 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
793 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
794 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
795 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
796 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
797 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
798 ok(rc
== -1, "Text not marked as modified, expected modified! (%d)\n", rc
);
800 DestroyWindow(hwndRichEdit
);
802 /* EM_GETCHARFORMAT tests */
803 for (i
= 0; tested_effects
[i
]; i
++)
805 hwndRichEdit
= new_richedit(NULL
);
806 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
808 /* Need to set a TrueType font to get consistent CFM_BOLD results */
809 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
810 cf2
.cbSize
= sizeof(CHARFORMAT2
);
811 cf2
.dwMask
= CFM_FACE
|CFM_WEIGHT
;
813 strcpy(cf2
.szFaceName
, "Courier New");
814 cf2
.wWeight
= FW_DONTCARE
;
815 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
) &cf2
);
817 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
818 cf2
.cbSize
= sizeof(CHARFORMAT2
);
819 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 4);
820 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
821 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
822 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == CFM_SUPERSCRIPT
)
824 (cf2
.dwMask
& tested_effects
[i
]) == tested_effects
[i
]),
825 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, tested_effects
[i
]);
826 ok((cf2
.dwEffects
& tested_effects
[i
]) == 0,
827 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
829 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
830 cf2
.cbSize
= sizeof(CHARFORMAT2
);
831 cf2
.dwMask
= tested_effects
[i
];
832 if (cf2
.dwMask
== CFE_SUBSCRIPT
|| cf2
.dwMask
== CFE_SUPERSCRIPT
)
833 cf2
.dwMask
= CFM_SUPERSCRIPT
;
834 cf2
.dwEffects
= tested_effects
[i
];
835 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
836 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
838 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
839 cf2
.cbSize
= sizeof(CHARFORMAT2
);
840 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
841 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
842 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
843 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == CFM_SUPERSCRIPT
)
845 (cf2
.dwMask
& tested_effects
[i
]) == tested_effects
[i
]),
846 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, tested_effects
[i
]);
847 ok((cf2
.dwEffects
& tested_effects
[i
]) == tested_effects
[i
],
848 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
850 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
851 cf2
.cbSize
= sizeof(CHARFORMAT2
);
852 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 4);
853 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
854 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
855 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == CFM_SUPERSCRIPT
)
857 (cf2
.dwMask
& tested_effects
[i
]) == tested_effects
[i
]),
858 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, tested_effects
[i
]);
859 ok((cf2
.dwEffects
& tested_effects
[i
]) == 0,
860 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
862 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
863 cf2
.cbSize
= sizeof(CHARFORMAT2
);
864 SendMessage(hwndRichEdit
, EM_SETSEL
, 1, 3);
865 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
866 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
867 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == 0)
869 (cf2
.dwMask
& tested_effects
[i
]) == 0),
870 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i
, cf2
.dwMask
, tested_effects
[i
]);
872 DestroyWindow(hwndRichEdit
);
875 for (i
= 0; tested_effects
[i
]; i
++)
877 hwndRichEdit
= new_richedit(NULL
);
878 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
880 /* Need to set a TrueType font to get consistent CFM_BOLD results */
881 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
882 cf2
.cbSize
= sizeof(CHARFORMAT2
);
883 cf2
.dwMask
= CFM_FACE
|CFM_WEIGHT
;
885 strcpy(cf2
.szFaceName
, "Courier New");
886 cf2
.wWeight
= FW_DONTCARE
;
887 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
) &cf2
);
889 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
890 cf2
.cbSize
= sizeof(CHARFORMAT2
);
891 cf2
.dwMask
= tested_effects
[i
];
892 if (cf2
.dwMask
== CFE_SUBSCRIPT
|| cf2
.dwMask
== CFE_SUPERSCRIPT
)
893 cf2
.dwMask
= CFM_SUPERSCRIPT
;
894 cf2
.dwEffects
= tested_effects
[i
];
895 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 4);
896 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
898 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
899 cf2
.cbSize
= sizeof(CHARFORMAT2
);
900 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
901 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
902 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
903 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == CFM_SUPERSCRIPT
)
905 (cf2
.dwMask
& tested_effects
[i
]) == tested_effects
[i
]),
906 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, tested_effects
[i
]);
907 ok((cf2
.dwEffects
& tested_effects
[i
]) == 0,
908 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
910 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
911 cf2
.cbSize
= sizeof(CHARFORMAT2
);
912 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 4);
913 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
914 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
915 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == CFM_SUPERSCRIPT
)
917 (cf2
.dwMask
& tested_effects
[i
]) == tested_effects
[i
]),
918 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, tested_effects
[i
]);
919 ok((cf2
.dwEffects
& tested_effects
[i
]) == tested_effects
[i
],
920 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
922 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
923 cf2
.cbSize
= sizeof(CHARFORMAT2
);
924 SendMessage(hwndRichEdit
, EM_SETSEL
, 1, 3);
925 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
926 ok ((((tested_effects
[i
] == CFE_SUBSCRIPT
|| tested_effects
[i
] == CFE_SUPERSCRIPT
) &&
927 (cf2
.dwMask
& CFM_SUPERSCRIPT
) == 0)
929 (cf2
.dwMask
& tested_effects
[i
]) == 0),
930 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i
, cf2
.dwMask
, tested_effects
[i
]);
931 ok((cf2
.dwEffects
& tested_effects
[i
]) == tested_effects
[i
],
932 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x set\n", i
, cf2
.dwEffects
, tested_effects
[i
]);
934 DestroyWindow(hwndRichEdit
);
937 /* Effects applied on an empty selection should take effect when selection is
938 replaced with text */
939 hwndRichEdit
= new_richedit(NULL
);
940 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
941 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 2); /* Empty selection */
943 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
944 cf2
.cbSize
= sizeof(CHARFORMAT2
);
945 cf2
.dwMask
= CFM_BOLD
;
946 cf2
.dwEffects
= CFE_BOLD
;
947 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
949 /* Selection is now nonempty */
950 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)"newi");
952 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
953 cf2
.cbSize
= sizeof(CHARFORMAT2
);
954 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 6);
955 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
957 ok (((cf2
.dwMask
& CFM_BOLD
) == CFM_BOLD
),
958 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, CFM_BOLD
);
959 ok((cf2
.dwEffects
& CFE_BOLD
) == CFE_BOLD
,
960 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, CFE_BOLD
);
963 /* Set two effects on an empty selection */
964 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
965 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 2); /* Empty selection */
967 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
968 cf2
.cbSize
= sizeof(CHARFORMAT2
);
969 cf2
.dwMask
= CFM_BOLD
;
970 cf2
.dwEffects
= CFE_BOLD
;
971 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
972 cf2
.dwMask
= CFM_ITALIC
;
973 cf2
.dwEffects
= CFE_ITALIC
;
974 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
976 /* Selection is now nonempty */
977 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)"newi");
979 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
980 cf2
.cbSize
= sizeof(CHARFORMAT2
);
981 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 6);
982 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
984 ok (((cf2
.dwMask
& (CFM_BOLD
|CFM_ITALIC
)) == (CFM_BOLD
|CFM_ITALIC
)),
985 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, (CFM_BOLD
|CFM_ITALIC
));
986 ok((cf2
.dwEffects
& (CFE_BOLD
|CFE_ITALIC
)) == (CFE_BOLD
|CFE_ITALIC
),
987 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, (CFE_BOLD
|CFE_ITALIC
));
989 /* Setting the (empty) selection to exactly the same place as before should
990 NOT clear the insertion style! */
991 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
992 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 2); /* Empty selection */
994 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
995 cf2
.cbSize
= sizeof(CHARFORMAT2
);
996 cf2
.dwMask
= CFM_BOLD
;
997 cf2
.dwEffects
= CFE_BOLD
;
998 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
1000 /* Empty selection in same place, insert style should NOT be forgotten here. */
1001 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 2);
1003 /* Selection is now nonempty */
1004 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)"newi");
1006 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
1007 cf2
.cbSize
= sizeof(CHARFORMAT2
);
1008 SendMessage(hwndRichEdit
, EM_SETSEL
, 2, 6);
1009 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
1011 ok (((cf2
.dwMask
& CFM_BOLD
) == CFM_BOLD
),
1012 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, CFM_BOLD
);
1013 ok((cf2
.dwEffects
& CFE_BOLD
) == CFE_BOLD
,
1014 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, CFE_BOLD
);
1016 /* Ditto with EM_EXSETSEL */
1017 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"wine");
1018 cr
.cpMin
= 2; cr
.cpMax
= 2;
1019 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
)&cr
); /* Empty selection */
1021 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
1022 cf2
.cbSize
= sizeof(CHARFORMAT2
);
1023 cf2
.dwMask
= CFM_BOLD
;
1024 cf2
.dwEffects
= CFE_BOLD
;
1025 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
1027 /* Empty selection in same place, insert style should NOT be forgotten here. */
1028 cr
.cpMin
= 2; cr
.cpMax
= 2;
1029 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
)&cr
); /* Empty selection */
1031 /* Selection is now nonempty */
1032 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)"newi");
1034 memset(&cf2
, 0, sizeof(CHARFORMAT2
));
1035 cf2
.cbSize
= sizeof(CHARFORMAT2
);
1036 cr
.cpMin
= 2; cr
.cpMax
= 6;
1037 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
)&cr
); /* Empty selection */
1038 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cf2
);
1040 ok (((cf2
.dwMask
& CFM_BOLD
) == CFM_BOLD
),
1041 "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i
, cf2
.dwMask
, CFM_BOLD
);
1042 ok((cf2
.dwEffects
& CFE_BOLD
) == CFE_BOLD
,
1043 "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i
, cf2
.dwEffects
, CFE_BOLD
);
1045 DestroyWindow(hwndRichEdit
);
1048 static void test_EM_SETTEXTMODE(void)
1050 HWND hwndRichEdit
= new_richedit(NULL
);
1051 CHARFORMAT2 cf2
, cf2test
;
1055 /*Test that EM_SETTEXTMODE fails if text exists within the control*/
1056 /*Insert text into the control*/
1058 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1060 /*Attempt to change the control to plain text mode*/
1061 rc
= SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, (WPARAM
) TM_PLAINTEXT
, 0);
1062 ok(rc
!= 0, "EM_SETTEXTMODE: changed text mode in control containing text - returned: %d\n", rc
);
1064 /*Test that EM_SETTEXTMODE does not allow rich edit text to be pasted.
1065 If rich text is pasted, it should have the same formatting as the rest
1066 of the text in the control*/
1068 /*Italicize the text
1069 *NOTE: If the default text was already italicized, the test will simply
1070 reverse; in other words, it will copy a regular "wine" into a plain
1071 text window that uses an italicized format*/
1072 cf2
.cbSize
= sizeof(CHARFORMAT2
);
1073 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
1076 cf2
.dwMask
= CFM_ITALIC
| cf2
.dwMask
;
1077 cf2
.dwEffects
= CFE_ITALIC
^ cf2
.dwEffects
;
1079 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
1080 ok(rc
== 0, "Text marked as modified, expected not modified!\n");
1082 /*EM_SETCHARFORMAT is not yet fully implemented for all WPARAMs in wine;
1083 however, SCF_ALL has been implemented*/
1084 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
1085 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
1087 rc
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
1088 ok(rc
== -1, "Text not marked as modified, expected modified! (%d)\n", rc
);
1090 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1092 /*Select the string "wine"*/
1095 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1097 /*Copy the italicized "wine" to the clipboard*/
1098 SendMessage(hwndRichEdit
, WM_COPY
, 0, 0);
1100 /*Reset the formatting to default*/
1101 cf2
.dwEffects
= CFE_ITALIC
^cf2
.dwEffects
;
1102 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
1103 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
1105 /*Clear the text in the control*/
1106 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1108 /*Switch to Plain Text Mode*/
1109 rc
= SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, (WPARAM
) TM_PLAINTEXT
, 0);
1110 ok(rc
== 0, "EM_SETTEXTMODE: unable to switch to plain text mode with empty control: returned: %d\n", rc
);
1112 /*Input "wine" again in normal format*/
1113 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1115 /*Paste the italicized "wine" into the control*/
1116 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
1118 /*Select a character from the first "wine" string*/
1121 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1123 /*Retrieve its formatting*/
1124 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
1127 /*Select a character from the second "wine" string*/
1130 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1132 /*Retrieve its formatting*/
1133 cf2test
.cbSize
= sizeof(CHARFORMAT2
);
1134 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
1137 /*Compare the two formattings*/
1138 ok((cf2
.dwMask
== cf2test
.dwMask
) && (cf2
.dwEffects
== cf2test
.dwEffects
),
1139 "two formats found in plain text mode - cf2.dwEffects: %x cf2test.dwEffects: %x\n",
1140 cf2
.dwEffects
, cf2test
.dwEffects
);
1141 /*Test TM_RICHTEXT by: switching back to Rich Text mode
1142 printing "wine" in the current format(normal)
1143 pasting "wine" from the clipboard(italicized)
1144 comparing the two formats(should differ)*/
1146 /*Attempt to switch with text in control*/
1147 rc
= SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, (WPARAM
) TM_RICHTEXT
, 0);
1148 ok(rc
!= 0, "EM_SETTEXTMODE: changed from plain text to rich text with text in control - returned: %d\n", rc
);
1151 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1153 /*Switch into Rich Text mode*/
1154 rc
= SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, (WPARAM
) TM_RICHTEXT
, 0);
1155 ok(rc
== 0, "EM_SETTEXTMODE: unable to change to rich text with empty control - returned: %d\n", rc
);
1157 /*Print "wine" in normal formatting into the control*/
1158 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1160 /*Paste italicized "wine" into the control*/
1161 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
1163 /*Select text from the first "wine" string*/
1166 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1168 /*Retrieve its formatting*/
1169 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
1172 /*Select text from the second "wine" string*/
1175 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1177 /*Retrieve its formatting*/
1178 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
,
1181 /*Test that the two formattings are not the same*/
1182 todo_wine
ok((cf2
.dwMask
== cf2test
.dwMask
) && (cf2
.dwEffects
!= cf2test
.dwEffects
),
1183 "expected different formats - cf2.dwMask: %x, cf2test.dwMask: %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
1184 cf2
.dwMask
, cf2test
.dwMask
, cf2
.dwEffects
, cf2test
.dwEffects
);
1186 DestroyWindow(hwndRichEdit
);
1189 static void test_SETPARAFORMAT(void)
1191 HWND hwndRichEdit
= new_richedit(NULL
);
1194 LONG expectedMask
= PFM_ALL2
& ~PFM_TABLEROWDELIMITER
;
1195 fmt
.cbSize
= sizeof(PARAFORMAT2
);
1196 fmt
.dwMask
= PFM_ALIGNMENT
;
1197 fmt
.wAlignment
= PFA_LEFT
;
1199 ret
= SendMessage(hwndRichEdit
, EM_SETPARAFORMAT
, 0, (LPARAM
) &fmt
);
1200 ok(ret
!= 0, "expected non-zero got %d\n", ret
);
1202 fmt
.cbSize
= sizeof(PARAFORMAT2
);
1204 ret
= SendMessage(hwndRichEdit
, EM_GETPARAFORMAT
, 0, (LPARAM
) &fmt
);
1205 /* Ignore the PFM_TABLEROWDELIMITER bit because it changes
1206 * between richedit different native builds of riched20.dll
1207 * used on different Windows versions. */
1208 ret
&= ~PFM_TABLEROWDELIMITER
;
1209 fmt
.dwMask
&= ~PFM_TABLEROWDELIMITER
;
1211 ok(ret
== expectedMask
, "expected %x got %x\n", expectedMask
, ret
);
1212 ok(fmt
.dwMask
== expectedMask
, "expected %x got %x\n", expectedMask
, fmt
.dwMask
);
1214 DestroyWindow(hwndRichEdit
);
1217 static void test_TM_PLAINTEXT(void)
1219 /*Tests plain text properties*/
1221 HWND hwndRichEdit
= new_richedit(NULL
);
1222 CHARFORMAT2 cf2
, cf2test
;
1226 /*Switch to plain text mode*/
1228 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1229 SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, TM_PLAINTEXT
, 0);
1231 /*Fill control with text*/
1233 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "Is Wine an emulator? No it's not");
1235 /*Select some text and bold it*/
1239 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1240 cf2
.cbSize
= sizeof(CHARFORMAT2
);
1241 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
1244 cf2
.dwMask
= CFM_BOLD
| cf2
.dwMask
;
1245 cf2
.dwEffects
= CFE_BOLD
^ cf2
.dwEffects
;
1247 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_SELECTION
, (LPARAM
) &cf2
);
1248 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
1250 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_WORD
| SCF_SELECTION
, (LPARAM
) &cf2
);
1251 ok(rc
== 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc
);
1253 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
)&cf2
);
1254 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
1256 /*Get the formatting of those characters*/
1258 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
, (LPARAM
) &cf2
);
1260 /*Get the formatting of some other characters*/
1261 cf2test
.cbSize
= sizeof(CHARFORMAT2
);
1264 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1265 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
, (LPARAM
) &cf2test
);
1267 /*Test that they are the same as plain text allows only one formatting*/
1269 ok((cf2
.dwMask
== cf2test
.dwMask
) && (cf2
.dwEffects
== cf2test
.dwEffects
),
1270 "two selections' formats differ - cf2.dwMask: %x, cf2test.dwMask %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
1271 cf2
.dwMask
, cf2test
.dwMask
, cf2
.dwEffects
, cf2test
.dwEffects
);
1273 /*Fill the control with a "wine" string, which when inserted will be bold*/
1275 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1277 /*Copy the bolded "wine" string*/
1281 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1282 SendMessage(hwndRichEdit
, WM_COPY
, 0, 0);
1284 /*Swap back to rich text*/
1286 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "");
1287 SendMessage(hwndRichEdit
, EM_SETTEXTMODE
, (WPARAM
) TM_RICHTEXT
, 0);
1289 /*Set the default formatting to bold italics*/
1291 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
, (LPARAM
) &cf2
);
1292 cf2
.dwMask
|= CFM_ITALIC
;
1293 cf2
.dwEffects
^= CFE_ITALIC
;
1294 rc
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
1295 ok(rc
== 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc
);
1297 /*Set the text in the control to "wine", which will be bold and italicized*/
1299 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "wine");
1301 /*Paste the plain text "wine" string, which should take the insert
1302 formatting, which at the moment is bold italics*/
1304 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
1306 /*Select the first "wine" string and retrieve its formatting*/
1310 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1311 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
, (LPARAM
) &cf2
);
1313 /*Select the second "wine" string and retrieve its formatting*/
1317 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
1318 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_SELECTION
, (LPARAM
) &cf2test
);
1320 /*Compare the two formattings. They should be the same.*/
1322 ok((cf2
.dwMask
== cf2test
.dwMask
) && (cf2
.dwEffects
== cf2test
.dwEffects
),
1323 "Copied text retained formatting - cf2.dwMask: %x, cf2test.dwMask: %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
1324 cf2
.dwMask
, cf2test
.dwMask
, cf2
.dwEffects
, cf2test
.dwEffects
);
1325 DestroyWindow(hwndRichEdit
);
1328 static void test_WM_GETTEXT(void)
1330 HWND hwndRichEdit
= new_richedit(NULL
);
1331 static const char text
[] = "Hello. My name is RichEdit!";
1332 static const char text2
[] = "Hello. My name is RichEdit!\r";
1333 static const char text2_after
[] = "Hello. My name is RichEdit!\r\n";
1334 char buffer
[1024] = {0};
1337 /* Baseline test with normal-sized buffer */
1338 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
1339 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1340 ok(result
== lstrlen(buffer
),
1341 "WM_GETTEXT returned %d, expected %d\n", result
, lstrlen(buffer
));
1342 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1343 result
= strcmp(buffer
,text
);
1345 "WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result
);
1347 /* Test for returned value of WM_GETTEXTLENGTH */
1348 result
= SendMessage(hwndRichEdit
, WM_GETTEXTLENGTH
, 0, 0);
1349 ok(result
== lstrlen(text
),
1350 "WM_GETTEXTLENGTH reports incorrect length %d, expected %d\n",
1351 result
, lstrlen(text
));
1353 /* Test for behavior in overflow case */
1354 memset(buffer
, 0, 1024);
1355 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, strlen(text
), (LPARAM
)buffer
);
1357 result
== lstrlenA(text
) - 1, /* XP, win2k3 */
1358 "WM_GETTEXT returned %d, expected 0 or %d\n", result
, lstrlenA(text
) - 1);
1359 result
= strcmp(buffer
,text
);
1361 result
= strncmp(buffer
, text
, lstrlenA(text
) - 1); /* XP, win2k3 */
1363 "WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result
);
1365 /* Baseline test with normal-sized buffer and carriage return */
1366 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text2
);
1367 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1368 ok(result
== lstrlen(buffer
),
1369 "WM_GETTEXT returned %d, expected %d\n", result
, lstrlen(buffer
));
1370 result
= strcmp(buffer
,text2_after
);
1372 "WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result
);
1374 /* Test for returned value of WM_GETTEXTLENGTH */
1375 result
= SendMessage(hwndRichEdit
, WM_GETTEXTLENGTH
, 0, 0);
1376 ok(result
== lstrlen(text2_after
),
1377 "WM_GETTEXTLENGTH reports incorrect length %d, expected %d\n",
1378 result
, lstrlen(text2_after
));
1380 /* Test for behavior of CRLF conversion in case of overflow */
1381 memset(buffer
, 0, 1024);
1382 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, strlen(text2
), (LPARAM
)buffer
);
1384 result
== lstrlenA(text2
) - 1, /* XP, win2k3 */
1385 "WM_GETTEXT returned %d, expected 0 or %d\n", result
, lstrlenA(text2
) - 1);
1386 result
= strcmp(buffer
,text2
);
1388 result
= strncmp(buffer
, text2
, lstrlenA(text2
) - 1); /* XP, win2k3 */
1390 "WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result
);
1392 DestroyWindow(hwndRichEdit
);
1395 static void test_EM_GETTEXTRANGE(void)
1397 HWND hwndRichEdit
= new_richedit(NULL
);
1398 const char * text1
= "foo bar\r\nfoo bar";
1399 const char * text2
= "foo bar\rfoo bar";
1400 const char * expect
= "bar\rfoo";
1401 char buffer
[1024] = {0};
1403 TEXTRANGEA textRange
;
1405 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text1
);
1407 textRange
.lpstrText
= buffer
;
1408 textRange
.chrg
.cpMin
= 4;
1409 textRange
.chrg
.cpMax
= 11;
1410 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1411 ok(result
== 7, "EM_GETTEXTRANGE returned %ld\n", result
);
1412 ok(!strcmp(expect
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1414 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text2
);
1416 textRange
.lpstrText
= buffer
;
1417 textRange
.chrg
.cpMin
= 4;
1418 textRange
.chrg
.cpMax
= 11;
1419 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1420 ok(result
== 7, "EM_GETTEXTRANGE returned %ld\n", result
);
1421 ok(!strcmp(expect
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1423 /* cpMax of text length is used instead of -1 in this case */
1424 textRange
.lpstrText
= buffer
;
1425 textRange
.chrg
.cpMin
= 0;
1426 textRange
.chrg
.cpMax
= -1;
1427 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1428 ok(result
== strlen(text2
), "EM_GETTEXTRANGE returned %ld\n", result
);
1429 ok(!strcmp(text2
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1431 /* cpMin < 0 causes no text to be copied, and 0 to be returned */
1432 textRange
.lpstrText
= buffer
;
1433 textRange
.chrg
.cpMin
= -1;
1434 textRange
.chrg
.cpMax
= 1;
1435 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1436 ok(result
== 0, "EM_GETTEXTRANGE returned %ld\n", result
);
1437 ok(!strcmp(text2
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1439 /* cpMax of -1 is not replaced with text length if cpMin != 0 */
1440 textRange
.lpstrText
= buffer
;
1441 textRange
.chrg
.cpMin
= 1;
1442 textRange
.chrg
.cpMax
= -1;
1443 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1444 ok(result
== 0, "EM_GETTEXTRANGE returned %ld\n", result
);
1445 ok(!strcmp(text2
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1447 /* no end character is copied if cpMax - cpMin < 0 */
1448 textRange
.lpstrText
= buffer
;
1449 textRange
.chrg
.cpMin
= 5;
1450 textRange
.chrg
.cpMax
= 5;
1451 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1452 ok(result
== 0, "EM_GETTEXTRANGE returned %ld\n", result
);
1453 ok(!strcmp(text2
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1455 /* cpMax of text length is used if cpMax > text length*/
1456 textRange
.lpstrText
= buffer
;
1457 textRange
.chrg
.cpMin
= 0;
1458 textRange
.chrg
.cpMax
= 1000;
1459 result
= SendMessage(hwndRichEdit
, EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
1460 ok(result
== strlen(text2
), "EM_GETTEXTRANGE returned %ld\n", result
);
1461 ok(!strcmp(text2
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1463 DestroyWindow(hwndRichEdit
);
1466 static void test_EM_GETSELTEXT(void)
1468 HWND hwndRichEdit
= new_richedit(NULL
);
1469 const char * text1
= "foo bar\r\nfoo bar";
1470 const char * text2
= "foo bar\rfoo bar";
1471 const char * expect
= "bar\rfoo";
1472 char buffer
[1024] = {0};
1475 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text1
);
1477 SendMessage(hwndRichEdit
, EM_SETSEL
, 4, 11);
1478 result
= SendMessage(hwndRichEdit
, EM_GETSELTEXT
, 0, (LPARAM
)buffer
);
1479 ok(result
== 7, "EM_GETTEXTRANGE returned %ld\n", result
);
1480 ok(!strcmp(expect
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1482 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text2
);
1484 SendMessage(hwndRichEdit
, EM_SETSEL
, 4, 11);
1485 result
= SendMessage(hwndRichEdit
, EM_GETSELTEXT
, 0, (LPARAM
)buffer
);
1486 ok(result
== 7, "EM_GETTEXTRANGE returned %ld\n", result
);
1487 ok(!strcmp(expect
, buffer
), "EM_GETTEXTRANGE filled %s\n", buffer
);
1489 DestroyWindow(hwndRichEdit
);
1492 /* FIXME: need to test unimplemented options and robustly test wparam */
1493 static void test_EM_SETOPTIONS(void)
1496 static const char text
[] = "Hello. My name is RichEdit!";
1497 char buffer
[1024] = {0};
1498 DWORD dwStyle
, options
, oldOptions
;
1499 DWORD optionStyles
= ES_AUTOVSCROLL
|ES_AUTOHSCROLL
|ES_NOHIDESEL
|
1500 ES_READONLY
|ES_WANTRETURN
|ES_SAVESEL
|
1501 ES_SELECTIONBAR
|ES_VERTICAL
;
1503 /* Test initial options. */
1504 hwndRichEdit
= CreateWindow(RICHEDIT_CLASS
, NULL
, WS_POPUP
,
1505 0, 0, 200, 60, NULL
, NULL
,
1506 hmoduleRichEdit
, NULL
);
1507 ok(hwndRichEdit
!= NULL
, "class: %s, error: %d\n",
1508 RICHEDIT_CLASS
, (int) GetLastError());
1509 options
= SendMessage(hwndRichEdit
, EM_GETOPTIONS
, 0, 0);
1510 ok(options
== 0, "Incorrect initial options %x\n", options
);
1511 DestroyWindow(hwndRichEdit
);
1513 hwndRichEdit
= CreateWindow(RICHEDIT_CLASS
, NULL
,
1514 WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
|WS_VISIBLE
,
1515 0, 0, 200, 60, NULL
, NULL
,
1516 hmoduleRichEdit
, NULL
);
1517 ok(hwndRichEdit
!= NULL
, "class: %s, error: %d\n",
1518 RICHEDIT_CLASS
, (int) GetLastError());
1519 options
= SendMessage(hwndRichEdit
, EM_GETOPTIONS
, 0, 0);
1520 /* WS_[VH]SCROLL cause the ECO_AUTO[VH]SCROLL options to be set */
1521 ok(options
== (ECO_AUTOVSCROLL
|ECO_AUTOHSCROLL
),
1522 "Incorrect initial options %x\n", options
);
1524 /* NEGATIVE TESTING - NO OPTIONS SET */
1525 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
1526 SendMessage(hwndRichEdit
, EM_SETOPTIONS
, ECOOP_SET
, 0);
1528 /* testing no readonly by sending 'a' to the control*/
1529 SetFocus(hwndRichEdit
);
1530 SendMessage(hwndRichEdit
, WM_CHAR
, 'a', 0x1E0001);
1531 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1533 "EM_SETOPTIONS: Text not changed! s1:%s s2:%s\n", text
, buffer
);
1534 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
1536 /* READONLY - sending 'a' to the control */
1537 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
1538 SendMessage(hwndRichEdit
, EM_SETOPTIONS
, ECOOP_SET
, ECO_READONLY
);
1539 SetFocus(hwndRichEdit
);
1540 SendMessage(hwndRichEdit
, WM_CHAR
, 'a', 0x1E0001);
1541 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1542 ok(buffer
[0]==text
[0],
1543 "EM_SETOPTIONS: Text changed! s1:%s s2:%s\n", text
, buffer
);
1545 /* EM_SETOPTIONS changes the window style, but changing the
1546 * window style does not change the options. */
1547 dwStyle
= GetWindowLong(hwndRichEdit
, GWL_STYLE
);
1548 ok(dwStyle
& ES_READONLY
, "Readonly style not set by EM_SETOPTIONS\n");
1549 SetWindowLong(hwndRichEdit
, GWL_STYLE
, dwStyle
& ~ES_READONLY
);
1550 options
= SendMessage(hwndRichEdit
, EM_GETOPTIONS
, 0, 0);
1551 ok(options
& ES_READONLY
, "Readonly option set by SetWindowLong\n");
1552 /* Confirm that the text is still read only. */
1553 SendMessage(hwndRichEdit
, WM_CHAR
, 'a', ('a' << 16) | 0x0001);
1554 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
1555 ok(buffer
[0]==text
[0],
1556 "EM_SETOPTIONS: Text changed! s1:%s s2:%s\n", text
, buffer
);
1558 oldOptions
= options
;
1559 SetWindowLong(hwndRichEdit
, GWL_STYLE
, dwStyle
|optionStyles
);
1560 options
= SendMessage(hwndRichEdit
, EM_GETOPTIONS
, 0, 0);
1561 ok(options
== oldOptions
,
1562 "Options set by SetWindowLong (%x -> %x)\n", oldOptions
, options
);
1564 DestroyWindow(hwndRichEdit
);
1567 static int check_CFE_LINK_selection(HWND hwnd
, int sel_start
, int sel_end
)
1569 CHARFORMAT2W text_format
;
1570 text_format
.cbSize
= sizeof(text_format
);
1571 SendMessage(hwnd
, EM_SETSEL
, sel_start
, sel_end
);
1572 SendMessage(hwnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &text_format
);
1573 return (text_format
.dwEffects
& CFE_LINK
) ? 1 : 0;
1576 static void check_CFE_LINK_rcvd(HWND hwnd
, int is_url
, const char * url
)
1578 int link_present
= 0;
1580 link_present
= check_CFE_LINK_selection(hwnd
, 0, 1);
1582 { /* control text is url; should get CFE_LINK */
1583 ok(0 != link_present
, "URL Case: CFE_LINK not set for [%s].\n", url
);
1587 ok(0 == link_present
, "Non-URL Case: CFE_LINK set for [%s].\n", url
);
1591 static HWND
new_static_wnd(HWND parent
) {
1592 return new_window("Static", 0, parent
);
1595 static void test_EM_AUTOURLDETECT(void)
1597 /* DO NOT change the properties of the first two elements. To shorten the
1598 tests, all tests after WM_SETTEXT test just the first two elements -
1599 one non-URL and one URL */
1605 {"http://www.winehq.org", 1},
1606 {"http//winehq.org", 0},
1607 {"ww.winehq.org", 0},
1608 {"www.winehq.org", 1},
1609 {"ftp://192.168.1.1", 1},
1610 {"ftp//192.168.1.1", 0},
1611 {"mailto:your@email.com", 1},
1612 {"prospero:prosperoserver", 1},
1614 {"news:newserver", 1},
1615 {"wais:waisserver", 1}
1620 HWND hwndRichEdit
, parent
;
1622 /* All of the following should cause the URL to be detected */
1623 const char * templates_delim
[] = {
1624 "This is some text with X on it",
1625 "This is some text with (X) on it",
1626 "This is some text with X\r on it",
1627 "This is some text with ---X--- on it",
1628 "This is some text with \"X\" on it",
1629 "This is some text with 'X' on it",
1630 "This is some text with 'X' on it",
1631 "This is some text with :X: on it",
1633 "This text ends with X",
1635 "This is some text with X) on it",
1636 "This is some text with X--- on it",
1637 "This is some text with X\" on it",
1638 "This is some text with X' on it",
1639 "This is some text with X: on it",
1641 "This is some text with (X on it",
1642 "This is some text with \rX on it",
1643 "This is some text with ---X on it",
1644 "This is some text with \"X on it",
1645 "This is some text with 'X on it",
1646 "This is some text with :X on it",
1648 /* None of these should cause the URL to be detected */
1649 const char * templates_non_delim
[] = {
1650 "This is some text with |X| on it",
1651 "This is some text with *X* on it",
1652 "This is some text with /X/ on it",
1653 "This is some text with +X+ on it",
1654 "This is some text with %X% on it",
1655 "This is some text with #X# on it",
1656 "This is some text with @X@ on it",
1657 "This is some text with \\X\\ on it",
1658 "This is some text with |X on it",
1659 "This is some text with *X on it",
1660 "This is some text with /X on it",
1661 "This is some text with +X on it",
1662 "This is some text with %X on it",
1663 "This is some text with #X on it",
1664 "This is some text with @X on it",
1665 "This is some text with \\X on it",
1667 /* All of these cause the URL detection to be extended by one more byte,
1668 thus demonstrating that the tested character is considered as part
1670 const char * templates_xten_delim
[] = {
1671 "This is some text with X| on it",
1672 "This is some text with X* on it",
1673 "This is some text with X/ on it",
1674 "This is some text with X+ on it",
1675 "This is some text with X% on it",
1676 "This is some text with X# on it",
1677 "This is some text with X@ on it",
1678 "This is some text with X\\ on it",
1682 parent
= new_static_wnd(NULL
);
1683 hwndRichEdit
= new_richedit(parent
);
1684 /* Try and pass EM_AUTOURLDETECT some test wParam values */
1685 urlRet
=SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, FALSE
, 0);
1686 ok(urlRet
==0, "Good wParam: urlRet is: %d\n", urlRet
);
1687 urlRet
=SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, 1, 0);
1688 ok(urlRet
==0, "Good wParam2: urlRet is: %d\n", urlRet
);
1689 /* Windows returns -2147024809 (0x80070057) on bad wParam values */
1690 urlRet
=SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, 8, 0);
1691 ok(urlRet
==E_INVALIDARG
, "Bad wParam: urlRet is: %d\n", urlRet
);
1692 urlRet
=SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, (WPARAM
)"h", (LPARAM
)"h");
1693 ok(urlRet
==E_INVALIDARG
, "Bad wParam2: urlRet is: %d\n", urlRet
);
1694 /* for each url, check the text to see if CFE_LINK effect is present */
1695 for (i
= 0; i
< sizeof(urls
)/sizeof(struct urls_s
); i
++) {
1697 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, FALSE
, 0);
1698 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) urls
[i
].text
);
1699 check_CFE_LINK_rcvd(hwndRichEdit
, 0, urls
[i
].text
);
1701 /* Link detection should happen immediately upon WM_SETTEXT */
1702 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
1703 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) urls
[i
].text
);
1704 check_CFE_LINK_rcvd(hwndRichEdit
, urls
[i
].is_url
, urls
[i
].text
);
1706 DestroyWindow(hwndRichEdit
);
1708 /* Test detection of URLs within normal text - WM_SETTEXT case. */
1709 for (i
= 0; i
< sizeof(urls
)/sizeof(struct urls_s
); i
++) {
1710 hwndRichEdit
= new_richedit(parent
);
1712 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
1717 at_pos
= strchr(templates_delim
[j
], 'X');
1718 at_offset
= at_pos
- templates_delim
[j
];
1719 strncpy(buffer
, templates_delim
[j
], at_offset
);
1720 buffer
[at_offset
] = '\0';
1721 strcat(buffer
, urls
[i
].text
);
1722 strcat(buffer
, templates_delim
[j
] + at_offset
+ 1);
1723 end_offset
= at_offset
+ strlen(urls
[i
].text
);
1725 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
1726 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) buffer
);
1728 /* This assumes no templates start with the URL itself, and that they
1729 have at least two characters before the URL text */
1730 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1731 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1732 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1733 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1734 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1735 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1739 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1740 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
1741 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1742 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1746 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1747 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1748 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1749 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1751 if (buffer
[end_offset
] != '\0')
1753 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1754 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
1755 if (buffer
[end_offset
+1] != '\0')
1757 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1758 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
1763 for (j
= 0; j
< sizeof(templates_non_delim
) / sizeof(const char *); j
++) {
1768 at_pos
= strchr(templates_non_delim
[j
], 'X');
1769 at_offset
= at_pos
- templates_non_delim
[j
];
1770 strncpy(buffer
, templates_non_delim
[j
], at_offset
);
1771 buffer
[at_offset
] = '\0';
1772 strcat(buffer
, urls
[i
].text
);
1773 strcat(buffer
, templates_non_delim
[j
] + at_offset
+ 1);
1774 end_offset
= at_offset
+ strlen(urls
[i
].text
);
1776 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
1777 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) buffer
);
1779 /* This assumes no templates start with the URL itself, and that they
1780 have at least two characters before the URL text */
1781 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1782 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1783 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1784 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1785 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1786 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1788 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1789 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1790 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1791 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1792 if (buffer
[end_offset
] != '\0')
1794 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1795 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
1796 if (buffer
[end_offset
+1] != '\0')
1798 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1799 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
1804 for (j
= 0; j
< sizeof(templates_xten_delim
) / sizeof(const char *); j
++) {
1809 at_pos
= strchr(templates_xten_delim
[j
], 'X');
1810 at_offset
= at_pos
- templates_xten_delim
[j
];
1811 strncpy(buffer
, templates_xten_delim
[j
], at_offset
);
1812 buffer
[at_offset
] = '\0';
1813 strcat(buffer
, urls
[i
].text
);
1814 strcat(buffer
, templates_xten_delim
[j
] + at_offset
+ 1);
1815 end_offset
= at_offset
+ strlen(urls
[i
].text
);
1817 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
1818 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) buffer
);
1820 /* This assumes no templates start with the URL itself, and that they
1821 have at least two characters before the URL text */
1822 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1823 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1824 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1825 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1826 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1827 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1831 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1832 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
1833 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1834 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1835 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1836 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
, end_offset
+1, buffer
);
1840 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1841 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1842 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1843 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1844 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1845 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+1, buffer
);
1847 if (buffer
[end_offset
+1] != '\0')
1849 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1850 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+ 2, buffer
);
1851 if (buffer
[end_offset
+2] != '\0')
1853 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+2, end_offset
+3),
1854 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+2, end_offset
+3, buffer
);
1859 DestroyWindow(hwndRichEdit
);
1860 hwndRichEdit
= NULL
;
1863 /* Test detection of URLs within normal text - WM_CHAR case. */
1864 /* Test only the first two URL examples for brevity */
1865 for (i
= 0; i
< 2; i
++) {
1866 hwndRichEdit
= new_richedit(parent
);
1868 /* Also for brevity, test only the first three delimiters */
1869 for (j
= 0; j
< 3; j
++) {
1875 at_pos
= strchr(templates_delim
[j
], 'X');
1876 at_offset
= at_pos
- templates_delim
[j
];
1877 end_offset
= at_offset
+ strlen(urls
[i
].text
);
1879 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
1880 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
1881 for (u
= 0; templates_delim
[j
][u
]; u
++) {
1882 if (templates_delim
[j
][u
] == '\r') {
1883 simulate_typing_characters(hwndRichEdit
, "\r");
1884 } else if (templates_delim
[j
][u
] != 'X') {
1885 SendMessage(hwndRichEdit
, WM_CHAR
, templates_delim
[j
][u
], 1);
1887 for (v
= 0; urls
[i
].text
[v
]; v
++) {
1888 SendMessage(hwndRichEdit
, WM_CHAR
, urls
[i
].text
[v
], 1);
1892 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
1894 /* This assumes no templates start with the URL itself, and that they
1895 have at least two characters before the URL text */
1896 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1897 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1898 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1899 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1900 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1901 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1905 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1906 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
1907 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1908 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1912 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1913 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1914 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1915 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1917 if (buffer
[end_offset
] != '\0')
1919 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1920 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
1921 if (buffer
[end_offset
+1] != '\0')
1923 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1924 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
1928 /* The following will insert a paragraph break after the first character
1929 of the URL candidate, thus breaking the URL. It is expected that the
1930 CFE_LINK attribute should break across both pieces of the URL */
1931 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
+1, at_offset
+1);
1932 simulate_typing_characters(hwndRichEdit
, "\r");
1933 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
1935 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1936 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1937 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1938 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1939 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1940 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1942 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1943 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1944 /* end_offset moved because of paragraph break */
1945 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1946 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+1, buffer
);
1947 ok(buffer
[end_offset
], "buffer \"%s\" ended prematurely. Is it missing a newline character?\n", buffer
);
1948 if (buffer
[end_offset
] != 0 && buffer
[end_offset
+1] != '\0')
1950 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1951 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
1952 if (buffer
[end_offset
+2] != '\0')
1954 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+2, end_offset
+3),
1955 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+2, end_offset
+3, buffer
);
1959 /* The following will remove the just-inserted paragraph break, thus
1960 restoring the URL */
1961 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
+2, at_offset
+2);
1962 simulate_typing_characters(hwndRichEdit
, "\b");
1963 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
1965 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
1966 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
1967 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
1968 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
1969 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
1970 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
1974 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1975 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
1976 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1977 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1981 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
1982 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
1983 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
1984 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
1986 if (buffer
[end_offset
] != '\0')
1988 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
1989 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
1990 if (buffer
[end_offset
+1] != '\0')
1992 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
1993 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
1997 DestroyWindow(hwndRichEdit
);
1998 hwndRichEdit
= NULL
;
2001 /* Test detection of URLs within normal text - EM_SETTEXTEX case. */
2002 /* Test just the first two URL examples for brevity */
2003 for (i
= 0; i
< 2; i
++) {
2006 hwndRichEdit
= new_richedit(parent
);
2008 /* There are at least three ways in which EM_SETTEXTEX must cause URLs to
2010 1) Set entire text, a la WM_SETTEXT
2011 2) Set a selection of the text to the URL
2012 3) Set a portion of the text at a time, which eventually results in
2014 All of them should give equivalent results
2017 /* Set entire text in one go, like WM_SETTEXT */
2018 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
2023 st
.codepage
= CP_ACP
;
2024 st
.flags
= ST_DEFAULT
;
2026 at_pos
= strchr(templates_delim
[j
], 'X');
2027 at_offset
= at_pos
- templates_delim
[j
];
2028 strncpy(buffer
, templates_delim
[j
], at_offset
);
2029 buffer
[at_offset
] = '\0';
2030 strcat(buffer
, urls
[i
].text
);
2031 strcat(buffer
, templates_delim
[j
] + at_offset
+ 1);
2032 end_offset
= at_offset
+ strlen(urls
[i
].text
);
2034 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
2035 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
) buffer
);
2037 /* This assumes no templates start with the URL itself, and that they
2038 have at least two characters before the URL text */
2039 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
2040 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
2041 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
2042 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
2043 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
2044 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
2048 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2049 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
2050 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2051 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2055 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2056 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
2057 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2058 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2060 if (buffer
[end_offset
] != '\0')
2062 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
2063 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
2064 if (buffer
[end_offset
+1] != '\0')
2066 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
2067 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
2072 /* Set selection with X to the URL */
2073 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
2078 at_pos
= strchr(templates_delim
[j
], 'X');
2079 at_offset
= at_pos
- templates_delim
[j
];
2080 end_offset
= at_offset
+ strlen(urls
[i
].text
);
2082 st
.codepage
= CP_ACP
;
2083 st
.flags
= ST_DEFAULT
;
2084 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
2085 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
) templates_delim
[j
]);
2086 st
.flags
= ST_SELECTION
;
2087 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
, at_offset
+1);
2088 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
) urls
[i
].text
);
2089 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
2091 /* This assumes no templates start with the URL itself, and that they
2092 have at least two characters before the URL text */
2093 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
2094 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
2095 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
2096 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
2097 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
2098 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
2102 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2103 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
2104 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2105 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2109 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2110 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
2111 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2112 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2114 if (buffer
[end_offset
] != '\0')
2116 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
2117 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
2118 if (buffer
[end_offset
+1] != '\0')
2120 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
2121 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
2126 /* Set selection with X to the first character of the URL, then the rest */
2127 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
2132 at_pos
= strchr(templates_delim
[j
], 'X');
2133 at_offset
= at_pos
- templates_delim
[j
];
2134 end_offset
= at_offset
+ strlen(urls
[i
].text
);
2136 strcpy(buffer
, "YY");
2137 buffer
[0] = urls
[i
].text
[0];
2139 st
.codepage
= CP_ACP
;
2140 st
.flags
= ST_DEFAULT
;
2141 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
2142 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
) templates_delim
[j
]);
2143 st
.flags
= ST_SELECTION
;
2144 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
, at_offset
+1);
2145 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
) buffer
);
2146 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
+1, at_offset
+2);
2147 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&st
, (LPARAM
)(urls
[i
].text
+ 1));
2148 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
2150 /* This assumes no templates start with the URL itself, and that they
2151 have at least two characters before the URL text */
2152 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
2153 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
2154 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
2155 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
2156 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
2157 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
2161 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2162 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
2163 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2164 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2168 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2169 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
2170 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2171 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2173 if (buffer
[end_offset
] != '\0')
2175 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
2176 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
2177 if (buffer
[end_offset
+1] != '\0')
2179 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
2180 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
2185 DestroyWindow(hwndRichEdit
);
2186 hwndRichEdit
= NULL
;
2189 /* Test detection of URLs within normal text - EM_REPLACESEL case. */
2190 /* Test just the first two URL examples for brevity */
2191 for (i
= 0; i
< 2; i
++) {
2192 hwndRichEdit
= new_richedit(parent
);
2194 /* Set selection with X to the URL */
2195 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
2200 at_pos
= strchr(templates_delim
[j
], 'X');
2201 at_offset
= at_pos
- templates_delim
[j
];
2202 end_offset
= at_offset
+ strlen(urls
[i
].text
);
2204 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
2205 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) templates_delim
[j
]);
2206 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
, at_offset
+1);
2207 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) urls
[i
].text
);
2208 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
2210 /* This assumes no templates start with the URL itself, and that they
2211 have at least two characters before the URL text */
2212 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
2213 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
2214 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
2215 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
2216 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
2217 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
2221 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2222 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
2223 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2224 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2228 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2229 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
2230 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2231 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2233 if (buffer
[end_offset
] != '\0')
2235 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
2236 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
2237 if (buffer
[end_offset
+1] != '\0')
2239 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
2240 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
2245 /* Set selection with X to the first character of the URL, then the rest */
2246 for (j
= 0; j
< sizeof(templates_delim
) / sizeof(const char *); j
++) {
2251 at_pos
= strchr(templates_delim
[j
], 'X');
2252 at_offset
= at_pos
- templates_delim
[j
];
2253 end_offset
= at_offset
+ strlen(urls
[i
].text
);
2255 strcpy(buffer
, "YY");
2256 buffer
[0] = urls
[i
].text
[0];
2258 SendMessage(hwndRichEdit
, EM_AUTOURLDETECT
, TRUE
, 0);
2259 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) templates_delim
[j
]);
2260 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
, at_offset
+1);
2261 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) buffer
);
2262 SendMessage(hwndRichEdit
, EM_SETSEL
, at_offset
+1, at_offset
+2);
2263 SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
)(urls
[i
].text
+ 1));
2264 SendMessage(hwndRichEdit
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
2266 /* This assumes no templates start with the URL itself, and that they
2267 have at least two characters before the URL text */
2268 ok(!check_CFE_LINK_selection(hwndRichEdit
, 0, 1),
2269 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer
);
2270 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-2, at_offset
-1),
2271 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-2, at_offset
-1, buffer
);
2272 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
-1, at_offset
),
2273 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
-1, at_offset
, buffer
);
2277 ok(check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2278 "CFE_LINK not set in (%d-%d), text: %s\n", at_offset
, at_offset
+1, buffer
);
2279 ok(check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2280 "CFE_LINK not set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2284 ok(!check_CFE_LINK_selection(hwndRichEdit
, at_offset
, at_offset
+1),
2285 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset
, at_offset
+ 1, buffer
);
2286 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
-1, end_offset
),
2287 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
-1, end_offset
, buffer
);
2289 if (buffer
[end_offset
] != '\0')
2291 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
, end_offset
+1),
2292 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
, end_offset
+ 1, buffer
);
2293 if (buffer
[end_offset
+1] != '\0')
2295 ok(!check_CFE_LINK_selection(hwndRichEdit
, end_offset
+1, end_offset
+2),
2296 "CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset
+1, end_offset
+2, buffer
);
2301 DestroyWindow(hwndRichEdit
);
2302 hwndRichEdit
= NULL
;
2305 DestroyWindow(parent
);
2308 static void test_EM_SCROLL(void)
2311 int r
; /* return value */
2312 int expr
; /* expected return value */
2313 HWND hwndRichEdit
= new_richedit(NULL
);
2314 int y_before
, y_after
; /* units of lines of text */
2316 /* test a richedit box containing a single line of text */
2317 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "a");/* one line of text */
2319 for (i
= 0; i
< 4; i
++) {
2320 static const int cmd
[4] = { SB_PAGEDOWN
, SB_PAGEUP
, SB_LINEDOWN
, SB_LINEUP
};
2322 r
= SendMessage(hwndRichEdit
, EM_SCROLL
, cmd
[i
], 0);
2323 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2324 ok(expr
== r
, "EM_SCROLL improper return value returned (i == %d). "
2325 "Got 0x%08x, expected 0x%08x\n", i
, r
, expr
);
2326 ok(y_after
== 0, "EM_SCROLL improper scroll. scrolled to line %d, not 1 "
2327 "(i == %d)\n", y_after
, i
);
2331 * test a richedit box that will scroll. There are two general
2332 * cases: the case without any long lines and the case with a long
2335 for (i
= 0; i
< 2; i
++) { /* iterate through different bodies of text */
2337 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "a\nb\nc\nd\ne");
2339 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)
2340 "a LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
2341 "LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
2342 "LONG LINE \nb\nc\nd\ne");
2343 for (j
= 0; j
< 12; j
++) /* reset scroll position to top */
2344 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_PAGEUP
, 0);
2346 /* get first visible line */
2347 y_before
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2348 r
= SendMessage(hwndRichEdit
, EM_SCROLL
, SB_PAGEDOWN
, 0); /* page down */
2350 /* get new current first visible line */
2351 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2353 ok(((r
& 0xffffff00) == 0x00010000) &&
2354 ((r
& 0x000000ff) != 0x00000000),
2355 "EM_SCROLL page down didn't scroll by a small positive number of "
2356 "lines (r == 0x%08x)\n", r
);
2357 ok(y_after
> y_before
, "EM_SCROLL page down not functioning "
2358 "(line %d scrolled to line %d\n", y_before
, y_after
);
2362 r
= SendMessage(hwndRichEdit
, EM_SCROLL
, SB_PAGEUP
, 0); /* page up */
2363 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2364 ok(((r
& 0xffffff00) == 0x0001ff00),
2365 "EM_SCROLL page up didn't scroll by a small negative number of lines "
2366 "(r == 0x%08x)\n", r
);
2367 ok(y_after
< y_before
, "EM_SCROLL page up not functioning (line "
2368 "%d scrolled to line %d\n", y_before
, y_after
);
2372 r
= SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEDOWN
, 0); /* line down */
2374 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2376 ok(r
== 0x00010001, "EM_SCROLL line down didn't scroll by one line "
2377 "(r == 0x%08x)\n", r
);
2378 ok(y_after
-1 == y_before
, "EM_SCROLL line down didn't go down by "
2379 "1 line (%d scrolled to %d)\n", y_before
, y_after
);
2383 r
= SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEUP
, 0); /* line up */
2385 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2387 ok(r
== 0x0001ffff, "EM_SCROLL line up didn't scroll by one line "
2388 "(r == 0x%08x)\n", r
);
2389 ok(y_after
+1 == y_before
, "EM_SCROLL line up didn't go up by 1 "
2390 "line (%d scrolled to %d)\n", y_before
, y_after
);
2394 r
= SendMessage(hwndRichEdit
, EM_SCROLL
,
2395 SB_LINEUP
, 0); /* lineup beyond top */
2397 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2400 "EM_SCROLL line up returned indicating movement (0x%08x)\n", r
);
2401 ok(y_before
== y_after
,
2402 "EM_SCROLL line up beyond top worked (%d)\n", y_after
);
2406 r
= SendMessage(hwndRichEdit
, EM_SCROLL
,
2407 SB_PAGEUP
, 0);/*page up beyond top */
2409 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2412 "EM_SCROLL page up returned indicating movement (0x%08x)\n", r
);
2413 ok(y_before
== y_after
,
2414 "EM_SCROLL page up beyond top worked (%d)\n", y_after
);
2416 for (j
= 0; j
< 12; j
++) /* page down all the way to the bottom */
2417 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_PAGEDOWN
, 0);
2418 y_before
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2419 r
= SendMessage(hwndRichEdit
, EM_SCROLL
,
2420 SB_PAGEDOWN
, 0); /* page down beyond bot */
2421 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2424 "EM_SCROLL page down returned indicating movement (0x%08x)\n", r
);
2425 ok(y_before
== y_after
,
2426 "EM_SCROLL page down beyond bottom worked (%d -> %d)\n",
2429 y_before
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2430 SendMessage(hwndRichEdit
, EM_SCROLL
,
2431 SB_LINEDOWN
, 0); /* line down beyond bot */
2432 y_after
= SendMessage(hwndRichEdit
, EM_GETFIRSTVISIBLELINE
, 0, 0);
2435 "EM_SCROLL line down returned indicating movement (0x%08x)\n", r
);
2436 ok(y_before
== y_after
,
2437 "EM_SCROLL line down beyond bottom worked (%d -> %d)\n",
2440 DestroyWindow(hwndRichEdit
);
2443 unsigned int recursionLevel
= 0;
2444 unsigned int WM_SIZE_recursionLevel
= 0;
2445 BOOL bailedOutOfRecursion
= FALSE
;
2446 LRESULT (WINAPI
*richeditProc
)(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
2448 static LRESULT WINAPI
RicheditStupidOverrideProcA(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2452 if (bailedOutOfRecursion
) return 0;
2453 if (recursionLevel
>= 32) {
2454 bailedOutOfRecursion
= TRUE
;
2461 WM_SIZE_recursionLevel
++;
2462 r
= richeditProc(hwnd
, message
, wParam
, lParam
);
2463 /* Because, uhhhh... I never heard of ES_DISABLENOSCROLL */
2464 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2465 WM_SIZE_recursionLevel
--;
2468 r
= richeditProc(hwnd
, message
, wParam
, lParam
);
2475 static void test_scrollbar_visibility(void)
2478 const char * text
="a\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n";
2483 /* These tests show that richedit should temporarily refrain from automatically
2484 hiding or showing its scrollbars (vertical at least) when an explicit request
2485 is made via ShowScrollBar() or similar, outside of standard richedit logic.
2486 Some applications depend on forced showing (when otherwise richedit would
2487 hide the vertical scrollbar) and are thrown on an endless recursive loop
2488 if richedit auto-hides the scrollbar again. Apparently they never heard of
2489 the ES_DISABLENOSCROLL style... */
2491 hwndRichEdit
= new_richedit(NULL
);
2493 /* Test default scrollbar visibility behavior */
2494 memset(&si
, 0, sizeof(si
));
2495 si
.cbSize
= sizeof(si
);
2496 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2497 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2498 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2499 "Vertical scrollbar is visible, should be invisible.\n");
2500 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2501 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2502 si
.nPage
, si
.nMin
, si
.nMax
);
2504 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2505 memset(&si
, 0, sizeof(si
));
2506 si
.cbSize
= sizeof(si
);
2507 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2508 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2509 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2510 "Vertical scrollbar is visible, should be invisible.\n");
2511 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2512 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2513 si
.nPage
, si
.nMin
, si
.nMax
);
2515 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2516 memset(&si
, 0, sizeof(si
));
2517 si
.cbSize
= sizeof(si
);
2518 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2519 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2520 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2521 "Vertical scrollbar is invisible, should be visible.\n");
2522 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2523 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2524 si
.nPage
, si
.nMin
, si
.nMax
);
2526 /* Oddly, setting text to NULL does *not* reset the scrollbar range,
2527 even though it hides the scrollbar */
2528 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2529 memset(&si
, 0, sizeof(si
));
2530 si
.cbSize
= sizeof(si
);
2531 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2532 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2533 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2534 "Vertical scrollbar is visible, should be invisible.\n");
2535 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2536 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2537 si
.nPage
, si
.nMin
, si
.nMax
);
2539 /* Setting non-scrolling text again does *not* reset scrollbar range */
2540 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2541 memset(&si
, 0, sizeof(si
));
2542 si
.cbSize
= sizeof(si
);
2543 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2544 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2545 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2546 "Vertical scrollbar is visible, should be invisible.\n");
2547 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2548 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2549 si
.nPage
, si
.nMin
, si
.nMax
);
2551 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2552 memset(&si
, 0, sizeof(si
));
2553 si
.cbSize
= sizeof(si
);
2554 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2555 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2556 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2557 "Vertical scrollbar is visible, should be invisible.\n");
2558 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2559 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2560 si
.nPage
, si
.nMin
, si
.nMax
);
2562 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2563 memset(&si
, 0, sizeof(si
));
2564 si
.cbSize
= sizeof(si
);
2565 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2566 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2567 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2568 "Vertical scrollbar is visible, should be invisible.\n");
2569 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2570 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2571 si
.nPage
, si
.nMin
, si
.nMax
);
2573 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"");
2574 memset(&si
, 0, sizeof(si
));
2575 si
.cbSize
= sizeof(si
);
2576 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2577 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2578 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2579 "Vertical scrollbar is visible, should be invisible.\n");
2580 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2581 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2582 si
.nPage
, si
.nMin
, si
.nMax
);
2584 DestroyWindow(hwndRichEdit
);
2586 /* Test again, with ES_DISABLENOSCROLL style */
2587 hwndRichEdit
= new_window(RICHEDIT_CLASS
, ES_MULTILINE
|ES_DISABLENOSCROLL
, NULL
);
2589 /* Test default scrollbar visibility behavior */
2590 memset(&si
, 0, sizeof(si
));
2591 si
.cbSize
= sizeof(si
);
2592 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2593 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2594 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2595 "Vertical scrollbar is invisible, should be visible.\n");
2596 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 1,
2597 "reported page/range is %d (%d..%d) expected 0 (0..1)\n",
2598 si
.nPage
, si
.nMin
, si
.nMax
);
2600 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2601 memset(&si
, 0, sizeof(si
));
2602 si
.cbSize
= sizeof(si
);
2603 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2604 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2605 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2606 "Vertical scrollbar is invisible, should be visible.\n");
2607 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 1,
2608 "reported page/range is %d (%d..%d) expected 0 (0..1)\n",
2609 si
.nPage
, si
.nMin
, si
.nMax
);
2611 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2612 memset(&si
, 0, sizeof(si
));
2613 si
.cbSize
= sizeof(si
);
2614 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2615 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2616 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2617 "Vertical scrollbar is invisible, should be visible.\n");
2618 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2619 "reported page/range is %d (%d..%d)\n",
2620 si
.nPage
, si
.nMin
, si
.nMax
);
2622 /* Oddly, setting text to NULL does *not* reset the scrollbar range */
2623 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2624 memset(&si
, 0, sizeof(si
));
2625 si
.cbSize
= sizeof(si
);
2626 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2627 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2628 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2629 "Vertical scrollbar is invisible, should be visible.\n");
2630 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2631 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2632 si
.nPage
, si
.nMin
, si
.nMax
);
2634 /* Setting non-scrolling text again does *not* reset scrollbar range */
2635 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2636 memset(&si
, 0, sizeof(si
));
2637 si
.cbSize
= sizeof(si
);
2638 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2639 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2640 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2641 "Vertical scrollbar is invisible, should be visible.\n");
2642 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2643 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2644 si
.nPage
, si
.nMin
, si
.nMax
);
2646 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2647 memset(&si
, 0, sizeof(si
));
2648 si
.cbSize
= sizeof(si
);
2649 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2650 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2651 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2652 "Vertical scrollbar is invisible, should be visible.\n");
2653 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2654 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2655 si
.nPage
, si
.nMin
, si
.nMax
);
2657 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2658 memset(&si
, 0, sizeof(si
));
2659 si
.cbSize
= sizeof(si
);
2660 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2661 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2662 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2663 "Vertical scrollbar is invisible, should be visible.\n");
2664 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2665 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2666 si
.nPage
, si
.nMin
, si
.nMax
);
2668 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"");
2669 memset(&si
, 0, sizeof(si
));
2670 si
.cbSize
= sizeof(si
);
2671 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2672 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2673 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2674 "Vertical scrollbar is invisible, should be visible.\n");
2675 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
> 1,
2676 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2677 si
.nPage
, si
.nMin
, si
.nMax
);
2679 DestroyWindow(hwndRichEdit
);
2681 /* Test behavior with explicit visibility request, using ShowScrollBar() */
2682 hwndRichEdit
= new_richedit(NULL
);
2684 /* Previously failed because builtin incorrectly re-hides scrollbar forced visible */
2685 ShowScrollBar(hwndRichEdit
, SB_VERT
, TRUE
);
2686 memset(&si
, 0, sizeof(si
));
2687 si
.cbSize
= sizeof(si
);
2688 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2689 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2690 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2691 "Vertical scrollbar is invisible, should be visible.\n");
2693 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 100,
2694 "reported page/range is %d (%d..%d) expected 0 (0..100)\n",
2695 si
.nPage
, si
.nMin
, si
.nMax
);
2698 /* Ditto, see above */
2699 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2700 memset(&si
, 0, sizeof(si
));
2701 si
.cbSize
= sizeof(si
);
2702 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2703 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2704 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2705 "Vertical scrollbar is invisible, should be visible.\n");
2707 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 100,
2708 "reported page/range is %d (%d..%d) expected 0 (0..100)\n",
2709 si
.nPage
, si
.nMin
, si
.nMax
);
2712 /* Ditto, see above */
2713 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2714 memset(&si
, 0, sizeof(si
));
2715 si
.cbSize
= sizeof(si
);
2716 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2717 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2718 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2719 "Vertical scrollbar is invisible, should be visible.\n");
2721 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 100,
2722 "reported page/range is %d (%d..%d) expected 0 (0..100)\n",
2723 si
.nPage
, si
.nMin
, si
.nMax
);
2726 /* Ditto, see above */
2727 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a\na");
2728 memset(&si
, 0, sizeof(si
));
2729 si
.cbSize
= sizeof(si
);
2730 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2731 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2732 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2733 "Vertical scrollbar is invisible, should be visible.\n");
2735 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 100,
2736 "reported page/range is %d (%d..%d) expected 0 (0..100)\n",
2737 si
.nPage
, si
.nMin
, si
.nMax
);
2740 /* Ditto, see above */
2741 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2742 memset(&si
, 0, sizeof(si
));
2743 si
.cbSize
= sizeof(si
);
2744 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2745 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2746 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2747 "Vertical scrollbar is invisible, should be visible.\n");
2749 ok(si
.nPage
== 0 && si
.nMin
== 0 && si
.nMax
== 100,
2750 "reported page/range is %d (%d..%d) expected 0 (0..100)\n",
2751 si
.nPage
, si
.nMin
, si
.nMax
);
2754 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2755 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2756 memset(&si
, 0, sizeof(si
));
2757 si
.cbSize
= sizeof(si
);
2758 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2759 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2760 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2761 "Vertical scrollbar is visible, should be invisible.\n");
2762 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2763 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2764 si
.nPage
, si
.nMin
, si
.nMax
);
2766 DestroyWindow(hwndRichEdit
);
2768 hwndRichEdit
= new_richedit(NULL
);
2770 ShowScrollBar(hwndRichEdit
, SB_VERT
, FALSE
);
2771 memset(&si
, 0, sizeof(si
));
2772 si
.cbSize
= sizeof(si
);
2773 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2774 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2775 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2776 "Vertical scrollbar is visible, should be invisible.\n");
2777 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2778 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2779 si
.nPage
, si
.nMin
, si
.nMax
);
2781 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2782 memset(&si
, 0, sizeof(si
));
2783 si
.cbSize
= sizeof(si
);
2784 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2785 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2786 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2787 "Vertical scrollbar is visible, should be invisible.\n");
2788 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2789 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2790 si
.nPage
, si
.nMin
, si
.nMax
);
2792 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2793 memset(&si
, 0, sizeof(si
));
2794 si
.cbSize
= sizeof(si
);
2795 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2796 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2797 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2798 "Vertical scrollbar is visible, should be invisible.\n");
2799 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2800 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2801 si
.nPage
, si
.nMin
, si
.nMax
);
2803 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2804 memset(&si
, 0, sizeof(si
));
2805 si
.cbSize
= sizeof(si
);
2806 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2807 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2808 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2809 "Vertical scrollbar is visible, should be invisible.\n");
2810 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2811 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2812 si
.nPage
, si
.nMin
, si
.nMax
);
2814 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2815 memset(&si
, 0, sizeof(si
));
2816 si
.cbSize
= sizeof(si
);
2817 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2818 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2819 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2820 "Vertical scrollbar is invisible, should be visible.\n");
2821 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2822 "reported page/range is %d (%d..%d)\n",
2823 si
.nPage
, si
.nMin
, si
.nMax
);
2825 /* Previously, builtin incorrectly re-shows explicitly hidden scrollbar */
2826 ShowScrollBar(hwndRichEdit
, SB_VERT
, FALSE
);
2827 memset(&si
, 0, sizeof(si
));
2828 si
.cbSize
= sizeof(si
);
2829 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2830 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2831 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2832 "Vertical scrollbar is visible, should be invisible.\n");
2833 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2834 "reported page/range is %d (%d..%d)\n",
2835 si
.nPage
, si
.nMin
, si
.nMax
);
2837 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2838 memset(&si
, 0, sizeof(si
));
2839 si
.cbSize
= sizeof(si
);
2840 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2841 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2842 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2843 "Vertical scrollbar is visible, should be invisible.\n");
2844 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2845 "reported page/range is %d (%d..%d)\n",
2846 si
.nPage
, si
.nMin
, si
.nMax
);
2848 /* Testing effect of EM_SCROLL on scrollbar visibility. It seems that
2849 EM_SCROLL will make visible any forcefully invisible scrollbar */
2850 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEDOWN
, 0);
2851 memset(&si
, 0, sizeof(si
));
2852 si
.cbSize
= sizeof(si
);
2853 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2854 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2855 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2856 "Vertical scrollbar is invisible, should be visible.\n");
2857 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2858 "reported page/range is %d (%d..%d)\n",
2859 si
.nPage
, si
.nMin
, si
.nMax
);
2861 ShowScrollBar(hwndRichEdit
, SB_VERT
, FALSE
);
2862 memset(&si
, 0, sizeof(si
));
2863 si
.cbSize
= sizeof(si
);
2864 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2865 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2866 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2867 "Vertical scrollbar is visible, should be invisible.\n");
2868 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2869 "reported page/range is %d (%d..%d)\n",
2870 si
.nPage
, si
.nMin
, si
.nMax
);
2872 /* Again, EM_SCROLL, with SB_LINEUP */
2873 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEUP
, 0);
2874 memset(&si
, 0, sizeof(si
));
2875 si
.cbSize
= sizeof(si
);
2876 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2877 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2878 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2879 "Vertical scrollbar is invisible, should be visible.\n");
2880 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2881 "reported page/range is %d (%d..%d)\n",
2882 si
.nPage
, si
.nMin
, si
.nMax
);
2884 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2885 memset(&si
, 0, sizeof(si
));
2886 si
.cbSize
= sizeof(si
);
2887 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2888 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2889 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2890 "Vertical scrollbar is visible, should be invisible.\n");
2891 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2892 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2893 si
.nPage
, si
.nMin
, si
.nMax
);
2895 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2896 memset(&si
, 0, sizeof(si
));
2897 si
.cbSize
= sizeof(si
);
2898 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2899 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2900 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2901 "Vertical scrollbar is invisible, should be visible.\n");
2902 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2903 "reported page/range is %d (%d..%d)\n",
2904 si
.nPage
, si
.nMin
, si
.nMax
);
2906 DestroyWindow(hwndRichEdit
);
2909 /* Test behavior with explicit visibility request, using SetWindowLong()() */
2910 hwndRichEdit
= new_richedit(NULL
);
2912 #define ENABLE_WS_VSCROLL(hwnd) \
2913 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_VSCROLL)
2914 #define DISABLE_WS_VSCROLL(hwnd) \
2915 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~WS_VSCROLL)
2917 /* Previously failed because builtin incorrectly re-hides scrollbar forced visible */
2918 ENABLE_WS_VSCROLL(hwndRichEdit
);
2919 memset(&si
, 0, sizeof(si
));
2920 si
.cbSize
= sizeof(si
);
2921 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2922 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2923 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2924 "Vertical scrollbar is invisible, should be visible.\n");
2925 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2926 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2927 si
.nPage
, si
.nMin
, si
.nMax
);
2929 /* Ditto, see above */
2930 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2931 memset(&si
, 0, sizeof(si
));
2932 si
.cbSize
= sizeof(si
);
2933 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2934 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2935 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2936 "Vertical scrollbar is invisible, should be visible.\n");
2937 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2938 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2939 si
.nPage
, si
.nMin
, si
.nMax
);
2941 /* Ditto, see above */
2942 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
2943 memset(&si
, 0, sizeof(si
));
2944 si
.cbSize
= sizeof(si
);
2945 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2946 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2947 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2948 "Vertical scrollbar is invisible, should be visible.\n");
2949 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2950 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2951 si
.nPage
, si
.nMin
, si
.nMax
);
2953 /* Ditto, see above */
2954 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a\na");
2955 memset(&si
, 0, sizeof(si
));
2956 si
.cbSize
= sizeof(si
);
2957 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2958 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2959 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2960 "Vertical scrollbar is invisible, should be visible.\n");
2961 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2962 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2963 si
.nPage
, si
.nMin
, si
.nMax
);
2965 /* Ditto, see above */
2966 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2967 memset(&si
, 0, sizeof(si
));
2968 si
.cbSize
= sizeof(si
);
2969 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2970 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2971 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
2972 "Vertical scrollbar is invisible, should be visible.\n");
2973 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
2974 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
2975 si
.nPage
, si
.nMin
, si
.nMax
);
2977 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
2978 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
2979 memset(&si
, 0, sizeof(si
));
2980 si
.cbSize
= sizeof(si
);
2981 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2982 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2983 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2984 "Vertical scrollbar is visible, should be invisible.\n");
2985 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
2986 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
2987 si
.nPage
, si
.nMin
, si
.nMax
);
2989 DestroyWindow(hwndRichEdit
);
2991 hwndRichEdit
= new_richedit(NULL
);
2993 DISABLE_WS_VSCROLL(hwndRichEdit
);
2994 memset(&si
, 0, sizeof(si
));
2995 si
.cbSize
= sizeof(si
);
2996 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
2997 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
2998 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
2999 "Vertical scrollbar is visible, should be invisible.\n");
3000 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
3001 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
3002 si
.nPage
, si
.nMin
, si
.nMax
);
3004 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
3005 memset(&si
, 0, sizeof(si
));
3006 si
.cbSize
= sizeof(si
);
3007 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3008 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3009 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3010 "Vertical scrollbar is visible, should be invisible.\n");
3011 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
3012 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
3013 si
.nPage
, si
.nMin
, si
.nMax
);
3015 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)"a");
3016 memset(&si
, 0, sizeof(si
));
3017 si
.cbSize
= sizeof(si
);
3018 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3019 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3020 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3021 "Vertical scrollbar is visible, should be invisible.\n");
3022 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
3023 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
3024 si
.nPage
, si
.nMin
, si
.nMax
);
3026 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
3027 memset(&si
, 0, sizeof(si
));
3028 si
.cbSize
= sizeof(si
);
3029 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3030 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3031 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3032 "Vertical scrollbar is visible, should be invisible.\n");
3033 ok(si
.nPage
== 0 && si
.nMin
== 0 && (si
.nMax
== 0 || si
.nMax
== 100),
3034 "reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
3035 si
.nPage
, si
.nMin
, si
.nMax
);
3037 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
3038 memset(&si
, 0, sizeof(si
));
3039 si
.cbSize
= sizeof(si
);
3040 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3041 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3042 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
3043 "Vertical scrollbar is invisible, should be visible.\n");
3044 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3045 "reported page/range is %d (%d..%d)\n",
3046 si
.nPage
, si
.nMin
, si
.nMax
);
3048 /* Previously, builtin incorrectly re-shows explicitly hidden scrollbar */
3049 DISABLE_WS_VSCROLL(hwndRichEdit
);
3050 memset(&si
, 0, sizeof(si
));
3051 si
.cbSize
= sizeof(si
);
3052 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3053 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3054 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3055 "Vertical scrollbar is visible, should be invisible.\n");
3056 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3057 "reported page/range is %d (%d..%d)\n",
3058 si
.nPage
, si
.nMin
, si
.nMax
);
3060 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
3061 memset(&si
, 0, sizeof(si
));
3062 si
.cbSize
= sizeof(si
);
3063 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3064 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3065 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3066 "Vertical scrollbar is visible, should be invisible.\n");
3067 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3068 "reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
3069 si
.nPage
, si
.nMin
, si
.nMax
);
3071 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)text
);
3072 memset(&si
, 0, sizeof(si
));
3073 si
.cbSize
= sizeof(si
);
3074 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3075 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3076 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
3077 "Vertical scrollbar is invisible, should be visible.\n");
3078 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3079 "reported page/range is %d (%d..%d)\n",
3080 si
.nPage
, si
.nMin
, si
.nMax
);
3082 DISABLE_WS_VSCROLL(hwndRichEdit
);
3083 memset(&si
, 0, sizeof(si
));
3084 si
.cbSize
= sizeof(si
);
3085 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3086 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3087 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3088 "Vertical scrollbar is visible, should be invisible.\n");
3089 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3090 "reported page/range is %d (%d..%d)\n",
3091 si
.nPage
, si
.nMin
, si
.nMax
);
3093 /* Testing effect of EM_SCROLL on scrollbar visibility. It seems that
3094 EM_SCROLL will make visible any forcefully invisible scrollbar */
3095 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEDOWN
, 0);
3096 memset(&si
, 0, sizeof(si
));
3097 si
.cbSize
= sizeof(si
);
3098 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3099 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3100 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
3101 "Vertical scrollbar is invisible, should be visible.\n");
3102 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3103 "reported page/range is %d (%d..%d)\n",
3104 si
.nPage
, si
.nMin
, si
.nMax
);
3106 DISABLE_WS_VSCROLL(hwndRichEdit
);
3107 memset(&si
, 0, sizeof(si
));
3108 si
.cbSize
= sizeof(si
);
3109 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3110 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3111 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) == 0),
3112 "Vertical scrollbar is visible, should be invisible.\n");
3113 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3114 "reported page/range is %d (%d..%d)\n",
3115 si
.nPage
, si
.nMin
, si
.nMax
);
3117 /* Again, EM_SCROLL, with SB_LINEUP */
3118 SendMessage(hwndRichEdit
, EM_SCROLL
, SB_LINEUP
, 0);
3119 memset(&si
, 0, sizeof(si
));
3120 si
.cbSize
= sizeof(si
);
3121 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3122 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3123 ok (((GetWindowLongA(hwndRichEdit
, GWL_STYLE
) & WS_VSCROLL
) != 0),
3124 "Vertical scrollbar is invisible, should be visible.\n");
3125 ok(si
.nPage
!= 0 && si
.nMin
== 0 && si
.nMax
!= 0,
3126 "reported page/range is %d (%d..%d)\n",
3127 si
.nPage
, si
.nMin
, si
.nMax
);
3129 DestroyWindow(hwndRichEdit
);
3131 /* This window proc models what is going on with Corman Lisp 3.0.
3132 At WM_SIZE, this proc unconditionally calls ShowScrollBar() to
3133 force the scrollbar into visibility. Recursion should NOT happen
3134 as a result of this action.
3136 r
= GetClassInfoA(NULL
, RICHEDIT_CLASS
, &cls
);
3138 richeditProc
= cls
.lpfnWndProc
;
3139 cls
.lpfnWndProc
= RicheditStupidOverrideProcA
;
3140 cls
.lpszClassName
= "RicheditStupidOverride";
3141 if(!RegisterClassA(&cls
)) assert(0);
3144 WM_SIZE_recursionLevel
= 0;
3145 bailedOutOfRecursion
= FALSE
;
3146 hwndRichEdit
= new_window(cls
.lpszClassName
, ES_MULTILINE
, NULL
);
3147 ok(!bailedOutOfRecursion
,
3148 "WM_SIZE/scrollbar mutual recursion detected, expected none!\n");
3151 WM_SIZE_recursionLevel
= 0;
3152 bailedOutOfRecursion
= FALSE
;
3153 MoveWindow(hwndRichEdit
, 0, 0, 250, 100, TRUE
);
3154 ok(!bailedOutOfRecursion
,
3155 "WM_SIZE/scrollbar mutual recursion detected, expected none!\n");
3157 /* Unblock window in order to process WM_DESTROY */
3159 bailedOutOfRecursion
= FALSE
;
3160 WM_SIZE_recursionLevel
= 0;
3161 DestroyWindow(hwndRichEdit
);
3165 static void test_EM_SETUNDOLIMIT(void)
3167 /* cases we test for:
3168 * default behaviour - limiting at 100 undo's
3169 * undo disabled - setting a limit of 0
3170 * undo limited - undo limit set to some to some number, like 2
3171 * bad input - sending a negative number should default to 100 undo's */
3173 HWND hwndRichEdit
= new_richedit(NULL
);
3178 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "x");
3181 SendMessage(hwndRichEdit
, WM_COPY
, 0, 0);
3182 /*Load "x" into the clipboard. Paste is an easy, undo'able operation.
3183 also, multiple pastes don't combine like WM_CHAR would */
3184 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
3186 /* first case - check the default */
3187 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0,0);
3188 for (i
=0; i
<101; i
++) /* Put 101 undo's on the stack */
3189 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
3190 for (i
=0; i
<100; i
++) /* Undo 100 of them */
3191 SendMessage(hwndRichEdit
, WM_UNDO
, 0, 0);
3192 ok(!SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0),
3193 "EM_SETUNDOLIMIT allowed more than a hundred undo's by default.\n");
3195 /* second case - cannot undo */
3196 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0, 0);
3197 SendMessage(hwndRichEdit
, EM_SETUNDOLIMIT
, 0, 0);
3198 SendMessage(hwndRichEdit
,
3199 WM_PASTE
, 0, 0); /* Try to put something in the undo stack */
3200 ok(!SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0),
3201 "EM_SETUNDOLIMIT allowed undo with UNDOLIMIT set to 0\n");
3203 /* third case - set it to an arbitrary number */
3204 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0, 0);
3205 SendMessage(hwndRichEdit
, EM_SETUNDOLIMIT
, 2, 0);
3206 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
3207 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
3208 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
3209 /* If SETUNDOLIMIT is working, there should only be two undo's after this */
3210 ok(SendMessage(hwndRichEdit
, EM_CANUNDO
, 0,0),
3211 "EM_SETUNDOLIMIT didn't allow the first undo with UNDOLIMIT set to 2\n");
3212 SendMessage(hwndRichEdit
, WM_UNDO
, 0, 0);
3213 ok(SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0),
3214 "EM_SETUNDOLIMIT didn't allow a second undo with UNDOLIMIT set to 2\n");
3215 SendMessage(hwndRichEdit
, WM_UNDO
, 0, 0);
3216 ok(!SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0),
3217 "EM_SETUNDOLIMIT allowed a third undo with UNDOLIMIT set to 2\n");
3219 /* fourth case - setting negative numbers should default to 100 undos */
3220 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0,0);
3221 result
= SendMessage(hwndRichEdit
, EM_SETUNDOLIMIT
, -1, 0);
3223 "EM_SETUNDOLIMIT returned %d when set to -1, instead of 100\n",result
);
3225 DestroyWindow(hwndRichEdit
);
3228 static void test_ES_PASSWORD(void)
3230 /* This isn't hugely testable, so we're just going to run it through its paces */
3232 HWND hwndRichEdit
= new_richedit(NULL
);
3235 /* First, check the default of a regular control */
3236 result
= SendMessage(hwndRichEdit
, EM_GETPASSWORDCHAR
, 0, 0);
3238 "EM_GETPASSWORDCHAR returned %c by default, instead of NULL\n",result
);
3240 /* Now, set it to something normal */
3241 SendMessage(hwndRichEdit
, EM_SETPASSWORDCHAR
, 'x', 0);
3242 result
= SendMessage(hwndRichEdit
, EM_GETPASSWORDCHAR
, 0, 0);
3244 "EM_GETPASSWORDCHAR returned %c (%d) when set to 'x', instead of x (120)\n",result
,result
);
3246 /* Now, set it to something odd */
3247 SendMessage(hwndRichEdit
, EM_SETPASSWORDCHAR
, (WCHAR
)1234, 0);
3248 result
= SendMessage(hwndRichEdit
, EM_GETPASSWORDCHAR
, 0, 0);
3250 "EM_GETPASSWORDCHAR returned %c (%d) when set to 'x', instead of x (120)\n",result
,result
);
3251 DestroyWindow(hwndRichEdit
);
3254 static DWORD CALLBACK
test_WM_SETTEXT_esCallback(DWORD_PTR dwCookie
,
3259 char** str
= (char**)dwCookie
;
3262 memcpy(*str
, pbBuff
, *pcb
);
3268 static void test_WM_SETTEXT(void)
3270 HWND hwndRichEdit
= new_richedit(NULL
);
3271 const char * TestItem1
= "TestSomeText";
3272 const char * TestItem2
= "TestSomeText\r";
3273 const char * TestItem2_after
= "TestSomeText\r\n";
3274 const char * TestItem3
= "TestSomeText\rSomeMoreText\r";
3275 const char * TestItem3_after
= "TestSomeText\r\nSomeMoreText\r\n";
3276 const char * TestItem4
= "TestSomeText\n\nTestSomeText";
3277 const char * TestItem4_after
= "TestSomeText\r\n\r\nTestSomeText";
3278 const char * TestItem5
= "TestSomeText\r\r\nTestSomeText";
3279 const char * TestItem5_after
= "TestSomeText TestSomeText";
3280 const char * TestItem6
= "TestSomeText\r\r\n\rTestSomeText";
3281 const char * TestItem6_after
= "TestSomeText \r\nTestSomeText";
3282 const char * TestItem7
= "TestSomeText\r\n\r\r\n\rTestSomeText";
3283 const char * TestItem7_after
= "TestSomeText\r\n \r\nTestSomeText";
3285 char buf
[1024] = {0};
3290 /* This test attempts to show that WM_SETTEXT on a riched20 control causes
3291 any solitary \r to be converted to \r\n on return. Properly paired
3292 \r\n are not affected. It also shows that the special sequence \r\r\n
3293 gets converted to a single space.
3296 #define TEST_SETTEXT(a, b) \
3297 result = SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) a); \
3298 ok (result == 1, "WM_SETTEXT returned %ld instead of 1\n", result); \
3299 result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buf); \
3300 ok (result == lstrlen(buf), \
3301 "WM_GETTEXT returned %ld instead of expected %u\n", \
3302 result, lstrlen(buf)); \
3303 result = strcmp(b, buf); \
3305 "WM_SETTEXT round trip: strcmp = %ld\n", result);
3307 TEST_SETTEXT(TestItem1
, TestItem1
)
3308 TEST_SETTEXT(TestItem2
, TestItem2_after
)
3309 TEST_SETTEXT(TestItem3
, TestItem3_after
)
3310 TEST_SETTEXT(TestItem3_after
, TestItem3_after
)
3311 TEST_SETTEXT(TestItem4
, TestItem4_after
)
3312 TEST_SETTEXT(TestItem5
, TestItem5_after
)
3313 TEST_SETTEXT(TestItem6
, TestItem6_after
)
3314 TEST_SETTEXT(TestItem7
, TestItem7_after
)
3316 /* The following test demonstrates that WM_SETTEXT supports RTF strings */
3317 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) TestItem1
);
3319 es
.dwCookie
= (DWORD_PTR
)&p
;
3321 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3322 memset(buf
, 0, sizeof(buf
));
3323 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3324 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
3325 trace("EM_STREAMOUT produced:\n%s\n", buf
);
3326 TEST_SETTEXT(buf
, TestItem1
)
3329 DestroyWindow(hwndRichEdit
);
3332 static void test_EM_STREAMOUT(void)
3334 HWND hwndRichEdit
= new_richedit(NULL
);
3337 char buf
[1024] = {0};
3340 const char * TestItem1
= "TestSomeText";
3341 const char * TestItem2
= "TestSomeText\r";
3342 const char * TestItem3
= "TestSomeText\r\n";
3344 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) TestItem1
);
3346 es
.dwCookie
= (DWORD_PTR
)&p
;
3348 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3349 memset(buf
, 0, sizeof(buf
));
3350 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3351 (WPARAM
)(SF_TEXT
), (LPARAM
)&es
);
3353 ok(r
== 12, "streamed text length is %d, expecting 12\n", r
);
3354 ok(strcmp(buf
, TestItem1
) == 0,
3355 "streamed text different, got %s\n", buf
);
3357 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) TestItem2
);
3359 es
.dwCookie
= (DWORD_PTR
)&p
;
3361 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3362 memset(buf
, 0, sizeof(buf
));
3363 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3364 (WPARAM
)(SF_TEXT
), (LPARAM
)&es
);
3366 /* Here again, \r gets converted to \r\n, like WM_GETTEXT */
3367 ok(r
== 14, "streamed text length is %d, expecting 14\n", r
);
3368 ok(strcmp(buf
, TestItem3
) == 0,
3369 "streamed text different from, got %s\n", buf
);
3370 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) TestItem3
);
3372 es
.dwCookie
= (DWORD_PTR
)&p
;
3374 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3375 memset(buf
, 0, sizeof(buf
));
3376 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3377 (WPARAM
)(SF_TEXT
), (LPARAM
)&es
);
3379 ok(r
== 14, "streamed text length is %d, expecting 14\n", r
);
3380 ok(strcmp(buf
, TestItem3
) == 0,
3381 "streamed text different, got %s\n", buf
);
3383 DestroyWindow(hwndRichEdit
);
3386 static void test_EM_STREAMOUT_FONTTBL(void)
3388 HWND hwndRichEdit
= new_richedit(NULL
);
3390 char buf
[1024] = {0};
3395 const char * TestItem
= "TestSomeText";
3397 /* fills in the richedit control with some text */
3398 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) TestItem
);
3400 /* streams out the text in rtf format */
3402 es
.dwCookie
= (DWORD_PTR
)&p
;
3404 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3405 memset(buf
, 0, sizeof(buf
));
3406 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3407 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
3409 /* scans for \fonttbl, error if not found */
3410 fontTbl
= strstr(buf
, "\\fonttbl");
3411 ok(fontTbl
!= NULL
, "missing \\fonttbl section\n");
3414 /* scans for terminating closing bracket */
3416 while(*fontTbl
&& brackCount
)
3420 else if(*fontTbl
== '}')
3424 /* checks wether closing bracket is ok */
3425 ok(brackCount
== 0, "missing closing bracket in \\fonttbl block\n");
3428 /* char before closing fonttbl block should be a closed bracket */
3430 ok(*fontTbl
== '}', "spurious character '%02x' before \\fonttbl closing bracket\n", *fontTbl
);
3432 /* char after fonttbl block should be a crlf */
3434 ok(*fontTbl
== 0x0d && *(fontTbl
+1) == 0x0a, "missing crlf after \\fonttbl block\n");
3437 DestroyWindow(hwndRichEdit
);
3441 static void test_EM_SETTEXTEX(void)
3443 HWND hwndRichEdit
, parent
;
3445 int sel_start
, sel_end
;
3448 WCHAR TestItem1
[] = {'T', 'e', 's', 't',
3450 'T', 'e', 'x', 't', 0};
3451 WCHAR TestItem1alt
[] = {'T', 'T', 'e', 's',
3457 WCHAR TestItem1altn
[] = {'T','T','e','s','t','S','o','m','e','T','e','x','t',
3458 '\r','t','S','o','m','e','T','e','x','t',0};
3459 WCHAR TestItem2
[] = {'T', 'e', 's', 't',
3463 const char * TestItem2_after
= "TestSomeText\r\n";
3464 WCHAR TestItem3
[] = {'T', 'e', 's', 't',
3467 '\r','\n','\r','\n', 0};
3468 WCHAR TestItem3alt
[] = {'T', 'e', 's', 't',
3472 WCHAR TestItem3_after
[] = {'T', 'e', 's', 't',
3476 WCHAR TestItem4
[] = {'T', 'e', 's', 't',
3479 '\r','\r','\n','\r',
3481 WCHAR TestItem4_after
[] = {'T', 'e', 's', 't',
3485 #define MAX_BUF_LEN 1024
3486 WCHAR buf
[MAX_BUF_LEN
];
3487 char bufACP
[MAX_BUF_LEN
];
3494 /* Test the scroll position with and without a parent window.
3496 * For some reason the scroll position is 0 after EM_SETTEXTEX
3497 * with the ST_SELECTION flag only when the control has a parent
3498 * window, even though the selection is at the end. */
3500 cls
.lpfnWndProc
= DefWindowProcA
;
3503 cls
.hInstance
= GetModuleHandleA(0);
3505 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
3506 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3507 cls
.lpszMenuName
= NULL
;
3508 cls
.lpszClassName
= "ParentTestClass";
3509 if(!RegisterClassA(&cls
)) assert(0);
3511 parent
= CreateWindow(cls
.lpszClassName
, NULL
, WS_POPUP
|WS_VISIBLE
,
3512 0, 0, 200, 60, NULL
, NULL
, NULL
, NULL
);
3513 ok (parent
!= 0, "Failed to create parent window\n");
3515 hwndRichEdit
= CreateWindowEx(0,
3516 RICHEDIT_CLASS
, NULL
,
3517 ES_MULTILINE
|WS_VSCROLL
|WS_VISIBLE
|WS_CHILD
,
3518 0, 0, 200, 60, parent
, NULL
,
3519 hmoduleRichEdit
, NULL
);
3521 setText
.codepage
= CP_ACP
;
3522 setText
.flags
= ST_SELECTION
;
3523 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
,
3524 (LPARAM
)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
3525 si
.cbSize
= sizeof(si
);
3527 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3528 todo_wine
ok(si
.nPos
== 0, "Position is incorrectly at %d\n", si
.nPos
);
3529 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
3530 ok(sel_start
== 18, "Selection start incorrectly at %d\n", sel_start
);
3531 ok(sel_end
== 18, "Selection end incorrectly at %d\n", sel_end
);
3533 DestroyWindow(parent
);
3535 /* Test without a parent window */
3536 hwndRichEdit
= new_richedit(NULL
);
3537 setText
.codepage
= CP_ACP
;
3538 setText
.flags
= ST_SELECTION
;
3539 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
,
3540 (LPARAM
)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
3541 si
.cbSize
= sizeof(si
);
3543 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3544 ok(si
.nPos
!= 0, "Position is incorrectly at %d\n", si
.nPos
);
3545 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
3546 ok(sel_start
== 18, "Selection start incorrectly at %d\n", sel_start
);
3547 ok(sel_end
== 18, "Selection end incorrectly at %d\n", sel_end
);
3549 /* The scroll position should also be 0 after EM_SETTEXTEX with ST_DEFAULT,
3550 * but this time it is because the selection is at the beginning. */
3551 setText
.codepage
= CP_ACP
;
3552 setText
.flags
= ST_DEFAULT
;
3553 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
,
3554 (LPARAM
)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
3555 si
.cbSize
= sizeof(si
);
3557 GetScrollInfo(hwndRichEdit
, SB_VERT
, &si
);
3558 ok(si
.nPos
== 0, "Position is incorrectly at %d\n", si
.nPos
);
3559 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
3560 ok(sel_start
== 0, "Selection start incorrectly at %d\n", sel_start
);
3561 ok(sel_end
== 0, "Selection end incorrectly at %d\n", sel_end
);
3563 setText
.codepage
= 1200; /* no constant for unicode */
3564 getText
.codepage
= 1200; /* no constant for unicode */
3565 getText
.cb
= MAX_BUF_LEN
;
3566 getText
.flags
= GT_DEFAULT
;
3567 getText
.lpDefaultChar
= NULL
;
3568 getText
.lpUsedDefChar
= NULL
;
3571 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem1
);
3572 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3573 ok(lstrcmpW(buf
, TestItem1
) == 0,
3574 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
3576 /* Unlike WM_SETTEXT/WM_GETTEXT pair, EM_SETTEXTEX/EM_GETTEXTEX does not
3577 convert \r to \r\n on return: !ST_SELECTION && Unicode && !\rtf
3579 setText
.codepage
= 1200; /* no constant for unicode */
3580 getText
.codepage
= 1200; /* no constant for unicode */
3581 getText
.cb
= MAX_BUF_LEN
;
3582 getText
.flags
= GT_DEFAULT
;
3583 getText
.lpDefaultChar
= NULL
;
3584 getText
.lpUsedDefChar
= NULL
;
3586 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem2
);
3587 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3588 ok(lstrcmpW(buf
, TestItem2
) == 0,
3589 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
3591 /* However, WM_GETTEXT *does* see \r\n where EM_GETTEXTEX would see \r */
3592 SendMessage(hwndRichEdit
, WM_GETTEXT
, MAX_BUF_LEN
, (LPARAM
)buf
);
3593 ok(strcmp((const char *)buf
, TestItem2_after
) == 0,
3594 "WM_GETTEXT did *not* see \\r converted to \\r\\n pairs.\n");
3596 /* Baseline test for just-enough buffer space for string */
3597 getText
.cb
= (lstrlenW(TestItem2
) + 1) * sizeof(WCHAR
);
3598 getText
.codepage
= 1200; /* no constant for unicode */
3599 getText
.flags
= GT_DEFAULT
;
3600 getText
.lpDefaultChar
= NULL
;
3601 getText
.lpUsedDefChar
= NULL
;
3602 memset(buf
, 0, MAX_BUF_LEN
);
3603 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3604 ok(lstrcmpW(buf
, TestItem2
) == 0,
3605 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
3607 /* When there is enough space for one character, but not both, of the CRLF
3608 pair at the end of the string, the CR is not copied at all. That is,
3609 the caller must not see CRLF pairs truncated to CR at the end of the
3612 getText
.cb
= (lstrlenW(TestItem2
) + 1) * sizeof(WCHAR
);
3613 getText
.codepage
= 1200; /* no constant for unicode */
3614 getText
.flags
= GT_USECRLF
; /* <-- asking for CR -> CRLF conversion */
3615 getText
.lpDefaultChar
= NULL
;
3616 getText
.lpUsedDefChar
= NULL
;
3617 memset(buf
, 0, MAX_BUF_LEN
);
3618 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3619 ok(lstrcmpW(buf
, TestItem1
) == 0,
3620 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
3623 /* \r\n pairs get changed into \r: !ST_SELECTION && Unicode && !\rtf */
3624 setText
.codepage
= 1200; /* no constant for unicode */
3625 getText
.codepage
= 1200; /* no constant for unicode */
3626 getText
.cb
= MAX_BUF_LEN
;
3627 getText
.flags
= GT_DEFAULT
;
3628 getText
.lpDefaultChar
= NULL
;
3629 getText
.lpUsedDefChar
= NULL
;
3631 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem3
);
3632 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3633 ok(lstrcmpW(buf
, TestItem3_after
) == 0,
3634 "EM_SETTEXTEX did not convert properly\n");
3636 /* \n also gets changed to \r: !ST_SELECTION && Unicode && !\rtf */
3637 setText
.codepage
= 1200; /* no constant for unicode */
3638 getText
.codepage
= 1200; /* no constant for unicode */
3639 getText
.cb
= MAX_BUF_LEN
;
3640 getText
.flags
= GT_DEFAULT
;
3641 getText
.lpDefaultChar
= NULL
;
3642 getText
.lpUsedDefChar
= NULL
;
3644 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem3alt
);
3645 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3646 ok(lstrcmpW(buf
, TestItem3_after
) == 0,
3647 "EM_SETTEXTEX did not convert properly\n");
3649 /* \r\r\n gets changed into single space: !ST_SELECTION && Unicode && !\rtf */
3650 setText
.codepage
= 1200; /* no constant for unicode */
3651 getText
.codepage
= 1200; /* no constant for unicode */
3652 getText
.cb
= MAX_BUF_LEN
;
3653 getText
.flags
= GT_DEFAULT
;
3654 getText
.lpDefaultChar
= NULL
;
3655 getText
.lpUsedDefChar
= NULL
;
3657 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem4
);
3658 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3659 ok(lstrcmpW(buf
, TestItem4_after
) == 0,
3660 "EM_SETTEXTEX did not convert properly\n");
3662 /* !ST_SELECTION && Unicode && !\rtf */
3663 result
= SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, 0);
3664 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3667 "EM_SETTEXTEX returned %d, instead of 1\n",result
);
3668 ok(lstrlenW(buf
) == 0,
3669 "EM_SETTEXTEX with NULL lParam should clear rich edit.\n");
3671 /* put some text back: !ST_SELECTION && Unicode && !\rtf */
3673 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem1
);
3674 /* select some text */
3677 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
3678 /* replace current selection: ST_SELECTION && Unicode && !\rtf */
3679 setText
.flags
= ST_SELECTION
;
3680 result
= SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, 0);
3682 "EM_SETTEXTEX with NULL lParam to replace selection"
3683 " with no text should return 0. Got %i\n",
3686 /* put some text back: !ST_SELECTION && Unicode && !\rtf */
3688 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem1
);
3689 /* select some text */
3692 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
3693 /* replace current selection: ST_SELECTION && Unicode && !\rtf */
3694 setText
.flags
= ST_SELECTION
;
3695 result
= SendMessage(hwndRichEdit
, EM_SETTEXTEX
,
3696 (WPARAM
)&setText
, (LPARAM
) TestItem1
);
3698 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3699 ok(result
== lstrlenW(TestItem1
),
3700 "EM_SETTEXTEX with NULL lParam to replace selection"
3701 " with no text should return 0. Got %i\n",
3703 ok(lstrlenW(buf
) == 22,
3704 "EM_SETTEXTEX to replace selection with more text failed: %i.\n",
3707 /* The following test demonstrates that EM_SETTEXTEX supports RTF strings */
3708 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "TestSomeText"); /* TestItem1 */
3710 es
.dwCookie
= (DWORD_PTR
)&p
;
3712 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3713 memset(buf
, 0, sizeof(buf
));
3714 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3715 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
3716 trace("EM_STREAMOUT produced:\n%s\n", (char *)buf
);
3718 /* !ST_SELECTION && !Unicode && \rtf */
3719 setText
.codepage
= CP_ACP
;/* EM_STREAMOUT saved as ANSI string */
3720 getText
.codepage
= 1200; /* no constant for unicode */
3721 getText
.cb
= MAX_BUF_LEN
;
3722 getText
.flags
= GT_DEFAULT
;
3723 getText
.lpDefaultChar
= NULL
;
3724 getText
.lpUsedDefChar
= NULL
;
3727 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) buf
);
3728 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3729 ok(lstrcmpW(buf
, TestItem1
) == 0,
3730 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
3732 /* The following test demonstrates that EM_SETTEXTEX treats text as ASCII if it
3733 * starts with ASCII characters "{\rtf" even when the codepage is unicode. */
3734 setText
.codepage
= 1200; /* Lie about code page (actual ASCII) */
3735 getText
.codepage
= CP_ACP
;
3736 getText
.cb
= MAX_BUF_LEN
;
3737 getText
.flags
= GT_DEFAULT
;
3738 getText
.lpDefaultChar
= NULL
;
3739 getText
.lpUsedDefChar
= NULL
;
3741 setText
.flags
= ST_SELECTION
;
3742 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1);
3743 result
= SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) "{\\rtf not unicode}");
3744 todo_wine
ok(result
== 11, "EM_SETTEXTEX incorrectly returned %d\n", result
);
3745 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) bufACP
);
3746 ok(lstrcmpA(bufACP
, "not unicode") == 0, "'%s' != 'not unicode'\n", bufACP
);
3748 /* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
3749 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "TestSomeText"); /* TestItem1 */
3751 es
.dwCookie
= (DWORD_PTR
)&p
;
3753 es
.pfnCallback
= test_WM_SETTEXT_esCallback
;
3754 memset(buf
, 0, sizeof(buf
));
3755 SendMessage(hwndRichEdit
, EM_STREAMOUT
,
3756 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
3757 trace("EM_STREAMOUT produced:\n%s\n", (char *)buf
);
3759 /* select some text */
3762 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
3764 /* ST_SELECTION && !Unicode && \rtf */
3765 setText
.codepage
= CP_ACP
;/* EM_STREAMOUT saved as ANSI string */
3766 getText
.codepage
= 1200; /* no constant for unicode */
3767 getText
.cb
= MAX_BUF_LEN
;
3768 getText
.flags
= GT_DEFAULT
;
3769 getText
.lpDefaultChar
= NULL
;
3770 getText
.lpUsedDefChar
= NULL
;
3772 setText
.flags
= ST_SELECTION
;
3773 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) buf
);
3774 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3775 ok_w3("Expected \"%s\" or \"%s\", got \"%s\"\n", TestItem1alt
, TestItem1altn
, buf
);
3777 /* The following test demonstrates that EM_SETTEXTEX replacing a selection */
3778 setText
.codepage
= 1200; /* no constant for unicode */
3779 getText
.codepage
= CP_ACP
;
3780 getText
.cb
= MAX_BUF_LEN
;
3783 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) TestItem1
); /* TestItem1 */
3784 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) bufACP
);
3786 /* select some text */
3789 SendMessage(hwndRichEdit
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
3791 /* ST_SELECTION && !Unicode && !\rtf */
3792 setText
.codepage
= CP_ACP
;
3793 getText
.codepage
= 1200; /* no constant for unicode */
3794 getText
.cb
= MAX_BUF_LEN
;
3795 getText
.flags
= GT_DEFAULT
;
3796 getText
.lpDefaultChar
= NULL
;
3797 getText
.lpUsedDefChar
= NULL
;
3799 setText
.flags
= ST_SELECTION
;
3800 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
) bufACP
);
3801 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buf
);
3802 ok(lstrcmpW(buf
, TestItem1alt
) == 0,
3803 "EM_GETTEXTEX results not what was set by EM_SETTEXTEX when"
3804 " using ST_SELECTION and non-Unicode\n");
3806 /* Test setting text using rich text format */
3808 setText
.codepage
= CP_ACP
;
3809 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
)"{\\rtf richtext}");
3810 getText
.codepage
= CP_ACP
;
3811 getText
.cb
= MAX_BUF_LEN
;
3812 getText
.flags
= GT_DEFAULT
;
3813 getText
.lpDefaultChar
= NULL
;
3814 getText
.lpUsedDefChar
= NULL
;
3815 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) bufACP
);
3816 ok(!strcmp(bufACP
, "richtext"), "expected 'richtext' but got '%s'\n", bufACP
);
3819 setText
.codepage
= CP_ACP
;
3820 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
)"{\\urtf morerichtext}");
3821 getText
.codepage
= CP_ACP
;
3822 getText
.cb
= MAX_BUF_LEN
;
3823 getText
.flags
= GT_DEFAULT
;
3824 getText
.lpDefaultChar
= NULL
;
3825 getText
.lpUsedDefChar
= NULL
;
3826 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) bufACP
);
3827 ok(!strcmp(bufACP
, "morerichtext"), "expected 'morerichtext' but got '%s'\n", bufACP
);
3829 DestroyWindow(hwndRichEdit
);
3832 static void test_EM_LIMITTEXT(void)
3836 HWND hwndRichEdit
= new_richedit(NULL
);
3838 /* The main purpose of this test is to demonstrate that the nonsense in MSDN
3839 * about setting the length to -1 for multiline edit controls doesn't happen.
3842 /* Don't check default gettextlimit case. That's done in other tests */
3844 /* Set textlimit to 100 */
3845 SendMessage (hwndRichEdit
, EM_LIMITTEXT
, 100, 0);
3846 ret
= SendMessage (hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3848 "EM_LIMITTEXT: set to 100, returned: %d, expected: 100\n", ret
);
3850 /* Set textlimit to 0 */
3851 SendMessage (hwndRichEdit
, EM_LIMITTEXT
, 0, 0);
3852 ret
= SendMessage (hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3854 "EM_LIMITTEXT: set to 0, returned: %d, expected: 65536\n", ret
);
3856 /* Set textlimit to -1 */
3857 SendMessage (hwndRichEdit
, EM_LIMITTEXT
, -1, 0);
3858 ret
= SendMessage (hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3860 "EM_LIMITTEXT: set to -1, returned: %d, expected: -1\n", ret
);
3862 /* Set textlimit to -2 */
3863 SendMessage (hwndRichEdit
, EM_LIMITTEXT
, -2, 0);
3864 ret
= SendMessage (hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3866 "EM_LIMITTEXT: set to -2, returned: %d, expected: -2\n", ret
);
3868 DestroyWindow (hwndRichEdit
);
3872 static void test_EM_EXLIMITTEXT(void)
3874 int i
, selBegin
, selEnd
, len1
, len2
;
3876 char text
[1024 + 1];
3877 char buffer
[1024 + 1];
3878 int textlimit
= 0; /* multiple of 100 */
3879 HWND hwndRichEdit
= new_richedit(NULL
);
3881 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3882 ok(32767 == i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 32767, i
); /* default */
3885 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
);
3886 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3888 ok(textlimit
== i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", textlimit
, i
);
3891 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
);
3892 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3894 ok(textlimit
== i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", textlimit
, i
);
3896 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, 0);
3897 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3898 /* default for WParam = 0 */
3899 ok(65536 == i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 65536, i
);
3901 textlimit
= sizeof(text
)-1;
3902 memset(text
, 'W', textlimit
);
3903 text
[sizeof(text
)-1] = 0;
3904 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
);
3905 /* maxed out text */
3906 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
3908 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1); /* select everything */
3909 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&selBegin
, (LPARAM
)&selEnd
);
3910 len1
= selEnd
- selBegin
;
3912 SendMessage(hwndRichEdit
, WM_KEYDOWN
, VK_BACK
, 1);
3913 SendMessage(hwndRichEdit
, WM_CHAR
, VK_BACK
, 1);
3914 SendMessage(hwndRichEdit
, WM_KEYUP
, VK_BACK
, 1);
3915 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1);
3916 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&selBegin
, (LPARAM
)&selEnd
);
3917 len2
= selEnd
- selBegin
;
3920 "EM_EXLIMITTEXT: Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
3923 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'A', 1);
3924 SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 1);
3925 SendMessage(hwndRichEdit
, WM_KEYUP
, 'A', 1);
3926 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1);
3927 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&selBegin
, (LPARAM
)&selEnd
);
3928 len1
= selEnd
- selBegin
;
3931 "EM_EXLIMITTEXT: Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
3934 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'A', 1);
3935 SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 1);
3936 SendMessage(hwndRichEdit
, WM_KEYUP
, 'A', 1); /* full; should be no effect */
3937 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1);
3938 SendMessage(hwndRichEdit
, EM_GETSEL
, (WPARAM
)&selBegin
, (LPARAM
)&selEnd
);
3939 len2
= selEnd
- selBegin
;
3942 "EM_EXLIMITTEXT: No Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
3945 /* set text up to the limit, select all the text, then add a char */
3947 memset(text
, 'W', textlimit
);
3948 text
[textlimit
] = 0;
3949 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
);
3950 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
3951 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1);
3952 SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 1);
3953 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
3954 result
= strcmp(buffer
, "A");
3955 ok(0 == result
, "got string = \"%s\"\n", buffer
);
3957 /* WM_SETTEXT not limited */
3959 memset(text
, 'W', textlimit
);
3960 text
[textlimit
] = 0;
3961 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
-5);
3962 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text
);
3963 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
3965 ok(10 == i
, "expected 10 chars\n");
3966 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3967 ok(10 == i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i
);
3969 /* try inserting more text at end */
3970 i
= SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
3971 ok(0 == i
, "WM_CHAR wasn't processed\n");
3972 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
3974 ok(10 == i
, "expected 10 chars, got %i\n", i
);
3975 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3976 ok(10 == i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i
);
3978 /* try inserting text at beginning */
3979 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 0);
3980 i
= SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
3981 ok(0 == i
, "WM_CHAR wasn't processed\n");
3982 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
3984 ok(10 == i
, "expected 10 chars, got %i\n", i
);
3985 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
3986 ok(10 == i
, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i
);
3988 /* WM_CHAR is limited */
3990 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, textlimit
);
3991 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, -1); /* select everything */
3992 i
= SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
3993 ok(0 == i
, "WM_CHAR wasn't processed\n");
3994 i
= SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
3995 ok(0 == i
, "WM_CHAR wasn't processed\n");
3996 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
3998 ok(1 == i
, "expected 1 chars, got %i instead\n", i
);
4000 DestroyWindow(hwndRichEdit
);
4003 static void test_EM_GETLIMITTEXT(void)
4006 HWND hwndRichEdit
= new_richedit(NULL
);
4008 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
4009 ok(32767 == i
, "expected: %d, actual: %d\n", 32767, i
); /* default value */
4011 SendMessage(hwndRichEdit
, EM_EXLIMITTEXT
, 0, 50000);
4012 i
= SendMessage(hwndRichEdit
, EM_GETLIMITTEXT
, 0, 0);
4013 ok(50000 == i
, "expected: %d, actual: %d\n", 50000, i
);
4015 DestroyWindow(hwndRichEdit
);
4018 static void test_WM_SETFONT(void)
4020 /* There is no invalid input or error conditions for this function.
4021 * NULL wParam and lParam just fall back to their default values
4022 * It should be noted that even if you use a gibberish name for your fonts
4023 * here, it will still work because the name is stored. They will display as
4024 * System, but will report their name to be whatever they were created as */
4026 HWND hwndRichEdit
= new_richedit(NULL
);
4027 HFONT testFont1
= CreateFontA (0,0,0,0,FW_LIGHT
, 0, 0, 0, ANSI_CHARSET
,
4028 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|
4029 FF_DONTCARE
, "Marlett");
4030 HFONT testFont2
= CreateFontA (0,0,0,0,FW_LIGHT
, 0, 0, 0, ANSI_CHARSET
,
4031 OUT_TT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|
4032 FF_DONTCARE
, "MS Sans Serif");
4033 HFONT testFont3
= CreateFontA (0,0,0,0,FW_LIGHT
, 0, 0, 0, ANSI_CHARSET
,
4034 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|
4035 FF_DONTCARE
, "Courier");
4036 LOGFONTA sentLogFont
;
4037 CHARFORMAT2A returnedCF2A
;
4039 returnedCF2A
.cbSize
= sizeof(returnedCF2A
);
4041 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "x");
4042 SendMessage(hwndRichEdit
, WM_SETFONT
, (WPARAM
)testFont1
, MAKELPARAM(TRUE
, 0));
4043 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &returnedCF2A
);
4045 GetObjectA(testFont1
, sizeof(LOGFONTA
), &sentLogFont
);
4046 ok (!strcmp(sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
),
4047 "EM_GETCHARFORMAT: Returned wrong font on test 1. Sent: %s, Returned: %s\n",
4048 sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
);
4050 SendMessage(hwndRichEdit
, WM_SETFONT
, (WPARAM
)testFont2
, MAKELPARAM(TRUE
, 0));
4051 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &returnedCF2A
);
4052 GetObjectA(testFont2
, sizeof(LOGFONTA
), &sentLogFont
);
4053 ok (!strcmp(sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
),
4054 "EM_GETCHARFORMAT: Returned wrong font on test 2. Sent: %s, Returned: %s\n",
4055 sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
);
4057 SendMessage(hwndRichEdit
, WM_SETFONT
, (WPARAM
)testFont3
, MAKELPARAM(TRUE
, 0));
4058 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &returnedCF2A
);
4059 GetObjectA(testFont3
, sizeof(LOGFONTA
), &sentLogFont
);
4060 ok (!strcmp(sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
),
4061 "EM_GETCHARFORMAT: Returned wrong font on test 3. Sent: %s, Returned: %s\n",
4062 sentLogFont
.lfFaceName
,returnedCF2A
.szFaceName
);
4064 /* This last test is special since we send in NULL. We clear the variables
4065 * and just compare to "System" instead of the sent in font name. */
4066 ZeroMemory(&returnedCF2A
,sizeof(returnedCF2A
));
4067 ZeroMemory(&sentLogFont
,sizeof(sentLogFont
));
4068 returnedCF2A
.cbSize
= sizeof(returnedCF2A
);
4070 SendMessage(hwndRichEdit
, WM_SETFONT
, 0, MAKELPARAM((WORD
) TRUE
, 0));
4071 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &returnedCF2A
);
4072 GetObjectA(NULL
, sizeof(LOGFONTA
), &sentLogFont
);
4073 ok (!strcmp("System",returnedCF2A
.szFaceName
),
4074 "EM_GETCHARFORMAT: Returned wrong font on test 4. Sent: NULL, Returned: %s. Expected \"System\".\n",returnedCF2A
.szFaceName
);
4076 DestroyWindow(hwndRichEdit
);
4080 static DWORD CALLBACK
test_EM_GETMODIFY_esCallback(DWORD_PTR dwCookie
,
4085 const char** str
= (const char**)dwCookie
;
4086 int size
= strlen(*str
);
4087 if(size
> 3) /* let's make it piecemeal for fun */
4094 memcpy(pbBuff
, *str
, *pcb
);
4100 static void test_EM_GETMODIFY(void)
4102 HWND hwndRichEdit
= new_richedit(NULL
);
4105 WCHAR TestItem1
[] = {'T', 'e', 's', 't',
4107 'T', 'e', 'x', 't', 0};
4108 WCHAR TestItem2
[] = {'T', 'e', 's', 't',
4110 'O', 't', 'h', 'e', 'r',
4111 'T', 'e', 'x', 't', 0};
4112 const char* streamText
= "hello world";
4117 HFONT testFont
= CreateFontA (0,0,0,0,FW_LIGHT
, 0, 0, 0, ANSI_CHARSET
,
4118 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
, DEFAULT_PITCH
|
4119 FF_DONTCARE
, "Courier");
4121 setText
.codepage
= 1200; /* no constant for unicode */
4122 setText
.flags
= ST_KEEPUNDO
;
4125 /* modify flag shouldn't be set when richedit is first created */
4126 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4128 "EM_GETMODIFY returned non-zero, instead of zero on create\n");
4130 /* setting modify flag should actually set it */
4131 SendMessage(hwndRichEdit
, EM_SETMODIFY
, TRUE
, 0);
4132 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4134 "EM_GETMODIFY returned zero, instead of non-zero on EM_SETMODIFY\n");
4136 /* clearing modify flag should actually clear it */
4137 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4138 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4140 "EM_GETMODIFY returned non-zero, instead of zero on EM_SETMODIFY\n");
4142 /* setting font doesn't change modify flag */
4143 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4144 SendMessage(hwndRichEdit
, WM_SETFONT
, (WPARAM
)testFont
, MAKELPARAM(TRUE
, 0));
4145 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4147 "EM_GETMODIFY returned non-zero, instead of zero on setting font\n");
4149 /* setting text should set modify flag */
4150 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4151 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
)TestItem1
);
4152 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4154 "EM_GETMODIFY returned zero, instead of non-zero on setting text\n");
4156 /* undo previous text doesn't reset modify flag */
4157 SendMessage(hwndRichEdit
, WM_UNDO
, 0, 0);
4158 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4160 "EM_GETMODIFY returned zero, instead of non-zero on undo after setting text\n");
4162 /* set text with no flag to keep undo stack should not set modify flag */
4163 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4165 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
)TestItem1
);
4166 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4168 "EM_GETMODIFY returned non-zero, instead of zero when setting text while not keeping undo stack\n");
4170 /* WM_SETTEXT doesn't modify */
4171 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4172 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
)TestItem2
);
4173 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4175 "EM_GETMODIFY returned non-zero for WM_SETTEXT\n");
4177 /* clear the text */
4178 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4179 SendMessage(hwndRichEdit
, WM_CLEAR
, 0, 0);
4180 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4182 "EM_GETMODIFY returned non-zero, instead of zero for WM_CLEAR\n");
4185 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4186 SendMessage(hwndRichEdit
, EM_SETTEXTEX
, (WPARAM
)&setText
, (LPARAM
)TestItem1
);
4187 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
4188 SendMessage(hwndRichEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)TestItem2
);
4189 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4191 "EM_GETMODIFY returned zero, instead of non-zero when replacing text\n");
4193 /* copy/paste text 1 */
4194 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4195 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
4196 SendMessage(hwndRichEdit
, WM_COPY
, 0, 0);
4197 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
4198 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4200 "EM_GETMODIFY returned zero, instead of non-zero when pasting identical text\n");
4202 /* copy/paste text 2 */
4203 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4204 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 2);
4205 SendMessage(hwndRichEdit
, WM_COPY
, 0, 0);
4206 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 3);
4207 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
4208 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4210 "EM_GETMODIFY returned zero, instead of non-zero when pasting different text\n");
4213 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4214 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 1);
4215 SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
4216 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4218 "EM_GETMODIFY returned zero, instead of non-zero for WM_CHAR\n");
4221 SendMessage(hwndRichEdit
, WM_CHAR
, 'A', 0);
4222 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4223 SendMessage(hwndRichEdit
, WM_KEYDOWN
, VK_BACK
, 0);
4224 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4226 "EM_GETMODIFY returned zero, instead of non-zero for backspace\n");
4228 /* set char format */
4229 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4230 cf2
.cbSize
= sizeof(CHARFORMAT2
);
4231 SendMessage(hwndRichEdit
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
4233 cf2
.dwMask
= CFM_ITALIC
| cf2
.dwMask
;
4234 cf2
.dwEffects
= CFE_ITALIC
^ cf2
.dwEffects
;
4235 SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
4236 result
= SendMessage(hwndRichEdit
, EM_SETCHARFORMAT
, (WPARAM
) SCF_ALL
, (LPARAM
) &cf2
);
4237 ok(result
== 1, "EM_SETCHARFORMAT returned %ld instead of 1\n", result
);
4238 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4240 "EM_GETMODIFY returned zero, instead of non-zero for EM_SETCHARFORMAT\n");
4242 /* set para format */
4243 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4244 pf2
.cbSize
= sizeof(PARAFORMAT2
);
4245 SendMessage(hwndRichEdit
, EM_GETPARAFORMAT
, 0,
4247 pf2
.dwMask
= PFM_ALIGNMENT
| pf2
.dwMask
;
4248 pf2
.wAlignment
= PFA_RIGHT
;
4249 SendMessage(hwndRichEdit
, EM_SETPARAFORMAT
, 0, (LPARAM
) &pf2
);
4250 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4252 "EM_GETMODIFY returned zero, instead of non-zero for EM_SETPARAFORMAT\n");
4255 SendMessage(hwndRichEdit
, EM_SETMODIFY
, FALSE
, 0);
4256 es
.dwCookie
= (DWORD_PTR
)&streamText
;
4258 es
.pfnCallback
= test_EM_GETMODIFY_esCallback
;
4259 SendMessage(hwndRichEdit
, EM_STREAMIN
,
4260 (WPARAM
)(SF_TEXT
), (LPARAM
)&es
);
4261 result
= SendMessage(hwndRichEdit
, EM_GETMODIFY
, 0, 0);
4263 "EM_GETMODIFY returned zero, instead of non-zero for EM_STREAM\n");
4265 DestroyWindow(hwndRichEdit
);
4271 LRESULT expected_retval
;
4272 int expected_getsel_start
;
4273 int expected_getsel_end
;
4274 int _getsel_todo_wine
;
4277 const struct exsetsel_s exsetsel_tests
[] = {
4279 {5, 10, 10, 5, 10, 0},
4280 {15, 17, 17, 15, 17, 0},
4281 /* test cpMax > strlen() */
4282 {0, 100, 18, 0, 18, 1},
4283 /* test cpMin == cpMax */
4285 /* test cpMin < 0 && cpMax >= 0 (bug 4462) */
4286 {-1, 0, 5, 5, 5, 0},
4287 {-1, 17, 5, 5, 5, 0},
4288 {-1, 18, 5, 5, 5, 0},
4289 /* test cpMin < 0 && cpMax < 0 */
4290 {-1, -1, 17, 17, 17, 0},
4291 {-4, -5, 17, 17, 17, 0},
4292 /* test cMin >=0 && cpMax < 0 (bug 6814) */
4293 {0, -1, 18, 0, 18, 1},
4294 {17, -5, 18, 17, 18, 1},
4295 {18, -3, 17, 17, 17, 0},
4296 /* test if cpMin > cpMax */
4297 {15, 19, 18, 15, 18, 1},
4298 {19, 15, 18, 15, 18, 1}
4301 static void check_EM_EXSETSEL(HWND hwnd
, const struct exsetsel_s
*setsel
, int id
) {
4306 cr
.cpMin
= setsel
->min
;
4307 cr
.cpMax
= setsel
->max
;
4308 result
= SendMessage(hwnd
, EM_EXSETSEL
, 0, (LPARAM
) &cr
);
4310 ok(result
== setsel
->expected_retval
, "EM_EXSETSEL(%d): expected: %ld actual: %ld\n", id
, setsel
->expected_retval
, result
);
4312 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
) &start
, (LPARAM
) &end
);
4314 if (setsel
->_getsel_todo_wine
) {
4316 ok(start
== setsel
->expected_getsel_start
&& end
== setsel
->expected_getsel_end
, "EM_EXSETSEL(%d): expected (%d,%d) actual:(%d,%d)\n", id
, setsel
->expected_getsel_start
, setsel
->expected_getsel_end
, start
, end
);
4319 ok(start
== setsel
->expected_getsel_start
&& end
== setsel
->expected_getsel_end
, "EM_EXSETSEL(%d): expected (%d,%d) actual:(%d,%d)\n", id
, setsel
->expected_getsel_start
, setsel
->expected_getsel_end
, start
, end
);
4323 static void test_EM_EXSETSEL(void)
4325 HWND hwndRichEdit
= new_richedit(NULL
);
4327 const int num_tests
= sizeof(exsetsel_tests
)/sizeof(struct exsetsel_s
);
4329 /* sending some text to the window */
4330 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "testing selection");
4331 /* 01234567890123456*/
4334 for (i
= 0; i
< num_tests
; i
++) {
4335 check_EM_EXSETSEL(hwndRichEdit
, &exsetsel_tests
[i
], i
);
4338 DestroyWindow(hwndRichEdit
);
4341 static void test_EM_REPLACESEL(int redraw
)
4343 HWND hwndRichEdit
= new_richedit(NULL
);
4344 char buffer
[1024] = {0};
4349 /* sending some text to the window */
4350 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "testing selection");
4351 /* 01234567890123456*/
4354 /* FIXME add more tests */
4355 SendMessage(hwndRichEdit
, EM_SETSEL
, 7, 17);
4356 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, 0);
4357 ok(0 == r
, "EM_REPLACESEL returned %d, expected 0\n", r
);
4358 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4359 r
= strcmp(buffer
, "testing");
4360 ok(0 == r
, "expected %d, got %d\n", 0, r
);
4362 DestroyWindow(hwndRichEdit
);
4364 hwndRichEdit
= new_richedit(NULL
);
4366 trace("Testing EM_REPLACESEL behavior with redraw=%d\n", redraw
);
4367 SendMessage(hwndRichEdit
, WM_SETREDRAW
, redraw
, 0);
4369 /* Test behavior with carriage returns and newlines */
4370 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4371 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "RichEdit1");
4372 ok(9 == r
, "EM_REPLACESEL returned %d, expected 9\n", r
);
4373 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4374 r
= strcmp(buffer
, "RichEdit1");
4375 ok(0 == r
, "expected %d, got %d\n", 0, r
);
4377 getText
.codepage
= CP_ACP
;
4378 getText
.flags
= GT_DEFAULT
;
4379 getText
.lpDefaultChar
= NULL
;
4380 getText
.lpUsedDefChar
= NULL
;
4381 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4382 ok(strcmp(buffer
, "RichEdit1") == 0,
4383 "EM_GETTEXTEX results not what was set by EM_REPLACESEL\n");
4385 /* Test number of lines reported after EM_REPLACESEL */
4386 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4387 ok(r
== 1, "EM_GETLINECOUNT returned %d, expected 1\n", r
);
4389 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4390 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "RichEdit1\r");
4391 ok(10 == r
, "EM_REPLACESEL returned %d, expected 10\n", r
);
4392 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4393 r
= strcmp(buffer
, "RichEdit1\r\n");
4394 ok(0 == r
, "expected %d, got %d\n", 0, r
);
4396 getText
.codepage
= CP_ACP
;
4397 getText
.flags
= GT_DEFAULT
;
4398 getText
.lpDefaultChar
= NULL
;
4399 getText
.lpUsedDefChar
= NULL
;
4400 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4401 ok(strcmp(buffer
, "RichEdit1\r") == 0,
4402 "EM_GETTEXTEX returned incorrect string\n");
4404 /* Test number of lines reported after EM_REPLACESEL */
4405 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4406 ok(r
== 2, "EM_GETLINECOUNT returned %d, expected 2\n", r
);
4408 /* Win98's riched20 and WinXP's riched20 disagree on what to return from
4409 EM_REPLACESEL. The general rule seems to be that Win98's riched20
4410 returns the number of characters *inserted* into the control (after
4411 required conversions), but WinXP's riched20 returns the number of
4412 characters interpreted from the original lParam. Wine's builtin riched20
4413 implements the WinXP behavior.
4415 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4416 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "RichEdit1\r\n");
4417 ok(11 == r
/* WinXP */ || 10 == r
/* Win98 */,
4418 "EM_REPLACESEL returned %d, expected 11 or 10\n", r
);
4420 /* Test number of lines reported after EM_REPLACESEL */
4421 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4422 ok(r
== 2, "EM_GETLINECOUNT returned %d, expected 2\n", r
);
4424 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4425 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4426 ok(cr
.cpMin
== 10, "EM_EXGETSEL returned cpMin=%d, expected 10\n", cr
.cpMin
);
4427 ok(cr
.cpMax
== 10, "EM_EXGETSEL returned cpMax=%d, expected 10\n", cr
.cpMax
);
4429 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4430 r
= strcmp(buffer
, "RichEdit1\r\n");
4431 ok(0 == r
, "expected %d, got %d\n", 0, r
);
4433 getText
.codepage
= CP_ACP
;
4434 getText
.flags
= GT_DEFAULT
;
4435 getText
.lpDefaultChar
= NULL
;
4436 getText
.lpUsedDefChar
= NULL
;
4437 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4438 ok(strcmp(buffer
, "RichEdit1\r") == 0,
4439 "EM_GETTEXTEX returned incorrect string\n");
4441 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4442 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4443 ok(cr
.cpMin
== 10, "EM_EXGETSEL returned cpMin=%d, expected 10\n", cr
.cpMin
);
4444 ok(cr
.cpMax
== 10, "EM_EXGETSEL returned cpMax=%d, expected 10\n", cr
.cpMax
);
4446 /* The following tests show that richedit should handle the special \r\r\n
4447 sequence by turning it into a single space on insertion. However,
4448 EM_REPLACESEL on WinXP returns the number of characters in the original
4452 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4453 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\r\r");
4454 ok(2 == r
, "EM_REPLACESEL returned %d, expected 4\n", r
);
4455 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4456 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4457 ok(cr
.cpMin
== 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr
.cpMin
);
4458 ok(cr
.cpMax
== 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr
.cpMax
);
4460 /* Test the actual string */
4462 getText
.codepage
= CP_ACP
;
4463 getText
.flags
= GT_DEFAULT
;
4464 getText
.lpDefaultChar
= NULL
;
4465 getText
.lpUsedDefChar
= NULL
;
4466 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4467 ok(strcmp(buffer
, "\r\r") == 0,
4468 "EM_GETTEXTEX returned incorrect string\n");
4470 /* Test number of lines reported after EM_REPLACESEL */
4471 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4472 ok(r
== 3, "EM_GETLINECOUNT returned %d, expected 3\n", r
);
4474 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4475 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\r\r\n");
4476 ok(3 == r
/* WinXP */ || 1 == r
/* Win98 */,
4477 "EM_REPLACESEL returned %d, expected 3 or 1\n", r
);
4478 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4479 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4480 ok(cr
.cpMin
== 1, "EM_EXGETSEL returned cpMin=%d, expected 1\n", cr
.cpMin
);
4481 ok(cr
.cpMax
== 1, "EM_EXGETSEL returned cpMax=%d, expected 1\n", cr
.cpMax
);
4483 /* Test the actual string */
4485 getText
.codepage
= CP_ACP
;
4486 getText
.flags
= GT_DEFAULT
;
4487 getText
.lpDefaultChar
= NULL
;
4488 getText
.lpUsedDefChar
= NULL
;
4489 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4490 ok(strcmp(buffer
, " ") == 0,
4491 "EM_GETTEXTEX returned incorrect string\n");
4493 /* Test number of lines reported after EM_REPLACESEL */
4494 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4495 ok(r
== 1, "EM_GETLINECOUNT returned %d, expected 1\n", r
);
4497 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4498 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\r\r\r\r\r\n\r\r\r");
4499 ok(9 == r
/* WinXP */ || 7 == r
/* Win98 */,
4500 "EM_REPLACESEL returned %d, expected 9 or 7\n", r
);
4501 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4502 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4503 ok(cr
.cpMin
== 7, "EM_EXGETSEL returned cpMin=%d, expected 7\n", cr
.cpMin
);
4504 ok(cr
.cpMax
== 7, "EM_EXGETSEL returned cpMax=%d, expected 7\n", cr
.cpMax
);
4506 /* Test the actual string */
4508 getText
.codepage
= CP_ACP
;
4509 getText
.flags
= GT_DEFAULT
;
4510 getText
.lpDefaultChar
= NULL
;
4511 getText
.lpUsedDefChar
= NULL
;
4512 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4513 ok(strcmp(buffer
, "\r\r\r \r\r\r") == 0,
4514 "EM_GETTEXTEX returned incorrect string\n");
4516 /* Test number of lines reported after EM_REPLACESEL */
4517 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4518 ok(r
== 7, "EM_GETLINECOUNT returned %d, expected 7\n", r
);
4520 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4521 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\r\r\n\r\n");
4522 ok(5 == r
/* WinXP */ || 2 == r
/* Win98 */,
4523 "EM_REPLACESEL returned %d, expected 5 or 2\n", r
);
4524 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4525 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4526 ok(cr
.cpMin
== 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr
.cpMin
);
4527 ok(cr
.cpMax
== 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr
.cpMax
);
4529 /* Test the actual string */
4531 getText
.codepage
= CP_ACP
;
4532 getText
.flags
= GT_DEFAULT
;
4533 getText
.lpDefaultChar
= NULL
;
4534 getText
.lpUsedDefChar
= NULL
;
4535 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4536 ok(strcmp(buffer
, " \r") == 0,
4537 "EM_GETTEXTEX returned incorrect string\n");
4539 /* Test number of lines reported after EM_REPLACESEL */
4540 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4541 ok(r
== 2, "EM_GETLINECOUNT returned %d, expected 2\n", r
);
4543 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4544 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\r\r\n\r\r");
4545 ok(5 == r
/* WinXP */ || 3 == r
/* Win98 */,
4546 "EM_REPLACESEL returned %d, expected 5 or 3\n", r
);
4547 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4548 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4549 ok(cr
.cpMin
== 3, "EM_EXGETSEL returned cpMin=%d, expected 3\n", cr
.cpMin
);
4550 ok(cr
.cpMax
== 3, "EM_EXGETSEL returned cpMax=%d, expected 3\n", cr
.cpMax
);
4552 /* Test the actual string */
4554 getText
.codepage
= CP_ACP
;
4555 getText
.flags
= GT_DEFAULT
;
4556 getText
.lpDefaultChar
= NULL
;
4557 getText
.lpUsedDefChar
= NULL
;
4558 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4559 ok(strcmp(buffer
, " \r\r") == 0,
4560 "EM_GETTEXTEX returned incorrect string\n");
4562 /* Test number of lines reported after EM_REPLACESEL */
4563 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4564 ok(r
== 3, "EM_GETLINECOUNT returned %d, expected 3\n", r
);
4566 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4567 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\rX\r\n\r\r");
4568 ok(6 == r
/* WinXP */ || 5 == r
/* Win98 */,
4569 "EM_REPLACESEL returned %d, expected 6 or 5\n", r
);
4570 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4571 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4572 ok(cr
.cpMin
== 5, "EM_EXGETSEL returned cpMin=%d, expected 5\n", cr
.cpMin
);
4573 ok(cr
.cpMax
== 5, "EM_EXGETSEL returned cpMax=%d, expected 5\n", cr
.cpMax
);
4575 /* Test the actual string */
4577 getText
.codepage
= CP_ACP
;
4578 getText
.flags
= GT_DEFAULT
;
4579 getText
.lpDefaultChar
= NULL
;
4580 getText
.lpUsedDefChar
= NULL
;
4581 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4582 ok(strcmp(buffer
, "\rX\r\r\r") == 0,
4583 "EM_GETTEXTEX returned incorrect string\n");
4585 /* Test number of lines reported after EM_REPLACESEL */
4586 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4587 ok(r
== 5, "EM_GETLINECOUNT returned %d, expected 5\n", r
);
4589 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4590 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\n\n");
4591 ok(2 == r
, "EM_REPLACESEL returned %d, expected 2\n", r
);
4592 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4593 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4594 ok(cr
.cpMin
== 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr
.cpMin
);
4595 ok(cr
.cpMax
== 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr
.cpMax
);
4597 /* Test the actual string */
4599 getText
.codepage
= CP_ACP
;
4600 getText
.flags
= GT_DEFAULT
;
4601 getText
.lpDefaultChar
= NULL
;
4602 getText
.lpUsedDefChar
= NULL
;
4603 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4604 ok(strcmp(buffer
, "\r\r") == 0,
4605 "EM_GETTEXTEX returned incorrect string\n");
4607 /* Test number of lines reported after EM_REPLACESEL */
4608 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4609 ok(r
== 3, "EM_GETLINECOUNT returned %d, expected 3\n", r
);
4611 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4612 r
= SendMessage(hwndRichEdit
, EM_REPLACESEL
, 0, (LPARAM
) "\n\n\n\n\r\r\r\r\n");
4613 ok(9 == r
/* WinXP */ || 7 == r
/* Win98 */,
4614 "EM_REPLACESEL returned %d, expected 9 or 7\n", r
);
4615 r
= SendMessage(hwndRichEdit
, EM_EXGETSEL
, 0, (LPARAM
)&cr
);
4616 ok(0 == r
, "EM_EXGETSEL returned %d, expected 0\n", r
);
4617 ok(cr
.cpMin
== 7, "EM_EXGETSEL returned cpMin=%d, expected 7\n", cr
.cpMin
);
4618 ok(cr
.cpMax
== 7, "EM_EXGETSEL returned cpMax=%d, expected 7\n", cr
.cpMax
);
4620 /* Test the actual string */
4622 getText
.codepage
= CP_ACP
;
4623 getText
.flags
= GT_DEFAULT
;
4624 getText
.lpDefaultChar
= NULL
;
4625 getText
.lpUsedDefChar
= NULL
;
4626 SendMessage(hwndRichEdit
, EM_GETTEXTEX
, (WPARAM
)&getText
, (LPARAM
) buffer
);
4627 ok(strcmp(buffer
, "\r\r\r\r\r\r ") == 0,
4628 "EM_GETTEXTEX returned incorrect string\n");
4630 /* Test number of lines reported after EM_REPLACESEL */
4631 r
= SendMessage(hwndRichEdit
, EM_GETLINECOUNT
, 0, 0);
4632 ok(r
== 7, "EM_GETLINECOUNT returned %d, expected 7\n", r
);
4635 /* This is needed to avoid interferring with keybd_event calls
4636 * on other tests that simulate keyboard events. */
4637 SendMessage(hwndRichEdit
, WM_SETREDRAW
, TRUE
, 0);
4639 DestroyWindow(hwndRichEdit
);
4642 static void test_WM_PASTE(void)
4645 char buffer
[1024] = {0};
4646 const char* text1
= "testing paste\r";
4647 const char* text1_step1
= "testing paste\r\ntesting paste\r\n";
4648 const char* text1_after
= "testing paste\r\n";
4649 const char* text2
= "testing paste\r\rtesting paste";
4650 const char* text2_after
= "testing paste\r\n\r\ntesting paste";
4651 const char* text3
= "testing paste\r\npaste\r\ntesting paste";
4652 HWND hwndRichEdit
= new_richedit(NULL
);
4654 /* Native riched20 inspects the keyboard state (e.g. GetKeyState)
4655 * to test the state of the modifiers (Ctrl/Alt/Shift).
4657 * Therefore Ctrl-<key> keystrokes need to be simulated with
4658 * keybd_event or by using SetKeyboardState to set the modifiers
4659 * and SendMessage to simulate the keystrokes.
4662 /* Sent keystrokes with keybd_event */
4663 #define SEND_CTRL_C(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, 'C')
4664 #define SEND_CTRL_X(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, 'X')
4665 #define SEND_CTRL_V(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, 'V')
4666 #define SEND_CTRL_Z(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, 'Z')
4667 #define SEND_CTRL_Y(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, 'Y')
4669 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text1
);
4670 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 14);
4672 SEND_CTRL_C(hwndRichEdit
); /* Copy */
4673 SendMessage(hwndRichEdit
, EM_SETSEL
, 14, 14);
4674 SEND_CTRL_V(hwndRichEdit
); /* Paste */
4675 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4676 /* Pasted text should be visible at this step */
4677 result
= strcmp(text1_step1
, buffer
);
4679 "test paste: strcmp = %i, text='%s'\n", result
, buffer
);
4681 SEND_CTRL_Z(hwndRichEdit
); /* Undo */
4682 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4683 /* Text should be the same as before (except for \r -> \r\n conversion) */
4684 result
= strcmp(text1_after
, buffer
);
4686 "test paste: strcmp = %i, text='%s'\n", result
, buffer
);
4688 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text2
);
4689 SendMessage(hwndRichEdit
, EM_SETSEL
, 8, 13);
4690 SEND_CTRL_C(hwndRichEdit
); /* Copy */
4691 SendMessage(hwndRichEdit
, EM_SETSEL
, 14, 14);
4692 SEND_CTRL_V(hwndRichEdit
); /* Paste */
4693 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4694 /* Pasted text should be visible at this step */
4695 result
= strcmp(text3
, buffer
);
4697 "test paste: strcmp = %i\n", result
);
4698 SEND_CTRL_Z(hwndRichEdit
); /* Undo */
4699 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4700 /* Text should be the same as before (except for \r -> \r\n conversion) */
4701 result
= strcmp(text2_after
, buffer
);
4703 "test paste: strcmp = %i\n", result
);
4704 SEND_CTRL_Y(hwndRichEdit
); /* Redo */
4705 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4706 /* Text should revert to post-paste state */
4707 result
= strcmp(buffer
,text3
);
4709 "test paste: strcmp = %i\n", result
);
4717 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4718 /* Send WM_CHAR to simulates Ctrl-V */
4719 SendMessage(hwndRichEdit
, WM_CHAR
, 22,
4720 (MapVirtualKey('V', MAPVK_VK_TO_VSC
) << 16) & 1);
4721 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4722 /* Shouldn't paste because pasting is handled by WM_KEYDOWN */
4723 result
= strcmp(buffer
,"");
4725 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4727 /* Send keystrokes with WM_KEYDOWN after setting the modifiers
4728 * with SetKeyboard state. */
4730 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4731 /* Simulates paste (Ctrl-V) */
4732 hold_key(VK_CONTROL
);
4733 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'V',
4734 (MapVirtualKey('V', MAPVK_VK_TO_VSC
) << 16) & 1);
4735 release_key(VK_CONTROL
);
4736 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4737 result
= strcmp(buffer
,"paste");
4739 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4741 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) text1
);
4742 SendMessage(hwndRichEdit
, EM_SETSEL
, 0, 7);
4743 /* Simulates copy (Ctrl-C) */
4744 hold_key(VK_CONTROL
);
4745 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'C',
4746 (MapVirtualKey('C', MAPVK_VK_TO_VSC
) << 16) & 1);
4747 release_key(VK_CONTROL
);
4748 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4749 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
4750 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4751 result
= strcmp(buffer
,"testing");
4753 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4755 /* Cut with WM_KEYDOWN to simulate Ctrl-X */
4756 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) "cut");
4757 /* Simulates select all (Ctrl-A) */
4758 hold_key(VK_CONTROL
);
4759 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'A',
4760 (MapVirtualKey('A', MAPVK_VK_TO_VSC
) << 16) & 1);
4761 /* Simulates select cut (Ctrl-X) */
4762 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'X',
4763 (MapVirtualKey('X', MAPVK_VK_TO_VSC
) << 16) & 1);
4764 release_key(VK_CONTROL
);
4765 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4766 result
= strcmp(buffer
,"");
4768 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4769 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, 0);
4770 SendMessage(hwndRichEdit
, WM_PASTE
, 0, 0);
4771 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4772 result
= strcmp(buffer
,"cut\r\n");
4773 todo_wine
ok(result
== 0,
4774 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4775 /* Simulates undo (Ctrl-Z) */
4776 hold_key(VK_CONTROL
);
4777 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'Z',
4778 (MapVirtualKey('Z', MAPVK_VK_TO_VSC
) << 16) & 1);
4779 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4780 result
= strcmp(buffer
,"");
4782 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4783 /* Simulates redo (Ctrl-Y) */
4784 SendMessage(hwndRichEdit
, WM_KEYDOWN
, 'Y',
4785 (MapVirtualKey('Y', MAPVK_VK_TO_VSC
) << 16) & 1);
4786 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
4787 result
= strcmp(buffer
,"cut\r\n");
4788 todo_wine
ok(result
== 0,
4789 "test paste: strcmp = %i, actual = '%s'\n", result
, buffer
);
4790 release_key(VK_CONTROL
);
4792 DestroyWindow(hwndRichEdit
);
4795 static void test_EM_FORMATRANGE(void)
4797 int i
, tpp_x
, tpp_y
;
4799 HWND hwndRichEdit
= new_richedit(NULL
);
4800 static const struct {
4801 const char *string
; /* The string */
4802 int first
; /* First 'pagebreak', 0 for don't care */
4803 int second
; /* Second 'pagebreak', 0 for don't care */
4805 {"WINE wine", 0, 0},
4806 {"WINE wineWine", 0, 0},
4807 {"WINE\r\nwine\r\nwine", 5, 10},
4808 {"WINE\r\nWINEwine\r\nWINEwine", 5, 14},
4809 {"WINE\r\n\r\nwine\r\nwine", 5, 6}
4812 hdc
= GetDC(hwndRichEdit
);
4813 ok(hdc
!= NULL
, "Could not get HDC\n");
4815 /* Calculate the twips per pixel */
4816 tpp_x
= 1440 / GetDeviceCaps(hdc
, LOGPIXELSX
);
4817 tpp_y
= 1440 / GetDeviceCaps(hdc
, LOGPIXELSY
);
4819 SendMessage(hwndRichEdit
, EM_FORMATRANGE
, FALSE
, 0);
4821 for (i
= 0; i
< sizeof(fmtstrings
)/sizeof(fmtstrings
[0]); i
++)
4824 GETTEXTLENGTHEX gtl
;
4828 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) fmtstrings
[i
].string
);
4830 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
4831 gtl
.codepage
= CP_ACP
;
4832 len
= SendMessageA(hwndRichEdit
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
4834 /* Get some size information for the string */
4835 GetTextExtentPoint32(hdc
, fmtstrings
[i
].string
, strlen(fmtstrings
[i
].string
), &stringsize
);
4837 /* Define the box to be half the width needed and a bit larger than the height.
4838 * Changes to the width means we have at least 2 pages. Changes to the height
4839 * is done so we can check the changing of fr.rc.bottom.
4841 fr
.hdc
= fr
.hdcTarget
= hdc
;
4842 fr
.rc
.top
= fr
.rcPage
.top
= fr
.rc
.left
= fr
.rcPage
.left
= 0;
4843 fr
.rc
.right
= fr
.rcPage
.right
= (stringsize
.cx
/ 2) * tpp_x
;
4844 fr
.rc
.bottom
= fr
.rcPage
.bottom
= (stringsize
.cy
+ 10) * tpp_y
;
4846 r
= SendMessage(hwndRichEdit
, EM_FORMATRANGE
, TRUE
, 0);
4848 ok(r
== len
, "Expected %d, got %d\n", len
, r
);
4851 /* We know that the page can't hold the full string. See how many characters
4852 * are on the first one
4856 r
= SendMessage(hwndRichEdit
, EM_FORMATRANGE
, TRUE
, (LPARAM
) &fr
);
4858 ok(fr
.rc
.bottom
== (stringsize
.cy
* tpp_y
), "Expected bottom to be %d, got %d\n", (stringsize
.cy
* tpp_y
), fr
.rc
.bottom
);
4860 if (fmtstrings
[i
].first
)
4862 ok(r
== fmtstrings
[i
].first
, "Expected %d, got %d\n", fmtstrings
[i
].first
, r
);
4865 ok(r
< len
, "Expected < %d, got %d\n", len
, r
);
4867 /* Do another page */
4869 r
= SendMessage(hwndRichEdit
, EM_FORMATRANGE
, TRUE
, (LPARAM
) &fr
);
4870 if (fmtstrings
[i
].second
)
4872 ok(r
== fmtstrings
[i
].second
, "Expected %d, got %d\n", fmtstrings
[i
].second
, r
);
4875 ok (r
< len
, "Expected < %d, got %d\n", len
, r
);
4877 /* There is at least on more page, but we don't care */
4879 r
= SendMessage(hwndRichEdit
, EM_FORMATRANGE
, TRUE
, 0);
4881 ok(r
== len
, "Expected %d, got %d\n", len
, r
);
4885 ReleaseDC(NULL
, hdc
);
4886 DestroyWindow(hwndRichEdit
);
4889 static int nCallbackCount
= 0;
4891 static DWORD CALLBACK
EditStreamCallback(DWORD_PTR dwCookie
, LPBYTE pbBuff
,
4894 const char text
[] = {'t','e','s','t'};
4896 if (sizeof(text
) <= cb
)
4898 if ((int)dwCookie
!= nCallbackCount
)
4904 memcpy (pbBuff
, text
, sizeof(text
));
4905 *pcb
= sizeof(text
);
4912 return 1; /* indicates callback failed */
4915 static DWORD CALLBACK
test_EM_STREAMIN_esCallback(DWORD_PTR dwCookie
,
4920 const char** str
= (const char**)dwCookie
;
4921 int size
= strlen(*str
);
4927 memcpy(pbBuff
, *str
, *pcb
);
4933 struct StringWithLength
{
4938 /* This callback is used to handled the null characters in a string. */
4939 static DWORD CALLBACK
test_EM_STREAMIN_esCallback2(DWORD_PTR dwCookie
,
4944 struct StringWithLength
* str
= (struct StringWithLength
*)dwCookie
;
4945 int size
= str
->length
;
4951 memcpy(pbBuff
, str
->buffer
, *pcb
);
4952 str
->buffer
+= *pcb
;
4953 str
->length
-= *pcb
;
4958 static void test_EM_STREAMIN(void)
4960 HWND hwndRichEdit
= new_richedit(NULL
);
4963 char buffer
[1024] = {0};
4965 const char * streamText0
= "{\\rtf1 TestSomeText}";
4966 const char * streamText0a
= "{\\rtf1 TestSomeText\\par}";
4967 const char * streamText0b
= "{\\rtf1 TestSomeText\\par\\par}";
4969 const char * streamText1
=
4970 "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang12298{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 System;}}\r\n"
4971 "\\viewkind4\\uc1\\pard\\f0\\fs17 TestSomeText\\par\r\n"
4974 /* In richedit 2.0 mode, this should NOT be accepted, unlike 1.0 */
4975 const char * streamText2
=
4976 "{{\\colortbl;\\red0\\green255\\blue102;\\red255\\green255\\blue255;"
4977 "\\red170\\green255\\blue255;\\red255\\green238\\blue0;\\red51\\green255"
4978 "\\blue221;\\red238\\green238\\blue238;}\\tx0 \\tx424 \\tx848 \\tx1272 "
4979 "\\tx1696 \\tx2120 \\tx2544 \\tx2968 \\tx3392 \\tx3816 \\tx4240 \\tx4664 "
4980 "\\tx5088 \\tx5512 \\tx5936 \\tx6360 \\tx6784 \\tx7208 \\tx7632 \\tx8056 "
4981 "\\tx8480 \\tx8904 \\tx9328 \\tx9752 \\tx10176 \\tx10600 \\tx11024 "
4982 "\\tx11448 \\tx11872 \\tx12296 \\tx12720 \\tx13144 \\cf2 RichEdit1\\line }";
4984 const char * streamText3
= "RichEdit1";
4986 struct StringWithLength cookieForStream4
;
4987 const char * streamText4
=
4988 "This text just needs to be long enough to cause run to be split onto "
4989 "two separate lines and make sure the null terminating character is "
4990 "handled properly.\0";
4991 int length4
= strlen(streamText4
) + 1;
4992 cookieForStream4
.buffer
= (char *)streamText4
;
4993 cookieForStream4
.length
= length4
;
4995 /* Minimal test without \par at the end */
4996 es
.dwCookie
= (DWORD_PTR
)&streamText0
;
4998 es
.pfnCallback
= test_EM_STREAMIN_esCallback
;
4999 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5000 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5002 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5004 "EM_STREAMIN: Test 0 returned %ld, expected 12\n", result
);
5005 result
= strcmp (buffer
,"TestSomeText");
5007 "EM_STREAMIN: Test 0 set wrong text: Result: %s\n",buffer
);
5008 ok(es
.dwError
== 0, "EM_STREAMIN: Test 0 set error %d, expected %d\n", es
.dwError
, 0);
5010 /* Native richedit 2.0 ignores last \par */
5011 es
.dwCookie
= (DWORD_PTR
)&streamText0a
;
5013 es
.pfnCallback
= test_EM_STREAMIN_esCallback
;
5014 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5015 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5017 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5019 "EM_STREAMIN: Test 0-a returned %ld, expected 12\n", result
);
5020 result
= strcmp (buffer
,"TestSomeText");
5022 "EM_STREAMIN: Test 0-a set wrong text: Result: %s\n",buffer
);
5023 ok(es
.dwError
== 0, "EM_STREAMIN: Test 0-a set error %d, expected %d\n", es
.dwError
, 0);
5025 /* Native richedit 2.0 ignores last \par, next-to-last \par appears */
5026 es
.dwCookie
= (DWORD_PTR
)&streamText0b
;
5028 es
.pfnCallback
= test_EM_STREAMIN_esCallback
;
5029 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5030 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5032 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5034 "EM_STREAMIN: Test 0-b returned %ld, expected 14\n", result
);
5035 result
= strcmp (buffer
,"TestSomeText\r\n");
5037 "EM_STREAMIN: Test 0-b set wrong text: Result: %s\n",buffer
);
5038 ok(es
.dwError
== 0, "EM_STREAMIN: Test 0-b set error %d, expected %d\n", es
.dwError
, 0);
5040 es
.dwCookie
= (DWORD_PTR
)&streamText1
;
5042 es
.pfnCallback
= test_EM_STREAMIN_esCallback
;
5043 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5044 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5046 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5048 "EM_STREAMIN: Test 1 returned %ld, expected 12\n", result
);
5049 result
= strcmp (buffer
,"TestSomeText");
5051 "EM_STREAMIN: Test 1 set wrong text: Result: %s\n",buffer
);
5052 ok(es
.dwError
== 0, "EM_STREAMIN: Test 1 set error %d, expected %d\n", es
.dwError
, 0);
5054 es
.dwCookie
= (DWORD_PTR
)&streamText2
;
5056 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5057 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5059 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5061 "EM_STREAMIN: Test 2 returned %ld, expected 0\n", result
);
5062 ok (strlen(buffer
) == 0,
5063 "EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer
);
5064 ok(es
.dwError
== -16, "EM_STREAMIN: Test 2 set error %d, expected %d\n", es
.dwError
, -16);
5066 es
.dwCookie
= (DWORD_PTR
)&streamText3
;
5068 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5069 (WPARAM
)(SF_RTF
), (LPARAM
)&es
);
5071 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5073 "EM_STREAMIN: Test 3 returned %ld, expected 0\n", result
);
5074 ok (strlen(buffer
) == 0,
5075 "EM_STREAMIN: Test 3 set wrong text: Result: %s\n",buffer
);
5076 ok(es
.dwError
== -16, "EM_STREAMIN: Test 3 set error %d, expected %d\n", es
.dwError
, -16);
5078 es
.dwCookie
= (DWORD_PTR
)&cookieForStream4
;
5080 es
.pfnCallback
= test_EM_STREAMIN_esCallback2
;
5081 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5082 (WPARAM
)(SF_TEXT
), (LPARAM
)&es
);
5084 result
= SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5085 ok (result
== length4
,
5086 "EM_STREAMIN: Test 4 returned %ld, expected %d\n", result
, length4
);
5087 ok(es
.dwError
== 0, "EM_STREAMIN: Test 4 set error %d, expected %d\n", es
.dwError
, 0);
5089 DestroyWindow(hwndRichEdit
);
5092 static void test_EM_StreamIn_Undo(void)
5094 /* The purpose of this test is to determine when a EM_StreamIn should be
5095 * undoable. This is important because WM_PASTE currently uses StreamIn and
5096 * pasting should always be undoable but streaming isn't always.
5099 * StreamIn plain text without SFF_SELECTION.
5100 * StreamIn plain text with SFF_SELECTION set but a zero-length selection
5101 * StreamIn plain text with SFF_SELECTION and a valid, normal selection
5102 * StreamIn plain text with SFF_SELECTION and a backwards-selection (from>to)
5103 * Feel free to add tests for other text modes or StreamIn things.
5107 HWND hwndRichEdit
= new_richedit(NULL
);
5110 char buffer
[1024] = {0};
5111 const char randomtext
[] = "Some text";
5113 es
.pfnCallback
= (EDITSTREAMCALLBACK
) EditStreamCallback
;
5115 /* StreamIn, no SFF_SELECTION */
5116 es
.dwCookie
= nCallbackCount
;
5117 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0,0);
5118 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) randomtext
);
5119 SendMessage(hwndRichEdit
, EM_SETSEL
,0,0);
5120 SendMessage(hwndRichEdit
, EM_STREAMIN
, (WPARAM
)SF_TEXT
, (LPARAM
)&es
);
5121 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5122 result
= strcmp (buffer
,"test");
5124 "EM_STREAMIN: Test 1 set wrong text: Result: %s\n",buffer
);
5126 result
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
5127 ok (result
== FALSE
,
5128 "EM_STREAMIN without SFF_SELECTION wrongly allows undo\n");
5130 /* StreamIn, SFF_SELECTION, but nothing selected */
5131 es
.dwCookie
= nCallbackCount
;
5132 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0,0);
5133 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) randomtext
);
5134 SendMessage(hwndRichEdit
, EM_SETSEL
,0,0);
5135 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5136 (WPARAM
)(SF_TEXT
|SFF_SELECTION
), (LPARAM
)&es
);
5137 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5138 result
= strcmp (buffer
,"testSome text");
5140 "EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer
);
5142 result
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
5144 "EM_STREAMIN with SFF_SELECTION but no selection set "
5145 "should create an undo\n");
5147 /* StreamIn, SFF_SELECTION, with a selection */
5148 es
.dwCookie
= nCallbackCount
;
5149 SendMessage(hwndRichEdit
,EM_EMPTYUNDOBUFFER
, 0,0);
5150 SendMessage(hwndRichEdit
, WM_SETTEXT
, 0, (LPARAM
) randomtext
);
5151 SendMessage(hwndRichEdit
, EM_SETSEL
,4,5);
5152 SendMessage(hwndRichEdit
, EM_STREAMIN
,
5153 (WPARAM
)(SF_TEXT
|SFF_SELECTION
), (LPARAM
)&es
);
5154 SendMessage(hwndRichEdit
, WM_GETTEXT
, 1024, (LPARAM
) buffer
);
5155 result
= strcmp (buffer
,"Sometesttext");
5157 "EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer
);
5159 result
= SendMessage(hwndRichEdit
, EM_CANUNDO
, 0, 0);
5161 "EM_STREAMIN with SFF_SELECTION and selection set "
5162 "should create an undo\n");
5164 DestroyWindow(hwndRichEdit
);
5167 static BOOL
is_em_settextex_supported(HWND hwnd
)
5169 SETTEXTEX stex
= { ST_DEFAULT
, CP_ACP
};
5170 return SendMessageA(hwnd
, EM_SETTEXTEX
, (WPARAM
)&stex
, 0) != 0;
5173 static void test_unicode_conversions(void)
5175 static const WCHAR tW
[] = {'t',0};
5176 static const WCHAR teW
[] = {'t','e',0};
5177 static const WCHAR textW
[] = {'t','e','s','t',0};
5178 static const char textA
[] = "test";
5182 int em_settextex_supported
, ret
;
5184 #define set_textA(hwnd, wm_set_text, txt) \
5186 SETTEXTEX stex = { ST_DEFAULT, CP_ACP }; \
5187 WPARAM wparam = (wm_set_text == WM_SETTEXT) ? 0 : (WPARAM)&stex; \
5188 assert(wm_set_text == WM_SETTEXT || wm_set_text == EM_SETTEXTEX); \
5189 ret = SendMessageA(hwnd, wm_set_text, wparam, (LPARAM)txt); \
5190 ok(ret, "SendMessageA(%02x) error %u\n", wm_set_text, GetLastError()); \
5192 #define expect_textA(hwnd, wm_get_text, txt) \
5194 GETTEXTEX gtex = { 64, GT_DEFAULT, CP_ACP, NULL, NULL }; \
5195 WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
5196 assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
5197 memset(bufA, 0xAA, sizeof(bufA)); \
5198 ret = SendMessageA(hwnd, wm_get_text, wparam, (LPARAM)bufA); \
5199 ok(ret, "SendMessageA(%02x) error %u\n", wm_get_text, GetLastError()); \
5200 ret = lstrcmpA(bufA, txt); \
5201 ok(!ret, "%02x: strings do not match: expected %s got %s\n", wm_get_text, txt, bufA); \
5204 #define set_textW(hwnd, wm_set_text, txt) \
5206 SETTEXTEX stex = { ST_DEFAULT, 1200 }; \
5207 WPARAM wparam = (wm_set_text == WM_SETTEXT) ? 0 : (WPARAM)&stex; \
5208 assert(wm_set_text == WM_SETTEXT || wm_set_text == EM_SETTEXTEX); \
5209 ret = SendMessageW(hwnd, wm_set_text, wparam, (LPARAM)txt); \
5210 ok(ret, "SendMessageW(%02x) error %u\n", wm_set_text, GetLastError()); \
5212 #define expect_textW(hwnd, wm_get_text, txt) \
5214 GETTEXTEX gtex = { 64, GT_DEFAULT, 1200, NULL, NULL }; \
5215 WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
5216 assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
5217 memset(bufW, 0xAA, sizeof(bufW)); \
5220 assert(wm_get_text == EM_GETTEXTEX); \
5221 ret = SendMessageA(hwnd, wm_get_text, wparam, (LPARAM)bufW); \
5222 ok(ret, "SendMessageA(%02x) error %u\n", wm_get_text, GetLastError()); \
5226 ret = SendMessageW(hwnd, wm_get_text, wparam, (LPARAM)bufW); \
5227 ok(ret, "SendMessageW(%02x) error %u\n", wm_get_text, GetLastError()); \
5229 ret = lstrcmpW(bufW, txt); \
5230 ok(!ret, "%02x: strings do not match: expected[0] %x got[0] %x\n", wm_get_text, txt[0], bufW[0]); \
5232 #define expect_empty(hwnd, wm_get_text) \
5234 GETTEXTEX gtex = { 64, GT_DEFAULT, CP_ACP, NULL, NULL }; \
5235 WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
5236 assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
5237 memset(bufA, 0xAA, sizeof(bufA)); \
5238 ret = SendMessageA(hwnd, wm_get_text, wparam, (LPARAM)bufA); \
5239 ok(!ret, "empty richedit should return 0, got %d\n", ret); \
5240 ok(!*bufA, "empty richedit should return empty string, got %s\n", bufA); \
5243 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
,
5244 0, 0, 200, 60, 0, 0, 0, 0);
5245 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5247 ret
= IsWindowUnicode(hwnd
);
5249 ok(!ret
, "RichEdit20W should NOT be unicode under Win9x\n");
5251 ok(ret
, "RichEdit20W should be unicode under NT\n");
5253 /* EM_SETTEXTEX is supported starting from version 3.0 */
5254 em_settextex_supported
= is_em_settextex_supported(hwnd
);
5255 trace("EM_SETTEXTEX is %ssupported on this platform\n",
5256 em_settextex_supported
? "" : "NOT ");
5258 expect_empty(hwnd
, WM_GETTEXT
);
5259 expect_empty(hwnd
, EM_GETTEXTEX
);
5261 ret
= SendMessageA(hwnd
, WM_CHAR
, (WPARAM
)textW
[0], 0);
5262 ok(!ret
, "SendMessageA(WM_CHAR) should return 0, got %d\n", ret
);
5263 expect_textA(hwnd
, WM_GETTEXT
, "t");
5264 expect_textA(hwnd
, EM_GETTEXTEX
, "t");
5265 expect_textW(hwnd
, EM_GETTEXTEX
, tW
);
5267 ret
= SendMessageA(hwnd
, WM_CHAR
, (WPARAM
)textA
[1], 0);
5268 ok(!ret
, "SendMessageA(WM_CHAR) should return 0, got %d\n", ret
);
5269 expect_textA(hwnd
, WM_GETTEXT
, "te");
5270 expect_textA(hwnd
, EM_GETTEXTEX
, "te");
5271 expect_textW(hwnd
, EM_GETTEXTEX
, teW
);
5273 set_textA(hwnd
, WM_SETTEXT
, NULL
);
5274 expect_empty(hwnd
, WM_GETTEXT
);
5275 expect_empty(hwnd
, EM_GETTEXTEX
);
5278 set_textA(hwnd
, WM_SETTEXT
, textW
);
5280 set_textA(hwnd
, WM_SETTEXT
, textA
);
5281 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5282 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5283 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5285 if (em_settextex_supported
)
5287 set_textA(hwnd
, EM_SETTEXTEX
, textA
);
5288 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5289 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5290 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5295 set_textW(hwnd
, WM_SETTEXT
, textW
);
5296 expect_textW(hwnd
, WM_GETTEXT
, textW
);
5297 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5298 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5299 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5301 if (em_settextex_supported
)
5303 set_textW(hwnd
, EM_SETTEXTEX
, textW
);
5304 expect_textW(hwnd
, WM_GETTEXT
, textW
);
5305 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5306 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5307 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5310 DestroyWindow(hwnd
);
5312 hwnd
= CreateWindowExA(0, "RichEdit20A", NULL
, WS_POPUP
,
5313 0, 0, 200, 60, 0, 0, 0, 0);
5314 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5316 ret
= IsWindowUnicode(hwnd
);
5317 ok(!ret
, "RichEdit20A should NOT be unicode\n");
5319 set_textA(hwnd
, WM_SETTEXT
, textA
);
5320 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5321 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5322 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5324 if (em_settextex_supported
)
5326 set_textA(hwnd
, EM_SETTEXTEX
, textA
);
5327 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5328 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5329 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5334 set_textW(hwnd
, WM_SETTEXT
, textW
);
5335 expect_textW(hwnd
, WM_GETTEXT
, textW
);
5336 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5337 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5338 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5340 if (em_settextex_supported
)
5342 set_textW(hwnd
, EM_SETTEXTEX
, textW
);
5343 expect_textW(hwnd
, WM_GETTEXT
, textW
);
5344 expect_textA(hwnd
, WM_GETTEXT
, textA
);
5345 expect_textW(hwnd
, EM_GETTEXTEX
, textW
);
5346 expect_textA(hwnd
, EM_GETTEXTEX
, textA
);
5349 DestroyWindow(hwnd
);
5352 static void test_WM_CHAR(void)
5356 const char * char_list
= "abc\rabc\r";
5357 const char * expected_content_single
= "abcabc";
5358 const char * expected_content_multi
= "abc\r\nabc\r\n";
5359 char buffer
[64] = {0};
5362 /* single-line control must IGNORE carriage returns */
5363 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
,
5364 0, 0, 200, 60, 0, 0, 0, 0);
5365 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5368 while (*p
!= '\0') {
5369 SendMessageA(hwnd
, WM_KEYDOWN
, *p
, 1);
5370 ret
= SendMessageA(hwnd
, WM_CHAR
, *p
, 1);
5371 ok(ret
== 0, "WM_CHAR('%c') ret=%d\n", *p
, ret
);
5372 SendMessageA(hwnd
, WM_KEYUP
, *p
, 1);
5376 SendMessage(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5377 ret
= strcmp(buffer
, expected_content_single
);
5378 ok(ret
== 0, "WM_GETTEXT recovered incorrect string!\n");
5380 DestroyWindow(hwnd
);
5382 /* multi-line control inserts CR normally */
5383 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
|ES_MULTILINE
,
5384 0, 0, 200, 60, 0, 0, 0, 0);
5385 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5388 while (*p
!= '\0') {
5389 SendMessageA(hwnd
, WM_KEYDOWN
, *p
, 1);
5390 ret
= SendMessageA(hwnd
, WM_CHAR
, *p
, 1);
5391 ok(ret
== 0, "WM_CHAR('%c') ret=%d\n", *p
, ret
);
5392 SendMessageA(hwnd
, WM_KEYUP
, *p
, 1);
5396 SendMessage(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5397 ret
= strcmp(buffer
, expected_content_multi
);
5398 ok(ret
== 0, "WM_GETTEXT recovered incorrect string!\n");
5400 DestroyWindow(hwnd
);
5403 static void test_EM_GETTEXTLENGTHEX(void)
5406 GETTEXTLENGTHEX gtl
;
5408 const char * base_string
= "base string";
5409 const char * test_string
= "a\nb\n\n\r\n";
5410 const char * test_string_after
= "a";
5411 const char * test_string_2
= "a\rtest\rstring";
5412 char buffer
[64] = {0};
5416 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
,
5417 0, 0, 200, 60, 0, 0, 0, 0);
5419 hwnd
= CreateWindowExA(0, "RichEdit20A", NULL
, WS_POPUP
,
5420 0, 0, 200, 60, 0, 0, 0, 0);
5421 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5423 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5424 gtl
.codepage
= CP_ACP
;
5425 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5426 ok(ret
== 0, "ret %d\n",ret
);
5428 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5429 gtl
.codepage
= CP_ACP
;
5430 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5431 ok(ret
== 0, "ret %d\n",ret
);
5433 SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) base_string
);
5435 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5436 gtl
.codepage
= CP_ACP
;
5437 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5438 ok(ret
== strlen(base_string
), "ret %d\n",ret
);
5440 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5441 gtl
.codepage
= CP_ACP
;
5442 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5443 ok(ret
== strlen(base_string
), "ret %d\n",ret
);
5445 SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) test_string
);
5447 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5448 gtl
.codepage
= CP_ACP
;
5449 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5450 ok(ret
== 1, "ret %d\n",ret
);
5452 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5453 gtl
.codepage
= CP_ACP
;
5454 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5455 ok(ret
== 1, "ret %d\n",ret
);
5457 SendMessage(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5458 ret
= strcmp(buffer
, test_string_after
);
5459 ok(ret
== 0, "WM_GETTEXT recovered incorrect string!\n");
5461 DestroyWindow(hwnd
);
5465 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
| ES_MULTILINE
,
5466 0, 0, 200, 60, 0, 0, 0, 0);
5468 hwnd
= CreateWindowExA(0, "RichEdit20A", NULL
, WS_POPUP
| ES_MULTILINE
,
5469 0, 0, 200, 60, 0, 0, 0, 0);
5470 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5472 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5473 gtl
.codepage
= CP_ACP
;
5474 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5475 ok(ret
== 0, "ret %d\n",ret
);
5477 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5478 gtl
.codepage
= CP_ACP
;
5479 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5480 ok(ret
== 0, "ret %d\n",ret
);
5482 SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) base_string
);
5484 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5485 gtl
.codepage
= CP_ACP
;
5486 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5487 ok(ret
== strlen(base_string
), "ret %d\n",ret
);
5489 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5490 gtl
.codepage
= CP_ACP
;
5491 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5492 ok(ret
== strlen(base_string
), "ret %d\n",ret
);
5494 SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) test_string_2
);
5496 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5497 gtl
.codepage
= CP_ACP
;
5498 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5499 ok(ret
== strlen(test_string_2
) + 2, "ret %d\n",ret
);
5501 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5502 gtl
.codepage
= CP_ACP
;
5503 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5504 ok(ret
== strlen(test_string_2
), "ret %d\n",ret
);
5506 SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) test_string
);
5508 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
| GTL_USECRLF
;
5509 gtl
.codepage
= CP_ACP
;
5510 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5511 ok(ret
== 10, "ret %d\n",ret
);
5513 gtl
.flags
= GTL_NUMCHARS
| GTL_PRECISE
;
5514 gtl
.codepage
= CP_ACP
;
5515 ret
= SendMessageA(hwnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>l
, 0);
5516 ok(ret
== 6, "ret %d\n",ret
);
5518 DestroyWindow(hwnd
);
5522 /* globals that parent and child access when checking event masks & notifications */
5523 static HWND eventMaskEditHwnd
= 0;
5524 static int queriedEventMask
;
5525 static int watchForEventMask
= 0;
5527 /* parent proc that queries the edit's event mask when it gets a WM_COMMAND */
5528 static LRESULT WINAPI
ParentMsgCheckProcA(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
5530 if(message
== WM_COMMAND
&& (watchForEventMask
& (wParam
>> 16)))
5532 queriedEventMask
= SendMessage(eventMaskEditHwnd
, EM_GETEVENTMASK
, 0, 0);
5534 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
5537 /* test event masks in combination with WM_COMMAND */
5538 static void test_eventMask(void)
5543 const char text
[] = "foo bar\n";
5546 /* register class to capture WM_COMMAND */
5548 cls
.lpfnWndProc
= ParentMsgCheckProcA
;
5551 cls
.hInstance
= GetModuleHandleA(0);
5553 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5554 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5555 cls
.lpszMenuName
= NULL
;
5556 cls
.lpszClassName
= "EventMaskParentClass";
5557 if(!RegisterClassA(&cls
)) assert(0);
5559 parent
= CreateWindow(cls
.lpszClassName
, NULL
, WS_POPUP
|WS_VISIBLE
,
5560 0, 0, 200, 60, NULL
, NULL
, NULL
, NULL
);
5561 ok (parent
!= 0, "Failed to create parent window\n");
5563 eventMaskEditHwnd
= new_richedit(parent
);
5564 ok(eventMaskEditHwnd
!= 0, "Failed to create edit window\n");
5566 eventMask
= ENM_CHANGE
| ENM_UPDATE
;
5567 ret
= SendMessage(eventMaskEditHwnd
, EM_SETEVENTMASK
, 0, (LPARAM
) eventMask
);
5568 ok(ret
== ENM_NONE
, "wrong event mask\n");
5569 ret
= SendMessage(eventMaskEditHwnd
, EM_GETEVENTMASK
, 0, 0);
5570 ok(ret
== eventMask
, "failed to set event mask\n");
5572 /* check what happens when we ask for EN_CHANGE and send WM_SETTEXT */
5573 queriedEventMask
= 0; /* initialize to something other than we expect */
5574 watchForEventMask
= EN_CHANGE
;
5575 ret
= SendMessage(eventMaskEditHwnd
, WM_SETTEXT
, 0, (LPARAM
) text
);
5576 ok(ret
== TRUE
, "failed to set text\n");
5577 /* richedit should mask off ENM_CHANGE when it sends an EN_CHANGE
5578 notification in response to WM_SETTEXT */
5579 ok(queriedEventMask
== (eventMask
& ~ENM_CHANGE
),
5580 "wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask
);
5582 /* check to see if EN_CHANGE is sent when redraw is turned off */
5583 SendMessage(eventMaskEditHwnd
, WM_CLEAR
, 0, 0);
5584 ok(IsWindowVisible(eventMaskEditHwnd
), "Window should be visible.\n");
5585 SendMessage(eventMaskEditHwnd
, WM_SETREDRAW
, FALSE
, 0);
5586 /* redraw is disabled by making the window invisible. */
5587 ok(!IsWindowVisible(eventMaskEditHwnd
), "Window shouldn't be visible.\n");
5588 queriedEventMask
= 0; /* initialize to something other than we expect */
5589 SendMessage(eventMaskEditHwnd
, EM_REPLACESEL
, 0, (LPARAM
) text
);
5590 ok(queriedEventMask
== (eventMask
& ~ENM_CHANGE
),
5591 "wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask
);
5592 SendMessage(eventMaskEditHwnd
, WM_SETREDRAW
, TRUE
, 0);
5593 ok(IsWindowVisible(eventMaskEditHwnd
), "Window should be visible.\n");
5595 /* check to see if EN_UPDATE is sent when the editor isn't visible */
5596 SendMessage(eventMaskEditHwnd
, WM_CLEAR
, 0, 0);
5597 style
= GetWindowLong(eventMaskEditHwnd
, GWL_STYLE
);
5598 SetWindowLong(eventMaskEditHwnd
, GWL_STYLE
, style
& ~WS_VISIBLE
);
5599 ok(!IsWindowVisible(eventMaskEditHwnd
), "Window shouldn't be visible.\n");
5600 watchForEventMask
= EN_UPDATE
;
5601 queriedEventMask
= 0; /* initialize to something other than we expect */
5602 SendMessage(eventMaskEditHwnd
, EM_REPLACESEL
, 0, (LPARAM
) text
);
5603 ok(queriedEventMask
== 0,
5604 "wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask
);
5605 SetWindowLong(eventMaskEditHwnd
, GWL_STYLE
, style
);
5606 ok(IsWindowVisible(eventMaskEditHwnd
), "Window should be visible.\n");
5607 queriedEventMask
= 0; /* initialize to something other than we expect */
5608 SendMessage(eventMaskEditHwnd
, EM_REPLACESEL
, 0, (LPARAM
) text
);
5609 ok(queriedEventMask
== eventMask
,
5610 "wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask
);
5613 DestroyWindow(parent
);
5616 static int received_WM_NOTIFY
= 0;
5617 static int modify_at_WM_NOTIFY
= 0;
5618 static HWND hwndRichedit_WM_NOTIFY
;
5620 static LRESULT WINAPI
WM_NOTIFY_ParentMsgCheckProcA(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
5622 if(message
== WM_NOTIFY
)
5624 received_WM_NOTIFY
= 1;
5625 modify_at_WM_NOTIFY
= SendMessage(hwndRichedit_WM_NOTIFY
, EM_GETMODIFY
, 0, 0);
5627 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
5630 static void test_WM_NOTIFY(void)
5636 /* register class to capture WM_NOTIFY */
5638 cls
.lpfnWndProc
= WM_NOTIFY_ParentMsgCheckProcA
;
5641 cls
.hInstance
= GetModuleHandleA(0);
5643 cls
.hCursor
= LoadCursorA(0, IDC_ARROW
);
5644 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
5645 cls
.lpszMenuName
= NULL
;
5646 cls
.lpszClassName
= "WM_NOTIFY_ParentClass";
5647 if(!RegisterClassA(&cls
)) assert(0);
5649 parent
= CreateWindow(cls
.lpszClassName
, NULL
, WS_POPUP
|WS_VISIBLE
,
5650 0, 0, 200, 60, NULL
, NULL
, NULL
, NULL
);
5651 ok (parent
!= 0, "Failed to create parent window\n");
5653 hwndRichedit_WM_NOTIFY
= new_richedit(parent
);
5654 ok(hwndRichedit_WM_NOTIFY
!= 0, "Failed to create edit window\n");
5656 SendMessage(hwndRichedit_WM_NOTIFY
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
5658 /* Notifications for selection change should only be sent when selection
5659 actually changes. EM_SETCHARFORMAT is one message that calls
5660 ME_CommitUndo, which should check whether message should be sent */
5661 received_WM_NOTIFY
= 0;
5662 cf2
.cbSize
= sizeof(CHARFORMAT2
);
5663 SendMessage(hwndRichedit_WM_NOTIFY
, EM_GETCHARFORMAT
, (WPARAM
) SCF_DEFAULT
,
5665 cf2
.dwMask
= CFM_ITALIC
| cf2
.dwMask
;
5666 cf2
.dwEffects
= CFE_ITALIC
^ cf2
.dwEffects
;
5667 SendMessage(hwndRichedit_WM_NOTIFY
, EM_SETCHARFORMAT
, 0, (LPARAM
) &cf2
);
5668 ok(received_WM_NOTIFY
== 0, "Unexpected WM_NOTIFY was sent!\n");
5670 /* WM_SETTEXT should NOT cause a WM_NOTIFY to be sent when selection is
5672 received_WM_NOTIFY
= 0;
5673 modify_at_WM_NOTIFY
= 0;
5674 SendMessage(hwndRichedit_WM_NOTIFY
, WM_SETTEXT
, 0, (LPARAM
)"sometext");
5675 ok(received_WM_NOTIFY
== 0, "Unexpected WM_NOTIFY was sent!\n");
5676 ok(modify_at_WM_NOTIFY
== 0, "WM_NOTIFY callback saw text flagged as modified!\n");
5678 received_WM_NOTIFY
= 0;
5679 modify_at_WM_NOTIFY
= 0;
5680 SendMessage(hwndRichedit_WM_NOTIFY
, EM_SETSEL
, 4, 4);
5681 ok(received_WM_NOTIFY
== 1, "Expected WM_NOTIFY was NOT sent!\n");
5683 received_WM_NOTIFY
= 0;
5684 modify_at_WM_NOTIFY
= 0;
5685 SendMessage(hwndRichedit_WM_NOTIFY
, WM_SETTEXT
, 0, (LPARAM
)"sometext");
5686 ok(received_WM_NOTIFY
== 1, "Expected WM_NOTIFY was NOT sent!\n");
5687 ok(modify_at_WM_NOTIFY
== 0, "WM_NOTIFY callback saw text flagged as modified!\n");
5689 /* Test for WM_NOTIFY messages with redraw disabled. */
5690 SendMessage(hwndRichedit_WM_NOTIFY
, EM_SETSEL
, 0, 0);
5691 SendMessage(hwndRichedit_WM_NOTIFY
, WM_SETREDRAW
, FALSE
, 0);
5692 received_WM_NOTIFY
= 0;
5693 SendMessage(hwndRichedit_WM_NOTIFY
, EM_REPLACESEL
, FALSE
, (LPARAM
)"inserted");
5694 ok(received_WM_NOTIFY
== 1, "Expected WM_NOTIFY was NOT sent!\n");
5695 SendMessage(hwndRichedit_WM_NOTIFY
, WM_SETREDRAW
, TRUE
, 0);
5697 DestroyWindow(hwndRichedit_WM_NOTIFY
);
5698 DestroyWindow(parent
);
5701 static void test_undo_coalescing(void)
5705 char buffer
[64] = {0};
5707 /* multi-line control inserts CR normally */
5709 hwnd
= CreateWindowExA(0, "RichEdit20W", NULL
, WS_POPUP
|ES_MULTILINE
,
5710 0, 0, 200, 60, 0, 0, 0, 0);
5712 hwnd
= CreateWindowExA(0, "RichEdit20A", NULL
, WS_POPUP
|ES_MULTILINE
,
5713 0, 0, 200, 60, 0, 0, 0, 0);
5714 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
5716 result
= SendMessage(hwnd
, EM_CANUNDO
, 0, 0);
5717 ok (result
== FALSE
, "Can undo after window creation.\n");
5718 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5719 ok (result
== FALSE
, "Undo operation successful with nothing to undo.\n");
5720 result
= SendMessage(hwnd
, EM_CANREDO
, 0, 0);
5721 ok (result
== FALSE
, "Can redo after window creation.\n");
5722 result
= SendMessage(hwnd
, EM_REDO
, 0, 0);
5723 ok (result
== FALSE
, "Redo operation successful with nothing undone.\n");
5725 /* Test the effect of arrows keys during typing on undo transactions*/
5726 simulate_typing_characters(hwnd
, "one two three");
5727 SendMessage(hwnd
, WM_KEYDOWN
, VK_RIGHT
, 1);
5728 SendMessage(hwnd
, WM_KEYUP
, VK_RIGHT
, 1);
5729 simulate_typing_characters(hwnd
, " four five six");
5731 result
= SendMessage(hwnd
, EM_CANREDO
, 0, 0);
5732 ok (result
== FALSE
, "Can redo before anything is undone.\n");
5733 result
= SendMessage(hwnd
, EM_CANUNDO
, 0, 0);
5734 ok (result
== TRUE
, "Cannot undo typed characters.\n");
5735 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5736 ok (result
== TRUE
, "EM_UNDO Failed to undo typed characters.\n");
5737 result
= SendMessage(hwnd
, EM_CANREDO
, 0, 0);
5738 ok (result
== TRUE
, "Cannot redo after undo.\n");
5739 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5740 result
= strcmp(buffer
, "one two three");
5741 ok (result
== 0, "expected '%s' but got '%s'\n", "one two three", buffer
);
5743 result
= SendMessage(hwnd
, EM_CANUNDO
, 0, 0);
5744 ok (result
== TRUE
, "Cannot undo typed characters.\n");
5745 result
= SendMessage(hwnd
, WM_UNDO
, 0, 0);
5746 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5747 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5748 result
= strcmp(buffer
, "");
5749 ok (result
== 0, "expected '%s' but got '%s'\n", "", buffer
);
5751 /* Test the effect of focus changes during typing on undo transactions*/
5752 simulate_typing_characters(hwnd
, "one two three");
5753 result
= SendMessage(hwnd
, EM_CANREDO
, 0, 0);
5754 ok (result
== FALSE
, "Redo buffer should have been cleared by typing.\n");
5755 SendMessage(hwnd
, WM_KILLFOCUS
, 0, 0);
5756 SendMessage(hwnd
, WM_SETFOCUS
, 0, 0);
5757 simulate_typing_characters(hwnd
, " four five six");
5758 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5759 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5760 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5761 result
= strcmp(buffer
, "one two three");
5762 ok (result
== 0, "expected '%s' but got '%s'\n", "one two three", buffer
);
5764 /* Test the effect of the back key during typing on undo transactions */
5765 SendMessage(hwnd
, EM_EMPTYUNDOBUFFER
, 0, 0);
5766 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"");
5767 ok (result
== TRUE
, "Failed to clear the text.\n");
5768 simulate_typing_characters(hwnd
, "one two threa");
5769 result
= SendMessage(hwnd
, EM_CANREDO
, 0, 0);
5770 ok (result
== FALSE
, "Redo buffer should have been cleared by typing.\n");
5771 SendMessage(hwnd
, WM_KEYDOWN
, VK_BACK
, 1);
5772 SendMessage(hwnd
, WM_KEYUP
, VK_BACK
, 1);
5773 simulate_typing_characters(hwnd
, "e four five six");
5774 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5775 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5776 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5777 result
= strcmp(buffer
, "");
5778 ok (result
== 0, "expected '%s' but got '%s'\n", "", buffer
);
5780 /* Test the effect of the delete key during typing on undo transactions */
5781 SendMessage(hwnd
, EM_EMPTYUNDOBUFFER
, 0, 0);
5782 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"abcd");
5783 ok(result
== TRUE
, "Failed to set the text.\n");
5784 SendMessage(hwnd
, EM_SETSEL
, (WPARAM
)1, (LPARAM
)1);
5785 SendMessage(hwnd
, WM_KEYDOWN
, VK_DELETE
, 1);
5786 SendMessage(hwnd
, WM_KEYUP
, VK_DELETE
, 1);
5787 SendMessage(hwnd
, WM_KEYDOWN
, VK_DELETE
, 1);
5788 SendMessage(hwnd
, WM_KEYUP
, VK_DELETE
, 1);
5789 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5790 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5791 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5792 result
= strcmp(buffer
, "acd");
5793 ok (result
== 0, "expected '%s' but got '%s'\n", "acd", buffer
);
5794 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5795 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5796 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5797 result
= strcmp(buffer
, "abcd");
5798 ok (result
== 0, "expected '%s' but got '%s'\n", "abcd", buffer
);
5800 /* Test the effect of EM_STOPGROUPTYPING on undo transactions*/
5801 SendMessage(hwnd
, EM_EMPTYUNDOBUFFER
, 0, 0);
5802 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"");
5803 ok (result
== TRUE
, "Failed to clear the text.\n");
5804 simulate_typing_characters(hwnd
, "one two three");
5805 result
= SendMessage(hwnd
, EM_STOPGROUPTYPING
, 0, 0);
5806 ok (result
== 0, "expected %d but got %d\n", 0, result
);
5807 simulate_typing_characters(hwnd
, " four five six");
5808 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5809 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5810 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5811 result
= strcmp(buffer
, "one two three");
5812 ok (result
== 0, "expected '%s' but got '%s'\n", "one two three", buffer
);
5813 result
= SendMessage(hwnd
, EM_UNDO
, 0, 0);
5814 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5815 ok (result
== TRUE
, "Failed to undo typed characters.\n");
5816 SendMessageA(hwnd
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
)buffer
);
5817 result
= strcmp(buffer
, "");
5818 ok (result
== 0, "expected '%s' but got '%s'\n", "", buffer
);
5820 DestroyWindow(hwnd
);
5823 static LONG CALLBACK
customWordBreakProc(WCHAR
*text
, int pos
, int bytes
, int code
)
5827 /* MSDN lied, length is actually the number of bytes. */
5828 length
= bytes
/ sizeof(WCHAR
);
5831 case WB_ISDELIMITER
:
5832 return text
[pos
] == 'X';
5834 case WB_MOVEWORDLEFT
:
5835 if (customWordBreakProc(text
, pos
, bytes
, WB_ISDELIMITER
))
5837 return min(customWordBreakProc(text
, pos
, bytes
, WB_LEFTBREAK
)-1, 0);
5840 while (pos
> 0 && !customWordBreakProc(text
, pos
, bytes
, WB_ISDELIMITER
))
5844 case WB_MOVEWORDRIGHT
:
5845 if (customWordBreakProc(text
, pos
, bytes
, WB_ISDELIMITER
))
5847 return min(customWordBreakProc(text
, pos
, bytes
, WB_RIGHTBREAK
)+1, length
);
5850 while (pos
< length
&& !customWordBreakProc(text
, pos
, bytes
, WB_ISDELIMITER
))
5854 ok(FALSE
, "Unexpected code %d\n", code
);
5860 #define SEND_CTRL_LEFT(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, VK_LEFT)
5861 #define SEND_CTRL_RIGHT(hwnd) pressKeyWithModifier(hwnd, VK_CONTROL, VK_RIGHT)
5863 static void test_word_movement(void)
5867 int sel_start
, sel_end
;
5868 const WCHAR textW
[] = {'o','n','e',' ','t','w','o','X','t','h','r','e','e',0};
5870 /* multi-line control inserts CR normally */
5871 hwnd
= new_richedit(NULL
);
5873 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"one two three");
5874 ok (result
== TRUE
, "Failed to clear the text.\n");
5875 SendMessage(hwnd
, EM_SETSEL
, 0, 0);
5876 /* |one two three */
5878 SEND_CTRL_RIGHT(hwnd
);
5879 /* one |two three */
5880 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5881 ok(sel_start
== sel_end
, "Selection should be empty\n");
5882 ok(sel_start
== 4, "Cursor is at %d instead of %d\n", sel_start
, 4);
5884 SEND_CTRL_RIGHT(hwnd
);
5885 /* one two |three */
5886 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5887 ok(sel_start
== sel_end
, "Selection should be empty\n");
5888 ok(sel_start
== 9, "Cursor is at %d instead of %d\n", sel_start
, 9);
5890 SEND_CTRL_LEFT(hwnd
);
5891 /* one |two three */
5892 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5893 ok(sel_start
== sel_end
, "Selection should be empty\n");
5894 ok(sel_start
== 4, "Cursor is at %d instead of %d\n", sel_start
, 4);
5896 SEND_CTRL_LEFT(hwnd
);
5897 /* |one two three */
5898 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5899 ok(sel_start
== sel_end
, "Selection should be empty\n");
5900 ok(sel_start
== 0, "Cursor is at %d instead of %d\n", sel_start
, 0);
5902 SendMessage(hwnd
, EM_SETSEL
, 8, 8);
5903 /* one two | three */
5904 SEND_CTRL_RIGHT(hwnd
);
5905 /* one two |three */
5906 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5907 ok(sel_start
== sel_end
, "Selection should be empty\n");
5908 ok(sel_start
== 9, "Cursor is at %d instead of %d\n", sel_start
, 9);
5910 SendMessage(hwnd
, EM_SETSEL
, 11, 11);
5911 /* one two th|ree */
5912 SEND_CTRL_LEFT(hwnd
);
5913 /* one two |three */
5914 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5915 ok(sel_start
== sel_end
, "Selection should be empty\n");
5916 ok(sel_start
== 9, "Cursor is at %d instead of %d\n", sel_start
, 9);
5918 /* Test with a custom word break procedure that uses X as the delimiter. */
5919 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0, (LPARAM
)"one twoXthree");
5920 ok (result
== TRUE
, "Failed to clear the text.\n");
5921 SendMessage(hwnd
, EM_SETWORDBREAKPROC
, 0, (LPARAM
)customWordBreakProc
);
5922 /* |one twoXthree */
5923 SEND_CTRL_RIGHT(hwnd
);
5924 /* one twoX|three */
5925 SendMessage(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5926 ok(sel_start
== sel_end
, "Selection should be empty\n");
5927 ok(sel_start
== 8, "Cursor is at %d instead of %d\n", sel_start
, 8);
5929 DestroyWindow(hwnd
);
5931 /* Make sure the behaviour is the same with a unicode richedit window,
5932 * and using unicode functions. */
5935 skip("Cannot test with unicode richedit window\n");
5939 hwnd
= CreateWindowW(RICHEDIT_CLASS20W
, NULL
,
5940 ES_MULTILINE
|WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
|WS_VISIBLE
,
5941 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
5943 /* Test with a custom word break procedure that uses X as the delimiter. */
5944 result
= SendMessageW(hwnd
, WM_SETTEXT
, 0, (LPARAM
)textW
);
5945 ok (result
== TRUE
, "Failed to clear the text.\n");
5946 SendMessageW(hwnd
, EM_SETWORDBREAKPROC
, 0, (LPARAM
)customWordBreakProc
);
5947 /* |one twoXthree */
5948 SEND_CTRL_RIGHT(hwnd
);
5949 /* one twoX|three */
5950 SendMessageW(hwnd
, EM_GETSEL
, (WPARAM
)&sel_start
, (LPARAM
)&sel_end
);
5951 ok(sel_start
== sel_end
, "Selection should be empty\n");
5952 ok(sel_start
== 8, "Cursor is at %d instead of %d\n", sel_start
, 8);
5954 DestroyWindow(hwnd
);
5957 static void test_EM_CHARFROMPOS(void)
5966 /* multi-line control inserts CR normally */
5967 hwnd
= new_richedit(NULL
);
5968 result
= SendMessageA(hwnd
, WM_SETTEXT
, 0,
5969 (LPARAM
)"one two three four five six seven\reight");
5971 GetClientRect(hwnd
, &rcClient
);
5973 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
5974 ok(result
== 34, "expected character index of 34 but got %d\n", result
);
5976 /* Test with points outside the bounds of the richedit control. */
5979 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
5980 todo_wine
ok(result
== 34, "expected character index of 34 but got %d\n", result
);
5984 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
5985 todo_wine
ok(result
== 33, "expected character index of 33 but got %d\n", result
);
5989 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
5990 todo_wine
ok(result
== 39, "expected character index of 39 but got %d\n", result
);
5994 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
5995 todo_wine
ok(result
== 0, "expected character index of 0 but got %d\n", result
);
5998 point
.y
= rcClient
.bottom
+ 1;
5999 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
6000 todo_wine
ok(result
== 34, "expected character index of 34 but got %d\n", result
);
6003 point
.y
= rcClient
.bottom
;
6004 result
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
)&point
);
6005 todo_wine
ok(result
== 39, "expected character index of 39 but got %d\n", result
);
6007 DestroyWindow(hwnd
);
6010 static void test_word_wrap(void)
6013 POINTL point
= {0, 60}; /* This point must be below the first line */
6014 const char *text
= "Must be long enough to test line wrapping";
6015 DWORD dwCommonStyle
= WS_VISIBLE
|WS_POPUP
|WS_VSCROLL
|ES_MULTILINE
;
6016 int res
, pos
, lines
;
6018 /* Test the effect of WS_HSCROLL and ES_AUTOHSCROLL styles on wrapping
6019 * when specified on window creation and set later. */
6020 hwnd
= CreateWindow(RICHEDIT_CLASS
, NULL
, dwCommonStyle
,
6021 0, 0, 200, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6022 ok(hwnd
!= NULL
, "error: %d\n", (int) GetLastError());
6023 res
= SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) text
);
6024 ok(res
, "WM_SETTEXT failed.\n");
6025 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6026 ok(pos
, "pos=%d indicating no word wrap when it is expected.\n", pos
);
6027 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6028 ok(lines
> 1, "Line was expected to wrap (lines=%d).\n", lines
);
6030 SetWindowLongW(hwnd
, GWL_STYLE
, dwCommonStyle
|WS_HSCROLL
|ES_AUTOHSCROLL
);
6031 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6032 ok(pos
, "pos=%d indicating no word wrap when it is expected.\n", pos
);
6033 DestroyWindow(hwnd
);
6035 hwnd
= CreateWindow(RICHEDIT_CLASS
, NULL
, dwCommonStyle
|WS_HSCROLL
,
6036 0, 0, 200, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6037 ok(hwnd
!= NULL
, "error: %d\n", (int) GetLastError());
6039 res
= SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) text
);
6040 ok(res
, "WM_SETTEXT failed.\n");
6041 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6042 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6043 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6044 ok(lines
== 1, "Line wasn't expected to wrap (lines=%d).\n", lines
);
6046 SetWindowLongW(hwnd
, GWL_STYLE
, dwCommonStyle
);
6047 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6048 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6049 DestroyWindow(hwnd
);
6051 hwnd
= CreateWindow(RICHEDIT_CLASS
, NULL
, dwCommonStyle
|ES_AUTOHSCROLL
,
6052 0, 0, 200, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6053 ok(hwnd
!= NULL
, "error: %d\n", (int) GetLastError());
6054 res
= SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) text
);
6055 ok(res
, "WM_SETTEXT failed.\n");
6056 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6057 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6059 SetWindowLongW(hwnd
, GWL_STYLE
, dwCommonStyle
);
6060 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6061 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6062 DestroyWindow(hwnd
);
6064 hwnd
= CreateWindow(RICHEDIT_CLASS
, NULL
,
6065 dwCommonStyle
|WS_HSCROLL
|ES_AUTOHSCROLL
,
6066 0, 0, 200, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6067 ok(hwnd
!= NULL
, "error: %d\n", (int) GetLastError());
6068 res
= SendMessage(hwnd
, WM_SETTEXT
, 0, (LPARAM
) text
);
6069 ok(res
, "WM_SETTEXT failed.\n");
6070 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6071 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6073 SetWindowLongW(hwnd
, GWL_STYLE
, dwCommonStyle
);
6074 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6075 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6077 /* Test the effect of EM_SETTARGETDEVICE on word wrap. */
6078 res
= SendMessage(hwnd
, EM_SETTARGETDEVICE
, 0, 1);
6079 ok(res
, "EM_SETTARGETDEVICE failed (returned %d).\n", res
);
6080 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6081 ok(!pos
, "pos=%d indicating word wrap when none is expected.\n", pos
);
6083 res
= SendMessage(hwnd
, EM_SETTARGETDEVICE
, 0, 0);
6084 ok(res
, "EM_SETTARGETDEVICE failed (returned %d).\n", res
);
6085 pos
= SendMessage(hwnd
, EM_CHARFROMPOS
, 0, (LPARAM
) &point
);
6086 ok(pos
, "pos=%d indicating no word wrap when it is expected.\n", pos
);
6087 DestroyWindow(hwnd
);
6089 /* Test to see if wrapping happens with redraw disabled. */
6090 hwnd
= CreateWindow(RICHEDIT_CLASS
, NULL
, dwCommonStyle
,
6091 0, 0, 400, 80, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6092 ok(hwnd
!= NULL
, "error: %d\n", (int) GetLastError());
6093 SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
6094 res
= SendMessage(hwnd
, EM_REPLACESEL
, FALSE
, (LPARAM
) text
);
6095 ok(res
, "EM_REPLACESEL failed.\n");
6096 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6097 ok(lines
== 1, "Line wasn't expected to wrap (lines=%d).\n", lines
);
6098 MoveWindow(hwnd
, 0, 0, 200, 80, FALSE
);
6099 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6100 ok(lines
> 1, "Line was expected to wrap (lines=%d).\n", lines
);
6102 SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
6103 DestroyWindow(hwnd
);
6106 static void test_autoscroll(void)
6108 HWND hwnd
= new_richedit(NULL
);
6109 int lines
, ret
, redraw
;
6112 for (redraw
= 0; redraw
<= 1; redraw
++) {
6113 trace("testing with WM_SETREDRAW=%d\n", redraw
);
6114 SendMessage(hwnd
, WM_SETREDRAW
, redraw
, 0);
6115 SendMessage(hwnd
, EM_REPLACESEL
, 0, (LPARAM
)"1\n2\n3\n4\n5\n6\n7\n8");
6116 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6117 ok(lines
== 8, "%d lines instead of 8\n", lines
);
6118 ret
= SendMessage(hwnd
, EM_GETSCROLLPOS
, 0, (LPARAM
)&pt
);
6119 ok(ret
== 1, "EM_GETSCROLLPOS returned %d instead of 1\n", ret
);
6120 ok(pt
.y
!= 0, "Didn't scroll down after replacing text.\n");
6121 ret
= GetWindowLong(hwnd
, GWL_STYLE
);
6122 ok(ret
& WS_VSCROLL
, "Scrollbar was not shown yet (style=%x).\n", (UINT
)ret
);
6124 SendMessage(hwnd
, WM_SETTEXT
, 0, 0);
6125 lines
= SendMessage(hwnd
, EM_GETLINECOUNT
, 0, 0);
6126 ok(lines
== 1, "%d lines instead of 1\n", lines
);
6127 ret
= SendMessage(hwnd
, EM_GETSCROLLPOS
, 0, (LPARAM
)&pt
);
6128 ok(ret
== 1, "EM_GETSCROLLPOS returned %d instead of 1\n", ret
);
6129 ok(pt
.y
== 0, "y scroll position is %d after clearing text.\n", pt
.y
);
6130 ret
= GetWindowLong(hwnd
, GWL_STYLE
);
6131 ok(!(ret
& WS_VSCROLL
), "Scrollbar is still shown (style=%x).\n", (UINT
)ret
);
6134 SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
6135 DestroyWindow(hwnd
);
6137 /* The WS_VSCROLL and WS_HSCROLL styles implicitly set
6138 * auto vertical/horizontal scrolling options. */
6139 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6140 WS_POPUP
|ES_MULTILINE
|WS_VSCROLL
|WS_HSCROLL
,
6141 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6142 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6143 ret
= SendMessage(hwnd
, EM_GETOPTIONS
, 0, 0);
6144 ok(ret
& ECO_AUTOVSCROLL
, "ECO_AUTOVSCROLL isn't set.\n");
6145 ok(ret
& ECO_AUTOHSCROLL
, "ECO_AUTOHSCROLL isn't set.\n");
6146 ret
= GetWindowLong(hwnd
, GWL_STYLE
);
6147 ok(!(ret
& ES_AUTOVSCROLL
), "ES_AUTOVSCROLL is set.\n");
6148 ok(!(ret
& ES_AUTOHSCROLL
), "ES_AUTOHSCROLL is set.\n");
6149 DestroyWindow(hwnd
);
6151 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6152 WS_POPUP
|ES_MULTILINE
,
6153 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6154 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6155 ret
= SendMessage(hwnd
, EM_GETOPTIONS
, 0, 0);
6156 ok(!(ret
& ECO_AUTOVSCROLL
), "ECO_AUTOVSCROLL is set.\n");
6157 ok(!(ret
& ECO_AUTOHSCROLL
), "ECO_AUTOHSCROLL is set.\n");
6158 ret
= GetWindowLong(hwnd
, GWL_STYLE
);
6159 ok(!(ret
& ES_AUTOVSCROLL
), "ES_AUTOVSCROLL is set.\n");
6160 ok(!(ret
& ES_AUTOHSCROLL
), "ES_AUTOHSCROLL is set.\n");
6161 DestroyWindow(hwnd
);
6165 static void test_format_rect(void)
6168 RECT rc
, expected
, clientRect
;
6172 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6173 ES_MULTILINE
|WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
|WS_VISIBLE
,
6174 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6175 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6177 GetClientRect(hwnd
, &clientRect
);
6179 expected
= clientRect
;
6181 expected
.right
-= 1;
6182 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6183 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6184 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6185 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6186 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6187 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6189 for (n
= -3; n
<= 3; n
++)
6196 SendMessageA(hwnd
, EM_SETRECT
, 0, (LPARAM
)&rc
);
6199 expected
.top
= max(0, rc
.top
);
6200 expected
.left
= max(0, rc
.left
);
6201 expected
.bottom
= min(clientRect
.bottom
, rc
.bottom
);
6202 expected
.right
= min(clientRect
.right
, rc
.right
);
6203 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6204 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6205 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6206 "[n=%d] rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6207 n
, rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6208 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6212 SendMessageA(hwnd
, EM_SETRECT
, 0, (LPARAM
)&rc
);
6213 expected
= clientRect
;
6214 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6215 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6216 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6217 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6218 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6219 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6221 /* Adding the selectionbar adds the selectionbar width to the left side. */
6222 SendMessageA(hwnd
, EM_SETOPTIONS
, ECOOP_OR
, ECO_SELECTIONBAR
);
6223 options
= SendMessageA(hwnd
, EM_GETOPTIONS
, 0, 0);
6224 ok(options
& ECO_SELECTIONBAR
, "EM_SETOPTIONS failed to add selectionbar.\n");
6225 expected
.left
+= 8; /* selection bar width */
6226 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6227 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6228 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6229 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6230 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6231 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6234 SendMessageA(hwnd
, EM_SETRECT
, 0, (LPARAM
)&rc
);
6235 expected
= clientRect
;
6236 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6237 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6238 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6239 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6240 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6241 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6243 /* Removing the selectionbar subtracts the selectionbar width from the left side,
6244 * even if the left side is already 0. */
6245 SendMessageA(hwnd
, EM_SETOPTIONS
, ECOOP_AND
, ~ECO_SELECTIONBAR
);
6246 options
= SendMessageA(hwnd
, EM_GETOPTIONS
, 0, 0);
6247 ok(!(options
& ECO_SELECTIONBAR
), "EM_SETOPTIONS failed to remove selectionbar.\n");
6248 expected
.left
-= 8; /* selection bar width */
6249 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6250 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6251 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6252 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6253 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6254 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6256 /* Set the absolute value of the formatting rectangle. */
6258 SendMessageA(hwnd
, EM_SETRECT
, 0, (LPARAM
)&rc
);
6259 expected
= clientRect
;
6260 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6261 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6262 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6263 "[n=%d] rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6264 n
, rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6265 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6267 /* MSDN documents the EM_SETRECT message as using the rectangle provided in
6268 * LPARAM as being a relative offset when the WPARAM value is 1, but these
6269 * tests show that this isn't true. */
6272 rc
.bottom
= clientRect
.bottom
- 15;
6273 rc
.right
= clientRect
.right
- 15;
6275 SendMessageA(hwnd
, EM_SETRECT
, 1, (LPARAM
)&rc
);
6276 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6277 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6278 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6279 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6280 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6281 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6283 /* For some reason it does not limit the values to the client rect with
6284 * a WPARAM value of 1. */
6287 rc
.bottom
= clientRect
.bottom
+ 15;
6288 rc
.right
= clientRect
.right
+ 15;
6290 SendMessageA(hwnd
, EM_SETRECT
, 1, (LPARAM
)&rc
);
6291 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6292 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6293 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6294 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6295 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6296 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6298 DestroyWindow(hwnd
);
6300 /* The extended window style affects the formatting rectangle. */
6301 hwnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, RICHEDIT_CLASS
, NULL
,
6302 ES_MULTILINE
|WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
|WS_VISIBLE
,
6303 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6304 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6306 GetClientRect(hwnd
, &clientRect
);
6308 expected
= clientRect
;
6311 expected
.right
-= 1;
6312 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6313 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6314 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6315 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6316 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6317 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6327 expected
.right
+= 1;
6328 SendMessageA(hwnd
, EM_SETRECT
, 0, (LPARAM
)&rc
);
6329 SendMessageA(hwnd
, EM_GETRECT
, 0, (LPARAM
)&rc
);
6330 ok(rc
.top
== expected
.top
&& rc
.left
== expected
.left
&&
6331 rc
.bottom
== expected
.bottom
&& rc
.right
== expected
.right
,
6332 "rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
6333 rc
.top
, rc
.left
, rc
.bottom
, rc
.right
,
6334 expected
.top
, expected
.left
, expected
.bottom
, expected
.right
);
6336 DestroyWindow(hwnd
);
6339 static void test_WM_GETDLGCODE(void)
6345 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6347 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6348 ES_MULTILINE
|ES_WANTRETURN
|WS_POPUP
,
6349 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6350 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6352 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, 0);
6353 expected
= expected
| DLGC_WANTMESSAGE
;
6354 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6356 DestroyWindow(hwnd
);
6358 msg
.message
= WM_KEYDOWN
;
6359 msg
.wParam
= VK_RETURN
;
6360 msg
.lParam
= MapVirtualKey(VK_RETURN
, MAPVK_VK_TO_VSC
) | 0x0001;
6363 msg
.time
= GetTickCount();
6365 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6366 ES_MULTILINE
|ES_WANTRETURN
|WS_POPUP
,
6367 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6368 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6370 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6371 expected
= expected
| DLGC_WANTMESSAGE
;
6372 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6374 DestroyWindow(hwnd
);
6376 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6377 ES_MULTILINE
|WS_POPUP
,
6378 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6379 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6381 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6382 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6383 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6385 DestroyWindow(hwnd
);
6387 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6388 ES_WANTRETURN
|WS_POPUP
,
6389 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6390 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6392 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6393 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6394 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6396 DestroyWindow(hwnd
);
6398 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6400 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6401 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6403 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6404 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6405 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6407 DestroyWindow(hwnd
);
6409 msg
.wParam
= VK_TAB
;
6410 msg
.lParam
= MapVirtualKey(VK_TAB
, MAPVK_VK_TO_VSC
) | 0x0001;
6412 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6413 ES_MULTILINE
|WS_POPUP
,
6414 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6415 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6417 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6418 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6419 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6421 DestroyWindow(hwnd
);
6423 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6425 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6426 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6428 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6429 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6430 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6432 DestroyWindow(hwnd
);
6434 hold_key(VK_CONTROL
);
6436 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6437 ES_MULTILINE
|WS_POPUP
,
6438 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6439 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6441 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6442 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6443 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6445 DestroyWindow(hwnd
);
6447 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6449 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6450 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6452 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6453 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6454 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6456 DestroyWindow(hwnd
);
6458 release_key(VK_CONTROL
);
6461 msg
.lParam
= MapVirtualKey('a', MAPVK_VK_TO_VSC
) | 0x0001;
6463 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6464 ES_MULTILINE
|WS_POPUP
,
6465 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6466 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6468 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6469 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6470 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6472 DestroyWindow(hwnd
);
6474 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6476 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6477 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6479 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6480 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6481 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6483 DestroyWindow(hwnd
);
6485 msg
.message
= WM_CHAR
;
6487 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6488 ES_MULTILINE
|WS_POPUP
,
6489 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6490 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6492 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6493 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
|DLGC_WANTMESSAGE
;
6494 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6496 DestroyWindow(hwnd
);
6498 hwnd
= CreateWindowEx(0, RICHEDIT_CLASS
, NULL
,
6500 0, 0, 200, 60, NULL
, NULL
, hmoduleRichEdit
, NULL
);
6501 ok(hwnd
!= NULL
, "class: %s, error: %d\n", RICHEDIT_CLASS
, (int) GetLastError());
6503 res
= SendMessage(hwnd
, WM_GETDLGCODE
, VK_RETURN
, (LPARAM
)&msg
);
6504 expected
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
6505 ok(res
== expected
, "WM_GETDLGCODE returned %x but expected %x\n",
6507 DestroyWindow(hwnd
);
6510 static void test_zoom(void)
6516 int numerator
, denominator
;
6518 hwnd
= new_richedit(NULL
);
6519 GetClientRect(hwnd
, &rc
);
6520 pt
.x
= (rc
.right
- rc
.left
) / 2;
6521 pt
.y
= (rc
.bottom
- rc
.top
) / 2;
6522 ClientToScreen(hwnd
, &pt
);
6524 /* Test initial zoom value */
6525 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6526 ok(numerator
== 0, "Numerator should be initialized to 0 (got %d).\n", numerator
);
6527 ok(denominator
== 0, "Denominator should be initialized to 0 (got %d).\n", denominator
);
6528 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6530 /* test scroll wheel */
6531 hold_key(VK_CONTROL
);
6532 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, WHEEL_DELTA
),
6533 MAKELPARAM(pt
.x
, pt
.y
));
6534 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6535 release_key(VK_CONTROL
);
6537 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6538 ok(numerator
== 110, "incorrect numerator is %d\n", numerator
);
6539 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6540 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6542 /* Test how much the mouse wheel can zoom in and out. */
6543 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)490, (LPARAM
)100);
6544 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6546 hold_key(VK_CONTROL
);
6547 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, WHEEL_DELTA
),
6548 MAKELPARAM(pt
.x
, pt
.y
));
6549 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6550 release_key(VK_CONTROL
);
6552 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6553 ok(numerator
== 500, "incorrect numerator is %d\n", numerator
);
6554 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6555 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6557 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)491, (LPARAM
)100);
6558 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6560 hold_key(VK_CONTROL
);
6561 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, WHEEL_DELTA
),
6562 MAKELPARAM(pt
.x
, pt
.y
));
6563 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6564 release_key(VK_CONTROL
);
6566 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6567 ok(numerator
== 491, "incorrect numerator is %d\n", numerator
);
6568 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6569 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6571 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)20, (LPARAM
)100);
6572 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6574 hold_key(VK_CONTROL
);
6575 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, -WHEEL_DELTA
),
6576 MAKELPARAM(pt
.x
, pt
.y
));
6577 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6578 release_key(VK_CONTROL
);
6580 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6581 ok(numerator
== 10, "incorrect numerator is %d\n", numerator
);
6582 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6583 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6585 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)19, (LPARAM
)100);
6586 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6588 hold_key(VK_CONTROL
);
6589 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, -WHEEL_DELTA
),
6590 MAKELPARAM(pt
.x
, pt
.y
));
6591 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6592 release_key(VK_CONTROL
);
6594 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6595 ok(numerator
== 19, "incorrect numerator is %d\n", numerator
);
6596 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6597 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6599 /* Test how WM_SCROLLWHEEL treats our custom denominator. */
6600 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)50, (LPARAM
)13);
6601 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6603 hold_key(VK_CONTROL
);
6604 ret
= SendMessage(hwnd
, WM_MOUSEWHEEL
, MAKEWPARAM(MK_CONTROL
, WHEEL_DELTA
),
6605 MAKELPARAM(pt
.x
, pt
.y
));
6606 ok(!ret
, "WM_MOUSEWHEEL failed (%d).\n", ret
);
6607 release_key(VK_CONTROL
);
6609 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6610 ok(numerator
== 394, "incorrect numerator is %d\n", numerator
);
6611 ok(denominator
== 100, "incorrect denominator is %d\n", denominator
);
6612 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6614 /* Test bounds checking on EM_SETZOOM */
6615 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)2, (LPARAM
)127);
6616 ok(ret
== TRUE
, "EM_SETZOOM rejected valid values (%d).\n", ret
);
6618 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)127, (LPARAM
)2);
6619 ok(ret
== TRUE
, "EM_SETZOOM rejected valid values (%d).\n", ret
);
6621 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)2, (LPARAM
)128);
6622 ok(ret
== FALSE
, "EM_SETZOOM accepted invalid values (%d).\n", ret
);
6624 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6625 ok(numerator
== 127, "incorrect numerator is %d\n", numerator
);
6626 ok(denominator
== 2, "incorrect denominator is %d\n", denominator
);
6627 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6629 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)128, (LPARAM
)2);
6630 ok(ret
== FALSE
, "EM_SETZOOM accepted invalid values (%d).\n", ret
);
6632 /* See if negative numbers are accepted. */
6633 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)-100, (LPARAM
)-100);
6634 ok(ret
== FALSE
, "EM_SETZOOM accepted invalid values (%d).\n", ret
);
6636 /* See if negative numbers are accepted. */
6637 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)0, (LPARAM
)100);
6638 ok(ret
== FALSE
, "EM_SETZOOM failed (%d).\n", ret
);
6640 ret
= SendMessage(hwnd
, EM_GETZOOM
, (WPARAM
)&numerator
, (LPARAM
)&denominator
);
6641 ok(numerator
== 127, "incorrect numerator is %d\n", numerator
);
6642 ok(denominator
== 2, "incorrect denominator is %d\n", denominator
);
6643 ok(ret
== TRUE
, "EM_GETZOOM failed (%d).\n", ret
);
6645 /* Reset the zoom value */
6646 ret
= SendMessage(hwnd
, EM_SETZOOM
, (WPARAM
)0, (LPARAM
)0);
6647 ok(ret
== TRUE
, "EM_SETZOOM failed (%d).\n", ret
);
6649 DestroyWindow(hwnd
);
6652 START_TEST( editor
)
6654 /* Must explicitly LoadLibrary(). The test has no references to functions in
6655 * RICHED20.DLL, so the linker doesn't actually link to it. */
6656 hmoduleRichEdit
= LoadLibrary("RICHED20.DLL");
6657 ok(hmoduleRichEdit
!= NULL
, "error: %d\n", (int) GetLastError());
6659 is_win9x
= GetVersion() & 0x80000000;
6664 test_EM_POSFROMCHAR();
6665 test_EM_SCROLLCARET();
6667 test_scrollbar_visibility();
6669 test_EM_LINELENGTH();
6670 test_EM_SETCHARFORMAT();
6671 test_EM_SETTEXTMODE();
6672 test_TM_PLAINTEXT();
6673 test_EM_SETOPTIONS();
6675 test_EM_GETTEXTRANGE();
6676 test_EM_GETSELTEXT();
6677 test_EM_SETUNDOLIMIT();
6679 test_EM_SETTEXTEX();
6680 test_EM_LIMITTEXT();
6681 test_EM_EXLIMITTEXT();
6682 test_EM_GETLIMITTEXT();
6684 test_EM_GETMODIFY();
6688 test_EM_STREAMOUT();
6689 test_EM_STREAMOUT_FONTTBL();
6690 test_EM_StreamIn_Undo();
6691 test_EM_FORMATRANGE();
6692 test_unicode_conversions();
6693 test_EM_GETTEXTLENGTHEX();
6694 test_EM_REPLACESEL(1);
6695 test_EM_REPLACESEL(0);
6697 test_EM_AUTOURLDETECT();
6699 test_undo_coalescing();
6700 test_word_movement();
6701 test_EM_CHARFROMPOS();
6702 test_SETPARAFORMAT();
6706 test_WM_GETDLGCODE();
6709 /* Set the environment variable WINETEST_RICHED20 to keep windows
6710 * responsive and open for 30 seconds. This is useful for debugging.
6712 if (getenv( "WINETEST_RICHED20" )) {
6713 keep_responsive(30);
6716 OleFlushClipboard();
6717 ok(FreeLibrary(hmoduleRichEdit
) != 0, "error: %d\n", (int) GetLastError());