Initialize the NONCLIENTMETRICS with 0 (helps moorhuhn.exe).
[wine] / objects / text.c
1 /*
2  * 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 "winbase.h"
14 #include "winuser.h"
15 #include "winerror.h"
16 #include "dc.h"
17 #include "gdi.h"
18 #include "heap.h"
19 #include "debugtools.h"
20 #include "cache.h"
21
22 DEFAULT_DEBUG_CHANNEL(text);
23
24 #define TAB     9
25 #define LF     10
26 #define CR     13
27 #define SPACE  32
28 #define PREFIX 38
29
30 #define SWAP_INT(a,b)  { int t = a; a = b; b = t; }
31
32 static int tabstop = 8;
33 static int tabwidth;
34 static int spacewidth;
35 static int prefix_offset;
36
37 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
38                                   char *dest, int *len, int width, WORD format)
39 {
40     /* Return next line of text from a string.
41      * 
42      * hdc - handle to DC.
43      * str - string to parse into lines.
44      * count - length of str.
45      * dest - destination in which to return line.
46      * len - length of resultant line in dest in chars.
47      * width - maximum width of line in pixels.
48      * format - format type passed to DrawText.
49      *
50      * Returns pointer to next char in str after end of the line
51      * or NULL if end of str reached.
52      */
53
54     int i = 0, j = 0, k;
55     int plen = 0;
56     int numspaces;
57     SIZE16 size;
58     int lasttab = 0;
59     int wb_i = 0, wb_j = 0, wb_count = 0;
60
61     while (*count)
62     {
63         switch (str[i])
64         {
65         case CR:
66         case LF:
67             if (!(format & DT_SINGLELINE))
68             {
69                 if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF))
70                 {
71                     (*count)--;
72                     i++;
73                 }
74                 i++;
75                 *len = j;
76                 (*count)--;
77                 return (&str[i]);
78             }
79             dest[j++] = str[i++];
80             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
81                 (format & DT_WORDBREAK))
82             {
83                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
84                     return NULL;
85                 plen += size.cx;
86             }
87             break;
88             
89         case PREFIX:
90             if (!(format & DT_NOPREFIX) && *count > 1)
91                 {
92                 if (str[++i] == PREFIX)
93                     (*count)--;
94                 else {
95                     prefix_offset = j;
96                     break;
97                 }
98             }
99             dest[j++] = str[i++];
100             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
101                 (format & DT_WORDBREAK))
102             {
103                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
104                     return NULL;
105                 plen += size.cx;
106             }
107             break;
108             
109         case TAB:
110             if (format & DT_EXPANDTABS)
111             {
112                 wb_i = ++i;
113                 wb_j = j;
114                 wb_count = *count;
115
116                 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
117                                                                  &size))
118                     return NULL;
119
120                 numspaces = (tabwidth - size.cx) / spacewidth;
121                 for (k = 0; k < numspaces; k++)
122                     dest[j++] = SPACE;
123                 plen += tabwidth - size.cx;
124                 lasttab = wb_j + numspaces;
125             }
126             else
127             {
128                 dest[j++] = str[i++];
129                 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
130                     (format & DT_WORDBREAK))
131                 {
132                     if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
133                         return NULL;
134                     plen += size.cx;
135                 }
136             }
137             break;
138
139         case SPACE:
140             dest[j++] = str[i++];
141             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
142                 (format & DT_WORDBREAK))
143             {
144                 wb_i = i;
145                 wb_j = j - 1;
146                 wb_count = *count;
147                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
148                     return NULL;
149                 plen += size.cx;
150             }
151             break;
152
153         default:
154             dest[j++] = str[i++];
155             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
156                 (format & DT_WORDBREAK))
157             {
158                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
159                     return NULL;
160                 plen += size.cx;
161             }
162         }
163
164         (*count)--;
165         if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
166         {
167             if (plen > width)
168             {
169                 if (format & DT_WORDBREAK)
170                 {
171                     if (wb_j)
172                     {
173                         *len = wb_j;
174                         *count = wb_count - 1;
175                         return (&str[wb_i]);
176                     }
177                 }
178                 else
179                 {
180                     *len = j;
181                     return (&str[i]);
182                 }
183             }
184         }
185     }
186     
187     *len = j;
188     return NULL;
189 }
190
191
192 /***********************************************************************
193  *           DrawText16    (USER.85)
194  */
195 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
196                          LPRECT16 rect, UINT16 flags )
197 {
198     SIZE16 size;
199     const char *strPtr;
200     static char line[1024];
201     int len, lh, count=i_count;
202     int prefix_x = 0;
203     int prefix_end = 0;
204     TEXTMETRIC16 tm;
205     int x = rect->left, y = rect->top;
206     int width = rect->right - rect->left;
207     int max_width = 0;
208
209     TRACE("%s, %d , [(%d,%d),(%d,%d)]\n",
210           debugstr_an (str, count), count,
211           rect->left, rect->top, rect->right, rect->bottom);
212
213     if (!str) return 0;
214     if (count == -1) count = strlen(str);
215     strPtr = str;
216
217     GetTextMetrics16(hdc, &tm);
218     if (flags & DT_EXTERNALLEADING)
219         lh = tm.tmHeight + tm.tmExternalLeading;
220     else
221         lh = tm.tmHeight;
222
223     if (flags & DT_TABSTOP)
224         tabstop = flags >> 8;
225
226     if (flags & DT_EXPANDTABS)
227     {
228         GetTextExtentPoint16(hdc, " ", 1, &size);
229         spacewidth = size.cx;
230         GetTextExtentPoint16(hdc, "o", 1, &size);
231         tabwidth = size.cx * tabstop;
232     }
233
234     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
235
236     do
237     {
238         prefix_offset = -1;
239         strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
240
241         if (prefix_offset != -1)
242         {
243             GetTextExtentPoint16(hdc, line, prefix_offset, &size);
244             prefix_x = size.cx;
245             GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
246             prefix_end = size.cx - 1;
247         }
248
249         if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
250         if (flags & DT_CENTER) x = (rect->left + rect->right -
251                                     size.cx) / 2;
252         else if (flags & DT_RIGHT) x = rect->right - size.cx;
253
254         if (flags & DT_SINGLELINE)
255         {
256             if (flags & DT_VCENTER) y = rect->top + 
257                 (rect->bottom - rect->top) / 2 - size.cy / 2;
258             else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
259         }
260         if (!(flags & DT_CALCRECT))
261         {
262             if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
263                               rect, line, len, NULL )) return 0;
264             if (prefix_offset != -1)
265             {
266                 HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
267                 HPEN oldPen = SelectObject( hdc, hpen );
268                 MoveTo16(hdc, x + prefix_x, y + tm.tmAscent + 1 );
269                 LineTo(hdc, x + prefix_end + 1, y + tm.tmAscent + 1 );
270                 SelectObject( hdc, oldPen );
271                 DeleteObject( hpen );
272             }
273         }
274         else if (size.cx > max_width)
275             max_width = size.cx;
276
277         y += lh;
278         if (strPtr)
279         {
280             if (!(flags & DT_NOCLIP))
281             {
282                 if (y > rect->bottom - lh)
283                     break;
284             }
285         }
286     }
287     while (strPtr);
288     if (flags & DT_CALCRECT)
289     {
290         rect->right = rect->left + max_width;
291         rect->bottom = y;
292     }
293     return y - rect->top;
294 }
295
296
297 /***********************************************************************
298  *           DrawText32A    (USER32.164)
299  */
300 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count,
301                           LPRECT rect, UINT flags )
302 {
303     RECT16 rect16;
304     INT16 ret;
305
306     if (!rect)
307         return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
308     CONV_RECT32TO16( rect, &rect16 );
309     ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
310     CONV_RECT16TO32( &rect16, rect );
311     return ret;
312 }
313
314
315 /***********************************************************************
316  *           DrawText32W    (USER32.167)
317  */
318 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count,
319                           LPRECT rect, UINT flags )
320 {
321     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
322     INT ret = DrawTextA( hdc, p, count, rect, flags );
323     HeapFree( GetProcessHeap(), 0, p );
324     return ret;
325 }
326
327 /***********************************************************************
328  *           DrawTextEx32A    (USER32.165)
329  */
330 INT WINAPI DrawTextExA( HDC hdc, LPCSTR str, INT count,
331                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
332 {
333     TRACE("(%d,'%s',%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
334     if(dtp) {
335         FIXME("Ignores params:%d,%d,%d,%d,%d\n",dtp->cbSize,
336                    dtp->iTabLength,dtp->iLeftMargin,dtp->iRightMargin,
337                    dtp->uiLengthDrawn);
338     }
339     return DrawTextA(hdc,str,count,rect,flags);
340 }
341
342 /***********************************************************************
343  *           DrawTextEx32W    (USER32.166)
344  */
345 INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT count,
346                      LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
347 {
348     TRACE("(%d,%p,%d,%p,0x%08x,%p)\n",hdc,str,count,rect,flags,dtp);
349     FIXME("ignores extended functionality\n");
350     return DrawTextW(hdc,str,count,rect,flags);
351 }
352
353 /***********************************************************************
354  *           ExtTextOut16    (GDI.351)
355  */
356 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
357                             const RECT16 *lprect, LPCSTR str, UINT16 count,
358                             const INT16 *lpDx )
359 {
360     BOOL        ret;
361     int         i;
362     RECT        rect32;
363     LPINT       lpdx32 = NULL;
364
365     if (lpDx) lpdx32 = (LPINT)HEAP_xalloc( GetProcessHeap(), 0,
366                                              sizeof(INT)*count );
367     if (lprect) CONV_RECT16TO32(lprect,&rect32);
368     if (lpdx32) for (i=count;i--;) lpdx32[i]=lpDx[i];
369     ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
370     if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
371     return ret;
372
373
374 }
375
376
377 /***********************************************************************
378  *           ExtTextOutA    (GDI32.98)
379  */
380 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
381                              const RECT *lprect, LPCSTR str, UINT count,
382                              const INT *lpDx )
383 {
384     /* str need not be \0 terminated but lstrcpynAtoW adds \0 so we allocate one
385        more byte */
386     LPWSTR p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) );
387     INT ret;
388     lstrcpynAtoW( p, str, count+1 );
389     ret = ExtTextOutW( hdc, x, y, flags, lprect, p, count, lpDx );
390     HeapFree( GetProcessHeap(), 0, p );
391     return ret;
392 }
393
394
395 /***********************************************************************
396  *           ExtTextOutW    (GDI32.99)
397  */
398 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
399                              const RECT *lprect, LPCWSTR str, UINT count,
400                              const INT *lpDx )
401 {
402     DC * dc = DC_GetDCPtr( hdc );
403     return dc && dc->funcs->pExtTextOut && 
404         dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
405 }
406
407
408 /***********************************************************************
409  *           TextOut16    (GDI.33)
410  */
411 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
412 {
413     return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
414 }
415
416
417 /***********************************************************************
418  *           TextOut32A    (GDI32.355)
419  */
420 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
421 {
422     return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
423 }
424
425
426 /***********************************************************************
427  *           TextOut32W    (GDI32.356)
428  */
429 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
430 {
431     return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
432 }
433
434
435 /***********************************************************************
436  *           TEXT_GrayString
437  *
438  * FIXME: The call to 16-bit code only works because the wine GDI is a 16-bit
439  * heap and we can guarantee that the handles fit in an INT16. We have to
440  * rethink the strategy once the migration to NT handles is complete.
441  * We are going to get a lot of code-duplication once this migration is
442  * completed...
443  * 
444  */
445 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, 
446                               GRAYSTRINGPROC fn, LPARAM lp, INT len,
447                               INT x, INT y, INT cx, INT cy, 
448                               BOOL unicode, BOOL _32bit)
449 {
450     HBITMAP hbm, hbmsave;
451     HBRUSH hbsave;
452     HFONT hfsave;
453     HDC memdc = CreateCompatibleDC(hdc);
454     int slen = len;
455     BOOL retval = TRUE;
456     RECT r;
457     COLORREF fg, bg;
458
459     if(!hdc) return FALSE;
460     
461     if(len == 0)
462     {
463         if(unicode)
464             slen = lstrlenW((LPCWSTR)lp);
465         else if(_32bit)
466             slen = lstrlenA((LPCSTR)lp);
467         else
468             slen = lstrlenA((LPCSTR)PTR_SEG_TO_LIN(lp));
469     }
470
471     if((cx == 0 || cy == 0) && slen != -1)
472     {
473         SIZE s;
474         if(unicode)
475             GetTextExtentPoint32W(hdc, (LPCWSTR)lp, slen, &s);
476         else if(_32bit)
477             GetTextExtentPoint32A(hdc, (LPCSTR)lp, slen, &s);
478         else
479             GetTextExtentPoint32A(hdc, (LPCSTR)PTR_SEG_TO_LIN(lp), slen, &s);
480         if(cx == 0) cx = s.cx;
481         if(cy == 0) cy = s.cy;
482     }
483
484     r.left = r.top = 0;
485     r.right = cx;
486     r.bottom = cy;
487
488     hbm = CreateBitmap(cx, cy, 1, 1, NULL);
489     hbmsave = (HBITMAP)SelectObject(memdc, hbm);
490     FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
491     SetTextColor(memdc, RGB(255, 255, 255));
492     SetBkColor(memdc, RGB(0, 0, 0));
493     hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
494             
495     if(fn)
496         if(_32bit)
497             retval = fn(memdc, lp, slen);
498         else
499             retval = (BOOL)((BOOL16)((GRAYSTRINGPROC16)fn)((HDC16)memdc, lp, (INT16)slen));
500     else
501         if(unicode)
502             TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen);
503         else if(_32bit)
504             TextOutA(memdc, 0, 0, (LPCSTR)lp, slen);
505         else
506             TextOutA(memdc, 0, 0, (LPCSTR)PTR_SEG_TO_LIN(lp), slen);
507
508     SelectObject(memdc, hfsave);
509
510 /*
511  * Windows doc says that the bitmap isn't grayed when len == -1 and
512  * the callback function returns FALSE. However, testing this on
513  * win95 showed otherwise...
514 */
515 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
516     if(retval || len != -1)
517 #endif
518     {
519         hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
520         PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
521         SelectObject(memdc, hbsave);
522     }
523
524     if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb);
525     fg = SetTextColor(hdc, RGB(0, 0, 0));
526     bg = SetBkColor(hdc, RGB(255, 255, 255));
527     BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
528     SetTextColor(hdc, fg);
529     SetBkColor(hdc, bg);
530     if(hb) SelectObject(hdc, hbsave);
531
532     SelectObject(memdc, hbmsave);
533     DeleteObject(hbm);
534     DeleteDC(memdc);
535     return retval;
536 }
537
538
539 /***********************************************************************
540  *           GrayString16   (USER.185)
541  */
542 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
543                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
544                             INT16 cx, INT16 cy )
545 {
546     return TEXT_GrayString(hdc, hbr, (GRAYSTRINGPROC)gsprc, lParam, cch, x, y, cx, cy, FALSE, FALSE);
547 }
548
549
550 /***********************************************************************
551  *           GrayString32A   (USER32.315)
552  */
553 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
554                              LPARAM lParam, INT cch, INT x, INT y,
555                              INT cx, INT cy )
556 {
557     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, FALSE, TRUE);
558 }
559
560
561 /***********************************************************************
562  *           GrayString32W   (USER32.316)
563  */
564 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
565                              LPARAM lParam, INT cch, INT x, INT y,
566                              INT cx, INT cy )
567 {
568     return TEXT_GrayString(hdc, hbr, gsprc, lParam, cch, x, y, cx, cy, TRUE, TRUE);
569 }
570
571
572 /***********************************************************************
573  *           TEXT_TabbedTextOut
574  *
575  * Helper function for TabbedTextOut() and GetTabbedTextExtent().
576  * Note: this doesn't work too well for text-alignment modes other
577  *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
578  */
579 LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCSTR lpstr,
580                          INT count, INT cTabStops, const INT16 *lpTabPos16,
581                          const INT *lpTabPos32, INT nTabOrg,
582                          BOOL fDisplayText )
583 {
584     INT defWidth;
585     DWORD extent = 0;
586     int i, tabPos = x;
587     int start = x;
588
589     if (cTabStops == 1)
590     {
591         defWidth = lpTabPos32 ? *lpTabPos32 : *lpTabPos16;
592         cTabStops = 0;
593     }
594     else
595     {
596         TEXTMETRIC16 tm;
597         GetTextMetrics16( hdc, &tm );
598         defWidth = 8 * tm.tmAveCharWidth;
599     }
600     
601     while (count > 0)
602     {
603         for (i = 0; i < count; i++)
604             if (lpstr[i] == '\t') break;
605         extent = GetTextExtent16( hdc, lpstr, i );
606         if (lpTabPos32)
607         {
608             while ((cTabStops > 0) &&
609                    (nTabOrg + *lpTabPos32 <= x + LOWORD(extent)))
610             {
611                 lpTabPos32++;
612                 cTabStops--;
613             }
614         }
615         else
616         {
617             while ((cTabStops > 0) &&
618                    (nTabOrg + *lpTabPos16 <= x + LOWORD(extent)))
619             {
620                 lpTabPos16++;
621                 cTabStops--;
622             }
623         }
624         if (i == count)
625             tabPos = x + LOWORD(extent);
626         else if (cTabStops > 0)
627             tabPos = nTabOrg + (lpTabPos32 ? *lpTabPos32 : *lpTabPos16);
628         else
629             tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
630         if (fDisplayText)
631         {
632             RECT r;
633             SetRect( &r, x, y, tabPos, y+HIWORD(extent) );
634             ExtTextOutA( hdc, x, y,
635                            GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
636                            &r, lpstr, i, NULL );
637         }
638         x = tabPos;
639         count -= i+1;
640         lpstr += i+1;
641     }
642     return MAKELONG(tabPos - start, HIWORD(extent));
643 }
644
645
646 /***********************************************************************
647  *           TabbedTextOut16    (USER.196)
648  */
649 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
650                              INT16 count, INT16 cTabStops,
651                              const INT16 *lpTabPos, INT16 nTabOrg )
652 {
653     TRACE("%04x %d,%d '%.*s' %d\n",
654                   hdc, x, y, count, lpstr, count );
655     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
656                                lpTabPos, NULL, nTabOrg, TRUE );
657 }
658
659
660 /***********************************************************************
661  *           TabbedTextOut32A    (USER32.542)
662  */
663 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr,
664                               INT count, INT cTabStops,
665                               const INT *lpTabPos, INT nTabOrg )
666 {
667     TRACE("%04x %d,%d '%.*s' %d\n",
668                   hdc, x, y, count, lpstr, count );
669     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
670                                NULL, lpTabPos, nTabOrg, TRUE );
671 }
672
673
674 /***********************************************************************
675  *           TabbedTextOut32W    (USER32.543)
676  */
677 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
678                               INT count, INT cTabStops,
679                               const INT *lpTabPos, INT nTabOrg )
680 {
681     LONG ret;
682     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
683     lstrcpynWtoA( p, str, count + 1 );
684     ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
685                             lpTabPos, nTabOrg );
686     HeapFree( GetProcessHeap(), 0, p );
687     return ret;
688 }
689
690
691 /***********************************************************************
692  *           GetTabbedTextExtent16    (USER.197)
693  */
694 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count, 
695                                     INT16 cTabStops, const INT16 *lpTabPos )
696 {
697     TRACE("%04x '%.*s' %d\n",
698                   hdc, count, lpstr, count );
699     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
700                                lpTabPos, NULL, 0, FALSE );
701 }
702
703
704 /***********************************************************************
705  *           GetTabbedTextExtent32A    (USER32.293)
706  */
707 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count, 
708                                      INT cTabStops, const INT *lpTabPos )
709 {
710     TRACE("%04x '%.*s' %d\n",
711                   hdc, count, lpstr, count );
712     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
713                                NULL, lpTabPos, 0, FALSE );
714 }
715
716
717 /***********************************************************************
718  *           GetTabbedTextExtent32W    (USER32.294)
719  */
720 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count, 
721                                      INT cTabStops, const INT *lpTabPos )
722 {
723     LONG ret;
724     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
725     lstrcpynWtoA( p, lpstr, count + 1 );
726     ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
727     HeapFree( GetProcessHeap(), 0, p );
728     return ret;
729 }
730
731 /***********************************************************************
732  * GetTextCharset32 [GDI32.226]  Gets character set for font in DC
733  *
734  * NOTES
735  *    Should it return a UINT32 instead of an INT32?
736  *    => YES, as GetTextCharsetInfo returns UINT32
737  *
738  * RETURNS
739  *    Success: Character set identifier
740  *    Failure: DEFAULT_CHARSET
741  */
742 UINT WINAPI GetTextCharset(
743     HDC hdc) /* [in] Handle to device context */
744 {
745     /* MSDN docs say this is equivalent */
746     return GetTextCharsetInfo(hdc, NULL, 0);
747 }
748
749 /***********************************************************************
750  * GetTextCharset16 [GDI.612]
751  */
752 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
753 {
754     return (UINT16)GetTextCharset(hdc);
755 }
756
757 /***********************************************************************
758  * GetTextCharsetInfo [GDI32.381]  Gets character set for font
759  *
760  * NOTES
761  *    Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
762  *    Should it return a UINT32 instead of an INT32?
763  *    => YES and YES, from win32.hlp from Borland
764  *
765  * RETURNS
766  *    Success: Character set identifier
767  *    Failure: DEFAULT_CHARSET
768  */
769 UINT WINAPI GetTextCharsetInfo(
770     HDC hdc,          /* [in]  Handle to device context */
771     LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
772     DWORD flags)        /* [in]  Reserved - must be 0 */
773 {
774     HGDIOBJ hFont;
775     UINT charSet = DEFAULT_CHARSET;
776     LOGFONTW lf;
777     CHARSETINFO csinfo;
778
779     hFont = GetCurrentObject(hdc, OBJ_FONT);
780     if (hFont == 0)
781         return(DEFAULT_CHARSET);
782     if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
783         charSet = lf.lfCharSet;
784
785     if (fs != NULL) {
786       if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
787            return  (DEFAULT_CHARSET);
788       memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
789     }
790     return charSet;
791 }
792
793 /***********************************************************************
794  * PolyTextOutA [GDI.402]  Draw several Strings
795  */
796 BOOL WINAPI PolyTextOutA (
797                           HDC hdc,               /* Handle to device context */                   
798                           PPOLYTEXTA pptxt,      /* array of strings */
799                           INT cStrings           /* Number of strings in array */
800                           )
801 {
802   FIXME("stub!\n");
803   SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
804   return 0;
805 }
806
807
808
809 /***********************************************************************
810  * PolyTextOutW [GDI.403] Draw several Strings
811  */
812 BOOL WINAPI PolyTextOutW ( 
813                           HDC hdc,               /* Handle to device context */                   
814                           PPOLYTEXTW pptxt,      /* array of strings */
815                           INT cStrings           /* Number of strings in array */
816                           )
817 {
818   FIXME("stub!\n");
819   SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
820   return 0;
821 }