Re: GTK TreeView control in Windows (DND issue)



On 18/09/2011 01:03, Dieter Verfaillie wrote:
> Currently, my best guess is that the WindowFromPoint() call
> doesn't give us the hwnd we're supposed to get in this case
> (in gdkdnd-win32.c::gdk_drag_find_window_for_screen(), around
> line 1988 with Peter's patches applied).

Digging deeper, it is part of the changes done in commit
http://git.gnome.org/browse/gtk+/commit/gdk/win32/gdkdnd-win32.c?h=gtk-2-24&id=eb21a7df290936223f6a80cef36b52a8c68a1d22
that is responsible for this problem.

Reverting gdk_drag_find_window_for_screen to the 2.16 era logic
effectively fixes treeview dnd (see attached patch). Have not yet
tested if this breaks other things so this patch needs more work.

This does most likely does break the wip generic OLE DnD method
though, but I'm not sure if we should care much about that in
the 2.24 branch?

So we're getting closer :)

mvg,
Dieter
>From e058ed7653b0166bb0ef88de0309ce94af8d7a01 Mon Sep 17 00:00:00 2001
From: Dieter Verfaillie <dieterv optionexplicit be>
Date: Sun, 18 Sep 2011 10:54:55 +0200
Subject: [PATCH] [WIP] Revert gdk_drag_find_window_for_screen to GTK+ 2.16
 era logic.

Fixes TreeView DnD, but most likely breaks generic OLE DnD...
---
 gdk/win32/gdkdnd-win32.c |   73 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c
index daf5291..c01f998 100644
--- a/gdk/win32/gdkdnd-win32.c
+++ b/gdk/win32/gdkdnd-win32.c
@@ -1970,6 +1970,43 @@ gdk_drag_get_protocol_for_display (GdkDisplay      *display,
   return 0;
 }
 
+typedef struct {
+  gint x;
+  gint y;
+  HWND ignore;
+  HWND result;
+} find_window_enum_arg;
+
+static BOOL CALLBACK
+find_window_enum_proc (HWND   hwnd,
+                       LPARAM lparam)
+{
+  RECT rect;
+  POINT tl, br;
+  find_window_enum_arg *a = (find_window_enum_arg *) lparam;
+
+  if (hwnd == a->ignore)
+    return TRUE;
+
+  if (!IsWindowVisible (hwnd))
+    return TRUE;
+
+  tl.x = tl.y = 0;
+  ClientToScreen (hwnd, &tl);
+  GetClientRect (hwnd, &rect);
+  br.x = rect.right;
+  br.y = rect.bottom;
+  ClientToScreen (hwnd, &br);
+
+  if (a->x >= tl.x && a->y >= tl.y && a->x < br.x && a->y < br.y)
+    {
+      a->result = hwnd;
+      return FALSE;
+    }
+  else
+    return TRUE;
+}
+
 void
 gdk_drag_find_window_for_screen (GdkDragContext  *context,
 				 GdkWindow       *drag_window,
@@ -1979,37 +2016,41 @@ gdk_drag_find_window_for_screen (GdkDragContext  *context,
 				 GdkWindow      **dest_window,
 				 GdkDragProtocol *protocol)
 {
-  POINT pt;
-  HWND hwnd;
+  find_window_enum_arg a;
 
-  pt.x = x_root - _gdk_offset_x;
-  pt.y = y_root - _gdk_offset_y;
+  a.x = x_root - _gdk_offset_x;
+  a.y = y_root - _gdk_offset_y;
+  a.ignore = drag_window ? GDK_WINDOW_HWND (drag_window) : NULL;
+  a.result = NULL;
 
-  hwnd = WindowFromPoint (pt);
+  EnumWindows (find_window_enum_proc, (LPARAM) &a);
 
-  if (hwnd == NULL)
+  if (a.result == NULL)
     *dest_window = NULL;
   else
     {
-      *dest_window = gdk_win32_handle_table_lookup (hwnd);
+      *dest_window = gdk_win32_handle_table_lookup (a.result);
       if (*dest_window)
-	g_object_ref (*dest_window);
-      else
-	*dest_window = gdk_window_foreign_new_for_display (_gdk_display, hwnd);
-
-      if (use_ole2_dnd)
-	*protocol = GDK_DRAG_PROTO_OLE2;
-      else if (context->source_window)
+        {
+          *dest_window = gdk_window_get_toplevel (*dest_window);
+          g_object_ref (*dest_window);
+        }
+
+      if (context->source_window)
+#ifdef OLE2_DND
+        *protocol = GDK_DRAG_PROTO_OLE2;
+#else
         *protocol = GDK_DRAG_PROTO_LOCAL;
+#endif
       else
-	*protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
+        *protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
     }
 
   GDK_NOTE (DND,
 	    g_print ("gdk_drag_find_window: %p %+d%+d: %p: %p %s\n",
 		     (drag_window ? GDK_WINDOW_HWND (drag_window) : NULL),
 		     x_root, y_root,
-		     hwnd,
+		     a.result,
 		     (*dest_window ? GDK_WINDOW_HWND (*dest_window) : NULL),
 		     _gdk_win32_drag_protocol_to_string (*protocol)));
 }
-- 
1.7.6.msysgit.0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]