]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorplane.c
Small documentation tweak
[~andy/gtk] / gtk / gtkcolorplane.c
index ab50610c46001ec2030895c2ebf568b3cd78ce03..33dc0260c4129dc215526ad131c79c08a2ba66e3 100644 (file)
  * 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"
 
-#include "gtkcolorplane.h"
-#include "gtkcolorutils.h"
+#include "gtkcolorplaneprivate.h"
+
 #include "gtkaccessible.h"
+#include "gtkadjustment.h"
+#include "gtkcolorutils.h"
+#include "gtkpressandholdprivate.h"
 #include "gtkintl.h"
 
 struct _GtkColorPlanePrivate
@@ -32,6 +33,8 @@ struct _GtkColorPlanePrivate
 
   cairo_surface_t *surface;
   gboolean in_drag;
+
+  GtkPressAndHold *press_and_hold;
 };
 
 G_DEFINE_TYPE (GtkColorPlane, gtk_color_plane, GTK_TYPE_DRAWING_AREA)
@@ -285,6 +288,48 @@ plane_motion_notify (GtkWidget      *widget,
   return TRUE;
 }
 
+static void
+hold_action (GtkPressAndHold *pah,
+             gint             x,
+             gint             y,
+             GtkColorPlane   *plane)
+{
+  gboolean handled;
+
+  g_signal_emit_by_name (plane, "popup-menu", &handled);
+}
+
+static gboolean
+plane_touch (GtkWidget     *widget,
+             GdkEventTouch *event)
+{
+  GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
+
+  if (!plane->priv->press_and_hold)
+    {
+      gint drag_threshold;
+
+      g_object_get (gtk_widget_get_settings (widget),
+                    "gtk-dnd-drag-threshold", &drag_threshold,
+                    NULL);
+
+      plane->priv->press_and_hold = gtk_press_and_hold_new ();
+
+      g_object_set (plane->priv->press_and_hold,
+                    "drag-threshold", drag_threshold,
+                    "hold-time", 1000,
+                    NULL);
+
+      g_signal_connect (plane->priv->press_and_hold, "hold",
+                        G_CALLBACK (hold_action), plane);
+    }
+
+  gtk_press_and_hold_process_event (plane->priv->press_and_hold, (GdkEvent *)event);
+  update_color (plane, event->x, event->y);
+
+  return TRUE;
+}
+
 static void
 sv_move (GtkColorPlane *plane,
          gdouble        ds,
@@ -382,6 +427,7 @@ gtk_color_plane_init (GtkColorPlane *plane)
 
   gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE);
   gtk_widget_set_events (GTK_WIDGET (plane), GDK_KEY_PRESS_MASK
+                                             | GDK_TOUCH_MASK
                                              | GDK_BUTTON_PRESS_MASK
                                              | GDK_BUTTON_RELEASE_MASK
                                              | GDK_POINTER_MOTION_MASK);
@@ -406,6 +452,8 @@ plane_finalize (GObject *object)
   g_clear_object (&plane->priv->s_adj);
   g_clear_object (&plane->priv->v_adj);
 
+  g_clear_object (&plane->priv->press_and_hold);
+
   G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object);
 }
 
@@ -424,6 +472,7 @@ gtk_color_plane_class_init (GtkColorPlaneClass *class)
   widget_class->motion_notify_event = plane_motion_notify;
   widget_class->grab_broken_event = plane_grab_broken;
   widget_class->key_press_event = plane_key_press;
+  widget_class->touch_event = plane_touch;
 
   g_type_class_add_private (class, sizeof (GtkColorPlanePrivate));
 }