From 73826fc967357a9009b0f04ceb396ad6ce619f2d Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 21 Mar 2002 04:48:31 +0000 Subject: [PATCH] Much expanded overview docs for GtkTreeView and related objects. --- docs/reference/ChangeLog | 4 + docs/reference/gtk/tree_widget.sgml | 282 +++++++++++++++++++++++++--- 2 files changed, 255 insertions(+), 31 deletions(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 45e2739508..7b0148e957 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2002-03-20 Cody Russell + + * gtk/tree_widget.sgml: Much expanded overview of the tree. + Tue Mar 12 00:29:31 2002 Jonathan Blandford * gtk/question_index.sgml: new FAQ. diff --git a/docs/reference/gtk/tree_widget.sgml b/docs/reference/gtk/tree_widget.sgml index 95619b1a10..f95525019f 100644 --- a/docs/reference/gtk/tree_widget.sgml +++ b/docs/reference/gtk/tree_widget.sgml @@ -1,4 +1,4 @@ - + Tree and List Widget Overview 3 @@ -38,7 +38,204 @@ created to display various parts of the file system, but only one copy need be kept in memory. + + The purpose of the cell renderers is to provide extensibility to the + widget and to allow multiple ways of rendering the same type of data. + For example, consider how to render a boolean variable. Should you + render it as a string of "True" or "False", "On" or "Off", or should + you render it as a checkbox? + + + Creating a model + + GTK+ 2.0 provides two types of models that can be used: + GtkListStore and + GtkTreeStore. GtkListStore is + used to model columned list widgets, while GtkTreeStore models + columned tree widgets. It is possible to develop a new type of model, + but the existing models should be satisfactory for all but the most + specialized of situations. Creating the model is quite simple: + + + + This creates a list store with two columns: a string column and a boolean + column. Typically the 2 is never passed directly like that; usually an + enum is created wherein the different columns are enumerated, followed by + a token that represents the total number of columns. The next example will + illustrate this, only using a tree store instead of a list store. Creating + a tree store operates almost exactly the same. + + + + Adding data to the model is done using + gtk_tree_store_set() or + gtk_list_store_set(), depending upon which sort of model was + created. To do this, a GtkTreeIter must + be acquired. The iterator points to the location where data will be added. + + + Once an iterator has been acquired, + gtk_tree_store_set() is used to apply data to the part of the model + that the iterator points to. Consider the following example: + + + + + Notice that the last argument is FALSE. This is always done because + this is a variable-argument function and it needs to know when to stop + processing arguments. It can be used to set the data in any or all + columns in a given row. + + + The third argument to gtk_tree_store_append() is the parent iterator. It + is used to add a row to a GtkTreeStore as a child of an existing row. This + means that the new row will only be visible when its parent is visible and + in its expanded state. Consider the following example: + + + + + + Creating the view component + + While there are two different models to choose from, there is only one + view widget to deal with. It works with either the list or the tree store. + Setting up a GtkTreeView is not a + difficult matter. It needs a GtkTreeModel + to know where to retrieve its data from. + + + + + Columns and cell renderers + + Cell renderers are used to draw the data in the tree model in a certain way. + There are three cell renderers to choose from with GTK+ 2.0, but the + adventuresome hacker may write more. + + + + A GtkTreeViewColumn is the + object that GtkTreeView uses to organize the vertical columns in + the tree view. It needs to know the name of the column to label + for the user, what type of cell renderer to use, and which piece of + data to retrieve from the model for a given row. + + + At this point, all the steps in creating a displayable tree have been + covered. The model is created, data is stored in it, a tree view is + created and columns are added to it. + + + + + Selection handling + + Most applications will need to not only deal with displaying data, but also + receiving input events from users. To do this, simply get a reference to + a selection object and connect to the "changed" signal. + + + + Then to retrieve data for the row selected: + + + + + Simple Example @@ -52,47 +249,70 @@