GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/statusbars.c
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 72 78 92.3%
Functions: 7 7 100.0%
Branches: 24 44 54.5%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/ui/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 WINAPI gate_ui_statusbar_update_design(gate_ui_ctrl_t* ctrl)
110 {
111 COLORREF bk_col = CLR_DEFAULT;
112 HWND 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 WINAPI gate_ui_statusbar_events(ui_hwnd_t 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 != UI_HWND_NULL))
143 {
144 HWND const hwndCtrl = (HWND)GATE_UI_WINAPI_GET_HWND(ctrl);
145 gate_ui_statusbar_t* const statusbar = (gate_ui_statusbar_t*)ctrl;
146 if (NULL != HWND_NULL)
147 {
148 switch (msg)
149 {
150 default:
151 {
152 break;
153 }
154 }
155 }
156 }
157 return false;
158 }
159
160 static gate_result_t WINAPI 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 = (HWND)GATE_UI_WINAPI_GET_HWND(ctrl);
168 TCHAR localbuffer[GATE_DEFAULT_LINE_LENGTH];
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 == HWND_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 static gate_result_t WINAPI 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 = (HWND)GATE_UI_WINAPI_GET_HWND(ctrl);
235 if (hwnd != 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 static gate_result_t WINAPI 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 = (HWND)GATE_UI_WINAPI_GET_HWND(ctrl);
258 if (hwnd != 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 ui_hwnd_t 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 == UI_HWND_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 = (HWND)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 static gate_result_t WINAPI gate_ui_progressbar_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* value)
386 {
387 gate_uint32_t native_value = 0;
388 gate_result_t ret = gate_ui_progressbar_get_value((gate_ui_progressbar_t*)ctrl, &native_value);
389 if (GATE_SUCCEEDED(ret))
390 {
391 if (value)
392 {
393 *value = (gate_int32_t)native_value;
394 }
395 }
396 return ret;
397 }
398 static gate_result_t WINAPI gate_ui_progressbar_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t value)
399 {
400 gate_result_t ret = gate_ui_progressbar_set_value((gate_ui_progressbar_t*)ctrl, (gate_uint32_t)value);
401 return ret;
402 }
403
404 static gate_result_t WINAPI gate_ui_progressbar_refresh(gate_ui_ctrl_t* ctrl)
405 {
406 ui_hwnd_t hwnd = GATE_UI_WINAPI_GET_HWND(ctrl);
407
408 #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT)
409 if (gate_ui_winapi_darkmode_supported())
410 {
411 HWND hwnd_ctrl = (HWND)hwnd;
412 BOOL dark_mode = gate_ui_winapi_darkmode_enabled() ? TRUE : FALSE;
413 gate_ui_winapi_apply_darkmode(hwnd_ctrl, dark_mode);
414 if (dark_mode)
415 {
416 gate_ui_host_t* host = GATE_UI_WINAPI_GET_HOST(ctrl);
417 gate_ui_color_t color;
418 gate_ui_host_default_color(host, GATE_UI_COLOR_CONTENTBACKGROUND, &color);
419 SendMessage(hwnd_ctrl, PBM_SETBKCOLOR, 0, RGB(color.r, color.g, color.b));
420 SendMessage(hwnd_ctrl, PBM_SETBARCOLOR, 0, CLR_DEFAULT);
421 }
422 else
423 {
424 SendMessage(hwnd_ctrl, PBM_SETBKCOLOR, 0, CLR_DEFAULT);
425 SendMessage(hwnd_ctrl, PBM_SETBARCOLOR, 0, CLR_DEFAULT);
426 }
427 }
428 #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */
429
430 return gate_ui_winapi_refresh_hwnd(hwnd);
431 }
432
433
434 static gate_ui_winapi_dispatchers_t global_win32_progressbar_dispatchers =
435 {
436 &gate_ui_winapi_destroy_with_font,
437 &gate_ui_winapi_is_enabled,
438 &gate_ui_winapi_is_visible,
439 &gate_ui_winapi_is_focused,
440 &gate_ui_winapi_get_position,
441 &gate_ui_winapi_get_size,
442 &gate_ui_winapi_get_children,
443 &gate_ui_winapi_get_text_length,
444 &gate_ui_winapi_get_text,
445 &gate_ui_progressbar_get_state,
446 &gate_ui_winapi_set_enabled,
447 &gate_ui_winapi_set_visible,
448 &gate_ui_winapi_set_focus,
449 &gate_ui_winapi_set_position,
450 &gate_ui_winapi_set_text,
451 &gate_ui_progressbar_set_state,
452 &gate_ui_progressbar_refresh
453 };
454
455
456
457 gate_result_t gate_ui_progressbar_create(
458 gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent,
459 gate_ui_position_t const* position,
460 gate_uint32_t flags,
461 void* userparam
462 )
463 {
464 gate_result_t ret;
465 do
466 {
467 gate_uint32_t styles = WS_CHILD | WS_CLIPSIBLINGS;
468 gate_uint32_t exstyles = 0;
469 ui_hwnd_t hwndParent;
470 gate_ui_host_t* host = gate_ui_ctrl_get_host(parent);
471 if (host == NULL)
472 {
473 ret = GATE_RESULT_INVALIDSTATE;
474 break;
475 }
476 hwndParent = GATE_UI_WINAPI_GET_HWND(parent);
477 if (hwndParent == UI_HWND_NULL)
478 {
479 ret = GATE_RESULT_INVALIDSTATE;
480 break;
481 }
482
483 gate_mem_clear(progressbar, sizeof(gate_ui_progressbar_t));
484 /*
485 #if defined(PBS_SMOOTH)
486 styles |= PBS_SMOOTH;
487 #endif
488 */
489 if (!GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_ENABLED)) styles |= WS_DISABLED;
490 if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_VISIBLE)) styles |= WS_VISIBLE;
491
492 ret = gate_ui_winapi_create(&progressbar->ctrl, host, hwndParent, PROGRESS_CLASS, position, styles, exstyles, NULL, userparam, true);
493 if (GATE_SUCCEEDED(ret))
494 {
495 HWND hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl);
496 GATE_UI_WINAPI_SET_DISPATCHER(&progressbar->ctrl, &global_win32_progressbar_dispatchers);
497 #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT)
498 gate_ui_winapi_set_window_theme(hwnd, L"", L"");
499 #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */
500 SendMessage(hwnd, PBM_SETRANGE32, 0, 100);
501 SendMessage(hwnd, PBM_SETPOS, 0, 0);
502 gate_ui_progressbar_refresh(&progressbar->ctrl);
503 }
504 } while (0);
505
506 return ret;
507
508 }
509
510 gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum)
511 {
512 gate_result_t ret = GATE_RESULT_FAILED;
513 const HWND hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl);
514 if (hwnd != HWND_NULL)
515 {
516 PBRANGE range = GATE_INIT_EMPTY;
517 WPARAM new_minimum = 0;
518 LPARAM new_maximum = 100;
519 SendMessage(hwnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
520 new_minimum = range.iLow;
521 SendMessage(hwnd, PBM_GETRANGE, FALSE, (LPARAM)&range);
522 new_maximum = range.iHigh;
523
524 if (minimum)
525 {
526 new_minimum = *minimum;
527 }
528 if (maximum)
529 {
530 new_maximum = *maximum;
531 }
532 SendMessage(hwnd, PBM_SETRANGE32, (WPARAM)new_minimum, (LPARAM)new_maximum);
533 ret = GATE_RESULT_OK;
534 }
535 return ret;
536 }
537 gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum)
538 {
539 gate_result_t ret = GATE_RESULT_FAILED;
540 const HWND hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl);
541 if (hwnd != HWND_NULL)
542 {
543 PBRANGE range = { 0, 0 };
544 if (minimum)
545 {
546 SendMessage(hwnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
547 *minimum = range.iLow;
548 }
549 if (maximum)
550 {
551 SendMessage(hwnd, PBM_GETRANGE, FALSE, (LPARAM)&range);
552 *maximum = range.iHigh;
553 }
554 ret = GATE_RESULT_OK;
555 }
556 return ret;
557 }
558
559 gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value)
560 {
561 gate_result_t ret = GATE_RESULT_FAILED;
562 const HWND hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl);
563 if (hwnd != HWND_NULL)
564 {
565 SendMessage(hwnd, PBM_SETPOS, (WPARAM)value, 0);
566 ret = GATE_RESULT_OK;
567 }
568 return ret;
569 }
570 gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value)
571 {
572 gate_result_t ret = GATE_RESULT_FAILED;
573 const HWND hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(&progressbar->ctrl);
574 if (hwnd != HWND_NULL)
575 {
576 UINT cur_pos = (UINT)SendMessage(hwnd, PBM_GETPOS, 0, 0);
577 if (value)
578 {
579 *value = (gate_uint32_t)cur_pos;
580 }
581 ret = GATE_RESULT_OK;
582 }
583 return ret;
584 }
585
586 #endif /* GATE_UI_WINAPI */
587
588
589
590 #if defined(GATE_UI_GTK)
591
592 #include "gate/ui/gateui_gtk.h"
593
594 static gate_uint32_t gate_ui_gtk_statusbar_get_text_length(gate_ui_ctrl_t* ctrl)
595 {
596 gint char_count = 0;
597 GtkStatusbar* statusbar = (GtkStatusbar*)GATE_UI_GTK_GET_CTRL_WIDGET(ctrl);
598
599 if (statusbar)
600 {
601 char_count = 0;
602 }
603 return (gate_uint32_t)char_count;
604 }
605 static gate_result_t gate_ui_gtk_statusbar_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text)
606 {
607 gate_result_t ret = GATE_RESULT_FAILED;
608 GtkStatusbar* statusbar = (GtkStatusbar*)GATE_UI_GTK_GET_CTRL_WIDGET(ctrl);
609 if (statusbar)
610 {
611 if (text != NULL)
612 {
613 gate_string_create_empty(text);
614 }
615 ret = GATE_RESULT_OK;
616 }
617 return ret;
618 }
619 static gate_result_t gate_ui_gtk_statusbar_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text)
620 {
621 gate_result_t ret = GATE_RESULT_FAILED;
622 GtkStatusbar* statusbar = GTK_STATUSBAR(GATE_UI_GTK_GET_CTRL_WIDGET(ctrl));
623 if (statusbar)
624 {
625 gchar buffer[4096];
626 buffer[0] = 0;
627 if (gate_string_length(text) != 0)
628 {
629 gate_str_print_text(buffer, sizeof(buffer), text->str, text->length);
630 }
631 gtk_statusbar_push(statusbar, 0, buffer);
632 ret = GATE_RESULT_OK;
633 }
634 return ret;
635 }
636
637 static gate_ui_gtk_dispatcher_t gate_ui_gtk_statusbar_dispatcher =
638 {
639 gate_ui_gtk_statusbar_get_text_length,
640 gate_ui_gtk_statusbar_get_text,
641 gate_ui_gtk_statusbar_set_text,
642 NULL,
643 NULL,
644 NULL
645 };
646
647 gate_result_t gate_ui_statusbar_create(
648 gate_ui_statusbar_t* statusbar, gate_ui_ctrl_t* parent,
649 gate_ui_position_t const* position,
650 gate_string_t const* caption,
651 gate_uint32_t flags,
652 void* userparam
653 )
654 {
655 GtkWidget* widget;
656 gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent);
657
658 gate_mem_clear(statusbar, sizeof(gate_ui_statusbar_t));
659 widget = gtk_statusbar_new();
660 if (widget == NULL)
661 {
662 return GATE_RESULT_FAILED;
663 }
664
665 gate_ui_gtk_ctrl_init(&statusbar->ctrl, widget, host, userparam, parent,
666 &gate_ui_gtk_statusbar_dispatcher, false, false, position, &flags);
667
668 /* g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gate_ui_form_event_destroy), statusbar);
669 */
670 return GATE_RESULT_OK;
671
672 }
673
674 static gate_result_t gate_ui_gtk_progessbar_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* value)
675 {
676 gate_ui_progressbar_t* progressbar = (gate_ui_progressbar_t*)ctrl;
677 gate_uint32_t native_value = 0;
678 gate_ui_progressbar_get_value(progressbar, &native_value);
679 return GATE_RESULT_NOTIMPLEMENTED;
680 }
681 static gate_result_t gate_ui_gtk_progessbar_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t value)
682 {
683 return GATE_RESULT_NOTIMPLEMENTED;
684 }
685
686 static gate_ui_gtk_dispatcher_t gate_ui_gtk_progressbar_dispatcher =
687 {
688 NULL,
689 NULL,
690 NULL,
691 &gate_ui_gtk_progessbar_get_state,
692 &gate_ui_gtk_progessbar_set_state,
693 NULL
694 };
695
696
697
698 gate_result_t gate_ui_progressbar_create(
699 gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent,
700 gate_ui_position_t const* position,
701 gate_uint32_t flags,
702 void* userparam
703 )
704 {
705 gate_result_t ret = GATE_RESULT_OK;
706 GtkWidget* widget;
707 gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent);
708
709 gate_mem_clear(progressbar, sizeof(gate_ui_progressbar_t));
710 widget = gtk_progress_bar_new();
711 if (widget == NULL)
712 {
713 return GATE_RESULT_FAILED;
714 }
715
716 ret = gate_ui_gtk_ctrl_init(&progressbar->ctrl, widget, host, userparam, parent,
717 &gate_ui_gtk_progressbar_dispatcher, false, false, position, &flags);
718
719
720 progressbar->min_value = 0;
721 progressbar->max_value = 100;
722 progressbar->current_value = 0;
723
724 return ret;
725 }
726
727 static void gate_ui_progressbar_normalize_values(gate_ui_progressbar_t* progressbar)
728 {
729 if (progressbar->max_value <= progressbar->min_value)
730 {
731 if (progressbar->min_value == (gate_uint32_t)-1)
732 {
733 progressbar->max_value = (gate_uint32_t)-1;
734 progressbar->min_value = progressbar->max_value - 1;
735 }
736 else
737 {
738 progressbar->max_value = progressbar->min_value + 1;
739 }
740 }
741
742
743 if (progressbar->current_value < progressbar->min_value)
744 {
745 progressbar->current_value = progressbar->min_value;
746 }
747 if (progressbar->current_value > progressbar->max_value)
748 {
749 progressbar->current_value = progressbar->max_value;
750 }
751 }
752
753 gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum)
754 {
755 gate_result_t ret = GATE_RESULT_OK;
756 gdouble progress_state = 0.0;
757 GtkProgressBar* pbar = GTK_PROGRESS_BAR(GATE_UI_GTK_GET_CTRL_WIDGET(&progressbar->ctrl));
758 if (minimum)
759 {
760 progressbar->min_value = *minimum;
761 }
762 if (maximum)
763 {
764 progressbar->max_value = *maximum;
765 }
766 gate_ui_progressbar_normalize_values(progressbar);
767
768 progress_state = (gdouble)(progressbar->current_value - progressbar->min_value)
769 / (gdouble)(progressbar->max_value - progressbar->min_value);
770
771 gtk_progress_bar_set_fraction(pbar, progress_state);
772 ret = GATE_RESULT_OK;
773
774 return ret;
775 }
776 gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum)
777 {
778 gate_result_t ret = GATE_RESULT_OK;
779 if (minimum)
780 {
781 *minimum = progressbar->min_value;
782 }
783 if (maximum)
784 {
785 *maximum = progressbar->max_value;
786 }
787 return ret;
788 }
789
790 gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value)
791 {
792 gate_result_t ret = GATE_RESULT_FAILED;
793 gdouble progress_state = 0.0;
794 GtkProgressBar* pbar = GTK_PROGRESS_BAR(GATE_UI_GTK_GET_CTRL_WIDGET(&progressbar->ctrl));
795
796 progressbar->current_value = value;
797 gate_ui_progressbar_normalize_values(progressbar);
798 progress_state = (gdouble)(progressbar->current_value - progressbar->min_value)
799 / (gdouble)(progressbar->max_value - progressbar->min_value);
800
801 gtk_progress_bar_set_fraction(pbar, progress_state);
802 ret = GATE_RESULT_OK;
803 return ret;
804 }
805 gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value)
806 {
807 if(!progressbar)
808 {
809 return GATE_RESULT_NULLPOINTER;
810 }
811 if (value)
812 {
813 *value = progressbar->current_value;
814 }
815 return GATE_RESULT_OK;
816 }
817
818 #endif /* GATE_UI_GTK */
819
820
821
822 #if defined(GATE_UI_MOTIF)
823
824 #include "gate/ui/gateui_motif.h"
825 #include <Xm/Label.h>
826 #include <Xm/Scale.h>
827
828
829 1 gate_result_t gate_ui_statusbar_create(gate_ui_statusbar_t* statusbar, gate_ui_ctrl_t* parent, gate_ui_position_t const* position,
830 gate_string_t const* caption, gate_uint32_t flags, void* userparam)
831 {
832 1 gate_result_t ret = GATE_RESULT_FAILED;
833 do
834 {
835 1 Widget w = NULL;
836 Arg args[8];
837 1 unsigned args_count = 0;
838
839
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!statusbar || !parent)
840 {
841 ret = GATE_RESULT_INVALIDARG;
842 break;
843 }
844
845 1 XtSetArg(args[args_count], XmNalignment, XmALIGNMENT_BEGINNING); ++args_count;
846
847 1 ret = gate_ui_motif_ctrl_create(&statusbar->ctrl, xmLabelWidgetClass, userparam, NULL, parent,
848 position, &flags, false, NULL, args, args_count);
849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
850 1 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&statusbar->ctrl);
851 1 ret = gate_ui_motif_widget_set_label(w, caption);
852 } while (0);
853
854 1 return ret;
855 }
856
857
858 1 gate_result_t gate_ui_progressbar_create(gate_ui_progressbar_t* progressbar, gate_ui_ctrl_t* parent, gate_ui_position_t const* position,
859 gate_uint32_t flags, void* userparam)
860 {
861 1 gate_result_t ret = GATE_RESULT_FAILED;
862 do
863 {
864 1 Widget w = NULL;
865 Arg args[12];
866 1 unsigned args_count = 0;
867
868
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!progressbar || !parent)
869 {
870 ret = GATE_RESULT_INVALIDARG;
871 break;
872 }
873
874 1 XtSetArg(args[args_count], XmNshowArrows, XmNONE); ++args_count;
875 1 XtSetArg(args[args_count], XmNshowValue, XmNONE); ++args_count;
876 1 XtSetArg(args[args_count], XmNslidingMode, XmTHERMOMETER); ++args_count;
877 1 XtSetArg(args[args_count], XmNshowArrows, XmNONE); ++args_count;
878 1 XtSetArg(args[args_count], XmNorientation, XmHORIZONTAL); ++args_count;
879 1 XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count;
880 1 XtSetArg(args[args_count], XmNminimum, 0); ++args_count;
881 1 XtSetArg(args[args_count], XmNmaximum, 100); ++args_count;
882 1 XtSetArg(args[args_count], XmNsliderVisual, XmTROUGH_COLOR); ++args_count;
883
884 1 ret = gate_ui_motif_ctrl_create(&progressbar->ctrl, xmScaleWidgetClass, userparam, NULL, parent,
885 position, &flags, false, NULL, args, args_count);
886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
887 } while (0);
888 1 return ret;
889 }
890
891 2 gate_result_t gate_ui_progressbar_set_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t const* minimum, gate_uint32_t const* maximum)
892 {
893 Widget w;
894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(progressbar != NULL);
895 2 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl);
896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(w != NULL);
897
898
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (minimum)
899 {
900 2 XtVaSetValues(w, XmNminimum, (int)*minimum, NULL, NULL);
901 }
902
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (maximum)
903 {
904 2 XtVaSetValues(w, XmNmaximum, (int)*maximum, NULL, NULL);
905 }
906
907 2 return GATE_RESULT_OK;
908 }
909
910 3 gate_result_t gate_ui_progressbar_get_limits(gate_ui_progressbar_t* progressbar, gate_uint32_t* minimum, gate_uint32_t* maximum)
911 {
912 Widget w;
913 3 int v = 0;
914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATE_DEBUG_ASSERT(progressbar != NULL);
915 3 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl);
916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATE_DEBUG_ASSERT(w != NULL);
917
918
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (minimum)
919 {
920 2 XtVaGetValues(w, XmNminimum, &v, NULL, NULL);
921 2 *minimum = (gate_uint32_t)v;
922 }
923
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (maximum)
924 {
925 2 XtVaGetValues(w, XmNmaximum, &v, NULL, NULL);
926 2 *maximum = (gate_uint32_t)v;
927 }
928
929 3 return GATE_RESULT_OK;
930 }
931
932 4 gate_result_t gate_ui_progressbar_set_value(gate_ui_progressbar_t* progressbar, gate_uint32_t value)
933 {
934 Widget w;
935
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATE_DEBUG_ASSERT(progressbar != NULL);
936 4 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl);
937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATE_DEBUG_ASSERT(w != NULL);
938
939 4 XtVaSetValues(w, XmNvalue, (int)value, NULL, NULL);
940
941 4 return GATE_RESULT_OK;
942 }
943
944 1 gate_result_t gate_ui_progressbar_get_value(gate_ui_progressbar_t* progressbar, gate_uint32_t* value)
945 {
946 Widget w;
947 1 int v = 0;
948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(progressbar != NULL);
949 1 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&progressbar->ctrl);
950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(w != NULL);
951
952
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (value)
953 {
954 1 XtVaGetValues(w, XmNvalue, &v, NULL, NULL);
955 1 *value = (gate_uint32_t)v;
956 }
957
958 1 return GATE_RESULT_OK;
959 }
960
961 #endif /* GATE_UI_MOTIF */
962