| 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/comboboxes.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace ui | ||
| 34 | { | ||
| 35 | size_t const Combobox::InvalidIndex = GATE_UI_COMBOBOX_INVALID_INDEX; | ||
| 36 | |||
| 37 | |||
| 38 | 1 | Combobox::Combobox() | |
| 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 | Combobox::~Combobox() 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 Combobox::create(ControlContainer& parent, Position const& pose, uint32_t flags) | |
| 53 | { | ||
| 54 | 1 | this->failIfCreated("Combobox::create"); | |
| 55 | |||
| 56 | 1 | result_t res = gate_ui_combobox_create(&this->impl, *parent, &pose, flags, this); | |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(res); |
| 58 | |||
| 59 | 1 | this->impl.on_select = &Combobox::on_select; | |
| 60 | 1 | this->attachNativeControl(&this->impl.ctrl); | |
| 61 | 1 | } | |
| 62 | |||
| 63 | 1 | void Combobox::performAction(enumint_t action) | |
| 64 | { | ||
| 65 | 1 | this->failIfNotCreated("Combobox::create"); | |
| 66 | 1 | result_t result = gate_ui_combobox_perform_action(&this->impl, action); | |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 68 | 1 | } | |
| 69 | |||
| 70 | 4 | size_t Combobox::getItemCount() | |
| 71 | { | ||
| 72 | 4 | return gate_ui_combobox_get_item_count(&this->impl); | |
| 73 | } | ||
| 74 | ✗ | void Combobox::insertItem(size_t atIndex, String const& text, void* itemParam) | |
| 75 | { | ||
| 76 | ✗ | this->failIfNotCreated("Combobox::insertItem"); | |
| 77 | ✗ | result_t res = gate_ui_combobox_insert_item(&this->impl, &atIndex, text.c_impl(), itemParam); | |
| 78 | ✗ | GATEXX_CHECK_ERROR(res); | |
| 79 | ✗ | } | |
| 80 | 3 | size_t Combobox::addItem(String const& text, void* itemParam) | |
| 81 | { | ||
| 82 | 3 | this->failIfNotCreated("Combobox::addItem"); | |
| 83 | 3 | size_t new_index = this->getItemCount(); | |
| 84 | 3 | result_t res = gate_ui_combobox_insert_item(&this->impl, NULL, text.c_impl(), itemParam); | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_ERROR(res); |
| 86 | 3 | return new_index; | |
| 87 | } | ||
| 88 | 1 | String Combobox::getItemText(size_t index) | |
| 89 | { | ||
| 90 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Combobox::getItemText"); |
| 91 | gate_string_t text; | ||
| 92 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_ui_combobox_get_item_text(&this->impl, index, &text); |
| 93 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(res); |
| 94 | 1 | String ret = String::duplicate(text); | |
| 95 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_release(&text); |
| 96 | 2 | return ret; | |
| 97 | } | ||
| 98 | 1 | void* Combobox::getItemParam(size_t index) | |
| 99 | { | ||
| 100 | 1 | this->failIfNotCreated("Combobox::getItemParam"); | |
| 101 | 1 | return gate_ui_combobox_get_item_param(&this->impl, index); | |
| 102 | } | ||
| 103 | 1 | void Combobox::setItemText(size_t index, String const& text) | |
| 104 | { | ||
| 105 | 1 | this->failIfNotCreated("Combobox::setItemParam"); | |
| 106 | 1 | result_t res = gate_ui_combobox_set_item_text(&this->impl, index, text.c_impl()); | |
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(res); |
| 108 | 1 | } | |
| 109 | |||
| 110 | 1 | void Combobox::removeItem(index_t index) | |
| 111 | { | ||
| 112 | 1 | this->failIfNotCreated("Combobox::removeItem"); | |
| 113 | 1 | result_t res = gate_ui_combobox_remove_item(&this->impl, index); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(res); |
| 115 | 1 | } | |
| 116 | 1 | bool_t Combobox::findItemParam(void* searchItemParam, size_t& foundAtIndex, size_t startAtIndex) | |
| 117 | { | ||
| 118 | 1 | this->failIfNotCreated("Combobox::findItemParam"); | |
| 119 | 1 | result_t res = gate_ui_combobox_find_item_param(&this->impl, searchItemParam, &foundAtIndex, startAtIndex); | |
| 120 |
1/3✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
1 | switch (res) |
| 121 | { | ||
| 122 | 1 | case GATE_RESULT_OK: | |
| 123 | { | ||
| 124 | 1 | return true; | |
| 125 | } | ||
| 126 | ✗ | case GATE_RESULT_NOMATCH: | |
| 127 | { | ||
| 128 | ✗ | break; | |
| 129 | } | ||
| 130 | ✗ | default: | |
| 131 | { | ||
| 132 | ✗ | GATEXX_RAISE_ERROR(res); | |
| 133 | ✗ | break; | |
| 134 | } | ||
| 135 | } | ||
| 136 | ✗ | return false; | |
| 137 | } | ||
| 138 | |||
| 139 | ✗ | Result<size_t> Combobox::getSelectedIndex() | |
| 140 | { | ||
| 141 | ✗ | this->failIfNotCreated("Combobox::getSelectedIndex"); | |
| 142 | ✗ | size_t index = 0; | |
| 143 | ✗ | result_t result = gate_ui_combobox_get_selected_item(&this->impl, &index); | |
| 144 | |||
| 145 | ✗ | return makeResult(result, index); | |
| 146 | } | ||
| 147 | 1 | bool_t Combobox::getSelectedItem(size_t* selectedIndex, String* text, void** itemParam) noexcept | |
| 148 | { | ||
| 149 | 1 | this->failIfNotCreated("Combobox::getSelectedItem"); | |
| 150 | 1 | size_t index = 0; | |
| 151 | 1 | result_t result = gate_ui_combobox_get_selected_item(&this->impl, &index); | |
| 152 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 153 | { | ||
| 154 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (selectedIndex) |
| 155 | { | ||
| 156 | 1 | *selectedIndex = index; | |
| 157 | } | ||
| 158 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (text) |
| 159 | { | ||
| 160 | gate_string_t strText; | ||
| 161 | 1 | result = gate_ui_combobox_get_item_text(&this->impl, index, &strText); | |
| 162 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 163 | { | ||
| 164 | 1 | *text = String::duplicate(strText); | |
| 165 | 1 | gate_string_release(&strText); | |
| 166 | } | ||
| 167 | else | ||
| 168 | { | ||
| 169 | ✗ | *text = String(); | |
| 170 | } | ||
| 171 | } | ||
| 172 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (itemParam) |
| 173 | { | ||
| 174 | 1 | *itemParam = gate_ui_combobox_get_item_param(&this->impl, index); | |
| 175 | } | ||
| 176 | 1 | return true; | |
| 177 | } | ||
| 178 | ✗ | return false; | |
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | 3 | void Combobox::setSelectedItem(size_t index) | |
| 183 | { | ||
| 184 | 3 | this->failIfNotCreated("Combobox::setSelectedItem"); | |
| 185 | 3 | result_t result = gate_ui_combobox_set_selected_item(&this->impl, index); | |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_EXCEPTION(result); |
| 187 | 3 | } | |
| 188 | ✗ | void Combobox::removeAllItems() | |
| 189 | { | ||
| 190 | ✗ | this->failIfNotCreated("Combobox::clear"); | |
| 191 | ✗ | result_t result = gate_ui_combobox_clear(&this->impl); | |
| 192 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 193 | ✗ | } | |
| 194 | |||
| 195 | ✗ | void Combobox::onSelect(size_t index) | |
| 196 | { | ||
| 197 | SelectArg arg; | ||
| 198 | ✗ | arg.Index = index; | |
| 199 | ✗ | this->SelectEvent(this, &arg); | |
| 200 | ✗ | } | |
| 201 | |||
| 202 | ✗ | void Combobox::on_select(gate_ui_ctrl_t* sender, gate_size_t index) | |
| 203 | { | ||
| 204 | ✗ | Combobox* cmbx = static_cast<Combobox*>(gate_ui_ctrl_get_userparam(sender)); | |
| 205 | ✗ | if (cmbx != NULL) | |
| 206 | { | ||
| 207 | try | ||
| 208 | { | ||
| 209 | ✗ | cmbx->onSelect(index); | |
| 210 | } | ||
| 211 | ✗ | catch (...) {} | |
| 212 | } | ||
| 213 | ✗ | } | |
| 214 | |||
| 215 | } // end of namespace ui | ||
| 216 | } // end of namespace gate | ||
| 217 | |||
| 218 |