]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkaspectframe.c
Updated Bulgarian translation by Alexander Shopov <ash@contact.bg>
[~andy/gtk] / gtk / gtkaspectframe.c
index 00fbde6c151fa53245c3bcd654903463a356af6e..0caa58312ccd9d459ae265c55f4ab611769d54d3 100644 (file)
  *     Copyright Owen Taylor                          4/9/97
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
 #include "gtkaspectframe.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 enum {
-  ARG_0,
-  ARG_XALIGN,
-  ARG_YALIGN,
-  ARG_RATIO,
-  ARG_OBEY_CHILD
+  PROP_0,
+  PROP_XALIGN,
+  PROP_YALIGN,
+  PROP_RATIO,
+  PROP_OBEY_CHILD
 };
 
-static void gtk_aspect_frame_class_init               (GtkAspectFrameClass *klass);
-static void gtk_aspect_frame_init                     (GtkAspectFrame      *aspect_frame);
-static void gtk_aspect_frame_set_arg                  (GtkObject           *object,
-                                                      GtkArg              *arg,
-                                                      guint                arg_id);
-static void gtk_aspect_frame_get_arg                  (GtkObject           *object,
-                                                      GtkArg              *arg,
-                                                      guint                arg_id);
+static void gtk_aspect_frame_set_property (GObject         *object,
+                                          guint            prop_id,
+                                          const GValue    *value,
+                                          GParamSpec      *pspec);
+static void gtk_aspect_frame_get_property (GObject         *object,
+                                          guint            prop_id,
+                                          GValue          *value,
+                                          GParamSpec      *pspec);
 static void gtk_aspect_frame_compute_child_allocation (GtkFrame            *frame,
                                                       GtkAllocation       *child_allocation);
 
 #define MAX_RATIO 10000.0
 #define MIN_RATIO 0.0001
 
-static GtkFrameClass *parent_class = NULL;
-
-GtkType
-gtk_aspect_frame_get_type (void)
-{
-  static GtkType aspect_frame_type = 0;
-  
-  if (!aspect_frame_type)
-    {
-      static const GtkTypeInfo aspect_frame_info =
-      {
-       "GtkAspectFrame",
-       sizeof (GtkAspectFrame),
-       sizeof (GtkAspectFrameClass),
-       (GtkClassInitFunc) gtk_aspect_frame_class_init,
-       (GtkObjectInitFunc) gtk_aspect_frame_init,
-        /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
-      };
-      
-      aspect_frame_type = gtk_type_unique (GTK_TYPE_FRAME, &aspect_frame_info);
-    }
-  
-  return aspect_frame_type;
-}
+G_DEFINE_TYPE (GtkAspectFrame, gtk_aspect_frame, GTK_TYPE_FRAME)
 
 static void
 gtk_aspect_frame_class_init (GtkAspectFrameClass *class)
 {
-  GtkObjectClass *object_class;
+  GObjectClass *gobject_class;
   GtkFrameClass *frame_class;
   
-  parent_class = gtk_type_class (GTK_TYPE_FRAME);
-
-  object_class = GTK_OBJECT_CLASS (class);
-  frame_class = GTK_FRAME_CLASS (class);
+  gobject_class = (GObjectClass*) class;
+  frame_class = (GtkFrameClass*) class;
   
-  object_class->set_arg = gtk_aspect_frame_set_arg;
-  object_class->get_arg = gtk_aspect_frame_get_arg;
+  gobject_class->set_property = gtk_aspect_frame_set_property;
+  gobject_class->get_property = gtk_aspect_frame_get_property;
 
   frame_class->compute_child_allocation = gtk_aspect_frame_compute_child_allocation;
 
-  gtk_object_add_arg_type ("GtkAspectFrame::xalign", GTK_TYPE_FLOAT,
-                          GTK_ARG_READWRITE, ARG_XALIGN);
-  gtk_object_add_arg_type ("GtkAspectFrame::yalign", GTK_TYPE_FLOAT,
-                          GTK_ARG_READWRITE, ARG_YALIGN);
-  gtk_object_add_arg_type ("GtkAspectFrame::ratio", GTK_TYPE_FLOAT,
-                          GTK_ARG_READWRITE, ARG_RATIO);
-  gtk_object_add_arg_type ("GtkAspectFrame::obey_child", GTK_TYPE_BOOL,
-                          GTK_ARG_READWRITE, ARG_OBEY_CHILD);  
+  g_object_class_install_property (gobject_class,
+                                   PROP_XALIGN,
+                                   g_param_spec_float ("xalign",
+                                                       P_("Horizontal Alignment"),
+                                                       P_("X alignment of the child"),
+                                                       0.0, 1.0, 0.5,
+                                                       GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_YALIGN,
+                                   g_param_spec_float ("yalign",
+                                                       P_("Vertical Alignment"),
+                                                       P_("Y alignment of the child"),
+                                                       0.0, 1.0, 0.5,
+                                                       GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_RATIO,
+                                   g_param_spec_float ("ratio",
+                                                       P_("Ratio"),
+                                                       P_("Aspect ratio if obey_child is FALSE"),
+                                                       MIN_RATIO, MAX_RATIO, 0.5,
+                                                       GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_OBEY_CHILD,
+                                   g_param_spec_boolean ("obey-child",
+                                                         P_("Obey child"),
+                                                         P_("Force aspect ratio to match that of the frame's child"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
 }
 
 static void
@@ -116,68 +113,74 @@ gtk_aspect_frame_init (GtkAspectFrame *aspect_frame)
 }
 
 static void
-gtk_aspect_frame_set_arg (GtkObject *object,
-                         GtkArg    *arg,
-                         guint      arg_id)
+gtk_aspect_frame_set_property (GObject         *object,
+                              guint            prop_id,
+                              const GValue    *value,
+                              GParamSpec      *pspec)
 {
   GtkAspectFrame *aspect_frame = GTK_ASPECT_FRAME (object);
   
-  switch (arg_id)
+  switch (prop_id)
     {
-    case ARG_XALIGN:
+      /* g_object_notify is handled by the _frame_set function */
+    case PROP_XALIGN:
       gtk_aspect_frame_set (aspect_frame,
-                           GTK_VALUE_FLOAT (*arg),
+                           g_value_get_float (value),
                            aspect_frame->yalign,
                            aspect_frame->ratio,
                            aspect_frame->obey_child);
       break;
-    case ARG_YALIGN:
+    case PROP_YALIGN:
       gtk_aspect_frame_set (aspect_frame,
                            aspect_frame->xalign,
-                           GTK_VALUE_FLOAT (*arg),
+                           g_value_get_float (value),
                            aspect_frame->ratio,
                            aspect_frame->obey_child);
       break;
-    case ARG_RATIO:
+    case PROP_RATIO:
       gtk_aspect_frame_set (aspect_frame,
                            aspect_frame->xalign,
                            aspect_frame->yalign,
-                           GTK_VALUE_FLOAT (*arg),
+                           g_value_get_float (value),
                            aspect_frame->obey_child);
       break;
-    case ARG_OBEY_CHILD:
+    case PROP_OBEY_CHILD:
       gtk_aspect_frame_set (aspect_frame,
                            aspect_frame->xalign,
                            aspect_frame->yalign,
                            aspect_frame->ratio,
-                           GTK_VALUE_BOOL (*arg));
+                           g_value_get_boolean (value));
+      break;
+    default:
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
 
 static void
-gtk_aspect_frame_get_arg (GtkObject *object,
-                         GtkArg    *arg,
-                         guint      arg_id)
+gtk_aspect_frame_get_property (GObject         *object,
+                              guint            prop_id,
+                              GValue          *value,
+                              GParamSpec      *pspec)
 {
   GtkAspectFrame *aspect_frame = GTK_ASPECT_FRAME (object);
   
-  switch (arg_id)
+  switch (prop_id)
     {
-    case ARG_XALIGN:
-      GTK_VALUE_FLOAT (*arg) = aspect_frame->xalign;
+    case PROP_XALIGN:
+      g_value_set_float (value, aspect_frame->xalign);
       break;
-    case ARG_YALIGN:
-      GTK_VALUE_FLOAT (*arg) = aspect_frame->yalign;
+    case PROP_YALIGN:
+      g_value_set_float (value, aspect_frame->yalign);
       break;
-    case ARG_RATIO:
-      GTK_VALUE_FLOAT (*arg) = aspect_frame->ratio;
+    case PROP_RATIO:
+      g_value_set_float (value, aspect_frame->ratio);
       break;
-    case ARG_OBEY_CHILD:
-      GTK_VALUE_BOOL (*arg) = aspect_frame->obey_child;
+    case PROP_OBEY_CHILD:
+      g_value_set_boolean (value, aspect_frame->obey_child);
       break;
     default:
-      arg->type = GTK_TYPE_INVALID;
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
@@ -191,7 +194,7 @@ gtk_aspect_frame_new (const gchar *label,
 {
   GtkAspectFrame *aspect_frame;
 
-  aspect_frame = gtk_type_new (gtk_aspect_frame_get_type ());
+  aspect_frame = g_object_new (GTK_TYPE_ASPECT_FRAME, NULL);
 
   aspect_frame->xalign = CLAMP (xalign, 0.0, 1.0);
   aspect_frame->yalign = CLAMP (yalign, 0.0, 1.0);
@@ -210,7 +213,6 @@ gtk_aspect_frame_set (GtkAspectFrame *aspect_frame,
                      gfloat          ratio,
                      gboolean        obey_child)
 {
-  g_return_if_fail (aspect_frame != NULL);
   g_return_if_fail (GTK_IS_ASPECT_FRAME (aspect_frame));
   
   xalign = CLAMP (xalign, 0.0, 1.0);
@@ -218,19 +220,36 @@ gtk_aspect_frame_set (GtkAspectFrame *aspect_frame,
   ratio = CLAMP (ratio, MIN_RATIO, MAX_RATIO);
   obey_child = obey_child != FALSE;
   
-  if ((aspect_frame->xalign != xalign) ||
-      (aspect_frame->yalign != yalign) ||
-      (aspect_frame->ratio != ratio) ||
-      (aspect_frame->obey_child != obey_child))
+  if (   (aspect_frame->xalign != xalign)
+      || (aspect_frame->yalign != yalign)
+      || (aspect_frame->ratio != ratio)
+      || (aspect_frame->obey_child != obey_child))
     {
-      GtkWidget *widget = GTK_WIDGET(aspect_frame);
-      
-      aspect_frame->xalign = xalign;
-      aspect_frame->yalign = yalign;
-      aspect_frame->ratio = ratio;
-      aspect_frame->obey_child = obey_child;
-      
-      gtk_widget_queue_resize (widget);
+      g_object_freeze_notify (G_OBJECT (aspect_frame));
+
+      if (aspect_frame->xalign != xalign)
+        {
+          aspect_frame->xalign = xalign;
+          g_object_notify (G_OBJECT (aspect_frame), "xalign");
+        }
+      if (aspect_frame->yalign != yalign)
+        {
+          aspect_frame->yalign = yalign;
+          g_object_notify (G_OBJECT (aspect_frame), "yalign");
+        }
+      if (aspect_frame->ratio != ratio)
+        {
+          aspect_frame->ratio = ratio;
+          g_object_notify (G_OBJECT (aspect_frame), "ratio");
+        }
+      if (aspect_frame->obey_child != obey_child)
+        {
+          aspect_frame->obey_child = obey_child;
+          g_object_notify (G_OBJECT (aspect_frame), "obey-child");
+        }
+      g_object_thaw_notify (G_OBJECT (aspect_frame));
+
+      gtk_widget_queue_resize (GTK_WIDGET (aspect_frame));
     }
 }
 
@@ -266,7 +285,7 @@ gtk_aspect_frame_compute_child_allocation (GtkFrame      *frame,
       else
        ratio = aspect_frame->ratio;
 
-      parent_class->compute_child_allocation (frame, &full_allocation);
+      GTK_FRAME_CLASS (gtk_aspect_frame_parent_class)->compute_child_allocation (frame, &full_allocation);
       
       if (ratio * full_allocation.height > full_allocation.width)
        {
@@ -283,5 +302,8 @@ gtk_aspect_frame_compute_child_allocation (GtkFrame      *frame,
       child_allocation->y = full_allocation.y + aspect_frame->yalign * (full_allocation.height - child_allocation->height);
     }
   else
-    parent_class->compute_child_allocation (frame, child_allocation);
+    GTK_FRAME_CLASS (gtk_aspect_frame_parent_class)->compute_child_allocation (frame, child_allocation);
 }
+
+#define __GTK_ASPECT_FRAME_C__
+#include "gtkaliasdef.c"