diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-02-18 20:02:24 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-02-18 20:02:24 +0000 |
commit | c8a2382b65120b32277f84394c55c7b51383523b (patch) | |
tree | 5fa6f133218b9f19106fb6720f1a7f6258f44476 /gtk | |
parent | ab1deac87fa395332b73daf8e2e4c893e23be3e4 (diff) | |
download | gtk+-c8a2382b65120b32277f84394c55c7b51383523b.tar.gz |
Remove OwnerGrabButtonMask from button entries for GDK_BUTTON_PRESS /
Fri Feb 18 14:37:29 2000 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (gdk_event_mask_table): Remove
OwnerGrabButtonMask from button entries for
GDK_BUTTON_PRESS / GDK_BUTTON_RELEASE.
* gtk/gtklayout.c (gtk_layout_realize): Always add GDK_SCROLL
to the event mask (which will result in button/press release
being added to the event mask on Unix) so scrolling works
for layouts in scroll windows.
* gdk/gdkevents.h (enum): Fix up GDK_ALL_EVENTS_MASK.
Patch from Anders Carlsson <andersca@picard.andersnet> to add
a scroll event.
* gtk/testgtk.c (scroll_test_scroll): Added an example of mouse wheel
scrolling to the "Test Scrolling" part of testgtk.
* gtk/gtkwidget.h (struct _GtkWidgetClass): Added scroll_event signal.
* gtk/gtkwidget.c: Added "scroll_event" GTK+ signal and matched
it against GDK_SCROLL.
* gtk/gtkrange.c (gtk_range_scroll_event): Updated to use the new
way of mouse wheel scrolling.
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_scroll_event): Likewise.
* gtk/gtkspinbutton.c (gtk_spin_button_scroll): Likewise.
* gtk/gtkmain.c: Removed previous mouse wheel hack.
* gdk/x11/gdkwindow-x11.c (gdk_event_mask_table): Added entry in
gdk_event_mask_table.
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Added
GdkEventScroll handler.
* gdk/gdkevents.h: Added GdkEventScroll structure.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtklayout.c | 2 | ||||
-rw-r--r-- | gtk/gtkmain.c | 37 | ||||
-rw-r--r-- | gtk/gtkrange.c | 27 | ||||
-rw-r--r-- | gtk/gtkscrolledwindow.c | 38 | ||||
-rw-r--r-- | gtk/gtkspinbutton.c | 49 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 12 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 2 | ||||
-rw-r--r-- | gtk/testgtk.c | 18 |
8 files changed, 130 insertions, 55 deletions
diff --git a/gtk/gtklayout.c b/gtk/gtklayout.c index b98aeadf38..bd21eead61 100644 --- a/gtk/gtklayout.c +++ b/gtk/gtklayout.c @@ -467,7 +467,7 @@ gtk_layout_realize (GtkWidget *widget) attributes.x = 0; attributes.y = 0; - attributes.event_mask = GDK_EXPOSURE_MASK | + attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK | gtk_widget_get_events (widget); layout->bin_window = gdk_window_new (widget->window, diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 08ffc830fe..c28c134f67 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -757,45 +757,10 @@ gtk_main_do_event (GdkEvent *event) gtk_widget_event (event_widget, event); break; + case GDK_SCROLL: case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: - /* We treat button 4-5 specially, assume we have - * a MS-style scrollwheel mouse, and try to find - * a plausible widget to scroll. We also trap - * button 4-5 double and triple clicks here, since - * they will be generated if the user scrolls quickly. - */ - if ((grab_widget == event_widget) && - (event->button.button == 4 || event->button.button == 5)) - { - GtkWidget *range = NULL; - GtkWidget *scrollwin; - - if (GTK_IS_RANGE (event_widget)) - range = event_widget; - else - { - scrollwin = gtk_widget_get_ancestor (event_widget, - GTK_TYPE_SCROLLED_WINDOW); - if (scrollwin) - range = GTK_SCROLLED_WINDOW (scrollwin)->vscrollbar; - } - - if (range && GTK_WIDGET_VISIBLE (range)) - { - if (event->type == GDK_BUTTON_PRESS) - { - GtkAdjustment *adj = GTK_RANGE (range)->adjustment; - gfloat new_value = adj->value + ((event->button.button == 4) ? - -adj->page_increment / 2: - adj->page_increment / 2); - new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); - gtk_adjustment_set_value (adj, new_value); - } - break; - } - } gtk_propagate_event (grab_widget, event); break; diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index a01f72edf3..c7ad58ab16 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -73,6 +73,8 @@ static gint gtk_range_focus_in (GtkWidget *widget, GdkEventFocus *event); static gint gtk_range_focus_out (GtkWidget *widget, GdkEventFocus *event); +static gint gtk_range_scroll_event (GtkWidget *widget, + GdkEventScroll *event); static void gtk_range_style_set (GtkWidget *widget, GtkStyle *previous_style); @@ -153,6 +155,7 @@ gtk_range_class_init (GtkRangeClass *class) widget_class->button_press_event = gtk_range_button_press; widget_class->button_release_event = gtk_range_button_release; widget_class->motion_notify_event = gtk_range_motion_notify; + widget_class->scroll_event = gtk_range_scroll_event; widget_class->key_press_event = gtk_range_key_press; widget_class->enter_notify_event = gtk_range_enter_notify; widget_class->leave_notify_event = gtk_range_leave_notify; @@ -979,6 +982,30 @@ gtk_range_button_release (GtkWidget *widget, } static gint +gtk_range_scroll_event (GtkWidget *widget, + GdkEventScroll *event) +{ + GtkRange *range; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_RANGE (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + range = GTK_RANGE (widget); + + if (GTK_WIDGET_VISIBLE (range)) { + GtkAdjustment *adj = GTK_RANGE (range)->adjustment; + gfloat new_value = adj->value + ((event->direction == GDK_SCROLL_UP) ? + -adj->page_increment / 2: + adj->page_increment / 2); + new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); + gtk_adjustment_set_value (adj, new_value); + } + + return FALSE; +} + +static gint gtk_range_motion_notify (GtkWidget *widget, GdkEventMotion *event) { diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index e9f0f1d857..2e7b969247 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -95,6 +95,8 @@ static void gtk_scrolled_window_size_request (GtkWidget *widg GtkRequisition *requisition); static void gtk_scrolled_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation); +static gint gtk_scrolled_window_scroll_event (GtkWidget *widget, + GdkEventScroll *event); static void gtk_scrolled_window_add (GtkContainer *container, GtkWidget *widget); static void gtk_scrolled_window_remove (GtkContainer *container, @@ -108,7 +110,6 @@ static void gtk_scrolled_window_relative_allocation(GtkWidget *widg static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, gpointer data); - static GtkContainerClass *parent_class = NULL; @@ -180,6 +181,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class) widget_class->draw = gtk_scrolled_window_draw; widget_class->size_request = gtk_scrolled_window_size_request; widget_class->size_allocate = gtk_scrolled_window_size_allocate; + widget_class->scroll_event = gtk_scrolled_window_scroll_event; container_class->add = gtk_scrolled_window_add; container_class->remove = gtk_scrolled_window_remove; @@ -270,6 +272,7 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window) scrolled_window->hscrollbar_visible = FALSE; scrolled_window->vscrollbar_visible = FALSE; scrolled_window->window_placement = GTK_CORNER_TOP_LEFT; + } GtkWidget* @@ -848,6 +851,39 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget, gtk_widget_hide (scrolled_window->vscrollbar); } +static gint +gtk_scrolled_window_scroll_event (GtkWidget *widget, + GdkEventScroll *event) +{ + GtkWidget *range; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN) + range = GTK_SCROLLED_WINDOW (widget)->vscrollbar; + else + range = GTK_SCROLLED_WINDOW (widget)->hscrollbar; + + if (range && GTK_WIDGET_VISIBLE (range)) + { + GtkAdjustment *adj = GTK_RANGE (range)->adjustment; + gfloat new_value; + + if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_LEFT) + new_value = adj->value - adj->page_increment / 2; + else + new_value = adj->value + adj->page_increment / 2; + + new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); + gtk_adjustment_set_value (adj, new_value); + + return TRUE; + } + + return FALSE; +} static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 162f63588e..8261e71589 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -45,8 +45,6 @@ #define MAX_TEXT_LENGTH 256 #define MAX_TIMER_CALLS 5 #define EPSILON 1e-5 -#define WHEEL_UP_BUTTON 4 -#define WHEEL_DOWN_BUTTON 5 enum { ARG_0, @@ -113,6 +111,8 @@ static gint gtk_spin_button_key_press (GtkWidget *widget, GdkEventKey *event); static gint gtk_spin_button_key_release (GtkWidget *widget, GdkEventKey *event); +static gint gtk_spin_button_scroll (GtkWidget *widget, + GdkEventScroll *event); static void gtk_spin_button_activate (GtkEditable *editable); static void gtk_spin_button_snap (GtkSpinButton *spin_button, gfloat val); @@ -235,6 +235,7 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) widget_class->size_allocate = gtk_spin_button_size_allocate; widget_class->draw = gtk_spin_button_draw; widget_class->expose_event = gtk_spin_button_expose; + widget_class->scroll_event = gtk_spin_button_scroll; widget_class->button_press_event = gtk_spin_button_button_press; widget_class->button_release_event = gtk_spin_button_button_release; widget_class->motion_notify_event = gtk_spin_button_motion_notify; @@ -752,6 +753,36 @@ gtk_spin_button_focus_out (GtkWidget *widget, } static gint +gtk_spin_button_scroll (GtkWidget *widget, + GdkEventScroll *event) +{ + GtkSpinButton *spin; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + spin = GTK_SPIN_BUTTON (widget); + + if (event->direction == GDK_SCROLL_UP) + { + if (!GTK_WIDGET_HAS_FOCUS (widget)) + gtk_widget_grab_focus (widget); + gtk_spin_button_real_spin (spin, spin->adjustment->step_increment); + } + else if (event->direction == GDK_SCROLL_DOWN) + { + if (!GTK_WIDGET_HAS_FOCUS (widget)) + gtk_widget_grab_focus (widget); + gtk_spin_button_real_spin (spin, -spin->adjustment->step_increment); + } + else + return FALSE; + + return TRUE; +} + +static gint gtk_spin_button_button_press (GtkWidget *widget, GdkEventButton *event) { @@ -765,19 +796,7 @@ gtk_spin_button_button_press (GtkWidget *widget, if (!spin->button) { - if (event->button == WHEEL_UP_BUTTON) - { - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - gtk_spin_button_real_spin (spin, spin->adjustment->step_increment); - } - else if (event->button == WHEEL_DOWN_BUTTON) - { - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - gtk_spin_button_real_spin (spin, -spin->adjustment->step_increment); - } - else if (event->window == spin->panel) + if (event->window == spin->panel) { if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index d8b35ccb31..28dbaa2b6f 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -64,6 +64,7 @@ enum { EVENT, BUTTON_PRESS_EVENT, BUTTON_RELEASE_EVENT, + SCROLL_EVENT, MOTION_NOTIFY_EVENT, DELETE_EVENT, DESTROY_EVENT, @@ -434,6 +435,14 @@ gtk_widget_class_init (GtkWidgetClass *klass) gtk_marshal_BOOL__POINTER, GTK_TYPE_BOOL, 1, GTK_TYPE_GDK_EVENT); + widget_signals[SCROLL_EVENT] = + gtk_signal_new ("scroll_event", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (GtkWidgetClass, scroll_event), + gtk_marshal_BOOL__POINTER, + GTK_TYPE_BOOL, 1, + GTK_TYPE_GDK_EVENT); widget_signals[MOTION_NOTIFY_EVENT] = gtk_signal_new ("motion_notify_event", GTK_RUN_LAST, @@ -2728,6 +2737,9 @@ gtk_widget_event (GtkWidget *widget, case GDK_3BUTTON_PRESS: signal_num = BUTTON_PRESS_EVENT; break; + case GDK_SCROLL: + signal_num = SCROLL_EVENT; + break; case GDK_BUTTON_RELEASE: signal_num = BUTTON_RELEASE_EVENT; break; diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index ff6523d31c..49431de875 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -297,6 +297,8 @@ struct _GtkWidgetClass GdkEventButton *event); gint (* button_release_event) (GtkWidget *widget, GdkEventButton *event); + gint (* scroll_event) (GtkWidget *widget, + GdkEventScroll *event); gint (* motion_notify_event) (GtkWidget *widget, GdkEventMotion *event); gint (* delete_event) (GtkWidget *widget, diff --git a/gtk/testgtk.c b/gtk/testgtk.c index c004a077f5..5331dea4df 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -7609,6 +7609,19 @@ scroll_test_expose (GtkWidget *widget, GdkEventExpose *event, return TRUE; } +static gint +scroll_test_scroll (GtkWidget *widget, GdkEventScroll *event, + GtkAdjustment *adj) +{ + gfloat new_value = adj->value + ((event->direction == GDK_SCROLL_UP) ? + -adj->page_increment / 2: + adj->page_increment / 2); + new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); + gtk_adjustment_set_value (adj, new_value); + + return TRUE; +} + static void scroll_test_configure (GtkWidget *widget, GdkEventConfigure *event, GtkAdjustment *adj) @@ -7728,7 +7741,7 @@ create_scroll_test (void) gtk_box_pack_start (GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0); gtk_widget_show (drawing_area); - gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK); + gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK | GDK_SCROLL_MASK); adj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 1000.0, 1.0, 180.0, 200.0)); scroll_test_pos = 0.0; @@ -7741,7 +7754,8 @@ create_scroll_test (void) GTK_SIGNAL_FUNC (scroll_test_expose), adj); gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event", GTK_SIGNAL_FUNC (scroll_test_configure), adj); - + gtk_signal_connect (GTK_OBJECT (drawing_area), "scroll_event", + GTK_SIGNAL_FUNC (scroll_test_scroll), adj); gtk_signal_connect (GTK_OBJECT (adj), "value_changed", GTK_SIGNAL_FUNC (scroll_test_adjustment_changed), |