UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2017 Olaf Wintermann. 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 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef TREE_H 30 #define TREE_H 31 32 #include "../ui/tree.h" 33 #include "toolkit.h" 34 35 #include <cx/array_list.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 typedef struct UiColData UiColData; 42 43 typedef struct UiListView { 44 UiObject *obj; 45 GtkWidget *widget; 46 UiVar *var; 47 UiModel *model; 48 #if GTK_CHECK_VERSION(4, 10, 0) 49 GListStore *liststore; 50 GtkSelectionModel *selectionmodel; 51 UiColData *columns; 52 #endif 53 ui_callback onactivate; 54 void *onactivatedata; 55 ui_callback onselection; 56 void *onselectiondata; 57 ui_callback ondragstart; 58 void *ondragstartdata; 59 ui_callback ondragcomplete; 60 void *ondragcompletedata; 61 ui_callback ondrop; 62 void *ondropdata; 63 UiListSelection selection; 64 65 } UiListView; 66 67 struct UiColData { 68 UiListView *listview; 69 int model_column; 70 int data_column; 71 }; 72 73 typedef struct UiTreeEventData { 74 UiObject *obj; 75 ui_callback activate; 76 ui_callback selection; 77 void *activatedata; 78 void *selectiondata; 79 } UiTreeEventData; 80 81 typedef struct UiListBox UiListBox; 82 83 typedef struct UiListBoxSubList { 84 UiVar *var; 85 size_t numitems; 86 char *header; 87 UiBool separator; 88 CxList *widgets; 89 UiListBox *listbox; 90 void *userdata; 91 size_t index; 92 } UiListBoxSubList; 93 94 struct UiListBox { 95 UiObject *obj; 96 GtkListBox *listbox; 97 CxList *sublists; // contains UiListBoxSubList elements 98 ui_sublist_getvalue_func getvalue; 99 ui_callback onactivate; 100 void *onactivatedata; 101 ui_callback onbuttonclick; 102 void *onbuttonclickdata; 103 104 GtkListBoxRow *first_row; 105 }; 106 107 108 #if GTK_CHECK_VERSION(4, 10, 0) 109 110 void ui_update_liststore(GListStore *liststore, UiList *list); 111 112 void ui_listview_update2(UiList *list, int i); 113 UiListSelection ui_listview_getselection2(UiList *list); 114 void ui_listview_setselection2(UiList *list, UiListSelection selection); 115 116 void ui_columnview_activate(void *ignore, guint position, gpointer userdata); 117 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer user_data); 118 119 void ui_dropdown_activate(GtkDropDown* self, gpointer userdata); 120 121 #endif 122 123 void* ui_strmodel_getvalue(void *elm, int column); 124 125 UIWIDGET ui_listview_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata); 126 UIWIDGET ui_table_var(UiObject *obj, UiVar *var, UiModel *model, UiListCallbacks cb); 127 128 GtkWidget* ui_get_tree_widget(UIWIDGET widget); 129 130 void ui_listview_update(UiList *list, int i); 131 UiListSelection ui_listview_getselection(UiList *list); 132 void ui_listview_setselection(UiList *list, UiListSelection selection); 133 134 void ui_combobox_destroy(GtkWidget *w, UiListView *v); 135 void ui_listview_destroy(GtkWidget *w, UiListView *v); 136 137 #if GTK_CHECK_VERSION(4, 10, 0) 138 139 #else 140 void ui_listview_activate_event( 141 GtkTreeView *tree_view, 142 GtkTreePath *path, 143 GtkTreeViewColumn *column, 144 UiTreeEventData *event); 145 void ui_listview_selection_event( 146 GtkTreeSelection *treeselection, 147 UiTreeEventData *event); 148 UiListSelection ui_listview_selection( 149 GtkTreeSelection *selection, 150 UiTreeEventData *event); 151 int ui_tree_path_list_index(GtkTreePath *path); 152 #endif 153 154 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args); 155 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args); 156 157 UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata); 158 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata); 159 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e); 160 void ui_combobox_modelupdate(UiList *list, int i); 161 UiListSelection ui_combobox_getselection(UiList *list); 162 void ui_combobox_setselection(UiList *list, UiListSelection selection); 163 164 void ui_listbox_update(UiListBox *listbox, int from, int to); 165 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index); 166 void ui_listbox_list_update(UiList *list, int i); 167 168 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data); 169 170 #ifdef __cplusplus 171 } 172 #endif 173 174 #endif /* TREE_H */ 175 176