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