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