summaryrefslogtreecommitdiffstats
path: root/starmath/source/uiobject.cxx
blob: a6f0c47cbd9b484beccdc065b4bafbde7dbff9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -*- 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/.
 */

#include <memory>
#include "uiobject.hxx"
#include <vcl/layout.hxx>
#include <ElementsDockingWindow.hxx>

ElementUIObject::ElementUIObject(SmElementsControl* pElementSelector,
        const OUString& rID):
    mpElementsSelector(pElementSelector),
    maID(rID)
{
}

SmElement* ElementUIObject::get_element()
{
    sal_uInt32 nID = maID.toUInt32();
    size_t n = mpElementsSelector->maElementList.size();
    if (nID >= n)
        return nullptr;

    return mpElementsSelector->maElementList[nID].get();
}

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)
            mpElementsSelector->maSelectHdlLink.Call(*pElement);
    }
}

ElementSelectorUIObject::ElementSelectorUIObject(vcl::Window* pElementSelectorWindow, SmElementsControl* pElementSelector)
    : WindowUIObject(pElementSelectorWindow)
    , mpElementsSelector(pElementSelector)
{
}

StringMap ElementSelectorUIObject::get_state()
{
    StringMap aMap = WindowUIObject::get_state();

    SmElement* pElement = mpElementsSelector->current();
    if (pElement)
        aMap["CurrentEntry"] = pElement->getText();

    aMap["CurrentSelection"] = OUString::fromUtf8(mpElementsSelector->msCurrentSetId);

    return aMap;
}

std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
{
    size_t nID = rID.toInt32();
    size_t n = mpElementsSelector->maElementList.size();
    if (nID >= n)
        throw css::uno::RuntimeException("invalid id");

    return std::unique_ptr<UIObject>(new ElementUIObject(mpElementsSelector, rID));
}

std::set<OUString> ElementSelectorUIObject::get_children() const
{
    std::set<OUString> aChildren;

    size_t n = mpElementsSelector->maElementList.size();
    for (size_t i = 0; i < n; ++i)
    {
        aChildren.insert(OUString::number(i));
    }

    return aChildren;
}

std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
{
    VclDrawingArea* pSmElementsWin = dynamic_cast<VclDrawingArea*>(pWindow);
    assert(pSmElementsWin);
    return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pSmElementsWin, static_cast<SmElementsControl*>(pSmElementsWin->GetUserData())));
}

OUString ElementSelectorUIObject::get_name() const
{
    return "SmElementSelector";
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */