LibreOffice Module sd (master) 1
uiobject.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <memory>
11#include <uiobject.hxx>
12
13#include <Window.hxx>
14#include <DrawViewShell.hxx>
15#include <sdpage.hxx>
16
18#include <sfx2/sfxsids.hrc>
19#include <svx/uiobject.hxx>
20#include <tools/debug.hxx>
21#include <utility>
22
23namespace
24{
25class ImpressSdrObject : public SdrUIObject
26{
27public:
28 ImpressSdrObject(const VclPtr<sd::Window>& xImpressWin, OUString aName);
29
30 SdrObject* get_object() override;
31
32private:
33 VclPtr<sd::Window> mxWindow;
34
35 OUString maName;
36};
37
38sd::DrawViewShell* getViewShell(const VclPtr<sd::Window>& xWindow)
39{
40 sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(xWindow->GetViewShell());
41 assert(pViewShell);
42
43 return pViewShell;
44}
45
46OUString getObjectName(SdrObject const* pObject)
47{
48 if (pObject->GetName().isEmpty())
49 return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
50 else
51 return pObject->GetName();
52}
53
54SdrObject* getObject(const VclPtr<sd::Window>& xWindow, std::u16string_view rName)
55{
56 SdrPage* pPage = getViewShell(xWindow)->getCurrentPage();
57
58 if (!pPage)
59 return nullptr;
60
61 size_t nObjs = pPage->GetObjCount();
62 for (size_t i = 0; i < nObjs; ++i)
63 {
64 SdrObject* pObj = pPage->GetObj(i);
65 if (rName == getObjectName(pObj))
66 return pObj;
67 }
68
69 return nullptr;
70}
71}
72
73ImpressSdrObject::ImpressSdrObject(const VclPtr<sd::Window>& xImpressWin, OUString aName)
74 : mxWindow(xImpressWin)
75 , maName(std::move(aName))
76{
77}
78
79SdrObject* ImpressSdrObject::get_object() { return getObject(mxWindow, maName); }
80
82 : WindowUIObject(xWindow)
83 , mxWindow(xWindow)
84{
85}
86
88{
90
91 aMap["SelectedText"] = getViewShell(mxWindow)->GetSelectionText(false);
92 aMap["CurrentSlide"] = OUString::number(getViewShell(mxWindow)->GetCurPagePos() + 1);
93 aMap["Zoom"] = OUString::number(getViewShell(mxWindow)->GetZoom());
94
95 return aMap;
96}
97
98void ImpressWindowUIObject::execute(const OUString& rAction, const StringMap& rParameters)
99{
100 if (rAction == "SET")
101 {
102 if (rParameters.find("ZOOM") != rParameters.end())
103 {
104 auto itr = rParameters.find("ZOOM");
105 OUString aVal = itr->second;
106 sal_Int32 nVal = aVal.toInt32();
107 getViewShell(mxWindow)->SetZoom(nVal);
108 }
109 }
110 else if (rAction == "GOTO")
111 {
112 if (rParameters.find("PAGE") != rParameters.end())
113 {
114 auto itr = rParameters.find("PAGE");
115 OUString aVal = itr->second;
116 sal_Int32 nVal = aVal.toInt32();
117 getViewShell(mxWindow)->SwitchPage(nVal - 1);
118 }
119 }
120 else if (rAction == "SELECT")
121 {
122 if (rParameters.find("OBJECT") != rParameters.end())
123 {
124 auto itr = rParameters.find("OBJECT");
125 OUString aName = itr->second;
126 SdrObject* pObj = getObject(mxWindow, aName);
127 SdrPageView* pPageView = getViewShell(mxWindow)->GetView()->GetSdrPageView();
128 getViewShell(mxWindow)->GetView()->MarkObj(pObj, pPageView);
129 }
130 }
131 else if (rAction == "SIDEBAR")
132 {
134 DBG_ASSERT(pViewFrm, "ImpressWindowUIObject::execute: no viewframe");
135 pViewFrm->ShowChildWindow(SID_SIDEBAR);
136
137 auto itr = rParameters.find("PANEL");
138 if (itr != rParameters.end())
139 {
140 OUString aVal = itr->second;
142 }
143 }
144 else if (rAction == "DESELECT")
145 {
146 getViewShell(mxWindow)->GetView()->UnMarkAll();
147 }
148 else
149 WindowUIObject::execute(rAction, rParameters);
150}
151
152std::unique_ptr<UIObject> ImpressWindowUIObject::get_child(const OUString& rID)
153{
154 return std::unique_ptr<UIObject>(new ImpressSdrObject(mxWindow, rID));
155}
156
157std::set<OUString> ImpressWindowUIObject::get_children() const
158{
159 SdrPage* pPage = getViewShell(mxWindow)->getCurrentPage();
160
161 std::set<OUString> aRet;
162 if (!pPage)
163 return aRet;
164
165 size_t nObjs = pPage->GetObjCount();
166 for (size_t i = 0; i < nObjs; ++i)
167 {
168 SdrObject* pObject = pPage->GetObj(i);
169 aRet.insert(getObjectName(pObject));
170 }
171
172 return aRet;
173}
174
175OUString ImpressWindowUIObject::get_name() const { return "ImpressWindowUIObject"; }
176
177std::unique_ptr<UIObject> ImpressWindowUIObject::create(vcl::Window* pWindow)
178{
179 sd::Window* pWin = dynamic_cast<sd::Window*>(pWindow);
180 assert(pWin);
181 return std::unique_ptr<UIObject>(new ImpressWindowUIObject(pWin));
182}
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maName
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:152
virtual StringMap get_state() override
Definition: uiobject.cxx:87
ImpressWindowUIObject(const VclPtr< sd::Window > &xWindow)
Definition: uiobject.cxx:81
virtual OUString get_name() const override
Definition: uiobject.cxx:175
VclPtr< sd::Window > mxWindow
Definition: uiobject.hxx:32
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:157
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:177
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:98
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
SdrView & GetView()
SdrPageView * GetSdrPageView() const
virtual SdrObject * get_object()=0
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxFrame & GetFrame() const
void ShowChildWindow(sal_uInt16, bool bVisible=true)
virtual StringMap get_state() override
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
#define DBG_ASSERT(sCon, aError)
EmbeddedObjectRef * pObject
OUString aName
int i
HashMap_OWString_Interface aMap
std::map< OUString, OUString > StringMap