forked from AuroraMiddleware/gtk
31df9723e5
* gtk/gtklabel.c: Fix docs. (#66383) * gtk/gtkbbox.c (gtk_button_box_set_child_secondary): Fix docs. (#66278, #66280) * gdk/gdkwindow.h (gdk_window_get_deskrelative_origin), gdk/gdkimage.h (gdk_image_get): Deprecate. (#66208) * gtk/gtkcolorsel.c (gtk_color_selection_set_update_policy): Don't emit a g_warning() about being deprecated. (#66208) * gtk/gtkaccellabel.c (gtk_accel_label_set_accel_widget): Add docs. * gtk/gtkcontainer.c: Doc fixes. * gtk/gtkliststore.c (gtk_list_store_clear): Add docs; misc doc fixes. * gtk/gtkstyle.c (gtk_style_attach): Add docs. * gdk-pixbuf.h (gdk_pixbuf_ref, gdk_pixbuf_unref, gdk_pixbuf_animation_ref, gdk_pixbuf_animation_unref): Deprecate. (#66208) * gtk/tmpl/gtklabel.sgml: Remove redundant docs. (#66383) * gtk/tree_widget.sgml: Typo fix. (#66256) * gdk-pixbuf/Makefile.am (SCAN_OPTIONS): Add --deprecated-guards. * gtk/tmpl/gtktext.sgml, gtk/tmpl/gtktree.sgml, gtk/tmpl/gtktreeitem.sgml: Updates.
91 lines
3.2 KiB
Plaintext
91 lines
3.2 KiB
Plaintext
<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>
|
|
<refpurpose>Overview of <link
|
|
linkend="GtkTreeModel">GtkTreeModel</link>, <link
|
|
linkend="GtkTreeView">GtkTreeView</link>, and other associated widgets</refpurpose>
|
|
</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
|
|
linkend="GtkTreeView">GtkTreeView</link> widget.
|
|
</para>
|
|
<para>
|
|
This widget is designed around a
|
|
<firstterm>Model/View/Controller</firstterm> design and consists
|
|
of four major parts:
|
|
<simplelist>
|
|
<member>the tree view widget (GtkTreeView)</member>
|
|
<member>the view column (GtkTreeViewColumn)</member>
|
|
<member>the cell renderers (GtkCellRenderer etc.)</member>
|
|
<member>and the model interface (GtkTreeModel)</member>
|
|
</simplelist>
|
|
The <emphasis>View</emphasis> is composed of the first three,
|
|
while the last is the <emphasis>Model</emphasis>. One of the
|
|
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.
|
|
</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
|
|
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.
|
|
<programlisting><![CDATA[
|
|
{
|
|
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 */
|
|
model = gtk_tree_store_new_with_values (1, G_TYPE_STRING);
|
|
populate_tree_model (model);
|
|
|
|
/* 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));
|
|
|
|
/* Create a cell render and arbitrarily make it red for demonstartion
|
|
*purposes */
|
|
cell_renderer = gtk_cell_renderer_text_new ();
|
|
g_object_set (G_OBJECT (cell_renderer), "foreground", "red", NULL);
|
|
|
|
/* 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,
|
|
"text", 0,
|
|
NULL);
|
|
|
|
/* Add the column to the view. */
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|