summaryrefslogtreecommitdiff
path: root/svx/source/uitest/sdrobject.cxx
blob: 7852d6a8bec7c0ce6207f7ef777eee7934a8e7fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <svx/uiobject.hxx>

#include <svx/svdobj.hxx>

#include <tools/fract.hxx>

SdrUIObject::~SdrUIObject()
{
}

StringMap SdrUIObject::get_state()
{
    StringMap aMap;
    SdrObject* pObject = get_object();

    if (!pObject)
        return aMap;

    aMap["Name"] = pObject->GetName();
    aMap["Description"] = pObject->GetDescription();
    aMap["Title"] = pObject->GetTitle();
    aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
    aMap["Layer"] = OUString::number(sal_uInt8(pObject->GetLayer()));
    aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
    aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
    aMap["PointCount"] = OUString::number(pObject->GetPointCount());
    aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
    aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
    aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
    aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
    aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
    aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
    aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
    aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
    aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
    aMap["Visible"] = OUString::boolean(pObject->IsVisible());
    aMap["HasText"] = OUString::boolean(pObject->HasText());

    return aMap;
}

void SdrUIObject::execute(const OUString& rAction,
        const StringMap& rParameters)
{
    SdrObject* pObj = get_object();
    if (!pObj)
        return;

    if (rAction == "MOVE")
    {
        auto itrNX = rParameters.find("X");
        if (itrNX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter X");

        auto itrNY = rParameters.find("Y");
        if (itrNY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter Y");

        long nX = itrNX->second.toInt32();
        long nY = itrNY->second.toInt32();
        Size aMoveRange(nX, nY);
        pObj->Move(aMoveRange);
    }
    else if (rAction == "RESIZE")
    {
        auto itrNX = rParameters.find("X");
        if (itrNX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter X");

        auto itrNY = rParameters.find("Y");
        if (itrNY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter Y");

        long nX = itrNX->second.toInt32();
        long nY = itrNY->second.toInt32();
        Point aPos(nX, nY);

        auto itrFracX = rParameters.find("FRAC_X");
        if (itrFracX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter FRAC_X");
        double nFracX = itrFracX->second.toDouble();
        Fraction aFracX(nFracX);

        auto itrFracY = rParameters.find("FRAC_Y");
        if (itrFracY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter FRAC_Y");
        double nFracY = itrFracY->second.toDouble();
        Fraction aFracY(nFracY);
        bool bRelative = true;
        pObj->Resize(aPos, aFracX, aFracY, bRelative);
    }
    else if (rAction == "CROP")
    {
        auto itrNX = rParameters.find("X");
        if (itrNX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter X");

        auto itrNY = rParameters.find("Y");
        if (itrNY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter Y");

        long nX = itrNX->second.toInt32();
        long nY = itrNY->second.toInt32();
        Point aPos(nX, nY);

        auto itrFracX = rParameters.find("FRAC_X");
        if (itrFracX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter FRAC_X");
        double nFracX = itrFracX->second.toDouble();
        Fraction aFracX(nFracX);

        auto itrFracY = rParameters.find("FRAC_Y");
        if (itrFracY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter FRAC_Y");
        double nFracY = itrFracY->second.toDouble();
        Fraction aFracY(nFracY);

        pObj->Crop(aPos, aFracX, aFracY);
    }
    else if (rAction == "ROTATE")
    {
        auto itrNX = rParameters.find("X");
        if (itrNX == rParameters.end())
            throw css::uno::RuntimeException("missing parameter X");

        auto itrNY = rParameters.find("Y");
        if (itrNY == rParameters.end())
            throw css::uno::RuntimeException("missing parameter Y");

        long nX = itrNX->second.toInt32();
        long nY = itrNY->second.toInt32();
        Point aPos(nX, nY);

        auto itrAngle = rParameters.find("ANGLE");
        if (itrAngle  == rParameters.end())
            throw css::uno::RuntimeException("missing parameter ANGLE");

        double nAngle = itrAngle->second.toDouble();
        pObj->Rotate(aPos, nAngle, 0, 0);
    }
    else if (rAction == "Mirror")
    {
        Point aPos;
        Point aPos2;
        pObj->Mirror(aPos, aPos2);
    }
    else if (rAction == "SHEAR")
    {
        Point aPos;
        double nAngle = 0;
        pObj->Shear(aPos, nAngle, 0, false);
    }
}

OUString SdrUIObject::get_type() const
{
    return OUString("SdrUIObject");
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */