| 1 | /* $Id: text.cpp,v 1.12 2000-08-18 18:14:59 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GDI32 text apis
|
|---|
| 5 | *
|
|---|
| 6 | * Based on Wine code (991031) (objects\text.c)
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 9 | * Copyright 1999-2000 Christoph Bratschi
|
|---|
| 10 | *
|
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 | #include <os2win.h>
|
|---|
| 15 | #include <stdlib.h>
|
|---|
| 16 | #include <misc.h>
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 | #include <float.h>
|
|---|
| 19 | #include "oslibgpi.h"
|
|---|
| 20 |
|
|---|
| 21 | #define DBG_LOCALLOG DBG_text
|
|---|
| 22 | #include "dbglocal.h"
|
|---|
| 23 |
|
|---|
| 24 | #define ELLIPSIS "..."
|
|---|
| 25 | #define ELLIPSISLEN 3
|
|---|
| 26 |
|
|---|
| 27 | typedef struct _POLYTEXTA
|
|---|
| 28 | {
|
|---|
| 29 | int x;
|
|---|
| 30 | int y;
|
|---|
| 31 | UINT n;
|
|---|
| 32 | LPCSTR lpstr;
|
|---|
| 33 | UINT uiFlags;
|
|---|
| 34 | RECT rcl;
|
|---|
| 35 | int *pdx;
|
|---|
| 36 | } POLYTEXTA;
|
|---|
| 37 |
|
|---|
| 38 | typedef struct _POLYTEXTW
|
|---|
| 39 | {
|
|---|
| 40 | int x;
|
|---|
| 41 | int y;
|
|---|
| 42 | UINT n;
|
|---|
| 43 | LPCWSTR lpstr;
|
|---|
| 44 | UINT uiFlags;
|
|---|
| 45 | RECT rcl;
|
|---|
| 46 | int *pdx;
|
|---|
| 47 | } POLYTEXTW;
|
|---|
| 48 |
|
|---|
| 49 | //******************************************************************************
|
|---|
| 50 | //******************************************************************************
|
|---|
| 51 | UINT WINAPI GetTextCharsetInfo(
|
|---|
| 52 | HDC hdc, /* [in] Handle to device context */
|
|---|
| 53 | LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
|
|---|
| 54 | DWORD flags) /* [in] Reserved - must be 0 */
|
|---|
| 55 | {
|
|---|
| 56 | HGDIOBJ hFont;
|
|---|
| 57 | UINT charSet = DEFAULT_CHARSET;
|
|---|
| 58 | LOGFONTW lf;
|
|---|
| 59 | CHARSETINFO csinfo;
|
|---|
| 60 |
|
|---|
| 61 | dprintf(("GetTextCharsetInfo %x %x %x", hdc, fs, flags));
|
|---|
| 62 |
|
|---|
| 63 | hFont = GetCurrentObject(hdc, OBJ_FONT);
|
|---|
| 64 | if (hFont == 0)
|
|---|
| 65 | return(DEFAULT_CHARSET);
|
|---|
| 66 | if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
|
|---|
| 67 | charSet = lf.lfCharSet;
|
|---|
| 68 |
|
|---|
| 69 | if (fs != NULL) {
|
|---|
| 70 | if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
|
|---|
| 71 | return (DEFAULT_CHARSET);
|
|---|
| 72 | memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
|
|---|
| 73 | }
|
|---|
| 74 | return charSet;
|
|---|
| 75 | }
|
|---|
| 76 | /***********************************************************************
|
|---|
| 77 | * GetTextCharset32 [GDI32.226] Gets character set for font in DC
|
|---|
| 78 | *
|
|---|
| 79 | * NOTES
|
|---|
| 80 | * Should it return a UINT32 instead of an INT32?
|
|---|
| 81 | * => YES, as GetTextCharsetInfo returns UINT32
|
|---|
| 82 | *
|
|---|
| 83 | * RETURNS
|
|---|
| 84 | * Success: Character set identifier
|
|---|
| 85 | * Failure: DEFAULT_CHARSET
|
|---|
| 86 | */
|
|---|
| 87 | UINT WINAPI GetTextCharset(HDC hdc) /* [in] Handle to device context */
|
|---|
| 88 | {
|
|---|
| 89 | /* MSDN docs say this is equivalent */
|
|---|
| 90 | return GetTextCharsetInfo(hdc, NULL, 0);
|
|---|
| 91 | }
|
|---|
| 92 | //******************************************************************************
|
|---|
| 93 | // CB: USER32 function, but here is the better place
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | INT SYSTEM EXPORT InternalDrawTextExA(HDC hdc,LPCSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams,BOOL isDrawTextEx)
|
|---|
| 96 | {
|
|---|
| 97 | INT rc;
|
|---|
| 98 | ULONG flCmd;
|
|---|
| 99 | RECT localRectangle;
|
|---|
| 100 | PRECT rectPtr;
|
|---|
| 101 | LONG lTabs,xLeft,yTop;
|
|---|
| 102 | UINT fpuctrlword;
|
|---|
| 103 |
|
|---|
| 104 | //SvL: Open32's DrawText messes up the fpu control word! (@#$@#$@#$)
|
|---|
| 105 | //CB: don't know if this is still the case with WinDrawTabbedText (-> testcase)
|
|---|
| 106 | fpuctrlword = _control87(0, 0);
|
|---|
| 107 |
|
|---|
| 108 | if ((!lpchText) || (cchText == 0) || (cchText < -1) || (lprc == NULL))
|
|---|
| 109 | {
|
|---|
| 110 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 111 | return 0;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | PVOID pHps = OSLibGpiQueryDCData(hdc);
|
|---|
| 115 |
|
|---|
| 116 | if (!pHps)
|
|---|
| 117 | {
|
|---|
| 118 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 119 | return 0;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | if (cchText == -1)
|
|---|
| 123 | {
|
|---|
| 124 | cchText = strlen(lpchText);
|
|---|
| 125 | if (cchText == 0)
|
|---|
| 126 | return 0; //CB: does Win32 return textheight in this case?
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | if (lpDTParams)
|
|---|
| 130 | {
|
|---|
| 131 | // set margins
|
|---|
| 132 | lprc->left += lpDTParams->iLeftMargin;
|
|---|
| 133 | lprc->right -= lpDTParams->iRightMargin;
|
|---|
| 134 |
|
|---|
| 135 | // just assume all the text has been drawn
|
|---|
| 136 | lpDTParams->uiLengthDrawn = cchText;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | if (!(dwDTFormat & DT_CALCRECT))
|
|---|
| 140 | {
|
|---|
| 141 | BOOL bTopBottomIsOkay;
|
|---|
| 142 |
|
|---|
| 143 | if ((getIsTopTop(pHps) && lprc->top > lprc->bottom) ||
|
|---|
| 144 | (!getIsTopTop(pHps) && lprc->top < lprc->bottom))
|
|---|
| 145 | bTopBottomIsOkay = FALSE;
|
|---|
| 146 | else
|
|---|
| 147 | bTopBottomIsOkay = TRUE;
|
|---|
| 148 |
|
|---|
| 149 | if ((lprc->left >= lprc->right) || !bTopBottomIsOkay)
|
|---|
| 150 | {
|
|---|
| 151 | TEXTMETRICA txtMetrics;
|
|---|
| 152 | BOOL result;
|
|---|
| 153 |
|
|---|
| 154 | result = GetTextMetricsA(hdc,&txtMetrics);
|
|---|
| 155 | if (result)
|
|---|
| 156 | rc = (int)txtMetrics.tmHeight;
|
|---|
| 157 | else
|
|---|
| 158 | rc = 0;
|
|---|
| 159 |
|
|---|
| 160 | if (lpDTParams)
|
|---|
| 161 | {
|
|---|
| 162 | lprc->left -= lpDTParams->iLeftMargin;
|
|---|
| 163 | lprc->right += lpDTParams->iRightMargin;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | return rc;
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | flCmd = DTOS_INVERT | DTOS_WORLDRECT | DTOS_TEXTATTRS | DTOS_AMPERSAND | DTOS_VERTICALEXTENT;
|
|---|
| 171 |
|
|---|
| 172 | LONG lMixMode = OSLibGpiQueryBackMix(pHps);
|
|---|
| 173 | if (lMixMode == BMOS_OVERPAINT) flCmd |= DTOS_OPAQUE;
|
|---|
| 174 |
|
|---|
| 175 | if (dwDTFormat & DT_CALCRECT)
|
|---|
| 176 | {
|
|---|
| 177 | rectPtr = lprc;
|
|---|
| 178 | flCmd |= DTOS_QUERYEXTENT;
|
|---|
| 179 |
|
|---|
| 180 | xLeft = rectPtr->left;
|
|---|
| 181 | yTop = rectPtr->top;
|
|---|
| 182 |
|
|---|
| 183 | if (dwDTFormat & DT_RIGHT)
|
|---|
| 184 | {
|
|---|
| 185 | if (rectPtr->left >= rectPtr->right)
|
|---|
| 186 | rectPtr->left = rectPtr->right-1;
|
|---|
| 187 | } else
|
|---|
| 188 | {
|
|---|
| 189 | if (rectPtr->right <= rectPtr->left)
|
|---|
| 190 | rectPtr->right = rectPtr->left+1;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | if (dwDTFormat & DT_BOTTOM)
|
|---|
| 194 | {
|
|---|
| 195 | if (rectPtr->top >= rectPtr->bottom)
|
|---|
| 196 | rectPtr->top = rectPtr->bottom-1;
|
|---|
| 197 | } else
|
|---|
| 198 | {
|
|---|
| 199 | if (rectPtr->bottom <= rectPtr->top)
|
|---|
| 200 | rectPtr->bottom = rectPtr->top+1;
|
|---|
| 201 | }
|
|---|
| 202 | } else
|
|---|
| 203 | {
|
|---|
| 204 | rectPtr = &localRectangle;
|
|---|
| 205 |
|
|---|
| 206 | if ((getMapMode(pHps) == MMOS_ANISOTROPIC) || (getMapMode(pHps) == MMOS_ISOTROPIC))
|
|---|
| 207 | {
|
|---|
| 208 | if (doesYAxisGrowNorth(pHps))
|
|---|
| 209 | {
|
|---|
| 210 | flCmd &= ~DTOS_INVERT;
|
|---|
| 211 | flCmd |= DTOS_INVERTCHAR;
|
|---|
| 212 | }
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | if (lprc->left > lprc->right)
|
|---|
| 216 | {
|
|---|
| 217 | rectPtr->left = lprc->right;
|
|---|
| 218 | rectPtr->right = lprc->left;
|
|---|
| 219 | } else
|
|---|
| 220 | {
|
|---|
| 221 | rectPtr->left = lprc->left;
|
|---|
| 222 | rectPtr->right = lprc->right;
|
|---|
| 223 | }
|
|---|
| 224 | if (lprc->top > lprc->bottom)
|
|---|
| 225 | {
|
|---|
| 226 | rectPtr->top = lprc->bottom;
|
|---|
| 227 | rectPtr->bottom = lprc->top;
|
|---|
| 228 | } else
|
|---|
| 229 | {
|
|---|
| 230 | rectPtr->top = lprc->top;
|
|---|
| 231 | rectPtr->bottom = lprc->bottom;
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | if (dwDTFormat & DT_EXPANDTABS)
|
|---|
| 236 | {
|
|---|
| 237 | if (isDrawTextEx)
|
|---|
| 238 | {
|
|---|
| 239 | lTabs = (lpDTParams && (dwDTFormat & DT_TABSTOP)) ? lpDTParams->iTabLength:8;
|
|---|
| 240 | } else
|
|---|
| 241 | {
|
|---|
| 242 | lTabs = 8;
|
|---|
| 243 |
|
|---|
| 244 | if (dwDTFormat & DT_TABSTOP)
|
|---|
| 245 | {
|
|---|
| 246 | lTabs = (dwDTFormat >> 8) & 0x000000FF;
|
|---|
| 247 | dwDTFormat &= 0xFFFF00FF;
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 | } else lTabs = -1;
|
|---|
| 251 |
|
|---|
| 252 | if (dwDTFormat & DT_RIGHT)
|
|---|
| 253 | flCmd |= DTOS_RIGHT;
|
|---|
| 254 | else
|
|---|
| 255 | if (dwDTFormat & DT_CENTER) flCmd |= DTOS_CENTER;
|
|---|
| 256 | if (dwDTFormat & DT_BOTTOM) flCmd |= DTOS_BOTTOM;
|
|---|
| 257 | if (dwDTFormat & DT_VCENTER) flCmd |= DTOS_VCENTER;
|
|---|
| 258 | if (dwDTFormat & DT_WORDBREAK) flCmd |= DTOS_WORDBREAK;
|
|---|
| 259 | if (dwDTFormat & DT_EXTERNALLEADING) flCmd |= DTOS_EXTERNALLEADING;
|
|---|
| 260 | if (!(dwDTFormat & DT_NOPREFIX)) flCmd |= DTOS_MNEMONIC;
|
|---|
| 261 | if (dwDTFormat & DT_SINGLELINE)
|
|---|
| 262 | flCmd |= DTOS_SINGLELINE;
|
|---|
| 263 | else
|
|---|
| 264 | flCmd |= DTOS_MULTILINE;
|
|---|
| 265 | if (dwDTFormat & DT_NOCLIP) flCmd |= DTOS_NOCLIP;
|
|---|
| 266 |
|
|---|
| 267 | //CB: DT_EDITCONTROL, DT_RTLREADING ignored
|
|---|
| 268 |
|
|---|
| 269 | BOOL done = FALSE;
|
|---|
| 270 |
|
|---|
| 271 | if ((dwDTFormat & DT_END_ELLIPSIS) && (cchText > 1))
|
|---|
| 272 | {
|
|---|
| 273 | int textWidth,width;
|
|---|
| 274 | RECT rect;
|
|---|
| 275 |
|
|---|
| 276 | SetRectEmpty(&rect);
|
|---|
| 277 | OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 278 | width = rectPtr->right-rectPtr->left;
|
|---|
| 279 | textWidth = rect.right-rect.left;
|
|---|
| 280 | if ((textWidth > width) && (width > 0))
|
|---|
| 281 | {
|
|---|
| 282 | char* newText;
|
|---|
| 283 | int newTextLen = cchText-1+ELLIPSISLEN;
|
|---|
| 284 | int preLen = cchText-1;
|
|---|
| 285 |
|
|---|
| 286 | newText = (char*)malloc(newTextLen+1);
|
|---|
| 287 | strncpy(newText,lpchText,cchText-1);
|
|---|
| 288 | do
|
|---|
| 289 | {
|
|---|
| 290 | strcpy(&newText[preLen],ELLIPSIS);
|
|---|
| 291 | OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 292 | textWidth = rect.right-rect.left;
|
|---|
| 293 | if (textWidth <= width || preLen == 1) break;
|
|---|
| 294 | newTextLen--;
|
|---|
| 295 | preLen--;
|
|---|
| 296 | } while (TRUE);
|
|---|
| 297 | rc = OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,rectPtr,0,0,flCmd);
|
|---|
| 298 | if (dwDTFormat & DT_MODIFYSTRING) strcpy((LPSTR)lpchText,newText); //check length?
|
|---|
| 299 | free(newText);
|
|---|
| 300 |
|
|---|
| 301 | done = TRUE;
|
|---|
| 302 | }
|
|---|
| 303 | } else if ((dwDTFormat & DT_PATH_ELLIPSIS) && (cchText > 1))
|
|---|
| 304 | {
|
|---|
| 305 | int textWidth,width;
|
|---|
| 306 | RECT rect;
|
|---|
| 307 |
|
|---|
| 308 | //CB: code not yet checked (-> testcase)
|
|---|
| 309 |
|
|---|
| 310 | SetRectEmpty(&rect);
|
|---|
| 311 | OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 312 | width = rectPtr->right-rectPtr->left;
|
|---|
| 313 | textWidth = rect.right-rect.left;
|
|---|
| 314 | if ((textWidth > width) && (width > 0))
|
|---|
| 315 | {
|
|---|
| 316 | char *newText,*slashPos;
|
|---|
| 317 | int newTextLen = cchText+ELLIPSISLEN;
|
|---|
| 318 |
|
|---|
| 319 | newText = (char*)malloc(newTextLen+1);
|
|---|
| 320 | strncpy(newText,lpchText,cchText);
|
|---|
| 321 | slashPos = strrchr(newText,(int)"\\");
|
|---|
| 322 | if (slashPos != NULL)
|
|---|
| 323 | {
|
|---|
| 324 | int preLen = slashPos-newText;
|
|---|
| 325 | char* endPtr = (char*)lpchText+preLen;
|
|---|
| 326 | int endLen = cchText-preLen;
|
|---|
| 327 | BOOL ok = FALSE;
|
|---|
| 328 |
|
|---|
| 329 | //delete start
|
|---|
| 330 | do
|
|---|
| 331 | {
|
|---|
| 332 | strcpy(&newText[preLen],ELLIPSIS);
|
|---|
| 333 | strncpy(&newText[preLen+ELLIPSISLEN],endPtr,endLen);
|
|---|
| 334 | OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 335 | textWidth = rect.right-rect.left;
|
|---|
| 336 | if (textWidth <= width)
|
|---|
| 337 | {
|
|---|
| 338 | ok = TRUE;
|
|---|
| 339 | break;
|
|---|
| 340 | }
|
|---|
| 341 | if (preLen == 0) break;
|
|---|
| 342 | newTextLen--;
|
|---|
| 343 | preLen--;
|
|---|
| 344 | } while (TRUE);
|
|---|
| 345 |
|
|---|
| 346 | if (!ok)
|
|---|
| 347 | {
|
|---|
| 348 | //delete end
|
|---|
| 349 | do
|
|---|
| 350 | {
|
|---|
| 351 | endPtr++;
|
|---|
| 352 | endLen--;
|
|---|
| 353 | newTextLen--;
|
|---|
| 354 | strncpy(&newText[ELLIPSISLEN],endPtr,endLen);
|
|---|
| 355 | OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 356 | textWidth = rect.right-rect.left;
|
|---|
| 357 | if ((textWidth <= width) || (endLen == 0)) break;
|
|---|
| 358 | } while (TRUE);
|
|---|
| 359 | }
|
|---|
| 360 | } else
|
|---|
| 361 | {
|
|---|
| 362 | int preLen,endLen;
|
|---|
| 363 |
|
|---|
| 364 | preLen = cchText/2;
|
|---|
| 365 | endLen = cchText-preLen; //endLen >= preLen
|
|---|
| 366 | char* endPtr = (char*)lpchText+preLen;
|
|---|
| 367 |
|
|---|
| 368 | do
|
|---|
| 369 | {
|
|---|
| 370 | strcpy(&newText[preLen],ELLIPSIS);
|
|---|
| 371 | strncpy(&newText[preLen+ELLIPSISLEN],endPtr,endLen);
|
|---|
| 372 | OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);
|
|---|
| 373 | textWidth = rect.right-rect.left;
|
|---|
| 374 | if ((textWidth <= width) || (preLen+endLen == 0)) break;
|
|---|
| 375 | if (endLen > preLen)
|
|---|
| 376 | {
|
|---|
| 377 | endLen--;
|
|---|
| 378 | endPtr++;
|
|---|
| 379 | } else preLen--;
|
|---|
| 380 | newTextLen--;
|
|---|
| 381 | } while (TRUE);
|
|---|
| 382 | }
|
|---|
| 383 | rc = OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,rectPtr,0,0,flCmd);
|
|---|
| 384 | if (dwDTFormat & DT_MODIFYSTRING) strcpy((LPSTR)lpchText,newText); //check length?
|
|---|
| 385 | free(newText);
|
|---|
| 386 |
|
|---|
| 387 | done = TRUE;
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | if (!done)
|
|---|
| 392 | {
|
|---|
| 393 | rc = OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,rectPtr,0,0,flCmd);
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | if (dwDTFormat & DT_CALCRECT)
|
|---|
| 397 | {
|
|---|
| 398 | if (!(dwDTFormat & DT_RIGHT) && (rectPtr->left < xLeft))
|
|---|
| 399 | {
|
|---|
| 400 | rectPtr->right = xLeft+(rectPtr->right-rectPtr->left);
|
|---|
| 401 | rectPtr->left = xLeft;
|
|---|
| 402 | }
|
|---|
| 403 | if (!(dwDTFormat & DT_BOTTOM) && (rectPtr->top < yTop))
|
|---|
| 404 | {
|
|---|
| 405 | rectPtr->bottom = yTop+(rectPtr->bottom-rectPtr->top);
|
|---|
| 406 | rectPtr->top = yTop;
|
|---|
| 407 | }
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | if (lpDTParams)
|
|---|
| 411 | {
|
|---|
| 412 | // don't forget to restore the margins
|
|---|
| 413 | lprc->left -= lpDTParams->iLeftMargin;
|
|---|
| 414 | lprc->right += lpDTParams->iRightMargin;
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 | _control87(fpuctrlword, 0xFFFF);
|
|---|
| 418 |
|
|---|
| 419 | return rc;
|
|---|
| 420 | }
|
|---|
| 421 | //******************************************************************************
|
|---|
| 422 | //******************************************************************************
|
|---|
| 423 | INT SYSTEM EXPORT InternalDrawTextExW(HDC hdc,LPCWSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams,BOOL isDrawTextEx)
|
|---|
| 424 | {
|
|---|
| 425 | char *astring = (cchText == -1) ? UnicodeToAsciiString((LPWSTR)lpchText):UnicodeToAsciiStringN((LPWSTR)lpchText,cchText);
|
|---|
| 426 | INT rc;
|
|---|
| 427 |
|
|---|
| 428 | dprintf(("InternalDrawTextExW %x %s %d %x", hdc, astring, cchText, dwDTFormat));
|
|---|
| 429 | rc = InternalDrawTextExA(hdc,astring,cchText,lprc,dwDTFormat,lpDTParams,isDrawTextEx);
|
|---|
| 430 | if (dwDTFormat & DT_MODIFYSTRING && (dwDTFormat & (DT_END_ELLIPSIS | DT_PATH_ELLIPSIS))) AsciiToUnicode(astring,(LPWSTR)lpchText);
|
|---|
| 431 | FreeAsciiString(astring);
|
|---|
| 432 |
|
|---|
| 433 | return(rc);
|
|---|
| 434 | }
|
|---|
| 435 | //******************************************************************************
|
|---|
| 436 | // CB: USER32 function, but here is the better place
|
|---|
| 437 | //******************************************************************************
|
|---|
| 438 | DWORD SYSTEM EXPORT InternalGetTabbedTextExtentA(HDC hDC,LPCSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions)
|
|---|
| 439 | {
|
|---|
| 440 | PVOID pHps = OSLibGpiQueryDCData(hDC);
|
|---|
| 441 | BOOL result;
|
|---|
| 442 | POINTLOS2 pts[TXTBOXOS_COUNT];
|
|---|
| 443 | POINTLOS2 widthHeight = {0,0};
|
|---|
| 444 |
|
|---|
| 445 | if (!pHps || (nCount == 0) || (nTabPositions < 0))
|
|---|
| 446 | return 0;
|
|---|
| 447 |
|
|---|
| 448 | if (nCount < 0)
|
|---|
| 449 | {
|
|---|
| 450 | SetLastError(ERROR_STACK_OVERFLOW);
|
|---|
| 451 | return 0;
|
|---|
| 452 | }
|
|---|
| 453 | if ((lpString == NULL) || (nCount > 512) || ((nTabPositions > 0) && (lpnTabStopPositions == NULL)))
|
|---|
| 454 | {
|
|---|
| 455 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 456 | return 0;
|
|---|
| 457 | }
|
|---|
| 458 | //CB: Win95 supports negative values for right aligned text
|
|---|
| 459 | for (INT i = 0;i < nTabPositions;i++)
|
|---|
| 460 | {
|
|---|
| 461 | if (lpnTabStopPositions[i] < 0)
|
|---|
| 462 | {
|
|---|
| 463 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 464 | return 0;
|
|---|
| 465 | }
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | result = OSLibGpiQueryTextBox(pHps,(nCount > 1) ? 1:nCount,lpString,TXTBOXOS_COUNT,pts);
|
|---|
| 469 | if (result == FALSE)
|
|---|
| 470 | return 0;
|
|---|
| 471 | calcDimensions(pts,&widthHeight);
|
|---|
| 472 |
|
|---|
| 473 | LONG rv1 = OSLibGpiQueryTabbedTextExtent(pHps,nCount,lpString,nTabPositions,lpnTabStopPositions);
|
|---|
| 474 | if (rv1 == GPIOS_ERROR)
|
|---|
| 475 | return 0;
|
|---|
| 476 |
|
|---|
| 477 | return (widthHeight.y <<16)+labs(rv1);
|
|---|
| 478 | }
|
|---|
| 479 | //******************************************************************************
|
|---|
| 480 | //******************************************************************************
|
|---|
| 481 | DWORD SYSTEM EXPORT InternalGetTabbedTextExtentW(HDC hDC,LPCWSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions)
|
|---|
| 482 | {
|
|---|
| 483 | char *astring = (nCount == -1) ? UnicodeToAsciiString((LPWSTR)lpString):UnicodeToAsciiStringN((LPWSTR)lpString,nCount);
|
|---|
| 484 | DWORD rc;
|
|---|
| 485 |
|
|---|
| 486 | rc = InternalGetTabbedTextExtentA(hDC,astring,nCount,nTabPositions,lpnTabStopPositions);
|
|---|
| 487 | FreeAsciiString(astring);
|
|---|
| 488 |
|
|---|
| 489 | return(rc);
|
|---|
| 490 | }
|
|---|
| 491 | //******************************************************************************
|
|---|
| 492 | // CB: USER32 function, but here is the better place
|
|---|
| 493 | //******************************************************************************
|
|---|
| 494 | LONG SYSTEM EXPORT InternalTabbedTextOutA(HDC hdc,INT x,INT y,LPCSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions,INT nTabOrigin)
|
|---|
| 495 | {
|
|---|
| 496 | PVOID pHps = OSLibGpiQueryDCData(hdc);
|
|---|
| 497 | POINTLOS2 ptl;
|
|---|
| 498 | DWORD dimensions;
|
|---|
| 499 |
|
|---|
| 500 | if ((pHps == NULL) || (lpString == NULL))
|
|---|
| 501 | {
|
|---|
| 502 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 503 | return 0;
|
|---|
| 504 | }
|
|---|
| 505 | if (nCount == -1)
|
|---|
| 506 | nCount = strlen(lpString);
|
|---|
| 507 | if (nCount < 1)
|
|---|
| 508 | {
|
|---|
| 509 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 510 | return 0;
|
|---|
| 511 | }
|
|---|
| 512 | if (lpnTabStopPositions == NULL)
|
|---|
| 513 | nTabPositions = 0;
|
|---|
| 514 | if (nTabPositions == 0)
|
|---|
| 515 | lpnTabStopPositions = NULL;
|
|---|
| 516 | if (nTabPositions < 0)
|
|---|
| 517 | {
|
|---|
| 518 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 519 | return 0;
|
|---|
| 520 | }
|
|---|
| 521 | if (getAlignUpdateCP(pHps) == TRUE)
|
|---|
| 522 | OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 523 | else
|
|---|
| 524 | {
|
|---|
| 525 | ptl.x = x;
|
|---|
| 526 | ptl.y = y;
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | //CB: nTabOrigin is ignored! -> wrong size (width)!
|
|---|
| 530 | // todo: change low word (width), height is ok
|
|---|
| 531 | dimensions = InternalGetTabbedTextExtentA(hdc,lpString,nCount,nTabPositions,lpnTabStopPositions);
|
|---|
| 532 | if (dimensions != 0)
|
|---|
| 533 | {
|
|---|
| 534 | LONG rcGPI;
|
|---|
| 535 |
|
|---|
| 536 | ptl.y += getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 537 |
|
|---|
| 538 | rcGPI = OSLibGpiTabbedCharStringAt(pHps,&ptl,NULL,0,nCount,lpString,nTabPositions,lpnTabStopPositions,nTabOrigin);
|
|---|
| 539 | if (rcGPI == GPIOS_ALTERROR)
|
|---|
| 540 | return 0;
|
|---|
| 541 | if (getAlignUpdateCP(pHps))
|
|---|
| 542 | {
|
|---|
| 543 | OSLibGpiQueryCurrentPosition (pHps,&ptl);
|
|---|
| 544 | ptl.y -= getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 545 | OSLibGpiSetCurrentPosition (pHps,&ptl);
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | return dimensions;
|
|---|
| 549 | }
|
|---|
| 550 | return 0;
|
|---|
| 551 | }
|
|---|
| 552 | //******************************************************************************
|
|---|
| 553 | //******************************************************************************
|
|---|
| 554 | LONG SYSTEM EXPORT InternalTabbedTextOutW(HDC hdc,INT x,INT y,LPCWSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions,INT nTabOrigin)
|
|---|
| 555 | {
|
|---|
| 556 | char *astring = (nCount == -1) ? UnicodeToAsciiString((LPWSTR)lpString):UnicodeToAsciiStringN((LPWSTR)lpString,nCount);
|
|---|
| 557 | LONG rc;
|
|---|
| 558 |
|
|---|
| 559 | rc = InternalTabbedTextOutA(hdc,x,y,astring,nCount,nTabPositions,lpnTabStopPositions,nTabOrigin);
|
|---|
| 560 | FreeAsciiString(astring);
|
|---|
| 561 |
|
|---|
| 562 | return(rc);
|
|---|
| 563 | }
|
|---|
| 564 | //******************************************************************************
|
|---|
| 565 | // todo: metafile support
|
|---|
| 566 | //******************************************************************************
|
|---|
| 567 | BOOL InternalTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,INT cbCount,CONST INT *lpDx,BOOL IsExtTextOut)
|
|---|
| 568 | {
|
|---|
| 569 | PVOID pHps = OSLibGpiQueryDCData(hdc);
|
|---|
| 570 | ULONG flOptions = 0;
|
|---|
| 571 | RECTLOS2 pmRect;
|
|---|
| 572 | POINTLOS2 ptl;
|
|---|
| 573 | LONG hits;
|
|---|
| 574 |
|
|---|
| 575 | if (!pHps || (cbCount < 0) || ((lpszString == NULL) && (cbCount != 0)))
|
|---|
| 576 | {
|
|---|
| 577 | dprintf(("InternalTextOutA: invalid parameter"));
|
|---|
| 578 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 579 | return FALSE;
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | if (cbCount > 512)
|
|---|
| 583 | {
|
|---|
| 584 | dprintf(("InternalTextOutA: invalid parameter cbCount"));
|
|---|
| 585 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 586 | return FALSE;
|
|---|
| 587 | }
|
|---|
| 588 | if (fuOptions & ~((UINT)(ETO_CLIPPED | ETO_OPAQUE)))
|
|---|
| 589 | {
|
|---|
| 590 | dprintf(("InternalTextOutA: invalid fuOptions"));
|
|---|
| 591 | //ETO_GLYPH_INDEX, ETO_RTLLEADING, ETO_NUMERICSLOCAL, ETO_NUMERICSLATIN, ETO_IGNORELANGUAGE, ETO_PDY are ignored
|
|---|
| 592 | return TRUE;
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | //CB: add metafile info
|
|---|
| 596 |
|
|---|
| 597 | if (lprc)
|
|---|
| 598 | {
|
|---|
| 599 | if (fuOptions)
|
|---|
| 600 | {
|
|---|
| 601 | MapWin32ToOS2Rect(*lprc,pmRect);
|
|---|
| 602 | if (excludeBottomRightPoint(pHps,(PPOINTLOS2)&pmRect) == 0)
|
|---|
| 603 | {
|
|---|
| 604 | dprintf(("InternalTextOutA: excludeBottomRightPoint returned 0"));
|
|---|
| 605 | return TRUE;
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | if (fuOptions & ETO_CLIPPED) flOptions |= CHSOS_CLIP;
|
|---|
| 609 | if (fuOptions & ETO_OPAQUE) flOptions |= CHSOS_OPAQUE;
|
|---|
| 610 | }
|
|---|
| 611 | }
|
|---|
| 612 | else
|
|---|
| 613 | {
|
|---|
| 614 | if (fuOptions)
|
|---|
| 615 | {
|
|---|
| 616 | dprintf(("InternalTextOutA: ERROR_INVALID_HANDLE"));
|
|---|
| 617 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 618 | return FALSE;
|
|---|
| 619 | }
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | if (cbCount == 0)
|
|---|
| 623 | {
|
|---|
| 624 | if (fuOptions & ETO_OPAQUE)
|
|---|
| 625 | {
|
|---|
| 626 | lpszString = " ";
|
|---|
| 627 | cbCount = 1;
|
|---|
| 628 | flOptions |= CHSOS_CLIP;
|
|---|
| 629 | }
|
|---|
| 630 | else {
|
|---|
| 631 | dprintf(("InternalTextOutA: cbCount == 0"));
|
|---|
| 632 | return TRUE;
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 | if (lpDx)
|
|---|
| 636 | flOptions |= CHSOS_VECTOR;
|
|---|
| 637 |
|
|---|
| 638 | if (!getAlignUpdateCP(pHps))
|
|---|
| 639 | {
|
|---|
| 640 | ptl.x = X;
|
|---|
| 641 | ptl.y = Y;
|
|---|
| 642 |
|
|---|
| 643 | flOptions |= CHSOS_LEAVEPOS;
|
|---|
| 644 | }
|
|---|
| 645 | else OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 646 |
|
|---|
| 647 | UINT align = GetTextAlign(hdc);
|
|---|
| 648 | LONG pmHAlign,pmVAlign;
|
|---|
| 649 |
|
|---|
| 650 | //CB: TA_RIGHT not supported by PM, only TA_CENTER and TA_LEFT
|
|---|
| 651 | if ((align & 0x6) == TA_RIGHT)
|
|---|
| 652 | {
|
|---|
| 653 | PPOINTLOS2 pts = (PPOINTLOS2)malloc((cbCount+1)*sizeof(POINTLOS2));
|
|---|
| 654 |
|
|---|
| 655 | OSLibGpiQueryCharStringPosAt(pHps,&ptl,flOptions,cbCount,lpszString,lpDx,pts);
|
|---|
| 656 | ptl.x -= pts[cbCount].x-pts[0].x;
|
|---|
| 657 | free(pts);
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | if (lprc && ((align & 0x18) == TA_BASELINE))
|
|---|
| 661 | {
|
|---|
| 662 | //CB: if TA_BASELINE is set, GPI doesn't fill rect
|
|---|
| 663 | // TA_BOTTOM fills rect
|
|---|
| 664 | OSLibGpiQueryTextAlignment(pHps,&pmHAlign,&pmVAlign);
|
|---|
| 665 | OSLibGpiSetTextAlignment(pHps,pmHAlign,(pmVAlign & ~TAOS_BASE) | TAOS_BOTTOM);
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | ptl.y += getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 669 |
|
|---|
| 670 | hits = OSLibGpiCharStringPosAt(pHps,&ptl,&pmRect,flOptions,cbCount,lpszString,lpDx);
|
|---|
| 671 |
|
|---|
| 672 | if (lprc && ((align & 0x18) == TA_BASELINE))
|
|---|
| 673 | OSLibGpiSetTextAlignment(pHps,pmHAlign,pmVAlign);
|
|---|
| 674 |
|
|---|
| 675 | if(hits == GPIOS_ERROR) {
|
|---|
| 676 | dprintf(("InternalTextOutA: OSLibGpiCharStringPosAt returned GPIOS_ERROR"));
|
|---|
| 677 | return FALSE;
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | if (getAlignUpdateCP(pHps))
|
|---|
| 681 | {
|
|---|
| 682 | OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 683 | ptl.y -= getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 684 | OSLibGpiSetCurrentPosition(pHps,&ptl);
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | return TRUE;
|
|---|
| 688 | }
|
|---|
| 689 | //******************************************************************************
|
|---|
| 690 | //******************************************************************************
|
|---|
| 691 | BOOL InternalTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,INT cbCount,CONST INT *lpDx,BOOL IsExtTextOut)
|
|---|
| 692 | {
|
|---|
| 693 | char *astring = (cbCount == -1) ? UnicodeToAsciiString((LPWSTR)lpszString):UnicodeToAsciiStringN((LPWSTR)lpszString,cbCount);
|
|---|
| 694 | BOOL rc;
|
|---|
| 695 |
|
|---|
| 696 | rc = InternalTextOutA(hdc,X,Y,fuOptions,lprc,(LPCSTR)astring,cbCount,lpDx,IsExtTextOut);
|
|---|
| 697 | FreeAsciiString(astring);
|
|---|
| 698 |
|
|---|
| 699 | return(rc);
|
|---|
| 700 | }
|
|---|
| 701 | //******************************************************************************
|
|---|
| 702 | //******************************************************************************
|
|---|
| 703 | BOOL WIN32API ExtTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,UINT cbCount,CONST INT *lpDx)
|
|---|
| 704 | {
|
|---|
| 705 | dprintf(("GDI32: ExtTextOutA %x %s", hdc, lpszString));
|
|---|
| 706 |
|
|---|
| 707 | return InternalTextOutA(hdc,X,Y,fuOptions,lprc,lpszString,cbCount,lpDx,TRUE);
|
|---|
| 708 | }
|
|---|
| 709 | //******************************************************************************
|
|---|
| 710 | //******************************************************************************
|
|---|
| 711 | BOOL WIN32API ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,UINT cbCount,CONST int *lpDx)
|
|---|
| 712 | {
|
|---|
| 713 | dprintf(("GDI32: ExtTextOutW\n"));
|
|---|
| 714 |
|
|---|
| 715 | return InternalTextOutW(hdc,X,Y,fuOptions,lprc,lpszString,cbCount,lpDx,TRUE);
|
|---|
| 716 | }
|
|---|
| 717 | //******************************************************************************
|
|---|
| 718 | //******************************************************************************
|
|---|
| 719 | BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
|
|---|
| 720 | {
|
|---|
| 721 | dprintf(("GDI32: TextOutA %x %s", hdc, lpszString));
|
|---|
| 722 |
|
|---|
| 723 | return InternalTextOutA(hdc,nXStart,nYStart,0,NULL,lpszString,cbString,NULL,FALSE);
|
|---|
| 724 | }
|
|---|
| 725 | //******************************************************************************
|
|---|
| 726 | //******************************************************************************
|
|---|
| 727 | BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
|
|---|
| 728 | {
|
|---|
| 729 | dprintf(("GDI32: TextOutW"));
|
|---|
| 730 |
|
|---|
| 731 | return InternalTextOutW(hdc,nXStart,nYStart,0,NULL,lpszString,cbString,NULL,FALSE);
|
|---|
| 732 | }
|
|---|
| 733 | //******************************************************************************
|
|---|
| 734 | //******************************************************************************
|
|---|
| 735 | BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings)
|
|---|
| 736 | {
|
|---|
| 737 | dprintf(("GDI32: PolyTextOutA"));
|
|---|
| 738 |
|
|---|
| 739 | for (INT x = 0;x < cStrings;x++)
|
|---|
| 740 | {
|
|---|
| 741 | BOOL rc;
|
|---|
| 742 |
|
|---|
| 743 | rc = InternalTextOutA(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl,pptxt[x].lpstr,pptxt[x].n,pptxt[x].pdx,TRUE);
|
|---|
| 744 | if (!rc) return FALSE;
|
|---|
| 745 | }
|
|---|
| 746 |
|
|---|
| 747 | return TRUE;
|
|---|
| 748 | }
|
|---|
| 749 | //******************************************************************************
|
|---|
| 750 | //******************************************************************************
|
|---|
| 751 | BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings)
|
|---|
| 752 | {
|
|---|
| 753 | dprintf(("GDI32: PolyTextOutW"));
|
|---|
| 754 |
|
|---|
| 755 | for (INT x = 0;x < cStrings;x++)
|
|---|
| 756 | {
|
|---|
| 757 | BOOL rc;
|
|---|
| 758 |
|
|---|
| 759 | rc = InternalTextOutW(hdc,pptxt[x].x,pptxt[x].y,pptxt[x].uiFlags,&pptxt[x].rcl,pptxt[x].lpstr,pptxt[x].n,pptxt[x].pdx,TRUE);
|
|---|
| 760 | if (!rc) return FALSE;
|
|---|
| 761 | }
|
|---|
| 762 |
|
|---|
| 763 | return TRUE;
|
|---|
| 764 | }
|
|---|