2016-07-17 16:43:40 +02:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2017-04-14 08:42:15 +10:00
|
|
|
#include <memory>
|
2016-07-17 16:43:40 +02:00
|
|
|
#include "uiobject.hxx"
|
2020-01-28 20:40:15 +00:00
|
|
|
#include <vcl/layout.hxx>
|
2017-10-23 22:31:51 +02:00
|
|
|
#include <ElementsDockingWindow.hxx>
|
2016-07-17 16:43:40 +02:00
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
ElementUIObject::ElementUIObject(SmElementsControl* pElementSelector,
|
2016-07-17 16:43:40 +02:00
|
|
|
const OUString& rID):
|
2020-01-28 20:40:15 +00:00
|
|
|
mpElementsSelector(pElementSelector),
|
2016-07-17 16:43:40 +02:00
|
|
|
maID(rID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SmElement* ElementUIObject::get_element()
|
|
|
|
{
|
|
|
|
sal_uInt32 nID = maID.toUInt32();
|
2020-01-28 20:40:15 +00:00
|
|
|
size_t n = mpElementsSelector->maElementList.size();
|
2016-07-17 16:43:40 +02:00
|
|
|
if (nID >= n)
|
|
|
|
return nullptr;
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
return mpElementsSelector->maElementList[nID].get();
|
2016-07-17 16:43:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
StringMap ElementUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap;
|
|
|
|
aMap["ID"] = maID;
|
|
|
|
|
|
|
|
SmElement* pElement = get_element();
|
|
|
|
if (pElement)
|
|
|
|
aMap["Text"] = pElement->getText();
|
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElementUIObject::execute(const OUString& rAction,
|
|
|
|
const StringMap& /*rParameters*/)
|
|
|
|
{
|
|
|
|
if (rAction == "SELECT")
|
|
|
|
{
|
|
|
|
SmElement* pElement = get_element();
|
|
|
|
if (pElement)
|
2020-01-28 20:40:15 +00:00
|
|
|
mpElementsSelector->maSelectHdlLink.Call(*pElement);
|
2016-07-17 16:43:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
ElementSelectorUIObject::ElementSelectorUIObject(vcl::Window* pElementSelectorWindow, SmElementsControl* pElementSelector)
|
|
|
|
: WindowUIObject(pElementSelectorWindow)
|
|
|
|
, mpElementsSelector(pElementSelector)
|
2016-07-17 16:43:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringMap ElementSelectorUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap = WindowUIObject::get_state();
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
SmElement* pElement = mpElementsSelector->current();
|
2016-07-17 16:43:40 +02:00
|
|
|
if (pElement)
|
|
|
|
aMap["CurrentEntry"] = pElement->getText();
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
aMap["CurrentSelection"] = OUString::fromUtf8(mpElementsSelector->msCurrentSetId);
|
2016-07-17 16:43:40 +02:00
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
|
|
|
|
{
|
|
|
|
size_t nID = rID.toInt32();
|
2020-01-28 20:40:15 +00:00
|
|
|
size_t n = mpElementsSelector->maElementList.size();
|
2016-07-17 16:43:40 +02:00
|
|
|
if (nID >= n)
|
|
|
|
throw css::uno::RuntimeException("invalid id");
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
return std::unique_ptr<UIObject>(new ElementUIObject(mpElementsSelector, rID));
|
2016-07-17 16:43:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::set<OUString> ElementSelectorUIObject::get_children() const
|
|
|
|
{
|
|
|
|
std::set<OUString> aChildren;
|
|
|
|
|
2020-01-28 20:40:15 +00:00
|
|
|
size_t n = mpElementsSelector->maElementList.size();
|
2016-07-17 16:43:40 +02:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
aChildren.insert(OUString::number(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return aChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
|
|
|
|
{
|
2020-01-28 20:40:15 +00:00
|
|
|
VclDrawingArea* pSmElementsWin = dynamic_cast<VclDrawingArea*>(pWindow);
|
|
|
|
assert(pSmElementsWin);
|
|
|
|
return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pSmElementsWin, static_cast<SmElementsControl*>(pSmElementsWin->GetUserData())));
|
2016-07-17 16:43:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString ElementSelectorUIObject::get_name() const
|
|
|
|
{
|
2019-07-30 17:48:38 +02:00
|
|
|
return "SmElementSelector";
|
2016-07-17 16:43:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|