GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_listviews.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 174 406 42.9%
Functions: 38 84 45.2%
Branches: 42 238 17.6%

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/listviews.hpp"
30
31 namespace gate
32 {
33 namespace ui
34 {
35
36 size_t const Listbox::InvalidIndex = GATE_UI_LISTBOX_INVALID_INDEX;
37
38 1 Listbox::Listbox()
39 1 : Control(&impl.ctrl)
40 {
41 1 Mem::clear(&this->impl, sizeof(this->impl));
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_ui_ctrl_init(&this->impl.ctrl);
43 1 }
44 2 Listbox::~Listbox() noexcept
45 {
46
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
2 if (this->isCreated())
47 {
48 this->destroy();
49 }
50 2 }
51
52 1 void Listbox::create(ControlContainer& parent, Position const& pose, uint32_t flags)
53 {
54 1 this->failIfCreated("Listbox::create");
55
56 1 result_t result = gate_ui_listbox_create(&this->impl, *parent, &pose, flags, this);
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
58
59 1 this->impl.on_select = &Listbox::on_select;
60 1 this->impl.on_contextmenu = &Listbox::on_contextmenu;
61 1 this->impl.on_open = &Listbox::on_open;
62
63 1 this->attachNativeControl(&this->impl.ctrl);
64 1 }
65 27 void Listbox::addItem(String const& text, void* param)
66 {
67 27 result_t result = gate_ui_listbox_insert_item(&this->impl, NULL, text.c_impl(), param);
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 GATEXX_CHECK_EXCEPTION(result);
69 27 }
70 void Listbox::insertItem(size_t index, String const& text, void* param)
71 {
72 result_t result = gate_ui_listbox_insert_item(&this->impl, &index, text.c_impl(), param);
73 GATEXX_CHECK_EXCEPTION(result);
74 }
75 5 bool_t Listbox::removeItem(size_t index)
76 {
77 5 result_t result = gate_ui_listbox_remove_item(&this->impl, index);
78 5 return GATE_SUCCEEDED(result);
79 }
80 1 void Listbox::removeAllItems()
81 {
82 1 result_t result = gate_ui_listbox_remove_all_items(&this->impl);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
84 1 }
85 6 size_t Listbox::getItemCount()
86 {
87 6 return gate_ui_listbox_get_item_count(&this->impl);
88 }
89 1 void* Listbox::getItemParam(size_t index)
90 {
91 1 return gate_ui_listbox_get_item_param(&this->impl, index);
92 }
93 1 size_t Listbox::findItemParam(void* param, size_t startAtIndex)
94 {
95 1 size_t ret = 0;
96
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listbox_find_param(&this->impl, param, startAtIndex, &ret);
97
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
98 1 return ret;
99 }
100 1 String Listbox::getItemText(size_t index)
101 {
102 gate_string_t text;
103
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listbox_get_text(&this->impl, index, &text);
104
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
105 2 return String::createFrom(text);
106 }
107 1 void Listbox::setItemText(size_t index, String const& text)
108 {
109 1 result_t result = gate_ui_listbox_set_text(&this->impl, index, text.c_impl());
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
111 1 }
112 1 bool_t Listbox::getSelectedItem(size_t& index)
113 {
114 1 index = gate_ui_listbox_get_selected_item(&this->impl);
115 1 return index != Listbox::InvalidIndex;
116 }
117 1 void Listbox::setSelectedItem(size_t index)
118 {
119 1 result_t result = gate_ui_listbox_set_selected_item(&this->impl, index);
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
121 1 }
122 void Listbox::setNoSelectedItem()
123 {
124 Listbox::setSelectedItem(Listbox::InvalidIndex);
125 }
126
127
128 void Listbox::onSelect(size_t index)
129 {
130 IndexArg arg;
131 arg.ListIndex = index;
132 this->SelectEvent(this, &arg);
133
134 }
135 void Listbox::onContextMenu(size_t index)
136 {
137 IndexArg arg;
138 arg.ListIndex = index;
139 this->ContextMenuEvent(this, &arg);
140
141 }
142 void Listbox::onOpen(size_t index)
143 {
144 IndexArg arg;
145 arg.ListIndex = index;
146 this->OpenEvent(this, &arg);
147 }
148
149 void Listbox::on_select(gate_ui_ctrl_t* sender, size_t index)
150 {
151 Listbox* lstbox = static_cast<Listbox*>(gate_ui_ctrl_get_userparam(sender));
152 try {
153 lstbox->onSelect(index);
154 }
155 catch (...) {}
156 }
157 void Listbox::on_contextmenu(gate_ui_ctrl_t* sender, size_t index)
158 {
159 Listbox* lstbox = static_cast<Listbox*>(gate_ui_ctrl_get_userparam(sender));
160 try {
161 lstbox->onContextMenu(index);
162 }
163 catch (...) {}
164
165 }
166 void Listbox::on_open(gate_ui_ctrl_t* sender, size_t index)
167 {
168 Listbox* lstbox = static_cast<Listbox*>(gate_ui_ctrl_get_userparam(sender));
169 try {
170 lstbox->onOpen(index);
171 }
172 catch (...) {}
173 }
174
175
176
177
178
179
180
181
182
183 size_t const Listview::InvalidIndex = GATE_UI_LISTVIEW_INVALID_INDEX;
184 intptr_t const Listview::InvalidIcon = GATE_UI_LISTVIEW_INVALID_ICON;
185
186 uint32_t const Listview::Flag_Multiselect = GATE_UI_FLAG_LISTVIEW_MULTISELECT;
187 uint32_t const Listview::Flag_Checkboxes = GATE_UI_FLAG_LISTVIEW_CHECKBOXES;
188 uint32_t const Listview::Flag_Icons = GATE_UI_FLAG_LISTVIEW_ICONS;
189
190
191
192 uint32_t const Listview::Column_Left = GATE_UI_LISTVIEW_COLUMN_LEFT;
193 uint32_t const Listview::Column_Right = GATE_UI_LISTVIEW_COLUMN_RIGHT;
194 uint32_t const Listview::Column_Center = GATE_UI_LISTVIEW_COLUMN_CENTER;
195
196
197 3 Listview::Column::Column(String const& title, uint32_t width, uint32_t flags)
198 {
199 3 gate_string_duplicate(&this->title, title.c_impl());
200 3 this->width = width;
201 3 this->flags = flags;
202 3 }
203 5 Listview::Column::Column(Column const& src)
204 {
205 5 gate_string_duplicate(&this->title, &src.title);
206 5 this->width = src.width;
207 5 this->flags = src.flags;
208 5 }
209 Listview::Column& Listview::Column::operator=(Column const& that)
210 {
211 if (this != &that)
212 {
213 gate_string_release(&this->title);
214 gate_string_duplicate(&this->title, &that.title);
215 this->width = that.width;
216 this->flags = that.flags;
217 }
218 return *this;
219 }
220 16 Listview::Column::~Column()
221 {
222 8 gate_string_release(&this->title);
223 8 }
224
225
226
227
228 1 Listview::Listview()
229 1 : Control(&impl.ctrl)
230 {
231 1 Mem::clear(&this->impl, sizeof(this->impl));
232
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_ui_ctrl_init(&this->impl.ctrl);
233 1 }
234 2 Listview::~Listview() noexcept
235 {
236 2 this->destroy();
237 2 }
238 1 void Listview::create(ControlContainer& parent, Position const& pose, uint32_t flags)
239 {
240 1 this->failIfCreated("Listview::create");
241
242 1 result_t result = gate_ui_listview_create(&this->impl, *parent, &pose, flags, this);
243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
244
245 1 this->impl.on_select = &Listview::on_select;
246 1 this->impl.on_unselect = &Listview::on_unselect;
247 1 this->impl.on_contextmenu = &Listview::on_contextmenu;
248 1 this->impl.on_open = &Listview::on_open;
249
250 1 this->attachNativeControl(&this->impl.ctrl);
251 1 }
252
253 1 void Listview::setColumns(gate_ui_listview_column_t const* columns, size_t column_count)
254 {
255 1 this->failIfNotCreated("Listview::setColumns");
256 1 result_t result = gate_ui_listview_set_columns(&this->impl, columns, column_count);
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
258 1 }
259 1 void Listview::setColumns(Column const* columns, size_t column_count)
260 {
261 GATE_DEBUG_ASSERT(sizeof(Column) == sizeof(gate_ui_listview_column_t));
262 1 this->setColumns(static_cast<gate_ui_listview_column_t const*>(columns), column_count);
263 1 }
264 1 void Listview::setColumns(Array<Column> const& columns)
265 {
266 1 this->setColumns(&columns[0], columns.size());
267 1 }
268
269 size_t Listview::getColumnCount()
270 {
271 this->failIfNotCreated("Listview::setColumnCount");
272 return gate_ui_listview_get_column_count(&this->impl);
273 }
274 bool_t Listview::getColumn(size_t index, String& text, uint32_t& width)
275 {
276 this->failIfNotCreated("Listview::getColumn");
277 gate_string_t txt;
278 result_t res = gate_ui_listview_get_column(&this->impl, index, &txt, &width);
279 if (GATE_SUCCEEDED(res))
280 {
281 text = String::createFrom(txt);
282 return true;
283 }
284 return false;
285 }
286
287 intptr_t Listview::addIcon(Icon const& icon)
288 {
289 this->failIfNotCreated("Listview::addIcon");
290 gate_intptr_t iconKey = Listview::InvalidIcon;
291 result_t result = gate_ui_listview_add_icon(&this->impl, icon.c_impl(), &iconKey);
292 GATEXX_CHECK_EXCEPTION(result);
293 return iconKey;
294 }
295 intptr_t Listview::addIcon(RasterImage const& image)
296 {
297 this->failIfNotCreated("Listview::addIcon");
298 gate_intptr_t iconKey = Listview::InvalidIcon;
299 result_t result = gate_ui_listview_add_icon_image(&this->impl, image.c_impl(), &iconKey);
300 GATEXX_CHECK_EXCEPTION(result);
301 return iconKey;
302 }
303
304
305 32 size_t Listview::getItemCount()
306 {
307 32 this->failIfNotCreated("Listview::getItemCount");
308 32 return gate_ui_listview_get_item_count(&this->impl);
309 }
310
311 1 void Listview::beginTransaction()
312 {
313 1 result_t result = gate_ui_listview_begin_transaction(&this->impl);
314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
315 1 }
316 1 void Listview::endTransaction()
317 {
318 1 result_t result = gate_ui_listview_end_transaction(&this->impl);
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
320 1 }
321
322 25 size_t Listview::addItem(String const& text, void* itemparam, intptr_t iconKey)
323 {
324 25 this->failIfNotCreated("Listview::addItem");
325 25 result_t result = gate_ui_listview_insert_item(&this->impl, NULL, text.c_impl(), iconKey, itemparam);
326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 GATEXX_CHECK_EXCEPTION(result);
327 25 return this->getItemCount() - 1;
328 }
329 1 size_t Listview::insertItem(size_t insertAt, String const& text, void* itemparam, intptr_t iconKey)
330 {
331 1 this->failIfNotCreated("Listview::insertItem");
332 1 size_t count = this->getItemCount();
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (insertAt > count)
334 {
335 return this->addItem(text, itemparam, iconKey);
336 }
337 else
338 {
339 1 result_t result = gate_ui_listview_insert_item(&this->impl, &insertAt, text.c_impl(), iconKey, itemparam);
340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
341 1 return insertAt;
342 }
343 }
344
345 1 size_t Listview::findItemParam(void* itemparam, size_t startAt)
346 {
347
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->failIfNotCreated("Listview::findItemParam");
348 1 size_t found = 0;
349
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listview_find_param(&this->impl, itemparam, startAt, &found);
350
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
351 1 return found;
352 }
353
354 1 void* Listview::getItemParam(size_t index)
355 {
356 1 this->failIfNotCreated("Listview::getItemParam");
357 1 return gate_ui_listview_get_item_param(&this->impl, index);
358 }
359 1 String Listview::getItemText(size_t index, size_t column)
360 {
361
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->failIfNotCreated("Listview::getItemText");
362 gate_string_t text;
363
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listview_get_text(&this->impl, index, column, &text);
364
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
365 2 return String::createFrom(text);
366 }
367 26 void Listview::setItemText(size_t index, String const& text, size_t column)
368 {
369 26 this->failIfNotCreated("Listview::setItemText");
370 26 result_t result = gate_ui_listview_set_text(&this->impl, index, column, text.c_impl());
371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 GATEXX_CHECK_EXCEPTION(result);
372 26 }
373 bool_t Listview::isItemSelected(size_t index)
374 {
375 this->failIfNotCreated("Listview::isItemSelected");
376 return gate_ui_listview_is_selected(&this->impl, index);
377 }
378 2 void Listview::setItemSelected(size_t index, bool_t selected)
379 {
380 2 this->failIfNotCreated("Listview::setItemSelected");
381 2 result_t result = gate_ui_listview_select_item(&this->impl, index, selected);
382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
383 2 }
384 bool_t Listview::isItemChecked(size_t index)
385 {
386 this->failIfNotCreated("Listview::isItemChecked");
387 return gate_ui_listview_is_checked(&this->impl, index);
388 }
389 1 void Listview::setItemChecked(size_t index, bool_t checked)
390 {
391 1 this->failIfNotCreated("Listview::setItemChecked");
392 1 result_t result = gate_ui_listview_set_checked(&this->impl, index, checked);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
394 1 }
395 1 bool_t Listview::getSelectedItem(size_t& index)
396 {
397 1 this->failIfNotCreated("Listview::getSelectedItem");
398 1 return GATE_SUCCEEDED(gate_ui_listview_get_selected_item(&this->impl, &index));
399 }
400 1 Array<size_t> Listview::getSelectedItems()
401 {
402
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->failIfNotCreated("Listview::getSelectedItems");
403 gate_array_t arr;
404
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listview_get_selected_items(&this->impl, &arr);
405
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
406
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 size_t cnt = gate_array_length(&arr);
407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (cnt == 0)
408 {
409 gate_array_release(&arr);
410 return Array<size_t>();
411 }
412 else
413 {
414
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 size_t const* ptr = static_cast<size_t const*>(gate_array_get(&arr, 0));
415
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Array<size_t> ret(ptr, cnt);
416
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_array_release(&arr);
417 1 return ret;
418 }
419 }
420 1 Array<size_t> Listview::getCheckedItems()
421 {
422
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->failIfNotCreated("Listview::setCheckedItems");
423 gate_array_t arr;
424
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_ui_listview_get_checked_items(&this->impl, &arr);
425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
426
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 size_t cnt = gate_array_length(&arr);
427
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (cnt == 0)
428 {
429
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_array_release(&arr);
430 1 return Array<size_t>();
431 }
432 else
433 {
434 size_t const* ptr = static_cast<size_t const*>(gate_array_get(&arr, 0));
435 Array<size_t> ret(ptr, cnt);
436 gate_array_release(&arr);
437 return ret;
438 }
439
440 }
441 5 bool_t Listview::removeItem(size_t index)
442 {
443 5 this->failIfNotCreated("Listview::removeItem");
444 5 return GATE_SUCCEEDED(gate_ui_listview_remove_item(&this->impl, index));
445 }
446
447 1 void Listview::removeAllItems()
448 {
449 1 this->failIfNotCreated("Listview::removeAllItems");
450 1 gate_ui_listview_remove_all_items(&this->impl);
451 1 }
452
453 void Listview::onSelect(size_t index, void* param)
454 {
455 IndexArg arg;
456 arg.ListIndex = index;
457 this->SelectEvent(this, &arg);
458 }
459 void Listview::onUnselect(size_t index, void* param)
460 {
461 IndexArg arg;
462 arg.ListIndex = index;
463 this->UnselectEvent(this, &arg);
464 }
465 void Listview::onContextMenu(size_t index, void* param)
466 {
467 IndexArg arg;
468 arg.ListIndex = index;
469 this->ContextMenuEvent(this, &arg);
470 }
471 void Listview::onOpen(size_t index, void* param)
472 {
473 IndexArg arg;
474 arg.ListIndex = index;
475 this->OpenEvent(this, &arg);
476 }
477
478
479 void Listview::on_select(gate_ui_ctrl_t* sender, size_t index, void* param)
480 {
481 Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender));
482 try {
483 lstvw->onSelect(index, param);
484 }
485 catch (...) {}
486 }
487 void Listview::on_unselect(gate_ui_ctrl_t* sender, size_t index, void* param)
488 {
489 Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender));
490 try {
491 lstvw->onUnselect(index, param);
492 }
493 catch (...) {}
494 }
495 void Listview::on_contextmenu(gate_ui_ctrl_t* sender, size_t index, void* param)
496 {
497 Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender));
498 try {
499 lstvw->onContextMenu(index, param);
500 }
501 catch (...) {}
502 }
503 void Listview::on_open(gate_ui_ctrl_t* sender, size_t index, void* param)
504 {
505 Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender));
506 try {
507 lstvw->onOpen(index, param);
508 }
509 catch (...) {}
510 }
511
512
513
514
515
516
517
518
519 size_t const Itemview::InvalidIndex = GATE_UI_ITEMVIEW_INVALID_INDEX;
520 intptr_t const Itemview::InvalidIcon = GATE_UI_ITEMVIEW_INVALID_ICON;
521
522 uint32_t const Itemview::Flag_Icons = GATE_UI_FLAG_ITEMVIEW_ICONS;
523
524 Itemview::Itemview()
525 : Control(&impl.ctrl)
526 {
527 Mem::clear(&this->impl, sizeof(this->impl));
528 gate_ui_ctrl_init(&this->impl.ctrl);
529 }
530 Itemview::~Itemview() noexcept
531 {
532 this->destroy();
533 }
534
535 void Itemview::create(ControlContainer& parent, Position const& pose, uint32_t flags)
536 {
537 this->failIfCreated("Itemview::create");
538 if (!parent.isCreated())
539 {
540 GATEXX_RAISE_ERROR(results::InvalidState);
541 }
542
543 result_t result = gate_ui_itemview_create(&this->impl, *parent, &pose, flags, this);
544 GATEXX_CHECK_ERROR(result);
545
546 this->impl.on_select = &Itemview::on_select;
547
548 this->attachNativeControl(&this->impl.ctrl);
549 }
550
551 intptr_t Itemview::addIcon(Icon const& icon)
552 {
553 this->failIfNotCreated("Itemview::addIcon");
554 gate_intptr_t iconKey = Listview::InvalidIcon;
555 result_t result = gate_ui_itemview_add_icon(&this->impl, icon.c_impl(), &iconKey);
556 GATEXX_CHECK_EXCEPTION(result);
557 return iconKey;
558 }
559 intptr_t Itemview::addIcon(RasterImage const& image)
560 {
561 this->failIfNotCreated("Itemview::addIcon");
562 gate_intptr_t iconKey = Listview::InvalidIcon;
563 result_t result = gate_ui_itemview_add_icon_image(&this->impl, image.c_impl(), &iconKey);
564 GATEXX_CHECK_EXCEPTION(result);
565 return iconKey;
566 }
567
568 size_t Itemview::getItemCount()
569 {
570 this->failIfNotCreated("Itemview::getItemCount");
571 return gate_ui_itemview_get_count(&this->impl);
572 }
573 size_t Itemview::addItem(String const& title, String const& subtitle, String const& additional, intptr_t iconKey, void* itemparam)
574 {
575 this->failIfNotCreated("Itemview::addItem");
576 size_t count = gate_ui_itemview_get_count(&this->impl);
577 return this->insertItem(count, title, subtitle, additional, iconKey, itemparam);
578 }
579 size_t Itemview::insertItem(size_t insertAt, String const& title, String const& subtitle, String const& additional, intptr_t iconKey, void* itemparam)
580 {
581 this->failIfNotCreated("Itemview::insertItem");
582 size_t count = gate_ui_itemview_get_count(&this->impl);
583 if (insertAt > count)
584 {
585 insertAt = count;
586 }
587 result_t result = gate_ui_itemview_insert(&this->impl, &insertAt, title.c_impl(), subtitle.c_impl(), additional.c_impl(), iconKey, itemparam);
588 GATEXX_CHECK_EXCEPTION(result);
589 return insertAt;
590 }
591
592 size_t Itemview::findItemParam(void* itemparam, size_t startAt)
593 {
594 this->failIfNotCreated("Itemview::findItemParam");
595 gate_size_t ret = 0;
596 result_t result = gate_ui_itemview_find_param(&this->impl, itemparam, startAt, &ret);
597 GATEXX_CHECK_EXCEPTION(result);
598 return ret;
599 }
600 void* Itemview::getItemParam(size_t index)
601 {
602 this->failIfNotCreated("Itemview::getItemParam");
603 return gate_ui_itemview_get_item_param(&this->impl, index);
604 }
605 String Itemview::getItemTitle(size_t index)
606 {
607 this->failIfNotCreated("Itemview::getItemTitle");
608 gate_string_t tmp = GATE_STRING_INIT_EMPTY;
609 result_t result = gate_ui_itemview_get_text(&this->impl, index, &tmp, NULL, NULL);
610 GATEXX_CHECK_EXCEPTION(result);
611 return String::createFrom(tmp);
612 }
613 void Itemview::setItemTitle(size_t index, String const& text)
614 {
615 this->failIfNotCreated("Itemview::setItemTitle");
616 result_t result = gate_ui_itemview_set_text(&this->impl, index, text.c_impl(), NULL, NULL);
617 GATEXX_CHECK_EXCEPTION(result);
618 }
619 String Itemview::getItemSubtitle(size_t index)
620 {
621 this->failIfNotCreated("Itemview::getItemSubtitle");
622 gate_string_t tmp = GATE_STRING_INIT_EMPTY;
623 result_t result = gate_ui_itemview_get_text(&this->impl, index, NULL, &tmp, NULL);
624 GATEXX_CHECK_EXCEPTION(result);
625 return String::createFrom(tmp);
626 }
627 void Itemview::setItemSubtitle(size_t index, String const& text)
628 {
629 this->failIfNotCreated("Itemview::setItemSubtitle");
630 result_t result = gate_ui_itemview_set_text(&this->impl, index, NULL, text.c_impl(), NULL);
631 GATEXX_CHECK_EXCEPTION(result);
632 }
633 String Itemview::getItemAddiontialText(size_t index)
634 {
635 this->failIfNotCreated("Itemview::getItemAddiontialText");
636 gate_string_t tmp = GATE_STRING_INIT_EMPTY;
637 result_t result = gate_ui_itemview_get_text(&this->impl, index, NULL, NULL, &tmp);
638 GATEXX_CHECK_EXCEPTION(result);
639 return String::createFrom(tmp);
640 }
641 void Itemview::setItemAdditionalText(size_t index, String const& text)
642 {
643 this->failIfNotCreated("Itemview::setItemAdditionalText");
644 result_t result = gate_ui_itemview_set_text(&this->impl, index, NULL, NULL, text.c_impl());
645 GATEXX_CHECK_EXCEPTION(result);
646 }
647 bool_t Itemview::isItemSelected(size_t index)
648 {
649 this->failIfNotCreated("Itemview::isItemSelected");
650 return gate_ui_itemview_is_selected(&this->impl, index);
651 }
652 void Itemview::setItemSelected(size_t index)
653 {
654 this->failIfNotCreated("Itemview::setItemSelected");
655 result_t result = gate_ui_itemview_select_item(&this->impl, index);
656 GATEXX_CHECK_EXCEPTION(result);
657 }
658 bool_t Itemview::getSelectedItem(size_t& index)
659 {
660 bool_t ret = false;
661 if (this->isCreated())
662 {
663 result_t result = gate_ui_itemview_get_selected_item(&this->impl, &index);
664 if (GATE_SUCCEEDED(result))
665 {
666 ret = true;
667 }
668 }
669 return ret;
670 }
671
672 bool_t Itemview::removeItem(size_t index)
673 {
674 this->failIfNotCreated("Itemview::removeItem");
675 result_t result = gate_ui_itemview_remove(&this->impl, index);
676 return GATE_SUCCEEDED(result);
677 }
678 void Itemview::removeAllItems()
679 {
680 this->failIfNotCreated("Itemview::removeAllItems");
681 result_t result = gate_ui_itemview_remove_all_items(&this->impl);
682 GATEXX_CHECK_EXCEPTION(result);
683 }
684
685 void Itemview::onSelect(size_t index, void* itemparam)
686 {
687 IndexArg arg;
688 arg.ListIndex = index;
689 this->SelectEvent(this, &arg);
690 }
691
692 void Itemview::on_select(gate_ui_ctrl_t* sender, size_t index, void* item_param)
693 {
694 Itemview* itemview = static_cast<Itemview*>(gate_ui_ctrl_get_userparam(sender));
695 try {
696 itemview->onSelect(index, item_param);
697 }
698 catch (...) {}
699 }
700
701
702
703
704
705
706 } // end of namespace ui
707 } // end of namespace gate
708
709