📄 sec-addingandremovingnodes.html
字号:
<HTML><HEAD><TITLE>Adding and Removing nodes</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="CTree Widget"HREF="ch-ctreewidget.html"><LINKREL="PREVIOUS"TITLE="CTree Widget"HREF="ch-ctreewidget.html"><LINKREL="NEXT"TITLE="Setting CTree Attributes"HREF="sec-settingctreeattributes.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="ch-ctreewidget.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 12. CTree Widget</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-settingctreeattributes.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-ADDINGANDREMOVINGNODES">12.2. Adding and Removing nodes</A></H1><P>The items in a CTree are termed <ICLASS="EMPHASIS">nodes</I>. Nodes are insertedinto a CTree in such a way as to create a hierarchy (although theorder of insertion is not critical). The following function is used toinsert a node:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkCTreeNode *gtk_ctree_insert_node( GtkCTree *ctree, GtkCTreeNode *parent, GtkCTreeNode *sibling, gchar *text[], guint8 spacing, GdkPixmap *pixmap_closed, GdkBitmap *mask_closed, GdkPixmap *pixmap_opened, GdkBitmap *mask_opened, gboolean is_leaf, gboolean expanded );</PRE></TD></TR></TABLE><P>This function looks a little daunting, but that is merely due to thepower of the CTreee widget. Not all of the parameters above arerequired.</P><P>The CTree widget allows you to specify pixmaps to display in eachnode. For branch nodes, you can specify different pixmaps for when thebranch is collapsed or expanded. This gives a nice visual feedback tothe user, but it is optional so you don't have to specify pixmaps.</P><P>Lets have a quick look at all of the parameters:</P><P></P><UL><LI><P> <TTCLASS="LITERAL">ctree</TT> - the CTree widget we are manipulating</P></LI><LI><P> <TTCLASS="LITERAL">parent</TT> - the parent node of the one we are inserting. May be <TTCLASS="LITERAL">NULL</TT> for a root-level (i.e. initial) node.</P></LI><LI><P> <TTCLASS="LITERAL">sibling</TT> - a sibling of the node we are inserting. May be <TTCLASS="LITERAL">NULL</TT> if there are no siblings.</P></LI><LI><P> <TTCLASS="LITERAL">text</TT> - the textual contents of each column in the tree for this node. This array <ICLASS="EMPHASIS">must</I> have an entry for each column, even if it is an empty string.</P></LI><LI><P> <TTCLASS="LITERAL">spacing</TT> - specifies the padding between the nodes pixmap and text elements, if a pixmap is provided</P></LI><LI><P> <TTCLASS="LITERAL">pixmap_closed</TT> - a pixmap to display for a collapsed branch node and for a leaf node.</P></LI><LI><P> <TTCLASS="LITERAL">mask_closed</TT> - a bitmap mask for the above pixmap.</P></LI><LI><P> <TTCLASS="LITERAL">pixmap_opened</TT> - a pixmap to display for an expanded branch node.</P></LI><LI><P> <TTCLASS="LITERAL">mask_opened</TT> - a bitmap mask for the above pixmap.</P></LI><LI><P> <TTCLASS="LITERAL">is_leaf</TT> - indicates whether this is a leaf or branch node.</P></LI><LI><P> <TTCLASS="LITERAL">expanded</TT> - indicates whether a branch node is initially expanded or collapsed.</P></LI></UL><P>An object pointer of type GtkCTreeNode is returned by thegtk_ctree_insert_node() function. This object pointer is used toreference the node when manipulating it. The node pointer is alsosupplied by many of the CTree signals to identify which node thesignal pertains to.</P><P>To remove a node for a CTree, the following function is provided:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_ctree_remove_node( GtkCTree *ctree, GtkCTreeNode *node );</PRE></TD></TR></TABLE><P>As you can see, you merely need to specify a CTree and the node toremove.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="ch-ctreewidget.html"><<< Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-settingctreeattributes.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">CTree Widget</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-ctreewidget.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Setting CTree Attributes</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -