Fixed as a NO_WINDOW



Those were all the API changes. Really, no kidding. Well, almost.

GtkFixed _really_ needs to be a NO_WINDOW widget; this 
has been bugging me since 1.0.

 * For correct theming
 * For consistency with all other containers that don't draw anything.
 * For reduced overhead.

Effects:

 * I couldn't find any code in GNOME cvs that this will break

 * If there is something that breaks, insert:

+    GTK_WIDGET_UNSET_FLAGS (fixed, GTK_WIDGET_NO_WINDOW)
   
   after creating the fixed.

   (I added the hack of making this work, because I'm pretty sure 
   people frequently use GtkFixed as an equivalent of a widget in some
   other toolkit with fixed placement, and I don't want
   such people to have write a new widget.)

Regards,
                                        Owen

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2590
diff -u -p -r1.2590 ChangeLog
--- ChangeLog	2001/11/18 02:15:47	1.2590
+++ ChangeLog	2001/11/18 23:31:19
@@ -1,3 +1,9 @@
+Sun Nov 18 18:18:11 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/gtkfixed.c: Make a NO_WINDOW widget, as it should
+	have been since the beginning, but as special hack,
+	allow clearing the NO_WINDOW flag to get a window widget.
+
 Sat Nov 17 21:07:46 2001  Owen Taylor  <otaylor redhat com>
 
 	* gtk/gtkenums.h: Include glib-object.h instead of
Index: docs/Changes-2.0.txt
===================================================================
RCS file: /cvs/gnome/gtk+/docs/Changes-2.0.txt,v
retrieving revision 1.40
diff -u -p -r1.40 Changes-2.0.txt
--- docs/Changes-2.0.txt	2001/11/18 00:34:19	1.40
+++ docs/Changes-2.0.txt	2001/11/18 23:31:19
@@ -528,7 +528,15 @@ Incompatible Changes from GTK+-1.2 to GT
      you must make sure you call gtk_container_propagate_expose()
      correctly, as you must for any NO_WINDOW widgets.
 
+  GtkFixed is a little special; it is now created by default as
+  a NO_WINDOW widget, but if you do 
+
+    GTK_WIDGET_UNSET_FLAGS (fixed, GTK_WIDGET_NO_WINDOW)
+
+  after creating a fixed widget, it will create a window and
+  handle it properly.
+
 * GtkLayout no longer has the xoffset, yoffset fields, which used
   to store the difference between world and window coordinates for
   layout->bin_window. These coordinate systems are now always
-  the same.
\ No newline at end of file
+  the same.
Index: gtk/gtkfixed.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfixed.c,v
retrieving revision 1.29
diff -u -p -r1.29 gtkfixed.c
--- gtk/gtkfixed.c	2001/11/14 21:49:59	1.29
+++ gtk/gtkfixed.c	2001/11/18 23:31:19
@@ -144,7 +144,7 @@ gtk_fixed_child_type (GtkContainer     *
 static void
 gtk_fixed_init (GtkFixed *fixed)
 {
-  GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
+  GTK_WIDGET_SET_FLAGS (fixed, GTK_NO_WINDOW);
  
   fixed->children = NULL;
 }
@@ -311,27 +311,32 @@ gtk_fixed_realize (GtkWidget *widget)
 
   g_return_if_fail (GTK_IS_FIXED (widget));
 
-  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
-
-  attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.x = widget->allocation.x;
-  attributes.y = widget->allocation.y;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
-  attributes.event_mask = gtk_widget_get_events (widget);
-  attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-
-  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, 
-				   attributes_mask);
-  gdk_window_set_user_data (widget->window, widget);
+  if (GTK_WIDGET_NO_WINDOW (widget))
+    GTK_WIDGET_CLASS (parent_class)->realize (widget);
+  else
+    {
+      GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+      attributes.window_type = GDK_WINDOW_CHILD;
+      attributes.x = widget->allocation.x;
+      attributes.y = widget->allocation.y;
+      attributes.width = widget->allocation.width;
+      attributes.height = widget->allocation.height;
+      attributes.wclass = GDK_INPUT_OUTPUT;
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.colormap = gtk_widget_get_colormap (widget);
+      attributes.event_mask = gtk_widget_get_events (widget);
+      attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
+      
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+      
+      widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, 
+				       attributes_mask);
+      gdk_window_set_user_data (widget->window, widget);
+      
+      widget->style = gtk_style_attach (widget->style, widget->window);
+      gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+    }
 }
 
 static void
@@ -390,13 +395,17 @@ gtk_fixed_size_allocate (GtkWidget     *
   fixed = GTK_FIXED (widget);
 
   widget->allocation = *allocation;
-  if (GTK_WIDGET_REALIZED (widget))
-    gdk_window_move_resize (widget->window,
-			    allocation->x, 
-			    allocation->y,
-			    allocation->width, 
-			    allocation->height);
 
+  if (!GTK_WIDGET_NO_WINDOW (widget))
+    {
+      if (GTK_WIDGET_REALIZED (widget))
+	gdk_window_move_resize (widget->window,
+				allocation->x, 
+				allocation->y,
+				allocation->width, 
+				allocation->height);
+    }
+      
   border_width = GTK_CONTAINER (fixed)->border_width;
   
   children = fixed->children;
@@ -410,6 +419,13 @@ gtk_fixed_size_allocate (GtkWidget     *
 	  gtk_widget_get_child_requisition (child->widget, &child_requisition);
 	  child_allocation.x = child->x + border_width;
 	  child_allocation.y = child->y + border_width;
+
+	  if (GTK_WIDGET_NO_WINDOW (widget))
+	    {
+	      child_allocation.x += widget->allocation.x;
+	      child_allocation.y += widget->allocation.y;
+	    }
+	  
 	  child_allocation.width = child_requisition.width;
 	  child_allocation.height = child_requisition.height;
 	  gtk_widget_size_allocate (child->widget, &child_allocation);



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