gtk_tut-12.html
来自「gtk是linux一款强大的夸平台的图形化开发工具」· HTML 代码 · 共 867 行 · 第 1/3 页
HTML
867 行
gint start, gint end );</PRE></CODE></BLOCKQUOTE><P>Remove the items from position <CODE>start</CODE> to position <CODE>end</CODE>from a GtkTree. The same warning about dereferencing applies here, asgtk_tree_clear_items() simply constructs a list and passes it togtk_tree_remove_items().<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_select_item( GtkTree *tree, gint item );</PRE></CODE></BLOCKQUOTE><P>Emits the "select_item" signal for the child at position<CODE>item</CODE>, thus selecting the child (unless you unselect it in asignal handler).<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_unselect_item( GtkTree *tree, gint item );</PRE></CODE></BLOCKQUOTE><P>Emits the "unselect_item" signal for the child at position<CODE>item</CODE>, thus unselecting the child.<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_select_child( GtkTree *tree, GtkWidget *tree_item );</PRE></CODE></BLOCKQUOTE><P>Emits the "select_item" signal for the child <CODE>tree_item</CODE>, thusselecting it.<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_unselect_child( GtkTree *tree, GtkWidget *tree_item );</PRE></CODE></BLOCKQUOTE><P>Emits the "unselect_item" signal for the child <CODE>tree_item</CODE>,thus unselecting it.<P><BLOCKQUOTE><CODE><PRE>gint gtk_tree_child_position( GtkTree *tree, GtkWidget *child );</PRE></CODE></BLOCKQUOTE><P>Returns the position in the tree of <CODE>child</CODE>, unless<CODE>child</CODE> is not in the tree, in which case it returns -1.<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_set_selection_mode( GtkTree *tree, GtkSelectionMode mode );</PRE></CODE></BLOCKQUOTE><P>Sets the selection mode, which can be one of GTK_SELECTION_SINGLE (thedefault), GTK_SELECTION_BROWSE, GTK_SELECTION_MULTIPLE, orGTK_SELECTION_EXTENDED. This is only defined for root trees, whichmakes sense, since the root tree "owns" the selection. Setting it forsubtrees has no effect at all; the value is simply ignored.<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_set_view_mode( GtkTree *tree, GtkTreeViewMode mode ); </PRE></CODE></BLOCKQUOTE><P>Sets the "view mode", which can be either GTK_TREE_VIEW_LINE (thedefault) or GTK_TREE_VIEW_ITEM. The view mode propagates from a treeto its subtrees, and can't be set exclusively to a subtree (this isnot exactly true - see the example code comments).<P>The term "view mode" is rather ambiguous - basically, it controls theway the highlight is drawn when one of a tree's children is selected.If it's GTK_TREE_VIEW_LINE, the entire GtkTreeItem widget ishighlighted, while for GTK_TREE_VIEW_ITEM, only the child widget(i.e. usually the label) is highlighted.<P><BLOCKQUOTE><CODE><PRE>void gtk_tree_set_view_lines( GtkTree *tree, guint flag );</PRE></CODE></BLOCKQUOTE><P>Controls whether connecting lines between tree items are drawn.<CODE>flag</CODE> is either TRUE, in which case they are, or FALSE, inwhich case they aren't.<P><BLOCKQUOTE><CODE><PRE>GtkTree *GTK_TREE (gpointer obj);</PRE></CODE></BLOCKQUOTE><P>Cast a generic pointer to `GtkTree *'.<P><BLOCKQUOTE><CODE><PRE>GtkTreeClass *GTK_TREE_CLASS (gpointer class);</PRE></CODE></BLOCKQUOTE><P>Cast a generic pointer to `GtkTreeClass*'.<P><BLOCKQUOTE><CODE><PRE>gint GTK_IS_TREE (gpointer obj);</PRE></CODE></BLOCKQUOTE><P>Determine if a generic pointer refers to a `GtkTree' object.<P><BLOCKQUOTE><CODE><PRE>gint GTK_IS_ROOT_TREE (gpointer obj)</PRE></CODE></BLOCKQUOTE><P>Determine if a generic pointer refers to a `GtkTree' object<EM>and</EM> is a root tree. Though this will accept any pointer, theresults of passing it a pointer that does not refer to a GtkTree areundefined and possibly harmful.<P><BLOCKQUOTE><CODE><PRE>GtkTree *GTK_TREE_ROOT_TREE (gpointer obj)</PRE></CODE></BLOCKQUOTE><P>Return the root tree of a pointer to a `GtkTree' object. The abovewarning applies.<P><BLOCKQUOTE><CODE><PRE>GList *GTK_TREE_SELECTION( gpointer obj)</PRE></CODE></BLOCKQUOTE><P>Return the selection list of the root tree of a `GtkTree' object. Theabove warning applies here, too.<P><H2><A NAME="sec_Tree_Item_Widget"></A> <A NAME="ss12.5">12.5 Tree Item Widget</A></H2><P>The GtkTreeItem widget, like GtkListItem, is derived from GtkItem,which in turn is derived from GtkBin. Therefore, the item itself is ageneric container holding exactly one child widget, which can be ofany type. The GtkTreeItem widget has a number of extra fields, butthe only one we need be concerned with is the <CODE>subtree</CODE> field.<P>The definition for the GtkTreeItem struct looks like this:<P><BLOCKQUOTE><CODE><PRE>struct _GtkTreeItem{ GtkItem item; GtkWidget *subtree; GtkWidget *pixmaps_box; GtkWidget *plus_pix_widget, *minus_pix_widget; GList *pixmaps; /* pixmap node for this items color depth */ guint expanded : 1;};</PRE></CODE></BLOCKQUOTE><P>The <CODE>pixmaps_box</CODE> field is a GtkEventBox which catches clickson the plus/minus symbol which controls expansion and collapsing. The<CODE>pixmaps</CODE> field points to an internal data structure. Sinceyou can always obtain the subtree of a GtkTreeItem in a (relatively)type-safe manner with the GTK_TREE_ITEM_SUBTREE (Item) macro, it'sprobably advisable never to touch the insides of a GtkTreeItem unlessyou <EM>really</EM> know what you're doing.<P>Since it is directly derived from a GtkItem it can be treated as suchby using the GTK_ITEM (TreeItem) macro. A GtkTreeItem usually holds alabel, so the convenience function gtk_list_item_new_with_label() isprovided. The same effect can be achieved using code like thefollowing, which is actually copied verbatim fromgtk_tree_item_new_with_label():<P><BLOCKQUOTE><CODE><PRE>tree_item = gtk_tree_item_new ();label_widget = gtk_label_new (label);gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);gtk_container_add (GTK_CONTAINER (tree_item), label_widget);gtk_widget_show (label_widget);</PRE></CODE></BLOCKQUOTE><P>As one is not forced to add a GtkLabel to a GtkTreeItem, you couldalso add a GtkHBox or a GtkArrow, or even a GtkNotebook (though yourapp will likely be quite unpopular in this case) to the GtkTreeItem.<P>If you remove all the items from a subtree, it will be destroyed andunparented, unless you reference it beforehand, and the GtkTreeItemwhich owns it will be collapsed. So, if you want it to stick around,do something like the following:<P><BLOCKQUOTE><CODE><PRE>gtk_widget_ref (tree);owner = GTK_TREE(tree)->tree_owner;gtk_container_remove (GTK_CONTAINER(tree), item);if (tree->parent == NULL){ gtk_tree_item_expand (GTK_TREE_ITEM(owner)); gtk_tree_item_set_subtree (GTK_TREE_ITEM(owner), tree);}else gtk_widget_unref (tree);</PRE></CODE></BLOCKQUOTE><P>Finally, drag-n-drop <EM>does</EM> work with GtkTreeItems. You justhave to make sure that the GtkTreeItem you want to make into a dragitem or a drop site has not only been added to a GtkTree, but thateach successive parent widget has a parent itself, all the way back toa toplevel or dialog window, when you call gtk_widget_dnd_drag_set()or gtk_widget_dnd_drop_set(). Otherwise, strange things will happen.<P><H3>Signals</H3><P>GtkTreeItem inherits the "select", "deselect", and "toggle" signalsfrom GtkItem. In addition, it adds two signals of its own, "expand"and "collapse".<P><BLOCKQUOTE><CODE><PRE>void select( GtkItem *tree_item );</PRE></CODE></BLOCKQUOTE><P>This signal is emitted when an item is about to be selected, eitherafter it has been clicked on by the user, or when the program callsgtk_tree_item_select(), gtk_item_select(), or gtk_tree_select_child().<P><BLOCKQUOTE><CODE><PRE>void deselect( GtkItem *tree_item );</PRE></CODE></BLOCKQUOTE><P>This signal is emitted when an item is about to be unselected, eitherafter it has been clicked on by the user, or when the program callsgtk_tree_item_deselect() or gtk_item_deselect(). In the case ofGtkTreeItems, it is also emitted by gtk_tree_unselect_child(), andsometimes gtk_tree_select_child().<P><BLOCKQUOTE><CODE><PRE>void toggle( GtkItem *tree_item );</PRE></CODE></BLOCKQUOTE><P>This signal is emitted when the program calls gtk_item_toggle(). Theeffect it has when emitted on a GtkTreeItem is to callgtk_tree_select_child() (and never gtk_tree_unselect_child()) on theitem's parent tree, if the item has a parent tree. If it doesn't,then the highlight is reversed on the item.<P><BLOCKQUOTE><CODE><PRE>void expand( GtkTreeItem *tree_item );</PRE></CODE></BLOCKQUOTE><P>This signal is emitted when the tree item's subtree is about to beexpanded, that is, when the user clicks on the plus sign next to theitem, or when the program calls gtk_tree_item_expand().<P><BLOCKQUOTE><CODE><PRE>void collapse( GtkTreeItem *tree_item );</PRE></CODE></BLOCKQUOTE><P>This signal is emitted when the tree item's subtree is about to becollapsed, that is, when the user clicks on the minus sign next to theitem, or when the program calls gtk_tree_item_collapse().<P><H3>Functions and Macros</H3><P><BLOCKQUOTE><CODE><PRE>guint gtk_tree_item_get_type( void );</PRE></CODE></BLOCKQUOTE><P>Returns the `GtkTreeItem' type identifier.<P><BLOCKQUOTE><CODE><PRE>GtkWidget* gtk_tree_item_new( void );</PRE></CODE></BLOCKQUOTE><P>Create a new GtkTreeItem object. The new widget is returned as a
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?