ui/gtk/tree.c

Sun, 01 Feb 2015 12:37:31 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 Feb 2015 12:37:31 +0100
changeset 85
91f45354d1e2
parent 75
efe2f65bea17
child 86
3c63f57a8f77
permissions
-rw-r--r--

added ui_layout_fill (WPF)

33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/context.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/object.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "container.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "tree.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 void* ui_strmodel_getvalue(void *elm, int column) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 return column == 0 ? elm : NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 return ui_listview(obj, list, ui_strmodel_getvalue, f, udata);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 // create treeview
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 GtkWidget *view = gtk_tree_view_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 #ifdef UI_GTK3
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 #else
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
63 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
64 modelinfo->getvalue = getvalue;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
65 UiListModel *model = ui_list_model_new(list, modelinfo);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(model));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 // add TreeView as observer to the UiList to update the TreeView if the
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 // data changes
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
70 UiTableView *listview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiTableView));
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 listview->widget = view;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 listview->list = list;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
73 listview->modelinfo = modelinfo;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 list->list->observers = ui_add_observer(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 list->list->observers,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 (ui_callback)ui_listview_update,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 listview);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 // add callback
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 if(f) {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
81 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 event->obj = obj;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
83 event->userdata = udata;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
84 event->activate = f;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
85 event->selection = NULL;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 g_signal_connect(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 view,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
90 G_CALLBACK(ui_listview_activate_event),
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 event);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 // add widget to the current container
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 gtk_scrolled_window_set_policy(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 GTK_SCROLLED_WINDOW(scroll_area),
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 GTK_POLICY_AUTOMATIC,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 gtk_container_add(GTK_CONTAINER(scroll_area), view);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
103 ct->add(ct, scroll_area, TRUE);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
105 // ct->current should point to view, not scroll_area, to make it possible
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
106 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
107 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
108
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 return scroll_area;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 listptr->list = list;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return ui_listview_var(obj, listptr, getvalue, f, udata);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 if(var) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 UiListVar *value = var->value;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 return ui_listview_var(obj, value->listptr, getvalue, f, udata);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 } else {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 // TODO: error
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
130 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
131 // create treeview
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
132 GtkWidget *view = gtk_tree_view_new();
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
133 for(int i=0;i<modelinfo->columns;i++) {
41
394f3b06dba1 fixed table bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
134 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
135 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
136 modelinfo->titles[i],
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
137 renderer,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
138 "text",
41
394f3b06dba1 fixed table bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
139 i,
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
140 NULL);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
141 gtk_tree_view_column_set_resizable(column, TRUE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
142 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
143 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
144
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
145 //gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
146 #ifdef UI_GTK3
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
147 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
148 #else
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
149
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
150 #endif
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
151
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
152 UiListModel *model = ui_list_model_new(list, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
153 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(model));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
154
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
155 // add TreeView as observer to the UiList to update the TreeView if the
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
156 // data changes
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
157 UiTableView *tableview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiTableView));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
158 tableview->widget = view;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
159 tableview->list = list;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
160 tableview->modelinfo = modelinfo;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
161 list->list->observers = ui_add_observer(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
162 list->list->observers,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
163 (ui_callback)ui_listview_update,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
164 tableview);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
166 // add callback
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
167 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
168 event->obj = obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
169 event->activate = modelinfo->activate;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
170 event->selection = modelinfo->selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
171 event->userdata = modelinfo->userdata;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
172 if(modelinfo->activate) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
173 g_signal_connect(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
174 view,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
175 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
176 G_CALLBACK(ui_listview_activate_event),
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
177 event);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
178 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
179 if(modelinfo->selection) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
180 GtkTreeSelection *selection = gtk_tree_view_get_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
181 GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
182 g_signal_connect(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
183 selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
184 "changed",
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
185 G_CALLBACK(ui_listview_selection_event),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
186 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
187 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
188 // TODO: destroy callback
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
189
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
190 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
191 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
192
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
193 // add widget to the current container
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
194 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
195 gtk_scrolled_window_set_policy(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
196 GTK_SCROLLED_WINDOW(scroll_area),
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 GTK_POLICY_AUTOMATIC,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199 gtk_container_add(GTK_CONTAINER(scroll_area), view);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
202 ct->add(ct, scroll_area, TRUE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
204 // ct->current should point to view, not scroll_area, to make it possible
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
205 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
206 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
207
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 return scroll_area;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 UIWIDGET ui_table(UiObject *obj, UiList *list, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
212 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
213 listptr->list = list;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
214 return ui_table_var(obj, listptr, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
215 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
217 UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
218 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
219 if(var) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
220 UiListVar *value = var->value;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
221 return ui_table_var(obj, value->listptr, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
222 } else {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
223 // TODO: error
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
224 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
225 return NULL;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
226 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
227
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
228
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
229
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
230 void ui_listview_update(UiEvent *event, UiTableView *view) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
231 UiListModel *model = ui_list_model_new(view->list, view->modelinfo);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(model));
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
233
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
234 // TODO: free old model
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
237 void ui_listview_activate_event(
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 GtkTreeView *treeview,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 GtkTreePath *path,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 GtkTreeViewColumn *column,
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
241 UiTreeEventData *event)
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
243 UiListSelection *selection = ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
244 gtk_tree_view_get_selection(treeview),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
245 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
246
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
247 UiEvent e;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
248 e.obj = event->obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
249 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
250 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
251 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
252 e.intval = selection->count > 0 ? selection->rows[0] : -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
253 event->activate(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
254
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
255 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
256 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
257 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
258 free(selection);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
259 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
260
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
261 void ui_listview_selection_event(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
262 GtkTreeSelection *treeselection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
263 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
264 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
265 UiListSelection *selection = ui_listview_selection(treeselection, event);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 UiEvent e;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 e.obj = event->obj;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
270 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
271 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
272 e.intval = selection->count > 0 ? selection->rows[0] : -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
273 event->selection(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
274
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
275 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
276 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
277 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
278 free(selection);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
280
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
281 UiListSelection* ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
282 GtkTreeSelection *selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
283 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
284 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
285 GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
286
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
287 UiListSelection *ls = malloc(sizeof(UiListSelection));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
288 ls->count = g_list_length(rows);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
289 ls->rows = calloc(ls->count, sizeof(int));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
290 GList *r = rows;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
291 int i = 0;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
292 while(r) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
293 GtkTreePath *path = r->data;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
294 ls->rows[i] = ui_tree_path_list_index(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
295 r = r->next;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
296 i++;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
297 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
298 return ls;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
299 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
300
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
301 int ui_tree_path_list_index(GtkTreePath *path) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
302 int depth = gtk_tree_path_get_depth(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
303 if(depth == 0) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
304 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
305 return -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
306 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
307 int *indices = gtk_tree_path_get_indices(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
308 return indices[depth - 1];
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
309 }

mercurial