Drop GTK_DEST_DEFAULT_HIGHLIGHT

Redo highlight handling slightly. GtkDropTarget now has
a ::armed property that can be tracked to do custom highlighting,
and we always add the dnd style class to armed drop sites.
This commit is contained in:
Matthias Clasen
2020-01-05 09:49:45 -05:00
parent e1f74c8f69
commit 1a3eeb1233
3 changed files with 32 additions and 13 deletions

View File

@@ -357,9 +357,6 @@ gtk_drag_dest_leave (GtkWidget *widget,
track_motion = gtk_drop_target_get_track_motion (dest);
armed = gtk_drop_target_get_armed (dest);
if ((flags & GTK_DEST_DEFAULT_HIGHLIGHT) && armed)
gtk_drag_unhighlight (widget);
if (!(flags & GTK_DEST_DEFAULT_MOTION) || armed || track_motion)
gtk_drop_target_emit_drag_leave (dest, drop, time);
@@ -400,13 +397,7 @@ gtk_drag_dest_motion (GtkWidget *widget,
if (actions && target)
{
if (!gtk_drop_target_get_armed (dest))
{
gtk_drop_target_set_armed (dest, TRUE);
if (flags & GTK_DEST_DEFAULT_HIGHLIGHT)
gtk_drag_highlight (widget);
}
gtk_drop_target_set_armed (dest, TRUE);
gdk_drop_status (drop, dest_actions);
}
else

View File

@@ -73,6 +73,7 @@ enum {
PROP_ACTIONS,
PROP_DEFAULTS,
PROP_TRACK_MOTION,
PROP_ARMED,
NUM_PROPERTIES
};
@@ -163,6 +164,10 @@ gtk_drop_target_get_property (GObject *object,
g_value_set_boolean (value, gtk_drop_target_get_track_motion (dest));
break;
case PROP_ARMED:
g_value_set_boolean (value, gtk_drop_target_get_armed (dest));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -218,6 +223,17 @@ gtk_drop_target_class_init (GtkDropTargetClass *class)
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkDropTarget:armmed:
*
* Whether the drop target is currently the targed of an ongoing drag operation,
* and highlighted.
*/
properties[PROP_ARMED] =
g_param_spec_boolean ("armed", P_("Armed"), P_("Armed"),
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
/**
@@ -713,7 +729,20 @@ void
gtk_drop_target_set_armed (GtkDropTarget *target,
gboolean armed)
{
if (target->armed == armed)
return;
target->armed = armed;
if (target->widget)
{
if (armed)
gtk_drag_highlight (target->widget);
else
gtk_drag_unhighlight (target->widget);
}
g_object_notify_by_pspec (G_OBJECT (target), properties[PROP_ARMED]);
}
gboolean

View File

@@ -45,9 +45,8 @@ typedef struct _GtkDropTarget GtkDropTarget;
* widget will check if the drag matches this widgets list of possible formats
* and actions.
* GTK+ will then call gdk_drag_status() as appropriate.
* @GTK_DEST_DEFAULT_HIGHLIGHT: If set for a widget, GTK+ will draw a highlight on
* this widget as long as a drag is over this widget and the widget drag format
* and action are acceptable.
* @GTK_DEST_DEFAULT_HIGHLIGHT: Does not do anything now. GTK always adds
* the dnd style class to armed drop sites.
* @GTK_DEST_DEFAULT_DROP: Does not do anything now.
* @GTK_DEST_DEFAULT_ALL: If set, specifies that all default actions should
* be taken.