4 * Copyright (c) 2004 Zach Gorman
5 * Copyright 2007 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
30 #define MODIFIED(rect) (rect.left = 10 && rect.right != 100 && rect.top == 10 && rect.bottom != 100)
31 #define SAME(rect) (rect.left = 10 && rect.right == 100 && rect.top == 10 && rect.bottom == 100)
32 #define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
34 static void test_DrawTextCalcRect(void)
38 HFONT hFont
, hOldFont
;
40 static CHAR text
[] = "Example text for testing DrawText in "
42 static WCHAR textW
[] = {'W','i','d','e',' ','c','h','a','r',' ',
43 's','t','r','i','n','g','\0'};
44 static CHAR emptystring
[] = "";
45 static WCHAR emptystringW
[] = { 0 };
46 INT textlen
, textheight
, heightcheck
;
47 RECT rect
= { 0, 0, 100, 0 };
50 BOOL conform_xp
= TRUE
;
53 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
54 0, 0, 200, 200, 0, 0, 0, NULL
);
55 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
57 ok(hdc
!= 0, "GetDC error %u\n", GetLastError());
58 trace("hdc %p\n", hdc
);
59 textlen
= lstrlenA(text
);
61 /* LOGFONT initialization */
62 memset(&lf
, 0, sizeof(lf
));
63 lf
.lfCharSet
= ANSI_CHARSET
;
64 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
65 lf
.lfWeight
= FW_DONTCARE
;
66 lf
.lfHeight
= 0; /* mapping mode dependent */
67 lf
.lfQuality
= DEFAULT_QUALITY
;
68 lstrcpyA(lf
.lfFaceName
, "Arial");
70 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
71 SetMapMode(hdc
, MM_HIENGLISH
);
72 lf
.lfHeight
= 100 * 9 / 72; /* 9 point */
73 hFont
= CreateFontIndirectA(&lf
);
74 ok(hFont
!= 0, "CreateFontIndirectA error %u\n",
76 hOldFont
= SelectObject(hdc
, hFont
);
78 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
79 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
81 ok( textheight
, "DrawTextA error %u\n", GetLastError());
83 trace("MM_HIENGLISH rect.bottom %d\n", rect
.bottom
);
84 todo_wine
ok(rect
.bottom
< 0, "In MM_HIENGLISH, DrawText with "
85 "DT_CALCRECT should return a negative rectangle bottom. "
86 "(bot=%d)\n", rect
.bottom
);
88 SelectObject(hdc
, hOldFont
);
89 ret
= DeleteObject(hFont
);
90 ok( ret
, "DeleteObject error %u\n", GetLastError());
93 /* DrawText in MM_TEXT with DT_CALCRECT */
94 SetMapMode(hdc
, MM_TEXT
);
95 lf
.lfHeight
= -MulDiv(9, GetDeviceCaps(hdc
,
96 LOGPIXELSY
), 72); /* 9 point */
97 hFont
= CreateFontIndirectA(&lf
);
98 ok(hFont
!= 0, "CreateFontIndirectA error %u\n",
100 hOldFont
= SelectObject(hdc
, hFont
);
102 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
103 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
105 ok( textheight
, "DrawTextA error %u\n", GetLastError());
107 trace("MM_TEXT rect.bottom %d\n", rect
.bottom
);
108 ok(rect
.bottom
> 0, "In MM_TEXT, DrawText with DT_CALCRECT "
109 "should return a positive rectangle bottom. (bot=%d)\n",
112 /* empty or null text should in some cases calc an empty rectangle */
114 SetRect( &rect
, 10,10, 100, 100);
115 heightcheck
= textheight
= DrawTextExA(hdc
, text
, 0, &rect
, DT_CALCRECT
, NULL
);
116 ok( !EMPTY(rect
) && !MODIFIED(rect
),
117 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
118 if (textheight
!= 0) /* Windows 98 */
120 win_skip("XP conformity failed, skipping XP tests. Probably win9x\n");
124 ok(textheight
==0,"Got textheight from DrawTextExA\n");
126 SetRect( &rect
, 10,10, 100, 100);
127 textheight
= DrawTextA(hdc
, text
, 0, &rect
, DT_CALCRECT
);
128 ok( !EMPTY(rect
) && !MODIFIED(rect
),
129 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
130 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
132 ok(textheight
==0,"Got textheight from DrawTextA\n");
133 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
135 SetRect( &rect
, 10,10, 100, 100);
137 heightcheck
= textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
, NULL
);
139 "rectangle should be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
140 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
142 SetRect( &rect
, 10,10, 100, 100);
143 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
);
145 "rectangle should be empty got %d,%d-%d,%d\n",
146 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
147 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
148 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
150 SetRect( &rect
, 10,10, 100, 100);
152 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
, NULL
);
153 ok( EMPTY(rect
) || !MODIFIED(rect
),
154 "rectangle should be empty or not modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
155 if (!textheight
) /* Windows NT 4 */
158 win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
162 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
164 SetRect( &rect
, 10,10, 100, 100);
165 textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
);
166 ok( EMPTY(rect
) || !MODIFIED(rect
),
167 "rectangle should be empty or NOT modified got %d,%d-%d,%d\n",
168 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
170 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
171 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
173 SetRect( &rect
, 10,10, 100, 100);
174 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
, NULL
);
175 ok( !EMPTY(rect
) && !MODIFIED(rect
),
176 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
178 ok(textheight
==0,"Got textheight from DrawTextExA\n");
180 SetRect( &rect
, 10,10, 100, 100);
181 textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
);
182 ok( !EMPTY(rect
) && !MODIFIED(rect
),
183 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
184 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
186 ok(textheight
==0,"Got textheight from DrawTextA\n");
187 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
189 /* DT_SINGLELINE tests */
191 SetRect( &rect
, 10,10, 100, 100);
192 heightcheck
= textheight
= DrawTextExA(hdc
, text
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
193 ok( !EMPTY(rect
) && !MODIFIED(rect
),
194 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
196 ok(textheight
==0,"Got textheight from DrawTextExA\n");
198 SetRect( &rect
, 10,10, 100, 100);
199 textheight
= DrawTextA(hdc
, text
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
200 ok( !EMPTY(rect
) && !MODIFIED(rect
),
201 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
202 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
204 ok(textheight
==0,"Got textheight from DrawTextA\n");
205 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
207 SetRect( &rect
, 10,10, 100, 100);
209 heightcheck
= textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
210 ok( !EMPTY(rect
) && MODIFIED(rect
),
211 "rectangle should be modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
212 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
214 SetRect( &rect
, 10,10, 100, 100);
215 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
216 ok( !EMPTY(rect
) && MODIFIED (rect
),
217 "rectangle should be modified got %d,%d-%d,%d\n",
218 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
219 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
220 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
222 SetRect( &rect
, 10,10, 100, 100);
224 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
225 ok( (!EMPTY(rect
) && MODIFIED(rect
)) || !MODIFIED(rect
),
226 "rectangle should be modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
228 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
230 SetRect( &rect
, 10,10, 100, 100);
231 textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
232 ok( (!EMPTY(rect
) && MODIFIED(rect
)) || !MODIFIED(rect
),
233 "rectangle should be modified got %d,%d-%d,%d\n",
234 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
236 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
237 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
239 SetRect( &rect
, 10,10, 100, 100);
240 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
241 ok( !EMPTY(rect
) && !MODIFIED(rect
),
242 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
244 ok(textheight
==0,"Got textheight from DrawTextExA\n");
246 SetRect( &rect
, 10,10, 100, 100);
247 textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
248 ok( !EMPTY(rect
) && !MODIFIED(rect
),
249 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
250 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
252 ok(textheight
==0,"Got textheight from DrawTextA\n");
253 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
255 /* further tests with 0 count, NULL and empty strings */
256 heightcheck
= textheight
= DrawTextA(hdc
, text
, 0, &rect
, 0);
258 ok(textheight
==0,"Got textheight from DrawTextA\n");
259 textheight
= DrawTextExA(hdc
, text
, 0, &rect
, 0, NULL
);
261 ok(textheight
==0,"Got textheight from DrawTextExA\n");
262 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
263 heightcheck
= textheight
= DrawTextA(hdc
, emptystring
, 0, &rect
, 0);
265 ok(textheight
==0,"Got textheight from DrawTextA\n");
266 textheight
= DrawTextExA(hdc
, emptystring
, 0, &rect
, 0, NULL
);
268 ok(textheight
==0,"Got textheight from DrawTextExA\n");
269 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
270 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, 0);
272 ok(textheight
==0,"Got textheight from DrawTextA\n");
273 textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, 0, NULL
);
275 ok(textheight
==0,"Got textheight from DrawTextExA\n");
276 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
277 heightcheck
= textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, 0);
278 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
279 textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, 0, NULL
);
280 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
281 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
282 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, 0);
284 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
285 textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, 0, NULL
);
287 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
288 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
289 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, 10, &rect
, 0);
290 ok(textheight
==0,"Got textheight from DrawTextA\n");
291 textheight
= DrawTextExA(hdc
, NULL
, 10, &rect
, 0, NULL
);
292 ok(textheight
==0,"Got textheight from DrawTextA\n");
293 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
296 /* invalid dtp size test */
297 dtp
.cbSize
= -1; /* Invalid */
298 dtp
.uiLengthDrawn
= 1337;
299 textheight
= DrawTextExA(hdc
, text
, 0, &rect
, 0, &dtp
);
300 ok(textheight
==0,"Got textheight from DrawTextExA\n");
301 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
302 dtp
.uiLengthDrawn
= 1337;
303 textheight
= DrawTextExA(hdc
, emptystring
, 0, &rect
, 0, &dtp
);
304 ok(textheight
==0,"Got textheight from DrawTextExA\n");
305 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
306 dtp
.uiLengthDrawn
= 1337;
307 textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, 0, &dtp
);
308 ok(textheight
==0,"Got textheight from DrawTextExA\n");
309 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
310 dtp
.uiLengthDrawn
= 1337;
311 textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, 0, &dtp
);
312 ok(textheight
==0,"Got textheight from DrawTextExA\n");
313 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
314 dtp
.uiLengthDrawn
= 1337;
315 textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, 0, &dtp
);
316 ok(textheight
==0,"Got textheight from DrawTextExA\n");
317 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
319 /* Margin calculations */
320 dtp
.cbSize
= sizeof(dtp
);
322 dtp
.iRightMargin
= 0;
323 SetRect( &rect
, 0, 0, 0, 0);
324 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
325 textlen
= rect
.right
; /* Width without margin */
327 SetRect( &rect
, 0, 0, 0, 0);
328 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
329 ok(rect
.right
==dtp
.iLeftMargin
+textlen
,"Incorrect left margin calculated rc(%d,%d)\n", rect
.left
, rect
.right
);
331 dtp
.iRightMargin
= 8;
332 SetRect( &rect
, 0, 0, 0, 0);
333 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
334 ok(rect
.right
==dtp
.iRightMargin
+textlen
,"Incorrect right margin calculated rc(%d,%d)\n", rect
.left
, rect
.right
);
336 /* Wide char versions */
337 SetRect( &rect
, 10,10, 100, 100);
339 heightcheck
= textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, DT_CALCRECT
, NULL
);
340 if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
) {
341 ok( !EMPTY(rect
) && !MODIFIED(rect
),
342 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
343 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
344 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
346 SetRect( &rect
, 10,10, 100, 100);
347 textheight
= DrawTextW(hdc
, textW
, 0, &rect
, DT_CALCRECT
);
348 ok( !EMPTY(rect
) && !MODIFIED(rect
),
349 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
350 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
351 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
352 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
354 SetRect( &rect
, 10,10, 100, 100);
355 heightcheck
= textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
, NULL
);
357 "rectangle should be empty got %d,%d-%d,%d\n",
358 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
359 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
361 SetRect( &rect
, 10,10, 100, 100);
362 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
);
364 "rectangle should be empty got %d,%d-%d,%d\n",
365 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
366 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
367 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
369 SetRect( &rect
, 10,10, 100, 100);
370 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
, NULL
);
371 ok( !EMPTY(rect
) && !MODIFIED(rect
),
372 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
373 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
374 if (textheight
) /* windows 2000 */
377 win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
381 ok(textheight
==0,"Got textheight from DrawTextExW\n");
383 SetRect( &rect
, 10,10, 100, 100);
384 textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
);
385 ok( !EMPTY(rect
) && !MODIFIED(rect
),
386 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
387 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
389 ok(textheight
==0,"Got textheight from DrawTextW\n");
390 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
394 SetRect( &rect
, 10,10, 100, 100);
395 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
, NULL
);
396 ok( !EMPTY(rect
) && !MODIFIED(rect
),
397 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
398 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
399 ok(textheight
==0,"Got textheight from DrawTextExW\n");
401 SetRect( &rect
, 10,10, 100, 100);
402 textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
);
403 ok( !EMPTY(rect
) && !MODIFIED(rect
),
404 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
405 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
406 ok(textheight
==0,"Got textheight from DrawTextW\n");
407 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
411 /* DT_SINGLELINE tests */
413 heightcheck
= textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
414 ok( !EMPTY(rect
) && !MODIFIED(rect
),
415 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
416 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
417 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
419 SetRect( &rect
, 10,10, 100, 100);
420 textheight
= DrawTextW(hdc
, textW
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
421 ok( !EMPTY(rect
) && !MODIFIED(rect
),
422 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
423 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
424 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
425 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
427 SetRect( &rect
, 10,10, 100, 100);
428 heightcheck
= textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
429 ok( !EMPTY(rect
) && MODIFIED(rect
),
430 "rectangle should be modified got %d,%d-%d,%d\n",
431 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
432 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
434 SetRect( &rect
, 10,10, 100, 100);
435 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
436 ok( !EMPTY(rect
) && MODIFIED(rect
),
437 "rectangle should be modified got %d,%d-%d,%d\n",
438 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
439 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
440 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
444 SetRect( &rect
, 10,10, 100, 100);
445 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
446 ok( !EMPTY(rect
) && !MODIFIED(rect
),
447 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
448 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
449 ok(textheight
==0,"Got textheight from DrawTextExW\n");
451 SetRect( &rect
, 10,10, 100, 100);
452 textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
453 ok( !EMPTY(rect
) && !MODIFIED(rect
),
454 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
455 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
456 ok(textheight
==0,"Got textheight from DrawTextW\n");
457 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
460 SetRect( &rect
, 10,10, 100, 100);
461 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
462 ok( !EMPTY(rect
) && !MODIFIED(rect
),
463 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
464 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
466 ok(textheight
==0,"Got textheight from DrawTextExW\n");
468 SetRect( &rect
, 10,10, 100, 100);
469 textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
470 ok( !EMPTY(rect
) && !MODIFIED(rect
),
471 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
472 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
474 ok(textheight
==0,"Got textheight from DrawTextW\n");
475 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
477 /* further tests with NULL and empty strings */
478 heightcheck
= textheight
= DrawTextW(hdc
, textW
, 0, &rect
, 0);
479 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
480 textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, 0, NULL
);
481 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
482 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
483 heightcheck
= textheight
= DrawTextW(hdc
, emptystringW
, 0, &rect
, 0);
484 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
485 textheight
= DrawTextExW(hdc
, emptystringW
, 0, &rect
, 0, NULL
);
486 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
487 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
488 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, 0);
490 ok(textheight
==0,"Got textheight from DrawTextW\n");
491 textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, 0, NULL
);
493 ok(textheight
==0,"Got textheight from DrawTextExW\n");
494 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
495 heightcheck
= textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, 0);
496 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
497 textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, 0, NULL
);
498 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
499 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
502 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, 0);
503 ok(textheight
==0,"Got textheight from DrawTextW\n");
504 textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, 0, NULL
);
505 ok(textheight
==0,"Got textheight from DrawTextExW\n");
506 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
507 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, 10, &rect
, 0);
508 ok(textheight
==0,"Got textheight from DrawTextW\n");
509 textheight
= DrawTextExW(hdc
, NULL
, 10, &rect
, 0, NULL
);
510 ok(textheight
==0,"Got textheight from DrawTextW\n");
511 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
514 dtp
.cbSize
= -1; /* Invalid */
515 dtp
.uiLengthDrawn
= 1337;
516 textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, 0, &dtp
);
517 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
518 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
519 dtp
.uiLengthDrawn
= 1337;
520 textheight
= DrawTextExW(hdc
, emptystringW
, 0, &rect
, 0, &dtp
);
522 ok(textheight
==0,"Got textheight from DrawTextExW\n");
523 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
524 dtp
.uiLengthDrawn
= 1337;
525 textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, 0, &dtp
);
527 ok(textheight
==0,"Got textheight from DrawTextExW\n");
528 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
529 dtp
.uiLengthDrawn
= 1337;
530 textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, 0, &dtp
);
531 ok(textheight
==0,"Got textheight from DrawTextExW\n");
532 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
535 dtp
.uiLengthDrawn
= 1337;
536 textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, 0, &dtp
);
537 ok(textheight
==0,"Got textheight from DrawTextExW\n");
538 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
542 /* More test cases from bug 12226 */
543 SetRect(&rect
, 0, 0, 0, 0);
544 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
| DT_LEFT
| DT_SINGLELINE
);
545 ok(textheight
, "DrawTextA error %u\n", GetLastError());
546 ok(0 == rect
.left
, "expected 0, got %d\n", rect
.left
);
547 ok(0 == rect
.right
, "expected 0, got %d\n", rect
.right
);
548 ok(0 == rect
.top
, "expected 0, got %d\n", rect
.top
);
549 ok(rect
.bottom
, "rect.bottom should not be 0\n");
551 SetRect(&rect
, 0, 0, 0, 0);
552 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
| DT_LEFT
| DT_SINGLELINE
);
553 if (!textheight
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
555 win_skip( "DrawTextW not implemented\n" );
559 ok(textheight
, "DrawTextW error %u\n", GetLastError());
560 ok(0 == rect
.left
, "expected 0, got %d\n", rect
.left
);
561 ok(0 == rect
.right
, "expected 0, got %d\n", rect
.right
);
562 ok(0 == rect
.top
, "expected 0, got %d\n", rect
.top
);
563 ok(rect
.bottom
, "rect.bottom should not be 0\n");
566 SelectObject(hdc
, hOldFont
);
567 ret
= DeleteObject(hFont
);
568 ok( ret
, "DeleteObject error %u\n", GetLastError());
571 ret
= ReleaseDC(hwnd
, hdc
);
572 ok( ret
, "ReleaseDC error %u\n", GetLastError());
573 ret
= DestroyWindow(hwnd
);
574 ok( ret
, "DestroyWindow error %u\n", GetLastError());
577 /* replace tabs by \t */
578 static void strfmt( const char *str
, char *strout
)
581 for(i
=0,j
=0;i
<=strlen(str
);i
++,j
++)
582 if((strout
[j
]=str
[i
])=='\t') {
589 #define TABTEST( tabval, tabcount, string, _exp) \
590 { int i,x_act, x_exp; char strdisp[64];\
591 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
592 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
593 strfmt( string, strdisp); \
594 /* trace( "Extent is %08lx\n", extent); */\
595 x_act = LOWORD( extent); \
597 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
598 strdisp, x_act, x_exp, tabval, tabcount); \
602 static void test_TabbedText(void)
609 INT tabs
[8], cx
, cy
, tab
, tabcount
,t
,align
;
612 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
613 0, 0, 200, 200, 0, 0, 0, NULL
);
614 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
616 ok(hdc
!= 0, "GetDC error %u\n", GetLastError());
618 ret
= GetTextMetricsA( hdc
, &tm
);
619 ok( ret
, "GetTextMetrics error %u\n", GetLastError());
621 extent
= GetTabbedTextExtentA( hdc
, "x", 1, 1, tabs
);
622 cx
= LOWORD( extent
);
623 cy
= HIWORD( extent
);
624 trace( "cx is %d cy is %d\n", cx
, cy
);
627 for( t
=-1; t
<=1; t
++) { /* slightly adjust the 4 char tabstop, to
628 catch the one off errors */
630 /* test the special case tabcount =1 and the general array (80 of tabs */
631 for( tabcount
= 1; tabcount
<= 8; tabcount
+=7) {
632 TABTEST( align
* tab
, tabcount
, "\t", tab
)
633 TABTEST( align
* tab
, tabcount
, "xxx\t", tab
)
634 TABTEST( align
* tab
, tabcount
, "\tx", tab
+cx
)
635 TABTEST( align
* tab
, tabcount
, "\t\t", tab
*2)
636 TABTEST( align
* tab
, tabcount
, "\tx\t", tab
*2)
637 TABTEST( align
* tab
, tabcount
, "x\tx", tab
+cx
)
638 TABTEST( align
* tab
, tabcount
, "xx\tx", tab
+cx
)
639 TABTEST( align
* tab
, tabcount
, "xxx\tx", tab
+cx
)
640 TABTEST( align
* tab
, tabcount
, "xxxx\tx", t
>0 ? tab
+ cx
: 2*tab
+cx
)
641 TABTEST( align
* tab
, tabcount
, "xxxxx\tx", 2*tab
+cx
)
645 for( t
=-1; t
<=1; t
++) { /* slightly adjust the 4 char tabstop, to
646 catch the one off errors */
648 /* test the special case tabcount =1 and the general array (8) of tabs */
649 for( tabcount
= 1; tabcount
<= 8; tabcount
+=7) {
650 TABTEST( align
* tab
, tabcount
, "\t", tab
)
651 TABTEST( align
* tab
, tabcount
, "xxx\t", tab
)
652 TABTEST( align
* tab
, tabcount
, "\tx", tab
)
653 TABTEST( align
* tab
, tabcount
, "\t\t", tab
*2)
654 TABTEST( align
* tab
, tabcount
, "\tx\t", tab
*2)
655 TABTEST( align
* tab
, tabcount
, "x\tx", tab
)
656 TABTEST( align
* tab
, tabcount
, "xx\tx", tab
)
657 TABTEST( align
* tab
, tabcount
, "xxx\tx", 4 * cx
>= tab
? 2*tab
:tab
)
658 TABTEST( align
* tab
, tabcount
, "xxxx\tx", 2*tab
)
659 TABTEST( align
* tab
, tabcount
, "xxxxx\tx", 2*tab
)
663 ReleaseDC( hwnd
, hdc
);
664 DestroyWindow( hwnd
);
667 static void test_DrawState(void)
669 static const char text
[] = "Sample text string";
674 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
675 0, 0, 200, 200, 0, 0, 0, NULL
);
681 SetLastError(0xdeadbeef);
682 ret
= DrawState(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, (LPARAM
)text
, strlen(text
),
683 0, 0, 10, 10, DST_TEXT
);
684 ok(ret
, "DrawState error %u\n", GetLastError());
686 SetLastError(0xdeadbeef);
687 ret
= DrawState(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, (LPARAM
)text
, 0,
688 0, 0, 10, 10, DST_TEXT
);
689 ok(ret
, "DrawState error %u\n", GetLastError());
691 SetLastError(0xdeadbeef);
692 ret
= DrawState(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, 0, strlen(text
),
693 0, 0, 10, 10, DST_TEXT
);
694 ok(!ret
|| broken(ret
) /* win98 */, "DrawState succeeded\n");
695 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
697 SetLastError(0xdeadbeef);
698 ret
= DrawState(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, 0, 0,
699 0, 0, 10, 10, DST_TEXT
);
700 ok(!ret
|| broken(ret
) /* win98 */, "DrawState succeeded\n");
701 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
703 ReleaseDC(hwnd
, hdc
);
710 test_DrawTextCalcRect();