user32: Delay creation of the 55AA pattern brush until it's needed.
[wine.git] / dlls / user32 / text.c
blob7bef4761c0fc8749f442dc07dfbf27737f8b1ca6
1 /*
2 * USER text functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 2002 Bill Medland
7 * Contains
8 * 1. DrawText functions
9 * 2. GrayString functions
10 * 3. TabbedText functions
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "config.h"
28 #include "wine/port.h"
30 #include <stdarg.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <assert.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "wine/unicode.h"
39 #include "winnls.h"
40 #include "controls.h"
41 #include "usp10.h"
42 #include "user_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(text);
47 /*********************************************************************
49 * DrawText functions
51 * Design issues
52 * How many buffers to use
53 * While processing in DrawText there are potentially three different forms
54 * of the text that need to be held. How are they best held?
55 * 1. The original text is needed, of course, to see what to display.
56 * 2. The text that will be returned to the user if the DT_MODIFYSTRING is
57 * in effect.
58 * 3. The buffered text that is about to be displayed e.g. the current line.
59 * Typically this will exclude the ampersands used for prefixing etc.
61 * Complications.
62 * a. If the buffered text to be displayed includes the ampersands then
63 * we will need special measurement and draw functions that will ignore
64 * the ampersands (e.g. by copying to a buffer without the prefix and
65 * then using the normal forms). This may involve less space but may
66 * require more processing. e.g. since a line containing tabs may
67 * contain several underlined characters either we need to carry around
68 * a list of prefix locations or we may need to locate them several
69 * times.
70 * b. If we actually directly modify the "original text" as we go then we
71 * will need some special "caching" to handle the fact that when we
72 * ellipsify the text the ellipsis may modify the next line of text,
73 * which we have not yet processed. (e.g. ellipsification of a W at the
74 * end of a line will overwrite the W, the \n and the first character of
75 * the next line, and a \0 will overwrite the second. Try it!!)
77 * Option 1. Three separate storages. (To be implemented)
78 * If DT_MODIFYSTRING is in effect then allocate an extra buffer to hold
79 * the edited string in some form, either as the string itself or as some
80 * sort of "edit list" to be applied just before returning.
81 * Use a buffer that holds the ellipsified current line sans ampersands
82 * and accept the need occasionally to recalculate the prefixes (if
83 * DT_EXPANDTABS and not DT_NOPREFIX and not DT_HIDEPREFIX)
86 #define TAB 9
87 #define LF 10
88 #define CR 13
89 #define SPACE 32
90 #define PREFIX 38
91 #define ALPHA_PREFIX 30 /* Win16: Alphabet prefix */
92 #define KANA_PREFIX 31 /* Win16: Katakana prefix */
94 #define FORWARD_SLASH '/'
95 #define BACK_SLASH '\\'
97 static const WCHAR ELLIPSISW[] = {'.','.','.', 0};
99 typedef struct tag_ellipsis_data
101 int before;
102 int len;
103 int under;
104 int after;
105 } ellipsis_data;
107 /*********************************************************************
108 * TEXT_Ellipsify (static)
110 * Add an ellipsis to the end of the given string whilst ensuring it fits.
112 * If the ellipsis alone doesn't fit then it will be returned anyway.
114 * See Also TEXT_PathEllipsify
116 * Arguments
117 * hdc [in] The handle to the DC that defines the font.
118 * str [in/out] The string that needs to be modified.
119 * max_str [in] The dimension of str (number of WCHAR).
120 * len_str [in/out] The number of characters in str
121 * width [in] The maximum width permitted (in logical coordinates)
122 * size [out] The dimensions of the text
123 * modstr [out] The modified form of the string, to be returned to the
124 * calling program. It is assumed that the caller has
125 * made sufficient space available so we don't need to
126 * know the size of the space. This pointer may be NULL if
127 * the modified string is not required.
128 * len_before [out] The number of characters before the ellipsis.
129 * len_ellip [out] The number of characters in the ellipsis.
131 * See for example Microsoft article Q249678.
133 * For now we will simply use three dots rather than worrying about whether
134 * the font contains an explicit ellipsis character.
136 static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len,
137 unsigned int *len_str, int width, SIZE *size,
138 WCHAR *modstr,
139 int *len_before, int *len_ellip)
141 unsigned int len_ellipsis;
142 unsigned int lo, mid, hi;
144 len_ellipsis = strlenW (ELLIPSISW);
145 if (len_ellipsis > max_len) len_ellipsis = max_len;
146 if (*len_str > max_len - len_ellipsis)
147 *len_str = max_len - len_ellipsis;
149 /* First do a quick binary search to get an upper bound for *len_str. */
150 if (*len_str > 0 &&
151 GetTextExtentExPointW(hdc, str, *len_str, width, NULL, NULL, size) &&
152 size->cx > width)
154 for (lo = 0, hi = *len_str; lo < hi; )
156 mid = (lo + hi) / 2;
157 if (!GetTextExtentExPointW(hdc, str, mid, width, NULL, NULL, size))
158 break;
159 if (size->cx > width)
160 hi = mid;
161 else
162 lo = mid + 1;
164 *len_str = hi;
166 /* Now this should take only a couple iterations at most. */
167 for ( ; ; )
169 memcpy(str + *len_str, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
171 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
172 NULL, NULL, size)) break;
174 if (!*len_str || size->cx <= width) break;
176 (*len_str)--;
178 *len_ellip = len_ellipsis;
179 *len_before = *len_str;
180 *len_str += len_ellipsis;
182 if (modstr)
184 memcpy (modstr, str, *len_str * sizeof(WCHAR));
185 modstr[*len_str] = '\0';
189 /*********************************************************************
190 * TEXT_PathEllipsify (static)
192 * Add an ellipsis to the provided string in order to make it fit within
193 * the width. The ellipsis is added as specified for the DT_PATH_ELLIPSIS
194 * flag.
196 * See Also TEXT_Ellipsify
198 * Arguments
199 * hdc [in] The handle to the DC that defines the font.
200 * str [in/out] The string that needs to be modified
201 * max_str [in] The dimension of str (number of WCHAR).
202 * len_str [in/out] The number of characters in str
203 * width [in] The maximum width permitted (in logical coordinates)
204 * size [out] The dimensions of the text
205 * modstr [out] The modified form of the string, to be returned to the
206 * calling program. It is assumed that the caller has
207 * made sufficient space available so we don't need to
208 * know the size of the space. This pointer may be NULL if
209 * the modified string is not required.
210 * pellip [out] The ellipsification results
212 * For now we will simply use three dots rather than worrying about whether
213 * the font contains an explicit ellipsis character.
215 * The following applies, I think to Win95. We will need to extend it for
216 * Win98 which can have both path and end ellipsis at the same time (e.g.
217 * C:\MyLongFileName.Txt becomes ...\MyLongFileN...)
219 * The resulting string consists of as much as possible of the following:
220 * 1. The ellipsis itself
221 * 2. The last \ or / of the string (if any)
222 * 3. Everything after the last \ or / of the string (if any) or the whole
223 * string if there is no / or \. I believe that under Win95 this would
224 * include everything even though some might be clipped off the end whereas
225 * under Win98 that might be ellipsified too.
226 * Yet to be investigated is whether this would include wordbreaking if the
227 * filename is more than 1 word and splitting if DT_EDITCONTROL was in
228 * effect. (If DT_EDITCONTROL is in effect then on occasions text will be
229 * broken within words).
230 * 4. All the stuff before the / or \, which is placed before the ellipsis.
232 static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len,
233 unsigned int *len_str, int width, SIZE *size,
234 WCHAR *modstr, ellipsis_data *pellip)
236 int len_ellipsis;
237 int len_trailing;
238 int len_under;
239 WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
241 len_ellipsis = strlenW (ELLIPSISW);
242 if (!max_len) return;
243 if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
244 if (*len_str + len_ellipsis >= max_len)
245 *len_str = max_len - len_ellipsis-1;
246 /* Hopefully this will never happen, otherwise it would probably lose
247 * the wrong character
249 str[*len_str] = '\0'; /* to simplify things */
251 lastBkSlash = strrchrW (str, BACK_SLASH);
252 lastFwdSlash = strrchrW (str, FORWARD_SLASH);
253 lastSlash = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
254 if (!lastSlash) lastSlash = str;
255 len_trailing = *len_str - (lastSlash - str);
257 /* overlap-safe movement to the right */
258 memmove (lastSlash+len_ellipsis, lastSlash, len_trailing * sizeof(WCHAR));
259 memcpy (lastSlash, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
260 len_trailing += len_ellipsis;
261 /* From this point on lastSlash actually points to the ellipsis in front
262 * of the last slash and len_trailing includes the ellipsis
265 len_under = 0;
266 for ( ; ; )
268 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
269 NULL, NULL, size)) break;
271 if (lastSlash == str || size->cx <= width) break;
273 /* overlap-safe movement to the left */
274 memmove (lastSlash-1, lastSlash, len_trailing * sizeof(WCHAR));
275 lastSlash--;
276 len_under++;
278 assert (*len_str);
279 (*len_str)--;
281 pellip->before = lastSlash-str;
282 pellip->len = len_ellipsis;
283 pellip->under = len_under;
284 pellip->after = len_trailing - len_ellipsis;
285 *len_str += len_ellipsis;
287 if (modstr)
289 memcpy(modstr, str, *len_str * sizeof(WCHAR));
290 modstr[*len_str] = '\0';
294 /*********************************************************************
295 * TEXT_WordBreak (static)
297 * Perform wordbreak processing on the given string
299 * Assumes that DT_WORDBREAK has been specified and not all the characters
300 * fit. Note that this function should even be called when the first character
301 * that doesn't fit is known to be a space or tab, so that it can swallow them.
303 * Note that the Windows processing has some strange properties.
304 * 1. If the text is left-justified and there is room for some of the spaces
305 * that follow the last word on the line then those that fit are included on
306 * the line.
307 * 2. If the text is centered or right-justified and there is room for some of
308 * the spaces that follow the last word on the line then all but one of those
309 * that fit are included on the line.
310 * 3. (Reasonable behaviour) If the word breaking causes a space to be the first
311 * character of a new line it will be skipped.
313 * Arguments
314 * hdc [in] The handle to the DC that defines the font.
315 * str [in/out] The string that needs to be broken.
316 * max_str [in] The dimension of str (number of WCHAR).
317 * len_str [in/out] The number of characters in str
318 * width [in] The maximum width permitted
319 * format [in] The format flags in effect
320 * chars_fit [in] The maximum number of characters of str that are already
321 * known to fit; chars_fit+1 is known not to fit.
322 * chars_used [out] The number of characters of str that have been "used" and
323 * do not need to be included in later text. For example this will
324 * include any spaces that have been discarded from the start of
325 * the next line.
326 * size [out] The size of the returned text in logical coordinates
328 * Pedantic assumption - Assumes that the text length is monotonically
329 * increasing with number of characters (i.e. no weird kernings)
331 * Algorithm
333 * Work back from the last character that did fit to either a space or the last
334 * character of a word, whichever is met first.
335 * If there was one or the first character didn't fit then
336 * If the text is centered or right justified and that one character was a
337 * space then break the line before that character
338 * Otherwise break the line after that character
339 * and if the next character is a space then discard it.
340 * Suppose there was none (and the first character did fit).
341 * If Break Within Word is permitted
342 * break the word after the last character that fits (there must be
343 * at least one; none is caught earlier).
344 * Otherwise
345 * discard any trailing space.
346 * include the whole word; it may be ellipsified later
348 * Break Within Word is permitted under a set of circumstances that are not
349 * totally clear yet. Currently our best guess is:
350 * If DT_EDITCONTROL is in effect and neither DT_WORD_ELLIPSIS nor
351 * DT_PATH_ELLIPSIS is
354 static void TEXT_WordBreak (HDC hdc, WCHAR *str, unsigned int max_str,
355 unsigned int *len_str,
356 int width, int format, unsigned int chars_fit,
357 unsigned int *chars_used, SIZE *size)
359 WCHAR *p;
360 BOOL word_fits;
361 SCRIPT_LOGATTR *sla;
362 SCRIPT_ANALYSIS sa;
363 int i;
365 assert (format & DT_WORDBREAK);
366 assert (chars_fit < *len_str);
368 sla = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_LOGATTR) * *len_str);
370 memset(&sa, 0, sizeof(SCRIPT_ANALYSIS));
371 sa.eScript = SCRIPT_UNDEFINED;
373 ScriptBreak(str, *len_str, &sa, sla);
375 /* Work back from the last character that did fit to either a space or the
376 * last character of a word, whichever is met first.
378 p = str + chars_fit; /* The character that doesn't fit */
379 i = chars_fit;
380 word_fits = TRUE;
381 if (!chars_fit)
382 ; /* we pretend that it fits anyway */
383 else if (sla[i].fSoftBreak) /* chars_fit < *len_str so this is valid */
385 /* the word just fitted */
386 p--;
388 else
390 while (i > 0 && !sla[(--i)+1].fSoftBreak) p--;
391 p--;
392 word_fits = (i != 0 || sla[i+1].fSoftBreak );
395 /* If there was one or the first character didn't fit then */
396 if (word_fits)
398 BOOL next_is_space;
399 /* break the line before/after that character */
400 if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE)
401 p++;
402 next_is_space = (p - str) < *len_str && *p == SPACE;
403 *len_str = p - str;
404 /* and if the next character is a space then discard it. */
405 *chars_used = *len_str;
406 if (next_is_space)
407 (*chars_used)++;
409 /* Suppose there was none. */
410 else
412 if ((format & (DT_EDITCONTROL | DT_WORD_ELLIPSIS | DT_PATH_ELLIPSIS)) ==
413 DT_EDITCONTROL)
415 /* break the word after the last character that fits (there must be
416 * at least one; none is caught earlier).
418 *len_str = chars_fit;
419 *chars_used = chars_fit;
421 /* FIXME - possible error. Since the next character is now removed
422 * this could make the text longer so that it no longer fits, and
423 * so we need a loop to test and shrink.
426 /* Otherwise */
427 else
429 /* discard any trailing space. */
430 const WCHAR *e = str + *len_str;
431 p = str + chars_fit;
432 while (p < e && *p != SPACE)
433 p++;
434 *chars_used = p - str;
435 if (p < e) /* i.e. loop failed because *p == SPACE */
436 (*chars_used)++;
438 /* include the whole word; it may be ellipsified later */
439 *len_str = p - str;
440 /* Possible optimisation; if DT_WORD_ELLIPSIS only use chars_fit+1
441 * so that it will be too long
445 /* Remeasure the string */
446 GetTextExtentExPointW (hdc, str, *len_str, 0, NULL, NULL, size);
447 HeapFree(GetProcessHeap(),0, sla);
450 /*********************************************************************
451 * TEXT_SkipChars
453 * Skip over the given number of characters, bearing in mind prefix
454 * substitution and the fact that a character may take more than one
455 * WCHAR (Unicode surrogates are two words long) (and there may have been
456 * a trailing &)
458 * Parameters
459 * new_count [out] The updated count
460 * new_str [out] The updated pointer
461 * start_count [in] The count of remaining characters corresponding to the
462 * start of the string
463 * start_str [in] The starting point of the string
464 * max [in] The number of characters actually in this segment of the
465 * string (the & counts)
466 * n [in] The number of characters to skip (if prefix then
467 * &c counts as one)
468 * prefix [in] Apply prefix substitution
470 * Return Values
471 * none
473 * Remarks
474 * There must be at least n characters in the string
475 * We need max because the "line" may have ended with a & followed by a tab
476 * or newline etc. which we don't want to swallow
479 static void TEXT_SkipChars (int *new_count, const WCHAR **new_str,
480 int start_count, const WCHAR *start_str,
481 int max, int n, int prefix)
483 /* This is specific to wide characters, MSDN doesn't say anything much
484 * about Unicode surrogates yet and it isn't clear if _wcsinc will
485 * correctly handle them so we'll just do this the easy way for now
488 if (prefix)
490 const WCHAR *str_on_entry = start_str;
491 assert (max >= n);
492 max -= n;
493 while (n--)
495 if ((*start_str == PREFIX || *start_str == ALPHA_PREFIX) && max--)
496 start_str++;
497 start_str++;
499 start_count -= (start_str - str_on_entry);
501 else
503 start_str += n;
504 start_count -= n;
506 *new_str = start_str;
507 *new_count = start_count;
510 /*********************************************************************
511 * TEXT_Reprefix
513 * Reanalyse the text to find the prefixed character. This is called when
514 * wordbreaking or ellipsification has shortened the string such that the
515 * previously noted prefixed character is no longer visible.
517 * Parameters
518 * str [in] The original string segment (including all characters)
519 * ns [in] The number of characters in str (including prefixes)
520 * pe [in] The ellipsification data
522 * Return Values
523 * The prefix offset within the new string segment (the one that contains the
524 * ellipses and does not contain the prefix characters) (-1 if none)
527 static int TEXT_Reprefix (const WCHAR *str, unsigned int ns,
528 const ellipsis_data *pe)
530 int result = -1;
531 unsigned int i;
532 unsigned int n = pe->before + pe->under + pe->after;
533 assert (n <= ns);
534 for (i = 0; i < n; i++, str++)
536 if (i == pe->before)
538 /* Reached the path ellipsis; jump over it */
539 if (ns < pe->under) break;
540 str += pe->under;
541 ns -= pe->under;
542 i += pe->under;
543 if (!pe->after) break; /* Nothing after the path ellipsis */
545 if (!ns) break;
546 ns--;
547 if (*str == PREFIX || *str == ALPHA_PREFIX)
549 str++;
550 if (!ns) break;
551 if (*str != PREFIX)
552 result = (i < pe->before || pe->under == 0) ? i : i - pe->under + pe->len;
553 /* pe->len may be non-zero while pe_under is zero */
554 ns--;
557 return result;
560 /*********************************************************************
561 * Returns true if and only if the remainder of the line is a single
562 * newline representation or nothing
565 static BOOL remainder_is_none_or_newline (int num_chars, const WCHAR *str)
567 if (!num_chars) return TRUE;
568 if (*str != LF && *str != CR) return FALSE;
569 if (!--num_chars) return TRUE;
570 if (*str == *(str+1)) return FALSE;
571 str++;
572 if (*str != CR && *str != LF) return FALSE;
573 if (--num_chars) return FALSE;
574 return TRUE;
577 /*********************************************************************
578 * Return next line of text from a string.
580 * hdc - handle to DC.
581 * str - string to parse into lines.
582 * count - length of str.
583 * dest - destination in which to return line.
584 * len - dest buffer size in chars on input, copied length into dest on output.
585 * width - maximum width of line in pixels.
586 * format - format type passed to DrawText.
587 * retsize - returned size of the line in pixels.
588 * last_line - TRUE if is the last line that will be processed
589 * p_retstr - If DT_MODIFYSTRING this points to a cursor in the buffer in which
590 * the return string is built.
591 * tabwidth - The width of a tab in logical coordinates
592 * pprefix_offset - Here is where we return the offset within dest of the first
593 * prefixed (underlined) character. -1 is returned if there
594 * are none. Note that there may be more; the calling code
595 * will need to use TEXT_Reprefix to find any later ones.
596 * pellip - Here is where we return the information about any ellipsification
597 * that was carried out. Note that if tabs are being expanded then
598 * this data will correspond to the last text segment actually
599 * returned in dest; by definition there would not have been any
600 * ellipsification in earlier text segments of the line.
602 * Returns pointer to next char in str after end of the line
603 * or NULL if end of str reached.
605 static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
606 WCHAR *dest, int *len, int width, DWORD format,
607 SIZE *retsize, int last_line, WCHAR **p_retstr,
608 int tabwidth, int *pprefix_offset,
609 ellipsis_data *pellip)
611 int i = 0, j = 0;
612 int plen = 0;
613 SIZE size;
614 int maxl = *len;
615 int seg_i, seg_count, seg_j;
616 int max_seg_width;
617 int num_fit;
618 BOOL word_broken, line_fits, ellipsified;
619 unsigned int j_in_seg;
620 *pprefix_offset = -1;
622 /* For each text segment in the line */
624 retsize->cy = 0;
625 while (*count)
628 /* Skip any leading tabs */
630 if (str[i] == TAB && (format & DT_EXPANDTABS))
632 plen = ((plen/tabwidth)+1)*tabwidth;
633 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
634 while (*count && str[i] == TAB)
636 plen += tabwidth;
637 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
642 /* Now copy as far as the next tab or cr/lf or eos */
644 seg_i = i;
645 seg_count = *count;
646 seg_j = j;
648 while (*count &&
649 (str[i] != TAB || !(format & DT_EXPANDTABS)) &&
650 ((str[i] != CR && str[i] != LF) || (format & DT_SINGLELINE)))
652 if ((format & DT_NOPREFIX) || *count <= 1)
654 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
655 continue;
658 if (str[i] == PREFIX || str[i] == ALPHA_PREFIX) {
659 (*count)--, i++; /* Throw away the prefix itself */
660 if (str[i] == PREFIX)
662 /* Swallow it before we see it again */
663 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
665 else if (*pprefix_offset == -1 || *pprefix_offset >= seg_j)
667 *pprefix_offset = j;
669 /* else the previous prefix was in an earlier segment of the
670 * line; we will leave it to the drawing code to catch this
671 * one.
674 else if (str[i] == KANA_PREFIX)
676 /* Throw away katakana access keys */
677 (*count)--, i++; /* skip the prefix */
678 (*count)--, i++; /* skip the letter */
680 else
682 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
687 /* Measure the whole text segment and possibly WordBreak and
688 * ellipsify it
691 j_in_seg = j - seg_j;
692 max_seg_width = width - plen;
693 GetTextExtentExPointW (hdc, dest + seg_j, j_in_seg, max_seg_width, &num_fit, NULL, &size);
695 /* The Microsoft handling of various combinations of formats is weird.
696 * The following may very easily be incorrect if several formats are
697 * combined, and may differ between versions (to say nothing of the
698 * several bugs in the Microsoft versions).
700 word_broken = FALSE;
701 line_fits = (num_fit >= j_in_seg);
702 if (!line_fits && (format & DT_WORDBREAK))
704 const WCHAR *s;
705 unsigned int chars_used;
706 TEXT_WordBreak (hdc, dest+seg_j, maxl-seg_j, &j_in_seg,
707 max_seg_width, format, num_fit, &chars_used, &size);
708 line_fits = (size.cx <= max_seg_width);
709 /* and correct the counts */
710 TEXT_SkipChars (count, &s, seg_count, str+seg_i, i-seg_i,
711 chars_used, !(format & DT_NOPREFIX));
712 i = s - str;
713 word_broken = TRUE;
715 pellip->before = j_in_seg;
716 pellip->under = 0;
717 pellip->after = 0;
718 pellip->len = 0;
719 ellipsified = FALSE;
720 if (!line_fits && (format & DT_PATH_ELLIPSIS))
722 TEXT_PathEllipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
723 max_seg_width, &size, *p_retstr, pellip);
724 line_fits = (size.cx <= max_seg_width);
725 ellipsified = TRUE;
727 /* NB we may end up ellipsifying a word-broken or path_ellipsified
728 * string */
729 if ((!line_fits && (format & DT_WORD_ELLIPSIS)) ||
730 ((format & DT_END_ELLIPSIS) &&
731 ((last_line && *count) ||
732 (remainder_is_none_or_newline (*count, &str[i]) && !line_fits))))
734 int before, len_ellipsis;
735 TEXT_Ellipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
736 max_seg_width, &size, *p_retstr, &before, &len_ellipsis);
737 if (before > pellip->before)
739 /* We must have done a path ellipsis too */
740 pellip->after = before - pellip->before - pellip->len;
741 /* Leave the len as the length of the first ellipsis */
743 else
745 /* If we are here after a path ellipsification it must be
746 * because even the ellipsis itself didn't fit.
748 assert (pellip->under == 0 && pellip->after == 0);
749 pellip->before = before;
750 pellip->len = len_ellipsis;
751 /* pellip->after remains as zero as does
752 * pellip->under
755 ellipsified = 1;
757 /* As an optimisation if we have ellipsified and we are expanding
758 * tabs and we haven't reached the end of the line we can skip to it
759 * now rather than going around the loop again.
761 if ((format & DT_EXPANDTABS) && ellipsified)
763 if (format & DT_SINGLELINE)
764 *count = 0;
765 else
767 while ((*count) && str[i] != CR && str[i] != LF)
769 (*count)--, i++;
774 j = seg_j + j_in_seg;
775 if (*pprefix_offset >= seg_j + pellip->before)
777 *pprefix_offset = TEXT_Reprefix (str + seg_i, i - seg_i, pellip);
778 if (*pprefix_offset != -1)
779 *pprefix_offset += seg_j;
782 plen += size.cx;
783 if (size.cy > retsize->cy)
784 retsize->cy = size.cy;
786 if (word_broken)
787 break;
788 else if (!*count)
789 break;
790 else if (str[i] == CR || str[i] == LF)
792 (*count)--, i++;
793 if (*count && (str[i] == CR || str[i] == LF) && str[i] != str[i-1])
795 (*count)--, i++;
797 break;
799 /* else it was a Tab and we go around again */
802 retsize->cx = plen;
803 *len = j;
804 if (*count)
805 return (&str[i]);
806 else
807 return NULL;
811 /***********************************************************************
812 * TEXT_DrawUnderscore
814 * Draw the underline under the prefixed character
816 * Parameters
817 * hdc [in] The handle of the DC for drawing
818 * x [in] The x location of the line segment (logical coordinates)
819 * y [in] The y location of where the underscore should appear
820 * (logical coordinates)
821 * str [in] The text of the line segment
822 * offset [in] The offset of the underscored character within str
823 * rect [in] Clipping rectangle (if not NULL)
826 static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int offset, const RECT *rect)
828 int prefix_x;
829 int prefix_end;
830 SIZE size;
831 HPEN hpen;
832 HPEN oldPen;
834 GetTextExtentPointW (hdc, str, offset, &size);
835 prefix_x = x + size.cx;
836 GetTextExtentPointW (hdc, str, offset+1, &size);
837 prefix_end = x + size.cx - 1;
838 /* The above method may eventually be slightly wrong due to kerning etc. */
840 /* Check for clipping */
841 if (rect){
842 if (prefix_x > rect->right || prefix_end < rect->left || y < rect->top || y > rect->bottom)
843 return; /* Completely outside */
844 /* Partially outside */
845 if (prefix_x < rect->left ) prefix_x = rect->left;
846 if (prefix_end > rect->right) prefix_end = rect->right;
849 hpen = CreatePen (PS_SOLID, 1, GetTextColor (hdc));
850 oldPen = SelectObject (hdc, hpen);
851 MoveToEx (hdc, prefix_x, y, NULL);
852 LineTo (hdc, prefix_end, y);
853 SelectObject (hdc, oldPen);
854 DeleteObject (hpen);
857 /***********************************************************************
858 * DrawTextExW (USER32.@)
860 * The documentation on the extra space required for DT_MODIFYSTRING at MSDN
861 * is not quite complete, especially with regard to \0. We will assume that
862 * the returned string could have a length of up to i_count+3 and also have
863 * a trailing \0 (which would be 4 more than a not-null-terminated string but
864 * 3 more than a null-terminated string). If this is not so then increase
865 * the allowance in DrawTextExA.
867 #define MAX_BUFFER 1024
868 INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
869 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
871 SIZE size;
872 const WCHAR *strPtr;
873 WCHAR *retstr, *p_retstr;
874 size_t size_retstr;
875 WCHAR line[MAX_BUFFER];
876 int len, lh, count=i_count;
877 TEXTMETRICW tm;
878 int lmargin = 0, rmargin = 0;
879 int x = rect->left, y = rect->top;
880 int width = rect->right - rect->left;
881 int max_width = 0;
882 int last_line;
883 int tabwidth /* to keep gcc happy */ = 0;
884 int prefix_offset;
885 ellipsis_data ellip;
886 BOOL invert_y=FALSE;
888 TRACE("%s, %d, [%s] %08x\n", debugstr_wn (str, count), count,
889 wine_dbgstr_rect(rect), flags);
891 if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
892 dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
894 if (!str) return 0;
896 strPtr = str;
898 if (flags & DT_SINGLELINE)
899 flags &= ~DT_WORDBREAK;
901 GetTextMetricsW(hdc, &tm);
902 if (flags & DT_EXTERNALLEADING)
903 lh = tm.tmHeight + tm.tmExternalLeading;
904 else
905 lh = tm.tmHeight;
907 if (str[0] && count == 0)
908 return lh;
910 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
911 return 0;
913 if (count == -1)
915 count = strlenW(str);
916 if (count == 0)
918 if( flags & DT_CALCRECT)
920 rect->right = rect->left;
921 if( flags & DT_SINGLELINE)
922 rect->bottom = rect->top + lh;
923 else
924 rect->bottom = rect->top;
926 return lh;
930 if (GetGraphicsMode(hdc) == GM_COMPATIBLE)
932 SIZE window_ext, viewport_ext;
933 GetWindowExtEx(hdc, &window_ext);
934 GetViewportExtEx(hdc, &viewport_ext);
935 if ((window_ext.cy > 0) != (viewport_ext.cy > 0))
936 invert_y = TRUE;
939 if (dtp)
941 lmargin = dtp->iLeftMargin;
942 rmargin = dtp->iRightMargin;
943 if (!(flags & (DT_CENTER | DT_RIGHT)))
944 x += lmargin;
945 dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */
948 if (flags & DT_EXPANDTABS)
950 int tabstop = ((flags & DT_TABSTOP) && dtp) ? dtp->iTabLength : 8;
951 tabwidth = tm.tmAveCharWidth * tabstop;
954 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
956 if (flags & DT_MODIFYSTRING)
958 size_retstr = (count + 4) * sizeof (WCHAR);
959 retstr = HeapAlloc(GetProcessHeap(), 0, size_retstr);
960 if (!retstr) return 0;
961 memcpy (retstr, str, size_retstr);
963 else
965 size_retstr = 0;
966 retstr = NULL;
968 p_retstr = retstr;
972 len = sizeof(line)/sizeof(line[0]);
973 if (invert_y)
974 last_line = !(flags & DT_NOCLIP) && y - ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) < rect->bottom;
975 else
976 last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom;
977 strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, &p_retstr, tabwidth, &prefix_offset, &ellip);
979 if (flags & DT_CENTER) x = (rect->left + rect->right -
980 size.cx) / 2;
981 else if (flags & DT_RIGHT) x = rect->right - size.cx;
983 if (flags & DT_SINGLELINE)
985 if (flags & DT_VCENTER) y = rect->top +
986 (rect->bottom - rect->top) / 2 - size.cy / 2;
987 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
990 if (!(flags & DT_CALCRECT))
992 const WCHAR *str = line;
993 int xseg = x;
994 while (len)
996 int len_seg;
997 SIZE size;
998 if ((flags & DT_EXPANDTABS))
1000 const WCHAR *p;
1001 p = str; while (p < str+len && *p != TAB) p++;
1002 len_seg = p - str;
1003 if (len_seg != len && !GetTextExtentPointW(hdc, str, len_seg, &size))
1005 HeapFree (GetProcessHeap(), 0, retstr);
1006 return 0;
1009 else
1010 len_seg = len;
1012 if (!ExtTextOutW( hdc, xseg, y,
1013 ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
1014 ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
1015 rect, str, len_seg, NULL ))
1017 HeapFree (GetProcessHeap(), 0, retstr);
1018 return 0;
1020 if (prefix_offset != -1 && prefix_offset < len_seg)
1022 TEXT_DrawUnderscore (hdc, xseg, y + tm.tmAscent + 1, str, prefix_offset, (flags & DT_NOCLIP) ? NULL : rect);
1024 len -= len_seg;
1025 str += len_seg;
1026 if (len)
1028 assert ((flags & DT_EXPANDTABS) && *str == TAB);
1029 len--; str++;
1030 xseg += ((size.cx/tabwidth)+1)*tabwidth;
1031 if (prefix_offset != -1)
1033 if (prefix_offset < len_seg)
1035 /* We have just drawn an underscore; we ought to
1036 * figure out where the next one is. I am going
1037 * to leave it for now until I have a better model
1038 * for the line, which will make reprefixing easier.
1039 * This is where ellip would be used.
1041 prefix_offset = -1;
1043 else
1044 prefix_offset -= len_seg;
1049 else if (size.cx > max_width)
1050 max_width = size.cx;
1052 if (invert_y)
1053 y -= lh;
1054 else
1055 y += lh;
1056 if (dtp)
1057 dtp->uiLengthDrawn += len;
1059 while (strPtr && !last_line);
1061 if (flags & DT_CALCRECT)
1063 rect->right = rect->left + max_width;
1064 rect->bottom = y;
1065 if (dtp)
1066 rect->right += lmargin + rmargin;
1068 if (retstr)
1070 memcpy (str, retstr, size_retstr);
1071 HeapFree (GetProcessHeap(), 0, retstr);
1073 return y - rect->top;
1076 /***********************************************************************
1077 * DrawTextExA (USER32.@)
1079 * If DT_MODIFYSTRING is specified then there must be room for up to
1080 * 4 extra characters. We take great care about just how much modified
1081 * string we return.
1083 INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
1084 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
1086 WCHAR *wstr;
1087 WCHAR *p;
1088 INT ret = 0;
1089 int i;
1090 DWORD wcount;
1091 DWORD wmax;
1092 DWORD amax;
1093 UINT cp;
1095 if (!count) return 0;
1096 if (!str && count > 0) return 0;
1097 if( !str || ((count == -1) && !(count = strlen(str))))
1099 int lh;
1100 TEXTMETRICA tm;
1102 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
1103 return 0;
1105 GetTextMetricsA(hdc, &tm);
1106 if (flags & DT_EXTERNALLEADING)
1107 lh = tm.tmHeight + tm.tmExternalLeading;
1108 else
1109 lh = tm.tmHeight;
1111 if( flags & DT_CALCRECT)
1113 rect->right = rect->left;
1114 if( flags & DT_SINGLELINE)
1115 rect->bottom = rect->top + lh;
1116 else
1117 rect->bottom = rect->top;
1119 return lh;
1121 cp = GdiGetCodePage( hdc );
1122 wcount = MultiByteToWideChar( cp, 0, str, count, NULL, 0 );
1123 wmax = wcount;
1124 amax = count;
1125 if (flags & DT_MODIFYSTRING)
1127 wmax += 4;
1128 amax += 4;
1130 wstr = HeapAlloc(GetProcessHeap(), 0, wmax * sizeof(WCHAR));
1131 if (wstr)
1133 MultiByteToWideChar( cp, 0, str, count, wstr, wcount );
1134 if (flags & DT_MODIFYSTRING)
1135 for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE;
1136 /* Initialise the extra characters so that we can see which ones
1137 * change. U+FFFE is guaranteed to be not a unicode character and
1138 * so will not be generated by DrawTextEx itself.
1140 ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp );
1141 if (flags & DT_MODIFYSTRING)
1143 /* Unfortunately the returned string may contain multiple \0s
1144 * and so we need to measure it ourselves.
1146 for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++;
1147 WideCharToMultiByte( cp, 0, wstr, wcount, str, amax, NULL, NULL );
1149 HeapFree(GetProcessHeap(), 0, wstr);
1151 return ret;
1154 /***********************************************************************
1155 * DrawTextW (USER32.@)
1157 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
1159 DRAWTEXTPARAMS dtp;
1161 memset (&dtp, 0, sizeof(dtp));
1162 dtp.cbSize = sizeof(dtp);
1163 if (flags & DT_TABSTOP)
1165 dtp.iTabLength = (flags >> 8) & 0xff;
1166 flags &= 0xffff00ff;
1168 return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp);
1171 /***********************************************************************
1172 * DrawTextA (USER32.@)
1174 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
1176 DRAWTEXTPARAMS dtp;
1178 memset (&dtp, 0, sizeof(dtp));
1179 dtp.cbSize = sizeof(dtp);
1180 if (flags & DT_TABSTOP)
1182 dtp.iTabLength = (flags >> 8) & 0xff;
1183 flags &= 0xffff00ff;
1185 return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp );
1188 /***********************************************************************
1190 * GrayString functions
1193 /* callback for ASCII gray string proc */
1194 static BOOL CALLBACK gray_string_callbackA( HDC hdc, LPARAM param, INT len )
1196 return TextOutA( hdc, 0, 0, (LPCSTR)param, len );
1199 /* callback for Unicode gray string proc */
1200 static BOOL CALLBACK gray_string_callbackW( HDC hdc, LPARAM param, INT len )
1202 return TextOutW( hdc, 0, 0, (LPCWSTR)param, len );
1205 /***********************************************************************
1206 * TEXT_GrayString
1208 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
1209 INT x, INT y, INT cx, INT cy )
1211 HBITMAP hbm, hbmsave;
1212 HBRUSH hbsave;
1213 HFONT hfsave;
1214 HDC memdc;
1215 int slen = len;
1216 BOOL retval = TRUE;
1217 COLORREF fg, bg;
1219 if(!hdc) return FALSE;
1220 if (!(memdc = CreateCompatibleDC(hdc))) return FALSE;
1222 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1223 hbmsave = SelectObject(memdc, hbm);
1224 hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
1225 PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
1226 SelectObject( memdc, hbsave );
1227 SetTextColor(memdc, RGB(255, 255, 255));
1228 SetBkColor(memdc, RGB(0, 0, 0));
1229 hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1231 retval = fn(memdc, lp, slen);
1232 SelectObject(memdc, hfsave);
1235 * Windows doc says that the bitmap isn't grayed when len == -1 and
1236 * the callback function returns FALSE. However, testing this on
1237 * win95 showed otherwise...
1239 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
1240 if(retval || len != -1)
1241 #endif
1243 hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
1244 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
1245 SelectObject(memdc, hbsave);
1248 if(hb) hbsave = SelectObject(hdc, hb);
1249 fg = SetTextColor(hdc, RGB(0, 0, 0));
1250 bg = SetBkColor(hdc, RGB(255, 255, 255));
1251 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
1252 SetTextColor(hdc, fg);
1253 SetBkColor(hdc, bg);
1254 if(hb) SelectObject(hdc, hbsave);
1256 SelectObject(memdc, hbmsave);
1257 DeleteObject(hbm);
1258 DeleteDC(memdc);
1259 return retval;
1263 /***********************************************************************
1264 * GrayStringA (USER32.@)
1266 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1267 LPARAM lParam, INT cch, INT x, INT y,
1268 INT cx, INT cy )
1270 if (!cch) cch = strlen( (LPCSTR)lParam );
1271 if ((cx == 0 || cy == 0) && cch != -1)
1273 SIZE s;
1274 GetTextExtentPoint32A( hdc, (LPCSTR)lParam, cch, &s );
1275 if (cx == 0) cx = s.cx;
1276 if (cy == 0) cy = s.cy;
1278 if (!gsprc) gsprc = gray_string_callbackA;
1279 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1283 /***********************************************************************
1284 * GrayStringW (USER32.@)
1286 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1287 LPARAM lParam, INT cch, INT x, INT y,
1288 INT cx, INT cy )
1290 if (!cch) cch = strlenW( (LPCWSTR)lParam );
1291 if ((cx == 0 || cy == 0) && cch != -1)
1293 SIZE s;
1294 GetTextExtentPoint32W( hdc, (LPCWSTR)lParam, cch, &s );
1295 if (cx == 0) cx = s.cx;
1296 if (cy == 0) cy = s.cy;
1298 if (!gsprc) gsprc = gray_string_callbackW;
1299 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1303 /***********************************************************************
1304 * TEXT_TabbedTextOut
1306 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
1307 * Note: this doesn't work too well for text-alignment modes other
1308 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
1310 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr,
1311 INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg,
1312 BOOL fDisplayText )
1314 INT defWidth;
1315 SIZE extent;
1316 int i, j;
1317 int start = x;
1319 if (!lpstr || count == 0) return 0;
1321 if (!lpTabPos)
1322 cTabStops=0;
1324 if (cTabStops == 1)
1326 defWidth = *lpTabPos;
1327 cTabStops = 0;
1329 else
1331 TEXTMETRICW tm;
1332 GetTextMetricsW( hdc, &tm );
1333 defWidth = 8 * tm.tmAveCharWidth;
1336 while (count > 0)
1338 RECT r;
1339 INT x0;
1340 x0 = x;
1341 r.left = x0;
1342 /* chop the string into substrings of 0 or more <tabs>
1343 * possibly followed by 1 or more normal characters */
1344 for (i = 0; i < count; i++)
1345 if (lpstr[i] != '\t') break;
1346 for (j = i; j < count; j++)
1347 if (lpstr[j] == '\t') break;
1348 /* get the extent of the normal character part */
1349 GetTextExtentPointW( hdc, lpstr + i, j - i , &extent );
1350 /* and if there is a <tab>, calculate its position */
1351 if( i) {
1352 /* get x coordinate for the drawing of this string */
1353 for (; cTabStops >= i; lpTabPos++, cTabStops--)
1355 if( nTabOrg + abs( *lpTabPos) > x) {
1356 if( lpTabPos[ i - 1] >= 0) {
1357 /* a left aligned tab */
1358 x0 = nTabOrg + lpTabPos[i-1];
1359 x = x0 + extent.cx;
1360 break;
1362 else
1364 /* if tab pos is negative then text is right-aligned
1365 * to tab stop meaning that the string extends to the
1366 * left, so we must subtract the width of the string */
1367 if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x)
1369 x = nTabOrg - lpTabPos[ i - 1];
1370 x0 = x - extent.cx;
1371 break;
1376 /* if we have run out of tab stops and we have a valid default tab
1377 * stop width then round x up to that width */
1378 if ((cTabStops < i) && (defWidth > 0)) {
1379 x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth;
1380 x = x0 + extent.cx;
1381 } else if ((cTabStops < i) && (defWidth < 0)) {
1382 x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i)
1383 * -defWidth;
1384 x0 = x - extent.cx;
1386 } else
1387 x += extent.cx;
1389 if (fDisplayText)
1391 r.top = y;
1392 r.right = x;
1393 r.bottom = y + extent.cy;
1394 ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
1395 &r, lpstr + i, j - i, NULL );
1397 count -= j;
1398 lpstr += j;
1400 return MAKELONG(x - start, extent.cy);
1404 /***********************************************************************
1405 * TabbedTextOutA (USER32.@)
1407 * See TabbedTextOutW.
1409 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
1410 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1412 LONG ret;
1413 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1414 LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1415 if (!strW) return 0;
1416 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1417 ret = TabbedTextOutW( hdc, x, y, strW, len, cTabStops, lpTabPos, nTabOrg );
1418 HeapFree( GetProcessHeap(), 0, strW );
1419 return ret;
1423 /***********************************************************************
1424 * TabbedTextOutW (USER32.@)
1426 * Draws tabbed text aligned using the specified tab stops.
1428 * PARAMS
1429 * hdc [I] Handle to device context to draw to.
1430 * x [I] X co-ordinate to start drawing the text at in logical units.
1431 * y [I] Y co-ordinate to start drawing the text at in logical units.
1432 * str [I] Pointer to the characters to draw.
1433 * count [I] Number of WCHARs pointed to by str.
1434 * cTabStops [I] Number of tab stops pointed to by lpTabPos.
1435 * lpTabPos [I] Tab stops in logical units. Should be sorted in ascending order.
1436 * nTabOrg [I] Starting position to expand tabs from in logical units.
1438 * RETURNS
1439 * The dimensions of the string drawn. The height is in the high-order word
1440 * and the width is in the low-order word.
1442 * NOTES
1443 * The tabs stops can be negative, in which case the text is right aligned to
1444 * that tab stop and, despite what MSDN says, this is supported on
1445 * Windows XP SP2.
1447 * BUGS
1448 * MSDN says that the TA_UPDATECP from GetTextAlign causes this function to
1449 * ignore the x and y co-ordinates, but this is unimplemented at the moment.
1451 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
1452 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1454 TRACE("%p %d,%d %s %d\n", hdc, x, y, debugstr_wn(str,count), count );
1455 return TEXT_TabbedTextOut( hdc, x, y, str, count, cTabStops, lpTabPos, nTabOrg, TRUE );
1459 /***********************************************************************
1460 * GetTabbedTextExtentA (USER32.@)
1462 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
1463 INT cTabStops, const INT *lpTabPos )
1465 LONG ret;
1466 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1467 LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1468 if (!strW) return 0;
1469 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1470 ret = GetTabbedTextExtentW( hdc, strW, len, cTabStops, lpTabPos );
1471 HeapFree( GetProcessHeap(), 0, strW );
1472 return ret;
1476 /***********************************************************************
1477 * GetTabbedTextExtentW (USER32.@)
1479 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
1480 INT cTabStops, const INT *lpTabPos )
1482 TRACE("%p %s %d\n", hdc, debugstr_wn(lpstr,count), count );
1483 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops, lpTabPos, 0, FALSE );