GDK/Win32: Rename "window" for DND/clipboard code

We want to make the distinction between GdkSurface's and native Windows
HWND clearer.
This commit is contained in:
Chun-wei Fan
2024-08-19 18:39:59 +08:00
parent 7488644176
commit b4c7dd770c
5 changed files with 78 additions and 78 deletions

View File

@@ -89,7 +89,7 @@ texts (strings) or textures (GdkPixbufs) this way.
On Windows:
Clipboard is opened by OpenClipboard(), emptied by EmptyClipboard() (which also
makes the window the clipboard owner), data is put into it by SetClipboardData().
makes the HWND the clipboard owner), data is put into it by SetClipboardData().
Clipboard is closed with CloseClipboard().
If SetClipboardData() is given a NULL data value, the owner will later
receive WM_RENDERFORMAT message, in response to which it must call
@@ -239,7 +239,7 @@ on all the clipboards it owns. This creates multiple write stream (one for each
format being stored), each backed by a HGLOBAL memory object. Once all memory
objects are written, the backend queues a store operation, passing along
all these HGLOBAL objects. The clipboard thread processes that by sending
WM_RENDERALLFORMATS to the window, then signals the task that it's done.
WM_RENDERALLFORMATS to the surface HWND, then signals the task that it's done.
When clipboard owner changes, the old owner receives WM_DESTROYCLIPBOARD message,
the clipboard thread schedules a call to gdk_clipboard_claim_remote()
@@ -390,10 +390,10 @@ typedef struct _GdkWin32ClipboardThread GdkWin32ClipboardThread;
struct _GdkWin32ClipboardThread
{
/* A hidden window that owns our clipboard
/* A hidden HWND that owns our clipboard
* and receives clipboard-related messages.
*/
HWND clipboard_window;
HWND clipboard_hwnd;
/* We receive instructions from the main thread in this queue */
GAsyncQueue *input_queue;
@@ -483,11 +483,11 @@ _gdk_win32_format_uses_hdata (UINT w32format)
/* This function is called in the main thread */
static gboolean
clipboard_window_created (gpointer user_data)
clipboard_hwnd_created (gpointer user_data)
{
GdkWin32Clipdrop *clipdrop = _gdk_win32_clipdrop_get ();
clipdrop->clipboard_window = (HWND) user_data;
clipdrop->clipboard_hwnd = (HWND) user_data;
return G_SOURCE_REMOVE;
}
@@ -730,7 +730,7 @@ process_advertise (GdkWin32ClipboardThreadAdvertise *adv)
return FALSE;
}
error_code = try_open_clipboard (adv->unset ? NULL : clipboard_thread_data->clipboard_window);
error_code = try_open_clipboard (adv->unset ? NULL : clipboard_thread_data->clipboard_hwnd);
if (error_code == ERROR_ACCESS_DENIED)
return TRUE;
@@ -809,7 +809,7 @@ process_store (GdkWin32ClipboardThreadStore *store)
return FALSE;
}
error_code = try_open_clipboard (clipboard_thread_data->clipboard_window);
error_code = try_open_clipboard (clipboard_thread_data->clipboard_hwnd);
if (error_code == ERROR_ACCESS_DENIED)
return TRUE;
@@ -831,7 +831,7 @@ process_store (GdkWin32ClipboardThreadStore *store)
* that we already own, otherwise we're just killing stuff that some other
* process put in there, which is not nice.
*/
if (GetClipboardOwner () != clipboard_thread_data->clipboard_window)
if (GetClipboardOwner () != clipboard_thread_data->clipboard_hwnd)
{
send_response (store->parent.item_type,
store->parent.opaque_task,
@@ -952,7 +952,7 @@ process_retrieve (GdkWin32ClipboardThreadRetrieve *retr)
}
if (clipboard_thread_data->clipboard_opened_for == INVALID_HANDLE_VALUE)
error_code = try_open_clipboard (clipboard_thread_data->clipboard_window);
error_code = try_open_clipboard (clipboard_thread_data->clipboard_hwnd);
else
error_code = try_open_clipboard (clipboard_thread_data->clipboard_opened_for);
@@ -1119,7 +1119,7 @@ discard_render (GdkWin32ClipboardThreadRender *render,
}
static LRESULT
inner_clipboard_window_procedure (HWND hwnd,
inner_clipboard_hwnd_procedure (HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam)
@@ -1139,7 +1139,7 @@ inner_clipboard_window_procedure (HWND hwnd,
if (queue_is_empty && clipboard_thread_data->wakeup_timer)
{
API_CALL (KillTimer, (clipboard_thread_data->clipboard_window, clipboard_thread_data->wakeup_timer));
API_CALL (KillTimer, (clipboard_thread_data->clipboard_hwnd, clipboard_thread_data->wakeup_timer));
clipboard_thread_data->wakeup_timer = 0;
}
@@ -1159,11 +1159,11 @@ inner_clipboard_window_procedure (HWND hwnd,
clipboard_thread_data->wakeup_timer != 0)
return 0;
if (SetTimer (clipboard_thread_data->clipboard_window, 1, 1000, NULL))
if (SetTimer (clipboard_thread_data->clipboard_hwnd, 1, 1000, NULL))
clipboard_thread_data->wakeup_timer = 1;
else
g_critical ("Failed to set a timer for the clipboard window 0x%p: %lu",
clipboard_thread_data->clipboard_window,
g_critical ("Failed to set a timer for the clipboard HWND 0x%p: %lu",
clipboard_thread_data->clipboard_hwnd,
GetLastError ());
}
@@ -1235,7 +1235,7 @@ inner_clipboard_window_procedure (HWND hwnd,
clipboard_thread_data->stored_hwnd_owner = hwnd_owner;
clipboard_thread_data->owner_change_time = g_get_monotonic_time ();
if (hwnd_owner != clipboard_thread_data->clipboard_window)
if (hwnd_owner != clipboard_thread_data->clipboard_hwnd)
{
if (clipboard_thread_data->cached_advertisement)
g_array_free (clipboard_thread_data->cached_advertisement, TRUE);
@@ -1243,9 +1243,9 @@ inner_clipboard_window_procedure (HWND hwnd,
clipboard_thread_data->cached_advertisement = NULL;
}
API_CALL (PostMessage, (clipboard_thread_data->clipboard_window, thread_wakeup_message, 0, 0));
API_CALL (PostMessage, (clipboard_thread_data->clipboard_hwnd, thread_wakeup_message, 0, 0));
if (hwnd_owner != clipboard_thread_data->clipboard_window)
if (hwnd_owner != clipboard_thread_data->clipboard_hwnd)
g_idle_add_full (G_PRIORITY_DEFAULT, clipboard_owner_changed, NULL, NULL);
}
@@ -1383,7 +1383,7 @@ inner_clipboard_window_procedure (HWND hwnd,
}
LRESULT CALLBACK
_clipboard_window_procedure (HWND hwnd,
_clipboard_hwnd_procedure (HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam)
@@ -1392,7 +1392,7 @@ _clipboard_window_procedure (HWND hwnd,
GDK_NOTE (EVENTS, g_print ("clipboard thread %s %p",
_gdk_win32_message_to_string (message), hwnd));
retval = inner_clipboard_window_procedure (hwnd, message, wparam, lparam);
retval = inner_clipboard_hwnd_procedure (hwnd, message, wparam, lparam);
GDK_NOTE (EVENTS, g_print (" => %" G_GINT64_FORMAT "\n", (gint64) retval));
@@ -1400,7 +1400,7 @@ _clipboard_window_procedure (HWND hwnd,
}
/*
* Creates a hidden window and add a clipboard listener
* Creates a hidden HWND and add a clipboard listener
*/
static gboolean
register_clipboard_notification ()
@@ -1409,7 +1409,7 @@ register_clipboard_notification ()
ATOM klass;
wclass.lpszClassName = L"GdkClipboardNotification";
wclass.lpfnWndProc = _clipboard_window_procedure;
wclass.lpfnWndProc = _clipboard_hwnd_procedure;
wclass.hInstance = this_module ();
wclass.cbWndExtra = sizeof (GdkWin32ClipboardThread *);
@@ -1417,23 +1417,23 @@ register_clipboard_notification ()
if (!klass)
return FALSE;
clipboard_thread_data->clipboard_window = CreateWindow (MAKEINTRESOURCE (klass),
clipboard_thread_data->clipboard_hwnd = CreateWindow (MAKEINTRESOURCE (klass),
NULL, WS_POPUP,
0, 0, 0, 0, NULL, NULL,
this_module (), NULL);
if (clipboard_thread_data->clipboard_window == NULL)
if (clipboard_thread_data->clipboard_hwnd == NULL)
goto failed;
SetLastError (0);
if (AddClipboardFormatListener (clipboard_thread_data->clipboard_window) == FALSE)
if (AddClipboardFormatListener (clipboard_thread_data->clipboard_hwnd) == FALSE)
{
DestroyWindow (clipboard_thread_data->clipboard_window);
DestroyWindow (clipboard_thread_data->clipboard_hwnd);
goto failed;
}
g_idle_add_full (G_PRIORITY_DEFAULT, clipboard_window_created, (gpointer) clipboard_thread_data->clipboard_window, NULL);
g_idle_add_full (G_PRIORITY_DEFAULT, clipboard_hwnd_created, (gpointer) clipboard_thread_data->clipboard_hwnd, NULL);
return TRUE;
@@ -1472,8 +1472,8 @@ _gdk_win32_clipboard_thread_main (gpointer data)
}
/* Just in case, as this should only happen when we shut down */
DestroyWindow (clipboard_thread_data->clipboard_window);
CloseHandle (clipboard_thread_data->clipboard_window);
DestroyWindow (clipboard_thread_data->clipboard_hwnd);
CloseHandle (clipboard_thread_data->clipboard_hwnd);
g_async_queue_unref (queue);
g_clear_pointer (&clipboard_thread_data, g_free);
@@ -2756,7 +2756,7 @@ _gdk_win32_advertise_clipboard_contentformats (GTask *task,
gsize mime_types_len;
gsize i;
g_assert (clipdrop->clipboard_window != NULL);
g_assert (clipdrop->clipboard_hwnd != NULL);
adv->parent.item_type = GDK_WIN32_CLIPBOARD_THREAD_QUEUE_ITEM_ADVERTISE;
adv->parent.start_time = g_get_monotonic_time ();
@@ -2779,7 +2779,7 @@ _gdk_win32_advertise_clipboard_contentformats (GTask *task,
}
g_async_queue_push (clipdrop->clipboard_open_thread_queue, adv);
API_CALL (PostMessage, (clipdrop->clipboard_window, thread_wakeup_message, 0, 0));
API_CALL (PostMessage, (clipdrop->clipboard_hwnd, thread_wakeup_message, 0, 0));
return;
}
@@ -2794,7 +2794,7 @@ _gdk_win32_retrieve_clipboard_contentformats (GTask *task,
gsize mime_types_len;
gsize i;
g_assert (clipdrop->clipboard_window != NULL);
g_assert (clipdrop->clipboard_hwnd != NULL);
retr->parent.item_type = GDK_WIN32_CLIPBOARD_THREAD_QUEUE_ITEM_RETRIEVE;
retr->parent.start_time = g_get_monotonic_time ();
@@ -2809,7 +2809,7 @@ _gdk_win32_retrieve_clipboard_contentformats (GTask *task,
_gdk_win32_add_contentformat_to_pairs (mime_types[i], retr->pairs);
g_async_queue_push (clipdrop->clipboard_open_thread_queue, retr);
API_CALL (PostMessage, (clipdrop->clipboard_window, thread_wakeup_message, 0, 0));
API_CALL (PostMessage, (clipdrop->clipboard_hwnd, thread_wakeup_message, 0, 0));
return;
}
@@ -2890,7 +2890,7 @@ clipboard_store_hdata_ready (GObject *clipboard,
store->elements = prep->elements;
g_async_queue_push (clipdrop->clipboard_open_thread_queue, store);
API_CALL (PostMessage, (clipdrop->clipboard_window, thread_wakeup_message, 0, 0));
API_CALL (PostMessage, (clipdrop->clipboard_hwnd, thread_wakeup_message, 0, 0));
g_free (prep);
}
@@ -2907,7 +2907,7 @@ _gdk_win32_store_clipboard_contentformats (GdkClipboard *cb,
GdkWin32Clipdrop *clipdrop = _gdk_win32_clipdrop_get ();
GdkWin32ClipboardStorePrep *prep;
g_assert (clipdrop->clipboard_window != NULL);
g_assert (clipdrop->clipboard_hwnd != NULL);
mime_types = gdk_content_formats_get_mime_types (contentformats, &n_mime_types);

View File

@@ -178,12 +178,12 @@ struct _GdkWin32Clipdrop
*/
GAsyncQueue *clipboard_render_queue;
/* Window handle for the clipboard window that we
/* Window handle for the clipboard surface that we
* receive from the clipboard thread. We use that
* to wake up the clipboard window main loop by
* to wake up the clipboard surface main loop by
* posting a message to it.
*/
HWND clipboard_window;
HWND clipboard_hwnd;
/* The thread that calls DoDragDrop (), which would
* normally block our main thread, as it runs its own

View File

@@ -46,10 +46,10 @@
*
* Source drag context, IDropSource and IDataObject for it are created
* (almost) simultaneously, whereas target drag context and IDropTarget
* are separated in time - IDropTarget is created when a window is made
* are separated in time - IDropTarget is created when a surface is made
* to accept drops, while target drag context is created when a dragging
* cursor enters the window and is destroyed when that cursor leaves
* the window.
* cursor enters the surface and is destroyed when that cursor leaves
* the surface.
*
* There's a mismatch between data types supported by W32 (W32 formats)
* and by GTK (GDK contentformats).
@@ -130,7 +130,7 @@
* How managed DnD works:
* GTK widget detects a drag gesture and calls
* S: gdk_drag_begin_from_point() -> backend:drag_begin()
* which creates the source drag context and the drag window,
* which creates the source drag context and the drag surface,
* and grabs the pointing device. GDK layer adds the context
* to a list of currently-active contexts.
*
@@ -151,15 +151,15 @@
* mouse movement.
* Drag context handles it by calling a bunch of functions to
* determine the state of the drag actions from the keys being
* pressed, finding the drag window (another backend function
* pressed, finding the drag surface (another backend function
* routed through GDK layer) and finally calls
* S: gdk_drag_motion -> backend:drag_motion()
* to notify the backend (i.e. itself) that the drag cursor
* moved.
* The response to that is to move the drag window and
* The response to that is to move the drag surface and
* do various bookkeeping.
* W32: OLE2 protocol does nothing (other than moving the
* drag window) in response to this, as all the functions
* drag surface) in response to this, as all the functions
* that GDK could perform here are already handled by the
* OS driving the DnD process via DoDragDrop() call.
*
@@ -726,7 +726,7 @@ gdk_win32_drag_init (GdkWin32Drag *drag)
_win32_main_thread == g_thread_self ());
drag->handle_events = TRUE;
drag->dest_window = INVALID_HANDLE_VALUE;
drag->dest_hwnd = INVALID_HANDLE_VALUE;
GDK_NOTE (DND, g_print ("gdk_win32_drag_init %p\n", drag));
}
@@ -806,11 +806,11 @@ gdk_drag_new (GdkDisplay *display,
static enum_formats *enum_formats_new (GArray *formats);
/* Finds a GdkDrag object that corresponds to a DnD operation
* which is currently targeting the dest_window
* which is currently targeting the dest_hwnd
* Does not give a reference.
*/
GdkDrag *
_gdk_win32_find_drag_for_dest_window (HWND dest_window)
_gdk_win32_find_drag_for_dest_hwnd (HWND dest_hwnd)
{
GHashTableIter iter;
GdkWin32Drag *drag_win32;
@@ -820,7 +820,7 @@ _gdk_win32_find_drag_for_dest_window (HWND dest_window)
g_hash_table_iter_init (&iter, clipdrop->active_source_drags);
while (g_hash_table_iter_next (&iter, (gpointer *) &drag_win32, (gpointer *) &ddd))
if (ddd->src_context->dest_window_handle == dest_window)
if (ddd->src_context->dest_window_handle == dest_hwnd)
return GDK_DRAG (drag_win32);
return NULL;
@@ -867,7 +867,7 @@ notify_dnd_enter (gpointer user_data)
GdkWin32DnDEnterLeaveNotify *notify = (GdkWin32DnDEnterLeaveNotify *) user_data;
GdkWin32Drag *drag_win32 = GDK_WIN32_DRAG (notify->opaque_context);
drag_win32->dest_window = notify->target_window_handle;
drag_win32->dest_hwnd = notify->target_window_handle;
g_free (notify);
@@ -880,10 +880,10 @@ notify_dnd_leave (gpointer user_data)
GdkWin32DnDEnterLeaveNotify *notify = (GdkWin32DnDEnterLeaveNotify *) user_data;
GdkWin32Drag *drag_win32 = GDK_WIN32_DRAG (notify->opaque_context);
if (notify->target_window_handle != drag_win32->dest_window)
g_warning ("DnD leave says that the window handle is 0x%p, but drag has 0x%p", notify->target_window_handle, drag_win32->dest_window);
if (notify->target_window_handle != drag_win32->dest_hwnd)
g_warning ("DnD leave says that the window handle is 0x%p, but drag has 0x%p", notify->target_window_handle, drag_win32->dest_hwnd);
drag_win32->dest_window = INVALID_HANDLE_VALUE;
drag_win32->dest_hwnd = INVALID_HANDLE_VALUE;
g_free (notify);
@@ -1901,7 +1901,7 @@ gdk_win32_drag_drop_done (GdkDrag *drag,
anim->frame_clock = gdk_surface_get_frame_clock (drag_win32->drag_surface);
anim->start_time = gdk_frame_clock_get_frame_time (anim->frame_clock);
GDK_NOTE (DND, g_print ("gdk_win32_drag_drop_done: animate the drag window from %d : %d to %d : %d\n",
GDK_NOTE (DND, g_print ("gdk_win32_drag_drop_done: animate the drag surface from %d : %d to %d : %d\n",
drag_win32->util_data.last_x, drag_win32->util_data.last_y,
drag_win32->start_x, drag_win32->start_y));
@@ -2082,7 +2082,7 @@ gdk_dnd_handle_key_event (GdkDrag *drag,
case GDK_KEY_KP_Enter:
case GDK_KEY_KP_Space:
if ((gdk_drag_get_selected_action (drag) != 0) &&
(drag_win32->dest_window != INVALID_HANDLE_VALUE))
(drag_win32->dest_hwnd != INVALID_HANDLE_VALUE))
{
g_signal_emit_by_name (drag, "drop-performed");
}
@@ -2139,7 +2139,7 @@ gdk_dnd_handle_grab_broken_event (GdkDrag *drag,
GDK_NOTE (DND, g_print ("gdk_dnd_handle_grab_broken_event: 0x%p\n", drag));
/* Don't cancel if we break the implicit grab from the initial button_press.
* Also, don't cancel if we re-grab on the widget or on our grab window, for
* Also, don't cancel if we re-grab on the widget or on our grab surface, for
* example, when changing the drag cursor.
*/
if (/* FIXME: event->implicit || */

View File

@@ -133,7 +133,7 @@ struct _drop_target_context
*/
GdkSurface *surface;
/* This is given to us by the OS, we store it here
* until the drag leaves our window. It is referenced
* until the drag leaves our surface HWND. It is referenced
* (using COM reference counting).
*/
IDataObject *data_object;
@@ -476,7 +476,7 @@ idroptarget_dragenter (LPDROPTARGET This,
GArray *droptarget_w32format_contentformat_map;
GDK_NOTE (DND, g_print ("idroptarget_dragenter %p @ %ld : %ld"
" for dest window 0x%p"
" for dest surface 0x%p"
". dwOKEffects = %lu\n",
This, pt.x, pt.y,
ctx->surface,
@@ -490,7 +490,7 @@ idroptarget_dragenter (LPDROPTARGET This,
drag = NULL;
if (ctx->surface)
drag = _gdk_win32_find_drag_for_dest_window (GDK_SURFACE_HWND (ctx->surface));
drag = _gdk_win32_find_drag_for_dest_hwnd (GDK_SURFACE_HWND (ctx->surface));
display = gdk_surface_get_display (ctx->surface);
@@ -537,7 +537,7 @@ idroptarget_dragenter (LPDROPTARGET This,
/* NOTE: This method is called continuously, even if nothing is
* happening, as long as the drag operation is in progress and
* the cursor is above our window.
* the cursor is above our surface.
* It is OK to return a "safe" dropeffect value (DROPEFFECT_NONE,
* to indicate that the drop is not possible here), when we
* do not yet have any real information about acceptability of
@@ -685,7 +685,7 @@ static IDropTargetVtbl idt_vtbl = {
};
static drop_target_context *
target_context_new (GdkSurface *window)
target_context_new (GdkSurface *surface)
{
drop_target_context *result;
@@ -693,11 +693,11 @@ target_context_new (GdkSurface *window)
result->idt.lpVtbl = &idt_vtbl;
result->ref_count = 0;
result->surface = window;
result->surface = surface;
idroptarget_addref (&result->idt);
GDK_NOTE (DND, g_print ("target_context_new: %p (window %p)\n", result, result->surface));
GDK_NOTE (DND, g_print ("target_context_new: %p (surface %p)\n", result, result->surface));
return result;
}
@@ -880,35 +880,35 @@ gdk_destroy_filter (GdkXEvent *xev,
#endif
void
_gdk_win32_surface_register_dnd (GdkSurface *window)
_gdk_win32_surface_register_dnd (GdkSurface *surface)
{
drop_target_context *ctx;
HRESULT hr;
GdkWin32Surface *impl;
g_return_if_fail (window != NULL);
g_return_if_fail (surface != NULL);
if (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
if (g_object_get_data (G_OBJECT (surface), "gdk-dnd-registered") != NULL)
return;
else
g_object_set_data (G_OBJECT (window), "gdk-dnd-registered", GINT_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (surface), "gdk-dnd-registered", GINT_TO_POINTER (TRUE));
GDK_NOTE (DND, g_print ("gdk_win32_surface_register_dnd: %p\n", GDK_SURFACE_HWND (window)));
GDK_NOTE (DND, g_print ("gdk_win32_surface_register_dnd: %p\n", GDK_SURFACE_HWND (surface)));
impl = GDK_WIN32_SURFACE (window);
impl = GDK_WIN32_SURFACE (surface);
/* Return if window is already setup for DND. */
/* Return if surface is already setup for DND. */
if (impl->drop_target != NULL)
return;
ctx = target_context_new (window);
ctx = target_context_new (surface);
hr = CoLockObjectExternal ((IUnknown *) &ctx->idt, TRUE, FALSE);
if (!SUCCEEDED (hr))
OTHER_API_FAILED ("CoLockObjectExternal");
else
{
hr = RegisterDragDrop (GDK_SURFACE_HWND (window), &ctx->idt);
hr = RegisterDragDrop (GDK_SURFACE_HWND (surface), &ctx->idt);
if (hr == DRAGDROP_E_ALREADYREGISTERED)
{
g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
@@ -924,9 +924,9 @@ _gdk_win32_surface_register_dnd (GdkSurface *window)
}
void
_gdk_win32_surface_unregister_dnd (GdkSurface *window)
_gdk_win32_surface_unregister_dnd (GdkSurface *surface)
{
GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
GdkWin32Surface *impl = GDK_WIN32_SURFACE (surface);
if (impl->drop_target)
idroptarget_release (&impl->drop_target->idt);

View File

@@ -52,10 +52,10 @@ struct _GdkWin32Drag
*/
GdkSurface *grab_surface;
/* The window currently under cursor.
/* The HWND currently under cursor.
* Will be INVALID_HANDLE_VALUE (not NULL!) if it is not known
*/
HWND dest_window;
HWND dest_hwnd;
/* The surface that we move along with the cursor to indicate
* what exactly is being dragged.
@@ -91,9 +91,9 @@ struct _GdkWin32DragClass
};
gpointer _gdk_win32_dnd_thread_main (gpointer data);
gpointer _gdk_win32_dnd_thread_main (gpointer data);
GdkDrag *_gdk_win32_find_drag_for_dest_window (HWND dest_window);
GdkDrag *_gdk_win32_find_drag_for_dest_hwnd (HWND dest_hwnd);
G_END_DECLS