forked from AuroraMiddleware/gtk
colorbutton, colorswatch: Simplify DND
- Use GDK_TYPE_RGBA and let GDK do the conversion from application-x-color - Don't do extra mime type checks when accept() does that for us already
This commit is contained in:
parent
3a7e3cf90d
commit
91d91a29e8
@ -126,8 +126,6 @@ static void gtk_color_button_clicked (GtkButton *button,
|
||||
|
||||
static guint color_button_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static const char *drop_types[] = { "application/x-color" };
|
||||
|
||||
static void gtk_color_button_iface_init (GtkColorChooserInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_WIDGET,
|
||||
@ -258,13 +256,8 @@ gtk_color_button_drag_drop (GtkDropTarget *dest,
|
||||
int y,
|
||||
GtkColorButton *button)
|
||||
{
|
||||
if (gdk_drop_has_value (drop, GDK_TYPE_RGBA))
|
||||
{
|
||||
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, button);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, button);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -302,7 +295,7 @@ gtk_color_button_init (GtkColorButton *button)
|
||||
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
|
||||
PangoLayout *layout;
|
||||
PangoRectangle rect;
|
||||
GdkContentFormats *targets;
|
||||
GdkContentFormats *formats;
|
||||
GtkDragSource *source;
|
||||
GtkDropTarget *dest;
|
||||
|
||||
@ -328,11 +321,11 @@ gtk_color_button_init (GtkColorButton *button)
|
||||
priv->rgba.alpha = 1;
|
||||
priv->use_alpha = FALSE;
|
||||
|
||||
targets = gdk_content_formats_new (drop_types, G_N_ELEMENTS (drop_types));
|
||||
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
|
||||
formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
|
||||
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
|
||||
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_color_button_drag_drop), button);
|
||||
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
|
||||
gdk_content_formats_unref (targets);
|
||||
gdk_content_formats_unref (formats);
|
||||
|
||||
source = gtk_drag_source_new ();
|
||||
g_signal_connect (source, "prepare", G_CALLBACK (gtk_color_button_drag_prepare), button);
|
||||
|
@ -159,13 +159,8 @@ swatch_drag_drop (GtkDropTarget *dest,
|
||||
int y,
|
||||
GtkColorSwatch *swatch)
|
||||
{
|
||||
if (gdk_drop_has_value (drop, GDK_TYPE_RGBA))
|
||||
{
|
||||
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, swatch);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, swatch);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -574,10 +569,6 @@ gtk_color_swatch_new (void)
|
||||
return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SWATCH, NULL);
|
||||
}
|
||||
|
||||
static const char *dnd_targets[] = {
|
||||
"application/x-color"
|
||||
};
|
||||
|
||||
static GdkContentProvider *
|
||||
gtk_color_swatch_drag_prepare (GtkDragSource *source,
|
||||
double x,
|
||||
@ -670,13 +661,12 @@ gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
||||
|
||||
if (can_drop && !priv->dest)
|
||||
{
|
||||
GdkContentFormats *targets;
|
||||
GdkContentFormats *formats;
|
||||
|
||||
targets = gdk_content_formats_new (dnd_targets, G_N_ELEMENTS (dnd_targets));
|
||||
priv->dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
|
||||
formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
|
||||
priv->dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
|
||||
g_signal_connect (priv->dest, "drag-drop", G_CALLBACK (swatch_drag_drop), swatch);
|
||||
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
|
||||
gdk_content_formats_unref (targets);
|
||||
}
|
||||
if (!can_drop && priv->dest)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user