| 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/listviews.h" | ||
| 30 | #include "gate/results.h" | ||
| 31 | #include "gate/debugging.h" | ||
| 32 | |||
| 33 | |||
| 34 | #if defined(GATE_UI_MOTIF) | ||
| 35 | |||
| 36 | #include "gate/ui/gateui_motif.h" | ||
| 37 | #include <Xm/List.h> | ||
| 38 | #include <Xm/Container.h> | ||
| 39 | #include <Xm/Label.h> | ||
| 40 | #include <Xm/ScrolledW.h> | ||
| 41 | #include <Xm/IconG.h> | ||
| 42 | #include <Xm/ScrollBar.h> | ||
| 43 | |||
| 44 | 6 | static gate_size_t gate_ui_listbox_widget_get_item_count(Widget w) | |
| 45 | { | ||
| 46 | 6 | int list_count = 0; | |
| 47 | 6 | XtVaGetValues(w, XmNitemCount, &list_count, NULL); | |
| 48 | 6 | return (gate_size_t)list_count; | |
| 49 | } | ||
| 50 | |||
| 51 | 1 | gate_result_t gate_ui_listbox_create(gate_ui_listbox_t* lstbox, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | |
| 52 | gate_uint32_t flags, void* userparam) | ||
| 53 | { | ||
| 54 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 55 | 1 | Widget parent_widget = NULL; | |
| 56 | Widget w; | ||
| 57 | Widget w_list; | ||
| 58 | Arg args[8]; | ||
| 59 | Cardinal args_count; | ||
| 60 | |||
| 61 | do | ||
| 62 | { | ||
| 63 | gate_arraylist_t item_params; | ||
| 64 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!lstbox || !parent) |
| 65 | { | ||
| 66 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 67 | ✗ | break; | |
| 68 | } | ||
| 69 | |||
| 70 | 1 | parent_widget = GATE_UI_MOTIF_GET_CTRL_CONTAINER(parent); | |
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!parent_widget) |
| 72 | { | ||
| 73 | ✗ | parent_widget = GATE_UI_MOTIF_GET_CTRL_WIDGET(parent); | |
| 74 | } | ||
| 75 | 1 | args_count = 0; | |
| 76 | 1 | XtSetArg(args[args_count], XmNscrollingPolicy, XmAPPLICATION_DEFINED); ++args_count; | |
| 77 | 1 | XtSetArg(args[args_count], XmNvisualPolicy, XmVARIABLE); ++args_count; | |
| 78 | 1 | XtSetArg(args[args_count], XmNscrollBarDisplayPolicy, XmSTATIC); ++args_count; | |
| 79 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 0); ++args_count; | |
| 80 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 0); ++args_count; | |
| 81 | |||
| 82 | 1 | w = XmCreateScrolledWindow(parent_widget, NULL, args, args_count); | |
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 84 | { | ||
| 85 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 86 | ✗ | break; | |
| 87 | } | ||
| 88 | |||
| 89 | 1 | args_count = 0; | |
| 90 | 1 | XtSetArg(args[args_count], XmNautomaticSelection, XmBROWSE_SELECT); ++args_count; | |
| 91 | //XtSetArg(args[args_count], XmNscrollBarDisplayPolicy, XmAS_NEEDED); ++args_count; | ||
| 92 | 1 | XtSetArg(args[args_count], XmNselectionPolicy, XmSINGLE_SELECT); ++args_count; | |
| 93 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 94 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 1); ++args_count; | |
| 95 | |||
| 96 | 1 | w_list = XmCreateList(w, NULL, args, args_count); | |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_list) |
| 98 | { | ||
| 99 | ✗ | XtDestroyWidget(w); | |
| 100 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 101 | ✗ | break; | |
| 102 | } | ||
| 103 | |||
| 104 | 1 | ret = gate_ui_motif_ctrl_init(&lstbox->ctrl, w, userparam, NULL, parent, w_list, position, &flags, NULL); | |
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_BREAK_IF_FAILED(ret); |
| 106 | |||
| 107 | 1 | item_params = gate_arraylist_create(sizeof(void*), NULL, 16, NULL, NULL); | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (item_params == NULL) |
| 109 | { | ||
| 110 | ✗ | gate_ui_motif_ctrl_destroy(&lstbox->ctrl); | |
| 111 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 112 | ✗ | break; | |
| 113 | } | ||
| 114 | 1 | GATE_UI_MOTIF_SET_CTRL_PRIVATE_ARG(&lstbox->ctrl, item_params); | |
| 115 | |||
| 116 | 1 | XtManageChild(w); | |
| 117 | 1 | XtManageChild(w_list); | |
| 118 | |||
| 119 | } while (0); | ||
| 120 | |||
| 121 | 1 | return ret; | |
| 122 | } | ||
| 123 | |||
| 124 | 27 | gate_result_t gate_ui_listbox_insert_item(gate_ui_listbox_t* lstbox, gate_size_t const* at_index, gate_string_t const* text, void* itemparam) | |
| 125 | { | ||
| 126 | 27 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 127 | 27 | XmString str = NULL; | |
| 128 | 27 | const gate_arraylist_t item_params = (gate_arraylist_t)GATE_UI_MOTIF_GET_CTRL_PRIVATE_ARG(&lstbox->ctrl); | |
| 129 | |||
| 130 | do | ||
| 131 | { | ||
| 132 | 27 | Widget w = NULL; | |
| 133 | gate_size_t item_count; | ||
| 134 | int insert_pos; | ||
| 135 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
|
27 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 136 | |||
| 137 | 27 | str = gate_ui_motif_create_string(text); | |
| 138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (!str) |
| 139 | { | ||
| 140 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 141 | ✗ | break; | |
| 142 | } | ||
| 143 | |||
| 144 | /* insert at end */ | ||
| 145 | 27 | insert_pos = 0; | |
| 146 | |||
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (at_index) |
| 148 | { | ||
| 149 | ✗ | item_count = gate_ui_listbox_widget_get_item_count(w); | |
| 150 | ✗ | if (*at_index < item_count) | |
| 151 | { | ||
| 152 | /* insert at position, counting starts at "1" */ | ||
| 153 | ✗ | insert_pos = (*at_index) + 1; | |
| 154 | } | ||
| 155 | ✗ | if (NULL == gate_arraylist_insert(item_params, *at_index, &itemparam, 1)) | |
| 156 | { | ||
| 157 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 158 | ✗ | break; | |
| 159 | } | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
|
27 | if (NULL == gate_arraylist_add(item_params, &itemparam)) |
| 164 | { | ||
| 165 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 166 | ✗ | break; | |
| 167 | } | ||
| 168 | } | ||
| 169 | 27 | XmListAddItem(w, str, insert_pos); | |
| 170 | 27 | ret = GATE_RESULT_OK; | |
| 171 | |||
| 172 | } while (0); | ||
| 173 | |||
| 174 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | if (str) |
| 175 | { | ||
| 176 | 27 | XmStringFree(str); | |
| 177 | } | ||
| 178 | |||
| 179 | 27 | return ret; | |
| 180 | } | ||
| 181 | |||
| 182 | 5 | gate_result_t gate_ui_listbox_remove_item(gate_ui_listbox_t* lstbox, gate_size_t index) | |
| 183 | { | ||
| 184 | 5 | Widget w = NULL; | |
| 185 | 5 | const gate_arraylist_t item_params = (gate_arraylist_t)GATE_UI_MOTIF_GET_CTRL_PRIVATE_ARG(&lstbox->ctrl); | |
| 186 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 187 | 5 | XmListDeletePos(w, (int)(index + 1)); | |
| 188 | 5 | gate_arraylist_remove(item_params, index, 1); | |
| 189 | 5 | return GATE_RESULT_OK; | |
| 190 | } | ||
| 191 | |||
| 192 | 1 | gate_result_t gate_ui_listbox_remove_all_items(gate_ui_listbox_t* lstbox) | |
| 193 | { | ||
| 194 | 1 | Widget w = NULL; | |
| 195 | 1 | const gate_arraylist_t item_params = (gate_arraylist_t)GATE_UI_MOTIF_GET_CTRL_PRIVATE_ARG(&lstbox->ctrl); | |
| 196 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 197 | 1 | XmListDeleteAllItems(w); | |
| 198 | 1 | gate_arraylist_clear(item_params); | |
| 199 | 1 | return GATE_RESULT_OK; | |
| 200 | } | ||
| 201 | |||
| 202 | 6 | gate_size_t gate_ui_listbox_get_item_count(gate_ui_listbox_t* lstbox) | |
| 203 | { | ||
| 204 | 6 | gate_size_t ret = 0; | |
| 205 | do | ||
| 206 | { | ||
| 207 | Widget w_list; | ||
| 208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!lstbox) break; |
| 209 | 6 | w_list = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstbox->ctrl); | |
| 210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!w_list) break; |
| 211 | |||
| 212 | 6 | ret = gate_ui_listbox_widget_get_item_count(w_list); | |
| 213 | } while (0); | ||
| 214 | |||
| 215 | 6 | return ret; | |
| 216 | } | ||
| 217 | |||
| 218 | 1 | void* gate_ui_listbox_get_item_param(gate_ui_listbox_t* lstbox, gate_size_t index) | |
| 219 | { | ||
| 220 | 1 | const gate_arraylist_t item_params = (gate_arraylist_t)GATE_UI_MOTIF_GET_CTRL_PRIVATE_ARG(&lstbox->ctrl); | |
| 221 | 1 | void** ptr_param = (void**)gate_arraylist_get(item_params, index); | |
| 222 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ptr_param) |
| 223 | { | ||
| 224 | 1 | return *ptr_param; | |
| 225 | } | ||
| 226 | ✗ | return NULL; | |
| 227 | } | ||
| 228 | |||
| 229 | 1 | gate_result_t gate_ui_listbox_find_param(gate_ui_listbox_t* lstbox, void* param, gate_size_t start_index, gate_size_t* found_index) | |
| 230 | { | ||
| 231 | 1 | const gate_arraylist_t item_params = (gate_arraylist_t)GATE_UI_MOTIF_GET_CTRL_PRIVATE_ARG(&lstbox->ctrl); | |
| 232 | gate_size_t ndx; | ||
| 233 | 1 | gate_size_t cnt = gate_arraylist_length(item_params); | |
| 234 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | for (ndx = start_index; ndx < cnt; ++ndx) |
| 235 | { | ||
| 236 | 1 | void** ptr_param = gate_arraylist_get(item_params, ndx); | |
| 237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!ptr_param) continue; |
| 238 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (*ptr_param == param) |
| 239 | { | ||
| 240 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (found_index) |
| 241 | { | ||
| 242 | 1 | *found_index = ndx; | |
| 243 | } | ||
| 244 | 1 | return GATE_RESULT_OK; | |
| 245 | } | ||
| 246 | } | ||
| 247 | ✗ | return GATE_RESULT_NOMATCH; | |
| 248 | } | ||
| 249 | |||
| 250 | 1 | gate_result_t gate_ui_listbox_get_text(gate_ui_listbox_t* lstbox, gate_size_t index, gate_string_t* text) | |
| 251 | { | ||
| 252 | 1 | int count = 0; | |
| 253 | 1 | XmStringTable tbl = NULL; | |
| 254 | 1 | Widget w = NULL; | |
| 255 | |||
| 256 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 257 | 1 | XtVaGetValues(w, XmNitemCount, &count, XmNitems, &tbl, NULL); | |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (index >= (int)count) |
| 259 | { | ||
| 260 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 261 | } | ||
| 262 | |||
| 263 | 1 | return gate_ui_motif_convert_string(tbl[index], text); | |
| 264 | } | ||
| 265 | |||
| 266 | 1 | gate_result_t gate_ui_listbox_set_text(gate_ui_listbox_t* lstbox, gate_size_t index, gate_string_t const* text) | |
| 267 | { | ||
| 268 | 1 | Widget w = NULL; | |
| 269 | int positions[1]; | ||
| 270 | XmString strs[1]; | ||
| 271 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 272 | 1 | strs[0] = gate_ui_motif_create_string(text); | |
| 273 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!strs[0]) return GATE_RESULT_OUTOFMEMORY; |
| 274 | 1 | positions[0] = (int)(index + 1); | |
| 275 | 1 | XmListReplacePositions(w, positions, strs, 1); | |
| 276 | 1 | XmStringFree(strs[0]); | |
| 277 | 1 | return GATE_RESULT_OK; | |
| 278 | } | ||
| 279 | |||
| 280 | 1 | gate_size_t gate_ui_listbox_get_selected_item(gate_ui_listbox_t* lstbox) | |
| 281 | { | ||
| 282 | 1 | gate_size_t ret = GATE_UI_LISTBOX_INVALID_INDEX; | |
| 283 | do | ||
| 284 | { | ||
| 285 | 1 | Widget w = NULL; | |
| 286 | 1 | int count = 0; | |
| 287 | 1 | int* ptr_positions = NULL; | |
| 288 | |||
| 289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!lstbox) |
| 290 | { | ||
| 291 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 292 | ✗ | break; | |
| 293 | } | ||
| 294 | 1 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstbox->ctrl); | |
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 296 | { | ||
| 297 | ✗ | ret = GATE_RESULT_INVALIDSTATE; | |
| 298 | ✗ | break; | |
| 299 | } | ||
| 300 | 1 | XtVaGetValues(w, XmNselectedPositionCount, &count, XmNselectedPositions, &ptr_positions, NULL); | |
| 301 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if ((count > 0) && (ptr_positions != NULL)) |
| 302 | { | ||
| 303 | 1 | ret = (gate_size_t)(ptr_positions[0] - 1); | |
| 304 | } | ||
| 305 | } while (0); | ||
| 306 | 1 | return ret; | |
| 307 | } | ||
| 308 | |||
| 309 | 1 | gate_result_t gate_ui_listbox_set_selected_item(gate_ui_listbox_t* lstbox, gate_size_t index) | |
| 310 | { | ||
| 311 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 312 | Widget w; | ||
| 313 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | GATE_UI_MOTIF_EXTRACT_CONTAINER_OR_RETURN_ERROR(lstbox, w); |
| 314 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (index == GATE_UI_LISTBOX_INVALID_INDEX) |
| 315 | { | ||
| 316 | ✗ | XmListDeselectAllItems(w); | |
| 317 | } | ||
| 318 | else | ||
| 319 | { | ||
| 320 | 1 | XmListSelectPos(w, (int)(index + 1), 1); | |
| 321 | } | ||
| 322 | 1 | return GATE_RESULT_OK; | |
| 323 | } | ||
| 324 | |||
| 325 | |||
| 326 | |||
| 327 | |||
| 328 | |||
| 329 | |||
| 330 | 1 | static gate_result_t motif_listview_destroy(gate_ui_ctrl_t* ctrl) | |
| 331 | { | ||
| 332 | 1 | gate_ui_listview_t* lv = (gate_ui_listview_t*)ctrl; | |
| 333 | Widget w_scroll; | ||
| 334 | Widget w_list; | ||
| 335 | |||
| 336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lv != NULL); |
| 337 | |||
| 338 | 1 | gate_ui_listview_remove_all_items(lv); | |
| 339 | |||
| 340 | 1 | w_scroll = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 341 | 1 | w_list = GATE_UI_MOTIF_GET_CTRL_CONTAINER(ctrl); | |
| 342 | |||
| 343 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_list) |
| 344 | { | ||
| 345 | 1 | Cardinal col_count = 0; | |
| 346 | 1 | XmStringTable col_tbl = NULL; | |
| 347 | |||
| 348 | 1 | XtUnmanageChild(w_list); | |
| 349 | 1 | XtVaGetValues(w_list, XmNdetailColumnHeadingCount, &col_count, XmNdetailColumnHeading, &col_tbl, NULL, NULL); | |
| 350 | 1 | XtVaSetValues(w_list, XmNdetailColumnHeadingCount, 0, XmNdetailColumnHeading, NULL, NULL, NULL); | |
| 351 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if ((col_count > 0) && (col_tbl != NULL)) |
| 352 | { | ||
| 353 | unsigned ndx; | ||
| 354 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (ndx = 0; ndx != col_count; ++ndx) |
| 355 | { | ||
| 356 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (col_tbl[ndx]) |
| 357 | { | ||
| 358 | 3 | XmStringFree(col_tbl[ndx]); | |
| 359 | 3 | col_tbl[ndx] = NULL; | |
| 360 | } | ||
| 361 | } | ||
| 362 | //XtFree((char*)col_tbl); | ||
| 363 | } | ||
| 364 | 1 | XtDestroyWidget(w_list); | |
| 365 | } | ||
| 366 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll) |
| 367 | { | ||
| 368 | 1 | XtUnmanageChild(w_scroll); | |
| 369 | 1 | XtDestroyWidget(w_scroll); | |
| 370 | } | ||
| 371 | |||
| 372 | 1 | gate_ui_iconlist_destroy(&lv->icons); | |
| 373 | |||
| 374 | 1 | gate_mem_clear(ctrl, sizeof(gate_ui_ctrl_t)); | |
| 375 | 1 | return GATE_RESULT_OK; | |
| 376 | } | ||
| 377 | |||
| 378 | 75 | static gate_result_t motif_listview_get_children(gate_ui_ctrl_t* ctrl, void** ptr_to_widgetlist, gate_size_t* ptr_to_children_count) | |
| 379 | { | ||
| 380 | 75 | Widget w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(ctrl); | |
| 381 | 75 | WidgetList children = NULL; | |
| 382 | 75 | Cardinal num_children = 0; | |
| 383 | |||
| 384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 | GATE_DEBUG_ASSERT(w != NULL); |
| 385 | 75 | XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, &num_children, NULL, NULL); | |
| 386 |
1/2✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
|
75 | if (ptr_to_widgetlist) |
| 387 | { | ||
| 388 | 75 | *ptr_to_widgetlist = children; | |
| 389 | } | ||
| 390 |
1/2✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
|
75 | if (ptr_to_children_count) |
| 391 | { | ||
| 392 | 75 | *ptr_to_children_count = (gate_size_t)num_children; | |
| 393 | } | ||
| 394 | 75 | return GATE_RESULT_OK; | |
| 395 | } | ||
| 396 | |||
| 397 | static gate_ui_motif_dispatcher_t listview_dispatcher = | ||
| 398 | { | ||
| 399 | &motif_listview_destroy, | ||
| 400 | NULL, | ||
| 401 | NULL, | ||
| 402 | NULL, | ||
| 403 | NULL, | ||
| 404 | NULL, | ||
| 405 | &motif_listview_get_children | ||
| 406 | }; | ||
| 407 | |||
| 408 | 2 | static gate_size_t motif_listview_resolve_item_widget_index(gate_ui_listview_t* lstvw, Widget item) | |
| 409 | { | ||
| 410 | 2 | WidgetList wl = NULL; | |
| 411 | 2 | gate_size_t widget_count = 0; | |
| 412 | 2 | gate_result_t ret = motif_listview_get_children(&lstvw->ctrl, (void**)&wl, &widget_count); | |
| 413 | 2 | gate_size_t item_index = 0; | |
| 414 | gate_size_t ndx; | ||
| 415 | Widget w; | ||
| 416 | |||
| 417 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 418 | { | ||
| 419 | 4 | w = wl[ndx]; | |
| 420 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
|
4 | if (!XmIsIconGadget(w)) |
| 421 | { | ||
| 422 | 2 | continue; | |
| 423 | } | ||
| 424 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (w == item) |
| 425 | { | ||
| 426 | 2 | return item_index; | |
| 427 | } | ||
| 428 | ✗ | ++item_index; | |
| 429 | } | ||
| 430 | ✗ | return GATE_STR_NPOS; | |
| 431 | } | ||
| 432 | |||
| 433 | 36 | static Widget motif_listview_get_item_widget(gate_ui_listview_t* lstvw, gate_size_t index) | |
| 434 | { | ||
| 435 | 36 | WidgetList wl = NULL; | |
| 436 | 36 | gate_size_t widget_count = 0; | |
| 437 | 36 | gate_size_t item_count = 0; | |
| 438 | 36 | gate_result_t ret = motif_listview_get_children(&lstvw->ctrl, (void**)&wl, &widget_count); | |
| 439 |
1/2✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
36 | if (GATE_SUCCEEDED(ret)) |
| 440 | { | ||
| 441 | gate_size_t ndx; | ||
| 442 |
1/2✓ Branch 0 taken 482 times.
✗ Branch 1 not taken.
|
482 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 443 | { | ||
| 444 | 482 | Widget w = wl[ndx]; | |
| 445 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 446 times.
|
482 | if (!XmIsIconGadget(w)) |
| 446 | { | ||
| 447 | 36 | continue; | |
| 448 | } | ||
| 449 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 410 times.
|
446 | if (index == item_count) |
| 450 | { | ||
| 451 | 36 | return w; | |
| 452 | } | ||
| 453 | 410 | ++item_count; | |
| 454 | } | ||
| 455 | } | ||
| 456 | ✗ | return NULL; | |
| 457 | } | ||
| 458 | |||
| 459 | |||
| 460 | ✗ | static void motif_listview_selection_callback(Widget widget, XtPointer client_data, XtPointer call_data) | |
| 461 | { | ||
| 462 | ✗ | gate_ui_listview_t* lv = (gate_ui_listview_t*)client_data; | |
| 463 | ✗ | XmContainerSelectCallbackStruct* evt_data = (XmContainerSelectCallbackStruct*)call_data; | |
| 464 | |||
| 465 | ✗ | if (lv && lv->on_select && evt_data && evt_data->selected_item_count > 0) | |
| 466 | { | ||
| 467 | ✗ | Widget item_widget = evt_data->selected_items[0]; | |
| 468 | ✗ | gate_size_t item_index = motif_listview_resolve_item_widget_index(lv, item_widget); | |
| 469 | ✗ | if (item_index != GATE_STR_NPOS) | |
| 470 | { | ||
| 471 | ✗ | void* item_data = NULL; | |
| 472 | ✗ | XtVaGetValues(item_widget, XmNuserData, &item_data, NULL, NULL); | |
| 473 | ✗ | lv->on_select(&lv->ctrl, item_index, item_data); | |
| 474 | } | ||
| 475 | } | ||
| 476 | ✗ | } | |
| 477 | |||
| 478 | 1 | gate_result_t gate_ui_listview_create(gate_ui_listview_t* lstvw, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | |
| 479 | gate_uint32_t flags, void* userparam) | ||
| 480 | { | ||
| 481 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 482 | |||
| 483 | do | ||
| 484 | { | ||
| 485 | 1 | Widget parent_widget = NULL; | |
| 486 | Widget w; | ||
| 487 | Widget w_list; | ||
| 488 | 1 | Widget w_scroll1 = NULL; | |
| 489 | 1 | Widget w_scroll2 = NULL; | |
| 490 | Arg args[12]; | ||
| 491 | Cardinal args_count; | ||
| 492 | gate_ui_host_t* ptr_host; | ||
| 493 | |||
| 494 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!lstvw || !parent) |
| 495 | { | ||
| 496 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 497 | ✗ | break; | |
| 498 | } | ||
| 499 | |||
| 500 | 1 | parent_widget = GATE_UI_MOTIF_GET_CTRL_CONTAINER(parent); | |
| 501 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!parent_widget) |
| 502 | { | ||
| 503 | ✗ | parent_widget = GATE_UI_MOTIF_GET_CTRL_WIDGET(parent); | |
| 504 | } | ||
| 505 | 1 | ptr_host = GATE_UI_MOTIF_GET_CTRL_HOST(parent); | |
| 506 | 1 | args_count = 0; | |
| 507 | 1 | XtSetArg(args[args_count], XmNscrollingPolicy, XmAUTOMATIC); ++args_count; | |
| 508 | 1 | XtSetArg(args[args_count], XmNvisualPolicy, XmVARIABLE); ++args_count; | |
| 509 | //XtSetArg(args[args_count], XmNscrollBarDisplayPolicy, XmSTATIC); ++args_count; | ||
| 510 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 511 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 1); ++args_count; | |
| 512 | |||
| 513 | 1 | w = XmCreateScrolledWindow(parent_widget, NULL, args, args_count); | |
| 514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 515 | { | ||
| 516 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 517 | ✗ | break; | |
| 518 | } | ||
| 519 | |||
| 520 | 1 | XtVaGetValues(w, XmNhorizontalScrollBar, &w_scroll1, XmNverticalScrollBar, &w_scroll2, NULL); | |
| 521 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll1) |
| 522 | { | ||
| 523 | 1 | XtVaSetValues(w_scroll1, XmNshadowThickness, 1, NULL); | |
| 524 | } | ||
| 525 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll2) |
| 526 | { | ||
| 527 | 1 | XtVaSetValues(w_scroll2, XmNshadowThickness, 1, NULL); | |
| 528 | } | ||
| 529 | |||
| 530 | 1 | args_count = 0; | |
| 531 | 1 | XtSetArg(args[args_count], XmNlayoutType, XmDETAIL); ++args_count; | |
| 532 | 1 | XtSetArg(args[args_count], XmNautomaticSelection, XmAUTO_SELECT); ++args_count; | |
| 533 | 1 | XtSetArg(args[args_count], XmNselectionPolicy, XmSINGLE_SELECT); ++args_count; | |
| 534 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 535 | |||
| 536 | 1 | w_list = XmCreateContainer(w, NULL, args, args_count); | |
| 537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_list) |
| 538 | { | ||
| 539 | ✗ | XtDestroyWidget(w); | |
| 540 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 541 | ✗ | break; | |
| 542 | } | ||
| 543 | |||
| 544 | 1 | ret = gate_ui_motif_ctrl_init(&lstvw->ctrl, w, userparam, NULL, parent, w_list, position, &flags, &listview_dispatcher); | |
| 545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_BREAK_IF_FAILED(ret); |
| 546 | |||
| 547 | 1 | gate_ui_iconlist_create(&lstvw->icons, ptr_host, 16, 16); | |
| 548 | |||
| 549 | 1 | XtManageChild(w); | |
| 550 | 1 | XtManageChild(w_list); | |
| 551 | |||
| 552 | 1 | XtAddCallback(w_list, XmNselectionCallback, &motif_listview_selection_callback, lstvw); | |
| 553 | } while (0); | ||
| 554 | |||
| 555 | 1 | return ret; | |
| 556 | } | ||
| 557 | |||
| 558 | 1 | gate_result_t gate_ui_listview_set_columns(gate_ui_listview_t* lstvw, gate_ui_listview_column_t const* columns, gate_size_t column_count) | |
| 559 | { | ||
| 560 | Widget w; | ||
| 561 | gate_size_t ndx; | ||
| 562 | 1 | Cardinal col_count = (Cardinal)column_count; | |
| 563 | 1 | XmStringTable col_headers = (XmStringTable)XtMalloc(column_count * sizeof(XmString)); | |
| 564 | |||
| 565 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!col_headers) |
| 566 | { | ||
| 567 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 568 | } | ||
| 569 | |||
| 570 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (ndx = 0; ndx != column_count; ++ndx) |
| 571 | { | ||
| 572 | 3 | col_headers[ndx] = gate_ui_motif_create_string(&columns[ndx].title); | |
| 573 | } | ||
| 574 | |||
| 575 | 1 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 576 | 1 | XtVaSetValues(w, | |
| 577 | XmNdetailColumnHeadingCount, col_count, | ||
| 578 | XmNdetailColumnHeading, col_headers, | ||
| 579 | NULL, NULL); | ||
| 580 | 1 | return GATE_RESULT_OK; | |
| 581 | } | ||
| 582 | |||
| 583 | 53 | gate_size_t gate_ui_listview_get_column_count(gate_ui_listview_t* lstvw) | |
| 584 | { | ||
| 585 | Widget w; | ||
| 586 | 53 | Cardinal col_count = 0; | |
| 587 | |||
| 588 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 589 | |||
| 590 | 53 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 591 | 53 | XtVaGetValues(w, XmNdetailColumnHeadingCount, &col_count, NULL, NULL); | |
| 592 | 53 | return col_count; | |
| 593 | } | ||
| 594 | |||
| 595 | 3 | gate_result_t gate_ui_listview_get_column(gate_ui_listview_t* lstvw, gate_size_t index, gate_string_t* text, gate_uint32_t* width) | |
| 596 | { | ||
| 597 | 3 | XmStringTable tbl = NULL; | |
| 598 | 3 | Widget w = NULL; | |
| 599 | 3 | Cardinal col_count = 0; | |
| 600 | |||
| 601 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 602 | |||
| 603 | 3 | w = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 604 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!w) |
| 605 | { | ||
| 606 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 607 | } | ||
| 608 | 3 | XtVaGetValues(w, XmNdetailColumnHeadingCount, &col_count, XmNdetailColumnHeading, &tbl, NULL, NULL); | |
| 609 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | if ((index < col_count) && (tbl != NULL)) |
| 610 | { | ||
| 611 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (text) |
| 612 | { | ||
| 613 | 3 | gate_ui_motif_convert_string(tbl[index], text); | |
| 614 | } | ||
| 615 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (width) |
| 616 | { | ||
| 617 | 3 | *width = 0; | |
| 618 | } | ||
| 619 | 3 | return GATE_RESULT_OK; | |
| 620 | } | ||
| 621 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 622 | } | ||
| 623 | |||
| 624 | ✗ | gate_result_t gate_ui_listview_add_icon(gate_ui_listview_t* lstvw, gate_ui_icon_t const* icon, gate_intptr_t* icon_key) | |
| 625 | { | ||
| 626 | ✗ | return GATE_RESULT_NOTIMPLEMENTED; | |
| 627 | } | ||
| 628 | |||
| 629 | 30 | static gate_result_t motif_ctrl_get_pixmap_image(gate_ui_iconlist_t* iconlst, gate_intptr_t icon_key, Pixmap* ptr_pm_image, Pixmap* ptr_pm_mask) | |
| 630 | { | ||
| 631 | 30 | Pixmap* ptr_pixmap = NULL; | |
| 632 | 30 | gate_arraylist_t pixmap_array = NULL; | |
| 633 | |||
| 634 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 13 times.
|
30 | if (icon_key == GATE_UI_LISTVIEW_INVALID_ICON) |
| 635 | { | ||
| 636 | 17 | return GATE_RESULT_NOTAVAILABLE; | |
| 637 | } | ||
| 638 | |||
| 639 | 13 | ptr_pixmap = (Pixmap*)gate_ui_iconlist_get_handle(iconlst, icon_key); | |
| 640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (ptr_pixmap == NULL) |
| 641 | { | ||
| 642 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 643 | } | ||
| 644 | |||
| 645 | /* retrieve image pixmap */ | ||
| 646 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (ptr_pm_image) |
| 647 | { | ||
| 648 | 13 | *ptr_pm_image = ptr_pixmap[1]; | |
| 649 | } | ||
| 650 | |||
| 651 | /* retrieve mask image */ | ||
| 652 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (ptr_pm_mask) |
| 653 | { | ||
| 654 | 13 | *ptr_pm_mask = ptr_pixmap[0]; | |
| 655 | } | ||
| 656 | |||
| 657 | 13 | return GATE_RESULT_OK; | |
| 658 | } | ||
| 659 | |||
| 660 | |||
| 661 | 1 | gate_result_t gate_ui_listview_add_icon_image(gate_ui_listview_t* lstvw, gate_rasterimage_t const* image, gate_intptr_t* icon_key) | |
| 662 | { | ||
| 663 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 664 | 1 | return gate_ui_iconlist_add_image(&lstvw->icons, image, icon_key); | |
| 665 | } | ||
| 666 | |||
| 667 | 1 | gate_result_t gate_ui_listview_begin_transaction(gate_ui_listview_t* lstvw) | |
| 668 | { | ||
| 669 | 1 | lstvw->transaction = gate_arraylist_create(sizeof(Widget), NULL, 0, NULL, NULL); | |
| 670 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | return (lstvw->transaction == NULL) ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK; |
| 671 | } | ||
| 672 | |||
| 673 | 1 | gate_result_t gate_ui_listview_end_transaction(gate_ui_listview_t* lstvw) | |
| 674 | { | ||
| 675 | 1 | gate_result_t ret = GATE_RESULT_OK; | |
| 676 | 1 | gate_arraylist_t arr = (gate_arraylist_t)lstvw->transaction; | |
| 677 | 1 | lstvw->transaction = NULL; | |
| 678 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (arr != NULL) |
| 679 | { | ||
| 680 | 1 | WidgetList lst = (WidgetList)gate_arraylist_get(arr, 0); | |
| 681 | 1 | Cardinal widget_count = gate_arraylist_length(arr); | |
| 682 | 1 | XtManageChildren(lst, widget_count); | |
| 683 | 1 | gate_arraylist_release(arr); | |
| 684 | } | ||
| 685 | 1 | return ret; | |
| 686 | } | ||
| 687 | |||
| 688 | 26 | gate_result_t gate_ui_listview_insert_item(gate_ui_listview_t* lstvw, gate_size_t const* atIndex, gate_string_t const* text, | |
| 689 | gate_intptr_t icon_key, void* itemparam) | ||
| 690 | { | ||
| 691 | Widget w_lstvw; | ||
| 692 | Widget new_widget; | ||
| 693 | 26 | Arg args[12] = GATE_INIT_EMPTY; | |
| 694 | 26 | Cardinal arg_count = 0; | |
| 695 | 26 | XmString main_text = NULL; | |
| 696 | XmStringTable text_items; | ||
| 697 | gate_size_t ndx; | ||
| 698 | Cardinal col_count; | ||
| 699 | Pixmap pm_image; | ||
| 700 | Pixmap pm_mask; | ||
| 701 | gate_result_t result; | ||
| 702 | |||
| 703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!lstvw) |
| 704 | { | ||
| 705 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 706 | } | ||
| 707 | 26 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!w_lstvw) |
| 709 | { | ||
| 710 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 711 | } | ||
| 712 | |||
| 713 | 26 | col_count = (Cardinal)gate_ui_listview_get_column_count(lstvw); | |
| 714 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (col_count > 0) |
| 715 | { | ||
| 716 | 26 | main_text = gate_ui_motif_create_string(text); | |
| 717 | 26 | --col_count; | |
| 718 | } | ||
| 719 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (col_count > 0) |
| 720 | { | ||
| 721 | 26 | text_items = (XmStringTable)XtMalloc(col_count * sizeof(XmString)); | |
| 722 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!text_items) |
| 723 | { | ||
| 724 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 725 | } | ||
| 726 | } | ||
| 727 | else | ||
| 728 | { | ||
| 729 | ✗ | text_items = NULL; | |
| 730 | } | ||
| 731 | |||
| 732 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
|
78 | for (ndx = 0; ndx < col_count; ++ndx) |
| 733 | { | ||
| 734 | 52 | text_items[ndx] = NULL; | |
| 735 | } | ||
| 736 | |||
| 737 | 26 | XtSetArg(args[arg_count], XmNviewType, XmSMALL_ICON); ++arg_count; | |
| 738 | 26 | XtSetArg(args[arg_count], XmNshadowThickness, 0); ++arg_count; | |
| 739 | 26 | XtSetArg(args[arg_count], XmNlabelString, main_text); ++arg_count; | |
| 740 | 26 | XtSetArg(args[arg_count], XmNdetail, text_items); ++arg_count; | |
| 741 | 26 | XtSetArg(args[arg_count], XmNdetailCount, col_count); ++arg_count; | |
| 742 | 26 | XtSetArg(args[arg_count], XmNuserData, itemparam); ++arg_count; | |
| 743 | |||
| 744 | 26 | result = motif_ctrl_get_pixmap_image(&lstvw->icons, icon_key, &pm_image, &pm_mask); | |
| 745 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (GATE_SUCCEEDED(result)) |
| 746 | { | ||
| 747 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (pm_image) |
| 748 | { | ||
| 749 | 13 | XtSetArg(args[arg_count], XmNsmallIconPixmap, pm_image); | |
| 750 | 13 | ++arg_count; | |
| 751 | } | ||
| 752 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (pm_mask) |
| 753 | { | ||
| 754 | 13 | XtSetArg(args[arg_count], XmNsmallIconMask, pm_mask); | |
| 755 | 13 | ++arg_count; | |
| 756 | } | ||
| 757 | } | ||
| 758 | |||
| 759 | 26 | new_widget = XmCreateIconGadget(w_lstvw, NULL, args, arg_count); | |
| 760 | |||
| 761 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!new_widget) |
| 762 | { | ||
| 763 | ✗ | return GATE_RESULT_FAILED; | |
| 764 | } | ||
| 765 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (lstvw->transaction == NULL) |
| 766 | { | ||
| 767 | 1 | XtManageChild(new_widget); | |
| 768 | if (atIndex) | ||
| 769 | { | ||
| 770 | /* TODO: Implement reorder: XmNpositionIndex / XmContainerReorder */ | ||
| 771 | } | ||
| 772 | } | ||
| 773 | else | ||
| 774 | { | ||
| 775 | 25 | gate_arraylist_t arr = (gate_arraylist_t)lstvw->transaction; | |
| 776 | 25 | gate_arraylist_add(arr, &new_widget); | |
| 777 | } | ||
| 778 | |||
| 779 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (text_items) |
| 780 | { | ||
| 781 | 26 | XtFree((char*)text_items); | |
| 782 | } | ||
| 783 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (main_text) |
| 784 | { | ||
| 785 | 26 | XmStringFree(main_text); | |
| 786 | } | ||
| 787 | |||
| 788 | 26 | return GATE_RESULT_OK; | |
| 789 | } | ||
| 790 | |||
| 791 | 26 | static void gate_ui_listview_destroy_item_widget(Widget w) | |
| 792 | { | ||
| 793 | 26 | XmString text = NULL; | |
| 794 | 26 | XtVaGetValues(w, XmNlabelString, &text, NULL, NULL); | |
| 795 | 26 | XtVaSetValues(w, XmNlabelString, NULL, NULL, NULL); | |
| 796 | |||
| 797 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (text) |
| 798 | { | ||
| 799 | 26 | XmStringFree(text); | |
| 800 | } | ||
| 801 | 26 | XtDestroyWidget(w); | |
| 802 | 26 | } | |
| 803 | |||
| 804 | 5 | gate_result_t gate_ui_listview_remove_item(gate_ui_listview_t* lstvw, gate_size_t index) | |
| 805 | { | ||
| 806 | Widget w; | ||
| 807 | 5 | Cardinal detail_count = 0; | |
| 808 | 5 | XmStringTable detail_tbl = NULL; | |
| 809 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 810 | 5 | w = motif_listview_get_item_widget(lstvw, index); | |
| 811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (w == NULL) |
| 812 | { | ||
| 813 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 814 | } | ||
| 815 | 5 | XtUnmanageChild(w); | |
| 816 | 5 | gate_ui_listview_destroy_item_widget(w); | |
| 817 | |||
| 818 | 5 | return GATE_RESULT_OK; | |
| 819 | } | ||
| 820 | |||
| 821 | 2 | static gate_arraylist_t gate_ui_listview_get_all_item_widgets(gate_ui_listview_t* lstvw) | |
| 822 | { | ||
| 823 | 2 | gate_arraylist_t ret = NULL; | |
| 824 | 2 | WidgetList wl = NULL; | |
| 825 | 2 | gate_size_t widget_count = 0; | |
| 826 | 2 | gate_result_t result = motif_listview_get_children(&lstvw->ctrl, (void**)&wl, &widget_count); | |
| 827 | |||
| 828 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (GATE_SUCCEEDED(result)) |
| 829 | { | ||
| 830 | gate_size_t ndx; | ||
| 831 | 2 | ret = gate_arraylist_create(sizeof(Widget), NULL, widget_count, NULL, NULL); | |
| 832 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ret != NULL) |
| 833 | { | ||
| 834 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 835 | { | ||
| 836 | 23 | Widget w = wl[ndx]; | |
| 837 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 21 times.
|
23 | if (!XmIsIconGadget(w)) |
| 838 | { | ||
| 839 | 2 | continue; | |
| 840 | } | ||
| 841 | 21 | gate_arraylist_add(ret, &w); | |
| 842 | } | ||
| 843 | } | ||
| 844 | } | ||
| 845 | 2 | return ret; | |
| 846 | } | ||
| 847 | |||
| 848 | 2 | gate_result_t gate_ui_listview_remove_all_items(gate_ui_listview_t* lstvw) | |
| 849 | { | ||
| 850 | 2 | gate_arraylist_t arr = gate_ui_listview_get_all_item_widgets(lstvw); | |
| 851 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (arr != NULL) |
| 852 | { | ||
| 853 | 2 | WidgetList wl = (WidgetList)gate_arraylist_get(arr, 0); | |
| 854 | 2 | gate_size_t wl_length = gate_arraylist_length(arr); | |
| 855 | gate_size_t ndx; | ||
| 856 | 2 | XtUnmanageChildren(wl, (Cardinal)wl_length); | |
| 857 | |||
| 858 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
|
23 | for (ndx = 0; ndx != wl_length; ++ndx) |
| 859 | { | ||
| 860 | 21 | gate_ui_listview_destroy_item_widget(wl[ndx]); | |
| 861 | } | ||
| 862 | 2 | gate_arraylist_release(arr); | |
| 863 | } | ||
| 864 | Widget w_list; | ||
| 865 | 2 | gate_size_t count = 0; | |
| 866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 867 | |||
| 868 | 2 | count = gate_ui_listview_get_item_count(lstvw); | |
| 869 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | while (count-- > 0) |
| 870 | { | ||
| 871 | ✗ | gate_ui_listview_remove_item(lstvw, count); | |
| 872 | } | ||
| 873 | 2 | return GATE_RESULT_OK; | |
| 874 | } | ||
| 875 | |||
| 876 | 34 | gate_size_t gate_ui_listview_get_item_count(gate_ui_listview_t* lstvw) | |
| 877 | { | ||
| 878 | 34 | WidgetList wl = NULL; | |
| 879 | 34 | gate_size_t widget_count = 0; | |
| 880 | 34 | gate_size_t item_count = 0; | |
| 881 | gate_result_t ret; | ||
| 882 | |||
| 883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
|
34 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 884 | 34 | ret = gate_ui_motif_ctrl_get_children(&lstvw->ctrl, (void**)&wl, &widget_count); | |
| 885 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | if (GATE_SUCCEEDED(ret)) |
| 886 | { | ||
| 887 | gate_size_t ndx; | ||
| 888 |
2/2✓ Branch 0 taken 514 times.
✓ Branch 1 taken 34 times.
|
548 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 889 | { | ||
| 890 | 514 | Widget w = wl[ndx]; | |
| 891 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 480 times.
|
514 | if (!XmIsIconGadget(w)) |
| 892 | { | ||
| 893 | 34 | continue; | |
| 894 | } | ||
| 895 | 480 | ++item_count; | |
| 896 | } | ||
| 897 | } | ||
| 898 | 34 | return item_count; | |
| 899 | } | ||
| 900 | |||
| 901 | 1 | void* gate_ui_listview_get_item_param(gate_ui_listview_t* lstvw, gate_size_t index) | |
| 902 | { | ||
| 903 | 1 | void* data = NULL; | |
| 904 | Widget w; | ||
| 905 | |||
| 906 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 907 | 1 | w = motif_listview_get_item_widget(lstvw, index); | |
| 908 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w != NULL) |
| 909 | { | ||
| 910 | 1 | XtVaGetValues(w, XmNuserData, &data, NULL, NULL); | |
| 911 | } | ||
| 912 | 1 | return data; | |
| 913 | } | ||
| 914 | |||
| 915 | 1 | gate_result_t gate_ui_listview_find_param(gate_ui_listview_t* lstvw, void* param, gate_size_t startIndex, gate_size_t* foundIndex) | |
| 916 | { | ||
| 917 | 1 | WidgetList wl = NULL; | |
| 918 | 1 | gate_size_t widget_count = 0; | |
| 919 | gate_result_t result; | ||
| 920 | |||
| 921 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 922 | 1 | result = motif_listview_get_children(&lstvw->ctrl, (void**)&wl, &widget_count); | |
| 923 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (GATE_SUCCEEDED(result)) |
| 924 | { | ||
| 925 | 1 | gate_size_t item_count = 0; | |
| 926 | gate_size_t ndx; | ||
| 927 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 928 | { | ||
| 929 | 2 | Widget w = wl[ndx]; | |
| 930 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | if (!XmIsIconGadget(w)) |
| 931 | { | ||
| 932 | 1 | continue; | |
| 933 | } | ||
| 934 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (item_count >= startIndex) |
| 935 | { | ||
| 936 | 1 | void* data = NULL; | |
| 937 | 1 | XtVaGetValues(w, XmNuserData, &data, NULL, NULL); | |
| 938 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (data == param) |
| 939 | { | ||
| 940 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (foundIndex) |
| 941 | { | ||
| 942 | 1 | *foundIndex = ndx; | |
| 943 | } | ||
| 944 | 1 | return GATE_RESULT_OK; | |
| 945 | } | ||
| 946 | } | ||
| 947 | ✗ | ++item_count; | |
| 948 | } | ||
| 949 | } | ||
| 950 | ✗ | return GATE_RESULT_NOMATCH; | |
| 951 | } | ||
| 952 | |||
| 953 | 1 | gate_result_t gate_ui_listview_get_text(gate_ui_listview_t* lstvw, gate_size_t index, gate_size_t subindex, gate_string_t* text) | |
| 954 | { | ||
| 955 | Widget w; | ||
| 956 | 1 | XmString xmstr = NULL; | |
| 957 | 1 | XmStringTable strtbl = NULL; | |
| 958 | 1 | Cardinal strcnt = 0; | |
| 959 | |||
| 960 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 961 | 1 | w = motif_listview_get_item_widget(lstvw, index); | |
| 962 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 963 | { | ||
| 964 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 965 | } | ||
| 966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (subindex == 0) |
| 967 | { | ||
| 968 | ✗ | XtVaGetValues(w, XmNlabelString, &xmstr, NULL, NULL); | |
| 969 | ✗ | if (text) | |
| 970 | { | ||
| 971 | ✗ | return gate_ui_motif_convert_string(xmstr, text); | |
| 972 | } | ||
| 973 | } | ||
| 974 | else | ||
| 975 | { | ||
| 976 | 1 | XtVaGetValues(w, XmNdetailCount, &strcnt, XmNdetail, &strtbl, NULL, NULL); | |
| 977 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (subindex >= strcnt) |
| 978 | { | ||
| 979 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 980 | } | ||
| 981 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (text) |
| 982 | { | ||
| 983 | 1 | return gate_ui_motif_convert_string(strtbl[subindex], text); | |
| 984 | } | ||
| 985 | } | ||
| 986 | ✗ | return GATE_RESULT_OK; | |
| 987 | } | ||
| 988 | |||
| 989 | 26 | gate_result_t gate_ui_listview_set_text(gate_ui_listview_t* lstvw, gate_size_t index, gate_size_t subindex, gate_string_t const* text) | |
| 990 | { | ||
| 991 | Widget w_lstvw; | ||
| 992 | Widget new_widget; | ||
| 993 | Widget item_widget; | ||
| 994 | 26 | XmStringTable text_items = NULL; | |
| 995 | 26 | XmString xmstr = NULL; | |
| 996 | 26 | XmString oldstr = NULL; | |
| 997 | gate_size_t ndx; | ||
| 998 | Cardinal col_count; | ||
| 999 | 26 | Cardinal text_items_count = 0; | |
| 1000 | |||
| 1001 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 1002 | |||
| 1003 | 26 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 1004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!w_lstvw) |
| 1005 | { | ||
| 1006 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1007 | } | ||
| 1008 | |||
| 1009 | 26 | item_widget = motif_listview_get_item_widget(lstvw, index); | |
| 1010 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!item_widget) |
| 1011 | { | ||
| 1012 | ✗ | return GATE_RESULT_NOMATCH; | |
| 1013 | } | ||
| 1014 | |||
| 1015 | 26 | col_count = (Cardinal)gate_ui_listview_get_column_count(lstvw); | |
| 1016 | |||
| 1017 | 26 | xmstr = gate_ui_motif_create_string(text); | |
| 1018 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (subindex == 0) |
| 1019 | { | ||
| 1020 | ✗ | XtVaGetValues(item_widget, XmNlabelString, &oldstr, NULL, NULL); | |
| 1021 | ✗ | XtVaSetValues(item_widget, XmNlabelString, xmstr, NULL, NULL); | |
| 1022 | } | ||
| 1023 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | else if (subindex < col_count) |
| 1024 | { | ||
| 1025 | 26 | XtVaGetValues(item_widget, XmNdetailCount, &text_items_count, XmNdetail, &text_items, NULL, NULL); | |
| 1026 |
2/4✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
|
26 | if (text_items && (subindex - 1 < text_items_count)) |
| 1027 | { | ||
| 1028 | 26 | oldstr = text_items[subindex - 1]; | |
| 1029 | 26 | text_items[subindex - 1] = xmstr; | |
| 1030 | } | ||
| 1031 | } | ||
| 1032 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (oldstr) |
| 1033 | { | ||
| 1034 | 1 | XmStringFree(oldstr); | |
| 1035 | } | ||
| 1036 | 26 | return GATE_RESULT_OK; | |
| 1037 | } | ||
| 1038 | |||
| 1039 | ✗ | gate_bool_t gate_ui_listview_is_checked(gate_ui_listview_t* lstvw, gate_size_t index) | |
| 1040 | { | ||
| 1041 | ✗ | return false; | |
| 1042 | } | ||
| 1043 | |||
| 1044 | 1 | gate_result_t gate_ui_listview_set_checked(gate_ui_listview_t* lstvw, gate_size_t index, gate_bool_t checked) | |
| 1045 | { | ||
| 1046 | /* TODO: Implementation */ | ||
| 1047 | 1 | return GATE_RESULT_OK; | |
| 1048 | } | ||
| 1049 | |||
| 1050 | 1 | gate_result_t gate_ui_listview_get_checked_items(gate_ui_listview_t* lstvw, gate_array_t* indexarray) | |
| 1051 | { | ||
| 1052 | /* TODO: Implementation*/ | ||
| 1053 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(indexarray) |
| 1054 | { | ||
| 1055 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_array_create_empty(indexarray)) |
| 1056 | { | ||
| 1057 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 1058 | } | ||
| 1059 | } | ||
| 1060 | 1 | return GATE_RESULT_OK; | |
| 1061 | } | ||
| 1062 | |||
| 1063 | 1 | gate_bool_t gate_ui_listview_is_selected(gate_ui_listview_t* lstvw, gate_size_t index) | |
| 1064 | { | ||
| 1065 | Widget w_lstvw; | ||
| 1066 | Widget w_item; | ||
| 1067 | 1 | Cardinal selcnt = 0; | |
| 1068 | 1 | WidgetList selitems = NULL; | |
| 1069 | unsigned ndx; | ||
| 1070 | |||
| 1071 | 1 | w_item = motif_listview_get_item_widget(lstvw, index); | |
| 1072 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_item) |
| 1073 | { | ||
| 1074 | ✗ | return false; | |
| 1075 | } | ||
| 1076 | |||
| 1077 | 1 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 1078 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_lstvw) |
| 1079 | { | ||
| 1080 | ✗ | return false; | |
| 1081 | } | ||
| 1082 | |||
| 1083 | 1 | XtVaGetValues(w_lstvw, XmNselectedObjectCount, &selcnt, XmNselectedObjects, &selitems, NULL, NULL); | |
| 1084 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if ((selitems == NULL) || (selcnt == 0)) |
| 1085 | { | ||
| 1086 | ✗ | return false; | |
| 1087 | } | ||
| 1088 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | for (ndx = 0; ndx != selcnt; ++ndx) |
| 1089 | { | ||
| 1090 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (selitems[ndx] == w_item) |
| 1091 | { | ||
| 1092 | 1 | return true; | |
| 1093 | } | ||
| 1094 | } | ||
| 1095 | ✗ | return false; | |
| 1096 | } | ||
| 1097 | |||
| 1098 | 1 | gate_result_t gate_ui_listview_get_selected_item(gate_ui_listview_t* lstvw, gate_size_t* index) | |
| 1099 | { | ||
| 1100 | Widget w_lstvw; | ||
| 1101 | 1 | Cardinal selcnt = 0; | |
| 1102 | 1 | WidgetList selitems = NULL; | |
| 1103 | |||
| 1104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 1105 | |||
| 1106 | 1 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 1107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_lstvw) |
| 1108 | { | ||
| 1109 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1110 | } | ||
| 1111 | |||
| 1112 | 1 | XtVaGetValues(w_lstvw, XmNselectedObjectCount, &selcnt, XmNselectedObjects, &selitems, NULL, NULL); | |
| 1113 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if ((selcnt == 0) || (selitems == NULL)) |
| 1114 | { | ||
| 1115 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 1116 | } | ||
| 1117 | |||
| 1118 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (index) |
| 1119 | { | ||
| 1120 | 1 | *index = motif_listview_resolve_item_widget_index(lstvw, selitems[0]); | |
| 1121 | } | ||
| 1122 | 1 | return GATE_RESULT_OK; | |
| 1123 | } | ||
| 1124 | |||
| 1125 | 1 | gate_result_t gate_ui_listview_get_selected_items(gate_ui_listview_t* lstvw, gate_array_t* indexarray) | |
| 1126 | { | ||
| 1127 | Widget w_lstvw; | ||
| 1128 | 1 | Cardinal selcnt = 0; | |
| 1129 | Cardinal ndx; | ||
| 1130 | 1 | WidgetList selitems = NULL; | |
| 1131 | 1 | gate_arraylist_t arr = NULL; | |
| 1132 | |||
| 1133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 1134 | |||
| 1135 | 1 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 1136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_lstvw) |
| 1137 | { | ||
| 1138 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1139 | } | ||
| 1140 | |||
| 1141 | 1 | XtVaGetValues(w_lstvw, XmNselectedObjectCount, &selcnt, XmNselectedObjects, &selitems, NULL, NULL); | |
| 1142 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if ((selcnt == 0) || (selitems == NULL)) |
| 1143 | { | ||
| 1144 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 1145 | } | ||
| 1146 | |||
| 1147 | 1 | arr = gate_arraylist_create(sizeof(gate_size_t), NULL, selcnt, NULL, NULL); | |
| 1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (arr == NULL) |
| 1149 | { | ||
| 1150 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 1151 | } | ||
| 1152 | |||
| 1153 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (ndx = 0; ndx != selcnt; ++ndx) |
| 1154 | { | ||
| 1155 | 1 | gate_size_t itemndx = motif_listview_resolve_item_widget_index(lstvw, selitems[ndx]); | |
| 1156 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (itemndx != GATE_STR_NPOS) |
| 1157 | { | ||
| 1158 | 1 | gate_arraylist_add(arr, &itemndx); | |
| 1159 | } | ||
| 1160 | } | ||
| 1161 | |||
| 1162 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (indexarray) |
| 1163 | { | ||
| 1164 | 1 | gate_array_create(indexarray, arr); | |
| 1165 | |||
| 1166 | } | ||
| 1167 | |||
| 1168 | 1 | gate_arraylist_release(arr); | |
| 1169 | 1 | return GATE_RESULT_OK; | |
| 1170 | } | ||
| 1171 | |||
| 1172 | 2 | gate_result_t gate_ui_listview_select_item(gate_ui_listview_t* lstvw, gate_size_t index, gate_bool_t selected) | |
| 1173 | { | ||
| 1174 | Widget w_lstvw; | ||
| 1175 | Widget w_item; | ||
| 1176 | Widget sel_widgets[1]; | ||
| 1177 | |||
| 1178 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATE_DEBUG_ASSERT(lstvw != NULL); |
| 1179 | |||
| 1180 | 2 | w_lstvw = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&lstvw->ctrl); | |
| 1181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!w_lstvw) |
| 1182 | { | ||
| 1183 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1184 | } | ||
| 1185 | |||
| 1186 | 2 | w_item = motif_listview_get_item_widget(lstvw, index); | |
| 1187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (w_item == NULL) |
| 1188 | { | ||
| 1189 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 1190 | } | ||
| 1191 | |||
| 1192 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (selected) |
| 1193 | { | ||
| 1194 | 2 | sel_widgets[0] = w_item; | |
| 1195 | 2 | XtVaSetValues(w_lstvw, XmNselectedObjects, &sel_widgets[0], XmNselectedObjectCount, 1, NULL, NULL); | |
| 1196 | } | ||
| 1197 | else | ||
| 1198 | { | ||
| 1199 | ✗ | XtVaSetValues(w_lstvw, XmNselectedObjects, NULL, XmNselectedObjectCount, 0, NULL, NULL); | |
| 1200 | } | ||
| 1201 | |||
| 1202 | 2 | return GATE_RESULT_OK; | |
| 1203 | } | ||
| 1204 | |||
| 1205 | |||
| 1206 | |||
| 1207 | |||
| 1208 | |||
| 1209 | 1 | static gate_result_t motif_itemview_destroy(gate_ui_ctrl_t* ctrl) | |
| 1210 | { | ||
| 1211 | 1 | gate_ui_itemview_t* iv = (gate_ui_itemview_t*)ctrl; | |
| 1212 | Widget w_scroll; | ||
| 1213 | Widget w_list; | ||
| 1214 | |||
| 1215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(iv != NULL); |
| 1216 | |||
| 1217 | 1 | gate_ui_itemview_remove_all_items(iv); | |
| 1218 | |||
| 1219 | 1 | w_scroll = GATE_UI_MOTIF_GET_CTRL_WIDGET(ctrl); | |
| 1220 | 1 | w_list = GATE_UI_MOTIF_GET_CTRL_CONTAINER(ctrl); | |
| 1221 | |||
| 1222 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_list) |
| 1223 | { | ||
| 1224 | 1 | XtUnmanageChild(w_list); | |
| 1225 | 1 | XtDestroyWidget(w_list); | |
| 1226 | } | ||
| 1227 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll) |
| 1228 | { | ||
| 1229 | 1 | XtUnmanageChild(w_scroll); | |
| 1230 | 1 | XtDestroyWidget(w_scroll); | |
| 1231 | } | ||
| 1232 | |||
| 1233 | 1 | gate_mem_clear(ctrl, sizeof(gate_ui_ctrl_t)); | |
| 1234 | 1 | return GATE_RESULT_OK; | |
| 1235 | } | ||
| 1236 | |||
| 1237 | |||
| 1238 | static gate_ui_motif_dispatcher_t itemview_dispatcher = | ||
| 1239 | { | ||
| 1240 | &motif_itemview_destroy, | ||
| 1241 | NULL, | ||
| 1242 | NULL, | ||
| 1243 | NULL, | ||
| 1244 | NULL, | ||
| 1245 | NULL, | ||
| 1246 | NULL | ||
| 1247 | }; | ||
| 1248 | |||
| 1249 | |||
| 1250 | 17 | static Widget motif_itemview_get_item_widget(gate_ui_itemview_t* itemview, gate_size_t index) | |
| 1251 | { | ||
| 1252 | gate_result_t result; | ||
| 1253 | 17 | WidgetList wl = NULL; | |
| 1254 | 17 | gate_size_t widget_count = 0; | |
| 1255 | gate_size_t n; | ||
| 1256 | 17 | gate_size_t real_index = 0; | |
| 1257 | |||
| 1258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1259 | 17 | result = gate_ui_motif_ctrl_get_children(&itemview->ctrl, (void**)&wl, &widget_count); | |
| 1260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (GATE_FAILED(result)) |
| 1261 | { | ||
| 1262 | ✗ | return NULL; | |
| 1263 | } | ||
| 1264 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | for (n = 0; n < widget_count; ++n) |
| 1265 | { | ||
| 1266 | 37 | Widget w = wl[n]; | |
| 1267 |
1/2✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
|
37 | if(XtIsSubclass(w, xmIconGadgetClass)) |
| 1268 | { | ||
| 1269 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 20 times.
|
37 | if (index == real_index) |
| 1270 | { | ||
| 1271 | 17 | return w; | |
| 1272 | } | ||
| 1273 | 20 | ++real_index; | |
| 1274 | } | ||
| 1275 | } | ||
| 1276 | ✗ | return NULL; | |
| 1277 | } | ||
| 1278 | |||
| 1279 | 1 | static gate_size_t motif_itemview_resolve_item_widget_index(gate_ui_itemview_t* itemview, Widget item_widget) | |
| 1280 | { | ||
| 1281 | gate_result_t result; | ||
| 1282 | 1 | WidgetList wl = NULL; | |
| 1283 | 1 | gate_size_t widget_count = 0; | |
| 1284 | gate_size_t ndx; | ||
| 1285 | 1 | gate_size_t real_index = 0; | |
| 1286 | |||
| 1287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1288 | 1 | result = gate_ui_motif_ctrl_get_children(&itemview->ctrl, (void**)&wl, &widget_count); | |
| 1289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (GATE_FAILED(result)) |
| 1290 | { | ||
| 1291 | ✗ | return GATE_STR_NPOS; | |
| 1292 | } | ||
| 1293 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | for (ndx = 0; ndx != widget_count; ++ndx) |
| 1294 | { | ||
| 1295 | 2 | Widget w = wl[ndx]; | |
| 1296 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if(XtIsSubclass(w, xmIconGadgetClass)) |
| 1297 | { | ||
| 1298 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (w == item_widget) |
| 1299 | { | ||
| 1300 | 1 | return real_index; | |
| 1301 | } | ||
| 1302 | 1 | ++real_index; | |
| 1303 | } | ||
| 1304 | } | ||
| 1305 | ✗ | return GATE_STR_NPOS; | |
| 1306 | } | ||
| 1307 | |||
| 1308 | |||
| 1309 | ✗ | static void motif_itemview_selection_callback(Widget widget, XtPointer client_data, XtPointer call_data) | |
| 1310 | { | ||
| 1311 | ✗ | gate_ui_itemview_t* iv = (gate_ui_itemview_t*)client_data; | |
| 1312 | ✗ | XmContainerSelectCallbackStruct* evt_data = (XmContainerSelectCallbackStruct*)call_data; | |
| 1313 | ✗ | void* item_data = NULL; | |
| 1314 | |||
| 1315 | ✗ | if (iv && iv->on_select && evt_data && evt_data->selected_item_count > 0) | |
| 1316 | { | ||
| 1317 | ✗ | Widget item_widget = evt_data->selected_items[0]; | |
| 1318 | ✗ | gate_size_t item_index = motif_itemview_resolve_item_widget_index(iv, item_widget); | |
| 1319 | ✗ | if (item_index != GATE_STR_NPOS) | |
| 1320 | { | ||
| 1321 | ✗ | XtVaGetValues(item_widget, XmNuserData, &item_data, NULL, NULL); | |
| 1322 | ✗ | iv->on_select(&iv->ctrl, item_index, item_data); | |
| 1323 | } | ||
| 1324 | } | ||
| 1325 | ✗ | } | |
| 1326 | |||
| 1327 | 1 | gate_result_t gate_ui_itemview_create(gate_ui_itemview_t* itemview, gate_ui_ctrl_t* parent, gate_ui_position_t const* position, | |
| 1328 | gate_uint32_t flags, void* userparam) | ||
| 1329 | { | ||
| 1330 | 1 | gate_result_t ret = GATE_RESULT_FAILED; | |
| 1331 | |||
| 1332 | do | ||
| 1333 | { | ||
| 1334 | 1 | Widget parent_widget = NULL; | |
| 1335 | Widget w; | ||
| 1336 | Widget w_list; | ||
| 1337 | 1 | Widget w_scroll1 = NULL; | |
| 1338 | 1 | Widget w_scroll2 = NULL; | |
| 1339 | Arg args[12]; | ||
| 1340 | Cardinal args_count; | ||
| 1341 | gate_ui_host_t* ptr_host; | ||
| 1342 | |||
| 1343 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!itemview || !parent) |
| 1344 | { | ||
| 1345 | ✗ | ret = GATE_RESULT_INVALIDARG; | |
| 1346 | ✗ | break; | |
| 1347 | } | ||
| 1348 | |||
| 1349 | 1 | ptr_host = GATE_UI_MOTIF_GET_CTRL_HOST(parent); | |
| 1350 | 1 | parent_widget = GATE_UI_MOTIF_GET_CTRL_CONTAINER(parent); | |
| 1351 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!parent_widget) |
| 1352 | { | ||
| 1353 | 1 | parent_widget = GATE_UI_MOTIF_GET_CTRL_WIDGET(parent); | |
| 1354 | } | ||
| 1355 | 1 | args_count = 0; | |
| 1356 | |||
| 1357 | 1 | XtSetArg(args[args_count], XmNscrollingPolicy, XmAUTOMATIC); ++args_count; | |
| 1358 | 1 | XtSetArg(args[args_count], XmNvisualPolicy, XmVARIABLE); ++args_count; | |
| 1359 | 1 | XtSetArg(args[args_count], XmNscrollBarDisplayPolicy, XmSTATIC); ++args_count; | |
| 1360 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 1361 | 1 | XtSetArg(args[args_count], XmNhighlightThickness, 1); ++args_count; | |
| 1362 | |||
| 1363 | 1 | w = XmCreateScrolledWindow(parent_widget, NULL, args, args_count); | |
| 1364 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w) |
| 1365 | { | ||
| 1366 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 1367 | ✗ | break; | |
| 1368 | } | ||
| 1369 | |||
| 1370 | 1 | XtVaGetValues(w, XmNhorizontalScrollBar, &w_scroll1, XmNverticalScrollBar, &w_scroll2, NULL, NULL); | |
| 1371 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll1 != NULL) |
| 1372 | { | ||
| 1373 | 1 | XtSetSensitive(w_scroll1, False); | |
| 1374 | } | ||
| 1375 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (w_scroll2 != NULL) |
| 1376 | { | ||
| 1377 | 1 | XtVaSetValues(w_scroll2, XmNshadowThickness, 1, NULL, NULL); | |
| 1378 | } | ||
| 1379 | |||
| 1380 | 1 | args_count = 0; | |
| 1381 | 1 | XtSetArg(args[args_count], XmNlayoutType, XmSPATIAL); ++args_count; | |
| 1382 | 1 | XtSetArg(args[args_count], XmNspatialStyle, XmGRID); ++args_count; | |
| 1383 | 1 | XtSetArg(args[args_count], XmNspatialResizeModel, XmGROW_MINOR); ++args_count; | |
| 1384 | 1 | XtSetArg(args[args_count], XmNspatialSnapModel, XmSNAP_TO_GRID); ++args_count; | |
| 1385 | 1 | XtSetArg(args[args_count], XmNspatialIncludeModel, XmFIRST_FIT); ++args_count; | |
| 1386 | 1 | XtSetArg(args[args_count], XmNlayoutDirection, XmTOP_TO_BOTTOM_LEFT_TO_RIGHT); ++args_count; | |
| 1387 | 1 | XtSetArg(args[args_count], XmNautomaticSelection, XmAUTO_SELECT); ++args_count; | |
| 1388 | 1 | XtSetArg(args[args_count], XmNselectionPolicy, XmSINGLE_SELECT); ++args_count; | |
| 1389 | 1 | XtSetArg(args[args_count], XmNlargeCellWidth, 640); ++args_count; | |
| 1390 | |||
| 1391 | 1 | XtSetArg(args[args_count], XmNshadowThickness, 1); ++args_count; | |
| 1392 | |||
| 1393 | 1 | w_list = XmCreateContainer(w, NULL, args, args_count); | |
| 1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_list) |
| 1395 | { | ||
| 1396 | ✗ | XtDestroyWidget(w); | |
| 1397 | ✗ | ret = GATE_RESULT_OUTOFRESOURCES; | |
| 1398 | ✗ | break; | |
| 1399 | } | ||
| 1400 | |||
| 1401 | 1 | ret = gate_ui_motif_ctrl_init(&itemview->ctrl, w, userparam, NULL, parent, w_list, position, &flags, &itemview_dispatcher); | |
| 1402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_BREAK_IF_FAILED(ret); |
| 1403 | |||
| 1404 | 1 | gate_ui_iconlist_create(&itemview->icons, ptr_host, 16, 16); | |
| 1405 | |||
| 1406 | 1 | XtManageChild(w); | |
| 1407 | 1 | XtManageChild(w_list); | |
| 1408 | |||
| 1409 | 1 | XtAddCallback(w_list, XmNselectionCallback, &motif_itemview_selection_callback, itemview); | |
| 1410 | } while (0); | ||
| 1411 | |||
| 1412 | 1 | return ret; | |
| 1413 | } | ||
| 1414 | |||
| 1415 | ✗ | gate_result_t gate_ui_itemview_add_icon(gate_ui_itemview_t* itemview, gate_ui_icon_t const* icon, gate_intptr_t* icon_key) | |
| 1416 | { | ||
| 1417 | ✗ | return gate_ui_iconlist_add_icon(&itemview->icons, icon, icon_key); | |
| 1418 | } | ||
| 1419 | |||
| 1420 | ✗ | gate_result_t gate_ui_itemview_add_icon_image(gate_ui_itemview_t* itemview, gate_rasterimage_t const* image, gate_intptr_t* icon_key) | |
| 1421 | { | ||
| 1422 | ✗ | GATE_DEBUG_ASSERT(itemview != NULL); | |
| 1423 | ✗ | return gate_ui_iconlist_add_image(&itemview->icons, image, icon_key); | |
| 1424 | } | ||
| 1425 | |||
| 1426 | 7 | static XmString motif_itemview_create_label(gate_string_t const* title, gate_string_t const* subtitle, gate_string_t const* additionals) | |
| 1427 | { | ||
| 1428 | gate_strbuilder_t sb; | ||
| 1429 | 7 | gate_string_t tmp_text = GATE_STRING_INIT_EMPTY; | |
| 1430 | XmString ret; | ||
| 1431 | |||
| 1432 | 7 | gate_strbuilder_create(&sb, 32); | |
| 1433 | 7 | gate_strbuilder_append_string(&sb, title); | |
| 1434 | 7 | gate_strbuilder_append_cstr(&sb, "\n"); | |
| 1435 | 7 | gate_strbuilder_append_string(&sb, subtitle); | |
| 1436 | 7 | gate_strbuilder_append_cstr(&sb, "\n"); | |
| 1437 | 7 | gate_strbuilder_append_string(&sb, additionals); | |
| 1438 | |||
| 1439 | 7 | gate_strbuilder_to_string(&sb, &tmp_text); | |
| 1440 | 7 | ret = gate_ui_motif_create_string(&tmp_text); | |
| 1441 | 7 | gate_strbuilder_release(&sb); | |
| 1442 | 7 | return ret; | |
| 1443 | } | ||
| 1444 | |||
| 1445 | 4 | gate_result_t gate_ui_itemview_insert(gate_ui_itemview_t* itemview, gate_size_t const* atIndex, gate_string_t const* title, | |
| 1446 | gate_string_t const* subtitle, gate_string_t const* additionals, gate_intptr_t icon_key, void* itemparam) | ||
| 1447 | { | ||
| 1448 | Widget w_view; | ||
| 1449 | Widget new_widget; | ||
| 1450 | 4 | Arg args[16] = GATE_INIT_EMPTY; | |
| 1451 | 4 | Cardinal arg_count = 0; | |
| 1452 | 4 | XmString main_text = NULL; | |
| 1453 | gate_size_t ndx; | ||
| 1454 | Cardinal col_count; | ||
| 1455 | Pixmap pm_image; | ||
| 1456 | Pixmap pm_mask; | ||
| 1457 | gate_result_t result; | ||
| 1458 | |||
| 1459 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1460 | |||
| 1461 | 4 | w_view = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&itemview->ctrl); | |
| 1462 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!w_view) |
| 1463 | { | ||
| 1464 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1465 | } | ||
| 1466 | |||
| 1467 | 4 | main_text = motif_itemview_create_label(title, subtitle, additionals); | |
| 1468 | |||
| 1469 | 4 | XtSetArg(args[arg_count], XmNviewType, XmSMALL_ICON); ++arg_count; | |
| 1470 | 4 | XtSetArg(args[arg_count], XmNshadowThickness, 0); ++arg_count; | |
| 1471 | 4 | XtSetArg(args[arg_count], XmNlabelString, main_text); ++arg_count; | |
| 1472 | 4 | XtSetArg(args[arg_count], XmNuserData, itemparam); ++arg_count; | |
| 1473 | |||
| 1474 | 4 | result = motif_ctrl_get_pixmap_image(&itemview->icons, icon_key, &pm_image, &pm_mask); | |
| 1475 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (GATE_SUCCEEDED(result)) |
| 1476 | { | ||
| 1477 | ✗ | if (pm_image) | |
| 1478 | { | ||
| 1479 | ✗ | XtSetArg(args[arg_count], XmNsmallIconPixmap, pm_image); | |
| 1480 | ✗ | ++arg_count; | |
| 1481 | } | ||
| 1482 | ✗ | if (pm_mask) | |
| 1483 | { | ||
| 1484 | ✗ | XtSetArg(args[arg_count], XmNsmallIconMask, pm_mask); | |
| 1485 | ✗ | ++arg_count; | |
| 1486 | } | ||
| 1487 | } | ||
| 1488 | |||
| 1489 | 4 | new_widget = XmCreateIconGadget(w_view, NULL, args, arg_count); | |
| 1490 | |||
| 1491 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!new_widget) |
| 1492 | { | ||
| 1493 | ✗ | return GATE_RESULT_FAILED; | |
| 1494 | } | ||
| 1495 | 4 | XtManageChild(new_widget); | |
| 1496 | |||
| 1497 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (main_text) |
| 1498 | { | ||
| 1499 | 4 | XmStringFree(main_text); | |
| 1500 | } | ||
| 1501 | |||
| 1502 | 4 | return GATE_RESULT_OK; | |
| 1503 | } | ||
| 1504 | |||
| 1505 | |||
| 1506 | |||
| 1507 | 1 | gate_result_t gate_ui_itemview_remove(gate_ui_itemview_t* itemview, gate_size_t index) | |
| 1508 | { | ||
| 1509 | 1 | Widget w = motif_itemview_get_item_widget(itemview, index); | |
| 1510 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (w == NULL) |
| 1511 | { | ||
| 1512 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 1513 | } | ||
| 1514 | else | ||
| 1515 | { | ||
| 1516 | 1 | XtDestroyWidget(w); | |
| 1517 | 1 | return GATE_RESULT_OK; | |
| 1518 | } | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | 2 | gate_result_t gate_ui_itemview_remove_all_items(gate_ui_itemview_t* itemview) | |
| 1522 | { | ||
| 1523 | 2 | Widget w_list = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&itemview->ctrl); | |
| 1524 | 2 | gate_ui_motif_widget_destroy_children(w_list, false); | |
| 1525 | 2 | return GATE_RESULT_OK; | |
| 1526 | } | ||
| 1527 | |||
| 1528 | 9 | gate_size_t gate_ui_itemview_get_count(gate_ui_itemview_t* itemview) | |
| 1529 | { | ||
| 1530 | 9 | WidgetList wl = NULL; | |
| 1531 | 9 | gate_size_t widget_count = 0; | |
| 1532 | gate_result_t ret; | ||
| 1533 | 9 | gate_size_t real_count = 0; | |
| 1534 | |||
| 1535 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1536 | 9 | ret = gate_ui_motif_ctrl_get_children(&itemview->ctrl, (void**)&wl, &widget_count); | |
| 1537 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (GATE_SUCCEEDED(ret)) |
| 1538 | { | ||
| 1539 | gate_size_t ndx; | ||
| 1540 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 9 times.
|
19 | for (ndx = 0; ndx < widget_count; ++ndx) |
| 1541 | { | ||
| 1542 | 10 | Widget w = wl[ndx]; | |
| 1543 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
|
10 | if (XtIsSubclass(w, xmIconGadgetClass)) |
| 1544 | { | ||
| 1545 | 8 | ++real_count; | |
| 1546 | } | ||
| 1547 | } | ||
| 1548 | 9 | return real_count; | |
| 1549 | } | ||
| 1550 | ✗ | return real_count; | |
| 1551 | } | ||
| 1552 | |||
| 1553 | 2 | void* gate_ui_itemview_get_item_param(gate_ui_itemview_t* itemview, gate_size_t index) | |
| 1554 | { | ||
| 1555 | Widget w; | ||
| 1556 | 2 | void* ret = NULL; | |
| 1557 | |||
| 1558 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1559 | |||
| 1560 | 2 | w = motif_itemview_get_item_widget(itemview, index); | |
| 1561 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (w) |
| 1562 | { | ||
| 1563 | 2 | XtVaGetValues(w, XmNuserData, &ret, NULL, NULL); | |
| 1564 | } | ||
| 1565 | 2 | return ret; | |
| 1566 | } | ||
| 1567 | |||
| 1568 | 2 | gate_result_t gate_ui_itemview_find_param(gate_ui_itemview_t* itemview, void* find_param, gate_size_t startIndex, gate_size_t* foundIndex) | |
| 1569 | { | ||
| 1570 | gate_result_t ret; | ||
| 1571 | |||
| 1572 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1573 | do | ||
| 1574 | { | ||
| 1575 | 2 | WidgetList wl = NULL; | |
| 1576 | Widget w; | ||
| 1577 | 2 | gate_size_t widget_count = 0; | |
| 1578 | gate_size_t ndx; | ||
| 1579 | void* item_param; | ||
| 1580 | |||
| 1581 | 2 | ret = gate_ui_motif_ctrl_get_children(&itemview->ctrl, (void**)&wl, &widget_count); | |
| 1582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATE_BREAK_IF_FAILED(ret); |
| 1583 | |||
| 1584 | 2 | ret = GATE_RESULT_NOMATCH; | |
| 1585 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | for (ndx = startIndex; ndx < widget_count; ++ndx) |
| 1586 | { | ||
| 1587 | 3 | w = wl[ndx]; | |
| 1588 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!w) |
| 1589 | { | ||
| 1590 | ✗ | continue; | |
| 1591 | } | ||
| 1592 | 3 | item_param = NULL; | |
| 1593 | 3 | XtVaGetValues(w, XmNuserData, &item_param, NULL, NULL); | |
| 1594 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (item_param == find_param) |
| 1595 | { | ||
| 1596 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (foundIndex) |
| 1597 | { | ||
| 1598 | 2 | *foundIndex = ndx; | |
| 1599 | } | ||
| 1600 | 2 | ret = GATE_RESULT_OK; | |
| 1601 | 2 | break; | |
| 1602 | } | ||
| 1603 | } | ||
| 1604 | } while (0); | ||
| 1605 | 2 | return ret; | |
| 1606 | } | ||
| 1607 | |||
| 1608 | 9 | gate_result_t gate_ui_itemview_get_text(gate_ui_itemview_t* itemview, gate_size_t index, | |
| 1609 | gate_string_t* title, gate_string_t* subtitle, gate_string_t* additionals) | ||
| 1610 | { | ||
| 1611 | Widget w_item; | ||
| 1612 | XmString xmstr; | ||
| 1613 | 9 | gate_string_t item_str = GATE_STRING_INIT_EMPTY; | |
| 1614 | 9 | gate_size_t pos1 = GATE_STR_NPOS; | |
| 1615 | 9 | gate_size_t pos2 = GATE_STR_NPOS; | |
| 1616 | |||
| 1617 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1618 | |||
| 1619 | 9 | w_item = motif_itemview_get_item_widget(itemview, index); | |
| 1620 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (w_item == NULL) |
| 1621 | { | ||
| 1622 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 1623 | } | ||
| 1624 | |||
| 1625 | 9 | XtVaGetValues(w_item, XmNlabelString, &xmstr, NULL, NULL); | |
| 1626 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (xmstr) |
| 1627 | { | ||
| 1628 | 9 | gate_ui_motif_convert_string(xmstr, &item_str); | |
| 1629 | } | ||
| 1630 | |||
| 1631 | 9 | pos1 = gate_string_char_pos(&item_str, '\n', 0); | |
| 1632 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (pos1 != GATE_STR_NPOS) |
| 1633 | { | ||
| 1634 | ✗ | pos2 = gate_string_char_pos(&item_str, '\n', pos1 + 1); | |
| 1635 | } | ||
| 1636 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (title) |
| 1637 | { | ||
| 1638 | 5 | gate_string_substr(title, &item_str, 0, pos1); | |
| 1639 | } | ||
| 1640 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (subtitle) |
| 1641 | { | ||
| 1642 | 5 | gate_string_substr(subtitle, &item_str, pos1 + 1, pos2 - pos1 - 1); | |
| 1643 | } | ||
| 1644 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (additionals) |
| 1645 | { | ||
| 1646 | 5 | gate_string_substr(additionals, &item_str, pos2 + 1, GATE_STR_NPOS); | |
| 1647 | } | ||
| 1648 | |||
| 1649 | 9 | gate_string_release(&item_str); | |
| 1650 | |||
| 1651 | 9 | return GATE_RESULT_OK; | |
| 1652 | } | ||
| 1653 | |||
| 1654 | 3 | gate_result_t gate_ui_itemview_set_text(gate_ui_itemview_t* itemview, gate_size_t index, | |
| 1655 | gate_string_t const* title, gate_string_t const* subtitle, gate_string_t const* additionals) | ||
| 1656 | { | ||
| 1657 | Widget w_item; | ||
| 1658 | XmString xmstr; | ||
| 1659 | 3 | gate_string_t old_title = GATE_STRING_INIT_EMPTY; | |
| 1660 | 3 | gate_string_t old_subtitle = GATE_STRING_INIT_EMPTY; | |
| 1661 | 3 | gate_string_t old_add = GATE_STRING_INIT_EMPTY; | |
| 1662 | |||
| 1663 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1664 | |||
| 1665 | 3 | w_item = motif_itemview_get_item_widget(itemview, index); | |
| 1666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (w_item == NULL) |
| 1667 | { | ||
| 1668 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 1669 | } | ||
| 1670 | |||
| 1671 |
3/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3 | if (!title || !subtitle || !additionals) |
| 1672 | { | ||
| 1673 | 3 | gate_ui_itemview_get_text(itemview, index, &old_title, &old_subtitle, &old_add); | |
| 1674 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (!title) title = &old_title; |
| 1675 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (!subtitle) subtitle = &old_subtitle; |
| 1676 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (!additionals) additionals = &old_add; |
| 1677 | } | ||
| 1678 | |||
| 1679 | 3 | xmstr = motif_itemview_create_label(title, subtitle, additionals); | |
| 1680 | 3 | XtVaSetValues(w_item, XmNlabelString, xmstr, NULL, NULL); | |
| 1681 | |||
| 1682 | 3 | gate_string_release(&old_title); | |
| 1683 | 3 | gate_string_release(&old_subtitle); | |
| 1684 | 3 | gate_string_release(&old_add); | |
| 1685 | |||
| 1686 | 3 | return GATE_RESULT_OK; | |
| 1687 | } | ||
| 1688 | |||
| 1689 | 1 | gate_bool_t gate_ui_itemview_is_selected(gate_ui_itemview_t* itemview, gate_size_t index) | |
| 1690 | { | ||
| 1691 | Widget w_iv; | ||
| 1692 | Widget w_item; | ||
| 1693 | 1 | Cardinal selcnt = 0; | |
| 1694 | 1 | WidgetList selitems = NULL; | |
| 1695 | unsigned ndx; | ||
| 1696 | |||
| 1697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1698 | |||
| 1699 | 1 | w_item = motif_itemview_get_item_widget(itemview, index); | |
| 1700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_item) |
| 1701 | { | ||
| 1702 | ✗ | return false; | |
| 1703 | } | ||
| 1704 | |||
| 1705 | 1 | w_iv = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&itemview->ctrl); | |
| 1706 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_iv) |
| 1707 | { | ||
| 1708 | ✗ | return false; | |
| 1709 | } | ||
| 1710 | |||
| 1711 | 1 | XtVaGetValues(w_iv, XmNselectedObjectCount, &selcnt, XmNselectedObjects, &selitems, NULL, NULL); | |
| 1712 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if ((selitems == NULL) || (selcnt == 0)) |
| 1713 | { | ||
| 1714 | ✗ | return false; | |
| 1715 | } | ||
| 1716 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | for (ndx = 0; ndx != selcnt; ++ndx) |
| 1717 | { | ||
| 1718 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (selitems[ndx] == w_item) |
| 1719 | { | ||
| 1720 | 1 | return true; | |
| 1721 | } | ||
| 1722 | } | ||
| 1723 | ✗ | return false; | |
| 1724 | } | ||
| 1725 | |||
| 1726 | 1 | gate_result_t gate_ui_itemview_get_selected_item(gate_ui_itemview_t* itemview, gate_size_t* index) | |
| 1727 | { | ||
| 1728 | Widget w_iv; | ||
| 1729 | 1 | Cardinal selcnt = 0; | |
| 1730 | 1 | WidgetList selitems = NULL; | |
| 1731 | |||
| 1732 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1733 | |||
| 1734 | 1 | w_iv = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&itemview->ctrl); | |
| 1735 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_iv) |
| 1736 | { | ||
| 1737 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1738 | } | ||
| 1739 | |||
| 1740 | 1 | XtVaGetValues(w_iv, XmNselectedObjectCount, &selcnt, XmNselectedObjects, &selitems, NULL, NULL); | |
| 1741 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if ((selcnt == 0) || (selitems == NULL)) |
| 1742 | { | ||
| 1743 | ✗ | return GATE_RESULT_NOTAVAILABLE; | |
| 1744 | } | ||
| 1745 | |||
| 1746 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (index) |
| 1747 | { | ||
| 1748 | 1 | *index = motif_itemview_resolve_item_widget_index(itemview, selitems[0]); | |
| 1749 | } | ||
| 1750 | 1 | return GATE_RESULT_OK; | |
| 1751 | } | ||
| 1752 | |||
| 1753 | 1 | gate_result_t gate_ui_itemview_select_item(gate_ui_itemview_t* itemview, gate_size_t index) | |
| 1754 | { | ||
| 1755 | Widget w_iv; | ||
| 1756 | Widget w_item; | ||
| 1757 | Widget sel_widgets[1]; | ||
| 1758 | |||
| 1759 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATE_DEBUG_ASSERT(itemview != NULL); |
| 1760 | |||
| 1761 | 1 | w_iv = GATE_UI_MOTIF_GET_CTRL_CONTAINER(&itemview->ctrl); | |
| 1762 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!w_iv) |
| 1763 | { | ||
| 1764 | ✗ | return GATE_RESULT_INVALIDSTATE; | |
| 1765 | } | ||
| 1766 | |||
| 1767 | 1 | w_item = motif_itemview_get_item_widget(itemview, index); | |
| 1768 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (w_item == NULL) |
| 1769 | { | ||
| 1770 | ✗ | XtVaSetValues(w_iv, XmNselectedObjects, NULL, XmNselectedObjectCount, 0, NULL, NULL); | |
| 1771 | } | ||
| 1772 | else | ||
| 1773 | { | ||
| 1774 | 1 | sel_widgets[0] = w_item; | |
| 1775 | 1 | XtVaSetValues(w_iv, XmNselectedObjects, &sel_widgets[0], XmNselectedObjectCount, 1, NULL, NULL); | |
| 1776 | } | ||
| 1777 | |||
| 1778 | 1 | return GATE_RESULT_OK; | |
| 1779 | } | ||
| 1780 | |||
| 1781 | #endif /* GATE_UI_MOTIF */ | ||
| 1782 |