diff options
author | Soeren Sandmann <sandmann@daimi.au.dk> | 2002-02-11 21:10:33 +0000 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@src.gnome.org> | 2002-02-11 21:10:33 +0000 |
commit | abc8455dea65b8f2aaff0bc871eacf5841b402c5 (patch) | |
tree | f6cd182b106c00fff4a696228cdf9be304e20088 /gtk | |
parent | d456e05b81b3ffcb7dc03817c063d872179eab0c (diff) | |
download | gtk+-abc8455dea65b8f2aaff0bc871eacf5841b402c5.tar.gz |
Opaque resizing + prelighting for paned widget. move reszing logic to
Mon Feb 11 22:03:15 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkpaned.[ch]: Opaque resizing + prelighting for paned widget.
* gtk/gtkvpaned.c, gtk/gtkvpaned.h: move reszing logic to gtkpaned.c
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkhpaned.c | 126 | ||||
-rw-r--r-- | gtk/gtkpaned.c | 156 | ||||
-rw-r--r-- | gtk/gtkpaned.h | 4 | ||||
-rw-r--r-- | gtk/gtkvpaned.c | 126 |
4 files changed, 154 insertions, 258 deletions
diff --git a/gtk/gtkhpaned.c b/gtk/gtkhpaned.c index 196ca41277..b0e6481a66 100644 --- a/gtk/gtkhpaned.c +++ b/gtk/gtkhpaned.c @@ -32,13 +32,6 @@ static void gtk_hpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_hpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static void gtk_hpaned_xor_line (GtkPaned *paned); -static gboolean gtk_hpaned_button_press (GtkWidget *widget, - GdkEventButton *event); -static gboolean gtk_hpaned_button_release (GtkWidget *widget, - GdkEventButton *event); -static gboolean gtk_hpaned_motion (GtkWidget *widget, - GdkEventMotion *event); static gpointer parent_class; @@ -78,9 +71,6 @@ gtk_hpaned_class_init (GtkHPanedClass *class) widget_class->size_request = gtk_hpaned_size_request; widget_class->size_allocate = gtk_hpaned_size_allocate; - 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; } static void @@ -231,119 +221,3 @@ gtk_hpaned_size_allocate (GtkWidget *widget, gtk_widget_size_allocate (paned->child2, &child_allocation); } } - -static void -gtk_hpaned_xor_line (GtkPaned *paned) -{ - GtkWidget *widget; - GdkGCValues values; - guint16 xpos; - gint handle_size; - - widget = GTK_WIDGET (paned); - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - if (!paned->xor_gc) - { - values.function = GDK_INVERT; - values.subwindow_mode = GDK_INCLUDE_INFERIORS; - paned->xor_gc = gdk_gc_new_with_values (widget->window, - &values, - GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); - } - - gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL); - - xpos = widget->allocation.x + paned->child1_size - + GTK_CONTAINER (paned)->border_width + handle_size / 2; - - gdk_draw_line (widget->window, paned->xor_gc, - xpos, - widget->allocation.y, - xpos, - widget->allocation.y + widget->allocation.height - 1); -} - -static gboolean -gtk_hpaned_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - GtkPaned *paned = GTK_PANED (widget); - gint handle_size; - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - if (!paned->in_drag && - event->window == paned->handle && event->button == 1) - { - 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 */ - gdk_pointer_grab(paned->handle, FALSE, - GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON1_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - NULL, NULL, event->time); - paned->child1_size += event->x - handle_size / 2; - paned->child1_size = CLAMP (paned->child1_size, 0, - widget->allocation.width - - handle_size - - 2 * GTK_CONTAINER (paned)->border_width); - gtk_hpaned_xor_line (paned); - - return TRUE; - } - - return FALSE; -} - -static gboolean -gtk_hpaned_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - GtkPaned *paned = GTK_PANED (widget); - GObject *object = G_OBJECT (widget); - - if (paned->in_drag && (event->button == 1)) - { - gtk_hpaned_xor_line (paned); - paned->in_drag = FALSE; - paned->position_set = TRUE; - gdk_pointer_ungrab (event->time); - gtk_widget_queue_resize (GTK_WIDGET (paned)); - g_object_freeze_notify (object); - g_object_notify (object, "position"); - g_object_notify (object, "position_set"); - g_object_thaw_notify (object); - - return TRUE; - } - - return FALSE; -} - -static gboolean -gtk_hpaned_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - GtkPaned *paned = GTK_PANED (widget); - gint x; - gint handle_size; - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - gtk_widget_get_pointer (widget, &x, NULL); - - if (paned->in_drag) - { - gint size = x - GTK_CONTAINER (paned)->border_width - handle_size / 2; - - gtk_hpaned_xor_line (paned); - paned->child1_size = CLAMP (size, paned->min_position, paned->max_position); - gtk_hpaned_xor_line (paned); - } - - return TRUE; -} diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index e3b3a4bfac..7bab61195c 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -63,8 +63,18 @@ static void gtk_paned_realize (GtkWidget *widget); static void gtk_paned_unrealize (GtkWidget *widget); static void gtk_paned_map (GtkWidget *widget); static void gtk_paned_unmap (GtkWidget *widget); -static gint gtk_paned_expose (GtkWidget *widget, +static gboolean gtk_paned_expose (GtkWidget *widget, GdkEventExpose *event); +static gboolean gtk_paned_enter (GtkWidget *widget, + GdkEventCrossing *event); +static gboolean gtk_paned_leave (GtkWidget *widget, + GdkEventCrossing *event); +static gboolean gtk_paned_button_press (GtkWidget *widget, + GdkEventButton *event); +static gboolean gtk_paned_button_release (GtkWidget *widget, + GdkEventButton *event); +static gboolean gtk_paned_motion (GtkWidget *widget, + GdkEventMotion *event); static gboolean gtk_paned_focus (GtkWidget *widget, GtkDirectionType direction); static void gtk_paned_add (GtkContainer *container, @@ -176,6 +186,11 @@ gtk_paned_class_init (GtkPanedClass *class) widget_class->unmap = gtk_paned_unmap; widget_class->expose_event = gtk_paned_expose; widget_class->focus = gtk_paned_focus; + widget_class->enter_notify_event = gtk_paned_enter; + widget_class->leave_notify_event = gtk_paned_leave; + widget_class->button_press_event = gtk_paned_button_press; + widget_class->button_release_event = gtk_paned_button_release; + widget_class->motion_notify_event = gtk_paned_motion; container_class->add = gtk_paned_add; container_class->remove = gtk_paned_remove; @@ -374,10 +389,13 @@ gtk_paned_init (GtkPaned *paned) paned->last_child1_focus = NULL; paned->last_child2_focus = NULL; paned->in_recursion = FALSE; + paned->handle_prelit = FALSE; paned->original_position = -1; paned->handle_pos.x = -1; paned->handle_pos.y = -1; + + paned->drag_pos = -1; } static void @@ -445,8 +463,11 @@ gtk_paned_realize (GtkWidget *widget) attributes.width = paned->handle_pos.width; attributes.height = paned->handle_pos.height; attributes.cursor = gdk_cursor_new (paned->cursor_type); + attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR; @@ -509,7 +530,7 @@ gtk_paned_unmap (GtkWidget *widget) GTK_WIDGET_CLASS (parent_class)->unmap (widget); } -static gint +static gboolean gtk_paned_expose (GtkWidget *widget, GdkEventExpose *event) { @@ -531,9 +552,12 @@ gtk_paned_expose (GtkWidget *widget, gdk_region_get_clipbox (region, &clip); - state = GTK_WIDGET_STATE (widget); if (gtk_widget_is_focus (widget)) state = GTK_STATE_SELECTED; + else if (paned->handle_prelit) + state = GTK_STATE_PRELIGHT; + else + state = GTK_WIDGET_STATE (widget); gtk_paint_handle (widget->style, widget->window, state, GTK_SHADOW_NONE, @@ -545,13 +569,68 @@ gtk_paned_expose (GtkWidget *widget, gdk_region_destroy (region); } - + /* Chain up to draw children */ GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); - + return FALSE; } +static void +update_drag (GtkPaned *paned) +{ + gint pos; + gint handle_size; + gint size; + + if (paned->orientation == GTK_ORIENTATION_HORIZONTAL) + gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos); + else + gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL); + + gtk_widget_style_get (GTK_WIDGET (paned), "handle_size", &handle_size, NULL); + + size = pos - GTK_CONTAINER (paned)->border_width - paned->drag_pos; + size = CLAMP (size, paned->min_position, paned->max_position); + + if (size != paned->child1_size) + gtk_paned_set_position (paned, size); +} + +static gboolean +gtk_paned_enter (GtkWidget *widget, + GdkEventCrossing *event) +{ + GtkPaned *paned = GTK_PANED (widget); + + if (paned->in_drag) + update_drag (paned); + else + { + paned->handle_prelit = TRUE; + gtk_widget_queue_draw (widget); + } + + return TRUE; +} + +static gboolean +gtk_paned_leave (GtkWidget *widget, + GdkEventCrossing *event) +{ + GtkPaned *paned = GTK_PANED (widget); + + if (paned->in_drag) + update_drag (paned); + else + { + paned->handle_prelit = FALSE; + gtk_widget_queue_draw (widget); + } + + return TRUE; +} + static gboolean gtk_paned_focus (GtkWidget *widget, GtkDirectionType direction) @@ -570,6 +649,73 @@ gtk_paned_focus (GtkWidget *widget, return retval; } +static gboolean +gtk_paned_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + GtkPaned *paned = GTK_PANED (widget); + + if (!paned->in_drag && + (event->window == paned->handle) && (event->button == 1)) + { + 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 */ + gdk_pointer_grab (paned->handle, FALSE, + GDK_POINTER_MOTION_HINT_MASK + | GDK_BUTTON1_MOTION_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_ENTER_NOTIFY_MASK + | GDK_LEAVE_NOTIFY_MASK, + NULL, NULL, + event->time); + + if (paned->orientation == GTK_ORIENTATION_HORIZONTAL) + paned->drag_pos = event->y; + else + paned->drag_pos = event->x; + + return TRUE; + } + + return FALSE; +} + +static gboolean +gtk_paned_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GtkPaned *paned = GTK_PANED (widget); + + if (paned->in_drag && (event->button == 1)) + { + paned->in_drag = FALSE; + paned->drag_pos = -1; + paned->position_set = TRUE; + gdk_pointer_ungrab (event->time); + + return TRUE; + } + + return FALSE; +} + +static gboolean +gtk_paned_motion (GtkWidget *widget, + GdkEventMotion *event) +{ + GtkPaned *paned = GTK_PANED (widget); + + if (paned->in_drag) + { + update_drag (paned); + return TRUE; + } + + return FALSE; +} + void gtk_paned_add1 (GtkPaned *paned, GtkWidget *widget) diff --git a/gtk/gtkpaned.h b/gtk/gtkpaned.h index 115dd12a6e..5940e32ea4 100644 --- a/gtk/gtkpaned.h +++ b/gtk/gtkpaned.h @@ -73,11 +73,13 @@ struct _GtkPaned guint child2_resize : 1; guint orientation : 1; guint in_recursion : 1; + guint handle_prelit : 1; GtkWidget *last_child1_focus; GtkWidget *last_child2_focus; GtkWidget *saved_focus; - + + gint drag_pos; gint original_position; }; diff --git a/gtk/gtkvpaned.c b/gtk/gtkvpaned.c index 5cfd4b6981..39316f8668 100644 --- a/gtk/gtkvpaned.c +++ b/gtk/gtkvpaned.c @@ -32,13 +32,6 @@ static void gtk_vpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_vpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static void gtk_vpaned_xor_line (GtkPaned *paned); -static gboolean gtk_vpaned_button_press (GtkWidget *widget, - GdkEventButton *event); -static gboolean gtk_vpaned_button_release (GtkWidget *widget, - GdkEventButton *event); -static gboolean gtk_vpaned_motion (GtkWidget *widget, - GdkEventMotion *event); static gpointer parent_class; @@ -78,9 +71,6 @@ gtk_vpaned_class_init (GtkVPanedClass *class) widget_class->size_request = gtk_vpaned_size_request; widget_class->size_allocate = gtk_vpaned_size_allocate; - 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; } static void @@ -231,119 +221,3 @@ gtk_vpaned_size_allocate (GtkWidget *widget, gtk_widget_size_allocate (paned->child2, &child_allocation); } } - -static void -gtk_vpaned_xor_line (GtkPaned *paned) -{ - GtkWidget *widget; - GdkGCValues values; - guint16 ypos; - gint handle_size; - - widget = GTK_WIDGET (paned); - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - if (!paned->xor_gc) - { - values.function = GDK_INVERT; - values.subwindow_mode = GDK_INCLUDE_INFERIORS; - paned->xor_gc = gdk_gc_new_with_values (widget->window, - &values, - GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); - } - - gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL); - - ypos = widget->allocation.y + paned->child1_size - + GTK_CONTAINER (paned)->border_width + handle_size / 2; - - gdk_draw_line (widget->window, paned->xor_gc, - widget->allocation.x, - ypos, - widget->allocation.x + widget->allocation.width - 1, - ypos); -} - -static gboolean -gtk_vpaned_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - GtkPaned *paned = GTK_PANED (widget); - gint handle_size; - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - if (!paned->in_drag && - (event->window == paned->handle) && (event->button == 1)) - { - 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 */ - gdk_pointer_grab (paned->handle, FALSE, - GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON1_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, NULL, NULL, - event->time); - paned->child1_size += event->y - handle_size / 2; - paned->child1_size = CLAMP (paned->child1_size, 0, - widget->allocation.height - - handle_size - - 2 * GTK_CONTAINER (paned)->border_width); - gtk_vpaned_xor_line(paned); - - return TRUE; - } - - return FALSE; -} - -static gboolean -gtk_vpaned_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - GtkPaned *paned = GTK_PANED (widget); - GObject *object = G_OBJECT (widget); - - if (paned->in_drag && (event->button == 1)) - { - gtk_vpaned_xor_line (paned); - paned->in_drag = FALSE; - paned->position_set = TRUE; - gdk_pointer_ungrab (event->time); - gtk_widget_queue_resize (GTK_WIDGET (paned)); - g_object_freeze_notify (object); - g_object_notify (object, "position"); - g_object_notify (object, "position_set"); - g_object_thaw_notify (object); - - return TRUE; - } - - return FALSE; -} - -static gboolean -gtk_vpaned_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - GtkPaned *paned = GTK_PANED (widget); - gint y; - gint handle_size; - - gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); - - gtk_widget_get_pointer (widget, NULL, &y); - - if (paned->in_drag) - { - gint size = y - GTK_CONTAINER (paned)->border_width - handle_size / 2; - - gtk_vpaned_xor_line (paned); - paned->child1_size = CLAMP (size, paned->min_position, paned->max_position); - gtk_vpaned_xor_line (paned); - } - - return TRUE; -} |