GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/gateui.c
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 348 416 83.7%
Functions: 47 55 85.5%
Branches: 114 178 64.0%

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/gateui.h"
30 #include "gate/results.h"
31
32
33 /****************************
34 * generic implementation *
35 ****************************/
36
37 22 gate_result_t gate_ui_ctrl_init(gate_ui_ctrl_t* ctrl)
38 {
39 22 gate_mem_clear(ctrl, sizeof(gate_ui_ctrl_t));
40 22 return GATE_RESULT_OK;
41 }
42
43
44 10 gate_result_t gate_ui_layout_create(gate_ui_layout_t* layout)
45 {
46 10 layout->border = 0;
47 10 layout->colspace = 0;
48 10 layout->rowspace = 0;
49 10 layout->columns = gate_arraylist_create(sizeof(gate_ui_layout_def_t), NULL, 0, NULL, NULL);
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (gate_arraylist_is_null(layout->columns))
51 {
52 ✗ return GATE_RESULT_OUTOFMEMORY;
53 }
54 10 layout->rows = gate_arraylist_create(sizeof(gate_ui_layout_def_t), NULL, 0, NULL, NULL);
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (gate_arraylist_is_null(layout->rows))
56 {
57 ✗ gate_arraylist_release(&layout->columns);
58 ✗ return GATE_RESULT_OUTOFMEMORY;
59 }
60 10 layout->cells = gate_arraylist_create(sizeof(gate_arraylist_t), NULL, 0, NULL, NULL);
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (gate_arraylist_is_null(layout->cells))
62 {
63 ✗ gate_arraylist_release(&layout->rows);
64 ✗ gate_arraylist_release(&layout->columns);
65 ✗ return GATE_RESULT_OUTOFMEMORY;
66 }
67 10 return GATE_RESULT_OK;
68 }
69
70 10 gate_result_t gate_ui_layout_destroy(gate_ui_layout_t* layout)
71 {
72 10 gate_size_t maxrows = gate_arraylist_length(layout->cells);
73 gate_size_t ndx;
74
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 10 times.
24 for (ndx = 0; ndx < maxrows; ++ndx)
75 {
76 14 gate_arraylist_t* collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, ndx);
77 14 gate_arraylist_release(collist);
78 }
79 10 gate_arraylist_release(&layout->cells);
80 10 gate_arraylist_release(&layout->rows);
81 10 gate_arraylist_release(&layout->columns);
82 10 return GATE_RESULT_OK;
83 }
84
85 5 gate_result_t gate_ui_layout_clear(gate_ui_layout_t* layout)
86 {
87 5 gate_ui_layout_destroy(layout);
88 5 return gate_ui_layout_create(layout);
89 }
90
91 static gate_ui_layout_cell_t const gate_ui_layout_empty_cell = { NULL, 0, 0, 0, 0, 0, 0 };
92
93 8 gate_result_t gate_ui_layout_add_column(gate_ui_layout_t* layout, gate_uint32_t type, gate_real32_t value)
94 {
95 gate_result_t ret;
96 gate_ui_layout_def_t def;
97 8 def.type = type;
98 8 def.value = value;
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (NULL == gate_arraylist_add(layout->columns, &def))
100 {
101 ✗ ret = GATE_RESULT_FAILED;
102 }
103 else
104 {
105 8 ret = GATE_RESULT_OK;
106 }
107 8 return ret;
108 }
109
110 14 gate_result_t gate_ui_layout_add_row(gate_ui_layout_t* layout, gate_uint32_t type, gate_real32_t value)
111 {
112 gate_result_t ret;
113 gate_ui_layout_def_t def;
114 14 def.type = type;
115 14 def.value = value;
116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (NULL == gate_arraylist_add(layout->rows, &def))
117 {
118 ✗ ret = GATE_RESULT_FAILED;
119 }
120 else
121 {
122 14 ret = GATE_RESULT_OK;
123 }
124 14 return ret;
125 }
126
127 14 gate_uint32_t gate_ui_layout_get_rows(gate_ui_layout_t* layout)
128 {
129 14 gate_uint32_t ret = 0;
130
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 if (!gate_arraylist_is_null(layout->rows))
131 {
132 14 ret = (gate_uint32_t)gate_arraylist_length(layout->rows);
133 }
134 14 return ret;
135 }
136 8 gate_uint32_t gate_ui_layout_get_columns(gate_ui_layout_t* layout)
137 {
138 8 gate_uint32_t ret = 0;
139
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 if (!gate_arraylist_is_null(layout->rows))
140 {
141 8 ret = (gate_uint32_t)gate_arraylist_length(layout->columns);
142 }
143 8 return ret;
144 }
145
146 2 gate_result_t gate_ui_layout_set_row(gate_ui_layout_t* layout, gate_uint32_t row, gate_uint32_t type, gate_real32_t value)
147 {
148 2 gate_ui_layout_def_t* def = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, row);
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (NULL == def)
150 {
151 ✗ return GATE_RESULT_NOMATCH;
152 }
153 else
154 {
155 2 def->type = type;
156 2 def->value = value;
157 2 return GATE_RESULT_OK;
158 }
159 }
160
161 1 gate_result_t gate_ui_layout_set_column(gate_ui_layout_t* layout, gate_uint32_t col, gate_uint32_t type, gate_real32_t value)
162 {
163 1 gate_ui_layout_def_t* def = (gate_ui_layout_def_t*)gate_arraylist_get(layout->columns, col);
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (NULL == def)
165 {
166 ✗ return GATE_RESULT_NOMATCH;
167 }
168 else
169 {
170 1 def->type = type;
171 1 def->value = value;
172 1 return GATE_RESULT_OK;
173 }
174 }
175
176 15 gate_result_t gate_ui_layout_set_control(gate_ui_layout_t* layout,
177 gate_ui_ctrl_t* ctrl, gate_uint32_t row, gate_uint32_t col,
178 gate_uint32_t rowspan, gate_uint32_t colspan
179 )
180 {
181 gate_size_t rowcount;
182 gate_size_t colcount;
183 gate_arraylist_t* collist;
184 gate_ui_layout_cell_t* cell;
185
186 15 rowcount = gate_arraylist_length(layout->cells);
187
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 15 times.
29 for (; rowcount <= row; ++rowcount)
188 {
189 14 gate_arraylist_t newlist = gate_arraylist_create(sizeof(gate_ui_layout_empty_cell), NULL, 0, NULL, NULL);
190
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (gate_arraylist_is_null(newlist))
191 {
192 ✗ return GATE_RESULT_OUTOFMEMORY;
193 }
194
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (NULL == gate_arraylist_add(layout->cells, &newlist))
195 {
196 ✗ gate_arraylist_release(&newlist);
197 ✗ return GATE_RESULT_OUTOFMEMORY;
198 }
199 }
200 15 collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row);
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (collist == NULL)
202 {
203 ✗ return GATE_RESULT_FAILED;
204 }
205 15 colcount = gate_arraylist_length(*collist);
206
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 15 times.
31 for (; colcount <= col; ++colcount)
207 {
208
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (NULL == gate_arraylist_add(*collist, &gate_ui_layout_empty_cell))
209 {
210 ✗ return GATE_RESULT_OUTOFMEMORY;
211 }
212 }
213 15 cell = (gate_ui_layout_cell_t*)gate_arraylist_get(*collist, col);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (cell == NULL)
215 {
216 ✗ return GATE_RESULT_FAILED;
217 }
218 15 cell->ctrl = ctrl;
219 15 cell->rowspan = rowspan;
220 15 cell->colspan = colspan;
221
222 15 return GATE_RESULT_OK;
223 }
224
225 2 gate_result_t gate_ui_layout_find_control(gate_ui_layout_t* layout,
226 gate_ui_ctrl_t* ctrl, gate_uint32_t* ptr_row, gate_uint32_t* ptr_col,
227 gate_uint32_t* ptr_rowspan, gate_uint32_t* ptr_colspan)
228 {
229 2 gate_size_t const rowcount = gate_arraylist_length(layout->cells);
230 gate_size_t row;
231
232
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 for (row = 0; row != rowcount; ++row)
233 {
234 2 gate_arraylist_t* const collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row);
235 2 gate_size_t const colcount = gate_arraylist_length(*collist);
236 gate_size_t col;
237
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 for (col = 0; col != colcount; ++col)
238 {
239 2 gate_ui_layout_cell_t* const cell = (gate_ui_layout_cell_t*)gate_arraylist_get(*collist, col);
240
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ctrl == cell->ctrl)
241 {
242
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ptr_row) *ptr_row = row;
243
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ptr_col) *ptr_col = col;
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ptr_rowspan) *ptr_rowspan = cell->rowspan;
245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ptr_colspan) *ptr_colspan = cell->colspan;
246 2 return GATE_RESULT_OK;
247 }
248 }
249 }
250 ✗ return GATE_RESULT_NOMATCH;
251 }
252
253
254 11 gate_result_t gate_ui_layout_apply(gate_ui_layout_t const* layout, gate_uint32_t unitLength, gate_ui_position_t const* pose)
255 {
256 gate_int32_t rowheights[256];
257 gate_int32_t colwidths[256];
258 gate_size_t rowcount;
259 gate_size_t colcount;
260
261 gate_int32_t width;
262 gate_int32_t height;
263 gate_int32_t remainwidth;
264 gate_int32_t remainheight;
265
266 gate_size_t ndx;
267 gate_size_t autocnt;
268 gate_ui_layout_def_t* currentdef;
269 gate_int32_t x, y, w, h;
270 gate_size_t row, col;
271 gate_ui_point_t ctrlpoint;
272 gate_ui_size_t ctrlsize;
273
274
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
11 if (!layout || !pose)
275 {
276 1 return GATE_RESULT_INVALIDDATA;
277 }
278
279 10 rowcount = gate_arraylist_length(layout->rows);
280 10 colcount = gate_arraylist_length(layout->columns);
281
282 10 width = pose->size.width - layout->border * 2;
283 10 height = pose->size.height - layout->border * 2;
284
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (rowcount > sizeof(rowheights) / sizeof(rowheights[0])) rowcount = sizeof(rowheights) / sizeof(rowheights[0]);
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (colcount > sizeof(colwidths) / sizeof(colwidths[0])) colcount = sizeof(colwidths) / sizeof(colwidths[0]);
287
288
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (colcount > 0) width -= (gate_int32_t)(colcount) * (gate_int32_t)layout->colspace;
289
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (rowcount > 0) height -= (gate_int32_t)(rowcount) * (gate_int32_t)layout->rowspace;
290 10 remainwidth = width;
291 10 remainheight = height;
292
293
294 /* calculating cell widths */
295 10 autocnt = 0;
296
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 10 times.
29 for (ndx = 0; ndx != colcount; ++ndx)
297 {
298 19 currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->columns, ndx);
299
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 13 times.
19 switch (currentdef->type)
300 {
301 ✗ case GATE_UI_LAYOUT_TYPE_PIXEL: colwidths[ndx] = (gate_int32_t)currentdef->value; break;
302 3 case GATE_UI_LAYOUT_TYPE_PERCENT: colwidths[ndx] = (gate_int32_t)((gate_real32_t)width * currentdef->value * 0.01f); break;
303 3 case GATE_UI_LAYOUT_TYPE_UNITSCALE: colwidths[ndx] = (gate_int32_t)((gate_real32_t)unitLength * currentdef->value); break;
304 13 default:
305 13 case GATE_UI_LAYOUT_TYPE_AUTO: colwidths[ndx] = 0; ++autocnt; break;
306 }
307 19 remainwidth -= colwidths[ndx];
308 }
309
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (autocnt > 0)
310 {
311
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 10 times.
29 for (ndx = 0; ndx != colcount; ++ndx)
312 {
313 19 currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->columns, ndx);
314
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 13 times.
19 switch (currentdef->type)
315 {
316 6 case GATE_UI_LAYOUT_TYPE_PIXEL:
317 case GATE_UI_LAYOUT_TYPE_PERCENT:
318 case GATE_UI_LAYOUT_TYPE_UNITSCALE:
319 6 break;
320 13 default:
321 case GATE_UI_LAYOUT_TYPE_AUTO:
322 13 colwidths[ndx] = remainwidth / (gate_int32_t)autocnt;
323 13 break;
324 }
325 }
326 }
327
328 /* calculating cell heights */
329 10 autocnt = 0;
330
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
41 for (ndx = 0; ndx != rowcount; ++ndx)
331 {
332 31 currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, ndx);
333
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 8 times.
31 switch (currentdef->type)
334 {
335 3 case GATE_UI_LAYOUT_TYPE_PIXEL: rowheights[ndx] = (gate_int32_t)currentdef->value; break;
336 ✗ case GATE_UI_LAYOUT_TYPE_PERCENT: rowheights[ndx] = (gate_int32_t)((gate_real32_t)height * currentdef->value * 0.01f); break;
337 20 case GATE_UI_LAYOUT_TYPE_UNITSCALE: rowheights[ndx] = (gate_int32_t)((gate_real32_t)unitLength * currentdef->value); break;
338 8 default:
339 8 case GATE_UI_LAYOUT_TYPE_AUTO: rowheights[ndx] = 0; ++autocnt; break;
340 }
341 31 remainheight -= rowheights[ndx];
342 }
343
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (autocnt > 0)
344 {
345
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 5 times.
19 for (ndx = 0; ndx != rowcount; ++ndx)
346 {
347 14 currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, ndx);
348
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
14 switch (currentdef->type)
349 {
350 6 case GATE_UI_LAYOUT_TYPE_PIXEL:
351 case GATE_UI_LAYOUT_TYPE_PERCENT:
352 case GATE_UI_LAYOUT_TYPE_UNITSCALE:
353 6 break;
354 8 default:
355 case GATE_UI_LAYOUT_TYPE_AUTO:
356 8 rowheights[ndx] = remainheight / (gate_int32_t)autocnt;
357 8 break;
358 }
359 }
360 }
361
362 /**/
363 10 y = pose->pos.y + layout->border + layout->rowspace / 2;
364
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
41 for (row = 0; row < rowcount; ++row)
365 {
366 gate_arraylist_t* currentcollist;
367 31 h = rowheights[row];
368
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 if (row >= gate_arraylist_length(layout->cells))
369 {
370 /* there are no further rows with column cells, so we can cancel further processing */
371 ✗ break;
372 }
373 31 currentcollist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row);
374
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (currentcollist != NULL)
375 {
376 31 x = pose->pos.x + layout->border + layout->colspace / 2;
377
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 19 times.
71 for (col = 0; col < colcount; ++col)
378 {
379 gate_ui_layout_cell_t* currentcell;
380 52 w = colwidths[col];
381
382
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 40 times.
52 if (col >= gate_arraylist_length(*currentcollist))
383 {
384 /* there are no more cells in the current row, so we can skip all remaining columns */
385 12 break;
386 }
387 40 currentcell = (gate_ui_layout_cell_t*)gate_arraylist_get(*currentcollist, col);
388
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (currentcell != NULL)
389 {
390
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 3 times.
40 if (currentcell->ctrl != NULL)
391 {
392
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 if (gate_ui_ctrl_is_created(currentcell->ctrl))
393 {
394 37 ctrlpoint.x = x;
395 37 ctrlpoint.y = y;
396 37 ctrlsize.width = w;
397 37 ctrlsize.height = h;
398
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 37 times.
49 for (ndx = 1; ndx < currentcell->colspan; ++ndx)
399 {
400 12 ctrlsize.width += colwidths[col + ndx] + layout->colspace;
401 }
402
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 37 times.
40 for (ndx = 1; ndx < currentcell->rowspan; ++ndx)
403 {
404 3 ctrlsize.height += rowheights[row + ndx] + layout->rowspace;
405 }
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (ctrlsize.width < 2) ctrlsize.width = 2;
407
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 31 times.
37 if (ctrlsize.height < 2) ctrlsize.height = 2;
408 37 gate_ui_ctrl_set_position(currentcell->ctrl, &ctrlpoint, &ctrlsize);
409 37 gate_ui_ctrl_refresh(currentcell->ctrl);
410 }
411 }
412 }
413 40 x += (w + layout->colspace);
414 }
415 }
416
417 31 y += (h + layout->rowspace);
418 }
419
420 10 return GATE_RESULT_OK;
421 }
422
423
424
425
426 #if defined(GATE_UI_WINAPI)
427
428 #include "gate/platforms.h"
429 #include "gate/ui/gateui_winapi.h"
430
431
432
433
434
435 gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam)
436 {
437 return gate_ui_winapi_host_init(host, apphandle, userparam);
438 }
439 gate_result_t gate_ui_host_uninit(gate_ui_host_t* host)
440 {
441 return gate_ui_winapi_host_uninit(host);
442 }
443 gate_result_t gate_ui_host_run(gate_ui_host_t* host)
444 {
445 gate_result_t ret = GATE_RESULT_OK;
446 while (GATE_SUCCEEDED(ret))
447 {
448 ret = gate_ui_winapi_host_process_msg(host);
449 }
450 if (ret == GATE_RESULT_CANCELED)
451 {
452 /* ui host has received a quit message, which is OK too */
453 ret = GATE_RESULT_OK;
454 }
455 return ret;
456 }
457 gate_result_t gate_ui_host_quit(gate_ui_host_t* host)
458 {
459 gate_result_t ret = GATE_RESULT_OK;
460 #if defined(GATE_SYS_WIN16)
461 GATE_UNUSED_ARG(host);
462 PostQuitMessage(0);
463 #else
464 DWORD threadId = GATE_UI_WINAPI_GET_HOST_THREADID(host);
465 if (PostThreadMessage(threadId, WM_QUIT, 0, 0))
466 {
467 ret = GATE_RESULT_OK;
468 }
469 else
470 {
471 gate_win32_print_lasterror(&ret, NULL, 0);
472 }
473 #endif
474 return ret;
475 }
476 void* gate_ui_host_get_userparam(gate_ui_host_t* host)
477 {
478 return GATE_UI_WINAPI_GET_HOST_USER_PARAM(host);
479 }
480 gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host)
481 {
482 return GATE_UI_WINAPI_GET_HOST_APPHANDLE(host);
483 }
484 gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host)
485 {
486 return GATE_UI_WINAPI_GET_HOST_LINEHEIGHT(host);
487 }
488 gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count)
489 {
490 const gate_uint32_t line_height = GATE_UI_WINAPI_GET_HOST_LINEHEIGHT(host);
491 gate_uint32_t height = line_height * 14 / 8;
492 if (line_count > 1)
493 {
494 height += (line_count - 1) * line_height;
495 }
496 ++height;
497 return height;
498 }
499
500
501
502 void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl)
503 {
504 void* ret = NULL;
505 if (ctrl != NULL)
506 {
507 ret = GATE_UI_WINAPI_GET_USER_PARAM(ctrl);
508 }
509 return ret;
510 }
511 gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl)
512 {
513 gate_ui_host_t* host = NULL;
514 if (ctrl != NULL)
515 {
516 host = GATE_UI_WINAPI_GET_HOST(ctrl);
517 }
518 return host;
519 }
520 gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl)
521 {
522 gate_ui_ctrl_t* ret = NULL;
523 if (ctrl != NULL)
524 {
525 gate_ui_host_t* host = GATE_UI_WINAPI_GET_HOST(ctrl);
526 ui_hwnd_t hwndParent = GATE_UI_WINAPI_GET_HWND_PARENT(ctrl);
527 if ((host) && (hwndParent))
528 {
529 ret = gate_ui_winapi_resolve_ctrl(host, hwndParent);
530 }
531 }
532 return ret;
533 }
534
535
536
537 gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl)
538 {
539 gate_ui_winapi_dispatchers_t* disp;
540 gate_array_t children;
541 gate_result_t ret;
542 gate_size_t children_count;
543 gate_ui_ctrl_t* const* ptr_child;
544 HWND hwnd = (HWND)NULL;
545
546 do
547 {
548 if (ctrl == NULL)
549 {
550 ret = GATE_RESULT_NULLPOINTER;
551 break;
552 }
553 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
554 if ((disp == NULL) || (disp->destroy == NULL))
555 {
556 hwnd = (HWND)GATE_UI_WINAPI_GET_HWND(ctrl);
557 if (hwnd == HWND_NULL)
558 {
559 ret = GATE_RESULT_OK; /* already destroyed, nothing to do */
560 }
561 else
562 {
563 ret = gate_ui_ctrl_get_children(ctrl, &children);
564 if (GATE_SUCCEEDED(ret))
565 {
566 children_count = gate_array_length(&children);
567 ptr_child = (gate_ui_ctrl_t* const*)gate_array_get(&children, 0);
568 while (children_count-- != 0)
569 {
570 gate_ui_ctrl_destroy(*ptr_child);
571 ++ptr_child;
572 }
573 gate_array_release(&children);
574 }
575
576 ret = gate_ui_winapi_destroy_with_font(ctrl);
577 }
578 }
579 else
580 {
581 ret = disp->destroy(ctrl);
582 }
583
584 GATE_UI_WINAPI_SET_HWND(ctrl, NULL);
585 GATE_UI_WINAPI_SET_HWND_PARENT(ctrl, NULL);
586 GATE_UI_WINAPI_SET_HOST(ctrl, NULL);
587 GATE_UI_WINAPI_SET_HWND_PROC(ctrl, NULL);
588 GATE_UI_WINAPI_SET_USER_PARAM(ctrl, NULL);
589 GATE_UI_WINAPI_SET_DISPATCHER(ctrl, NULL);
590 GATE_UI_WINAPI_SET_CTRL_PARAM(ctrl, NULL);
591 } while (0);
592 return ret;
593 }
594 gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl)
595 {
596 return gate_ui_winapi_is_created(ctrl);
597 }
598 gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl)
599 {
600 gate_ui_winapi_dispatchers_t* disp;
601 if (ctrl == NULL)
602 {
603 return false;
604 }
605 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
606 if ((disp == NULL) || (disp->is_enabled == NULL))
607 {
608 return gate_ui_winapi_is_enabled(ctrl);
609 }
610 return disp->is_enabled(ctrl);
611 }
612 gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl)
613 {
614 gate_ui_winapi_dispatchers_t* disp;
615 if (ctrl == NULL)
616 {
617 return false;
618 }
619 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
620 if ((disp == NULL) || (disp->is_visible == NULL))
621 {
622 return gate_ui_winapi_is_visible(ctrl);
623 }
624 return disp->is_visible(ctrl);
625
626 }
627 gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl)
628 {
629 gate_ui_winapi_dispatchers_t* disp;
630 if (ctrl == NULL)
631 {
632 return false;
633 }
634 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
635 if ((disp == NULL) || (disp->is_focused == NULL))
636 {
637 return gate_ui_winapi_is_focused(ctrl);
638 }
639 return disp->is_focused(ctrl);
640
641 }
642 gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position)
643 {
644 gate_ui_winapi_dispatchers_t* disp;
645 if (ctrl == NULL)
646 {
647 return GATE_RESULT_NULLPOINTER;
648 }
649 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
650 if ((disp == NULL) || (disp->get_position == NULL))
651 {
652 return gate_ui_winapi_get_position(ctrl, position);
653 }
654 return disp->get_position(ctrl, position);
655 }
656 gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size)
657 {
658 gate_ui_winapi_dispatchers_t* disp;
659 if (ctrl == NULL)
660 {
661 return GATE_RESULT_NULLPOINTER;
662 }
663 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
664 if ((disp == NULL) || (disp->get_size == NULL))
665 {
666 return gate_ui_winapi_get_size(ctrl, size);
667 }
668 return disp->get_size(ctrl, size);
669 }
670 gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children)
671 {
672 gate_ui_winapi_dispatchers_t* disp;
673 if (ctrl == NULL)
674 {
675 return GATE_RESULT_NULLPOINTER;
676 }
677 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
678 if ((disp == NULL) || (disp->get_children == NULL))
679 {
680 return gate_ui_winapi_get_children(ctrl, children);
681 }
682 return disp->get_children(ctrl, children);
683 }
684 gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length)
685 {
686 gate_ui_winapi_dispatchers_t* disp;
687 if (ctrl == NULL)
688 {
689 return GATE_RESULT_NULLPOINTER;
690 }
691 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
692 if ((disp == NULL) || (disp->get_text == NULL))
693 {
694 return gate_ui_winapi_get_text_length(ctrl, length);
695 }
696 return disp->get_text_length(ctrl, length);
697 }
698
699 gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text)
700 {
701 gate_ui_winapi_dispatchers_t* disp;
702 if (ctrl == NULL)
703 {
704 return GATE_RESULT_NULLPOINTER;
705 }
706 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
707 if ((disp == NULL) || (disp->get_text == NULL))
708 {
709 return gate_ui_winapi_get_text(ctrl, text);
710 }
711 return disp->get_text(ctrl, text);
712 }
713 gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* state)
714 {
715 gate_ui_winapi_dispatchers_t* disp;
716 if (ctrl == NULL)
717 {
718 return GATE_RESULT_NULLPOINTER;
719 }
720 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
721 if ((disp == NULL) || (disp->get_state == NULL))
722 {
723 return gate_ui_winapi_get_state(ctrl, state);
724 }
725 return disp->get_state(ctrl, state);
726 }
727
728 gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate)
729 {
730 gate_ui_winapi_dispatchers_t* disp;
731 if (ctrl == NULL)
732 {
733 return GATE_RESULT_NULLPOINTER;
734 }
735 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
736 if ((disp == NULL) || (disp->set_enabled == NULL))
737 {
738 return gate_ui_winapi_set_enabled(ctrl, enabledstate);
739 }
740 return disp->set_enabled(ctrl, enabledstate);
741 }
742 gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility)
743 {
744 gate_ui_winapi_dispatchers_t* disp;
745 if (ctrl == NULL)
746 {
747 return GATE_RESULT_NULLPOINTER;
748 }
749 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
750 if ((disp == NULL) || (disp->set_visible == NULL))
751 {
752 return gate_ui_winapi_set_visible(ctrl, visibility);
753 }
754 return disp->set_visible(ctrl, visibility);
755 }
756 gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl)
757 {
758 gate_ui_winapi_dispatchers_t* disp;
759 if (ctrl == NULL)
760 {
761 return GATE_RESULT_NULLPOINTER;
762 }
763 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
764 if ((disp == NULL) || (disp->set_focus == NULL))
765 {
766 return gate_ui_winapi_set_focus(ctrl);
767 }
768 return disp->set_focus(ctrl);
769 }
770 gate_result_t gate_ui_ctrl_set_position(gate_ui_ctrl_t* ctrl, gate_ui_point_t const* position, gate_ui_size_t const* size)
771 {
772 gate_ui_winapi_dispatchers_t* disp;
773 if (ctrl == NULL)
774 {
775 return GATE_RESULT_NULLPOINTER;
776 }
777 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
778 if ((disp == NULL) || (disp->set_position == NULL))
779 {
780 return gate_ui_winapi_set_position(ctrl, position, size);
781 }
782 return disp->set_position(ctrl, position, size);
783 }
784 gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text)
785 {
786 gate_ui_winapi_dispatchers_t* disp;
787 if (ctrl == NULL)
788 {
789 return GATE_RESULT_NULLPOINTER;
790 }
791 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
792 if ((disp == NULL) || (disp->set_text == NULL))
793 {
794 return gate_ui_winapi_set_text(ctrl, text);
795 }
796 return disp->set_text(ctrl, text);
797 }
798 gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state)
799 {
800 gate_ui_winapi_dispatchers_t* disp;
801 if (ctrl == NULL)
802 {
803 return GATE_RESULT_NULLPOINTER;
804 }
805 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
806 if ((disp == NULL) || (disp->set_state == NULL))
807 {
808 return gate_ui_winapi_set_state(ctrl, state);
809 }
810 return disp->set_state(ctrl, state);
811 }
812
813 gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl)
814 {
815 gate_ui_winapi_dispatchers_t* disp;
816 if (ctrl == NULL)
817 {
818 return GATE_RESULT_NULLPOINTER;
819 }
820 disp = GATE_UI_WINAPI_GET_DISPATCHER(ctrl);
821 if ((disp == NULL) || (disp->refresh == NULL))
822 {
823 return gate_ui_winapi_refresh(ctrl);
824 }
825 return disp->refresh(ctrl);
826
827 }
828
829 typedef struct gate_ui_host_enum_fonts_helper
830 {
831 gate_ui_enum_fontnames_callback_t cb;
832 void* userparam;
833 } gate_ui_host_enum_fonts_helper_t;
834
835 #if defined(GATE_SYS_WIN16)
836 static int CALLBACK gate_ui_host_enum_fonts_callback(LOGFONT const FAR* lplf, TEXTMETRIC const FAR* lptm, int dwType, LPARAM lpData)
837 #else
838 static int CALLBACK gate_ui_host_enum_fonts_callback(LOGFONT const* lplf, TEXTMETRIC const* lptm, DWORD dwType, LPARAM lpData)
839 #endif
840 {
841 gate_ui_host_enum_fonts_helper_t* helper = (gate_ui_host_enum_fonts_helper_t*)(void*)(gate_intptr_t)lpData;
842 char fontname[128];
843
844 GATE_UNUSED_ARG(lptm);
845 GATE_UNUSED_ARG(dwType);
846 gate_win32_winstr_2_utf8(lplf->lfFaceName, gate_win32_str_len(lplf->lfFaceName), fontname, sizeof(fontname));
847
848 helper->cb(fontname, helper->userparam);
849 return TRUE;
850 }
851
852 gate_result_t gate_ui_host_enum_fonts(gate_ui_host_t* host, gate_ui_enum_fontnames_callback_t callback, void* userparam)
853 {
854 gate_result_t ret;
855 gate_ui_host_enum_fonts_helper_t helper;
856 HDC hdc;
857 GATE_UNUSED_ARG(host);
858 hdc = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
859 if (!hdc)
860 {
861 ret = GATE_RESULT_OUTOFRESOURCES;
862 }
863 else
864 {
865 helper.cb = callback;
866 helper.userparam = userparam;
867 EnumFonts(hdc, NULL, &gate_ui_host_enum_fonts_callback, (LPARAM)(gate_intptr_t)(void*)&helper);
868 ret = GATE_RESULT_OK;
869 }
870 return ret;
871
872 }
873 gate_result_t gate_ui_host_default_font(gate_ui_host_t* host, gate_uint32_t fonttype, gate_ui_font_t* font)
874 {
875 gate_result_t ret = GATE_RESULT_OK;
876 GATE_UNUSED_ARG(host);
877
878 ret = gate_ui_winapi_get_default_font(font);
879 if (GATE_SUCCEEDED(ret))
880 {
881 switch (fonttype)
882 {
883 case GATE_UI_FONT_TYPE_STANDARD:
884 {
885 break;
886 }
887 case GATE_UI_FONT_TYPE_SANSSERIF:
888 {
889 gate_mem_copy(&font->font_name[0], "Arial", 6);
890 break;
891 }
892 case GATE_UI_FONT_TYPE_SERIF:
893 {
894 gate_mem_copy(&font->font_name[0], "Times New Roman", 16);
895 break;
896 }
897 case GATE_UI_FONT_TYPE_MONOSPACE:
898 {
899 gate_mem_copy(&font->font_name[0], "Courier New", 12);
900 break;
901 }
902 default:
903 {
904 ret = GATE_RESULT_INVALIDARG;
905 break;
906 }
907 }
908 }
909 return ret;
910 }
911
912 #define GATE_UI_HOST_DEFAULT_DPI_VALUE 96
913
914 static gate_int32_t gate_ui_host_get_default_dpi()
915 {
916 static gate_int32_t cached_dpi_value = 0;
917 gate_int32_t ret = GATE_UI_HOST_DEFAULT_DPI_VALUE;
918
919 if (cached_dpi_value == 0)
920 {
921 int tmp = GATE_UI_HOST_DEFAULT_DPI_VALUE;
922 HDC hdc_screen = GetDC(NULL);
923 if (hdc_screen)
924 {
925 tmp = GetDeviceCaps(hdc_screen, LOGPIXELSY);
926 if (tmp == 0)
927 {
928 tmp = GATE_UI_HOST_DEFAULT_DPI_VALUE;
929 }
930 ReleaseDC(NULL, hdc_screen);
931 }
932 cached_dpi_value = tmp;
933 ret = tmp;
934 }
935 else
936 {
937 ret = cached_dpi_value;
938 }
939 return ret;
940 }
941
942 gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points)
943 {
944 gate_int32_t dpi = gate_ui_host_get_default_dpi();
945 (void)host;
946 return (gate_int32_t)((points * (gate_real32_t)dpi / 72.0f) + 0.5f);
947 }
948 gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels)
949 {
950 gate_int32_t dpi = gate_ui_host_get_default_dpi();
951 gate_int32_t tmp = (gate_int32_t)((pixels * 72.0f / (gate_real32_t)dpi) + 0.5f);
952 (void)host;
953 return (gate_real32_t)tmp;
954 }
955
956 #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT)
957 static gate_ui_color_t dark_color_window_background = { 0x00, 0x00, 0x00, 0xff };
958 static gate_ui_color_t dark_color_window_text = { 0xff, 0xff, 0xff, 0xff };
959 static gate_ui_color_t dark_color_window_text_disabled = { 0xcc, 0xcc, 0xcc, 0xff };
960
961 static gate_ui_color_t dark_color_menu_background = { 0x2b, 0x2b, 0x2b, 0xff };
962 static gate_ui_color_t dark_color_menu_selected = { 0x41, 0x41, 0x41, 0xff };
963 static gate_ui_color_t dark_color_menu_text = { 0xff, 0xff, 0xff, 0xff };
964
965 static gate_ui_color_t dark_color_content_background = { 0x19, 0x19, 0x19, 0xff };
966 static gate_ui_color_t dark_color_content_text = { 0xff, 0xff, 0xff, 0xff };
967 static gate_ui_color_t dark_color_content_text_disabled = { 0xcc, 0xcc, 0xcc, 0xff };
968 static gate_ui_color_t dark_color_content_selected = { 0x33, 0x33, 0x33, 0xff };
969 static gate_ui_color_t dark_color_content_focus = { 0x62, 0x62, 0x62, 0xff };
970 static gate_ui_color_t dark_color_content_hilight = { 0x77, 0x77, 0x77, 0xff };
971
972 static gate_ui_color_t dark_color_control_background = { 0x20, 0x20, 0x20, 0xff };
973 static gate_ui_color_t dark_color_control_text = { 0xff, 0xff, 0xff, 0xff };
974 static gate_ui_color_t dark_color_control_text_disabled = { 0xcc, 0xcc, 0xcc, 0xff };
975
976 static gate_ui_color_t dark_color_border_light = { 0xa0, 0xa0, 0xa0, 0xff };
977 static gate_ui_color_t dark_color_border_dark = { 0x12, 0x12, 0x12, 0xff };
978
979 /* Content - Hilight : 4d4d4d */
980
981 #endif
982
983 gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col)
984 {
985 int syscolor;
986 COLORREF color;
987 /*gate_result_t result; */
988 /*wchar_t const* theme_color_name = NULL;*/
989 #if !defined(GATE_SYS_WIN16)
990 gate_ui_color_t* ptr_col = NULL;
991 #endif
992 GATE_UNUSED_ARG(host);
993
994 #if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT)
995 if (gate_ui_winapi_darkmode_enabled())
996 {
997 switch (colortype)
998 {
999 case GATE_UI_COLOR_BACKGROUND:
1000 case GATE_UI_COLOR_WORKSPACE:
1001 case GATE_UI_COLOR_WINDOW: ptr_col = &dark_color_window_background; break;
1002 case GATE_UI_COLOR_WINDOWTEXT: ptr_col = &dark_color_window_text; break;
1003 case GATE_UI_COLOR_WINDOWTEXTDISABLED: ptr_col = &dark_color_window_text_disabled; break;
1004
1005 case GATE_UI_COLOR_DIALOG: ptr_col = &dark_color_control_background; break;
1006 case GATE_UI_COLOR_DIALOGTEXT: ptr_col = &dark_color_control_text; break;
1007 case GATE_UI_COLOR_DIALOGTEXTDISABLED: ptr_col = &dark_color_control_text_disabled;break;
1008
1009 case GATE_UI_COLOR_CONTROL: ptr_col = &dark_color_control_background; break;
1010 case GATE_UI_COLOR_CONTROLTEXT: ptr_col = &dark_color_control_text; break;
1011 case GATE_UI_COLOR_CONTROLTEXTDISABLED: ptr_col = &dark_color_control_text_disabled;break;
1012
1013 case GATE_UI_COLOR_CONTROLBORDERLIGHT: ptr_col = &dark_color_border_light; break;
1014 case GATE_UI_COLOR_CONTROLBORDERHILIGHT: ptr_col = &dark_color_border_light; break;
1015 case GATE_UI_COLOR_CONTROLBORDERSHADOW: ptr_col = &dark_color_border_dark; break;
1016 case GATE_UI_COLOR_CONTROLBORDERDARKSHADOW: ptr_col = &dark_color_border_dark; break;
1017
1018 case GATE_UI_COLOR_MENUBACKGROUND: ptr_col = &dark_color_menu_background; break;
1019 case GATE_UI_COLOR_MENUTEXT: ptr_col = &dark_color_menu_text; break;
1020 case GATE_UI_COLOR_SELECTEDMENUBACKGROUND: ptr_col = &dark_color_menu_selected; break;
1021 case GATE_UI_COLOR_SELECTEDMENUTEXT: ptr_col = &dark_color_menu_text; break;
1022 case GATE_UI_COLOR_HOVERMENUBACKGROUND: ptr_col = &dark_color_menu_selected; break;
1023 case GATE_UI_COLOR_HOVERMENUTEXT: ptr_col = &dark_color_menu_text; break;
1024
1025 case GATE_UI_COLOR_CONTENTBACKGROUND: ptr_col = &dark_color_content_background; break;
1026 case GATE_UI_COLOR_CONTENTTEXT: ptr_col = &dark_color_content_text; break;
1027 case GATE_UI_COLOR_CONTENTTEXTDISABLED: ptr_col = &dark_color_content_text_disabled;break;
1028 case GATE_UI_COLOR_CONTENTSELECTEDBACKGROUND: ptr_col = &dark_color_content_selected; break;
1029 case GATE_UI_COLOR_CONTENTSELECTEDTEXT: ptr_col = &dark_color_content_text; break;
1030 case GATE_UI_COLOR_CONTENTBORDERLIGHT: ptr_col = &dark_color_border_light; break;
1031 case GATE_UI_COLOR_CONTENTBORDERHILIGHT: ptr_col = &dark_color_border_light; break;
1032 case GATE_UI_COLOR_CONTENTBORDERSHADOW: ptr_col = &dark_color_border_dark; break;
1033 case GATE_UI_COLOR_CONTENTBORDERDARKSHADOW: ptr_col = &dark_color_border_dark; break;
1034 }
1035
1036 if (ptr_col != NULL)
1037 {
1038 if (col)
1039 {
1040 *col = *ptr_col;
1041 }
1042 return GATE_RESULT_OK;
1043 }
1044 }
1045 #endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */
1046
1047 /* default win32 colors */
1048 syscolor = gate_ui_winapi_get_syscolor_index(colortype);
1049
1050 if (syscolor == -1)
1051 {
1052 return GATE_RESULT_NOTSUPPORTED;
1053 }
1054 else
1055 {
1056 color = GetSysColor(syscolor);
1057 if (col != NULL)
1058 {
1059 col->r = GetRValue(color);
1060 col->g = GetGValue(color);
1061 col->b = GetBValue(color);
1062 col->a = 255;
1063 }
1064 return GATE_RESULT_OK;
1065 }
1066 }
1067
1068 gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text)
1069 {
1070 gate_result_t ret;
1071 HWND appwnd = GATE_UI_WINAPI_GET_HOST_APPWND(host);
1072 HANDLE hdata;
1073 LPVOID ptrdata;
1074 gate_strbuilder_t builder;
1075 do
1076 {
1077 if (!appwnd)
1078 {
1079 ret = GATE_RESULT_NOTAVAILABLE;
1080 break;
1081 }
1082
1083 if (IsClipboardFormatAvailable(CF_TEXT))
1084 {
1085 if (!OpenClipboard(appwnd))
1086 {
1087 ret = GATE_RESULT_NOTAVAILABLE;
1088 break;
1089 }
1090
1091 ret = GATE_RESULT_OK;
1092 hdata = GetClipboardData(CF_TEXT);
1093
1094 if (hdata == NULL)
1095 {
1096 gate_string_create_empty(text);
1097 }
1098 else
1099 {
1100 ptrdata = GlobalLock(hdata);
1101 if (ptrdata == NULL)
1102 {
1103 gate_string_create_empty(text);
1104 }
1105 else
1106 {
1107 gate_string_create(text, (gate_char8_t const*)ptrdata, gate_str_length((gate_char8_t const*)ptrdata));
1108 }
1109 GlobalUnlock(hdata);
1110 }
1111 CloseClipboard();
1112 }
1113 else if (IsClipboardFormatAvailable(CF_OEMTEXT))
1114 {
1115 if (!OpenClipboard(appwnd))
1116 {
1117 ret = GATE_RESULT_NOTAVAILABLE;
1118 break;
1119 }
1120
1121 ret = GATE_RESULT_OK;
1122 hdata = GetClipboardData(CF_OEMTEXT);
1123
1124 if (hdata == NULL)
1125 {
1126 gate_string_create_empty(text);
1127 }
1128 else
1129 {
1130 ptrdata = GlobalLock(hdata);
1131 if (ptrdata == NULL)
1132 {
1133 gate_string_create_empty(text);
1134 }
1135 else
1136 {
1137 gate_string_create(text, (gate_char8_t const*)ptrdata, gate_str_length((gate_char8_t const*)ptrdata));
1138 }
1139 GlobalUnlock(hdata);
1140 }
1141 CloseClipboard();
1142 }
1143 #if !defined(GATE_SYS_WIN16)
1144 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1145 {
1146 if (!OpenClipboard(appwnd))
1147 {
1148 ret = GATE_RESULT_NOTAVAILABLE;
1149 break;
1150 }
1151
1152 ret = GATE_RESULT_OK;
1153 hdata = GetClipboardData(CF_UNICODETEXT);
1154
1155 if (hdata == NULL)
1156 {
1157 gate_string_create_empty(text);
1158 }
1159 else
1160 {
1161 ptrdata = GlobalLock(hdata);
1162 if (ptrdata == NULL)
1163 {
1164 gate_string_create_empty(text);
1165 }
1166 else
1167 {
1168 gate_strbuilder_create(&builder, 0);
1169 gate_strbuilder_append_text16(&builder, (wchar_t const*)ptrdata, gate_str16_length((wchar_t const*)ptrdata));
1170 gate_strbuilder_to_string(&builder, text);
1171 gate_strbuilder_release(&builder);
1172 }
1173 GlobalUnlock(hdata);
1174 }
1175 CloseClipboard();
1176 }
1177 #endif /* GATE_SYS_WIN16 */
1178 else
1179 {
1180 ret = GATE_RESULT_INVALIDCONTENT;
1181 break;
1182 }
1183 } while (0);
1184
1185 return ret;
1186 }
1187 gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text)
1188 {
1189 gate_result_t ret;
1190 HWND appwnd = GATE_UI_WINAPI_GET_HOST_APPWND(host);
1191 gate_size_t textlen;
1192 HGLOBAL memhandle;
1193 LPVOID memptr;
1194
1195 do
1196 {
1197 if (appwnd == NULL)
1198 {
1199 ret = GATE_RESULT_NOTAVAILABLE;
1200 break;
1201 }
1202 if (!OpenClipboard(appwnd))
1203 {
1204 ret = GATE_RESULT_NOTAVAILABLE;
1205 break;
1206 }
1207
1208 EmptyClipboard();
1209
1210 do
1211 {
1212 textlen = gate_string_length(text);
1213 if (textlen == 0)
1214 {
1215 ret = GATE_RESULT_OK;
1216 break; /* we are done */
1217 }
1218
1219 #if !defined(GATE_SYS_WIN16)
1220 /* write UTF16 text */
1221 memhandle = GlobalAlloc(GMEM_MOVEABLE, ((textlen + 2) * sizeof(gate_char16_t)));
1222 if (memhandle == NULL)
1223 {
1224 CloseClipboard();
1225 ret = GATE_RESULT_OUTOFMEMORY;
1226 break;
1227 }
1228 memptr = GlobalLock(memhandle);
1229 gate_str_utf8_2_utf16(text->str, text->length, memptr, textlen + 1);
1230 GlobalUnlock(memhandle);
1231 if (SetClipboardData(CF_UNICODETEXT, memhandle))
1232 {
1233 ret = GATE_RESULT_OK;
1234 break;
1235 }
1236 else
1237 {
1238 ret = GATE_RESULT_FAILED;
1239 GlobalFree(memhandle);
1240 break;
1241 }
1242 #endif /* GATE_SYS_WIN16 */
1243
1244 /* write plain text */
1245 memhandle = GlobalAlloc(GMEM_MOVEABLE, ((textlen + 2) * sizeof(gate_char8_t)));
1246 if (memhandle == NULL)
1247 {
1248 CloseClipboard();
1249 ret = GATE_RESULT_OUTOFMEMORY;
1250 break;
1251 }
1252 memptr = GlobalLock(memhandle);
1253 gate_str_print_text((gate_char8_t*)memptr, textlen + 2, text->str, text->length);
1254 GlobalUnlock(memhandle);
1255 if (!SetClipboardData(CF_OEMTEXT, memhandle))
1256 {
1257 GlobalFree(memhandle);
1258 ret = GATE_RESULT_FAILED;
1259 break;
1260 }
1261
1262 /* success state reached */
1263 ret = GATE_RESULT_OK;
1264 } while (0);
1265 CloseClipboard();
1266 } while (0);
1267
1268 return ret;
1269 }
1270
1271 gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1272 {
1273 RECT r = GATE_INIT_EMPTY;
1274 #if !defined(GATE_SYS_WIN16)
1275 gate_win32_userapi_t const* const userapi = gate_win32_userapi();
1276 /* try param info first */
1277 if (userapi->UserSystemParametersInfo)
1278 {
1279 if (userapi->UserSystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0))
1280 {
1281 area->pos.x = r.left;
1282 area->pos.y = r.top;
1283 area->size.width = r.right - r.left;
1284 area->size.height = r.bottom - r.top;
1285 return GATE_RESULT_OK;
1286 }
1287 }
1288 #endif
1289 /* fallback: */
1290 return gate_ui_host_total_workarea(host, area);
1291 }
1292
1293 #ifndef SM_XVIRTUALSCREEN
1294 #define SM_XVIRTUALSCREEN 76
1295 #endif
1296 #ifndef SM_YVIRTUALSCREEN
1297 #define SM_YVIRTUALSCREEN 77
1298 #endif
1299 #ifndef SM_CXVIRTUALSCREEN
1300 #define SM_CXVIRTUALSCREEN 78
1301 #endif
1302 #ifndef SM_CYVIRTUALSCREEN
1303 #define SM_CYVIRTUALSCREEN 79
1304 #endif
1305
1306 gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1307 {
1308 GATE_UNUSED_ARG(host);
1309 area->pos.x = GetSystemMetrics(SM_XVIRTUALSCREEN);
1310 area->pos.y = GetSystemMetrics(SM_YVIRTUALSCREEN);
1311 area->size.width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
1312 area->size.height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
1313 if (area->size.width == 0)
1314 {
1315 area->size.width = GetSystemMetrics(SM_CXSCREEN);
1316 }
1317 if (area->size.height == 0)
1318 {
1319 area->size.height = GetSystemMetrics(SM_CYSCREEN);
1320 }
1321 return GATE_RESULT_OK;
1322 }
1323
1324 gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code)
1325 {
1326 return gate_ui_winapi_host_post_runner(host, code, true, true);
1327 }
1328
1329 gate_result_t gate_ui_host_process_events(gate_ui_host_t* host)
1330 {
1331 return gate_ui_winapi_host_process_msg(host);
1332 }
1333
1334
1335
1336 #endif /* GATE_SYS_WIN */
1337
1338
1339
1340 #if defined(GATE_UI_GTK)
1341
1342 #include "gate/ui/gateui_gtk.h"
1343
1344 gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam)
1345 {
1346 return gate_ui_gtk_host_init(host, apphandle, userparam);
1347 }
1348 gate_result_t gate_ui_host_uninit(gate_ui_host_t* host)
1349 {
1350 return gate_ui_gtk_host_uninit(host);
1351 }
1352 gate_result_t gate_ui_host_run(gate_ui_host_t* host)
1353 {
1354 return gate_ui_gtk_host_run(host);
1355 }
1356 gate_result_t gate_ui_host_quit(gate_ui_host_t* host)
1357 {
1358 return gate_ui_gtk_host_quit(host);
1359 }
1360 void* gate_ui_host_get_userparam(gate_ui_host_t* host)
1361 {
1362 return GATE_UI_GTK_GET_HOST_USER_PARAM(host);
1363 }
1364 gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host)
1365 {
1366 return GATE_UI_GTK_GET_HOST_APPHANDLE(host);
1367 }
1368 gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host)
1369 {
1370 return 16;
1371 }
1372 gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count)
1373 {
1374 gate_uint32_t height = 14 + line_count * gate_ui_host_default_line_height(host);
1375 return height;
1376 }
1377
1378 gate_result_t gate_ui_host_enum_fonts(gate_ui_host_t* host, gate_ui_enum_fontnames_callback_t callback, void* userparam)
1379 {
1380 gate_result_t ret = GATE_RESULT_FAILED;
1381 PangoFontMap* font_map = pango_cairo_font_map_get_default(); /* must not be freed */
1382 PangoFontFamily** families = NULL;
1383 int families_count = 0;
1384 int index;
1385 char const* name = NULL;
1386
1387 do
1388 {
1389 if (!font_map)
1390 {
1391 ret = GATE_RESULT_OUTOFRESOURCES;
1392 break;
1393 }
1394 pango_font_map_list_families(font_map, &families, &families_count);
1395
1396 if (families_count <= 0)
1397 {
1398 ret = GATE_RESULT_NOTAVAILABLE;
1399 break;
1400 }
1401
1402 ret = GATE_RESULT_OK;
1403
1404 for (index = 0; index != families_count; ++index)
1405 {
1406 name = pango_font_family_get_name(families[index]);
1407 if (!name)
1408 {
1409 continue;
1410 }
1411 pango_font_family_is_monospace(families[index]);
1412
1413 if (callback)
1414 {
1415 if (!callback(name, userparam))
1416 {
1417 /* cancelled by user */
1418 break;
1419 }
1420 }
1421 }
1422
1423 } while (0);
1424
1425 if (families)
1426 {
1427 g_free(families);
1428 }
1429
1430 return ret;
1431 }
1432
1433 static gate_bool_t gate_ui_enum_fontnames_callback_test(char const* font_name, void* userparam)
1434 {
1435 return true;
1436 }
1437
1438 gate_result_t gate_ui_host_default_font(gate_ui_host_t* host, gate_uint32_t fonttype, gate_ui_font_t* font)
1439 {
1440 gate_ui_host_enum_fonts(host, &gate_ui_enum_fontnames_callback_test, NULL);
1441 gate_str_print_text(font->font_name, sizeof(font->font_name), "Monospace", 9);
1442 font->size = 12;
1443 font->orientation = 0;
1444 font->bold = false;
1445 font->italic = false;
1446 font->underline = false;
1447 font->strikeout = false;
1448
1449 return GATE_RESULT_OK;
1450 }
1451 gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points)
1452 {
1453 gate_int32_t dpi = 96;
1454 gate_int32_t fppi = 72;
1455 return (gate_int32_t)(points * dpi / fppi);
1456 }
1457 gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels)
1458 {
1459 gate_real32_t dpi = 96.0f;
1460 gate_real32_t fppi = 72.0f;
1461 return (gate_real32_t)pixels * fppi / dpi;
1462 }
1463
1464 gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col)
1465 {
1466 return GATE_RESULT_NOTIMPLEMENTED;
1467 }
1468 gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text)
1469 {
1470 return GATE_RESULT_NOTIMPLEMENTED;
1471 }
1472 gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text)
1473 {
1474 return GATE_RESULT_NOTIMPLEMENTED;
1475 }
1476 gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1477 {
1478 return GATE_RESULT_NOTIMPLEMENTED;
1479 }
1480 gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1481 {
1482 return GATE_RESULT_NOTIMPLEMENTED;
1483 }
1484 gate_result_t gate_ui_host_process_events(gate_ui_host_t* host)
1485 {
1486 /* TODO */
1487 return GATE_RESULT_OK;
1488 }
1489
1490 static gboolean gate_ui_host_execute_callback(gpointer data)
1491 {
1492 gate_runnable_t* const runnable = (gate_runnable_t*)data;
1493 if (runnable != NULL)
1494 {
1495 gate_runnable_run(runnable);
1496 gate_object_release(runnable);
1497 }
1498 return FALSE;
1499 }
1500
1501 gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code)
1502 {
1503 if (code == NULL)
1504 {
1505 return GATE_RESULT_NULLPOINTER;
1506 }
1507 gate_object_retain(code);
1508 gdk_threads_add_idle(&gate_ui_host_execute_callback, code);
1509 return GATE_RESULT_OK;
1510 }
1511
1512
1513
1514 void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl)
1515 {
1516 if (ctrl != NULL)
1517 {
1518 return GATE_UI_GTK_GET_CTRL_USER_PARAM(ctrl);
1519 }
1520 return NULL;
1521 }
1522 gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl)
1523 {
1524 if (ctrl != NULL)
1525 {
1526 return GATE_UI_GTK_GET_CTRL_HOST(ctrl);
1527 }
1528 return NULL;
1529 }
1530 gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl)
1531 {
1532 if (ctrl != NULL)
1533 {
1534
1535 }
1536 return NULL;
1537 }
1538
1539 gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl)
1540 {
1541 gate_array_t children;
1542 gate_result_t ret;
1543 gate_size_t children_count;
1544 gate_ui_ctrl_t* const* ptr_child;
1545
1546 do
1547 {
1548 if (ctrl == NULL)
1549 {
1550 ret = GATE_RESULT_NULLPOINTER;
1551 break;
1552 }
1553 ret = gate_ui_ctrl_get_children(ctrl, &children);
1554 if (GATE_SUCCEEDED(ret))
1555 {
1556 children_count = gate_array_length(&children);
1557 ptr_child = (gate_ui_ctrl_t* const*)gate_array_get(&children, 0);
1558 while (children_count-- != 0)
1559 {
1560 if (*ptr_child)
1561 {
1562 gate_ui_ctrl_destroy(*ptr_child);
1563 }
1564 ++ptr_child;
1565 }
1566 gate_array_release(&children);
1567 }
1568
1569 ret = gate_ui_gtk_ctrl_destroy(ctrl);
1570 } while (0);
1571 return ret;
1572 }
1573 gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl)
1574 {
1575 gate_bool_t ret = false;
1576 if (ctrl != NULL)
1577 {
1578 ret = GATE_UI_GTK_GET_CTRL_WIDGET(ctrl) != NULL;
1579 }
1580 return ret;
1581 }
1582 gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl)
1583 {
1584 gate_bool_t ret = false;
1585 if (ctrl != NULL)
1586 {
1587 ret = gate_ui_gtk_ctrl_is_enabled(ctrl);
1588 }
1589 return ret;
1590 }
1591 gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl)
1592 {
1593 gate_bool_t ret = false;
1594 if (ctrl != NULL)
1595 {
1596 ret = gate_ui_gtk_ctrl_is_visible(ctrl);
1597 }
1598 return ret;
1599 }
1600 gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl)
1601 {
1602 gate_bool_t ret = false;
1603 if (ctrl != NULL)
1604 {
1605 ret = gate_ui_gtk_ctrl_has_focus(ctrl);
1606 }
1607 return ret;
1608 }
1609 gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position)
1610 {
1611 if (ctrl != NULL)
1612 {
1613 return gate_ui_gtk_ctrl_get_position(ctrl, position);
1614 }
1615 return GATE_RESULT_NULLPOINTER;
1616 }
1617 gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size)
1618 {
1619 if (ctrl != NULL)
1620 {
1621 return gate_ui_gtk_ctrl_get_size(ctrl, size);
1622 }
1623 return GATE_RESULT_NULLPOINTER;
1624 }
1625 gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children)
1626 {
1627 if ((ctrl == NULL) || (children == NULL))
1628 {
1629 return GATE_RESULT_NULLPOINTER;
1630 }
1631
1632 return gate_ui_gtk_ctrl_get_children(ctrl, children);
1633 }
1634 gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text)
1635 {
1636 gate_ui_gtk_dispatcher_t* disp;
1637 if (ctrl == NULL)
1638 {
1639 return GATE_RESULT_NULLPOINTER;
1640 }
1641 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1642 if ((disp == NULL) || (disp->get_text == NULL))
1643 {
1644 return GATE_RESULT_NOTSUPPORTED;
1645 }
1646 return disp->get_text(ctrl, text);
1647 }
1648 gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length)
1649 {
1650 gate_ui_gtk_dispatcher_t* disp;
1651 gate_uint32_t l;
1652 if (ctrl == NULL)
1653 {
1654 return GATE_RESULT_NULLPOINTER;
1655 }
1656 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1657 if ((disp == NULL) || (disp->get_text_length == NULL))
1658 {
1659 return GATE_RESULT_NOTSUPPORTED;
1660 }
1661 l = disp->get_text_length(ctrl);
1662 if (length != NULL)
1663 {
1664 *length = l;
1665 }
1666 return GATE_RESULT_OK;
1667 }
1668 gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text)
1669 {
1670 gate_ui_gtk_dispatcher_t* disp;
1671 if (ctrl == NULL)
1672 {
1673 return GATE_RESULT_NULLPOINTER;
1674 }
1675 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1676 if ((disp == NULL) || (disp->set_text == NULL))
1677 {
1678 return GATE_RESULT_NOTSUPPORTED;
1679 }
1680 return disp->set_text(ctrl, text);
1681 }
1682 gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* state)
1683 {
1684 gate_ui_gtk_dispatcher_t* disp;
1685 if (ctrl == NULL)
1686 {
1687 return GATE_RESULT_NULLPOINTER;
1688 }
1689 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1690 if ((disp == NULL) || (disp->get_state == NULL))
1691 {
1692 return GATE_RESULT_NOTSUPPORTED;
1693 }
1694 return disp->get_state(ctrl, state);
1695 }
1696 gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state)
1697 {
1698 gate_ui_gtk_dispatcher_t* disp;
1699 if (ctrl == NULL)
1700 {
1701 return GATE_RESULT_NULLPOINTER;
1702 }
1703 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1704 if ((disp == NULL) || (disp->set_state == NULL))
1705 {
1706 return GATE_RESULT_NOTSUPPORTED;
1707 }
1708 return disp->set_state(ctrl, state);
1709 }
1710 gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl)
1711 {
1712 gate_ui_gtk_dispatcher_t* disp;
1713 if (ctrl == NULL)
1714 {
1715 return GATE_RESULT_NULLPOINTER;
1716 }
1717 disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl);
1718 if ((disp == NULL) || (disp->refresh == NULL))
1719 {
1720 return gate_ui_gtk_ctrl_refresh(ctrl);
1721 }
1722 return disp->refresh(ctrl);
1723 }
1724
1725 gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate)
1726 {
1727 return gate_ui_gtk_ctrl_set_enabled(ctrl, enabledstate);
1728 }
1729 gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility)
1730 {
1731 return gate_ui_gtk_ctrl_set_visible(ctrl, visibility);
1732 }
1733 gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl)
1734 {
1735 return gate_ui_gtk_ctrl_set_focus(ctrl);
1736 }
1737 gate_result_t gate_ui_ctrl_set_position(gate_ui_ctrl_t* ctrl, gate_ui_point_t const* position, gate_ui_size_t const* size)
1738 {
1739 return gate_ui_gtk_ctrl_set_position(ctrl, position, size);
1740 }
1741
1742 #endif /*GATE_UI_GTK*/
1743
1744
1745
1746 #if defined(GATE_UI_MOTIF)
1747
1748 #include "gate/ui/gateui_motif.h"
1749 #include "gate/memalloc.h"
1750 #include "gate/debugging.h"
1751
1752 static char gate_ui_motif_app_class[] = "GATE_UI_MOTIF_APP_CLASS";
1753 static char gate_ui_motif_app_name[] = "GATE_UI_MOTIF_APP_NAME";
1754 static char empty_str[] = "";
1755
1756 1 gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam)
1757 {
1758 1 gate_result_t ret = GATE_RESULT_FAILED;
1759 1 XtAppContext app = NULL;
1760 1 Display* disp = NULL;
1761 1 Widget root = NULL;
1762 1 char* display_name = NULL;
1763 1 char default_display_name[] = ":0";
1764 1 char* app_name = gate_ui_motif_app_name;
1765 1 char* app_class = gate_ui_motif_app_class;
1766 1 int argc = 0;
1767 1 char* argv[] = { empty_str };
1768
1769 do
1770 {
1771 1 gate_mem_clear(host, sizeof(gate_ui_host_t));
1772 1 XtToolkitInitialize();
1773 1 app = XtCreateApplicationContext();
1774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!app)
1775 {
1776 ✗ GATE_DEBUG_TRACE("XtCreateApplicationContext() failed");
1777 ✗ ret = GATE_RESULT_OUTOFMEMORY;
1778 ✗ break;
1779 }
1780 1 disp = XtOpenDisplay(app, NULL, app_name, app_class, NULL, 0, &argc, argv);
1781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!disp)
1782 {
1783 ✗ GATE_DEBUG_TRACE("XtOpenDisplay(NULL) failed");
1784 ✗ disp = XtOpenDisplay(app, default_display_name, app_name, app_class, NULL, 0, &argc, argv);
1785 }
1786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!disp)
1787 {
1788 ✗ GATE_DEBUG_TRACE("XtOpenDisplay(...) failed");
1789 ✗ ret = GATE_RESULT_OUTOFMEMORY;
1790 ✗ break;
1791 }
1792
1793 1 GATE_UI_MOTIF_SET_HOST_APPHANDLE(host, app);
1794 1 GATE_UI_MOTIF_SET_HOST_DISPLAY(host, disp);
1795 1 GATE_UI_MOTIF_SET_HOST_USER_PARAM(host, userparam);
1796 1 GATE_UI_MOTIF_SET_HOST_ROOT(host, root);
1797
1798 1 ret = GATE_RESULT_OK;
1799 } while (0);
1800
1801 1 return ret;
1802 }
1803 1 gate_result_t gate_ui_host_uninit(gate_ui_host_t* host)
1804 {
1805 1 XtAppContext ctx = (XtAppContext)GATE_UI_MOTIF_GET_HOST_APPHANDLE(host);
1806 1 Display* disp = GATE_UI_MOTIF_GET_HOST_DISPLAY(host);
1807 1 gate_ui_motif_host_dispatch_pending_events(host, true);
1808
1809 1 XtCloseDisplay(disp);
1810 1 XtDestroyApplicationContext(ctx);
1811 1 gate_mem_clear(host, sizeof(gate_ui_host_t));
1812 1 return GATE_RESULT_OK;
1813 }
1814 1 gate_result_t gate_ui_host_run(gate_ui_host_t* host)
1815 {
1816 1 return gate_ui_motif_host_dispatch_events(host);
1817 }
1818
1819 284368 static Boolean motif_host_quit_worker(XtPointer param)
1820 {
1821 284368 XtAppContext ctx = (XtAppContext)param;
1822
1/2
✓ Branch 0 taken 284368 times.
✗ Branch 1 not taken.
284368 if (ctx)
1823 {
1824 284368 XtAppSetExitFlag(ctx);
1825 }
1826 284368 return FALSE; /* do not call this worker again */
1827 }
1828
1829 1 gate_result_t gate_ui_host_quit(gate_ui_host_t* host)
1830 {
1831 1 XtAppContext ctx = (XtAppContext)GATE_UI_MOTIF_GET_HOST_APPHANDLE(host);
1832 1 return gate_ui_motif_host_add_native_workproc(host, &motif_host_quit_worker, ctx);
1833 }
1834 1 void* gate_ui_host_get_userparam(gate_ui_host_t* host)
1835 {
1836 1 return GATE_UI_MOTIF_GET_HOST_USER_PARAM(host);
1837 }
1838 ✗ gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host)
1839 {
1840 ✗ return GATE_UI_MOTIF_GET_HOST_APPHANDLE(host);
1841 }
1842 11 gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host)
1843 {
1844 11 gate_real32_t default_font_size_pt = 10.0f;
1845 11 return (gate_uint32_t)gate_ui_host_get_pixels_in_points(host, default_font_size_pt);
1846 }
1847 10 gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count)
1848 {
1849 10 gate_uint32_t line_height = gate_ui_host_default_line_height(host);
1850 10 return line_height * line_count + (line_height + 5);
1851 }
1852 ✗ gate_result_t gate_ui_host_enum_fonts(gate_ui_host_t* host, gate_ui_enum_fontnames_callback_t callback, void* userparam)
1853 {
1854 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1855 }
1856 2 gate_result_t gate_ui_host_default_font(gate_ui_host_t* host, gate_uint32_t fonttype, gate_ui_font_t* font)
1857 {
1858 //gate_ui_host_enum_fonts(host, &gate_ui_enum_fontnames_callback_test, NULL);
1859 2 gate_str_print_text(font->font_name, sizeof(font->font_name), "fixed", 5);
1860 2 font->size = 12;
1861 2 font->orientation = 0;
1862 2 font->bold = false;
1863 2 font->italic = false;
1864 2 font->underline = false;
1865 2 font->strikeout = false;
1866
1867 2 return GATE_RESULT_OK;
1868 }
1869
1870 13 static gate_int32_t gate_ui_host_get_default_dpi()
1871 {
1872 13 return 96;
1873 }
1874 12 gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points)
1875 {
1876 12 gate_int32_t dpi = gate_ui_host_get_default_dpi();
1877 (void)host;
1878 12 return (gate_int32_t)((points * (gate_real32_t)dpi / 72.0f) + 0.5f);
1879 }
1880 1 gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels)
1881 {
1882 1 gate_int32_t dpi = gate_ui_host_get_default_dpi();
1883 1 gate_int32_t tmp = (gate_int32_t)((pixels * 72.0f / (gate_real32_t)dpi) + 0.5f);
1884 (void)host;
1885 1 return (gate_real32_t)tmp;
1886 }
1887 ✗ gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col)
1888 {
1889 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1890 }
1891 ✗ gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text)
1892 {
1893 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1894 }
1895 ✗ gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text)
1896 {
1897 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1898 }
1899 ✗ gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1900 {
1901 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1902 }
1903 ✗ gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
1904 {
1905 ✗ return GATE_RESULT_NOTIMPLEMENTED;
1906 }
1907 1 gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code)
1908 {
1909 1 return gate_ui_motif_host_add_workproc(host, code);
1910 }
1911 1 gate_result_t gate_ui_host_process_events(gate_ui_host_t* host)
1912 {
1913 1 return gate_ui_motif_host_dispatch_pending_events(host, false);
1914 }
1915
1916
1917
1918 20 void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl)
1919 {
1920 20 return GATE_UI_MOTIF_GET_CTRL_USER_PARAM(ctrl);
1921 }
1922
1923 6 gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl)
1924 {
1925 6 return GATE_UI_MOTIF_GET_CTRL_HOST(ctrl);
1926 }
1927
1928 ✗ gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl)
1929 {
1930 ✗ return GATE_UI_MOTIF_GET_CTRL_PARENT(ctrl);
1931 }
1932
1933 24 gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl)
1934 {
1935 24 return gate_ui_motif_ctrl_destroy(ctrl);
1936 }
1937
1938 311 gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl)
1939 {
1940 311 Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
1941 311 return w != NULL;
1942 }
1943
1944 3 gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl)
1945 {
1946 3 Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
1947 3 return XtIsSensitive(w) ? true : false;
1948 }
1949
1950 3 gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl)
1951 {
1952 3 Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
1953 3 return XtIsRealized(w) ? true : false;
1954 }
1955
1956 3 gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl)
1957 {
1958 3 return false;
1959 }
1960
1961 4 gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position)
1962 {
1963 gate_result_t ret;
1964 Dimension x, y, width, height;
1965 Widget w;
1966 do
1967 {
1968
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (!ctrl || !position)
1969 {
1970 ✗ ret = GATE_RESULT_INVALIDARG;
1971 ✗ break;
1972 }
1973
1974 4 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
1975 4 ret = gate_ui_motif_widget_get_position(w, &position->pos, &position->size);
1976 } while (0);
1977
1978 4 return ret;
1979 }
1980
1981 12 gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size)
1982 {
1983 gate_result_t ret;
1984 Dimension width, height;
1985 Widget w;
1986 do
1987 {
1988
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (!ctrl || !size)
1989 {
1990 ✗ ret = GATE_RESULT_INVALIDARG;
1991 ✗ break;
1992 }
1993
1994 12 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
1995 12 ret = gate_ui_motif_widget_get_position(w, NULL, size);
1996 } while (0);
1997 12 return ret;
1998 }
1999
2000 42 gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children)
2001 {
2002 42 gate_result_t ret = GATE_RESULT_FAILED;
2003 42 Widget child = NULL;
2004 42 WidgetList list = NULL;
2005 42 gate_size_t list_count = 0;
2006 gate_size_t ndx;
2007 42 gate_ui_ctrl_t* ptr_ctrl = NULL;
2008 42 gate_arraylist_t arr = GATE_INIT_EMPTY;
2009
2010 do
2011 {
2012 42 arr = gate_arraylist_create(sizeof(gate_ui_ctrl_t*), NULL, 0, NULL, NULL);
2013
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
42 if (gate_arraylist_is_null(arr))
2014 {
2015 ✗ ret = GATE_RESULT_OUTOFMEMORY;
2016 ✗ break;
2017 }
2018
2019 42 ret = gate_ui_motif_ctrl_get_children(ctrl, (void**)&list, &list_count);
2020
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 20 times.
42 GATE_BREAK_IF_FAILED(ret);
2021
2022
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 20 times.
49 for (ndx = 0; ndx != list_count; ++ndx)
2023 {
2024 29 child = list[ndx];
2025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 if (!child)
2026 {
2027 ✗ continue;
2028 }
2029 29 ptr_ctrl = gate_ui_motif_widget_get_ctrl(child);
2030
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 21 times.
29 if (!ptr_ctrl)
2031 {
2032 8 continue;
2033 }
2034 21 gate_arraylist_add(arr, &ptr_ctrl);
2035 }
2036
2037
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (NULL == gate_array_create(children, arr))
2038 {
2039 ✗ ret = GATE_RESULT_OUTOFMEMORY;
2040 ✗ break;
2041 }
2042 20 ret = GATE_RESULT_OK;
2043 } while (0);
2044
2045 42 gate_arraylist_release(&arr);
2046 42 return ret;
2047 }
2048
2049 6 gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text)
2050 {
2051 6 return gate_ui_motif_ctrl_get_text(ctrl, text);
2052 }
2053
2054 1 gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length)
2055 {
2056 1 gate_string_t text = GATE_STRING_INIT_EMPTY;
2057 1 gate_result_t ret = gate_ui_ctrl_get_text(ctrl, &text);
2058
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (GATE_SUCCEEDED(ret) && length)
2059 {
2060 1 *length = (gate_uint32_t)gate_string_length(&text);
2061 1 gate_string_release(&text);
2062 }
2063 1 return ret;
2064 }
2065
2066 2 gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* ptr_state)
2067 {
2068 2 gate_ui_motif_dispatcher_t* ptr_disp = NULL;
2069 2 Widget w = NULL;
2070
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (!ctrl || !ptr_state)
2071 {
2072 ✗ return GATE_RESULT_INVALIDARG;
2073 }
2074 2 ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl);
2075
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (ptr_disp && ptr_disp->get_state)
2076 {
2077 2 return ptr_disp->get_state(ctrl, ptr_state);
2078 }
2079 ✗ return GATE_RESULT_NOTSUPPORTED;
2080 }
2081
2082 3 gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate)
2083 {
2084 Widget w;
2085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!ctrl)
2086 {
2087 ✗ return GATE_RESULT_INVALIDARG;
2088 }
2089 3 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
2090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!w)
2091 {
2092 ✗ return GATE_RESULT_INVALIDSTATE;
2093 }
2094 3 XtSetSensitive(w, enabledstate);
2095 3 return GATE_RESULT_OK;
2096 }
2097 4 gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility)
2098 {
2099 Widget w;
2100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!ctrl)
2101 {
2102 ✗ return GATE_RESULT_INVALIDARG;
2103 }
2104 4 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
2105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!w)
2106 {
2107 ✗ return GATE_RESULT_INVALIDSTATE;
2108 }
2109
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (visibility)
2110 {
2111 4 gate_ui_host_t* host = gate_ui_ctrl_get_host(ctrl);
2112 4 XtMapWidget(w);
2113 4 gate_ui_motif_host_dispatch_pending_events(host, false);
2114 4 return gate_ui_ctrl_refresh(ctrl);
2115 }
2116 else
2117 {
2118 ✗ XtUnmapWidget(w);
2119 ✗ return GATE_RESULT_OK;
2120 }
2121 }
2122 2 gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl)
2123 {
2124 Widget w;
2125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!ctrl)
2126 {
2127 ✗ return GATE_RESULT_INVALIDARG;
2128 }
2129 2 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
2130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!w)
2131 {
2132 ✗ return GATE_RESULT_INVALIDSTATE;
2133 }
2134 2 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
2135 2 return GATE_RESULT_OK;
2136 }
2137 40 gate_result_t gate_ui_ctrl_set_position(gate_ui_ctrl_t* ctrl, gate_ui_point_t const* position, gate_ui_size_t const* size)
2138 {
2139 Widget w;
2140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!ctrl)
2141 {
2142 ✗ return GATE_RESULT_INVALIDARG;
2143 }
2144 40 w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl);
2145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!w)
2146 {
2147 ✗ return GATE_RESULT_INVALIDSTATE;
2148 }
2149 40 return gate_ui_motif_widget_set_position(w, position, size);
2150 }
2151 7 gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text)
2152 {
2153 7 return gate_ui_motif_ctrl_set_text(ctrl, text);
2154 }
2155 2 gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state)
2156 {
2157 2 gate_ui_motif_dispatcher_t* ptr_disp = NULL;
2158 2 Widget w = NULL;
2159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!ctrl)
2160 {
2161 ✗ return GATE_RESULT_INVALIDARG;
2162 }
2163 2 ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl);
2164
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (ptr_disp && ptr_disp->set_state)
2165 {
2166 2 return ptr_disp->set_state(ctrl, state);
2167 }
2168 ✗ return GATE_RESULT_NOTSUPPORTED;
2169 }
2170 41 gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl)
2171 {
2172 41 gate_ui_motif_dispatcher_t* disp = NULL;
2173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (!ctrl)
2174 {
2175 ✗ return GATE_RESULT_INVALIDARG;
2176 }
2177 41 disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl);
2178
4/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 17 times.
41 if (disp && disp->refresh)
2179 {
2180 4 return disp->refresh(ctrl);
2181 }
2182 else
2183 {
2184 37 return gate_ui_motif_ctrl_refresh(ctrl);
2185 }
2186 }
2187
2188
2189 #endif /* GATE_UI_MOTIF */
2190
2191
2192
2193 #if defined(GATE_UI_WASMHTML)
2194
2195 #include "gate/ui/gateui_wasmhtml.h"
2196
2197
2198 gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam)
2199 {
2200 return gate_ui_wasm_host_init(host, apphandle, userparam);
2201 }
2202 gate_result_t gate_ui_host_uninit(gate_ui_host_t* host)
2203 {
2204 return gate_ui_wasm_host_uninit(host);
2205 }
2206 gate_result_t gate_ui_host_run(gate_ui_host_t* host)
2207 {
2208 gate_result_t ret = GATE_RESULT_OK;
2209 return ret;
2210 }
2211 gate_result_t gate_ui_host_quit(gate_ui_host_t* host)
2212 {
2213 gate_result_t ret = GATE_RESULT_OK;
2214 return ret;
2215 }
2216 void* gate_ui_host_get_userparam(gate_ui_host_t* host)
2217 {
2218 return GATE_UI_WASM_GET_HOST_USER_PARAM(host);
2219 }
2220 gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host)
2221 {
2222 return GATE_UI_WASM_GET_HOST_APPHANDLE(host);
2223 }
2224 gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host)
2225 {
2226 return GATE_UI_WASM_GET_HOST_LINEHEIGHT(host);
2227 }
2228 gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count)
2229 {
2230 const gate_uint32_t line_height = GATE_UI_WASM_GET_HOST_LINEHEIGHT(host);
2231 gate_uint32_t height = line_height * 14 / 8;
2232 if (line_count > 1)
2233 {
2234 height += (line_count - 1) * line_height;
2235 }
2236 ++height;
2237 return height;
2238 }
2239
2240 static gate_int32_t gate_ui_host_get_default_dpi()
2241 {
2242 return 96;
2243 }
2244
2245 gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points)
2246 {
2247 gate_int32_t dpi = gate_ui_host_get_default_dpi();
2248 (void)host;
2249 return (gate_int32_t)((points * (gate_real32_t)dpi / 72.0f) + 0.5f);
2250 }
2251 gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels)
2252 {
2253 gate_int32_t dpi = gate_ui_host_get_default_dpi();
2254 gate_int32_t tmp = (gate_int32_t)((pixels * 72.0f / (gate_real32_t)dpi) + 0.5f);
2255 (void)host;
2256 return (gate_real32_t)tmp;
2257 }
2258 gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col)
2259 {
2260 return GATE_RESULT_NOTIMPLEMENTED;
2261 }
2262 gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text)
2263 {
2264 return GATE_RESULT_NOTIMPLEMENTED;
2265 }
2266 gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text)
2267 {
2268 return GATE_RESULT_NOTIMPLEMENTED;
2269 }
2270 gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
2271 {
2272 return GATE_RESULT_NOTIMPLEMENTED;
2273 }
2274 gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area)
2275 {
2276 return GATE_RESULT_NOTIMPLEMENTED;
2277 }
2278 gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code)
2279 {
2280 return GATE_RESULT_NOTIMPLEMENTED;
2281 }
2282 gate_result_t gate_ui_host_process_events(gate_ui_host_t* host)
2283 {
2284 return GATE_RESULT_NOTIMPLEMENTED;
2285 }
2286
2287
2288
2289 void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl)
2290 {
2291 return GATE_UI_WASM_GET_CTRL_USER_PARAM(ctrl);
2292 }
2293
2294 gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl)
2295 {
2296 return GATE_UI_WASM_GET_CTRL_HOST(ctrl);
2297 }
2298
2299 gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl)
2300 {
2301 return NULL;
2302 }
2303
2304 gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl)
2305 {
2306 return GATE_RESULT_NOTIMPLEMENTED;
2307 }
2308
2309 gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl)
2310 {
2311 return false;
2312 }
2313
2314 gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl)
2315 {
2316 return false;
2317 }
2318
2319 gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl)
2320 {
2321 return false;
2322 }
2323
2324 gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl)
2325 {
2326 return false;
2327 }
2328
2329 gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position)
2330 {
2331 return GATE_RESULT_NOTIMPLEMENTED;
2332 }
2333
2334 gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size)
2335 {
2336 return GATE_RESULT_NOTIMPLEMENTED;
2337 }
2338
2339 gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children)
2340 {
2341 return GATE_RESULT_NOTIMPLEMENTED;
2342 }
2343
2344 gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text)
2345 {
2346 return GATE_RESULT_NOTIMPLEMENTED;
2347 }
2348
2349 gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length)
2350 {
2351 return GATE_RESULT_NOTIMPLEMENTED;
2352 }
2353
2354 gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* ptr_state)
2355 {
2356 return GATE_RESULT_NOTIMPLEMENTED;
2357 }
2358
2359 gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate)
2360 {
2361 return GATE_RESULT_NOTIMPLEMENTED;
2362 }
2363 gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility)
2364 {
2365 return GATE_RESULT_NOTIMPLEMENTED;
2366 }
2367 gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl)
2368 {
2369 return GATE_RESULT_NOTIMPLEMENTED;
2370 }
2371 gate_result_t gate_ui_ctrl_set_position(gate_ui_ctrl_t* ctrl, gate_ui_point_t const* position, gate_ui_size_t const* size)
2372 {
2373 return GATE_RESULT_NOTIMPLEMENTED;
2374 }
2375 gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text)
2376 {
2377 return GATE_RESULT_NOTIMPLEMENTED;
2378 }
2379 gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state)
2380 {
2381 return GATE_RESULT_NOTIMPLEMENTED;
2382 }
2383
2384 gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl)
2385 {
2386 return GATE_RESULT_NOTIMPLEMENTED;
2387 }
2388
2389
2390 #endif
2391