GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_dialogs.cpp
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 0 147 0.0%
Functions: 0 36 0.0%
Branches: 0 124 0.0%

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/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 ✗ GATEXX_TRY_CATCHALL(
212 {
213 this->filterDescr.add(description);
214 },
215 {
216 this->filterExt.removeAt(this->filterExt.length() - 1);
217 GATEXX_RETHROW;
218 });
219 ✗ }
220 ✗ void FilePickerDialog::addFilter(char const* extensionPattern, char const* description)
221 {
222 ✗ this->addFilter(String(extensionPattern), String(description));
223 ✗ }
224 ✗ size_t FilePickerDialog::getFilterCount() const
225 {
226 ✗ GATE_DEBUG_ASSERT(this->filterExt.length() == this->filterDescr.length());
227 ✗ return this->filterExt.length();
228 }
229 ✗ String FilePickerDialog::getFilterExtension(size_t index) const
230 {
231 ✗ GATE_DEBUG_ASSERT(index < this->filterExt.length());
232 ✗ return this->filterExt[index];
233 }
234 ✗ String FilePickerDialog::getFilterDescription(size_t index) const
235 {
236 ✗ GATE_DEBUG_ASSERT(index < this->filterDescr.length());
237 ✗ return this->filterDescr[index];
238 }
239
240 ✗ void FilePickerDialog::setSelectedFilter(size_t index)
241 {
242 ✗ GATE_DEBUG_ASSERT(index < this->filterDescr.length());
243 ✗ this->selectedFilter = index;
244 ✗ }
245 ✗ size_t FilePickerDialog::getSelectedFilter() const
246 {
247 ✗ return this->selectedFilter;
248 }
249
250 ✗ bool_t FilePickerDialog::showOpenDialog(ControlContainer& ctrl)
251 {
252 gate_ui_dialog_filter_t filters[128];
253 ✗ size_t filterCnt = this->getFilterCount();
254 gate_string_t initDir;
255 gate_string_t filePath;
256 ✗ gate_string_duplicate(&initDir, this->initDir.c_impl());
257 ✗ gate_string_duplicate(&filePath, this->fileName.c_impl());
258
259 ✗ for (size_t ndx = 0; ndx != filterCnt; ++ndx)
260 {
261 ✗ filters[ndx].extension = this->filterExt[ndx].c_str();
262 ✗ filters[ndx].description = this->filterDescr[ndx].c_str();
263 }
264
265 ✗ result_t result = gate_ui_dialog_openfile(ctrl.c_impl(), &filters[0], filterCnt, &this->selectedFilter,
266 ✗ this->dlgTitle.empty() ? NULL : this->dlgTitle.c_impl(), &initDir, &filePath
267 );
268
269 ✗ if (GATE_SUCCEEDED(result))
270 {
271 ✗ GATEXX_TRY_CATCHALL(
272 {
273 String tmpDir = String::duplicate(initDir);
274 String tmpFile = String::duplicate(filePath);
275 this->initDir.swap(tmpDir);
276 this->fileName.swap(tmpFile);
277 },
278 {
279 gate_string_release(&initDir);
280 gate_string_release(&filePath);
281 GATEXX_RETHROW;
282 });
283 }
284
285 ✗ gate_string_release(&initDir);
286 ✗ gate_string_release(&filePath);
287
288 ✗ if (result == GATE_RESULT_CANCELED)
289 {
290 ✗ return false;
291 }
292 ✗ GATEXX_CHECK_ERROR(result);
293 ✗ return true;
294 }
295
296 ✗ bool_t FilePickerDialog::showSaveDialog(ControlContainer& ctrl)
297 {
298 gate_ui_dialog_filter_t filters[128];
299 ✗ size_t filterCnt = this->getFilterCount();
300 gate_string_t initDir;
301 gate_string_t filePath;
302 ✗ gate_string_duplicate(&initDir, this->initDir.c_impl());
303 ✗ gate_string_duplicate(&filePath, this->fileName.c_impl());
304
305 ✗ for (size_t ndx = 0; ndx != filterCnt; ++ndx)
306 {
307 ✗ filters[ndx].extension = this->filterExt[ndx].c_str();
308 ✗ filters[ndx].description = this->filterDescr[ndx].c_str();
309 }
310
311 ✗ result_t result = gate_ui_dialog_savefile(ctrl.c_impl(), &filters[0], filterCnt, &this->selectedFilter,
312 ✗ this->dlgTitle.empty() ? NULL : this->dlgTitle.c_impl(), &initDir, &filePath
313 );
314
315 ✗ if (GATE_SUCCEEDED(result))
316 {
317 ✗ GATEXX_TRY_CATCHALL(
318 {
319 String tmpDir = String::duplicate(initDir);
320 String tmpFile = String::duplicate(filePath);
321 this->initDir.swap(tmpDir);
322 this->fileName.swap(tmpFile);
323 },
324 {
325 gate_string_release(&initDir);
326 gate_string_release(&filePath);
327 GATEXX_RETHROW;
328 });
329 }
330
331 ✗ gate_string_release(&initDir);
332 ✗ gate_string_release(&filePath);
333
334 ✗ if (result == GATE_RESULT_CANCELED)
335 {
336 ✗ return false;
337 }
338 ✗ GATEXX_CHECK_ERROR(result);
339 ✗ return true;
340 }
341
342
343 } // end of namespace ui
344 } // end of namespace gate
345