forked from AuroraMiddleware/gtk
colorswatch: Make drag source optional
When using a colorswatch as a drag icon, this can get in the way, so make it optional.
This commit is contained in:
parent
cd49a7f9e9
commit
de5b88477a
@ -65,6 +65,7 @@ struct _GtkColorSwatch
|
|||||||
|
|
||||||
GtkWidget *popover;
|
GtkWidget *popover;
|
||||||
GtkDropTarget *dest;
|
GtkDropTarget *dest;
|
||||||
|
GtkDragSource *source;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkColorSwatchClass
|
struct _GtkColorSwatchClass
|
||||||
@ -81,7 +82,8 @@ enum
|
|||||||
PROP_RGBA,
|
PROP_RGBA,
|
||||||
PROP_SELECTABLE,
|
PROP_SELECTABLE,
|
||||||
PROP_HAS_MENU,
|
PROP_HAS_MENU,
|
||||||
PROP_CAN_DROP
|
PROP_CAN_DROP,
|
||||||
|
PROP_CAN_DRAG
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
|
G_DEFINE_TYPE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
|
||||||
@ -429,6 +431,9 @@ swatch_get_property (GObject *object,
|
|||||||
case PROP_CAN_DROP:
|
case PROP_CAN_DROP:
|
||||||
g_value_set_boolean (value, swatch->dest != NULL);
|
g_value_set_boolean (value, swatch->dest != NULL);
|
||||||
break;
|
break;
|
||||||
|
case PROP_CAN_DRAG:
|
||||||
|
g_value_set_boolean (value, swatch->source != NULL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -457,6 +462,9 @@ swatch_set_property (GObject *object,
|
|||||||
case PROP_CAN_DROP:
|
case PROP_CAN_DROP:
|
||||||
gtk_color_swatch_set_can_drop (swatch, g_value_get_boolean (value));
|
gtk_color_swatch_set_can_drop (swatch, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
case PROP_CAN_DRAG:
|
||||||
|
gtk_color_swatch_set_can_drag (swatch, g_value_get_boolean (value));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -512,6 +520,9 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
|
|||||||
g_object_class_install_property (object_class, PROP_CAN_DROP,
|
g_object_class_install_property (object_class, PROP_CAN_DROP,
|
||||||
g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"),
|
g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"),
|
||||||
FALSE, GTK_PARAM_READWRITE));
|
FALSE, GTK_PARAM_READWRITE));
|
||||||
|
g_object_class_install_property (object_class, PROP_CAN_DRAG,
|
||||||
|
g_param_spec_boolean ("can-drag", P_("Can Drag"), P_("Whether the swatch should allow drags"),
|
||||||
|
TRUE, GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkColorSwatch|menu.popup:
|
* GtkColorSwatch|menu.popup:
|
||||||
@ -568,6 +579,8 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
|
|||||||
G_CALLBACK (key_controller_key_pressed), swatch);
|
G_CALLBACK (key_controller_key_pressed), swatch);
|
||||||
gtk_widget_add_controller (GTK_WIDGET (swatch), controller);
|
gtk_widget_add_controller (GTK_WIDGET (swatch), controller);
|
||||||
|
|
||||||
|
gtk_color_swatch_set_can_drag (swatch, TRUE);
|
||||||
|
|
||||||
gtk_widget_add_css_class (GTK_WIDGET (swatch), "activatable");
|
gtk_widget_add_css_class (GTK_WIDGET (swatch), "activatable");
|
||||||
|
|
||||||
swatch->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
|
swatch->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
|
||||||
@ -598,18 +611,10 @@ void
|
|||||||
gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
|
gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
|
||||||
const GdkRGBA *color)
|
const GdkRGBA *color)
|
||||||
{
|
{
|
||||||
if (!swatch->has_color)
|
|
||||||
{
|
|
||||||
GtkDragSource *source;
|
|
||||||
|
|
||||||
source = gtk_drag_source_new ();
|
|
||||||
g_signal_connect (source, "prepare", G_CALLBACK (gtk_color_swatch_drag_prepare), swatch);
|
|
||||||
|
|
||||||
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (source));
|
|
||||||
}
|
|
||||||
|
|
||||||
swatch->has_color = TRUE;
|
swatch->has_color = TRUE;
|
||||||
swatch->color = *color;
|
swatch->color = *color;
|
||||||
|
if (swatch->source)
|
||||||
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (swatch->source), GTK_PHASE_CAPTURE);
|
||||||
|
|
||||||
if (INTENSITY (swatch->color.red, swatch->color.green, swatch->color.blue) > 0.5)
|
if (INTENSITY (swatch->color.red, swatch->color.green, swatch->color.blue) > 0.5)
|
||||||
{
|
{
|
||||||
@ -681,6 +686,30 @@ gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
|||||||
g_object_notify (G_OBJECT (swatch), "can-drop");
|
g_object_notify (G_OBJECT (swatch), "can-drop");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_swatch_set_can_drag (GtkColorSwatch *swatch,
|
||||||
|
gboolean can_drag)
|
||||||
|
{
|
||||||
|
if (can_drag == (swatch->source != NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (can_drag && !swatch->source)
|
||||||
|
{
|
||||||
|
swatch->source = gtk_drag_source_new ();
|
||||||
|
g_signal_connect (swatch->source, "prepare", G_CALLBACK (gtk_color_swatch_drag_prepare), swatch);
|
||||||
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (swatch->source),
|
||||||
|
swatch->has_color ? GTK_PHASE_CAPTURE : GTK_PHASE_NONE);
|
||||||
|
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (swatch->source));
|
||||||
|
}
|
||||||
|
if (!can_drag && swatch->source)
|
||||||
|
{
|
||||||
|
gtk_widget_remove_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (swatch->source));
|
||||||
|
swatch->source = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (swatch), "can-drag");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
||||||
gboolean use_alpha)
|
gboolean use_alpha)
|
||||||
|
@ -42,6 +42,8 @@ void gtk_color_swatch_set_hsva (GtkColorSwatch *swatch,
|
|||||||
double a);
|
double a);
|
||||||
void gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
void gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
||||||
gboolean can_drop);
|
gboolean can_drop);
|
||||||
|
void gtk_color_swatch_set_can_drag (GtkColorSwatch *swatch,
|
||||||
|
gboolean can_drag);
|
||||||
void gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
|
void gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
|
||||||
const char *icon);
|
const char *icon);
|
||||||
void gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
void gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
||||||
|
Loading…
Reference in New Issue
Block a user