1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/svdorect.hxx>
#include <svx/xpoly.hxx>
#include <svx/svdtrans.hxx>
#include <svx/svddrag.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdview.hxx>
#include <svx/svdopath.hxx>
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
#include <sdr/properties/rectangleproperties.hxx>
#include <sdr/contact/viewcontactofsdrrectobj.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/debug.hxx>
#include <vcl/ptrstyle.hxx>
using namespace com::sun::star;
// BaseProperties section
std::unique_ptr<sdr::properties::BaseProperties> SdrRectObj::CreateObjectSpecificProperties()
{
return std::make_unique<sdr::properties::RectangleProperties>(*this);
}
// DrawContact section
std::unique_ptr<sdr::contact::ViewContact> SdrRectObj::CreateObjectSpecificViewContact()
{
return std::make_unique<sdr::contact::ViewContactOfSdrRectObj>(*this);
}
SdrRectObj::SdrRectObj(SdrModel& rSdrModel)
: SdrTextObj(rSdrModel)
{
bClosedObj=true;
}
SdrRectObj::SdrRectObj(
SdrModel& rSdrModel,
const tools::Rectangle& rRect)
: SdrTextObj(rSdrModel, rRect)
{
bClosedObj=true;
}
SdrRectObj::SdrRectObj(
SdrModel& rSdrModel,
SdrObjKind eNewTextKind)
: SdrTextObj(rSdrModel, eNewTextKind)
{
DBG_ASSERT(eTextKind==OBJ_TEXT ||
eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT,
"SdrRectObj::SdrRectObj(SdrObjKind) can only be applied to text frames.");
bClosedObj=true;
}
SdrRectObj::SdrRectObj(
SdrModel& rSdrModel,
SdrObjKind eNewTextKind,
const tools::Rectangle& rRect)
: SdrTextObj(rSdrModel, eNewTextKind, rRect)
{
DBG_ASSERT(eTextKind==OBJ_TEXT ||
eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT,
"SdrRectObj::SdrRectObj(SdrObjKind,...) can only be applied to text frames.");
bClosedObj=true;
}
SdrRectObj::~SdrRectObj()
{
}
void SdrRectObj::SetXPolyDirty()
{
mpXPoly.reset();
}
XPolygon SdrRectObj::ImpCalcXPoly(const tools::Rectangle& rRect1, long nRad1) const
{
XPolygon aXPoly(rRect1,nRad1,nRad1);
const sal_uInt16 nPointCnt(aXPoly.GetPointCount());
XPolygon aNewPoly(nPointCnt+1);
sal_uInt16 nShift=nPointCnt-2;
if (nRad1!=0) nShift=nPointCnt-5;
sal_uInt16 j=nShift;
for (sal_uInt16 i=1; i<nPointCnt; i++) {
aNewPoly[i]=aXPoly[j];
aNewPoly.SetFlags(i,aXPoly.GetFlags(j));
j++;
if (j>=nPointCnt) j=1;
}
aNewPoly[0]=rRect1.BottomCenter();
aNewPoly[nPointCnt]=aNewPoly[0];
aXPoly=aNewPoly;
// these angles always relate to the top left corner of aRect
if (aGeo.nShearAngle!=0) ShearXPoly(aXPoly,maRect.TopLeft(),aGeo.nTan);
if (aGeo.nRotationAngle!=0) RotateXPoly(aXPoly,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
return aXPoly;
}
void SdrRectObj::RecalcXPoly()
{
mpXPoly.reset( new XPolygon(ImpCalcXPoly(maRect,GetEckenradius())) );
}
const XPolygon& SdrRectObj::GetXPoly() const
{
if(!mpXPoly)
{
const_cast<SdrRectObj*>(this)->RecalcXPoly();
}
return *mpXPoly;
}
void SdrRectObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
{
bool bNoTextFrame=!IsTextFrame();
rInfo.bResizeFreeAllowed=bNoTextFrame || aGeo.nRotationAngle%9000==0;
rInfo.bResizePropAllowed=true;
rInfo.bRotateFreeAllowed=true;
rInfo.bRotate90Allowed =true;
rInfo.bMirrorFreeAllowed=bNoTextFrame;
rInfo.bMirror45Allowed =bNoTextFrame;
rInfo.bMirror90Allowed =bNoTextFrame;
// allow transparency
rInfo.bTransparenceAllowed = true;
rInfo.bShearAllowed =bNoTextFrame;
rInfo.bEdgeRadiusAllowed=true;
bool bCanConv=!HasText() || ImpCanConvTextToCurve();
if (bCanConv && !bNoTextFrame && !HasText()) {
bCanConv=HasFill() || HasLine();
}
rInfo.bCanConvToPath =bCanConv;
rInfo.bCanConvToPoly =bCanConv;
rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary());
}
sal_uInt16 SdrRectObj::GetObjIdentifier() const
{
if (IsTextFrame()) return sal_uInt16(eTextKind);
else return sal_uInt16(OBJ_RECT);
}
void SdrRectObj::TakeUnrotatedSnapRect(tools::Rectangle& rRect) const
{
rRect = maRect;
if (aGeo.nShearAngle!=0)
{
long nDst=FRound((maRect.Bottom()-maRect.Top())*aGeo.nTan);
if (aGeo.nShearAngle>0)
{
Point aRef(rRect.TopLeft());
rRect.AdjustLeft( -nDst );
Point aTmpPt(rRect.TopLeft());
RotatePoint(aTmpPt,aRef,aGeo.nSin,aGeo.nCos);
aTmpPt-=rRect.TopLeft();
rRect.Move(aTmpPt.X(),aTmpPt.Y());
}
else
{
rRect.AdjustRight( -nDst );
}
}
}
OUString SdrRectObj::TakeObjNameSingul() const
{
if (IsTextFrame())
{
return SdrTextObj::TakeObjNameSingul();
}
OUStringBuffer sName;
bool bRounded = GetEckenradius() != 0; // rounded down
const char* pResId = bRounded ? STR_ObjNameSingulRECTRND : STR_ObjNameSingulRECT;
if (aGeo.nShearAngle!=0)
{
pResId = bRounded ? STR_ObjNameSingulPARALRND : STR_ObjNameSingulPARAL; // parallelogram or, maybe, rhombus
}
else if (maRect.GetWidth() == maRect.GetHeight())
{
pResId = bRounded ? STR_ObjNameSingulQUADRND : STR_ObjNameSingulQUAD; // square
}
sName.append(SvxResId(pResId));
OUString aName(GetName());
if (!aName.isEmpty())
{
sName.append(' ');
sName.append('\'');
sName.append(aName);
sName.append('\'');
}
return sName.makeStringAndClear();
}
OUString SdrRectObj::TakeObjNamePlural() const
{
if (IsTextFrame())
{
return SdrTextObj::TakeObjNamePlural();
}
bool bRounded = GetEckenradius() != 0; // rounded down
const char* pResId = bRounded ? STR_ObjNamePluralRECTRND : STR_ObjNamePluralRECT;
if (aGeo.nShearAngle!=0)
{
pResId = bRounded ? STR_ObjNamePluralPARALRND : STR_ObjNamePluralPARAL; // parallelogram or rhombus
}
else if (maRect.GetWidth() == maRect.GetHeight())
{
pResId = bRounded ? STR_ObjNamePluralQUADRND : STR_ObjNamePluralQUAD; // square
}
return SvxResId(pResId);
}
SdrRectObj* SdrRectObj::CloneSdrObject(SdrModel& rTargetModel) const
{
return CloneHelper< SdrRectObj >(rTargetModel);
}
SdrRectObj& SdrRectObj::operator=(const SdrRectObj& rCopy)
{
if ( this == &rCopy )
return *this;
SdrTextObj::operator=( rCopy );
if ( rCopy.mpXPoly )
mpXPoly.reset( new XPolygon( *rCopy.mpXPoly ) );
else
mpXPoly.reset();
return *this;
}
basegfx::B2DPolyPolygon SdrRectObj::TakeXorPoly() const
{
XPolyPolygon aXPP;
aXPP.Insert(ImpCalcXPoly(maRect,GetEckenradius()));
return aXPP.getB2DPolyPolygon();
}
void SdrRectObj::RecalcSnapRect()
{
long nEckRad=GetEckenradius();
if ((aGeo.nRotationAngle!=0 || aGeo.nShearAngle!=0) && nEckRad!=0) {
maSnapRect=GetXPoly().GetBoundRect();
} else {
SdrTextObj::RecalcSnapRect();
}
}
void SdrRectObj::NbcSetSnapRect(const tools::Rectangle& rRect)
{
SdrTextObj::NbcSetSnapRect(rRect);
SetXPolyDirty();
}
void SdrRectObj::NbcSetLogicRect(const tools::Rectangle& rRect)
{
SdrTextObj::NbcSetLogicRect(rRect);
SetXPolyDirty();
}
sal_uInt32 SdrRectObj::GetHdlCount() const
{
return IsTextFrame() ? 10 : 9;
}
void SdrRectObj::AddToHdlList(SdrHdlList& rHdlList) const
{
// A text box has an additional (pseudo-)handle for the blinking frame.
if(IsTextFrame())
{
OSL_ENSURE(!IsTextEditActive(), "Do not use an ImpTextframeHdl for highlighting text in active text edit, this will collide with EditEngine paints (!)");
std::unique_ptr<SdrHdl> pH(new ImpTextframeHdl(maRect));
pH->SetObj(const_cast<SdrRectObj*>(this));
pH->SetRotationAngle(aGeo.nRotationAngle);
rHdlList.AddHdl(std::move(pH));
}
for(sal_Int32 nHdlNum = 1; nHdlNum <= 9; ++nHdlNum)
{
Point aPnt;
SdrHdlKind eKind = SdrHdlKind::Move;
switch(nHdlNum)
{
case 1: // Handle for changing the corner radius
{
long a = GetEckenradius();
long b = std::max(maRect.GetWidth(),maRect.GetHeight())/2; // rounded up, because GetWidth() adds 1
if (a>b) a=b;
if (a<0) a=0;
aPnt=maRect.TopLeft();
aPnt.AdjustX(a );
eKind = SdrHdlKind::Circle;
break;
}
case 2: aPnt=maRect.TopLeft(); eKind = SdrHdlKind::UpperLeft; break;
case 3: aPnt=maRect.TopCenter(); eKind = SdrHdlKind::Upper; break;
case 4: aPnt=maRect.TopRight(); eKind = SdrHdlKind::UpperRight; break;
case 5: aPnt=maRect.LeftCenter(); eKind = SdrHdlKind::Left ; break;
case 6: aPnt=maRect.RightCenter(); eKind = SdrHdlKind::Right; break;
case 7: aPnt=maRect.BottomLeft(); eKind = SdrHdlKind::LowerLeft; break;
case 8: aPnt=maRect.BottomCenter(); eKind = SdrHdlKind::Lower; break;
case 9: aPnt=maRect.BottomRight(); eKind = SdrHdlKind::LowerRight; break;
}
if(aGeo.nShearAngle)
{
ShearPoint(aPnt,maRect.TopLeft(),aGeo.nTan);
}
if(aGeo.nRotationAngle)
{
RotatePoint(aPnt,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
}
std::unique_ptr<SdrHdl> pH(new SdrHdl(aPnt,eKind));
pH->SetObj(const_cast<SdrRectObj*>(this));
pH->SetRotationAngle(aGeo.nRotationAngle);
rHdlList.AddHdl(std::move(pH));
}
}
bool SdrRectObj::hasSpecialDrag() const
{
return true;
}
bool SdrRectObj::beginSpecialDrag(SdrDragStat& rDrag) const
{
const bool bRad(rDrag.GetHdl() && SdrHdlKind::Circle == rDrag.GetHdl()->GetKind());
if(bRad)
{
rDrag.SetEndDragChangesAttributes(true);
return true;
}
return SdrTextObj::beginSpecialDrag(rDrag);
}
bool SdrRectObj::applySpecialDrag(SdrDragStat& rDrag)
{
const bool bRad(rDrag.GetHdl() && SdrHdlKind::Circle == rDrag.GetHdl()->GetKind());
if (bRad)
{
Point aPt(rDrag.GetNow());
if(aGeo.nRotationAngle)
RotatePoint(aPt,maRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
sal_Int32 nRad(aPt.X() - maRect.Left());
if (nRad < 0)
nRad = 0;
if(nRad != GetEckenradius())
{
NbcSetEckenradius(nRad);
}
return true;
}
else
{
return SdrTextObj::applySpecialDrag(rDrag);
}
}
OUString SdrRectObj::getSpecialDragComment(const SdrDragStat& rDrag) const
{
const bool bCreateComment(rDrag.GetView() && this == rDrag.GetView()->GetCreateObj());
if(bCreateComment)
{
return OUString();
}
else
{
const bool bRad(rDrag.GetHdl() && SdrHdlKind::Circle == rDrag.GetHdl()->GetKind());
if(bRad)
{
Point aPt(rDrag.GetNow());
// -sin for reversal
if(aGeo.nRotationAngle)
RotatePoint(aPt, maRect.TopLeft(), -aGeo.nSin, aGeo.nCos);
sal_Int32 nRad(aPt.X() - maRect.Left());
if(nRad < 0)
nRad = 0;
OUStringBuffer aBuf(ImpGetDescriptionStr(STR_DragRectEckRad));
aBuf.append(" (");
aBuf.append(GetMetrStr(nRad));
aBuf.append(')');
return aBuf.makeStringAndClear();
}
else
{
return SdrTextObj::getSpecialDragComment(rDrag);
}
}
}
basegfx::B2DPolyPolygon SdrRectObj::TakeCreatePoly(const SdrDragStat& rDrag) const
{
tools::Rectangle aRect1;
rDrag.TakeCreateRect(aRect1);
aRect1.Justify();
basegfx::B2DPolyPolygon aRetval;
aRetval.append(ImpCalcXPoly(aRect1,GetEckenradius()).getB2DPolygon());
return aRetval;
}
PointerStyle SdrRectObj::GetCreatePointer() const
{
if (IsTextFrame()) return PointerStyle::DrawText;
return PointerStyle::DrawRect;
}
void SdrRectObj::NbcMove(const Size& rSiz)
{
SdrTextObj::NbcMove(rSiz);
SetXPolyDirty();
}
void SdrRectObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
SdrTextObj::NbcResize(rRef,xFact,yFact);
SetXPolyDirty();
}
void SdrRectObj::NbcRotate(const Point& rRef, long nAngle, double sn, double cs)
{
SdrTextObj::NbcRotate(rRef,nAngle,sn,cs);
SetXPolyDirty();
}
void SdrRectObj::NbcShear(const Point& rRef, long nAngle, double tn, bool bVShear)
{
SdrTextObj::NbcShear(rRef,nAngle,tn,bVShear);
SetXPolyDirty();
}
void SdrRectObj::NbcMirror(const Point& rRef1, const Point& rRef2)
{
SdrTextObj::NbcMirror(rRef1,rRef2);
SetXPolyDirty();
}
SdrGluePoint SdrRectObj::GetVertexGluePoint(sal_uInt16 nPosNum) const
{
sal_Int32 nWdt = ImpGetLineWdt(); // #i25616#
// #i25616#
if(!LineIsOutsideGeometry())
{
nWdt++;
nWdt /= 2;
}
Point aPt;
switch (nPosNum) {
case 0: aPt=maRect.TopCenter(); aPt.AdjustY( -nWdt ); break;
case 1: aPt=maRect.RightCenter(); aPt.AdjustX(nWdt ); break;
case 2: aPt=maRect.BottomCenter(); aPt.AdjustY(nWdt ); break;
case 3: aPt=maRect.LeftCenter(); aPt.AdjustX( -nWdt ); break;
}
if (aGeo.nShearAngle!=0) ShearPoint(aPt,maRect.TopLeft(),aGeo.nTan);
if (aGeo.nRotationAngle!=0) RotatePoint(aPt,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
aPt-=GetSnapRect().Center();
SdrGluePoint aGP(aPt);
aGP.SetPercent(false);
return aGP;
}
SdrGluePoint SdrRectObj::GetCornerGluePoint(sal_uInt16 nPosNum) const
{
sal_Int32 nWdt = ImpGetLineWdt(); // #i25616#
// #i25616#
if(!LineIsOutsideGeometry())
{
nWdt++;
nWdt /= 2;
}
Point aPt;
switch (nPosNum) {
case 0: aPt=maRect.TopLeft(); aPt.AdjustX( -nWdt ); aPt.AdjustY( -nWdt ); break;
case 1: aPt=maRect.TopRight(); aPt.AdjustX(nWdt ); aPt.AdjustY( -nWdt ); break;
case 2: aPt=maRect.BottomRight(); aPt.AdjustX(nWdt ); aPt.AdjustY(nWdt ); break;
case 3: aPt=maRect.BottomLeft(); aPt.AdjustX( -nWdt ); aPt.AdjustY(nWdt ); break;
}
if (aGeo.nShearAngle!=0) ShearPoint(aPt,maRect.TopLeft(),aGeo.nTan);
if (aGeo.nRotationAngle!=0) RotatePoint(aPt,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
aPt-=GetSnapRect().Center();
SdrGluePoint aGP(aPt);
aGP.SetPercent(false);
return aGP;
}
SdrObjectUniquePtr SdrRectObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
{
XPolygon aXP(ImpCalcXPoly(maRect,GetEckenradius()));
{ // TODO: this is only for the moment, until we have the new TakeContour()
aXP.Remove(0,1);
aXP[aXP.GetPointCount()-1]=aXP[0];
}
basegfx::B2DPolyPolygon aPolyPolygon(aXP.getB2DPolygon());
aPolyPolygon.removeDoublePoints();
SdrObjectUniquePtr pRet;
// small correction: Do not create something when no fill and no line. To
// be sure to not damage something with non-text frames, do this only
// when used with bAddText==false from other converters
if((bAddText && !IsTextFrame()) || HasFill() || HasLine())
{
pRet = ImpConvertMakeObj(aPolyPolygon, true, bBezier);
}
if(bAddText)
{
pRet = ImpConvertAddText(std::move(pRet), bBezier);
}
return pRet;
}
void SdrRectObj::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
SdrTextObj::Notify(rBC,rHint);
SetXPolyDirty(); // because of the corner radius
}
void SdrRectObj::RestGeoData(const SdrObjGeoData& rGeo)
{
SdrTextObj::RestGeoData(rGeo);
SetXPolyDirty();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|