[gtk+] Add gtk_widget_(un)register_window



commit 3d4cd4db3ed9f6c47566a69d745441e2662ac2ab
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Feb 5 09:36:49 2013 +0100

    Add gtk_widget_(un)register_window
    
    This replaces the previously hardcoded calls to gdk_window_set_user_data,
    and also lets us track which windows are a part of a widget. Old code
    should continue working as is, but new features that require the
    windows may not work perfectly.
    
    We need this for the transparent widget support to work, as we need
    to specially mark the windows of child widgets.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687842

 gtk/gtk.symbols            |    2 +
 gtk/gtkbutton.c            |    4 +-
 gtk/gtkcalendar.c          |    8 ++--
 gtk/gtkcolorswatch.c       |    4 +-
 gtk/gtkdrawingarea.c       |    2 +-
 gtk/gtkentry.c             |    6 ++--
 gtk/gtkeventbox.c          |    6 ++--
 gtk/gtkexpander.c          |    4 +-
 gtk/gtkfixed.c             |    2 +-
 gtk/gtkiconview.c          |    6 ++--
 gtk/gtkinvisible.c         |    2 +-
 gtk/gtklabel.c             |    4 +-
 gtk/gtklayout.c            |    6 ++--
 gtk/gtkmenu.c              |   14 ++++----
 gtk/gtkmenuitem.c          |    4 +-
 gtk/gtkmenushell.c         |    2 +-
 gtk/gtkmisc.c              |    2 +-
 gtk/gtknotebook.c          |    8 ++--
 gtk/gtkoffscreenwindow.c   |    2 +-
 gtk/gtkoverlay.c           |    6 ++--
 gtk/gtkpaned.c             |   10 +++---
 gtk/gtkpathbar.c           |    4 +-
 gtk/gtkplug.c              |    6 ++--
 gtk/gtkrange.c             |    4 +-
 gtk/gtkscrolledwindow.c    |    4 +-
 gtk/gtkseparatortoolitem.c |    4 +-
 gtk/gtksocket.c            |    2 +-
 gtk/gtkspinbutton.c        |    8 ++--
 gtk/gtkswitch.c            |    4 +-
 gtk/gtktexthandle.c        |    3 +-
 gtk/gtktextview.c          |   10 +++---
 gtk/gtktoolbar.c           |    4 +-
 gtk/gtktoolitem.c          |    4 +-
 gtk/gtktoolitemgroup.c     |    2 +-
 gtk/gtktoolpalette.c       |    2 +-
 gtk/gtktreeview.c          |   31 +++++++++-----------
 gtk/gtktreeviewcolumn.c    |    4 +-
 gtk/gtkviewport.c          |   10 +++---
 gtk/gtkwidget.c            |   67 +++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkwidget.h            |    6 ++++
 gtk/gtkwin32embedwidget.c  |    4 +-
 gtk/gtkwindow.c            |    8 ++--
 42 files changed, 183 insertions(+), 112 deletions(-)
---
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index eb10a91..9f0d61a 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -3839,6 +3839,7 @@ gtk_widget_queue_resize
 gtk_widget_queue_resize_no_redraw
 gtk_widget_realize
 gtk_widget_region_intersect
+gtk_widget_register_window
 gtk_widget_remove_accelerator
 gtk_widget_remove_mnemonic_label
 gtk_widget_render_icon
@@ -3909,6 +3910,7 @@ gtk_widget_trigger_tooltip_query
 gtk_widget_unmap
 gtk_widget_unparent
 gtk_widget_unrealize
+gtk_widget_unregister_window
 gtk_widget_unset_state_flags
 gtk_widget_insert_action_group
 #ifdef GDK_WINDOWING_WIN32
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 824f498..3ac36a7 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1420,7 +1420,7 @@ gtk_button_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (window,
                                        &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, button);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -1434,7 +1434,7 @@ gtk_button_unrealize (GtkWidget *widget)
 
   if (priv->event_window)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 89d4142..cfceb08 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -1593,7 +1593,7 @@ calendar_realize_arrows (GtkCalendar *calendar)
                                                &attributes,
                                                attributes_mask);
 
-          gdk_window_set_user_data (priv->arrow_win[i], widget);
+          gtk_widget_register_window (widget, priv->arrow_win[i]);
         }
       priv->arrow_prelight = 0x0;
     }
@@ -1614,7 +1614,7 @@ calendar_unrealize_arrows (GtkCalendar *calendar)
     {
       if (priv->arrow_win[i])
         {
-          gdk_window_set_user_data (priv->arrow_win[i], NULL);
+          gtk_widget_unregister_window (GTK_WIDGET (calendar), priv->arrow_win[i]);
           gdk_window_destroy (priv->arrow_win[i]);
           priv->arrow_win[i] = NULL;
         }
@@ -1704,7 +1704,7 @@ gtk_calendar_realize (GtkWidget *widget)
 
   priv->main_win = gdk_window_new (gtk_widget_get_window (widget),
                                    &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->main_win, widget);
+  gtk_widget_register_window (widget, priv->main_win);
 
   calendar_realize_arrows (GTK_CALENDAR (widget));
 }
@@ -1718,7 +1718,7 @@ gtk_calendar_unrealize (GtkWidget *widget)
 
   if (priv->main_win)
     {
-      gdk_window_set_user_data (priv->main_win, NULL);
+      gtk_widget_unregister_window (widget, priv->main_win);
       gdk_window_destroy (priv->main_win);
       priv->main_win = NULL;
     }
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index f6d662b..e33a3f6 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -628,7 +628,7 @@ swatch_realize (GtkWidget *widget)
   swatch->priv->event_window = 
     gdk_window_new (window,
                     &attributes, attributes_mask);
-  gdk_window_set_user_data (swatch->priv->event_window, widget);
+  gtk_widget_register_window (widget, swatch->priv->event_window);
 }
 
 static void
@@ -638,7 +638,7 @@ swatch_unrealize (GtkWidget *widget)
 
   if (swatch->priv->event_window)
     {
-      gdk_window_set_user_data (swatch->priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, swatch->priv->event_window);
       gdk_window_destroy (swatch->priv->event_window);
       swatch->priv->event_window = NULL;
     }
diff --git a/gtk/gtkdrawingarea.c b/gtk/gtkdrawingarea.c
index 912992b..60b958f 100644
--- a/gtk/gtkdrawingarea.c
+++ b/gtk/gtkdrawingarea.c
@@ -194,7 +194,7 @@ gtk_drawing_area_realize (GtkWidget *widget)
 
       window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                &attributes, attributes_mask);
-      gdk_window_set_user_data (window, darea);
+      gtk_widget_register_window (widget, window);
       gtk_widget_set_window (widget, window);
 
       gtk_style_context_set_background (gtk_widget_get_style_context (widget),
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 184277c..d6a3804 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -2973,7 +2973,7 @@ realize_icon_info (GtkWidget            *widget,
   icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
                                       &attributes,
                                       attributes_mask);
-  gdk_window_set_user_data (icon_info->window, widget);
+  gtk_widget_register_window (widget, icon_info->window);
 
   gtk_widget_queue_resize (widget);
 }
@@ -3100,7 +3100,7 @@ gtk_entry_realize (GtkWidget *widget)
                                     &attributes,
                                     attributes_mask);
 
-  gdk_window_set_user_data (priv->text_area, entry);
+  gtk_widget_register_window (widget, priv->text_area);
 
   if (attributes_mask & GDK_WA_CURSOR)
     g_object_unref (attributes.cursor);
@@ -3145,7 +3145,7 @@ gtk_entry_unrealize (GtkWidget *widget)
   
   if (priv->text_area)
     {
-      gdk_window_set_user_data (priv->text_area, NULL);
+      gtk_widget_unregister_window (widget, priv->text_area);
       gdk_window_destroy (priv->text_area);
       priv->text_area = NULL;
     }
diff --git a/gtk/gtkeventbox.c b/gtk/gtkeventbox.c
index 6f0b027..98025be 100644
--- a/gtk/gtkeventbox.c
+++ b/gtk/gtkeventbox.c
@@ -429,7 +429,7 @@ gtk_event_box_realize (GtkWidget *widget)
       window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                &attributes, attributes_mask);
       gtk_widget_set_window (widget, window);
-      gdk_window_set_user_data (window, widget);
+      gtk_widget_register_window (widget, window);
     }
   else
     {
@@ -448,7 +448,7 @@ gtk_event_box_realize (GtkWidget *widget)
 
       priv->event_window = gdk_window_new (window,
                                            &attributes, attributes_mask);
-      gdk_window_set_user_data (priv->event_window, widget);
+      gtk_widget_register_window (widget, priv->event_window);
     }
 
   if (visible_window)
@@ -462,7 +462,7 @@ gtk_event_box_unrealize (GtkWidget *widget)
 
   if (priv->event_window != NULL)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index d4253e8..6f6a196 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -577,7 +577,7 @@ gtk_expander_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                        &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, widget);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -587,7 +587,7 @@ gtk_expander_unrealize (GtkWidget *widget)
 
   if (priv->event_window)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtkfixed.c b/gtk/gtkfixed.c
index 1d09e0d..14c35af 100644
--- a/gtk/gtkfixed.c
+++ b/gtk/gtkfixed.c
@@ -379,7 +379,7 @@ gtk_fixed_realize (GtkWidget *widget)
       window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                &attributes, attributes_mask);
       gtk_widget_set_window (widget, window);
-      gdk_window_set_user_data (window, widget);
+      gtk_widget_register_window (widget, window);
 
       gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                         window);
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index ffbbbba..0c6dc03 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -1301,7 +1301,7 @@ gtk_icon_view_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -1322,7 +1322,7 @@ gtk_icon_view_realize (GtkWidget *widget)
   
   icon_view->priv->bin_window = gdk_window_new (window,
 						&attributes, attributes_mask);
-  gdk_window_set_user_data (icon_view->priv->bin_window, widget);
+  gtk_widget_register_window (widget, icon_view->priv->bin_window);
 
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_set_background (context, icon_view->priv->bin_window);
@@ -1338,7 +1338,7 @@ gtk_icon_view_unrealize (GtkWidget *widget)
 
   icon_view = GTK_ICON_VIEW (widget);
 
-  gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
+  gtk_widget_unregister_window (widget, icon_view->priv->bin_window);
   gdk_window_destroy (icon_view->priv->bin_window);
   icon_view->priv->bin_window = NULL;
 
diff --git a/gtk/gtkinvisible.c b/gtk/gtkinvisible.c
index a98b18d..27ca250 100644
--- a/gtk/gtkinvisible.c
+++ b/gtk/gtkinvisible.c
@@ -260,7 +260,7 @@ gtk_invisible_realize (GtkWidget *widget)
 
   window = gdk_window_new (parent, &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 }
 
 static void
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 942c093..bc17554 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4982,7 +4982,7 @@ gtk_label_create_window (GtkLabel *label)
 
   priv->select_info->window = gdk_window_new (gtk_widget_get_window (widget),
                                                &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->select_info->window, widget);
+  gtk_widget_register_window (widget, priv->select_info->window);
 
   if (attributes_mask & GDK_WA_CURSOR)
     g_object_unref (attributes.cursor);
@@ -4998,7 +4998,7 @@ gtk_label_destroy_window (GtkLabel *label)
   if (priv->select_info->window == NULL)
     return;
 
-  gdk_window_set_user_data (priv->select_info->window, NULL);
+  gtk_widget_unregister_window (GTK_WIDGET (label), priv->select_info->window);
   gdk_window_destroy (priv->select_info->window);
   priv->select_info->window = NULL;
 }
diff --git a/gtk/gtklayout.c b/gtk/gtklayout.c
index 10528bb..73cdb62 100644
--- a/gtk/gtklayout.c
+++ b/gtk/gtklayout.c
@@ -885,7 +885,7 @@ gtk_layout_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -899,7 +899,7 @@ gtk_layout_realize (GtkWidget *widget)
 
   priv->bin_window = gdk_window_new (window,
                                      &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->bin_window, widget);
+  gtk_widget_register_window (widget, priv->bin_window);
   gtk_style_context_set_background (gtk_widget_get_style_context (widget), priv->bin_window);
 
   tmp_list = priv->children;
@@ -958,7 +958,7 @@ gtk_layout_unrealize (GtkWidget *widget)
   GtkLayout *layout = GTK_LAYOUT (widget);
   GtkLayoutPrivate *priv = layout->priv;
 
-  gdk_window_set_user_data (priv->bin_window, NULL);
+  gtk_widget_unregister_window (widget, priv->bin_window);
   gdk_window_destroy (priv->bin_window);
   priv->bin_window = NULL;
 
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 208f95e..79bde09 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2551,7 +2551,7 @@ gtk_menu_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   get_menu_padding (widget, &padding);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
@@ -2576,7 +2576,7 @@ gtk_menu_realize (GtkWidget *widget)
 
   priv->view_window = gdk_window_new (window,
                                       &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->view_window, menu);
+  gtk_widget_register_window (widget, priv->view_window);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -2592,7 +2592,7 @@ gtk_menu_realize (GtkWidget *widget)
 
   priv->bin_window = gdk_window_new (priv->view_window,
                                      &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->bin_window, menu);
+  gtk_widget_register_window (widget, priv->bin_window);
 
   children = GTK_MENU_SHELL (menu)->priv->children;
   while (children)
@@ -2648,7 +2648,7 @@ menu_grab_transfer_window_get (GtkMenu *menu)
 
       window = gdk_window_new (gtk_widget_get_root_window (GTK_WIDGET (menu)),
                                &attributes, attributes_mask);
-      gdk_window_set_user_data (window, menu);
+      gtk_widget_register_window (GTK_WIDGET (menu), window);
 
       gdk_window_show (window);
 
@@ -2664,7 +2664,7 @@ menu_grab_transfer_window_destroy (GtkMenu *menu)
   GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window");
   if (window)
     {
-      gdk_window_set_user_data (window, NULL);
+      gtk_widget_unregister_window (GTK_WIDGET (menu), window);
       gdk_window_destroy (window);
       g_object_set_data (G_OBJECT (menu), I_("gtk-menu-transfer-window"), NULL);
     }
@@ -2678,11 +2678,11 @@ gtk_menu_unrealize (GtkWidget *widget)
 
   menu_grab_transfer_window_destroy (menu);
 
-  gdk_window_set_user_data (priv->view_window, NULL);
+  gtk_widget_unregister_window (widget, priv->view_window);
   gdk_window_destroy (priv->view_window);
   priv->view_window = NULL;
 
-  gdk_window_set_user_data (priv->bin_window, NULL);
+  gtk_widget_unregister_window (widget, priv->bin_window);
   gdk_window_destroy (priv->bin_window);
   priv->bin_window = NULL;
 
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index c3f50e1..73c2545 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -1566,7 +1566,7 @@ gtk_menu_item_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                        &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, widget);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -1575,7 +1575,7 @@ gtk_menu_item_unrealize (GtkWidget *widget)
   GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
   GtkMenuItemPrivate *priv = menu_item->priv;
 
-  gdk_window_set_user_data (priv->event_window, NULL);
+  gtk_widget_unregister_window (widget, priv->event_window);
   gdk_window_destroy (priv->event_window);
   priv->event_window = NULL;
 
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 30de337..ae36459 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -649,7 +649,7 @@ gtk_menu_shell_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_set_background (context, window);
diff --git a/gtk/gtkmisc.c b/gtk/gtkmisc.c
index bb5b3f3..4bd162c 100644
--- a/gtk/gtkmisc.c
+++ b/gtk/gtkmisc.c
@@ -397,7 +397,7 @@ gtk_misc_realize (GtkWidget *widget)
 
       window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
       gtk_widget_set_window (widget, window);
-      gdk_window_set_user_data (window, widget);
+      gtk_widget_register_window (widget, window);
       gdk_window_set_background_pattern (window, NULL);
     }
 }
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 377dc90..5f0ce00 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1908,7 +1908,7 @@ gtk_notebook_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                            &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, notebook);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -1917,13 +1917,13 @@ gtk_notebook_unrealize (GtkWidget *widget)
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
 
-  gdk_window_set_user_data (priv->event_window, NULL);
+  gtk_widget_unregister_window (widget, priv->event_window);
   gdk_window_destroy (priv->event_window);
   priv->event_window = NULL;
 
   if (priv->drag_window)
     {
-      gdk_window_set_user_data (priv->drag_window, NULL);
+      gtk_widget_unregister_window (widget, priv->drag_window);
       gdk_window_destroy (priv->drag_window);
       priv->drag_window = NULL;
     }
@@ -3126,7 +3126,7 @@ show_drag_window (GtkNotebook        *notebook,
       priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                           &attributes,
                                           attributes_mask);
-      gdk_window_set_user_data (priv->drag_window, widget);
+      gtk_widget_register_window (widget, priv->drag_window);
       gdk_window_set_background_rgba (priv->drag_window, &transparent);
     }
 
diff --git a/gtk/gtkoffscreenwindow.c b/gtk/gtkoffscreenwindow.c
index e5a33cc..8e9f23f 100644
--- a/gtk/gtkoffscreenwindow.c
+++ b/gtk/gtkoffscreenwindow.c
@@ -183,7 +183,7 @@ gtk_offscreen_window_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   child = gtk_bin_get_child (bin);
   if (child)
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index a66ede8..de80637 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -105,7 +105,7 @@ gtk_overlay_create_child_window (GtkOverlay *overlay,
 
   window = gdk_window_new (gtk_widget_get_window (widget),
                            &attributes, attributes_mask);
-  gdk_window_set_user_data (window, overlay);
+  gtk_widget_register_window (widget, window);
   gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
 
   gtk_widget_set_parent_window (child, window);
@@ -443,7 +443,7 @@ gtk_overlay_unrealize (GtkWidget *widget)
       child = children->data;
 
       gtk_widget_set_parent_window (child->widget, NULL);
-      gdk_window_set_user_data (child->window, NULL);
+      gtk_widget_unregister_window (widget, child->window);
       gdk_window_destroy (child->window);
       child->window = NULL;
     }
@@ -539,7 +539,7 @@ gtk_overlay_remove (GtkContainer *container,
         {
           if (child->window != NULL)
             {
-              gdk_window_set_user_data (child->window, NULL);
+              gtk_widget_unregister_window (GTK_WIDGET (container), child->window);
               gdk_window_destroy (child->window);
             }
 
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 5b374b2..7c5ec38 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -1320,7 +1320,7 @@ gtk_paned_create_child_window (GtkPaned  *paned,
 
   window = gdk_window_new (gtk_widget_get_window (widget),
                            &attributes, attributes_mask);
-  gdk_window_set_user_data (window, paned);
+  gtk_widget_register_window (widget, window);
   gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
 
   if (child)
@@ -1366,7 +1366,7 @@ gtk_paned_realize (GtkWidget *widget)
 
   priv->handle = gdk_window_new (window,
                                  &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->handle, paned);
+  gtk_widget_register_window (widget, priv->handle);
   if (attributes_mask & GDK_WA_CURSOR)
     g_object_unref (attributes.cursor);
 
@@ -1382,19 +1382,19 @@ gtk_paned_unrealize (GtkWidget *widget)
 
   if (priv->child2)
     gtk_widget_set_parent_window (priv->child2, NULL);
-  gdk_window_set_user_data (priv->child2_window, NULL);
+  gtk_widget_unregister_window (widget, priv->child2_window);
   gdk_window_destroy (priv->child2_window);
   priv->child2_window = NULL;
 
   if (priv->child1)
     gtk_widget_set_parent_window (priv->child1, NULL);
-  gdk_window_set_user_data (priv->child1_window, NULL);
+  gtk_widget_unregister_window (widget, priv->child1_window);
   gdk_window_destroy (priv->child1_window);
   priv->child1_window = NULL;
 
   if (priv->handle)
     {
-      gdk_window_set_user_data (priv->handle, NULL);
+      gtk_widget_unregister_window (widget, priv->handle);
       gdk_window_destroy (priv->handle);
       priv->handle = NULL;
     }
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index aec2b0a..03ac4c9 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -472,7 +472,7 @@ gtk_path_bar_realize (GtkWidget *widget)
 
   path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                            &attributes, attributes_mask);
-  gdk_window_set_user_data (path_bar->event_window, widget);
+  gtk_widget_register_window (widget, path_bar->event_window);
 }
 
 static void
@@ -482,7 +482,7 @@ gtk_path_bar_unrealize (GtkWidget *widget)
 
   path_bar = GTK_PATH_BAR (widget);
 
-  gdk_window_set_user_data (path_bar->event_window, NULL);
+  gtk_widget_unregister_window (widget, path_bar->event_window);
   gdk_window_destroy (path_bar->event_window);
   path_bar->event_window = NULL;
 
diff --git a/gtk/gtkplug.c b/gtk/gtkplug.c
index 9c019dd..65df936 100644
--- a/gtk/gtkplug.c
+++ b/gtk/gtkplug.c
@@ -677,7 +677,7 @@ gtk_plug_unrealize (GtkWidget *widget)
 
   if (priv->socket_window != NULL)
     {
-      gdk_window_set_user_data (priv->socket_window, NULL);
+      gtk_widget_unregister_window (widget, priv->socket_window);
       g_object_unref (priv->socket_window);
       priv->socket_window = NULL;
 
@@ -879,7 +879,7 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
 	      {
 		GtkWidget *widget = GTK_WIDGET (plug);
 
-                gdk_window_set_user_data (priv->socket_window, NULL);
+                gtk_widget_unregister_window (widget, priv->socket_window);
 		g_object_unref (priv->socket_window);
 		priv->socket_window = NULL;
 
@@ -1088,7 +1088,7 @@ gtk_plug_realize (GtkWidget *widget)
       gtk_widget_set_window (widget, gdk_window);
     }
 
-  gdk_window_set_user_data (gdk_window, window);
+  gtk_widget_register_window (widget, gdk_window);
 
   gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                     gdk_window);
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 775503a..d627566 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -1738,7 +1738,7 @@ gtk_range_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 					&attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, range);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -1749,7 +1749,7 @@ gtk_range_unrealize (GtkWidget *widget)
 
   gtk_range_remove_step_timer (range);
 
-  gdk_window_set_user_data (priv->event_window, NULL);
+  gtk_widget_unregister_window (widget, priv->event_window);
   gdk_window_destroy (priv->event_window);
   priv->event_window = NULL;
 
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index a5dd811..0095072 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -3392,7 +3392,7 @@ gtk_scrolled_window_realize (GtkWidget *widget)
   scrolled_window->priv->overshoot_window =
     gdk_window_new (gtk_widget_get_parent_window (widget),
                     &attributes, attributes_mask);
-  gdk_window_set_user_data (scrolled_window->priv->overshoot_window, widget);
+  gtk_widget_register_window (widget, scrolled_window->priv->overshoot_window);
 
   child_widget = gtk_bin_get_child (GTK_BIN (widget));
 
@@ -3408,7 +3408,7 @@ gtk_scrolled_window_unrealize (GtkWidget *widget)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
 
-  gdk_window_set_user_data (scrolled_window->priv->overshoot_window, NULL);
+  gtk_widget_unregister_window (widget, scrolled_window->priv->overshoot_window);
   gdk_window_destroy (scrolled_window->priv->overshoot_window);
   scrolled_window->priv->overshoot_window = NULL;
 
diff --git a/gtk/gtkseparatortoolitem.c b/gtk/gtkseparatortoolitem.c
index 5df1199..33a003a 100644
--- a/gtk/gtkseparatortoolitem.c
+++ b/gtk/gtkseparatortoolitem.c
@@ -304,7 +304,7 @@ gtk_separator_tool_item_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                        &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, widget);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -315,7 +315,7 @@ gtk_separator_tool_item_unrealize (GtkWidget *widget)
 
   if (priv->event_window)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtksocket.c b/gtk/gtksocket.c
index c787636..fc893b8 100644
--- a/gtk/gtksocket.c
+++ b/gtk/gtksocket.c
@@ -404,7 +404,7 @@ gtk_socket_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, socket);
+  gtk_widget_register_window (widget, window);
 
   gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                     window);
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index bc1e4a8..c20a69f 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1034,7 +1034,7 @@ gtk_spin_button_realize (GtkWidget *widget)
 
   priv->down_panel = gdk_window_new (gtk_widget_get_window (widget),
                                      &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->down_panel, widget);
+  gtk_widget_register_window (widget, priv->down_panel);
 
   /* create the right panel window */
   attributes.x = up_allocation.x;
@@ -1044,7 +1044,7 @@ gtk_spin_button_realize (GtkWidget *widget)
 
   priv->up_panel = gdk_window_new (gtk_widget_get_window (widget),
                                       &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->up_panel, widget);
+  gtk_widget_register_window (widget, priv->up_panel);
 
   return_val = FALSE;
   g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val);
@@ -1064,14 +1064,14 @@ gtk_spin_button_unrealize (GtkWidget *widget)
 
   if (priv->down_panel)
     {
-      gdk_window_set_user_data (priv->down_panel, NULL);
+      gtk_widget_unregister_window (widget, priv->down_panel);
       gdk_window_destroy (priv->down_panel);
       priv->down_panel = NULL;
     }
 
   if (priv->up_panel)
     {
-      gdk_window_set_user_data (priv->up_panel, NULL);
+      gtk_widget_unregister_window (widget, priv->up_panel);
       gdk_window_destroy (priv->up_panel);
       priv->up_panel = NULL;
     }
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index d2e575d..dfcfedc 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -458,7 +458,7 @@ gtk_switch_realize (GtkWidget *widget)
   priv->event_window = gdk_window_new (parent_window,
                                        &attributes,
                                        attributes_mask);
-  gdk_window_set_user_data (priv->event_window, widget);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -468,7 +468,7 @@ gtk_switch_unrealize (GtkWidget *widget)
 
   if (priv->event_window != NULL)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtktexthandle.c b/gtk/gtktexthandle.c
index 6c7033b..871b3ac 100644
--- a/gtk/gtktexthandle.c
+++ b/gtk/gtktexthandle.c
@@ -197,7 +197,7 @@ _gtk_text_handle_create_window (GtkTextHandle         *handle,
 
   window = gdk_window_new (gtk_widget_get_root_window (priv->parent),
 			   &attributes, mask);
-  gdk_window_set_user_data (window, priv->parent);
+  gtk_widget_register_window (priv->parent, window);
   gdk_window_set_background_rgba (window, &bg);
 
   _gtk_text_handle_update_shape (handle, window, pos);
@@ -304,6 +304,7 @@ _gtk_text_handle_update_window (GtkTextHandle         *handle,
                                   width / 2, 0, &x, &y);
     }
 
+  gtk_widget_unregister_window (priv->parent, handle_window->window);
   gdk_window_destroy (handle_window->window);
 
   /* Create new window and apply old state */
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 2fe292c..5845aae 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4094,7 +4094,7 @@ gtk_text_view_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   context = gtk_widget_get_style_context (widget);
 
@@ -8748,7 +8748,7 @@ text_window_realize (GtkTextWindow *win,
                                 &attributes, attributes_mask);
 
   gdk_window_show (win->window);
-  gdk_window_set_user_data (win->window, win->widget);
+  gtk_widget_register_window (win->widget, win->window);
   gdk_window_lower (win->window);
 
   attributes.x = 0;
@@ -8770,7 +8770,7 @@ text_window_realize (GtkTextWindow *win,
                                     attributes_mask);
 
   gdk_window_show (win->bin_window);
-  gdk_window_set_user_data (win->bin_window, win->widget);
+  gtk_widget_register_window (win->widget, win->bin_window);
 
   context = gtk_widget_get_style_context (widget);
   state = gtk_widget_get_state_flags (widget);
@@ -8821,8 +8821,8 @@ text_window_unrealize (GtkTextWindow *win)
                                         NULL);
     }
 
-  gdk_window_set_user_data (win->window, NULL);
-  gdk_window_set_user_data (win->bin_window, NULL);
+  gtk_widget_unregister_window (win->widget, win->window);
+  gtk_widget_unregister_window (win->widget, win->bin_window);
   gdk_window_destroy (win->bin_window);
   gdk_window_destroy (win->window);
   win->window = NULL;
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 5caeb0d..0ca1b7e 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -844,7 +844,7 @@ gtk_toolbar_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 				       &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, toolbar);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -855,7 +855,7 @@ gtk_toolbar_unrealize (GtkWidget *widget)
 
   if (priv->event_window)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c
index 26ad140..1671753 100644
--- a/gtk/gtktoolitem.c
+++ b/gtk/gtktoolitem.c
@@ -432,7 +432,7 @@ create_drag_window (GtkToolItem *toolitem)
 
   toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 					  &attributes, attributes_mask);
-  gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
+  gtk_widget_register_window (widget, toolitem->priv->drag_window);
 }
 
 static void
@@ -457,7 +457,7 @@ destroy_drag_window (GtkToolItem *toolitem)
 {
   if (toolitem->priv->drag_window)
     {
-      gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
+      gtk_widget_unregister_window (GTK_WIDGET (toolitem), toolitem->priv->drag_window);
       gdk_window_destroy (toolitem->priv->drag_window);
       toolitem->priv->drag_window = NULL;
     }
diff --git a/gtk/gtktoolitemgroup.c b/gtk/gtktoolitemgroup.c
index 5907bf4..d6aa825 100644
--- a/gtk/gtktoolitemgroup.c
+++ b/gtk/gtktoolitemgroup.c
@@ -1241,7 +1241,7 @@ gtk_tool_item_group_realize (GtkWidget *widget)
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
 
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_style_context_set_background (context, window);
 
diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c
index 688688c..8c77ec1 100644
--- a/gtk/gtktoolpalette.c
+++ b/gtk/gtktoolpalette.c
@@ -733,7 +733,7 @@ gtk_tool_palette_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                     window);
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 6da71f1..34898ab 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -2247,7 +2247,7 @@ gtk_tree_view_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -2268,7 +2268,7 @@ gtk_tree_view_realize (GtkWidget *widget)
 
   tree_view->priv->bin_window = gdk_window_new (window,
 						&attributes, attributes_mask);
-  gdk_window_set_user_data (tree_view->priv->bin_window, widget);
+  gtk_widget_register_window (widget, tree_view->priv->bin_window);
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -2289,7 +2289,7 @@ gtk_tree_view_realize (GtkWidget *widget)
 
   tree_view->priv->header_window = gdk_window_new (window,
 						   &attributes, attributes_mask);
-  gdk_window_set_user_data (tree_view->priv->header_window, widget);
+  gtk_widget_register_window (widget, tree_view->priv->header_window);
 
   gtk_tree_view_ensure_background (tree_view);
 
@@ -2364,24 +2364,24 @@ gtk_tree_view_unrealize (GtkWidget *widget)
   for (list = priv->columns; list; list = list->next)
     _gtk_tree_view_column_unrealize_button (GTK_TREE_VIEW_COLUMN (list->data));
 
-  gdk_window_set_user_data (priv->bin_window, NULL);
+  gtk_widget_unregister_window (widget, priv->bin_window);
   gdk_window_destroy (priv->bin_window);
   priv->bin_window = NULL;
 
-  gdk_window_set_user_data (priv->header_window, NULL);
+  gtk_widget_unregister_window (widget, priv->header_window);
   gdk_window_destroy (priv->header_window);
   priv->header_window = NULL;
 
   if (priv->drag_window)
     {
-      gdk_window_set_user_data (priv->drag_window, NULL);
+      gtk_widget_unregister_window (widget, priv->drag_window);
       gdk_window_destroy (priv->drag_window);
       priv->drag_window = NULL;
     }
 
   if (priv->drag_highlight_window)
     {
-      gdk_window_set_user_data (priv->drag_highlight_window, NULL);
+      gtk_widget_unregister_window (widget, priv->drag_highlight_window);
       gdk_window_destroy (priv->drag_highlight_window);
       priv->drag_highlight_window = NULL;
     }
@@ -3807,8 +3807,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 
 	  if (tree_view->priv->drag_highlight_window)
 	    {
-	      gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
-					NULL);
+	      gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 	      gdk_window_destroy (tree_view->priv->drag_highlight_window);
 	    }
 
@@ -3824,7 +3823,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 	  attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
 	  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
 	  tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
-	  gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
+	  gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 
 	  mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
           cr = cairo_create (mask_image);
@@ -3874,8 +3873,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 	{
 	  if (tree_view->priv->drag_highlight_window)
 	    {
-	      gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
-					NULL);
+	      gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 	      gdk_window_destroy (tree_view->priv->drag_highlight_window);
 	    }
 
@@ -3890,7 +3888,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 	  attributes.height = height;
 	  tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
 								   &attributes, attributes_mask);
-	  gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
+	  gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 
 	  mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
 
@@ -3956,8 +3954,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 	{
 	  if (tree_view->priv->drag_highlight_window)
 	    {
-	      gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
-					NULL);
+	      gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 	      gdk_window_destroy (tree_view->priv->drag_highlight_window);
 	    }
 
@@ -3971,7 +3968,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
 	  attributes.width = width;
 	  attributes.height = height;
 	  tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget), &attributes, attributes_mask);
-	  gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
+	  gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 
 	  mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
 
@@ -9815,7 +9812,7 @@ _gtk_tree_view_column_start_drag (GtkTreeView       *tree_view,
   tree_view->priv->drag_window = gdk_window_new (tree_view->priv->header_window,
                                                  &attributes,
                                                  attributes_mask);
-  gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
+  gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_window);
 
   if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
     {
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index ab2d21d..af2317c 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -1400,7 +1400,7 @@ _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
   attr.x       = (allocation.x + (rtl ? 0 : allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2;
   priv->window = gdk_window_new (_gtk_tree_view_get_header_window (tree_view),
 				 &attr, attributes_mask);
-  gdk_window_set_user_data (priv->window, tree_view);
+  gtk_widget_register_window (GTK_WIDGET (tree_view), priv->window);
 
   gtk_tree_view_column_update_button (column);
 
@@ -1417,7 +1417,7 @@ _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column)
   priv = column->priv;
   g_return_if_fail (priv->window != NULL);
 
-  gdk_window_set_user_data (priv->window, NULL);
+  gtk_widget_unregister_window (GTK_WIDGET (priv->tree_view), priv->window);
   gdk_window_destroy (priv->window);
   priv->window = NULL;
 }
diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c
index e82d70b..935bda7 100644
--- a/gtk/gtkviewport.c
+++ b/gtk/gtkviewport.c
@@ -689,7 +689,7 @@ gtk_viewport_realize (GtkWidget *widget)
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, viewport);
+  gtk_widget_register_window (widget, window);
 
   viewport_get_view_allocation (viewport, &view_allocation);
   
@@ -701,7 +701,7 @@ gtk_viewport_realize (GtkWidget *widget)
 
   priv->view_window = gdk_window_new (window,
                                       &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->view_window, viewport);
+  gtk_widget_register_window (widget, priv->view_window);
 
   attributes.x = - gtk_adjustment_get_value (hadjustment);
   attributes.y = - gtk_adjustment_get_value (vadjustment);
@@ -711,7 +711,7 @@ gtk_viewport_realize (GtkWidget *widget)
   attributes.event_mask = event_mask;
 
   priv->bin_window = gdk_window_new (priv->view_window, &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->bin_window, viewport);
+  gtk_widget_register_window (widget, priv->bin_window);
 
   child = gtk_bin_get_child (bin);
   if (child)
@@ -731,11 +731,11 @@ gtk_viewport_unrealize (GtkWidget *widget)
   GtkViewport *viewport = GTK_VIEWPORT (widget);
   GtkViewportPrivate *priv = viewport->priv;
 
-  gdk_window_set_user_data (priv->view_window, NULL);
+  gtk_widget_unregister_window (widget, priv->view_window);
   gdk_window_destroy (priv->view_window);
   priv->view_window = NULL;
 
-  gdk_window_set_user_data (priv->bin_window, NULL);
+  gtk_widget_unregister_window (widget, priv->bin_window);
   gdk_window_destroy (priv->bin_window);
   priv->bin_window = NULL;
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2f4da17..2118c43 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -395,6 +395,7 @@ struct _GtkWidgetPrivate
    * GTK_NO_WINDOW flag being set).
    */
   GdkWindow *window;
+  GList *registered_windows;
 
   /* The widget's parent */
   GtkWidget *parent;
@@ -10536,7 +10537,7 @@ gtk_widget_real_unrealize (GtkWidget *widget)
 
   if (gtk_widget_get_has_window (widget))
     {
-      gdk_window_set_user_data (priv->window, NULL);
+      gtk_widget_unregister_window (widget, priv->window);
       gdk_window_destroy (priv->window);
       priv->window = NULL;
     }
@@ -13638,6 +13639,70 @@ gtk_widget_set_window (GtkWidget *widget,
 }
 
 /**
+ * gtk_widget_register_window:
+ * @widget: a #GtkWidget
+ * @window: a #GdkWindow
+ *
+ * Registers a #GdkWindow with the widget and sets it up so that
+ * the widget recieves events for it. Call gtk_widget_unregister_window()
+ * when destroying the window.
+ *
+ * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
+ * this up. This is now deprecated and you should use gtk_widget_register_window()
+ * instead. Old code will keep working as is, although some new features like
+ * transparency might not work perfectly.
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_register_window (GtkWidget    *widget,
+			    GdkWindow    *window)
+{
+  GtkWidgetPrivate *priv;
+  gpointer user_data;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  gdk_window_get_user_data (window, &user_data);
+  g_assert (user_data == NULL);
+
+  priv = widget->priv;
+
+  gdk_window_set_user_data (window, widget);
+  priv->registered_windows = g_list_prepend (priv->registered_windows, window);
+}
+
+/**
+ * gtk_widget_unregister_window:
+ * @widget: a #GtkWidget
+ * @window: a #GdkWindow
+ *
+ * Unregisters a #GdkWindow from the widget that was previously set up with
+ * gtk_widget_register_window(). You need to call this when the window is
+ * no longer used by the widget, such as when you destroy it.
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_unregister_window (GtkWidget    *widget,
+			      GdkWindow    *window)
+{
+  GtkWidgetPrivate *priv;
+  gpointer user_data;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  priv = widget->priv;
+
+  gdk_window_get_user_data (window, &user_data);
+  g_assert (user_data == widget);
+  gdk_window_set_user_data (window, NULL);
+  priv->registered_windows = g_list_remove (priv->registered_windows, window);
+}
+
+/**
  * gtk_widget_get_window:
  * @widget: a #GtkWidget
  *
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 0f1638f..ff4f417 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -630,6 +630,12 @@ gboolean              gtk_widget_get_child_visible      (GtkWidget    *widget);
 void                  gtk_widget_set_window             (GtkWidget    *widget,
                                                          GdkWindow    *window);
 GdkWindow           * gtk_widget_get_window             (GtkWidget    *widget);
+GDK_AVAILABLE_IN_3_8
+void                  gtk_widget_register_window        (GtkWidget    *widget,
+                                                         GdkWindow    *window);
+GDK_AVAILABLE_IN_3_8
+void                  gtk_widget_unregister_window      (GtkWidget    *widget,
+                                                         GdkWindow    *window);
 
 int                   gtk_widget_get_allocated_width    (GtkWidget     *widget);
 int                   gtk_widget_get_allocated_height   (GtkWidget     *widget);
diff --git a/gtk/gtkwin32embedwidget.c b/gtk/gtkwin32embedwidget.c
index 181ff85..0ac9d08 100644
--- a/gtk/gtkwin32embedwidget.c
+++ b/gtk/gtkwin32embedwidget.c
@@ -136,7 +136,7 @@ gtk_win32_embed_widget_unrealize (GtkWidget *widget)
   
   if (embed_widget->parent_window != NULL)
     {
-      gdk_window_set_user_data (embed_widget->parent_window, NULL);
+      gtk_widget_unregister_window (widget, embed_widget->parent_window);
       g_object_unref (embed_widget->parent_window);
       embed_widget->parent_window = NULL;
     }
@@ -234,7 +234,7 @@ gtk_win32_embed_widget_realize (GtkWidget *widget)
   gdk_window = gdk_window_new (embed_widget->parent_window,
                                &attributes, attributes_mask);
   gtk_widget_set_window (widget, gdk_window);
-  gdk_window_set_user_data (gdk_window, window);
+  gtk_widget_register_window (widget, gdk_window);
 
   embed_widget->old_window_procedure = (gpointer)
     SetWindowLongPtrW(GDK_WINDOW_HWND (gdk_window),
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0984886..6fc82f8 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -5203,7 +5203,7 @@ gtk_window_realize (GtkWidget *widget)
       gdk_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 				   &attributes, attributes_mask);
       gtk_widget_set_window (widget, gdk_window);
-      gdk_window_set_user_data (gdk_window, widget);
+      gtk_widget_register_window (widget, gdk_window);
 
       gtk_style_context_set_background (gtk_widget_get_style_context (widget), gdk_window);
 
@@ -5286,7 +5286,7 @@ gtk_window_realize (GtkWidget *widget)
 
   gdk_window_enable_synchronized_configure (gdk_window);
 
-  gdk_window_set_user_data (gdk_window, window);
+  gtk_widget_register_window (widget, gdk_window);
 
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_set_background (context, gdk_window);
@@ -5768,7 +5768,7 @@ resize_grip_create_window (GtkWindow *window)
                                       attributes_mask);
   gdk_window_set_background_rgba (priv->grip_window, &transparent);
 
-  gdk_window_set_user_data (priv->grip_window, widget);
+  gtk_widget_register_window (widget, priv->grip_window);
 
   gdk_window_raise (priv->grip_window);
 
@@ -5781,7 +5781,7 @@ resize_grip_destroy_window (GtkWindow *window)
 {
   GtkWindowPrivate *priv = window->priv;
 
-  gdk_window_set_user_data (priv->grip_window, NULL);
+  gtk_widget_unregister_window (GTK_WIDGET (window), priv->grip_window);
   gdk_window_destroy (priv->grip_window);
   priv->grip_window = NULL;
   update_grip_visibility (window);


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