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,
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,
24 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
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,
33 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
35 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
37 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
39 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
41 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
43 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
47 gtk_tree_store_insert_with_values (store
, &parent
, NULL
, 2,
50 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
52 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
54 gtk_tree_store_insert_with_values (store
, &iter
, &parent
, 0,
57 return GTK_TREE_MODEL (store
);
61 set_color_func (GtkTreeViewColumn
*column
,
62 GtkCellRenderer
*cell
,
67 if (gtk_tree_model_iter_has_child (model
, iter
))
68 g_object_set (cell
, "cell-background", "Grey", NULL
);
70 g_object_set (cell
, "cell-background", NULL
, NULL
);
74 tree_view_row_activated (GtkTreeView
*tree_view
,
76 GtkTreeViewColumn
*column
)
78 if (gtk_tree_path_get_depth (path
) > 1)
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
);
84 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view
), path
, FALSE
);
88 tree_view_select_func (GtkTreeSelection
*selection
,
91 gboolean path_currently_selected
,
94 if (gtk_tree_path_get_depth (path
) > 1)
101 main (int argc
, char **argv
)
103 GtkWidget
*window
, *sw
, *tv
;
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
);
126 "show-expanders", FALSE
,
127 "level-indentation", 10,
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
,
138 renderer
= gtk_cell_renderer_text_new ();
139 column
= gtk_tree_view_column_new_with_attributes ("(none)",
143 gtk_tree_view_column_set_cell_data_func (column
,
148 gtk_tree_view_insert_column (GTK_TREE_VIEW (tv
), column
, 0);
150 gtk_widget_show_all (window
);