bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / uitest / uiobject.cxx
blob4919ffc91c75ee1531508fe958d4babe4d28f813
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 <memory>
11 #include <uiobject.hxx>
13 #include <Window.hxx>
14 #include <DrawViewShell.hxx>
15 #include <sdpage.hxx>
17 #include <svx/uiobject.hxx>
19 class ImpressSdrObject : public SdrUIObject
21 public:
22 ImpressSdrObject(const VclPtr<sd::Window>& xImpressWin, const OUString& rName);
24 SdrObject* get_object() override;
26 private:
27 VclPtr<sd::Window> mxWindow;
29 OUString const maName;
32 namespace {
34 sd::DrawViewShell* getViewShell(const VclPtr<sd::Window>& xWindow)
36 sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(xWindow->GetViewShell());
37 assert(pViewShell);
39 return pViewShell;
42 OUString getObjectName(SdrObject const * pObject)
44 if (pObject->GetName().isEmpty())
45 return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
46 else
47 return pObject->GetName();
50 SdrObject* getObject(const VclPtr<sd::Window>& xWindow, const OUString& rName)
52 SdrPage* pPage = getViewShell(xWindow)->getCurrentPage();
54 if (!pPage)
55 return nullptr;
57 size_t nObjs = pPage->GetObjCount();
58 for (size_t i = 0; i < nObjs; ++i)
60 SdrObject* pObj = pPage->GetObj(i);
61 if (rName == getObjectName(pObj))
62 return pObj;
65 return nullptr;
71 ImpressSdrObject::ImpressSdrObject(const VclPtr<sd::Window>& xImpressWin, const OUString& rName):
72 mxWindow(xImpressWin),
73 maName(rName)
77 SdrObject* ImpressSdrObject::get_object()
79 return getObject(mxWindow, maName);
82 ImpressWindowUIObject::ImpressWindowUIObject(const VclPtr<sd::Window>& xWindow):
83 WindowUIObject(xWindow),
84 mxWindow(xWindow)
88 StringMap ImpressWindowUIObject::get_state()
90 StringMap aMap = WindowUIObject::get_state();
92 aMap["SelectedText"] = getViewShell(mxWindow)->GetSelectionText(false);
93 aMap["CurrentSlide"] = OUString::number(getViewShell(mxWindow)->GetCurPagePos() + 1);
94 aMap["Zoom"] = OUString::number(getViewShell(mxWindow)->GetZoom());
96 return aMap;
99 void ImpressWindowUIObject::execute(const OUString& rAction,
100 const StringMap& rParameters)
102 if (rAction == "SET")
104 if (rParameters.find("ZOOM") != rParameters.end())
106 auto itr = rParameters.find("ZOOM");
107 OUString aVal = itr->second;
108 sal_Int32 nVal = aVal.toInt32();
109 getViewShell(mxWindow)->SetZoom(nVal);
112 else if (rAction == "GOTO")
114 if (rParameters.find("PAGE") != rParameters.end())
116 auto itr = rParameters.find("PAGE");
117 OUString aVal = itr->second;
118 sal_Int32 nVal = aVal.toInt32();
119 getViewShell(mxWindow)->SwitchPage(nVal);
122 else if (rAction == "SELECT")
124 if (rParameters.find("OBJECT") != rParameters.end())
126 auto itr = rParameters.find("OBJECT");
127 OUString aName = itr->second;
128 SdrObject* pObj = getObject(mxWindow, aName);
129 SdrPageView* pPageView = getViewShell(mxWindow)->GetView()->GetSdrPageView();
130 getViewShell(mxWindow)->GetView()->MarkObj(pObj, pPageView);
133 else if (rAction == "DESELECT")
135 getViewShell(mxWindow)->GetView()->UnMarkAll();
137 else
138 WindowUIObject::execute(rAction, rParameters);
141 std::unique_ptr<UIObject> ImpressWindowUIObject::get_child(const OUString& rID)
143 return std::unique_ptr<UIObject>(new ImpressSdrObject(mxWindow, rID));
146 std::set<OUString> ImpressWindowUIObject::get_children() const
148 SdrPage* pPage = getViewShell(mxWindow)->getCurrentPage();
150 std::set<OUString> aRet;
151 if (!pPage)
152 return aRet;
154 size_t nObjs = pPage->GetObjCount();
155 for (size_t i = 0; i < nObjs; ++i)
157 SdrObject* pObject = pPage->GetObj(i);
158 aRet.insert(getObjectName(pObject));
161 return aRet;
164 OUString ImpressWindowUIObject::get_name() const
166 return OUString("ImpressWindowUIObject");
169 std::unique_ptr<UIObject> ImpressWindowUIObject::create(vcl::Window* pWindow)
171 sd::Window* pWin = dynamic_cast<sd::Window*>(pWindow);
172 assert(pWin);
173 return std::unique_ptr<UIObject>(new ImpressWindowUIObject(pWin));
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */