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