Re: Patch to GtkPaned.
- From: Mikael Hermansson <mikeh bahnhof se>
- To: Christopher James Lahey <clahey helixcode com>
- Cc: gtk-devel-list gtk org
- Subject: Re: Patch to GtkPaned.
- Date: Wed, 14 Feb 2001 03:36:28 +0100
Sound very good :-)
On tis, 13 feb 2001 09:28:33 Christopher James Lahey wrote:
> This patch adds two things to GtkPaned. Firstly, it handles hiding
> either
> of the subwidgets well. If you hide one of the children, it gives all
> the
> space to the other child and also hides the handle.
>
> Secondly, it adds a Gtk Argument "quantum". This is an int which is the
> preferred size of changes for the position of the divider. For instance,
> this is used in evolution's calendar so that the mini calendar will
> always
> be approximately a multiple of the size that makes it look best.
>
> It also adds to the panes test in gtktest the ability to hide either of
> the children of either GtkPaned.
>
> I'd like to commit this to Gtk+ HEAD. If there's any problems with this,
> please let me know. Also let me know if you approve this patch. I'm not
> on the list so I would need to be mailed directly.
>
> Thanks,
> Chris
>
> ? gtkpaned.diff
> Index: gtkhpaned.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkhpaned.c,v
> retrieving revision 1.27
> diff -u -r1.27 gtkhpaned.c
> --- gtkhpaned.c 2000/12/04 23:04:14 1.27
> +++ gtkhpaned.c 2001/02/13 08:19:20
> @@ -18,7 +18,7 @@
> */
>
> /*
> - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
> + * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
> * file for a list of people on the GTK+ Team. See the ChangeLog
> * files for a list of changes. These files are distributed with
> * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
> @@ -26,7 +26,7 @@
>
> #include "gtkhpaned.h"
>
> -static void gtk_hpaned_class_init (GtkHPanedClass *klass);
> +static void gtk_hpaned_class_init (GtkHPanedClass *class);
> static void gtk_hpaned_init (GtkHPaned *hpaned);
> static void gtk_hpaned_size_request (GtkWidget *widget,
> GtkRequisition *requisition);
> @@ -41,6 +41,7 @@
> GdkEventButton *event);
> static gboolean gtk_hpaned_motion (GtkWidget *widget,
> GdkEventMotion *event);
> +static gboolean gtk_hpaned_handle_shown (GtkPaned *paned);
>
> static gpointer parent_class;
>
> @@ -73,10 +74,12 @@
> gtk_hpaned_class_init (GtkHPanedClass *class)
> {
> GtkWidgetClass *widget_class;
> + GtkPanedClass *paned_class;
>
> parent_class = gtk_type_class (GTK_TYPE_PANED);
>
> widget_class = (GtkWidgetClass *) class;
> + paned_class = (GtkPanedClass *) class;
>
> widget_class->size_request = gtk_hpaned_size_request;
> widget_class->size_allocate = gtk_hpaned_size_allocate;
> @@ -84,6 +87,8 @@
> widget_class->button_press_event = gtk_hpaned_button_press;
> widget_class->button_release_event = gtk_hpaned_button_release;
> widget_class->motion_notify_event = gtk_hpaned_motion;
> +
> + paned_class->handle_shown = gtk_hpaned_handle_shown;
> }
>
> static void
> @@ -99,6 +104,14 @@
> paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
> }
>
> +/**
> + * gtk_hpaned_new:
> + *
> + * Creates a new horizontal paned widget. This lets you have 2 panes
> + * that the user can resize.
> + *
> + * Returns: The GtkHPaned.
> + */
> GtkWidget *
> gtk_hpaned_new (void)
> {
> @@ -140,8 +153,10 @@
> requisition->width += child_requisition.width;
> }
>
> - requisition->width += GTK_CONTAINER (paned)->border_width * 2 +
> paned->handle_size;
> + requisition->width += GTK_CONTAINER (paned)->border_width * 2;
> requisition->height += GTK_CONTAINER (paned)->border_width * 2;
> + if (gtk_paned_handle_shown(paned))
> + requisition->width += paned->handle_size;
> }
>
> static void
> @@ -154,6 +169,7 @@
> GtkAllocation child1_allocation;
> GtkAllocation child2_allocation;
> gint border_width;
> + gboolean handle_shown;
>
> g_return_if_fail (widget != NULL);
> g_return_if_fail (GTK_IS_HPANED (widget));
> @@ -163,29 +179,48 @@
> paned = GTK_PANED (widget);
> border_width = GTK_CONTAINER (paned)->border_width;
>
> - if (paned->child1)
> + if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
> gtk_widget_get_child_requisition (paned->child1,
> &child1_requisition);
> else
> child1_requisition.width = 0;
>
> - if (paned->child2)
> + if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
> gtk_widget_get_child_requisition (paned->child2,
> &child2_requisition);
> else
> child2_requisition.width = 0;
>
> gtk_paned_compute_position (paned,
> MAX (1, (gint) widget->allocation.width
> - - (gint) paned->handle_size
> - 2 * border_width),
> child1_requisition.width,
> child2_requisition.width);
>
> /* Move the handle before the children so we don't get extra expose
> events */
>
> - paned->handle_xpos = paned->child1_size + border_width;
> - paned->handle_ypos = border_width;
> - paned->handle_width = paned->handle_size;
> - paned->handle_height = MAX (1, (gint) widget->allocation.height - 2 *
> border_width);
> + handle_shown = gtk_paned_handle_shown(paned);
> + if (handle_shown)
> + {
> + paned->handle_xpos = paned->child1_real_size + border_width;
> + paned->handle_ypos = border_width;
> + paned->handle_width = paned->handle_size;
> + paned->handle_height = MAX (1, (gint) widget->allocation.height -
> 2 * border_width);
> +
> + if (GTK_WIDGET_REALIZED (widget))
> + {
> + gdk_window_move_resize (paned->handle,
> + paned->handle_xpos,
> + paned->handle_ypos,
> + paned->handle_size,
> + paned->handle_height);
> + if (paned->handle)
> + gdk_window_show(paned->handle);
> + }
> + }
> + else
> + {
> + if (paned->handle && GTK_WIDGET_REALIZED (widget))
> + gdk_window_hide(paned->handle);
> + }
>
> if (GTK_WIDGET_REALIZED (widget))
> {
> @@ -193,20 +228,19 @@
> allocation->x, allocation->y,
> allocation->width,
> allocation->height);
> -
> - gdk_window_move_resize (paned->handle,
> - paned->handle_xpos,
> - paned->handle_ypos,
> - paned->handle_size,
> - paned->handle_height);
> }
>
> child1_allocation.height = child2_allocation.height = MAX (1, (gint)
> allocation->height - border_width * 2);
> - child1_allocation.width = paned->child1_size;
> + child1_allocation.width = MAX (1, paned->child1_real_size);
> child1_allocation.x = border_width;
> child1_allocation.y = child2_allocation.y = border_width;
>
> - child2_allocation.x = child1_allocation.x + child1_allocation.width +
> paned->handle_width;
> + if (handle_shown)
> + child2_allocation.x = (child1_allocation.x + (int)
> child1_allocation.width +
> + (int) paned->handle_width);
> + else
> + child2_allocation.x = child1_allocation.x + (int)
> child1_allocation.width;
> +
> child2_allocation.width = MAX (1, (gint) allocation->width -
> child2_allocation.x - border_width);
>
> /* Now allocate the childen, making sure, when resizing not to
> @@ -291,7 +325,7 @@
> gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID,
> GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL);
>
> - xpos = paned->child1_size
> + xpos = paned->child1_real_size
> + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2;
>
> gdk_draw_line (widget->window, paned->xor_gc,
> @@ -315,6 +349,7 @@
> if (!paned->in_drag &&
> event->window == paned->handle && event->button == 1)
> {
> + paned->old_child1_size = paned->child1_size;
> paned->in_drag = TRUE;
> /* We need a server grab here, not gtk_grab_add(), since
> * we don't want to pass events on to the widget's children */
> @@ -323,11 +358,12 @@
> | GDK_BUTTON1_MOTION_MASK
> | GDK_BUTTON_RELEASE_MASK,
> NULL, NULL, event->time);
> - paned->child1_size += event->x - paned->handle_size / 2;
> + paned->child1_size = gtk_paned_quantized_size(paned,
> paned->child1_size + event->x - paned->handle_size / 2);
> paned->child1_size = CLAMP (paned->child1_size, 0,
> widget->allocation.width
> - paned->handle_size
> - 2 * GTK_CONTAINER (paned)->border_width);
> + paned->child1_real_size = paned->child1_size;
> gtk_hpaned_xor_line (paned);
>
> return TRUE;
> @@ -380,12 +416,30 @@
>
> if (paned->in_drag)
> {
> - gint size = x - GTK_CONTAINER (paned)->border_width -
> paned->handle_size / 2;
> + gint size;
> + gint new_child1_size;
> +
> + size = x - GTK_CONTAINER (paned)->border_width -
> paned->handle_size / 2;
> +
> + new_child1_size = CLAMP (gtk_paned_quantized_size(paned, size),
> + paned->min_position,
> + paned->max_position);
>
> + if (new_child1_size == paned->child1_size)
> + return TRUE;
> +
> gtk_hpaned_xor_line (paned);
> - paned->child1_size = CLAMP (size, paned->min_position,
> paned->max_position);
> + paned->child1_size = new_child1_size;
> + paned->child1_real_size = paned->child1_size;
> gtk_hpaned_xor_line (paned);
> }
>
> return TRUE;
> +}
> +
> +static gboolean
> +gtk_hpaned_handle_shown (GtkPaned *paned)
> +{
> + return ((paned->child1 && paned->child2) &&
> + (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE
> (paned->child2)));
> }
> Index: gtkpaned.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkpaned.c,v
> retrieving revision 1.31
> diff -u -r1.31 gtkpaned.c
> --- gtkpaned.c 2001/02/03 01:09:40 1.31
> +++ gtkpaned.c 2001/02/13 08:19:20
> @@ -28,10 +28,11 @@
>
> enum {
> ARG_0,
> - ARG_HANDLE_SIZE
> + ARG_HANDLE_SIZE,
> + ARG_QUANTUM,
> };
>
> -static void gtk_paned_class_init (GtkPanedClass *klass);
> +static void gtk_paned_class_init (GtkPanedClass *class);
> static void gtk_paned_init (GtkPaned *paned);
> static void gtk_paned_set_arg (GtkObject *object,
> GtkArg *arg,
> @@ -110,8 +111,12 @@
> container_class->forall = gtk_paned_forall;
> container_class->child_type = gtk_paned_child_type;
>
> + class->handle_shown = NULL;
> +
> gtk_object_add_arg_type("GtkPaned::handle_size", GTK_TYPE_UINT,
> GTK_ARG_READWRITE, ARG_HANDLE_SIZE);
> + gtk_object_add_arg_type("GtkPaned::quantum", GTK_TYPE_UINT,
> + GTK_ARG_READWRITE, ARG_QUANTUM);
> }
>
> static GtkType
> @@ -143,6 +148,10 @@
>
> paned->handle_xpos = -1;
> paned->handle_ypos = -1;
> +
> + paned->old_child1_size = 0;
> + paned->child1_size = 0;
> + paned->quantum = 1;
> }
>
> static void
> @@ -157,6 +166,11 @@
> case ARG_HANDLE_SIZE:
> gtk_paned_set_handle_size (paned, GTK_VALUE_UINT (*arg));
> break;
> + case ARG_QUANTUM:
> + paned->quantum = GTK_VALUE_UINT (*arg);
> + if (paned->quantum == 0)
> + paned->quantum = 1;
> + break;
> default:
> break;
> }
> @@ -174,6 +188,9 @@
> case ARG_HANDLE_SIZE:
> GTK_VALUE_UINT (*arg) = paned->handle_size;
> break;
> + case ARG_QUANTUM:
> + GTK_VALUE_UINT (*arg) = paned->quantum;
> + break;
> default:
> arg->type = GTK_TYPE_INVALID;
> break;
> @@ -231,7 +248,8 @@
>
> gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
>
> - gdk_window_show (paned->handle);
> + if (gtk_paned_handle_shown(paned))
> + gdk_window_show (paned->handle);
> }
>
> static void
> @@ -312,10 +330,19 @@
> {
> paned = GTK_PANED (widget);
>
> - if (event->window != paned->handle)
> + if (paned->handle && event->window == paned->handle)
> {
> + if (gtk_paned_handle_shown(paned))
> + {
> + child_event = *event;
> + event->area.x += paned->handle_xpos;
> + event->area.y += paned->handle_ypos;
> + gtk_widget_draw (widget, &event->area);
> + }
> + }
> + else
> + {
> child_event = *event;
> -
> if (paned->child1 &&
> GTK_WIDGET_NO_WINDOW (paned->child1) &&
> gtk_widget_intersect (paned->child1, &event->area,
> &child_event.area))
> @@ -494,7 +521,7 @@
> g_return_val_if_fail (paned != NULL, 0);
> g_return_val_if_fail (GTK_IS_PANED (paned), 0);
>
> - return paned->child1_size;
> + return paned->child1_real_size;
> }
>
> /**
> @@ -550,6 +577,9 @@
> {
> g_return_if_fail (paned != NULL);
> g_return_if_fail (GTK_IS_PANED (paned));
> +
> + if (gtk_paned_handle_shown(paned))
> + allocation -= (gint) paned->handle_size;
>
> paned->min_position = paned->child1_shrink ? 0 : child1_req;
>
> @@ -577,14 +607,38 @@
> {
> if (paned->child1_resize && !paned->child2_resize)
> paned->child1_size += allocation - paned->last_allocation;
> - else if (!(!paned->child1_resize && paned->child2_resize))
> + else if (paned->child1_resize && paned->child2_resize)
> paned->child1_size = allocation * ((gdouble)
> paned->child1_size / (paned->last_allocation));
> }
> }
>
> - paned->child1_size = CLAMP (paned->child1_size,
> - paned->min_position,
> - paned->max_position);
> + paned->child1_real_size = CLAMP (paned->child1_size,
> + paned->min_position,
> + paned->max_position);
>
> paned->last_allocation = allocation;
> +}
> +
> +gboolean
> +gtk_paned_handle_shown(GtkPaned *paned)
> +{
> + GtkPanedClass *class = GTK_PANED_CLASS(G_OBJECT_GET_CLASS(paned));
> + if (class->handle_shown)
> + return (*class->handle_shown)(paned);
> + else
> + return TRUE;
> +}
> +
> +gint
> +gtk_paned_quantized_size(GtkPaned *paned,
> + gint size)
> +{
> + gint quantization = size - paned->old_child1_size;
> + if (quantization > 0)
> + quantization += paned->quantum / 2;
> + else
> + quantization -= paned->quantum / 2;
> + quantization /= paned->quantum;
> + quantization *= paned->quantum;
> + return paned->old_child1_size + quantization;
> }
> Index: gtkpaned.h
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkpaned.h,v
> retrieving revision 1.15
> diff -u -r1.15 gtkpaned.h
> --- gtkpaned.h 2000/08/30 00:33:38 1.15
> +++ gtkpaned.h 2001/02/13 08:19:20
> @@ -1,4 +1,3 @@
> -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
> */
> /* GTK - The GIMP Toolkit
> * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh
> MacDonald
> *
> @@ -64,11 +63,15 @@
> guint16 handle_width;
> guint16 handle_height;
>
> + gint child1_real_size;
> gint child1_size;
> gint last_allocation;
> gint min_position;
> gint max_position;
>
> + gint old_child1_size;
> + gint quantum;
> +
> guint position_set : 1;
> guint in_drag : 1;
> guint child1_shrink : 1;
> @@ -83,6 +86,9 @@
> struct _GtkPanedClass
> {
> GtkContainerClass parent_class;
> +
> + /* Protected virtual method. */
> + gboolean (*handle_shown) (GtkPaned *paned);
> };
>
>
> @@ -110,6 +116,9 @@
> gint allocation,
> gint child1_req,
> gint child2_req);
> +int gtk_paned_handle_shown (GtkPaned *paned);
> +gint gtk_paned_quantized_size (GtkPaned *paned,
> + int size);
> #ifdef __cplusplus
> }
> #endif /* __cplusplus */
> Index: gtkvpaned.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkvpaned.c,v
> retrieving revision 1.29
> diff -u -r1.29 gtkvpaned.c
> --- gtkvpaned.c 2000/12/04 23:04:17 1.29
> +++ gtkvpaned.c 2001/02/13 08:19:20
> @@ -18,7 +18,7 @@
> */
>
> /*
> - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
> + * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
> * file for a list of people on the GTK+ Team. See the ChangeLog
> * files for a list of changes. These files are distributed with
> * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
> @@ -26,7 +26,7 @@
>
> #include "gtkvpaned.h"
>
> -static void gtk_vpaned_class_init (GtkVPanedClass *klass);
> +static void gtk_vpaned_class_init (GtkVPanedClass *class);
> static void gtk_vpaned_init (GtkVPaned *vpaned);
> static void gtk_vpaned_size_request (GtkWidget *widget,
> GtkRequisition *requisition);
> @@ -41,6 +41,7 @@
> GdkEventButton *event);
> static gboolean gtk_vpaned_motion (GtkWidget *widget,
> GdkEventMotion *event);
> +static gboolean gtk_vpaned_handle_shown (GtkPaned *paned);
>
> static gpointer parent_class;
>
> @@ -73,10 +74,12 @@
> gtk_vpaned_class_init (GtkVPanedClass *class)
> {
> GtkWidgetClass *widget_class;
> + GtkPanedClass *paned_class;
>
> parent_class = gtk_type_class (GTK_TYPE_PANED);
>
> widget_class = (GtkWidgetClass *) class;
> + paned_class = GTK_PANED_CLASS (class);
>
> widget_class->size_request = gtk_vpaned_size_request;
> widget_class->size_allocate = gtk_vpaned_size_allocate;
> @@ -84,6 +87,8 @@
> widget_class->button_press_event = gtk_vpaned_button_press;
> widget_class->button_release_event = gtk_vpaned_button_release;
> widget_class->motion_notify_event = gtk_vpaned_motion;
> +
> + paned_class->handle_shown = gtk_vpaned_handle_shown;
> }
>
> static void
> @@ -99,6 +104,14 @@
> paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
> }
>
> +/**
> + * gtk_vpaned_new:
> + *
> + * Creates a new vertical paned widget. This lets you have 2 panes
> + * that the user can resize.
> + *
> + * Returns: The GtkVPaned.
> + */
> GtkWidget *
> gtk_vpaned_new (void)
> {
> @@ -140,8 +153,10 @@
> requisition->height += child_requisition.height;
> }
>
> - requisition->height += GTK_CONTAINER (paned)->border_width * 2 +
> paned->handle_size;
> + requisition->height += GTK_CONTAINER (paned)->border_width * 2;
> requisition->width += GTK_CONTAINER (paned)->border_width * 2;
> + if (gtk_paned_handle_shown(paned))
> + requisition->height += paned->handle_size;
> }
>
> static void
> @@ -154,6 +169,7 @@
> GtkAllocation child1_allocation;
> GtkAllocation child2_allocation;
> gint border_width;
> + gboolean handle_shown;
>
> g_return_if_fail (widget != NULL);
> g_return_if_fail (GTK_IS_VPANED (widget));
> @@ -163,29 +179,48 @@
> paned = GTK_PANED (widget);
> border_width = GTK_CONTAINER (widget)->border_width;
>
> - if (paned->child1)
> + if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
> gtk_widget_get_child_requisition (paned->child1,
> &child1_requisition);
> else
> child1_requisition.height = 0;
>
> - if (paned->child2)
> + if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
> gtk_widget_get_child_requisition (paned->child2,
> &child2_requisition);
> else
> child2_requisition.height = 0;
>
> gtk_paned_compute_position (paned,
> MAX (1, (gint) widget->allocation.height
> - - (gint) paned->handle_size
> - 2 * border_width),
> child1_requisition.height,
> child2_requisition.height);
>
> /* Move the handle before the children so we don't get extra expose
> events */
>
> - paned->handle_xpos = border_width;
> - paned->handle_ypos = paned->child1_size + border_width;
> - paned->handle_width = MAX (1, (gint) widget->allocation.width - 2 *
> border_width);
> - paned->handle_height = paned->handle_size;
> + handle_shown = gtk_paned_handle_shown(paned);
> + if (handle_shown)
> + {
> + paned->handle_xpos = border_width;
> + paned->handle_ypos = paned->child1_real_size + border_width;
> + paned->handle_width = MAX (1, (gint) widget->allocation.width - 2
> * border_width);
> + paned->handle_height = paned->handle_size;
> +
> + if (GTK_WIDGET_REALIZED (widget))
> + {
> + gdk_window_move_resize (paned->handle,
> + paned->handle_xpos,
> + paned->handle_ypos,
> + paned->handle_width,
> + paned->handle_size);
> + if (paned->handle)
> + gdk_window_show(paned->handle);
> + }
> + }
> + else
> + {
> + if (paned->handle && GTK_WIDGET_REALIZED (widget))
> + gdk_window_hide(paned->handle);
> + }
>
> if (GTK_WIDGET_REALIZED(widget))
> {
> @@ -193,20 +228,19 @@
> allocation->x, allocation->y,
> allocation->width,
> allocation->height);
> -
> - gdk_window_move_resize (paned->handle,
> - paned->handle_xpos,
> - paned->handle_ypos,
> - paned->handle_width,
> - paned->handle_size);
> }
>
> child1_allocation.width = child2_allocation.width = MAX (1, (gint)
> allocation->width - border_width * 2);
> - child1_allocation.height = paned->child1_size;
> + child1_allocation.height = MAX (1, (int) paned->child1_real_size);
> child1_allocation.x = child2_allocation.x = border_width;
> child1_allocation.y = border_width;
> +
> + if (handle_shown)
> + child2_allocation.y = (child1_allocation.y + (int)
> child1_allocation.height +
> + (int) paned->handle_height);
> + else
> + child2_allocation.y = child1_allocation.y + (int)
> child1_allocation.height;
>
> - child2_allocation.y = child1_allocation.y + child1_allocation.height +
> paned->handle_height;
> child2_allocation.height = MAX(1, (gint) allocation->height -
> child2_allocation.y - border_width);
>
> /* Now allocate the childen, making sure, when resizing not to
> @@ -293,7 +327,7 @@
> gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID,
> GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL);
>
> - ypos = paned->child1_size
> + ypos = paned->child1_real_size
> + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2;
>
> gdk_draw_line (widget->window, paned->xor_gc,
> @@ -317,6 +351,7 @@
> if (!paned->in_drag &&
> (event->window == paned->handle) && (event->button == 1))
> {
> + paned->old_child1_size = paned->child1_size;
> paned->in_drag = TRUE;
> /* We need a server grab here, not gtk_grab_add(), since
> * we don't want to pass events on to the widget's children */
> @@ -325,11 +360,12 @@
> | GDK_BUTTON1_MOTION_MASK
> | GDK_BUTTON_RELEASE_MASK, NULL, NULL,
> event->time);
> - paned->child1_size += event->y - paned->handle_size / 2;
> + paned->child1_size = gtk_paned_quantized_size(paned,
> paned->child1_size + event->y - paned->handle_size / 2);
> paned->child1_size = CLAMP (paned->child1_size, 0,
> widget->allocation.height -
> paned->handle_size -
> 2 * GTK_CONTAINER (paned)->border_width);
> + paned->child1_real_size = paned->child1_size;
> gtk_vpaned_xor_line(paned);
>
> return TRUE;
> @@ -382,12 +418,30 @@
>
> if (paned->in_drag)
> {
> - gint size = y - GTK_CONTAINER(paned)->border_width -
> paned->handle_size / 2;
> + gint size;
> + gint new_child1_size;
> +
> + size = y - GTK_CONTAINER(paned)->border_width - paned->handle_size
> / 2;
> +
> + new_child1_size = CLAMP (gtk_paned_quantized_size(paned, size),
> + paned->min_position,
> + paned->max_position);
>
> + if (new_child1_size == paned->child1_size)
> + return TRUE;
> +
> gtk_vpaned_xor_line (paned);
> - paned->child1_size = CLAMP (size, paned->min_position,
> paned->max_position);
> + paned->child1_size = new_child1_size;
> + paned->child1_real_size = paned->child1_size;
> gtk_vpaned_xor_line(paned);
> }
>
> return TRUE;
> +}
> +
> +static gboolean
> +gtk_vpaned_handle_shown (GtkPaned *paned)
> +{
> + return ((paned->child1 && paned->child2) &&
> + (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE
> (paned->child2)));
> }
> Index: testgtk.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/testgtk.c,v
> retrieving revision 1.216
> diff -u -r1.216 testgtk.c
> --- testgtk.c 2001/02/09 00:40:48 1.216
> +++ testgtk.c 2001/02/13 08:19:20
> @@ -6936,6 +6936,15 @@
> gtk_widget_unref (child);
> }
>
> +void
> +toggle_shown (GtkWidget *widget, GtkWidget *child)
> +{
> + if (GTK_WIDGET_VISIBLE(child))
> + gtk_widget_hide(child);
> + else
> + gtk_widget_show(child);
> +}
> +
> GtkWidget *
> create_pane_options (GtkPaned *paned,
> const gchar *frame_label,
> @@ -6950,7 +6959,7 @@
> frame = gtk_frame_new (frame_label);
> gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
>
> - table = gtk_table_new (3, 2, 4);
> + table = gtk_table_new (4, 2, TRUE);
> gtk_container_add (GTK_CONTAINER (frame), table);
>
> label = gtk_label_new (label1);
> @@ -6972,6 +6981,15 @@
> gtk_signal_connect (GTK_OBJECT (check_button), "toggled",
> GTK_SIGNAL_FUNC (toggle_shrink),
> paned->child1);
> +
> + check_button = gtk_check_button_new_with_label ("Shown");
> + gtk_table_attach_defaults (GTK_TABLE (table), check_button,
> + 0, 1, 3, 4);
> + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
> + TRUE);
> + gtk_signal_connect (GTK_OBJECT (check_button), "toggled",
> + GTK_SIGNAL_FUNC (toggle_shown),
> + paned->child1);
>
> label = gtk_label_new (label2);
> gtk_table_attach_defaults (GTK_TABLE (table), label,
> @@ -6993,6 +7011,15 @@
> TRUE);
> gtk_signal_connect (GTK_OBJECT (check_button), "toggled",
> GTK_SIGNAL_FUNC (toggle_shrink),
> + paned->child2);
> +
> + check_button = gtk_check_button_new_with_label ("Shown");
> + gtk_table_attach_defaults (GTK_TABLE (table), check_button,
> + 1, 2, 3, 4);
> + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
> + TRUE);
> + gtk_signal_connect (GTK_OBJECT (check_button), "toggled",
> + GTK_SIGNAL_FUNC (toggle_shown),
> paned->child2);
>
> return frame;
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]