- Don't string copy from uninitialised stack memory. In fact don't
[wine/dcerpc.git] / dlls / user / text.c
blob2fa374c7de46f66d097802a168f5b8e72056a204
1 /*
2 * USER text functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * Contains
7 * 1. DrawText functions
8 * 2. GrayString functions
9 * 3. TabbedText functions
12 #include <string.h>
14 #include "windef.h"
15 #include "wingdi.h"
16 #include "wine/winuser16.h"
17 #include "wine/unicode.h"
18 #include "winbase.h"
19 #include "winerror.h"
20 #include "winnls.h"
21 #include "user.h"
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(text);
26 #define countof(a) (sizeof(a)/sizeof(a[0]))
28 /*********************************************************************
30 * DrawText functions
33 #define TAB 9
34 #define LF 10
35 #define CR 13
36 #define SPACE 32
37 #define PREFIX 38
39 #define ELLIPSIS "..."
40 #define FORWARD_SLASH '/'
41 #define BACK_SLASH '\\'
43 static const WCHAR SPACEW[] = {' ', 0};
44 static const WCHAR oW[] = {'o', 0};
45 static const WCHAR ELLIPSISW[] = {'.','.','.', 0};
46 static const WCHAR FORWARD_SLASHW[] = {'/', 0};
47 static const WCHAR BACK_SLASHW[] = {'\\', 0};
49 static int tabstop;
50 static int tabwidth;
51 static int spacewidth;
52 static int prefix_offset;
55 /*********************************************************************
56 * Return next line of text from a string.
58 * hdc - handle to DC.
59 * str - string to parse into lines.
60 * count - length of str.
61 * dest - destination in which to return line.
62 * len - dest buffer size in chars on input, copied length into dest on output.
63 * width - maximum width of line in pixels.
64 * format - format type passed to DrawText.
66 * Returns pointer to next char in str after end of the line
67 * or NULL if end of str reached.
69 * FIXME:
70 * GetTextExtentPoint is used to get the width of each character,
71 * rather than GetCharABCWidth... So the whitespace between
72 * characters is ignored, and the reported len is too great.
74 static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
75 WCHAR *dest, int *len, int width, WORD format)
77 int i = 0, j = 0, k;
78 int plen = 0;
79 int numspaces;
80 SIZE size;
81 int lasttab = 0;
82 int wb_i = 0, wb_j = 0, wb_count = 0;
83 int maxl = *len;
85 while (*count && j < maxl)
87 switch (str[i])
89 case CR:
90 case LF:
91 if (!(format & DT_SINGLELINE))
93 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
95 (*count)--;
96 i++;
98 i++;
99 *len = j;
100 (*count)--;
101 return (&str[i]);
103 dest[j++] = str[i++];
104 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
105 (format & DT_WORDBREAK))
107 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
108 return NULL;
109 plen += size.cx;
111 break;
113 case PREFIX:
114 if (!(format & DT_NOPREFIX) && *count > 1)
116 if (str[++i] == PREFIX)
117 (*count)--;
118 else {
119 prefix_offset = j;
120 break;
123 dest[j++] = str[i++];
124 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
125 (format & DT_WORDBREAK))
127 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
128 return NULL;
129 plen += size.cx;
131 break;
133 case TAB:
134 if (format & DT_EXPANDTABS)
136 wb_i = ++i;
137 wb_j = j;
138 wb_count = *count;
140 if (!GetTextExtentPointW(hdc, &dest[lasttab], j - lasttab, &size))
141 return NULL;
143 numspaces = (tabwidth - size.cx) / spacewidth;
144 for (k = 0; k < numspaces; k++)
145 dest[j++] = SPACE;
146 plen += tabwidth - size.cx;
147 lasttab = wb_j + numspaces;
149 else
151 dest[j++] = str[i++];
152 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
153 (format & DT_WORDBREAK))
155 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
156 return NULL;
157 plen += size.cx;
160 break;
162 case SPACE:
163 dest[j++] = str[i++];
164 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
165 (format & DT_WORDBREAK))
167 wb_i = i;
168 wb_j = j - 1;
169 wb_count = *count;
170 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
171 return NULL;
172 plen += size.cx;
174 break;
176 default:
177 dest[j++] = str[i++];
178 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
179 (format & DT_WORDBREAK))
181 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
182 return NULL;
183 plen += size.cx;
187 (*count)--;
188 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
190 if (plen > width)
192 if (format & DT_WORDBREAK)
194 if (wb_j)
196 *len = wb_j;
197 *count = wb_count - 1;
198 return (&str[wb_i]);
201 else
203 *len = j;
204 return (&str[i]);
210 *len = j;
211 return NULL;
215 /***********************************************************************
216 * DrawTextExW (USER32.@)
218 #define MAX_STATIC_BUFFER 1024
219 INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
220 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
222 SIZE size;
223 const WCHAR *strPtr;
224 static WCHAR line[MAX_STATIC_BUFFER];
225 int len, lh, count=i_count;
226 int prefix_x = 0;
227 int prefix_end = 0;
228 TEXTMETRICW tm;
229 int lmargin = 0, rmargin = 0;
230 int x = rect->left, y = rect->top;
231 int width = rect->right - rect->left;
232 int max_width = 0;
234 TRACE("%s, %d , [(%d,%d),(%d,%d)]\n", debugstr_wn (str, count), count,
235 rect->left, rect->top, rect->right, rect->bottom);
237 if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
238 dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
240 if (!str) return 0;
241 if (count == -1) count = strlenW(str);
242 if (count == 0) return 0;
243 strPtr = str;
245 GetTextMetricsW(hdc, &tm);
246 if (flags & DT_EXTERNALLEADING)
247 lh = tm.tmHeight + tm.tmExternalLeading;
248 else
249 lh = tm.tmHeight;
251 if (dtp)
253 lmargin = dtp->iLeftMargin * tm.tmAveCharWidth;
254 rmargin = dtp->iRightMargin * tm.tmAveCharWidth;
255 if (!(flags & (DT_CENTER | DT_RIGHT)))
256 x += lmargin;
257 dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */
260 tabstop = ((flags & DT_TABSTOP) && dtp) ? dtp->iTabLength : 8;
262 if (flags & DT_EXPANDTABS)
264 GetTextExtentPointW(hdc, SPACEW, 1, &size);
265 spacewidth = size.cx;
266 GetTextExtentPointW(hdc, oW, 1, &size);
267 tabwidth = size.cx * tabstop;
270 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
274 prefix_offset = -1;
275 len = MAX_STATIC_BUFFER;
276 strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags);
278 if (prefix_offset != -1)
280 GetTextExtentPointW(hdc, line, prefix_offset, &size);
281 prefix_x = size.cx;
282 GetTextExtentPointW(hdc, line, prefix_offset + 1, &size);
283 prefix_end = size.cx - 1;
286 if (!GetTextExtentPointW(hdc, line, len, &size)) return 0;
287 if (flags & DT_CENTER) x = (rect->left + rect->right -
288 size.cx) / 2;
289 else if (flags & DT_RIGHT) x = rect->right - size.cx;
291 if (flags & DT_SINGLELINE)
293 if (flags & DT_VCENTER) y = rect->top +
294 (rect->bottom - rect->top) / 2 - size.cy / 2;
295 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
298 if ((flags & DT_SINGLELINE) && size.cx > width &&
299 (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS)))
301 WCHAR swapStr[countof(line)];
302 WCHAR* fnameDelim = NULL;
303 int totalLen = i_count >= 0 ? i_count : strlenW(str);
304 int fnameLen = totalLen;
306 /* allow room for '...' */
307 count = min(totalLen+3, countof(line)-3);
309 if (flags & DT_WORD_ELLIPSIS)
310 flags |= DT_WORDBREAK;
312 if (flags & DT_PATH_ELLIPSIS)
314 WCHAR* lastBkSlash = NULL;
315 WCHAR* lastFwdSlash = NULL;
316 strncpyW(line, str, totalLen);
317 line[totalLen] = '\0';
318 lastBkSlash = strrchrW(line, BACK_SLASHW[0]);
319 lastFwdSlash = strrchrW(line, FORWARD_SLASHW[0]);
320 fnameDelim = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
322 if (fnameDelim)
323 fnameLen = &line[totalLen] - fnameDelim;
324 else
325 fnameDelim = (WCHAR*)str;
327 strcpyW(swapStr, ELLIPSISW);
328 strncpyW(swapStr+strlenW(swapStr), fnameDelim, fnameLen);
329 swapStr[fnameLen+3] = '\0';
330 strncpyW(swapStr+strlenW(swapStr), str, totalLen - fnameLen);
331 swapStr[totalLen+3] = '\0';
333 else /* DT_END_ELLIPSIS | DT_WORD_ELLIPSIS */
335 strcpyW(swapStr, ELLIPSISW);
336 strncpyW(swapStr+strlenW(swapStr), str, totalLen);
339 len = MAX_STATIC_BUFFER;
340 TEXT_NextLineW(hdc, swapStr, &count, line, &len, width, flags);
342 /* if only the ELLIPSIS will fit, just let it be clipped */
343 len = max(3, len);
344 GetTextExtentPointW(hdc, line, len, &size);
346 /* FIXME:
347 * NextLine uses GetTextExtentPoint for each character,
348 * rather than GetCharABCWidth... So the whitespace between
349 * characters is ignored in the width measurement, and the
350 * reported len is too great. To compensate, we must get
351 * the width of the entire line and adjust len accordingly.
353 while ((size.cx > width) && (len > 3))
355 line[--len] = '\0';
356 GetTextExtentPointW(hdc, line, len, &size);
359 if (fnameLen < len-3) /* some of the path will fit */
361 /* put the ELLIPSIS between the path and filename */
362 strncpyW(swapStr, &line[fnameLen+3], len-3-fnameLen);
363 swapStr[len-3-fnameLen] = '\0';
364 strcatW(swapStr, ELLIPSISW);
365 strncpyW(swapStr+strlenW(swapStr), &line[3], fnameLen);
367 else
369 /* move the ELLIPSIS to the end */
370 strncpyW(swapStr, &line[3], len-3);
371 swapStr[len-3] = '\0';
372 strcpyW(swapStr+strlenW(swapStr), ELLIPSISW);
375 strncpyW(line, swapStr, len);
376 line[len] = '\0';
377 strPtr = NULL;
379 if (flags & DT_MODIFYSTRING)
380 strcpyW(str, swapStr);
382 /* Note that really we ought to refigure the location of
383 * the underline for the prefix; it might be currently set for
384 * something we have just ellipsified out.
387 if (!(flags & DT_CALCRECT))
389 if (!ExtTextOutW( hdc, x, y,
390 ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
391 ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
392 rect, line, len, NULL )) return 0;
393 if (prefix_offset != -1)
395 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
396 HPEN oldPen = SelectObject( hdc, hpen );
397 MoveToEx(hdc, x + prefix_x, y + tm.tmAscent + 1, NULL );
398 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
399 SelectObject( hdc, oldPen );
400 DeleteObject( hpen );
403 else if (size.cx > max_width)
404 max_width = size.cx;
406 y += lh;
407 if (strPtr)
409 if (!(flags & DT_NOCLIP))
411 if (y > rect->bottom - lh)
412 break;
415 if (dtp)
416 dtp->uiLengthDrawn += len;
418 while (strPtr);
420 if (flags & DT_CALCRECT)
422 rect->right = rect->left + max_width;
423 rect->bottom = y;
424 if (dtp)
425 rect->right += lmargin + rmargin;
427 return y - rect->top;
430 /***********************************************************************
431 * DrawTextExA (USER32.@)
433 INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
434 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
436 WCHAR *wstr;
437 INT ret = 0;
438 DWORD wcount;
440 if (count == -1) count = strlen(str);
441 if (!count) return 0;
442 wcount = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 );
443 wstr = HeapAlloc(GetProcessHeap(), 0, wcount * sizeof(WCHAR));
444 if (wstr)
446 MultiByteToWideChar( CP_ACP, 0, str, count, wstr, wcount );
447 ret = DrawTextExW( hdc, wstr, wcount, rect, flags, NULL );
448 if (flags & DT_MODIFYSTRING)
449 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, count, NULL, NULL );
450 HeapFree(GetProcessHeap(), 0, wstr);
452 return ret;
455 /***********************************************************************
456 * DrawTextW (USER32.@)
458 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
460 DRAWTEXTPARAMS dtp;
462 memset (&dtp, 0, sizeof(dtp));
463 if (flags & DT_TABSTOP)
465 dtp.iTabLength = (flags >> 8) && 0xff;
466 flags &= 0xffff00ff;
468 return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp);
471 /***********************************************************************
472 * DrawTextA (USER32.@)
474 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
476 DRAWTEXTPARAMS dtp;
478 memset (&dtp, 0, sizeof(dtp));
479 if (flags & DT_TABSTOP)
481 dtp.iTabLength = (flags >> 8) && 0xff;
482 flags &= 0xffff00ff;
484 return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp );
487 /***********************************************************************
488 * DrawText (USER.85)
490 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
492 INT16 ret;
494 if (rect)
496 RECT rect32;
497 CONV_RECT16TO32( rect, &rect32 );
498 ret = DrawTextA( hdc, str, count, &rect32, flags );
499 CONV_RECT32TO16( &rect32, rect );
501 else ret = DrawTextA( hdc, str, count, NULL, flags);
502 return ret;
506 /***********************************************************************
508 * GrayString functions
511 /* ### start build ### */
512 extern WORD CALLBACK TEXT_CallTo16_word_wlw(GRAYSTRINGPROC16,WORD,LONG,WORD);
513 /* ### stop build ### */
515 struct gray_string_info
517 GRAYSTRINGPROC16 proc;
518 LPARAM param;
521 /* callback for 16-bit gray string proc */
522 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
524 const struct gray_string_info *info = (struct gray_string_info *)param;
525 return TEXT_CallTo16_word_wlw( info->proc, hdc, info->param, len );
528 /***********************************************************************
529 * TEXT_GrayString
531 * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
532 * heap and we can guarantee that the handles fit in an INT16. We have to
533 * rethink the strategy once the migration to NT handles is complete.
534 * We are going to get a lot of code-duplication once this migration is
535 * completed...
538 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
539 INT x, INT y, INT cx, INT cy, BOOL unicode, BOOL _32bit)
541 HBITMAP hbm, hbmsave;
542 HBRUSH hbsave;
543 HFONT hfsave;
544 HDC memdc;
545 int slen = len;
546 BOOL retval = TRUE;
547 COLORREF fg, bg;
549 if(!hdc) return FALSE;
550 if (!(memdc = CreateCompatibleDC(hdc))) return FALSE;
552 if(len == 0)
554 if(unicode)
555 slen = lstrlenW((LPCWSTR)lp);
556 else if(_32bit)
557 slen = strlen((LPCSTR)lp);
558 else
559 slen = strlen(MapSL(lp));
562 if((cx == 0 || cy == 0) && slen != -1)
564 SIZE s;
565 if(unicode)
566 GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
567 else if(_32bit)
568 GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
569 else
570 GetTextExtentPoint32A(hdc, MapSL(lp), slen, &s);
571 if(cx == 0) cx = s.cx;
572 if(cy == 0) cy = s.cy;
575 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
576 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
577 hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
578 PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
579 SelectObject( memdc, hbsave );
580 SetTextColor(memdc, RGB(255, 255, 255));
581 SetBkColor(memdc, RGB(0, 0, 0));
582 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
584 if(fn)
586 if(_32bit)
587 retval = fn(memdc, lp, slen);
588 else
589 retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
591 else
593 if(unicode)
594 TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
595 else if(_32bit)
596 TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
597 else
598 TextOutA(memdc, 0, 0, MapSL(lp), slen);
601 SelectObject(memdc, hfsave);
604 * Windows doc says that the bitmap isn't grayed when len == -1 and
605 * the callback function returns FALSE. However, testing this on
606 * win95 showed otherwise...
608 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
609 if(retval || len != -1)
610 #endif
612 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
613 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
614 SelectObject(memdc, hbsave);
617 if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
618 fg = SetTextColor(hdc, RGB(0, 0, 0));
619 bg = SetBkColor(hdc, RGB(255, 255, 255));
620 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
621 SetTextColor(hdc, fg);
622 SetBkColor(hdc, bg);
623 if(hb) SelectObject(hdc, hbsave);
625 SelectObject(memdc, hbmsave);
626 DeleteObject(hbm);
627 DeleteDC(memdc);
628 return retval;
632 /***********************************************************************
633 * GrayString (USER.185)
635 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
636 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
637 INT16 cx, INT16 cy )
639 struct gray_string_info info;
641 if (!gsprc) return TEXT_GrayString(hdc, hbr, NULL, lParam, cch, x, y, cx, cy, FALSE, FALSE);
642 info.proc = gsprc;
643 info.param = lParam;
644 return TEXT_GrayString( hdc, hbr, gray_string_callback, (LPARAM)&info,
645 cch, x, y, cx, cy, FALSE, FALSE);
649 /***********************************************************************
650 * GrayStringA (USER32.@)
652 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
653 LPARAM lParam, INT cch, INT x, INT y,
654 INT cx, INT cy )
656 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy,
657 FALSE, TRUE);
661 /***********************************************************************
662 * GrayStringW (USER32.@)
664 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
665 LPARAM lParam, INT cch, INT x, INT y,
666 INT cx, INT cy )
668 return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy,
669 TRUE, TRUE);
672 /***********************************************************************
674 * TabbedText functions
677 /***********************************************************************
678 * TEXT_TabbedTextOut
680 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
681 * Note: this doesn't work too well for text-alignment modes other
682 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
684 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
685 INT count, INT cTabStops, const INT16 *lpTabPos16,
686 const INT *lpTabPos32, INT nTabOrg,
687 BOOL fDisplayText )
689 INT defWidth;
690 SIZE extent;
691 int i, tabPos = x;
692 int start = x;
694 extent.cx = 0;
695 extent.cy = 0;
697 if (cTabStops == 1)
699 defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
700 cTabStops = 0;
702 else
704 TEXTMETRICA tm;
705 GetTextMetricsA( hdc, &tm );
706 defWidth = 8 * tm.tmAveCharWidth;
709 while (count > 0)
711 for (i = 0; i < count; i++)
712 if (lpstr[i] == '\t') break;
713 GetTextExtentPointA( hdc, lpstr, i, &extent );
714 if (lpTabPos32)
716 while ((cTabStops > 0) &&
717 (nTabOrg + *lpTabPos32 <= x + extent.cx))
719 lpTabPos32++;
720 cTabStops--;
723 else
725 while ((cTabStops > 0) &&
726 (nTabOrg + *lpTabPos16 <= x + extent.cx))
728 lpTabPos16++;
729 cTabStops--;
732 if (i == count)
733 tabPos = x + extent.cx;
734 else if (cTabStops > 0)
735 tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
736 else
737 tabPos = nTabOrg + ((x + extent.cx - nTabOrg) / defWidth + 1) * defWidth;
738 if (fDisplayText)
740 RECT r;
741 r.left = x;
742 r.top = y;
743 r.right = tabPos;
744 r.bottom = y + extent.cy;
745 ExtTextOutA( hdc, x, y,
746 GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
747 &r, lpstr, i, NULL );
749 x = tabPos;
750 count -= i+1;
751 lpstr += i+1;
753 return MAKELONG(tabPos - start, extent.cy);
757 /***********************************************************************
758 * TabbedTextOut (USER.196)
760 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
761 INT16 count, INT16 cTabStops,
762 const INT16 *lpTabPos, INT16 nTabOrg )
764 TRACE("%04x %d,%d %s %d\n", hdc, x, y, debugstr_an(lpstr,count), count );
765 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
766 lpTabPos, NULL, nTabOrg, TRUE );
770 /***********************************************************************
771 * TabbedTextOutA (USER32.@)
773 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
774 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
776 TRACE("%04x %d,%d %s %d\n", hdc, x, y, debugstr_an(lpstr,count), count );
777 return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
778 NULL, lpTabPos, nTabOrg, TRUE );
782 /***********************************************************************
783 * TabbedTextOutW (USER32.@)
785 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
786 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
788 LONG ret;
789 LPSTR p;
790 INT acount;
791 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
793 acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
794 p = HeapAlloc( GetProcessHeap(), 0, acount );
795 if(p == NULL) return 0; /* FIXME: is this the correct return on failure */
796 acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
797 ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops, lpTabPos, nTabOrg );
798 HeapFree( GetProcessHeap(), 0, p );
799 return ret;
803 /***********************************************************************
804 * GetTabbedTextExtent (USER.197)
806 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
807 INT16 cTabStops, const INT16 *lpTabPos )
809 TRACE("%04x %s %d\n", hdc, debugstr_an(lpstr,count), count );
810 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
811 lpTabPos, NULL, 0, FALSE );
815 /***********************************************************************
816 * GetTabbedTextExtentA (USER32.@)
818 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
819 INT cTabStops, const INT *lpTabPos )
821 TRACE("%04x %s %d\n", hdc, debugstr_an(lpstr,count), count );
822 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
823 NULL, lpTabPos, 0, FALSE );
827 /***********************************************************************
828 * GetTabbedTextExtentW (USER32.@)
830 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
831 INT cTabStops, const INT *lpTabPos )
833 LONG ret;
834 LPSTR p;
835 INT acount;
836 UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
838 acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL);
839 p = HeapAlloc( GetProcessHeap(), 0, acount );
840 if(p == NULL) return 0; /* FIXME: is this the correct failure value? */
841 acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL);
842 ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos );
843 HeapFree( GetProcessHeap(), 0, p );
844 return ret;