[gtk+] gtk: fixes for offscreen widgets



commit fdf936b5ad62818a6e9dfc4b906175de94af8224
Author: Michael Natterer <mitch gimp org>
Date:   Thu Apr 15 13:02:04 2010 +0200

    gtk: fixes for offscreen widgets
    
    Fix gtk_widget_translate_coordinates() and
    _gtk_widget_synthesize_crossing() so they work in hierarchies with
    offscreen widgets.

 gtk/gtkwidget.c |   55 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f02b481..58ed371 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4183,6 +4183,7 @@ gtk_widget_translate_coordinates (GtkWidget  *src_widget,
 {
   GtkWidget *ancestor;
   GdkWindow *window;
+  GList *dest_list = NULL;
 
   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
@@ -4210,14 +4211,14 @@ gtk_widget_translate_coordinates (GtkWidget  *src_widget,
   window = src_widget->window;
   while (window != ancestor->window)
     {
-      gint dx, dy;
-      
-      gdk_window_get_position (window, &dx, &dy);
-      
-      src_x += dx;
-      src_y += dy;
-      
-      window = gdk_window_get_parent (window);
+      gdouble dx, dy;
+
+      gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
+
+      src_x = dx;
+      src_y = dy;
+
+      window = gdk_window_get_effective_parent (window);
 
       if (!window)		/* Handle GtkHandleBox */
 	return FALSE;
@@ -4227,17 +4228,27 @@ gtk_widget_translate_coordinates (GtkWidget  *src_widget,
   window = dest_widget->window;
   while (window != ancestor->window)
     {
-      gint dx, dy;
-      
-      gdk_window_get_position (window, &dx, &dy);
-      
-      src_x -= dx;
-      src_y -= dy;
-      
-      window = gdk_window_get_parent (window);
-      
+      dest_list = g_list_prepend (dest_list, window);
+
+      window = gdk_window_get_effective_parent (window);
+
       if (!window)		/* Handle GtkHandleBox */
-	return FALSE;
+        {
+          g_list_free (dest_list);
+          return FALSE;
+        }
+    }
+
+  while (dest_list)
+    {
+      gdouble dx, dy;
+
+      gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
+
+      src_x = dx;
+      src_y = dy;
+
+      dest_list = g_list_remove (dest_list, dest_list->data);
     }
 
   /* Translate from window relative to allocation relative */
@@ -9030,7 +9041,7 @@ _gtk_widget_synthesize_crossing (GtkWidget      *from,
 
       while (from_ancestor != NULL)
 	{
-	  from_ancestor = gdk_window_get_parent (from_ancestor);
+	  from_ancestor = gdk_window_get_effective_parent (from_ancestor);
           if (from_ancestor == NULL)
             break;
           from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
@@ -9055,7 +9066,7 @@ _gtk_widget_synthesize_crossing (GtkWidget      *from,
 
       while (to_ancestor != NULL)
 	{
-	  to_ancestor = gdk_window_get_parent (to_ancestor);
+	  to_ancestor = gdk_window_get_effective_parent (to_ancestor);
 	  if (to_ancestor == NULL)
             break;
           to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
@@ -9084,7 +9095,7 @@ _gtk_widget_synthesize_crossing (GtkWidget      *from,
 	{
 	  if (from_ancestor != NULL)
 	    {
-	      from_ancestor = gdk_window_get_parent (from_ancestor);
+	      from_ancestor = gdk_window_get_effective_parent (from_ancestor);
 	      if (from_ancestor == to_window)
 		break;
               if (from_ancestor)
@@ -9092,7 +9103,7 @@ _gtk_widget_synthesize_crossing (GtkWidget      *from,
 	    }
 	  if (to_ancestor != NULL)
 	    {
-	      to_ancestor = gdk_window_get_parent (to_ancestor);
+	      to_ancestor = gdk_window_get_effective_parent (to_ancestor);
 	      if (to_ancestor == from_window)
 		break;
               if (to_ancestor)



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