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 //TODO: this looks dangerous, as there appears to be no protocol to guarantee that
73 // *pEntry will live as long as the new TreeListEntryUIObject referencing it by raw
74 // pointer
75 }
76 else if (nID == -1) // FIXME hack?
77 {
78 if (auto const pEdit = mxTreeList->GetEditWidget())
79 {
80 return std::unique_ptr<UIObject>(new EditUIObject(pEdit));
81 }
82 }
83
84 return nullptr;
85}
86
87std::set<OUString> TreeListUIObject::get_children() const
88{
89 std::set<OUString> aChildren;
90
91 size_t nChildren = mxTreeList->GetLevelChildCount(nullptr);
92 for (size_t i = 0; i < nChildren; ++i)
93 {
94 aChildren.insert(OUString::number(i));
95 }
96
97 return aChildren;
98}
99
101{
102 return "TreeListUIObject";
103}
104
105std::unique_ptr<UIObject> TreeListUIObject::create(vcl::Window* pWindow)
106{
107 SvTreeListBox* pTreeList = dynamic_cast<SvTreeListBox*>(pWindow);
108 assert(pTreeList);
109 return std::unique_ptr<UIObject>(new TreeListUIObject(pTreeList));
110}
111
113 mxTreeList(xTreeList),
114 mpEntry(pEntry)
115{
116}
117
119{
121
123 aMap["Children"] = OUString::number(mxTreeList->GetLevelChildCount(mpEntry));
124 aMap["VisibleChildCount"] = OUString::number(mxTreeList->GetVisibleChildCount(mpEntry));
125 aMap["IsSelected"] = OUString::boolean(mxTreeList->IsSelected(mpEntry));
126
127 aMap["IsSemiTransparent"] = OUString::boolean(bool(mpEntry->GetFlags() & SvTLEntryFlags::SEMITRANSPARENT));
128
130 if (pItem)
131 aMap["IsChecked"] = OUString::boolean(pItem->IsStateChecked());
132
133 return aMap;
134}
135
136void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
137{
138 if (rAction == "COLLAPSE")
139 {
141 }
142 else if (rAction == "EXPAND")
143 {
145 }
146 else if (rAction == "SELECT")
147 {
149 }
150 else if (rAction == "DESELECT")
151 {
152 mxTreeList->Select(mpEntry, false);
153 }
154 else if (rAction == "CLICK")
155 {
157 if (!pItem)
158 return;
159 pItem->ClickHdl(mpEntry);
160 }
161 else if (rAction == "DOUBLECLICK")
162 {
165 }
166}
167
168std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
169{
170 sal_Int32 nID = rID.toInt32();
171 if (nID >= 0)
172 {
174 if (!pEntry)
175 return nullptr;
176
177 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
178 //TODO: this looks dangerous, as there appears to be no protocol to guarantee that
179 // *pEntry will live as long as the new TreeListEntryUIObject referencing it by raw
180 // pointer
181 }
182
183 return nullptr;
184}
185
186std::set<OUString> TreeListEntryUIObject::get_children() const
187{
188 std::set<OUString> aChildren;
189
190 size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
191 for (size_t i = 0; i < nChildren; ++i)
192 {
193 aChildren.insert(OUString::number(i));
194 }
195
196 return aChildren;
197}
198
200{
201 return "TreeListEntry";
202}
203
204/* 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:1310
sal_uInt32 GetVisibleCount() const
Definition: treelist.hxx:228
sal_uInt32 GetSelectionCount() const
Definition: treelist.cxx:1029
sal_uInt32 GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:269
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:251
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