Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / uitest / sdrobject.cxx
blob0892556791d29fe63e5eaad0dac34d427367d7ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <svx/uiobject.hxx>
12 #include <svx/svdobj.hxx>
14 #include <tools/fract.hxx>
16 #include <memory>
17 #include <svx/SvxColorValueSet.hxx>
19 SdrUIObject::~SdrUIObject() {}
21 StringMap SdrUIObject::get_state()
23 StringMap aMap;
24 SdrObject* pObject = get_object();
26 if (!pObject)
27 return aMap;
29 aMap["Name"] = pObject->GetName();
30 aMap["Description"] = pObject->GetDescription();
31 aMap["Title"] = pObject->GetTitle();
32 aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
33 aMap["Layer"] = OUString::number(sal_uInt8(pObject->GetLayer()));
34 aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
35 aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
36 aMap["PointCount"] = OUString::number(pObject->GetPointCount());
37 aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
38 aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
39 aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
40 aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
41 aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
42 aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
43 aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
44 aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
45 aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
46 aMap["Visible"] = OUString::boolean(pObject->IsVisible());
47 aMap["HasText"] = OUString::boolean(pObject->HasText());
49 return aMap;
52 void SdrUIObject::execute(const OUString& rAction, const StringMap& rParameters)
54 SdrObject* pObj = get_object();
55 if (!pObj)
56 return;
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 tools::Long nX = itrNX->second.toInt32();
69 tools::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 tools::Long nX = itrNX->second.toInt32();
84 tools::Long nY = itrNY->second.toInt32();
85 Point aPos(nX, nY);
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 tools::Long nX = itrNX->second.toInt32();
139 tools::Long nY = itrNY->second.toInt32();
140 Point aPos(nX, nY);
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 { return "SdrUIObject"; }
161 SvxColorValueSetUIObject::SvxColorValueSetUIObject(vcl::Window* pColorSetWin)
162 : DrawingAreaUIObject(pColorSetWin)
163 , mpColorSet(static_cast<SvxColorValueSet*>(mpController))
167 void SvxColorValueSetUIObject::execute(const OUString& rAction, const StringMap& rParameters)
169 if (rAction == "CHOOSE")
171 if (rParameters.find("POS") != rParameters.end())
173 OUString aIndexStr = rParameters.find("POS")->second;
174 sal_Int32 nIndex = aIndexStr.toInt32();
175 mpColorSet->SelectItem(nIndex);
176 mpColorSet->Select();
179 else
180 DrawingAreaUIObject::execute(rAction, rParameters);
183 std::unique_ptr<UIObject> SvxColorValueSetUIObject::create(vcl::Window* pWindow)
185 return std::unique_ptr<UIObject>(new SvxColorValueSetUIObject(pWindow));
188 OUString SvxColorValueSetUIObject::get_name() const { return "SvxColorValueSetUIObject"; }
190 StringMap SvxColorValueSetUIObject::get_state()
192 StringMap aMap = DrawingAreaUIObject::get_state();
193 aMap["CurrColorId"] = OUString::number(mpColorSet->GetSelectedItemId());
194 aMap["CurrColorPos"] = OUString::number(mpColorSet->GetSelectItemPos());
195 aMap["ColorsCount"] = OUString::number(mpColorSet->GetItemCount());
196 aMap["ColCount"] = OUString::number(mpColorSet->GetColCount());
197 aMap["ColorText"] = mpColorSet->GetItemText(mpColorSet->GetSelectedItemId());
198 Color currColor = mpColorSet->GetItemColor(mpColorSet->GetSelectedItemId());
199 aMap["R"] = OUString::number(currColor.GetRed());
200 aMap["G"] = OUString::number(currColor.GetGreen());
201 aMap["B"] = OUString::number(currColor.GetBlue());
202 aMap["RGB"] = "(" + OUString::number(currColor.GetRed()) + ","
203 + OUString::number(currColor.GetGreen()) + ","
204 + OUString::number(currColor.GetBlue()) + ")";
205 return aMap;
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */