| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/ui/statusbars.h" | ||
| 30 | #include "gate/results.h" | ||
| 31 | #include "gate/debugging.h" | ||
| 32 | |||
| 33 | |||
| 34 | ✗ | gate_result_t gate_ui_progressbar_set_percent(gate_ui_progressbar_t* progressbar, gate_real32_t percent_value) | |
| 35 | { | ||
| 36 | static const gate_uint32_t percent_min = 0; | ||
| 37 | static const gate_uint32_t percent_max = 10000; | ||
| 38 | gate_result_t ret; | ||
| 39 | gate_uint32_t current_value; | ||
| 40 | |||
| 41 | ✗ | if (percent_value < 0.0f) | |
| 42 | { | ||
| 43 | ✗ | percent_value = 0.0f; | |
| 44 | } | ||
| 45 | ✗ | if (percent_value > 100.0f) | |
| 46 | { | ||
| 47 | ✗ | percent_value = 100.0f; | |
| 48 | } | ||
| 49 | ✗ | current_value = (gate_uint32_t)(percent_value * 100.0f); | |
| 50 | ✗ | ret = gate_ui_progressbar_set_limits(progressbar, &percent_min, &percent_max); | |
| 51 | ✗ | if (GATE_SUCCEEDED(ret)) | |
| 52 | { | ||
| 53 | ✗ | ret = gate_ui_progressbar_set_value(progressbar, current_value); | |
| 54 | } | ||
| 55 | ✗ | return ret; | |
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | #if defined(GATE_UI_WINAPI) | ||
| 62 | |||
| 63 | #ifndef _WIN32_IE | ||
| 64 | #if defined(GATE_COMPILER_TCC) | ||
| 65 | # define _WIN32_IE 0x0501 | ||
| 66 | #else | ||
| 67 | # define _WIN32_IE 0x0400 | ||
| 68 | #endif | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #include "gate/platforms.h" | ||
| 72 | #include "gate/ui/gateui_winapi.h" | ||
| 73 | |||
| 74 | #if defined(GATE_SYS_WIN16) | ||
| 75 | # define CLR_DEFAULT 0xFF000000L | ||
| 76 | # define CCM_FIRST 0x2000 | ||
| 77 | # define CCM_LAST (CCM_FIRST + 0x200) | ||
| 78 | # define CCM_SETBKCOLOR (CCM_FIRST + 1) | ||
| 79 | # define SB_SETBKCOLOR CCM_SETBKCOLOR | ||
| 80 | # define SB_SETTEXT (WM_USER+1) | ||
| 81 | # define SB_GETTEXT (WM_USER+2) | ||
| 82 | # define SB_GETTEXTLENGTH (WM_USER+3) | ||
| 83 | # define SB_SIMPLE (WM_USER+9) | ||
| 84 | # define CCS_NORESIZE 0x00000004L | ||
| 85 | # define CCS_NOPARENTALIGN 0x00000008L | ||
| 86 | # define STATUSCLASSNAME "msctls_statusbar" | ||
| 87 | |||
| 88 | # define PROGRESS_CLASS "msctls_progress" | ||
| 89 | # define PBM_SETRANGE (WM_USER+1) | ||
| 90 | # define PBM_SETPOS (WM_USER+2) | ||
| 91 | # define PBM_DELTAPOS (WM_USER+3) | ||
| 92 | # define PBM_SETSTEP (WM_USER+4) | ||
| 93 | # define PBM_STEPIT (WM_USER+5) | ||
| 94 | # define PBM_SETRANGE32 (WM_USER+6) | ||
| 95 | typedef struct | ||
| 96 | { | ||
| 97 | int iLow; | ||
| 98 | int iHigh; | ||
| 99 | } PBRANGE, * PPBRANGE; | ||
| 100 | # define PBM_GETRANGE (WM_USER+7) | ||
| 101 | # define PBM_GETPOS (WM_USER+8) | ||
| 102 | # define PBM_SETBARCOLOR (WM_USER+9) | ||
| 103 | # define PBM_SETBKCOLOR CCM_SETBKCOLOR | ||
| 104 | #else | ||
| 105 | # include <commctrl.h> | ||
| 106 | #endif | ||
| 107 | |||
| 108 | |||
| 109 | static void gate_ui_statusbar_update_design(gate_ui_ctrl_t* ctrl) | ||
| 110 | { | ||
| 111 | COLORREF bk_col = CLR_DEFAULT; | ||
| 112 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 113 | |||
| 114 | #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT) | ||
| 115 | gate_ui_host_t* host; | ||
| 116 | gate_ui_color_t color; | ||
| 117 | if (gate_ui_winapi_is_darkmode_applied(hwnd)) | ||
| 118 | { | ||
| 119 | host = GATE_UI_WINAPI_GET_HOST(ctrl); | ||
| 120 | /* SB_SETBKCOLOR only works when visual styles are disabled */ | ||
| 121 | gate_ui_winapi_set_window_theme(hwnd, L"", L""); | ||
| 122 | gate_ui_host_default_color(host, GATE_UI_COLOR_CONTROL, &color); | ||
| 123 | bk_col = RGB(color.r, color.g, color.b); | ||
| 124 | /* TODO Set Text color*/ | ||
| 125 | } | ||
| 126 | else | ||
| 127 | { | ||
| 128 | /* re-enable visual styles */ | ||
| 129 | gate_ui_winapi_set_window_theme(hwnd, NULL, NULL); | ||
| 130 | } | ||
| 131 | #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */ | ||
| 132 | |||
| 133 | #if !defined(GATE_SYS_WINCE) | ||
| 134 | SendMessage(hwnd, SB_SETBKCOLOR, 0, bk_col); | ||
| 135 | #endif | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | static gate_bool_t gate_ui_statusbar_events(void* hwnd, gate_ui_ctrl_t* ctrl, gate_uint32_t msg, gate_uintptr_t wParam, gate_intptr_t lParam, gate_intptr_t* lresult) | ||
| 140 | { | ||
| 141 | HWND hwndCtrl; | ||
| 142 | gate_ui_statusbar_t* statusbar; | ||
| 143 | |||
| 144 | if ((ctrl != NULL) && (hwnd != NULL)) | ||
| 145 | { | ||
| 146 | hwndCtrl = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 147 | statusbar = (gate_ui_statusbar_t*)ctrl; | ||
| 148 | if (NULL != hwndCtrl) | ||
| 149 | { | ||
| 150 | switch (msg) | ||
| 151 | { | ||
| 152 | default: | ||
| 153 | { | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | return false; | ||
| 160 | } | ||
| 161 | |||
| 162 | gate_result_t gate_ui_statusbar_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text) | ||
| 163 | { | ||
| 164 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 165 | HWND hwndCtrl = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 166 | TCHAR localbuffer[4096]; | ||
| 167 | TCHAR* heapbuffer = NULL; | ||
| 168 | TCHAR* buffer; | ||
| 169 | gate_size_t localbufferlen = sizeof(localbuffer) / sizeof(localbuffer[0]); | ||
| 170 | gate_size_t textlen = gate_string_length(text); | ||
| 171 | |||
| 172 | do | ||
| 173 | { | ||
| 174 | if (hwndCtrl == NULL) | ||
| 175 | { | ||
| 176 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 177 | break; | ||
| 178 | } | ||
| 179 | if (textlen < localbufferlen) | ||
| 180 | { | ||
| 181 | if (textlen == 0) | ||
| 182 | { | ||
| 183 | localbuffer[0] = 0; | ||
| 184 | } | ||
| 185 | else | ||
| 186 | { | ||
| 187 | if (0 == gate_win32_utf8_2_winstr(text->str, text->length, &localbuffer[0], localbufferlen)) | ||
| 188 | { | ||
| 189 | ret = GATE_RESULT_INVALIDINPUT; | ||
| 190 | break; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | buffer = &localbuffer[0]; | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | heapbuffer = (TCHAR*)gate_mem_alloc(sizeof(TCHAR) * (textlen + 64)); | ||
| 198 | if (heapbuffer == NULL) | ||
| 199 | { | ||
| 200 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 201 | break; | ||
| 202 | } | ||
| 203 | if (0 == gate_win32_utf8_2_winstr(text->str, text->length, heapbuffer, (textlen + 64))) | ||
| 204 | { | ||
| 205 | ret = GATE_RESULT_INVALIDINPUT; | ||
| 206 | break; | ||
| 207 | } | ||
| 208 | buffer = heapbuffer; | ||
| 209 | } | ||
| 210 | #ifndef SB_SIMPLEID | ||
| 211 | #define SB_SIMPLEID 0xff | ||
| 212 | #endif | ||
| 213 | if (FALSE == SendMessage(hwndCtrl, SB_SETTEXT, MAKEWORD(SB_SIMPLEID, 0), (LPARAM)buffer)) | ||
| 214 | { | ||
| 215 | gate_win32_print_lasterror(&ret, NULL, 0); | ||
| 216 | } | ||
| 217 | else | ||
| 218 | { | ||
| 219 | ret = GATE_RESULT_OK; | ||
| 220 | } | ||
| 221 | } while (0); | ||
| 222 | |||
| 223 | if (heapbuffer != NULL) | ||
| 224 | { | ||
| 225 | gate_mem_dealloc(heapbuffer); | ||
| 226 | } | ||
| 227 | return ret; | ||
| 228 | } | ||
| 229 | |||
| 230 | gate_result_t gate_ui_statusbar_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length) | ||
| 231 | { | ||
| 232 | gate_result_t ret = GATE_RESULT_NOTAVAILABLE; | ||
| 233 | HWND hwnd = NULL; | ||
| 234 | int txtlength; | ||
| 235 | if (ctrl != NULL) | ||
| 236 | { | ||
| 237 | hwnd = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 238 | if (hwnd != NULL) | ||
| 239 | { | ||
| 240 | txtlength = LOWORD(SendMessage(hwnd, SB_GETTEXTLENGTH, SB_SIMPLEID, 0)); | ||
| 241 | if (length != NULL) | ||
| 242 | { | ||
| 243 | *length = txtlength; | ||
| 244 | } | ||
| 245 | ret = GATE_RESULT_OK; | ||
| 246 | } | ||
| 247 | } | ||
| 248 | return ret; | ||
| 249 | } | ||
| 250 | |||
| 251 | gate_result_t gate_ui_statusbar_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text) | ||
| 252 | { | ||
| 253 | gate_result_t ret = GATE_RESULT_NOTAVAILABLE; | ||
| 254 | HWND hwnd = NULL; | ||
| 255 | int length; | ||
| 256 | gate_size_t strcapacity; | ||
| 257 | LPTSTR str = NULL; | ||
| 258 | TCHAR localstr[4096]; | ||
| 259 | LPTSTR strptr; | ||
| 260 | if (ctrl != NULL) | ||
| 261 | { | ||
| 262 | hwnd = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 263 | if (hwnd != NULL) | ||
| 264 | { | ||
| 265 | length = LOWORD(SendMessage(hwnd, SB_GETTEXTLENGTH, SB_SIMPLEID, 0)); | ||
| 266 | if (length <= 0) | ||
| 267 | { | ||
| 268 | gate_string_create_empty(text); | ||
| 269 | ret = GATE_RESULT_OK; | ||
| 270 | } | ||
| 271 | else | ||
| 272 | { | ||
| 273 | do | ||
| 274 | { | ||
| 275 | strcapacity = ((gate_size_t)length + 2 + (gate_size_t)length / 2); | ||
| 276 | if (strcapacity > sizeof(localstr) / sizeof(localstr[0])) | ||
| 277 | { | ||
| 278 | str = gate_mem_alloc(strcapacity * sizeof(TCHAR)); | ||
| 279 | if (str == NULL) | ||
| 280 | { | ||
| 281 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 282 | break; | ||
| 283 | } | ||
| 284 | strptr = str; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | { | ||
| 288 | strptr = localstr; | ||
| 289 | } | ||
| 290 | length = LOWORD(SendMessage(hwnd, SB_GETTEXT, SB_SIMPLEID, (LPARAM)strptr)); | ||
| 291 | if (length <= 0) | ||
| 292 | { | ||
| 293 | gate_string_create_empty(text); | ||
| 294 | ret = GATE_RESULT_OK; | ||
| 295 | } | ||
| 296 | else | ||
| 297 | { | ||
| 298 | if (NULL == gate_win32_winstr_2_utf8_string(strptr, length, text)) | ||
| 299 | { | ||
| 300 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 301 | } | ||
| 302 | else | ||
| 303 | { | ||
| 304 | ret = GATE_RESULT_OK; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | } while (0); | ||
| 309 | } | ||
| 310 | } | ||
| 311 | } | ||
| 312 | if (str != NULL) | ||
| 313 | { | ||
| 314 | gate_mem_dealloc(str); | ||
| 315 | } | ||
| 316 | return ret; | ||
| 317 | } | ||
| 318 | |||
| 319 | static gate_ui_winapi_dispatchers_t global_win32_statusbar_dispatchers = | ||
| 320 | { | ||
| 321 | &gate_ui_winapi_destroy_with_font, | ||
| 322 | &gate_ui_winapi_is_enabled, | ||
| 323 | &gate_ui_winapi_is_visible, | ||
| 324 | &gate_ui_winapi_is_focused, | ||
| 325 | &gate_ui_winapi_get_position, | ||
| 326 | &gate_ui_winapi_get_size, | ||
| 327 | &gate_ui_winapi_get_children, | ||
| 328 | &gate_ui_statusbar_get_text_length, | ||
| 329 | &gate_ui_statusbar_get_text, | ||
| 330 | &gate_ui_winapi_get_state, | ||
| 331 | &gate_ui_winapi_set_enabled, | ||
| 332 | &gate_ui_winapi_set_visible, | ||
| 333 | &gate_ui_winapi_set_focus, | ||
| 334 | &gate_ui_winapi_set_position, | ||
| 335 | &gate_ui_statusbar_set_text, | ||
| 336 | &gate_ui_winapi_set_state, | ||
| 337 | &gate_ui_winapi_refresh | ||
| 338 | }; | ||
| 339 | |||
| 340 | gate_result_t gate_ui_statusbar_create(gate_ui_statusbar_t* statusbar, gate_ui_ctrl_t* parent, | ||
| 341 | gate_ui_position_t const* position, gate_string_t const* caption, gate_uint32_t flags, void* userparam) | ||
| 342 | { | ||
| 343 | gate_result_t ret; | ||
| 344 | gate_uint32_t styles, exstyles; | ||
| 345 | gate_ui_host_t* host; | ||
| 346 | HWND hwndParent; | ||
| 347 | HWND hwndCtrl; | ||
| 348 | |||
| 349 | do | ||
| 350 | { | ||
| 351 | host = gate_ui_ctrl_get_host(parent); | ||
| 352 | if (host == NULL) | ||
| 353 | { | ||
| 354 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 355 | break; | ||
| 356 | } | ||
| 357 | hwndParent = GATE_UI_WINAPI_GET_HWND(parent); | ||
| 358 | if (hwndParent == NULL) | ||
| 359 | { | ||
| 360 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 361 | break; | ||
| 362 | } | ||
| 363 | |||
| 364 | gate_mem_clear(statusbar, sizeof(gate_ui_statusbar_t)); | ||
| 365 | |||
| 366 | exstyles = 0; | ||
| 367 | styles = WS_CHILD | WS_CLIPSIBLINGS | CCS_NOPARENTALIGN | CCS_NORESIZE; | ||
| 368 | #if defined(SBT_TOOLTIPS) | ||
| 369 | styles |= SBT_TOOLTIPS; | ||
| 370 | #endif | ||
| 371 | #if defined(SBARS_SIZEGRIP) | ||
| 372 | /*styles |= SBARS_SIZEGRIP;*/ | ||
| 373 | #endif | ||
| 374 | |||
| 375 | if (!GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_ENABLED)) styles |= WS_DISABLED; | ||
| 376 | if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_VISIBLE)) styles |= WS_VISIBLE; | ||
| 377 | |||
| 378 | ret = gate_ui_winapi_create(&statusbar->ctrl, host, hwndParent, STATUSCLASSNAME, position, styles, exstyles, NULL, userparam, true); | ||
| 379 | if (GATE_SUCCEEDED(ret)) | ||
| 380 | { | ||
| 381 | GATE_UI_WINAPI_SET_DISPATCHER(&statusbar->ctrl, &global_win32_statusbar_dispatchers); | ||
| 382 | hwndCtrl = GATE_UI_WINAPI_GET_HWND(&statusbar->ctrl); | ||
| 383 | SendMessage(hwndCtrl, SB_SIMPLE, TRUE, 0); | ||
| 384 | gate_ui_statusbar_set_text(&statusbar->ctrl, caption); | ||
| 385 | |||
| 386 | gate_ui_statusbar_update_design(&statusbar->ctrl); | ||
| 387 | } | ||
| 388 | } while (0); | ||
| 389 | |||
| 390 | return ret; | ||
| 391 | |||
| 392 | } | ||
| 393 | |||
| 394 | |||
| 395 | |||
| 396 | |||
| 397 | static gate_result_t gate_ui_progressbar_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* value) | ||
| 398 | { | ||
| 399 | gate_uint32_t native_value = 0; | ||
| 400 | gate_result_t ret = gate_ui_progressbar_get_value((gate_ui_progressbar_t*)ctrl, &native_value); | ||
| 401 | if (GATE_SUCCEEDED(ret)) | ||
| 402 | { | ||
| 403 | if (value) | ||
| 404 | { | ||
| 405 | *value = (gate_int32_t)native_value; | ||
| 406 | } | ||
| 407 | } | ||
| 408 | return ret; | ||
| 409 | } | ||
| 410 | static gate_result_t gate_ui_progressbar_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t value) | ||
| 411 | { | ||
| 412 | gate_result_t ret = gate_ui_progressbar_set_value((gate_ui_progressbar_t*)ctrl, (gate_uint32_t)value); | ||
| 413 | return ret; | ||
| 414 | } | ||
| 415 | |||
| 416 | static gate_result_t gate_ui_progressbar_refresh(gate_ui_ctrl_t* ctrl) | ||
| 417 | { | ||
| 418 | HWND hwnd_ctrl = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 419 | |||
| 420 | #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT) | ||
| 421 | gate_ui_host_t* host; | ||
| 422 | gate_ui_color_t color; | ||
| 423 | BOOL dark_mode; | ||
| 424 | if (gate_ui_winapi_darkmode_supported()) | ||
| 425 | { | ||
| 426 | dark_mode = gate_ui_winapi_darkmode_enabled() ? TRUE : FALSE; | ||
| 427 | gate_ui_winapi_apply_darkmode(hwnd_ctrl, dark_mode); | ||
| 428 | if (dark_mode) | ||
| 429 | { | ||
| 430 | host = GATE_UI_WINAPI_GET_HOST(ctrl); | ||
| 431 | gate_ui_host_default_color(host, GATE_UI_COLOR_CONTENTBACKGROUND, &color); | ||
| 432 | SendMessage(hwnd_ctrl, PBM_SETBKCOLOR, 0, RGB(color.r, color.g, color.b)); | ||
| 433 | SendMessage(hwnd_ctrl, PBM_SETBARCOLOR, 0, CLR_DEFAULT); | ||
| 434 | } | ||
| 435 | else | ||
| 436 | { | ||
| 437 | SendMessage(hwnd_ctrl, PBM_SETBKCOLOR, 0, CLR_DEFAULT); | ||
| 438 | SendMessage(hwnd_ctrl, PBM_SETBARCOLOR, 0, CLR_DEFAULT); | ||
| 439 | } | ||
| 440 | } | ||
| 441 | #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */ | ||
| 442 | |||
| 443 | return gate_ui_winapi_refresh_hwnd(hwnd_ctrl); | ||
| 444 | } | ||
| 445 | |||
| 446 | |||
| 447 | static gate_ui_winapi_dispatchers_t global_win32_progressbar_dispatchers = | ||
| 448 | { | ||
| 449 | &gate_ui_winapi_destroy_with_font, | ||
| 450 | &gate_ui_winapi_is_enabled, | ||
| 451 | &gate_ui_winapi_is_visible, | ||
| 452 | &gate_ui_winapi_is_focused, | ||
| 453 | &gate_ui_winapi_get_position, | ||
| 454 | &gate_ui_winapi_get_size, | ||
| 455 | &gate_ui_winapi_get_children, | ||
| 456 | &gate_ui_winapi_get_text_length, | ||
| 457 | &gate_ui_winapi_get_text, | ||
| 458 | &gate_ui_progressbar_get_state, | ||
| 459 | &gate_ui_winapi_set_enabled, | ||
| 460 | &gate_ui_winapi_set_visible, | ||
| 461 | &gate_ui_winapi_set_focus, | ||
| 462 | &gate_ui_winapi_set_position, | ||
| 463 | &gate_ui_winapi_set_text, | ||
| 464 | &gate_ui_progressbar_set_state, | ||
| 465 | &gate_ui_progressbar_refresh | ||
| 466 | }; | ||
| 467 | |||
| 468 | |||
| 469 | |||
| 470 | gate_result_t gate_ui_progressbar_create( | ||
| 471 | gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent, | ||
| 472 | gate_ui_position_t const* position, | ||
| 473 | gate_uint32_t flags, | ||
| 474 | void* userparam | ||
| 475 | ) | ||
| 476 | { | ||
| 477 | gate_result_t ret; | ||
| 478 | gate_uint32_t styles, exstyles; | ||
| 479 | gate_ui_host_t* host; | ||
| 480 | HWND hwndParent; | ||
| 481 | HWND hwnd; | ||
| 482 | |||
| 483 | do | ||
| 484 | { | ||
| 485 | host = gate_ui_ctrl_get_host(parent); | ||
| 486 | if (host == NULL) | ||
| 487 | { | ||
| 488 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 489 | break; | ||
| 490 | } | ||
| 491 | hwndParent = GATE_UI_WINAPI_GET_HWND(parent); | ||
| 492 | if (hwndParent == NULL) | ||
| 493 | { | ||
| 494 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 495 | break; | ||
| 496 | } | ||
| 497 | |||
| 498 | gate_mem_clear(progressbar, sizeof(gate_ui_progressbar_t)); | ||
| 499 | |||
| 500 | exstyles = 0; | ||
| 501 | styles = WS_CHILD | WS_CLIPSIBLINGS; | ||
| 502 | /* | ||
| 503 | #if defined(PBS_SMOOTH) | ||
| 504 | styles |= PBS_SMOOTH; | ||
| 505 | #endif | ||
| 506 | */ | ||
| 507 | if (!GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_ENABLED)) styles |= WS_DISABLED; | ||
| 508 | if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_VISIBLE)) styles |= WS_VISIBLE; | ||
| 509 | |||
| 510 | ret = gate_ui_winapi_create(&progressbar->ctrl, host, hwndParent, PROGRESS_CLASS, position, styles, exstyles, NULL, userparam, true); | ||
| 511 | if (GATE_SUCCEEDED(ret)) | ||
| 512 | { | ||
| 513 | GATE_UI_WINAPI_SET_DISPATCHER(&progressbar->ctrl, &global_win32_progressbar_dispatchers); | ||
| 514 | hwnd = GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl); | ||
| 515 | #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT) | ||
| 516 | gate_ui_winapi_set_window_theme(hwnd, L"", L""); | ||
| 517 | #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */ | ||
| 518 | SendMessage(hwnd, PBM_SETRANGE32, 0, 100); | ||
| 519 | SendMessage(hwnd, PBM_SETPOS, 0, 0); | ||
| 520 | gate_ui_progressbar_refresh(&progressbar->ctrl); | ||
| 521 | } | ||
| 522 | } while (0); | ||
| 523 | |||
| 524 | return ret; | ||
| 525 | |||
| 526 | } | ||
| 527 | |||
| 528 | gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum) | ||
| 529 | { | ||
| 530 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 531 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl); | ||
| 532 | PBRANGE range = GATE_INIT_EMPTY; | ||
| 533 | WPARAM new_minimum = 0; | ||
| 534 | LPARAM new_maximum = 100; | ||
| 535 | if (hwnd) | ||
| 536 | { | ||
| 537 | SendMessage(hwnd, PBM_GETRANGE, TRUE, (LPARAM)&range); | ||
| 538 | new_minimum = range.iLow; | ||
| 539 | SendMessage(hwnd, PBM_GETRANGE, FALSE, (LPARAM)&range); | ||
| 540 | new_maximum = range.iHigh; | ||
| 541 | |||
| 542 | if (minimum) | ||
| 543 | { | ||
| 544 | new_minimum = *minimum; | ||
| 545 | } | ||
| 546 | if (maximum) | ||
| 547 | { | ||
| 548 | new_maximum = *maximum; | ||
| 549 | } | ||
| 550 | SendMessage(hwnd, PBM_SETRANGE32, (WPARAM)new_minimum, (LPARAM)new_maximum); | ||
| 551 | ret = GATE_RESULT_OK; | ||
| 552 | } | ||
| 553 | return ret; | ||
| 554 | } | ||
| 555 | gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum) | ||
| 556 | { | ||
| 557 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 558 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl); | ||
| 559 | PBRANGE range = { 0, 0 }; | ||
| 560 | if (hwnd) | ||
| 561 | { | ||
| 562 | if (minimum) | ||
| 563 | { | ||
| 564 | SendMessage(hwnd, PBM_GETRANGE, TRUE, (LPARAM)&range); | ||
| 565 | *minimum = range.iLow; | ||
| 566 | } | ||
| 567 | if (maximum) | ||
| 568 | { | ||
| 569 | SendMessage(hwnd, PBM_GETRANGE, FALSE, (LPARAM)&range); | ||
| 570 | *maximum = range.iHigh; | ||
| 571 | } | ||
| 572 | ret = GATE_RESULT_OK; | ||
| 573 | } | ||
| 574 | return ret; | ||
| 575 | } | ||
| 576 | |||
| 577 | gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value) | ||
| 578 | { | ||
| 579 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 580 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl); | ||
| 581 | if (hwnd) | ||
| 582 | { | ||
| 583 | SendMessage(hwnd, PBM_SETPOS, (WPARAM)value, 0); | ||
| 584 | ret = GATE_RESULT_OK; | ||
| 585 | } | ||
| 586 | return ret; | ||
| 587 | } | ||
| 588 | gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value) | ||
| 589 | { | ||
| 590 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 591 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl); | ||
| 592 | UINT cur_pos; | ||
| 593 | if (hwnd) | ||
| 594 | { | ||
| 595 | cur_pos = (UINT)SendMessage(hwnd, PBM_GETPOS, 0, 0); | ||
| 596 | if (value) | ||
| 597 | { | ||
| 598 | *value = (gate_uint32_t)cur_pos; | ||
| 599 | } | ||
| 600 | ret = GATE_RESULT_OK; | ||
| 601 | } | ||
| 602 | return ret; | ||
| 603 | } | ||
| 604 | |||
| 605 | |||
| 606 | |||
| 607 | |||
| 608 | |||
| 609 | #endif /* GATE_UI_WINAPI */ | ||
| 610 | |||
| 611 | |||
| 612 | #if defined(GATE_UI_GTK) | ||
| 613 | |||
| 614 | #include "gate/ui/gateui_gtk.h" | ||
| 615 | |||
| 616 | |||
| 617 | static gate_uint32_t gate_ui_gtk_statusbar_get_text_length(gate_ui_ctrl_t* ctrl) | ||
| 618 | { | ||
| 619 | gint char_count = 0; | ||
| 620 | GtkStatusbar* statusbar = (GtkStatusbar*)GATE_UI_GTK_GET_CTRL_WIDGET(ctrl); | ||
| 621 | |||
| 622 | if (statusbar) | ||
| 623 | { | ||
| 624 | char_count = 0; | ||
| 625 | } | ||
| 626 | return (gate_uint32_t)char_count; | ||
| 627 | } | ||
| 628 | static gate_result_t gate_ui_gtk_statusbar_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text) | ||
| 629 | { | ||
| 630 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 631 | GtkStatusbar* statusbar = (GtkStatusbar*)GATE_UI_GTK_GET_CTRL_WIDGET(ctrl); | ||
| 632 | if (statusbar) | ||
| 633 | { | ||
| 634 | if (text != NULL) | ||
| 635 | { | ||
| 636 | gate_string_create_empty(text); | ||
| 637 | } | ||
| 638 | ret = GATE_RESULT_OK; | ||
| 639 | } | ||
| 640 | return ret; | ||
| 641 | } | ||
| 642 | static gate_result_t gate_ui_gtk_statusbar_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text) | ||
| 643 | { | ||
| 644 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 645 | GtkStatusbar* statusbar = GTK_STATUSBAR(GATE_UI_GTK_GET_CTRL_WIDGET(ctrl)); | ||
| 646 | guint context_id = 0; | ||
| 647 | gchar buffer[4096]; | ||
| 648 | if (statusbar) | ||
| 649 | { | ||
| 650 | buffer[0] = 0; | ||
| 651 | if (gate_string_length(text) != 0) | ||
| 652 | { | ||
| 653 | gate_str_print_text(buffer, sizeof(buffer), text->str, text->length); | ||
| 654 | } | ||
| 655 | gtk_statusbar_push(statusbar, 0, buffer); | ||
| 656 | ret = GATE_RESULT_OK; | ||
| 657 | } | ||
| 658 | return ret; | ||
| 659 | } | ||
| 660 | |||
| 661 | static gate_ui_gtk_dispatcher_t gate_ui_gtk_statusbar_dispatcher = | ||
| 662 | { | ||
| 663 | gate_ui_gtk_statusbar_get_text_length, | ||
| 664 | gate_ui_gtk_statusbar_get_text, | ||
| 665 | gate_ui_gtk_statusbar_set_text, | ||
| 666 | NULL, | ||
| 667 | NULL, | ||
| 668 | NULL | ||
| 669 | }; | ||
| 670 | |||
| 671 | gate_result_t gate_ui_statusbar_create( | ||
| 672 | gate_ui_statusbar_t* statusbar, gate_ui_ctrl_t* parent, | ||
| 673 | gate_ui_position_t const* position, | ||
| 674 | gate_string_t const* caption, | ||
| 675 | gate_uint32_t flags, | ||
| 676 | void* userparam | ||
| 677 | ) | ||
| 678 | { | ||
| 679 | GtkWidget* widget; | ||
| 680 | gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent); | ||
| 681 | GtkContainer* parentContainer = GATE_UI_GTK_GET_CTRL_CONTAINER(parent); | ||
| 682 | |||
| 683 | gate_mem_clear(statusbar, sizeof(gate_ui_statusbar_t)); | ||
| 684 | widget = gtk_statusbar_new(); | ||
| 685 | if (widget == NULL) | ||
| 686 | { | ||
| 687 | return GATE_RESULT_FAILED; | ||
| 688 | } | ||
| 689 | |||
| 690 | gate_ui_gtk_ctrl_init(&statusbar->ctrl, widget, host, userparam, parent, | ||
| 691 | &gate_ui_gtk_statusbar_dispatcher, false, false, position, &flags); | ||
| 692 | |||
| 693 | /* g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gate_ui_form_event_destroy), statusbar); | ||
| 694 | */ | ||
| 695 | return GATE_RESULT_OK; | ||
| 696 | |||
| 697 | } | ||
| 698 | |||
| 699 | static gate_result_t gate_ui_gtk_progessbar_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* value) | ||
| 700 | { | ||
| 701 | gate_ui_progressbar_t* progressbar = (gate_ui_progressbar_t*)ctrl; | ||
| 702 | gate_uint32_t native_value = 0; | ||
| 703 | gate_ui_progressbar_get_value(progressbar, &native_value); | ||
| 704 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 705 | } | ||
| 706 | static gate_result_t gate_ui_gtk_progessbar_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t value) | ||
| 707 | { | ||
| 708 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 709 | } | ||
| 710 | |||
| 711 | static gate_ui_gtk_dispatcher_t gate_ui_gtk_progressbar_dispatcher = | ||
| 712 | { | ||
| 713 | NULL, | ||
| 714 | NULL, | ||
| 715 | NULL, | ||
| 716 | &gate_ui_gtk_progessbar_get_state, | ||
| 717 | &gate_ui_gtk_progessbar_set_state, | ||
| 718 | NULL | ||
| 719 | }; | ||
| 720 | |||
| 721 | |||
| 722 | |||
| 723 | gate_result_t gate_ui_progressbar_create( | ||
| 724 | gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent, | ||
| 725 | gate_ui_position_t const* position, | ||
| 726 | gate_uint32_t flags, | ||
| 727 | void* userparam | ||
| 728 | ) | ||
| 729 | { | ||
| 730 | gate_result_t ret = GATE_RESULT_OK; | ||
| 731 | GtkWidget* widget; | ||
| 732 | gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent); | ||
| 733 | |||
| 734 | gate_mem_clear(progressbar, sizeof(gate_ui_progressbar_t)); | ||
| 735 | widget = gtk_progress_bar_new(); | ||
| 736 | if (widget == NULL) | ||
| 737 | { | ||
| 738 | return GATE_RESULT_FAILED; | ||
| 739 | } | ||
| 740 | |||
| 741 | ret = gate_ui_gtk_ctrl_init(&progressbar->ctrl, widget, host, userparam, parent, | ||
| 742 | &gate_ui_gtk_progressbar_dispatcher, false, false, position, &flags); | ||
| 743 | |||
| 744 | |||
| 745 | progressbar->min_value = 0; | ||
| 746 | progressbar->max_value = 100; | ||
| 747 | progressbar->current_value = 0; | ||
| 748 | |||
| 749 | return ret; | ||
| 750 | } | ||
| 751 | |||
| 752 | static void gate_ui_progressbar_normalize_values(gate_ui_progressbar_t* progressbar) | ||
| 753 | { | ||
| 754 | if (progressbar->max_value <= progressbar->min_value) | ||
| 755 | { | ||
| 756 | if (progressbar->min_value == (gate_uint32_t)-1) | ||
| 757 | { | ||
| 758 | progressbar->max_value = (gate_uint32_t)-1; | ||
| 759 | progressbar->min_value = progressbar->max_value - 1; | ||
| 760 | } | ||
| 761 | else | ||
| 762 | { | ||
| 763 | progressbar->max_value = progressbar->min_value + 1; | ||
| 764 | } | ||
| 765 | } | ||
| 766 | |||
| 767 | |||
| 768 | if (progressbar->current_value < progressbar->min_value) | ||
| 769 | { | ||
| 770 | progressbar->current_value = progressbar->min_value; | ||
| 771 | } | ||
| 772 | if (progressbar->current_value > progressbar->max_value) | ||
| 773 | { | ||
| 774 | progressbar->current_value = progressbar->max_value; | ||
| 775 | } | ||
| 776 | } | ||
| 777 | |||
| 778 | gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum) | ||
| 779 | { | ||
| 780 | gate_result_t ret = GATE_RESULT_OK; | ||
| 781 | gdouble progress_state = 0.0; | ||
| 782 | GtkProgressBar* pbar = GTK_PROGRESS_BAR(GATE_UI_GTK_GET_CTRL_WIDGET(&progressbar->ctrl)); | ||
| 783 | if (minimum) | ||
| 784 | { | ||
| 785 | progressbar->min_value = *minimum; | ||
| 786 | } | ||
| 787 | if (maximum) | ||
| 788 | { | ||
| 789 | progressbar->max_value = *maximum; | ||
| 790 | } | ||
| 791 | gate_ui_progressbar_normalize_values(progressbar); | ||
| 792 | |||
| 793 | progress_state = (gdouble)(progressbar->current_value - progressbar->min_value) | ||
| 794 | / (gdouble)(progressbar->max_value - progressbar->min_value); | ||
| 795 | |||
| 796 | gtk_progress_bar_set_fraction(pbar, progress_state); | ||
| 797 | ret = GATE_RESULT_OK; | ||
| 798 | |||
| 799 | return ret; | ||
| 800 | } | ||
| 801 | gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum) | ||
| 802 | { | ||
| 803 | gate_result_t ret = GATE_RESULT_OK; | ||
| 804 | if (minimum) | ||
| 805 | { | ||
| 806 | *minimum = progressbar->min_value; | ||
| 807 | } | ||
| 808 | if (maximum) | ||
| 809 | { | ||
| 810 | *maximum = progressbar->max_value; | ||
| 811 | } | ||
| 812 | return ret; | ||
| 813 | } | ||
| 814 | |||
| 815 | gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value) | ||
| 816 | { | ||
| 817 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 818 | gdouble progress_state = 0.0; | ||
| 819 | GtkProgressBar* pbar = GTK_PROGRESS_BAR(GATE_UI_GTK_GET_CTRL_WIDGET(&progressbar->ctrl)); | ||
| 820 | |||
| 821 | progressbar->current_value = value; | ||
| 822 | gate_ui_progressbar_normalize_values(progressbar); | ||
| 823 | progress_state = (gdouble)(progressbar->current_value - progressbar->min_value) | ||
| 824 | / (gdouble)(progressbar->max_value - progressbar->min_value); | ||
| 825 | |||
| 826 | gtk_progress_bar_set_fraction(pbar, progress_state); | ||
| 827 | ret = GATE_RESULT_OK; | ||
| 828 | return ret; | ||
| 829 | } | ||
| 830 | gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value) | ||
| 831 | { | ||
| 832 | if (value) | ||
| 833 | { | ||
| 834 | *value = progressbar->current_value; | ||
| 835 | } | ||
| 836 | return GATE_RESULT_FAILED; | ||
| 837 | } | ||
| 838 | |||
| 839 | #endif /* GATE_UI_GTK */ | ||
| 840 | |||
| 841 | |||
| 842 | |||
| 843 | #if defined(GATE_UI_MOTIF) | ||
| 844 | |||
| 845 | #include "gate/ui/gateui_motif.h" | ||
| 846 | #include <Xm/Label.h> | ||
| 847 | #include <Xm/Scale.h> | ||
| 848 | |||
| 849 | |||
| 850 | ✗ | gate_result_t gate_ui_statusbar_create(gate_ui_statusbar_t* statusbar, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | |
| 851 | gate_string_t const* caption, gate_uint32_t flags, void* userparam) | ||
| 852 | { | ||
| 853 | ✗ | gate_result_t ret = GATE_RESULT_FAILED; | |
| 854 | ✗ | Widget w = NULL; | |
| 855 | Arg args[8]; | ||
| 856 | ✗ | unsigned args_count = 0; | |
| 857 | |||
| 858 | do | ||
| 859 | { | ||
| 860 | ✗ | if (!statusbar || !parent) | |
| 861 | { | ||
| 862 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 863 | ✗ | break; | |
| 864 | } | ||
| 865 | |||
| 866 | ✗ | XtSetArg(args[args_count], XmNalignment, XmALIGNMENT_BEGINNING); ++args_count; | |
| 867 | |||
| 868 | ✗ | ret = gate_ui_motif_ctrl_create(&statusbar->ctrl, xmLabelWidgetClass, userparam, NULL, parent, | |
| 869 | position, &flags, false, NULL, args, args_count); | ||
| 870 | ✗ | GATE_BREAK_IF_FAILED(ret); | |
| 871 | ✗ | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&statusbar->ctrl); | |
| 872 | ✗ | ret = gate_ui_motif_widget_set_label(w, caption); | |
| 873 | } while (0); | ||
| 874 | |||
| 875 | ✗ | return ret; | |
| 876 | } | ||
| 877 | |||
| 878 | |||
| 879 | |||
| 880 | ✗ | gate_result_t gate_ui_progressbar_create(gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | |
| 881 | gate_uint32_t flags, void* userparam) | ||
| 882 | { | ||
| 883 | ✗ | gate_result_t ret = GATE_RESULT_FAILED; | |
| 884 | ✗ | Widget w = NULL; | |
| 885 | Arg args[12]; | ||
| 886 | ✗ | unsigned args_count = 0; | |
| 887 | |||
| 888 | do | ||
| 889 | { | ||
| 890 | ✗ | if (!progressbar || !parent) | |
| 891 | { | ||
| 892 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 893 | ✗ | break; | |
| 894 | } | ||
| 895 | |||
| 896 | ✗ | XtSetArg(args[args_count], XmNshowArrows, XmNONE); ++args_count; | |
| 897 | ✗ | XtSetArg(args[args_count], XmNshowValue, XmNONE); ++args_count; | |
| 898 | ✗ | XtSetArg(args[args_count], XmNslidingMode, XmTHERMOMETER); ++args_count; | |
| 899 | ✗ | XtSetArg(args[args_count], XmNshowArrows, XmNONE); ++args_count; | |
| 900 | ✗ | XtSetArg(args[args_count], XmNorientation, XmHORIZONTAL); ++args_count; | |
| 901 | ✗ | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 902 | ✗ | XtSetArg(args[args_count], XmNminimum, 0); ++args_count; | |
| 903 | ✗ | XtSetArg(args[args_count], XmNmaximum, 100); ++args_count; | |
| 904 | ✗ | XtSetArg(args[args_count], XmNsliderVisual, XmTROUGH_COLOR); ++args_count; | |
| 905 | |||
| 906 | ✗ | ret = gate_ui_motif_ctrl_create(&progressbar->ctrl, xmScaleWidgetClass, userparam, NULL, parent, | |
| 907 | position, &flags, false, NULL, args, args_count); | ||
| 908 | ✗ | GATE_BREAK_IF_FAILED(ret); | |
| 909 | } while (0); | ||
| 910 | ✗ | return ret; | |
| 911 | } | ||
| 912 | |||
| 913 | ✗ | gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum) | |
| 914 | { | ||
| 915 | Widget w; | ||
| 916 | ✗ | GATE_DEBUG_ASSERT(progressbar != NULL); | |
| 917 | ✗ | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl); | |
| 918 | ✗ | GATE_DEBUG_ASSERT(w != NULL); | |
| 919 | |||
| 920 | ✗ | if (minimum) | |
| 921 | { | ||
| 922 | ✗ | XtVaSetValues(w, XmNminimum, (int)*minimum, NULL, NULL); | |
| 923 | } | ||
| 924 | ✗ | if (maximum) | |
| 925 | { | ||
| 926 | ✗ | XtVaSetValues(w, XmNmaximum, (int)*maximum, NULL, NULL); | |
| 927 | } | ||
| 928 | |||
| 929 | ✗ | return GATE_RESULT_OK; | |
| 930 | } | ||
| 931 | |||
| 932 | ✗ | gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum) | |
| 933 | { | ||
| 934 | Widget w; | ||
| 935 | ✗ | int v = 0; | |
| 936 | ✗ | GATE_DEBUG_ASSERT(progressbar != NULL); | |
| 937 | ✗ | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl); | |
| 938 | ✗ | GATE_DEBUG_ASSERT(w != NULL); | |
| 939 | |||
| 940 | ✗ | if (minimum) | |
| 941 | { | ||
| 942 | ✗ | XtVaGetValues(w, XmNminimum, &v, NULL, NULL); | |
| 943 | ✗ | *minimum = (gate_uint32_t)v; | |
| 944 | } | ||
| 945 | ✗ | if (maximum) | |
| 946 | { | ||
| 947 | ✗ | XtVaGetValues(w, XmNmaximum, &v, NULL, NULL); | |
| 948 | ✗ | *maximum = (gate_uint32_t)v; | |
| 949 | } | ||
| 950 | |||
| 951 | ✗ | return GATE_RESULT_OK; | |
| 952 | } | ||
| 953 | |||
| 954 | ✗ | gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value) | |
| 955 | { | ||
| 956 | Widget w; | ||
| 957 | ✗ | GATE_DEBUG_ASSERT(progressbar != NULL); | |
| 958 | ✗ | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl); | |
| 959 | ✗ | GATE_DEBUG_ASSERT(w != NULL); | |
| 960 | |||
| 961 | ✗ | XtVaSetValues(w, XmNvalue, (int)value, NULL, NULL); | |
| 962 | |||
| 963 | ✗ | return GATE_RESULT_OK; | |
| 964 | } | ||
| 965 | |||
| 966 | ✗ | gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value) | |
| 967 | { | ||
| 968 | Widget w; | ||
| 969 | ✗ | int v = 0; | |
| 970 | ✗ | GATE_DEBUG_ASSERT(progressbar != NULL); | |
| 971 | ✗ | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl); | |
| 972 | ✗ | GATE_DEBUG_ASSERT(w != NULL); | |
| 973 | |||
| 974 | ✗ | if (value) | |
| 975 | { | ||
| 976 | ✗ | XtVaGetValues(w, XmNvalue, &v, NULL, NULL); | |
| 977 | ✗ | *value = (gate_uint32_t)v; | |
| 978 | } | ||
| 979 | |||
| 980 | ✗ | return GATE_RESULT_OK; | |
| 981 | } | ||
| 982 | |||
| 983 | #endif /* GATE_UI_MOTIF */ | ||
| 984 |