ui/ui/tree.h

changeset 0
804d8803eade
equal deleted inserted replaced
-1:000000000000 0:804d8803eade
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 UI_TREE_H
30 #define UI_TREE_H
31
32 #include "toolkit.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 typedef struct UiModel UiModel;
39 typedef struct UiListCallbacks UiListCallbacks;
40 typedef struct UiListSelection UiListSelection;
41
42 typedef enum UiModelType {
43 UI_STRING = 0,
44 UI_INTEGER,
45 UI_ICON,
46 UI_ICON_TEXT,
47 } UiModelType;
48
49 struct UiModel {
50 /*
51 * number of columns
52 */
53 int columns;
54
55 /*
56 * array of column types
57 * array length is the number of columns
58 */
59 UiModelType *types;
60
61 /*
62 * array of column titles
63 * array length is the number of columns
64 */
65 char **titles;
66
67 /*
68 * function for translating model data to view data
69 * first argument is the pointer returned by UiList->get or UiTree->get
70 * second argument is the column index
71 * TODO: return
72 */
73 void*(*getvalue)(void*, int);
74
75 UiBool(*candrop)(UiEvent*, UiSelection*, UiList*, int);
76 void(*drop)(UiEvent*, UiSelection*, UiList*, int);
77 UiBool(*candrag)(UiEvent*, UiList*, int);
78 void(*data_get)(UiEvent*, UiSelection*, UiList*, int);
79 void(*data_delete)(UiEvent*, UiList*, int);
80 };
81
82 struct UiListCallbacks {
83 /*
84 * selection callback
85 */
86 ui_callback activate;
87
88 /*
89 * cursor callback
90 */
91 ui_callback selection;
92
93 /*
94 * userdata for all callbacks
95 */
96 void *userdata;
97 };
98
99 struct UiListSelection {
100 /*
101 * number of selected items
102 */
103 int count;
104
105 /*
106 * indices of selected rows
107 */
108 int *rows;
109 };
110
111 UiModel* ui_model(UiContext *ctx, ...);
112 void ui_model_free(UiContext *ctx, UiModel *mi);
113
114 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata);
115 UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata);
116 UIWIDGET ui_listview_nv(UiObject *obj, char *listname, ui_getvaluefunc getvalue, ui_callback f, void *udata);
117
118 UIWIDGET ui_table(UiObject *obj, UiList *data, UiModel *model, UiListCallbacks cb);
119 UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModel *model, UiListCallbacks cb);
120
121 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...);
122 void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm);
123 void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...);
124 void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm);
125
126 UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata);
127 UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata);
128 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata);
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif /* UI_TREE_H */
135

mercurial