| 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/treeviews.h" | ||
| 30 | #include "gate/results.h" | ||
| 31 | #include "gate/debugging.h" | ||
| 32 | |||
| 33 | #if defined(GATE_UI_WINAPI) | ||
| 34 | |||
| 35 | #include "gate/ui/gateui_winapi.h" | ||
| 36 | #include "gate/platforms.h" | ||
| 37 | #ifdef _WIN32_IE | ||
| 38 | # undef _WIN32_IE | ||
| 39 | # if defined(GATE_COMPILER_TCC) | ||
| 40 | # define _WIN32_IE 0x0501 | ||
| 41 | # else | ||
| 42 | # define _WIN32_IE 0x0400 | ||
| 43 | # endif | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #if defined(GATE_SYS_WIN16) | ||
| 47 | |||
| 48 | typedef struct tagNMHDR | ||
| 49 | { | ||
| 50 | HWND hwndFrom; | ||
| 51 | UINT_PTR idFrom; | ||
| 52 | UINT code; | ||
| 53 | } NMHDR; | ||
| 54 | |||
| 55 | #define TV_HITTESTINFO TVHITTESTINFO | ||
| 56 | |||
| 57 | struct _TREEITEM; | ||
| 58 | typedef struct _TREEITEM* HTREEITEM; | ||
| 59 | |||
| 60 | typedef struct tagTVHITTESTINFO { | ||
| 61 | POINT pt; | ||
| 62 | UINT flags; | ||
| 63 | HTREEITEM hItem; | ||
| 64 | } TVHITTESTINFO, * LPTVHITTESTINFO; | ||
| 65 | |||
| 66 | #define LPTV_ITEM LPTVITEM | ||
| 67 | #define TV_ITEM TVITEM | ||
| 68 | |||
| 69 | typedef struct tagTVITEM { | ||
| 70 | UINT mask; | ||
| 71 | HTREEITEM hItem; | ||
| 72 | UINT state; | ||
| 73 | UINT stateMask; | ||
| 74 | LPSTR pszText; | ||
| 75 | int cchTextMax; | ||
| 76 | int iImage; | ||
| 77 | int iSelectedImage; | ||
| 78 | int cChildren; | ||
| 79 | LPARAM lParam; | ||
| 80 | } TVITEM, * LPTVITEM; | ||
| 81 | |||
| 82 | typedef struct tagNMTREEVIEW { | ||
| 83 | NMHDR hdr; | ||
| 84 | UINT action; | ||
| 85 | TVITEM itemOld; | ||
| 86 | TVITEM itemNew; | ||
| 87 | POINT ptDrag; | ||
| 88 | } NMTREEVIEW, * LPNMTREEVIEW; | ||
| 89 | |||
| 90 | #define WM_NOTIFY 0x004E | ||
| 91 | #define TV_FIRST 0x1100 // TreeView messages | ||
| 92 | #define TVHT_NOWHERE 0x0001 | ||
| 93 | #define TVHT_ONITEMICON 0x0002 | ||
| 94 | #define TVHT_ONITEMLABEL 0x0004 | ||
| 95 | #define TVHT_ONITEMSTATEICON 0x0040 | ||
| 96 | #define TVHT_ONITEM (TVHT_ONITEMICON | TVHT_ONITEMLABEL | TVHT_ONITEMSTATEICON) | ||
| 97 | #define TVHT_ONITEMINDENT 0x0008 | ||
| 98 | #define TVHT_ONITEMBUTTON 0x0010 | ||
| 99 | #define TVHT_ONITEMRIGHT 0x0020 | ||
| 100 | #define TVHT_ONITEMSTATEICON 0x0040 | ||
| 101 | |||
| 102 | #define TVHT_ABOVE 0x0100 | ||
| 103 | #define TVHT_BELOW 0x0200 | ||
| 104 | #define TVHT_TORIGHT 0x0400 | ||
| 105 | #define TVHT_TOLEFT 0x0800 | ||
| 106 | |||
| 107 | #define TVGN_ROOT 0x0000 | ||
| 108 | #define TVGN_NEXT 0x0001 | ||
| 109 | #define TVGN_PREVIOUS 0x0002 | ||
| 110 | #define TVGN_PARENT 0x0003 | ||
| 111 | #define TVGN_CHILD 0x0004 | ||
| 112 | #define TVGN_FIRSTVISIBLE 0x0005 | ||
| 113 | #define TVGN_NEXTVISIBLE 0x0006 | ||
| 114 | #define TVGN_PREVIOUSVISIBLE 0x0007 | ||
| 115 | #define TVGN_DROPHILITE 0x0008 | ||
| 116 | #define TVGN_CARET 0x0009 | ||
| 117 | #define TVGN_LASTVISIBLE 0x000A | ||
| 118 | |||
| 119 | #define TVS_HASBUTTONS 0x0001 | ||
| 120 | #define TVS_HASLINES 0x0002 | ||
| 121 | #define TVS_LINESATROOT 0x0004 | ||
| 122 | #define TVS_EDITLABELS 0x0008 | ||
| 123 | #define TVS_DISABLEDRAGDROP 0x0010 | ||
| 124 | #define TVS_SHOWSELALWAYS 0x0020 | ||
| 125 | #define TVS_RTLREADING 0x0040 | ||
| 126 | |||
| 127 | #define TVS_NOTOOLTIPS 0x0080 | ||
| 128 | #define TVS_CHECKBOXES 0x0100 | ||
| 129 | #define TVS_TRACKSELECT 0x0200 | ||
| 130 | #define TVS_SINGLEEXPAND 0x0400 | ||
| 131 | #define TVS_INFOTIP 0x0800 | ||
| 132 | #define TVS_FULLROWSELECT 0x1000 | ||
| 133 | #define TVS_NOSCROLL 0x2000 | ||
| 134 | #define TVS_NONEVENHEIGHT 0x4000 | ||
| 135 | #define TVS_NOHSCROLL 0x8000 | ||
| 136 | |||
| 137 | #define TVE_COLLAPSE 0x0001 | ||
| 138 | #define TVE_EXPAND 0x0002 | ||
| 139 | #define TVE_TOGGLE 0x0003 | ||
| 140 | #define TVE_EXPANDPARTIAL 0x4000 | ||
| 141 | #define TVE_COLLAPSERESET 0x8000 | ||
| 142 | |||
| 143 | #define TVN_FIRST (0U-400U) // treeview | ||
| 144 | #define TVN_LAST (0U-499U) | ||
| 145 | #define TVN_SELCHANGED (TVN_FIRST-2) | ||
| 146 | |||
| 147 | #define WC_TREEVIEW "SysTreeView" | ||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | #define TVM_SELECTITEM (TV_FIRST + 11) | ||
| 152 | #define TreeView_Select(hwnd, hitem, code) \ | ||
| 153 | (BOOL)SendMessage((hwnd), TVM_SELECTITEM, (WPARAM)(code), (LPARAM)(HTREEITEM)(hitem)) | ||
| 154 | |||
| 155 | |||
| 156 | #define TreeView_SelectItem(hwnd, hitem) TreeView_Select(hwnd, hitem, TVGN_CARET) | ||
| 157 | #define TreeView_SelectDropTarget(hwnd, hitem) TreeView_Select(hwnd, hitem, TVGN_DROPHILITE) | ||
| 158 | #define TreeView_SelectSetFirstVisible(hwnd, hitem) TreeView_Select(hwnd, hitem, TVGN_FIRSTVISIBLE) | ||
| 159 | |||
| 160 | #define TVM_HITTEST (TV_FIRST + 17) | ||
| 161 | #define TreeView_HitTest(hwnd, lpht) \ | ||
| 162 | (HTREEITEM)SendMessage((hwnd), TVM_HITTEST, 0, (LPARAM)(LPTV_HITTESTINFO)(lpht)) | ||
| 163 | |||
| 164 | #define LPTV_HITTESTINFO LPTVHITTESTINFO | ||
| 165 | |||
| 166 | #define TVM_INSERTITEM (TV_FIRST + 0) | ||
| 167 | #define TreeView_InsertItem(hwnd, lpis) \ | ||
| 168 | (HTREEITEM)SendMessage((hwnd), TVM_INSERTITEM, 0, (LPARAM)(LPTV_INSERTSTRUCT)(lpis)) | ||
| 169 | |||
| 170 | |||
| 171 | #define TVM_DELETEITEM (TV_FIRST + 1) | ||
| 172 | #define TreeView_DeleteItem(hwnd, hitem) \ | ||
| 173 | (BOOL)SendMessage((hwnd), TVM_DELETEITEM, 0, (LPARAM)(HTREEITEM)(hitem)) | ||
| 174 | |||
| 175 | |||
| 176 | #define TreeView_DeleteAllItems(hwnd) \ | ||
| 177 | (BOOL)SendMessage((hwnd), TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT) | ||
| 178 | |||
| 179 | |||
| 180 | #define TVM_EXPAND (TV_FIRST + 2) | ||
| 181 | #define TreeView_Expand(hwnd, hitem, code) \ | ||
| 182 | (BOOL)SendMessage((hwnd), TVM_EXPAND, (WPARAM)(code), (LPARAM)(HTREEITEM)(hitem)) | ||
| 183 | |||
| 184 | #define TVM_GETNEXTITEM (TV_FIRST + 10) | ||
| 185 | #define TreeView_GetNextItem(hwnd, hitem, code) \ | ||
| 186 | (HTREEITEM)SendMessage((hwnd), TVM_GETNEXTITEM, (WPARAM)(code), (LPARAM)(HTREEITEM)(hitem)) | ||
| 187 | |||
| 188 | #define TVM_GETITEM (TV_FIRST + 12) | ||
| 189 | #define TreeView_GetItem(hwnd, pitem) \ | ||
| 190 | (BOOL)SendMessage((hwnd), TVM_GETITEM, 0, (LPARAM)(TV_ITEM *)(pitem)) | ||
| 191 | |||
| 192 | #define TVM_SETITEM (TV_FIRST + 13) | ||
| 193 | #define TreeView_SetItem(hwnd, pitem) \ | ||
| 194 | (BOOL)SendMessage((hwnd), TVM_SETITEM, 0, (LPARAM)(const TV_ITEM *)(pitem)) | ||
| 195 | |||
| 196 | |||
| 197 | #define TreeView_GetChild(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_CHILD) | ||
| 198 | #define TreeView_GetNextSibling(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_NEXT) | ||
| 199 | #define TreeView_GetPrevSibling(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_PREVIOUS) | ||
| 200 | #define TreeView_GetParent(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_PARENT) | ||
| 201 | #define TreeView_GetFirstVisible(hwnd) TreeView_GetNextItem(hwnd, NULL, TVGN_FIRSTVISIBLE) | ||
| 202 | #define TreeView_GetNextVisible(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_NEXTVISIBLE) | ||
| 203 | #define TreeView_GetPrevVisible(hwnd, hitem) TreeView_GetNextItem(hwnd, hitem, TVGN_PREVIOUSVISIBLE) | ||
| 204 | #define TreeView_GetSelection(hwnd) TreeView_GetNextItem(hwnd, NULL, TVGN_CARET) | ||
| 205 | #define TreeView_GetDropHilight(hwnd) TreeView_GetNextItem(hwnd, NULL, TVGN_DROPHILITE) | ||
| 206 | #define TreeView_GetRoot(hwnd) TreeView_GetNextItem(hwnd, NULL, TVGN_ROOT) | ||
| 207 | #define TreeView_GetLastVisible(hwnd) TreeView_GetNextItem(hwnd, NULL, TVGN_LASTVISIBLE) | ||
| 208 | |||
| 209 | |||
| 210 | typedef struct tagTVINSERTSTRUCT { | ||
| 211 | HTREEITEM hParent; | ||
| 212 | HTREEITEM hInsertAfter; | ||
| 213 | TV_ITEM item; | ||
| 214 | } TVINSERTSTRUCT, * LPTVINSERTSTRUCT; | ||
| 215 | |||
| 216 | #define TV_INSERTSTRUCT TVINSERTSTRUCT | ||
| 217 | #define LPTV_INSERTSTRUCT LPTVINSERTSTRUCT | ||
| 218 | |||
| 219 | #define TVIF_TEXT 0x0001 | ||
| 220 | #define TVIF_IMAGE 0x0002 | ||
| 221 | #define TVIF_PARAM 0x0004 | ||
| 222 | #define TVIF_STATE 0x0008 | ||
| 223 | #define TVIF_HANDLE 0x0010 | ||
| 224 | #define TVIF_SELECTEDIMAGE 0x0020 | ||
| 225 | #define TVIF_CHILDREN 0x0040 | ||
| 226 | #define TVIF_INTEGRAL 0x0080 | ||
| 227 | |||
| 228 | #define TVIS_SELECTED 0x0002 | ||
| 229 | #define TVIS_CUT 0x0004 | ||
| 230 | #define TVIS_DROPHILITED 0x0008 | ||
| 231 | #define TVIS_BOLD 0x0010 | ||
| 232 | #define TVIS_EXPANDED 0x0020 | ||
| 233 | #define TVIS_EXPANDEDONCE 0x0040 | ||
| 234 | #define TVIS_EXPANDPARTIAL 0x0080 | ||
| 235 | |||
| 236 | #define TVIS_OVERLAYMASK 0x0F00 | ||
| 237 | #define TVIS_STATEIMAGEMASK 0xF000 | ||
| 238 | #define TVIS_USERMASK 0xF000 | ||
| 239 | |||
| 240 | #define TVI_ROOT ((HTREEITEM)(ULONG_PTR)-0x10000) | ||
| 241 | #define TVI_FIRST ((HTREEITEM)(ULONG_PTR)-0x0FFFF) | ||
| 242 | #define TVI_LAST ((HTREEITEM)(ULONG_PTR)-0x0FFFE) | ||
| 243 | #define TVI_SORT ((HTREEITEM)(ULONG_PTR)-0x0FFFD) | ||
| 244 | |||
| 245 | |||
| 246 | #else /* GATE_SYS_WIN16 */ | ||
| 247 | #include <commctrl.h> | ||
| 248 | #endif | ||
| 249 | |||
| 250 | |||
| 251 | |||
| 252 | static COLORREF gate_ui_treeview_get_bk_color(gate_ui_ctrl_t* ctrl) | ||
| 253 | { | ||
| 254 | gate_ui_host_t* host = GATE_UI_WINAPI_GET_HOST(ctrl); | ||
| 255 | gate_color_t color; | ||
| 256 | gate_ui_host_default_color(host, GATE_UI_COLOR_CONTENTBACKGROUND, &color); | ||
| 257 | return RGB(color.r, color.g, color.b); | ||
| 258 | } | ||
| 259 | |||
| 260 | static COLORREF gate_ui_treeview_get_text_color(gate_ui_ctrl_t* ctrl) | ||
| 261 | { | ||
| 262 | gate_ui_host_t* host = GATE_UI_WINAPI_GET_HOST(ctrl); | ||
| 263 | gate_color_t color; | ||
| 264 | gate_ui_host_default_color(host, GATE_UI_COLOR_CONTENTTEXT, &color); | ||
| 265 | return RGB(color.r, color.g, color.b); | ||
| 266 | } | ||
| 267 | |||
| 268 | |||
| 269 | static void gate_ui_treeview_update_colors(gate_ui_ctrl_t* ctrl) | ||
| 270 | { | ||
| 271 | #if !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WIN16) | ||
| 272 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 273 | COLORREF colref_bk = gate_ui_treeview_get_bk_color(ctrl); | ||
| 274 | COLORREF colref_text = gate_ui_treeview_get_text_color(ctrl); | ||
| 275 | |||
| 276 | if ((TreeView_GetBkColor(hwnd) != colref_bk) || (TreeView_GetTextColor(hwnd) != colref_text)) | ||
| 277 | { | ||
| 278 | TreeView_SetBkColor(hwnd, colref_bk); | ||
| 279 | TreeView_SetTextColor(hwnd, colref_text); | ||
| 280 | } | ||
| 281 | #endif /* !GATE_SYS_WINCE */ | ||
| 282 | } | ||
| 283 | |||
| 284 | static gate_bool_t gate_ui_treeview_events(void* hwnd, gate_ui_ctrl_t* ctrl, gate_uint32_t msg, gate_uintptr_t wParam, gate_intptr_t lParam, gate_intptr_t* lresult) | ||
| 285 | { | ||
| 286 | HWND hwndCtrl; | ||
| 287 | gate_ui_treeview_t* trvw; | ||
| 288 | |||
| 289 | if ((ctrl) && (hwnd)) | ||
| 290 | { | ||
| 291 | trvw = (gate_ui_treeview_t*)ctrl; | ||
| 292 | hwndCtrl = GATE_UI_WINAPI_GET_HWND(ctrl); | ||
| 293 | |||
| 294 | if (hwndCtrl) | ||
| 295 | { | ||
| 296 | switch (msg) | ||
| 297 | { | ||
| 298 | case WM_ERASEBKGND: | ||
| 299 | { | ||
| 300 | HDC hdc = (HDC)wParam; | ||
| 301 | RECT rect; | ||
| 302 | BOOL succeeded = TRUE; | ||
| 303 | gate_ui_treeview_update_colors(ctrl); | ||
| 304 | #if !defined(GATE_SYS_WIN16) | ||
| 305 | succeeded = | ||
| 306 | #endif | ||
| 307 | GetClientRect(hwndCtrl, &rect); | ||
| 308 | if (succeeded) | ||
| 309 | { | ||
| 310 | HBRUSH hbrush = CreateSolidBrush(gate_ui_treeview_get_bk_color(ctrl)); | ||
| 311 | if (hbrush) | ||
| 312 | { | ||
| 313 | FillRect(hdc, &rect, hbrush); | ||
| 314 | DeleteObject((HGDIOBJ)hbrush); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | *lresult = 1; | ||
| 318 | return true; | ||
| 319 | } | ||
| 320 | case WM_LBUTTONDBLCLK: | ||
| 321 | { | ||
| 322 | HTREEITEM hItem; | ||
| 323 | TV_HITTESTINFO hti; | ||
| 324 | hti.flags = TVHT_ONITEM; | ||
| 325 | hti.hItem = NULL; | ||
| 326 | hti.pt.x = (LONG)LOWORD(lParam); | ||
| 327 | hti.pt.y = (LONG)HIWORD(lParam); | ||
| 328 | hItem = TreeView_HitTest(hwndCtrl, &hti); | ||
| 329 | if (hItem != NULL) | ||
| 330 | { | ||
| 331 | if (trvw->on_dblclick != NULL) | ||
| 332 | { | ||
| 333 | trvw->on_dblclick(&trvw->ctrl, (gate_ui_treeview_item_t)hItem); | ||
| 334 | } | ||
| 335 | } | ||
| 336 | *lresult = 0; | ||
| 337 | return true; | ||
| 338 | } | ||
| 339 | case WM_RBUTTONDOWN: | ||
| 340 | { | ||
| 341 | HTREEITEM hItem; | ||
| 342 | TV_HITTESTINFO hti; | ||
| 343 | hti.flags = TVHT_ONITEM; | ||
| 344 | hti.hItem = NULL; | ||
| 345 | hti.pt.x = (LONG)LOWORD(lParam); | ||
| 346 | hti.pt.y = (LONG)HIWORD(lParam); | ||
| 347 | hItem = TreeView_HitTest(hwndCtrl, &hti); | ||
| 348 | if (hItem != NULL) | ||
| 349 | { | ||
| 350 | if (trvw->on_contextmenu != NULL) | ||
| 351 | { | ||
| 352 | TreeView_SelectDropTarget(hwndCtrl, hItem); | ||
| 353 | trvw->on_contextmenu(&trvw->ctrl, (gate_ui_treeview_item_t)hItem); | ||
| 354 | TreeView_SelectDropTarget(hwndCtrl, NULL); | ||
| 355 | } | ||
| 356 | } | ||
| 357 | *lresult = 0; | ||
| 358 | return true; | ||
| 359 | } | ||
| 360 | case WM_NOTIFY: | ||
| 361 | { | ||
| 362 | NMHDR* nmhdr = (NMHDR*)lParam; | ||
| 363 | if (nmhdr->hwndFrom == hwndCtrl) | ||
| 364 | { | ||
| 365 | switch (nmhdr->code) | ||
| 366 | { | ||
| 367 | case TVN_SELCHANGED: | ||
| 368 | { | ||
| 369 | NMTREEVIEW* nmtv = (NMTREEVIEW*)nmhdr; | ||
| 370 | trvw->on_select(&trvw->ctrl, (gate_ui_treeview_item_t)nmtv->itemNew.hItem); | ||
| 371 | *lresult = 0; | ||
| 372 | return true; | ||
| 373 | } | ||
| 374 | } | ||
| 375 | } | ||
| 376 | break; | ||
| 377 | } | ||
| 378 | default: | ||
| 379 | { | ||
| 380 | break; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | } | ||
| 384 | } | ||
| 385 | return false; | ||
| 386 | } | ||
| 387 | |||
| 388 | gate_result_t gate_ui_treeview_create( | ||
| 389 | gate_ui_treeview_t* trvw, gate_ui_ctrl_t* parent, | ||
| 390 | gate_ui_position_t const* position, | ||
| 391 | gate_uint32_t flags, | ||
| 392 | void* userparam | ||
| 393 | ) | ||
| 394 | { | ||
| 395 | gate_result_t ret; | ||
| 396 | |||
| 397 | do | ||
| 398 | { | ||
| 399 | gate_uint32_t styles = WS_CHILD | WS_CLIPSIBLINGS | WS_TABSTOP | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS; | ||
| 400 | gate_uint32_t exstyles = 0; | ||
| 401 | HWND hwndParent; | ||
| 402 | gate_ui_host_t* host = gate_ui_ctrl_get_host(parent); | ||
| 403 | |||
| 404 | if (host == NULL) | ||
| 405 | { | ||
| 406 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 407 | break; | ||
| 408 | } | ||
| 409 | hwndParent = GATE_UI_WINAPI_GET_HWND(parent); | ||
| 410 | if (hwndParent == NULL) | ||
| 411 | { | ||
| 412 | ret = GATE_RESULT_INVALIDSTATE; | ||
| 413 | break; | ||
| 414 | } | ||
| 415 | |||
| 416 | gate_mem_clear(trvw, sizeof(gate_ui_treeview_t)); | ||
| 417 | |||
| 418 | #if !defined(GATE_SYS_WIN16) | ||
| 419 | exstyles |= WS_EX_CLIENTEDGE; | ||
| 420 | #endif | ||
| 421 | |||
| 422 | if (!GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_ENABLED)) styles |= WS_DISABLED; | ||
| 423 | if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_VISIBLE)) styles |= WS_VISIBLE; | ||
| 424 | |||
| 425 | ret = gate_ui_winapi_create(&trvw->ctrl, host, hwndParent, WC_TREEVIEW, position, styles, exstyles, NULL, userparam, true); | ||
| 426 | if (GATE_SUCCEEDED(ret)) | ||
| 427 | { | ||
| 428 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 429 | |||
| 430 | #if !defined(GATE_SYS_WIN16) | ||
| 431 | if (GATE_FLAG_ENABLED(flags, GATE_UI_FLAG_TREEVIEW_ICONS)) | ||
| 432 | { | ||
| 433 | ret = gate_ui_iconlist_create(&trvw->icons, host, 16, 16); | ||
| 434 | if (GATE_FAILED(ret)) | ||
| 435 | { | ||
| 436 | gate_ui_winapi_destroy(&trvw->ctrl); | ||
| 437 | break; | ||
| 438 | } | ||
| 439 | TreeView_SetImageList(hwnd, (HIMAGELIST)trvw->icons.resources[0], TVSIL_NORMAL); | ||
| 440 | } | ||
| 441 | #endif | ||
| 442 | gate_ui_winapi_register_event(host, hwndParent, WM_NOTIFY, &gate_ui_treeview_events, &trvw->ctrl); | ||
| 443 | gate_ui_winapi_register_event(host, hwnd, WM_RBUTTONDOWN, &gate_ui_treeview_events, &trvw->ctrl); | ||
| 444 | gate_ui_winapi_register_event(host, hwnd, WM_LBUTTONDBLCLK, &gate_ui_treeview_events, &trvw->ctrl); | ||
| 445 | gate_ui_winapi_register_event(host, hwnd, WM_ERASEBKGND, &gate_ui_treeview_events, &trvw->ctrl); | ||
| 446 | |||
| 447 | gate_ui_treeview_update_colors(&trvw->ctrl); | ||
| 448 | gate_ui_winapi_refresh(&trvw->ctrl); | ||
| 449 | } | ||
| 450 | } while (0); | ||
| 451 | |||
| 452 | return ret; | ||
| 453 | } | ||
| 454 | |||
| 455 | gate_result_t gate_ui_treeview_add_icon(gate_ui_treeview_t* trvw, gate_ui_icon_t const* icon, gate_intptr_t* icon_key) | ||
| 456 | { | ||
| 457 | return gate_ui_iconlist_add(&trvw->icons, icon, icon_key); | ||
| 458 | } | ||
| 459 | |||
| 460 | gate_result_t gate_ui_treeview_add_icon_image(gate_ui_treeview_t* trvw, gate_rasterimage_t const* image, gate_intptr_t* icon_key) | ||
| 461 | { | ||
| 462 | return gate_ui_iconlist_add_image(&trvw->icons, image, icon_key); | ||
| 463 | } | ||
| 464 | |||
| 465 | gate_result_t gate_ui_treeview_add(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t const* parent, gate_string_t const* text, | ||
| 466 | gate_intptr_t iconkey, void* itemparam, gate_ui_treeview_item_t* newitem) | ||
| 467 | { | ||
| 468 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 469 | TVINSERTSTRUCT insert; | ||
| 470 | HTREEITEM newtreeitem; | ||
| 471 | TCHAR txtbuffer[4096]; | ||
| 472 | gate_size_t txtbufferused = gate_win32_utf8_2_winstr(text->str, text->length, txtbuffer, sizeof(txtbuffer) / sizeof(txtbuffer[0])); | ||
| 473 | gate_mem_clear(&insert, sizeof(insert)); | ||
| 474 | insert.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_STATE; | ||
| 475 | insert.item.pszText = &txtbuffer[0]; | ||
| 476 | insert.item.cchTextMax = (int)txtbufferused; | ||
| 477 | insert.item.stateMask = TVIS_SELECTED; | ||
| 478 | insert.item.lParam = (LPARAM)(gate_intptr_t)itemparam; | ||
| 479 | if (parent == NULL) | ||
| 480 | { | ||
| 481 | insert.hParent = NULL; | ||
| 482 | insert.hInsertAfter = TVI_ROOT; | ||
| 483 | } | ||
| 484 | else | ||
| 485 | { | ||
| 486 | insert.hParent = (HTREEITEM)*parent; | ||
| 487 | insert.hInsertAfter = TVI_LAST; | ||
| 488 | } | ||
| 489 | if (trvw->icons.resources[0] != NULL) | ||
| 490 | { | ||
| 491 | if (iconkey != GATE_UI_TREEVIEW_INVALID_ICON) | ||
| 492 | { | ||
| 493 | insert.item.iImage = (int)iconkey; | ||
| 494 | insert.item.iSelectedImage = (int)iconkey; | ||
| 495 | insert.item.mask |= (TVIF_IMAGE | TVIF_SELECTEDIMAGE); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | newtreeitem = TreeView_InsertItem(hwnd, &insert); | ||
| 500 | if (newtreeitem) | ||
| 501 | { | ||
| 502 | *newitem = (gate_ui_treeview_item_t)newtreeitem; | ||
| 503 | return GATE_RESULT_OK; | ||
| 504 | } | ||
| 505 | else | ||
| 506 | { | ||
| 507 | return GATE_RESULT_FAILED; | ||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | gate_result_t gate_ui_treeview_remove(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 512 | { | ||
| 513 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 514 | if (TreeView_DeleteItem(hwnd, (HTREEITEM)item)) | ||
| 515 | { | ||
| 516 | return GATE_RESULT_OK; | ||
| 517 | } | ||
| 518 | else | ||
| 519 | { | ||
| 520 | return GATE_RESULT_FAILED; | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 524 | gate_result_t gate_ui_treeview_clear(gate_ui_treeview_t* trvw) | ||
| 525 | { | ||
| 526 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 527 | if (TreeView_DeleteAllItems(hwnd)) | ||
| 528 | { | ||
| 529 | return GATE_RESULT_OK; | ||
| 530 | } | ||
| 531 | else | ||
| 532 | { | ||
| 533 | return GATE_RESULT_FAILED; | ||
| 534 | } | ||
| 535 | } | ||
| 536 | |||
| 537 | void* gate_ui_treeview_get_itemparam(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 538 | { | ||
| 539 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 540 | TVITEM tvitem; | ||
| 541 | gate_mem_clear(&tvitem, sizeof(tvitem)); | ||
| 542 | tvitem.hItem = (HTREEITEM)item; | ||
| 543 | tvitem.mask = TVIF_PARAM; | ||
| 544 | if (TreeView_GetItem(hwnd, &tvitem)) | ||
| 545 | { | ||
| 546 | return (void*)(gate_intptr_t)tvitem.lParam; | ||
| 547 | } | ||
| 548 | return NULL; | ||
| 549 | } | ||
| 550 | |||
| 551 | |||
| 552 | gate_result_t gate_ui_treeview_get_parent(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_ui_treeview_item_t* parent) | ||
| 553 | { | ||
| 554 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 555 | HTREEITEM parentItem = TreeView_GetParent(hwnd, (HTREEITEM)item); | ||
| 556 | if (parentItem == NULL) | ||
| 557 | { | ||
| 558 | return GATE_RESULT_NOTAVAILABLE; | ||
| 559 | } | ||
| 560 | else | ||
| 561 | { | ||
| 562 | *parent = (gate_ui_treeview_item_t)parentItem; | ||
| 563 | return GATE_RESULT_OK; | ||
| 564 | } | ||
| 565 | } | ||
| 566 | gate_result_t gate_ui_treeview_get_children(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_array_t* children) | ||
| 567 | { | ||
| 568 | gate_result_t ret; | ||
| 569 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 570 | HTREEITEM child = TreeView_GetChild(hwnd, (HTREEITEM)item); | ||
| 571 | TVITEM itemdata; | ||
| 572 | gate_arraylist_t itemlist; | ||
| 573 | gate_size_t prealloc = 0; | ||
| 574 | gate_ui_treeview_item_t nextitem; | ||
| 575 | if (child != NULL) | ||
| 576 | { | ||
| 577 | gate_mem_clear(&itemdata, sizeof(itemdata)); | ||
| 578 | itemdata.hItem = (HTREEITEM)item; | ||
| 579 | itemdata.mask = TVIF_CHILDREN; | ||
| 580 | if (TreeView_GetItem(hwnd, &itemdata)) | ||
| 581 | { | ||
| 582 | prealloc = itemdata.cChildren; | ||
| 583 | } | ||
| 584 | } | ||
| 585 | itemlist = gate_arraylist_create(sizeof(gate_ui_treeview_item_t), NULL, prealloc, NULL, NULL); | ||
| 586 | if (!itemlist) | ||
| 587 | { | ||
| 588 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 589 | } | ||
| 590 | else | ||
| 591 | { | ||
| 592 | ret = GATE_RESULT_OK; | ||
| 593 | while (child != NULL) | ||
| 594 | { | ||
| 595 | nextitem = (gate_ui_treeview_item_t)child; | ||
| 596 | if (NULL == gate_arraylist_add(itemlist, &nextitem)) | ||
| 597 | { | ||
| 598 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 599 | break; | ||
| 600 | } | ||
| 601 | child = TreeView_GetNextItem(hwnd, child, TVGN_NEXT); | ||
| 602 | } | ||
| 603 | if (GATE_SUCCEEDED(ret)) | ||
| 604 | { | ||
| 605 | if (NULL == gate_array_create(children, itemlist)) | ||
| 606 | { | ||
| 607 | ret = GATE_RESULT_FAILED; | ||
| 608 | } | ||
| 609 | } | ||
| 610 | gate_arraylist_release(itemlist); | ||
| 611 | } | ||
| 612 | return ret; | ||
| 613 | } | ||
| 614 | gate_result_t gate_ui_treeview_get_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t* text) | ||
| 615 | { | ||
| 616 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 617 | TCHAR buffer[4096]; | ||
| 618 | TVITEM tvitem; | ||
| 619 | gate_mem_clear(&tvitem, sizeof(tvitem)); | ||
| 620 | tvitem.hItem = (HTREEITEM)item; | ||
| 621 | tvitem.mask = TVIF_TEXT; | ||
| 622 | tvitem.pszText = &buffer[0]; | ||
| 623 | tvitem.cchTextMax = sizeof(buffer) / sizeof(buffer[0]); | ||
| 624 | if (TreeView_GetItem(hwnd, &tvitem)) | ||
| 625 | { | ||
| 626 | if (NULL != gate_win32_winstr_2_utf8_string(buffer, tvitem.cchTextMax, text)) | ||
| 627 | { | ||
| 628 | return GATE_RESULT_OK; | ||
| 629 | } | ||
| 630 | } | ||
| 631 | return GATE_RESULT_FAILED; | ||
| 632 | } | ||
| 633 | gate_result_t gate_ui_treeview_set_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t const* text) | ||
| 634 | { | ||
| 635 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 636 | TCHAR buffer[4096]; | ||
| 637 | TVITEM tvitem; | ||
| 638 | gate_mem_clear(&tvitem, sizeof(tvitem)); | ||
| 639 | tvitem.hItem = (HTREEITEM)item; | ||
| 640 | tvitem.mask = TVIF_TEXT; | ||
| 641 | tvitem.pszText = &buffer[0]; | ||
| 642 | tvitem.cchTextMax = (int)gate_win32_utf8_2_winstr(text->str, text->length, buffer, sizeof(buffer) / sizeof(buffer[0])); | ||
| 643 | if (TreeView_SetItem(hwnd, &tvitem)) | ||
| 644 | { | ||
| 645 | return GATE_RESULT_OK; | ||
| 646 | } | ||
| 647 | return GATE_RESULT_FAILED; | ||
| 648 | } | ||
| 649 | |||
| 650 | gate_bool_t gate_ui_treeview_is_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 651 | { | ||
| 652 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 653 | TVITEM tvitem; | ||
| 654 | gate_mem_clear(&tvitem, sizeof(tvitem)); | ||
| 655 | tvitem.hItem = (HTREEITEM)item; | ||
| 656 | tvitem.mask = TVIF_STATE; | ||
| 657 | tvitem.stateMask = TVIS_EXPANDED; | ||
| 658 | tvitem.state = 0; | ||
| 659 | if (TreeView_GetItem(hwnd, &tvitem)) | ||
| 660 | { | ||
| 661 | return (tvitem.state & TVIS_EXPANDED) == TVIS_EXPANDED; | ||
| 662 | } | ||
| 663 | return false; | ||
| 664 | } | ||
| 665 | gate_result_t gate_ui_treeview_set_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_bool_t expanded) | ||
| 666 | { | ||
| 667 | if (gate_ui_treeview_is_expanded(trvw, item) != expanded) | ||
| 668 | { | ||
| 669 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 670 | if (TreeView_Expand(hwnd, (HTREEITEM)item, expanded ? TVE_EXPAND : TVE_COLLAPSE)) | ||
| 671 | { | ||
| 672 | return GATE_RESULT_OK; | ||
| 673 | } | ||
| 674 | else | ||
| 675 | { | ||
| 676 | return GATE_RESULT_FAILED; | ||
| 677 | } | ||
| 678 | } | ||
| 679 | return GATE_RESULT_OK; | ||
| 680 | } | ||
| 681 | |||
| 682 | gate_result_t gate_ui_treeview_get_selected_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t* item) | ||
| 683 | { | ||
| 684 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 685 | HTREEITEM hitem = TreeView_GetSelection(hwnd); | ||
| 686 | if (hitem == NULL) | ||
| 687 | { | ||
| 688 | *item = (gate_ui_treeview_item_t)hitem; | ||
| 689 | return GATE_RESULT_OK; | ||
| 690 | } | ||
| 691 | else | ||
| 692 | { | ||
| 693 | return GATE_RESULT_NOMATCH; | ||
| 694 | } | ||
| 695 | } | ||
| 696 | |||
| 697 | gate_result_t gate_ui_treeview_select_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 698 | { | ||
| 699 | HWND hwnd = GATE_UI_WINAPI_GET_HWND(&trvw->ctrl); | ||
| 700 | if (TreeView_SelectItem(hwnd, (HTREEITEM)item)) | ||
| 701 | { | ||
| 702 | return GATE_RESULT_OK; | ||
| 703 | } | ||
| 704 | else | ||
| 705 | { | ||
| 706 | return GATE_RESULT_FAILED; | ||
| 707 | } | ||
| 708 | } | ||
| 709 | |||
| 710 | |||
| 711 | #endif /*GATE_UI_WINAPI*/ | ||
| 712 | |||
| 713 | |||
| 714 | |||
| 715 | #if defined(GATE_UI_GTK) | ||
| 716 | |||
| 717 | #include "gate/ui/gateui_gtk.h" | ||
| 718 | |||
| 719 | #define GATE_UI_GTK_TREEVIEW_FIELD_TEXT 0 | ||
| 720 | #define GATE_UI_GTK_TREEVIEW_FIELD_ID 1 | ||
| 721 | #define GATE_UI_GTK_TREEVIEW_FIELD_PARAM 2 | ||
| 722 | #define GATE_UI_GTK_TREEVIEW_FIELD_ICON 3 | ||
| 723 | |||
| 724 | static void gate_ui_gtk_treeview_on_cursor_changed(GtkTreeView* tree_view, gpointer user_data) | ||
| 725 | { | ||
| 726 | gate_ui_treeview_t* trvw = (gate_ui_treeview_t*)user_data; | ||
| 727 | gate_ui_treeview_item_t item; | ||
| 728 | gate_result_t result; | ||
| 729 | result = gate_ui_treeview_get_selected_item(trvw, &item); | ||
| 730 | if (GATE_SUCCEEDED(result)) | ||
| 731 | { | ||
| 732 | trvw->on_select(&trvw->ctrl, item); | ||
| 733 | } | ||
| 734 | else | ||
| 735 | { | ||
| 736 | trvw->on_select(&trvw->ctrl, GATE_UI_TREEVIEW_INVALID_ITEM); | ||
| 737 | } | ||
| 738 | } | ||
| 739 | |||
| 740 | static void gate_ui_gtk_treeview_on_destroy(GtkWidget* object, gpointer user_data) | ||
| 741 | { | ||
| 742 | gate_ui_treeview_t* trvw = (gate_ui_treeview_t*)user_data; | ||
| 743 | gate_ui_iconlist_destroy(&trvw->icons); | ||
| 744 | } | ||
| 745 | |||
| 746 | gate_result_t gate_ui_treeview_create(gate_ui_treeview_t* trvw, gate_ui_ctrl_t* parent, | ||
| 747 | gate_ui_position_t const* position, gate_uint32_t flags, void* userparam) | ||
| 748 | { | ||
| 749 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 750 | |||
| 751 | do | ||
| 752 | { | ||
| 753 | GtkWidget* widget; | ||
| 754 | GtkTreeViewColumn* col; | ||
| 755 | GtkCellRenderer* renderer; | ||
| 756 | GtkTreeModel* model; | ||
| 757 | /*GtkTreeStore* treestore;*/ | ||
| 758 | GtkWidget* scroll_widget; | ||
| 759 | gate_ui_host_t* host = GATE_UI_GTK_GET_CTRL_HOST(parent); | ||
| 760 | |||
| 761 | gate_mem_clear(trvw, sizeof(gate_ui_treeview_t)); | ||
| 762 | widget = gtk_tree_view_new(); | ||
| 763 | if (widget == NULL) | ||
| 764 | { | ||
| 765 | ret = GATE_RESULT_OUTOFRESOURCES; | ||
| 766 | break; | ||
| 767 | } | ||
| 768 | |||
| 769 | col = gtk_tree_view_column_new(); | ||
| 770 | gtk_tree_view_column_set_title(col, "Tree view"); | ||
| 771 | |||
| 772 | renderer = gtk_cell_renderer_pixbuf_new(); | ||
| 773 | gtk_tree_view_column_pack_start(col, renderer, FALSE); | ||
| 774 | gtk_tree_view_column_add_attribute(col, renderer, "pixbuf", GATE_UI_GTK_TREEVIEW_FIELD_ICON); | ||
| 775 | renderer = gtk_cell_renderer_text_new(); | ||
| 776 | gtk_tree_view_column_pack_start(col, renderer, FALSE); | ||
| 777 | gtk_tree_view_column_add_attribute(col, renderer, "text", GATE_UI_GTK_TREEVIEW_FIELD_TEXT); | ||
| 778 | |||
| 779 | model = GTK_TREE_MODEL(gtk_tree_store_new(4, | ||
| 780 | G_TYPE_STRING, /* text */ | ||
| 781 | G_TYPE_POINTER, /* item-id */ | ||
| 782 | G_TYPE_POINTER, /* item-param */ | ||
| 783 | GDK_TYPE_PIXBUF, /* icon */ | ||
| 784 | -1)); | ||
| 785 | |||
| 786 | gtk_tree_view_set_model(GTK_TREE_VIEW(widget), model); | ||
| 787 | g_object_unref(model); | ||
| 788 | |||
| 789 | gtk_tree_view_append_column(GTK_TREE_VIEW(widget), col); | ||
| 790 | |||
| 791 | scroll_widget = gtk_scrolled_window_new(NULL, NULL); | ||
| 792 | if (scroll_widget == NULL) | ||
| 793 | { | ||
| 794 | gtk_widget_destroy(widget); | ||
| 795 | ret = GATE_RESULT_OUTOFRESOURCES; | ||
| 796 | break; | ||
| 797 | } | ||
| 798 | |||
| 799 | gtk_container_add(GTK_CONTAINER(scroll_widget), widget); | ||
| 800 | gtk_widget_show(widget); | ||
| 801 | |||
| 802 | ret = gate_ui_gtk_ctrl_init(&trvw->ctrl, scroll_widget, host, userparam, parent, | ||
| 803 | NULL, false, false, position, &flags); | ||
| 804 | |||
| 805 | if (GATE_SUCCEEDED(ret)) | ||
| 806 | { | ||
| 807 | ret = gate_ui_iconlist_create(&trvw->icons, host, 16, 16); | ||
| 808 | if (GATE_FAILED(ret)) | ||
| 809 | { | ||
| 810 | gate_ui_gtk_ctrl_destroy(&trvw->ctrl); | ||
| 811 | break; | ||
| 812 | } | ||
| 813 | |||
| 814 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(widget), FALSE); | ||
| 815 | gtk_tree_view_set_show_expanders(GTK_TREE_VIEW(widget), TRUE); | ||
| 816 | |||
| 817 | g_signal_connect(G_OBJECT(widget), "cursor-changed", G_CALLBACK(gate_ui_gtk_treeview_on_cursor_changed), (gpointer)trvw); | ||
| 818 | g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gate_ui_gtk_treeview_on_destroy), (gpointer)trvw); | ||
| 819 | } | ||
| 820 | //cursor-changed | ||
| 821 | } while (0); | ||
| 822 | |||
| 823 | return ret; | ||
| 824 | } | ||
| 825 | |||
| 826 | gate_result_t gate_ui_treeview_add_icon(gate_ui_treeview_t* trvw, gate_ui_icon_t const* icon, gate_intptr_t* icon_key) | ||
| 827 | { | ||
| 828 | return gate_ui_iconlist_add(&trvw->icons, icon, icon_key); | ||
| 829 | } | ||
| 830 | |||
| 831 | gate_result_t gate_ui_treeview_add_icon_image(gate_ui_treeview_t* trvw, gate_rasterimage_t const* image, gate_intptr_t* icon_key) | ||
| 832 | { | ||
| 833 | return gate_ui_iconlist_add_image(&trvw->icons, image, icon_key); | ||
| 834 | } | ||
| 835 | |||
| 836 | static gate_atomic_int64_t gate_ui_treeview_item_id = 0; | ||
| 837 | |||
| 838 | static gate_bool_t gate_ui_treeview_resolve(GtkTreeModel* model, GtkTreeIter* current_iter, void* id, GtkTreeIter* found_iter) | ||
| 839 | { | ||
| 840 | GtkTreeIter first; | ||
| 841 | |||
| 842 | if (current_iter == NULL) | ||
| 843 | { | ||
| 844 | if (!gtk_tree_model_get_iter_first(model, &first)) | ||
| 845 | { | ||
| 846 | return false; | ||
| 847 | } | ||
| 848 | current_iter = &first; | ||
| 849 | } | ||
| 850 | do | ||
| 851 | { | ||
| 852 | GtkTreeIter first_child; | ||
| 853 | GValue value = GATE_INIT_EMPTY; | ||
| 854 | gtk_tree_model_get_value(model, current_iter, 1, &value); | ||
| 855 | if (g_value_get_pointer(&value) == id) | ||
| 856 | { | ||
| 857 | *found_iter = *current_iter; | ||
| 858 | return true; | ||
| 859 | } | ||
| 860 | g_value_unset(&value); | ||
| 861 | |||
| 862 | if (gtk_tree_model_iter_children(model, &first_child, current_iter)) | ||
| 863 | { | ||
| 864 | if (gate_ui_treeview_resolve(model, &first_child, id, found_iter)) | ||
| 865 | { | ||
| 866 | return true; | ||
| 867 | } | ||
| 868 | } | ||
| 869 | } while (gtk_tree_model_iter_next(model, current_iter)); | ||
| 870 | return false; | ||
| 871 | } | ||
| 872 | |||
| 873 | gate_result_t gate_ui_treeview_add(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t const* parent, gate_string_t const* text, | ||
| 874 | gate_intptr_t icon_key, void* itemparam, gate_ui_treeview_item_t* newitem) | ||
| 875 | { | ||
| 876 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 877 | |||
| 878 | do | ||
| 879 | { | ||
| 880 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 881 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 882 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 883 | GtkTreeStore* store = GTK_TREE_STORE(model); | ||
| 884 | GtkTreeIter tree_iter; | ||
| 885 | GtkTreeIter parent_iter; | ||
| 886 | gate_ui_treeview_item_t new_item_id = (gate_uintptr_t)gate_atomic_int64_inc(&gate_ui_treeview_item_id); | ||
| 887 | char textbuffer[4096]; | ||
| 888 | |||
| 889 | GATE_STRING_TO_BUFFER(text, textbuffer); | ||
| 890 | if (parent != NULL) | ||
| 891 | { | ||
| 892 | if (!gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)*parent, &parent_iter)) | ||
| 893 | { | ||
| 894 | ret = GATE_RESULT_NOMATCH; | ||
| 895 | break; | ||
| 896 | } | ||
| 897 | } | ||
| 898 | |||
| 899 | gtk_tree_store_append(store, &tree_iter, parent ? &parent_iter : NULL); | ||
| 900 | gtk_tree_store_set(store, &tree_iter, | ||
| 901 | GATE_UI_GTK_TREEVIEW_FIELD_TEXT, textbuffer, | ||
| 902 | GATE_UI_GTK_TREEVIEW_FIELD_ID, (void*)new_item_id, | ||
| 903 | GATE_UI_GTK_TREEVIEW_FIELD_PARAM, itemparam, | ||
| 904 | -1); | ||
| 905 | |||
| 906 | if (trvw->icons.resources[0] && (icon_key != GATE_UI_TREEVIEW_INVALID_ICON)) | ||
| 907 | { | ||
| 908 | gate_ui_icon_t const* ptr_icon = gate_arraylist_get((gate_arraylist_t)trvw->icons.resources[0], (gate_size_t)icon_key); | ||
| 909 | if (ptr_icon) | ||
| 910 | { | ||
| 911 | void* ptr_pixbuf = ptr_icon->resources[0]; | ||
| 912 | if (ptr_pixbuf) | ||
| 913 | { | ||
| 914 | gtk_tree_store_set(store, &tree_iter, GATE_UI_GTK_TREEVIEW_FIELD_ICON, ptr_pixbuf, -1); | ||
| 915 | } | ||
| 916 | } | ||
| 917 | } | ||
| 918 | |||
| 919 | if (newitem != NULL) | ||
| 920 | { | ||
| 921 | *newitem = new_item_id; | ||
| 922 | } | ||
| 923 | ret = GATE_RESULT_OK; | ||
| 924 | |||
| 925 | } while (0); | ||
| 926 | return ret; | ||
| 927 | } | ||
| 928 | void* gate_ui_treeview_get_itemparam(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 929 | { | ||
| 930 | void* ret = NULL; | ||
| 931 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 932 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 933 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 934 | GtkTreeIter iter_found; | ||
| 935 | |||
| 936 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &iter_found)) | ||
| 937 | { | ||
| 938 | GValue value = GATE_INIT_EMPTY; | ||
| 939 | gtk_tree_model_get_value(model, &iter_found, 2, &value); | ||
| 940 | ret = g_value_get_pointer(&value); | ||
| 941 | g_value_unset(&value); | ||
| 942 | } | ||
| 943 | |||
| 944 | /* error / unresolved case */ | ||
| 945 | return ret; | ||
| 946 | } | ||
| 947 | |||
| 948 | static void gate_ui_treeview_remove_recursive(GtkTreeModel* model, GtkTreeIter* current_iter) | ||
| 949 | { | ||
| 950 | GtkTreeIter item; | ||
| 951 | if (gtk_tree_model_iter_children(model, &item, current_iter)) | ||
| 952 | { | ||
| 953 | do | ||
| 954 | { | ||
| 955 | gate_ui_treeview_remove_recursive(model, &item); | ||
| 956 | } while (gtk_tree_model_iter_next(model, &item)); | ||
| 957 | } | ||
| 958 | |||
| 959 | item = *current_iter; | ||
| 960 | gtk_tree_store_remove(GTK_TREE_STORE(model), &item); | ||
| 961 | } | ||
| 962 | |||
| 963 | gate_result_t gate_ui_treeview_remove(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 964 | { | ||
| 965 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 966 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 967 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 968 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 969 | GtkTreeIter iter_found; | ||
| 970 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &iter_found)) | ||
| 971 | { | ||
| 972 | gate_ui_treeview_remove_recursive(model, &iter_found); | ||
| 973 | ret = GATE_RESULT_OK; | ||
| 974 | } | ||
| 975 | else | ||
| 976 | { | ||
| 977 | ret = GATE_RESULT_NOMATCH; | ||
| 978 | } | ||
| 979 | return ret; | ||
| 980 | } | ||
| 981 | gate_result_t gate_ui_treeview_clear(gate_ui_treeview_t* trvw) | ||
| 982 | { | ||
| 983 | gate_result_t ret = GATE_RESULT_OK; | ||
| 984 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 985 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 986 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 987 | gtk_tree_store_clear(GTK_TREE_STORE(model)); | ||
| 988 | return ret; | ||
| 989 | } | ||
| 990 | gate_result_t gate_ui_treeview_get_parent(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_ui_treeview_item_t* parent) | ||
| 991 | { | ||
| 992 | gate_result_t ret = GATE_RESULT_NOMATCH; | ||
| 993 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 994 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 995 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 996 | GtkTreeIter found_iter; | ||
| 997 | GtkTreeIter parent_iter; | ||
| 998 | GValue value = GATE_INIT_EMPTY; | ||
| 999 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1000 | { | ||
| 1001 | if (gtk_tree_model_iter_parent(model, &parent_iter, &found_iter)) | ||
| 1002 | { | ||
| 1003 | gtk_tree_model_get_value(model, &parent_iter, 1, &value); | ||
| 1004 | if (parent != NULL) | ||
| 1005 | { | ||
| 1006 | *parent = (gate_ui_treeview_item_t)(gate_uintptr_t)g_value_get_pointer(&value); | ||
| 1007 | } | ||
| 1008 | g_value_unset(&value); | ||
| 1009 | ret = GATE_RESULT_OK; | ||
| 1010 | } | ||
| 1011 | } | ||
| 1012 | return ret; | ||
| 1013 | } | ||
| 1014 | gate_result_t gate_ui_treeview_get_children(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_array_t* children) | ||
| 1015 | { | ||
| 1016 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 1017 | gate_arraylist_t arraylist = NULL; | ||
| 1018 | do | ||
| 1019 | { | ||
| 1020 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1021 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1022 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 1023 | GtkTreeIter found_iter; | ||
| 1024 | GtkTreeIter child_iter; | ||
| 1025 | GValue value = GATE_INIT_EMPTY; | ||
| 1026 | |||
| 1027 | arraylist = gate_arraylist_create(sizeof(gate_ui_treeview_item_t), NULL, 0, NULL, NULL); | ||
| 1028 | if (arraylist == NULL) | ||
| 1029 | { | ||
| 1030 | ret = GATE_RESULT_OUTOFMEMORY; | ||
| 1031 | break; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | if (item == 0) | ||
| 1035 | { | ||
| 1036 | if(!gtk_tree_model_get_iter_first(model, &found_iter)) | ||
| 1037 | { | ||
| 1038 | ret = GATE_RESULT_NOMATCH; | ||
| 1039 | break; | ||
| 1040 | } | ||
| 1041 | do | ||
| 1042 | { | ||
| 1043 | gate_ui_treeview_item_t child_item; | ||
| 1044 | GValue value = GATE_INIT_EMPTY; | ||
| 1045 | gtk_tree_model_get_value(model, &found_iter, 1, &value); | ||
| 1046 | child_item = (gate_ui_treeview_item_t)g_value_get_pointer(&value); | ||
| 1047 | g_value_unset(&value); | ||
| 1048 | gate_arraylist_add(arraylist, &child_item); | ||
| 1049 | |||
| 1050 | } while (gtk_tree_model_iter_next(model, &found_iter)); | ||
| 1051 | } | ||
| 1052 | else | ||
| 1053 | { | ||
| 1054 | if (!gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1055 | { | ||
| 1056 | ret = GATE_RESULT_NOMATCH; | ||
| 1057 | break; | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | if (gtk_tree_model_iter_children(model, &child_iter, &found_iter)) | ||
| 1061 | { | ||
| 1062 | do | ||
| 1063 | { | ||
| 1064 | void* ptr_value = NULL; | ||
| 1065 | gtk_tree_model_get_value(model, &child_iter, 1, &value); | ||
| 1066 | ptr_value = g_value_get_pointer(&value); | ||
| 1067 | gate_arraylist_add(arraylist, (void const*)&ptr_value); | ||
| 1068 | g_value_unset(&value); | ||
| 1069 | } while (gtk_tree_model_iter_next(model, &child_iter)); | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | if (NULL != gate_array_create(children, arraylist)) | ||
| 1074 | { | ||
| 1075 | ret = GATE_RESULT_OK; | ||
| 1076 | } | ||
| 1077 | } while (0); | ||
| 1078 | if (arraylist != NULL) | ||
| 1079 | { | ||
| 1080 | gate_arraylist_release(arraylist); | ||
| 1081 | } | ||
| 1082 | return ret; | ||
| 1083 | } | ||
| 1084 | gate_result_t gate_ui_treeview_get_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t* text) | ||
| 1085 | { | ||
| 1086 | gate_result_t ret = GATE_RESULT_NOMATCH; | ||
| 1087 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1088 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1089 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 1090 | GtkTreeIter found_iter; | ||
| 1091 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1092 | { | ||
| 1093 | GValue value = GATE_INIT_EMPTY; | ||
| 1094 | char const* text_buffer = NULL; | ||
| 1095 | gtk_tree_model_get_value(model, &found_iter, 0, &value); | ||
| 1096 | text_buffer = g_value_get_string(&value); | ||
| 1097 | if (NULL != gate_string_create(text, text_buffer, gate_str_length(text_buffer))) | ||
| 1098 | { | ||
| 1099 | ret = GATE_RESULT_OK; | ||
| 1100 | } | ||
| 1101 | g_value_unset(&value); | ||
| 1102 | } | ||
| 1103 | return ret; | ||
| 1104 | } | ||
| 1105 | gate_result_t gate_ui_treeview_set_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t const* text) | ||
| 1106 | { | ||
| 1107 | gate_result_t ret = GATE_RESULT_NOMATCH; | ||
| 1108 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1109 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1110 | GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 1111 | GtkTreeIter found_iter; | ||
| 1112 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1113 | { | ||
| 1114 | GValue value = GATE_INIT_EMPTY; | ||
| 1115 | gchar text_buffer[4096]; | ||
| 1116 | GATE_STRING_TO_BUFFER(text, text_buffer); | ||
| 1117 | g_value_init(&value, G_TYPE_STRING); | ||
| 1118 | g_value_set_string(&value, text_buffer); | ||
| 1119 | gtk_tree_store_set_value(GTK_TREE_STORE(model), &found_iter, 0, &value); | ||
| 1120 | g_value_unset(&value); | ||
| 1121 | ret = GATE_RESULT_OK; | ||
| 1122 | } | ||
| 1123 | return ret; | ||
| 1124 | } | ||
| 1125 | gate_bool_t gate_ui_treeview_is_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 1126 | { | ||
| 1127 | gate_result_t ret = false; | ||
| 1128 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1129 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1130 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
| 1131 | GtkTreeModel* model = gtk_tree_view_get_model(treeview); | ||
| 1132 | GtkTreeIter found_iter; | ||
| 1133 | |||
| 1134 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1135 | { | ||
| 1136 | GtkTreePath* path = gtk_tree_model_get_path(model, &found_iter); | ||
| 1137 | ret = gtk_tree_view_row_expanded(treeview, path); | ||
| 1138 | gtk_tree_path_free(path); | ||
| 1139 | } | ||
| 1140 | return ret; | ||
| 1141 | } | ||
| 1142 | gate_result_t gate_ui_treeview_set_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_bool_t expanded) | ||
| 1143 | { | ||
| 1144 | gate_result_t ret = GATE_RESULT_NOMATCH; | ||
| 1145 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1146 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1147 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
| 1148 | GtkTreeModel* model = gtk_tree_view_get_model(treeview); | ||
| 1149 | GtkTreeIter found_iter; | ||
| 1150 | |||
| 1151 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1152 | { | ||
| 1153 | GtkTreePath* path = gtk_tree_model_get_path(model, &found_iter); | ||
| 1154 | if (expanded) | ||
| 1155 | { | ||
| 1156 | gtk_tree_view_expand_to_path(treeview, path); | ||
| 1157 | } | ||
| 1158 | else | ||
| 1159 | { | ||
| 1160 | gtk_tree_view_collapse_row(treeview, path); | ||
| 1161 | } | ||
| 1162 | gtk_tree_path_free(path); | ||
| 1163 | ret = GATE_RESULT_OK; | ||
| 1164 | } | ||
| 1165 | return ret; | ||
| 1166 | } | ||
| 1167 | gate_result_t gate_ui_treeview_get_selected_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t* item) | ||
| 1168 | { | ||
| 1169 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 1170 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1171 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1172 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
| 1173 | GtkTreeModel* model = gtk_tree_view_get_model(treeview); | ||
| 1174 | GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); | ||
| 1175 | GtkTreeIter found_iter; | ||
| 1176 | |||
| 1177 | if (gtk_tree_selection_get_selected(selection, &model, &found_iter)) | ||
| 1178 | { | ||
| 1179 | GValue value = GATE_INIT_EMPTY; | ||
| 1180 | gtk_tree_model_get_value(model, &found_iter, 1, &value); | ||
| 1181 | *item = (gate_ui_treeview_item_t)(gate_uintptr_t)g_value_get_pointer(&value); | ||
| 1182 | g_value_unset(&value); | ||
| 1183 | ret = GATE_RESULT_OK; | ||
| 1184 | } | ||
| 1185 | else | ||
| 1186 | { | ||
| 1187 | *item = GATE_UI_TREEVIEW_INVALID_ITEM; | ||
| 1188 | ret = GATE_RESULT_NOMATCH; | ||
| 1189 | } | ||
| 1190 | return ret; | ||
| 1191 | } | ||
| 1192 | gate_result_t gate_ui_treeview_select_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | ||
| 1193 | { | ||
| 1194 | gate_result_t ret = GATE_RESULT_FAILED; | ||
| 1195 | GtkWidget* scroll_widget = GATE_UI_GTK_GET_CTRL_WIDGET(&trvw->ctrl); | ||
| 1196 | GtkWidget* widget = gtk_bin_get_child(GTK_BIN(scroll_widget)); | ||
| 1197 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
| 1198 | GtkTreeModel* model = gtk_tree_view_get_model(treeview); | ||
| 1199 | GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); | ||
| 1200 | GtkTreeIter found_iter; | ||
| 1201 | if (gate_ui_treeview_resolve(model, NULL, (void*)(gate_uintptr_t)item, &found_iter)) | ||
| 1202 | { | ||
| 1203 | GtkTreePath* path = gtk_tree_model_get_path(model, &found_iter); | ||
| 1204 | gtk_tree_selection_select_iter(selection, &found_iter); | ||
| 1205 | gtk_tree_path_free(path); | ||
| 1206 | ret = GATE_RESULT_OK; | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | return ret; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | #endif /* GATE_UI_GTK */ | ||
| 1213 | |||
| 1214 | |||
| 1215 | |||
| 1216 | #if defined(GATE_UI_MOTIF) | ||
| 1217 | |||
| 1218 | #include "gate/ui/gateui_motif.h" | ||
| 1219 | #include <Xm/List.h> | ||
| 1220 | #include <Xm/Tree.h> | ||
| 1221 | #include <Xm/Hierarchy.h> | ||
| 1222 | #include <Xm/Label.h> | ||
| 1223 | #include <Xm/PushB.h> | ||
| 1224 | #include <Xm/Outline.h> | ||
| 1225 | #include <Xm/ScrolledW.h> | ||
| 1226 | #include <Xm/ToggleB.h> | ||
| 1227 | #include <Xm/Manager.h> | ||
| 1228 | |||
| 1229 | 4 | static void motif_treeview_remove_node_widget(Widget node) | |
| 1230 | { | ||
| 1231 | 4 | XtUnmanageChild(node); | |
| 1232 | 4 | XtDestroyWidget(node); | |
| 1233 | 4 | } | |
| 1234 | |||
| 1235 | 4 | static void motif_treeview_remove_nodes_recursive(Widget node) | |
| 1236 | { | ||
| 1237 | 4 | WidgetList wlist = XmHierarchyGetChildNodes(node); | |
| 1238 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (wlist) |
| 1239 | { | ||
| 1240 | gate_size_t ndx; | ||
| 1241 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (ndx = 0; wlist[ndx]; ++ndx) |
| 1242 | { | ||
| 1243 | 2 | motif_treeview_remove_nodes_recursive(wlist[ndx]); | |
| 1244 | } | ||
| 1245 | 1 | XtFree((char*)wlist); | |
| 1246 | } | ||
| 1247 | 4 | motif_treeview_remove_node_widget(node); | |
| 1248 | 4 | } | |
| 1249 | |||
| 1250 | 1 | static gate_result_t motif_treeview_root_elements(gate_ui_treeview_t* tv, gate_array_t* list) | |
| 1251 | { | ||
| 1252 | 1 | WidgetList children = NULL; | |
| 1253 | 1 | Cardinal num_children = 0; | |
| 1254 | Widget w; | ||
| 1255 | unsigned ndx; | ||
| 1256 | gate_arraylist_t arr; | ||
| 1257 | |||
| 1258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(tv != NULL); |
| 1259 | 1 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&tv->ctrl); | |
| 1260 | |||
| 1261 | 1 | arr = gate_arraylist_create(sizeof(Widget), NULL, 0, NULL, NULL); | |
| 1262 | |||
| 1263 | 1 | XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, &num_children, NULL, NULL); | |
| 1264 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (ndx = 0; ndx != num_children; ++ndx) |
| 1265 | { | ||
| 1266 | 6 | Widget parent_widget = NULL; | |
| 1267 | 6 | Widget child_widget = children[ndx]; | |
| 1268 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
|
6 | if (!XmIsPushButton(child_widget)) |
| 1269 | { | ||
| 1270 | 3 | continue; | |
| 1271 | } | ||
| 1272 | 3 | XtVaGetValues(child_widget, XmNparentNode, &parent_widget, NULL, NULL); | |
| 1273 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (parent_widget == NULL) |
| 1274 | { | ||
| 1275 | 1 | gate_arraylist_add(arr, &child_widget); | |
| 1276 | } | ||
| 1277 | } | ||
| 1278 | 1 | gate_array_create(list, arr); | |
| 1279 | 1 | gate_arraylist_release(arr); | |
| 1280 | 1 | return GATE_RESULT_OK; | |
| 1281 | } | ||
| 1282 | |||
| 1283 | 1 | static gate_result_t motif_treeview_destroy(gate_ui_ctrl_t* ctrl) | |
| 1284 | { | ||
| 1285 | 1 | gate_ui_treeview_t* tv = (gate_ui_treeview_t*)ctrl; | |
| 1286 | gate_array_t arr; | ||
| 1287 | unsigned ndx; | ||
| 1288 | gate_size_t cnt; | ||
| 1289 | Widget w; | ||
| 1290 | |||
| 1291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(tv != NULL); |
| 1292 | |||
| 1293 | 1 | motif_treeview_root_elements(tv, &arr); | |
| 1294 | 1 | cnt = gate_array_length(&arr); | |
| 1295 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (ndx = 0; ndx < cnt; ++ndx) |
| 1296 | { | ||
| 1297 | 1 | Widget* ptr_node = (Widget*)gate_array_get(&arr, ndx); | |
| 1298 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!ptr_node || !*ptr_node) continue; |
| 1299 | 1 | motif_treeview_remove_nodes_recursive(*ptr_node); | |
| 1300 | } | ||
| 1301 | 1 | gate_array_release(&arr); | |
| 1302 | |||
| 1303 | 1 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(ctrl); | |
| 1304 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w) |
| 1305 | { | ||
| 1306 | 1 | XtUnmanageChild(w); | |
| 1307 | 1 | XtDestroyWidget(w); | |
| 1308 | } | ||
| 1309 | |||
| 1310 | 1 | w = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1311 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w) |
| 1312 | { | ||
| 1313 | 1 | XtUnmanageChild(w); | |
| 1314 | 1 | XtDestroyWidget(w); | |
| 1315 | } | ||
| 1316 | |||
| 1317 | 1 | gate_mem_clear(ctrl, sizeof(gate_ui_ctrl_t)); | |
| 1318 | 1 | return GATE_RESULT_OK; | |
| 1319 | } | ||
| 1320 | |||
| 1321 | 1 | static gate_result_t motif_treeview_get_children(gate_ui_ctrl_t* ctrl, void** ptr_to_widgetlist, gate_size_t* ptr_to_children_count) | |
| 1322 | { | ||
| 1323 | GATE_UNUSED_ARG(ctrl); | ||
| 1324 | |||
| 1325 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ptr_to_widgetlist) *ptr_to_widgetlist = NULL; |
| 1326 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ptr_to_children_count) *ptr_to_children_count = 0; |
| 1327 | 1 | return GATE_RESULT_OK; | |
| 1328 | } | ||
| 1329 | |||
| 1330 | |||
| 1331 | static gate_ui_motif_dispatcher_t treeview_dispatcher = | ||
| 1332 | { | ||
| 1333 | &motif_treeview_destroy, | ||
| 1334 | NULL, | ||
| 1335 | NULL, | ||
| 1336 | NULL, | ||
| 1337 | NULL, | ||
| 1338 | NULL, | ||
| 1339 | &motif_treeview_get_children | ||
| 1340 | }; | ||
| 1341 | |||
| 1342 | 1 | gate_result_t gate_ui_treeview_create( | |
| 1343 | gate_ui_treeview_t* trvw, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | ||
| 1344 | gate_uint32_t flags, void* userparam) | ||
| 1345 | { | ||
| 1346 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 1347 | do | ||
| 1348 | { | ||
| 1349 | 1 | Widget parent_widget = NULL; | |
| 1350 | Widget w; | ||
| 1351 | Widget w_tree; | ||
| 1352 | 1 | Widget w_scroll1 = NULL; | |
| 1353 | 1 | Widget w_scroll2 = NULL; | |
| 1354 | Arg args[10]; | ||
| 1355 | Cardinal args_count; | ||
| 1356 | /* XmNtreeDefaultLineStyle; */ | ||
| 1357 | |||
| 1358 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!trvw || !parent) |
| 1359 | { | ||
| 1360 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 1361 | ✗ | break; | |
| 1362 | } | ||
| 1363 | |||
| 1364 | 1 | parent_widget = GATE_UI_MOTIF_GET_CTRL_CONTAINER(parent); | |
| 1365 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!parent_widget) |
| 1366 | { | ||
| 1367 | ✗ | parent_widget = GATE_UI_MOTIF_GET_CTRL_WIDGET(parent); | |
| 1368 | } | ||
| 1369 | |||
| 1370 | 1 | args_count = 0; | |
| 1371 | 1 | XtSetArg(args[args_count], XmNscrollingPolicy, XmAUTOMATIC); ++args_count; | |
| 1372 | 1 | XtSetArg(args[args_count], XmNvisualPolicy, XmVARIABLE); ++args_count; | |
| 1373 | 1 | XtSetArg(args[args_count], XmNshowSash, True); ++args_count; | |
| 1374 | 1 | XtSetArg(args[args_count], XmNscrollBarDisplayPolicy, XmSTATIC); ++args_count; | |
| 1375 | //XtSetArg(args[args_count], XmNallowResize, True); ++args_count; | ||
| 1376 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 1377 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 1); ++args_count; | |
| 1378 | |||
| 1379 | 1 | w = XmCreateScrolledWindow(parent_widget, NULL, args, args_count); | |
| 1380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 1381 | { | ||
| 1382 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 1383 | ✗ | break; | |
| 1384 | } | ||
| 1385 | |||
| 1386 | 1 | XtVaGetValues(w, XmNhorizontalScrollBar, &w_scroll1, XmNverticalScrollBar, &w_scroll2, NULL); | |
| 1387 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll1) |
| 1388 | { | ||
| 1389 | 1 | XtVaSetValues(w_scroll1, XmNshadowThickness, 1, NULL); | |
| 1390 | } | ||
| 1391 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll2) |
| 1392 | { | ||
| 1393 | 1 | XtVaSetValues(w_scroll2, XmNshadowThickness, 1, NULL); | |
| 1394 | } | ||
| 1395 | |||
| 1396 | 1 | args_count = 0; | |
| 1397 | 1 | XtSetArg(args[args_count], XmNunitType, XmPIXELS); ++args_count; | |
| 1398 | 1 | XtSetArg(args[args_count], XmNconnectNodes, True); ++args_count; | |
| 1399 | 1 | XtSetArg(args[args_count], XmNindentSpace, 24); ++args_count; | |
| 1400 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 0); ++args_count; | |
| 1401 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 0); ++args_count; | |
| 1402 | 1 | XtSetArg(args[args_count], XmNhorizontalMargin, 1); ++args_count; | |
| 1403 | 1 | XtSetArg(args[args_count], XmNverticalMargin, 1); ++args_count; | |
| 1404 | |||
| 1405 | 1 | w_tree = XmCreateOutline(w, NULL, args, args_count); | |
| 1406 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_tree) |
| 1407 | { | ||
| 1408 | ✗ | XtDestroyWidget(w); | |
| 1409 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 1410 | ✗ | break; | |
| 1411 | } | ||
| 1412 | |||
| 1413 | 1 | ret = gate_ui_motif_ctrl_init(&trvw->ctrl, w, userparam, NULL, parent, w_tree, position, &flags, &treeview_dispatcher); | |
| 1414 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_BREAK_IF_FAILED(ret); |
| 1415 | |||
| 1416 | 1 | XtManageChild(w); | |
| 1417 | 1 | XtManageChild(w_tree); | |
| 1418 | } while (0); | ||
| 1419 | |||
| 1420 | 1 | return ret; | |
| 1421 | } | ||
| 1422 | |||
| 1423 | ✗ | gate_result_t gate_ui_treeview_add_icon(gate_ui_treeview_t* trvw, gate_ui_icon_t const* icon, gate_intptr_t* icon_key) | |
| 1424 | { | ||
| 1425 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1426 | } | ||
| 1427 | |||
| 1428 | ✗ | gate_result_t gate_ui_treeview_add_icon_image(gate_ui_treeview_t* trvw, gate_rasterimage_t const* image, gate_intptr_t* icon_key) | |
| 1429 | { | ||
| 1430 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1431 | } | ||
| 1432 | |||
| 1433 | ✗ | static gate_bool_t gate_ui_treeview_is_node_selected(Widget node) | |
| 1434 | { | ||
| 1435 | ✗ | Dimension dim = 0; | |
| 1436 | ✗ | XtVaGetValues(node, XmNshadowThickness, &dim, NULL, NULL); | |
| 1437 | ✗ | return dim != 0; | |
| 1438 | } | ||
| 1439 | |||
| 1440 | ✗ | static void gate_ui_treeview_set_node_selected(Widget node, gate_bool_t selected) | |
| 1441 | { | ||
| 1442 | ✗ | Dimension olddim = 0; | |
| 1443 | ✗ | Dimension newdim = selected ? 1 : 0; | |
| 1444 | ✗ | XtVaGetValues(node, XmNshadowThickness, &olddim, NULL, NULL); | |
| 1445 | ✗ | if (olddim != newdim) | |
| 1446 | { | ||
| 1447 | ✗ | XtVaSetValues(node, XmNshadowThickness, newdim, NULL, NULL); | |
| 1448 | /* TODO: update UI*/ | ||
| 1449 | } | ||
| 1450 | ✗ | } | |
| 1451 | |||
| 1452 | typedef gate_bool_t(*gate_ui_treeview_node_iterate_callback_t)(gate_ui_treeview_t* ptr_trvw, Widget node, void* param); | ||
| 1453 | |||
| 1454 | ✗ | static gate_result_t gate_ui_treeview_node_iterate(gate_ui_treeview_t* ptr_trvw, gate_ui_treeview_node_iterate_callback_t callback, void* param) | |
| 1455 | { | ||
| 1456 | gate_result_t ret; | ||
| 1457 | ✗ | WidgetList root_nodes = NULL; | |
| 1458 | ✗ | gate_size_t root_nodes_count = 0; | |
| 1459 | gate_size_t ndx; | ||
| 1460 | ✗ | gate_bool_t continue_iterate = true; | |
| 1461 | |||
| 1462 | ✗ | ret = gate_ui_motif_ctrl_get_children(&ptr_trvw->ctrl, (void**)&root_nodes, &root_nodes_count); | |
| 1463 | ✗ | if (GATE_FAILED(ret)) | |
| 1464 | { | ||
| 1465 | ✗ | return ret; | |
| 1466 | } | ||
| 1467 | |||
| 1468 | ✗ | for (ndx = 0; continue_iterate && (ndx != root_nodes_count); ++ndx) | |
| 1469 | { | ||
| 1470 | ✗ | continue_iterate = callback(ptr_trvw, root_nodes[ndx], param); | |
| 1471 | } | ||
| 1472 | ✗ | return ret; | |
| 1473 | } | ||
| 1474 | |||
| 1475 | ✗ | static void gate_ui_treeview_set_node_selected_recursive(Widget node, Widget node_to_select) | |
| 1476 | { | ||
| 1477 | ✗ | WidgetList sub_nodes = NULL; | |
| 1478 | ✗ | gate_ui_treeview_set_node_selected(node, node == node_to_select); | |
| 1479 | ✗ | sub_nodes = XmHierarchyGetChildNodes(node); | |
| 1480 | ✗ | if (sub_nodes) | |
| 1481 | { | ||
| 1482 | gate_size_t ndx; | ||
| 1483 | ✗ | for (ndx = 0; sub_nodes[ndx]; ++ndx) | |
| 1484 | { | ||
| 1485 | ✗ | gate_ui_treeview_set_node_selected_recursive(sub_nodes[ndx], node_to_select); | |
| 1486 | } | ||
| 1487 | ✗ | XtFree((char*)sub_nodes); | |
| 1488 | } | ||
| 1489 | ✗ | } | |
| 1490 | |||
| 1491 | ✗ | static gate_bool_t gate_ui_treeview_node_iterate_select(gate_ui_treeview_t* ptr_trvw, Widget node, void* param) | |
| 1492 | { | ||
| 1493 | ✗ | Widget to_select = (Widget)param; | |
| 1494 | ✗ | gate_ui_treeview_set_node_selected(node, node == to_select); | |
| 1495 | ✗ | return true; | |
| 1496 | } | ||
| 1497 | |||
| 1498 | ✗ | static void gate_ui_treeview_select_node_widget_and_unselect_others(gate_ui_treeview_t* ptr_trvw, Widget node_to_select) | |
| 1499 | { | ||
| 1500 | ✗ | gate_ui_treeview_node_iterate(ptr_trvw, &gate_ui_treeview_node_iterate_select, (void*)node_to_select); | |
| 1501 | ✗ | } | |
| 1502 | |||
| 1503 | 1 | static Widget gate_ui_treeview_get_selected_node_widget(gate_ui_treeview_t* ptr_trvw) | |
| 1504 | { | ||
| 1505 | 1 | Widget ret = NULL; | |
| 1506 | 1 | WidgetList children = NULL; | |
| 1507 | gate_size_t ndx; | ||
| 1508 | 1 | gate_size_t children_count = 0; | |
| 1509 | gate_result_t result; | ||
| 1510 | |||
| 1511 | 1 | result = gate_ui_motif_ctrl_get_children(&ptr_trvw->ctrl, (void**)&children, &children_count); | |
| 1512 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (GATE_FAILED(result)) |
| 1513 | { | ||
| 1514 | ✗ | return NULL; | |
| 1515 | } | ||
| 1516 | |||
| 1517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | for (ndx = 0; ndx != children_count; ++ndx) |
| 1518 | { | ||
| 1519 | ✗ | Widget node = children[ndx]; | |
| 1520 | ✗ | if (node) | |
| 1521 | { | ||
| 1522 | ✗ | if (gate_ui_treeview_is_node_selected(node)) | |
| 1523 | { | ||
| 1524 | ✗ | ret = node; | |
| 1525 | ✗ | break; | |
| 1526 | } | ||
| 1527 | } | ||
| 1528 | } | ||
| 1529 | 1 | return ret; | |
| 1530 | } | ||
| 1531 | |||
| 1532 | ✗ | static void gate_ui_treeview_on_node_widget_click(Widget node_widget, XtPointer client_data, XtPointer event_data) | |
| 1533 | { | ||
| 1534 | ✗ | gate_ui_treeview_t* ptr_trvw = (gate_ui_treeview_t*)client_data; | |
| 1535 | ✗ | if (ptr_trvw) | |
| 1536 | { | ||
| 1537 | ✗ | gate_ui_treeview_select_node_widget_and_unselect_others(ptr_trvw, node_widget); | |
| 1538 | ✗ | if (ptr_trvw->on_select) | |
| 1539 | { | ||
| 1540 | ✗ | ptr_trvw->on_select(&ptr_trvw->ctrl, (gate_ui_treeview_item_t)node_widget); | |
| 1541 | } | ||
| 1542 | } | ||
| 1543 | ✗ | } | |
| 1544 | |||
| 1545 | 4 | gate_result_t gate_ui_treeview_add(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t const* parent, gate_string_t const* text, | |
| 1546 | gate_intptr_t iconkey, void* itemparam, gate_ui_treeview_item_t* newitem) | ||
| 1547 | { | ||
| 1548 | Widget w_tree; | ||
| 1549 | Widget w_node; | ||
| 1550 | XmString xmstr; | ||
| 1551 | Arg args[10]; | ||
| 1552 | Cardinal args_count; | ||
| 1553 | |||
| 1554 | 4 | w_tree = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&trvw->ctrl); | |
| 1555 | |||
| 1556 | 4 | xmstr = gate_ui_motif_create_string(text); | |
| 1557 | |||
| 1558 | 4 | args_count = 0; | |
| 1559 | 4 | XtSetArg(args[args_count], XmNlabelString, xmstr); ++args_count; | |
| 1560 | 4 | XtSetArg(args[args_count], XmNnodeState, XmClosed); ++args_count; | |
| 1561 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | XtSetArg(args[args_count], XmNparentNode, parent ? (Widget)*parent : (Widget)NULL); ++args_count; |
| 1562 | //XtSetArg(args[args_count], XmNlineStyle, 99); ++args_count; | ||
| 1563 | 4 | XtSetArg(args[args_count], XmNshadowThickness, 0); ++args_count; | |
| 1564 | //XtSetArg(args[args_count], XmNtoggleMode, XmTOGGLE_BOOLEAN); ++args_count; | ||
| 1565 | //XtSetArg(args[args_count], XmNset, XmUNSET); ++args_count; | ||
| 1566 | //XtSetArg(args[args_count], XmNalignment, XmALIGNMENT_BEGINNING); ++args_count; | ||
| 1567 | 4 | XtSetArg(args[args_count], XmNuserData, itemparam); ++args_count; | |
| 1568 | 4 | XtSetArg(args[args_count], XmNhighlightThickness, 1); ++args_count; | |
| 1569 | |||
| 1570 | 4 | w_node = XtCreateWidget(NULL, xmPushButtonWidgetClass, w_tree, args, args_count); | |
| 1571 | //w_node = XtCreateWidget(NULL, xmLabelWidgetClass, w_tree, args, argcount); | ||
| 1572 | //w_node = XtCreateWidget(NULL, xmToggleButtonWidgetClass, w_tree, args, argcount); | ||
| 1573 | 4 | XmStringFree(xmstr); | |
| 1574 | |||
| 1575 | 4 | XtAddCallback(w_node, XmNactivateCallback, gate_ui_treeview_on_node_widget_click, trvw); | |
| 1576 | |||
| 1577 | 4 | *newitem = (gate_uintptr_t)w_node; | |
| 1578 | 4 | XtManageChild(w_node); | |
| 1579 | 4 | return GATE_RESULT_OK; | |
| 1580 | } | ||
| 1581 | |||
| 1582 | 1 | void* gate_ui_treeview_get_itemparam(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | |
| 1583 | { | ||
| 1584 | 1 | Widget w = (Widget)item; | |
| 1585 | 1 | void* userdata = NULL; | |
| 1586 | |||
| 1587 | 1 | XtVaGetValues(w, XmNuserData, &userdata, NULL, NULL); | |
| 1588 | 1 | return userdata; | |
| 1589 | } | ||
| 1590 | |||
| 1591 | 1 | gate_result_t gate_ui_treeview_remove(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | |
| 1592 | { | ||
| 1593 | 1 | Widget trvw_widget = GATE_UI_MOTIF_GET_CTRL_WIDGET(&trvw->ctrl); | |
| 1594 | 1 | Widget w = (Widget)item; | |
| 1595 | 1 | motif_treeview_remove_nodes_recursive(w); | |
| 1596 | 1 | return GATE_RESULT_OK; | |
| 1597 | } | ||
| 1598 | |||
| 1599 | ✗ | gate_result_t gate_ui_treeview_clear(gate_ui_treeview_t* trvw) | |
| 1600 | { | ||
| 1601 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 1602 | } | ||
| 1603 | |||
| 1604 | 1 | gate_result_t gate_ui_treeview_get_parent(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_ui_treeview_item_t* parent) | |
| 1605 | { | ||
| 1606 | 1 | Widget w = (Widget)item; | |
| 1607 | 1 | Widget w_parent = NULL; | |
| 1608 | |||
| 1609 | 1 | XtVaGetValues(w, XmNparentNode, &w_parent, NULL, NULL); | |
| 1610 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (w_parent) |
| 1611 | { | ||
| 1612 | ✗ | *parent = (gate_ui_treeview_item_t)w_parent; | |
| 1613 | } | ||
| 1614 | else | ||
| 1615 | { | ||
| 1616 | 1 | *parent = 0; | |
| 1617 | } | ||
| 1618 | 1 | return GATE_RESULT_OK; | |
| 1619 | } | ||
| 1620 | |||
| 1621 | 1 | gate_result_t gate_ui_treeview_get_children(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_array_t* children) | |
| 1622 | { | ||
| 1623 | 1 | Widget w_tree = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&trvw->ctrl); | |
| 1624 | 1 | Widget w = (Widget)item; | |
| 1625 | 1 | WidgetList wlist = NULL; | |
| 1626 | 1 | Cardinal wlist_count = 0; | |
| 1627 | 1 | gate_bool_t free_wlist = false; | |
| 1628 | 1 | gate_bool_t filter_parent = false; | |
| 1629 | 1 | gate_arraylist_t arr = gate_arraylist_create(sizeof(gate_ui_treeview_item_t), NULL, 0, NULL, NULL); | |
| 1630 | |||
| 1631 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (NULL == arr) |
| 1632 | { | ||
| 1633 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 1634 | } | ||
| 1635 | |||
| 1636 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (item) |
| 1637 | { | ||
| 1638 | ✗ | wlist = XmHierarchyGetChildNodes(w); | |
| 1639 | ✗ | free_wlist = true; | |
| 1640 | ✗ | while(wlist[wlist_count] != NULL) | |
| 1641 | { | ||
| 1642 | ✗ | ++wlist_count; | |
| 1643 | }; | ||
| 1644 | } | ||
| 1645 | else | ||
| 1646 | { | ||
| 1647 | 1 | XtVaGetValues(w_tree, XmNchildren, &wlist, XmNnumChildren, &wlist_count, NULL); | |
| 1648 | 1 | filter_parent = true; | |
| 1649 | } | ||
| 1650 | |||
| 1651 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (wlist) |
| 1652 | { | ||
| 1653 | gate_size_t ndx; | ||
| 1654 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (ndx = 0; ndx < wlist_count; ++ndx) |
| 1655 | { | ||
| 1656 | 6 | Widget child = wlist[ndx]; | |
| 1657 | 6 | gate_ui_treeview_item_t subitem = (gate_ui_treeview_item_t)child; | |
| 1658 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
|
6 | if (!XtIsSubclass(child, xmPushButtonWidgetClass)) |
| 1659 | { | ||
| 1660 | 5 | continue; | |
| 1661 | } | ||
| 1662 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if(filter_parent) |
| 1663 | { | ||
| 1664 | 3 | Widget w_parent = NULL; | |
| 1665 | 3 | XtVaGetValues(child, XmNparentNode, &w_parent, NULL, NULL); | |
| 1666 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (w_parent != w) |
| 1667 | { | ||
| 1668 | 2 | continue; | |
| 1669 | } | ||
| 1670 | } | ||
| 1671 | 1 | gate_arraylist_add(arr, &subitem); | |
| 1672 | } | ||
| 1673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(free_wlist) |
| 1674 | { | ||
| 1675 | ✗ | XtFree((char*)wlist); | |
| 1676 | } | ||
| 1677 | } | ||
| 1678 | |||
| 1679 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_array_create(children, arr)) |
| 1680 | { | ||
| 1681 | ✗ | gate_arraylist_release(arr); | |
| 1682 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 1683 | } | ||
| 1684 | else | ||
| 1685 | { | ||
| 1686 | 1 | gate_arraylist_release(arr); | |
| 1687 | 1 | return GATE_RESULT_OK; | |
| 1688 | } | ||
| 1689 | } | ||
| 1690 | |||
| 1691 | 1 | gate_result_t gate_ui_treeview_get_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t* text) | |
| 1692 | { | ||
| 1693 | 1 | Widget w = (Widget)item; | |
| 1694 | 1 | return gate_ui_motif_widget_get_label(w, text); | |
| 1695 | } | ||
| 1696 | |||
| 1697 | 1 | gate_result_t gate_ui_treeview_set_text(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_string_t const* text) | |
| 1698 | { | ||
| 1699 | 1 | Widget w = (Widget)item; | |
| 1700 | 1 | return gate_ui_motif_widget_set_label(w, text); | |
| 1701 | } | ||
| 1702 | |||
| 1703 | ✗ | gate_bool_t gate_ui_treeview_is_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | |
| 1704 | { | ||
| 1705 | ✗ | Widget w = (Widget)item; | |
| 1706 | ✗ | Cardinal v = 0; | |
| 1707 | ✗ | XtVaGetValues(w, XmNoutlineState, &v, NULL, NULL); | |
| 1708 | ✗ | return (v == XmEXPANDED) ? true : false; | |
| 1709 | } | ||
| 1710 | |||
| 1711 | 2 | gate_result_t gate_ui_treeview_set_expanded(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item, gate_bool_t expanded) | |
| 1712 | { | ||
| 1713 | 2 | Widget w = (Widget)item; | |
| 1714 | 2 | XtVaSetValues(w, XmNoutlineState, (expanded ? XmEXPANDED : XmCOLLAPSED), NULL, NULL); | |
| 1715 | 2 | return GATE_RESULT_OK; | |
| 1716 | } | ||
| 1717 | |||
| 1718 | 1 | gate_result_t gate_ui_treeview_get_selected_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t* item) | |
| 1719 | { | ||
| 1720 | 1 | Widget sel_widget = gate_ui_treeview_get_selected_node_widget(trvw); | |
| 1721 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (sel_widget) |
| 1722 | { | ||
| 1723 | ✗ | *item = (gate_ui_treeview_item_t)sel_widget; | |
| 1724 | ✗ | return GATE_RESULT_OK; | |
| 1725 | } | ||
| 1726 | else | ||
| 1727 | { | ||
| 1728 | 1 | return GATE_RESULT_NOMATCH; | |
| 1729 | } | ||
| 1730 | } | ||
| 1731 | |||
| 1732 | ✗ | gate_result_t gate_ui_treeview_select_item(gate_ui_treeview_t* trvw, gate_ui_treeview_item_t item) | |
| 1733 | { | ||
| 1734 | ✗ | Widget w_to_select = (Widget)item; | |
| 1735 | ✗ | gate_ui_treeview_select_node_widget_and_unselect_others(trvw, w_to_select); | |
| 1736 | ✗ | if (trvw->on_select) | |
| 1737 | { | ||
| 1738 | ✗ | trvw->on_select(&trvw->ctrl, item); | |
| 1739 | } | ||
| 1740 | ✗ | return GATE_RESULT_OK; | |
| 1741 | } | ||
| 1742 | |||
| 1743 | #endif /* GATE_UI_MOTIF */ | ||
| 1744 |