Added mappings for a few messages.
[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 "user.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 - dest buffer size in chars on input, copied length into dest on output.
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     int maxl = *len;
74
75     while (*count && j < maxl)
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  *           DrawText    (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.@)
226  */
227 #define MAX_STATIC_BUFFER 1024
228 INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
229                         LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
230 {
231     SIZE size;
232     const WCHAR *strPtr;
233     static WCHAR line[MAX_STATIC_BUFFER];
234     int len, lh, count=i_count;
235     int prefix_x = 0;
236     int prefix_end = 0;
237     TEXTMETRICW tm;
238     int lmargin = 0, rmargin = 0;
239     int x = rect->left, y = rect->top;
240     int width = rect->right - rect->left;
241     int max_width = 0;
242
243     TRACE("%s, %d , [(%d,%d),(%d,%d)]\n", debugstr_wn (str, count), count,
244           rect->left, rect->top, rect->right, rect->bottom);
245
246    if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
247           dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
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 (dtp)
261     {
262         lmargin = dtp->iLeftMargin * tm.tmAveCharWidth;
263         rmargin = dtp->iRightMargin * tm.tmAveCharWidth;
264         if (!(flags & (DT_CENTER | DT_RIGHT)))
265             x += lmargin;
266         dtp->uiLengthDrawn = 0;     /* This param RECEIVES number of chars processed */
267     }
268
269     if (flags & DT_TABSTOP)
270         tabstop = dtp ? dtp->iTabLength : flags >> 8;
271
272     if (flags & DT_EXPANDTABS)
273     {
274         GetTextExtentPointW(hdc, SPACEW, 1, &size);
275         spacewidth = size.cx;
276         GetTextExtentPointW(hdc, oW, 1, &size);
277         tabwidth = size.cx * tabstop;
278     }
279
280     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
281
282     do
283     {
284         prefix_offset = -1;
285         len = MAX_STATIC_BUFFER;
286         strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags);
287
288         if (prefix_offset != -1)
289         {
290             GetTextExtentPointW(hdc, line, prefix_offset, &size);
291             prefix_x = size.cx;
292             GetTextExtentPointW(hdc, line, prefix_offset + 1, &size);
293             prefix_end = size.cx - 1;
294         }
295
296         if (!GetTextExtentPointW(hdc, line, len, &size)) return 0;
297         if (flags & DT_CENTER) x = (rect->left + rect->right -
298                                     size.cx) / 2;
299         else if (flags & DT_RIGHT) x = rect->right - size.cx;
300
301         if (flags & DT_SINGLELINE)
302         {
303             if (flags & DT_VCENTER) y = rect->top +
304                 (rect->bottom - rect->top) / 2 - size.cy / 2;
305             else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
306
307             if (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS))
308             {
309                 WCHAR swapStr[sizeof(line)];
310                 WCHAR* fnameDelim = NULL;
311                 int totalLen = i_count >= 0 ? i_count : strlenW(str);
312
313                 if (size.cx > width)
314                 {
315                     int fnameLen = totalLen;
316
317                     /* allow room for '...' */
318                     count = min(totalLen+3, sizeof(line)-3);
319
320                     if (flags & DT_WORD_ELLIPSIS)
321                         flags |= DT_WORDBREAK;
322
323                     if (flags & DT_PATH_ELLIPSIS)
324                     {
325                         WCHAR* lastBkSlash = NULL;
326                         WCHAR* lastFwdSlash = NULL;
327                         strncpyW(line, str, totalLen);
328                         line[totalLen] = '\0';
329                         lastBkSlash = strrchrW(line, BACK_SLASHW[0]);
330                         lastFwdSlash = strrchrW(line, FORWARD_SLASHW[0]);
331                         fnameDelim = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
332
333                         if (fnameDelim)
334                             fnameLen = &line[totalLen] - fnameDelim;
335                         else
336                             fnameDelim = (WCHAR*)str;
337
338                         strcpyW(swapStr, ELLIPSISW);
339                         strncpyW(swapStr+strlenW(swapStr), fnameDelim, fnameLen);
340                         swapStr[fnameLen+3] = '\0';
341                         strncpyW(swapStr+strlenW(swapStr), str, totalLen - fnameLen);
342                         swapStr[totalLen+3] = '\0';
343                     }
344                     else  /* DT_END_ELLIPSIS | DT_WORD_ELLIPSIS */
345                     {
346                         strcpyW(swapStr, ELLIPSISW);
347                         strncpyW(swapStr+strlenW(swapStr), str, totalLen);
348                     }
349
350                     len = MAX_STATIC_BUFFER;
351                     TEXT_NextLineW(hdc, swapStr, &count, line, &len, width, flags);
352
353                     /* if only the ELLIPSIS will fit, just let it be clipped */
354                     len = max(3, len);
355                     GetTextExtentPointW(hdc, line, len, &size);
356
357                     /* FIXME:
358                      * NextLine uses GetTextExtentPoint for each character,
359                      * rather than GetCharABCWidth...  So the whitespace between
360                      * characters is ignored in the width measurement, and the
361                      * reported len is too great.  To compensate, we must get
362                      * the width of the entire line and adjust len accordingly.
363                     */
364                     while ((size.cx > width) && (len > 3))
365                     {
366                         line[--len] = '\0';
367                         GetTextExtentPointW(hdc, line, len, &size);
368                     }
369
370                     if (fnameLen < len-3) /* some of the path will fit */
371                     {
372                         /* put the ELLIPSIS between the path and filename */
373                         strncpyW(swapStr, &line[fnameLen+3], len-3-fnameLen);
374                         swapStr[len-3-fnameLen] = '\0';
375                         strcatW(swapStr, ELLIPSISW);
376                         strncpyW(swapStr+strlenW(swapStr), &line[3], fnameLen);
377                     }
378                     else
379                     {
380                         /* move the ELLIPSIS to the end */
381                         strncpyW(swapStr, &line[3], len-3);
382                         swapStr[len-3] = '\0';
383                         strcpyW(swapStr+strlenW(swapStr), ELLIPSISW);
384                     }
385
386                     strncpyW(line, swapStr, len);
387                     line[len] = '\0';
388                     strPtr = NULL;
389                 }
390                if (flags & DT_MODIFYSTRING)
391                     strcpyW(str, swapStr);
392             }
393         }
394         if (!(flags & DT_CALCRECT))
395         {
396            if (!ExtTextOutW( hdc, x, y,
397                     ( (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED )  |  ( (flags & DT_RTLREADING) ? 0 : ETO_RTLREADING ),
398                     rect, line, len, NULL ))  return 0;
399             if (prefix_offset != -1)
400             {
401                 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
402                 HPEN oldPen = SelectObject( hdc, hpen );
403                 MoveToEx(hdc, x + prefix_x, y + tm.tmAscent + 1, NULL );
404                 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
405                 SelectObject( hdc, oldPen );
406                 DeleteObject( hpen );
407             }
408         }
409         else if (size.cx > max_width)
410             max_width = size.cx;
411
412         y += lh;
413         if (strPtr)
414         {
415             if (!(flags & DT_NOCLIP))
416             {
417                 if (y > rect->bottom - lh)
418                     break;
419             }
420         }
421         if (dtp)
422             dtp->uiLengthDrawn += len;
423     }
424     while (strPtr);
425
426     if (flags & DT_CALCRECT)
427     {
428         rect->right = rect->left + max_width;
429         rect->bottom = y;
430         if (dtp)
431             rect->right += lmargin + rmargin;
432     }
433     return y - rect->top;
434 }
435
436 /***********************************************************************
437  *           DrawTextExA    (USER32.@)
438  */
439 INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
440                         LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
441 {
442    WCHAR *wstr;
443    INT ret = 0;
444    DWORD wcount;
445
446    if (count == -1) count = strlen(str);
447    if (!count) return 0;
448    wcount = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 );
449    wstr = HeapAlloc(GetProcessHeap(), 0, wcount * sizeof(WCHAR));
450    if (wstr)
451    {
452        MultiByteToWideChar( CP_ACP, 0, str, count, wstr, wcount );
453        ret = DrawTextExW( hdc, wstr, wcount, rect, flags, NULL );
454        if (flags & DT_MODIFYSTRING)
455             WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, count, NULL, NULL );
456        HeapFree(GetProcessHeap(), 0, wstr);
457    }
458    return ret;
459 }
460
461 /***********************************************************************
462  *           DrawTextW    (USER32.@)
463  */
464 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
465 {
466     return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, NULL);
467 }
468
469 /***********************************************************************
470  *           DrawTextA    (USER32.@)
471  */
472 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
473 {
474     return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, NULL );
475 }
476
477 /***********************************************************************
478  *           TEXT_GrayString
479  *
480  * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
481  * heap and we can guarantee that the handles fit in an INT16. We have to
482  * rethink the strategy once the migration to NT handles is complete.
483  * We are going to get a lot of code-duplication once this migration is
484  * completed...
485  * 
486  */
487 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
488                             INT x, INT y, INT cx, INT cy, BOOL unicode, BOOL _32bit)
489 {
490     HBITMAP hbm, hbmsave;
491     HBRUSH hbsave;
492     HFONT hfsave;
493     HDC memdc = CreateCompatibleDC(hdc);
494     int slen = len;
495     BOOL retval = TRUE;
496     COLORREF fg, bg;
497
498     if(!hdc) return FALSE;
499     
500     if(len == 0)
501     {
502         if(unicode)
503             slen = lstrlenW((LPCWSTR)lp);
504         else if(_32bit)
505             slen = strlen((LPCSTR)lp);
506         else
507             slen = strlen(MapSL(lp));
508     }
509
510     if((cx == 0 || cy == 0) && slen != -1)
511     {
512         SIZE s;
513         if(unicode)
514             GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
515         else if(_32bit)
516             GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
517         else
518             GetTextExtentPoint32A(hdc, MapSL(lp), slen, &s);
519         if(cx == 0) cx = s.cx;
520         if(cy == 0) cy = s.cy;
521     }
522
523     hbm = CreateBitmap(cx, cy, 1, 1, NULL);
524     hbmsave = (HBITMAP)SelectObject(memdc, hbm);
525     hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
526     PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
527     SelectObject( memdc, hbsave );
528     SetTextColor(memdc, RGB(255, 255, 255));
529     SetBkColor(memdc, RGB(0, 0, 0));
530     hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
531
532     if(fn)
533     {
534         if(_32bit)
535             retval = fn(memdc, lp, slen);
536         else
537             retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
538     }
539     else
540     {
541         if(unicode)
542             TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
543         else if(_32bit)
544             TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
545         else
546             TextOutA(memdc, 0, 0, MapSL(lp), slen);
547     }
548
549     SelectObject(memdc, hfsave);
550
551 /*
552  * Windows doc says that the bitmap isn't grayed when len == -1 and
553  * the callback function returns FALSE. However, testing this on
554  * win95 showed otherwise...
555 */
556 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
557     if(retval || len != -1)
558 #endif
559     {
560         hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
561         PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
562         SelectObject(memdc, hbsave);
563     }
564
565     if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
566     fg = SetTextColor(hdc, RGB(0, 0, 0));
567     bg = SetBkColor(hdc, RGB(255, 255, 255));
568     BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
569     SetTextColor(hdc, fg);
570     SetBkColor(hdc, bg);
571     if(hb) SelectObject(hdc, hbsave);
572
573     SelectObject(memdc, hbmsave);
574     DeleteObject(hbm);
575     DeleteDC(memdc);
576     return retval;
577 }
578
579
580 /***********************************************************************
581  *           GrayString16   (USER.185)
582  */
583 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
584                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
585                             INT16 cx, INT16 cy )
586 {
587     return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch,
588                            x, y, cx, cy, FALSE, FALSE);
589 }
590
591
592 /***********************************************************************
593  *           GrayStringA   (USER32.@)
594  */
595 BOOL WINAPI GrayStringA( 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                            FALSE, TRUE);
601 }
602
603
604 /***********************************************************************
605  *           GrayStringW   (USER32.@)
606  */
607 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
608                          LPARAM lParam, INT cch, INT x, INT y,
609                          INT cx, INT cy )
610 {
611     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy,
612                            TRUE, TRUE);
613 }
614
615 /***********************************************************************
616  *           TEXT_TabbedTextOut
617  *
618  * Helper function for TabbedTextOut() and GetTabbedTextExtent().
619  * Note: this doesn't work too well for text-alignment modes other
620  *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
621  */
622 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
623                                 INT count, INT cTabStops, const INT16 *lpTabPos16,
624                                 const INT *lpTabPos32, INT nTabOrg,
625                                 BOOL fDisplayText )
626 {
627     INT defWidth;
628     SIZE extent;
629     int i, tabPos = x;
630     int start = x;
631
632     extent.cx = 0;
633     extent.cy = 0;
634
635     if (cTabStops == 1)
636     {
637         defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
638         cTabStops = 0;
639     }
640     else
641     {
642         TEXTMETRICA tm;
643         GetTextMetricsA( hdc, &tm );
644         defWidth = 8 * tm.tmAveCharWidth;
645     }
646
647     while (count > 0)
648     {
649         for (i = 0; i < count; i++)
650             if (lpstr[i] == '\t') break;
651         GetTextExtentPointA( hdc, lpstr, i, &extent );
652         if (lpTabPos32)
653         {
654             while ((cTabStops > 0) &&
655                    (nTabOrg + *lpTabPos32 <= x + extent.cx))
656             {
657                 lpTabPos32++;
658                 cTabStops--;
659             }
660         }
661         else
662         {
663             while ((cTabStops > 0) &&
664                    (nTabOrg + *lpTabPos16 <= x + extent.cx))
665             {
666                 lpTabPos16++;
667                 cTabStops--;
668             }
669         }
670         if (i == count)
671             tabPos = x + extent.cx;
672         else if (cTabStops > 0)
673             tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
674         else
675             tabPos = nTabOrg + ((x + extent.cx - nTabOrg) / defWidth + 1) * defWidth;
676         if (fDisplayText)
677         {
678             RECT r;
679             r.left   = x;
680             r.top    = y;
681             r.right  = tabPos;
682             r.bottom = y + extent.cy;
683             ExtTextOutA( hdc, x, y,
684                            GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
685                            &r, lpstr, i, NULL );
686         }
687         x = tabPos;
688         count -= i+1;
689         lpstr += i+1;
690     }
691     return MAKELONG(tabPos - start, extent.cy);
692 }
693
694
695 /***********************************************************************
696  *           TabbedTextOut    (USER.196)
697  */
698 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
699                              INT16 count, INT16 cTabStops,
700                              const INT16 *lpTabPos, INT16 nTabOrg )
701 {
702     TRACE("%04x %d,%d %s %d\n", hdc, x, y, debugstr_an(lpstr,count), count );
703     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
704                                lpTabPos, NULL, nTabOrg, TRUE );
705 }
706
707
708 /***********************************************************************
709  *           TabbedTextOutA    (USER32.@)
710  */
711 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
712                             INT cTabStops, const INT *lpTabPos, INT nTabOrg )
713 {
714     TRACE("%04x %d,%d %s %d\n", hdc, x, y, debugstr_an(lpstr,count), count );
715     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
716                                NULL, lpTabPos, nTabOrg, TRUE );
717 }
718
719
720 /***********************************************************************
721  *           TabbedTextOutW    (USER32.@)
722  */
723 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
724                             INT cTabStops, const INT *lpTabPos, INT nTabOrg )
725 {
726     LONG ret;
727     LPSTR p;
728     INT acount;
729     UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
730
731     acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
732     p = HeapAlloc( GetProcessHeap(), 0, acount );
733     if(p == NULL) return 0; /* FIXME: is this the correct return on failure */ 
734     acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
735     ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops, lpTabPos, nTabOrg );
736     HeapFree( GetProcessHeap(), 0, p );
737     return ret;
738 }
739
740
741 /***********************************************************************
742  *           GetTabbedTextExtent    (USER.197)
743  */
744 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
745                                     INT16 cTabStops, const INT16 *lpTabPos )
746 {
747     TRACE("%04x %s %d\n", hdc, debugstr_an(lpstr,count), count );
748     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
749                                lpTabPos, NULL, 0, FALSE );
750 }
751
752
753 /***********************************************************************
754  *           GetTabbedTextExtentA    (USER32.@)
755  */
756 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
757                                    INT cTabStops, const INT *lpTabPos )
758 {
759     TRACE("%04x %s %d\n", hdc, debugstr_an(lpstr,count), count );
760     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
761                                NULL, lpTabPos, 0, FALSE );
762 }
763
764
765 /***********************************************************************
766  *           GetTabbedTextExtentW    (USER32.@)
767  */
768 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
769                                    INT cTabStops, const INT *lpTabPos )
770 {
771     LONG ret;
772     LPSTR p;
773     INT acount;
774     UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
775
776     acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL);
777     p = HeapAlloc( GetProcessHeap(), 0, acount );
778     if(p == NULL) return 0; /* FIXME: is this the correct failure value? */
779     acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL);
780     ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos );
781     HeapFree( GetProcessHeap(), 0, p );
782     return ret;
783 }