source: branches/swt/src/user32/text.c

Last change on this file was 22097, checked in by rousseau, 11 years ago

Include a bunch of Console Debug calls

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