nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / treelist / uiobject.cxx
blobe7fb516b5d21bf43bb4178038fddeebd1e06e1e6
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 return aMap;
114 void TreeListEntryUIObject::execute(const OUString& rAction, const StringMap& /*rParameters*/)
116 if (rAction == "COLLAPSE")
118 mxTreeList->Collapse(mpEntry);
120 else if (rAction == "EXPAND")
122 mxTreeList->Expand(mpEntry);
124 else if (rAction == "SELECT")
126 mxTreeList->Select(mpEntry);
128 else if (rAction == "DESELECT")
130 mxTreeList->Select(mpEntry, false);
132 else if (rAction == "CLICK")
134 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(mpEntry->GetFirstItem(SvLBoxItemType::Button));
135 if (!pItem)
136 return;
137 pItem->ClickHdl(mpEntry);
139 else if (rAction == "DOUBLECLICK")
141 mxTreeList->Select(mpEntry);
142 mxTreeList->DoubleClickHdl();
146 std::unique_ptr<UIObject> TreeListEntryUIObject::get_child(const OUString& rID)
148 sal_Int32 nID = rID.toInt32();
149 if (nID >= 0)
151 SvTreeListEntry* pEntry = mxTreeList->GetEntry(mpEntry, nID);
152 if (!pEntry)
153 return nullptr;
155 return std::unique_ptr<UIObject>(new TreeListEntryUIObject(mxTreeList, pEntry));
158 return nullptr;
161 std::set<OUString> TreeListEntryUIObject::get_children() const
163 std::set<OUString> aChildren;
165 size_t nChildren = mxTreeList->GetLevelChildCount(mpEntry);
166 for (size_t i = 0; i < nChildren; ++i)
168 aChildren.insert(OUString::number(i));
171 return aChildren;
174 OUString TreeListEntryUIObject::get_type() const
176 return "TreeListEntry";
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */