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 #include <vcl/svlbitm.hxx>
12 #include <vcl/uitest/uiobject.hxx>
13 #include <vcl/treelistbox.hxx>
14 #include <vcl/treelistentry.hxx>
15 
17  WindowUIObject(xTreeList),
18  mxTreeList(xTreeList)
19 {
20 }
21 
22 namespace {
23 
24 bool isCheckBoxList(const VclPtr<SvTreeListBox>& xTreeList)
25 {
26  return (xTreeList->GetTreeFlags() & SvTreeFlags::CHKBTN) == SvTreeFlags::CHKBTN;
27 }
28 
29 }
30 
32 {
34 
35  aMap["SelectionCount"] = OUString::number(mxTreeList->GetSelectionCount());
36  aMap["VisibleCount"] = OUString::number(mxTreeList->GetVisibleCount());
37  aMap["Children"] = OUString::number(mxTreeList->GetChildCount(nullptr));
38  aMap["LevelChildren"] = OUString::number(mxTreeList->GetLevelChildCount(nullptr));
39  aMap["CheckBoxList"] = OUString::boolean(isCheckBoxList(mxTreeList));
41  aMap["SelectEntryText"] = pEntry ? mxTreeList->GetEntryText(pEntry) : OUString();
42 
43  return aMap;
44 }
45 
46 void TreeListUIObject::execute(const OUString& rAction,
47  const StringMap& rParameters)
48 {
49  if (rAction.isEmpty())
50  {
51  }
52  else
53  WindowUIObject::execute(rAction, rParameters);
54 }
55 
56 std::unique_ptr<UIObject> TreeListUIObject::get_child(const OUString& rID)
57 {
58  sal_Int32 nID = rID.toInt32();
59  if (nID >= 0)
60  {
61  SvTreeListEntry* pEntry = mxTreeList->GetEntry(nullptr, nID);
62  if (!pEntry)
63  return nullptr;
64 
65  return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
66  }
67 
68  return nullptr;
69 }
70 
71 std::set<OUString> TreeListUIObject::get_children() const
72 {
73  std::set<OUString> aChildren;
74 
75  size_t nChildren = mxTreeList->GetLevelChildCount(nullptr);
76  for (size_t i = 0; i < nChildren; ++i)
77  {
78  aChildren.insert(OUString::number(i));
79  }
80 
81  return aChildren;
82 }
83 
85 {
86  return "TreeListUIObject";
87 }
88 
89 std::unique_ptr<UIObject> TreeListUIObject::create(vcl::Window* pWindow)
90 {
91  SvTreeListBox* pTreeList = dynamic_cast<SvTreeListBox*>(pWindow);
92  assert(pTreeList);
93  return std::unique_ptr<UIObject>(new TreeListUIObject(pTreeList));
94 }
95 
97  mxTreeList(xTreeList),
98  mpEntry(pEntry)
99 {
100 }
101 
103 {
104  StringMap aMap;
105 
106  aMap["Text"] = mxTreeList->GetEntryText(mpEntry);
107  aMap["Children"] = OUString::number(mxTreeList->GetLevelChildCount(mpEntry));
108  aMap["VisibleChildCount"] = OUString::number(mxTreeList->GetVisibleChildCount(mpEntry));
109 
110  return aMap;
111 }
112 
113 void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
114 {
115  if (rAction == "COLLAPSE")
116  {
118  }
119  else if (rAction == "EXPAND")
120  {
122  }
123  else if (rAction == "SELECT")
124  {
126  }
127  else if (rAction == "DESELECT")
128  {
129  mxTreeList->Select(mpEntry, false);
130  }
131  else if (rAction == "CLICK")
132  {
134  if (!pItem)
135  return;
136  pItem->ClickHdl(mpEntry);
137  }
138 }
139 
140 std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
141 {
142  sal_Int32 nID = rID.toInt32();
143  if (nID >= 0)
144  {
145  SvTreeListEntry* pEntry = mxTreeList->GetEntry(mpEntry, nID);
146  if (!pEntry)
147  return nullptr;
148 
149  return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
150  }
151 
152  return nullptr;
153 }
154 
155 std::set<OUString> TreeListEntryUIObject::get_children() const
156 {
157  std::set<OUString> aChildren;
158 
159  size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
160  for (size_t i = 0; i < nChildren; ++i)
161  {
162  aChildren.insert(OUString::number(i));
163  }
164 
165  return aChildren;
166 }
167 
169 {
170  return "TreeListEntry";
171 }
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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.
TreeListUIObject(const VclPtr< SvTreeListBox > &xTreeList)
virtual StringMap get_state() override
Returns the state of the wrapped UI object as a string key value map.
virtual OUString get_type() const override
Returns the type of the UIObject.
virtual OUString get_name() const override
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Executes an action on the wrapped UI object, possibly with some additional parameters.
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Executes an action on the wrapped UI object, possibly with some additional parameters.
virtual StringMap get_state() override
Returns the state of the wrapped UI object as a string key value map.
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:257
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Returns the child of the current UIObject with the corresponding id.
TreeListEntryUIObject(const VclPtr< SvTreeListBox > &xTreeList, SvTreeListEntry *pEntry)
sal_uLong GetLevelChildCount(SvTreeListEntry *pParent) const
int i
virtual bool Collapse(SvTreeListEntry *pParent)
std::map< const OUString, OUString > StringMap
Definition: uiobject.hxx:31
virtual OUString GetEntryText(SvTreeListEntry *pEntry) const
virtual bool Expand(SvTreeListEntry *pParent)
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:429
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:451
SvTreeListEntry *const mpEntry
Definition: uiobject.hxx:453
sal_uLong GetVisibleCount() const
Definition: treelist.hxx:234
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:290
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
SvTreeListEntry * GetEntry(SvTreeListEntry *pParent, sal_uLong nPos) const
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Returns the child of the current UIObject with the corresponding id.
const SvLBoxItem * GetFirstItem(SvLBoxItemType eType) const
sal_uLong GetChildCount(SvTreeListEntry const *pParent) const
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
sal_uLong GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:280
sal_uLong GetSelectionCount() const
Definition: treelist.cxx:1092
SvTreeFlags GetTreeFlags() const
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.