| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, 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_ui_listview_column_create(this, title.c_impl(), width, flags); | |
| 200 | 3 | } | |
| 201 | 5 | Listview::Column::Column(Column const& src) | |
| 202 | { | ||
| 203 | 5 | gate_ui_listview_column_create(this, &src.title, src.width, src.flags); | |
| 204 | 5 | } | |
| 205 | ✗ | Listview::Column& Listview::Column::operator=(Column const& that) | |
| 206 | { | ||
| 207 | ✗ | if (this != &that) | |
| 208 | { | ||
| 209 | ✗ | gate_string_release(&this->title); | |
| 210 | ✗ | gate_string_duplicate(&this->title, &that.title); | |
| 211 | ✗ | this->width = that.width; | |
| 212 | ✗ | this->flags = that.flags; | |
| 213 | } | ||
| 214 | ✗ | return *this; | |
| 215 | } | ||
| 216 | 16 | Listview::Column::~Column() | |
| 217 | { | ||
| 218 | 8 | gate_ui_listview_columns_release(this, 1); | |
| 219 | 8 | } | |
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | |||
| 224 | 1 | Listview::Listview() | |
| 225 | 1 | : Control(&impl.ctrl) | |
| 226 | { | ||
| 227 | 1 | Mem::clear(&this->impl, sizeof(this->impl)); | |
| 228 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_ui_ctrl_init(&this->impl.ctrl); |
| 229 | 1 | } | |
| 230 | 2 | Listview::~Listview() noexcept | |
| 231 | { | ||
| 232 | 2 | this->destroy(); | |
| 233 | 2 | } | |
| 234 | 1 | void Listview::create(ControlContainer& parent, Position const& pose, uint32_t flags) | |
| 235 | { | ||
| 236 | 1 | this->failIfCreated("Listview::create"); | |
| 237 | |||
| 238 | 1 | result_t result = gate_ui_listview_create(&this->impl, *parent, &pose, flags, this); | |
| 239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 240 | |||
| 241 | 1 | this->impl.on_select = &Listview::on_select; | |
| 242 | 1 | this->impl.on_unselect = &Listview::on_unselect; | |
| 243 | 1 | this->impl.on_contextmenu = &Listview::on_contextmenu; | |
| 244 | 1 | this->impl.on_open = &Listview::on_open; | |
| 245 | |||
| 246 | 1 | this->attachNativeControl(&this->impl.ctrl); | |
| 247 | 1 | } | |
| 248 | |||
| 249 | 1 | void Listview::setColumns(gate_ui_listview_column_t const* columns, size_t column_count) | |
| 250 | { | ||
| 251 | 1 | this->failIfNotCreated("Listview::setColumns"); | |
| 252 | 1 | result_t result = gate_ui_listview_set_columns(&this->impl, columns, column_count); | |
| 253 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 254 | 1 | } | |
| 255 | 1 | void Listview::setColumns(Column const* columns, size_t column_count) | |
| 256 | { | ||
| 257 | GATE_DEBUG_ASSERT(sizeof(Column) == sizeof(gate_ui_listview_column_t)); | ||
| 258 | 1 | this->setColumns(static_cast<gate_ui_listview_column_t const*>(columns), column_count); | |
| 259 | 1 | } | |
| 260 | 1 | void Listview::setColumns(Array<Column> const& columns) | |
| 261 | { | ||
| 262 | 1 | this->setColumns(&columns[0], columns.size()); | |
| 263 | 1 | } | |
| 264 | |||
| 265 | 1 | size_t Listview::getColumnCount() | |
| 266 | { | ||
| 267 | 1 | this->failIfNotCreated("Listview::setColumnCount"); | |
| 268 | 1 | return gate_ui_listview_get_column_count(&this->impl); | |
| 269 | } | ||
| 270 | 3 | bool_t Listview::getColumn(size_t index, String& text, uint32_t& width) | |
| 271 | { | ||
| 272 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | this->failIfNotCreated("Listview::getColumn"); |
| 273 | gate_string_t txt; | ||
| 274 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t res = gate_ui_listview_get_column(&this->impl, index, &txt, &width); |
| 275 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (GATE_SUCCEEDED(res)) |
| 276 | { | ||
| 277 | 3 | text = String::createFrom(txt); | |
| 278 | 3 | return true; | |
| 279 | } | ||
| 280 | ✗ | return false; | |
| 281 | } | ||
| 282 | |||
| 283 | ✗ | intptr_t Listview::addIcon(Icon const& icon) | |
| 284 | { | ||
| 285 | ✗ | this->failIfNotCreated("Listview::addIcon"); | |
| 286 | ✗ | gate_intptr_t iconKey = Listview::InvalidIcon; | |
| 287 | ✗ | result_t result = gate_ui_listview_add_icon(&this->impl, icon.c_impl(), &iconKey); | |
| 288 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 289 | ✗ | return iconKey; | |
| 290 | } | ||
| 291 | 1 | intptr_t Listview::addIcon(RasterImage const& image) | |
| 292 | { | ||
| 293 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Listview::addIcon"); |
| 294 | 1 | gate_intptr_t iconKey = Listview::InvalidIcon; | |
| 295 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | result_t result = gate_ui_listview_add_icon_image(&this->impl, image.c_impl(), &iconKey); |
| 296 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 297 | 1 | return iconKey; | |
| 298 | } | ||
| 299 | |||
| 300 | |||
| 301 | 32 | size_t Listview::getItemCount() | |
| 302 | { | ||
| 303 | 32 | this->failIfNotCreated("Listview::getItemCount"); | |
| 304 | 32 | return gate_ui_listview_get_item_count(&this->impl); | |
| 305 | } | ||
| 306 | |||
| 307 | 1 | void Listview::beginTransaction() | |
| 308 | { | ||
| 309 | 1 | result_t result = gate_ui_listview_begin_transaction(&this->impl); | |
| 310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 311 | 1 | } | |
| 312 | 1 | void Listview::endTransaction() | |
| 313 | { | ||
| 314 | 1 | result_t result = gate_ui_listview_end_transaction(&this->impl); | |
| 315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 316 | 1 | } | |
| 317 | |||
| 318 | 25 | size_t Listview::addItem(String const& text, void* itemparam, intptr_t iconKey) | |
| 319 | { | ||
| 320 | 25 | this->failIfNotCreated("Listview::addItem"); | |
| 321 | 25 | result_t result = gate_ui_listview_insert_item(&this->impl, NULL, text.c_impl(), iconKey, itemparam); | |
| 322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | GATEXX_CHECK_EXCEPTION(result); |
| 323 | 25 | return this->getItemCount() - 1; | |
| 324 | } | ||
| 325 | 1 | size_t Listview::insertItem(size_t insertAt, String const& text, void* itemparam, intptr_t iconKey) | |
| 326 | { | ||
| 327 | 1 | this->failIfNotCreated("Listview::insertItem"); | |
| 328 | 1 | size_t count = this->getItemCount(); | |
| 329 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (insertAt > count) |
| 330 | { | ||
| 331 | ✗ | return this->addItem(text, itemparam, iconKey); | |
| 332 | } | ||
| 333 | else | ||
| 334 | { | ||
| 335 | 1 | result_t result = gate_ui_listview_insert_item(&this->impl, &insertAt, text.c_impl(), iconKey, itemparam); | |
| 336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 337 | 1 | return insertAt; | |
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | 1 | size_t Listview::findItemParam(void* itemparam, size_t startAt) | |
| 342 | { | ||
| 343 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Listview::findItemParam"); |
| 344 | 1 | size_t found = 0; | |
| 345 |
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); |
| 346 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 347 | 1 | return found; | |
| 348 | } | ||
| 349 | |||
| 350 | 1 | void* Listview::getItemParam(size_t index) | |
| 351 | { | ||
| 352 | 1 | this->failIfNotCreated("Listview::getItemParam"); | |
| 353 | 1 | return gate_ui_listview_get_item_param(&this->impl, index); | |
| 354 | } | ||
| 355 | 1 | String Listview::getItemText(size_t index, size_t column) | |
| 356 | { | ||
| 357 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Listview::getItemText"); |
| 358 | gate_string_t text; | ||
| 359 |
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); |
| 360 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 361 | 2 | return String::createFrom(text); | |
| 362 | } | ||
| 363 | 26 | void Listview::setItemText(size_t index, String const& text, size_t column) | |
| 364 | { | ||
| 365 | 26 | this->failIfNotCreated("Listview::setItemText"); | |
| 366 | 26 | result_t result = gate_ui_listview_set_text(&this->impl, index, column, text.c_impl()); | |
| 367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | GATEXX_CHECK_EXCEPTION(result); |
| 368 | 26 | } | |
| 369 | 1 | bool_t Listview::isItemSelected(size_t index) | |
| 370 | { | ||
| 371 | 1 | this->failIfNotCreated("Listview::isItemSelected"); | |
| 372 | 1 | return gate_ui_listview_is_selected(&this->impl, index); | |
| 373 | } | ||
| 374 | 2 | void Listview::setItemSelected(size_t index, bool_t selected) | |
| 375 | { | ||
| 376 | 2 | this->failIfNotCreated("Listview::setItemSelected"); | |
| 377 | 2 | result_t result = gate_ui_listview_select_item(&this->impl, index, selected); | |
| 378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 379 | 2 | } | |
| 380 | ✗ | bool_t Listview::isItemChecked(size_t index) | |
| 381 | { | ||
| 382 | ✗ | this->failIfNotCreated("Listview::isItemChecked"); | |
| 383 | ✗ | return gate_ui_listview_is_checked(&this->impl, index); | |
| 384 | } | ||
| 385 | 1 | void Listview::setItemChecked(size_t index, bool_t checked) | |
| 386 | { | ||
| 387 | 1 | this->failIfNotCreated("Listview::setItemChecked"); | |
| 388 | 1 | result_t result = gate_ui_listview_set_checked(&this->impl, index, checked); | |
| 389 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 390 | 1 | } | |
| 391 | 1 | bool_t Listview::getSelectedItem(size_t& index) | |
| 392 | { | ||
| 393 | 1 | this->failIfNotCreated("Listview::getSelectedItem"); | |
| 394 | 1 | return GATE_SUCCEEDED(gate_ui_listview_get_selected_item(&this->impl, &index)); | |
| 395 | } | ||
| 396 | 1 | Array<size_t> Listview::getSelectedItems() | |
| 397 | { | ||
| 398 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Listview::getSelectedItems"); |
| 399 | gate_array_t arr; | ||
| 400 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_listview_get_selected_items(&this->impl, &arr); |
| 401 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 402 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t cnt = gate_array_length(&arr); |
| 403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (cnt == 0) |
| 404 | { | ||
| 405 | ✗ | gate_array_release(&arr); | |
| 406 | ✗ | return Array<size_t>(); | |
| 407 | } | ||
| 408 | else | ||
| 409 | { | ||
| 410 |
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)); |
| 411 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Array<size_t> ret(ptr, cnt); |
| 412 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_array_release(&arr); |
| 413 | 1 | return ret; | |
| 414 | } | ||
| 415 | } | ||
| 416 | 1 | Array<size_t> Listview::getCheckedItems() | |
| 417 | { | ||
| 418 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Listview::setCheckedItems"); |
| 419 | gate_array_t arr; | ||
| 420 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_listview_get_checked_items(&this->impl, &arr); |
| 421 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 422 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t cnt = gate_array_length(&arr); |
| 423 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (cnt == 0) |
| 424 | { | ||
| 425 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_array_release(&arr); |
| 426 | 1 | return Array<size_t>(); | |
| 427 | } | ||
| 428 | else | ||
| 429 | { | ||
| 430 | ✗ | size_t const* ptr = static_cast<size_t const*>(gate_array_get(&arr, 0)); | |
| 431 | ✗ | Array<size_t> ret(ptr, cnt); | |
| 432 | ✗ | gate_array_release(&arr); | |
| 433 | ✗ | return ret; | |
| 434 | } | ||
| 435 | |||
| 436 | } | ||
| 437 | 5 | bool_t Listview::removeItem(size_t index) | |
| 438 | { | ||
| 439 | 5 | this->failIfNotCreated("Listview::removeItem"); | |
| 440 | 5 | return GATE_SUCCEEDED(gate_ui_listview_remove_item(&this->impl, index)); | |
| 441 | } | ||
| 442 | |||
| 443 | 1 | void Listview::removeAllItems() | |
| 444 | { | ||
| 445 | 1 | this->failIfNotCreated("Listview::removeAllItems"); | |
| 446 | 1 | gate_ui_listview_remove_all_items(&this->impl); | |
| 447 | 1 | } | |
| 448 | |||
| 449 | ✗ | void Listview::onSelect(size_t index, void* param) | |
| 450 | { | ||
| 451 | IndexArg arg; | ||
| 452 | ✗ | arg.ListIndex = index; | |
| 453 | ✗ | this->SelectEvent(this, &arg); | |
| 454 | ✗ | } | |
| 455 | ✗ | void Listview::onUnselect(size_t index, void* param) | |
| 456 | { | ||
| 457 | IndexArg arg; | ||
| 458 | ✗ | arg.ListIndex = index; | |
| 459 | ✗ | this->UnselectEvent(this, &arg); | |
| 460 | ✗ | } | |
| 461 | ✗ | void Listview::onContextMenu(size_t index, void* param) | |
| 462 | { | ||
| 463 | IndexArg arg; | ||
| 464 | ✗ | arg.ListIndex = index; | |
| 465 | ✗ | this->ContextMenuEvent(this, &arg); | |
| 466 | ✗ | } | |
| 467 | ✗ | void Listview::onOpen(size_t index, void* param) | |
| 468 | { | ||
| 469 | IndexArg arg; | ||
| 470 | ✗ | arg.ListIndex = index; | |
| 471 | ✗ | this->OpenEvent(this, &arg); | |
| 472 | ✗ | } | |
| 473 | |||
| 474 | |||
| 475 | ✗ | void Listview::on_select(gate_ui_ctrl_t* sender, size_t index, void* param) | |
| 476 | { | ||
| 477 | ✗ | Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender)); | |
| 478 | try { | ||
| 479 | ✗ | lstvw->onSelect(index, param); | |
| 480 | } | ||
| 481 | ✗ | catch (...) {} | |
| 482 | ✗ | } | |
| 483 | ✗ | void Listview::on_unselect(gate_ui_ctrl_t* sender, size_t index, void* param) | |
| 484 | { | ||
| 485 | ✗ | Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender)); | |
| 486 | try { | ||
| 487 | ✗ | lstvw->onUnselect(index, param); | |
| 488 | } | ||
| 489 | ✗ | catch (...) {} | |
| 490 | ✗ | } | |
| 491 | ✗ | void Listview::on_contextmenu(gate_ui_ctrl_t* sender, size_t index, void* param) | |
| 492 | { | ||
| 493 | ✗ | Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender)); | |
| 494 | try { | ||
| 495 | ✗ | lstvw->onContextMenu(index, param); | |
| 496 | } | ||
| 497 | ✗ | catch (...) {} | |
| 498 | ✗ | } | |
| 499 | ✗ | void Listview::on_open(gate_ui_ctrl_t* sender, size_t index, void* param) | |
| 500 | { | ||
| 501 | ✗ | Listview* lstvw = static_cast<Listview*>(gate_ui_ctrl_get_userparam(sender)); | |
| 502 | try { | ||
| 503 | ✗ | lstvw->onOpen(index, param); | |
| 504 | } | ||
| 505 | ✗ | catch (...) {} | |
| 506 | ✗ | } | |
| 507 | |||
| 508 | |||
| 509 | |||
| 510 | |||
| 511 | |||
| 512 | |||
| 513 | |||
| 514 | |||
| 515 | size_t const Itemview::InvalidIndex = GATE_UI_ITEMVIEW_INVALID_INDEX; | ||
| 516 | intptr_t const Itemview::InvalidIcon = GATE_UI_ITEMVIEW_INVALID_ICON; | ||
| 517 | |||
| 518 | uint32_t const Itemview::Flag_Icons = GATE_UI_FLAG_ITEMVIEW_ICONS; | ||
| 519 | |||
| 520 | 1 | Itemview::Itemview() | |
| 521 | 1 | : Control(&impl.ctrl) | |
| 522 | { | ||
| 523 | 1 | Mem::clear(&this->impl, sizeof(this->impl)); | |
| 524 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_ui_ctrl_init(&this->impl.ctrl); |
| 525 | 1 | } | |
| 526 | 2 | Itemview::~Itemview() noexcept | |
| 527 | { | ||
| 528 | 2 | this->destroy(); | |
| 529 | 2 | } | |
| 530 | |||
| 531 | 1 | void Itemview::create(ControlContainer& parent, Position const& pose, uint32_t flags) | |
| 532 | { | ||
| 533 | 1 | this->failIfCreated("Itemview::create"); | |
| 534 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!parent.isCreated()) |
| 535 | { | ||
| 536 | ✗ | GATEXX_RAISE_ERROR(results::InvalidState); | |
| 537 | } | ||
| 538 | |||
| 539 | 1 | result_t result = gate_ui_itemview_create(&this->impl, *parent, &pose, flags, this); | |
| 540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 541 | |||
| 542 | 1 | this->impl.on_select = &Itemview::on_select; | |
| 543 | |||
| 544 | 1 | this->attachNativeControl(&this->impl.ctrl); | |
| 545 | 1 | } | |
| 546 | |||
| 547 | ✗ | intptr_t Itemview::addIcon(Icon const& icon) | |
| 548 | { | ||
| 549 | ✗ | this->failIfNotCreated("Itemview::addIcon"); | |
| 550 | ✗ | gate_intptr_t iconKey = Listview::InvalidIcon; | |
| 551 | ✗ | result_t result = gate_ui_itemview_add_icon(&this->impl, icon.c_impl(), &iconKey); | |
| 552 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 553 | ✗ | return iconKey; | |
| 554 | } | ||
| 555 | ✗ | intptr_t Itemview::addIcon(RasterImage const& image) | |
| 556 | { | ||
| 557 | ✗ | this->failIfNotCreated("Itemview::addIcon"); | |
| 558 | ✗ | gate_intptr_t iconKey = Listview::InvalidIcon; | |
| 559 | ✗ | result_t result = gate_ui_itemview_add_icon_image(&this->impl, image.c_impl(), &iconKey); | |
| 560 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 561 | ✗ | return iconKey; | |
| 562 | } | ||
| 563 | |||
| 564 | 1 | size_t Itemview::getItemCount() | |
| 565 | { | ||
| 566 | 1 | this->failIfNotCreated("Itemview::getItemCount"); | |
| 567 | 1 | return gate_ui_itemview_get_count(&this->impl); | |
| 568 | } | ||
| 569 | 4 | size_t Itemview::addItem(String const& title, String const& subtitle, String const& additional, intptr_t iconKey, void* itemparam) | |
| 570 | { | ||
| 571 | 4 | this->failIfNotCreated("Itemview::addItem"); | |
| 572 | 4 | size_t count = gate_ui_itemview_get_count(&this->impl); | |
| 573 | 4 | return this->insertItem(count, title, subtitle, additional, iconKey, itemparam); | |
| 574 | } | ||
| 575 | 4 | size_t Itemview::insertItem(size_t insertAt, String const& title, String const& subtitle, String const& additional, intptr_t iconKey, void* itemparam) | |
| 576 | { | ||
| 577 | 4 | this->failIfNotCreated("Itemview::insertItem"); | |
| 578 | 4 | size_t count = gate_ui_itemview_get_count(&this->impl); | |
| 579 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (insertAt > count) |
| 580 | { | ||
| 581 | ✗ | insertAt = count; | |
| 582 | } | ||
| 583 | 4 | result_t result = gate_ui_itemview_insert(&this->impl, &insertAt, title.c_impl(), subtitle.c_impl(), additional.c_impl(), iconKey, itemparam); | |
| 584 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 585 | 4 | return insertAt; | |
| 586 | } | ||
| 587 | |||
| 588 | 2 | size_t Itemview::findItemParam(void* itemparam, size_t startAt) | |
| 589 | { | ||
| 590 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | this->failIfNotCreated("Itemview::findItemParam"); |
| 591 | 2 | gate_size_t ret = 0; | |
| 592 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_ui_itemview_find_param(&this->impl, itemparam, startAt, &ret); |
| 593 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 594 | 2 | return ret; | |
| 595 | } | ||
| 596 | 2 | void* Itemview::getItemParam(size_t index) | |
| 597 | { | ||
| 598 | 2 | this->failIfNotCreated("Itemview::getItemParam"); | |
| 599 | 2 | return gate_ui_itemview_get_item_param(&this->impl, index); | |
| 600 | } | ||
| 601 | 2 | String Itemview::getItemTitle(size_t index) | |
| 602 | { | ||
| 603 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | this->failIfNotCreated("Itemview::getItemTitle"); |
| 604 | 2 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 605 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_ui_itemview_get_text(&this->impl, index, &tmp, NULL, NULL); |
| 606 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 607 | 4 | return String::createFrom(tmp); | |
| 608 | } | ||
| 609 | 1 | void Itemview::setItemTitle(size_t index, String const& text) | |
| 610 | { | ||
| 611 | 1 | this->failIfNotCreated("Itemview::setItemTitle"); | |
| 612 | 1 | result_t result = gate_ui_itemview_set_text(&this->impl, index, text.c_impl(), NULL, NULL); | |
| 613 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 614 | 1 | } | |
| 615 | 2 | String Itemview::getItemSubtitle(size_t index) | |
| 616 | { | ||
| 617 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | this->failIfNotCreated("Itemview::getItemSubtitle"); |
| 618 | 2 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 619 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_ui_itemview_get_text(&this->impl, index, NULL, &tmp, NULL); |
| 620 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 621 | 4 | return String::createFrom(tmp); | |
| 622 | } | ||
| 623 | 1 | void Itemview::setItemSubtitle(size_t index, String const& text) | |
| 624 | { | ||
| 625 | 1 | this->failIfNotCreated("Itemview::setItemSubtitle"); | |
| 626 | 1 | result_t result = gate_ui_itemview_set_text(&this->impl, index, NULL, text.c_impl(), NULL); | |
| 627 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 628 | 1 | } | |
| 629 | 2 | String Itemview::getItemAddiontialText(size_t index) | |
| 630 | { | ||
| 631 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | this->failIfNotCreated("Itemview::getItemAddiontialText"); |
| 632 | 2 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 633 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_ui_itemview_get_text(&this->impl, index, NULL, NULL, &tmp); |
| 634 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 635 | 4 | return String::createFrom(tmp); | |
| 636 | } | ||
| 637 | 1 | void Itemview::setItemAdditionalText(size_t index, String const& text) | |
| 638 | { | ||
| 639 | 1 | this->failIfNotCreated("Itemview::setItemAdditionalText"); | |
| 640 | 1 | result_t result = gate_ui_itemview_set_text(&this->impl, index, NULL, NULL, text.c_impl()); | |
| 641 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 642 | 1 | } | |
| 643 | 1 | bool_t Itemview::isItemSelected(size_t index) | |
| 644 | { | ||
| 645 | 1 | this->failIfNotCreated("Itemview::isItemSelected"); | |
| 646 | 1 | return gate_ui_itemview_is_selected(&this->impl, index); | |
| 647 | } | ||
| 648 | 1 | void Itemview::setItemSelected(size_t index) | |
| 649 | { | ||
| 650 | 1 | this->failIfNotCreated("Itemview::setItemSelected"); | |
| 651 | 1 | result_t result = gate_ui_itemview_select_item(&this->impl, index); | |
| 652 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 653 | 1 | } | |
| 654 | 1 | bool_t Itemview::getSelectedItem(size_t& index) | |
| 655 | { | ||
| 656 | 1 | bool_t ret = false; | |
| 657 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (this->isCreated()) |
| 658 | { | ||
| 659 | 1 | result_t result = gate_ui_itemview_get_selected_item(&this->impl, &index); | |
| 660 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 661 | { | ||
| 662 | 1 | ret = true; | |
| 663 | } | ||
| 664 | } | ||
| 665 | 1 | return ret; | |
| 666 | } | ||
| 667 | |||
| 668 | 1 | bool_t Itemview::removeItem(size_t index) | |
| 669 | { | ||
| 670 | 1 | this->failIfNotCreated("Itemview::removeItem"); | |
| 671 | 1 | result_t result = gate_ui_itemview_remove(&this->impl, index); | |
| 672 | 1 | return GATE_SUCCEEDED(result); | |
| 673 | } | ||
| 674 | 1 | void Itemview::removeAllItems() | |
| 675 | { | ||
| 676 | 1 | this->failIfNotCreated("Itemview::removeAllItems"); | |
| 677 | 1 | result_t result = gate_ui_itemview_remove_all_items(&this->impl); | |
| 678 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 679 | 1 | } | |
| 680 | |||
| 681 | ✗ | void Itemview::onSelect(size_t index, void* itemparam) | |
| 682 | { | ||
| 683 | IndexArg arg; | ||
| 684 | ✗ | arg.ListIndex = index; | |
| 685 | ✗ | this->SelectEvent(this, &arg); | |
| 686 | ✗ | } | |
| 687 | |||
| 688 | ✗ | void Itemview::on_select(gate_ui_ctrl_t* sender, size_t index, void* item_param) | |
| 689 | { | ||
| 690 | ✗ | Itemview* itemview = static_cast<Itemview*>(gate_ui_ctrl_get_userparam(sender)); | |
| 691 | try { | ||
| 692 | ✗ | itemview->onSelect(index, item_param); | |
| 693 | } | ||
| 694 | ✗ | catch (...) {} | |
| 695 | ✗ | } | |
| 696 | |||
| 697 | |||
| 698 | |||
| 699 | |||
| 700 | |||
| 701 | |||
| 702 | } // end of namespace ui | ||
| 703 | } // end of namespace gate | ||
| 704 | |||
| 705 |