Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / starmath / source / uiobject.cxx
blob33c7ba7056024168916b42b41de60330b3252149
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 <ElementsDockingWindow.hxx>
15 ElementUIObject::ElementUIObject(const VclPtr<SmElementsControl>& xElementSelector,
16 const OUString& rID):
17 mxElementsSelector(xElementSelector),
18 maID(rID)
22 SmElement* ElementUIObject::get_element()
24 sal_uInt32 nID = maID.toUInt32();
25 size_t n = mxElementsSelector->maElementList.size();
26 if (nID >= n)
27 return nullptr;
29 return mxElementsSelector->maElementList[nID].get();
32 StringMap ElementUIObject::get_state()
34 StringMap aMap;
35 aMap["ID"] = maID;
37 SmElement* pElement = get_element();
38 if (pElement)
39 aMap["Text"] = pElement->getText();
41 return aMap;
44 void ElementUIObject::execute(const OUString& rAction,
45 const StringMap& /*rParameters*/)
47 if (rAction == "SELECT")
49 SmElement* pElement = get_element();
50 if (pElement)
51 mxElementsSelector->maSelectHdlLink.Call(*pElement);
55 ElementSelectorUIObject::ElementSelectorUIObject(const VclPtr<SmElementsControl>& xElementSelector):
56 WindowUIObject(xElementSelector),
57 mxElementsSelector(xElementSelector)
61 StringMap ElementSelectorUIObject::get_state()
63 StringMap aMap = WindowUIObject::get_state();
65 SmElement* pElement = mxElementsSelector->mpCurrentElement;
66 if (pElement)
67 aMap["CurrentEntry"] = pElement->getText();
69 aMap["CurrentSelection"] = OUString::fromUtf8(mxElementsSelector->msCurrentSetId);
71 return aMap;
74 std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
76 size_t nID = rID.toInt32();
77 size_t n = mxElementsSelector->maElementList.size();
78 if (nID >= n)
79 throw css::uno::RuntimeException("invalid id");
81 return std::unique_ptr<UIObject>(new ElementUIObject(mxElementsSelector, rID));
84 std::set<OUString> ElementSelectorUIObject::get_children() const
86 std::set<OUString> aChildren;
88 size_t n = mxElementsSelector->maElementList.size();
89 for (size_t i = 0; i < n; ++i)
91 aChildren.insert(OUString::number(i));
94 return aChildren;
97 std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
99 SmElementsControl* pElementsControl = dynamic_cast<SmElementsControl*>(pWindow);
100 assert(pElementsControl);
102 return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pElementsControl));
105 OUString ElementSelectorUIObject::get_name() const
107 return OUString("SmElementSelector");
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */