]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdrawingarea.c
Seal center_allocation field in GtkAspectFrame.
[~andy/gtk] / gtk / gtkdrawingarea.c
index 992ebcf550658db579ebc3c57e4ccd6a9771ece9..6d9cfc9f11c5edbafd614549df360fb009f05fac 100644 (file)
 #include "gtkalias.h"
 
 
-static void gtk_drawing_area_class_init    (GtkDrawingAreaClass *klass);
-static void gtk_drawing_area_init          (GtkDrawingArea      *darea);
 static void gtk_drawing_area_realize       (GtkWidget           *widget);
 static void gtk_drawing_area_size_allocate (GtkWidget           *widget,
                                            GtkAllocation       *allocation);
 static void gtk_drawing_area_send_configure (GtkDrawingArea     *darea);
 
-
-GType
-gtk_drawing_area_get_type (void)
-{
-  static GType drawing_area_type = 0;
-
-  if (!drawing_area_type)
-    {
-      static const GTypeInfo drawing_area_info =
-      {
-       sizeof (GtkDrawingAreaClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_drawing_area_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkDrawingArea),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_drawing_area_init,
-      };
-
-      drawing_area_type =
-       g_type_register_static (GTK_TYPE_WIDGET, I_("GtkDrawingArea"),
-                               &drawing_area_info, 0);
-    }
-
-  return drawing_area_type;
-}
+G_DEFINE_TYPE (GtkDrawingArea, gtk_drawing_area, GTK_TYPE_WIDGET)
 
 static void
 gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
@@ -104,32 +75,37 @@ gtk_drawing_area_size (GtkDrawingArea *darea,
 static void
 gtk_drawing_area_realize (GtkWidget *widget)
 {
-  GtkDrawingArea *darea;
+  GtkDrawingArea *darea = GTK_DRAWING_AREA (widget);
   GdkWindowAttr attributes;
   gint attributes_mask;
 
-  g_return_if_fail (GTK_IS_DRAWING_AREA (widget));
-
-  darea = GTK_DRAWING_AREA (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) | GDK_EXPOSURE_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, darea);
-
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+  if (GTK_WIDGET_NO_WINDOW (widget))
+    {
+      GTK_WIDGET_CLASS (gtk_drawing_area_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) | GDK_EXPOSURE_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, darea);
+
+      widget->style = gtk_style_attach (widget->style, widget->window);
+      gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+    }
 
   gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
 }
@@ -145,9 +121,10 @@ gtk_drawing_area_size_allocate (GtkWidget     *widget,
 
   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))
+        gdk_window_move_resize (widget->window,
+                                allocation->x, allocation->y,
+                                allocation->width, allocation->height);
 
       gtk_drawing_area_send_configure (GTK_DRAWING_AREA (widget));
     }