|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#define GTK_ENABLE_BROKEN
|
|
Packit Service |
fb6fa5 |
#include "config.h"
|
|
Packit Service |
fb6fa5 |
#include <gtk/gtk.h>
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* for all the GtkItem:: and GtkTreeItem:: signals */
|
|
Packit Service |
fb6fa5 |
static void cb_itemsignal( GtkWidget *item,
|
|
Packit Service |
fb6fa5 |
gchar *signame )
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
gchar *name;
|
|
Packit Service |
fb6fa5 |
GtkLabel *label;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* It's a Bin, so it has one child, which we know to be a
|
|
Packit Service |
fb6fa5 |
label, so get that */
|
|
Packit Service |
fb6fa5 |
label = GTK_LABEL (GTK_BIN (item)->child);
|
|
Packit Service |
fb6fa5 |
/* Get the text of the label */
|
|
Packit Service |
fb6fa5 |
gtk_label_get (label, &name);
|
|
Packit Service |
fb6fa5 |
/* Get the level of the tree which the item is in */
|
|
Packit Service |
fb6fa5 |
g_print ("%s called for item %s->%p, level %d\n", signame, name,
|
|
Packit Service |
fb6fa5 |
item, GTK_TREE (item->parent)->level);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Note that this is never called */
|
|
Packit Service |
fb6fa5 |
static void cb_unselect_child( GtkWidget *root_tree,
|
|
Packit Service |
fb6fa5 |
GtkWidget *child,
|
|
Packit Service |
fb6fa5 |
GtkWidget *subtree )
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
g_print ("unselect_child called for root tree %p, subtree %p, child %p\n",
|
|
Packit Service |
fb6fa5 |
root_tree, subtree, child);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Note that this is called every time the user clicks on an item,
|
|
Packit Service |
fb6fa5 |
whether it is already selected or not. */
|
|
Packit Service |
fb6fa5 |
static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
|
|
Packit Service |
fb6fa5 |
GtkWidget *subtree)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
g_print ("select_child called for root tree %p, subtree %p, child %p\n",
|
|
Packit Service |
fb6fa5 |
root_tree, subtree, child);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void cb_selection_changed( GtkWidget *tree )
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GList *i;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_print ("selection_change called for tree %p\n", tree);
|
|
Packit Service |
fb6fa5 |
g_print ("selected objects are:\n");
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
i = GTK_TREE_SELECTION_OLD (tree);
|
|
Packit Service |
fb6fa5 |
while (i) {
|
|
Packit Service |
fb6fa5 |
gchar *name;
|
|
Packit Service |
fb6fa5 |
GtkLabel *label;
|
|
Packit Service |
fb6fa5 |
GtkWidget *item;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Get a GtkWidget pointer from the list node */
|
|
Packit Service |
fb6fa5 |
item = GTK_WIDGET (i->data);
|
|
Packit Service |
fb6fa5 |
label = GTK_LABEL (GTK_BIN (item)->child);
|
|
Packit Service |
fb6fa5 |
gtk_label_get (label, &name);
|
|
Packit Service |
fb6fa5 |
g_print ("\t%s on level %d\n", name, GTK_TREE
|
|
Packit Service |
fb6fa5 |
(item->parent)->level);
|
|
Packit Service |
fb6fa5 |
i = i->next;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
int main( int argc,
|
|
Packit Service |
fb6fa5 |
char *argv[] )
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkWidget *window, *scrolled_win, *tree;
|
|
Packit Service |
fb6fa5 |
static gchar *itemnames[] = {"Foo", "Bar", "Baz", "Quux",
|
|
Packit Service |
fb6fa5 |
"Maurice"};
|
|
Packit Service |
fb6fa5 |
gint i;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_init (&argc, &argv);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* a generic toplevel window */
|
|
Packit Service |
fb6fa5 |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (window), "delete_event",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (gtk_main_quit), NULL);
|
|
Packit Service |
fb6fa5 |
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* A generic scrolled window */
|
|
Packit Service |
fb6fa5 |
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
Packit Service |
fb6fa5 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
Packit Service |
fb6fa5 |
GTK_POLICY_AUTOMATIC,
|
|
Packit Service |
fb6fa5 |
GTK_POLICY_AUTOMATIC);
|
|
Packit Service |
fb6fa5 |
gtk_widget_set_size_request (scrolled_win, 150, 200);
|
|
Packit Service |
fb6fa5 |
gtk_container_add (GTK_CONTAINER (window), scrolled_win);
|
|
Packit Service |
fb6fa5 |
gtk_widget_show (scrolled_win);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Create the root tree */
|
|
Packit Service |
fb6fa5 |
tree = gtk_tree_new ();
|
|
Packit Service |
fb6fa5 |
g_print ("root tree is %p\n", tree);
|
|
Packit Service |
fb6fa5 |
/* connect all GtkTree:: signals */
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (tree), "select_child",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_select_child), tree);
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (tree), "unselect_child",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_unselect_child), tree);
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT(tree), "selection_changed",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK(cb_selection_changed), tree);
|
|
Packit Service |
fb6fa5 |
/* Add it to the scrolled window */
|
|
Packit Service |
fb6fa5 |
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
Packit Service |
fb6fa5 |
tree);
|
|
Packit Service |
fb6fa5 |
/* Set the selection mode */
|
|
Packit Service |
fb6fa5 |
gtk_tree_set_selection_mode (GTK_TREE (tree),
|
|
Packit Service |
fb6fa5 |
GTK_SELECTION_MULTIPLE);
|
|
Packit Service |
fb6fa5 |
/* Show it */
|
|
Packit Service |
fb6fa5 |
gtk_widget_show (tree);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
for (i = 0; i < 5; i++){
|
|
Packit Service |
fb6fa5 |
GtkWidget *subtree, *item;
|
|
Packit Service |
fb6fa5 |
gint j;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Create a tree item */
|
|
Packit Service |
fb6fa5 |
item = gtk_tree_item_new_with_label (itemnames[i]);
|
|
Packit Service |
fb6fa5 |
/* Connect all GtkItem:: and GtkTreeItem:: signals */
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (item), "select",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "select");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (item), "deselect",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "deselect");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (item), "toggle",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "toggle");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (item), "expand",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "expand");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (item), "collapse",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "collapse");
|
|
Packit Service |
fb6fa5 |
/* Add it to the parent tree */
|
|
Packit Service |
fb6fa5 |
gtk_tree_append (GTK_TREE (tree), item);
|
|
Packit Service |
fb6fa5 |
/* Show it - this can be done at any time */
|
|
Packit Service |
fb6fa5 |
gtk_widget_show (item);
|
|
Packit Service |
fb6fa5 |
/* Create this item's subtree */
|
|
Packit Service |
fb6fa5 |
subtree = gtk_tree_new ();
|
|
Packit Service |
fb6fa5 |
g_print ("-> item %s->%p, subtree %p\n", itemnames[i], item,
|
|
Packit Service |
fb6fa5 |
subtree);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* This is still necessary if you want these signals to be called
|
|
Packit Service |
fb6fa5 |
for the subtree's children. Note that selection_change will be
|
|
Packit Service |
fb6fa5 |
signalled for the root tree regardless. */
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subtree), "select_child",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_select_child), subtree);
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subtree), "unselect_child",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_unselect_child), subtree);
|
|
Packit Service |
fb6fa5 |
/* This has absolutely no effect, because it is completely ignored
|
|
Packit Service |
fb6fa5 |
in subtrees */
|
|
Packit Service |
fb6fa5 |
gtk_tree_set_selection_mode (GTK_TREE (subtree),
|
|
Packit Service |
fb6fa5 |
GTK_SELECTION_SINGLE);
|
|
Packit Service |
fb6fa5 |
/* Neither does this, but for a rather different reason - the
|
|
Packit Service |
fb6fa5 |
view_mode and view_line values of a tree are propagated to
|
|
Packit Service |
fb6fa5 |
subtrees when they are mapped. So, setting it later on would
|
|
Packit Service |
fb6fa5 |
actually have a (somewhat unpredictable) effect */
|
|
Packit Service |
fb6fa5 |
gtk_tree_set_view_mode (GTK_TREE (subtree), GTK_TREE_VIEW_ITEM);
|
|
Packit Service |
fb6fa5 |
/* Set this item's subtree - note that you cannot do this until
|
|
Packit Service |
fb6fa5 |
AFTER the item has been added to its parent tree! */
|
|
Packit Service |
fb6fa5 |
gtk_tree_item_set_subtree (GTK_TREE_ITEM (item), subtree);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
for (j = 0; j < 5; j++){
|
|
Packit Service |
fb6fa5 |
GtkWidget *subitem;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Create a subtree item, in much the same way */
|
|
Packit Service |
fb6fa5 |
subitem = gtk_tree_item_new_with_label (itemnames[j]);
|
|
Packit Service |
fb6fa5 |
/* Connect all GtkItem:: and GtkTreeItem:: signals */
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subitem), "select",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "select");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subitem), "deselect",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "deselect");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subitem), "toggle",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "toggle");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subitem), "expand",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "expand");
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (subitem), "collapse",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_itemsignal), "collapse");
|
|
Packit Service |
fb6fa5 |
g_print ("-> -> item %s->%p\n", itemnames[j], subitem);
|
|
Packit Service |
fb6fa5 |
/* Add it to its parent tree */
|
|
Packit Service |
fb6fa5 |
gtk_tree_append (GTK_TREE (subtree), subitem);
|
|
Packit Service |
fb6fa5 |
/* Show it */
|
|
Packit Service |
fb6fa5 |
gtk_widget_show (subitem);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Show the window and loop endlessly */
|
|
Packit Service |
fb6fa5 |
gtk_widget_show (window);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_main();
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
return 0;
|
|
Packit Service |
fb6fa5 |
}
|