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