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/toolkit/svlbitm.hxx>
12 #include <vcl/uitest/uiobject.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  aMap["IsSelected"] = OUString::boolean(mxTreeList->IsSelected(mpEntry));
110 
112  if (pItem)
113  aMap["IsChecked"] = OUString::boolean(pItem->IsStateChecked());
114 
115  return aMap;
116 }
117 
118 void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
119 {
120  if (rAction == "COLLAPSE")
121  {
123  }
124  else if (rAction == "EXPAND")
125  {
127  }
128  else if (rAction == "SELECT")
129  {
131  }
132  else if (rAction == "DESELECT")
133  {
134  mxTreeList->Select(mpEntry, false);
135  }
136  else if (rAction == "CLICK")
137  {
139  if (!pItem)
140  return;
141  pItem->ClickHdl(mpEntry);
142  }
143  else if (rAction == "DOUBLECLICK")
144  {
147  }
148 }
149 
150 std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
151 {
152  sal_Int32 nID = rID.toInt32();
153  if (nID >= 0)
154  {
155  SvTreeListEntry* pEntry = mxTreeList->GetEntry(mpEntry, nID);
156  if (!pEntry)
157  return nullptr;
158 
159  return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
160  }
161 
162  return nullptr;
163 }
164 
165 std::set<OUString> TreeListEntryUIObject::get_children() const
166 {
167  std::set<OUString> aChildren;
168 
169  size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
170  for (size_t i = 0; i < nChildren; ++i)
171  {
172  aChildren.insert(OUString::number(i));
173  }
174 
175  return aChildren;
176 }
177 
179 {
180  return "TreeListEntry";
181 }
182 
183 /* 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.
bool DoubleClickHdl()
virtual OUString get_name() const override
HashMap_OWString_Interface aMap
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.
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:253
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
bool IsSelected(const SvTreeListEntry *pEntry) const
Definition: treelist.cxx:1328
bool Collapse(SvTreeListEntry *pParent)
virtual OUString GetEntryText(SvTreeListEntry *pEntry) const
bool Expand(SvTreeListEntry *pParent)
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:465
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:487
SvTreeListEntry *const mpEntry
Definition: uiobject.hxx:489
sal_uLong GetVisibleCount() const
Definition: treelist.hxx:230
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:353
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
std::map< OUString, OUString > StringMap
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
bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
sal_uLong GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:271
sal_uLong GetSelectionCount() const
Definition: treelist.cxx:1047
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.