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/dialogs.hpp" |
30 |
|
|
|
31 |
|
|
namespace gate |
32 |
|
|
{ |
33 |
|
|
namespace ui |
34 |
|
|
{ |
35 |
|
|
|
36 |
|
✗ |
DialogSession::DialogSession(Host& host) |
37 |
|
|
{ |
38 |
|
✗ |
result_t result = gate_ui_dialog_session_init(&this->impl, host.c_impl(), NULL); |
39 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
40 |
|
✗ |
} |
41 |
|
✗ |
DialogSession::DialogSession(Control& ctrl) |
42 |
|
|
{ |
43 |
|
✗ |
gate_ui_ctrl_t* ptr_ctrl = ctrl.c_impl(); |
44 |
|
✗ |
gate_ui_host_t* ptr_host = gate_ui_ctrl_get_host(ptr_ctrl); |
45 |
|
✗ |
result_t result = gate_ui_dialog_session_init(&this->impl, ptr_host, ptr_ctrl); |
46 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
47 |
|
✗ |
} |
48 |
|
✗ |
DialogSession::~DialogSession() noexcept |
49 |
|
|
{ |
50 |
|
✗ |
gate_ui_dialog_session_uninit(&this->impl); |
51 |
|
✗ |
} |
52 |
|
|
|
53 |
|
✗ |
void DialogSession::run() |
54 |
|
|
{ |
55 |
|
✗ |
result_t result = gate_ui_dialog_session_run(&this->impl); |
56 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
57 |
|
✗ |
} |
58 |
|
✗ |
void DialogSession::quit() |
59 |
|
|
{ |
60 |
|
✗ |
result_t result = gate_ui_dialog_session_quit(&this->impl); |
61 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
62 |
|
✗ |
} |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
uint32_t const MsgBox::Type_OkOnly = GATE_UI_MSGBOX_TYPE_OK; |
68 |
|
|
uint32_t const MsgBox::Type_OkCancel = GATE_UI_MSGBOX_TYPE_OKCANCEL; |
69 |
|
|
uint32_t const MsgBox::Type_YesNo = GATE_UI_MSGBOX_TYPE_YESNO; |
70 |
|
|
uint32_t const MsgBox::Type_YesNoCancel = GATE_UI_MSGBOX_TYPE_YESNOCANCEL; |
71 |
|
|
uint32_t const MsgBox::Type_RetryCancel = GATE_UI_MSGBOX_TYPE_RETRYCANCEL; |
72 |
|
|
uint32_t const MsgBox::Type_RetryCancelIgnore = GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE; |
73 |
|
|
|
74 |
|
|
uint32_t const MsgBox::Type_Info = GATE_UI_MSGBOX_TYPE_INFO; |
75 |
|
|
uint32_t const MsgBox::Type_Question = GATE_UI_MSGBOX_TYPE_QUESTION; |
76 |
|
|
uint32_t const MsgBox::Type_Warning = GATE_UI_MSGBOX_TYPE_WARNING; |
77 |
|
|
uint32_t const MsgBox::Type_Error = GATE_UI_MSGBOX_TYPE_ERROR; |
78 |
|
|
|
79 |
|
|
|
80 |
|
✗ |
MessageDialog::MessageDialog() |
81 |
|
|
{ |
82 |
|
✗ |
} |
83 |
|
✗ |
MessageDialog::~MessageDialog() noexcept |
84 |
|
|
{ |
85 |
|
✗ |
} |
86 |
|
✗ |
MessageDialog::ChoiceEnum MessageDialog::show(ControlContainer& ctrl, String const& text, String const& title, uint32_t type) |
87 |
|
|
{ |
88 |
|
✗ |
enumint_t choice = 0; |
89 |
|
✗ |
result_t result = gate_ui_dialog_msgbox(ctrl.c_impl(), text.c_impl(), title.c_impl(), type, &choice); |
90 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
91 |
|
|
|
92 |
|
✗ |
return ChoiceEnum(choice); |
93 |
|
|
} |
94 |
|
✗ |
MessageDialog::ChoiceEnum MessageDialog::show(ControlContainer& ctrl, StringBuilder& text, String const& title, uint32_t type) |
95 |
|
|
{ |
96 |
|
✗ |
return this->show(ctrl, text.toString(), title, type); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
✗ |
InputDialog::InputDialog() |
102 |
|
|
{ |
103 |
|
✗ |
} |
104 |
|
✗ |
InputDialog::~InputDialog() noexcept |
105 |
|
|
{ |
106 |
|
✗ |
} |
107 |
|
|
|
108 |
|
✗ |
Optional<String> InputDialog::show(ControlContainer& parent, String const& text, String const& title, String const& input) |
109 |
|
|
{ |
110 |
|
✗ |
Optional<String> ret; |
111 |
|
✗ |
gate_string_t tmp = GATE_STRING_INIT_EMPTY; |
112 |
|
✗ |
result_t result = gate_ui_dialog_inputbox(parent.c_impl(), text.c_impl(), title.c_impl(), input.c_impl(), &tmp); |
113 |
|
✗ |
if (GATE_SUCCEEDED(result)) |
114 |
|
|
{ |
115 |
|
✗ |
ret.create(String::createFrom(tmp)); |
116 |
|
|
} |
117 |
|
|
else |
118 |
|
|
{ |
119 |
|
✗ |
if (result != GATE_RESULT_CANCELED) |
120 |
|
|
{ |
121 |
|
✗ |
GATEXX_RAISE_EXCEPTION(result, "InputBox dialog failed", 0); |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
✗ |
gate_string_release(&tmp); |
125 |
|
✗ |
return ret; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
|
129 |
|
✗ |
ChoiceDialog::ChoiceDialog() |
130 |
|
|
{ |
131 |
|
✗ |
} |
132 |
|
✗ |
ChoiceDialog::~ChoiceDialog() noexcept |
133 |
|
|
{ |
134 |
|
|
|
135 |
|
✗ |
} |
136 |
|
|
|
137 |
|
✗ |
Optional<Property> ChoiceDialog::show(ControlContainer& parent, PropTable const& table, |
138 |
|
|
String const& text, String const& title) |
139 |
|
|
{ |
140 |
|
✗ |
Optional<Property> ret; |
141 |
|
✗ |
Property propSelected; |
142 |
|
✗ |
result_t result = gate_ui_dialog_choice(parent.c_impl(), text.c_impl(), title.c_impl(), table.c_impl(), propSelected.c_impl()); |
143 |
|
|
|
144 |
|
✗ |
if (GATE_SUCCEEDED(result)) |
145 |
|
|
{ |
146 |
|
✗ |
ret.create(propSelected); |
147 |
|
|
} |
148 |
|
✗ |
return ret; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
✗ |
FilePickerDialog::FilePickerDialog() |
154 |
|
✗ |
: selectedFilter(0) |
155 |
|
|
{ |
156 |
|
|
|
157 |
|
✗ |
} |
158 |
|
✗ |
FilePickerDialog::~FilePickerDialog() |
159 |
|
|
{ |
160 |
|
|
|
161 |
|
✗ |
} |
162 |
|
|
|
163 |
|
✗ |
void FilePickerDialog::setFileName(char const* file) |
164 |
|
|
{ |
165 |
|
✗ |
this->fileName = String(file); |
166 |
|
✗ |
} |
167 |
|
✗ |
void FilePickerDialog::setFileName(String const& file) |
168 |
|
|
{ |
169 |
|
✗ |
this->fileName = file; |
170 |
|
✗ |
} |
171 |
|
✗ |
String FilePickerDialog::getFileName() const |
172 |
|
|
{ |
173 |
|
✗ |
return this->fileName; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
✗ |
void FilePickerDialog::setDirectory(char const* dir) |
177 |
|
|
{ |
178 |
|
✗ |
this->initDir = String(dir); |
179 |
|
✗ |
} |
180 |
|
✗ |
void FilePickerDialog::setDirectory(String const& dir) |
181 |
|
|
{ |
182 |
|
✗ |
this->initDir = dir; |
183 |
|
✗ |
} |
184 |
|
✗ |
String FilePickerDialog::getDirectory() const |
185 |
|
|
{ |
186 |
|
✗ |
return this->initDir; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
✗ |
void FilePickerDialog::setDialogTitle(char const* title) |
190 |
|
|
{ |
191 |
|
✗ |
this->dlgTitle = String(title); |
192 |
|
✗ |
} |
193 |
|
✗ |
void FilePickerDialog::setDialogTitle(String const& title) |
194 |
|
|
{ |
195 |
|
✗ |
this->dlgTitle = title; |
196 |
|
✗ |
} |
197 |
|
✗ |
String FilePickerDialog::getDialogTitle() const |
198 |
|
|
{ |
199 |
|
✗ |
return this->dlgTitle; |
200 |
|
|
} |
201 |
|
|
|
202 |
|
✗ |
void FilePickerDialog::clearFilters() |
203 |
|
|
{ |
204 |
|
✗ |
this->filterExt.clear(); |
205 |
|
✗ |
this->filterDescr.clear(); |
206 |
|
✗ |
this->selectedFilter = 0; |
207 |
|
✗ |
} |
208 |
|
✗ |
void FilePickerDialog::addFilter(String const& extensionPattern, String const& description) |
209 |
|
|
{ |
210 |
|
✗ |
this->filterExt.add(extensionPattern); |
211 |
|
|
try |
212 |
|
|
{ |
213 |
|
✗ |
this->filterDescr.add(description); |
214 |
|
|
} |
215 |
|
✗ |
catch (...) |
216 |
|
|
{ |
217 |
|
✗ |
this->filterExt.removeAt(this->filterExt.length() - 1); |
218 |
|
✗ |
throw; |
219 |
|
|
} |
220 |
|
✗ |
} |
221 |
|
✗ |
void FilePickerDialog::addFilter(char const* extensionPattern, char const* description) |
222 |
|
|
{ |
223 |
|
✗ |
this->addFilter(String(extensionPattern), String(description)); |
224 |
|
✗ |
} |
225 |
|
✗ |
size_t FilePickerDialog::getFilterCount() const |
226 |
|
|
{ |
227 |
|
✗ |
GATE_DEBUG_ASSERT(this->filterExt.length() == this->filterDescr.length()); |
228 |
|
✗ |
return this->filterExt.length(); |
229 |
|
|
} |
230 |
|
✗ |
String FilePickerDialog::getFilterExtension(size_t index) const |
231 |
|
|
{ |
232 |
|
✗ |
GATE_DEBUG_ASSERT(index < this->filterExt.length()); |
233 |
|
✗ |
return this->filterExt[index]; |
234 |
|
|
} |
235 |
|
✗ |
String FilePickerDialog::getFilterDescription(size_t index) const |
236 |
|
|
{ |
237 |
|
✗ |
GATE_DEBUG_ASSERT(index < this->filterDescr.length()); |
238 |
|
✗ |
return this->filterDescr[index]; |
239 |
|
|
} |
240 |
|
|
|
241 |
|
✗ |
void FilePickerDialog::setSelectedFilter(size_t index) |
242 |
|
|
{ |
243 |
|
✗ |
GATE_DEBUG_ASSERT(index < this->filterDescr.length()); |
244 |
|
✗ |
this->selectedFilter = index; |
245 |
|
✗ |
} |
246 |
|
✗ |
size_t FilePickerDialog::getSelectedFilter() const |
247 |
|
|
{ |
248 |
|
✗ |
return this->selectedFilter; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
✗ |
bool_t FilePickerDialog::showOpenDialog(ControlContainer& ctrl) |
252 |
|
|
{ |
253 |
|
|
gate_ui_dialog_filter_t filters[128]; |
254 |
|
✗ |
size_t filterCnt = this->getFilterCount(); |
255 |
|
|
gate_string_t initDir; |
256 |
|
|
gate_string_t filePath; |
257 |
|
✗ |
gate_string_duplicate(&initDir, this->initDir.c_impl()); |
258 |
|
✗ |
gate_string_duplicate(&filePath, this->fileName.c_impl()); |
259 |
|
|
|
260 |
|
✗ |
for (size_t ndx = 0; ndx != filterCnt; ++ndx) |
261 |
|
|
{ |
262 |
|
✗ |
filters[ndx].extension = this->filterExt[ndx].c_str(); |
263 |
|
✗ |
filters[ndx].description = this->filterDescr[ndx].c_str(); |
264 |
|
|
} |
265 |
|
|
|
266 |
|
✗ |
result_t result = gate_ui_dialog_openfile(ctrl.c_impl(), &filters[0], filterCnt, &this->selectedFilter, |
267 |
|
✗ |
this->dlgTitle.empty() ? NULL : this->dlgTitle.c_impl(), &initDir, &filePath |
268 |
|
|
); |
269 |
|
|
|
270 |
|
✗ |
if (GATE_SUCCEEDED(result)) |
271 |
|
|
{ |
272 |
|
|
try |
273 |
|
|
{ |
274 |
|
✗ |
String tmpDir = String::duplicate(initDir); |
275 |
|
✗ |
String tmpFile = String::duplicate(filePath); |
276 |
|
✗ |
this->initDir.swap(tmpDir); |
277 |
|
✗ |
this->fileName.swap(tmpFile); |
278 |
|
|
} |
279 |
|
|
catch (...) |
280 |
|
|
{ |
281 |
|
|
gate_string_release(&initDir); |
282 |
|
|
gate_string_release(&filePath); |
283 |
|
|
throw; |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
|
287 |
|
✗ |
gate_string_release(&initDir); |
288 |
|
✗ |
gate_string_release(&filePath); |
289 |
|
|
|
290 |
|
✗ |
if (result == GATE_RESULT_CANCELED) |
291 |
|
|
{ |
292 |
|
✗ |
return false; |
293 |
|
|
} |
294 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
295 |
|
✗ |
return true; |
296 |
|
|
} |
297 |
|
|
|
298 |
|
✗ |
bool_t FilePickerDialog::showSaveDialog(ControlContainer& ctrl) |
299 |
|
|
{ |
300 |
|
|
gate_ui_dialog_filter_t filters[128]; |
301 |
|
✗ |
size_t filterCnt = this->getFilterCount(); |
302 |
|
|
gate_string_t initDir; |
303 |
|
|
gate_string_t filePath; |
304 |
|
✗ |
gate_string_duplicate(&initDir, this->initDir.c_impl()); |
305 |
|
✗ |
gate_string_duplicate(&filePath, this->fileName.c_impl()); |
306 |
|
|
|
307 |
|
✗ |
for (size_t ndx = 0; ndx != filterCnt; ++ndx) |
308 |
|
|
{ |
309 |
|
✗ |
filters[ndx].extension = this->filterExt[ndx].c_str(); |
310 |
|
✗ |
filters[ndx].description = this->filterDescr[ndx].c_str(); |
311 |
|
|
} |
312 |
|
|
|
313 |
|
✗ |
result_t result = gate_ui_dialog_savefile(ctrl.c_impl(), &filters[0], filterCnt, &this->selectedFilter, |
314 |
|
✗ |
this->dlgTitle.empty() ? NULL : this->dlgTitle.c_impl(), &initDir, &filePath |
315 |
|
|
); |
316 |
|
|
|
317 |
|
✗ |
if (GATE_SUCCEEDED(result)) |
318 |
|
|
{ |
319 |
|
|
try |
320 |
|
|
{ |
321 |
|
✗ |
String tmpDir = String::duplicate(initDir); |
322 |
|
✗ |
String tmpFile = String::duplicate(filePath); |
323 |
|
✗ |
this->initDir.swap(tmpDir); |
324 |
|
✗ |
this->fileName.swap(tmpFile); |
325 |
|
|
} |
326 |
|
|
catch (...) |
327 |
|
|
{ |
328 |
|
|
gate_string_release(&initDir); |
329 |
|
|
gate_string_release(&filePath); |
330 |
|
|
throw; |
331 |
|
|
} |
332 |
|
|
} |
333 |
|
|
|
334 |
|
✗ |
gate_string_release(&initDir); |
335 |
|
✗ |
gate_string_release(&filePath); |
336 |
|
|
|
337 |
|
✗ |
if (result == GATE_RESULT_CANCELED) |
338 |
|
|
{ |
339 |
|
✗ |
return false; |
340 |
|
|
} |
341 |
|
✗ |
GATEXX_CHECK_ERROR(result); |
342 |
|
✗ |
return true; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
|
346 |
|
|
} // end of namespace ui |
347 |
|
|
} // end of namespace gate |
348 |
|
|
|