#include <gdk/gdkdisplaymanager.h>
#include <gdk/gdkdnd.h>
#include <gdk/gdkdrawcontext.h>
+#include <gdk/gdkdrop.h>
#include <gdk/gdkenumtypes.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkframeclock.h>
#include "gdkenumtypes.h"
#include "gdkeventsprivate.h"
+#define DROP_SUBCLASS 1
+
typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
struct _GdkDragContextPrivate
{
+#ifndef DROP_SUBCLASS
GdkDisplay *display;
GdkDevice *device;
+#endif
GdkContentFormats *formats;
};
enum {
PROP_0,
PROP_CONTENT,
+#ifndef DROP_SUBCLASS
PROP_DEVICE,
PROP_DISPLAY,
PROP_FORMATS,
+#endif
N_PROPERTIES
};
static guint signals[N_SIGNALS] = { 0 };
static GList *contexts = NULL;
-G_DEFINE_TYPE_WITH_PRIVATE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GdkDragContext, gdk_drag_context, GDK_TYPE_DROP)
/**
* SECTION:dnd
GdkDisplay *
gdk_drag_context_get_display (GdkDragContext *context)
{
+#ifdef DROP_SUBCLASS
+ return gdk_drop_get_display (GDK_DROP (context));
+#else
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
return priv->display;
+#endif
}
/**
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
+#ifdef DROP_SUBCLASS
+ GdkContentFormats *formats = gdk_drop_get_formats (GDK_DROP (context));
+
+ if (formats)
+ return formats;
+#endif
return priv->formats;
}
GdkDevice *
gdk_drag_context_get_device (GdkDragContext *context)
{
+#ifdef DROP_SUBCLASS
+ return gdk_drop_get_device (GDK_DROP (context));
+#else
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
return priv->device;
+#endif
}
static void
}
break;
+#ifndef DROP_SUBCLASS
case PROP_DEVICE:
priv->device = g_value_dup_object (value);
g_assert (priv->device != NULL);
g_assert (priv->formats != NULL);
}
break;
+#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
GParamSpec *pspec)
{
GdkDragContext *context = GDK_DRAG_CONTEXT (gobject);
+#ifndef DROP_SUBCLASS
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
+#endif
switch (prop_id)
{
g_value_set_object (value, context->content);
break;
+#ifndef DROP_SUBCLASS
case PROP_DEVICE:
g_value_set_object (value, priv->device);
break;
case PROP_FORMATS:
g_value_set_boxed (value, priv->formats);
break;
+#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
+#ifndef DROP_SUBCLASS
/**
* GdkDragContext:device:
*
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
+#endif
/**
* GdkDragContext::cancel:
#include "gdkdnd.h"
+#include "gdkdropprivate.h"
+
G_BEGIN_DECLS
struct _GdkDragContextClass {
- GObjectClass parent_class;
+ GdkDropClass parent_class;
void (*drag_status) (GdkDragContext *context,
GdkDragAction action,
};
struct _GdkDragContext {
- GObject parent_instance;
+ GdkDrop parent_instance;
/*< private >*/
gboolean is_source;
--- /dev/null
+/*
+ * Copyright © 2018 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#include "config.h"
+
+#include "gdkdndprivate.h"
+#include "gdkdisplay.h"
+#include "gdksurface.h"
+#include "gdkintl.h"
+#include "gdkcontentformats.h"
+#include "gdkcontentprovider.h"
+#include "gdkcontentserializer.h"
+#include "gdkcursor.h"
+#include "gdkenumtypes.h"
+#include "gdkeventsprivate.h"
+
+typedef struct _GdkDropPrivate GdkDropPrivate;
+
+struct _GdkDropPrivate {
+ GdkDevice *device;
+ GdkContentFormats *formats;
+};
+
+enum {
+ PROP_0,
+ PROP_DEVICE,
+ PROP_DISPLAY,
+ PROP_FORMATS,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
+
+/**
+ * GdkDrop:
+ *
+ * The GdkDrop struct contains only private fields and
+ * should not be accessed directly.
+ */
+
+static void
+gdk_drop_init (GdkDrop *self)
+{
+}
+
+static void
+gdk_drop_set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDrop *self = GDK_DROP (gobject);
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_DEVICE:
+ priv->device = g_value_dup_object (value);
+ g_assert (priv->device != NULL);
+ break;
+
+ case PROP_FORMATS:
+ priv->formats = g_value_dup_boxed (value);
+#ifdef DROP_SUBCLASS
+ g_assert (priv->formats != NULL);
+#endif
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_drop_get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDrop *self = GDK_DROP (gobject);
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_DEVICE:
+ g_value_set_object (value, priv->device);
+ break;
+
+ case PROP_DISPLAY:
+ g_value_set_object (value, gdk_device_get_display (priv->device));
+ break;
+
+ case PROP_FORMATS:
+ g_value_set_boxed (value, priv->formats);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_drop_finalize (GObject *object)
+{
+ GdkDrop *self = GDK_DROP (object);
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ g_clear_object (&priv->device);
+
+ G_OBJECT_CLASS (gdk_drop_parent_class)->finalize (object);
+}
+
+static void
+gdk_drop_class_init (GdkDropClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gdk_drop_get_property;
+ object_class->set_property = gdk_drop_set_property;
+ object_class->finalize = gdk_drop_finalize;
+
+ /**
+ * GdkDrop:device:
+ *
+ * The #GdkDevice performing the drop
+ */
+ properties[PROP_DEVICE] =
+ g_param_spec_object ("device",
+ "Device",
+ "The device performing the drop",
+ GDK_TYPE_DEVICE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GdkDrop:display:
+ *
+ * The #GdkDisplay that the drop belongs to.
+ */
+ properties[PROP_DISPLAY] =
+ g_param_spec_object ("display",
+ "Display",
+ "Display this drag belongs to",
+ GDK_TYPE_DISPLAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GdkDrop:formats:
+ *
+ * The possible formats that the drop can provide its data in.
+ */
+ properties[PROP_FORMATS] =
+ g_param_spec_boxed ("formats",
+ "Formats",
+ "The possible formats for data",
+ GDK_TYPE_CONTENT_FORMATS,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+/**
+ * gdk_drop_get_display:
+ * @self: a #GdkDrop
+ *
+ * Gets the #GdkDisplay that @self was created for.
+ *
+ * Returns: (transfer none): a #GdkDisplay
+ **/
+GdkDisplay *
+gdk_drop_get_display (GdkDrop *self)
+{
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ g_return_val_if_fail (GDK_IS_DROP (self), NULL);
+
+ return gdk_device_get_display (priv->device);
+}
+
+/**
+ * gdk_drop_get_device:
+ * @self: a #GdkDrop
+ *
+ * Returns the #GdkDevice performing the drop.
+ *
+ * Returns: (transfer none): The #GdkDevice performing the drop.
+ **/
+GdkDevice *
+gdk_drop_get_device (GdkDrop *self)
+{
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ g_return_val_if_fail (GDK_IS_DROP (self), NULL);
+
+ return priv->device;
+}
+
+/**
+ * gdk_drop_get_formats:
+ * @self: a #GdkDrop
+ *
+ * Returns the #GdkContentFormats that the drop offers the data
+ * to be read in.
+ *
+ * Returns: (transfer none): The possible #GdkContentFormats
+ **/
+GdkContentFormats *
+gdk_drop_get_formats (GdkDrop *self)
+{
+ GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+ g_return_val_if_fail (GDK_IS_DROP (self), NULL);
+
+ return priv->formats;
+}
+
--- /dev/null
+/*
+ * Copyright © 2018 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+
+#ifndef __GDK_DROP_H__
+#define __GDK_DROP_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdktypes.h>
+#include <gdk/gdkversionmacros.h>
+
+G_BEGIN_DECLS
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkDrop, g_object_unref)
+
+#define GDK_TYPE_DROP (gdk_drop_get_type ())
+#define GDK_DROP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_DROP, GdkDrop))
+#define GDK_IS_DROP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_DROP))
+
+GDK_AVAILABLE_IN_ALL
+GType gdk_drop_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_ALL
+GdkDisplay * gdk_drop_get_display (GdkDrop *self);
+GDK_AVAILABLE_IN_ALL
+GdkDevice * gdk_drop_get_device (GdkDrop *self);
+GDK_AVAILABLE_IN_ALL
+GdkContentFormats * gdk_drop_get_formats (GdkDrop *self);
+
+G_END_DECLS
+
+#endif /* __GDK_DROP_H__ */
--- /dev/null
+/*
+ * Copyright © 2018 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#ifndef __GDK_DROP_PRIVATE_H__
+#define __GDK_DROP_PRIVATE_H__
+
+#include "gdkdrop.h"
+
+G_BEGIN_DECLS
+
+
+#define GDK_DROP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_DROP, GdkDropClass))
+#define GDK_IS_DROP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_DROP))
+#define GDK_DROP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_DROP, GdkDropClass))
+
+typedef struct _GdkDropClass GdkDropClass;
+
+
+struct _GdkDrop {
+ GObject parent_instance;
+};
+
+struct _GdkDropClass {
+ GObjectClass parent_class;
+};
+
+
+G_END_DECLS
+
+#endif
typedef struct _GdkTexture GdkTexture;
typedef struct _GdkDevice GdkDevice;
typedef struct _GdkDragContext GdkDragContext;
+typedef struct _GdkDrop GdkDrop;
typedef struct _GdkClipboard GdkClipboard;
typedef struct _GdkDisplayManager GdkDisplayManager;
'gdkdisplaymanager.c',
'gdkdnd.c',
'gdkdrawcontext.c',
+ 'gdkdrop.c',
'gdkevents.c',
'gdkframeclock.c',
'gdkframeclockidle.c',
'gdkdisplaymanager.h',
'gdkdnd.h',
'gdkdrawcontext.h',
+ 'gdkdrop.h',
'gdkevents.h',
'gdkframeclock.h',
'gdkframetimings.h',
NULL);
gdk_content_formats_unref (formats);
}
+ else if (g_str_equal (g_type_name (type), "GdkDrop"))
+ {
+ GdkContentFormats *formats = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
+ instance = g_object_new (type,
+ "device", gdk_seat_get_pointer (gdk_display_get_default_seat (gdk_display_get_default ())),
+ "formats", formats,
+ NULL);
+ gdk_content_formats_unref (formats);
+ }
else
instance = g_object_new (type, NULL);
if (g_str_equal (g_type_name (test_type), "GdkClipboard"))
object = g_object_new (test_type, "display", gdk_display_get_default (), NULL);
- else if (g_str_equal (g_type_name (test_type), "GdkDragContext"))
+ else if (g_str_equal (g_type_name (test_type), "GdkDragContext") ||
+ g_str_equal (g_type_name (test_type), "GdkDrop"))
{
GdkContentFormats *formats = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
object = g_object_new (test_type,