1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
),
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();
46 void TreeListUIObject::execute(const OUString
& rAction
,
47 const StringMap
& rParameters
)
49 if (rAction
.isEmpty())
53 WindowUIObject::execute(rAction
, rParameters
);
56 std::unique_ptr
<UIObject
> TreeListUIObject::get_child(const OUString
& rID
)
58 sal_Int32 nID
= rID
.toInt32();
61 SvTreeListEntry
* pEntry
= mxTreeList
->GetEntry(nullptr, nID
);
65 return std::unique_ptr
<UIObject
>(new TreeListEntryUIObject(mxTreeList
, pEntry
));
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
));
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
);
93 return std::unique_ptr
<UIObject
>(new TreeListUIObject(pTreeList
));
96 TreeListEntryUIObject::TreeListEntryUIObject(const VclPtr
<SvTreeListBox
>& xTreeList
, SvTreeListEntry
* pEntry
):
97 mxTreeList(xTreeList
),
102 StringMap
TreeListEntryUIObject::get_state()
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
));
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
));
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();
151 SvTreeListEntry
* pEntry
= mxTreeList
->GetEntry(mpEntry
, nID
);
155 return std::unique_ptr
<UIObject
>(new TreeListEntryUIObject(mxTreeList
, pEntry
));
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
));
174 OUString
TreeListEntryUIObject::get_type() const
176 return "TreeListEntry";
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */