1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include <svx/svdorect.hxx> 28 #include <math.h> 29 #include <stdlib.h> 30 #include <svx/xpool.hxx> 31 #include <svx/xpoly.hxx> 32 #include <svx/svdattr.hxx> 33 #include <svx/svdpool.hxx> 34 #include <svx/svdtrans.hxx> 35 #include <svx/svdetc.hxx> 36 #include <svx/svddrag.hxx> 37 #include <svx/svdmodel.hxx> 38 #include <svx/svdpage.hxx> 39 #include <svx/svdocapt.hxx> // fuer Import von SdrFileVersion 2 40 #include <svx/svdpagv.hxx> // fuer 41 #include <svx/svdview.hxx> // das 42 #include <svx/svdundo.hxx> // Macro-Beispiel 43 #include <svx/svdopath.hxx> 44 #include "svx/svdglob.hxx" // Stringcache 45 #include "svx/svdstr.hrc" // Objektname 46 #include <svx/xflclit.hxx> 47 #include <svx/xlnclit.hxx> 48 #include <svx/xlnwtit.hxx> 49 #include "svdoimp.hxx" 50 #include <svx/sdr/properties/rectangleproperties.hxx> 51 #include <svx/sdr/contact/viewcontactofsdrrectobj.hxx> 52 #include <basegfx/polygon/b2dpolygon.hxx> 53 #include <basegfx/polygon/b2dpolygontools.hxx> 54 55 ////////////////////////////////////////////////////////////////////////////// 56 // BaseProperties section 57 58 sdr::properties::BaseProperties* SdrRectObj::CreateObjectSpecificProperties() 59 { 60 return new sdr::properties::RectangleProperties(*this); 61 } 62 63 ////////////////////////////////////////////////////////////////////////////// 64 // DrawContact section 65 66 sdr::contact::ViewContact* SdrRectObj::CreateObjectSpecificViewContact() 67 { 68 return new sdr::contact::ViewContactOfSdrRectObj(*this); 69 } 70 71 ////////////////////////////////////////////////////////////////////////////// 72 73 TYPEINIT1(SdrRectObj,SdrTextObj); 74 75 SdrRectObj::SdrRectObj() 76 : mpXPoly(0L) 77 { 78 bClosedObj=sal_True; 79 } 80 81 SdrRectObj::SdrRectObj(const Rectangle& rRect) 82 : SdrTextObj(rRect), 83 mpXPoly(NULL) 84 { 85 bClosedObj=sal_True; 86 } 87 88 SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind) 89 : SdrTextObj(eNewTextKind), 90 mpXPoly(NULL) 91 { 92 DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT || 93 eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT, 94 "SdrRectObj::SdrRectObj(SdrObjKind) ist nur fuer Textrahmen gedacht"); 95 bClosedObj=sal_True; 96 } 97 98 SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const Rectangle& rRect) 99 : SdrTextObj(eNewTextKind,rRect), 100 mpXPoly(NULL) 101 { 102 DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT || 103 eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT, 104 "SdrRectObj::SdrRectObj(SdrObjKind,...) ist nur fuer Textrahmen gedacht"); 105 bClosedObj=sal_True; 106 } 107 108 SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const Rectangle& rNewRect, SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat) 109 : SdrTextObj(eNewTextKind,rNewRect,rInput,rBaseURL,eFormat), 110 mpXPoly(NULL) 111 { 112 DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT || 113 eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT, 114 "SdrRectObj::SdrRectObj(SdrObjKind,...) ist nur fuer Textrahmen gedacht"); 115 bClosedObj=sal_True; 116 } 117 118 SdrRectObj::~SdrRectObj() 119 { 120 if(mpXPoly) 121 { 122 delete mpXPoly; 123 } 124 } 125 126 void SdrRectObj::SetXPolyDirty() 127 { 128 if(mpXPoly) 129 { 130 delete mpXPoly; 131 mpXPoly = 0L; 132 } 133 } 134 135 FASTBOOL SdrRectObj::PaintNeedsXPoly(long nEckRad) const 136 { 137 FASTBOOL bNeed=aGeo.nDrehWink!=0 || aGeo.nShearWink!=0 || nEckRad!=0; 138 return bNeed; 139 } 140 141 XPolygon SdrRectObj::ImpCalcXPoly(const Rectangle& rRect1, long nRad1) const 142 { 143 XPolygon aXPoly(rRect1,nRad1,nRad1); 144 const sal_uInt16 nPointAnz(aXPoly.GetPointCount()); 145 XPolygon aNeuPoly(nPointAnz+1); 146 sal_uInt16 nShift=nPointAnz-2; 147 if (nRad1!=0) nShift=nPointAnz-5; 148 sal_uInt16 j=nShift; 149 for (sal_uInt16 i=1; i<nPointAnz; i++) { 150 aNeuPoly[i]=aXPoly[j]; 151 aNeuPoly.SetFlags(i,aXPoly.GetFlags(j)); 152 j++; 153 if (j>=nPointAnz) j=1; 154 } 155 aNeuPoly[0]=rRect1.BottomCenter(); 156 aNeuPoly[nPointAnz]=aNeuPoly[0]; 157 aXPoly=aNeuPoly; 158 159 // Die Winkelangaben beziehen sich immer auf die linke obere Ecke von !aRect! 160 if (aGeo.nShearWink!=0) ShearXPoly(aXPoly,aRect.TopLeft(),aGeo.nTan); 161 if (aGeo.nDrehWink!=0) RotateXPoly(aXPoly,aRect.TopLeft(),aGeo.nSin,aGeo.nCos); 162 return aXPoly; 163 } 164 165 void SdrRectObj::RecalcXPoly() 166 { 167 mpXPoly = new XPolygon(ImpCalcXPoly(aRect,GetEckenradius())); 168 } 169 170 const XPolygon& SdrRectObj::GetXPoly() const 171 { 172 if(!mpXPoly) 173 { 174 ((SdrRectObj*)this)->RecalcXPoly(); 175 } 176 177 return *mpXPoly; 178 } 179 180 void SdrRectObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const 181 { 182 FASTBOOL bNoTextFrame=!IsTextFrame(); 183 rInfo.bResizeFreeAllowed=bNoTextFrame || aGeo.nDrehWink%9000==0; 184 rInfo.bResizePropAllowed=sal_True; 185 rInfo.bRotateFreeAllowed=sal_True; 186 rInfo.bRotate90Allowed =sal_True; 187 rInfo.bMirrorFreeAllowed=bNoTextFrame; 188 rInfo.bMirror45Allowed =bNoTextFrame; 189 rInfo.bMirror90Allowed =bNoTextFrame; 190 191 // allow transparence 192 rInfo.bTransparenceAllowed = sal_True; 193 194 // gradient depends on fillstyle 195 XFillStyle eFillStyle = ((XFillStyleItem&)(GetObjectItem(XATTR_FILLSTYLE))).GetValue(); 196 rInfo.bGradientAllowed = (eFillStyle == XFILL_GRADIENT); 197 198 rInfo.bShearAllowed =bNoTextFrame; 199 rInfo.bEdgeRadiusAllowed=sal_True; 200 201 FASTBOOL bCanConv=!HasText() || ImpCanConvTextToCurve(); 202 if (bCanConv && !bNoTextFrame && !HasText()) { 203 bCanConv=HasFill() || HasLine(); 204 } 205 rInfo.bCanConvToPath =bCanConv; 206 rInfo.bCanConvToPoly =bCanConv; 207 rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary()); 208 } 209 210 sal_uInt16 SdrRectObj::GetObjIdentifier() const 211 { 212 if (IsTextFrame()) return sal_uInt16(eTextKind); 213 else return sal_uInt16(OBJ_RECT); 214 } 215 216 void SdrRectObj::TakeUnrotatedSnapRect(Rectangle& rRect) const 217 { 218 rRect=aRect; 219 if (aGeo.nShearWink!=0) { 220 long nDst=Round((aRect.Bottom()-aRect.Top())*aGeo.nTan); 221 if (aGeo.nShearWink>0) { 222 Point aRef(rRect.TopLeft()); 223 rRect.Left()-=nDst; 224 Point aTmpPt(rRect.TopLeft()); 225 RotatePoint(aTmpPt,aRef,aGeo.nSin,aGeo.nCos); 226 aTmpPt-=rRect.TopLeft(); 227 rRect.Move(aTmpPt.X(),aTmpPt.Y()); 228 } else { 229 rRect.Right()-=nDst; 230 } 231 } 232 } 233 234 void SdrRectObj::TakeObjNameSingul(XubString& rName) const 235 { 236 if (IsTextFrame()) 237 { 238 SdrTextObj::TakeObjNameSingul(rName); 239 } 240 else 241 { 242 sal_uInt16 nResId=STR_ObjNameSingulRECT; 243 if (aGeo.nShearWink!=0) { 244 nResId+=4; // Parallelogramm oder Raute 245 // Raute ist nicht, weil Shear die vertikalen Kanten verlaengert! 246 // Wenn Zeit ist, werde ich das mal berechnen. 247 } else { 248 if (aRect.GetWidth()==aRect.GetHeight()) nResId+=2; // Quadrat 249 } 250 if (GetEckenradius()!=0) nResId+=8; // abgerundet 251 rName=ImpGetResStr(nResId); 252 253 String aName( GetName() ); 254 if(aName.Len()) 255 { 256 rName += sal_Unicode(' '); 257 rName += sal_Unicode('\''); 258 rName += aName; 259 rName += sal_Unicode('\''); 260 } 261 } 262 } 263 264 void SdrRectObj::TakeObjNamePlural(XubString& rName) const 265 { 266 if (IsTextFrame()) SdrTextObj::TakeObjNamePlural(rName); 267 else { 268 sal_uInt16 nResId=STR_ObjNamePluralRECT; 269 if (aGeo.nShearWink!=0) { 270 nResId+=4; // Parallelogramm oder Raute 271 } else { 272 if (aRect.GetWidth()==aRect.GetHeight()) nResId+=2; // Quadrat 273 } 274 if (GetEckenradius()!=0) nResId+=8; // abgerundet 275 rName=ImpGetResStr(nResId); 276 } 277 } 278 279 void SdrRectObj::operator=(const SdrObject& rObj) 280 { 281 SdrTextObj::operator=(rObj); 282 } 283 284 basegfx::B2DPolyPolygon SdrRectObj::TakeXorPoly() const 285 { 286 XPolyPolygon aXPP; 287 aXPP.Insert(ImpCalcXPoly(aRect,GetEckenradius())); 288 return aXPP.getB2DPolyPolygon(); 289 } 290 291 void SdrRectObj::RecalcSnapRect() 292 { 293 long nEckRad=GetEckenradius(); 294 if ((aGeo.nDrehWink!=0 || aGeo.nShearWink!=0) && nEckRad!=0) { 295 maSnapRect=GetXPoly().GetBoundRect(); 296 } else { 297 SdrTextObj::RecalcSnapRect(); 298 } 299 } 300 301 void SdrRectObj::NbcSetSnapRect(const Rectangle& rRect) 302 { 303 SdrTextObj::NbcSetSnapRect(rRect); 304 SetXPolyDirty(); 305 } 306 307 void SdrRectObj::NbcSetLogicRect(const Rectangle& rRect) 308 { 309 SdrTextObj::NbcSetLogicRect(rRect); 310 SetXPolyDirty(); 311 } 312 313 sal_uInt32 SdrRectObj::GetHdlCount() const 314 { 315 return IsTextFrame() ? 10 : 9; 316 } 317 318 SdrHdl* SdrRectObj::GetHdl(sal_uInt32 nHdlNum) const 319 { 320 SdrHdl* pH = NULL; 321 Point aPnt; 322 SdrHdlKind eKind = HDL_MOVE; 323 324 if(!IsTextFrame()) 325 { 326 nHdlNum++; 327 } 328 329 switch(nHdlNum) 330 { 331 case 0: 332 { 333 pH = new ImpTextframeHdl(aRect); 334 pH->SetObj((SdrObject*)this); 335 pH->SetDrehWink(aGeo.nDrehWink); 336 break; 337 } 338 case 1: 339 { 340 long a = GetEckenradius(); 341 long b = Max(aRect.GetWidth(),aRect.GetHeight())/2; // Wird aufgerundet, da GetWidth() eins draufaddiert 342 if (a>b) a=b; 343 if (a<0) a=0; 344 aPnt=aRect.TopLeft(); 345 aPnt.X()+=a; 346 eKind = HDL_CIRC; 347 break; 348 } 349 case 2: aPnt=aRect.TopLeft(); eKind = HDL_UPLFT; break; // Oben links 350 case 3: aPnt=aRect.TopCenter(); eKind = HDL_UPPER; break; // Oben 351 case 4: aPnt=aRect.TopRight(); eKind = HDL_UPRGT; break; // Oben rechts 352 case 5: aPnt=aRect.LeftCenter(); eKind = HDL_LEFT ; break; // Links 353 case 6: aPnt=aRect.RightCenter(); eKind = HDL_RIGHT; break; // Rechts 354 case 7: aPnt=aRect.BottomLeft(); eKind = HDL_LWLFT; break; // Unten links 355 case 8: aPnt=aRect.BottomCenter(); eKind = HDL_LOWER; break; // Unten 356 case 9: aPnt=aRect.BottomRight(); eKind = HDL_LWRGT; break; // Unten rechts 357 } 358 359 if(!pH) 360 { 361 if(aGeo.nShearWink) 362 { 363 ShearPoint(aPnt,aRect.TopLeft(),aGeo.nTan); 364 } 365 366 if(aGeo.nDrehWink) 367 { 368 RotatePoint(aPnt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos); 369 } 370 371 pH = new SdrHdl(aPnt,eKind); 372 pH->SetObj((SdrObject*)this); 373 pH->SetDrehWink(aGeo.nDrehWink); 374 } 375 376 return pH; 377 } 378 379 //////////////////////////////////////////////////////////////////////////////////////////////////// 380 381 bool SdrRectObj::hasSpecialDrag() const 382 { 383 return true; 384 } 385 386 bool SdrRectObj::beginSpecialDrag(SdrDragStat& rDrag) const 387 { 388 const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind()); 389 390 if(bRad) 391 { 392 rDrag.SetEndDragChangesAttributes(true); 393 394 return true; 395 } 396 397 return SdrTextObj::beginSpecialDrag(rDrag); 398 } 399 400 bool SdrRectObj::applySpecialDrag(SdrDragStat& rDrag) 401 { 402 const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind()); 403 404 if (bRad) 405 { 406 Rectangle aBoundRect0; 407 Point aPt(rDrag.GetNow()); 408 409 if(aGeo.nDrehWink) 410 RotatePoint(aPt,aRect.TopLeft(),-aGeo.nSin,aGeo.nCos); 411 412 sal_Int32 nRad(aPt.X() - aRect.Left()); 413 414 if (nRad < 0) 415 nRad = 0; 416 417 if(nRad != GetEckenradius()) 418 { 419 NbcSetEckenradius(nRad); 420 } 421 422 return true; 423 } 424 else 425 { 426 return SdrTextObj::applySpecialDrag(rDrag); 427 } 428 } 429 430 String SdrRectObj::getSpecialDragComment(const SdrDragStat& rDrag) const 431 { 432 const bool bCreateComment(rDrag.GetView() && this == rDrag.GetView()->GetCreateObj()); 433 434 if(bCreateComment) 435 { 436 return String(); 437 } 438 else 439 { 440 const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind()); 441 442 if(bRad) 443 { 444 Point aPt(rDrag.GetNow()); 445 446 // -sin fuer Umkehrung 447 if(aGeo.nDrehWink) 448 RotatePoint(aPt, aRect.TopLeft(), -aGeo.nSin, aGeo.nCos); 449 450 sal_Int32 nRad(aPt.X() - aRect.Left()); 451 452 if(nRad < 0) 453 nRad = 0; 454 455 XubString aStr; 456 457 ImpTakeDescriptionStr(STR_DragRectEckRad, aStr); 458 aStr.AppendAscii(" ("); 459 aStr += GetMetrStr(nRad); 460 aStr += sal_Unicode(')'); 461 462 return aStr; 463 } 464 else 465 { 466 return SdrTextObj::getSpecialDragComment(rDrag); 467 } 468 } 469 } 470 471 //////////////////////////////////////////////////////////////////////////////////////////////////// 472 473 basegfx::B2DPolyPolygon SdrRectObj::TakeCreatePoly(const SdrDragStat& rDrag) const 474 { 475 Rectangle aRect1; 476 rDrag.TakeCreateRect(aRect1); 477 aRect1.Justify(); 478 479 basegfx::B2DPolyPolygon aRetval; 480 aRetval.append(ImpCalcXPoly(aRect1,GetEckenradius()).getB2DPolygon()); 481 return aRetval; 482 } 483 484 Pointer SdrRectObj::GetCreatePointer() const 485 { 486 if (IsTextFrame()) return Pointer(POINTER_DRAW_TEXT); 487 return Pointer(POINTER_DRAW_RECT); 488 } 489 490 void SdrRectObj::NbcMove(const Size& rSiz) 491 { 492 SdrTextObj::NbcMove(rSiz); 493 SetXPolyDirty(); 494 } 495 496 void SdrRectObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) 497 { 498 SdrTextObj::NbcResize(rRef,xFact,yFact); 499 SetXPolyDirty(); 500 } 501 502 void SdrRectObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs) 503 { 504 SdrTextObj::NbcRotate(rRef,nWink,sn,cs); 505 SetXPolyDirty(); 506 } 507 508 void SdrRectObj::NbcShear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear) 509 { 510 SdrTextObj::NbcShear(rRef,nWink,tn,bVShear); 511 SetXPolyDirty(); 512 } 513 514 void SdrRectObj::NbcMirror(const Point& rRef1, const Point& rRef2) 515 { 516 SdrTextObj::NbcMirror(rRef1,rRef2); 517 SetXPolyDirty(); 518 } 519 520 FASTBOOL SdrRectObj::DoMacro(const SdrObjMacroHitRec& rRec) 521 { 522 return SdrTextObj::DoMacro(rRec); 523 } 524 525 XubString SdrRectObj::GetMacroPopupComment(const SdrObjMacroHitRec& rRec) const 526 { 527 return SdrTextObj::GetMacroPopupComment(rRec); 528 } 529 530 SdrGluePoint SdrRectObj::GetVertexGluePoint(sal_uInt16 nPosNum) const 531 { 532 sal_Int32 nWdt = ImpGetLineWdt(); // #i25616# ((XLineWidthItem&)(GetObjectItem(XATTR_LINEWIDTH))).GetValue(); 533 534 // #i25616# 535 if(!LineIsOutsideGeometry()) 536 { 537 nWdt++; 538 nWdt /= 2; 539 } 540 541 Point aPt; 542 switch (nPosNum) { 543 case 0: aPt=aRect.TopCenter(); aPt.Y()-=nWdt; break; 544 case 1: aPt=aRect.RightCenter(); aPt.X()+=nWdt; break; 545 case 2: aPt=aRect.BottomCenter(); aPt.Y()+=nWdt; break; 546 case 3: aPt=aRect.LeftCenter(); aPt.X()-=nWdt; break; 547 } 548 if (aGeo.nShearWink!=0) ShearPoint(aPt,aRect.TopLeft(),aGeo.nTan); 549 if (aGeo.nDrehWink!=0) RotatePoint(aPt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos); 550 aPt-=GetSnapRect().Center(); 551 SdrGluePoint aGP(aPt); 552 aGP.SetPercent(sal_False); 553 return aGP; 554 } 555 556 SdrGluePoint SdrRectObj::GetCornerGluePoint(sal_uInt16 nPosNum) const 557 { 558 sal_Int32 nWdt = ImpGetLineWdt(); // #i25616# ((XLineWidthItem&)(GetObjectItem(XATTR_LINEWIDTH))).GetValue(); 559 560 // #i25616# 561 if(!LineIsOutsideGeometry()) 562 { 563 nWdt++; 564 nWdt /= 2; 565 } 566 567 Point aPt; 568 switch (nPosNum) { 569 case 0: aPt=aRect.TopLeft(); aPt.X()-=nWdt; aPt.Y()-=nWdt; break; 570 case 1: aPt=aRect.TopRight(); aPt.X()+=nWdt; aPt.Y()-=nWdt; break; 571 case 2: aPt=aRect.BottomRight(); aPt.X()+=nWdt; aPt.Y()+=nWdt; break; 572 case 3: aPt=aRect.BottomLeft(); aPt.X()-=nWdt; aPt.Y()+=nWdt; break; 573 } 574 if (aGeo.nShearWink!=0) ShearPoint(aPt,aRect.TopLeft(),aGeo.nTan); 575 if (aGeo.nDrehWink!=0) RotatePoint(aPt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos); 576 aPt-=GetSnapRect().Center(); 577 SdrGluePoint aGP(aPt); 578 aGP.SetPercent(sal_False); 579 return aGP; 580 } 581 582 SdrObject* SdrRectObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const 583 { 584 XPolygon aXP(ImpCalcXPoly(aRect,GetEckenradius())); 585 { // #40608# Nur Uebergangsweise bis zum neuen TakeContour() 586 aXP.Remove(0,1); 587 aXP[aXP.GetPointCount()-1]=aXP[0]; 588 } 589 590 basegfx::B2DPolyPolygon aPolyPolygon(aXP.getB2DPolygon()); 591 aPolyPolygon.removeDoublePoints(); 592 SdrObject* pRet = 0L; 593 594 if(!IsTextFrame() || HasFill() || HasLine()) 595 { 596 pRet = ImpConvertMakeObj(aPolyPolygon, sal_True, bBezier); 597 } 598 599 if(bAddText) 600 { 601 pRet = ImpConvertAddText(pRet, bBezier); 602 } 603 604 return pRet; 605 } 606 607 void SdrRectObj::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) 608 { 609 SdrTextObj::Notify(rBC,rHint); 610 SetXPolyDirty(); // wg. Eckenradius 611 } 612 613 void SdrRectObj::RestGeoData(const SdrObjGeoData& rGeo) 614 { 615 SdrTextObj::RestGeoData(rGeo); 616 SetXPolyDirty(); 617 } 618 619 // eof 620