[gtk+/rendering-cleanup: 106/141] gtk: Change gtk_widget_get_visual()



commit c00595ffbc1d18a8fea6eefa42eeaa68087192a4
Author: Benjamin Otte <otte redhat com>
Date:   Sat Aug 28 18:52:27 2010 +0200

    gtk: Change gtk_widget_get_visual()
    
    We now return the visual of the topmost widget in widget's stack that
    has a window. If no such widget exists, but a GtkWindow is a parent, we
    return its visual (note: GtkWindow Will gain support for setting visuals
    soon). If a window doesn't exist, we return the system visual of the
    default screen.
    
    This change has multiple reasons:
    - Colormaps are gone
      Now visuals are the most important resource for creating GDK windows.
    - Allow widgets to change visuals for themselves and their children
      By walking the hierarchy, we ensure that child windows have the same
      visual as their parents by default. But widgets can still select a
      different visual in their realize handler when creating the GDK
      window.
    - Have a replacement for gtk_widget_set_colormap()
      That function is going to die with colormaps, so a replacement was
      needed. That replacement is going to be gdk_window_set_visual().
    - Make a future transition to no-window GTK easy
      Should we ever attempt a change to make all GTK widgets no-window, a
      gtk_widget_set_visual() would be silly, as only widgets with windows
      can have their own visuals. So only toplevels will gain the ability to
      change it.

 gtk/gtkwidget.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9e7ef83..d71f419 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -8348,9 +8348,21 @@ gtk_widget_get_colormap (GtkWidget *widget)
 GdkVisual*
 gtk_widget_get_visual (GtkWidget *widget)
 {
+  GtkWidget *w;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
+  for (w = widget; w != NULL; w = w->priv->parent)
+    {
+      if (gtk_widget_get_has_window (w) &&
+          w->priv->window)
+        return gdk_drawable_get_visual (w->priv->window);
+
+      if (GTK_IS_WINDOW (w))
+        return gdk_screen_get_system_visual (GTK_WINDOW (w)->screen);
+    }
+
+  return gdk_screen_get_system_visual (gdk_screen_get_default ());
 }
 
 /**



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