1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <svx/uiobject.hxx>
12 #include <svx/svdobj.hxx>
14 #include <tools/fract.hxx>
16 SdrUIObject::~SdrUIObject()
20 StringMap
SdrUIObject::get_state()
23 SdrObject
* pObject
= get_object();
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());
51 void SdrUIObject::execute(const OUString
& rAction
,
52 const StringMap
& rParameters
)
54 SdrObject
* pObj
= get_object();
58 if (rAction
== "MOVE")
60 auto itrNX
= rParameters
.find("X");
61 if (itrNX
== rParameters
.end())
62 throw css::uno::RuntimeException("missing parameter X");
64 auto itrNY
= rParameters
.find("Y");
65 if (itrNY
== rParameters
.end())
66 throw css::uno::RuntimeException("missing parameter Y");
68 long nX
= itrNX
->second
.toInt32();
69 long nY
= itrNY
->second
.toInt32();
70 Size
aMoveRange(nX
, nY
);
71 pObj
->Move(aMoveRange
);
73 else if (rAction
== "RESIZE")
75 auto itrNX
= rParameters
.find("X");
76 if (itrNX
== rParameters
.end())
77 throw css::uno::RuntimeException("missing parameter X");
79 auto itrNY
= rParameters
.find("Y");
80 if (itrNY
== rParameters
.end())
81 throw css::uno::RuntimeException("missing parameter Y");
83 long nX
= itrNX
->second
.toInt32();
84 long nY
= itrNY
->second
.toInt32();
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
);
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*/);
100 else if (rAction
== "CROP")
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");
108 auto itrNY
= rParameters
.find("Y");
109 if (itrNY
== rParameters
.end())
110 throw css::uno::RuntimeException("missing parameter Y");
112 const double fX(itrNX
->second
.toDouble());
113 const double fY(itrNY
->second
.toDouble());
114 const basegfx::B2DPoint
aPos(fX
, fY
);
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());
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());
126 pObj
->Crop(aPos
, fFracX
, fFracY
);
128 else if (rAction
== "ROTATE")
130 auto itrNX
= rParameters
.find("X");
131 if (itrNX
== rParameters
.end())
132 throw css::uno::RuntimeException("missing parameter X");
134 auto itrNY
= rParameters
.find("Y");
135 if (itrNY
== rParameters
.end())
136 throw css::uno::RuntimeException("missing parameter Y");
138 long nX
= itrNX
->second
.toInt32();
139 long nY
= itrNY
->second
.toInt32();
142 auto itrAngle
= rParameters
.find("ANGLE");
143 if (itrAngle
== rParameters
.end())
144 throw css::uno::RuntimeException("missing parameter ANGLE");
146 double nAngle
= itrAngle
->second
.toDouble();
147 pObj
->Rotate(aPos
, nAngle
, 0, 0);
149 else if (rAction
== "Mirror")
151 pObj
->Mirror(Point(), Point());
153 else if (rAction
== "SHEAR")
155 pObj
->Shear(Point(), 0.0/*nAngle*/, 0, false);
159 OUString
SdrUIObject::get_type() const
161 return "SdrUIObject";
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */