]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorscale.c
filechooserbutton: Do not propagate state from the dialog unless it is active
[~andy/gtk] / gtk / gtkcolorscale.c
index d7fde5aa1d85c0a9960b61e5cd88caac13794966..88e4459b59441b8886d0cb51f86ec27670d5d674 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -26,6 +24,7 @@
 #include "gtkorientable.h"
 #include "gtkstylecontext.h"
 #include "gtkaccessible.h"
+#include "gtkpressandholdprivate.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -37,6 +36,8 @@ struct _GtkColorScalePrivate
   gint width, height;
   GdkRGBA color;
   GtkColorScaleType type;
+
+  GtkPressAndHold *press_and_hold;
 };
 
 enum
@@ -250,6 +251,7 @@ gtk_color_scale_init (GtkColorScale *scale)
   scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale,
                                              GTK_TYPE_COLOR_SCALE,
                                              GtkColorScalePrivate);
+  gtk_widget_add_events (GTK_WIDGET (scale), GDK_TOUCH_MASK);
 }
 
 static void
@@ -260,6 +262,8 @@ scale_finalize (GObject *object)
   if (scale->priv->surface)
     cairo_surface_destroy (scale->priv->surface);
 
+  g_clear_object (&scale->priv->press_and_hold);
+
   G_OBJECT_CLASS (gtk_color_scale_parent_class)->finalize (object);
 }
 
@@ -320,6 +324,48 @@ scale_set_property (GObject      *object,
     }
 }
 
+static void
+hold_action (GtkPressAndHold *pah,
+             gint             x,
+             gint             y,
+             GtkColorScale   *scale)
+{
+  gboolean handled;
+
+  g_signal_emit_by_name (scale, "popup-menu", &handled);
+}
+
+static gboolean
+scale_touch (GtkWidget     *widget,
+             GdkEventTouch *event)
+{
+  GtkColorScale *scale = GTK_COLOR_SCALE (widget);
+
+  if (!scale->priv->press_and_hold)
+    {
+      gint drag_threshold;
+
+      g_object_get (gtk_widget_get_settings (widget),
+                    "gtk-dnd-drag-threshold", &drag_threshold,
+                    NULL);
+
+      scale->priv->press_and_hold = gtk_press_and_hold_new ();
+
+      g_object_set (scale->priv->press_and_hold,
+                    "drag-threshold", drag_threshold,
+                    "hold-time", 1000,
+                    NULL);
+
+      g_signal_connect (scale->priv->press_and_hold, "hold",
+                        G_CALLBACK (hold_action), scale);
+    }
+
+  gtk_press_and_hold_process_event (scale->priv->press_and_hold, (GdkEvent *)event);
+
+  return GTK_WIDGET_CLASS (gtk_color_scale_parent_class)->touch_event (widget, event);
+}
+
+
 static void
 gtk_color_scale_class_init (GtkColorScaleClass *class)
 {
@@ -331,6 +377,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
   object_class->set_property = scale_set_property;
 
   widget_class->draw = scale_draw;
+  widget_class->touch_event = scale_touch;
 
   g_object_class_install_property (object_class, PROP_SCALE_TYPE,
       g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"),