From fbd76f40c44dd02acaa73ebaf843189b96da3357 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 21 Aug 2012 15:19:12 -0500 Subject: when the mouse is over the GtkSwitch widget, the menuitem should delegate the mouse down and motion events to it. --- src/idoswitchmenuitem.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/idoswitchmenuitem.c') diff --git a/src/idoswitchmenuitem.c b/src/idoswitchmenuitem.c index 3831336..2ff60a3 100644 --- a/src/idoswitchmenuitem.c +++ b/src/idoswitchmenuitem.c @@ -24,6 +24,10 @@ static gboolean ido_switch_menu_button_release_event (GtkWidget * widget, GdkEventButton * event); +static gboolean ido_switch_menu_button_press_event (GtkWidget * widget, + GdkEventButton * event); +static gboolean ido_switch_menu_item_motion_notify_event (GtkWidget *menuitem, + GdkEventMotion *event); struct _IdoSwitchMenuItemPrivate @@ -50,7 +54,9 @@ ido_switch_menu_item_class_init (IdoSwitchMenuItemClass *klass) g_type_class_add_private (gobject_class, sizeof (IdoSwitchMenuItemPrivate)); widget_class = GTK_WIDGET_CLASS (klass); + widget_class->button_press_event = ido_switch_menu_button_press_event; widget_class->button_release_event = ido_switch_menu_button_release_event; + widget_class->motion_notify_event = ido_switch_menu_item_motion_notify_event; check_class = GTK_CHECK_MENU_ITEM_CLASS (klass); check_class->draw_indicator = NULL; @@ -101,6 +107,51 @@ ido_switch_menu_button_release_event (GtkWidget * widget, GdkEventButton * event return TRUE; /* stop the event so that it doesn't trigger popdown() */ } +/*** +**** +**** +***/ + +static gboolean +ido_switch_menu_button_press_event (GtkWidget * w, GdkEventButton * e) +{ + gboolean delegated = FALSE; + IdoSwitchMenuItemPrivate * p = IDO_SWITCH_MENU_ITEM(w)->priv; + + GtkAllocation a; + gtk_widget_get_allocation (p->switch_w, &a); + + if ((a.x <= e->x) && (e->x < a.x + a.width)) + { + e->x -= a.x; + e->x_root -= a.x; + gtk_widget_event (p->switch_w, (GdkEvent*)e); + delegated = TRUE; + } + + return delegated; +} + +static gboolean +ido_switch_menu_item_motion_notify_event (GtkWidget * w, GdkEventMotion * e) +{ + gboolean delegated = FALSE; + IdoSwitchMenuItemPrivate * p = IDO_SWITCH_MENU_ITEM(w)->priv; + + GtkAllocation a; + gtk_widget_get_allocation (p->switch_w, &a); + + if ((a.x <= e->x) && (e->x < a.x + a.width)) + { + e->x -= a.x; + e->x_root -= a.x; + gtk_widget_event (p->switch_w, (GdkEvent*)e); + delegated = TRUE; + } + + return delegated; +} + /*** **** Public API ***/ -- cgit v1.2.3