GCC Code Coverage Report


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