[gimp] libgimpwidgets: new gimp_color_area_enable_drag() API.



commit f50976d81b9145d83e9f08f31f12bce38df77b9a
Author: Jehan <jehan girinstud io>
Date:   Thu Feb 17 17:04:49 2022 +0100

    libgimpwidgets: new gimp_color_area_enable_drag() API.
    
    This would allow to enable, configure or disable drag ability of a
    GimpColorArea ater its creation.
    
    I tested that it works correctly in binding. For instance in Python:
    
    > area.enable_drag(0)
    > area.enable_drag(Gdk.ModifierType.BUTTON1_MASK |
    >                  Gdk.ModifierType.BUTTON2_MASK)
    
    … correctly disable then reanable the drag with buttons 1 and 2 (in
    particular, I wanted to verify there was any reason why the property was
    G_PARAM_CONSTRUCT_ONLY. Turns out there was no good reason).
    
    I was interested by such API because having long list of parameters in
    various APIs is very annoying. It is much nicer to have simple
    constructors with decent defaults and proper API to modify a widget
    afterwards in order to cater to special needs.

 libgimpwidgets/gimpcolorarea.c | 26 ++++++++++++++++++++++++--
 libgimpwidgets/gimpcolorarea.h |  2 ++
 2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorarea.c b/libgimpwidgets/gimpcolorarea.c
index ffa334e70e..d29bcd9b7a 100644
--- a/libgimpwidgets/gimpcolorarea.c
+++ b/libgimpwidgets/gimpcolorarea.c
@@ -216,8 +216,7 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
                                                        "The modifier mask that triggers dragging the color",
                                                        GDK_TYPE_MODIFIER_TYPE,
                                                        0,
-                                                       GIMP_PARAM_WRITABLE |
-                                                       G_PARAM_CONSTRUCT_ONLY));
+                                                       GIMP_PARAM_WRITABLE));
   /**
    * GimpColorArea:draw-border:
    *
@@ -336,6 +335,8 @@ gimp_color_area_set_property (GObject      *object,
                              drag_mask,
                              &target, 1,
                              GDK_ACTION_COPY | GDK_ACTION_MOVE);
+      else
+        gtk_drag_source_unset (GTK_WIDGET (area));
       break;
 
     case PROP_DRAW_BORDER:
@@ -624,6 +625,27 @@ gimp_color_area_set_type (GimpColorArea     *area,
     }
 }
 
+/**
+ * gimp_color_area_enable_drag:
+ * @area:      A #GimpColorArea.
+ * @drag_mask: The bitmask of buttons that can start the drag.
+ *
+ * Allows dragging the color displayed with buttons identified by
+ * @drag_mask. The drag supports targets of type "application/x-color".
+ *
+ * Note that setting a @drag_mask of 0 disables the drag ability.
+ **/
+void
+gimp_color_area_enable_drag (GimpColorArea   *area,
+                             GdkModifierType  drag_mask)
+{
+  g_return_if_fail (GIMP_IS_COLOR_AREA (area));
+
+  g_object_set (area,
+                "drag-mask", drag_mask,
+                NULL);
+}
+
 /**
  * gimp_color_area_set_draw_border:
  * @area: Pointer to a #GimpColorArea.
diff --git a/libgimpwidgets/gimpcolorarea.h b/libgimpwidgets/gimpcolorarea.h
index 693ae4e159..09d01b6b63 100644
--- a/libgimpwidgets/gimpcolorarea.h
+++ b/libgimpwidgets/gimpcolorarea.h
@@ -84,6 +84,8 @@ void        gimp_color_area_get_color        (GimpColorArea     *area,
 gboolean    gimp_color_area_has_alpha        (GimpColorArea     *area);
 void        gimp_color_area_set_type         (GimpColorArea     *area,
                                               GimpColorAreaType  type);
+void        gimp_color_area_enable_drag      (GimpColorArea     *area,
+                                              GdkModifierType    drag_mask);
 void        gimp_color_area_set_draw_border  (GimpColorArea     *area,
                                               gboolean           draw_border);
 void        gimp_color_area_set_out_of_gamut (GimpColorArea     *area,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]