GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/dialogs.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 523 0.0%
Functions: 0 17 0.0%
Branches: 0 298 0.0%

Line Branch Exec Source
1 #include "gate/ui/dialogs.h"
2 #include "gate/ui/forms.h"
3 #include "gate/ui/buttons.h"
4 #include "gate/ui/labels.h"
5 #include "gate/ui/textboxes.h"
6 #include "gate/ui/listviews.h"
7 #include "gate/results.h"
8 #include "gate/debugging.h"
9
10
11 static void* const gate_ui_dialog_session_offline = (void*)(gate_uintptr_t)0;
12 static void* const gate_ui_dialog_session_online = (void*)(gate_uintptr_t)1;
13
14 static gate_string_t const text_ok = GATE_STRING_INIT_STATIC("OK");
15 static gate_string_t const text_cancel = GATE_STRING_INIT_STATIC("Cancel");
16
17 typedef struct inputbox_context
18 {
19 gate_ui_dialog_session_t dlg_session;
20 gate_bool_t confirmed;
21 } inputbox_context_t;
22
23 static void inputbox_btn_ok_on_click(gate_ui_ctrl_t* sender)
24 {
25 inputbox_context_t* context = (inputbox_context_t*)gate_ui_ctrl_get_userparam(sender);
26 if (context)
27 {
28 context->confirmed = true;
29 gate_ui_dialog_session_quit(&context->dlg_session);
30 }
31 }
32
33 static void inputbox_btn_cancel_on_click(gate_ui_ctrl_t* sender)
34 {
35 inputbox_context_t* context = (inputbox_context_t*)gate_ui_ctrl_get_userparam(sender);
36 if (context)
37 {
38 context->confirmed = false;
39 gate_ui_dialog_session_quit(&context->dlg_session);
40 }
41 }
42
43
44 gate_result_t gate_ui_dialog_inputbox(gate_ui_ctrl_t* owner, gate_string_t const* message,
45 gate_string_t const* title, gate_string_t const* input,
46 gate_string_t* output)
47 {
48 gate_result_t ret;
49 gate_ui_host_t* host;
50 gate_ui_form_t* owner_form;
51 inputbox_context_t context = GATE_INIT_EMPTY;
52 gate_ui_form_t frm_dialog = GATE_INIT_EMPTY;
53 gate_ui_textbox_t txt_msg = GATE_INIT_EMPTY;
54 gate_ui_textbox_t txt_input = GATE_INIT_EMPTY;
55 gate_ui_button_t btn_ok = GATE_INIT_EMPTY;
56 gate_ui_button_t btn_cancel = GATE_INIT_EMPTY;
57 gate_ui_position_t frm_position = GATE_INIT_EMPTY;
58 gate_ui_position_t const* ptr_frm_position = &frm_position;
59 gate_ui_position_t owner_position = GATE_INIT_EMPTY;
60 gate_ui_layout_t layout = GATE_INIT_EMPTY;
61 gate_int32_t line_height;
62
63 GATE_DEBUG_ASSERT(owner != NULL);
64
65 host = gate_ui_ctrl_get_host(owner);
66 owner_form = gate_ui_form_get_top_level_form(owner);
67
68 do
69 {
70 gate_ui_host_default_workarea(host, &frm_position);
71
72 line_height = (gate_int32_t)gate_ui_host_default_line_height(host);
73 ret = gate_ui_layout_create(&layout);
74 GATE_BREAK_IF_FAILED(ret);
75 layout.border = line_height / 3;
76 layout.colspace = line_height / 4;
77 layout.rowspace = line_height / 4;
78
79 if (frm_position.size.width > frm_position.size.height)
80 {
81 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
82 GATE_BREAK_IF_FAILED(ret);
83 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 4.0f);
84 GATE_BREAK_IF_FAILED(ret);
85
86 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
87 GATE_BREAK_IF_FAILED(ret);
88 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
89 GATE_BREAK_IF_FAILED(ret);
90 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
91 GATE_BREAK_IF_FAILED(ret);
92 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
93 GATE_BREAK_IF_FAILED(ret);
94
95 ret = gate_ui_layout_set_control(&layout, &txt_msg.ctrl, 0, 0, 3, 1);
96 GATE_BREAK_IF_FAILED(ret);
97 ret = gate_ui_layout_set_control(&layout, &btn_ok.ctrl, 0, 1, 1, 1);
98 GATE_BREAK_IF_FAILED(ret);
99 ret = gate_ui_layout_set_control(&layout, &btn_cancel.ctrl, 1, 1, 1, 1);
100 GATE_BREAK_IF_FAILED(ret);
101 ret = gate_ui_layout_set_control(&layout, &txt_input.ctrl, 3, 0, 1, 2);
102 GATE_BREAK_IF_FAILED(ret);
103 }
104 else
105 {
106 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
107 GATE_BREAK_IF_FAILED(ret);
108 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
109 GATE_BREAK_IF_FAILED(ret);
110
111 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
112 GATE_BREAK_IF_FAILED(ret);
113 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.00f);
114 GATE_BREAK_IF_FAILED(ret);
115 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
116 GATE_BREAK_IF_FAILED(ret);
117
118 ret = gate_ui_layout_set_control(&layout, &txt_msg.ctrl, 0, 0, 1, 2);
119 GATE_BREAK_IF_FAILED(ret);
120 ret = gate_ui_layout_set_control(&layout, &txt_input.ctrl, 1, 0, 1, 2);
121 GATE_BREAK_IF_FAILED(ret);
122 ret = gate_ui_layout_set_control(&layout, &btn_ok.ctrl, 2, 0, 1, 1);
123 GATE_BREAK_IF_FAILED(ret);
124 ret = gate_ui_layout_set_control(&layout, &btn_cancel.ctrl, 2, 1, 1, 1);
125 GATE_BREAK_IF_FAILED(ret);
126 }
127
128 #if defined(GATE_SYS_WINCE)
129 ptr_frm_position = NULL;
130 owner_form = NULL;
131 #else
132 frm_position.pos.x = 0;
133 frm_position.pos.y = 0;
134
135 frm_position.size.height = line_height * 16;
136 frm_position.size.width = line_height * 32;
137 if (owner)
138 {
139 gate_ui_ctrl_get_position(owner, &owner_position);
140 frm_position.pos.x = owner_position.pos.x + (owner_position.size.width - frm_position.size.width) / 2;
141 frm_position.pos.y = owner_position.pos.y + (owner_position.size.height - frm_position.size.height) / 2;
142 }
143 #endif
144
145 ret = gate_ui_form_create(&frm_dialog, host, ptr_frm_position, title,
146 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_FORM_NOCLOSE | GATE_UI_FLAG_FORM_DIALOGSTYLE,
147 owner_form, &context);
148 GATE_BREAK_IF_FAILED(ret);
149 frm_dialog.on_confirm = &inputbox_btn_ok_on_click;
150 frm_dialog.on_cancel = &inputbox_btn_cancel_on_click;
151 ret = gate_ui_form_set_layout(&frm_dialog, &layout);
152 GATE_BREAK_IF_FAILED(ret);
153
154 ret = gate_ui_textbox_create(&txt_msg, &frm_dialog.ctrl, NULL, message,
155 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE |
156 GATE_UI_FLAG_TEXTBOX_READONLY | GATE_UI_FLAG_TEXTBOX_MULTILINE | GATE_UI_FLAG_TEXTBOX_VSCROLL,
157 NULL);
158 GATE_BREAK_IF_FAILED(ret);
159
160 ret = gate_ui_textbox_create(&txt_input, &frm_dialog.ctrl, NULL, input, GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, NULL);
161 GATE_BREAK_IF_FAILED(ret);
162
163 ret = gate_ui_button_create(&btn_ok, &frm_dialog.ctrl, NULL, &text_ok,
164 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, &context);
165 GATE_BREAK_IF_FAILED(ret);
166 btn_ok.on_click = &inputbox_btn_ok_on_click;
167
168 ret = gate_ui_button_create(&btn_cancel, &frm_dialog.ctrl, NULL, &text_cancel,
169 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, &context);
170 GATE_BREAK_IF_FAILED(ret);
171 btn_cancel.on_click = &inputbox_btn_cancel_on_click;
172
173 ret = gate_ui_ctrl_set_visible(&frm_dialog.ctrl, true);
174 GATE_BREAK_IF_FAILED(ret);
175 ret = gate_ui_ctrl_refresh(&frm_dialog.ctrl);
176 GATE_BREAK_IF_FAILED(ret);
177
178 ret = gate_ui_dialog_session_init(&context.dlg_session, host, &frm_dialog.ctrl);
179 GATE_BREAK_IF_FAILED(ret);
180 ret = gate_ui_form_begin_dialog(&frm_dialog);
181 GATE_BREAK_IF_FAILED(ret);
182
183 do
184 {
185 ret = gate_ui_dialog_session_run(&context.dlg_session);
186 GATE_BREAK_IF_FAILED(ret);
187 if (context.confirmed)
188 {
189 ret = gate_ui_ctrl_get_text(&txt_input.ctrl, output);
190 }
191 else
192 {
193 ret = GATE_RESULT_CANCELED;
194 }
195 } while (0);
196
197 gate_ui_form_end_dialog(&frm_dialog);
198 gate_ui_dialog_session_uninit(&context.dlg_session);
199
200 } while (0);
201
202 gate_ui_ctrl_destroy(&txt_input.ctrl);
203 gate_ui_ctrl_destroy(&txt_msg.ctrl);
204 gate_ui_ctrl_destroy(&btn_cancel.ctrl);
205 gate_ui_ctrl_destroy(&btn_ok.ctrl);
206 gate_ui_ctrl_destroy(&frm_dialog.ctrl);
207
208 gate_ui_layout_destroy(&layout);
209
210 gate_ui_host_process_events(host);
211
212 return ret;
213 }
214
215
216
217 typedef struct choicebox_context
218 {
219 gate_ui_dialog_session_t dlg_session;
220 gate_bool_t confirmed;
221 gate_ui_listview_t* lv;
222 } choicebox_context_t;
223
224 static void choicebox_lv_open(gate_ui_ctrl_t* sender, gate_size_t index, void* item_param)
225 {
226 choicebox_context_t* context = (choicebox_context_t*)gate_ui_ctrl_get_userparam(sender);
227 gate_size_t sel_index;
228 gate_result_t result;
229
230 GATE_UNUSED_ARG(index);
231 if (context)
232 {
233 if (context->lv)
234 {
235 result = gate_ui_listview_get_selected_item(context->lv, &sel_index);
236 if (GATE_SUCCEEDED(result))
237 {
238 if (sel_index != GATE_UI_LISTVIEW_INVALID_INDEX)
239 {
240 context->confirmed = true;
241 gate_ui_dialog_session_quit(&context->dlg_session);
242 }
243 }
244 }
245 }
246 }
247
248 static void choicebox_btn_ok_on_click(gate_ui_ctrl_t* sender)
249 {
250 choicebox_context_t* context = (choicebox_context_t*)gate_ui_ctrl_get_userparam(sender);
251 gate_size_t sel_index;
252 gate_result_t result;
253 if (context)
254 {
255 if (context->lv)
256 {
257 result = gate_ui_listview_get_selected_item(context->lv, &sel_index);
258 if (GATE_SUCCEEDED(result))
259 {
260 if (sel_index != GATE_UI_LISTVIEW_INVALID_INDEX)
261 {
262 context->confirmed = true;
263 gate_ui_dialog_session_quit(&context->dlg_session);
264 }
265 }
266 }
267 }
268 }
269
270 static void choicebox_btn_cancel_on_click(gate_ui_ctrl_t* sender)
271 {
272 choicebox_context_t* context = (choicebox_context_t*)gate_ui_ctrl_get_userparam(sender);
273 if (context)
274 {
275 context->confirmed = false;
276 gate_ui_dialog_session_quit(&context->dlg_session);
277 }
278 }
279
280 gate_result_t gate_ui_dialog_choice(gate_ui_ctrl_t* owner, gate_string_t const* text, gate_string_t const* title,
281 gate_proptable_t const* table, gate_property_t* selected_entry)
282 {
283 gate_result_t ret;
284 gate_result_t result;
285 gate_ui_host_t* host = gate_ui_ctrl_get_host(owner);
286 gate_ui_form_t* owner_form = gate_ui_form_get_top_level_form(owner);
287 choicebox_context_t context = GATE_INIT_EMPTY;
288 gate_ui_form_t frm_dialog = GATE_INIT_EMPTY;
289 gate_ui_label_t lbl_msg = GATE_INIT_EMPTY;
290 gate_ui_listview_t lv_table = GATE_INIT_EMPTY;
291 gate_ui_button_t btn_ok = GATE_INIT_EMPTY;
292 gate_ui_button_t btn_cancel = GATE_INIT_EMPTY;
293 gate_ui_position_t frm_position = { { 0, 0 }, { 512, 240 } };
294 gate_ui_position_t owner_position = GATE_INIT_EMPTY;
295 gate_ui_layout_t layout = GATE_INIT_EMPTY;
296 gate_int32_t line_height;
297 gate_size_t index;
298 gate_size_t count;
299 gate_size_t colindex, rowindex;
300 gate_string_t str_tmp = GATE_STRING_INIT_EMPTY;
301 gate_size_t indices[32] = GATE_INIT_EMPTY;
302 /* gate_size_t const max_indices = sizeof(indices) / sizeof(indices[0]); */
303 gate_size_t indices_used = 0;
304 gate_ui_listview_column_t columns[32] = GATE_INIT_EMPTY;
305 gate_property_typeid_t proptype;
306 gate_uint32_t flags;
307 gate_property_t const* ptr_prop;
308 gate_string_t str_prop = GATE_STRING_INIT_EMPTY;
309 gate_uint32_t colwidth = 92;
310 gate_ui_position_t workarea;
311
312 do
313 {
314 gate_mem_clear(&context, sizeof(context));
315 context.lv = &lv_table;
316
317 line_height = (gate_int32_t)gate_ui_host_default_line_height(host);
318 ret = gate_ui_layout_create(&layout);
319 GATE_BREAK_IF_FAILED(ret);
320 layout.border = 6;
321 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
322 GATE_BREAK_IF_FAILED(ret);
323 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 5.0f);
324 GATE_BREAK_IF_FAILED(ret);
325 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 0.33f);
326 GATE_BREAK_IF_FAILED(ret);
327 ret = gate_ui_layout_add_column(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 5.0f);
328 GATE_BREAK_IF_FAILED(ret);
329
330
331 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
332 GATE_BREAK_IF_FAILED(ret);
333 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 0.33f);
334 GATE_BREAK_IF_FAILED(ret);
335 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_AUTO, 0.0f);
336 GATE_BREAK_IF_FAILED(ret);
337 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 0.33f);
338 GATE_BREAK_IF_FAILED(ret);
339 ret = gate_ui_layout_add_row(&layout, GATE_UI_LAYOUT_TYPE_UNITSCALE, 1.0f);
340 GATE_BREAK_IF_FAILED(ret);
341
342
343 ret = gate_ui_layout_set_control(&layout, &lbl_msg.ctrl, 0, 0, 1, 4);
344 GATE_BREAK_IF_FAILED(ret);
345
346 ret = gate_ui_layout_set_control(&layout, &lv_table.ctrl, 2, 0, 1, 4);
347 GATE_BREAK_IF_FAILED(ret);
348
349 ret = gate_ui_layout_set_control(&layout, &btn_ok.ctrl, 4, 1, 1, 1);
350 GATE_BREAK_IF_FAILED(ret);
351
352 ret = gate_ui_layout_set_control(&layout, &btn_cancel.ctrl, 4, 3, 1, 1);
353 GATE_BREAK_IF_FAILED(ret);
354
355 frm_position.size.height = line_height * 32;
356 frm_position.size.width = line_height * 48;
357 colwidth = line_height * 12;
358 if (owner_form)
359 {
360 gate_ui_ctrl_get_position(&owner_form->ctrl, &owner_position);
361 frm_position.pos.x = owner_position.pos.x + (owner_position.size.width - frm_position.size.width) / 2;
362 frm_position.pos.y = owner_position.pos.y + (owner_position.size.height - frm_position.size.height) / 2;
363 }
364
365 ret = gate_ui_host_default_workarea(host, &workarea);
366 if (GATE_SUCCEEDED(ret))
367 {
368 if (frm_position.pos.x + frm_position.size.width > workarea.pos.x + workarea.size.width)
369 {
370 frm_position.pos.x = workarea.pos.x + workarea.size.width - frm_position.size.width;
371 }
372 if (frm_position.pos.y + frm_position.size.height > workarea.pos.y + workarea.size.height)
373 {
374 frm_position.pos.y = workarea.pos.y + workarea.size.height - frm_position.size.height;
375 }
376
377 if (frm_position.pos.x < workarea.pos.x)
378 {
379 frm_position.pos.x = workarea.pos.x;
380 }
381 if (frm_position.pos.y < workarea.pos.y)
382 {
383 frm_position.pos.y = workarea.pos.y;
384 }
385 }
386
387 ret = gate_ui_form_create(&frm_dialog, host, &frm_position, title,
388 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_RESIZABLE | GATE_UI_FLAG_FORM_DIALOGSTYLE,
389 owner_form, &context);
390 GATE_BREAK_IF_FAILED(ret);
391 ret = gate_ui_form_set_layout(&frm_dialog, &layout);
392 GATE_BREAK_IF_FAILED(ret);
393
394 ret = gate_ui_label_create(&lbl_msg, &frm_dialog.ctrl, NULL, text,
395 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, NULL);
396 GATE_BREAK_IF_FAILED(ret);
397
398 ret = gate_ui_listview_create(&lv_table, &frm_dialog.ctrl, NULL,
399 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, &context);
400 GATE_BREAK_IF_FAILED(ret);
401
402 ret = gate_ui_button_create(&btn_ok, &frm_dialog.ctrl, NULL, &text_ok,
403 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, &context);
404 GATE_BREAK_IF_FAILED(ret);
405
406 ret = gate_ui_button_create(&btn_cancel, &frm_dialog.ctrl, NULL, &text_cancel,
407 GATE_UI_FLAG_ENABLED | GATE_UI_FLAG_VISIBLE, &context);
408 GATE_BREAK_IF_FAILED(ret);
409
410 frm_dialog.on_confirm = &choicebox_btn_ok_on_click;
411 frm_dialog.on_cancel = &choicebox_btn_cancel_on_click;
412 btn_ok.on_click = &choicebox_btn_ok_on_click;
413 btn_cancel.on_click = &choicebox_btn_cancel_on_click;
414 lv_table.on_open = &choicebox_lv_open;
415
416 ret = gate_ui_ctrl_set_visible(&frm_dialog.ctrl, true);
417 GATE_BREAK_IF_FAILED(ret);
418 ret = gate_ui_ctrl_refresh(&frm_dialog.ctrl);
419 GATE_BREAK_IF_FAILED(ret);
420
421 ret = gate_ui_dialog_session_init(&context.dlg_session, host, &frm_dialog.ctrl);
422 GATE_BREAK_IF_FAILED(ret);
423 ret = gate_ui_form_begin_dialog(&frm_dialog);
424 GATE_BREAK_IF_FAILED(ret);
425
426 count = gate_proptable_get_column_count(table);
427 for (colindex = 0; colindex != count; ++colindex)
428 {
429 result = gate_proptable_get_column_name(table, colindex, &str_tmp);
430 if (GATE_FAILED(result))
431 {
432 continue;
433 }
434 if (!gate_string_starts_with_str(&str_tmp, "__"))
435 {
436 proptype = gate_proptable_get_column_type(table, colindex);
437 if ((proptype == GATE_PROPERTY_TYPE_INT) || (proptype == GATE_PROPERTY_TYPE_REAL))
438 {
439 flags = GATE_UI_LISTVIEW_COLUMN_RIGHT;
440 }
441 else
442 {
443 flags = GATE_UI_LISTVIEW_COLUMN_LEFT;
444 }
445 result = gate_ui_listview_column_create(&columns[indices_used], &str_tmp, colwidth, flags);
446 GATE_BREAK_IF_FAILED(result);
447 if (GATE_SUCCEEDED(result))
448 {
449 indices[indices_used] = colindex;
450 ++indices_used;
451 }
452 }
453 gate_string_release(&str_tmp);
454 }
455
456 ret = gate_ui_listview_set_columns(&lv_table, columns, indices_used);
457 GATE_BREAK_IF_FAILED(ret);
458
459 count = gate_proptable_get_row_count(table);
460 for (index = 0; index != count; ++index)
461 {
462 ret = gate_ui_listview_insert_item(&lv_table, &index, NULL, GATE_UI_LISTVIEW_INVALID_ICON, (void*)index);
463 for (colindex = 0; colindex != indices_used; ++colindex)
464 {
465 ptr_prop = gate_proptable_get_item_at(table, index, indices[colindex]);
466 if (ptr_prop)
467 {
468 result = gate_property_get_string(ptr_prop, &str_prop);
469 if (GATE_SUCCEEDED(result))
470 {
471 gate_ui_listview_set_text(&lv_table, index, colindex, &str_prop);
472 gate_string_release(&str_prop);
473 }
474 }
475 }
476 }
477
478 do
479 {
480 ret = gate_ui_dialog_session_run(&context.dlg_session);
481 GATE_BREAK_IF_FAILED(ret);
482
483 if (context.confirmed)
484 {
485 result = gate_ui_listview_get_selected_item(&lv_table, &index);
486 if (GATE_SUCCEEDED(result))
487 {
488 rowindex = (gate_size_t)gate_ui_listview_get_item_param(&lv_table, index);
489 ret = gate_proptable_get_row(table, rowindex, selected_entry);
490 }
491 }
492 else
493 {
494 ret = GATE_RESULT_CANCELED;
495 }
496 } while (0);
497
498 gate_ui_form_end_dialog(&frm_dialog);
499 gate_ui_dialog_session_uninit(&context.dlg_session);
500
501 } while (0);
502
503 //gate_ui_listview_columns_release(columns, indices_used);
504 gate_ui_ctrl_destroy(&lbl_msg.ctrl);
505 gate_ui_ctrl_destroy(&lv_table.ctrl);
506 gate_ui_ctrl_destroy(&btn_cancel.ctrl);
507 gate_ui_ctrl_destroy(&btn_ok.ctrl);
508 gate_ui_ctrl_destroy(&frm_dialog.ctrl);
509
510 gate_ui_layout_destroy(&layout);
511
512 return ret;
513 }
514
515
516
517
518
519
520 #if defined(GATE_UI_WINAPI)
521
522 #include "gate/ui/gateui_winapi.h"
523 #include "gate/debugging.h"
524 #include "gate/platforms.h"
525 #include "gate/results.h"
526 #include <commdlg.h>
527
528 #if defined(GATE_COMPILER_MSVC)
529 # if defined(GATE_SYS_WINCE)
530 # pragma comment(lib, "Ceshell.lib")
531 # pragma comment(lib, "Commdlg.lib")
532 # else
533 # pragma comment(lib, "Comdlg32.lib")
534 # endif
535 #endif
536
537 gate_result_t gate_ui_dialog_session_init(gate_ui_dialog_session_t* session, gate_ui_host_t* host, gate_ui_ctrl_t* ctrl)
538 {
539 gate_result_t ret = GATE_RESULT_FAILED;
540 do
541 {
542 if (session == NULL)
543 {
544 ret = GATE_RESULT_NULLPOINTER;
545 break;
546 }
547 gate_mem_clear(session, sizeof(gate_ui_dialog_session_t));
548
549 if (NULL == ctrl)
550 {
551 ret = GATE_RESULT_INVALIDARG;
552 break;
553 }
554
555 session->handles[0] = host;
556 session->handles[1] = ctrl;
557 session->handles[2] = gate_ui_dialog_session_offline;
558 ret = GATE_RESULT_OK;
559 } while (0);
560 return ret;
561 }
562 gate_result_t gate_ui_dialog_session_run(gate_ui_dialog_session_t* session)
563 {
564 gate_result_t ret = GATE_RESULT_OK;
565 gate_ui_host_t* host = (gate_ui_host_t*)session->handles[0];
566 gate_ui_ctrl_t* ctrl = (gate_ui_ctrl_t*)session->handles[1];
567 HWND hwnd = (HWND)NULL;
568
569 session->handles[2] = gate_ui_dialog_session_online;
570
571 if (ctrl)
572 {
573 hwnd = GATE_UI_WINAPI_GET_HWND(ctrl);
574 }
575
576 while (GATE_SUCCEEDED(ret) && (session->handles[2] == gate_ui_dialog_session_online))
577 {
578 ret = gate_ui_winapi_host_process_dlg_msg(host, (void*)hwnd);
579 if (ret == GATE_RESULT_CANCELED)
580 {
581 PostQuitMessage(0);
582 ret = GATE_RESULT_OK;
583 break;
584 }
585 }
586 return ret;
587 }
588 gate_result_t gate_ui_dialog_session_quit(gate_ui_dialog_session_t* session)
589 {
590 gate_ui_host_t* host = (gate_ui_host_t*)session->handles[0];
591 session->handles[2] = gate_ui_dialog_session_offline;
592 return gate_ui_winapi_host_post_noop(host);
593 }
594 gate_result_t gate_ui_dialog_session_uninit(gate_ui_dialog_session_t* session)
595 {
596 gate_mem_clear(session, sizeof(gate_ui_dialog_session_t));
597 return GATE_RESULT_OK;
598 }
599
600
601
602
603 gate_result_t gate_ui_dialog_msgbox(gate_ui_ctrl_t* owner, gate_string_t const* text, gate_string_t const* title, gate_enumint_t type, gate_enumint_t* choice)
604 {
605 HWND hwnd = (HWND)NULL;
606 TCHAR bufferText[4096];
607 TCHAR bufferTitle[256];
608 UINT uType = 0;
609
610 int result;
611 if (owner != NULL)
612 {
613 hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(owner);
614 }
615
616 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK)) uType = MB_OK;
617 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL)) uType = MB_OKCANCEL;
618 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO)) uType = MB_YESNO;
619 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL)) uType = MB_YESNOCANCEL;
620 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL)) uType = MB_RETRYCANCEL;
621 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE)) uType = MB_ABORTRETRYIGNORE;
622 else return GATE_RESULT_INVALIDARG;
623
624 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_INFO)) uType |= MB_ICONINFORMATION;
625 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_QUESTION)) uType |= MB_ICONQUESTION;
626 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_WARNING)) uType |= MB_ICONEXCLAMATION;
627 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_ERROR)) uType |= MB_ICONHAND;
628
629 #if !defined(GATE_SYS_WINCE)
630 uType |= MB_TASKMODAL;
631 #endif
632
633 gate_win32_utf8_2_winstr(text->str, text->length, bufferText, sizeof(bufferText) / sizeof(bufferText[0]));
634 gate_win32_utf8_2_winstr(title->str, title->length, bufferTitle, sizeof(bufferTitle) / sizeof(bufferTitle[0]));
635
636 result = MessageBox(hwnd, bufferText, bufferTitle, uType);
637 switch (result)
638 {
639 case IDOK: *choice = GATE_UI_MSGBOX_CHOICE_OK; return GATE_RESULT_OK;
640 case IDCANCEL: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; return GATE_RESULT_OK;
641 case IDYES: *choice = GATE_UI_MSGBOX_CHOICE_YES; return GATE_RESULT_OK;
642 case IDNO: *choice = GATE_UI_MSGBOX_CHOICE_NO; return GATE_RESULT_OK;
643 case IDABORT: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; return GATE_RESULT_OK;
644 case IDIGNORE: *choice = GATE_UI_MSGBOX_CHOICE_IGNORE; return GATE_RESULT_OK;
645 case IDRETRY: *choice = GATE_UI_MSGBOX_CHOICE_RETRY; return GATE_RESULT_OK;
646 default:
647 {
648 return GATE_RESULT_CANCELED;
649 }
650 }
651 }
652
653
654
655 #ifndef CDERR_STRUCTSIZE
656 # define CDERR_STRUCTSIZE 0x0001
657 #endif
658
659 gate_result_t gate_ui_dialog_openfile(gate_ui_ctrl_t* owner,
660 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
661 gate_string_t const* title, gate_string_t const* initialdir,
662 gate_string_t* filepath
663 )
664 {
665 OPENFILENAME ofn;
666 TCHAR filename[2048];
667 TCHAR filetitle[1024];
668 TCHAR filedir[2048];
669 TCHAR dlgtitle[1024];
670 TCHAR filter[1024];
671 TCHAR defext[256];
672 TCHAR* ptrfilter = &filter[0];
673 gate_size_t filterlen = sizeof(filter) / sizeof(filter[0]) - 2;
674 //gate_strbuilder_t filterbuilder;
675 gate_size_t ndx;
676 gate_size_t extlen, descrlen;
677 DWORD dwError;
678
679 gate_mem_clear(&ofn, sizeof(ofn));
680
681 ofn.lStructSize = sizeof(ofn);
682 if (owner != NULL)
683 {
684 ofn.hwndOwner = GATE_UI_WINAPI_GET_HWND(owner);
685 }
686 ofn.hInstance = gate_win32_get_hinst();
687
688 if (filepath != NULL)
689 {
690 gate_win32_utf8_2_winstr(filepath->str, filepath->length, filename, sizeof(filename) / sizeof(filename[0]));
691 }
692 else
693 {
694 filename[0] = 0;
695 }
696
697 if (title != NULL)
698 {
699 gate_win32_utf8_2_winstr(title->str, title->length, dlgtitle, sizeof(dlgtitle) / sizeof(dlgtitle[0]));
700 ofn.lpstrTitle = &dlgtitle[0];
701 }
702 else
703 {
704 ofn.lpstrTitle = NULL;
705 }
706
707 if ((filefilters != NULL) && (filefiltercount > 0))
708 {
709 /* build file filters */
710 GATE_DEBUG_ASSERT(selectedfilefilter ? (*selectedfilefilter < filefiltercount) : true);
711 //gate_strbuilder_create(&filterbuilder, 256);
712 for (ndx = 0; ndx != filefiltercount; ++ndx)
713 {
714 extlen = gate_str_length(filefilters[ndx].extension);
715 descrlen = gate_str_length(filefilters[ndx].description);
716 if (extlen + descrlen + 4 >= filterlen)
717 {
718 break;
719 }
720 if ((selectedfilefilter != NULL) && (*selectedfilefilter == ndx))
721 {
722 gate_win32_utf8_2_winstr(filefilters[ndx].extension, extlen, defext, sizeof(defext) / sizeof(defext[0]));
723 ofn.lpstrDefExt = &defext[0];
724 ofn.nFilterIndex = (DWORD)ndx + 1;
725 }
726 descrlen = gate_win32_utf8_2_winstr(filefilters[ndx].description, descrlen, ptrfilter, filterlen);
727 ptrfilter[descrlen] = 0;
728 ptrfilter += (descrlen + 1);
729 filterlen -= (descrlen + 1);
730 extlen = gate_win32_utf8_2_winstr(filefilters[ndx].extension, extlen, ptrfilter, filterlen);
731 ptrfilter[extlen] = 0;
732 ptrfilter += (extlen + 1);
733 filterlen -= (extlen + 1);
734 }
735 ptrfilter[0] = 0;
736 ptrfilter[1] = 0;
737
738 ofn.lpstrFilter = &filter[0];
739 }
740 else
741 {
742 ofn.lpstrFilter = NULL;
743 ofn.nFilterIndex = 0;
744 ofn.lpstrDefExt = NULL;
745 }
746
747 if (initialdir != NULL)
748 {
749 gate_win32_utf8_2_winstr(initialdir->str, initialdir->length, filedir, sizeof(filedir) / sizeof(filedir[0]));
750 ofn.lpstrInitialDir = &filedir[0];
751 }
752 else
753 {
754 ofn.lpstrInitialDir = NULL;
755 }
756
757 ofn.lpstrFile = &filename[0];
758 ofn.nMaxFile = sizeof(filename) / sizeof(filename[0]) - 1;
759 ofn.lpstrFileTitle = filetitle;
760 ofn.nMaxFileTitle = sizeof(filetitle) / sizeof(filetitle[0]);
761
762 ofn.Flags = OFN_EXPLORER | OFN_CREATEPROMPT | OFN_FILEMUSTEXIST
763 #if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16)
764 | OFN_ENABLESIZING
765 #endif
766 ;
767 if (FALSE == GetOpenFileName(&ofn))
768 {
769 /* cancelled or error */
770 dwError = CommDlgExtendedError();
771 if (dwError == 0)
772 {
773 /* cancelled by user */
774 return GATE_RESULT_CANCELED;
775 }
776 #if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16)
777 else if (dwError == CDERR_STRUCTSIZE)
778 {
779 /* retry with NT4-compatible format */
780 ofn.lStructSize = sizeof(OPENFILENAME_NT4);
781 if (FALSE == GetOpenFileName(&ofn))
782 {
783 dwError = CommDlgExtendedError();
784 if (dwError == 0)
785 {
786 /* cancelled by user */
787 return GATE_RESULT_CANCELED;
788 }
789 else
790 {
791 /* anything else is an internal error */
792 return GATE_RESULT_FAILED;
793 }
794 }
795 }
796 #endif
797 else
798 {
799 /* anything else is an internal error */
800 return GATE_RESULT_FAILED;
801 }
802 }
803
804 /* call succeeded */
805 if ((selectedfilefilter != NULL) && (ofn.nFilterIndex > 0))
806 {
807 *selectedfilefilter = ofn.nFilterIndex - 1;
808 }
809 if (filepath != NULL)
810 {
811 gate_string_release(filepath);
812 gate_win32_winstr_2_utf8_string(filename, gate_win32_winstr_length(filename), filepath);
813 }
814 return GATE_RESULT_OK;
815 }
816
817 gate_result_t gate_ui_dialog_savefile(gate_ui_ctrl_t* owner,
818 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
819 gate_string_t const* title, gate_string_t const* initialdir,
820 gate_string_t* filepath
821 )
822 {
823 OPENFILENAME ofn;
824 TCHAR filename[2048];
825 TCHAR filetitle[1024];
826 TCHAR filedir[2048];
827 TCHAR dlgtitle[1024];
828 TCHAR filter[1024];
829 TCHAR defext[256];
830 TCHAR* ptrfilter = &filter[0];
831 gate_size_t filterlen = sizeof(filter) / sizeof(filter[0]) - 2;
832 //gate_strbuilder_t filterbuilder;
833 gate_size_t ndx;
834 gate_size_t extlen, descrlen;
835 DWORD dwError;
836
837 gate_mem_clear(&ofn, sizeof(ofn));
838
839 ofn.lStructSize = sizeof(ofn);
840 if (owner != NULL)
841 {
842 ofn.hwndOwner = GATE_UI_WINAPI_GET_HWND(owner);
843 }
844 ofn.hInstance = gate_win32_get_hinst();
845
846 if (filepath != NULL)
847 {
848 gate_win32_utf8_2_winstr(filepath->str, filepath->length, filename, sizeof(filename) / sizeof(filename[0]));
849 }
850 else
851 {
852 filename[0] = 0;
853 }
854
855 if (title != NULL)
856 {
857 gate_win32_utf8_2_winstr(title->str, title->length, dlgtitle, sizeof(dlgtitle) / sizeof(dlgtitle[0]));
858 ofn.lpstrTitle = &dlgtitle[0];
859 }
860 else
861 {
862 ofn.lpstrTitle = NULL;
863 }
864
865 if ((filefilters != NULL) && (filefiltercount > 0))
866 {
867 /* build file filters */
868 GATE_DEBUG_ASSERT(selectedfilefilter ? (*selectedfilefilter < filefiltercount) : true);
869 //gate_strbuilder_create(&filterbuilder, 256);
870 for (ndx = 0; ndx != filefiltercount; ++ndx)
871 {
872 extlen = gate_str_length(filefilters[ndx].extension);
873 descrlen = gate_str_length(filefilters[ndx].description);
874 if (extlen + descrlen + 4 >= filterlen)
875 {
876 break;
877 }
878 if ((selectedfilefilter != NULL) && (*selectedfilefilter == ndx))
879 {
880 gate_win32_utf8_2_winstr(filefilters[ndx].extension, extlen, defext, sizeof(defext) / sizeof(defext[0]));
881 ofn.lpstrDefExt = &defext[0];
882 ofn.nFilterIndex = (DWORD)ndx + 1;
883 }
884 descrlen = gate_win32_utf8_2_winstr(filefilters[ndx].description, descrlen, ptrfilter, filterlen);
885 ptrfilter[descrlen] = 0;
886 ptrfilter += (descrlen + 1);
887 filterlen -= (descrlen + 1);
888 extlen = gate_win32_utf8_2_winstr(filefilters[ndx].extension, extlen, ptrfilter, filterlen);
889 ptrfilter[extlen] = 0;
890 ptrfilter += (extlen + 1);
891 filterlen -= (extlen + 1);
892 }
893 ptrfilter[0] = 0;
894 ptrfilter[1] = 0;
895
896 ofn.lpstrFilter = &filter[0];
897 }
898 else
899 {
900 ofn.lpstrFilter = NULL;
901 ofn.nFilterIndex = 0;
902 ofn.lpstrDefExt = NULL;
903 }
904
905 if (initialdir != NULL)
906 {
907 gate_win32_utf8_2_winstr(initialdir->str, initialdir->length, filedir, sizeof(filedir) / sizeof(filedir[0]));
908 ofn.lpstrInitialDir = &filedir[0];
909 }
910 else
911 {
912 ofn.lpstrInitialDir = NULL;
913 }
914
915 ofn.lpstrFile = &filename[0];
916 ofn.nMaxFile = sizeof(filename) / sizeof(filename[0]) - 1;
917 ofn.lpstrFileTitle = filetitle;
918 ofn.nMaxFileTitle = sizeof(filetitle) / sizeof(filetitle[0]);
919
920 ofn.Flags = OFN_EXPLORER | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT
921 #if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16)
922 | OFN_ENABLESIZING
923 #endif
924 ;
925 if (FALSE == GetSaveFileName(&ofn))
926 {
927 /* cancelled or error */
928 dwError = CommDlgExtendedError();
929 if (dwError == 0)
930 {
931 /* cancelled by user */
932 return GATE_RESULT_CANCELED;
933 }
934 #if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16)
935 else if (dwError == CDERR_STRUCTSIZE)
936 {
937 /* retry with NT4-compatible format */
938 ofn.lStructSize = sizeof(OPENFILENAME_NT4);
939 if (FALSE == GetOpenFileName(&ofn))
940 {
941 dwError = CommDlgExtendedError();
942 if (dwError == 0)
943 {
944 /* cancelled by user */
945 return GATE_RESULT_CANCELED;
946 }
947 else
948 {
949 /* anything else is an internal error */
950 return GATE_RESULT_FAILED;
951 }
952 }
953 }
954 #endif
955 else
956 {
957 /* anything else is an internal error */
958 return GATE_RESULT_FAILED;
959 }
960 }
961
962 if ((selectedfilefilter != NULL) && (ofn.nFilterIndex > 0))
963 {
964 *selectedfilefilter = ofn.nFilterIndex - 1;
965 }
966 if (filepath != NULL)
967 {
968 gate_string_release(filepath);
969 gate_win32_winstr_2_utf8_string(filename, gate_win32_winstr_length(filename), filepath);
970 }
971 return GATE_RESULT_OK;
972 }
973
974
975 #endif /* GATE_UI_WINAPI */
976
977
978 #if defined(GATE_UI_GTK)
979
980 #include "gate/ui/gateui_gtk.h"
981
982
983 gate_result_t gate_ui_dialog_session_init(gate_ui_dialog_session_t* session, gate_ui_host_t* host, gate_ui_ctrl_t* ctrl)
984 {
985 gate_mem_clear(session, sizeof(session));
986 session->handles[0] = host;
987 session->handles[1] = ctrl;
988 session->handles[2] = gate_ui_dialog_session_offline;
989 return GATE_RESULT_OK;
990 }
991 gate_result_t gate_ui_dialog_session_run(gate_ui_dialog_session_t* session)
992 {
993 gate_result_t ret = GATE_RESULT_OK;
994 session->handles[2] = gate_ui_dialog_session_online;
995
996 while (session->handles[2] == gate_ui_dialog_session_online)
997 {
998 if (gtk_main_iteration())
999 {
1000 /* gtk_main_quit() was called */
1001 break;
1002 }
1003 }
1004 session->handles[2] = gate_ui_dialog_session_offline;
1005 return ret;
1006 }
1007 gate_result_t gate_ui_dialog_session_quit(gate_ui_dialog_session_t* session)
1008 {
1009 session->handles[2] = gate_ui_dialog_session_offline;
1010 return GATE_RESULT_OK;
1011 }
1012 gate_result_t gate_ui_dialog_session_uninit(gate_ui_dialog_session_t* session)
1013 {
1014 gate_mem_clear(session, sizeof(session));
1015 return GATE_RESULT_OK;
1016 }
1017
1018
1019 gate_result_t gate_ui_dialog_msgbox(gate_ui_ctrl_t* parent, gate_string_t const* text, gate_string_t const* title, gate_enumint_t type, gate_enumint_t* choice)
1020 {
1021 gate_result_t result = GATE_RESULT_OK;
1022 GtkWidget* parent_widget = GATE_UI_GTK_GET_CTRL_WIDGET(parent);
1023 GtkWidget* dialog;
1024 GtkMessageType msg_type;
1025 GtkButtonsType btn_type;
1026 gint dialog_result;
1027 char title_buffer[256];
1028 char text_buffer[4096];
1029
1030 if (!gate_string_is_empty(text))
1031 {
1032 gate_str_print_text(text_buffer, sizeof(text_buffer), text->str, text->length);
1033 }
1034 else
1035 {
1036 text_buffer[0] = 0;
1037 }
1038
1039 if (!gate_string_is_empty(title))
1040 {
1041 gate_str_print_text(title_buffer, sizeof(title_buffer), title->str, title->length);
1042 }
1043 else
1044 {
1045 title_buffer[0] = 0;
1046 }
1047
1048 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK)) btn_type = GTK_BUTTONS_OK;
1049 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL)) btn_type = GTK_BUTTONS_CANCEL;
1050 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO)) btn_type = GTK_BUTTONS_YES_NO;
1051 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL)) btn_type = GTK_BUTTONS_YES_NO;
1052 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL)) btn_type = GTK_BUTTONS_OK_CANCEL;
1053 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE))btn_type = GTK_BUTTONS_YES_NO;
1054 else return GATE_RESULT_INVALIDARG;
1055
1056 msg_type = GTK_MESSAGE_OTHER;
1057 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_INFO)) msg_type = GTK_MESSAGE_INFO;
1058 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_QUESTION)) msg_type = GTK_MESSAGE_QUESTION;
1059 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_WARNING)) msg_type = GTK_MESSAGE_WARNING;
1060 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_ERROR)) msg_type = GTK_MESSAGE_ERROR;
1061
1062
1063 dialog = gtk_message_dialog_new(GTK_WINDOW(parent_widget), GTK_DIALOG_MODAL, msg_type, btn_type, "%s", text_buffer);
1064 gtk_window_set_title(GTK_WINDOW(dialog), title_buffer);
1065
1066 dialog_result = gtk_dialog_run(GTK_DIALOG(dialog));
1067
1068 gtk_widget_destroy(dialog);
1069
1070 if (choice != NULL)
1071 {
1072 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK))
1073 {
1074 *choice = GATE_UI_MSGBOX_CHOICE_OK;
1075 }
1076 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL))
1077 {
1078 switch (dialog_result)
1079 {
1080 case GTK_RESPONSE_OK:
1081 *choice = GATE_UI_MSGBOX_CHOICE_OK;
1082 break;
1083 default:
1084 *choice = GATE_UI_MSGBOX_CHOICE_CANCEL;
1085 break;
1086 }
1087 }
1088 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO))
1089 {
1090 switch (dialog_result)
1091 {
1092 case GTK_RESPONSE_YES:
1093 *choice = GATE_UI_MSGBOX_CHOICE_YES;
1094 break;
1095 default:
1096 *choice = GATE_UI_MSGBOX_CHOICE_NO;
1097 break;
1098 }
1099 }
1100 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL))
1101 {
1102 switch (dialog_result)
1103 {
1104 case GTK_RESPONSE_YES:
1105 *choice = GATE_UI_MSGBOX_CHOICE_YES;
1106 break;
1107 case GTK_RESPONSE_NO:
1108 *choice = GATE_UI_MSGBOX_CHOICE_NO;
1109 break;
1110 default:
1111 *choice = GATE_UI_MSGBOX_CHOICE_CANCEL;
1112 break;
1113 }
1114
1115 }
1116 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL))
1117 {
1118 switch (dialog_result)
1119 {
1120 case GTK_RESPONSE_OK:
1121 *choice = GATE_UI_MSGBOX_CHOICE_RETRY;
1122 break;
1123 default:
1124 *choice = GATE_UI_MSGBOX_CHOICE_CANCEL;
1125 break;
1126 }
1127 }
1128 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE))
1129 {
1130 switch (dialog_result)
1131 {
1132 case GTK_RESPONSE_YES:
1133 *choice = GATE_UI_MSGBOX_CHOICE_RETRY;
1134 break;
1135 case GTK_RESPONSE_NO:
1136 *choice = GATE_UI_MSGBOX_CHOICE_CANCEL;
1137 break;
1138 default:
1139 *choice = GATE_UI_MSGBOX_CHOICE_IGNORE;
1140 break;
1141 }
1142 }
1143 else
1144 {
1145 *choice = GATE_UI_MSGBOX_CHOICE_CANCEL;
1146 }
1147 }
1148
1149 return result;
1150 }
1151
1152
1153 gate_result_t gate_ui_dialog_openfile(gate_ui_ctrl_t* parent,
1154 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
1155 gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1156 {
1157 gate_result_t ret = GATE_RESULT_FAILED;
1158 GtkWidget* parent_widget = GATE_UI_GTK_GET_CTRL_WIDGET(parent);
1159 GtkWidget* dialog;
1160 GtkFileChooser* chooser;
1161 GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
1162 gint res;
1163 gchar* ptr_filepath;
1164
1165 dialog = gtk_file_chooser_dialog_new("Open File",
1166 GTK_WINDOW(parent_widget),
1167 action,
1168 "_Cancel", GTK_RESPONSE_CANCEL,
1169 "_Open", GTK_RESPONSE_ACCEPT,
1170 NULL);
1171
1172 res = gtk_dialog_run(GTK_DIALOG(dialog));
1173 if (res == GTK_RESPONSE_ACCEPT)
1174 {
1175 chooser = GTK_FILE_CHOOSER(dialog);
1176 ptr_filepath = gtk_file_chooser_get_filename(chooser);
1177 if (ptr_filepath)
1178 {
1179 if (NULL != gate_string_create(filepath, ptr_filepath, gate_str_length(ptr_filepath)))
1180 {
1181 ret = GATE_RESULT_OK;
1182 }
1183 g_free(ptr_filepath);
1184 }
1185 }
1186 else if (res == GTK_RESPONSE_CANCEL)
1187 {
1188 ret = GATE_RESULT_CANCELED;
1189 }
1190 gtk_widget_destroy(dialog);
1191
1192 return ret;
1193 }
1194
1195 gate_result_t gate_ui_dialog_savefile(gate_ui_ctrl_t* parent,
1196 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
1197 gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1198 {
1199 gate_result_t ret = GATE_RESULT_FAILED;
1200 GtkWidget* parent_widget = GATE_UI_GTK_GET_CTRL_WIDGET(parent);
1201 GtkWidget* dialog;
1202 GtkFileChooser* chooser;
1203 GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
1204 gint res;
1205 gchar* ptr_filepath;
1206
1207 dialog = gtk_file_chooser_dialog_new("Save File",
1208 GTK_WINDOW(parent_widget),
1209 action,
1210 "_Cancel", GTK_RESPONSE_CANCEL,
1211 "_Save", GTK_RESPONSE_ACCEPT,
1212 NULL);
1213
1214 res = gtk_dialog_run(GTK_DIALOG(dialog));
1215 if (res == GTK_RESPONSE_ACCEPT)
1216 {
1217 chooser = GTK_FILE_CHOOSER(dialog);
1218 ptr_filepath = gtk_file_chooser_get_filename(chooser);
1219 if (ptr_filepath)
1220 {
1221 if (NULL != gate_string_create(filepath, ptr_filepath, gate_str_length(ptr_filepath)))
1222 {
1223 ret = GATE_RESULT_OK;
1224 }
1225 g_free(ptr_filepath);
1226 }
1227 }
1228 else if (res == GTK_RESPONSE_CANCEL)
1229 {
1230 ret = GATE_RESULT_CANCELED;
1231 }
1232 gtk_widget_destroy(dialog);
1233
1234 return ret;
1235 }
1236
1237 #endif /* GATE_UI_GTK */
1238
1239
1240
1241 #if defined(GATE_UI_MOTIF)
1242
1243 #include "gate/ui/gateui_motif.h"
1244 #include <Xm/MessageB.h>
1245 #include <Xm/FileSB.h>
1246
1247 gate_result_t gate_ui_dialog_session_init(gate_ui_dialog_session_t* session, gate_ui_host_t* host, gate_ui_ctrl_t* ctrl)
1248 {
1249 Widget w_ctrl = NULL;
1250 Widget w_owner = NULL;
1251 gate_mem_clear(session, sizeof(gate_ui_dialog_session_t));
1252 session->handles[0] = session;
1253 session->handles[1] = host;
1254 session->handles[2] = ctrl;
1255 return GATE_RESULT_OK;
1256 }
1257 gate_result_t gate_ui_dialog_session_run(gate_ui_dialog_session_t* session)
1258 {
1259 gate_result_t ret = GATE_RESULT_FAILED;
1260 gate_ui_host_t* host;
1261 Widget w_owner;
1262
1263 do
1264 {
1265 if (!session)
1266 {
1267 ret = GATE_RESULT_INVALIDARG;
1268 break;
1269 }
1270 host = (gate_ui_host_t*)session->handles[1];
1271 if (!host)
1272 {
1273 ret = GATE_RESULT_INVALIDSTATE;
1274 break;
1275 }
1276
1277 ret = GATE_RESULT_OK;
1278 while (session->handles[1] != NULL)
1279 {
1280 ret = gate_ui_motif_host_dispatch_pending_events(host, false);
1281 GATE_BREAK_IF_FAILED(ret);
1282 }
1283
1284 } while (0);
1285
1286 return ret;
1287 }
1288 gate_result_t gate_ui_dialog_session_quit(gate_ui_dialog_session_t* session)
1289 {
1290 session->handles[1] = NULL;
1291 return GATE_RESULT_OK;
1292 }
1293 gate_result_t gate_ui_dialog_session_uninit(gate_ui_dialog_session_t* session)
1294 {
1295 gate_mem_clear(session, sizeof(gate_ui_dialog_session_t));
1296 return GATE_RESULT_OK;
1297 }
1298
1299
1300 static void gate_ui_dialog_msgbox_callback(Widget widget, XtPointer client_data, XtPointer call_data)
1301 {
1302 gate_ui_dialog_session_t* session = (gate_ui_dialog_session_t*)client_data;
1303 XmAnyCallbackStruct* cbs = (XmAnyCallbackStruct*)call_data;
1304 gate_enumint_t* ptr_choice = (gate_enumint_t*)session->handles[3];
1305
1306 switch (cbs->reason)
1307 {
1308 case XmCR_OK: *ptr_choice = 1; break;
1309 case XmCR_CANCEL: *ptr_choice = 2; break;
1310 case XmCR_HELP: *ptr_choice = 3; break;
1311 }
1312
1313 gate_ui_dialog_session_quit(session);
1314 }
1315
1316 gate_result_t gate_ui_dialog_msgbox(gate_ui_ctrl_t* owner, gate_string_t const* text, gate_string_t const* title,
1317 gate_enumint_t type, gate_enumint_t* choice)
1318 {
1319 gate_result_t ret = GATE_RESULT_FAILED;
1320 gate_ui_host_t* host = GATE_UI_MOTIF_GET_CTRL_HOST(owner);
1321 Widget parent = GATE_UI_MOTIF_GET_CTRL_WIDGET(owner);
1322 Widget dialog = NULL;
1323 Widget child = NULL;
1324 gate_ui_dialog_session_t session;
1325 Arg arg[12];
1326 XmString msg_text = NULL;
1327 XmString msg_title = NULL;
1328 XmString msg_btn1 = NULL;
1329 XmString msg_btn2 = NULL;
1330 XmString msg_btn3 = NULL;
1331 gate_bool_t hide2 = false;
1332 gate_bool_t hide3 = false;
1333 int n = 0;
1334 gate_enumint_t user_choice = 0;
1335
1336 do
1337 {
1338 msg_text = gate_ui_motif_create_string(text);
1339 if (NULL == msg_text)
1340 {
1341 ret = GATE_RESULT_OUTOFMEMORY;
1342 break;
1343 }
1344 msg_title = gate_ui_motif_create_string(title);
1345 if (NULL == msg_text)
1346 {
1347 ret = GATE_RESULT_OUTOFMEMORY;
1348 break;
1349 }
1350 XtSetArg(arg[n], XmNmessageString, msg_text); ++n;
1351 XtSetArg(arg[n], XmNdialogTitle, msg_title); ++n;
1352
1353 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK))
1354 {
1355 msg_btn2 = XmStringCreateLocalized("");
1356 msg_btn3 = XmStringCreateLocalized("");
1357 hide2 = true;
1358 hide3 = true;
1359 XtSetArg(arg[n], XmNcancelLabelString, msg_btn2); ++n;
1360 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1361 }
1362 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL))
1363 {
1364 msg_btn3 = XmStringCreateLocalized("");
1365 hide3 = true;
1366 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1367 }
1368 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO))
1369 {
1370 msg_btn1 = XmStringCreateLocalized("Yes");
1371 msg_btn2 = XmStringCreateLocalized("No");
1372 msg_btn3 = XmStringCreateLocalized("");
1373 hide3 = true;
1374 XtSetArg(arg[n], XmNokLabelString, msg_btn1); ++n;
1375 XtSetArg(arg[n], XmNcancelLabelString, msg_btn2); ++n;
1376 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1377 }
1378 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL))
1379 {
1380 msg_btn1 = XmStringCreateLocalized("Yes");
1381 msg_btn2 = XmStringCreateLocalized("No");
1382 msg_btn3 = XmStringCreateLocalized("Cancel");
1383 XtSetArg(arg[n], XmNokLabelString, msg_btn1); ++n;
1384 XtSetArg(arg[n], XmNcancelLabelString, msg_btn2); ++n;
1385 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1386 }
1387 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL))
1388 {
1389 msg_btn1 = XmStringCreateLocalized("Retry");
1390 msg_btn3 = XmStringCreateLocalized("");
1391 hide3 = true;
1392 XtSetArg(arg[n], XmNokLabelString, msg_btn1); ++n;
1393 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1394 }
1395 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE))
1396 {
1397 msg_btn1 = XmStringCreateLocalized("Retry");
1398 msg_btn2 = XmStringCreateLocalized("Ignore");
1399 msg_btn3 = XmStringCreateLocalized("");
1400 hide3 = true;
1401 XtSetArg(arg[n], XmNokLabelString, msg_btn1); ++n;
1402 XtSetArg(arg[n], XmNcancelLabelString, msg_btn2); ++n;
1403 XtSetArg(arg[n], XmNhelpLabelString, msg_btn3); ++n;
1404 }
1405
1406 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_INFO))
1407 {
1408 dialog = XmCreateInformationDialog(parent, "gate_ui_dialog_msgbox", arg, n);
1409 }
1410 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_QUESTION))
1411 {
1412 dialog = XmCreateQuestionDialog(parent, "gate_ui_dialog_msgbox", arg, n);
1413 }
1414 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_WARNING))
1415 {
1416 dialog = XmCreateWarningDialog(parent, "gate_ui_dialog_msgbox", arg, n);
1417 }
1418 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_ERROR))
1419 {
1420 dialog = XmCreateErrorDialog(parent, "gate_ui_dialog_msgbox", arg, n);
1421 }
1422 else
1423 {
1424 dialog = XmCreateMessageDialog(parent, "gate_ui_dialog_msgbox", arg, n);
1425 }
1426
1427 XtVaSetValues(dialog, XmNdialogStyle, XmDIALOG_APPLICATION_MODAL, NULL, NULL);
1428
1429 XtManageChild(dialog);
1430
1431 XtAddCallback(dialog, XmNokCallback, &gate_ui_dialog_msgbox_callback, &session);
1432 if (!hide2)
1433 {
1434 XtAddCallback(dialog, XmNcancelCallback, &gate_ui_dialog_msgbox_callback, &session);
1435 }
1436 else
1437 {
1438 child = XtNameToWidget(dialog, "Cancel");
1439 if (child)
1440 {
1441 XtVaSetValues(child, XmNsensitive, False, NULL);
1442 }
1443 }
1444 if (!hide3)
1445 {
1446 XtAddCallback(dialog, XmNhelpCallback, &gate_ui_dialog_msgbox_callback, &session);
1447 }
1448 else
1449 {
1450 child = XtNameToWidget(dialog, "Help");
1451 if (child)
1452 {
1453 XtVaSetValues(child, XmNsensitive, False, NULL);
1454 }
1455 }
1456
1457 ret = gate_ui_dialog_session_init(&session, host, owner);
1458 GATE_BREAK_IF_FAILED(ret);
1459 session.handles[3] = &user_choice;
1460
1461 ret = gate_ui_dialog_session_run(&session);
1462
1463 XtUnmanageChild(dialog);
1464
1465 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK))
1466 {
1467 *choice = GATE_UI_MSGBOX_CHOICE_OK;
1468 }
1469 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL))
1470 {
1471 switch (user_choice)
1472 {
1473 case 1: *choice = GATE_UI_MSGBOX_CHOICE_OK; break;
1474 case 2: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1475 case 3: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1476 }
1477 }
1478 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO))
1479 {
1480 switch (user_choice)
1481 {
1482 case 1: *choice = GATE_UI_MSGBOX_CHOICE_YES; break;
1483 case 2: *choice = GATE_UI_MSGBOX_CHOICE_NO; break;
1484 case 3: *choice = GATE_UI_MSGBOX_CHOICE_NO; break;
1485 }
1486 }
1487 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL))
1488 {
1489 switch (user_choice)
1490 {
1491 case 1: *choice = GATE_UI_MSGBOX_CHOICE_YES; break;
1492 case 2: *choice = GATE_UI_MSGBOX_CHOICE_NO; break;
1493 case 3: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1494 }
1495 }
1496 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL))
1497 {
1498 switch (user_choice)
1499 {
1500 case 1: *choice = GATE_UI_MSGBOX_CHOICE_RETRY; break;
1501 case 2: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1502 case 3: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1503 }
1504 }
1505 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE))
1506 {
1507 switch (user_choice)
1508 {
1509 case 1: *choice = GATE_UI_MSGBOX_CHOICE_RETRY; break;
1510 case 2: *choice = GATE_UI_MSGBOX_CHOICE_CANCEL; break;
1511 case 3: *choice = GATE_UI_MSGBOX_CHOICE_IGNORE; break;
1512 }
1513 }
1514 } while (0);
1515
1516 if (msg_text != NULL)
1517 {
1518 XmStringFree(msg_text);
1519 }
1520 if (msg_btn1 != NULL)
1521 {
1522 XmStringFree(msg_btn1);
1523 }
1524 if (msg_btn2 != NULL)
1525 {
1526 XmStringFree(msg_btn2);
1527 }
1528 if (msg_btn3 != NULL)
1529 {
1530 XmStringFree(msg_btn3);
1531 }
1532 if (msg_title != NULL)
1533 {
1534 XmStringFree(msg_title);
1535 }
1536 if (dialog)
1537 {
1538 XtDestroyWidget(dialog);
1539 }
1540 return ret;
1541 }
1542
1543
1544 static void gate_ui_dialog_file_ok(Widget widget, XtPointer client_data, XtPointer call_data)
1545 {
1546 gate_ui_dialog_session_t* session = (gate_ui_dialog_session_t*)client_data;
1547 XmFileSelectionBoxCallbackStruct* cbs = (XmFileSelectionBoxCallbackStruct*)call_data;
1548 char* filename = NULL;
1549
1550 if (session && cbs)
1551 {
1552 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &filename);
1553 session->handles[3] = filename;
1554 gate_ui_dialog_session_quit(session);
1555 }
1556 }
1557
1558 static void gate_ui_dialog_file_cancel(Widget widget, XtPointer client_data, XtPointer call_data)
1559 {
1560 gate_ui_dialog_session_t* session = (gate_ui_dialog_session_t*)client_data;
1561 char* filename = NULL;
1562
1563 if (session)
1564 {
1565 session->handles[3] = NULL;
1566 gate_ui_dialog_session_quit(session);
1567 }
1568 }
1569
1570
1571 gate_result_t gate_ui_dialog_openfile(gate_ui_ctrl_t* owner, gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount,
1572 gate_size_t* selectedfilefilter, gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1573 {
1574 gate_result_t ret = GATE_RESULT_FAILED;
1575 gate_ui_host_t* host = GATE_UI_MOTIF_GET_CTRL_HOST(owner);
1576 Widget parent = GATE_UI_MOTIF_GET_CTRL_WIDGET(owner);
1577 Widget dialog = NULL;
1578 gate_ui_dialog_session_t session;
1579 Arg arg[12];
1580 XmString str_title = NULL;
1581 XmString str_initdir = NULL;
1582 int n = 0;
1583 gate_uint32_t user_choice = 0;
1584 char* ptr_filename = NULL;
1585
1586 do
1587 {
1588 gate_mem_clear(filepath, sizeof(gate_string_t));
1589
1590 if (!gate_string_is_empty(title))
1591 {
1592 str_title = gate_ui_motif_create_string(title);
1593 if (NULL == str_title)
1594 {
1595 ret = GATE_RESULT_OUTOFMEMORY;
1596 break;
1597 }
1598 XtSetArg(arg[n], XmNtitle, str_title); ++n;
1599 }
1600
1601 XtSetArg(arg[n], XmNfileTypeMask, (XmFILE_REGULAR | XmFILE_DIRECTORY)); ++n;
1602
1603 if (!gate_string_is_empty(initialdir))
1604 {
1605 str_initdir = gate_ui_motif_create_string(initialdir);
1606 if (NULL == str_title)
1607 {
1608 ret = GATE_RESULT_OUTOFMEMORY;
1609 break;
1610 }
1611 XtSetArg(arg[n], XmNdirectory, str_initdir); ++n;
1612 }
1613
1614 dialog = XmCreateFileSelectionDialog(parent, "gate_ui_dialog_openfile", arg, n);
1615
1616 XtAddCallback(dialog, XmNcancelCallback, &gate_ui_dialog_file_cancel, &session);
1617 XtAddCallback(dialog, XmNokCallback, &gate_ui_dialog_file_ok, &session);
1618
1619 XtManageChild(dialog);
1620
1621 ret = gate_ui_dialog_session_init(&session, host, owner);
1622 GATE_BREAK_IF_FAILED(ret);
1623 session.handles[3] = &user_choice;
1624 ret = gate_ui_dialog_session_run(&session);
1625 ptr_filename = (char*)session.handles[3];
1626
1627 XtUnmanageChild(dialog);
1628 GATE_BREAK_IF_FAILED(ret);
1629
1630 if (ptr_filename == NULL)
1631 {
1632 ret = GATE_RESULT_CANCELED;
1633 }
1634 else
1635 {
1636 gate_string_create(filepath, ptr_filename, gate_str_length(ptr_filename));
1637 ret = GATE_RESULT_OK;
1638 }
1639 } while (0);
1640
1641 if (ptr_filename)
1642 {
1643 XtFree(ptr_filename);
1644 }
1645 if (dialog)
1646 {
1647 XtDestroyWidget(dialog);
1648 }
1649 if (str_initdir != NULL)
1650 {
1651 XmStringFree(str_initdir);
1652 }
1653 if (str_title != NULL)
1654 {
1655 XmStringFree(str_title);
1656 }
1657 return ret;
1658 }
1659
1660 gate_result_t gate_ui_dialog_savefile(gate_ui_ctrl_t* owner, gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount,
1661 gate_size_t* selectedfilefilter, gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1662 {
1663 return gate_ui_dialog_openfile(owner, filefilters, filefiltercount, selectedfilefilter, title, initialdir, filepath);
1664 }
1665
1666 #endif /* GATE_UI_MOTIF */
1667
1668
1669
1670
1671 #if defined(GATE_UI_WASMHTML)
1672
1673 #include "gate/ui/gateui_wasmhtml.h"
1674 #include "gate/platform/wasm/wasm_gate.h"
1675
1676 GATE_UI_API gate_result_t gate_ui_dialog_session_init(gate_ui_dialog_session_t* session, gate_ui_host_t* host, gate_ui_ctrl_t* ctrl)
1677 {
1678 return GATE_RESULT_NOTIMPLEMENTED;
1679 }
1680 GATE_UI_API gate_result_t gate_ui_dialog_session_run(gate_ui_dialog_session_t* session)
1681 {
1682 return GATE_RESULT_NOTIMPLEMENTED;
1683 }
1684 GATE_UI_API gate_result_t gate_ui_dialog_session_quit(gate_ui_dialog_session_t* session)
1685 {
1686 return GATE_RESULT_NOTIMPLEMENTED;
1687 }
1688 GATE_UI_API gate_result_t gate_ui_dialog_session_uninit(gate_ui_dialog_session_t* session)
1689 {
1690 return GATE_RESULT_NOTIMPLEMENTED;
1691 }
1692
1693 GATE_UI_API gate_result_t gate_ui_dialog_msgbox(gate_ui_ctrl_t* owner,
1694 gate_string_t const* text, gate_string_t const* title, gate_enumint_t type, gate_enumint_t* ptr_choice)
1695 {
1696 gate_result_t ret = GATE_RESULT_FAILED;
1697 gate_strbuilder_t builder = GATE_INIT_EMPTY;
1698 gate_string_t js = GATE_STRING_INIT_EMPTY;
1699 int js_choice = 0;
1700 gate_enumint_t user_choice = 0;
1701
1702 do
1703 {
1704 gate_strbuilder_create(&builder, 512);
1705 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK))
1706 {
1707 gate_strbuilder_append(&builder,
1708 GATE_PRINT_CSTR, "alert(\"",
1709 GATE_PRINT_STRING, title,
1710 GATE_PRINT_STRING, "\\n\\n",
1711 GATE_PRINT_STRING, text,
1712 GATE_PRINT_CSTR, "\");",
1713 GATE_PRINT_CSTR, "return 1;",
1714 GATE_PRINT_END
1715 );
1716 }
1717 else
1718 {
1719 gate_strbuilder_append(&builder,
1720 GATE_PRINT_CSTR, "choice = confirm(\"",
1721 GATE_PRINT_STRING, title,
1722 GATE_PRINT_STRING, "\\n\\n",
1723 GATE_PRINT_STRING, text,
1724 GATE_PRINT_CSTR, "\");",
1725 GATE_PRINT_CSTR, "return choice ? 1 : 0;",
1726 GATE_PRINT_END
1727 );
1728 }
1729
1730 gate_strbuilder_to_string(&builder, &js);
1731
1732 gate_wasm_js_execute_int(&js, &js_choice);
1733
1734 if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OK))
1735 {
1736 user_choice = GATE_UI_MSGBOX_CHOICE_OK;
1737 }
1738 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_OKCANCEL))
1739 {
1740 user_choice = js_choice ? GATE_UI_MSGBOX_CHOICE_OK : GATE_UI_MSGBOX_CHOICE_CANCEL;
1741 }
1742 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNO))
1743 {
1744 user_choice = js_choice ? GATE_UI_MSGBOX_CHOICE_YES : GATE_UI_MSGBOX_CHOICE_NO;
1745 }
1746 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_YESNOCANCEL))
1747 {
1748 //TODO
1749 user_choice = js_choice ? GATE_UI_MSGBOX_CHOICE_YES : GATE_UI_MSGBOX_CHOICE_NO;
1750 }
1751 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCEL))
1752 {
1753 user_choice = js_choice ? GATE_UI_MSGBOX_CHOICE_RETRY : GATE_UI_MSGBOX_CHOICE_CANCEL;
1754 }
1755 else if (GATE_FLAG_ENABLED(type, GATE_UI_MSGBOX_TYPE_RETRYCANCELIGNORE))
1756 {
1757 //TODO
1758 user_choice = js_choice ? GATE_UI_MSGBOX_CHOICE_RETRY : GATE_UI_MSGBOX_CHOICE_CANCEL;
1759 }
1760
1761 if (ptr_choice)
1762 {
1763 *ptr_choice = user_choice;
1764 }
1765 ret = GATE_RESULT_OK;
1766 } while (0);
1767
1768 gate_string_release(&js);
1769 gate_strbuilder_release(&builder);
1770 return ret;
1771 }
1772
1773
1774 GATE_UI_API gate_result_t gate_ui_dialog_openfile(gate_ui_ctrl_t* owner,
1775 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
1776 gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1777 {
1778 return GATE_RESULT_NOTIMPLEMENTED;
1779 }
1780
1781 GATE_UI_API gate_result_t gate_ui_dialog_savefile(gate_ui_ctrl_t* owner,
1782 gate_ui_dialog_filter_t const* filefilters, gate_size_t filefiltercount, gate_size_t* selectedfilefilter,
1783 gate_string_t const* title, gate_string_t const* initialdir, gate_string_t* filepath)
1784 {
1785 return GATE_RESULT_NOTIMPLEMENTED;
1786 }
1787
1788 #endif /* GATE_UI_WASMHTML */
1789
1790