Add powerbox hook
[gtk-with-powerbox.git] / tests / testgrouping.c
blob4b412d01ef1d92d1d757bdce5c5f056456b858f7
1 #include <gtk/gtk.h>
4 static GtkTreeModel *
5 create_model (void)
7 GtkTreeStore *store;
8 GtkTreeIter iter;
9 GtkTreeIter parent;
11 store = gtk_tree_store_new (1, G_TYPE_STRING);
13 gtk_tree_store_insert_with_values (store, &parent, NULL, 0,
14 0, "Applications", -1);
16 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
17 0, "File Manager", -1);
18 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
19 0, "Gossip", -1);
20 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
21 0, "System Settings", -1);
22 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
23 0, "The GIMP", -1);
24 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
25 0, "Terminal", -1);
26 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
27 0, "Word Processor", -1);
30 gtk_tree_store_insert_with_values (store, &parent, NULL, 1,
31 0, "Documents", -1);
33 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
34 0, "blaat.txt", -1);
35 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
36 0, "sliff.txt", -1);
37 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
38 0, "test.txt", -1);
39 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
40 0, "blaat.txt", -1);
41 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
42 0, "brrrr.txt", -1);
43 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
44 0, "hohoho.txt", -1);
47 gtk_tree_store_insert_with_values (store, &parent, NULL, 2,
48 0, "Images", -1);
50 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
51 0, "image1.png", -1);
52 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
53 0, "image2.png", -1);
54 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
55 0, "image3.jpg", -1);
57 return GTK_TREE_MODEL (store);
60 static void
61 set_color_func (GtkTreeViewColumn *column,
62 GtkCellRenderer *cell,
63 GtkTreeModel *model,
64 GtkTreeIter *iter,
65 gpointer data)
67 if (gtk_tree_model_iter_has_child (model, iter))
68 g_object_set (cell, "cell-background", "Grey", NULL);
69 else
70 g_object_set (cell, "cell-background", NULL, NULL);
73 static void
74 tree_view_row_activated (GtkTreeView *tree_view,
75 GtkTreePath *path,
76 GtkTreeViewColumn *column)
78 if (gtk_tree_path_get_depth (path) > 1)
79 return;
81 if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (tree_view), path))
82 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
83 else
84 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
87 static gboolean
88 tree_view_select_func (GtkTreeSelection *selection,
89 GtkTreeModel *model,
90 GtkTreePath *path,
91 gboolean path_currently_selected,
92 gpointer data)
94 if (gtk_tree_path_get_depth (path) > 1)
95 return TRUE;
97 return FALSE;
101 main (int argc, char **argv)
103 GtkWidget *window, *sw, *tv;
104 GtkTreeModel *model;
105 GtkCellRenderer *renderer;
106 GtkTreeViewColumn *column;
108 gtk_init (&argc, &argv);
110 model = create_model ();
112 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
113 g_signal_connect (window, "delete_event",
114 G_CALLBACK (gtk_main_quit), NULL);
115 gtk_window_set_default_size (GTK_WINDOW (window), 320, 480);
117 sw = gtk_scrolled_window_new (NULL, NULL);
118 gtk_container_add (GTK_CONTAINER (window), sw);
120 tv = gtk_tree_view_new_with_model (model);
121 gtk_container_add (GTK_CONTAINER (sw), tv);
123 g_signal_connect (tv, "row-activated",
124 G_CALLBACK (tree_view_row_activated), tv);
125 g_object_set (tv,
126 "show-expanders", FALSE,
127 "level-indentation", 10,
128 NULL);
130 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tv), FALSE);
131 gtk_tree_view_expand_all (GTK_TREE_VIEW (tv));
133 gtk_tree_selection_set_select_function (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv)),
134 tree_view_select_func,
135 NULL,
136 NULL);
138 renderer = gtk_cell_renderer_text_new ();
139 column = gtk_tree_view_column_new_with_attributes ("(none)",
140 renderer,
141 "text", 0,
142 NULL);
143 gtk_tree_view_column_set_cell_data_func (column,
144 renderer,
145 set_color_func,
146 NULL,
147 NULL);
148 gtk_tree_view_insert_column (GTK_TREE_VIEW (tv), column, 0);
150 gtk_widget_show_all (window);
152 gtk_main ();
154 return 0;