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 
16 #include <memory>
17 #include <svx/SvxColorValueSet.hxx>
18 #include <vcl/layout.hxx>
19 
21 {
22 }
23 
25 {
28 
29  if (!pObject)
30  return aMap;
31 
32  aMap["Name"] = pObject->GetName();
33  aMap["Description"] = pObject->GetDescription();
34  aMap["Title"] = pObject->GetTitle();
35  aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
36  aMap["Layer"] = OUString::number(sal_uInt8(pObject->GetLayer()));
37  aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
38  aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
39  aMap["PointCount"] = OUString::number(pObject->GetPointCount());
40  aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
41  aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
42  aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
43  aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
44  aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
45  aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
46  aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
47  aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
48  aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
49  aMap["Visible"] = OUString::boolean(pObject->IsVisible());
50  aMap["HasText"] = OUString::boolean(pObject->HasText());
51 
52  return aMap;
53 }
54 
55 void SdrUIObject::execute(const OUString& rAction,
56  const StringMap& rParameters)
57 {
58  SdrObject* pObj = get_object();
59  if (!pObj)
60  return;
61 
62  if (rAction == "MOVE")
63  {
64  auto itrNX = rParameters.find("X");
65  if (itrNX == rParameters.end())
66  throw css::uno::RuntimeException("missing parameter X");
67 
68  auto itrNY = rParameters.find("Y");
69  if (itrNY == rParameters.end())
70  throw css::uno::RuntimeException("missing parameter Y");
71 
72  long nX = itrNX->second.toInt32();
73  long nY = itrNY->second.toInt32();
74  Size aMoveRange(nX, nY);
75  pObj->Move(aMoveRange);
76  }
77  else if (rAction == "RESIZE")
78  {
79  auto itrNX = rParameters.find("X");
80  if (itrNX == rParameters.end())
81  throw css::uno::RuntimeException("missing parameter X");
82 
83  auto itrNY = rParameters.find("Y");
84  if (itrNY == rParameters.end())
85  throw css::uno::RuntimeException("missing parameter Y");
86 
87  long nX = itrNX->second.toInt32();
88  long nY = itrNY->second.toInt32();
89  Point aPos(nX, nY);
90 
91  auto itrFracX = rParameters.find("FRAC_X");
92  if (itrFracX == rParameters.end())
93  throw css::uno::RuntimeException("missing parameter FRAC_X");
94  double nFracX = itrFracX->second.toDouble();
95  Fraction aFracX(nFracX);
96 
97  auto itrFracY = rParameters.find("FRAC_Y");
98  if (itrFracY == rParameters.end())
99  throw css::uno::RuntimeException("missing parameter FRAC_Y");
100  double nFracY = itrFracY->second.toDouble();
101  Fraction aFracY(nFracY);
102  pObj->Resize(aPos, aFracX, aFracY, true/*bRelative*/);
103  }
104  else if (rAction == "CROP")
105  {
106  // RotateFlyFrame3: Note: Crop does nothing at SdrObject
107  // anymore, see comment at SdrObject::NbcCrop
108  auto itrNX = rParameters.find("X");
109  if (itrNX == rParameters.end())
110  throw css::uno::RuntimeException("missing parameter X");
111 
112  auto itrNY = rParameters.find("Y");
113  if (itrNY == rParameters.end())
114  throw css::uno::RuntimeException("missing parameter Y");
115 
116  const double fX(itrNX->second.toDouble());
117  const double fY(itrNY->second.toDouble());
118  const basegfx::B2DPoint aPos(fX, fY);
119 
120  auto itrFracX = rParameters.find("FRAC_X");
121  if (itrFracX == rParameters.end())
122  throw css::uno::RuntimeException("missing parameter FRAC_X");
123  const double fFracX(itrFracX->second.toDouble());
124 
125  auto itrFracY = rParameters.find("FRAC_Y");
126  if (itrFracY == rParameters.end())
127  throw css::uno::RuntimeException("missing parameter FRAC_Y");
128  const double fFracY(itrFracY->second.toDouble());
129 
130  pObj->Crop(aPos, fFracX, fFracY);
131  }
132  else if (rAction == "ROTATE")
133  {
134  auto itrNX = rParameters.find("X");
135  if (itrNX == rParameters.end())
136  throw css::uno::RuntimeException("missing parameter X");
137 
138  auto itrNY = rParameters.find("Y");
139  if (itrNY == rParameters.end())
140  throw css::uno::RuntimeException("missing parameter Y");
141 
142  long nX = itrNX->second.toInt32();
143  long nY = itrNY->second.toInt32();
144  Point aPos(nX, nY);
145 
146  auto itrAngle = rParameters.find("ANGLE");
147  if (itrAngle == rParameters.end())
148  throw css::uno::RuntimeException("missing parameter ANGLE");
149 
150  double nAngle = itrAngle->second.toDouble();
151  pObj->Rotate(aPos, nAngle, 0, 0);
152  }
153  else if (rAction == "Mirror")
154  {
155  pObj->Mirror(Point(), Point());
156  }
157  else if (rAction == "SHEAR")
158  {
159  pObj->Shear(Point(), 0.0/*nAngle*/, 0, false);
160  }
161 }
162 
163 OUString SdrUIObject::get_type() const
164 {
165  return "SdrUIObject";
166 }
167 
168 
170  WindowUIObject(xColorSetWin),
171  mpColorSet(pColorSet)
172 {
173 }
174 
175 void SvxColorValueSetUIObject::execute(const OUString& rAction,
176  const StringMap& rParameters)
177 {
178  if (rAction == "CHOOSE")
179  {
180  if (rParameters.find("POS") != rParameters.end())
181  {
182  OUString aIndexStr = rParameters.find("POS")->second;
183  sal_Int32 nIndex = aIndexStr.toInt32();
184  mpColorSet->SelectItem(nIndex);
185  mpColorSet->Select();
186  }
187  }
188  else
189  WindowUIObject::execute(rAction, rParameters);
190 }
191 
192 std::unique_ptr<UIObject> SvxColorValueSetUIObject::create(vcl::Window* pWindow)
193 {
194  VclDrawingArea* pColorSetWin = dynamic_cast<VclDrawingArea*>(pWindow);
195  assert(pColorSetWin);
196  return std::unique_ptr<UIObject>(new SvxColorValueSetUIObject(pColorSetWin, static_cast<SvxColorValueSet*>(pColorSetWin->GetUserData())));
197 }
198 
200 {
201  return "SvxColorValueSetUIObject";
202 }
203 
205 {
207  aMap["CurrColorId"] = OUString::number( mpColorSet->GetSelectedItemId() );
208  aMap["CurrColorPos"] = OUString::number( mpColorSet->GetSelectItemPos() );
209  aMap["ColorsCount"] = OUString::number(mpColorSet->GetItemCount());
210  aMap["ColCount"] = OUString::number(mpColorSet->GetColCount());
211  aMap["ColorText"] = mpColorSet->GetItemText(mpColorSet->GetSelectedItemId());
213  aMap["R"] = OUString::number(currColor.GetRed());
214  aMap["G"] = OUString::number(currColor.GetGreen());
215  aMap["B"] = OUString::number(currColor.GetBlue());
216  aMap["RGB"] = "("+OUString::number(currColor.GetRed())+","+OUString::number(currColor.GetGreen())+","+OUString::number(currColor.GetBlue())+")";
217  return aMap;
218 }
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool HasTextEdit() const
Definition: svdobj.cxx:1688
sal_uInt16 GetColCount() const
sal_Int32 nIndex
virtual StringMap get_state() override
Definition: sdrobject.cxx:24
bool IsClosedObj() const
Definition: svdobj.hxx:788
sal_uInt8 GetRed() const
virtual void Resize(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bUnsetRelative=true)
Definition: svdobj.cxx:1484
SvxColorValueSetUIObject(vcl::Window *xColorSetWin, SvxColorValueSet *pColorSet)
Definition: sdrobject.cxx:169
virtual bool IsPolyObj() const
Definition: svdobj.cxx:1660
bool IsEdgeObj() const
Definition: svdobj.hxx:795
OUString GetDescription() const
Definition: svdobj.cxx:786
virtual OUString get_type() const override
Definition: sdrobject.cxx:163
virtual bool HasText() const
Definition: svdobj.cxx:2989
void * GetUserData() const
sal_uInt16 GetSelectedItemId() const
virtual sal_uInt32 GetPointCount() const
Definition: svdobj.cxx:1665
EmbeddedObjectRef * pObject
virtual void Rotate(const Point &rRef, long nAngle, double sn, double cs)
Definition: svdobj.cxx:1511
bool IsVisible() const
Definition: svdobj.hxx:805
HashMap_OWString_Interface aMap
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
virtual StringMap get_state() override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual void Crop(const basegfx::B2DPoint &rRef, double fxFact, double fyFact)
Definition: svdobj.cxx:1502
OUString get_name() const override
Definition: sdrobject.cxx:199
sal_uInt8 GetBlue() const
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: sdrobject.cxx:175
bool IsPrintable() const
Definition: svdobj.hxx:803
OUString GetTitle() const
Definition: svdobj.cxx:742
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:796
virtual bool HasMacro() const
Definition: svdobj.cxx:1762
bool IsGroupObject() const
Definition: svdobj.cxx:642
OUString GetItemText(sal_uInt16 nItemId) const
virtual void Move(const Size &rSiz)
Definition: svdobj.cxx:1467
bool IsResizeProtect() const
Definition: svdobj.hxx:801
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrObject * get_object()=0
virtual void Mirror(const Point &rRef1, const Point &rRef2)
Definition: svdobj.cxx:1522
OUString GetName() const
Definition: svdobj.cxx:698
size_t GetSelectItemPos() const
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:577
void SelectItem(sal_uInt16 nItemId)
sal_uInt8 GetGreen() const
bool IsUnoObj() const
Definition: svdobj.hxx:797
size_t GetItemCount() const
virtual StringMap get_state() override
Definition: sdrobject.cxx:204
unsigned char sal_uInt8
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: sdrobject.cxx:55
virtual void Select()
virtual void Shear(const Point &rRef, long nAngle, double tn, bool bVShear)
Definition: svdobj.cxx:1531
virtual ~SdrUIObject() override
Definition: sdrobject.cxx:20
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: sdrobject.cxx:192
bool Is3DObj() const
Definition: svdobj.hxx:796
Color GetItemColor(sal_uInt16 nItemId) const
bool IsMoveProtect() const
Definition: svdobj.hxx:799