Fixed some issues found by winapi_check.
[wine] / dlls / user / text.c
1 /*
2  * USER text functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
6  */
7
8 #include <string.h>
9
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "wine/unicode.h"
14 #include "winbase.h"
15 #include "winerror.h"
16 #include "winnls.h"
17 #include "cache.h"
18 #include "debugtools.h"
19
20 DEFAULT_DEBUG_CHANNEL(text);
21
22 #define TAB     9
23 #define LF     10
24 #define CR     13
25 #define SPACE  32
26 #define PREFIX 38
27
28 #define ELLIPSIS "..."
29 #define FORWARD_SLASH '/'
30 #define BACK_SLASH '\\'
31
32 static const WCHAR SPACEW[] = {' ', 0};
33 static const WCHAR oW[] = {'o', 0};
34 static const WCHAR ELLIPSISW[] = {'.','.','.', 0};
35 static const WCHAR FORWARD_SLASHW[] = {'/', 0};
36 static const WCHAR BACK_SLASHW[] = {'\\', 0};
37
38 #define SWAP_INT(a,b)  { int t = a; a = b; b = t; }
39
40 static int tabstop = 8;
41 static int tabwidth;
42 static int spacewidth;
43 static int prefix_offset;
44
45 /*********************************************************************
46  *  Return next line of text from a string.
47  * 
48  * hdc - handle to DC.
49  * str - string to parse into lines.
50  * count - length of str.
51  * dest - destination in which to return line.
52  * len - length of resultant line in dest in chars.
53  * width - maximum width of line in pixels.
54  * format - format type passed to DrawText.
55  *
56  * Returns pointer to next char in str after end of the line
57  * or NULL if end of str reached.
58  *
59  * FIXME:
60  * GetTextExtentPoint is used to get the width of each character, 
61  * rather than GetCharABCWidth...  So the whitespace between
62  * characters is ignored, and the reported len is too great.
63  */
64 static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
65                                   WCHAR *dest, int *len, int width, WORD format)
66 {
67     int i = 0, j = 0, k;
68     int plen = 0;
69     int numspaces;
70     SIZE size;
71     int lasttab = 0;
72     int wb_i = 0, wb_j = 0, wb_count = 0;
73
74     while (*count)
75     {
76         switch (str[i])
77         {
78         case CR:
79         case LF:
80             if (!(format & DT_SINGLELINE))
81             {
82                 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
83                 {
84                     (*count)--;
85                     i++;
86                 }
87                 i++;
88                 *len = j;
89                 (*count)--;
90                 return (&str[i]);
91             }
92             dest[j++] = str[i++];
93             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
94                 (format & DT_WORDBREAK))
95             {
96                 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
97                     return NULL;
98                 plen += size.cx;
99             }
100             break;
101             
102         case PREFIX:
103             if (!(format & DT_NOPREFIX) && *count > 1)
104                 {
105                 if (str[++i] == PREFIX)
106                     (*count)--;
107                 else {
108                     prefix_offset = j;
109                     break;
110                 }
111             }
112             dest[j++] = str[i++];
113             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
114                 (format & DT_WORDBREAK))
115             {
116                 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
117                     return NULL;
118                 plen += size.cx;
119             }
120             break;
121             
122         case TAB:
123             if (format & DT_EXPANDTABS)
124             {
125                 wb_i = ++i;
126                 wb_j = j;
127                 wb_count = *count;
128
129                 if (!GetTextExtentPointW(hdc, &dest[lasttab], j - lasttab, &size))
130                     return NULL;
131
132                 numspaces = (tabwidth - size.cx) / spacewidth;
133                 for (k = 0; k < numspaces; k++)
134                     dest[j++] = SPACE;
135                 plen += tabwidth - size.cx;
136                 lasttab = wb_j + numspaces;
137             }
138             else
139             {
140                 dest[j++] = str[i++];
141                 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
142                     (format & DT_WORDBREAK))
143                 {
144                     if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
145                         return NULL;
146                     plen += size.cx;
147                 }
148             }
149             break;
150
151         case SPACE:
152             dest[j++] = str[i++];
153             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
154                 (format & DT_WORDBREAK))
155             {
156                 wb_i = i;
157                 wb_j = j - 1;
158                 wb_count = *count;
159                 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
160                     return NULL;
161                 plen += size.cx;
162             }
163             break;
164
165         default:
166             dest[j++] = str[i++];
167             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
168                 (format & DT_WORDBREAK))
169             {
170                 if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size))
171                     return NULL;
172                 plen += size.cx;
173             }
174         }
175
176         (*count)--;
177         if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
178         {
179             if (plen > width)
180             {
181                 if (format & DT_WORDBREAK)
182                 {
183                     if (wb_j)
184                     {
185                         *len = wb_j;
186                         *count = wb_count - 1;
187                         return (&str[wb_i]);
188                     }
189                 }
190                 else
191                 {
192                     *len = j;
193                     return (&str[i]);
194                 }
195             }
196         }
197     }
198     
199     *len = j;
200     return NULL;
201 }
202
203
204 /***********************************************************************
205  *           DrawText16    (USER.85)
206  */
207 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
208 {
209     INT16 ret;
210
211     if (rect)
212     {
213         RECT rect32;
214         CONV_RECT16TO32( rect, &rect32 );
215         ret = DrawTextA( hdc, str, count, &rect32, flags );
216         CONV_RECT32TO16( &rect32, rect );
217     }
218     else ret = DrawTextA( hdc, str, count, NULL, flags);
219     return ret;
220 }
221
222
223 /***********************************************************************
224  *           DrawTextExW    (USER32.166)
225  */
226 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count, 
227                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
228 {
229     SIZE size;
230     const WCHAR *strPtr;
231     static WCHAR line[1024];
232     int len, lh, count=i_count;
233     int prefix_x = 0;
234     int prefix_end = 0;
235     TEXTMETRICW tm;
236     int x = rect->left, y = rect->top;
237     int width = rect->right - rect->left;
238     int max_width = 0;
239
240     TRACE("%s, %d , [(%d,%d),(%d,%d)]\n", debugstr_wn (str, count), count,
241           rect->left, rect->top, rect->right, rect->bottom);
242
243     if(dtp) {
244         FIXME("Ignores params:%d,%d,%d,%d\n", dtp->cbSize,
245               dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
246     }
247
248     if (!str) return 0;
249     if (count == -1) count = strlenW(str);
250     if (count == 0) return 0;
251     strPtr = str;
252
253     GetTextMetricsW(hdc, &tm);
254     if (flags & DT_EXTERNALLEADING)
255         lh = tm.tmHeight + tm.tmExternalLeading;
256     else
257         lh = tm.tmHeight;
258
259     if (flags & DT_TABSTOP)
260         tabstop = flags >> 8;
261
262     if (flags & DT_EXPANDTABS)
263     {
264         GetTextExtentPointW(hdc, SPACEW, 1, &size);
265         spacewidth = size.cx;
266         GetTextExtentPointW(hdc, oW, 1, &size);
267         tabwidth = size.cx * tabstop;
268     }
269
270     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
271
272     do
273     {
274         prefix_offset = -1;
275         strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags);
276
277         if (prefix_offset != -1)
278         {
279             GetTextExtentPointW(hdc, line, prefix_offset, &size);
280             prefix_x = size.cx;
281             GetTextExtentPointW(hdc, line, prefix_offset + 1, &size);
282             prefix_end = size.cx - 1;
283         }
284
285         if (!GetTextExtentPointW(hdc, line, len, &size)) return 0;
286         if (flags & DT_CENTER) x = (rect->left + rect->right -
287                                     size.cx) / 2;
288         else if (flags & DT_RIGHT) x = rect->right - size.cx;
289
290         if (flags & DT_SINGLELINE)
291         {
292             if (flags & DT_VCENTER) y = rect->top + 
293                 (rect->bottom - rect->top) / 2 - size.cy / 2;
294             else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
295
296             if (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS))
297             {
298                 WCHAR swapStr[sizeof(line)];
299                 WCHAR* fnameDelim = NULL;
300                 int totalLen = i_count >= 0 ? i_count : strlenW(str);
301
302                 if (size.cx > width)
303                 {
304                     int fnameLen = totalLen;
305
306                     /* allow room for '...' */
307                     count = min(totalLen+3, sizeof(line)-3);
308
309                     if (flags & DT_WORD_ELLIPSIS)
310                         flags |= DT_WORDBREAK;
311
312                     if (flags & DT_PATH_ELLIPSIS) 
313                     {
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 = lastFwdSlash ? lastFwdSlash : lastBkSlash;
321                         if (lastBkSlash && lastFwdSlash) /* which is last? */
322                            if (lastBkSlash > lastFwdSlash)
323                                 fnameDelim = lastBkSlash;
324
325                         if (fnameDelim)
326                             fnameLen = &line[totalLen] - fnameDelim;
327                         else 
328                             fnameDelim = (WCHAR*)str;
329
330                         strcpyW(swapStr, ELLIPSISW);
331                         strncpyW(swapStr+strlenW(swapStr), fnameDelim, fnameLen);
332                         swapStr[fnameLen+3] = '\0';
333                         strncpyW(swapStr+strlenW(swapStr), str, totalLen - fnameLen);
334                         swapStr[totalLen+3] = '\0';
335                     }
336                     else  /* DT_END_ELLIPSIS | DT_WORD_ELLIPSIS */
337                     {
338                         strcpyW(swapStr, ELLIPSISW);
339                         strncpyW(swapStr+strlenW(swapStr), str, totalLen);
340                     }
341
342                     TEXT_NextLineW(hdc, swapStr, &count, line, &len, width, flags); 
343
344                     /* if only the ELLIPSIS will fit, just let it be clipped */
345                     len = max(3, len);
346                     GetTextExtentPointW(hdc, line, len, &size);
347
348                     /* FIXME:
349                      * NextLine uses GetTextExtentPoint for each character, 
350                      * rather than GetCharABCWidth...  So the whitespace between
351                      * characters is ignored in the width measurement, and the 
352                      * reported len is too great.  To compensate, we must get
353                      * the width of the entire line and adjust len accordingly.
354                     */
355                     while ((size.cx > width) && (len > 3))
356                     {
357                         line[--len] = '\0';
358                         GetTextExtentPointW(hdc, line, len, &size);
359                     }
360
361                     if (fnameLen < len-3) /* some of the path will fit */
362                     {
363                         /* put the ELLIPSIS between the path and filename */
364                         strncpyW(swapStr, &line[fnameLen+3], len-3-fnameLen); 
365                         swapStr[len-3-fnameLen] = '\0';
366                         strcatW(swapStr, ELLIPSISW); 
367                         strncpyW(swapStr+strlenW(swapStr), &line[3], fnameLen); 
368                     }
369                     else
370                     {
371                         /* move the ELLIPSIS to the end */
372                         strncpyW(swapStr, &line[3], len-3);
373                         swapStr[len-3] = '\0';
374                         strcpyW(swapStr+strlenW(swapStr), ELLIPSISW);
375                     }
376
377                     strncpyW(line, swapStr, len);
378                     line[len] = '\0';
379                     strPtr = NULL;
380                 }
381             }
382         }
383         if (!(flags & DT_CALCRECT))
384         {
385             if (!ExtTextOutW(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
386                              rect, line, len, NULL )) return 0;
387             if (prefix_offset != -1)
388             {
389                 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
390                 HPEN oldPen = SelectObject( hdc, hpen );
391                 MoveToEx(hdc, x + prefix_x, y + tm.tmAscent + 1, NULL );
392                 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
393                 SelectObject( hdc, oldPen );
394                 DeleteObject( hpen );
395             }
396         }
397         else if (size.cx > max_width)
398             max_width = size.cx;
399
400         y += lh;
401         if (strPtr)
402         {
403             if (!(flags & DT_NOCLIP))
404             {
405                 if (y > rect->bottom - lh)
406                     break;
407             }
408         }
409     }
410     while (strPtr);
411     if (flags & DT_CALCRECT)
412     {
413         rect->right = rect->left + max_width;
414         rect->bottom = y;
415     }
416     return y - rect->top;
417 }
418
419 /***********************************************************************
420  *           DrawTextA    (USER32.164)
421  */
422 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
423 {
424    WCHAR *wstr;
425    INT ret = 0;
426    DWORD wcount;
427
428    if (count == -1) count = strlen(str);
429    if (!count) return 0;
430    wcount = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 );
431    wstr = HeapAlloc(GetProcessHeap(), 0, wcount * sizeof(WCHAR));
432    if (wstr)
433    {
434        MultiByteToWideChar( CP_ACP, 0, str, count, wstr, wcount );
435        ret = DrawTextExW( hdc, wstr, wcount, rect, flags, NULL );
436        HeapFree(GetProcessHeap(), 0, wstr);
437    }
438    return ret;
439 }
440
441 /***********************************************************************
442  *           DrawTextW    (USER32.167)
443  */
444 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
445                           LPRECT rect, UINT flags )
446 {
447     return DrawTextExW(hdc, str, count, rect, flags, NULL);
448 }
449
450 /***********************************************************************
451  *           DrawTextExA    (USER32.165)
452  */
453 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
454                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
455 {
456     TRACE("(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
457     if(dtp) {
458         FIXME("Ignores params:%d,%d,%d,%d\n",dtp->cbSize,
459                    dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin);
460     }
461     return DrawTextA(hdc,str,count,rect,flags);
462 }
463
464 /***********************************************************************
465  *           TEXT_GrayString
466  *
467  * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
468  * heap and we can guarantee that the handles fit in an INT16. We have to
469  * rethink the strategy once the migration to NT handles is complete.
470  * We are going to get a lot of code-duplication once this migration is
471  * completed...
472  * 
473  */
474 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
475                             INT x, INT y, INT cx, INT cy, BOOL unicode, BOOL _32bit)
476 {
477     HBITMAP hbm, hbmsave;
478     HBRUSH hbsave;
479     HFONT hfsave;
480     HDC memdc = CreateCompatibleDC(hdc);
481     int slen = len;
482     BOOL retval = TRUE;
483     COLORREF fg, bg;
484
485     if(!hdc) return FALSE;
486     
487     if(len == 0)
488     {
489         if(unicode)
490             slen = lstrlenW((LPCWSTR)lp);
491         else if(_32bit)
492             slen = strlen((LPCSTR)lp);
493         else
494             slen = strlen(MapSL(lp));
495     }
496
497     if((cx == 0 || cy == 0) && slen != -1)
498     {
499         SIZE s;
500         if(unicode)
501             GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
502         else if(_32bit)
503             GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
504         else
505             GetTextExtentPoint32A(hdc, MapSL(lp), slen, &s);
506         if(cx == 0) cx = s.cx;
507         if(cy == 0) cy = s.cy;
508     }
509
510     hbm = CreateBitmap(cx, cy, 1, 1, NULL);
511     hbmsave = (HBITMAP)SelectObject(memdc, hbm);
512     hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
513     PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
514     SelectObject( memdc, hbsave );
515     SetTextColor(memdc, RGB(255, 255, 255));
516     SetBkColor(memdc, RGB(0, 0, 0));
517     hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
518
519     if(fn)
520     {
521         if(_32bit)
522             retval = fn(memdc, lp, slen);
523         else
524             retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
525     }
526     else
527     {
528         if(unicode)
529             TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
530         else if(_32bit)
531             TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
532         else
533             TextOutA(memdc, 0, 0, MapSL(lp), slen);
534     }
535
536     SelectObject(memdc, hfsave);
537
538 /*
539  * Windows doc says that the bitmap isn't grayed when len == -1 and
540  * the callback function returns FALSE. However, testing this on
541  * win95 showed otherwise...
542 */
543 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
544     if(retval || len != -1)
545 #endif
546     {
547         hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
548         PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
549         SelectObject(memdc, hbsave);
550     }
551
552     if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
553     fg = SetTextColor(hdc, RGB(0, 0, 0));
554     bg = SetBkColor(hdc, RGB(255, 255, 255));
555     BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
556     SetTextColor(hdc, fg);
557     SetBkColor(hdc, bg);
558     if(hb) SelectObject(hdc, hbsave);
559
560     SelectObject(memdc, hbmsave);
561     DeleteObject(hbm);
562     DeleteDC(memdc);
563     return retval;
564 }
565
566
567 /***********************************************************************
568  *           GrayString16   (USER.185)
569  */
570 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
571                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
572                             INT16 cx, INT16 cy )
573 {
574     return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch,
575                            x, y, cx, cy, FALSE, FALSE);
576 }
577
578
579 /***********************************************************************
580  *           GrayStringA   (USER32.315)
581  */
582 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
583                          LPARAM lParam, INT cch, INT x, INT y,
584                          INT cx, INT cy )
585 {
586     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy,
587                            FALSE, TRUE);
588 }
589
590
591 /***********************************************************************
592  *           GrayStringW   (USER32.316)
593  */
594 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
595                          LPARAM lParam, INT cch, INT x, INT y,
596                          INT cx, INT cy )
597 {
598     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy,
599                            TRUE, TRUE);
600 }
601
602 /***********************************************************************
603  *           TEXT_TabbedTextOut
604  *
605  * Helper function for TabbedTextOut() and GetTabbedTextExtent().
606  * Note: this doesn't work too well for text-alignment modes other
607  *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
608  */
609 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
610                                 INT count, INT cTabStops, const INT16 *lpTabPos16,
611                                 const INT *lpTabPos32, INT nTabOrg,
612                                 BOOL fDisplayText )
613 {
614     INT defWidth;
615     SIZE extent;
616     int i, tabPos = x;
617     int start = x;
618
619     extent.cx = 0;
620     extent.cy = 0;
621
622     if (cTabStops == 1)
623     {
624         defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
625         cTabStops = 0;
626     }
627     else
628     {
629         TEXTMETRICA tm;
630         GetTextMetricsA( hdc, &tm );
631         defWidth = 8 * tm.tmAveCharWidth;
632     }
633
634     while (count > 0)
635     {
636         for (i = 0; i < count; i++)
637             if (lpstr[i] == '\t') break;
638         GetTextExtentPointA( hdc, lpstr, i, &extent );
639         if (lpTabPos32)
640         {
641             while ((cTabStops > 0) &&
642                    (nTabOrg + *lpTabPos32 <= x + extent.cx))
643             {
644                 lpTabPos32++;
645                 cTabStops--;
646             }
647         }
648         else
649         {
650             while ((cTabStops > 0) &&
651                    (nTabOrg + *lpTabPos16 <= x + extent.cx))
652             {
653                 lpTabPos16++;
654                 cTabStops--;
655             }
656         }
657         if (i == count)
658             tabPos = x + extent.cx;
659         else if (cTabStops > 0)
660             tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
661         else
662             tabPos = nTabOrg + ((x + extent.cx - nTabOrg) / defWidth + 1) * defWidth;
663         if (fDisplayText)
664         {
665             RECT r;
666             r.left   = x;
667             r.top    = y;
668             r.right  = tabPos;
669             r.bottom = y + extent.cy;
670             ExtTextOutA( hdc, x, y,
671                            GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
672                            &r, lpstr, i, NULL );
673         }
674         x = tabPos;
675         count -= i+1;
676         lpstr += i+1;
677     }
678     return MAKELONG(tabPos - start, extent.cy);
679 }
680
681
682 /***********************************************************************
683  *           TabbedTextOut16    (USER.196)
684  */
685 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
686                              INT16 count, INT16 cTabStops,
687                              const INT16 *lpTabPos, INT16 nTabOrg )
688 {
689     TRACE("%04x %d,%d '%.*s' %d\n", hdc, x, y, count, lpstr, count );
690     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
691                                lpTabPos, NULL, nTabOrg, TRUE );
692 }
693
694
695 /***********************************************************************
696  *           TabbedTextOutA    (USER32.542)
697  */
698 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
699                             INT cTabStops, const INT *lpTabPos, INT nTabOrg )
700 {
701     TRACE("%04x %d,%d '%.*s' %d\n", hdc, x, y, count, lpstr, count );
702     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
703                                NULL, lpTabPos, nTabOrg, TRUE );
704 }
705
706
707 /***********************************************************************
708  *           TabbedTextOutW    (USER32.543)
709  */
710 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
711                             INT cTabStops, const INT *lpTabPos, INT nTabOrg )
712 {
713     LONG ret;
714     LPSTR p;
715     INT acount;
716     UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
717
718     acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
719     p = HeapAlloc( GetProcessHeap(), 0, acount );
720     if(p == NULL) return 0; /* FIXME: is this the correct return on failure */ 
721     acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
722     ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops, lpTabPos, nTabOrg );
723     HeapFree( GetProcessHeap(), 0, p );
724     return ret;
725 }
726
727
728 /***********************************************************************
729  *           GetTabbedTextExtent16    (USER.197)
730  */
731 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
732                                     INT16 cTabStops, const INT16 *lpTabPos )
733 {
734     TRACE("%04x '%.*s' %d\n", hdc, count, lpstr, count );
735     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
736                                lpTabPos, NULL, 0, FALSE );
737 }
738
739
740 /***********************************************************************
741  *           GetTabbedTextExtentA    (USER32.293)
742  */
743 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
744                                    INT cTabStops, const INT *lpTabPos )
745 {
746     TRACE("%04x '%.*s' %d\n", hdc, count, lpstr, count );
747     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
748                                NULL, lpTabPos, 0, FALSE );
749 }
750
751
752 /***********************************************************************
753  *           GetTabbedTextExtentW    (USER32.294)
754  */
755 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
756                                    INT cTabStops, const INT *lpTabPos )
757 {
758     LONG ret;
759     LPSTR p;
760     INT acount;
761     UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
762
763     acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL);
764     p = HeapAlloc( GetProcessHeap(), 0, acount );
765     if(p == NULL) return 0; /* FIXME: is this the correct failure value? */
766     acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL);
767     ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos );
768     HeapFree( GetProcessHeap(), 0, p );
769     return ret;
770 }