GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_treeviews.cpp
Date: 2025-09-22 22:57:09
Exec Total Coverage
Lines: 0 115 0.0%
Functions: 0 23 0.0%
Branches: 0 78 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/ui/treeviews.hpp"
30
31 namespace gate
32 {
33 namespace ui
34 {
35 intptr_t const Treeview::InvalidIcon = GATE_UI_TREEVIEW_INVALID_ICON;
36 uint32_t const Treeview::Flag_Icons = GATE_UI_FLAG_TREEVIEW_ICONS;
37
38
39 ✗ Treeview::Treeview()
40 ✗ : Control(&impl.ctrl)
41 {
42 ✗ Mem::clear(&this->impl, sizeof(this->impl));
43 ✗ gate_ui_ctrl_init(&this->impl.ctrl);
44 ✗ }
45 ✗ Treeview::~Treeview() noexcept
46 {
47 ✗ if (this->isCreated())
48 {
49 ✗ this->destroy();
50 }
51 ✗ }
52
53 ✗ void Treeview::create(ControlContainer& parent, Position const& pose, uint32_t flags)
54 {
55 ✗ this->failIfCreated("Treeview::create");
56
57 ✗ result_t result = gate_ui_treeview_create(&this->impl, *parent, &pose, flags, this);
58 ✗ GATEXX_CHECK_ERROR(result);
59
60 ✗ this->impl.on_select = &Treeview::on_select;
61 ✗ this->impl.on_contextmenu = &Treeview::on_contextmenu;
62 ✗ this->impl.on_dblclick = &Treeview::on_dblclick;
63
64 ✗ this->attachNativeControl(&this->impl.ctrl);
65 ✗ }
66
67 ✗ intptr_t Treeview::addIcon(Icon const& icon)
68 {
69 ✗ this->failIfNotCreated("Treeview::addIcon");
70
71 ✗ gate_intptr_t itemKey = InvalidIcon;
72 ✗ result_t result = gate_ui_treeview_add_icon(&this->impl, icon.c_impl(), &itemKey);
73 ✗ GATEXX_CHECK_EXCEPTION(result);
74 ✗ return itemKey;
75 }
76 ✗ intptr_t Treeview::addIcon(RasterImage const& image)
77 {
78 ✗ this->failIfNotCreated("Treeview::addIcon");
79
80 ✗ gate_intptr_t itemKey = InvalidIcon;
81 ✗ result_t result = gate_ui_treeview_add_icon_image(&this->impl, image.c_impl(), &itemKey);
82 ✗ GATEXX_CHECK_EXCEPTION(result);
83 ✗ return itemKey;
84 }
85
86
87 ✗ Treeview::item_t Treeview::addItem(item_t const* parent, String const& text, void* itemparam, intptr_t iconKey)
88 {
89 ✗ this->failIfNotCreated("Treeview::addItem");
90
91 ✗ item_t item = item_t();
92 ✗ result_t result = gate_ui_treeview_add(&this->impl, parent, text.c_impl(), iconKey, itemparam, &item);
93 ✗ GATEXX_CHECK_EXCEPTION(result);
94 ✗ return item;
95 }
96 ✗ void* Treeview::getItemParam(item_t item)
97 {
98 ✗ this->failIfNotCreated("Treeview::getItemParam");
99 ✗ return gate_ui_treeview_get_itemparam(&this->impl, item);
100 }
101 ✗ String Treeview::getItemText(item_t item)
102 {
103 ✗ this->failIfNotCreated("Treeview::getItemText");
104
105 gate_string_t text;
106 ✗ result_t result = gate_ui_treeview_get_text(&this->impl, item, &text);
107 ✗ GATEXX_CHECK_EXCEPTION(result);
108 ✗ return String::createFrom(text);
109 }
110 ✗ void Treeview::setItemText(item_t item, String const& text)
111 {
112 ✗ this->failIfNotCreated("Treeview::setItemText");
113 ✗ result_t result = gate_ui_treeview_set_text(&this->impl, item, text.c_impl());
114 ✗ GATEXX_CHECK_EXCEPTION(result);
115 ✗ }
116 ✗ bool_t Treeview::isItemExpanded(item_t item)
117 {
118 ✗ this->failIfNotCreated("Treeview::isItemExpanded");
119 ✗ return gate_ui_treeview_is_expanded(&this->impl, item);
120 }
121 ✗ void Treeview::expandItem(item_t item)
122 {
123 ✗ this->failIfNotCreated("Treeview::expandItem");
124 ✗ result_t result = gate_ui_treeview_set_expanded(&this->impl, item, true);
125 ✗ GATEXX_CHECK_EXCEPTION(result);
126 ✗ }
127 ✗ void Treeview::collapseItem(item_t item)
128 {
129 ✗ this->failIfNotCreated("Treeview::collapseItem");
130 ✗ result_t result = gate_ui_treeview_set_expanded(&this->impl, item, false);
131 ✗ GATEXX_CHECK_EXCEPTION(result);
132 ✗ }
133 ✗ bool_t Treeview::removeItem(item_t item)
134 {
135 ✗ if (!this->isCreated())
136 {
137 ✗ return false;
138 }
139 ✗ return GATE_SUCCEEDED(gate_ui_treeview_remove(&this->impl, item));
140 }
141 ✗ bool_t Treeview::getParentItem(item_t item, item_t& parent)
142 {
143 ✗ if (!this->isCreated())
144 {
145 ✗ return false;
146 }
147 ✗ result_t res = gate_ui_treeview_get_parent(&this->impl, item, &parent);
148 ✗ return GATE_SUCCEEDED(res);
149 }
150 ✗ Array<Treeview::item_t> Treeview::getItemChildren(item_t item)
151 {
152 ✗ this->failIfNotCreated("Treeview::getItemChildren");
153 gate_array_t arr;
154 ✗ result_t result = gate_ui_treeview_get_children(&this->impl, item, &arr);
155 ✗ GATEXX_CHECK_EXCEPTION(result);
156 ✗ Array<Treeview::item_t> ret = Array<Treeview::item_t>::createFrom(arr);
157 ✗ gate_array_release(&arr);
158 ✗ return ret;
159 }
160
161 ✗ bool_t Treeview::getSelectedItem(item_t& item)
162 {
163 ✗ if (!this->isCreated())
164 {
165 ✗ return false;
166 }
167 ✗ result_t res = gate_ui_treeview_get_selected_item(&this->impl, &item);
168 ✗ return GATE_SUCCEEDED(res);
169 }
170 ✗ void Treeview::selectItem(item_t item)
171 {
172 ✗ this->failIfNotCreated("Treeview::selectItem");
173 ✗ result_t result = gate_ui_treeview_select_item(&this->impl, item);
174 ✗ GATEXX_CHECK_EXCEPTION(result);
175 ✗ }
176
177 ✗ void Treeview::onSelect(item_t item)
178 {
179 ItemArg arg;
180 ✗ arg.Item = item;
181 ✗ this->SelectEvent(this, &arg);
182 ✗ }
183 ✗ void Treeview::onContextMenu(item_t item)
184 {
185 ItemArg arg;
186 ✗ arg.Item = item;
187 ✗ this->ContextMenuEvent(this, &arg);
188
189 ✗ }
190 ✗ void Treeview::onDblClick(item_t item)
191 {
192 ItemArg arg;
193 ✗ arg.Item = item;
194 ✗ this->DblClickEvent(this, &arg);
195 ✗ }
196
197 ✗ void Treeview::on_select(gate_ui_ctrl_t* sender, item_t item)
198 {
199 ✗ Treeview* trvw = static_cast<Treeview*>(gate_ui_ctrl_get_userparam(sender));
200 try {
201 ✗ trvw->onSelect(item);
202 }
203 ✗ catch (...) {}
204 ✗ }
205 ✗ void Treeview::on_contextmenu(gate_ui_ctrl_t* sender, item_t item)
206 {
207 ✗ Treeview* trvw = static_cast<Treeview*>(gate_ui_ctrl_get_userparam(sender));
208 try {
209 ✗ trvw->onContextMenu(item);
210 }
211 ✗ catch (...) {}
212 ✗ }
213 ✗ void Treeview::on_dblclick(gate_ui_ctrl_t* sender, item_t item)
214 {
215 ✗ Treeview* trvw = static_cast<Treeview*>(gate_ui_ctrl_get_userparam(sender));
216 try {
217 ✗ trvw->onDblClick(item);
218 }
219 ✗ catch (...) {}
220 ✗ }
221
222 } // end of namespace ui
223 } // end of namespace gate
224
225