LibreOffice Module vcl (master) 1
treelist/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
12#include <vcl/toolkit/edit.hxx>
17
19 WindowUIObject(xTreeList),
20 mxTreeList(xTreeList)
21{
22}
23
24namespace {
25
26bool isCheckBoxList(const VclPtr<SvTreeListBox>& xTreeList)
27{
28 return (xTreeList->GetTreeFlags() & SvTreeFlags::CHKBTN) == SvTreeFlags::CHKBTN;
29}
30
31}
32
34{
36
37 aMap["SelectionCount"] = OUString::number(mxTreeList->GetSelectionCount());
38 aMap["VisibleCount"] = OUString::number(mxTreeList->GetVisibleCount());
39 aMap["Children"] = OUString::number(mxTreeList->GetChildCount(nullptr));
40 aMap["LevelChildren"] = OUString::number(mxTreeList->GetLevelChildCount(nullptr));
41 aMap["CheckBoxList"] = OUString::boolean(isCheckBoxList(mxTreeList));
43 aMap["SelectEntryText"] = pEntry ? mxTreeList->GetEntryText(pEntry) : OUString();
44
45 return aMap;
46}
47
48void TreeListUIObject::execute(const OUString& rAction,
49 const StringMap& rParameters)
50{
51 if (rAction.isEmpty())
52 {
53 }
54 else if (auto const pEdit = mxTreeList->GetEditWidget())
55 {
56 std::unique_ptr<UIObject>(new EditUIObject(pEdit))->execute(rAction, rParameters);
57 }
58 else
59 WindowUIObject::execute(rAction, rParameters);
60}
61
62std::unique_ptr<UIObject> TreeListUIObject::get_child(const OUString& rID)
63{
64 sal_Int32 nID = rID.toInt32();
65 if (nID >= 0)
66 {
67 SvTreeListEntry* pEntry = mxTreeList->GetEntry(nullptr, nID);
68 if (!pEntry)
69 return nullptr;
70
71 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
72 }
73 else if (nID == -1) // FIXME hack?
74 {
75 if (auto const pEdit = mxTreeList->GetEditWidget())
76 {
77 return std::unique_ptr<UIObject>(new EditUIObject(pEdit));
78 }
79 }
80
81 return nullptr;
82}
83
84std::set<OUString> TreeListUIObject::get_children() const
85{
86 std::set<OUString> aChildren;
87
88 size_t nChildren = mxTreeList->GetLevelChildCount(nullptr);
89 for (size_t i = 0; i < nChildren; ++i)
90 {
91 aChildren.insert(OUString::number(i));
92 }
93
94 return aChildren;
95}
96
98{
99 return "TreeListUIObject";
100}
101
102std::unique_ptr<UIObject> TreeListUIObject::create(vcl::Window* pWindow)
103{
104 SvTreeListBox* pTreeList = dynamic_cast<SvTreeListBox*>(pWindow);
105 assert(pTreeList);
106 return std::unique_ptr<UIObject>(new TreeListUIObject(pTreeList));
107}
108
110 mxTreeList(xTreeList),
111 mpEntry(pEntry)
112{
113}
114
116{
118
120 aMap["Children"] = OUString::number(mxTreeList->GetLevelChildCount(mpEntry));
121 aMap["VisibleChildCount"] = OUString::number(mxTreeList->GetVisibleChildCount(mpEntry));
122 aMap["IsSelected"] = OUString::boolean(mxTreeList->IsSelected(mpEntry));
123
124 aMap["IsSemiTransparent"] = OUString::boolean(bool(mpEntry->GetFlags() & SvTLEntryFlags::SEMITRANSPARENT));
125
127 if (pItem)
128 aMap["IsChecked"] = OUString::boolean(pItem->IsStateChecked());
129
130 return aMap;
131}
132
133void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
134{
135 if (rAction == "COLLAPSE")
136 {
138 }
139 else if (rAction == "EXPAND")
140 {
142 }
143 else if (rAction == "SELECT")
144 {
146 }
147 else if (rAction == "DESELECT")
148 {
149 mxTreeList->Select(mpEntry, false);
150 }
151 else if (rAction == "CLICK")
152 {
154 if (!pItem)
155 return;
156 pItem->ClickHdl(mpEntry);
157 }
158 else if (rAction == "DOUBLECLICK")
159 {
162 }
163}
164
165std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
166{
167 sal_Int32 nID = rID.toInt32();
168 if (nID >= 0)
169 {
171 if (!pEntry)
172 return nullptr;
173
174 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
175 }
176
177 return nullptr;
178}
179
180std::set<OUString> TreeListEntryUIObject::get_children() const
181{
182 std::set<OUString> aChildren;
183
184 size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
185 for (size_t i = 0; i < nChildren; ++i)
186 {
187 aChildren.insert(OUString::number(i));
188 }
189
190 return aChildren;
191}
192
194{
195 return "TreeListEntry";
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:353
bool IsStateChecked() const
Definition: svlbitm.hxx:184
bool IsSelected(const SvTreeListEntry *pEntry) const
Definition: treelist.cxx:1325
sal_uInt32 GetVisibleCount() const
Definition: treelist.hxx:229
sal_uInt32 GetSelectionCount() const
Definition: treelist.cxx:1044
sal_uInt32 GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:270
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:252
SvTreeFlags GetTreeFlags() const
SvTreeListEntry * GetEntry(SvTreeListEntry *pParent, sal_uInt32 nPos) const
virtual OUString GetEntryText(SvTreeListEntry *pEntry) const
bool Collapse(SvTreeListEntry *pParent)
bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
sal_uInt32 GetChildCount(SvTreeListEntry const *pParent) const
void SetCurEntry(SvTreeListEntry *_pEntry)
VclPtr< Edit > GetEditWidget() const
sal_uInt32 GetLevelChildCount(SvTreeListEntry *pParent) const
bool Expand(SvTreeListEntry *pParent)
bool DoubleClickHdl()
const SvLBoxItem * GetFirstItem(SvLBoxItemType eType) const
SvTLEntryFlags GetFlags() const
virtual StringMap get_state() override
Returns the state of the wrapped UI object as a string key value map.
virtual std::set< OUString > get_children() const override
Returns a set containing all descendants of the object.
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:510
SvTreeListEntry *const mpEntry
Definition: uiobject.hxx:512
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Returns the child of the current UIObject with the corresponding id.
virtual OUString get_type() const override
Returns the type of the UIObject.
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Executes an action on the wrapped UI object, possibly with some additional parameters.
TreeListEntryUIObject(const VclPtr< SvTreeListBox > &xTreeList, SvTreeListEntry *pEntry)
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:488
TreeListUIObject(const VclPtr< SvTreeListBox > &xTreeList)
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Executes an action on the wrapped UI object, possibly with some additional parameters.
virtual std::set< OUString > get_children() const override
Returns a set containing all descendants of the object.
virtual StringMap get_state() override
Returns the state of the wrapped UI object as a string key value map.
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Returns the child of the current UIObject with the corresponding id.
virtual OUString get_name() const override
virtual StringMap get_state() override
Returns the state of the wrapped UI object as a string key value map.
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Executes an action on the wrapped UI object, possibly with some additional parameters.
int i
HashMap_OWString_Interface aMap
std::map< OUString, OUString > StringMap