⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtktreeitem.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 3 页
字号:
  g_return_if_fail (tree_item != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));  gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[COLLAPSE_TREE], NULL);}static voidgtk_tree_item_add_pixmaps (GtkTreeItem *tree_item){  GList *tmp_list;  GdkColormap *colormap;  GtkTreePixmaps *pixmap_node = NULL;  g_return_if_fail (tree_item != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));  if (tree_item->pixmaps)    return;  colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_item));  tmp_list = pixmaps;  while (tmp_list)    {      pixmap_node = (GtkTreePixmaps *)tmp_list->data;      if (pixmap_node->colormap == colormap)	break;            tmp_list = tmp_list->next;    }  if (tmp_list)    {      pixmap_node->refcount++;      tree_item->pixmaps = tmp_list;    }  else    {      pixmap_node = g_new (GtkTreePixmaps, 1);      pixmap_node->colormap = colormap;      gdk_colormap_ref (colormap);      pixmap_node->refcount = 1;      /* create pixmaps for plus icon */      pixmap_node->pixmap_plus = 	gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,				      &pixmap_node->mask_plus,				      NULL,				      tree_plus);            /* create pixmaps for minus icon */      pixmap_node->pixmap_minus = 	gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,				      &pixmap_node->mask_minus,				      NULL,				      tree_minus);      tree_item->pixmaps = pixmaps = g_list_prepend (pixmaps, pixmap_node);    }    gtk_pixmap_set (GTK_PIXMAP (tree_item->plus_pix_widget), 		  pixmap_node->pixmap_plus, pixmap_node->mask_plus);  gtk_pixmap_set (GTK_PIXMAP (tree_item->minus_pix_widget), 		  pixmap_node->pixmap_minus, pixmap_node->mask_minus);}static voidgtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item){  g_return_if_fail (tree_item != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));  if (tree_item->pixmaps)    {      GtkTreePixmaps *pixmap_node = (GtkTreePixmaps *)tree_item->pixmaps->data;            g_assert (pixmap_node->refcount > 0);            if (--pixmap_node->refcount == 0)	{	  gdk_colormap_unref (pixmap_node->colormap);	  gdk_pixmap_unref (pixmap_node->pixmap_plus);	  gdk_bitmap_unref (pixmap_node->mask_plus);	  gdk_pixmap_unref (pixmap_node->pixmap_minus);	  gdk_bitmap_unref (pixmap_node->mask_minus);	  	  pixmaps = g_list_remove_link (pixmaps, tree_item->pixmaps);	  g_list_free_1 (tree_item->pixmaps);	  g_free (pixmap_node);	}      tree_item->pixmaps = NULL;    }}static voidgtk_tree_item_realize (GtkWidget *widget){      g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  if (GTK_WIDGET_CLASS (parent_class)->realize)    (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);    gdk_window_set_background (widget->window, 			     &widget->style->base[GTK_STATE_NORMAL]);  gtk_tree_item_add_pixmaps (GTK_TREE_ITEM (widget));}static voidgtk_tree_item_size_request (GtkWidget      *widget,			    GtkRequisition *requisition){  GtkBin *bin;  GtkTreeItem* item;  GtkRequisition child_requisition;  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  g_return_if_fail (requisition != NULL);  bin = GTK_BIN (widget);  item = GTK_TREE_ITEM(widget);  requisition->width = (GTK_CONTAINER (widget)->border_width +			widget->style->klass->xthickness) * 2;  requisition->height = GTK_CONTAINER (widget)->border_width * 2;  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))    {      GtkRequisition pix_requisition;            gtk_widget_size_request (bin->child, &child_requisition);      requisition->width += child_requisition.width;      gtk_widget_size_request (item->pixmaps_box, 			       &pix_requisition);      requisition->width += pix_requisition.width + DEFAULT_DELTA + 	GTK_TREE (widget->parent)->current_indent;      requisition->height += MAX (child_requisition.height,				  pix_requisition.height);    }}static voidgtk_tree_item_size_allocate (GtkWidget     *widget,			     GtkAllocation *allocation){  GtkBin *bin;  GtkTreeItem* item;  GtkAllocation child_allocation;  guint border_width;  int temp;  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  g_return_if_fail (allocation != NULL);  widget->allocation = *allocation;  if (GTK_WIDGET_REALIZED (widget))    gdk_window_move_resize (widget->window,			    allocation->x, allocation->y,			    allocation->width, allocation->height);  bin = GTK_BIN (widget);  item = GTK_TREE_ITEM(widget);  if (bin->child)    {      border_width = (GTK_CONTAINER (widget)->border_width +		      widget->style->klass->xthickness);      child_allocation.x = border_width + GTK_TREE(widget->parent)->current_indent;      child_allocation.y = GTK_CONTAINER (widget)->border_width;      child_allocation.width = item->pixmaps_box->requisition.width;      child_allocation.height = item->pixmaps_box->requisition.height;            temp = allocation->height - child_allocation.height;      child_allocation.y += ( temp / 2 ) + ( temp % 2 );      gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);      child_allocation.y = GTK_CONTAINER (widget)->border_width;      child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);      child_allocation.x += item->pixmaps_box->requisition.width+DEFAULT_DELTA;      child_allocation.width = 	MAX (1, (gint)allocation->width - ((gint)child_allocation.x + border_width));      gtk_widget_size_allocate (bin->child, &child_allocation);    }}static void gtk_tree_item_draw_lines (GtkWidget *widget) {  GtkTreeItem* item;  GtkTree* tree;  guint lx1, ly1, lx2, ly2;  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  item = GTK_TREE_ITEM(widget);  tree = GTK_TREE(widget->parent);  if (!tree->view_line)    return;  /* draw vertical line */  lx1 = item->pixmaps_box->allocation.width;  lx1 = lx2 = ((lx1 / 2) + (lx1 % 2) + 	       GTK_CONTAINER (widget)->border_width + 1 + tree->current_indent);  ly1 = 0;  ly2 = widget->allocation.height;  if (g_list_last (tree->children)->data == widget)    ly2 = (ly2 / 2) + (ly2 % 2);  if (tree != tree->root_tree)    gdk_draw_line (widget->window, widget->style->black_gc, lx1, ly1, lx2, ly2);  /* draw vertical line for subtree connecting */  if(g_list_last(tree->children)->data != (gpointer)widget)    ly2 = (ly2 / 2) + (ly2 % 2);    lx2 += DEFAULT_DELTA;  if (item->subtree && item->expanded)    gdk_draw_line (widget->window, widget->style->black_gc,		   lx2, ly2, lx2, widget->allocation.height);  /* draw horizontal line */  ly1 = ly2;  lx2 += 2;  gdk_draw_line (widget->window, widget->style->black_gc,		 lx1, ly1, lx2, ly2);  lx2 -= DEFAULT_DELTA+2;  ly1 = 0;  ly2 = widget->allocation.height;  if (tree != tree->root_tree)    {      item = GTK_TREE_ITEM (tree->tree_owner);      tree = GTK_TREE (GTK_WIDGET (tree)->parent);      while (tree != tree->root_tree)	{	  lx1 = lx2 -= tree->indent_value;	  	  if (g_list_last (tree->children)->data != item)	    gdk_draw_line (widget->window, widget->style->black_gc, lx1, ly1, lx2, ly2);	  item = GTK_TREE_ITEM (tree->tree_owner);	  tree = GTK_TREE (GTK_WIDGET (tree)->parent);	}     }}static voidgtk_tree_item_paint (GtkWidget    *widget,		     GdkRectangle *area){  GtkBin *bin;  GdkRectangle child_area, item_area;  GtkTreeItem* tree_item;  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  g_return_if_fail (area != NULL);  /* FIXME: We should honor tree->view_mode, here - I think   * the desired effect is that when the mode is VIEW_ITEM,   * only the subitem is drawn as selected, not the entire   * line. (Like the way that the tree in Windows Explorer   * works).   */  if (GTK_WIDGET_DRAWABLE (widget))    {      bin = GTK_BIN (widget);      tree_item = GTK_TREE_ITEM(widget);      if (widget->state == GTK_STATE_NORMAL)	{	  gdk_window_set_back_pixmap (widget->window, NULL, TRUE);	  gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);	}      else 	{	  if (!GTK_WIDGET_IS_SENSITIVE (widget)) 	    gtk_paint_flat_box(widget->style, widget->window,			       widget->state, GTK_STATE_INSENSITIVE,			       area, widget, "treeitem",			       0, 0, -1, -1);	  else	    gtk_paint_flat_box(widget->style, widget->window,			       widget->state, GTK_SHADOW_ETCHED_OUT,			       area, widget, "treeitem",			       0, 0, -1, -1);	}      /* draw left size of tree item */      item_area.x = 0;      item_area.y = 0;      item_area.width = (tree_item->pixmaps_box->allocation.width + DEFAULT_DELTA +			 GTK_TREE (widget->parent)->current_indent + 2);      item_area.height = widget->allocation.height;      if (gdk_rectangle_intersect(&item_area, area, &child_area)) 	{	  	  gtk_tree_item_draw_lines(widget);	  if (tree_item->pixmaps_box && 	      GTK_WIDGET_VISIBLE(tree_item->pixmaps_box) &&	      gtk_widget_intersect (tree_item->pixmaps_box, area, &child_area))	    gtk_widget_draw (tree_item->pixmaps_box, &child_area);	}      if (GTK_WIDGET_HAS_FOCUS (widget))	gtk_paint_focus (widget->style, widget->window,			 NULL, widget, "treeitem",			 0, 0,			 widget->allocation.width - 1,			 widget->allocation.height - 1);          }}static voidgtk_tree_item_draw (GtkWidget    *widget,		    GdkRectangle *area){  GtkBin *bin;  GdkRectangle child_area;  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  g_return_if_fail (area != NULL);  if (GTK_WIDGET_DRAWABLE (widget))    {      bin = GTK_BIN (widget);      gtk_tree_item_paint (widget, area);           if (bin->child && 	  gtk_widget_intersect (bin->child, area, &child_area))	gtk_widget_draw (bin->child, &child_area);    }}static voidgtk_tree_item_draw_focus (GtkWidget *widget){  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_TREE_ITEM (widget));  gtk_widget_draw(widget, NULL);}static gintgtk_tree_item_button_press (GtkWidget      *widget,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -