Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

drawtext.c File Reference

#include "precomp.h"

Go to the source code of this file.

Defines

#define CR   13
#define LF   10
#define DT_HFMTMASK   0x03

Functions

BOOL IsMetaFile (HDC hdc)
int DrawTextExA (HDC hdc, LPSTR lpchText, int cchText, LPRECT lprc, UINT format, LPDRAWTEXTPARAMS lpdtp)
int DrawTextW (HDC hdc, LPCWSTR lpchText, int cchText, LPRECT lprc, UINT format)
int DrawTextA (HDC hdc, LPCSTR lpchText, int cchText, LPRECT lprc, UINT format)
LONG TabTextOut (HDC hdc, int x, int y, LPCWSTR lpstring, int nCount, int nTabPositions, CONST INT *lpTabPositions, int iTabOrigin, BOOL fDrawTheText, int iCharset)
LONG UserLpkTabbedTextOut (HDC hdc, int x, int y, LPCWSTR lpstring, int nCount, int nTabPositions, CONST INT *lpTabPositions, int iTabOrigin, BOOL fDrawTheText, int cxCharWidth, int cyCharHeight, int iCharset)
LONG TabbedTextOutW (HDC hdc, int x, int y, LPCWSTR lpstring, int cchChars, int nTabPositions, CONST INT *lpintTabStopPositions, int iTabOrigin)
LONG TabbedTextOutA (HDC hdc, int x, int y, LPCSTR pString, int chCount, int nTabPositions, CONST INT *pnTabStopPositions, int nTabOrigin)
DWORD GetTabbedTextExtentW (HDC hdc, LPCWSTR pString, int chCount, int nTabPositions, CONST INT *pnTabStopPositions)
DWORD GetTabbedTextExtentA (HDC hdc, LPCSTR pString, int chCount, int nTabPositions, CONST INT *pnTabStopPositions)
void PSMTextOut (HDC hdc, int xLeft, int yTop, LPWSTR lpsz, int cch, DWORD dwFlags)
void UserLpkPSMTextOut (HDC hdc, int xLeft, int yTop, LPWSTR lpsz, int cch, DWORD dwFlags)

Variables

CONST WCHAR gwszNullStr [] = L""


Define Documentation

#define CR   13
 

Definition at line 15 of file client/drawtext.c.

Referenced by DrawTextExWorker(), DT_GetLineBreak(), and GetNextWordbreak().

#define DT_HFMTMASK   0x03
 

Definition at line 18 of file client/drawtext.c.

Referenced by DT_AdjustWhiteSpaces().

#define LF   10
 

Definition at line 16 of file client/drawtext.c.

Referenced by DrawTextExWorker(), DT_GetLineBreak(), and GetNextWordbreak().


Function Documentation

int DrawTextA HDC  hdc,
LPCSTR  lpchText,
int  cchText,
LPRECT  lprc,
UINT  format
 

Definition at line 166 of file client/drawtext.c.

References DrawTextExA(), format, and NULL.

00172 { 00173 DRAWTEXTPARAMS DTparams; 00174 LPDRAWTEXTPARAMS lpDTparams = NULL; 00175 00176 /* v-ronaar: fix bug #24985 00177 * Disallow negative string lengths, except -1 (which has special meaning). 00178 */ 00179 if (cchText < -1) 00180 return(0); 00181 00182 if (format & DT_TABSTOP) { 00183 DTparams.cbSize = sizeof(DRAWTEXTPARAMS); 00184 DTparams.iLeftMargin = DTparams.iRightMargin = 0; 00185 DTparams.iTabLength = (format & 0xff00) >> 8; 00186 lpDTparams = &DTparams; 00187 format &= 0xffff00ff; 00188 } 00189 00190 return DrawTextExA(hdc, (LPSTR)lpchText, cchText, lprc, format, lpDTparams); 00191 }

int DrawTextExA HDC  hdc,
LPSTR  lpchText,
int  cchText,
LPRECT  lprc,
UINT  format,
LPDRAWTEXTPARAMS  lpdtp
 

Definition at line 47 of file client/drawtext.c.

References CCHELLIPSIS, CHAR, DBCS_CHARSIZE, DrawTextExWorker(), FALSE, format, gwszNullStr, IS_DBCS_ENABLED, MBToWCSEx(), NULL, TRUE, UserLocalFree, and UserLocalReAlloc.

Referenced by DrawTextA().

00054 { 00055 LPWSTR lpwstr; 00056 int iRet; 00057 int iUniString; 00058 WORD wCodePage = (WORD)GdiGetCodePage(hdc); 00059 00060 if (cchText == -1) { 00061 // USER_AWCONV_COUNTSTRINGSZ does not count/convert trailing \0. 00062 cchText = USER_AWCONV_COUNTSTRINGSZ; 00063 } else if (cchText < -1) { 00064 return 0; 00065 } 00066 00067 if ((iUniString = MBToWCSEx(wCodePage, lpchText, cchText, &lpwstr, -1, TRUE)) == 0) { 00068 if (cchText == USER_AWCONV_COUNTSTRINGSZ) { 00069 lpwstr = (LPWSTR)gwszNullStr; 00070 format &= ~DT_MODIFYSTRING; 00071 } else { 00072 return 0; 00073 } 00074 } 00075 00076 /* 00077 * Grow the buffer to accomodate the ellipsis (see AddEllipsisAndDrawLine) 00078 */ 00079 if (format & DT_MODIFYSTRING) { 00080 int iNewLen = (iUniString + CCHELLIPSIS + 1) * sizeof(*lpwstr); 00081 LPWSTR lpwstrNew = UserLocalReAlloc(lpwstr, iNewLen, HEAP_ZERO_MEMORY); 00082 if (lpwstrNew == NULL) { 00083 UserLocalFree((HANDLE)lpwstr); 00084 return FALSE; 00085 } 00086 lpwstr = lpwstrNew; 00087 } 00088 00089 iRet = DrawTextExWorker(hdc, lpwstr, iUniString, lprc, format, lpdtp, GetTextCharset(hdc)); 00090 00091 if (format & DT_MODIFYSTRING) { 00092 /* 00093 * Note that if the buffer grew and the caller provided the string size, 00094 * then we won't return the additional characters... fixing this 00095 * might break some apps so let's leave it alone until some one complains 00096 */ 00097 if (cchText < 0) { 00098 UserAssert(cchText == USER_AWCONV_COUNTSTRINGSZ); 00099 // Guess how many bytes we can put in the buffer... 00100 // We can safely assume the maximum bytes available. 00101 // At worst, even for DBCS, the buffer size required 00102 // will be smaller than or equal to the orignal size, 00103 // because some DBCS characters would be substituted 00104 // to SBC ".", which is one byte each. 00105 // On the other hand, the number of characters converted 00106 // is limited by both iUniString and cchText. 00107 // 00108 if (IS_DBCS_ENABLED()) { 00109 cchText = iUniString * DBCS_CHARSIZE; 00110 } else { 00111 cchText = iUniString * sizeof(CHAR); 00112 } 00113 } 00114 WCSToMBEx(wCodePage, lpwstr, iUniString, &lpchText, cchText, FALSE); 00115 } 00116 00117 if (lpwstr != gwszNullStr) { 00118 UserLocalFree((HANDLE)lpwstr); 00119 } 00120 00121 return iRet; 00122 }

int DrawTextW HDC  hdc,
LPCWSTR  lpchText,
int  cchText,
LPRECT  lprc,
UINT  format
 

Definition at line 131 of file client/drawtext.c.

References DrawTextExW(), format, and NULL.

00137 { 00138 DRAWTEXTPARAMS DTparams; 00139 LPDRAWTEXTPARAMS lpDTparams = NULL; 00140 00141 /* v-ronaar: fix bug #24985 00142 * Disallow negative string lengths, except -1 (which has special meaning). 00143 */ 00144 if (cchText < -1) 00145 return(0); 00146 00147 if (format & DT_TABSTOP) 00148 { 00149 DTparams.cbSize = sizeof(DRAWTEXTPARAMS); 00150 DTparams.iLeftMargin = DTparams.iRightMargin = 0; 00151 DTparams.iTabLength = (format & 0xff00) >> 8; 00152 lpDTparams = &DTparams; 00153 format &= 0xffff00ff; 00154 } 00155 00156 return DrawTextExW(hdc, (LPWSTR)lpchText, cchText, lprc, format, lpDTparams); 00157 }

DWORD GetTabbedTextExtentA HDC  hdc,
LPCSTR  pString,
int  chCount,
int  nTabPositions,
CONST INT pnTabStopPositions
 

Definition at line 508 of file client/drawtext.c.

References BOOL, DWORD, FALSE, gwszNullStr, MBToWCSEx(), TabTextOut(), TRUE, and UserLocalFree.

00514 { 00515 LPWSTR lpwstr; 00516 BOOL bRet; 00517 WORD wCodePage = (WORD)GdiGetCodePage(hdc); 00518 int iUniString; 00519 00520 if (chCount == -1) { 00521 chCount = USER_AWCONV_COUNTSTRINGSZ; 00522 } 00523 if ((iUniString = MBToWCSEx(wCodePage, pString, chCount, &lpwstr, -1, TRUE)) == 0) { 00524 if (chCount == USER_AWCONV_COUNTSTRINGSZ) { 00525 lpwstr = (LPWSTR)gwszNullStr; 00526 } else { 00527 return FALSE; 00528 } 00529 } 00530 00531 bRet = TabTextOut(hdc, 0, 0, lpwstr, iUniString, 00532 nTabPositions, pnTabStopPositions, 0, FALSE, GetTextCharset(hdc)); 00533 00534 if (lpwstr != gwszNullStr) { 00535 UserLocalFree((HANDLE)lpwstr); 00536 } 00537 00538 return bRet; 00539 }

DWORD GetTabbedTextExtentW HDC  hdc,
LPCWSTR  pString,
int  chCount,
int  nTabPositions,
CONST INT pnTabStopPositions
 

Definition at line 497 of file client/drawtext.c.

References DWORD, FALSE, and TabTextOut().

00503 { 00504 return TabTextOut(hdc, 0, 0, pString, chCount, 00505 nTabPositions, pnTabStopPositions, 0, FALSE, -1); 00506 }

BOOL IsMetaFile HDC  hdc  ) 
 

Definition at line 27 of file client/drawtext.c.

References BOOL, and DWORD.

Referenced by DrawCaption(), DrawCaptionTemp(), DrawIconEx(), and DrawMenuBarTemp().

00029 { 00030 DWORD dwType = GetObjectType(hdc); 00031 return (dwType == OBJ_METAFILE || 00032 dwType == OBJ_METADC || 00033 dwType == OBJ_ENHMETAFILE || 00034 dwType == OBJ_ENHMETADC); 00035 }

void PSMTextOut HDC  hdc,
int  xLeft,
int  yTop,
LPWSTR  lpsz,
int  cch,
DWORD  dwFlags
 

Definition at line 555 of file client/drawtext.c.

References dwFlags.

Referenced by DrawStateW(), DT_InitDrawTextInfo(), and xxxStaticPaint().

00562 { 00563 /* 00564 * By default this is just a call to UserLpkPSMTextOut. If an 00565 * LPK is installed, this calls out to the LPK. The LPK calls 00566 * UserLpkPSMTextOut, if necessary. 00567 */ 00568 (*fpLpkPSMTextOut)(hdc, xLeft, yTop, lpsz, cch, dwFlags); 00569 return; 00570 }

LONG TabbedTextOutA HDC  hdc,
int  x,
int  y,
LPCSTR  pString,
int  chCount,
int  nTabPositions,
CONST INT pnTabStopPositions,
int  nTabOrigin
 

Definition at line 459 of file client/drawtext.c.

References BOOL, FALSE, gwszNullStr, MBToWCSEx(), TabTextOut(), TRUE, and UserLocalFree.

00468 { 00469 LPWSTR lpwstr; 00470 BOOL bRet; 00471 WORD wCodePage = (WORD)GdiGetCodePage(hdc); 00472 int iUniString; 00473 00474 if (chCount == -1) { 00475 chCount = USER_AWCONV_COUNTSTRINGSZ; 00476 } 00477 00478 if ((iUniString = MBToWCSEx(wCodePage, pString, chCount, &lpwstr, -1, TRUE)) == 0) { 00479 if (chCount == USER_AWCONV_COUNTSTRINGSZ) { 00480 lpwstr = (LPWSTR)gwszNullStr; 00481 } else { 00482 return FALSE; 00483 } 00484 } 00485 00486 bRet = TabTextOut( 00487 hdc, x, y, lpwstr, iUniString, nTabPositions, 00488 pnTabStopPositions, nTabOrigin, TRUE, GetTextCharset(hdc)); 00489 00490 if (lpwstr != gwszNullStr) { 00491 UserLocalFree((HANDLE)lpwstr); 00492 } 00493 00494 return bRet; 00495 }

LONG TabbedTextOutW HDC  hdc,
int  x,
int  y,
LPCWSTR  lpstring,
int  cchChars,
int  nTabPositions,
CONST INT lpintTabStopPositions,
int  iTabOrigin
 

Definition at line 438 of file client/drawtext.c.

References TabTextOut(), and TRUE.

00447 { 00448 return TabTextOut(hdc, x, y, lpstring, cchChars, 00449 nTabPositions, lpintTabStopPositions, iTabOrigin, TRUE, -1); 00450 }

LONG TabTextOut HDC  hdc,
int  x,
int  y,
LPCWSTR  lpstring,
int  nCount,
int  nTabPositions,
CONST INT lpTabPositions,
int  iTabOrigin,
BOOL  fDrawTheText,
int  iCharset
 

Definition at line 212 of file client/drawtext.c.

References gpsi, IsSysFontAndDefaultMode(), and NULL.

Referenced by GetTabbedTextExtentA(), GetTabbedTextExtentW(), LBPrintCallback(), TabbedTextOutA(), and TabbedTextOutW().

00223 { 00224 int cxCharWidth; 00225 int cyCharHeight = 0; 00226 00227 if (nCount == -1 && lpstring) { 00228 nCount = wcslen(lpstring); 00229 } 00230 if (!lpstring || nCount < 0 || nTabPositions < 0) 00231 return 0; 00232 00233 00234 // Check if it is SysFont AND the mapping mode is MM_TEXT; 00235 // Fix made in connection with Bug #8717 --02-01-90 --SANKAR-- 00236 if (IsSysFontAndDefaultMode(hdc)) 00237 { 00238 cxCharWidth = gpsi->cxSysFontChar; 00239 cyCharHeight = gpsi->cySysFontChar; 00240 } else { 00241 cxCharWidth = GdiGetCharDimensions(hdc, NULL, &cyCharHeight); 00242 if (cxCharWidth == 0) { 00243 RIPMSG0(RIP_WARNING, "TabTextOut: GdiGetCharDimensions failed"); 00244 return 0; 00245 } 00246 } 00247 00248 return (*fpLpkTabbedTextOut)(hdc, x, y, lpstring, nCount, nTabPositions, 00249 lpTabPositions, iTabOrigin, fDrawTheText, 00250 cxCharWidth, cyCharHeight, iCharset); 00251 }

void UserLpkPSMTextOut HDC  hdc,
int  xLeft,
int  yTop,
LPWSTR  lpsz,
int  cch,
DWORD  dwFlags
 

Definition at line 580 of file client/drawtext.c.

References dwFlags, GetPrefixCount(), NULL, SetRect(), UserLocalAlloc, and UserLocalFree.

00587 { 00588 int cx; 00589 LONG textsize, result; 00590 WCHAR achWorkBuffer[255]; 00591 WCHAR *pchOut = achWorkBuffer; 00592 TEXTMETRICW textMetric; 00593 SIZE size; 00594 RECT rc; 00595 COLORREF color; 00596 00597 if (cch > sizeof(achWorkBuffer)/sizeof(WCHAR)) { 00598 pchOut = (WCHAR*)UserLocalAlloc(HEAP_ZERO_MEMORY, (cch+1) * sizeof(WCHAR)); 00599 if (pchOut == NULL) 00600 return; 00601 } 00602 00603 result = GetPrefixCount(lpsz, cch, pchOut, cch); 00604 /* 00605 * DT_PREFIXONLY is a new 5.0 option used when switching from keyboard cues off 00606 * to on. 00607 */ 00608 if (!(dwFlags & DT_PREFIXONLY)) { 00609 TextOutW(hdc, xLeft, yTop, pchOut, cch - HIWORD(result)); 00610 } 00611 00612 /* 00613 * Any true prefix characters to underline? 00614 */ 00615 if (LOWORD(result) == 0xFFFF || dwFlags & DT_HIDEPREFIX) { 00616 if (pchOut != achWorkBuffer) 00617 UserLocalFree(pchOut); 00618 return; 00619 } 00620 00621 if (!GetTextMetricsW(hdc, &textMetric)) { 00622 textMetric.tmOverhang = 0; 00623 textMetric.tmAscent = 0; 00624 } 00625 00626 /* 00627 * For proportional fonts, find starting point of underline. 00628 */ 00629 if (LOWORD(result) != 0) { 00630 00631 /* 00632 * How far in does underline start (if not at 0th byte.). 00633 */ 00634 GetTextExtentPointW(hdc, pchOut, LOWORD(result), &size); 00635 xLeft += size.cx; 00636 00637 /* 00638 * Adjust starting point of underline if not at first char and there is 00639 * an overhang. (Italics or bold fonts.) 00640 */ 00641 xLeft = xLeft - textMetric.tmOverhang; 00642 } 00643 00644 /* 00645 * Adjust for proportional font when setting the length of the underline and 00646 * height of text. 00647 */ 00648 GetTextExtentPointW(hdc, pchOut + LOWORD(result), 1, &size); 00649 textsize = size.cx; 00650 00651 /* 00652 * Find the width of the underline character. Just subtract out the overhang 00653 * divided by two so that we look better with italic fonts. This is not 00654 * going to effect embolded fonts since their overhang is 1. 00655 */ 00656 cx = LOWORD(textsize) - textMetric.tmOverhang / 2; 00657 00658 /* 00659 * Get height of text so that underline is at bottom. 00660 */ 00661 yTop += textMetric.tmAscent + 1; 00662 00663 /* 00664 * Draw the underline using the foreground color. 00665 */ 00666 SetRect(&rc, xLeft, yTop, xLeft+cx, yTop+1); 00667 color = SetBkColor(hdc, GetTextColor(hdc)); 00668 ExtTextOutW(hdc, xLeft, yTop, ETO_OPAQUE, &rc, TEXT(""), 0, NULL); 00669 SetBkColor(hdc, color); 00670 00671 if (pchOut != achWorkBuffer) { 00672 UserLocalFree(pchOut); 00673 } 00674 }

LONG UserLpkTabbedTextOut HDC  hdc,
int  x,
int  y,
LPCWSTR  lpstring,
int  nCount,
int  nTabPositions,
CONST INT lpTabPositions,
int  iTabOrigin,
BOOL  fDrawTheText,
int  cxCharWidth,
int  cyCharHeight,
int  iCharset
 

Definition at line 253 of file client/drawtext.c.

References BOOL, FALSE, NULL, TRUE, and UINT.

00266 { 00267 SIZE textextent, viewextent, windowextent; 00268 int initialx = x; 00269 int cch; 00270 LPCWSTR lp; 00271 int iOneTab = 0; 00272 RECT rc; 00273 UINT uOpaque = (GetBkMode(hdc) == OPAQUE) ? ETO_OPAQUE : 0; 00274 BOOL fStrStart = TRUE; 00275 int ySign = 1; //Assume y increases in down direction. 00276 00277 UNREFERENCED_PARAMETER(iCharset); //Needed by lpk, but not us 00278 /* 00279 * If no tabstop positions are specified, then use a default of 8 system 00280 * font ave char widths or use the single fixed tab stop. 00281 */ 00282 if (!lpTabPositions) { 00283 // no tab stops specified -- default to a tab stop every 8 characters 00284 iOneTab = 8 * cxCharWidth; 00285 } else if (nTabPositions == 1) { 00286 // one tab stop specified -- treat value as the tab increment, one 00287 // tab stop every increment 00288 iOneTab = lpTabPositions[0]; 00289 00290 if (!iOneTab) 00291 iOneTab = 1; 00292 } 00293 00294 // Calculate if the y increases or decreases in the down direction using 00295 // the ViewPortExtent and WindowExtents. 00296 // If this call fails, hdc must be invalid 00297 if (!GetViewportExtEx(hdc, &viewextent)) 00298 return 0; 00299 GetWindowExtEx(hdc, &windowextent); 00300 if ((viewextent.cy ^ windowextent.cy) & 0x80000000) 00301 ySign = -1; 00302 00303 rc.left = initialx; 00304 rc.top = y; 00305 rc.bottom = rc.top + (ySign * cyCharHeight); 00306 00307 while (TRUE) { 00308 // count the number of characters until the next tab character 00309 // this set of characters (substring) will be the working set for 00310 // each iteration of this loop 00311 for (cch = nCount, lp = lpstring; cch && (*lp != TEXT('\t')); lp++, cch--) 00312 { 00313 } 00314 00315 // Compute the number of characters to be drawn with textout. 00316 cch = nCount - cch; 00317 00318 // Compute the number of characters remaining. 00319 nCount -= cch + 1; 00320 00321 // get height and width of substring 00322 if (cch == 0) { 00323 textextent.cx = 0; 00324 textextent.cy = cyCharHeight; 00325 } else 00326 GetTextExtentPointW(hdc, lpstring, cch, &textextent); 00327 00328 if (fStrStart) 00329 // first iteration should just spit out the first substring 00330 // no tabbing occurs until the first tab character is encountered 00331 fStrStart = FALSE; 00332 else 00333 { 00334 // not the first iteration -- tab accordingly 00335 00336 int xTab; 00337 int i; 00338 00339 if (!iOneTab) 00340 { 00341 // look thru tab stop array for next tab stop after existing 00342 // text to put this substring 00343 for (i = 0; i < nTabPositions; i++) 00344 { 00345 xTab = lpTabPositions[i]; 00346 00347 if (xTab < 0) 00348 // calc length needed to use this right justified tab 00349 xTab = (iTabOrigin - xTab) - textextent.cx; 00350 else 00351 // calc length needed to use this left justified tab 00352 xTab = iTabOrigin + xTab; 00353 00354 if (x < xTab) 00355 { 00356 // we found a tab with enough room -- let's use it 00357 x = xTab; 00358 break; 00359 } 00360 } 00361 00362 if (i == nTabPositions) 00363 // we've exhausted all of the given tab positions 00364 // go back to default of a tab stop every 8 characters 00365 iOneTab = 8 * cxCharWidth; 00366 } 00367 00368 // we have to recheck iOneTab here (instead of just saying "else") 00369 // because iOneTab will be set if we've run out of tab stops 00370 if (iOneTab) 00371 { 00372 if (iOneTab < 0) 00373 { 00374 // calc next available right justified tab stop 00375 xTab = x + textextent.cx - iTabOrigin; 00376 xTab = ((xTab / iOneTab) * iOneTab) - iOneTab - textextent.cx + iTabOrigin; 00377 } 00378 else 00379 { 00380 // calc next available left justified tab stop 00381 xTab = x - iTabOrigin; 00382 xTab = ((xTab / iOneTab) * iOneTab) + iOneTab + iTabOrigin; 00383 } 00384 x = xTab; 00385 } 00386 } 00387 00388 if (fDrawTheText) { 00389 00390 /* 00391 * Output all text up to the tab (or end of string) and get its 00392 * extent. 00393 */ 00394 rc.right = x + textextent.cx; 00395 ExtTextOutW( 00396 hdc, x, y, uOpaque, &rc, (LPWSTR)lpstring, 00397 cch, NULL); 00398 rc.left = rc.right; 00399 } 00400 00401 // Skip over the tab and the characters we just drew. 00402 x += textextent.cx; 00403 00404 // Skip over the characters we just drew. 00405 lpstring += cch; 00406 00407 // See if we have more to draw OR see if this string ends in 00408 // a tab character that needs to be drawn. 00409 if((nCount > 0) || ((nCount == 0) && (*lpstring == TEXT('\t')))) 00410 { 00411 00412 lpstring++; // Skip over the tab 00413 continue; 00414 } 00415 else 00416 break; // Break from the loop. 00417 } 00418 return MAKELONG((x - initialx), (short)textextent.cy); 00419 }


Variable Documentation

CONST WCHAR gwszNullStr[] = L""
 

Definition at line 45 of file client/drawtext.c.

Referenced by DrawTextExA(), GetTabbedTextExtentA(), and TabbedTextOutA().


Generated on Sat May 15 19:43:29 2004 for test by doxygen 1.3.7