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