Changeset 7682 for trunk/src/gdi32/text.cpp
- Timestamp:
- Dec 26, 2001, 12:33:10 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gdi32/text.cpp
r6684 r7682 1 /* $Id: text.cpp,v 1.2 7 2001-09-09 12:24:13sandervl Exp $ */1 /* $Id: text.cpp,v 1.28 2001-12-26 11:33:10 sandervl Exp $ */ 2 2 3 3 /* … … 70 70 return GetTextCharsetInfo(hdc, NULL, 0); 71 71 } 72 //******************************************************************************73 // CB: USER32 function, but here is the better place74 //******************************************************************************75 INT SYSTEM EXPORT InternalDrawTextExA(HDC hdc,LPCSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams,BOOL isDrawTextEx)76 {77 INT rc;78 ULONG flCmd;79 RECT localRectangle;80 PRECT rectPtr;81 LONG lTabs,xLeft,yTop;82 UINT fpuctrlword;83 84 //SvL: Open32's DrawText messes up the fpu control word! (@#$@#$@#$)85 //CB: don't know if this is still the case with WinDrawTabbedText (-> testcase)86 fpuctrlword = _control87(0, 0);87 88 if ((!lpchText) || (cchText == 0) || (cchText < -1) || (lprc == NULL))89 {90 SetLastError(ERROR_INVALID_PARAMETER);91 return 0;92 }93 94 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);95 96 if (!pHps)97 {98 SetLastError(ERROR_INVALID_HANDLE);99 return 0;100 }101 102 if (cchText == -1)103 {104 cchText = strlen(lpchText);105 if (cchText == 0)106 return 0; //CB: does Win32 return textheight in this case?107 }108 109 if (lpDTParams)110 {111 // set margins112 lprc->left += lpDTParams->iLeftMargin;113 lprc->right -= lpDTParams->iRightMargin;114 115 // just assume all the text has been drawn116 lpDTParams->uiLengthDrawn = cchText;117 }118 119 if (!(dwDTFormat & DT_CALCRECT))120 {121 BOOL bTopBottomIsOkay;122 123 if ((getIsTopTop(pHps) && lprc->top > lprc->bottom) ||124 (!getIsTopTop(pHps) && lprc->top < lprc->bottom))125 bTopBottomIsOkay = FALSE;126 else127 bTopBottomIsOkay = TRUE;128 129 if ((lprc->left >= lprc->right) || !bTopBottomIsOkay)130 {131 TEXTMETRICA txtMetrics;132 BOOL result;133 134 result = GetTextMetricsA(hdc,&txtMetrics);135 if (result)136 rc = (int)txtMetrics.tmHeight;137 else138 rc = 0;139 140 if (lpDTParams)141 {142 lprc->left -= lpDTParams->iLeftMargin;143 lprc->right += lpDTParams->iRightMargin;144 }145 146 return rc;147 }148 }149 #ifdef INVERT150 flCmd = DTOS_INVERT | DTOS_WORLDRECT | DTOS_TEXTATTRS | DTOS_AMPERSAND | DTOS_VERTICALEXTENT;151 #else152 flCmd = DTOS_INVERT | DTOS_WORLDRECT | DTOS_TEXTATTRS | DTOS_AMPERSAND | DTOS_VERTICALEXTENT;153 #endif154 155 LONG lMixMode = OSLibGpiQueryBackMix(pHps);156 if (lMixMode == BMOS_OVERPAINT) flCmd |= DTOS_OPAQUE;157 158 if (dwDTFormat & DT_CALCRECT)159 {160 rectPtr = lprc;161 flCmd |= DTOS_QUERYEXTENT;162 163 xLeft = rectPtr->left;164 yTop = rectPtr->top;165 166 if (dwDTFormat & DT_RIGHT)167 {168 if (rectPtr->left >= rectPtr->right)169 rectPtr->left = rectPtr->right-1;170 } else171 {172 if (rectPtr->right <= rectPtr->left)173 rectPtr->right = rectPtr->left+1;174 }175 176 if (dwDTFormat & DT_BOTTOM)177 {178 if (rectPtr->top >= rectPtr->bottom)179 rectPtr->top = rectPtr->bottom-1;180 } else181 {182 if (rectPtr->bottom <= rectPtr->top)183 rectPtr->bottom = rectPtr->top+1;184 }185 } else186 {187 rectPtr = &localRectangle;188 189 if ((getMapMode(pHps) == MMOS_ANISOTROPIC) || (getMapMode(pHps) == MMOS_ISOTROPIC))190 {191 if (doesYAxisGrowNorth(pHps))192 {193 flCmd &= ~DTOS_INVERT;194 flCmd |= DTOS_INVERTCHAR;195 }196 }197 198 if (lprc->left > lprc->right)199 {200 rectPtr->left = lprc->right;201 rectPtr->right = lprc->left;202 } else203 {204 rectPtr->left = lprc->left;205 rectPtr->right = lprc->right;206 }207 if (lprc->top > lprc->bottom)208 {209 rectPtr->top = lprc->bottom;210 rectPtr->bottom = lprc->top;211 } else212 {213 rectPtr->top = lprc->top;214 rectPtr->bottom = lprc->bottom;215 }216 217 #ifndef INVERT218 if (pHps->yInvert > 0) {219 int temp = pHps->yInvert - rectPtr->bottom;220 rectPtr->bottom = pHps->yInvert - rectPtr->top;221 rectPtr->top = temp;222 }223 #endif224 }225 226 #ifndef INVERT227 //// dwDTFormat &= ~DT_INVERT;228 //// dwDTFormat |= DT_INVERTCHAR;229 int top = rectPtr->top;230 #endif231 232 if (dwDTFormat & DT_EXPANDTABS)233 {234 if (isDrawTextEx)235 {236 lTabs = (lpDTParams && (dwDTFormat & DT_TABSTOP)) ? lpDTParams->iTabLength:8;237 } else238 {239 lTabs = 8;240 241 if (dwDTFormat & DT_TABSTOP)242 {243 lTabs = (dwDTFormat >> 8) & 0x000000FF;244 dwDTFormat &= 0xFFFF00FF;245 }246 }247 } else lTabs = -1;248 249 if (dwDTFormat & DT_RIGHT)250 flCmd |= DTOS_RIGHT;251 else252 if (dwDTFormat & DT_CENTER) flCmd |= DTOS_CENTER;253 if (dwDTFormat & DT_BOTTOM) flCmd |= DTOS_BOTTOM;254 if (dwDTFormat & DT_VCENTER) flCmd |= DTOS_VCENTER;255 if (dwDTFormat & DT_WORDBREAK) flCmd |= DTOS_WORDBREAK;256 if (dwDTFormat & DT_EXTERNALLEADING) flCmd |= DTOS_EXTERNALLEADING;257 if (!(dwDTFormat & DT_NOPREFIX)) flCmd |= DTOS_MNEMONIC;258 if (dwDTFormat & DT_SINGLELINE)259 flCmd |= DTOS_SINGLELINE;260 else261 flCmd |= DTOS_MULTILINE;262 if (dwDTFormat & DT_NOCLIP) flCmd |= DTOS_NOCLIP;263 264 //CB: DT_EDITCONTROL, DT_RTLREADING ignored265 266 BOOL done = FALSE;267 268 if ((dwDTFormat & DT_END_ELLIPSIS) && (cchText > 1))269 {270 int textWidth,width;271 RECT rect;272 273 SetRectEmpty(&rect);274 OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);275 width = rectPtr->right-rectPtr->left;276 textWidth = rect.right-rect.left;277 if ((textWidth > width) && (width > 0))278 {279 char* newText;280 int newTextLen = cchText-1+ELLIPSISLEN;281 int preLen = cchText-1;282 283 newText = (char*)malloc(newTextLen+1);284 strncpy(newText,lpchText,cchText-1);285 do286 {287 strcpy(&newText[preLen],ELLIPSIS);288 OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);289 textWidth = rect.right-rect.left;290 if (textWidth <= width || preLen == 1) break;291 newTextLen--;292 preLen--;293 } while (TRUE);294 rc = OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,rectPtr,0,0,flCmd);295 if (dwDTFormat & DT_MODIFYSTRING) strcpy((LPSTR)lpchText,newText); //check length?296 free(newText);297 298 done = TRUE;299 }300 } else if ((dwDTFormat & DT_PATH_ELLIPSIS) && (cchText > 1))301 {302 int textWidth,width;303 RECT rect;304 305 //CB: code not yet checked (-> testcase)306 307 SetRectEmpty(&rect);308 OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);309 width = rectPtr->right-rectPtr->left;310 textWidth = rect.right-rect.left;311 if ((textWidth > width) && (width > 0))312 {313 char *newText,*slashPos;314 int newTextLen = cchText+ELLIPSISLEN;315 316 newText = (char*)malloc(newTextLen+1);317 strncpy(newText,lpchText,cchText);318 319 // PH 2000/10/01 "//" appeared wrong ...320 slashPos = strrchr(newText,(int)'\\');321 if (slashPos != NULL)322 {323 int preLen = slashPos-newText;324 char* endPtr = (char*)lpchText+preLen;325 int endLen = cchText-preLen;326 BOOL ok = FALSE;327 328 //delete start329 do330 {331 strcpy(&newText[preLen],ELLIPSIS);332 strncpy(&newText[preLen+ELLIPSISLEN],endPtr,endLen);333 OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);334 textWidth = rect.right-rect.left;335 if (textWidth <= width)336 {337 ok = TRUE;338 break;339 }340 if (preLen == 0) break;341 newTextLen--;342 preLen--;343 } while (TRUE);344 345 if (!ok)346 {347 //delete end348 do349 {350 endPtr++;351 endLen--;352 newTextLen--;353 strncpy(&newText[ELLIPSISLEN],endPtr,endLen);354 OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);355 textWidth = rect.right-rect.left;356 if ((textWidth <= width) || (endLen == 0)) break;357 } while (TRUE);358 }359 } else360 {361 int preLen,endLen;362 363 preLen = cchText/2;364 endLen = cchText-preLen; //endLen >= preLen365 char* endPtr = (char*)lpchText+preLen;366 367 do368 {369 strcpy(&newText[preLen],ELLIPSIS);370 strncpy(&newText[preLen+ELLIPSISLEN],endPtr,endLen);371 OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,&rect,0,0,flCmd | DTOS_QUERYEXTENT);372 textWidth = rect.right-rect.left;373 if ((textWidth <= width) || (preLen+endLen == 0)) break;374 if (endLen > preLen)375 {376 endLen--;377 endPtr++;378 } else preLen--;379 newTextLen--;380 } while (TRUE);381 }382 rc = OSLibWinDrawTabbedText(pHps,newTextLen,lTabs,newText,rectPtr,0,0,flCmd);383 if (dwDTFormat & DT_MODIFYSTRING) strcpy((LPSTR)lpchText,newText); //check length?384 free(newText);385 386 done = TRUE;387 }388 }389 390 if (!done)391 {392 rc = OSLibWinDrawTabbedText(pHps,cchText,lTabs,lpchText,rectPtr,0,0,flCmd);393 }394 395 if (dwDTFormat & DT_CALCRECT)396 {397 #ifndef INVERT398 if (pHps->yInvert > 0) {399 top = top - rectPtr->top;400 rectPtr->top += top;401 rectPtr->bottom += top;402 } /* endif */403 #endif404 if (!(dwDTFormat & DT_RIGHT) && (rectPtr->left < xLeft))405 {406 rectPtr->right = xLeft+(rectPtr->right-rectPtr->left);407 rectPtr->left = xLeft;408 }409 if (!(dwDTFormat & DT_BOTTOM) && (rectPtr->top < yTop))410 {411 rectPtr->bottom = yTop+(rectPtr->bottom-rectPtr->top);412 rectPtr->top = yTop;413 }414 }415 416 if (lpDTParams)417 {418 // don't forget to restore the margins419 lprc->left -= lpDTParams->iLeftMargin;420 lprc->right += lpDTParams->iRightMargin;421 }422 423 _control87(fpuctrlword, 0xFFFF);424 425 return rc;426 }427 //******************************************************************************428 //******************************************************************************429 INT SYSTEM EXPORT InternalDrawTextExW(HDC hdc,LPCWSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams,BOOL isDrawTextEx)430 {431 char *astring = NULL;432 INT rc;433 434 if(cchText == -1) {435 astring = UnicodeToAsciiString((LPWSTR)lpchText);436 }437 else {438 astring = (char *)HEAP_malloc(cchText+1);439 UnicodeToAsciiN((LPWSTR)lpchText, astring, cchText+1);440 astring[cchText] = 0;441 }442 443 dprintf(("InternalDrawTextExW %x %s %d %x", hdc, astring, cchText, dwDTFormat));444 rc = InternalDrawTextExA(hdc,astring,cchText,lprc,dwDTFormat,lpDTParams,isDrawTextEx);445 if (dwDTFormat & DT_MODIFYSTRING && (dwDTFormat & (DT_END_ELLIPSIS | DT_PATH_ELLIPSIS))) AsciiToUnicode(astring,(LPWSTR)lpchText);446 FreeAsciiString(astring);447 448 return(rc);449 }450 #if 0451 //Replaced with Wine functions in user32\text.cpp)452 //******************************************************************************453 // CB: USER32 function, but here is the better place454 //******************************************************************************455 DWORD SYSTEM EXPORT InternalGetTabbedTextExtentA(HDC hDC,LPCSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions)456 {457 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hDC);458 BOOL result;459 POINTLOS2 pts[TXTBOXOS_COUNT];460 POINTLOS2 widthHeight = {0,0};461 462 if (!pHps || (nCount == 0) || (nTabPositions < 0))463 return 0;464 465 if (nCount < 0)466 {467 SetLastError(ERROR_STACK_OVERFLOW);468 return 0;469 }470 if ((lpString == NULL) || ((nTabPositions > 0) && (lpnTabStopPositions == NULL)))471 {472 SetLastError(ERROR_INVALID_PARAMETER);473 return 0;474 }475 if(nCount > 512) {476 DWORD cbStringNew;477 DWORD ret1;478 DWORD ret = 0;479 480 dprintf(("WARNING: InternalGetTabbedTextExtentA string longer than 512 chars; splitting up"));481 while(nCount) {482 cbStringNew = min(500, nCount);483 484 ret = InternalGetTabbedTextExtentA(hDC, lpString, cbStringNew, nTabPositions, lpnTabStopPositions);485 lpString += cbStringNew;486 nCount -= cbStringNew;487 }488 return ret;489 }490 491 //CB: Win95 supports negative values for right aligned text492 for (INT i = 0;i < nTabPositions;i++)493 {494 if (lpnTabStopPositions[i] < 0)495 {496 SetLastError(ERROR_INVALID_PARAMETER);497 return 0;498 }499 }500 501 result = OSLibGpiQueryTextBox(pHps,(nCount > 1) ? 1:nCount,lpString,TXTBOXOS_COUNT,pts);502 if (result == FALSE)503 return 0;504 calcDimensions(pts,&widthHeight);505 506 LONG rv1 = OSLibGpiQueryTabbedTextExtent(pHps,nCount,lpString,nTabPositions,lpnTabStopPositions);507 if (rv1 == GPIOS_ERROR)508 return 0;509 510 return (widthHeight.y <<16)+labs(rv1);511 }512 //******************************************************************************513 //******************************************************************************514 DWORD SYSTEM EXPORT InternalGetTabbedTextExtentW(HDC hDC,LPCWSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions)515 {516 char *astring;517 DWORD rc;518 519 if(nCount == -1) {520 astring = UnicodeToAsciiString((LPWSTR)lpString);521 }522 else {523 astring = (char *)HEAP_malloc(nCount+1);524 UnicodeToAsciiN((LPWSTR)lpString, astring, nCount+1);525 astring[nCount] = 0;526 }527 528 rc = InternalGetTabbedTextExtentA(hDC,astring,nCount,nTabPositions,lpnTabStopPositions);529 FreeAsciiString(astring);530 531 return(rc);532 }533 //******************************************************************************534 // CB: USER32 function, but here is the better place535 //******************************************************************************536 LONG SYSTEM EXPORT InternalTabbedTextOutA(HDC hdc,INT x,INT y,LPCSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions,INT nTabOrigin)537 {538 pDCData pHps = (pDCData)OSLibGpiQueryDCData(hdc);539 POINTLOS2 ptl;540 DWORD dimensions;541 542 if ((pHps == NULL) || (lpString == NULL))543 {544 SetLastError(ERROR_INVALID_HANDLE);545 return 0;546 }547 if (nCount == -1)548 nCount = strlen(lpString);549 if (nCount < 1)550 {551 SetLastError(ERROR_INVALID_HANDLE);552 return 0;553 }554 if (lpnTabStopPositions == NULL)555 nTabPositions = 0;556 if (nTabPositions == 0)557 lpnTabStopPositions = NULL;558 if (nTabPositions < 0)559 {560 SetLastError(ERROR_INVALID_HANDLE);561 return 0;562 }563 if (getAlignUpdateCP(pHps) == TRUE) {564 OSLibGpiQueryCurrentPosition(pHps,&ptl);565 }566 else567 {568 ptl.x = x;569 ptl.y = y;570 #ifndef INVERT571 if (pHps->yInvert > 0) {572 ptl.y = pHps->yInvert - ptl.y;573 }574 #endif575 }576 577 //CB: nTabOrigin is ignored! -> wrong size (width)!578 // todo: change low word (width), height is ok579 dimensions = InternalGetTabbedTextExtentA(hdc,lpString,nCount,nTabPositions,lpnTabStopPositions);580 if (dimensions != 0)581 {582 LONG rcGPI;583 584 ptl.y += getWorldYDeltaFor1Pixel(pHps);585 586 rcGPI = OSLibGpiTabbedCharStringAt(pHps,&ptl,NULL,0,nCount,lpString,nTabPositions,lpnTabStopPositions,nTabOrigin);587 if (rcGPI == GPIOS_ALTERROR)588 return 0;589 if (getAlignUpdateCP(pHps))590 {591 OSLibGpiQueryCurrentPosition (pHps,&ptl);592 ptl.y -= getWorldYDeltaFor1Pixel(pHps);593 OSLibGpiSetCurrentPosition (pHps,&ptl);594 }595 596 return dimensions;597 }598 return 0;599 }600 //******************************************************************************601 //******************************************************************************602 LONG SYSTEM EXPORT InternalTabbedTextOutW(HDC hdc,INT x,INT y,LPCWSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions,INT nTabOrigin)603 {604 char *astring;605 LONG rc;606 607 if(nCount == -1) {608 astring = UnicodeToAsciiString((LPWSTR)lpString);609 }610 else {611 astring = (char *)HEAP_malloc(nCount+1);612 UnicodeToAsciiN((LPWSTR)lpString, astring, nCount+1);613 astring[nCount] = 0;614 }615 616 rc = InternalTabbedTextOutA(hdc,x,y,astring,nCount,nTabPositions,lpnTabStopPositions,nTabOrigin);617 FreeAsciiString(astring);618 619 return(rc);620 }621 #endif622 72 //****************************************************************************** 623 73 // todo: metafile support … … 847 297 BOOL WIN32API PolyTextOutA(HDC hdc,POLYTEXTA *pptxt,int cStrings) 848 298 { 849 dprintf(("GDI32: PolyTextOutA "));299 dprintf(("GDI32: PolyTextOutA %x %x %d", hdc, pptxt, cStrings)); 850 300 851 301 for (INT x = 0;x < cStrings;x++) … … 863 313 BOOL WIN32API PolyTextOutW(HDC hdc,POLYTEXTW *pptxt,int cStrings) 864 314 { 865 dprintf(("GDI32: PolyTextOutW "));315 dprintf(("GDI32: PolyTextOutW %x %x %d", hdc, pptxt, cStrings)); 866 316 867 317 for (INT x = 0;x < cStrings;x++)
Note:
See TracChangeset
for help on using the changeset viewer.