forked from AuroraMiddleware/gtk
gtkexpander: Remove event window
Detect presses/releases inside the label area instead.
This commit is contained in:
parent
1858f310aa
commit
8731ca6ca5
@ -144,7 +144,6 @@ enum
|
|||||||
struct _GtkExpanderPrivate
|
struct _GtkExpanderPrivate
|
||||||
{
|
{
|
||||||
GtkWidget *label_widget;
|
GtkWidget *label_widget;
|
||||||
GdkWindow *event_window;
|
|
||||||
|
|
||||||
GtkCssGadget *gadget;
|
GtkCssGadget *gadget;
|
||||||
GtkWidget *title_widget;
|
GtkWidget *title_widget;
|
||||||
@ -161,6 +160,7 @@ struct _GtkExpanderPrivate
|
|||||||
guint prelight : 1;
|
guint prelight : 1;
|
||||||
guint label_fill : 1;
|
guint label_fill : 1;
|
||||||
guint resize_toplevel : 1;
|
guint resize_toplevel : 1;
|
||||||
|
guint pressed_in_title : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gtk_expander_set_property (GObject *object,
|
static void gtk_expander_set_property (GObject *object,
|
||||||
@ -173,12 +173,8 @@ static void gtk_expander_get_property (GObject *object,
|
|||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
|
|
||||||
static void gtk_expander_destroy (GtkWidget *widget);
|
static void gtk_expander_destroy (GtkWidget *widget);
|
||||||
static void gtk_expander_realize (GtkWidget *widget);
|
|
||||||
static void gtk_expander_unrealize (GtkWidget *widget);
|
|
||||||
static void gtk_expander_size_allocate (GtkWidget *widget,
|
static void gtk_expander_size_allocate (GtkWidget *widget,
|
||||||
GtkAllocation *allocation);
|
GtkAllocation *allocation);
|
||||||
static void gtk_expander_map (GtkWidget *widget);
|
|
||||||
static void gtk_expander_unmap (GtkWidget *widget);
|
|
||||||
static void gtk_expander_snapshot (GtkWidget *widget,
|
static void gtk_expander_snapshot (GtkWidget *widget,
|
||||||
GtkSnapshot *snapshot);
|
GtkSnapshot *snapshot);
|
||||||
|
|
||||||
@ -225,6 +221,11 @@ static void gtk_expander_state_flags_changed (GtkWidget *widget,
|
|||||||
GtkStateFlags previous_state);
|
GtkStateFlags previous_state);
|
||||||
|
|
||||||
/* Gestures */
|
/* Gestures */
|
||||||
|
static void gesture_multipress_pressed_cb (GtkGestureMultiPress *gesture,
|
||||||
|
gint n_press,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
GtkExpander *expander);
|
||||||
static void gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
|
static void gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
|
||||||
gint n_press,
|
gint n_press,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
@ -262,11 +263,7 @@ gtk_expander_class_init (GtkExpanderClass *klass)
|
|||||||
gobject_class->get_property = gtk_expander_get_property;
|
gobject_class->get_property = gtk_expander_get_property;
|
||||||
|
|
||||||
widget_class->destroy = gtk_expander_destroy;
|
widget_class->destroy = gtk_expander_destroy;
|
||||||
widget_class->realize = gtk_expander_realize;
|
|
||||||
widget_class->unrealize = gtk_expander_unrealize;
|
|
||||||
widget_class->size_allocate = gtk_expander_size_allocate;
|
widget_class->size_allocate = gtk_expander_size_allocate;
|
||||||
widget_class->map = gtk_expander_map;
|
|
||||||
widget_class->unmap = gtk_expander_unmap;
|
|
||||||
widget_class->snapshot = gtk_expander_snapshot;
|
widget_class->snapshot = gtk_expander_snapshot;
|
||||||
widget_class->enter_notify_event = gtk_expander_enter_notify;
|
widget_class->enter_notify_event = gtk_expander_enter_notify;
|
||||||
widget_class->leave_notify_event = gtk_expander_leave_notify;
|
widget_class->leave_notify_event = gtk_expander_leave_notify;
|
||||||
@ -370,7 +367,6 @@ gtk_expander_init (GtkExpander *expander)
|
|||||||
gtk_widget_set_has_window (GTK_WIDGET (expander), FALSE);
|
gtk_widget_set_has_window (GTK_WIDGET (expander), FALSE);
|
||||||
|
|
||||||
priv->label_widget = NULL;
|
priv->label_widget = NULL;
|
||||||
priv->event_window = NULL;
|
|
||||||
priv->spacing = 0;
|
priv->spacing = 0;
|
||||||
|
|
||||||
priv->expanded = FALSE;
|
priv->expanded = FALSE;
|
||||||
@ -403,6 +399,8 @@ gtk_expander_init (GtkExpander *expander)
|
|||||||
GDK_BUTTON_PRIMARY);
|
GDK_BUTTON_PRIMARY);
|
||||||
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture),
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->multipress_gesture),
|
||||||
FALSE);
|
FALSE);
|
||||||
|
g_signal_connect (priv->multipress_gesture, "pressed",
|
||||||
|
G_CALLBACK (gesture_multipress_pressed_cb), expander);
|
||||||
g_signal_connect (priv->multipress_gesture, "released",
|
g_signal_connect (priv->multipress_gesture, "released",
|
||||||
G_CALLBACK (gesture_multipress_released_cb), expander);
|
G_CALLBACK (gesture_multipress_released_cb), expander);
|
||||||
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture),
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->multipress_gesture),
|
||||||
@ -524,39 +522,6 @@ gtk_expander_destroy (GtkWidget *widget)
|
|||||||
g_clear_object (&priv->gadget);
|
g_clear_object (&priv->gadget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_expander_realize (GtkWidget *widget)
|
|
||||||
{
|
|
||||||
GtkAllocation allocation;
|
|
||||||
GtkExpanderPrivate *priv;
|
|
||||||
|
|
||||||
priv = GTK_EXPANDER (widget)->priv;
|
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_expander_parent_class)->realize (widget);
|
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
|
||||||
|
|
||||||
priv->event_window = gdk_window_new_input (gtk_widget_get_window (widget),
|
|
||||||
GDK_ALL_EVENTS_MASK,
|
|
||||||
&allocation);
|
|
||||||
gtk_widget_register_window (widget, priv->event_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_expander_unrealize (GtkWidget *widget)
|
|
||||||
{
|
|
||||||
GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
|
|
||||||
|
|
||||||
if (priv->event_window)
|
|
||||||
{
|
|
||||||
gtk_widget_unregister_window (widget, priv->event_window);
|
|
||||||
gdk_window_destroy (priv->event_window);
|
|
||||||
priv->event_window = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_expander_parent_class)->unrealize (widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_expander_size_allocate (GtkWidget *widget,
|
gtk_expander_size_allocate (GtkWidget *widget,
|
||||||
GtkAllocation *allocation)
|
GtkAllocation *allocation)
|
||||||
@ -572,40 +537,6 @@ gtk_expander_size_allocate (GtkWidget *widget,
|
|||||||
&clip);
|
&clip);
|
||||||
|
|
||||||
gtk_widget_set_clip (widget, &clip);
|
gtk_widget_set_clip (widget, &clip);
|
||||||
|
|
||||||
if (gtk_widget_get_realized (widget))
|
|
||||||
{
|
|
||||||
GtkAllocation title_allocation;
|
|
||||||
|
|
||||||
gtk_widget_get_allocation (priv->title_widget, &title_allocation);
|
|
||||||
gdk_window_move_resize (priv->event_window,
|
|
||||||
title_allocation.x, title_allocation.y,
|
|
||||||
title_allocation.width, title_allocation.height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_expander_map (GtkWidget *widget)
|
|
||||||
{
|
|
||||||
GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
|
|
||||||
|
|
||||||
gtk_widget_map (priv->title_widget);
|
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_expander_parent_class)->map (widget);
|
|
||||||
|
|
||||||
if (priv->event_window)
|
|
||||||
gdk_window_show (priv->event_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_expander_unmap (GtkWidget *widget)
|
|
||||||
{
|
|
||||||
GtkExpanderPrivate *priv = GTK_EXPANDER (widget)->priv;
|
|
||||||
|
|
||||||
if (priv->event_window)
|
|
||||||
gdk_window_hide (priv->event_window);
|
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_expander_parent_class)->unmap (widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -615,6 +546,30 @@ gtk_expander_snapshot (GtkWidget *widget,
|
|||||||
gtk_css_gadget_snapshot (GTK_EXPANDER (widget)->priv->gadget, snapshot);
|
gtk_css_gadget_snapshot (GTK_EXPANDER (widget)->priv->gadget, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gesture_multipress_pressed_cb (GtkGestureMultiPress *gesture,
|
||||||
|
gint n_press,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
GtkExpander *expander)
|
||||||
|
{
|
||||||
|
GtkExpanderPrivate *priv = expander->priv;
|
||||||
|
GtkAllocation title_allocation, allocation;
|
||||||
|
|
||||||
|
gtk_widget_get_allocation (GTK_WIDGET (expander), &allocation);
|
||||||
|
gtk_widget_get_allocation (priv->title_widget, &title_allocation);
|
||||||
|
/* Coordinates are in the widget coordinate system, so transform
|
||||||
|
* the title_allocation to it.
|
||||||
|
*/
|
||||||
|
title_allocation.x -= allocation.x;
|
||||||
|
title_allocation.y -= allocation.y;
|
||||||
|
|
||||||
|
priv->pressed_in_title = (x >= title_allocation.x &&
|
||||||
|
x < title_allocation.x + title_allocation.width &&
|
||||||
|
y >= title_allocation.y &&
|
||||||
|
y < title_allocation.y + title_allocation.height);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
|
gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
|
||||||
gint n_press,
|
gint n_press,
|
||||||
@ -622,7 +577,7 @@ gesture_multipress_released_cb (GtkGestureMultiPress *gesture,
|
|||||||
gdouble y,
|
gdouble y,
|
||||||
GtkExpander *expander)
|
GtkExpander *expander)
|
||||||
{
|
{
|
||||||
if (expander->priv->prelight)
|
if (expander->priv->pressed_in_title)
|
||||||
gtk_widget_activate (GTK_WIDGET (expander));
|
gtk_widget_activate (GTK_WIDGET (expander));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,8 +619,7 @@ gtk_expander_enter_notify (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||||
|
|
||||||
if (event->window == expander->priv->event_window &&
|
if (event->detail != GDK_NOTIFY_INFERIOR)
|
||||||
event->detail != GDK_NOTIFY_INFERIOR)
|
|
||||||
{
|
{
|
||||||
expander->priv->prelight = TRUE;
|
expander->priv->prelight = TRUE;
|
||||||
|
|
||||||
@ -686,8 +640,7 @@ gtk_expander_leave_notify (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||||
|
|
||||||
if (event->window == expander->priv->event_window &&
|
if (event->detail != GDK_NOTIFY_INFERIOR)
|
||||||
event->detail != GDK_NOTIFY_INFERIOR)
|
|
||||||
{
|
{
|
||||||
expander->priv->prelight = FALSE;
|
expander->priv->prelight = FALSE;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user