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