| 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 | 18 | gate_result_t gate_ui_ctrl_init(gate_ui_ctrl_t* ctrl) | |
| 38 | { | ||
| 39 | 18 | gate_mem_clear(ctrl, sizeof(gate_ui_ctrl_t)); | |
| 40 | 18 | return GATE_RESULT_OK; | |
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | 8 | gate_result_t gate_ui_layout_create(gate_ui_layout_t* layout) | |
| 45 | { | ||
| 46 | 8 | layout->border = 0; | |
| 47 | 8 | layout->colspace = 0; | |
| 48 | 8 | layout->rowspace = 0; | |
| 49 | 8 | 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 8 times.
|
8 | if (layout->columns == NULL) |
| 51 | { | ||
| 52 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 53 | } | ||
| 54 | 8 | 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 8 times.
|
8 | if (layout->rows == NULL) |
| 56 | { | ||
| 57 | ✗ | gate_arraylist_release(layout->columns); | |
| 58 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 59 | } | ||
| 60 | 8 | layout->cells = gate_arraylist_create(sizeof(gate_arraylist_t), NULL, 0, NULL, NULL); | |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (layout->cells == NULL) |
| 62 | { | ||
| 63 | ✗ | gate_arraylist_release(layout->rows); | |
| 64 | ✗ | gate_arraylist_release(layout->columns); | |
| 65 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 66 | } | ||
| 67 | 8 | return GATE_RESULT_OK; | |
| 68 | } | ||
| 69 | |||
| 70 | 8 | gate_result_t gate_ui_layout_destroy(gate_ui_layout_t* layout) | |
| 71 | { | ||
| 72 | 8 | gate_size_t maxrows = gate_arraylist_length(layout->cells); | |
| 73 | gate_size_t ndx; | ||
| 74 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 8 times.
|
19 | for (ndx = 0; ndx < maxrows; ++ndx) |
| 75 | { | ||
| 76 | 11 | gate_arraylist_t* collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, ndx); | |
| 77 | 11 | gate_arraylist_release(*collist); | |
| 78 | } | ||
| 79 | 8 | gate_arraylist_release(layout->cells); | |
| 80 | 8 | gate_arraylist_release(layout->rows); | |
| 81 | 8 | gate_arraylist_release(layout->columns); | |
| 82 | 8 | return GATE_RESULT_NOTIMPLEMENTED; | |
| 83 | } | ||
| 84 | |||
| 85 | 4 | gate_result_t gate_ui_layout_clear(gate_ui_layout_t* layout) | |
| 86 | { | ||
| 87 | 4 | gate_ui_layout_destroy(layout); | |
| 88 | 4 | 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 | 7 | 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 | 7 | def.type = type; | |
| 98 | 7 | def.value = value; | |
| 99 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | if (NULL == gate_arraylist_add(layout->columns, &def)) |
| 100 | { | ||
| 101 | ✗ | ret = GATE_RESULT_FAILED; | |
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | 7 | ret = GATE_RESULT_OK; | |
| 106 | } | ||
| 107 | 7 | return ret; | |
| 108 | } | ||
| 109 | |||
| 110 | 12 | 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 | 12 | def.type = type; | |
| 115 | 12 | def.value = value; | |
| 116 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if (NULL == gate_arraylist_add(layout->rows, &def)) |
| 117 | { | ||
| 118 | ✗ | ret = GATE_RESULT_FAILED; | |
| 119 | } | ||
| 120 | else | ||
| 121 | { | ||
| 122 | 12 | ret = GATE_RESULT_OK; | |
| 123 | } | ||
| 124 | 12 | return ret; | |
| 125 | } | ||
| 126 | |||
| 127 | 12 | gate_uint32_t gate_ui_layout_get_rows(gate_ui_layout_t* layout) | |
| 128 | { | ||
| 129 | 12 | gate_uint32_t ret = 0; | |
| 130 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (layout->rows != NULL) |
| 131 | { | ||
| 132 | 12 | ret = (gate_uint32_t)gate_arraylist_length(layout->rows); | |
| 133 | } | ||
| 134 | 12 | return ret; | |
| 135 | } | ||
| 136 | 7 | gate_uint32_t gate_ui_layout_get_columns(gate_ui_layout_t* layout) | |
| 137 | { | ||
| 138 | 7 | gate_uint32_t ret = 0; | |
| 139 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (layout->rows != NULL) |
| 140 | { | ||
| 141 | 7 | ret = (gate_uint32_t)gate_arraylist_length(layout->columns); | |
| 142 | } | ||
| 143 | 7 | return ret; | |
| 144 | } | ||
| 145 | |||
| 146 | ✗ | 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 | ✗ | gate_ui_layout_def_t* def = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, row); | |
| 149 | ✗ | if (NULL == def) | |
| 150 | { | ||
| 151 | ✗ | return GATE_RESULT_NOMATCH; | |
| 152 | } | ||
| 153 | else | ||
| 154 | { | ||
| 155 | ✗ | def->type = type; | |
| 156 | ✗ | def->value = value; | |
| 157 | ✗ | return GATE_RESULT_OK; | |
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | ✗ | 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 | ✗ | gate_ui_layout_def_t* def = (gate_ui_layout_def_t*)gate_arraylist_get(layout->columns, col); | |
| 164 | ✗ | if (NULL == def) | |
| 165 | { | ||
| 166 | ✗ | return GATE_RESULT_NOMATCH; | |
| 167 | } | ||
| 168 | else | ||
| 169 | { | ||
| 170 | ✗ | def->type = type; | |
| 171 | ✗ | def->value = value; | |
| 172 | ✗ | return GATE_RESULT_OK; | |
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | 13 | 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 | 13 | rowcount = gate_arraylist_length(layout->cells); | |
| 188 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 13 times.
|
24 | for (; rowcount <= row; ++rowcount) |
| 189 | { | ||
| 190 | 11 | newlist = gate_arraylist_create(sizeof(gate_ui_layout_empty_cell), NULL, 0, NULL, NULL); | |
| 191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (newlist == NULL) |
| 192 | { | ||
| 193 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 194 | } | ||
| 195 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if (NULL == gate_arraylist_add(layout->cells, &newlist)) |
| 196 | { | ||
| 197 | ✗ | gate_arraylist_release(newlist); | |
| 198 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 199 | } | ||
| 200 | } | ||
| 201 | 13 | collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row); | |
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (collist == NULL) |
| 203 | { | ||
| 204 | ✗ | return GATE_RESULT_FAILED; | |
| 205 | } | ||
| 206 | 13 | colcount = gate_arraylist_length(*collist); | |
| 207 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 13 times.
|
27 | for (; colcount <= col; ++colcount) |
| 208 | { | ||
| 209 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
|
14 | if (NULL == gate_arraylist_add(*collist, &gate_ui_layout_empty_cell)) |
| 210 | { | ||
| 211 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 212 | } | ||
| 213 | } | ||
| 214 | 13 | cell = (gate_ui_layout_cell_t*)gate_arraylist_get(*collist, col); | |
| 215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (cell == NULL) |
| 216 | { | ||
| 217 | ✗ | return GATE_RESULT_FAILED; | |
| 218 | } | ||
| 219 | 13 | cell->ctrl = ctrl; | |
| 220 | 13 | cell->rowspan = rowspan; | |
| 221 | 13 | cell->colspan = colspan; | |
| 222 | |||
| 223 | 13 | return GATE_RESULT_OK; | |
| 224 | } | ||
| 225 | |||
| 226 | ✗ | 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 | ✗ | gate_size_t const rowcount = gate_arraylist_length(layout->cells); | |
| 231 | gate_size_t row; | ||
| 232 | |||
| 233 | ✗ | for (row = 0; row != rowcount; ++row) | |
| 234 | { | ||
| 235 | ✗ | gate_arraylist_t* const collist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row); | |
| 236 | ✗ | gate_size_t const colcount = gate_arraylist_length(*collist); | |
| 237 | gate_size_t col; | ||
| 238 | ✗ | for (col = 0; col != colcount; ++col) | |
| 239 | { | ||
| 240 | ✗ | gate_ui_layout_cell_t* const cell = (gate_ui_layout_cell_t*)gate_arraylist_get(*collist, col); | |
| 241 | ✗ | if (ctrl == cell->ctrl) | |
| 242 | { | ||
| 243 | ✗ | if (ptr_row) *ptr_row = row; | |
| 244 | ✗ | if (ptr_col) *ptr_col = col; | |
| 245 | ✗ | if (ptr_rowspan) *ptr_rowspan = cell->rowspan; | |
| 246 | ✗ | if (ptr_colspan) *ptr_colspan = cell->colspan; | |
| 247 | ✗ | return GATE_RESULT_OK; | |
| 248 | } | ||
| 249 | } | ||
| 250 | } | ||
| 251 | ✗ | return GATE_RESULT_NOMATCH; | |
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | 10 | 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 9 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
10 | if (!layout || !pose) |
| 276 | { | ||
| 277 | 1 | return GATE_RESULT_INVALIDDATA; | |
| 278 | } | ||
| 279 | |||
| 280 | 9 | rowcount = gate_arraylist_length(layout->rows); | |
| 281 | 9 | colcount = gate_arraylist_length(layout->columns); | |
| 282 | |||
| 283 | 9 | width = pose->size.width - layout->border * 2; | |
| 284 | 9 | height = pose->size.height - layout->border * 2; | |
| 285 | |||
| 286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (rowcount > sizeof(rowheights) / sizeof(rowheights[0])) rowcount = sizeof(rowheights) / sizeof(rowheights[0]); |
| 287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (colcount > sizeof(colwidths) / sizeof(colwidths[0])) colcount = sizeof(colwidths) / sizeof(colwidths[0]); |
| 288 | |||
| 289 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (colcount > 0) width -= (gate_int32_t)(colcount) * (gate_int32_t)layout->colspace; |
| 290 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (rowcount > 0) height -= (gate_int32_t)(rowcount) * (gate_int32_t)layout->rowspace; |
| 291 | 9 | remainwidth = width; | |
| 292 | 9 | remainheight = height; | |
| 293 | |||
| 294 | |||
| 295 | /* calculating cell widths */ | ||
| 296 | 9 | autocnt = 0; | |
| 297 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | for (ndx = 0; ndx != colcount; ++ndx) |
| 298 | { | ||
| 299 | 18 | 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 12 times.
|
18 | 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 | 12 | default: | |
| 306 | 12 | case GATE_UI_LAYOUT_TYPE_AUTO: colwidths[ndx] = 0; ++autocnt; break; | |
| 307 | } | ||
| 308 | 18 | remainwidth -= colwidths[ndx]; | |
| 309 | } | ||
| 310 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (autocnt > 0) |
| 311 | { | ||
| 312 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | for (ndx = 0; ndx != colcount; ++ndx) |
| 313 | { | ||
| 314 | 18 | currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->columns, ndx); | |
| 315 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
|
18 | 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 | 12 | default: | |
| 322 | case GATE_UI_LAYOUT_TYPE_AUTO: | ||
| 323 | 12 | colwidths[ndx] = remainwidth / (gate_int32_t)autocnt; | |
| 324 | 12 | break; | |
| 325 | } | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | /* calculating cell heights */ | ||
| 330 | 9 | autocnt = 0; | |
| 331 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 9 times.
|
37 | for (ndx = 0; ndx != rowcount; ++ndx) |
| 332 | { | ||
| 333 | 28 | currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, ndx); | |
| 334 |
2/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 7 times.
|
28 | switch (currentdef->type) |
| 335 | { | ||
| 336 | ✗ | 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 | 21 | case GATE_UI_LAYOUT_TYPE_UNITSCALE: rowheights[ndx] = (gate_int32_t)((gate_real32_t)unitLength * currentdef->value); break; | |
| 339 | 7 | default: | |
| 340 | 7 | case GATE_UI_LAYOUT_TYPE_AUTO: rowheights[ndx] = 0; ++autocnt; break; | |
| 341 | } | ||
| 342 | 28 | remainheight -= rowheights[ndx]; | |
| 343 | } | ||
| 344 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | if (autocnt > 0) |
| 345 | { | ||
| 346 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
|
17 | for (ndx = 0; ndx != rowcount; ++ndx) |
| 347 | { | ||
| 348 | 13 | currentdef = (gate_ui_layout_def_t*)gate_arraylist_get(layout->rows, ndx); | |
| 349 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 7 times.
|
13 | 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 | 7 | default: | |
| 356 | case GATE_UI_LAYOUT_TYPE_AUTO: | ||
| 357 | 7 | rowheights[ndx] = remainheight / (gate_int32_t)autocnt; | |
| 358 | 7 | break; | |
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | /**/ | ||
| 364 | 9 | y = pose->pos.y + layout->border + layout->rowspace / 2; | |
| 365 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
|
35 | for (row = 0; row < rowcount; ++row) |
| 366 | { | ||
| 367 | gate_arraylist_t* currentcollist; | ||
| 368 | 28 | h = rowheights[row]; | |
| 369 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 26 times.
|
28 | if (row >= gate_arraylist_length(layout->cells)) |
| 370 | { | ||
| 371 | /* there are no further rows with column cells, so we can cancel further processing */ | ||
| 372 | 2 | break; | |
| 373 | } | ||
| 374 | 26 | currentcollist = (gate_arraylist_t*)gate_arraylist_get(layout->cells, row); | |
| 375 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (currentcollist != NULL) |
| 376 | { | ||
| 377 | 26 | x = pose->pos.x + layout->border + layout->colspace / 2; | |
| 378 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 16 times.
|
63 | for (col = 0; col < colcount; ++col) |
| 379 | { | ||
| 380 | gate_ui_layout_cell_t* currentcell; | ||
| 381 | 47 | w = colwidths[col]; | |
| 382 | |||
| 383 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 37 times.
|
47 | 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 | 10 | break; | |
| 387 | } | ||
| 388 | 37 | currentcell = (gate_ui_layout_cell_t*)gate_arraylist_get(*currentcollist, col); | |
| 389 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | if (currentcell != NULL) |
| 390 | { | ||
| 391 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 3 times.
|
37 | if (currentcell->ctrl != NULL) |
| 392 | { | ||
| 393 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
34 | if (gate_ui_ctrl_is_created(currentcell->ctrl)) |
| 394 | { | ||
| 395 | 34 | ctrlpoint.x = x; | |
| 396 | 34 | ctrlpoint.y = y; | |
| 397 | 34 | ctrlsize.width = w; | |
| 398 | 34 | ctrlsize.height = h; | |
| 399 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 34 times.
|
46 | 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 34 times.
|
37 | 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 34 times.
|
34 | if (ctrlsize.width < 2) ctrlsize.width = 2; |
| 408 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 29 times.
|
34 | if (ctrlsize.height < 2) ctrlsize.height = 2; |
| 409 | 34 | gate_ui_ctrl_set_position(currentcell->ctrl, &ctrlpoint, &ctrlsize); | |
| 410 | 34 | gate_ui_ctrl_refresh(currentcell->ctrl); | |
| 411 | } | ||
| 412 | } | ||
| 413 | } | ||
| 414 | 37 | x += (w + layout->colspace); | |
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | 26 | y += (h + layout->rowspace); | |
| 419 | } | ||
| 420 | |||
| 421 | 9 | 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 | HWND hwndParent = GATE_UI_WINAPI_GET_HWND_PARENT(ctrl); | ||
| 528 | if ((host) && (hwndParent)) | ||
| 529 | { | ||
| 530 | ret = gate_ui_winapi_resolve_ctrl(host, (void*)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 = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 558 | if (!hwnd) | ||
| 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 | |||
| 1492 | |||
| 1493 | |||
| 1494 | |||
| 1495 | void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl) | ||
| 1496 | { | ||
| 1497 | if (ctrl != NULL) | ||
| 1498 | { | ||
| 1499 | return GATE_UI_GTK_GET_CTRL_USER_PARAM(ctrl); | ||
| 1500 | } | ||
| 1501 | return NULL; | ||
| 1502 | } | ||
| 1503 | gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl) | ||
| 1504 | { | ||
| 1505 | if (ctrl != NULL) | ||
| 1506 | { | ||
| 1507 | return GATE_UI_GTK_GET_CTRL_HOST(ctrl); | ||
| 1508 | } | ||
| 1509 | return NULL; | ||
| 1510 | } | ||
| 1511 | gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl) | ||
| 1512 | { | ||
| 1513 | if (ctrl != NULL) | ||
| 1514 | { | ||
| 1515 | |||
| 1516 | } | ||
| 1517 | return NULL; | ||
| 1518 | } | ||
| 1519 | |||
| 1520 | gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl) | ||
| 1521 | { | ||
| 1522 | gate_array_t children; | ||
| 1523 | gate_result_t ret; | ||
| 1524 | gate_size_t children_count; | ||
| 1525 | gate_ui_ctrl_t* const* ptr_child; | ||
| 1526 | |||
| 1527 | do | ||
| 1528 | { | ||
| 1529 | if (ctrl == NULL) | ||
| 1530 | { | ||
| 1531 | ret = GATE_RESULT_NULLPOINTER; | ||
| 1532 | break; | ||
| 1533 | } | ||
| 1534 | ret = gate_ui_ctrl_get_children(ctrl, &children); | ||
| 1535 | if (GATE_SUCCEEDED(ret)) | ||
| 1536 | { | ||
| 1537 | children_count = gate_array_length(&children); | ||
| 1538 | ptr_child = (gate_ui_ctrl_t* const*)gate_array_get(&children, 0); | ||
| 1539 | while (children_count-- != 0) | ||
| 1540 | { | ||
| 1541 | if (*ptr_child) | ||
| 1542 | { | ||
| 1543 | gate_ui_ctrl_destroy(*ptr_child); | ||
| 1544 | } | ||
| 1545 | ++ptr_child; | ||
| 1546 | } | ||
| 1547 | gate_array_release(&children); | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | ret = gate_ui_gtk_ctrl_destroy(ctrl); | ||
| 1551 | } while (0); | ||
| 1552 | return ret; | ||
| 1553 | } | ||
| 1554 | gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl) | ||
| 1555 | { | ||
| 1556 | gate_bool_t ret = false; | ||
| 1557 | if (ctrl != NULL) | ||
| 1558 | { | ||
| 1559 | ret = GATE_UI_GTK_GET_CTRL_WIDGET(ctrl) != NULL; | ||
| 1560 | } | ||
| 1561 | return ret; | ||
| 1562 | } | ||
| 1563 | gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl) | ||
| 1564 | { | ||
| 1565 | gate_bool_t ret = false; | ||
| 1566 | if (ctrl != NULL) | ||
| 1567 | { | ||
| 1568 | ret = gate_ui_gtk_ctrl_is_enabled(ctrl); | ||
| 1569 | } | ||
| 1570 | return ret; | ||
| 1571 | } | ||
| 1572 | gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl) | ||
| 1573 | { | ||
| 1574 | gate_bool_t ret = false; | ||
| 1575 | if (ctrl != NULL) | ||
| 1576 | { | ||
| 1577 | ret = gate_ui_gtk_ctrl_is_visible(ctrl); | ||
| 1578 | } | ||
| 1579 | return ret; | ||
| 1580 | } | ||
| 1581 | gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl) | ||
| 1582 | { | ||
| 1583 | gate_bool_t ret = false; | ||
| 1584 | if (ctrl != NULL) | ||
| 1585 | { | ||
| 1586 | ret = gate_ui_gtk_ctrl_has_focus(ctrl); | ||
| 1587 | } | ||
| 1588 | return ret; | ||
| 1589 | } | ||
| 1590 | gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position) | ||
| 1591 | { | ||
| 1592 | if (ctrl != NULL) | ||
| 1593 | { | ||
| 1594 | return gate_ui_gtk_ctrl_get_position(ctrl, position); | ||
| 1595 | } | ||
| 1596 | return GATE_RESULT_NULLPOINTER; | ||
| 1597 | } | ||
| 1598 | gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size) | ||
| 1599 | { | ||
| 1600 | if (ctrl != NULL) | ||
| 1601 | { | ||
| 1602 | return gate_ui_gtk_ctrl_get_size(ctrl, size); | ||
| 1603 | } | ||
| 1604 | return GATE_RESULT_NULLPOINTER; | ||
| 1605 | } | ||
| 1606 | gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children) | ||
| 1607 | { | ||
| 1608 | if ((ctrl == NULL) || (children == NULL)) | ||
| 1609 | { | ||
| 1610 | return GATE_RESULT_NULLPOINTER; | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | return gate_ui_gtk_ctrl_get_children(ctrl, children); | ||
| 1614 | } | ||
| 1615 | gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text) | ||
| 1616 | { | ||
| 1617 | gate_ui_gtk_dispatcher_t* disp; | ||
| 1618 | if (ctrl == NULL) | ||
| 1619 | { | ||
| 1620 | return GATE_RESULT_NULLPOINTER; | ||
| 1621 | } | ||
| 1622 | disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl); | ||
| 1623 | if ((disp == NULL) || (disp->get_text == NULL)) | ||
| 1624 | { | ||
| 1625 | return GATE_RESULT_NOTSUPPORTED; | ||
| 1626 | } | ||
| 1627 | return disp->get_text(ctrl, text); | ||
| 1628 | } | ||
| 1629 | gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length) | ||
| 1630 | { | ||
| 1631 | gate_ui_gtk_dispatcher_t* disp; | ||
| 1632 | gate_uint32_t l; | ||
| 1633 | if (ctrl == NULL) | ||
| 1634 | { | ||
| 1635 | return GATE_RESULT_NULLPOINTER; | ||
| 1636 | } | ||
| 1637 | disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl); | ||
| 1638 | if ((disp == NULL) || (disp->get_text_length == NULL)) | ||
| 1639 | { | ||
| 1640 | return GATE_RESULT_NOTSUPPORTED; | ||
| 1641 | } | ||
| 1642 | l = disp->get_text_length(ctrl); | ||
| 1643 | if (length != NULL) | ||
| 1644 | { | ||
| 1645 | *length = l; | ||
| 1646 | } | ||
| 1647 | return GATE_RESULT_OK; | ||
| 1648 | } | ||
| 1649 | gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text) | ||
| 1650 | { | ||
| 1651 | gate_ui_gtk_dispatcher_t* disp; | ||
| 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->set_text == NULL)) | ||
| 1658 | { | ||
| 1659 | return GATE_RESULT_NOTSUPPORTED; | ||
| 1660 | } | ||
| 1661 | return disp->set_text(ctrl, text); | ||
| 1662 | } | ||
| 1663 | gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* state) | ||
| 1664 | { | ||
| 1665 | gate_ui_gtk_dispatcher_t* disp; | ||
| 1666 | if (ctrl == NULL) | ||
| 1667 | { | ||
| 1668 | return GATE_RESULT_NULLPOINTER; | ||
| 1669 | } | ||
| 1670 | disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl); | ||
| 1671 | if ((disp == NULL) || (disp->get_state == NULL)) | ||
| 1672 | { | ||
| 1673 | return GATE_RESULT_NOTSUPPORTED; | ||
| 1674 | } | ||
| 1675 | return disp->get_state(ctrl, state); | ||
| 1676 | } | ||
| 1677 | gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state) | ||
| 1678 | { | ||
| 1679 | gate_ui_gtk_dispatcher_t* disp; | ||
| 1680 | if (ctrl == NULL) | ||
| 1681 | { | ||
| 1682 | return GATE_RESULT_NULLPOINTER; | ||
| 1683 | } | ||
| 1684 | disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl); | ||
| 1685 | if ((disp == NULL) || (disp->set_state == NULL)) | ||
| 1686 | { | ||
| 1687 | return GATE_RESULT_NOTSUPPORTED; | ||
| 1688 | } | ||
| 1689 | return disp->set_state(ctrl, state); | ||
| 1690 | } | ||
| 1691 | gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl) | ||
| 1692 | { | ||
| 1693 | gate_ui_gtk_dispatcher_t* disp; | ||
| 1694 | if (ctrl == NULL) | ||
| 1695 | { | ||
| 1696 | return GATE_RESULT_NULLPOINTER; | ||
| 1697 | } | ||
| 1698 | disp = GATE_UI_GTK_GET_CTRL_DISP(ctrl); | ||
| 1699 | if ((disp == NULL) || (disp->refresh == NULL)) | ||
| 1700 | { | ||
| 1701 | return gate_ui_gtk_ctrl_refresh(ctrl); | ||
| 1702 | } | ||
| 1703 | return disp->refresh(ctrl); | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | |||
| 1707 | gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate) | ||
| 1708 | { | ||
| 1709 | return gate_ui_gtk_ctrl_set_enabled(ctrl, enabledstate); | ||
| 1710 | } | ||
| 1711 | gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility) | ||
| 1712 | { | ||
| 1713 | return gate_ui_gtk_ctrl_set_visible(ctrl, visibility); | ||
| 1714 | } | ||
| 1715 | gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl) | ||
| 1716 | { | ||
| 1717 | return gate_ui_gtk_ctrl_set_focus(ctrl); | ||
| 1718 | } | ||
| 1719 | 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) | ||
| 1720 | { | ||
| 1721 | return gate_ui_gtk_ctrl_set_position(ctrl, position, size); | ||
| 1722 | } | ||
| 1723 | |||
| 1724 | #endif /*GATE_UI_GTK*/ | ||
| 1725 | |||
| 1726 | |||
| 1727 | |||
| 1728 | #if defined(GATE_UI_MOTIF) | ||
| 1729 | |||
| 1730 | #include "gate/ui/gateui_motif.h" | ||
| 1731 | #include "gate/memalloc.h" | ||
| 1732 | #include "gate/debugging.h" | ||
| 1733 | |||
| 1734 | static char gate_ui_motif_app_class[] = "GATE_UI_MOTIF_APP_CLASS"; | ||
| 1735 | static char gate_ui_motif_app_name[] = "GATE_UI_MOTIF_APP_NAME"; | ||
| 1736 | static char empty_str[] = ""; | ||
| 1737 | |||
| 1738 | 1 | gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam) | |
| 1739 | { | ||
| 1740 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 1741 | 1 | XtAppContext app = NULL; | |
| 1742 | 1 | Display* disp = NULL; | |
| 1743 | 1 | Widget root = NULL; | |
| 1744 | 1 | char* display_name = NULL; | |
| 1745 | 1 | char default_display_name[] = ":0"; | |
| 1746 | 1 | char* app_name = gate_ui_motif_app_name; | |
| 1747 | 1 | char* app_class = gate_ui_motif_app_class; | |
| 1748 | 1 | int argc = 0; | |
| 1749 | 1 | char* argv[] = { empty_str }; | |
| 1750 | |||
| 1751 | do | ||
| 1752 | { | ||
| 1753 | 1 | gate_mem_clear(host, sizeof(gate_ui_host_t)); | |
| 1754 | 1 | XtToolkitInitialize(); | |
| 1755 | 1 | app = XtCreateApplicationContext(); | |
| 1756 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!app) |
| 1757 | { | ||
| 1758 | ✗ | GATE_DEBUG_TRACE("XtCreateApplicationContext() failed"); | |
| 1759 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 1760 | ✗ | break; | |
| 1761 | } | ||
| 1762 | 1 | disp = XtOpenDisplay(app, NULL, app_name, app_class, NULL, 0, &argc, argv); | |
| 1763 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!disp) |
| 1764 | { | ||
| 1765 | ✗ | GATE_DEBUG_TRACE("XtOpenDisplay(NULL) failed"); | |
| 1766 | ✗ | disp = XtOpenDisplay(app, default_display_name, app_name, app_class, NULL, 0, &argc, argv); | |
| 1767 | } | ||
| 1768 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!disp) |
| 1769 | { | ||
| 1770 | ✗ | GATE_DEBUG_TRACE("XtOpenDisplay(...) failed"); | |
| 1771 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 1772 | ✗ | break; | |
| 1773 | } | ||
| 1774 | |||
| 1775 | 1 | GATE_UI_MOTIF_SET_HOST_APPHANDLE(host, app); | |
| 1776 | 1 | GATE_UI_MOTIF_SET_HOST_DISPLAY(host, disp); | |
| 1777 | 1 | GATE_UI_MOTIF_SET_HOST_USER_PARAM(host, userparam); | |
| 1778 | 1 | GATE_UI_MOTIF_SET_HOST_ROOT(host, root); | |
| 1779 | |||
| 1780 | 1 | ret = GATE_RESULT_OK; | |
| 1781 | } while (0); | ||
| 1782 | |||
| 1783 | 1 | return ret; | |
| 1784 | } | ||
| 1785 | 1 | gate_result_t gate_ui_host_uninit(gate_ui_host_t* host) | |
| 1786 | { | ||
| 1787 | 1 | XtAppContext ctx = (XtAppContext)GATE_UI_MOTIF_GET_HOST_APPHANDLE(host); | |
| 1788 | 1 | Display* disp = GATE_UI_MOTIF_GET_HOST_DISPLAY(host); | |
| 1789 | 1 | gate_ui_motif_host_dispatch_pending_events(host, true); | |
| 1790 | |||
| 1791 | 1 | XtCloseDisplay(disp); | |
| 1792 | 1 | XtDestroyApplicationContext(ctx); | |
| 1793 | 1 | gate_mem_clear(host, sizeof(gate_ui_host_t)); | |
| 1794 | 1 | return GATE_RESULT_OK; | |
| 1795 | } | ||
| 1796 | 1 | gate_result_t gate_ui_host_run(gate_ui_host_t* host) | |
| 1797 | { | ||
| 1798 | 1 | return gate_ui_motif_host_dispatch_events(host); | |
| 1799 | } | ||
| 1800 | |||
| 1801 | 298607 | static Boolean motif_host_quit_worker(XtPointer param) | |
| 1802 | { | ||
| 1803 | 298607 | XtAppContext ctx = (XtAppContext)param; | |
| 1804 |
1/2✓ Branch 0 taken 298607 times.
✗ Branch 1 not taken.
|
298607 | if (ctx) |
| 1805 | { | ||
| 1806 | 298607 | XtAppSetExitFlag(ctx); | |
| 1807 | } | ||
| 1808 | 298607 | return FALSE; /* do not call this worker again */ | |
| 1809 | } | ||
| 1810 | |||
| 1811 | 1 | gate_result_t gate_ui_host_quit(gate_ui_host_t* host) | |
| 1812 | { | ||
| 1813 | 1 | XtAppContext ctx = (XtAppContext)GATE_UI_MOTIF_GET_HOST_APPHANDLE(host); | |
| 1814 | 1 | return gate_ui_motif_host_add_native_workproc(host, &motif_host_quit_worker, ctx); | |
| 1815 | } | ||
| 1816 | 1 | void* gate_ui_host_get_userparam(gate_ui_host_t* host) | |
| 1817 | { | ||
| 1818 | 1 | return GATE_UI_MOTIF_GET_HOST_USER_PARAM(host); | |
| 1819 | } | ||
| 1820 | ✗ | gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host) | |
| 1821 | { | ||
| 1822 | ✗ | return GATE_UI_MOTIF_GET_HOST_APPHANDLE(host); | |
| 1823 | } | ||
| 1824 | 10 | gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host) | |
| 1825 | { | ||
| 1826 | 10 | gate_real32_t default_font_size_pt = 10.0f; | |
| 1827 | 10 | return (gate_uint32_t)gate_ui_host_get_pixels_in_points(host, default_font_size_pt); | |
| 1828 | } | ||
| 1829 | 9 | gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count) | |
| 1830 | { | ||
| 1831 | 9 | gate_uint32_t line_height = gate_ui_host_default_line_height(host); | |
| 1832 | 9 | return line_height * line_count + (line_height + 5); | |
| 1833 | } | ||
| 1834 | ✗ | gate_result_t gate_ui_host_enum_fonts(gate_ui_host_t* host, gate_ui_enum_fontnames_callback_t callback, void* userparam) | |
| 1835 | { | ||
| 1836 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1837 | } | ||
| 1838 | 2 | gate_result_t gate_ui_host_default_font(gate_ui_host_t* host, gate_uint32_t fonttype, gate_ui_font_t* font) | |
| 1839 | { | ||
| 1840 | //gate_ui_host_enum_fonts(host, &gate_ui_enum_fontnames_callback_test, NULL); | ||
| 1841 | 2 | gate_str_print_text(font->font_name, sizeof(font->font_name), "fixed", 5); | |
| 1842 | 2 | font->size = 12; | |
| 1843 | 2 | font->orientation = 0; | |
| 1844 | 2 | font->bold = false; | |
| 1845 | 2 | font->italic = false; | |
| 1846 | 2 | font->underline = false; | |
| 1847 | 2 | font->strikeout = false; | |
| 1848 | |||
| 1849 | 2 | return GATE_RESULT_OK; | |
| 1850 | } | ||
| 1851 | |||
| 1852 | 10 | static gate_int32_t gate_ui_host_get_default_dpi() | |
| 1853 | { | ||
| 1854 | 10 | return 96; | |
| 1855 | } | ||
| 1856 | 10 | gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points) | |
| 1857 | { | ||
| 1858 | 10 | gate_int32_t dpi = gate_ui_host_get_default_dpi(); | |
| 1859 | (void)host; | ||
| 1860 | 10 | return (gate_int32_t)((points * (gate_real32_t)dpi / 72.0f) + 0.5f); | |
| 1861 | } | ||
| 1862 | ✗ | gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels) | |
| 1863 | { | ||
| 1864 | ✗ | gate_int32_t dpi = gate_ui_host_get_default_dpi(); | |
| 1865 | ✗ | gate_int32_t tmp = (gate_int32_t)((pixels * 72.0f / (gate_real32_t)dpi) + 0.5f); | |
| 1866 | (void)host; | ||
| 1867 | ✗ | return (gate_real32_t)tmp; | |
| 1868 | } | ||
| 1869 | ✗ | gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col) | |
| 1870 | { | ||
| 1871 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1872 | } | ||
| 1873 | ✗ | gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text) | |
| 1874 | { | ||
| 1875 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1876 | } | ||
| 1877 | ✗ | gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text) | |
| 1878 | { | ||
| 1879 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1880 | } | ||
| 1881 | ✗ | gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area) | |
| 1882 | { | ||
| 1883 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1884 | } | ||
| 1885 | ✗ | gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area) | |
| 1886 | { | ||
| 1887 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1888 | } | ||
| 1889 | ✗ | gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code) | |
| 1890 | { | ||
| 1891 | ✗ | return gate_ui_motif_host_add_workproc(host, code); | |
| 1892 | } | ||
| 1893 | ✗ | gate_result_t gate_ui_host_process_events(gate_ui_host_t* host) | |
| 1894 | { | ||
| 1895 | ✗ | return gate_ui_motif_host_dispatch_pending_events(host, false); | |
| 1896 | } | ||
| 1897 | |||
| 1898 | |||
| 1899 | |||
| 1900 | 12 | void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl) | |
| 1901 | { | ||
| 1902 | 12 | return GATE_UI_MOTIF_GET_CTRL_USER_PARAM(ctrl); | |
| 1903 | } | ||
| 1904 | |||
| 1905 | 6 | gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl) | |
| 1906 | { | ||
| 1907 | 6 | return GATE_UI_MOTIF_GET_CTRL_HOST(ctrl); | |
| 1908 | } | ||
| 1909 | |||
| 1910 | ✗ | gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl) | |
| 1911 | { | ||
| 1912 | ✗ | return GATE_UI_MOTIF_GET_CTRL_PARENT(ctrl); | |
| 1913 | } | ||
| 1914 | |||
| 1915 | 20 | gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl) | |
| 1916 | { | ||
| 1917 | 20 | return gate_ui_motif_ctrl_destroy(ctrl); | |
| 1918 | } | ||
| 1919 | |||
| 1920 | 279 | gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl) | |
| 1921 | { | ||
| 1922 | 279 | Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1923 | 279 | return w != NULL; | |
| 1924 | } | ||
| 1925 | |||
| 1926 | 3 | gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl) | |
| 1927 | { | ||
| 1928 | 3 | Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1929 | 3 | return XtIsSensitive(w) ? true : false; | |
| 1930 | } | ||
| 1931 | |||
| 1932 | 3 | gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl) | |
| 1933 | { | ||
| 1934 | 3 | Widget w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1935 | 3 | return XtIsRealized(w) ? true : false; | |
| 1936 | } | ||
| 1937 | |||
| 1938 | 3 | gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl) | |
| 1939 | { | ||
| 1940 | 3 | return false; | |
| 1941 | } | ||
| 1942 | |||
| 1943 | 4 | gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position) | |
| 1944 | { | ||
| 1945 | gate_result_t ret; | ||
| 1946 | Dimension x, y, width, height; | ||
| 1947 | Widget w; | ||
| 1948 | do | ||
| 1949 | { | ||
| 1950 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (!ctrl || !position) |
| 1951 | { | ||
| 1952 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 1953 | ✗ | break; | |
| 1954 | } | ||
| 1955 | |||
| 1956 | 4 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1957 | 4 | ret = gate_ui_motif_widget_get_position(w, &position->pos, &position->size); | |
| 1958 | } while (0); | ||
| 1959 | |||
| 1960 | 4 | return ret; | |
| 1961 | } | ||
| 1962 | |||
| 1963 | 9 | gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size) | |
| 1964 | { | ||
| 1965 | gate_result_t ret; | ||
| 1966 | Dimension width, height; | ||
| 1967 | Widget w; | ||
| 1968 | do | ||
| 1969 | { | ||
| 1970 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
9 | if (!ctrl || !size) |
| 1971 | { | ||
| 1972 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 1973 | ✗ | break; | |
| 1974 | } | ||
| 1975 | |||
| 1976 | 9 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1977 | 9 | ret = gate_ui_motif_widget_get_position(w, NULL, size); | |
| 1978 | } while (0); | ||
| 1979 | 9 | return ret; | |
| 1980 | } | ||
| 1981 | |||
| 1982 | 35 | gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children) | |
| 1983 | { | ||
| 1984 | 35 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 1985 | 35 | Widget child = NULL; | |
| 1986 | 35 | WidgetList list = NULL; | |
| 1987 | 35 | gate_size_t list_count = 0; | |
| 1988 | gate_size_t ndx; | ||
| 1989 | 35 | gate_ui_ctrl_t* ptr_ctrl = NULL; | |
| 1990 | 35 | gate_arraylist_t arr = NULL; | |
| 1991 | |||
| 1992 | do | ||
| 1993 | { | ||
| 1994 | 35 | arr = gate_arraylist_create(sizeof(gate_ui_ctrl_t*), NULL, 0, NULL, NULL); | |
| 1995 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (!arr) |
| 1996 | { | ||
| 1997 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 1998 | ✗ | break; | |
| 1999 | } | ||
| 2000 | |||
| 2001 | 35 | ret = gate_ui_motif_ctrl_get_children(ctrl, (void**)&list, &list_count); | |
| 2002 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 17 times.
|
35 | GATE_BREAK_IF_FAILED(ret); |
| 2003 | |||
| 2004 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 17 times.
|
37 | for (ndx = 0; ndx != list_count; ++ndx) |
| 2005 | { | ||
| 2006 | 20 | child = list[ndx]; | |
| 2007 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (!child) |
| 2008 | { | ||
| 2009 | ✗ | continue; | |
| 2010 | } | ||
| 2011 | 20 | ptr_ctrl = gate_ui_motif_widget_get_ctrl(child); | |
| 2012 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
|
20 | if (!ptr_ctrl) |
| 2013 | { | ||
| 2014 | 3 | continue; | |
| 2015 | } | ||
| 2016 | 17 | gate_arraylist_add(arr, &ptr_ctrl); | |
| 2017 | } | ||
| 2018 | |||
| 2019 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
17 | if (NULL == gate_array_create(children, arr)) |
| 2020 | { | ||
| 2021 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 2022 | ✗ | break; | |
| 2023 | } | ||
| 2024 | 17 | ret = GATE_RESULT_OK; | |
| 2025 | } while (0); | ||
| 2026 | |||
| 2027 | 35 | gate_arraylist_release(arr); | |
| 2028 | 35 | return ret; | |
| 2029 | } | ||
| 2030 | |||
| 2031 | 4 | gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text) | |
| 2032 | { | ||
| 2033 | 4 | gate_ui_motif_dispatcher_t* ptr_disp = NULL; | |
| 2034 | 4 | Widget w = NULL; | |
| 2035 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (!ctrl || !text) |
| 2036 | { | ||
| 2037 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2038 | } | ||
| 2039 | 4 | ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl); | |
| 2040 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
4 | if (ptr_disp && ptr_disp->get_text) |
| 2041 | { | ||
| 2042 | 1 | return ptr_disp->get_text(ctrl, text); | |
| 2043 | } | ||
| 2044 | 3 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2045 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!w) |
| 2046 | { | ||
| 2047 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2048 | } | ||
| 2049 | 3 | return gate_ui_motif_widget_get_label(w, text); | |
| 2050 | } | ||
| 2051 | |||
| 2052 | ✗ | gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length) | |
| 2053 | { | ||
| 2054 | ✗ | gate_string_t text = GATE_STRING_INIT_EMPTY; | |
| 2055 | ✗ | gate_result_t ret = gate_ui_ctrl_get_text(ctrl, &text); | |
| 2056 | ✗ | if (GATE_SUCCEEDED(ret) && length) | |
| 2057 | { | ||
| 2058 | ✗ | *length = (gate_uint32_t)gate_string_length(&text); | |
| 2059 | } | ||
| 2060 | ✗ | gate_string_release(&text); | |
| 2061 | ✗ | return ret; | |
| 2062 | } | ||
| 2063 | |||
| 2064 | 2 | gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* ptr_state) | |
| 2065 | { | ||
| 2066 | 2 | gate_ui_motif_dispatcher_t* ptr_disp = NULL; | |
| 2067 | 2 | Widget w = NULL; | |
| 2068 |
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) |
| 2069 | { | ||
| 2070 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2071 | } | ||
| 2072 | 2 | ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl); | |
| 2073 |
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) |
| 2074 | { | ||
| 2075 | 2 | return ptr_disp->get_state(ctrl, ptr_state); | |
| 2076 | } | ||
| 2077 | ✗ | return GATE_RESULT_NOTSUPPORTED; | |
| 2078 | } | ||
| 2079 | |||
| 2080 | 3 | gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate) | |
| 2081 | { | ||
| 2082 | Widget w; | ||
| 2083 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!ctrl) |
| 2084 | { | ||
| 2085 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2086 | } | ||
| 2087 | 3 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2088 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!w) |
| 2089 | { | ||
| 2090 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 2091 | } | ||
| 2092 | 3 | XtSetSensitive(w, enabledstate); | |
| 2093 | 3 | return GATE_RESULT_OK; | |
| 2094 | } | ||
| 2095 | 4 | gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility) | |
| 2096 | { | ||
| 2097 | Widget w; | ||
| 2098 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!ctrl) |
| 2099 | { | ||
| 2100 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2101 | } | ||
| 2102 | 4 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!w) |
| 2104 | { | ||
| 2105 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 2106 | } | ||
| 2107 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (visibility) |
| 2108 | { | ||
| 2109 | 4 | gate_ui_host_t* host = gate_ui_ctrl_get_host(ctrl); | |
| 2110 | 4 | XtMapWidget(w); | |
| 2111 | 4 | gate_ui_motif_host_dispatch_pending_events(host, false); | |
| 2112 | 4 | return gate_ui_ctrl_refresh(ctrl); | |
| 2113 | } | ||
| 2114 | else | ||
| 2115 | { | ||
| 2116 | ✗ | XtUnmapWidget(w); | |
| 2117 | ✗ | return GATE_RESULT_OK; | |
| 2118 | } | ||
| 2119 | } | ||
| 2120 | 2 | gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl) | |
| 2121 | { | ||
| 2122 | Widget w; | ||
| 2123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!ctrl) |
| 2124 | { | ||
| 2125 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2126 | } | ||
| 2127 | 2 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!w) |
| 2129 | { | ||
| 2130 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 2131 | } | ||
| 2132 | 2 | XmProcessTraversal(w, XmTRAVERSE_CURRENT); | |
| 2133 | 2 | return GATE_RESULT_OK; | |
| 2134 | } | ||
| 2135 | 37 | 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) | |
| 2136 | { | ||
| 2137 | Widget w; | ||
| 2138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (!ctrl) |
| 2139 | { | ||
| 2140 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2141 | } | ||
| 2142 | 37 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (!w) |
| 2144 | { | ||
| 2145 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 2146 | } | ||
| 2147 | 37 | return gate_ui_motif_widget_set_position(w, position, size); | |
| 2148 | } | ||
| 2149 | 7 | gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text) | |
| 2150 | { | ||
| 2151 | 7 | gate_ui_motif_dispatcher_t* ptr_disp = NULL; | |
| 2152 | Widget w; | ||
| 2153 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
|
7 | if (!ctrl || !text) |
| 2154 | { | ||
| 2155 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2156 | } | ||
| 2157 | 7 | ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl); | |
| 2158 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
|
7 | if (ptr_disp && ptr_disp->set_text) |
| 2159 | { | ||
| 2160 | 2 | return ptr_disp->set_text(ctrl, text); | |
| 2161 | } | ||
| 2162 | 5 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 2163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!w) |
| 2164 | { | ||
| 2165 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 2166 | } | ||
| 2167 | 5 | return gate_ui_motif_widget_set_label(w, text); | |
| 2168 | } | ||
| 2169 | 2 | gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state) | |
| 2170 | { | ||
| 2171 | 2 | gate_ui_motif_dispatcher_t* ptr_disp = NULL; | |
| 2172 | 2 | Widget w = NULL; | |
| 2173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!ctrl) |
| 2174 | { | ||
| 2175 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2176 | } | ||
| 2177 | 2 | ptr_disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl); | |
| 2178 |
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) |
| 2179 | { | ||
| 2180 | 2 | return ptr_disp->set_state(ctrl, state); | |
| 2181 | } | ||
| 2182 | ✗ | return GATE_RESULT_NOTSUPPORTED; | |
| 2183 | } | ||
| 2184 | 38 | gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl) | |
| 2185 | { | ||
| 2186 | 38 | gate_ui_motif_dispatcher_t* disp = NULL; | |
| 2187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
|
38 | if (!ctrl) |
| 2188 | { | ||
| 2189 | ✗ | return GATE_RESULT_INVALIDARG; | |
| 2190 | } | ||
| 2191 | 38 | disp = GATE_UI_MOTIF_GET_CTRL_DISP(ctrl); | |
| 2192 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 17 times.
|
38 | if (disp && disp->refresh) |
| 2193 | { | ||
| 2194 | 4 | return disp->refresh(ctrl); | |
| 2195 | } | ||
| 2196 | else | ||
| 2197 | { | ||
| 2198 | 34 | return gate_ui_motif_ctrl_refresh(ctrl); | |
| 2199 | } | ||
| 2200 | } | ||
| 2201 | |||
| 2202 | |||
| 2203 | #endif /* GATE_UI_MOTIF */ | ||
| 2204 | |||
| 2205 | |||
| 2206 | |||
| 2207 | #if defined(GATE_UI_WASMHTML) | ||
| 2208 | |||
| 2209 | #include "gate/ui/gateui_wasmhtml.h" | ||
| 2210 | |||
| 2211 | |||
| 2212 | gate_result_t gate_ui_host_init(gate_ui_host_t* host, gate_uintptr_t apphandle, void* userparam) | ||
| 2213 | { | ||
| 2214 | return gate_ui_wasm_host_init(host, apphandle, userparam); | ||
| 2215 | } | ||
| 2216 | gate_result_t gate_ui_host_uninit(gate_ui_host_t* host) | ||
| 2217 | { | ||
| 2218 | return gate_ui_wasm_host_uninit(host); | ||
| 2219 | } | ||
| 2220 | gate_result_t gate_ui_host_run(gate_ui_host_t* host) | ||
| 2221 | { | ||
| 2222 | gate_result_t ret = GATE_RESULT_OK; | ||
| 2223 | return ret; | ||
| 2224 | } | ||
| 2225 | gate_result_t gate_ui_host_quit(gate_ui_host_t* host) | ||
| 2226 | { | ||
| 2227 | gate_result_t ret = GATE_RESULT_OK; | ||
| 2228 | return ret; | ||
| 2229 | } | ||
| 2230 | void* gate_ui_host_get_userparam(gate_ui_host_t* host) | ||
| 2231 | { | ||
| 2232 | return GATE_UI_WASM_GET_HOST_USER_PARAM(host); | ||
| 2233 | } | ||
| 2234 | gate_uintptr_t gate_ui_host_get_apphandle(gate_ui_host_t* host) | ||
| 2235 | { | ||
| 2236 | return GATE_UI_WASM_GET_HOST_APPHANDLE(host); | ||
| 2237 | } | ||
| 2238 | gate_uint32_t gate_ui_host_default_line_height(gate_ui_host_t* host) | ||
| 2239 | { | ||
| 2240 | return GATE_UI_WASM_GET_HOST_LINEHEIGHT(host); | ||
| 2241 | } | ||
| 2242 | gate_uint32_t gate_ui_host_default_control_height(gate_ui_host_t* host, gate_uint32_t line_count) | ||
| 2243 | { | ||
| 2244 | const gate_uint32_t line_height = GATE_UI_WASM_GET_HOST_LINEHEIGHT(host); | ||
| 2245 | gate_uint32_t height = line_height * 14 / 8; | ||
| 2246 | if (line_count > 1) | ||
| 2247 | { | ||
| 2248 | height += (line_count - 1) * line_height; | ||
| 2249 | } | ||
| 2250 | ++height; | ||
| 2251 | return height; | ||
| 2252 | } | ||
| 2253 | |||
| 2254 | static gate_int32_t gate_ui_host_get_default_dpi() | ||
| 2255 | { | ||
| 2256 | return 96; | ||
| 2257 | } | ||
| 2258 | |||
| 2259 | gate_int32_t gate_ui_host_get_pixels_in_points(gate_ui_host_t* host, gate_real32_t points) | ||
| 2260 | { | ||
| 2261 | gate_int32_t dpi = gate_ui_host_get_default_dpi(); | ||
| 2262 | (void)host; | ||
| 2263 | return (gate_int32_t)((points * (gate_real32_t)dpi / 72.0f) + 0.5f); | ||
| 2264 | } | ||
| 2265 | gate_real32_t gate_ui_host_get_points_in_pixels(gate_ui_host_t* host, gate_int32_t pixels) | ||
| 2266 | { | ||
| 2267 | gate_int32_t dpi = gate_ui_host_get_default_dpi(); | ||
| 2268 | gate_int32_t tmp = (gate_int32_t)((pixels * 72.0f / (gate_real32_t)dpi) + 0.5f); | ||
| 2269 | (void)host; | ||
| 2270 | return (gate_real32_t)tmp; | ||
| 2271 | } | ||
| 2272 | gate_result_t gate_ui_host_default_color(gate_ui_host_t* host, gate_uint32_t colortype, gate_ui_color_t* col) | ||
| 2273 | { | ||
| 2274 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2275 | } | ||
| 2276 | gate_result_t gate_ui_host_clipboard_get_text(gate_ui_host_t* host, gate_string_t* text) | ||
| 2277 | { | ||
| 2278 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2279 | } | ||
| 2280 | gate_result_t gate_ui_host_clipboard_set_text(gate_ui_host_t* host, gate_string_t const* text) | ||
| 2281 | { | ||
| 2282 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2283 | } | ||
| 2284 | gate_result_t gate_ui_host_default_workarea(gate_ui_host_t* host, gate_ui_position_t* area) | ||
| 2285 | { | ||
| 2286 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2287 | } | ||
| 2288 | gate_result_t gate_ui_host_total_workarea(gate_ui_host_t* host, gate_ui_position_t* area) | ||
| 2289 | { | ||
| 2290 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2291 | } | ||
| 2292 | gate_result_t gate_ui_host_execute(gate_ui_host_t* host, gate_runnable_t* code) | ||
| 2293 | { | ||
| 2294 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2295 | } | ||
| 2296 | gate_result_t gate_ui_host_process_events(gate_ui_host_t* host) | ||
| 2297 | { | ||
| 2298 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | |||
| 2302 | |||
| 2303 | void* gate_ui_ctrl_get_userparam(gate_ui_ctrl_t* ctrl) | ||
| 2304 | { | ||
| 2305 | return GATE_UI_WASM_GET_CTRL_USER_PARAM(ctrl); | ||
| 2306 | } | ||
| 2307 | |||
| 2308 | gate_ui_host_t* gate_ui_ctrl_get_host(gate_ui_ctrl_t* ctrl) | ||
| 2309 | { | ||
| 2310 | return GATE_UI_WASM_GET_CTRL_HOST(ctrl); | ||
| 2311 | } | ||
| 2312 | |||
| 2313 | gate_ui_ctrl_t* gate_ui_ctrl_get_parent(gate_ui_ctrl_t* ctrl) | ||
| 2314 | { | ||
| 2315 | return NULL; | ||
| 2316 | } | ||
| 2317 | |||
| 2318 | gate_result_t gate_ui_ctrl_destroy(gate_ui_ctrl_t* ctrl) | ||
| 2319 | { | ||
| 2320 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2321 | } | ||
| 2322 | |||
| 2323 | gate_bool_t gate_ui_ctrl_is_created(gate_ui_ctrl_t* ctrl) | ||
| 2324 | { | ||
| 2325 | return false; | ||
| 2326 | } | ||
| 2327 | |||
| 2328 | gate_bool_t gate_ui_ctrl_is_enabled(gate_ui_ctrl_t* ctrl) | ||
| 2329 | { | ||
| 2330 | return false; | ||
| 2331 | } | ||
| 2332 | |||
| 2333 | gate_bool_t gate_ui_ctrl_is_visible(gate_ui_ctrl_t* ctrl) | ||
| 2334 | { | ||
| 2335 | return false; | ||
| 2336 | } | ||
| 2337 | |||
| 2338 | gate_bool_t gate_ui_ctrl_is_focused(gate_ui_ctrl_t* ctrl) | ||
| 2339 | { | ||
| 2340 | return false; | ||
| 2341 | } | ||
| 2342 | |||
| 2343 | gate_result_t gate_ui_ctrl_get_position(gate_ui_ctrl_t* ctrl, gate_ui_position_t* position) | ||
| 2344 | { | ||
| 2345 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2346 | } | ||
| 2347 | |||
| 2348 | gate_result_t gate_ui_ctrl_get_size(gate_ui_ctrl_t* ctrl, gate_ui_size_t* size) | ||
| 2349 | { | ||
| 2350 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2351 | } | ||
| 2352 | |||
| 2353 | gate_result_t gate_ui_ctrl_get_children(gate_ui_ctrl_t* ctrl, gate_array_t* children) | ||
| 2354 | { | ||
| 2355 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | gate_result_t gate_ui_ctrl_get_text(gate_ui_ctrl_t* ctrl, gate_string_t* text) | ||
| 2359 | { | ||
| 2360 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2361 | } | ||
| 2362 | |||
| 2363 | gate_result_t gate_ui_ctrl_get_text_length(gate_ui_ctrl_t* ctrl, gate_uint32_t* length) | ||
| 2364 | { | ||
| 2365 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2366 | } | ||
| 2367 | |||
| 2368 | gate_result_t gate_ui_ctrl_get_state(gate_ui_ctrl_t* ctrl, gate_int32_t* ptr_state) | ||
| 2369 | { | ||
| 2370 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2371 | } | ||
| 2372 | |||
| 2373 | gate_result_t gate_ui_ctrl_set_enabled(gate_ui_ctrl_t* ctrl, gate_bool_t enabledstate) | ||
| 2374 | { | ||
| 2375 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2376 | } | ||
| 2377 | gate_result_t gate_ui_ctrl_set_visible(gate_ui_ctrl_t* ctrl, gate_bool_t visibility) | ||
| 2378 | { | ||
| 2379 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2380 | } | ||
| 2381 | gate_result_t gate_ui_ctrl_set_focus(gate_ui_ctrl_t* ctrl) | ||
| 2382 | { | ||
| 2383 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2384 | } | ||
| 2385 | 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) | ||
| 2386 | { | ||
| 2387 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2388 | } | ||
| 2389 | gate_result_t gate_ui_ctrl_set_text(gate_ui_ctrl_t* ctrl, gate_string_t const* text) | ||
| 2390 | { | ||
| 2391 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2392 | } | ||
| 2393 | gate_result_t gate_ui_ctrl_set_state(gate_ui_ctrl_t* ctrl, gate_int32_t state) | ||
| 2394 | { | ||
| 2395 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2396 | } | ||
| 2397 | |||
| 2398 | gate_result_t gate_ui_ctrl_refresh(gate_ui_ctrl_t* ctrl) | ||
| 2399 | { | ||
| 2400 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 2401 | } | ||
| 2402 | |||
| 2403 | |||
| 2404 | #endif | ||
| 2405 |