📄 gtkpacker.c
字号:
g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_PACKER (widget)); packer = GTK_PACKER (widget); GTK_WIDGET_UNSET_FLAGS (packer, GTK_MAPPED); children = g_list_first(packer->children); while (children) { child = children->data; children = g_list_next(children); if (GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_MAPPED (child->widget)) gtk_widget_unmap (child->widget); }}static void gtk_packer_draw (GtkWidget *widget, GdkRectangle *area){ GtkPacker *packer; GtkPackerChild *child; GdkRectangle child_area; GList *children; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_PACKER (widget)); if (GTK_WIDGET_DRAWABLE (widget)) { packer = GTK_PACKER (widget); children = g_list_first(packer->children); while (children != NULL) { child = children->data; children = g_list_next(children); if (gtk_widget_intersect (child->widget, area, &child_area)) gtk_widget_draw (child->widget, &child_area); } } }static gint gtk_packer_expose (GtkWidget *widget, GdkEventExpose *event){ GtkPacker *packer; GtkPackerChild *child; GdkEventExpose child_event; GList *children; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_PACKER (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (GTK_WIDGET_DRAWABLE (widget)) { packer = GTK_PACKER (widget); child_event = *event; children = g_list_first(packer->children); while (children) { child = children->data; children = g_list_next(children); if (GTK_WIDGET_NO_WINDOW (child->widget) && gtk_widget_intersect (child->widget, &event->area, &child_event.area)) gtk_widget_event (child->widget, (GdkEvent*) &child_event); } } return FALSE;}static void gtk_packer_size_request (GtkWidget *widget, GtkRequisition *requisition){ GtkPacker *packer; GtkContainer *container; GtkPackerChild *child; GList *children; gint nvis_vert_children; gint nvis_horz_children; gint width, height; gint maxWidth, maxHeight; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_PACKER (widget)); g_return_if_fail (requisition != NULL); packer = GTK_PACKER (widget); container = GTK_CONTAINER (widget); requisition->width = 0; requisition->height = 0; nvis_vert_children = 0; nvis_horz_children = 0; width = height = maxWidth = maxHeight = 0; children = g_list_first(packer->children); while (children != NULL) { child = children->data; if (GTK_WIDGET_VISIBLE (child->widget)) { GtkRequisition child_requisition; gtk_widget_size_request (child->widget, &child_requisition); if ((child->side == GTK_SIDE_TOP) || (child->side == GTK_SIDE_BOTTOM)) { maxWidth = MAX (maxWidth, (child_requisition.width + 2 * child->border_width + child->pad_x + child->i_pad_x + width)); height += (child_requisition.height + 2 * child->border_width + child->pad_y + child->i_pad_y); } else { maxHeight = MAX (maxHeight, (child_requisition.height + 2 * child->border_width + child->pad_y + child->i_pad_y + height)); width += (child_requisition.width + 2 * child->border_width + child->pad_x + child->i_pad_x); } } children = g_list_next(children); } requisition->width = MAX (maxWidth, width) + 2 * container->border_width; requisition->height = MAX (maxHeight, height) + 2 * container->border_width;}static gintYExpansion (GList *children, gint cavityHeight){ GList *list; GtkPackerChild *child; GtkWidget *widget; gint numExpand, minExpand, curExpand; gint childHeight; minExpand = cavityHeight; numExpand = 0; list = children; while (list != NULL) { GtkRequisition child_requisition; child = list->data; widget = child->widget; gtk_widget_get_child_requisition (widget, &child_requisition); childHeight = (child_requisition.height + 2 * child->border_width + child->i_pad_y + child->pad_y); if ((child->side == GTK_SIDE_LEFT) || (child->side == GTK_SIDE_RIGHT)) { curExpand = (cavityHeight - childHeight)/numExpand; minExpand = MIN(minExpand, curExpand); } else { cavityHeight -= childHeight; if (child->options & GTK_PACK_EXPAND) numExpand++; } list = g_list_next(list); } curExpand = cavityHeight/numExpand; if (curExpand < minExpand) minExpand = curExpand; return (minExpand < 0) ? 0 : minExpand;}static gintXExpansion (GList *children, gint cavityWidth){ GList *list; GtkPackerChild *child; GtkWidget *widget; gint numExpand, minExpand, curExpand; gint childWidth; minExpand = cavityWidth; numExpand = 0; list = children; while (list != NULL) { GtkRequisition child_requisition; child = list->data; widget = child->widget; gtk_widget_get_child_requisition (widget, &child_requisition); childWidth = (child_requisition.width + 2 * child->border_width + child->i_pad_x + child->pad_x); if ((child->side == GTK_SIDE_TOP) || (child->side == GTK_SIDE_BOTTOM)) { curExpand = (cavityWidth - childWidth)/numExpand; minExpand = MIN(minExpand, curExpand); } else { cavityWidth -= childWidth; if (child->options & GTK_PACK_EXPAND) numExpand++; } list = g_list_next(list); } curExpand = cavityWidth/numExpand; if (curExpand < minExpand) minExpand = curExpand; return (minExpand < 0) ? 0 : minExpand; }static void gtk_packer_size_allocate (GtkWidget *widget, GtkAllocation *allocation){ GtkPacker *packer; GtkContainer *container; GtkAllocation child_allocation; GList *list; GtkPackerChild *child; gint cavityX, cavityY; gint cavityWidth, cavityHeight; gint width, height, x, y; gint frameHeight, frameWidth, frameX, frameY; gint borderX, borderY; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_PACKER (widget)); g_return_if_fail (allocation != NULL); packer = GTK_PACKER (widget); container = GTK_CONTAINER (widget); x = y = 0; widget->allocation = *allocation; cavityX = widget->allocation.x + container->border_width; cavityY = widget->allocation.y + container->border_width; cavityWidth = widget->allocation.width - 2 * container->border_width; cavityHeight = widget->allocation.height - 2 * container->border_width; list = g_list_first (packer->children); while (list != NULL) { GtkRequisition child_requisition; child = list->data; gtk_widget_get_child_requisition (child->widget, &child_requisition); if ((child->side == GTK_SIDE_TOP) || (child->side == GTK_SIDE_BOTTOM)) { frameWidth = cavityWidth; frameHeight = (child_requisition.height + 2 * child->border_width + child->pad_y + child->i_pad_y); if (child->options & GTK_PACK_EXPAND) frameHeight += YExpansion(list, cavityHeight); cavityHeight -= frameHeight; if (cavityHeight < 0) { frameHeight += cavityHeight; cavityHeight = 0; } frameX = cavityX; if (child->side == GTK_SIDE_TOP) { frameY = cavityY; cavityY += frameHeight; } else { frameY = cavityY + cavityHeight; } } else { frameHeight = cavityHeight; frameWidth = (child_requisition.width + 2 * child->border_width + child->pad_x + child->i_pad_x); if (child->options & GTK_PACK_EXPAND) frameWidth += XExpansion(list, cavityWidth); cavityWidth -= frameWidth; if (cavityWidth < 0) { frameWidth += cavityWidth; cavityWidth = 0; } frameY = cavityY; if (child->side == GTK_SIDE_LEFT) { frameX = cavityX; cavityX += frameWidth; } else { frameX = cavityX + cavityWidth; } } borderX = child->pad_x + 2 * child->border_width; borderY = child->pad_y + 2 * child->border_width; width = (child_requisition.width + 2 * child->border_width + child->i_pad_x); if ((child->options & GTK_FILL_X) || (width > (frameWidth - borderX))) width = frameWidth - borderX; height = (child_requisition.height + 2 * child->border_width + child->i_pad_y); if ((child->options & GTK_FILL_Y) || (height > (frameHeight - borderY))) height = frameHeight - borderY; borderX /= 2; borderY /= 2; switch (child->anchor) { case GTK_ANCHOR_N: x = frameX + (frameWidth - width)/2; y = frameY + borderY; break; case GTK_ANCHOR_NE: x = frameX + frameWidth - width - borderX; y = frameY + borderY; break; case GTK_ANCHOR_E: x = frameX + frameWidth - width - borderX; y = frameY + (frameHeight - height)/2; break; case GTK_ANCHOR_SE: x = frameX + frameWidth - width - borderX; y = frameY + frameHeight - height - borderY; break; case GTK_ANCHOR_S: x = frameX + (frameWidth - width)/2; y = frameY + frameHeight - height - borderY; break; case GTK_ANCHOR_SW: x = frameX + borderX; y = frameY + frameHeight - height - borderY; break; case GTK_ANCHOR_W: x = frameX + borderX; y = frameY + (frameHeight - height)/2; break; case GTK_ANCHOR_NW: x = frameX + borderX; y = frameY + borderY; break; case GTK_ANCHOR_CENTER: x = frameX + (frameWidth - width)/2; y = frameY + (frameHeight - height)/2; break; default: g_warning ("gtk_packer_size_allocate(): bad anchor type: %d", child->anchor); } if (width <= 0 || height <= 0) { gtk_widget_unmap(child->widget); } else { child_allocation.x = x; child_allocation.y = y; child_allocation.width = width; child_allocation.height = height; gtk_widget_size_allocate (child->widget, &child_allocation); if (GTK_WIDGET_MAPPED (widget) && !(GTK_WIDGET_MAPPED (child->widget))) gtk_widget_map(child->widget); } list = g_list_next(list); }}static voidgtk_packer_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data){ GtkPacker *packer; GtkPackerChild *child; GList *children; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_PACKER (container)); g_return_if_fail (callback != NULL); packer = GTK_PACKER (container); children = g_list_first (packer->children); while (children != NULL) { child = children->data; children = g_list_next(children); (* callback) (child->widget, callback_data); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -