Re: GtkTreeView question



On Mon, 24 Feb 2003 19:02:16 +0100
Bernd Bartmann <Bernd Bartmann sohanet de> wrote:

> Is it possible to create a tree node in a GtkTreeView which has no 
> sub-nodes but nonetheless has the expand/collapse handle?

Well, sort of.  For a parent node to have a expand/collapse handle, I
create a child node using gtk_tree_store_append() and then don't follow 
with a call to gtk_tree_store_set().  Yes, this creates a child node, 
albeit an empty one.  

This empty child node is easy to detect in a "row_expand" signal 
callback.  This is how I do it:


void
on_treeview1_row_expanded       (GtkTreeView     *treeview,
                                        GtkTreeIter     *arg1,
                                        GtkTreePath     *arg2,
                                        gpointer         user_data)
{
    extern GtkTreeStore *treestore;
    GtkTreeIter child_iter;

    gchar *name;   // assume "name" is the file/directory name of G_TYPE_STRING

    // See if this row has ever had a name gtk_tree_store_set()'ed to it.
    // If not, read the directory contents
    gtk_tree_model_get(GTK_TREE_MODEL(treestore), arg1,
                        NAME_COLUMN, &name, -1);
    if (!name)
    {
        g_print("Read this directory's contents here.");

        // Replace the blank child with the first directory entry
        // You may be tempted to remove the blank child node and then append a
        // new one.  Don't.  If you remove the blank child node GTK gets
        // confused and won't expand the parent row.  
        gtk_tree_model_iter_children(GTK_TREE_MODEL(treestore), &child_iter, 
arg1);
        gtk_tree_store_set (treestore, &child_iter, NAME_COLUMN, 
first_entry_name, -1);

        // Append all of the other directory entries
        gtk_tree_store_append(treestore, &child_iter, arg1);
        gtk_tree_store_set (treestore, &child_iter, NAME_COLUMN, 
second_entry_name, -1);
     }
     return;
}

I hope this helps.

--
Ken Rastatter, Design Engineer
Sensotec, Inc.
2080 Arlingate Lane, Columbus, Ohio, 43228-4112 USA

Voice: (614)850-5000 Fax: (614)850-6041 Toll Free: 1-800-848-6564
Home Page:  http://www.sensotec.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]