ui/ui/tree.h

changeset 0
2483f517c562
child 13
5a8762fcfecc
equal deleted inserted replaced
-1:000000000000 0:2483f517c562
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 typedef struct UiListDnd UiListDnd;
42
43 typedef struct UiListArgs UiListArgs;
44
45 typedef enum UiModelType {
46 UI_STRING = 0,
47 UI_INTEGER,
48 UI_ICON,
49 UI_ICON_TEXT,
50 } UiModelType;
51
52 struct UiModel {
53 /*
54 * number of columns
55 */
56 int columns;
57
58 /*
59 * array of column types
60 * array length is the number of columns
61 */
62 UiModelType *types;
63
64 /*
65 * array of column titles
66 * array length is the number of columns
67 */
68 char **titles;
69
70 /*
71 * function for translating model data to view data
72 * first argument is the pointer returned by UiList->get or UiTree->get
73 * second argument is the column index
74 * TODO: return
75 */
76 void*(*getvalue)(void*, int);
77 };
78
79 struct UiListCallbacks {
80 /*
81 * selection callback
82 */
83 ui_callback activate;
84
85 /*
86 * cursor callback
87 */
88 ui_callback selection;
89
90 /*
91 * userdata for all callbacks
92 */
93 void *userdata;
94 };
95
96 struct UiListSelection {
97 /*
98 * number of selected items
99 */
100 int count;
101
102 /*
103 * indices of selected rows
104 */
105 int *rows;
106 };
107
108 struct UiListDnd {
109 UiListSelection selection;
110 UiDnD *dnd;
111 };
112
113 struct UiListArgs {
114 UiTri fill;
115 UiBool hexpand;
116 UiBool vexpand;
117 int colspan;
118 int rowspan;
119
120 UiList* list;
121 const char* varname;
122 UiModel* model;
123 ui_getvaluefunc getvalue;
124 ui_callback onactivate;
125 void* onactivatedata;
126 ui_callback onselection;
127 void* onselectiondata;
128 ui_callback ondragstart;
129 void* ondragstartdata;
130 ui_callback ondragcomplete;
131 void* ondragcompletedata;
132 ui_callback ondrop;
133 void* ondropsdata;
134 UiBool multiselection;
135 };
136
137 UIEXPORT UiModel* ui_model(UiContext *ctx, ...);
138 UIEXPORT UiModel* ui_model_copy(UiContext *ctx, UiModel* model);
139 UIEXPORT void ui_model_free(UiContext *ctx, UiModel *mi);
140
141 #define ui_listview(obj, ...) ui_listview_create(obj, (UiListArgs) { __VA_ARGS__ } )
142 #define ui_table(obj, ...) ui_table_create(obj, (UiListArgs) { __VA_ARGS__ } )
143 #define ui_combobox(obj, ...) ui_combobox_create(obj, (UiListArgs) { __VA_ARGS__ } )
144 #define ui_breadcrumbbar(obj, ...) ui_breadcrumbbar_create(obj, (UiListArgs) { __VA_ARGS__ } )
145
146 UIEXPORT UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args);
147 UIEXPORT UIWIDGET ui_table_create(UiObject* obj, UiListArgs args);
148 UIEXPORT UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args);
149 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args);
150
151
152 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...);
153 void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm);
154 void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...);
155 void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm);
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* UI_TREE_H */
162

mercurial