📄 sec-handlingtheselectionlist.html
字号:
<HTML><HEAD><TITLE>Handling the Selection List</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="Adding a Subtree"HREF="sec-addingasubtree.html"><LINKREL="NEXT"TITLE="Tree Widget Internals"HREF="sec-treewidgetinternals.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-addingasubtree.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 13. Tree Widget</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-treewidgetinternals.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-HANDLINGTHESELECTIONLIST">13.3. Handling the Selection List</A></H1><P>As with CList, the Tree type has a <TTCLASS="LITERAL">selection</TT> field, andit is possible to control the behaviour of the tree (somewhat) bysetting the selection type using:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_tree_set_selection_mode( GtkTree *tree, GtkSelectionMode mode );</PRE></TD></TR></TABLE><P>The semantics associated with the various selection modes aredescribed in the section on the CList widget. As with the CListwidget, the "select_child", "unselect_child" (not really - see <AHREF="sec-treewidgetinternals.html#SEC-TREESIGNALS">Signals</A> below for an explanation),and "selection_changed" signals are emitted when list items areselected or unselected. However, in order to take advantage of thesesignals, you need to know <ICLASS="EMPHASIS">which</I> Tree widget they will beemitted by, and where to find the list of selected items.</P><P>This is a source of potential confusion. The best way to explain thisis that though all Tree widgets are created equal, some are more equalthan others. All Tree widgets have their own X window, and cantherefore receive events such as mouse clicks (if their TreeItems ortheir children don't catch them first!). However, to make<TTCLASS="LITERAL">GTK_SELECTION_SINGLE</TT> and <TTCLASS="LITERAL">GTK_SELECTION_BROWSE</TT> selectiontypes behave in a sane manner, the list of selected items is specificto the topmost Tree widget in a hierarchy, known as the "root tree".</P><P>Thus, accessing the <TTCLASS="LITERAL">selection</TT> field directly in an arbitraryTree widget is not a good idea unless you <ICLASS="EMPHASIS">know</I> it's the roottree. Instead, use the <TTCLASS="LITERAL">GTK_TREE_SELECTION (Tree)</TT> macro, whichgives the root tree's selection list as a GList pointer. Of course,this list can include items that are not in the subtree in question ifthe selection type is <TTCLASS="LITERAL">GTK_SELECTION_MULTIPLE</TT>.</P><P>Finally, the "select_child" (and "unselect_child", in theory) signalsare emitted by all trees, but the "selection_changed" signal is onlyemitted by the root tree. Consequently, if you want to handle the"select_child" signal for a tree and all its subtrees, you will haveto call gtk_signal_connect() for every subtree.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-addingasubtree.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-treewidgetinternals.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Adding a Subtree</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-treewidget.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Tree Widget Internals</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -