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