2000-10-30 23:21:38 +00:00
|
|
|
<refentry id="TreeWidget" revision="30 Oct 2000">
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle>Tree and List Widget Overview</refentrytitle>
|
|
|
|
<manvolnum>3</manvolnum>
|
|
|
|
<refmiscinfo>GTK Library</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>Tree and List Widget Overview</refname>
|
2001-09-08 18:23:47 +00:00
|
|
|
<refpurpose>Overview of <link
|
|
|
|
linkend="GtkTreeModel">GtkTreeModel</link>, <link
|
2001-12-06 21:38:12 +00:00
|
|
|
linkend="GtkTreeView">GtkTreeView</link>, and other associated widgets</refpurpose>
|
2000-10-30 23:21:38 +00:00
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Overview</title>
|
|
|
|
<para>
|
|
|
|
To create a tree or list in GTK+, you need to use the <link
|
|
|
|
linkend="GtkTreeModel">GtkTreeModel</link> interface, in
|
|
|
|
conjunction with the <link
|
2001-09-08 18:23:47 +00:00
|
|
|
linkend="GtkTreeView">GtkTreeView</link> widget.
|
2000-10-30 23:21:38 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2001-09-08 18:23:47 +00:00
|
|
|
This widget is designed around a
|
|
|
|
<firstterm>Model/View/Controller</firstterm> design and consists
|
|
|
|
of four major parts:
|
|
|
|
<simplelist>
|
Small additions.
* gtk/tmpl/gtktextview.sgml: Small additions.
* gtk/tmpl/gtksignal.sgml: Explain what to use instead.
* gtk/question_index.sgml, gtk/text_widget.sgml, gtk/tree_widget.sgml,
gtk/changes-1.2.sgml, gtk/changes-2.0.sgml,
gtk/framebuffer.sgml: SGML fixes and additions.
* gtk/tmpl/gtksignal.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkeditable.sgml, gtk/tmpl/gtkfilesel.sgml,
gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkrc.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkwindow.sgml:
Replace references to deprecated functions.
2002-01-03 23:04:44 +00:00
|
|
|
<member>the tree view widget (<structname>GtkTreeView</structname>)</member>
|
|
|
|
<member>the view column (<structname>GtkTreeViewColumn</structname>)</member>
|
|
|
|
<member>the cell renderers (<structname>GtkCellRenderer</structname> etc.)</member>
|
|
|
|
<member>and the model interface (<structname>GtkTreeModel</structname>)</member>
|
2001-09-08 18:23:47 +00:00
|
|
|
</simplelist>
|
2001-10-02 19:40:54 +00:00
|
|
|
The <emphasis>View</emphasis> is composed of the first three,
|
|
|
|
while the last is the <emphasis>Model</emphasis>. One of the
|
2001-09-08 18:23:47 +00:00
|
|
|
prime benefits of the MVC design is that multiple views can be
|
|
|
|
created of a single model. For example, a model mapping the file
|
|
|
|
system could be created for a file manager. Many views could be
|
|
|
|
created to display various parts of the file system, but only one
|
|
|
|
copy need be kept in memory.
|
2000-10-30 23:21:38 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
|
|
|
<title>Simple Example</title>
|
|
|
|
<para>
|
|
|
|
Here is a simple example of using a <link
|
|
|
|
linkend="GtkTreeView">GtkTreeView</link> widget in context of the
|
|
|
|
other widgets. It simply creates a simple model and view, and
|
|
|
|
puts them together. Note that the model is never populated with
|
2001-09-08 18:23:47 +00:00
|
|
|
data — that is left as an exercise for the reader. More
|
|
|
|
information can be found on this in the <link
|
|
|
|
linkend="GtkTreeStore">GtkTreeModel</link> section.
|
Small additions.
* gtk/tmpl/gtktextview.sgml: Small additions.
* gtk/tmpl/gtksignal.sgml: Explain what to use instead.
* gtk/question_index.sgml, gtk/text_widget.sgml, gtk/tree_widget.sgml,
gtk/changes-1.2.sgml, gtk/changes-2.0.sgml,
gtk/framebuffer.sgml: SGML fixes and additions.
* gtk/tmpl/gtksignal.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkeditable.sgml, gtk/tmpl/gtkfilesel.sgml,
gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkrc.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkwindow.sgml:
Replace references to deprecated functions.
2002-01-03 23:04:44 +00:00
|
|
|
<informalexample><programlisting><![CDATA[
|
2002-03-06 19:22:36 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_ONE,
|
|
|
|
N_COLUMNS
|
|
|
|
};
|
|
|
|
|
2000-10-30 23:21:38 +00:00
|
|
|
{
|
|
|
|
GtkTreeStore *model;
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *cell_renderer;
|
|
|
|
|
|
|
|
/* Create a model. We are using the store model for now, though we
|
|
|
|
* could use any other GtkTreeModel */
|
2002-03-06 19:29:08 +00:00
|
|
|
model = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING);
|
2002-03-06 19:22:36 +00:00
|
|
|
|
|
|
|
/* custom function to fill the model with data */
|
2001-09-08 18:23:47 +00:00
|
|
|
populate_tree_model (model);
|
2000-10-30 23:21:38 +00:00
|
|
|
|
|
|
|
/* Create a view */
|
|
|
|
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
|
|
|
|
|
|
|
|
/* The view now holds a reference. We can get rid of our own
|
|
|
|
* reference */
|
|
|
|
g_object_unref (G_OBJECT (model));
|
|
|
|
|
2002-03-06 19:22:36 +00:00
|
|
|
/* Create a cell render and arbitrarily make it red for demonstration
|
|
|
|
* purposes */
|
2000-10-30 23:21:38 +00:00
|
|
|
cell_renderer = gtk_cell_renderer_text_new ();
|
2001-09-08 18:23:47 +00:00
|
|
|
g_object_set (G_OBJECT (cell_renderer), "foreground", "red", NULL);
|
2000-10-30 23:21:38 +00:00
|
|
|
|
|
|
|
/* Create a column, associating the "text" attribute of the
|
|
|
|
* cell_renderer to the first column of the model */
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("title",
|
|
|
|
cell_renderer,
|
2002-03-06 19:22:36 +00:00
|
|
|
"text", COLUMN_ONE,
|
2000-10-30 23:21:38 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Add the column to the view. */
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
|
2002-03-06 19:22:36 +00:00
|
|
|
|
|
|
|
/* Now we can manipulate the view just like any other GTK widget */
|
|
|
|
...
|
2000-10-30 23:21:38 +00:00
|
|
|
}
|
|
|
|
]]>
|
Small additions.
* gtk/tmpl/gtktextview.sgml: Small additions.
* gtk/tmpl/gtksignal.sgml: Explain what to use instead.
* gtk/question_index.sgml, gtk/text_widget.sgml, gtk/tree_widget.sgml,
gtk/changes-1.2.sgml, gtk/changes-2.0.sgml,
gtk/framebuffer.sgml: SGML fixes and additions.
* gtk/tmpl/gtksignal.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkeditable.sgml, gtk/tmpl/gtkfilesel.sgml,
gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkrc.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkwindow.sgml:
Replace references to deprecated functions.
2002-01-03 23:04:44 +00:00
|
|
|
</programlisting></informalexample>
|
2000-10-30 23:21:38 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|