]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfixed.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtkfixed.c
index 2295d286f60e94115077ecf5af0a8bf0ed6bc5a0..05a5a1e0f0c43e378b41adfa98068a98add02418 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include "config.h"
 #include "gtkfixed.h"
+#include "gtkprivate.h"
 #include "gtkintl.h"
-
+#include "gtkalias.h"
 enum {
   CHILD_PROP_0,
   CHILD_PROP_X,
   CHILD_PROP_Y
 };
 
-static void gtk_fixed_class_init    (GtkFixedClass    *klass);
-static void gtk_fixed_init          (GtkFixed         *fixed);
 static void gtk_fixed_realize       (GtkWidget        *widget);
 static void gtk_fixed_size_request  (GtkWidget        *widget,
                                     GtkRequisition   *requisition);
@@ -48,7 +48,7 @@ static void gtk_fixed_forall        (GtkContainer     *container,
                                     gboolean          include_internals,
                                     GtkCallback       callback,
                                     gpointer          callback_data);
-static GtkType gtk_fixed_child_type (GtkContainer     *container);
+static GType gtk_fixed_child_type   (GtkContainer     *container);
 
 static void gtk_fixed_set_child_property (GtkContainer *container,
                                           GtkWidget    *child,
@@ -61,47 +61,17 @@ static void gtk_fixed_get_child_property (GtkContainer *container,
                                           GValue       *value,
                                           GParamSpec   *pspec);
 
-static GtkContainerClass *parent_class = NULL;
-
-
-GtkType
-gtk_fixed_get_type (void)
-{
-  static GtkType fixed_type = 0;
-
-  if (!fixed_type)
-    {
-      static const GtkTypeInfo fixed_info =
-      {
-       "GtkFixed",
-       sizeof (GtkFixed),
-       sizeof (GtkFixedClass),
-       (GtkClassInitFunc) gtk_fixed_class_init,
-       (GtkObjectInitFunc) gtk_fixed_init,
-       /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
-      };
-
-      fixed_type = gtk_type_unique (GTK_TYPE_CONTAINER, &fixed_info);
-    }
-
-  return fixed_type;
-}
+G_DEFINE_TYPE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
 
 static void
 gtk_fixed_class_init (GtkFixedClass *class)
 {
-  GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
 
-  object_class = (GtkObjectClass*) class;
   widget_class = (GtkWidgetClass*) class;
   container_class = (GtkContainerClass*) class;
 
-  parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
-
   widget_class->realize = gtk_fixed_realize;
   widget_class->size_request = gtk_fixed_size_request;
   widget_class->size_allocate = gtk_fixed_size_allocate;
@@ -117,25 +87,25 @@ gtk_fixed_class_init (GtkFixedClass *class)
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_X,
                                              g_param_spec_int ("x",
-                                                                _("X position"),
-                                                                _("X position of child widget"),
+                                                                P_("X position"),
+                                                                P_("X position of child widget"),
                                                                 G_MININT,
                                                                 G_MAXINT,
                                                                 0,
-                                                                G_PARAM_READWRITE));
+                                                                GTK_PARAM_READWRITE));
 
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_Y,
                                              g_param_spec_int ("y",
-                                                                _("Y position"),
-                                                                _("Y position of child widget"),
+                                                                P_("Y position"),
+                                                                P_("Y position of child widget"),
                                                                 G_MININT,
                                                                 G_MAXINT,
                                                                 0,
-                                                                G_PARAM_READWRITE));
+                                                                GTK_PARAM_READWRITE));
 }
 
-static GtkType
+static GType
 gtk_fixed_child_type (GtkContainer     *container)
 {
   return GTK_TYPE_WIDGET;
@@ -144,18 +114,15 @@ gtk_fixed_child_type (GtkContainer     *container)
 static void
 gtk_fixed_init (GtkFixed *fixed)
 {
-  GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW);
+  gtk_widget_set_has_window (GTK_WIDGET (fixed), FALSE);
+
   fixed->children = NULL;
 }
 
 GtkWidget*
 gtk_fixed_new (void)
 {
-  GtkFixed *fixed;
-
-  fixed = gtk_type_new (GTK_TYPE_FIXED);
-  return GTK_WIDGET (fixed);
+  return g_object_new (GTK_TYPE_FIXED, NULL);
 }
 
 static GtkFixedChild*
@@ -188,7 +155,7 @@ gtk_fixed_put (GtkFixed       *fixed,
   GtkFixedChild *child_info;
 
   g_return_if_fail (GTK_IS_FIXED (fixed));
-  g_return_if_fail (widget != NULL);
+  g_return_if_fail (GTK_IS_WIDGET (widget));
 
   child_info = g_new (GtkFixedChild, 1);
   child_info->widget = widget;
@@ -234,7 +201,8 @@ gtk_fixed_move_internal (GtkFixed       *fixed,
 
   gtk_widget_thaw_child_notify (widget);
   
-  if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (fixed))
+  if (gtk_widget_get_visible (widget) &&
+      gtk_widget_get_visible (GTK_WIDGET (fixed)))
     gtk_widget_queue_resize (GTK_WIDGET (fixed));
 }
 
@@ -244,10 +212,6 @@ gtk_fixed_move (GtkFixed       *fixed,
                 gint            x,
                 gint            y)
 {
-  g_return_if_fail (GTK_IS_FIXED (fixed));
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (widget->parent == GTK_WIDGET (fixed));
-
   gtk_fixed_move_internal (fixed, widget, TRUE, x, TRUE, y);
 }
 
@@ -309,29 +273,32 @@ gtk_fixed_realize (GtkWidget *widget)
   GdkWindowAttr attributes;
   gint attributes_mask;
 
-  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);
-
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+  if (!gtk_widget_get_has_window (widget))
+    GTK_WIDGET_CLASS (gtk_fixed_parent_class)->realize (widget);
+  else
+    {
+      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);
+      
+      widget->style = gtk_style_attach (widget->style, widget->window);
+      gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+    }
 }
 
 static void
@@ -343,9 +310,6 @@ gtk_fixed_size_request (GtkWidget      *widget,
   GList *children;
   GtkRequisition child_requisition;
 
-  g_return_if_fail (GTK_IS_FIXED (widget));
-  g_return_if_fail (requisition != NULL);
-
   fixed = GTK_FIXED (widget);
   requisition->width = 0;
   requisition->height = 0;
@@ -356,7 +320,7 @@ gtk_fixed_size_request (GtkWidget      *widget,
       child = children->data;
       children = children->next;
 
-      if (GTK_WIDGET_VISIBLE (child->widget))
+      if (gtk_widget_get_visible (child->widget))
        {
           gtk_widget_size_request (child->widget, &child_requisition);
 
@@ -384,19 +348,20 @@ gtk_fixed_size_allocate (GtkWidget     *widget,
   GList *children;
   guint16 border_width;
 
-  g_return_if_fail (GTK_IS_FIXED(widget));
-  g_return_if_fail (allocation != NULL);
-
   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_get_has_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;
@@ -405,11 +370,18 @@ gtk_fixed_size_allocate (GtkWidget     *widget,
       child = children->data;
       children = children->next;
       
-      if (GTK_WIDGET_VISIBLE (child->widget))
+      if (gtk_widget_get_visible (child->widget))
        {
          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_get_has_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);
@@ -421,9 +393,6 @@ static void
 gtk_fixed_add (GtkContainer *container,
               GtkWidget    *widget)
 {
-  g_return_if_fail (GTK_IS_FIXED (container));
-  g_return_if_fail (widget != NULL);
-
   gtk_fixed_put (GTK_FIXED (container), widget, 0, 0);
 }
 
@@ -433,12 +402,11 @@ gtk_fixed_remove (GtkContainer *container,
 {
   GtkFixed *fixed;
   GtkFixedChild *child;
+  GtkWidget *widget_container;
   GList *children;
 
-  g_return_if_fail (GTK_IS_FIXED (container));
-  g_return_if_fail (widget != NULL);
-
   fixed = GTK_FIXED (container);
+  widget_container = GTK_WIDGET (container);
 
   children = fixed->children;
   while (children)
@@ -447,7 +415,7 @@ gtk_fixed_remove (GtkContainer *container,
 
       if (child->widget == widget)
        {
-         gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
+         gboolean was_visible = gtk_widget_get_visible (widget);
          
          gtk_widget_unparent (widget);
 
@@ -455,8 +423,8 @@ gtk_fixed_remove (GtkContainer *container,
          g_list_free (children);
          g_free (child);
 
-         if (was_visible && GTK_WIDGET_VISIBLE (container))
-           gtk_widget_queue_resize (GTK_WIDGET (container));
+         if (was_visible && gtk_widget_get_visible (widget_container))
+           gtk_widget_queue_resize (widget_container);
 
          break;
        }
@@ -471,15 +439,10 @@ gtk_fixed_forall (GtkContainer *container,
                  GtkCallback   callback,
                  gpointer      callback_data)
 {
-  GtkFixed *fixed;
+  GtkFixed *fixed = GTK_FIXED (container);
   GtkFixedChild *child;
   GList *children;
 
-  g_return_if_fail (GTK_IS_FIXED (container));
-  g_return_if_fail (callback != NULL);
-
-  fixed = GTK_FIXED (container);
-
   children = fixed->children;
   while (children)
     {
@@ -489,3 +452,54 @@ gtk_fixed_forall (GtkContainer *container,
       (* callback) (child->widget, callback_data);
     }
 }
+
+/**
+ * gtk_fixed_set_has_window:
+ * @fixed: a #GtkFixed
+ * @has_window: %TRUE if a separate window should be created
+ * 
+ * Sets whether a #GtkFixed widget is created with a separate
+ * #GdkWindow for @widget->window or not. (By default, it will be
+ * created with no separate #GdkWindow). This function must be called
+ * while the #GtkFixed is not realized, for instance, immediately after the
+ * window is created.
+ * 
+ * This function was added to provide an easy migration path for
+ * older applications which may expect #GtkFixed to have a separate window.
+ *
+ * Deprecated: 2.20: Use gtk_widget_set_has_window() instead.
+ **/
+void
+gtk_fixed_set_has_window (GtkFixed *fixed,
+                         gboolean  has_window)
+{
+  g_return_if_fail (GTK_IS_FIXED (fixed));
+  g_return_if_fail (!GTK_WIDGET_REALIZED (fixed));
+
+  if (has_window != gtk_widget_get_has_window (GTK_WIDGET (fixed)))
+    {
+      gtk_widget_set_has_window (GTK_WIDGET (fixed), has_window);
+    }
+}
+
+/**
+ * gtk_fixed_get_has_window:
+ * @fixed: a #GtkWidget
+ * 
+ * Gets whether the #GtkFixed has its own #GdkWindow.
+ * See gtk_fixed_set_has_window().
+ * 
+ * Return value: %TRUE if @fixed has its own window.
+ *
+ * Deprecated: 2.20: Use gtk_widget_get_has_window() instead.
+ **/
+gboolean
+gtk_fixed_get_has_window (GtkFixed *fixed)
+{
+  g_return_val_if_fail (GTK_IS_FIXED (fixed), FALSE);
+
+  return gtk_widget_get_has_window (GTK_WIDGET (fixed));
+}
+
+#define __GTK_FIXED_C__
+#include "gtkaliasdef.c"