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/splitters.h" |
30 |
|
|
#include "gate/results.h" |
31 |
|
|
|
32 |
|
|
#if defined(GATE_UI_WINAPI) |
33 |
|
|
|
34 |
|
|
#include "gate/ui/gateui_winapi.h" |
35 |
|
|
#include "gate/platforms.h" |
36 |
|
|
#include <windowsx.h> |
37 |
|
|
|
38 |
|
|
static BOOL SetWindowPosIfRequired(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) |
39 |
|
|
{ |
40 |
|
|
RECT rect; |
41 |
|
|
POINT point; |
42 |
|
|
HWND hWndParent; |
43 |
|
|
BOOL ret = TRUE; |
44 |
|
|
|
45 |
|
|
#if !defined(GATE_SYS_WIN16) |
46 |
|
|
ret = |
47 |
|
|
#endif |
48 |
|
|
GetWindowRect(hWnd, &rect); |
49 |
|
|
if (ret) |
50 |
|
|
{ |
51 |
|
|
hWndParent = GetParent(hWnd); |
52 |
|
|
|
53 |
|
|
point.x = rect.left; |
54 |
|
|
point.y = rect.top; |
55 |
|
|
|
56 |
|
|
if (hWndParent != NULL) |
57 |
|
|
{ |
58 |
|
|
ScreenToClient(hWndParent, &point); |
59 |
|
|
} |
60 |
|
|
if ((X != point.x) || (Y != point.y) || |
61 |
|
|
(cx != rect.right - rect.left) || (cy != rect.bottom - rect.top) |
62 |
|
|
) |
63 |
|
|
{ |
64 |
|
|
ret = SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); |
65 |
|
|
} |
66 |
|
|
else |
67 |
|
|
{ |
68 |
|
|
ret = FALSE; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
return ret; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
static void gate_ui_splitter_resize(gate_ui_splitter_t* splitter, HWND hwndFirst, HWND hwndSecond) |
76 |
|
|
{ |
77 |
|
|
gate_ui_size_t sz; |
78 |
|
|
gate_result_t ret; |
79 |
|
|
gate_ui_host_t* host = GATE_UI_WINAPI_GET_HOST(&splitter->ctrl); |
80 |
|
|
gate_uint32_t lineheight = gate_ui_host_default_line_height(host); |
81 |
|
|
gate_uint32_t length; |
82 |
|
|
gate_int32_t separator; |
83 |
|
|
UINT showflags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_DRAWFRAME; |
84 |
|
|
do |
85 |
|
|
{ |
86 |
|
|
ret = gate_ui_winapi_get_size(&splitter->ctrl, &sz); |
87 |
|
|
if (GATE_FAILED(ret)) break; |
88 |
|
|
|
89 |
|
|
separator = lineheight / 5; |
90 |
|
|
if (separator < 1) separator = 1; |
91 |
|
|
|
92 |
|
|
if (splitter->vertical) |
93 |
|
|
{ |
94 |
|
|
length = sz.height; |
95 |
|
|
} |
96 |
|
|
else |
97 |
|
|
{ |
98 |
|
|
length = sz.width; |
99 |
|
|
} |
100 |
|
|
if (length < splitter->minimum * 3 / 2) |
101 |
|
|
{ |
102 |
|
|
ret = GATE_RESULT_FAILED; |
103 |
|
|
break; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
if (splitter->value > length - splitter->minimum) |
108 |
|
|
{ |
109 |
|
|
splitter->value = length - splitter->minimum; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
if (splitter->value < splitter->minimum) |
113 |
|
|
{ |
114 |
|
|
splitter->value = splitter->minimum; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
if (splitter->vertical) |
118 |
|
|
{ |
119 |
|
|
if (hwndFirst != NULL) |
120 |
|
|
{ |
121 |
|
|
SetWindowPosIfRequired(hwndFirst, NULL, 0, 0, sz.width, splitter->value - separator, showflags); |
122 |
|
|
} |
123 |
|
|
if (hwndSecond != NULL) |
124 |
|
|
{ |
125 |
|
|
SetWindowPosIfRequired(hwndSecond, NULL, 0, splitter->value + separator, sz.width, sz.height - splitter->value - separator, showflags); |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
else |
129 |
|
|
{ |
130 |
|
|
if (hwndFirst != NULL) |
131 |
|
|
{ |
132 |
|
|
SetWindowPosIfRequired(hwndFirst, NULL, 0, 0, splitter->value - separator, sz.height, showflags); |
133 |
|
|
} |
134 |
|
|
if (hwndSecond != NULL) |
135 |
|
|
{ |
136 |
|
|
SetWindowPosIfRequired(hwndSecond, NULL, splitter->value + separator, 0, sz.width - splitter->value - separator, sz.height, showflags); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
} while (0); |
140 |
|
|
|
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
static gate_bool_t gate_ui_splitter_events(void* hwnd, gate_ui_ctrl_t* ctrl, gate_uint32_t msg, gate_uintptr_t wParam, gate_intptr_t lParam, gate_intptr_t* lresult) |
144 |
|
|
{ |
145 |
|
|
HWND hwnd_ctrl; |
146 |
|
|
gate_ui_splitter_t* splitter; |
147 |
|
|
POINT pnt; |
148 |
|
|
HWND hwnd_parent; |
149 |
|
|
RECT rect; |
150 |
|
|
HDC hdc; |
151 |
|
|
HBRUSH hbr_bk_gnd = NULL; |
152 |
|
|
gate_ui_host_t* host = NULL; |
153 |
|
|
static HCURSOR hcursor = NULL; |
154 |
|
|
#if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT) |
155 |
|
|
gate_ui_color_t col; |
156 |
|
|
#endif |
157 |
|
|
|
158 |
|
|
if (ctrl != NULL) |
159 |
|
|
{ |
160 |
|
|
hwnd_ctrl = GATE_UI_WINAPI_GET_HWND(ctrl); |
161 |
|
|
if (hwnd == hwnd_ctrl) |
162 |
|
|
{ |
163 |
|
|
if (hcursor == NULL) |
164 |
|
|
{ |
165 |
|
|
hcursor = LoadCursor(NULL, IDC_SIZEWE); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
splitter = (gate_ui_splitter_t*)ctrl; |
169 |
|
|
switch (msg) |
170 |
|
|
{ |
171 |
|
|
#if !defined(GATE_SYS_WIN16) |
172 |
|
|
case WM_CTLCOLOREDIT: |
173 |
|
|
case WM_CTLCOLORBTN: |
174 |
|
|
case WM_CTLCOLORLISTBOX: |
175 |
|
|
case WM_CTLCOLORMSGBOX: |
176 |
|
|
case WM_CTLCOLORSCROLLBAR: |
177 |
|
|
case WM_CTLCOLORDLG: |
178 |
|
|
case WM_CTLCOLORSTATIC: |
179 |
|
|
{ |
180 |
|
|
*lresult = SendMessage(GetParent((HWND)hwnd), msg, wParam, lParam); |
181 |
|
|
return true; |
182 |
|
|
break; |
183 |
|
|
} |
184 |
|
|
#endif /* GATE_SYS_WIN16 */ |
185 |
|
|
case WM_ERASEBKGND: |
186 |
|
|
{ |
187 |
|
|
hwnd_parent = GetParent(hwnd_ctrl); |
188 |
|
|
hdc = (HDC)wParam; |
189 |
|
|
|
190 |
|
|
#if defined(GATE_UI_WINAPI_DARKMODE_SUPPORT) |
191 |
|
|
if (gate_ui_winapi_is_darkmode_applied(hwnd_ctrl)) |
192 |
|
|
{ |
193 |
|
|
host = GATE_UI_WINAPI_GET_HOST(ctrl); |
194 |
|
|
|
195 |
|
|
gate_ui_host_default_color(host, GATE_UI_COLOR_CONTROL, &col); |
196 |
|
|
hbr_bk_gnd = (HBRUSH)gate_ui_winapi_host_get_brush(host, &col); |
197 |
|
|
} |
198 |
|
|
else |
199 |
|
|
#endif /* GATE_UI_WINAPI_DARKMODE_SUPPORT */ |
200 |
|
|
{ |
201 |
|
|
hbr_bk_gnd = (HBRUSH)gate_ui_winapi_get_syscolor_brush( |
202 |
|
|
gate_ui_winapi_get_syscolor_index(GATE_UI_COLOR_CONTROL)); |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
if (hbr_bk_gnd) |
206 |
|
|
{ |
207 |
|
|
GetClientRect(hwnd_ctrl, &rect); |
208 |
|
|
FillRect(hdc, &rect, hbr_bk_gnd); |
209 |
|
|
*lresult = 1; |
210 |
|
|
return true; |
211 |
|
|
} |
212 |
|
|
break; |
213 |
|
|
} |
214 |
|
|
case WM_SIZE: |
215 |
|
|
{ |
216 |
|
|
gate_ui_splitter_update(splitter); |
217 |
|
|
break; |
218 |
|
|
} |
219 |
|
|
case WM_SETCURSOR: |
220 |
|
|
{ |
221 |
|
|
GetCursorPos(&pnt); |
222 |
|
|
if (hwnd == WindowFromPoint(pnt)) |
223 |
|
|
{ |
224 |
|
|
SetCursor(hcursor); |
225 |
|
|
*lresult = TRUE; |
226 |
|
|
return true; |
227 |
|
|
} |
228 |
|
|
break; |
229 |
|
|
} |
230 |
|
|
case WM_LBUTTONDOWN: |
231 |
|
|
{ |
232 |
|
|
splitter->drag_mode = true; |
233 |
|
|
splitter->click_point.x = GET_X_LPARAM(lParam); |
234 |
|
|
splitter->click_point.y = GET_Y_LPARAM(lParam); |
235 |
|
|
SetCapture(hwnd_ctrl); |
236 |
|
|
break; |
237 |
|
|
} |
238 |
|
|
case WM_MOUSEMOVE: |
239 |
|
|
{ |
240 |
|
|
if (splitter->drag_mode) |
241 |
|
|
{ |
242 |
|
|
if ((splitter->click_point.x != GET_X_LPARAM(lParam)) |
243 |
|
|
|| (splitter->click_point.y != GET_Y_LPARAM(lParam)) |
244 |
|
|
) |
245 |
|
|
{ |
246 |
|
|
if (splitter->vertical) |
247 |
|
|
{ |
248 |
|
|
splitter->click_point.y = GET_Y_LPARAM(lParam); |
249 |
|
|
if (splitter->click_point.y < 0) splitter->click_point.y = 0; |
250 |
|
|
splitter->value = splitter->click_point.y; |
251 |
|
|
} |
252 |
|
|
else |
253 |
|
|
{ |
254 |
|
|
splitter->click_point.x = GET_X_LPARAM(lParam); |
255 |
|
|
if (splitter->click_point.x < 0) splitter->click_point.x = 0; |
256 |
|
|
splitter->value = splitter->click_point.x; |
257 |
|
|
} |
258 |
|
|
gate_ui_splitter_update(splitter); |
259 |
|
|
} |
260 |
|
|
} |
261 |
|
|
break; |
262 |
|
|
} |
263 |
|
|
case WM_LBUTTONUP: |
264 |
|
|
{ |
265 |
|
|
splitter->drag_mode = false; |
266 |
|
|
ReleaseCapture(); |
267 |
|
|
break; |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
} |
271 |
|
|
} |
272 |
|
|
return false; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
gate_result_t gate_ui_splitter_create( |
276 |
|
|
gate_ui_splitter_t* splitter, gate_ui_ctrl_t* parent, |
277 |
|
|
gate_ui_position_t const* position, |
278 |
|
|
gate_bool_t vertical, |
279 |
|
|
gate_uint32_t flags, |
280 |
|
|
void* userparam |
281 |
|
|
) |
282 |
|
|
{ |
283 |
|
|
gate_result_t ret; |
284 |
|
|
gate_uint32_t styles = 0; |
285 |
|
|
gate_uint32_t exstyles = 0; |
286 |
|
|
gate_ui_host_t* host; |
287 |
|
|
gate_ui_size_t clientsize; |
288 |
|
|
HWND hwnd; |
289 |
|
|
HWND hwndParent; |
290 |
|
|
|
291 |
|
|
do |
292 |
|
|
{ |
293 |
|
|
host = gate_ui_ctrl_get_host(parent); |
294 |
|
|
if (host == NULL) |
295 |
|
|
{ |
296 |
|
|
ret = GATE_RESULT_INVALIDSTATE; |
297 |
|
|
break; |
298 |
|
|
} |
299 |
|
|
hwndParent = GATE_UI_WINAPI_GET_HWND(parent); |
300 |
|
|
if (hwndParent == NULL) |
301 |
|
|
{ |
302 |
|
|
ret = GATE_RESULT_INVALIDSTATE; |
303 |
|
|
break; |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
gate_mem_clear(splitter, sizeof(gate_ui_splitter_t)); |
307 |
|
|
splitter->minimum = 32; |
308 |
|
|
splitter->vertical = vertical; |
309 |
|
|
#if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16) |
310 |
|
|
exstyles = WS_EX_CONTROLPARENT; |
311 |
|
|
#endif |
312 |
|
|
styles = WS_CHILD | WS_CLIPCHILDREN; |
313 |
|
|
|
314 |
|
|
if (!GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_ENABLED)) styles |= WS_DISABLED; |
315 |
|
|
if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_VISIBLE)) styles |= WS_VISIBLE; |
316 |
|
|
|
317 |
|
|
ret = gate_ui_winapi_create(&splitter->ctrl, host, hwndParent, NULL, position, styles, exstyles, NULL, userparam, false); |
318 |
|
|
if (GATE_SUCCEEDED(ret)) |
319 |
|
|
{ |
320 |
|
|
hwnd = GATE_UI_WINAPI_GET_HWND(&splitter->ctrl); |
321 |
|
|
gate_ui_winapi_get_size(&splitter->ctrl, &clientsize); |
322 |
|
|
splitter->value = (vertical ? clientsize.height : clientsize.width) / 2; |
323 |
|
|
|
324 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_SIZE, &gate_ui_splitter_events, &splitter->ctrl); |
325 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_SETCURSOR, &gate_ui_splitter_events, &splitter->ctrl); |
326 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_LBUTTONDOWN, &gate_ui_splitter_events, &splitter->ctrl); |
327 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_LBUTTONUP, &gate_ui_splitter_events, &splitter->ctrl); |
328 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_MOUSEMOVE, &gate_ui_splitter_events, &splitter->ctrl); |
329 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_ERASEBKGND, &gate_ui_splitter_events, &splitter->ctrl); |
330 |
|
|
|
331 |
|
|
#if !defined(GATE_SYS_WIN16) |
332 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORDLG, &gate_ui_splitter_events, &splitter->ctrl); |
333 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORSTATIC, &gate_ui_splitter_events, &splitter->ctrl); |
334 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLOREDIT, &gate_ui_splitter_events, &splitter->ctrl); |
335 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORBTN, &gate_ui_splitter_events, &splitter->ctrl); |
336 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORLISTBOX, &gate_ui_splitter_events, &splitter->ctrl); |
337 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORMSGBOX, &gate_ui_splitter_events, &splitter->ctrl); |
338 |
|
|
gate_ui_winapi_register_event(host, hwnd, WM_CTLCOLORSCROLLBAR, &gate_ui_splitter_events, &splitter->ctrl); |
339 |
|
|
#endif |
340 |
|
|
|
341 |
|
|
} |
342 |
|
|
} while (0); |
343 |
|
|
|
344 |
|
|
return ret; |
345 |
|
|
} |
346 |
|
|
|
347 |
|
|
gate_result_t gate_ui_splitter_set(gate_ui_splitter_t* splitter, gate_uint32_t const* minimum, gate_uint32_t const* value) |
348 |
|
|
{ |
349 |
|
|
gate_result_t ret = GATE_RESULT_OK; |
350 |
|
|
HWND hwnd = GATE_UI_WINAPI_GET_HWND(&splitter->ctrl); |
351 |
|
|
|
352 |
|
|
if (minimum != NULL) |
353 |
|
|
{ |
354 |
|
|
splitter->minimum = *minimum; |
355 |
|
|
} |
356 |
|
|
if (value != NULL) |
357 |
|
|
{ |
358 |
|
|
splitter->value = *value; |
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
if (hwnd != NULL) |
362 |
|
|
{ |
363 |
|
|
ret = gate_ui_splitter_update(splitter); |
364 |
|
|
} |
365 |
|
|
return ret; |
366 |
|
|
} |
367 |
|
|
|
368 |
|
|
struct gate_ui_splitter_enum_child_windows |
369 |
|
|
{ |
370 |
|
|
HWND parent; |
371 |
|
|
HWND first; |
372 |
|
|
HWND second; |
373 |
|
|
}; |
374 |
|
|
|
375 |
|
|
static BOOL CALLBACK gate_ui_splitter_enum_children(HWND hwnd, LPARAM lParam) |
376 |
|
|
{ |
377 |
|
|
struct gate_ui_splitter_enum_child_windows* param = (struct gate_ui_splitter_enum_child_windows*)(gate_intptr_t)lParam; |
378 |
|
|
if (GetParent(hwnd) == param->parent) |
379 |
|
|
{ |
380 |
|
|
if (param->first == NULL) |
381 |
|
|
{ |
382 |
|
|
param->first = hwnd; |
383 |
|
|
} |
384 |
|
|
else if (param->second == NULL) |
385 |
|
|
{ |
386 |
|
|
param->second = hwnd; |
387 |
|
|
} |
388 |
|
|
} |
389 |
|
|
return TRUE; |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
|
393 |
|
|
gate_result_t gate_ui_splitter_update(gate_ui_splitter_t* splitter) |
394 |
|
|
{ |
395 |
|
|
gate_result_t ret = GATE_RESULT_INVALIDARG; |
396 |
|
|
HWND hwnd = GATE_UI_WINAPI_GET_HWND(&splitter->ctrl); |
397 |
|
|
struct gate_ui_splitter_enum_child_windows children; |
398 |
|
|
|
399 |
|
|
if (hwnd != NULL) |
400 |
|
|
{ |
401 |
|
|
children.parent = hwnd; |
402 |
|
|
children.first = NULL; |
403 |
|
|
children.second = NULL; |
404 |
|
|
#if defined(GATE_SYS_WINCE) |
405 |
|
|
children.first = GetWindow(hwnd, GW_CHILD); |
406 |
|
|
ret = GATE_RESULT_FAILED; |
407 |
|
|
if (children.first != NULL) |
408 |
|
|
{ |
409 |
|
|
children.second = GetWindow(children.first, GW_HWNDNEXT); |
410 |
|
|
} |
411 |
|
|
#else |
412 |
|
|
EnumChildWindows(hwnd, &gate_ui_splitter_enum_children, (LPARAM)(gate_intptr_t)&children); |
413 |
|
|
#endif |
414 |
|
|
if ((children.first != NULL) || (children.second != NULL)) |
415 |
|
|
{ |
416 |
|
|
gate_ui_splitter_resize(splitter, children.first, children.second); |
417 |
|
|
} |
418 |
|
|
ret = GATE_RESULT_OK; |
419 |
|
|
} |
420 |
|
|
return ret; |
421 |
|
|
} |
422 |
|
|
|
423 |
|
|
gate_result_t gate_ui_splitter_set_first(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
424 |
|
|
{ |
425 |
|
|
GATE_UNUSED_ARG(splitter); |
426 |
|
|
GATE_UNUSED_ARG(ctrl); |
427 |
|
|
return GATE_RESULT_OK; |
428 |
|
|
} |
429 |
|
|
gate_result_t gate_ui_splitter_set_second(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
430 |
|
|
{ |
431 |
|
|
GATE_UNUSED_ARG(splitter); |
432 |
|
|
GATE_UNUSED_ARG(ctrl); |
433 |
|
|
return GATE_RESULT_OK; |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
#endif /* GATE_UI_WINAPI */ |
439 |
|
|
|
440 |
|
|
|
441 |
|
|
#if defined(GATE_UI_GTK) |
442 |
|
|
|
443 |
|
|
#include "gate/ui/gateui_gtk.h" |
444 |
|
|
|
445 |
|
|
|
446 |
|
|
static gboolean gate_ui_gtk_splitter_refresh_idle_callback(gpointer user_data) |
447 |
|
|
{ |
448 |
|
|
gate_ui_splitter_t* splitter = (gate_ui_splitter_t*)user_data; |
449 |
|
|
gate_ui_gtk_ctrl_refresh(&splitter->ctrl); |
450 |
|
|
return FALSE; /* FALSE means: do not invoke this callback again (until next call to g_idle_add()) */ |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
|
454 |
|
|
static gate_result_t gate_ui_gtk_splitter_refresh(gate_ui_ctrl_t* ctrl) |
455 |
|
|
{ |
456 |
|
|
gate_ui_splitter_t* splitter = (gate_ui_splitter_t*)ctrl; |
457 |
|
|
g_idle_add(&gate_ui_gtk_splitter_refresh_idle_callback, splitter); |
458 |
|
|
return gate_ui_gtk_ctrl_refresh(ctrl); |
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
static gate_result_t gate_ui_gtk_splitter_destroy(gate_ui_ctrl_t* ctrl) |
462 |
|
|
{ |
463 |
|
|
return gate_ui_gtk_ctrl_destroy_native(ctrl); |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
|
467 |
|
|
static gate_ui_gtk_dispatcher_t gate_ui_gtk_splitter_dispatcher = |
468 |
|
|
{ |
469 |
|
|
NULL /*get_text_length*/, |
470 |
|
|
NULL /*get_text*/, |
471 |
|
|
NULL /*set_text*/, |
472 |
|
|
NULL /*get_state*/, |
473 |
|
|
NULL /*set_state*/, |
474 |
|
|
&gate_ui_gtk_splitter_refresh, |
475 |
|
|
&gate_ui_gtk_splitter_destroy |
476 |
|
|
}; |
477 |
|
|
|
478 |
|
|
|
479 |
|
|
gate_result_t gate_ui_splitter_create( |
480 |
|
|
gate_ui_splitter_t* splitter, gate_ui_ctrl_t* parent, |
481 |
|
|
gate_ui_position_t const* position, |
482 |
|
|
gate_bool_t vertical, |
483 |
|
|
gate_uint32_t flags, |
484 |
|
|
void* userparam |
485 |
|
|
) |
486 |
|
|
{ |
487 |
|
|
GtkWidget* widget; |
488 |
|
|
gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent); |
489 |
|
|
|
490 |
|
|
gate_mem_clear(splitter, sizeof(gate_ui_splitter_t)); |
491 |
|
|
widget = gtk_paned_new(vertical ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL); |
492 |
|
|
if (widget == NULL) |
493 |
|
|
{ |
494 |
|
|
return GATE_RESULT_FAILED; |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
gate_ui_gtk_ctrl_init(&splitter->ctrl, widget, host, userparam, parent, |
498 |
|
|
&gate_ui_gtk_splitter_dispatcher, false, true, position, &flags); |
499 |
|
|
|
500 |
|
|
return GATE_RESULT_OK; |
501 |
|
|
} |
502 |
|
|
|
503 |
|
|
gate_result_t gate_ui_splitter_set(gate_ui_splitter_t* splitter, |
504 |
|
|
gate_uint32_t const* minimum, gate_uint32_t const* value) |
505 |
|
|
{ |
506 |
|
|
gate_result_t ret = GATE_RESULT_OK; |
507 |
|
|
GtkWidget* container = GATE_UI_GTK_GET_CTRL_WIDGET(&splitter->ctrl); |
508 |
|
|
|
509 |
|
|
if (value) |
510 |
|
|
{ |
511 |
|
|
gtk_paned_set_position(GTK_PANED(container), (gint)*value); |
512 |
|
|
} |
513 |
|
|
return ret; |
514 |
|
|
} |
515 |
|
|
|
516 |
|
|
gate_result_t gate_ui_splitter_update(gate_ui_splitter_t* splitter) |
517 |
|
|
{ |
518 |
|
|
gate_result_t ret = GATE_RESULT_OK; |
519 |
|
|
GtkWidget* container = GATE_UI_GTK_GET_CTRL_WIDGET(&splitter->ctrl); |
520 |
|
|
|
521 |
|
|
return ret; |
522 |
|
|
} |
523 |
|
|
|
524 |
|
|
gate_result_t gate_ui_splitter_set_first(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
525 |
|
|
{ |
526 |
|
|
gate_result_t ret = GATE_RESULT_OK; |
527 |
|
|
GtkWidget* widget = GATE_UI_GTK_GET_CTRL_WIDGET(&splitter->ctrl); |
528 |
|
|
GtkWidget* child = GATE_UI_GTK_GET_CTRL_WIDGET(ctrl); |
529 |
|
|
GtkContainer* container = GTK_CONTAINER(widget); |
530 |
|
|
|
531 |
|
|
gtk_paned_add1(GTK_PANED(widget), child); |
532 |
|
|
if (!gtk_widget_get_realized(child)) |
533 |
|
|
{ |
534 |
|
|
gtk_widget_realize(child); |
535 |
|
|
} |
536 |
|
|
|
537 |
|
|
return ret; |
538 |
|
|
} |
539 |
|
|
gate_result_t gate_ui_splitter_set_second(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
540 |
|
|
{ |
541 |
|
|
gate_result_t ret = GATE_RESULT_OK; |
542 |
|
|
GtkWidget* widget = GATE_UI_GTK_GET_CTRL_WIDGET(&splitter->ctrl); |
543 |
|
|
GtkWidget* child = GATE_UI_GTK_GET_CTRL_WIDGET(ctrl); |
544 |
|
|
GtkContainer* container = GTK_CONTAINER(widget); |
545 |
|
|
|
546 |
|
|
gtk_paned_add2(GTK_PANED(widget), child); |
547 |
|
|
if (!gtk_widget_get_realized(child)) |
548 |
|
|
{ |
549 |
|
|
gtk_widget_realize(child); |
550 |
|
|
} |
551 |
|
|
|
552 |
|
|
return ret; |
553 |
|
|
} |
554 |
|
|
|
555 |
|
|
#endif /* GATE_UI_GTK */ |
556 |
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
#if defined(GATE_UI_MOTIF) |
560 |
|
|
|
561 |
|
|
#include "gate/ui/gateui_motif.h" |
562 |
|
|
#include <Xm/Paned.h> |
563 |
|
|
|
564 |
|
✗ |
gate_result_t gate_ui_splitter_create(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, |
565 |
|
|
gate_bool_t vertical, gate_uint32_t flags, void* userparam) |
566 |
|
|
{ |
567 |
|
✗ |
gate_result_t ret = GATE_RESULT_FAILED; |
568 |
|
|
Arg args[8]; |
569 |
|
✗ |
unsigned args_count = 0; |
570 |
|
✗ |
Widget w = NULL; |
571 |
|
|
|
572 |
|
|
do |
573 |
|
|
{ |
574 |
|
✗ |
if (!splitter || !parent) |
575 |
|
|
{ |
576 |
|
✗ |
ret = GATE_RESULT_INVALIDARG; |
577 |
|
✗ |
break; |
578 |
|
|
} |
579 |
|
|
|
580 |
|
✗ |
XtSetArg(args[args_count], XmNorientation, (vertical ? XmVERTICAL : XmHORIZONTAL)); ++args_count; |
581 |
|
|
|
582 |
|
✗ |
ret = gate_ui_motif_ctrl_create(&splitter->ctrl, xmPanedWidgetClass, userparam, NULL, parent, |
583 |
|
|
position, &flags, false, NULL, args, args_count); |
584 |
|
✗ |
GATE_BREAK_IF_FAILED(ret); |
585 |
|
|
|
586 |
|
✗ |
splitter->vertical = vertical; |
587 |
|
✗ |
splitter->minimum = 0; |
588 |
|
✗ |
splitter->drag_mode = false; |
589 |
|
✗ |
splitter->value = 0; |
590 |
|
|
|
591 |
|
|
} while (0); |
592 |
|
|
|
593 |
|
✗ |
return ret; |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
|
597 |
|
✗ |
static void apply_splitter_settings_to_children(gate_ui_splitter_t* splitter) |
598 |
|
|
{ |
599 |
|
✗ |
Widget w = NULL; |
600 |
|
✗ |
WidgetList children = NULL; |
601 |
|
✗ |
int count = 0; |
602 |
|
|
int ndx; |
603 |
|
|
|
604 |
|
✗ |
w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&splitter->ctrl); |
605 |
|
✗ |
XmPanedGetPanes(w, &children, &count); |
606 |
|
✗ |
if (count > 0) |
607 |
|
|
{ |
608 |
|
✗ |
if (splitter->value != 0) |
609 |
|
|
{ |
610 |
|
✗ |
XtVaSetValues(children[0], |
611 |
|
✗ |
XmNpreferredPaneSize, (Cardinal)splitter->value, |
612 |
|
|
XmNresizeToPreferred, TRUE, |
613 |
|
|
NULL, NULL); |
614 |
|
|
} |
615 |
|
✗ |
if (splitter->minimum != 0) |
616 |
|
|
{ |
617 |
|
✗ |
for (ndx = 0; ndx != count; ++ndx) |
618 |
|
|
{ |
619 |
|
✗ |
XtVaSetValues(children[ndx], |
620 |
|
✗ |
XmNpaneMinimum, (Cardinal)splitter->minimum, |
621 |
|
|
NULL, NULL); |
622 |
|
|
} |
623 |
|
|
} |
624 |
|
|
} |
625 |
|
✗ |
} |
626 |
|
|
|
627 |
|
✗ |
gate_result_t gate_ui_splitter_set(gate_ui_splitter_t* splitter, gate_uint32_t const* minimum, gate_uint32_t const* value) |
628 |
|
|
{ |
629 |
|
✗ |
gate_result_t ret = GATE_RESULT_FAILED; |
630 |
|
✗ |
Widget w = NULL; |
631 |
|
|
|
632 |
|
|
do |
633 |
|
|
{ |
634 |
|
✗ |
if (!gate_ui_ctrl_is_created(&splitter->ctrl)) |
635 |
|
|
{ |
636 |
|
✗ |
ret = GATE_RESULT_INVALIDSTATE; |
637 |
|
✗ |
break; |
638 |
|
|
} |
639 |
|
✗ |
w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&splitter->ctrl); |
640 |
|
✗ |
if (!w) |
641 |
|
|
{ |
642 |
|
✗ |
ret = GATE_RESULT_INVALIDSTATE; |
643 |
|
✗ |
break; |
644 |
|
|
} |
645 |
|
|
|
646 |
|
✗ |
if (minimum) |
647 |
|
|
{ |
648 |
|
✗ |
splitter->minimum = *minimum; |
649 |
|
|
} |
650 |
|
✗ |
if (value) |
651 |
|
|
{ |
652 |
|
✗ |
splitter->value = *value; |
653 |
|
|
} |
654 |
|
|
|
655 |
|
✗ |
apply_splitter_settings_to_children(splitter); |
656 |
|
|
|
657 |
|
✗ |
ret = GATE_RESULT_OK; |
658 |
|
|
} while (0); |
659 |
|
✗ |
return ret; |
660 |
|
|
} |
661 |
|
|
|
662 |
|
✗ |
gate_result_t gate_ui_splitter_update(gate_ui_splitter_t* splitter) |
663 |
|
|
{ |
664 |
|
✗ |
return GATE_RESULT_NOTIMPLEMENTED; |
665 |
|
|
} |
666 |
|
|
|
667 |
|
✗ |
static gate_result_t gate_ui_splitter_add_child(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
668 |
|
|
{ |
669 |
|
✗ |
gate_result_t ret = GATE_RESULT_FAILED; |
670 |
|
✗ |
Widget w = NULL; |
671 |
|
✗ |
Widget c = NULL; |
672 |
|
|
gate_ui_host_t* ptr_host; |
673 |
|
|
XtAppContext app_context; |
674 |
|
|
|
675 |
|
|
do |
676 |
|
|
{ |
677 |
|
✗ |
if (!gate_ui_ctrl_is_created(&splitter->ctrl) || !gate_ui_ctrl_is_created(ctrl)) |
678 |
|
|
{ |
679 |
|
✗ |
ret = GATE_RESULT_INVALIDSTATE; |
680 |
|
✗ |
break; |
681 |
|
|
} |
682 |
|
✗ |
w = GATE_UI_MOTIF_GET_CTRL_WIDGET(&splitter->ctrl); |
683 |
|
✗ |
c = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); |
684 |
|
✗ |
if (!w || !c) |
685 |
|
|
{ |
686 |
|
✗ |
ret = GATE_RESULT_INVALIDSTATE; |
687 |
|
✗ |
break; |
688 |
|
|
} |
689 |
|
|
|
690 |
|
✗ |
apply_splitter_settings_to_children(splitter); |
691 |
|
|
|
692 |
|
✗ |
ret = GATE_RESULT_OK; |
693 |
|
|
} while (0); |
694 |
|
✗ |
return ret; |
695 |
|
|
} |
696 |
|
|
|
697 |
|
✗ |
gate_result_t gate_ui_splitter_set_first(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
698 |
|
|
{ |
699 |
|
✗ |
return gate_ui_splitter_add_child(splitter, ctrl); |
700 |
|
|
} |
701 |
|
|
|
702 |
|
✗ |
gate_result_t gate_ui_splitter_set_second(gate_ui_splitter_t* splitter, gate_ui_ctrl_t* ctrl) |
703 |
|
|
{ |
704 |
|
✗ |
return gate_ui_splitter_add_child(splitter, ctrl); |
705 |
|
|
} |
706 |
|
|
|
707 |
|
|
#endif /* GATE_UI_MOTIF */ |
708 |
|
|
|