2019-12-30 03:47:26 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright 2019 Matthias Clasen
|
|
|
|
*
|
|
|
|
* 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 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-03-02 01:55:38 +00:00
|
|
|
#include "gtkdragicon.h"
|
2019-12-30 03:47:26 +00:00
|
|
|
|
|
|
|
#include "gtkwidgetprivate.h"
|
2020-01-18 14:57:13 +00:00
|
|
|
#include "gtkcssstyleprivate.h"
|
|
|
|
#include "gtkcsstypesprivate.h"
|
2020-08-13 23:21:05 +00:00
|
|
|
#include "gtknativeprivate.h"
|
2020-01-06 20:47:25 +00:00
|
|
|
#include "gtkpicture.h"
|
2020-05-16 06:01:22 +00:00
|
|
|
#include "gtkcssboxesimplprivate.h"
|
2020-01-18 14:57:13 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2019-12-30 03:47:26 +00:00
|
|
|
|
2021-10-03 06:20:30 +00:00
|
|
|
#include "gdk/gdksurfaceprivate.h"
|
|
|
|
|
2020-03-02 02:11:14 +00:00
|
|
|
/* for the drag icons */
|
|
|
|
#include "gtkcolorswatchprivate.h"
|
2021-08-20 03:51:20 +00:00
|
|
|
#include "gtkimage.h"
|
2020-03-02 02:11:14 +00:00
|
|
|
#include "gtklabel.h"
|
2021-08-20 03:51:20 +00:00
|
|
|
#include "gtkrendernodepaintableprivate.h"
|
2022-10-06 02:59:51 +00:00
|
|
|
#include "gtktextutilprivate.h"
|
2020-03-02 02:11:14 +00:00
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
|
2020-01-09 05:50:33 +00:00
|
|
|
/**
|
2021-02-28 18:02:08 +00:00
|
|
|
* GtkDragIcon:
|
2020-01-09 05:50:33 +00:00
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* `GtkDragIcon` is a `GtkRoot` implementation for drag icons.
|
|
|
|
*
|
2021-03-01 06:32:24 +00:00
|
|
|
* A drag icon moves with the pointer during a Drag-and-Drop operation
|
2021-02-28 18:02:08 +00:00
|
|
|
* and is destroyed when the drag ends.
|
2020-01-09 05:50:33 +00:00
|
|
|
*
|
|
|
|
* To set up a drag icon and associate it with an ongoing drag operation,
|
2021-02-28 18:02:08 +00:00
|
|
|
* use [func@Gtk.DragIcon.get_for_drag] to get the icon for a drag. You can
|
|
|
|
* then use it like any other widget and use [method@Gtk.DragIcon.set_child]
|
|
|
|
* to set whatever widget should be used for the drag icon.
|
2020-03-02 01:55:38 +00:00
|
|
|
*
|
|
|
|
* Keep in mind that drag icons do not allow user input.
|
2020-01-09 05:50:33 +00:00
|
|
|
*/
|
2019-12-30 03:47:26 +00:00
|
|
|
struct _GtkDragIcon
|
|
|
|
{
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
|
|
|
GdkSurface *surface;
|
|
|
|
GskRenderer *renderer;
|
2020-03-01 21:28:39 +00:00
|
|
|
GtkWidget *child;
|
2019-12-30 03:47:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkDragIconClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2020-03-01 21:28:39 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_CHILD,
|
|
|
|
|
|
|
|
LAST_ARG
|
2019-12-30 03:47:26 +00:00
|
|
|
};
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
static GParamSpec *properties[LAST_ARG] = { NULL, };
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
static void gtk_drag_icon_root_init (GtkRootInterface *iface);
|
|
|
|
static void gtk_drag_icon_native_init (GtkNativeInterface *iface);
|
|
|
|
|
2020-05-01 16:21:42 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkDragIcon, gtk_drag_icon, GTK_TYPE_WIDGET,
|
2019-12-30 03:47:26 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_NATIVE,
|
|
|
|
gtk_drag_icon_native_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ROOT,
|
|
|
|
gtk_drag_icon_root_init))
|
|
|
|
|
|
|
|
static GdkDisplay *
|
|
|
|
gtk_drag_icon_root_get_display (GtkRoot *self)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (self);
|
|
|
|
|
|
|
|
if (icon->surface)
|
|
|
|
return gdk_surface_get_display (icon->surface);
|
|
|
|
|
|
|
|
return gdk_display_get_default ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_root_init (GtkRootInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_display = gtk_drag_icon_root_get_display;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkSurface *
|
|
|
|
gtk_drag_icon_native_get_surface (GtkNative *native)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (native);
|
|
|
|
|
|
|
|
return icon->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskRenderer *
|
|
|
|
gtk_drag_icon_native_get_renderer (GtkNative *native)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (native);
|
|
|
|
|
|
|
|
return icon->renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_native_get_surface_transform (GtkNative *native,
|
2020-05-17 21:08:01 +00:00
|
|
|
double *x,
|
|
|
|
double *y)
|
2019-12-30 03:47:26 +00:00
|
|
|
{
|
2020-05-16 06:01:22 +00:00
|
|
|
GtkCssBoxes css_boxes;
|
|
|
|
const graphene_rect_t *margin_rect;
|
|
|
|
|
|
|
|
gtk_css_boxes_init (&css_boxes, GTK_WIDGET (native));
|
|
|
|
margin_rect = gtk_css_boxes_get_margin_rect (&css_boxes);
|
|
|
|
|
|
|
|
*x = - margin_rect->origin.x;
|
|
|
|
*y = - margin_rect->origin.y;
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_move_resize (GtkDragIcon *icon)
|
|
|
|
{
|
|
|
|
GtkRequisition req;
|
|
|
|
|
|
|
|
if (icon->surface)
|
|
|
|
{
|
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (icon), NULL, &req);
|
2020-03-03 23:56:23 +00:00
|
|
|
gdk_drag_surface_present (GDK_DRAG_SURFACE (icon->surface),
|
|
|
|
MAX (1, req.width),
|
|
|
|
MAX (1, req.height));
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 10:11:05 +00:00
|
|
|
static void
|
|
|
|
gtk_drag_icon_present (GtkDragIcon *icon)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (icon);
|
2019-12-30 03:47:26 +00:00
|
|
|
|
|
|
|
if (!_gtk_widget_get_alloc_needed (widget))
|
|
|
|
gtk_widget_ensure_allocate (widget);
|
|
|
|
else if (gtk_widget_get_visible (widget))
|
2020-11-25 14:06:09 +00:00
|
|
|
gtk_drag_icon_move_resize (icon);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 10:59:23 +00:00
|
|
|
static void
|
|
|
|
gtk_drag_icon_native_layout (GtkNative *native,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
gtk_widget_allocate (GTK_WIDGET (native), width, height, -1, NULL);
|
|
|
|
}
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
static void
|
|
|
|
gtk_drag_icon_native_init (GtkNativeInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_surface = gtk_drag_icon_native_get_surface;
|
|
|
|
iface->get_renderer = gtk_drag_icon_native_get_renderer;
|
|
|
|
iface->get_surface_transform = gtk_drag_icon_native_get_surface_transform;
|
2020-12-02 10:59:23 +00:00
|
|
|
iface->layout = gtk_drag_icon_native_layout;
|
2020-11-25 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
static gboolean
|
|
|
|
surface_render (GdkSurface *surface,
|
|
|
|
cairo_region_t *region,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_widget_render (widget, surface, region);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
|
|
|
g_warn_if_fail (icon->surface != NULL);
|
|
|
|
|
|
|
|
gdk_surface_set_widget (icon->surface, widget);
|
|
|
|
|
|
|
|
g_signal_connect (icon->surface, "render", G_CALLBACK (surface_render), widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_drag_icon_parent_class)->realize (widget);
|
|
|
|
|
|
|
|
icon->renderer = gsk_renderer_new_for_surface (icon->surface);
|
2020-12-02 10:59:23 +00:00
|
|
|
|
|
|
|
gtk_native_realize (GTK_NATIVE (icon));
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
2020-12-02 10:59:23 +00:00
|
|
|
gtk_native_unrealize (GTK_NATIVE (icon));
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_drag_icon_parent_class)->unrealize (widget);
|
|
|
|
|
|
|
|
gsk_renderer_unrealize (icon->renderer);
|
|
|
|
g_clear_object (&icon->renderer);
|
|
|
|
|
|
|
|
if (icon->surface)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (icon->surface, surface_render, widget);
|
|
|
|
gdk_surface_set_widget (icon->surface, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
2020-03-03 23:56:23 +00:00
|
|
|
gtk_drag_icon_move_resize (icon);
|
2019-12-30 03:47:26 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_drag_icon_parent_class)->map (widget);
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (icon->child && gtk_widget_get_visible (icon->child))
|
|
|
|
gtk_widget_map (icon->child);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
|
|
|
g_warn_if_fail (icon->surface != NULL);
|
|
|
|
GTK_WIDGET_CLASS (gtk_drag_icon_parent_class)->unmap (widget);
|
|
|
|
if (icon->surface)
|
|
|
|
gdk_surface_hide (icon->surface);
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (icon->child)
|
|
|
|
gtk_widget_unmap (icon->child);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (icon->child)
|
|
|
|
gtk_widget_measure (icon->child,
|
2019-12-30 03:47:26 +00:00
|
|
|
orientation, for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (widget);
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (icon->child)
|
|
|
|
gtk_widget_allocate (icon->child, width, height, baseline, NULL);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_show (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
_gtk_widget_set_visible_flag (widget, TRUE);
|
|
|
|
gtk_css_node_validate (gtk_widget_get_css_node (widget));
|
|
|
|
gtk_widget_realize (widget);
|
2020-12-04 10:11:05 +00:00
|
|
|
gtk_drag_icon_present (GTK_DRAG_ICON (widget));
|
2019-12-30 03:47:26 +00:00
|
|
|
gtk_widget_map (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_hide (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
_gtk_widget_set_visible_flag (widget, FALSE);
|
|
|
|
gtk_widget_unmap (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkDragIcon *icon = GTK_DRAG_ICON (object);
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
g_clear_pointer (&icon->child, gtk_widget_unparent);
|
2019-12-30 03:47:26 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_drag_icon_parent_class)->dispose (object);
|
|
|
|
|
|
|
|
g_clear_object (&icon->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2020-03-01 21:28:39 +00:00
|
|
|
GtkDragIcon *self = GTK_DRAG_ICON (object);
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-03-01 21:28:39 +00:00
|
|
|
case PROP_CHILD:
|
|
|
|
g_value_set_object (value, self->child);
|
|
|
|
break;
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2020-03-01 21:28:39 +00:00
|
|
|
GtkDragIcon *self = GTK_DRAG_ICON (object);
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-03-01 21:28:39 +00:00
|
|
|
case PROP_CHILD:
|
|
|
|
gtk_drag_icon_set_child (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2019-12-30 03:47:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_class_init (GtkDragIconClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = gtk_drag_icon_dispose;
|
|
|
|
object_class->get_property = gtk_drag_icon_get_property;
|
|
|
|
object_class->set_property = gtk_drag_icon_set_property;
|
|
|
|
|
|
|
|
widget_class->realize = gtk_drag_icon_realize;
|
|
|
|
widget_class->unrealize = gtk_drag_icon_unrealize;
|
|
|
|
widget_class->map = gtk_drag_icon_map;
|
|
|
|
widget_class->unmap = gtk_drag_icon_unmap;
|
|
|
|
widget_class->measure = gtk_drag_icon_measure;
|
|
|
|
widget_class->size_allocate = gtk_drag_icon_size_allocate;
|
|
|
|
widget_class->show = gtk_drag_icon_show;
|
|
|
|
widget_class->hide = gtk_drag_icon_hide;
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
/**
|
2021-02-28 18:02:08 +00:00
|
|
|
* GtkDragIcon:child: (attributes org.gtk.Property.get=gtk_drag_icon_get_child org.gtk.Property.set=gtk_drag_icon_set_child)
|
2020-03-01 21:28:39 +00:00
|
|
|
*
|
|
|
|
* The widget to display as drag icon.
|
|
|
|
*/
|
|
|
|
properties[PROP_CHILD] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("child", NULL, NULL,
|
2020-03-01 21:28:39 +00:00
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_ARG, properties);
|
2019-12-30 03:47:26 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "dnd");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_drag_icon_init (GtkDragIcon *self)
|
|
|
|
{
|
2021-12-13 02:28:34 +00:00
|
|
|
gtk_widget_set_can_target (GTK_WIDGET (self), FALSE);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-09 05:50:33 +00:00
|
|
|
/**
|
2020-03-02 01:55:38 +00:00
|
|
|
* gtk_drag_icon_get_for_drag:
|
2021-02-28 18:02:08 +00:00
|
|
|
* @drag: a `GdkDrag`
|
2020-03-02 01:55:38 +00:00
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* Gets the `GtkDragIcon` in use with @drag.
|
2020-01-09 05:50:33 +00:00
|
|
|
*
|
2020-03-02 01:55:38 +00:00
|
|
|
* If no drag icon exists yet, a new one will be created
|
|
|
|
* and shown.
|
2020-01-09 05:50:33 +00:00
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* Returns: (transfer none): the `GtkDragIcon`
|
2020-01-09 05:50:33 +00:00
|
|
|
*/
|
2020-01-06 20:47:25 +00:00
|
|
|
GtkWidget *
|
2020-03-02 01:55:38 +00:00
|
|
|
gtk_drag_icon_get_for_drag (GdkDrag *drag)
|
2020-01-06 20:47:25 +00:00
|
|
|
{
|
2020-03-02 01:55:38 +00:00
|
|
|
static GQuark drag_icon_quark = 0;
|
|
|
|
GtkWidget *self;
|
2020-01-06 20:47:25 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_DRAG (drag), NULL);
|
|
|
|
|
2020-03-02 01:55:38 +00:00
|
|
|
if (G_UNLIKELY (drag_icon_quark == 0))
|
|
|
|
drag_icon_quark = g_quark_from_static_string ("-gtk-drag-icon");
|
|
|
|
|
|
|
|
self = g_object_get_qdata (G_OBJECT (drag), drag_icon_quark);
|
|
|
|
if (self == NULL)
|
|
|
|
{
|
|
|
|
self = g_object_new (GTK_TYPE_DRAG_ICON, NULL);
|
|
|
|
|
|
|
|
GTK_DRAG_ICON (self)->surface = g_object_ref (gdk_drag_get_drag_surface (drag));
|
2020-01-06 20:47:25 +00:00
|
|
|
|
2020-03-02 01:55:38 +00:00
|
|
|
g_object_set_qdata_full (G_OBJECT (drag), drag_icon_quark, g_object_ref_sink (self), g_object_unref);
|
2020-01-06 20:47:25 +00:00
|
|
|
|
2020-11-25 14:02:26 +00:00
|
|
|
if (GTK_DRAG_ICON (self)->child != NULL)
|
2022-11-28 18:43:36 +00:00
|
|
|
gtk_widget_set_visible (self, TRUE);
|
2020-03-02 01:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2020-01-06 20:47:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-09 05:50:33 +00:00
|
|
|
/**
|
|
|
|
* gtk_drag_icon_set_from_paintable:
|
2021-02-28 18:02:08 +00:00
|
|
|
* @drag: a `GdkDrag`
|
|
|
|
* @paintable: a `GdkPaintable` to display
|
2020-01-09 05:50:33 +00:00
|
|
|
* @hot_x: X coordinate of the hotspot
|
|
|
|
* @hot_y: Y coordinate of the hotspot
|
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* Creates a `GtkDragIcon` that shows @paintable, and associates
|
|
|
|
* it with the drag operation.
|
|
|
|
*
|
|
|
|
* The hotspot position on the paintable is aligned with the
|
|
|
|
* hotspot of the cursor.
|
2020-01-09 05:50:33 +00:00
|
|
|
*/
|
2020-01-06 20:47:25 +00:00
|
|
|
void
|
|
|
|
gtk_drag_icon_set_from_paintable (GdkDrag *drag,
|
|
|
|
GdkPaintable *paintable,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
|
|
|
{
|
|
|
|
GtkWidget *icon;
|
|
|
|
GtkWidget *picture;
|
|
|
|
|
|
|
|
gdk_drag_set_hotspot (drag, hot_x, hot_y);
|
|
|
|
|
2020-03-02 01:55:38 +00:00
|
|
|
icon = gtk_drag_icon_get_for_drag (drag);
|
2020-01-06 20:47:25 +00:00
|
|
|
|
|
|
|
picture = gtk_picture_new_for_paintable (paintable);
|
|
|
|
gtk_picture_set_can_shrink (GTK_PICTURE (picture), FALSE);
|
2020-03-01 21:28:39 +00:00
|
|
|
gtk_drag_icon_set_child (GTK_DRAG_ICON (icon), picture);
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
/**
|
2021-02-28 18:02:08 +00:00
|
|
|
* gtk_drag_icon_set_child: (attributes org.gtk.Method.set_property=child)
|
|
|
|
* @self: a `GtkDragIcon`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @child: (nullable): a `GtkWidget`
|
2020-03-01 21:28:39 +00:00
|
|
|
*
|
|
|
|
* Sets the widget to display as the drag icon.
|
2021-02-28 18:02:08 +00:00
|
|
|
*/
|
2019-12-30 03:47:26 +00:00
|
|
|
void
|
2020-03-01 21:28:39 +00:00
|
|
|
gtk_drag_icon_set_child (GtkDragIcon *self,
|
|
|
|
GtkWidget *child)
|
2019-12-30 03:47:26 +00:00
|
|
|
{
|
2020-03-01 21:28:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_DRAG_ICON (self));
|
|
|
|
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
|
|
|
|
|
|
|
if (self->child == child)
|
2019-12-30 03:47:26 +00:00
|
|
|
return;
|
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (self->child)
|
|
|
|
gtk_widget_unparent (self->child);
|
2019-12-30 03:47:26 +00:00
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
self->child = child;
|
2019-12-30 03:47:26 +00:00
|
|
|
|
2020-03-01 21:28:39 +00:00
|
|
|
if (self->child)
|
2020-11-25 14:02:26 +00:00
|
|
|
{
|
|
|
|
gtk_widget_set_parent (self->child, GTK_WIDGET (self));
|
2022-11-28 18:43:36 +00:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self), TRUE);
|
2020-11-25 14:02:26 +00:00
|
|
|
}
|
2020-03-01 21:28:39 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHILD]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:02:08 +00:00
|
|
|
* gtk_drag_icon_get_child: (attributes org.gtk.Method.get_property=child)
|
|
|
|
* @self: a `GtkDragIcon`
|
2020-03-01 21:28:39 +00:00
|
|
|
*
|
|
|
|
* Gets the widget currently used as drag icon.
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (nullable) (transfer none): The drag icon
|
2020-03-01 21:28:39 +00:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_drag_icon_get_child (GtkDragIcon *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_DRAG_ICON (self), NULL);
|
|
|
|
|
|
|
|
return self->child;
|
2019-12-30 03:47:26 +00:00
|
|
|
}
|
2020-03-01 21:28:39 +00:00
|
|
|
|
2020-03-02 02:11:14 +00:00
|
|
|
/**
|
|
|
|
* gtk_drag_icon_create_widget_for_value:
|
2021-02-28 18:02:08 +00:00
|
|
|
* @value: a `GValue`
|
2020-03-02 02:11:14 +00:00
|
|
|
*
|
|
|
|
* Creates a widget that can be used as a drag icon for the given
|
|
|
|
* @value.
|
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* Supported types include strings, `GdkRGBA` and `GtkTextBuffer`.
|
2020-03-02 02:11:14 +00:00
|
|
|
* If GTK does not know how to create a widget for a given value,
|
|
|
|
* it will return %NULL.
|
|
|
|
*
|
2021-06-19 15:01:57 +00:00
|
|
|
* This method is used to set the default drag icon on drag-and-drop
|
2021-02-28 18:02:08 +00:00
|
|
|
* operations started by `GtkDragSource`, so you don't need to set
|
2020-03-02 02:11:14 +00:00
|
|
|
* a drag icon using this function there.
|
|
|
|
*
|
2021-02-28 18:02:08 +00:00
|
|
|
* Returns: (nullable) (transfer full): A new `GtkWidget`
|
|
|
|
* for displaying @value as a drag icon.
|
|
|
|
*/
|
2020-03-02 02:11:14 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_drag_icon_create_widget_for_value (const GValue *value)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_VALUE (value), NULL);
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS (value, G_TYPE_STRING))
|
|
|
|
{
|
|
|
|
return gtk_label_new (g_value_get_string (value));
|
|
|
|
}
|
2021-12-13 01:43:50 +00:00
|
|
|
else if (G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE))
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
image = gtk_image_new_from_paintable (g_value_get_object (value));
|
|
|
|
gtk_widget_add_css_class (image, "large-icons");
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
2020-03-02 02:11:14 +00:00
|
|
|
else if (G_VALUE_HOLDS (value, GDK_TYPE_RGBA))
|
|
|
|
{
|
|
|
|
GtkWidget *swatch;
|
|
|
|
|
|
|
|
swatch = gtk_color_swatch_new ();
|
2021-12-13 02:01:40 +00:00
|
|
|
gtk_color_swatch_set_can_drag (GTK_COLOR_SWATCH (swatch), FALSE);
|
|
|
|
gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (swatch), FALSE);
|
2020-03-02 02:11:14 +00:00
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (swatch), g_value_get_boxed (value));
|
|
|
|
|
|
|
|
return swatch;
|
|
|
|
}
|
2021-12-13 01:43:50 +00:00
|
|
|
else if (G_VALUE_HOLDS (value, G_TYPE_FILE))
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
info = g_file_query_info (G_FILE (g_value_get_object (value)), "standard::icon", 0, NULL, NULL);
|
2023-01-30 18:26:37 +00:00
|
|
|
if (!info)
|
|
|
|
return NULL;
|
|
|
|
|
2021-12-13 01:43:50 +00:00
|
|
|
image = gtk_image_new_from_gicon (g_file_info_get_icon (info));
|
|
|
|
gtk_widget_add_css_class (image, "large-icons");
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
2020-03-02 02:11:14 +00:00
|
|
|
else if (G_VALUE_HOLDS (value, GTK_TYPE_TEXT_BUFFER))
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = g_value_get_object (value);
|
|
|
|
GtkTextIter start, end;
|
|
|
|
GdkPaintable *paintable;
|
|
|
|
GtkWidget *picture;
|
|
|
|
|
|
|
|
if (buffer == NULL || !gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
picture = gtk_picture_new ();
|
|
|
|
paintable = gtk_text_util_create_rich_drag_icon (picture, buffer, &start, &end);
|
|
|
|
gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
|
|
|
|
gtk_picture_set_can_shrink (GTK_PICTURE (picture), FALSE);
|
|
|
|
g_object_unref (paintable);
|
|
|
|
|
|
|
|
return picture;
|
|
|
|
}
|
2021-08-20 03:51:20 +00:00
|
|
|
else if (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE))
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
GdkPaintable *paintable;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
node = gsk_value_get_render_node (value);
|
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
2021-12-13 02:28:34 +00:00
|
|
|
|
2021-08-20 03:51:20 +00:00
|
|
|
gsk_render_node_get_bounds (node, &bounds);
|
|
|
|
paintable = gtk_render_node_paintable_new (node, &bounds);
|
|
|
|
image = gtk_image_new_from_paintable (paintable);
|
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
|
|
|
g_object_unref (paintable);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
2020-03-02 02:11:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|