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