Entry may have no text
[LibreOffice.git] / vcl / source / treelist / uiobject.cxx
blobccc0668041395ade80b0889522d3e1e34bb6a68a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <memory>
11 #include <vcl/toolkit/svlbitm.hxx>
12 #include <vcl/uitest/uiobject.hxx>
13 #include <vcl/toolkit/treelistbox.hxx>
14 #include <vcl/toolkit/treelistentry.hxx>
16 TreeListUIObject::TreeListUIObject(const VclPtr<SvTreeListBox>& xTreeList):
17 WindowUIObject(xTreeList),
18 mxTreeList(xTreeList)
22 namespace {
24 bool isCheckBoxList(const VclPtr<SvTreeListBox>& xTreeList)
26 return (xTreeList->GetTreeFlags() & SvTreeFlags::CHKBTN) == SvTreeFlags::CHKBTN;
31 StringMap TreeListUIObject::get_state()
33 StringMap aMap = WindowUIObject::get_state();
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));
40 SvTreeListEntry* pEntry = mxTreeList->FirstSelected();
41 aMap["SelectEntryText"] = pEntry ? mxTreeList->GetEntryText(pEntry) : OUString();
43 return aMap;
46 void TreeListUIObject::execute(const OUString& rAction,
47 const StringMap& rParameters)
49 if (rAction.isEmpty())
52 else
53 WindowUIObject::execute(rAction, rParameters);
56 std::unique_ptr<UIObject> TreeListUIObject::get_child(const OUString& rID)
58 sal_Int32 nID = rID.toInt32();
59 if (nID >= 0)
61 SvTreeListEntry* pEntry = mxTreeList->GetEntry(nullptr, nID);
62 if (!pEntry)
63 return nullptr;
65 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
68 return nullptr;
71 std::set<OUString> TreeListUIObject::get_children() const
73 std::set<OUString> aChildren;
75 size_t nChildren = mxTreeList->GetLevelChildCount(nullptr);
76 for (size_t i = 0; i < nChildren; ++i)
78 aChildren.insert(OUString::number(i));
81 return aChildren;
84 OUString TreeListUIObject::get_name() const
86 return "TreeListUIObject";
89 std::unique_ptr<UIObject> TreeListUIObject::create(vcl::Window* pWindow)
91 SvTreeListBox* pTreeList = dynamic_cast<SvTreeListBox*>(pWindow);
92 assert(pTreeList);
93 return std::unique_ptr<UIObject>(new TreeListUIObject(pTreeList));
96 TreeListEntryUIObject::TreeListEntryUIObject(const VclPtr<SvTreeListBox>& xTreeList, SvTreeListEntry* pEntry):
97 mxTreeList(xTreeList),
98 mpEntry(pEntry)
102 StringMap TreeListEntryUIObject::get_state()
104 StringMap aMap;
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));
111 aMap["IsSemiTransparent"] = OUString::boolean(bool(mpEntry->GetFlags() & SvTLEntryFlags::SEMITRANSPARENT));
113 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(mpEntry->GetFirstItem(SvLBoxItemType::Button));
114 if (pItem)
115 aMap["IsChecked"] = OUString::boolean(pItem->IsStateChecked());
117 return aMap;
120 void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
122 if (rAction == "COLLAPSE")
124 mxTreeList->Collapse(mpEntry);
126 else if (rAction == "EXPAND")
128 mxTreeList->Expand(mpEntry);
130 else if (rAction == "SELECT")
132 mxTreeList->Select(mpEntry);
134 else if (rAction == "DESELECT")
136 mxTreeList->Select(mpEntry, false);
138 else if (rAction == "CLICK")
140 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(mpEntry->GetFirstItem(SvLBoxItemType::Button));
141 if (!pItem)
142 return;
143 pItem->ClickHdl(mpEntry);
145 else if (rAction == "DOUBLECLICK")
147 mxTreeList->Select(mpEntry);
148 mxTreeList->DoubleClickHdl();
152 std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
154 sal_Int32 nID = rID.toInt32();
155 if (nID >= 0)
157 SvTreeListEntry* pEntry = mxTreeList->GetEntry(mpEntry, nID);
158 if (!pEntry)
159 return nullptr;
161 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
164 return nullptr;
167 std::set<OUString> TreeListEntryUIObject::get_children() const
169 std::set<OUString> aChildren;
171 size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
172 for (size_t i = 0; i < nChildren; ++i)
174 aChildren.insert(OUString::number(i));
177 return aChildren;
180 OUString TreeListEntryUIObject::get_type() const
182 return "TreeListEntry";
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */