cURL: follow redirects
[LibreOffice.git] / starmath / source / uiobject.cxx
blob0ed9468c00d757e22ab4eab848353abe5ebcca89
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 "uiobject.hxx"
12 #include "ElementsDockingWindow.hxx"
14 ElementUIObject::ElementUIObject(VclPtr<SmElementsControl> xElementSelector,
15 const OUString& rID):
16 mxElementsSelector(xElementSelector),
17 maID(rID)
21 SmElement* ElementUIObject::get_element()
23 sal_uInt32 nID = maID.toUInt32();
24 size_t n = mxElementsSelector->maElementList.size();
25 if (nID >= n)
26 return nullptr;
28 return mxElementsSelector->maElementList[nID].get();
31 StringMap ElementUIObject::get_state()
33 StringMap aMap;
34 aMap["ID"] = maID;
36 SmElement* pElement = get_element();
37 if (pElement)
38 aMap["Text"] = pElement->getText();
40 return aMap;
43 void ElementUIObject::execute(const OUString& rAction,
44 const StringMap& /*rParameters*/)
46 if (rAction == "SELECT")
48 SmElement* pElement = get_element();
49 if (pElement)
50 mxElementsSelector->maSelectHdlLink.Call(*pElement);
54 ElementSelectorUIObject::ElementSelectorUIObject(VclPtr<SmElementsControl> xElementSelector):
55 WindowUIObject(xElementSelector),
56 mxElementsSelector(xElementSelector)
60 StringMap ElementSelectorUIObject::get_state()
62 StringMap aMap = WindowUIObject::get_state();
64 SmElement* pElement = mxElementsSelector->mpCurrentElement;
65 if (pElement)
66 aMap["CurrentEntry"] = pElement->getText();
68 aMap["CurrentSelection"] = OUString::number(mxElementsSelector->maCurrentSetId);
70 return aMap;
73 std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
75 size_t nID = rID.toInt32();
76 size_t n = mxElementsSelector->maElementList.size();
77 if (nID >= n)
78 throw css::uno::RuntimeException("invalid id");
80 return std::unique_ptr<UIObject>(new ElementUIObject(mxElementsSelector, rID));
83 std::set<OUString> ElementSelectorUIObject::get_children() const
85 std::set<OUString> aChildren;
87 size_t n = mxElementsSelector->maElementList.size();
88 for (size_t i = 0; i < n; ++i)
90 aChildren.insert(OUString::number(i));
93 return aChildren;
96 std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
98 SmElementsControl* pElementsControl = dynamic_cast<SmElementsControl*>(pWindow);
99 assert(pElementsControl);
101 return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pElementsControl));
104 OUString ElementSelectorUIObject::get_name() const
106 return OUString("SmElementSelector");
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */