Thu, 15 May 2014 15:53:29 +0200
refactored value binding system
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 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | UiListModel *model = ui_list_model_new(list, getvalue); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | 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
|
65 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | // 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
|
67 | // data changes |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | UiListView *listview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListView)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | listview->widget = view; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | listview->list = list; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | listview->getvalue = getvalue; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | list->list->observers = ui_add_observer( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | list->list->observers, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | (ui_callback)ui_listview_update, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | listview); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | // add callback |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | if(f) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | UiEventData *event = ucx_mempool_malloc( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | obj->ctx->mempool, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | sizeof(UiEventData)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | event->obj = obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | event->user_data = udata; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | event->callback = f; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | event->value = 0; |
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", |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | G_CALLBACK(ui_listview_selected), |
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); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | ct->add(ct, scroll_area); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | return scroll_area; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | 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
|
109 | 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
|
110 | listptr->list = list; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | 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
|
112 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | 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
|
115 | 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
|
116 | if(var) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | UiListVar *value = var->value; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | 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
|
119 | } else { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | // TODO: error |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | return NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
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 | void ui_listview_update(UiEvent *event, UiListView *view) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | UiList *list = view->list->list; |
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 | UiListModel *model = ui_list_model_new(view->list, view->getvalue); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(model)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | void ui_listview_selected( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | GtkTreeView *treeview, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | GtkTreePath *path, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | GtkTreeViewColumn *column, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | UiEventData *event) |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | int *indices = gtk_tree_path_get_indices(path); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | int depth = gtk_tree_path_get_depth(path); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | if(depth == 0) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | fprintf(stderr, "UiError: ui_treeview_selected: depth == 0\n"); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | return; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | GtkTreeModel *model = gtk_tree_view_get_model(treeview); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | GtkTreeIter iter; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | gtk_tree_model_get_iter (model, &iter, path); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | void *value = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | gtk_tree_model_get(model, &iter, 0, &value, -1); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | UiEvent e; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | e.obj = event->obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | e.window = event->obj->window; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | e.document = event->obj->document; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | e.eventdata = value; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | e.intval = indices[depth-1]; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | event->callback(&e, event->user_data); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | } |