📄 sec-treewidgetinternals.html
字号:
<HTML><HEAD><TITLE>Tree Widget Internals</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Tree Widget"HREF="ch-treewidget.html"><LINKREL="PREVIOUS"TITLE="Handling the Selection List"HREF="sec-handlingtheselectionlist.html"><LINKREL="NEXT"TITLE="Tree Item Widget"HREF="sec-treeitemwidget.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%"> <tr> <td bgcolor="#FFFFFF" valign=top nowrap> <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A> <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR> </td> <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-handlingtheselectionlist.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 13. Tree Widget</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-treeitemwidget.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-TREEWIDGETINTERNALS">13.4. Tree Widget Internals</A></H1><P>The Tree's struct definition looks like this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">struct _GtkTree{ GtkContainer container; GList *children; GtkTree* root_tree; /* owner of selection list */ GtkWidget* tree_owner; GList *selection; guint level; guint indent_value; guint current_indent; guint selection_mode : 2; guint view_mode : 1; guint view_line : 1;};</PRE></TD></TR></TABLE><P>The perils associated with accessing the <TTCLASS="LITERAL">selection</TT> fielddirectly have already been mentioned. The other important fields ofthe struct can also be accessed with handy macros or class functions.<TTCLASS="LITERAL">GTK_IS_ROOT_TREE (Tree)</TT> returns a boolean value whichindicates whether a tree is the root tree in a Tree hierarchy, while<TTCLASS="LITERAL">GTK_TREE_ROOT_TREE (Tree)</TT> returns the root tree, an object oftype GtkTree (so, remember to cast it using <TTCLASS="LITERAL">GTK_WIDGET (Tree)</TT> ifyou want to use one of the gtk_widget_*() functions on it).</P><P>Instead of directly accessing the children field of a Tree widget,it's probably best to cast it using >tt/GTK_CONTAINER (Tree)/, andpass it to the gtk_container_children() function. This creates aduplicate of the original list, so it's advisable to free it up usingg_list_free() after you're done with it, or to iterate on itdestructively, like this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> children = gtk_container_children (GTK_CONTAINER (tree)); while (children) { do_something_nice (GTK_TREE_ITEM (children->data)); children = g_list_remove_link (children, children);}</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">tree_owner</TT> field is defined only in subtrees, where itpoints to the TreeItem widget which holds the tree in question.The <TTCLASS="LITERAL">level</TT> field indicates how deeply nested a particular treeis; root trees have level 0, and each successive level of subtrees hasa level one greater than the parent level. This field is set onlyafter a Tree widget is actually mapped (i.e. drawn on the screen).</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-TREESIGNALS">13.4.1. Signals</A></H2><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void selection_changed( GtkTree *tree );</PRE></TD></TR></TABLE><P>This signal will be emitted whenever the <TTCLASS="LITERAL">selection</TT> field of aTree has changed. This happens when a child of the Tree isselected or deselected.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void select_child( GtkTree *tree, GtkWidget *child );</PRE></TD></TR></TABLE><P>This signal is emitted when a child of the Tree is about to getselected. This happens on calls to gtk_tree_select_item(),gtk_tree_select_child(), on <ICLASS="EMPHASIS">all</I> button presses and calls togtk_tree_item_toggle() and gtk_item_toggle(). It may sometimes beindirectly triggered on other occasions where children get added to orremoved from the Tree.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void unselect_child (GtkTree *tree, GtkWidget *child);</PRE></TD></TR></TABLE><P>This signal is emitted when a child of the Tree is about to getdeselected. As of GTK 1.0.4, this seems to only occur on calls togtk_tree_unselect_item() or gtk_tree_unselect_child(), and perhaps onother occasions, but <ICLASS="EMPHASIS">not</I> when a button press deselects achild, nor on emission of the "toggle" signal by gtk_item_toggle().</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="SEC-TREEFUNCTIONSANDMACROS">13.4.2. Functions and Macros</A></H2><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">guint gtk_tree_get_type( void );</PRE></TD></TR></TABLE><P>Returns the "GtkTree" type identifier.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget* gtk_tree_new( void );</PRE></TD></TR></TABLE><P>Create a new Tree object. The new widget is returned as a pointer to aGtkWidget object. NULL is returned on failure.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_tree_append( GtkTree *tree, GtkWidget *tree_item );</PRE></TD></TR></TABLE><P>Append a tree item to a Tree.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -