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>
11 #include <svx/svdobj.hxx>
12 #include <svx/SvxColorValueSet.hxx>
13 #include <tools/fract.hxx>
14 #include <vcl/window.hxx>
17 SdrUIObject::~SdrUIObject() {}
19 StringMap
SdrUIObject::get_state()
22 SdrObject
* pObject
= get_object();
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());
50 void SdrUIObject::execute(const OUString
& rAction
, const StringMap
& rParameters
)
52 SdrObject
* pObj
= get_object();
56 if (rAction
== "MOVE")
58 auto itrNX
= rParameters
.find("X");
59 if (itrNX
== rParameters
.end())
60 throw css::uno::RuntimeException("missing parameter X");
62 auto itrNY
= rParameters
.find("Y");
63 if (itrNY
== rParameters
.end())
64 throw css::uno::RuntimeException("missing parameter Y");
66 tools::Long nX
= itrNX
->second
.toInt32();
67 tools::Long nY
= itrNY
->second
.toInt32();
68 Size
aMoveRange(nX
, nY
);
69 pObj
->Move(aMoveRange
);
71 else if (rAction
== "RESIZE")
73 auto itrNX
= rParameters
.find("X");
74 if (itrNX
== rParameters
.end())
75 throw css::uno::RuntimeException("missing parameter X");
77 auto itrNY
= rParameters
.find("Y");
78 if (itrNY
== rParameters
.end())
79 throw css::uno::RuntimeException("missing parameter Y");
81 tools::Long nX
= itrNX
->second
.toInt32();
82 tools::Long nY
= itrNY
->second
.toInt32();
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
);
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*/);
98 else if (rAction
== "CROP")
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");
106 auto itrNY
= rParameters
.find("Y");
107 if (itrNY
== rParameters
.end())
108 throw css::uno::RuntimeException("missing parameter Y");
110 const double fX(itrNX
->second
.toDouble());
111 const double fY(itrNY
->second
.toDouble());
112 const basegfx::B2DPoint
aPos(fX
, fY
);
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());
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());
124 pObj
->Crop(aPos
, fFracX
, fFracY
);
126 else if (rAction
== "ROTATE")
128 auto itrNX
= rParameters
.find("X");
129 if (itrNX
== rParameters
.end())
130 throw css::uno::RuntimeException("missing parameter X");
132 auto itrNY
= rParameters
.find("Y");
133 if (itrNY
== rParameters
.end())
134 throw css::uno::RuntimeException("missing parameter Y");
136 tools::Long nX
= itrNX
->second
.toInt32();
137 tools::Long nY
= itrNY
->second
.toInt32();
140 auto itrAngle
= rParameters
.find("ANGLE");
141 if (itrAngle
== rParameters
.end())
142 throw css::uno::RuntimeException("missing parameter ANGLE");
144 double nAngle
= itrAngle
->second
.toDouble();
145 pObj
->Rotate(aPos
, Degree100(sal_Int32(nAngle
)), 0, 0);
147 else if (rAction
== "Mirror")
149 pObj
->Mirror(Point(), Point());
151 else if (rAction
== "SHEAR")
153 pObj
->Shear(Point(), 0_deg100
/*nAngle*/, 0, false);
157 OUString
SdrUIObject::get_type() const { return "SdrUIObject"; }
159 SvxColorValueSetUIObject::SvxColorValueSetUIObject(vcl::Window
* pColorSetWin
)
160 : DrawingAreaUIObject(pColorSetWin
)
161 , mpColorSet(static_cast<SvxColorValueSet
*>(mpController
))
165 void SvxColorValueSetUIObject::execute(const OUString
& rAction
, const StringMap
& rParameters
)
167 if (rAction
== "CHOOSE")
169 if (rParameters
.find("POS") != rParameters
.end())
171 OUString aIndexStr
= rParameters
.find("POS")->second
;
172 sal_Int32 nIndex
= aIndexStr
.toInt32();
173 mpColorSet
->SelectItem(nIndex
);
174 mpColorSet
->Select();
178 DrawingAreaUIObject::execute(rAction
, rParameters
);
181 std::unique_ptr
<UIObject
> SvxColorValueSetUIObject::create(vcl::Window
* pWindow
)
183 return std::unique_ptr
<UIObject
>(new SvxColorValueSetUIObject(pWindow
));
186 OUString
SvxColorValueSetUIObject::get_name() const { return "SvxColorValueSetUIObject"; }
188 StringMap
SvxColorValueSetUIObject::get_state()
190 StringMap aMap
= DrawingAreaUIObject::get_state();
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());
196 Color currColor
= mpColorSet
->GetItemColor(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()) + ")";
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */