mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 22:10:08 +00:00
dnd: Make actions a private member variable
Use a setter in the backends.
This commit is contained in:
parent
18c3b725b4
commit
2e27967814
22
gdk/gdkdnd.c
22
gdk/gdkdnd.c
@ -46,6 +46,8 @@ struct _GdkDragContextPrivate
|
||||
GdkDevice *device;
|
||||
#endif
|
||||
GdkContentFormats *formats;
|
||||
GdkDragAction actions;
|
||||
GdkDragAction suggested_action;
|
||||
};
|
||||
|
||||
static struct {
|
||||
@ -166,9 +168,11 @@ gdk_drag_context_get_formats (GdkDragContext *context)
|
||||
GdkDragAction
|
||||
gdk_drag_context_get_actions (GdkDragContext *context)
|
||||
{
|
||||
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
|
||||
|
||||
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
|
||||
|
||||
return context->actions;
|
||||
return priv->actions;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,9 +186,11 @@ gdk_drag_context_get_actions (GdkDragContext *context)
|
||||
GdkDragAction
|
||||
gdk_drag_context_get_suggested_action (GdkDragContext *context)
|
||||
{
|
||||
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
|
||||
|
||||
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
|
||||
|
||||
return context->suggested_action;
|
||||
return priv->suggested_action;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -707,6 +713,17 @@ gdk_drag_context_write_finish (GdkDragContext *context,
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
void
|
||||
gdk_drag_context_set_actions (GdkDragContext *context,
|
||||
GdkDragAction actions,
|
||||
GdkDragAction suggested_action)
|
||||
{
|
||||
GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
|
||||
|
||||
priv->actions = actions;
|
||||
priv->suggested_action = suggested_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_drag_context_get_drag_surface:
|
||||
* @context: a #GdkDragContext
|
||||
@ -894,4 +911,3 @@ gdk_drag_action_is_unique (GdkDragAction action)
|
||||
{
|
||||
return (action & (action - 1)) == 0;
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,6 @@ struct _GdkDragContext {
|
||||
GdkSurface *drag_surface;
|
||||
|
||||
GdkContentProvider *content;
|
||||
GdkDragAction actions;
|
||||
GdkDragAction suggested_action;
|
||||
GdkDragAction action;
|
||||
|
||||
guint drop_done : 1; /* Whether gdk_drag_drop_done() was performed */
|
||||
@ -87,6 +85,10 @@ struct _GdkDragContext {
|
||||
|
||||
void gdk_drag_context_set_cursor (GdkDragContext *context,
|
||||
GdkCursor *cursor);
|
||||
void gdk_drag_context_set_actions (GdkDragContext *context,
|
||||
GdkDragAction actions,
|
||||
GdkDragAction suggested_action);
|
||||
|
||||
void gdk_drag_context_cancel (GdkDragContext *context,
|
||||
GdkDragCancelReason reason);
|
||||
gboolean gdk_drag_context_handle_source_event (GdkEvent *event);
|
||||
|
@ -559,11 +559,13 @@ drag_action_to_drag_operation (GdkDragAction action)
|
||||
static void
|
||||
update_context_from_dragging_info (id <NSDraggingInfo> sender)
|
||||
{
|
||||
GdkDragAction action;
|
||||
|
||||
g_assert (current_context != NULL);
|
||||
|
||||
GDK_QUARTZ_DRAG_CONTEXT (current_context)->dragging_info = sender;
|
||||
current_context->suggested_action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
|
||||
current_context->actions = current_context->suggested_action;
|
||||
action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
|
||||
gdk_drag_context_set_actions (current_context, action, action);
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
|
@ -1154,7 +1154,9 @@ data_offer_source_actions (void *data,
|
||||
if (drop_context == NULL)
|
||||
return;
|
||||
|
||||
drop_context->actions = gdk_wayland_actions_to_gdk_actions (source_actions);
|
||||
gdk_drag_context_set_actions (drop_context,
|
||||
gdk_wayland_actions_to_gdk_actions (source_actions),
|
||||
gdk_drag_context_get_suggested_action (drop_context));
|
||||
|
||||
_gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
|
||||
GDK_CURRENT_TIME);
|
||||
@ -1180,7 +1182,9 @@ data_offer_action (void *data,
|
||||
if (drop_context == NULL)
|
||||
return;
|
||||
|
||||
drop_context->suggested_action = gdk_wayland_actions_to_gdk_actions (action);
|
||||
gdk_drag_context_set_actions (drop_context,
|
||||
gdk_drag_context_get_actions (drop_context),
|
||||
gdk_wayland_actions_to_gdk_actions (action));
|
||||
|
||||
_gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
|
||||
GDK_CURRENT_TIME);
|
||||
|
@ -146,13 +146,6 @@ gdk_to_wl_actions (GdkDragAction action)
|
||||
return dnd_actions;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_wayland_drag_context_set_action (GdkDragContext *context,
|
||||
GdkDragAction action)
|
||||
{
|
||||
context->suggested_action = context->action = action;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_wayland_drag_context_drag_abort (GdkDragContext *context,
|
||||
guint32 time)
|
||||
@ -326,8 +319,6 @@ gdk_wayland_drag_context_init (GdkWaylandDragContext *context_wayland)
|
||||
contexts = g_list_prepend (contexts, context);
|
||||
|
||||
context->action = GDK_ACTION_COPY;
|
||||
context->suggested_action = GDK_ACTION_COPY;
|
||||
context->actions = GDK_ACTION_COPY | GDK_ACTION_MOVE;
|
||||
}
|
||||
|
||||
static GdkSurface *
|
||||
|
@ -119,9 +119,6 @@ void _gdk_wayland_drag_context_set_coords (GdkDragContext *context,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
|
||||
void gdk_wayland_drag_context_set_action (GdkDragContext *context,
|
||||
GdkDragAction action);
|
||||
|
||||
GdkDragContext * gdk_wayland_drag_context_lookup_by_data_source (struct wl_data_source *source);
|
||||
GdkDragContext * gdk_wayland_drag_context_lookup_by_source_surface (GdkSurface *surface);
|
||||
struct wl_data_source * gdk_wayland_drag_context_get_data_source (GdkDragContext *context);
|
||||
|
@ -825,7 +825,7 @@ gdk_drag_context_new (GdkDisplay *display,
|
||||
|
||||
context->is_source = TRUE;
|
||||
g_set_object (&context->source_surface, source_surface);
|
||||
context->actions = actions;
|
||||
gdk_drag_context_set_actions (context, actions, actions);
|
||||
context_win32->protocol = protocol;
|
||||
|
||||
gdk_content_formats_unref (formats);
|
||||
@ -1806,7 +1806,7 @@ local_send_motion (GdkDragContext *context,
|
||||
tmp_event->dnd.time = time;
|
||||
gdk_event_set_device (tmp_event, gdk_drag_context_get_device (current_dest_drag));
|
||||
|
||||
current_dest_drag->suggested_action = action;
|
||||
gdk_drag_context_set_actions (current_dest_drag, action, action);
|
||||
|
||||
tmp_event->dnd.x_root = x_root;
|
||||
tmp_event->dnd.y_root = y_root;
|
||||
@ -2092,8 +2092,6 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
|
||||
g_return_val_if_fail (context != NULL, FALSE);
|
||||
|
||||
context->actions = possible_actions;
|
||||
|
||||
GDK_NOTE (DND, g_print ("gdk_win32_drag_context_drag_motion: @ %+d:%+d %s suggested=%s, possible=%s\n"
|
||||
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
|
||||
x_root, y_root,
|
||||
@ -2101,8 +2099,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
_gdk_win32_drag_action_to_string (suggested_action),
|
||||
_gdk_win32_drag_action_to_string (possible_actions),
|
||||
context,
|
||||
_gdk_win32_drag_action_to_string (context->actions),
|
||||
_gdk_win32_drag_action_to_string (context->suggested_action),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
|
||||
_gdk_win32_drag_action_to_string (context->action)));
|
||||
|
||||
context_win32 = GDK_WIN32_DRAG_CONTEXT (context);
|
||||
@ -2120,9 +2118,9 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
dest_surface);
|
||||
|
||||
if (dest_context)
|
||||
dest_context->actions = context->actions;
|
||||
gdk_drag_context_set_actions (dest_context, possible_actions, suggested_action);
|
||||
|
||||
context->suggested_action = suggested_action;
|
||||
gdk_drag_context_set_actions (context, possible_actions, suggested_action);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2146,12 +2144,12 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
context->suggested_action = suggested_action;
|
||||
gdk_drag_context_set_actions (context, possible_actions, suggested_action);
|
||||
}
|
||||
else
|
||||
{
|
||||
context->dest_surface = NULL;
|
||||
context->action = 0;
|
||||
gdk_drag_context_set_actions (context, 0, 0);
|
||||
}
|
||||
|
||||
GDK_NOTE (DND, g_print ("gdk_dnd_handle_drag_status: 0x%p\n",
|
||||
@ -2192,8 +2190,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
GDK_NOTE (DND, g_print (" returning TRUE\n"
|
||||
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
|
||||
context,
|
||||
_gdk_win32_drag_action_to_string (context->actions),
|
||||
_gdk_win32_drag_action_to_string (context->suggested_action),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
|
||||
_gdk_win32_drag_action_to_string (context->action)));
|
||||
return TRUE;
|
||||
}
|
||||
@ -2203,8 +2201,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
|
||||
GDK_NOTE (DND, g_print (" returning FALSE\n"
|
||||
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
|
||||
context,
|
||||
_gdk_win32_drag_action_to_string (context->actions),
|
||||
_gdk_win32_drag_action_to_string (context->suggested_action),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
|
||||
_gdk_win32_drag_action_to_string (context->action)));
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ gdk_drop_context_new (GdkDisplay *display,
|
||||
context->is_source = FALSE;
|
||||
g_set_object (&context->source_surface, source_surface);
|
||||
g_set_object (&context->dest_surface, dest_surface);
|
||||
context->actions = actions;
|
||||
gdk_drag_context_set_actions (context, actions, actions);
|
||||
context_win32->protocol = protocol;
|
||||
|
||||
gdk_content_formats_unref (formats);
|
||||
@ -445,7 +445,9 @@ idroptarget_dragenter (LPDROPTARGET This,
|
||||
|
||||
ctx->context = context;
|
||||
context->action = GDK_ACTION_MOVE;
|
||||
context->suggested_action = get_suggested_action (context_win32, grfKeyState);
|
||||
gdk_drag_context_set_actions (context,
|
||||
GDK_ACTION_COPY | GDK_ACTION_MOVE,
|
||||
get_suggested_action (context_win32, grfKeyState));
|
||||
set_data_object (&ctx->data_object, pDataObj);
|
||||
pt_x = pt.x / context_win32->scale + _gdk_offset_x;
|
||||
pt_y = pt.y / context_win32->scale + _gdk_offset_y;
|
||||
@ -482,9 +484,11 @@ idroptarget_dragover (LPDROPTARGET This,
|
||||
gint pt_x = pt.x / context_win32->scale + _gdk_offset_x;
|
||||
gint pt_y = pt.y / context_win32->scale + _gdk_offset_y;
|
||||
|
||||
ctx->context->suggested_action = get_suggested_action (context_win32, grfKeyState);
|
||||
gdk_drag_context_set_actions (ctx->context,
|
||||
gdk_drag_context_get_actions (ctx->context),
|
||||
get_suggested_action (context_win32, grfKeyState));
|
||||
|
||||
GDK_NOTE (DND, g_print ("idroptarget_dragover %p @ %d : %d (raw %ld : %ld), suggests %d action S_OK\n", This, pt_x, pt_y, pt.x, pt.y, ctx->context->suggested_action));
|
||||
GDK_NOTE (DND, g_print ("idroptarget_dragover %p @ %d : %d (raw %ld : %ld), suggests %d action S_OK\n", This, pt_x, pt_y, pt.x, pt.y, gdk_drag_context_get_suggested_action (ctx->context)));
|
||||
|
||||
if (pt_x != context_win32->last_x ||
|
||||
pt_y != context_win32->last_y ||
|
||||
@ -541,7 +545,9 @@ idroptarget_drop (LPDROPTARGET This,
|
||||
return E_POINTER;
|
||||
}
|
||||
|
||||
ctx->context->suggested_action = get_suggested_action (context_win32, grfKeyState);
|
||||
gdk_drag_context_set_actions (ctx->context,
|
||||
gdk_drag_context_get_actions (ctx->context),
|
||||
get_suggested_action (context_win32, grfKeyState));
|
||||
|
||||
dnd_event_emit (GDK_DROP_START, ctx->context, pt_x, pt_y, ctx->context->dest_surface);
|
||||
|
||||
@ -734,8 +740,7 @@ gdk_dropfiles_filter (GdkWin32Display *display,
|
||||
context_win32 = GDK_WIN32_DROP_CONTEXT (context);
|
||||
/* WM_DROPFILES drops are always file names */
|
||||
|
||||
|
||||
context->suggested_action = GDK_ACTION_COPY;
|
||||
gdk_drag_context_set_actions (context, GDK_ACTION_COPY, GDK_ACTION_COPY);
|
||||
current_dest_drag = context;
|
||||
|
||||
hdrop = (HANDLE) msg->wParam;
|
||||
@ -860,8 +865,8 @@ gdk_win32_drop_context_drag_status (GdkDragContext *context,
|
||||
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
|
||||
_gdk_win32_drag_action_to_string (action),
|
||||
context,
|
||||
_gdk_win32_drag_action_to_string (context->actions),
|
||||
_gdk_win32_drag_action_to_string (context->suggested_action),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
|
||||
_gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
|
||||
_gdk_win32_drag_action_to_string (context->action)));
|
||||
|
||||
context->action = action;
|
||||
@ -1227,7 +1232,7 @@ _gdk_win32_local_send_enter (GdkDragContext *context,
|
||||
context->source_surface,
|
||||
context->dest_surface,
|
||||
gdk_content_formats_ref (gdk_drag_context_get_formats (context)),
|
||||
context->actions,
|
||||
gdk_drag_context_get_actions (context),
|
||||
GDK_DRAG_PROTO_LOCAL);
|
||||
|
||||
gdk_surface_set_events (new_context->source_surface,
|
||||
|
@ -1527,6 +1527,7 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
|
||||
{
|
||||
GdkDragContext *context = GDK_DRAG_CONTEXT (context_x11);
|
||||
GdkDisplay *display = gdk_drag_context_get_display (context);
|
||||
GdkDragAction actions = GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK;
|
||||
Atom type;
|
||||
int format;
|
||||
gulong nitems, after;
|
||||
@ -1549,12 +1550,12 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
|
||||
&after, &data) == Success &&
|
||||
type == XA_ATOM)
|
||||
{
|
||||
actions = 0;
|
||||
|
||||
atoms = (Atom *)data;
|
||||
|
||||
context->actions = 0;
|
||||
|
||||
for (i = 0; i < nitems; i++)
|
||||
context->actions |= xdnd_action_from_atom (display, atoms[i]);
|
||||
actions |= xdnd_action_from_atom (display, atoms[i]);
|
||||
|
||||
context_x11->xdnd_have_actions = TRUE;
|
||||
|
||||
@ -1562,20 +1563,20 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
|
||||
if (GDK_DISPLAY_DEBUG_CHECK (display, DND))
|
||||
{
|
||||
GString *action_str = g_string_new (NULL);
|
||||
if (context->actions & GDK_ACTION_MOVE)
|
||||
GdkDragAction actions = gdk_drag_context_get_actions (context);
|
||||
if (actions & GDK_ACTION_MOVE)
|
||||
g_string_append(action_str, "MOVE ");
|
||||
if (context->actions & GDK_ACTION_COPY)
|
||||
if (actions & GDK_ACTION_COPY)
|
||||
g_string_append(action_str, "COPY ");
|
||||
if (context->actions & GDK_ACTION_LINK)
|
||||
if (actions & GDK_ACTION_LINK)
|
||||
g_string_append(action_str, "LINK ");
|
||||
if (context->actions & GDK_ACTION_ASK)
|
||||
if (actions & GDK_ACTION_ASK)
|
||||
g_string_append(action_str, "ASK ");
|
||||
|
||||
g_message("Xdnd actions = %s", action_str->str);
|
||||
g_string_free (action_str, TRUE);
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
}
|
||||
|
||||
if (data)
|
||||
@ -1595,10 +1596,12 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
|
||||
|
||||
if (source_context)
|
||||
{
|
||||
context->actions = source_context->actions;
|
||||
actions = gdk_drag_context_get_actions (source_context);
|
||||
context_x11->xdnd_have_actions = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gdk_drag_context_set_actions (context, actions, gdk_drag_context_get_suggested_action (context));
|
||||
}
|
||||
|
||||
/* We have to make sure that the XdndActionList we keep internally
|
||||
@ -1899,6 +1902,7 @@ xdnd_position_filter (const XEvent *xevent,
|
||||
GdkX11Display *display_x11;
|
||||
GdkDragContext *context;
|
||||
GdkX11DragContext *context_x11;
|
||||
GdkDragAction suggested_action;
|
||||
|
||||
if (!event->any.surface ||
|
||||
gdk_surface_get_surface_type (event->any.surface) == GDK_SURFACE_FOREIGN)
|
||||
@ -1930,10 +1934,15 @@ xdnd_position_filter (const XEvent *xevent,
|
||||
|
||||
event->dnd.time = time;
|
||||
|
||||
context->suggested_action = xdnd_action_from_atom (display, action);
|
||||
|
||||
if (!context_x11->xdnd_have_actions)
|
||||
context->actions = context->suggested_action;
|
||||
suggested_action = xdnd_action_from_atom (display, action);
|
||||
if (context_x11->xdnd_have_actions)
|
||||
gdk_drag_context_set_actions (context,
|
||||
gdk_drag_context_get_actions (context),
|
||||
suggested_action);
|
||||
else
|
||||
gdk_drag_context_set_actions (context,
|
||||
suggested_action,
|
||||
suggested_action);
|
||||
|
||||
event->dnd.x_root = x_root / impl->surface_scale;
|
||||
event->dnd.y_root = y_root / impl->surface_scale;
|
||||
@ -2219,7 +2228,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
|
||||
if (context_x11->drag_surface)
|
||||
move_drag_surface (context, x_root, y_root);
|
||||
|
||||
context->actions = possible_actions;
|
||||
gdk_drag_context_set_actions (context, possible_actions, suggested_action);
|
||||
|
||||
if (protocol == GDK_DRAG_PROTO_XDND && context_x11->version == 0)
|
||||
{
|
||||
@ -2261,7 +2270,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
|
||||
|
||||
if (dest_context)
|
||||
{
|
||||
dest_context->actions = context->actions;
|
||||
gdk_drag_context_set_actions (dest_context, possible_actions, suggested_action);
|
||||
GDK_X11_DRAG_CONTEXT (dest_context)->xdnd_have_actions = TRUE;
|
||||
}
|
||||
}
|
||||
@ -2294,7 +2303,6 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
context->suggested_action = suggested_action;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2312,10 +2320,6 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
|
||||
g_signal_emit_by_name (context, "action-changed", context->action);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context->suggested_action = suggested_action;
|
||||
}
|
||||
|
||||
/* Send a drag-motion event */
|
||||
|
||||
@ -2342,7 +2346,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
|
||||
*/
|
||||
if (gdk_content_formats_contain_mime_type (formats, "application/x-rootwindow-drop") ||
|
||||
gdk_content_formats_contain_mime_type (formats, "application/x-rootwin-drop"))
|
||||
context->action = context->suggested_action;
|
||||
context->action = gdk_drag_context_get_suggested_action (context);
|
||||
else
|
||||
context->action = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user