📄 gtktree.c
字号:
tmp_list = selected_widgets; while (tmp_list) { widget = tmp_list->data; tmp_list = tmp_list->next; #ifdef TREE_DEBUG g_message("* widget [%#x] subtree [%#x]\n", (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));#endif /* TREE_DEBUG */ /* remove widget of selection */ root_tree->selection = g_list_remove (root_tree->selection, widget); /* unref it to authorize is destruction */ gtk_widget_unref (widget); } /* emit only one selection_changed signal */ gtk_signal_emit (GTK_OBJECT (root_tree), tree_signals[SELECTION_CHANGED]); } #ifdef TREE_DEBUG g_message("* free selected_widgets list\n");#endif /* TREE_DEBUG */ g_list_free (selected_widgets); g_list_free (sorted_list); if (root_tree->children && !root_tree->selection && (root_tree->selection_mode == GTK_SELECTION_BROWSE)) {#ifdef TREE_DEBUG g_message("* BROWSE mode, select another item\n");#endif /* TREE_DEBUG */ widget = root_tree->children->data; gtk_tree_select_child (root_tree, widget); } if (GTK_WIDGET_VISIBLE (root_tree)) {#ifdef TREE_DEBUG g_message("* query queue resizing for root_tree\n");#endif /* TREE_DEBUG */ gtk_widget_queue_resize (GTK_WIDGET (root_tree)); }}voidgtk_tree_select_child (GtkTree *tree, GtkWidget *tree_item){ g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); g_return_if_fail (tree_item != NULL); g_return_if_fail (GTK_IS_TREE_ITEM (tree_item)); gtk_signal_emit (GTK_OBJECT (tree), tree_signals[SELECT_CHILD], tree_item);}voidgtk_tree_select_item (GtkTree *tree, gint item){ GList *tmp_list; g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); tmp_list = g_list_nth (tree->children, item); if (tmp_list) gtk_tree_select_child (tree, GTK_WIDGET (tmp_list->data)); }static voidgtk_tree_size_allocate (GtkWidget *widget, GtkAllocation *allocation){ GtkTree *tree; GtkWidget *child, *subtree; GtkAllocation child_allocation; GList *children; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TREE (widget)); g_return_if_fail (allocation != NULL); tree = GTK_TREE (widget); widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); if (tree->children) { child_allocation.x = GTK_CONTAINER (tree)->border_width; child_allocation.y = GTK_CONTAINER (tree)->border_width; child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2); children = tree->children; while (children) { child = children->data; children = children->next; if (GTK_WIDGET_VISIBLE (child)) { GtkRequisition child_requisition; gtk_widget_get_child_requisition (child, &child_requisition); child_allocation.height = child_requisition.height; gtk_widget_size_allocate (child, &child_allocation); child_allocation.y += child_allocation.height; if((subtree = GTK_TREE_ITEM(child)->subtree)) if(GTK_WIDGET_VISIBLE (subtree)) { child_allocation.height = subtree->requisition.height; gtk_widget_size_allocate (subtree, &child_allocation); child_allocation.y += child_allocation.height; } } } } }static voidgtk_tree_size_request (GtkWidget *widget, GtkRequisition *requisition){ GtkTree *tree; GtkWidget *child, *subtree; GList *children; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TREE (widget)); g_return_if_fail (requisition != NULL); tree = GTK_TREE (widget); requisition->width = 0; requisition->height = 0; children = tree->children; while (children) { child = children->data; children = children->next; if (GTK_WIDGET_VISIBLE (child)) { gtk_widget_size_request (child, &child_requisition); requisition->width = MAX (requisition->width, child_requisition.width); requisition->height += child_requisition.height; if((subtree = GTK_TREE_ITEM(child)->subtree) && GTK_WIDGET_VISIBLE (subtree)) { gtk_widget_size_request (subtree, &child_requisition); requisition->width = MAX (requisition->width, child_requisition.width); requisition->height += child_requisition.height; } } } requisition->width += GTK_CONTAINER (tree)->border_width * 2; requisition->height += GTK_CONTAINER (tree)->border_width * 2; requisition->width = MAX (requisition->width, 1); requisition->height = MAX (requisition->height, 1); }static voidgtk_tree_unmap (GtkWidget *widget){ g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TREE (widget)); GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); gdk_window_hide (widget->window); }voidgtk_tree_unselect_child (GtkTree *tree, GtkWidget *tree_item){ g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); g_return_if_fail (tree_item != NULL); g_return_if_fail (GTK_IS_TREE_ITEM (tree_item)); gtk_signal_emit (GTK_OBJECT (tree), tree_signals[UNSELECT_CHILD], tree_item);}voidgtk_tree_unselect_item (GtkTree *tree, gint item){ GList *tmp_list; g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); tmp_list = g_list_nth (tree->children, item); if (tmp_list) gtk_tree_unselect_child (tree, GTK_WIDGET (tmp_list->data)); }static voidgtk_real_tree_select_child (GtkTree *tree, GtkWidget *child){ GList *selection, *root_selection; GList *tmp_list; GtkWidget *tmp_item; g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); g_return_if_fail (child != NULL); g_return_if_fail (GTK_IS_TREE_ITEM (child)); root_selection = tree->root_tree->selection; switch (tree->root_tree->selection_mode) { case GTK_SELECTION_SINGLE: selection = root_selection; /* remove old selection list */ while (selection) { tmp_item = selection->data; if (tmp_item != child) { gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item)); tmp_list = selection; selection = selection->next; root_selection = g_list_remove_link (root_selection, tmp_list); gtk_widget_unref (tmp_item); g_list_free (tmp_list); } else selection = selection->next; } if (child->state == GTK_STATE_NORMAL) { gtk_tree_item_select (GTK_TREE_ITEM (child)); root_selection = g_list_prepend (root_selection, child); gtk_widget_ref (child); } else if (child->state == GTK_STATE_SELECTED) { gtk_tree_item_deselect (GTK_TREE_ITEM (child)); root_selection = g_list_remove (root_selection, child); gtk_widget_unref (child); } tree->root_tree->selection = root_selection; gtk_signal_emit (GTK_OBJECT (tree->root_tree), tree_signals[SELECTION_CHANGED]); break; case GTK_SELECTION_BROWSE: selection = root_selection; while (selection) { tmp_item = selection->data; if (tmp_item != child) { gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item)); tmp_list = selection; selection = selection->next; root_selection = g_list_remove_link (root_selection, tmp_list); gtk_widget_unref (tmp_item); g_list_free (tmp_list); } else selection = selection->next; } tree->root_tree->selection = root_selection; if (child->state == GTK_STATE_NORMAL) { gtk_tree_item_select (GTK_TREE_ITEM (child)); root_selection = g_list_prepend (root_selection, child); gtk_widget_ref (child); tree->root_tree->selection = root_selection; gtk_signal_emit (GTK_OBJECT (tree->root_tree), tree_signals[SELECTION_CHANGED]); } break; case GTK_SELECTION_MULTIPLE: if (child->state == GTK_STATE_NORMAL) { gtk_tree_item_select (GTK_TREE_ITEM (child)); root_selection = g_list_prepend (root_selection, child); gtk_widget_ref (child); tree->root_tree->selection = root_selection; gtk_signal_emit (GTK_OBJECT (tree->root_tree), tree_signals[SELECTION_CHANGED]); } else if (child->state == GTK_STATE_SELECTED) { gtk_tree_item_deselect (GTK_TREE_ITEM (child)); root_selection = g_list_remove (root_selection, child); gtk_widget_unref (child); tree->root_tree->selection = root_selection; gtk_signal_emit (GTK_OBJECT (tree->root_tree), tree_signals[SELECTION_CHANGED]); } break; case GTK_SELECTION_EXTENDED: break; }}static voidgtk_real_tree_unselect_child (GtkTree *tree, GtkWidget *child){ g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); g_return_if_fail (child != NULL); g_return_if_fail (GTK_IS_TREE_ITEM (child)); switch (tree->selection_mode) { case GTK_SELECTION_SINGLE: case GTK_SELECTION_MULTIPLE: case GTK_SELECTION_BROWSE: if (child->state == GTK_STATE_SELECTED) { GtkTree* root_tree = GTK_TREE_ROOT_TREE(tree); gtk_tree_item_deselect (GTK_TREE_ITEM (child)); root_tree->selection = g_list_remove (root_tree->selection, child); gtk_widget_unref (child); gtk_signal_emit (GTK_OBJECT (tree->root_tree), tree_signals[SELECTION_CHANGED]); } break; case GTK_SELECTION_EXTENDED: break; }}voidgtk_tree_set_selection_mode (GtkTree *tree, GtkSelectionMode mode) { g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); tree->selection_mode = mode;}voidgtk_tree_set_view_mode (GtkTree *tree, GtkTreeViewMode mode) { g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); tree->view_mode = mode;}voidgtk_tree_set_view_lines (GtkTree *tree, guint flag) { g_return_if_fail (tree != NULL); g_return_if_fail (GTK_IS_TREE (tree)); tree->view_line = flag;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -