📄 gtkscrolledwindow.c
字号:
requisition->height += hscrollbar_requisition.height; } } if (scrolled_window->hscrollbar_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) { requisition->width = MAX (requisition->width, hscrollbar_requisition.width); if (!extra_height || GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) extra_height = SCROLLBAR_SPACING (scrolled_window) + hscrollbar_requisition.height; } if (scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) { requisition->height = MAX (requisition->height, vscrollbar_requisition.height); if (!extra_width || GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) extra_width = SCROLLBAR_SPACING (scrolled_window) + vscrollbar_requisition.width; } requisition->width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width); requisition->height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);}static voidgtk_scrolled_window_relative_allocation (GtkWidget *widget, GtkAllocation *allocation){ GtkScrolledWindow *scrolled_window; g_return_if_fail (widget != NULL); g_return_if_fail (allocation != NULL); scrolled_window = GTK_SCROLLED_WINDOW (widget); allocation->x = GTK_CONTAINER (widget)->border_width; allocation->y = GTK_CONTAINER (widget)->border_width; allocation->width = MAX (1, (gint)widget->allocation.width - allocation->x * 2); allocation->height = MAX (1, (gint)widget->allocation.height - allocation->y * 2); if (scrolled_window->vscrollbar_visible) { GtkRequisition vscrollbar_requisition; gtk_widget_get_child_requisition (scrolled_window->vscrollbar, &vscrollbar_requisition); if (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT || scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT) allocation->x += (vscrollbar_requisition.width + SCROLLBAR_SPACING (scrolled_window)); allocation->width = MAX (1, (gint)allocation->width - ((gint)vscrollbar_requisition.width + (gint)SCROLLBAR_SPACING (scrolled_window))); } if (scrolled_window->hscrollbar_visible) { GtkRequisition hscrollbar_requisition; gtk_widget_get_child_requisition (scrolled_window->hscrollbar, &hscrollbar_requisition); if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT || scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT) allocation->y += (hscrollbar_requisition.height + SCROLLBAR_SPACING (scrolled_window)); allocation->height = MAX (1, (gint)allocation->height - ((gint)hscrollbar_requisition.height + (gint)SCROLLBAR_SPACING (scrolled_window))); }}static voidgtk_scrolled_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation){ GtkScrolledWindow *scrolled_window; GtkBin *bin; GtkAllocation relative_allocation; GtkAllocation child_allocation; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); g_return_if_fail (allocation != NULL); scrolled_window = GTK_SCROLLED_WINDOW (widget); bin = GTK_BIN (scrolled_window); widget->allocation = *allocation; if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS) scrolled_window->hscrollbar_visible = TRUE; else if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER) scrolled_window->hscrollbar_visible = FALSE; if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS) scrolled_window->vscrollbar_visible = TRUE; else if (scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER) scrolled_window->vscrollbar_visible = FALSE; if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { gboolean previous_hvis; gboolean previous_vvis; guint count = 0; do { gtk_scrolled_window_relative_allocation (widget, &relative_allocation); child_allocation.x = relative_allocation.x + allocation->x; child_allocation.y = relative_allocation.y + allocation->y; child_allocation.width = relative_allocation.width; child_allocation.height = relative_allocation.height; previous_hvis = scrolled_window->hscrollbar_visible; previous_vvis = scrolled_window->vscrollbar_visible; gtk_widget_size_allocate (bin->child, &child_allocation); /* If, after the first iteration, the hscrollbar and the * vscrollbar flip visiblity, then we need both. */ if (count && previous_hvis != scrolled_window->hscrollbar_visible && previous_vvis != scrolled_window->vscrollbar_visible) { scrolled_window->hscrollbar_visible = TRUE; scrolled_window->vscrollbar_visible = TRUE; /* a new resize is already queued at this point, * so we will immediatedly get reinvoked */ return; } count++; } while (previous_hvis != scrolled_window->hscrollbar_visible || previous_vvis != scrolled_window->vscrollbar_visible); } else gtk_scrolled_window_relative_allocation (widget, &relative_allocation); if (scrolled_window->hscrollbar_visible) { GtkRequisition hscrollbar_requisition; gtk_widget_get_child_requisition (scrolled_window->hscrollbar, &hscrollbar_requisition); if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) gtk_widget_show (scrolled_window->hscrollbar); child_allocation.x = relative_allocation.x; if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT) child_allocation.y = (relative_allocation.y + relative_allocation.height + SCROLLBAR_SPACING (scrolled_window)); else child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width; child_allocation.width = relative_allocation.width; child_allocation.height = hscrollbar_requisition.height; child_allocation.x += allocation->x; child_allocation.y += allocation->y; gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation); } else if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) gtk_widget_hide (scrolled_window->hscrollbar); if (scrolled_window->vscrollbar_visible) { GtkRequisition vscrollbar_requisition; if (!GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) gtk_widget_show (scrolled_window->vscrollbar); gtk_widget_get_child_requisition (scrolled_window->vscrollbar, &vscrollbar_requisition); if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT) child_allocation.x = (relative_allocation.x + relative_allocation.width + SCROLLBAR_SPACING (scrolled_window)); else child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width; child_allocation.y = relative_allocation.y; child_allocation.width = vscrollbar_requisition.width; child_allocation.height = relative_allocation.height; child_allocation.x += allocation->x; child_allocation.y += allocation->y; gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation); } else if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) gtk_widget_hide (scrolled_window->vscrollbar);}static voidgtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, gpointer data){ GtkScrolledWindow *scrolled_win; g_return_if_fail (adjustment != NULL); g_return_if_fail (data != NULL); scrolled_win = GTK_SCROLLED_WINDOW (data); if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->hscrollbar))) { if (scrolled_win->hscrollbar_policy == GTK_POLICY_AUTOMATIC) { gboolean visible; visible = scrolled_win->hscrollbar_visible; scrolled_win->hscrollbar_visible = (adjustment->upper - adjustment->lower > adjustment->page_size); if (scrolled_win->hscrollbar_visible != visible) gtk_widget_queue_resize (GTK_WIDGET (scrolled_win)); } } else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->vscrollbar))) { if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC) { gboolean visible; visible = scrolled_win->vscrollbar_visible; scrolled_win->vscrollbar_visible = (adjustment->upper - adjustment->lower > adjustment->page_size); if (scrolled_win->vscrollbar_visible != visible) gtk_widget_queue_resize (GTK_WIDGET (scrolled_win)); } }}static voidgtk_scrolled_window_add (GtkContainer *container, GtkWidget *child){ GtkScrolledWindow *scrolled_window; GtkBin *bin; bin = GTK_BIN (container); g_return_if_fail (bin->child == NULL); scrolled_window = GTK_SCROLLED_WINDOW (container); bin->child = child; gtk_widget_set_parent (child, GTK_WIDGET (bin)); /* this is a temporary message */ if (!gtk_widget_set_scroll_adjustments (child, gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)), gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)))) g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget " "use gtk_scrolled_window_add_with_viewport() instead"); if (GTK_WIDGET_REALIZED (child->parent)) gtk_widget_realize (child); if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { if (GTK_WIDGET_MAPPED (child->parent)) gtk_widget_map (child); gtk_widget_queue_resize (child); }}static voidgtk_scrolled_window_remove (GtkContainer *container, GtkWidget *child){ g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); g_return_if_fail (child != NULL); g_return_if_fail (GTK_BIN (container)->child == child); gtk_widget_set_scroll_adjustments (child, NULL, NULL); /* chain parent class handler to remove child */ GTK_CONTAINER_CLASS (parent_class)->remove (container, child);}voidgtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, GtkWidget *child){ GtkBin *bin; GtkWidget *viewport; g_return_if_fail (scrolled_window != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); g_return_if_fail (child != NULL); g_return_if_fail (GTK_IS_WIDGET (child)); g_return_if_fail (child->parent == NULL); bin = GTK_BIN (scrolled_window); if (bin->child != NULL) { g_return_if_fail (GTK_IS_VIEWPORT (bin->child)); g_return_if_fail (GTK_BIN (bin->child)->child == NULL); viewport = bin->child; } else { viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window), gtk_scrolled_window_get_vadjustment (scrolled_window)); gtk_container_add (GTK_CONTAINER (scrolled_window), viewport); } gtk_widget_show (viewport); gtk_container_add (GTK_CONTAINER (viewport), child);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -