LibreOffice Module svx (master)  1
sdrobject.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <svx/uiobject.hxx>
11 
12 #include <svx/svdobj.hxx>
13 
14 #include <tools/fract.hxx>
15 
17 {
18 }
19 
21 {
24 
25  if (!pObject)
26  return aMap;
27 
28  aMap["Name"] = pObject->GetName();
29  aMap["Description"] = pObject->GetDescription();
30  aMap["Title"] = pObject->GetTitle();
31  aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
32  aMap["Layer"] = OUString::number(sal_uInt8(pObject->GetLayer()));
33  aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
34  aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
35  aMap["PointCount"] = OUString::number(pObject->GetPointCount());
36  aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
37  aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
38  aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
39  aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
40  aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
41  aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
42  aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
43  aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
44  aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
45  aMap["Visible"] = OUString::boolean(pObject->IsVisible());
46  aMap["HasText"] = OUString::boolean(pObject->HasText());
47 
48  return aMap;
49 }
50 
51 void SdrUIObject::execute(const OUString& rAction,
52  const StringMap& rParameters)
53 {
54  SdrObject* pObj = get_object();
55  if (!pObj)
56  return;
57 
58  if (rAction == "MOVE")
59  {
60  auto itrNX = rParameters.find("X");
61  if (itrNX == rParameters.end())
62  throw css::uno::RuntimeException("missing parameter X");
63 
64  auto itrNY = rParameters.find("Y");
65  if (itrNY == rParameters.end())
66  throw css::uno::RuntimeException("missing parameter Y");
67 
68  long nX = itrNX->second.toInt32();
69  long nY = itrNY->second.toInt32();
70  Size aMoveRange(nX, nY);
71  pObj->Move(aMoveRange);
72  }
73  else if (rAction == "RESIZE")
74  {
75  auto itrNX = rParameters.find("X");
76  if (itrNX == rParameters.end())
77  throw css::uno::RuntimeException("missing parameter X");
78 
79  auto itrNY = rParameters.find("Y");
80  if (itrNY == rParameters.end())
81  throw css::uno::RuntimeException("missing parameter Y");
82 
83  long nX = itrNX->second.toInt32();
84  long nY = itrNY->second.toInt32();
85  Point aPos(nX, nY);
86 
87  auto itrFracX = rParameters.find("FRAC_X");
88  if (itrFracX == rParameters.end())
89  throw css::uno::RuntimeException("missing parameter FRAC_X");
90  double nFracX = itrFracX->second.toDouble();
91  Fraction aFracX(nFracX);
92 
93  auto itrFracY = rParameters.find("FRAC_Y");
94  if (itrFracY == rParameters.end())
95  throw css::uno::RuntimeException("missing parameter FRAC_Y");
96  double nFracY = itrFracY->second.toDouble();
97  Fraction aFracY(nFracY);
98  pObj->Resize(aPos, aFracX, aFracY, true/*bRelative*/);
99  }
100  else if (rAction == "CROP")
101  {
102  // RotateFlyFrame3: Note: Crop does nothing at SdrObject
103  // anymore, see comment at SdrObject::NbcCrop
104  auto itrNX = rParameters.find("X");
105  if (itrNX == rParameters.end())
106  throw css::uno::RuntimeException("missing parameter X");
107 
108  auto itrNY = rParameters.find("Y");
109  if (itrNY == rParameters.end())
110  throw css::uno::RuntimeException("missing parameter Y");
111 
112  const double fX(itrNX->second.toDouble());
113  const double fY(itrNY->second.toDouble());
114  const basegfx::B2DPoint aPos(fX, fY);
115 
116  auto itrFracX = rParameters.find("FRAC_X");
117  if (itrFracX == rParameters.end())
118  throw css::uno::RuntimeException("missing parameter FRAC_X");
119  const double fFracX(itrFracX->second.toDouble());
120 
121  auto itrFracY = rParameters.find("FRAC_Y");
122  if (itrFracY == rParameters.end())
123  throw css::uno::RuntimeException("missing parameter FRAC_Y");
124  const double fFracY(itrFracY->second.toDouble());
125 
126  pObj->Crop(aPos, fFracX, fFracY);
127  }
128  else if (rAction == "ROTATE")
129  {
130  auto itrNX = rParameters.find("X");
131  if (itrNX == rParameters.end())
132  throw css::uno::RuntimeException("missing parameter X");
133 
134  auto itrNY = rParameters.find("Y");
135  if (itrNY == rParameters.end())
136  throw css::uno::RuntimeException("missing parameter Y");
137 
138  long nX = itrNX->second.toInt32();
139  long nY = itrNY->second.toInt32();
140  Point aPos(nX, nY);
141 
142  auto itrAngle = rParameters.find("ANGLE");
143  if (itrAngle == rParameters.end())
144  throw css::uno::RuntimeException("missing parameter ANGLE");
145 
146  double nAngle = itrAngle->second.toDouble();
147  pObj->Rotate(aPos, nAngle, 0, 0);
148  }
149  else if (rAction == "Mirror")
150  {
151  pObj->Mirror(Point(), Point());
152  }
153  else if (rAction == "SHEAR")
154  {
155  pObj->Shear(Point(), 0.0/*nAngle*/, 0, false);
156  }
157 }
158 
159 OUString SdrUIObject::get_type() const
160 {
161  return "SdrUIObject";
162 }
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool HasTextEdit() const
Definition: svdobj.cxx:1715
virtual StringMap get_state() override
Definition: sdrobject.cxx:20
bool IsClosedObj() const
Definition: svdobj.hxx:787
virtual void Resize(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bUnsetRelative=true)
Definition: svdobj.cxx:1511
virtual bool IsPolyObj() const
Definition: svdobj.cxx:1687
bool IsEdgeObj() const
Definition: svdobj.hxx:794
OUString GetDescription() const
Definition: svdobj.cxx:813
virtual OUString get_type() const override
Definition: sdrobject.cxx:159
virtual bool HasText() const
Definition: svdobj.cxx:3011
virtual sal_uInt32 GetPointCount() const
Definition: svdobj.cxx:1692
EmbeddedObjectRef * pObject
virtual void Rotate(const Point &rRef, long nAngle, double sn, double cs)
Definition: svdobj.cxx:1538
bool IsVisible() const
Definition: svdobj.hxx:804
HashMap_OWString_Interface aMap
virtual void Crop(const basegfx::B2DPoint &rRef, double fxFact, double fyFact)
Definition: svdobj.cxx:1529
bool IsPrintable() const
Definition: svdobj.hxx:802
OUString GetTitle() const
Definition: svdobj.cxx:769
std::map< const OUString, OUString > StringMap
sal_uInt32 GetOrdNum() const
The order number (aka ZOrder, aka z-index) determines whether a SdrObject is located above or below a...
Definition: svdobj.cxx:823
virtual bool HasMacro() const
Definition: svdobj.cxx:1784
bool IsGroupObject() const
Definition: svdobj.cxx:669
virtual void Move(const Size &rSiz)
Definition: svdobj.cxx:1494
bool IsResizeProtect() const
Definition: svdobj.hxx:800
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrObject * get_object()=0
virtual void Mirror(const Point &rRef1, const Point &rRef2)
Definition: svdobj.cxx:1549
OUString GetName() const
Definition: svdobj.cxx:725
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:604
bool IsUnoObj() const
Definition: svdobj.hxx:796
unsigned char sal_uInt8
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: sdrobject.cxx:51
virtual void Shear(const Point &rRef, long nAngle, double tn, bool bVShear)
Definition: svdobj.cxx:1558
virtual ~SdrUIObject() override
Definition: sdrobject.cxx:16
bool Is3DObj() const
Definition: svdobj.hxx:795
bool IsMoveProtect() const
Definition: svdobj.hxx:798