color-swatch: make this a no-window widget
Instead of having an input/output GdkWindow, make the widget no-window, and use a separate input-only window for events, and paint on the parent window directly.
This commit is contained in:
parent
8e4b17738e
commit
9160a68c7f
@ -44,6 +44,8 @@ struct _GtkColorSwatchPrivate
|
|||||||
guint contains_pointer : 1;
|
guint contains_pointer : 1;
|
||||||
guint use_alpha : 1;
|
guint use_alpha : 1;
|
||||||
guint selectable : 1;
|
guint selectable : 1;
|
||||||
|
|
||||||
|
GdkWindow *event_window;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -72,11 +74,8 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
|
|||||||
GtkColorSwatchPrivate);
|
GtkColorSwatchPrivate);
|
||||||
|
|
||||||
gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
|
gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
|
||||||
gtk_widget_set_events (GTK_WIDGET (swatch), GDK_BUTTON_PRESS_MASK
|
gtk_widget_set_has_window (GTK_WIDGET (swatch), FALSE);
|
||||||
| GDK_BUTTON_RELEASE_MASK
|
|
||||||
| GDK_EXPOSURE_MASK
|
|
||||||
| GDK_ENTER_NOTIFY_MASK
|
|
||||||
| GDK_LEAVE_NOTIFY_MASK);
|
|
||||||
swatch->priv->use_alpha = TRUE;
|
swatch->priv->use_alpha = TRUE;
|
||||||
swatch->priv->selectable = TRUE;
|
swatch->priv->selectable = TRUE;
|
||||||
}
|
}
|
||||||
@ -510,32 +509,93 @@ swatch_button_release (GtkWidget *widget,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
swatch_map (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->map (widget);
|
||||||
|
|
||||||
|
if (swatch->priv->event_window)
|
||||||
|
gdk_window_show (swatch->priv->event_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
swatch_unmap (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||||
|
|
||||||
|
if (swatch->priv->event_window)
|
||||||
|
gdk_window_hide (swatch->priv->event_window);
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->unmap (widget);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
swatch_realize (GtkWidget *widget)
|
swatch_realize (GtkWidget *widget)
|
||||||
{
|
{
|
||||||
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
GdkWindowAttr attributes;
|
GdkWindowAttr attributes;
|
||||||
gint attributes_mask;
|
gint attributes_mask;
|
||||||
|
|
||||||
gtk_widget_set_realized (widget, TRUE);
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
gtk_widget_set_realized (widget, TRUE);
|
||||||
|
|
||||||
attributes.window_type = GDK_WINDOW_CHILD;
|
attributes.window_type = GDK_WINDOW_CHILD;
|
||||||
attributes.x = allocation.x;
|
attributes.x = allocation.x;
|
||||||
attributes.y = allocation.y;
|
attributes.y = allocation.y;
|
||||||
attributes.width = allocation.width;
|
attributes.width = allocation.width;
|
||||||
attributes.height = allocation.height;
|
attributes.height = allocation.height;
|
||||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
attributes.wclass = GDK_INPUT_ONLY;
|
||||||
attributes.visual = gtk_widget_get_visual (widget);
|
attributes.event_mask = gtk_widget_get_events (widget);
|
||||||
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
|
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
|
||||||
|
GDK_BUTTON_RELEASE_MASK |
|
||||||
|
GDK_ENTER_NOTIFY_MASK |
|
||||||
|
GDK_LEAVE_NOTIFY_MASK);
|
||||||
|
|
||||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
|
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
||||||
|
|
||||||
window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
window = gtk_widget_get_parent_window (widget);
|
||||||
&attributes, attributes_mask);
|
|
||||||
gdk_window_set_user_data (window, widget);
|
|
||||||
gtk_widget_set_window (widget, window);
|
gtk_widget_set_window (widget, window);
|
||||||
|
g_object_ref (window);
|
||||||
|
|
||||||
|
swatch->priv->event_window =
|
||||||
|
gdk_window_new (window,
|
||||||
|
&attributes, attributes_mask);
|
||||||
|
gdk_window_set_user_data (swatch->priv->event_window, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
swatch_unrealize (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||||
|
|
||||||
|
if (swatch->priv->event_window)
|
||||||
|
{
|
||||||
|
gdk_window_set_user_data (swatch->priv->event_window, NULL);
|
||||||
|
gdk_window_destroy (swatch->priv->event_window);
|
||||||
|
swatch->priv->event_window = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->unrealize (widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
swatch_size_allocate (GtkWidget *widget,
|
||||||
|
GtkAllocation *allocation)
|
||||||
|
{
|
||||||
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||||
|
|
||||||
|
gtk_widget_set_allocation (widget, allocation);
|
||||||
|
|
||||||
|
if (gtk_widget_get_realized (widget))
|
||||||
|
gdk_window_move_resize (swatch->priv->event_window,
|
||||||
|
allocation->x,
|
||||||
|
allocation->y,
|
||||||
|
allocation->width,
|
||||||
|
allocation->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -626,6 +686,10 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
|
|||||||
widget_class->enter_notify_event = swatch_enter_notify;
|
widget_class->enter_notify_event = swatch_enter_notify;
|
||||||
widget_class->leave_notify_event = swatch_leave_notify;
|
widget_class->leave_notify_event = swatch_leave_notify;
|
||||||
widget_class->realize = swatch_realize;
|
widget_class->realize = swatch_realize;
|
||||||
|
widget_class->unrealize = swatch_unrealize;
|
||||||
|
widget_class->map = swatch_map;
|
||||||
|
widget_class->unmap = swatch_unmap;
|
||||||
|
widget_class->size_allocate = swatch_size_allocate;
|
||||||
|
|
||||||
signals[ACTIVATE] =
|
signals[ACTIVATE] =
|
||||||
g_signal_new ("activate",
|
g_signal_new ("activate",
|
||||||
|
Loading…
Reference in New Issue
Block a user