Add patch from Jonathan Blandford and Anders Carlsson to change the Paned

Thu Feb 17 17:10:12 2000  Owen Taylor  <otaylor@redhat.com>

	* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
	and Anders Carlsson to change the Paned widgets so that they
	can be dragged from anywhere along the length. Also change
	the way that this is drawn to make this apparent.

	* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
	from George Lebl to check that option_menu->menu is present
	before getting history.
This commit is contained in:
Owen Taylor 2000-02-17 22:12:25 +00:00 committed by Owen Taylor
parent d0f73034cf
commit ab1deac87f
15 changed files with 572 additions and 458 deletions

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -1,3 +1,14 @@
Thu Feb 17 17:10:12 2000 Owen Taylor <otaylor@redhat.com>
* gtk/gt{h,k,}vpaned.[ch]: Add patch from Jonathan Blandford
and Anders Carlsson to change the Paned widgets so that they
can be dragged from anywhere along the length. Also change
the way that this is drawn to make this apparent.
* gtk/gtkoptionmenu.c (gtk_option_menu_get_history): Apply patch
from George Lebl to check that option_menu->menu is present
before getting history.
2000-02-14 Tor Lillqvist <tml@iki.fi> 2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments * gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments

View File

@ -9,3 +9,7 @@ Incompatible Changes from GTK+-1.2 to GTK+-1.4:
match what we do for glib, and other similar cases. match what we do for glib, and other similar cases.
- The detail arguments in the GtkStyleClass structure are now 'const gchar *'. - The detail arguments in the GtkStyleClass structure are now 'const gchar *'.
- gtk_paned_set_gutter_size() has been removed, since the small handle tab
has been changed to include the entire area previously occupied by
the gutter.

View File

@ -1,3 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* GTK - The GIMP Toolkit /* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* *
@ -25,24 +26,22 @@
*/ */
#include "gtkhpaned.h" #include "gtkhpaned.h"
#include "gtkmain.h"
#include "gtksignal.h"
static void gtk_hpaned_class_init (GtkHPanedClass *klass); static void gtk_hpaned_class_init (GtkHPanedClass *klass);
static void gtk_hpaned_init (GtkHPaned *hpaned); static void gtk_hpaned_init (GtkHPaned *hpaned);
static void gtk_hpaned_size_request (GtkWidget *widget, static void gtk_hpaned_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_hpaned_size_allocate (GtkWidget *widget, static void gtk_hpaned_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static void gtk_hpaned_draw (GtkWidget *widget, static void gtk_hpaned_draw (GtkWidget *widget,
GdkRectangle *area); GdkRectangle *area);
static void gtk_hpaned_xor_line (GtkPaned *paned); static void gtk_hpaned_xor_line (GtkPaned *paned);
static gint gtk_hpaned_button_press (GtkWidget *widget, static gboolean gtk_hpaned_button_press (GtkWidget *widget,
GdkEventButton *event); GdkEventButton *event);
static gint gtk_hpaned_button_release (GtkWidget *widget, static gboolean gtk_hpaned_button_release (GtkWidget *widget,
GdkEventButton *event); GdkEventButton *event);
static gint gtk_hpaned_motion (GtkWidget *widget, static gboolean gtk_hpaned_motion (GtkWidget *widget,
GdkEventMotion *event); GdkEventMotion *event);
GtkType GtkType
gtk_hpaned_get_type (void) gtk_hpaned_get_type (void)
@ -59,8 +58,8 @@ gtk_hpaned_get_type (void)
(GtkClassInitFunc) gtk_hpaned_class_init, (GtkClassInitFunc) gtk_hpaned_class_init,
(GtkObjectInitFunc) gtk_hpaned_init, (GtkObjectInitFunc) gtk_hpaned_init,
/* reserved_1 */ NULL, /* reserved_1 */ NULL,
/* reserved_2 */ NULL, /* reserved_2 */ NULL,
(GtkClassInitFunc) NULL, (GtkClassInitFunc) NULL,
}; };
hpaned_type = gtk_type_unique (GTK_TYPE_PANED, &hpaned_info); hpaned_type = gtk_type_unique (GTK_TYPE_PANED, &hpaned_info);
@ -74,7 +73,7 @@ gtk_hpaned_class_init (GtkHPanedClass *class)
{ {
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class;
widget_class = (GtkWidgetClass*) class; widget_class = (GtkWidgetClass *) class;
widget_class->size_request = gtk_hpaned_size_request; widget_class->size_request = gtk_hpaned_size_request;
widget_class->size_allocate = gtk_hpaned_size_allocate; widget_class->size_allocate = gtk_hpaned_size_allocate;
@ -87,9 +86,17 @@ gtk_hpaned_class_init (GtkHPanedClass *class)
static void static void
gtk_hpaned_init (GtkHPaned *hpaned) gtk_hpaned_init (GtkHPaned *hpaned)
{ {
GtkPaned *paned;
g_return_if_fail (hpaned != NULL);
g_return_if_fail (GTK_IS_PANED (hpaned));
paned = GTK_PANED (hpaned);
paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
} }
GtkWidget* GtkWidget *
gtk_hpaned_new (void) gtk_hpaned_new (void)
{ {
GtkHPaned *hpaned; GtkHPaned *hpaned;
@ -130,7 +137,7 @@ gtk_hpaned_size_request (GtkWidget *widget,
requisition->width += child_requisition.width; requisition->width += child_requisition.width;
} }
requisition->width += GTK_CONTAINER (paned)->border_width * 2 + paned->gutter_size; requisition->width += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size;
requisition->height += GTK_CONTAINER (paned)->border_width * 2; requisition->height += GTK_CONTAINER (paned)->border_width * 2;
} }
@ -143,7 +150,6 @@ gtk_hpaned_size_allocate (GtkWidget *widget,
GtkRequisition child2_requisition; GtkRequisition child2_requisition;
GtkAllocation child1_allocation; GtkAllocation child1_allocation;
GtkAllocation child2_allocation; GtkAllocation child2_allocation;
GdkRectangle old_groove_rectangle;
guint16 border_width; guint16 border_width;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
@ -167,63 +173,43 @@ gtk_hpaned_size_allocate (GtkWidget *widget,
gtk_paned_compute_position (paned, gtk_paned_compute_position (paned,
widget->allocation.width widget->allocation.width
- paned->gutter_size - paned->handle_size
- 2 * border_width, - 2 * border_width,
child1_requisition.width, child1_requisition.width,
child2_requisition.width); child2_requisition.width);
/* Move the handle before the children so we don't get extra expose events */ /* Move the handle before the children so we don't get extra expose events */
paned->handle_xpos = paned->child1_size + border_width + paned->gutter_size / 2 - paned->handle_size / 2; paned->handle_xpos = paned->child1_size + border_width;
paned->handle_ypos = allocation->height - border_width - 2*paned->handle_size; paned->handle_ypos = 0;
paned->handle_width = paned->handle_size;
paned->handle_height = widget->allocation.height;
if (GTK_WIDGET_REALIZED (widget)) if (GTK_WIDGET_REALIZED (widget))
{ {
gdk_window_move_resize (widget->window, gdk_window_move_resize (widget->window,
allocation->x, allocation->y, allocation->x, allocation->y,
allocation->width, allocation->height); allocation->width,
allocation->height);
gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos); 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.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
child1_allocation.width = paned->child1_size; child1_allocation.width = paned->child1_size;
child1_allocation.x = border_width; child1_allocation.x = border_width;
child1_allocation.y = child2_allocation.y = border_width; child1_allocation.y = child2_allocation.y = border_width;
old_groove_rectangle = paned->groove_rectangle; child2_allocation.x = child1_allocation.x + child1_allocation.width + paned->handle_width;
child2_allocation.width = MAX (1, (gint) allocation->width - child2_allocation.x - border_width);
paned->groove_rectangle.x = child1_allocation.x
+ child1_allocation.width + paned->gutter_size / 2 - 1;
paned->groove_rectangle.y = 0;
paned->groove_rectangle.width = 2;
paned->groove_rectangle.height = allocation->height;
if (GTK_WIDGET_DRAWABLE (widget) &&
((paned->groove_rectangle.x != old_groove_rectangle.x) ||
(paned->groove_rectangle.y != old_groove_rectangle.y) ||
(paned->groove_rectangle.width != old_groove_rectangle.width) ||
(paned->groove_rectangle.height != old_groove_rectangle.height)))
{
gtk_widget_queue_clear_area (widget,
old_groove_rectangle.x,
old_groove_rectangle.y,
old_groove_rectangle.width,
old_groove_rectangle.height);
gtk_widget_queue_draw_area (widget,
paned->groove_rectangle.x,
paned->groove_rectangle.y,
paned->groove_rectangle.width,
paned->groove_rectangle.height);
}
child2_allocation.x = paned->groove_rectangle.x + paned->gutter_size / 2 + 1;
child2_allocation.width = MAX (1, (gint)allocation->width
- child2_allocation.x - border_width);
/* Now allocate the childen, making sure, when resizing not to /* Now allocate the childen, making sure, when resizing not to
* overlap the windows */ * overlap the windows */
if (GTK_WIDGET_MAPPED(widget) && if (GTK_WIDGET_MAPPED (widget) &&
paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
paned->child1->allocation.width < child1_allocation.width) paned->child1->allocation.width < child1_allocation.width)
{ {
@ -242,7 +228,7 @@ gtk_hpaned_size_allocate (GtkWidget *widget,
static void static void
gtk_hpaned_draw (GtkWidget *widget, gtk_hpaned_draw (GtkWidget *widget,
GdkRectangle *area) GdkRectangle *area)
{ {
GtkPaned *paned; GtkPaned *paned;
GdkRectangle handle_area, child_area; GdkRectangle handle_area, child_area;
@ -253,50 +239,95 @@ gtk_hpaned_draw (GtkWidget *widget,
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
{ {
gint width, height;
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
border_width = GTK_CONTAINER (paned)->border_width; border_width = GTK_CONTAINER (paned)->border_width;
gdk_window_clear_area (widget->window, gdk_window_clear_area (widget->window,
area->x, area->y, area->width, area->height); area->x, area->y, area->width,
area->height);
/* Redraw the handle
*/
gdk_window_get_size (paned->handle, &width, &height);
handle_area.x = paned->handle_xpos; handle_area.x = paned->handle_xpos;
handle_area.y = paned->handle_ypos; handle_area.y = paned->handle_ypos;
handle_area.width = width; handle_area.width = paned->handle_size;
handle_area.height = height; handle_area.height = paned->handle_height;
if (gdk_rectangle_intersect (&handle_area, area, &child_area)) if (gdk_rectangle_intersect (&handle_area, area, &child_area))
{ {
child_area.x -= handle_area.x; if (widget->allocation.height > 2)
child_area.y -= handle_area.y; {
gtk_paint_box (widget->style, paned->handle, gdk_draw_point (paned->handle,
GTK_WIDGET_STATE(widget), widget->style->fg_gc[GTK_STATE_NORMAL],
GTK_SHADOW_OUT, paned->handle_size/2,
&child_area, widget, "paned", paned->handle_height/2);
0, 0, gdk_draw_point (paned->handle,
width, height); widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 - 1);
}
if (widget->allocation.height > 11)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 + 5);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 + 4);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 - 5);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 - 6);
}
if (widget->allocation.height > 20)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 - 10);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 - 11);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 + 10);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 + 9);
}
if (widget->allocation.height > 30)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 - 15);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 - 16);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_size/2,
paned->handle_height/2 + 15);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_size/2 - 1,
paned->handle_height/2 + 14);
}
} }
/* Redraw the groove
*/
gtk_paint_vline(widget->style, widget->window, GTK_STATE_NORMAL,
area, widget, "hpaned",
0, widget->allocation.height - 1,
border_width + paned->child1_size + paned->gutter_size / 2 - 1);
/* Redraw the children /* Redraw the children
*/ */
if (paned->child1 && if (paned->child1 && gtk_widget_intersect (paned->child1, area, &child_area))
gtk_widget_intersect (paned->child1, area, &child_area)) gtk_widget_draw(paned->child1, &child_area);
gtk_widget_draw (paned->child1, &child_area); if (paned->child2 && gtk_widget_intersect(paned->child2, area, &child_area))
if (paned->child2 && gtk_widget_draw(paned->child2, &child_area);
gtk_widget_intersect (paned->child2, area, &child_area))
gtk_widget_draw (paned->child2, &child_area);
} }
} }
@ -315,12 +346,14 @@ gtk_hpaned_xor_line (GtkPaned *paned)
values.subwindow_mode = GDK_INCLUDE_INFERIORS; values.subwindow_mode = GDK_INCLUDE_INFERIORS;
paned->xor_gc = gdk_gc_new_with_values (widget->window, paned->xor_gc = gdk_gc_new_with_values (widget->window,
&values, &values,
GDK_GC_FUNCTION | GDK_GC_FUNCTION | GDK_GC_SUBWINDOW);
GDK_GC_SUBWINDOW);
} }
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_size
+ GTK_CONTAINER (paned)->border_width + paned->gutter_size / 2; + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2;
gdk_draw_line (widget->window, paned->xor_gc, gdk_draw_line (widget->window, paned->xor_gc,
xpos, xpos,
@ -329,44 +362,49 @@ gtk_hpaned_xor_line (GtkPaned *paned)
widget->allocation.height - 1); widget->allocation.height - 1);
} }
static gint static gboolean
gtk_hpaned_button_press (GtkWidget *widget, GdkEventButton *event) gtk_hpaned_button_press (GtkWidget *widget,
GdkEventButton *event)
{ {
GtkPaned *paned; GtkPaned *paned;
g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_PANED (widget),FALSE); g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
if (!paned->in_drag && if (!paned->in_drag &&
(event->window == paned->handle) && (event->button == 1)) event->window == paned->handle && event->button == 1)
{ {
paned->in_drag = TRUE; paned->in_drag = TRUE;
/* We need a server grab here, not gtk_grab_add(), since /* We need a server grab here, not gtk_grab_add(), since
* we don't want to pass events on to the widget's children */ * we don't want to pass events on to the widget's children */
gdk_pointer_grab (paned->handle, FALSE, gdk_pointer_grab(paned->handle, FALSE,
GDK_POINTER_MOTION_HINT_MASK GDK_POINTER_MOTION_HINT_MASK
| GDK_BUTTON1_MOTION_MASK | GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON_RELEASE_MASK, | GDK_BUTTON_RELEASE_MASK,
NULL, NULL, event->time); NULL, NULL, event->time);
paned->child1_size += event->x - paned->handle_size / 2; paned->child1_size += event->x - paned->handle_size / 2;
paned->child1_size = CLAMP (paned->child1_size, 0, paned->child1_size = CLAMP (paned->child1_size, 0,
widget->allocation.width - paned->gutter_size widget->allocation.width
- 2 * GTK_CONTAINER (paned)->border_width); - paned->handle_size
- 2 * GTK_CONTAINER (paned)->border_width);
gtk_hpaned_xor_line (paned); gtk_hpaned_xor_line (paned);
return TRUE;
} }
return TRUE; return FALSE;
} }
static gint static gboolean
gtk_hpaned_button_release (GtkWidget *widget, GdkEventButton *event) gtk_hpaned_button_release (GtkWidget *widget,
GdkEventButton *event)
{ {
GtkPaned *paned; GtkPaned *paned;
g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_PANED (widget),FALSE); g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
@ -377,13 +415,16 @@ gtk_hpaned_button_release (GtkWidget *widget, GdkEventButton *event)
paned->position_set = TRUE; paned->position_set = TRUE;
gdk_pointer_ungrab (event->time); gdk_pointer_ungrab (event->time);
gtk_widget_queue_resize (GTK_WIDGET (paned)); gtk_widget_queue_resize (GTK_WIDGET (paned));
return TRUE;
} }
return TRUE; return FALSE;
} }
static gint static gboolean
gtk_hpaned_motion (GtkWidget *widget, GdkEventMotion *event) gtk_hpaned_motion (GtkWidget *widget,
GdkEventMotion *event)
{ {
GtkPaned *paned; GtkPaned *paned;
gint x; gint x;
@ -400,12 +441,10 @@ gtk_hpaned_motion (GtkWidget *widget, GdkEventMotion *event)
if (paned->in_drag) if (paned->in_drag)
{ {
gint size = x - GTK_CONTAINER (paned)->border_width - paned->gutter_size/2; gint size = x - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2;
gtk_hpaned_xor_line (paned); gtk_hpaned_xor_line (paned);
paned->child1_size = CLAMP (size, paned->child1_size = CLAMP (size, paned->min_position, paned->max_position);
paned->min_position,
paned->max_position);
gtk_hpaned_xor_line (paned); gtk_hpaned_xor_line (paned);
} }

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog * file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with * files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
@ -27,16 +27,12 @@
#ifndef __GTK_HPANED_H__ #ifndef __GTK_HPANED_H__
#define __GTK_HPANED_H__ #define __GTK_HPANED_H__
#include <gdk/gdk.h>
#include <gtk/gtkpaned.h> #include <gtk/gtkpaned.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define GTK_TYPE_HPANED (gtk_hpaned_get_type ()) #define GTK_TYPE_HPANED (gtk_hpaned_get_type ())
#define GTK_HPANED(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HPANED, GtkHPaned)) #define GTK_HPANED(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HPANED, GtkHPaned))
#define GTK_HPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HPANED, GtkHPanedClass)) #define GTK_HPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HPANED, GtkHPanedClass))
@ -45,8 +41,8 @@ extern "C" {
#define GTK_HPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_HPANED, GtkHPanedClass)) #define GTK_HPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_HPANED, GtkHPanedClass))
typedef struct _GtkHPaned GtkHPaned; typedef struct _GtkHPaned GtkHPaned;
typedef struct _GtkHPanedClass GtkHPanedClass; typedef struct _GtkHPanedClass GtkHPanedClass;
struct _GtkHPaned struct _GtkHPaned
{ {
@ -58,14 +54,11 @@ struct _GtkHPanedClass
GtkPanedClass parent_class; GtkPanedClass parent_class;
}; };
GtkType gtk_hpaned_get_type (void); GtkType gtk_hpaned_get_type (void);
GtkWidget* gtk_hpaned_new (void); GtkWidget *gtk_hpaned_new (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __GTK_HPANED_H__ */ #endif /* __GTK_HPANED_H__ */

View File

@ -251,11 +251,16 @@ gtk_option_menu_get_history (GtkOptionMenu *option_menu)
g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu), -1); g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu), -1);
active_widget = gtk_menu_get_active (GTK_MENU (option_menu->menu)); if (option_menu->menu)
{
active_widget = gtk_menu_get_active (GTK_MENU (option_menu->menu));
if (active_widget) if (active_widget)
return g_list_index (GTK_MENU_SHELL (option_menu->menu)->children, return g_list_index (GTK_MENU_SHELL (option_menu->menu)->children,
active_widget); active_widget);
else
return -1;
}
else else
return -1; return -1;
} }

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog * file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with * files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
@ -28,34 +28,32 @@
enum { enum {
ARG_0, ARG_0,
ARG_HANDLE_SIZE, ARG_HANDLE_SIZE
ARG_GUTTER_SIZE
}; };
static void gtk_paned_class_init (GtkPanedClass *klass); static void gtk_paned_class_init (GtkPanedClass *klass);
static void gtk_paned_init (GtkPaned *paned); static void gtk_paned_init (GtkPaned *paned);
static void gtk_paned_set_arg (GtkObject *object, static void gtk_paned_set_arg (GtkObject *object,
GtkArg *arg, GtkArg *arg,
guint arg_id); guint arg_id);
static void gtk_paned_get_arg (GtkObject *object, static void gtk_paned_get_arg (GtkObject *object,
GtkArg *arg, GtkArg *arg,
guint arg_id); guint arg_id);
static void gtk_paned_realize (GtkWidget *widget); static void gtk_paned_realize (GtkWidget *widget);
static void gtk_paned_map (GtkWidget *widget); static void gtk_paned_map (GtkWidget *widget);
static void gtk_paned_unmap (GtkWidget *widget); static void gtk_paned_unmap (GtkWidget *widget);
static void gtk_paned_unrealize (GtkWidget *widget); static void gtk_paned_unrealize (GtkWidget *widget);
static gint gtk_paned_expose (GtkWidget *widget, static gint gtk_paned_expose (GtkWidget *widget,
GdkEventExpose *event); GdkEventExpose *event);
static void gtk_paned_add (GtkContainer *container, static void gtk_paned_add (GtkContainer *container,
GtkWidget *widget); GtkWidget *widget);
static void gtk_paned_remove (GtkContainer *container, static void gtk_paned_remove (GtkContainer *container,
GtkWidget *widget); GtkWidget *widget);
static void gtk_paned_forall (GtkContainer *container, static void gtk_paned_forall (GtkContainer *container,
gboolean include_internals, gboolean include_internals,
GtkCallback callback, GtkCallback callback,
gpointer callback_data); gpointer callback_data);
static GtkType gtk_paned_child_type (GtkContainer *container); static GtkType gtk_paned_child_type (GtkContainer *container);
static GtkContainerClass *parent_class = NULL; static GtkContainerClass *parent_class = NULL;
@ -76,7 +74,7 @@ gtk_paned_get_type (void)
(GtkObjectInitFunc) gtk_paned_init, (GtkObjectInitFunc) gtk_paned_init,
/* reserved_1 */ NULL, /* reserved_1 */ NULL,
/* reserved_2 */ NULL, /* reserved_2 */ NULL,
(GtkClassInitFunc) NULL, (GtkClassInitFunc) NULL,
}; };
paned_type = gtk_type_unique (GTK_TYPE_CONTAINER, &paned_info); paned_type = gtk_type_unique (GTK_TYPE_CONTAINER, &paned_info);
@ -92,9 +90,9 @@ gtk_paned_class_init (GtkPanedClass *class)
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class;
GtkContainerClass *container_class; GtkContainerClass *container_class;
object_class = (GtkObjectClass*) class; object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass*) class; widget_class = (GtkWidgetClass *) class;
container_class = (GtkContainerClass*) class; container_class = (GtkContainerClass *) class;
parent_class = gtk_type_class (GTK_TYPE_CONTAINER); parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
@ -112,10 +110,8 @@ gtk_paned_class_init (GtkPanedClass *class)
container_class->forall = gtk_paned_forall; container_class->forall = gtk_paned_forall;
container_class->child_type = gtk_paned_child_type; container_class->child_type = gtk_paned_child_type;
gtk_object_add_arg_type ("GtkPaned::handle_size", GTK_TYPE_UINT, gtk_object_add_arg_type("GtkPaned::handle_size", GTK_TYPE_UINT,
GTK_ARG_READWRITE, ARG_HANDLE_SIZE); GTK_ARG_READWRITE, ARG_HANDLE_SIZE);
gtk_object_add_arg_type ("GtkPaned::gutter_size", GTK_TYPE_UINT,
GTK_ARG_READWRITE, ARG_GUTTER_SIZE);
} }
static GtkType static GtkType
@ -136,9 +132,11 @@ gtk_paned_init (GtkPaned *paned)
paned->child2 = NULL; paned->child2 = NULL;
paned->handle = NULL; paned->handle = NULL;
paned->xor_gc = NULL; paned->xor_gc = NULL;
paned->cursor_type = GDK_CROSS;
paned->handle_size = 10; paned->handle_width = 5;
paned->gutter_size = 6; paned->handle_height = 5;
paned->handle_size = 5;
paned->position_set = FALSE; paned->position_set = FALSE;
paned->last_allocation = -1; paned->last_allocation = -1;
paned->in_drag = FALSE; paned->in_drag = FALSE;
@ -159,8 +157,7 @@ gtk_paned_set_arg (GtkObject *object,
case ARG_HANDLE_SIZE: case ARG_HANDLE_SIZE:
gtk_paned_set_handle_size (paned, GTK_VALUE_UINT (*arg)); gtk_paned_set_handle_size (paned, GTK_VALUE_UINT (*arg));
break; break;
case ARG_GUTTER_SIZE: default:
gtk_paned_set_gutter_size (paned, GTK_VALUE_UINT (*arg));
break; break;
} }
} }
@ -177,9 +174,6 @@ gtk_paned_get_arg (GtkObject *object,
case ARG_HANDLE_SIZE: case ARG_HANDLE_SIZE:
GTK_VALUE_UINT (*arg) = paned->handle_size; GTK_VALUE_UINT (*arg) = paned->handle_size;
break; break;
case ARG_GUTTER_SIZE:
GTK_VALUE_UINT (*arg) = paned->gutter_size;
break;
default: default:
arg->type = GTK_TYPE_INVALID; arg->type = GTK_TYPE_INVALID;
break; break;
@ -210,15 +204,15 @@ gtk_paned_realize (GtkWidget *widget)
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), widget->window = gdk_window_new (gtk_widget_get_parent_window(widget),
&attributes, attributes_mask); &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, paned); gdk_window_set_user_data (widget->window, paned);
attributes.x = paned->handle_xpos; attributes.x = paned->handle_xpos;
attributes.y = paned->handle_ypos; attributes.y = paned->handle_ypos;
attributes.width = paned->handle_size; attributes.width = paned->handle_width;
attributes.height = paned->handle_size; attributes.height = paned->handle_height;
attributes.cursor = gdk_cursor_new (GDK_CROSS); attributes.cursor = gdk_cursor_new (paned->cursor_type);
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_MASK |
@ -316,15 +310,12 @@ gtk_paned_expose (GtkWidget *widget,
{ {
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
/* An expose event for the handle */
if (event->window == paned->handle) if (event->window == paned->handle)
{ {
gtk_paint_box (widget->style, paned->handle, child_event = *event;
GTK_WIDGET_STATE(widget), event->area.x += paned->handle_xpos;
GTK_SHADOW_OUT, event->area.y += paned->handle_ypos;
&event->area, widget, "paned", gtk_widget_draw (widget, &event->area);
0, 0,
paned->handle_size, paned->handle_size);
} }
else else
{ {
@ -332,26 +323,21 @@ gtk_paned_expose (GtkWidget *widget,
if (paned->child1 && if (paned->child1 &&
GTK_WIDGET_NO_WINDOW (paned->child1) && GTK_WIDGET_NO_WINDOW (paned->child1) &&
gtk_widget_intersect (paned->child1, &event->area, &child_event.area)) gtk_widget_intersect (paned->child1, &event->area, &child_event.area))
gtk_widget_event (paned->child1, (GdkEvent*) &child_event); gtk_widget_event (paned->child1, (GdkEvent *) &child_event);
if (paned->child2 && if (paned->child2 &&
GTK_WIDGET_NO_WINDOW (paned->child2) && GTK_WIDGET_NO_WINDOW (paned->child2) &&
gtk_widget_intersect (paned->child2, &event->area, &child_event.area)) gtk_widget_intersect (paned->child2, &event->area, &child_event.area))
gtk_widget_event (paned->child2, (GdkEvent*) &child_event); gtk_widget_event (paned->child2, (GdkEvent *) &child_event);
/* redraw the groove if necessary */
if (gdk_rectangle_intersect (&paned->groove_rectangle,
&event->area,
&child_event.area))
gtk_widget_draw (widget, &child_event.area);
} }
} }
return FALSE; return FALSE;
} }
void void
gtk_paned_add1 (GtkPaned *paned, gtk_paned_add1 (GtkPaned *paned,
GtkWidget *widget) GtkWidget *widget)
{ {
gtk_paned_pack1 (paned, widget, FALSE, TRUE); gtk_paned_pack1 (paned, widget, FALSE, TRUE);
} }
@ -364,10 +350,10 @@ gtk_paned_add2 (GtkPaned *paned,
} }
void void
gtk_paned_pack1 (GtkPaned *paned, gtk_paned_pack1 (GtkPaned *paned,
GtkWidget *child, GtkWidget *child,
gboolean resize, gboolean resize,
gboolean shrink) gboolean shrink)
{ {
g_return_if_fail (paned != NULL); g_return_if_fail (paned != NULL);
g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_PANED (paned));
@ -425,6 +411,7 @@ gtk_paned_pack2 (GtkPaned *paned,
} }
} }
static void static void
gtk_paned_add (GtkContainer *container, gtk_paned_add (GtkContainer *container,
GtkWidget *widget) GtkWidget *widget)
@ -438,9 +425,9 @@ gtk_paned_add (GtkContainer *container,
paned = GTK_PANED (container); paned = GTK_PANED (container);
if (!paned->child1) if (!paned->child1)
gtk_paned_add1 (GTK_PANED (container),widget); gtk_paned_add1 (GTK_PANED (container), widget);
else if (!paned->child2) else if (!paned->child2)
gtk_paned_add2 (GTK_PANED (container),widget); gtk_paned_add2 (GTK_PANED (container), widget);
} }
static void static void
@ -464,7 +451,7 @@ gtk_paned_remove (GtkContainer *container,
paned->child1 = NULL; paned->child1 = NULL;
if (was_visible && GTK_WIDGET_VISIBLE (container)) if (was_visible && GTK_WIDGET_VISIBLE (container))
gtk_widget_queue_resize (GTK_WIDGET (container)); gtk_widget_queue_resize (GTK_WIDGET (container));
} }
else if (paned->child2 == widget) else if (paned->child2 == widget)
{ {
@ -473,13 +460,13 @@ gtk_paned_remove (GtkContainer *container,
paned->child2 = NULL; paned->child2 = NULL;
if (was_visible && GTK_WIDGET_VISIBLE (container)) if (was_visible && GTK_WIDGET_VISIBLE (container))
gtk_widget_queue_resize (GTK_WIDGET (container)); gtk_widget_queue_resize (GTK_WIDGET (container));
} }
} }
static void static void
gtk_paned_forall (GtkContainer *container, gtk_paned_forall (GtkContainer *container,
gboolean include_internals, gboolean include_internals,
GtkCallback callback, GtkCallback callback,
gpointer callback_data) gpointer callback_data)
{ {
@ -492,14 +479,14 @@ gtk_paned_forall (GtkContainer *container,
paned = GTK_PANED (container); paned = GTK_PANED (container);
if (paned->child1) if (paned->child1)
(* callback) (paned->child1, callback_data); (*callback) (paned->child1, callback_data);
if (paned->child2) if (paned->child2)
(* callback) (paned->child2, callback_data); (*callback) (paned->child2, callback_data);
} }
void void
gtk_paned_set_position (GtkPaned *paned, gtk_paned_set_position (GtkPaned *paned,
gint position) gint position)
{ {
g_return_if_fail (paned != NULL); g_return_if_fail (paned != NULL);
g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_PANED (paned));
@ -516,7 +503,9 @@ gtk_paned_set_position (GtkPaned *paned,
paned->position_set = TRUE; paned->position_set = TRUE;
} }
else else
paned->position_set = FALSE; {
paned->position_set = FALSE;
}
gtk_widget_queue_resize (GTK_WIDGET (paned)); gtk_widget_queue_resize (GTK_WIDGET (paned));
} }
@ -525,40 +514,19 @@ void
gtk_paned_set_handle_size (GtkPaned *paned, gtk_paned_set_handle_size (GtkPaned *paned,
guint16 size) guint16 size)
{ {
gint x,y;
g_return_if_fail (paned != NULL); g_return_if_fail (paned != NULL);
g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_PANED (paned));
if (paned->handle) gtk_widget_queue_resize (GTK_WIDGET (paned));
{
gdk_window_get_geometry (paned->handle, &x, &y, NULL, NULL, NULL);
gdk_window_move_resize (paned->handle,
x + paned->handle_size / 2 - size / 2,
y + paned->handle_size / 2 - size / 2,
size, size);
}
paned->handle_size = size; paned->handle_size = size;
} }
void void
gtk_paned_set_gutter_size (GtkPaned *paned, gtk_paned_compute_position(GtkPaned *paned,
guint16 size) gint allocation,
{ gint child1_req,
g_return_if_fail (paned != NULL); gint child2_req)
g_return_if_fail (GTK_IS_PANED (paned));
paned->gutter_size = size;
if (GTK_WIDGET_VISIBLE (GTK_WIDGET (paned)))
gtk_widget_queue_resize (GTK_WIDGET (paned));
}
void
gtk_paned_compute_position (GtkPaned *paned,
gint allocation,
gint child1_req,
gint child2_req)
{ {
g_return_if_fail (paned != NULL); g_return_if_fail (paned != NULL);
g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_PANED (paned));
@ -576,7 +544,8 @@ gtk_paned_compute_position (GtkPaned *paned,
else if (!paned->child1_resize && paned->child2_resize) else if (!paned->child1_resize && paned->child2_resize)
paned->child1_size = child1_req; paned->child1_size = child1_req;
else else
paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)); paned->child1_size = allocation * ((gdouble) child1_req /
(child1_req + child2_req));
} }
else else
{ {
@ -586,9 +555,9 @@ gtk_paned_compute_position (GtkPaned *paned,
if (paned->last_allocation >= 0) if (paned->last_allocation >= 0)
{ {
if (paned->child1_resize && !paned->child2_resize) if (paned->child1_resize && !paned->child2_resize)
paned->child1_size += (allocation - paned->last_allocation); 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 = allocation * ((gdouble) paned->child1_size / (paned->last_allocation));
} }
} }
@ -597,5 +566,4 @@ gtk_paned_compute_position (GtkPaned *paned,
paned->max_position); paned->max_position);
paned->last_allocation = allocation; paned->last_allocation = allocation;
} }

View File

@ -1,3 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* GTK - The GIMP Toolkit /* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* *
@ -18,7 +19,7 @@
*/ */
/* /*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog * file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with * files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
@ -27,11 +28,8 @@
#ifndef __GTK_PANED_H__ #ifndef __GTK_PANED_H__
#define __GTK_PANED_H__ #define __GTK_PANED_H__
#include <gdk/gdk.h>
#include <gtk/gtkcontainer.h> #include <gtk/gtkcontainer.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
@ -45,8 +43,8 @@ extern "C" {
#define GTK_PANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_PANED, GtkPanedClass)) #define GTK_PANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_PANED, GtkPanedClass))
typedef struct _GtkPaned GtkPaned; typedef struct _GtkPaned GtkPaned;
typedef struct _GtkPanedClass GtkPanedClass; typedef struct _GtkPanedClass GtkPanedClass;
struct _GtkPaned struct _GtkPaned
{ {
@ -56,14 +54,16 @@ struct _GtkPaned
GtkWidget *child2; GtkWidget *child2;
GdkWindow *handle; GdkWindow *handle;
GdkRectangle groove_rectangle;
GdkGC *xor_gc; GdkGC *xor_gc;
GdkCursorType cursor_type;
/*< public >*/ /*< public >*/
guint16 handle_size; guint16 handle_size;
guint16 gutter_size;
/*< private >*/ /*< private >*/
guint16 handle_width;
guint16 handle_height;
gint child1_size; gint child1_size;
gint last_allocation; gint last_allocation;
gint min_position; gint min_position;
@ -101,20 +101,16 @@ void gtk_paned_pack2 (GtkPaned *paned,
gboolean shrink); gboolean shrink);
void gtk_paned_set_position (GtkPaned *paned, void gtk_paned_set_position (GtkPaned *paned,
gint position); gint position);
void gtk_paned_set_handle_size (GtkPaned *paned, void gtk_paned_set_handle_size (GtkPaned *paned,
guint16 size); guint16 size);
void gtk_paned_set_gutter_size (GtkPaned *paned,
guint16 size);
/* Internal function */ /* Internal function */
void gtk_paned_compute_position (GtkPaned *paned, void gtk_paned_compute_position (GtkPaned *paned,
gint allocation, gint allocation,
gint child1_req, gint child1_req,
gint child2_req); gint child2_req);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __GTK_PANED_H__ */ #endif /* __GTK_PANED_H__ */

View File

@ -25,24 +25,22 @@
*/ */
#include "gtkvpaned.h" #include "gtkvpaned.h"
#include "gtkmain.h"
#include "gtksignal.h"
static void gtk_vpaned_class_init (GtkVPanedClass *klass); static void gtk_vpaned_class_init (GtkVPanedClass *klass);
static void gtk_vpaned_init (GtkVPaned *vpaned); static void gtk_vpaned_init (GtkVPaned *vpaned);
static void gtk_vpaned_size_request (GtkWidget *widget, static void gtk_vpaned_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_vpaned_size_allocate (GtkWidget *widget, static void gtk_vpaned_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static void gtk_vpaned_draw (GtkWidget *widget, static void gtk_vpaned_draw (GtkWidget *widget,
GdkRectangle *area); GdkRectangle *area);
static void gtk_vpaned_xor_line (GtkPaned *paned); static void gtk_vpaned_xor_line (GtkPaned *paned);
static gint gtk_vpaned_button_press (GtkWidget *widget, static gboolean gtk_vpaned_button_press (GtkWidget *widget,
GdkEventButton *event); GdkEventButton *event);
static gint gtk_vpaned_button_release (GtkWidget *widget, static gboolean gtk_vpaned_button_release (GtkWidget *widget,
GdkEventButton *event); GdkEventButton *event);
static gint gtk_vpaned_motion (GtkWidget *widget, static gboolean gtk_vpaned_motion (GtkWidget *widget,
GdkEventMotion *event); GdkEventMotion *event);
GtkType GtkType
gtk_vpaned_get_type (void) gtk_vpaned_get_type (void)
@ -59,11 +57,11 @@ gtk_vpaned_get_type (void)
(GtkClassInitFunc) gtk_vpaned_class_init, (GtkClassInitFunc) gtk_vpaned_class_init,
(GtkObjectInitFunc) gtk_vpaned_init, (GtkObjectInitFunc) gtk_vpaned_init,
/* reserved_1 */ NULL, /* reserved_1 */ NULL,
/* reserved_2 */ NULL, /* reserved_2 */ NULL,
(GtkClassInitFunc) NULL, (GtkClassInitFunc) NULL,
}; };
vpaned_type = gtk_type_unique (GTK_TYPE_PANED, &vpaned_info); vpaned_type = gtk_type_unique(gtk_paned_get_type(), &vpaned_info);
} }
return vpaned_type; return vpaned_type;
@ -74,7 +72,7 @@ gtk_vpaned_class_init (GtkVPanedClass *class)
{ {
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class;
widget_class = (GtkWidgetClass*) class; widget_class = (GtkWidgetClass *) class;
widget_class->size_request = gtk_vpaned_size_request; widget_class->size_request = gtk_vpaned_size_request;
widget_class->size_allocate = gtk_vpaned_size_allocate; widget_class->size_allocate = gtk_vpaned_size_allocate;
@ -87,9 +85,17 @@ gtk_vpaned_class_init (GtkVPanedClass *class)
static void static void
gtk_vpaned_init (GtkVPaned *vpaned) gtk_vpaned_init (GtkVPaned *vpaned)
{ {
GtkPaned *paned;
g_return_if_fail (vpaned != NULL);
g_return_if_fail (GTK_IS_PANED (vpaned));
paned = GTK_PANED (vpaned);
paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
} }
GtkWidget* GtkWidget *
gtk_vpaned_new (void) gtk_vpaned_new (void)
{ {
GtkVPaned *vpaned; GtkVPaned *vpaned;
@ -130,7 +136,7 @@ gtk_vpaned_size_request (GtkWidget *widget,
requisition->height += child_requisition.height; requisition->height += child_requisition.height;
} }
requisition->height += GTK_CONTAINER (paned)->border_width * 2 + paned->gutter_size; requisition->height += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size;
requisition->width += GTK_CONTAINER (paned)->border_width * 2; requisition->width += GTK_CONTAINER (paned)->border_width * 2;
} }
@ -143,7 +149,6 @@ gtk_vpaned_size_allocate (GtkWidget *widget,
GtkRequisition child2_requisition; GtkRequisition child2_requisition;
GtkAllocation child1_allocation; GtkAllocation child1_allocation;
GtkAllocation child2_allocation; GtkAllocation child2_allocation;
GdkRectangle old_groove_rectangle;
guint16 border_width; guint16 border_width;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
@ -165,84 +170,64 @@ gtk_vpaned_size_allocate (GtkWidget *widget,
else else
child2_requisition.height = 0; child2_requisition.height = 0;
gtk_paned_compute_position (paned, gtk_paned_compute_position(paned,
widget->allocation.height widget->allocation.height
- paned->gutter_size - paned->handle_size
- 2 * border_width, - 2 * border_width,
child1_requisition.height, child1_requisition.height,
child2_requisition.height); child2_requisition.height);
/* Move the handle before the children so we don't get extra expose events */ /* Move the handle before the children so we don't get extra expose events */
paned->handle_xpos = allocation->width - border_width - 2 * paned->handle_size; paned->handle_xpos = 0;
paned->handle_ypos = paned->child1_size + border_width + paned->gutter_size / 2 - paned->handle_size / 2; paned->handle_ypos = paned->child1_size + border_width;
paned->handle_width = widget->allocation.width;
paned->handle_height = paned->handle_size;
if (GTK_WIDGET_REALIZED (widget)) if (GTK_WIDGET_REALIZED(widget))
{ {
gdk_window_move_resize (widget->window, gdk_window_move_resize (widget->window,
allocation->x, allocation->y, allocation->x, allocation->y,
allocation->width, allocation->height); allocation->width,
allocation->height);
gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos); 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.width = child2_allocation.width = MAX(1, (gint) allocation->width - border_width * 2);
child1_allocation.height = paned->child1_size; child1_allocation.height = paned->child1_size;
child1_allocation.x = child2_allocation.x = border_width; child1_allocation.x = child2_allocation.x = border_width;
child1_allocation.y = border_width; child1_allocation.y = border_width;
old_groove_rectangle = paned->groove_rectangle; 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);
paned->groove_rectangle.y = child1_allocation.y
+ child1_allocation.height + paned->gutter_size / 2 - 1;
paned->groove_rectangle.x = 0;
paned->groove_rectangle.height = 2;
paned->groove_rectangle.width = allocation->width;
if (GTK_WIDGET_DRAWABLE (widget) &&
((paned->groove_rectangle.x != old_groove_rectangle.x) ||
(paned->groove_rectangle.y != old_groove_rectangle.y) ||
(paned->groove_rectangle.width != old_groove_rectangle.width) ||
(paned->groove_rectangle.height != old_groove_rectangle.height)))
{
gtk_widget_queue_clear_area (widget,
old_groove_rectangle.x,
old_groove_rectangle.y,
old_groove_rectangle.width,
old_groove_rectangle.height);
gtk_widget_queue_draw_area (widget,
paned->groove_rectangle.x,
paned->groove_rectangle.y,
paned->groove_rectangle.width,
paned->groove_rectangle.height);
}
child2_allocation.y = paned->groove_rectangle.y + paned->gutter_size / 2 + 1;
child2_allocation.height = MAX (1, (gint)allocation->height
- child2_allocation.y - border_width);
/* Now allocate the childen, making sure, when resizing not to /* Now allocate the childen, making sure, when resizing not to
* overlap the windows */ * overlap the windows */
if (GTK_WIDGET_MAPPED(widget) && if (GTK_WIDGET_MAPPED (widget) &&
paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
paned->child1->allocation.height < child1_allocation.height) paned->child1->allocation.height < child1_allocation.height)
{ {
if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
gtk_widget_size_allocate (paned->child2, &child2_allocation); gtk_widget_size_allocate(paned->child2, &child2_allocation);
gtk_widget_size_allocate (paned->child1, &child1_allocation); gtk_widget_size_allocate(paned->child1, &child1_allocation);
} }
else else
{ {
if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
gtk_widget_size_allocate (paned->child1, &child1_allocation); gtk_widget_size_allocate(paned->child1, &child1_allocation);
if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
gtk_widget_size_allocate (paned->child2, &child2_allocation); gtk_widget_size_allocate(paned->child2, &child2_allocation);
} }
} }
static void static void
gtk_vpaned_draw (GtkWidget *widget, gtk_vpaned_draw (GtkWidget *widget,
GdkRectangle *area) GdkRectangle *area)
{ {
GtkPaned *paned; GtkPaned *paned;
GdkRectangle handle_area, child_area; GdkRectangle handle_area, child_area;
@ -253,51 +238,95 @@ gtk_vpaned_draw (GtkWidget *widget,
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
{ {
gint width, height;
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
border_width = GTK_CONTAINER (paned)->border_width; border_width = GTK_CONTAINER (paned)->border_width;
gdk_window_clear_area (widget->window, gdk_window_clear_area (widget->window,
area->x, area->y, area->width, area->height); area->x, area->y, area->width,
area->height);
/* Redraw the handle
*/
gdk_window_get_size (paned->handle, &width, &height);
handle_area.x = paned->handle_xpos; handle_area.x = paned->handle_xpos;
handle_area.y = paned->handle_ypos; handle_area.y = paned->handle_ypos;
handle_area.width = width; handle_area.width = paned->handle_height;
handle_area.height = height; handle_area.height = paned->handle_size;
if (gdk_rectangle_intersect (&handle_area, area, &child_area)) if (gdk_rectangle_intersect (&handle_area, area, &child_area))
{ {
child_area.x -= handle_area.x; if (widget->allocation.height > 2)
child_area.y -= handle_area.y; {
gtk_paint_box (widget->style, paned->handle, gdk_draw_point (paned->handle,
GTK_WIDGET_STATE(widget), widget->style->fg_gc[GTK_STATE_NORMAL],
GTK_SHADOW_OUT, paned->handle_width/2,
&child_area, widget, "paned", paned->handle_size/2);
0, 0, gdk_draw_point (paned->handle,
width, height); widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 - 1,
paned->handle_size/2 - 1);
}
if (widget->allocation.height > 11)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 + 5,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 + 4,
paned->handle_size/2 - 1);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 - 5,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 - 6,
paned->handle_size/2 - 1);
}
if (widget->allocation.height > 20)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 - 10,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 - 11,
paned->handle_size/2 - 1);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 + 10,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 + 9,
paned->handle_size/2 - 1);
}
if (widget->allocation.height > 30)
{
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 - 15,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 - 16,
paned->handle_size/2 - 1);
gdk_draw_point (paned->handle,
widget->style->fg_gc[GTK_STATE_NORMAL],
paned->handle_width/2 + 15,
paned->handle_size/2);
gdk_draw_point (paned->handle,
widget->style->bg_gc[GTK_STATE_PRELIGHT],
paned->handle_width/2 + 14,
paned->handle_size/2 - 1);
}
} }
/* Redraw the groove
*/
gtk_paint_hline(widget->style, widget->window, GTK_STATE_NORMAL,
area, widget, "vpaned",
0, widget->allocation.width - 1,
border_width + paned->child1_size + paned->gutter_size / 2 - 1);
/* Redraw the children /* Redraw the children
*/ */
if (paned->child1 && if (paned->child1 && gtk_widget_intersect (paned->child1, area, &child_area))
gtk_widget_intersect (paned->child1, area, &child_area)) gtk_widget_draw (paned->child1, &child_area);
gtk_widget_draw (paned->child1, &child_area); if (paned->child2 && gtk_widget_intersect (paned->child2, area, &child_area))
if (paned->child2 && gtk_widget_draw (paned->child2, &child_area);
gtk_widget_intersect (paned->child2, area, &child_area))
gtk_widget_draw (paned->child2, &child_area);
} }
} }
@ -308,7 +337,7 @@ gtk_vpaned_xor_line (GtkPaned *paned)
GdkGCValues values; GdkGCValues values;
guint16 ypos; guint16 ypos;
widget = GTK_WIDGET(paned); widget = GTK_WIDGET (paned);
if (!paned->xor_gc) if (!paned->xor_gc)
{ {
@ -316,12 +345,14 @@ gtk_vpaned_xor_line (GtkPaned *paned)
values.subwindow_mode = GDK_INCLUDE_INFERIORS; values.subwindow_mode = GDK_INCLUDE_INFERIORS;
paned->xor_gc = gdk_gc_new_with_values (widget->window, paned->xor_gc = gdk_gc_new_with_values (widget->window,
&values, &values,
GDK_GC_FUNCTION | GDK_GC_FUNCTION | GDK_GC_SUBWINDOW);
GDK_GC_SUBWINDOW);
} }
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_size
+ GTK_CONTAINER (paned)->border_width + paned->gutter_size / 2; + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2;
gdk_draw_line (widget->window, paned->xor_gc, gdk_draw_line (widget->window, paned->xor_gc,
0, 0,
@ -330,13 +361,14 @@ gtk_vpaned_xor_line (GtkPaned *paned)
ypos); ypos);
} }
static gint static gboolean
gtk_vpaned_button_press (GtkWidget *widget, GdkEventButton *event) gtk_vpaned_button_press (GtkWidget *widget,
GdkEventButton *event)
{ {
GtkPaned *paned; GtkPaned *paned;
g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_PANED (widget),FALSE); g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
@ -349,20 +381,24 @@ gtk_vpaned_button_press (GtkWidget *widget, GdkEventButton *event)
gdk_pointer_grab (paned->handle, FALSE, gdk_pointer_grab (paned->handle, FALSE,
GDK_POINTER_MOTION_HINT_MASK GDK_POINTER_MOTION_HINT_MASK
| GDK_BUTTON1_MOTION_MASK | GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON_RELEASE_MASK, | GDK_BUTTON_RELEASE_MASK, NULL, NULL,
NULL, NULL, event->time); event->time);
paned->child1_size += event->y - paned->handle_size / 2; paned->child1_size += event->y - paned->handle_size / 2;
paned->child1_size = CLAMP (paned->child1_size, 0, paned->child1_size = CLAMP (paned->child1_size, 0,
widget->allocation.height - paned->gutter_size widget->allocation.height -
- 2 * GTK_CONTAINER (paned)->border_width); paned->handle_size -
gtk_vpaned_xor_line (paned); 2 * GTK_CONTAINER (paned)->border_width);
gtk_vpaned_xor_line(paned);
return TRUE;
} }
return TRUE; return FALSE;
} }
static gint static gboolean
gtk_vpaned_button_release (GtkWidget *widget, GdkEventButton *event) gtk_vpaned_button_release (GtkWidget *widget,
GdkEventButton *event)
{ {
GtkPaned *paned; GtkPaned *paned;
@ -378,13 +414,16 @@ gtk_vpaned_button_release (GtkWidget *widget, GdkEventButton *event)
paned->position_set = TRUE; paned->position_set = TRUE;
gdk_pointer_ungrab (event->time); gdk_pointer_ungrab (event->time);
gtk_widget_queue_resize (GTK_WIDGET (paned)); gtk_widget_queue_resize (GTK_WIDGET (paned));
return TRUE;
} }
return TRUE; return FALSE;
} }
static gint static gboolean
gtk_vpaned_motion (GtkWidget *widget, GdkEventMotion *event) gtk_vpaned_motion (GtkWidget *widget,
GdkEventMotion *event)
{ {
GtkPaned *paned; GtkPaned *paned;
gint y; gint y;
@ -393,21 +432,19 @@ gtk_vpaned_motion (GtkWidget *widget, GdkEventMotion *event)
g_return_val_if_fail (GTK_IS_PANED (widget), FALSE); g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
if (event->is_hint || event->window != widget->window) if (event->is_hint || event->window != widget->window)
gtk_widget_get_pointer(widget, NULL, &y); gtk_widget_get_pointer (widget, NULL, &y);
else else
y = event->y; y = event->y;
paned = GTK_PANED (widget); paned = GTK_PANED (widget);
if (paned->in_drag) if (paned->in_drag)
{ {
gint size = y - GTK_CONTAINER (paned)->border_width - paned->gutter_size/2; gint size = y - GTK_CONTAINER(paned)->border_width - paned->handle_size / 2;
gtk_vpaned_xor_line (paned); gtk_vpaned_xor_line (paned);
paned->child1_size = CLAMP (size, paned->child1_size = CLAMP (size, paned->min_position, paned->max_position);
paned->min_position, gtk_vpaned_xor_line(paned);
paned->max_position);
gtk_vpaned_xor_line (paned);
} }
return TRUE; return TRUE;

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog * file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with * files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
@ -27,11 +27,8 @@
#ifndef __GTK_VPANED_H__ #ifndef __GTK_VPANED_H__
#define __GTK_VPANED_H__ #define __GTK_VPANED_H__
#include <gdk/gdk.h>
#include <gtk/gtkpaned.h> #include <gtk/gtkpaned.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
@ -45,8 +42,8 @@ extern "C" {
#define GTK_VPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_VPANED, GtkVPanedClass)) #define GTK_VPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_VPANED, GtkVPanedClass))
typedef struct _GtkVPaned GtkVPaned; typedef struct _GtkVPaned GtkVPaned;
typedef struct _GtkVPanedClass GtkVPanedClass; typedef struct _GtkVPanedClass GtkVPanedClass;
struct _GtkVPaned struct _GtkVPaned
{ {
@ -58,14 +55,12 @@ struct _GtkVPanedClass
GtkPanedClass parent_class; GtkPanedClass parent_class;
}; };
GtkType gtk_vpaned_get_type (void); GtkType gtk_vpaned_get_type (void);
GtkWidget* gtk_vpaned_new (void); GtkWidget *gtk_vpaned_new (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __GTK_VPANED_H__ */ #endif /* __GTK_VPANED_H__ */