+static void
+get_preferred_size_for_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint size,
+ gint *minimum,
+ gint *natural)
+{
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (size < 0)
+ gtk_widget_get_preferred_width (widget, minimum, natural);
+ else
+ gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
+ else
+ if (size < 0)
+ gtk_widget_get_preferred_height (widget, minimum, natural);
+ else
+ gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint size,
+ gint *minimum,
+ gint *natural)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ GtkPanedPrivate *priv = paned->priv;
+ gint child_min, child_nat;
+
+ *minimum = *natural = 0;
+
+ if (priv->child1 && gtk_widget_get_visible (priv->child1))
+ {
+ get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
+ if (priv->child1_shrink && priv->orientation == orientation)
+ *minimum = 0;
+ else
+ *minimum = child_min;
+ *natural = child_nat;
+ }
+
+ if (priv->child2 && gtk_widget_get_visible (priv->child2))
+ {
+ get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
+
+ if (priv->orientation == orientation)
+ {
+ if (!priv->child2_shrink)
+ *minimum += child_min;
+ *natural += child_nat;
+ }
+ else
+ {
+ *minimum = MAX (*minimum, child_min);
+ *natural = MAX (*natural, child_nat);
+ }
+ }
+
+ if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
+ priv->child2 && gtk_widget_get_visible (priv->child2))
+ {
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ if (priv->orientation == orientation)
+ {
+ *minimum += handle_size;
+ *natural += handle_size;
+ }
+ }
+}
+
+static void
+gtk_paned_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
+}
+
+static void
+gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum,
+ gint *natural)
+{
+ gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
+}
+
+static void
+flip_child (GtkWidget *widget,
+ GtkAllocation *child_pos)
+{
+ GtkAllocation allocation;
+ gint x, width;
+
+ gtk_widget_get_allocation (widget, &allocation);
+ x = allocation.x;
+ width = allocation.width;
+
+ child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
+}
+
+static void
+gtk_paned_set_child_visible (GtkPaned *paned,
+ guint id,
+ gboolean visible)
+{
+ GtkPanedPrivate *priv = paned->priv;
+ GtkWidget *child;
+
+ child = id == CHILD1 ? priv->child1 : priv->child2;
+
+ if (child == NULL)
+ return;
+
+ gtk_widget_set_child_visible (child, visible);
+
+ if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
+ {
+ GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
+
+ if (visible != gdk_window_is_visible (window))
+ {
+ if (visible)
+ gdk_window_show (window);
+ else
+ gdk_window_hide (window);
+ }
+ }
+}
+
+static void
+gtk_paned_child_allocate (GtkWidget *child,
+ GdkWindow *child_window, /* can be NULL */
+ const GtkAllocation *window_allocation,
+ GtkAllocation *child_allocation)
+{
+ if (child_window)
+ gdk_window_move_resize (child_window,
+ window_allocation->x, window_allocation->y,
+ window_allocation->width, window_allocation->height);
+
+ gtk_widget_size_allocate (child, child_allocation);
+}
+
+static void
+gtk_paned_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ GtkPanedPrivate *priv = paned->priv;
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
+ priv->child2 && gtk_widget_get_visible (priv->child2))
+ {
+ GtkAllocation child1_allocation, window1_allocation;
+ GtkAllocation child2_allocation, window2_allocation;
+ GtkAllocation priv_child1_allocation;
+ GdkRectangle old_handle_pos;
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ old_handle_pos = priv->handle_pos;
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gint child1_width, child2_width;
+
+ gtk_widget_get_preferred_width_for_height (priv->child1,
+ allocation->height,
+ &child1_width, NULL);
+ gtk_widget_get_preferred_width_for_height (priv->child2,
+ allocation->height,
+ &child2_width, NULL);
+
+ gtk_paned_calc_position (paned,
+ MAX (1, allocation->width - handle_size),
+ child1_width,
+ child2_width);
+
+ priv->handle_pos.x = allocation->x + priv->child1_size;
+ priv->handle_pos.y = allocation->y;
+ priv->handle_pos.width = handle_size;
+ priv->handle_pos.height = allocation->height;
+
+ window1_allocation.height = window2_allocation.height = allocation->height;
+ window1_allocation.width = MAX (1, priv->child1_size);
+ window1_allocation.x = allocation->x;
+ window1_allocation.y = window2_allocation.y = allocation->y;
+
+ window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
+ window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
+ {
+ flip_child (widget, &(window2_allocation));
+ flip_child (widget, &(window1_allocation));
+ flip_child (widget, &(priv->handle_pos));
+ }
+
+ child1_allocation.x = child1_allocation.y = 0;
+ child1_allocation.width = window1_allocation.width;
+ child1_allocation.height = window1_allocation.height;
+ if (child1_width > child1_allocation.width)
+ {
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
+ child1_allocation.x -= child1_width - child1_allocation.width;
+ child1_allocation.width = child1_width;
+ }
+
+ child2_allocation.x = child2_allocation.y = 0;
+ child2_allocation.width = window2_allocation.width;
+ child2_allocation.height = window2_allocation.height;
+ if (child2_width > child2_allocation.width)
+ {
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
+ child2_allocation.x -= child2_width - child2_allocation.width;
+ child2_allocation.width = child2_width;
+ }
+ }
+ else
+ {
+ gint child1_height, child2_height;
+
+ gtk_widget_get_preferred_height_for_width (priv->child1,
+ allocation->width,
+ &child1_height, NULL);
+ gtk_widget_get_preferred_height_for_width (priv->child2,
+ allocation->width,
+ &child2_height, NULL);
+
+ gtk_paned_calc_position (paned,
+ MAX (1, allocation->height - handle_size),
+ child1_height,
+ child2_height);
+
+ priv->handle_pos.x = allocation->x;
+ priv->handle_pos.y = allocation->y + priv->child1_size;
+ priv->handle_pos.width = allocation->width;
+ priv->handle_pos.height = handle_size;
+
+ window1_allocation.width = window2_allocation.width = allocation->width;
+ window1_allocation.height = MAX (1, priv->child1_size);
+ window1_allocation.x = window2_allocation.x = allocation->x;
+ window1_allocation.y = allocation->y;
+
+ window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
+ window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
+
+ child1_allocation.x = child1_allocation.y = 0;
+ child1_allocation.width = window1_allocation.width;
+ child1_allocation.height = window1_allocation.height;
+ if (child1_height > child1_allocation.height)
+ {
+ child1_allocation.y -= child1_height - child1_allocation.height;
+ child1_allocation.height = child1_height;
+ }
+
+ child2_allocation.x = child2_allocation.y = 0;
+ child2_allocation.width = window2_allocation.width;
+ child2_allocation.height = window2_allocation.height;
+ if (child2_height > child2_allocation.height)
+ child2_allocation.height = child2_height;
+ }
+
+ if (gtk_widget_get_mapped (widget) &&
+ (old_handle_pos.x != priv->handle_pos.x ||
+ old_handle_pos.y != priv->handle_pos.y ||
+ old_handle_pos.width != priv->handle_pos.width ||
+ old_handle_pos.height != priv->handle_pos.height))
+ {
+ GdkWindow *window;
+
+ window = gtk_widget_get_window (widget);
+ gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
+ gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
+ }
+
+ if (gtk_widget_get_realized (widget))
+ {
+ if (gtk_widget_get_mapped (widget))
+ gdk_window_show (priv->handle);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gdk_window_move_resize (priv->handle,
+ priv->handle_pos.x,
+ priv->handle_pos.y,
+ handle_size,
+ priv->handle_pos.height);
+ }
+ else
+ {
+ gdk_window_move_resize (priv->handle,
+ priv->handle_pos.x,
+ priv->handle_pos.y,
+ priv->handle_pos.width,
+ handle_size);
+ }
+ }
+
+ /* Now allocate the childen, making sure, when resizing not to
+ * overlap the windows
+ */
+ gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
+ if (gtk_widget_get_mapped (widget) &&
+ ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ priv_child1_allocation.width < child1_allocation.width) ||
+
+ (priv->orientation == GTK_ORIENTATION_VERTICAL &&
+ priv_child1_allocation.height < child1_allocation.height)))
+ {
+ gtk_paned_child_allocate (priv->child2,
+ priv->child2_window,
+ &window2_allocation,
+ &child2_allocation);
+ gtk_paned_child_allocate (priv->child1,
+ priv->child1_window,
+ &window1_allocation,
+ &child1_allocation);
+ }
+ else
+ {
+ gtk_paned_child_allocate (priv->child1,
+ priv->child1_window,
+ &window1_allocation,
+ &child1_allocation);
+ gtk_paned_child_allocate (priv->child2,
+ priv->child2_window,
+ &window2_allocation,
+ &child2_allocation);
+ }
+ }
+ else
+ {
+ GtkAllocation window_allocation, child_allocation;
+
+ if (gtk_widget_get_realized (widget))
+ gdk_window_hide (priv->handle);
+
+ window_allocation.x = allocation->x;
+ window_allocation.y = allocation->y;
+ window_allocation.width = allocation->width;
+ window_allocation.height = allocation->height;
+ child_allocation.x = child_allocation.y = 0;
+ child_allocation.width = allocation->width;
+ child_allocation.height = allocation->height;
+
+ if (priv->child1 && gtk_widget_get_visible (priv->child1))
+ {
+ gtk_paned_set_child_visible (paned, 0, TRUE);
+ if (priv->child2)
+ gtk_paned_set_child_visible (paned, 1, FALSE);
+
+ gtk_paned_child_allocate (priv->child1,
+ priv->child1_window,
+ &window_allocation,
+ &child_allocation);
+ }
+ else if (priv->child2 && gtk_widget_get_visible (priv->child2))
+ {
+ gtk_paned_set_child_visible (paned, 1, TRUE);
+ if (priv->child1)
+ gtk_paned_set_child_visible (paned, 0, FALSE);
+
+ gtk_paned_child_allocate (priv->child2,
+ priv->child2_window,
+ &window_allocation,
+ &child_allocation);
+ }
+ else
+ {
+ if (priv->child1)
+ gtk_paned_set_child_visible (paned, 0, FALSE);
+ if (priv->child2)
+ gtk_paned_set_child_visible (paned, 1, FALSE);
+ }
+ }
+}
+
+static GdkWindow *
+gtk_paned_create_child_window (GtkPaned *paned,
+ GtkWidget *child) /* may be NULL */
+{
+ GtkWidget *widget = GTK_WIDGET (paned);
+ GtkPanedPrivate *priv = paned->priv;
+ GdkWindow *window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+ if (child)
+ {
+ GtkAllocation allocation;
+ int handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ child == priv->child2 && priv->child1 &&
+ gtk_widget_get_visible (priv->child1))
+ attributes.x = priv->handle_pos.x + handle_size;
+ else
+ attributes.x = allocation.x;
+ if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
+ child == priv->child2 && priv->child1 &&
+ gtk_widget_get_visible (priv->child1))
+ attributes.y = priv->handle_pos.y + handle_size;
+ else
+ attributes.y = allocation.y;
+
+ gtk_widget_get_allocation (child, &allocation);
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
+ }
+ else
+ {
+ attributes.width = 1;
+ attributes.height = 1;
+ attributes_mask = 0;
+ }
+
+ window = gdk_window_new (gtk_widget_get_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_register_window (widget, window);
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
+
+ if (child)
+ gtk_widget_set_parent_window (child, window);
+
+ return window;
+}
+