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 && SvTreeListBox::HasEntryText(pEntry))
42  ? mxTreeList->GetEntryText(pEntry)
43  : OUString();
44 
45  return aMap;
46 }
47 
48 void TreeListUIObject::execute(const OUString& rAction,
49  const StringMap& rParameters)
50 {
51  if (rAction.isEmpty())
52  {
53  }
54  else
55  WindowUIObject::execute(rAction, rParameters);
56 }
57 
58 std::unique_ptr<UIObject> TreeListUIObject::get_child(const OUString& rID)
59 {
60  sal_Int32 nID = rID.toInt32();
61  if (nID >= 0)
62  {
63  SvTreeListEntry* pEntry = mxTreeList->GetEntry(nullptr, nID);
64  if (!pEntry)
65  return nullptr;
66 
67  return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
68  }
69 
70  return nullptr;
71 }
72 
73 std::set<OUString> TreeListUIObject::get_children() const
74 {
75  std::set<OUString> aChildren;
76 
77  size_t nChildren = mxTreeList->GetLevelChildCount(nullptr);
78  for (size_t i = 0; i < nChildren; ++i)
79  {
80  aChildren.insert(OUString::number(i));
81  }
82 
83  return aChildren;
84 }
85 
87 {
88  return "TreeListUIObject";
89 }
90 
91 std::unique_ptr<UIObject> TreeListUIObject::create(vcl::Window* pWindow)
92 {
93  SvTreeListBox* pTreeList = dynamic_cast<SvTreeListBox*>(pWindow);
94  assert(pTreeList);
95  return std::unique_ptr<UIObject>(new TreeListUIObject(pTreeList));
96 }
97 
99  mxTreeList(xTreeList),
100  mpEntry(pEntry)
101 {
102 }
103 
105 {
106  StringMap aMap;
107 
108  aMap["Text"] = mxTreeList->GetEntryText(mpEntry);
109  aMap["Children"] = OUString::number(mxTreeList->GetLevelChildCount(mpEntry));
110  aMap["VisibleChildCount"] = OUString::number(mxTreeList->GetVisibleChildCount(mpEntry));
111  aMap["IsSelected"] = OUString::boolean(mxTreeList->IsSelected(mpEntry));
112 
113  aMap["IsSemiTransparent"] = OUString::boolean(bool(mpEntry->GetFlags() & SvTLEntryFlags::SEMITRANSPARENT));
114 
116  if (pItem)
117  aMap["IsChecked"] = OUString::boolean(pItem->IsStateChecked());
118 
119  return aMap;
120 }
121 
122 void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
123 {
124  if (rAction == "COLLAPSE")
125  {
127  }
128  else if (rAction == "EXPAND")
129  {
131  }
132  else if (rAction == "SELECT")
133  {
135  }
136  else if (rAction == "DESELECT")
137  {
138  mxTreeList->Select(mpEntry, false);
139  }
140  else if (rAction == "CLICK")
141  {
143  if (!pItem)
144  return;
145  pItem->ClickHdl(mpEntry);
146  }
147  else if (rAction == "DOUBLECLICK")
148  {
151  }
152 }
153 
154 std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
155 {
156  sal_Int32 nID = rID.toInt32();
157  if (nID >= 0)
158  {
159  SvTreeListEntry* pEntry = mxTreeList->GetEntry(mpEntry, nID);
160  if (!pEntry)
161  return nullptr;
162 
163  return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
164  }
165 
166  return nullptr;
167 }
168 
169 std::set<OUString> TreeListEntryUIObject::get_children() const
170 {
171  std::set<OUString> aChildren;
172 
173  size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
174  for (size_t i = 0; i < nChildren; ++i)
175  {
176  aChildren.insert(OUString::number(i));
177  }
178 
179  return aChildren;
180 }
181 
183 {
184  return "TreeListEntry";
185 }
186 
187 /* 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.
SvTLEntryFlags GetFlags() const
sal_uInt32 GetChildCount(SvTreeListEntry const *pParent) const
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.
SvTreeListEntry * FirstSelected() const
Definition: treelist.hxx:252
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_uInt32 GetVisibleChildCount(SvTreeListEntry *pParent) const
Definition: treelist.hxx:270
sal_uInt32 GetVisibleCount() const
Definition: treelist.hxx:229
int i
sal_uInt32 GetSelectionCount() const
Definition: treelist.cxx:1043
bool IsSelected(const SvTreeListEntry *pEntry) const
Definition: treelist.cxx:1324
bool IsStateChecked() const
Definition: svlbitm.hxx:184
bool Collapse(SvTreeListEntry *pParent)
virtual OUString GetEntryText(SvTreeListEntry *pEntry) const
bool Expand(SvTreeListEntry *pParent)
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:488
VclPtr< SvTreeListBox > mxTreeList
Definition: uiobject.hxx:510
SvTreeListEntry *const mpEntry
Definition: uiobject.hxx:512
sal_uInt32 GetLevelChildCount(SvTreeListEntry *pParent) const
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:352
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
SvTreeListEntry * GetEntry(SvTreeListEntry *pParent, sal_uInt32 nPos) const
std::map< OUString, OUString > StringMap
static bool HasEntryText(const SvTreeListEntry *pEntry)
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
bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
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.