[gtk/wip/otte/dnd: 8/9] colorbutton, colorswatch: Simplify DND
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/dnd: 8/9] colorbutton, colorswatch: Simplify DND
- Date: Sun, 16 Feb 2020 19:14:00 +0000 (UTC)
commit f1c2b3b8e645e6e12847745bcb2251784da4bc65
Author: Benjamin Otte <otte redhat com>
Date: Sun Feb 16 18:48:45 2020 +0100
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
gtk/gtkcolorbutton.c | 19 ++++++-------------
gtk/gtkcolorswatch.c | 20 +++++---------------
2 files changed, 11 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 4d304c1a46..91a96301c6 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -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);
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index 4a2ad7e93b..b59c49862b 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]