]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprogress.c
Bug 131920 – gtkNotebook sends incorrect switch_page value
[~andy/gtk] / gtk / gtkprogress.c
index 368eead79da6c2c8e9a8005afccbcc16b1340d0b..587d6e8bcd0c93f7591b71cd14e2b8c45997f25a 100644 (file)
  */
 
 #include <config.h>
-#include <glib/gprintf.h>
 #include <math.h>
 #include <string.h>
-#include "gtkalias.h"
+#undef GTK_DISABLE_DEPRECATED
 #include "gtkprogress.h" 
+#include "gtkprivate.h" 
 #include "gtkintl.h"
+#include "gtkalias.h"
 
 #define EPSILON  1e-5
 #define DEFAULT_FORMAT "%P %%"
@@ -44,8 +45,6 @@ enum {
 };
 
 
-static void gtk_progress_class_init      (GtkProgressClass *klass);
-static void gtk_progress_init            (GtkProgress      *progress);
 static void gtk_progress_set_property    (GObject          *object,
                                          guint             prop_id,
                                          const GValue     *value,
@@ -57,7 +56,7 @@ static void gtk_progress_get_property    (GObject          *object,
 static void gtk_progress_destroy         (GtkObject        *object);
 static void gtk_progress_finalize        (GObject          *object);
 static void gtk_progress_realize         (GtkWidget        *widget);
-static gint gtk_progress_expose          (GtkWidget        *widget,
+static gboolean gtk_progress_expose      (GtkWidget        *widget,
                                          GdkEventExpose   *event);
 static void gtk_progress_size_allocate   (GtkWidget        *widget,
                                          GtkAllocation    *allocation);
@@ -67,36 +66,7 @@ static void gtk_progress_value_changed   (GtkAdjustment    *adjustment,
 static void gtk_progress_changed         (GtkAdjustment    *adjustment,
                                          GtkProgress      *progress);
 
-
-static GtkWidgetClass *parent_class = NULL;
-
-
-GType
-gtk_progress_get_type (void)
-{
-  static GType progress_type = 0;
-
-  if (!progress_type)
-    {
-      static const GTypeInfo progress_info =
-      {
-       sizeof (GtkProgressClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_progress_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkProgress),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_progress_init,
-      };
-
-      progress_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkProgress",
-                                             &progress_info, 0);
-    }
-
-  return progress_type;
-}
+G_DEFINE_TYPE (GtkProgress, gtk_progress, GTK_TYPE_WIDGET)
 
 static void
 gtk_progress_class_init (GtkProgressClass *class)
@@ -108,8 +78,6 @@ gtk_progress_class_init (GtkProgressClass *class)
   object_class = (GtkObjectClass *) class;
   widget_class = (GtkWidgetClass *) class;
 
-  parent_class = gtk_type_class (GTK_TYPE_WIDGET);
-
   gobject_class->finalize = gtk_progress_finalize;
 
   gobject_class->set_property = gtk_progress_set_property;
@@ -124,41 +92,37 @@ gtk_progress_class_init (GtkProgressClass *class)
   class->paint = NULL;
   class->update = NULL;
   class->act_mode_enter = NULL;
-
+  
   g_object_class_install_property (gobject_class,
                                    PROP_ACTIVITY_MODE,
-                                   g_param_spec_boolean ("activity_mode",
+                                   g_param_spec_boolean ("activity-mode",
                                                         P_("Activity mode"),
-                                                        P_("If TRUE the GtkProgress is in activity mode, meaning that it signals something is happening, but not how much of the activity is finished. This is used when you're doing something that you don't know how long it will take"),
+                                                        P_("If TRUE, the GtkProgress is in activity mode, meaning that it signals "
+                                                            "something is happening, but not how much of the activity is finished. "
+                                                            "This is used when you're doing something but don't know how long it will take."),
                                                         FALSE,
-                                                        G_PARAM_READWRITE));
-
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_TEXT,
-                                   g_param_spec_boolean ("show_text",
+                                   g_param_spec_boolean ("show-text",
                                                         P_("Show text"),
-                                                        P_("Whether the progress is shown as text"),
+                                                        P_("Whether the progress is shown as text."),
                                                         FALSE,
-                                                        G_PARAM_READWRITE));
-
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_TEXT_XALIGN,
-                                  g_param_spec_float ("text_xalign",
+                                  g_param_spec_float ("text-xalign",
                                                       P_("Text x alignment"),
-                                                      P_("A number between 0.0 and 1.0 specifying the horizontal alignment of the text in the progress widget"),
-                                                      0.0,
-                                                      1.0,
-                                                      0.5,
-                                                      G_PARAM_READWRITE));  
-    g_object_class_install_property (gobject_class,
+                                                       P_("The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
+                                                      0.0, 1.0, 0.5,
+                                                      GTK_PARAM_READWRITE));  
+  g_object_class_install_property (gobject_class,
                                   PROP_TEXT_YALIGN,
-                                  g_param_spec_float ("text_yalign",
+                                  g_param_spec_float ("text-yalign",
                                                       P_("Text y alignment"),
-                                                      P_("A number between 0.0 and 1.0 specifying the vertical alignment of the text in the progress widget"),
-                                                      0.0,
-                                                      1.0,
-                                                      0.5,
-                                                      G_PARAM_READWRITE));
+                                                       P_("The vertical text alignment, from 0 (top) to 1 (bottom)."),
+                                                      0.0, 1.0, 0.5,
+                                                      GTK_PARAM_READWRITE));
 }
 
 static void
@@ -241,13 +205,10 @@ gtk_progress_init (GtkProgress *progress)
 static void
 gtk_progress_realize (GtkWidget *widget)
 {
-  GtkProgress *progress;
+  GtkProgress *progress = GTK_PROGRESS (widget);
   GdkWindowAttr attributes;
   gint attributes_mask;
 
-  g_return_if_fail (GTK_IS_PROGRESS (widget));
-
-  progress = GTK_PROGRESS (widget);
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
   attributes.window_type = GDK_WINDOW_CHILD;
@@ -276,11 +237,7 @@ gtk_progress_realize (GtkWidget *widget)
 static void
 gtk_progress_destroy (GtkObject *object)
 {
-  GtkProgress *progress;
-
-  g_return_if_fail (GTK_IS_PROGRESS (object));
-
-  progress = GTK_PROGRESS (object);
+  GtkProgress *progress = GTK_PROGRESS (object);
 
   if (progress->adjustment)
     {
@@ -294,34 +251,26 @@ gtk_progress_destroy (GtkObject *object)
       progress->adjustment = NULL;
     }
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_progress_parent_class)->destroy (object);
 }
 
 static void
 gtk_progress_finalize (GObject *object)
 {
-  GtkProgress *progress;
-
-  g_return_if_fail (GTK_IS_PROGRESS (object));
-
-  progress = GTK_PROGRESS (object);
+  GtkProgress *progress = GTK_PROGRESS (object);
 
   if (progress->offscreen_pixmap)
     g_object_unref (progress->offscreen_pixmap);
 
-  if (progress->format)
-    g_free (progress->format);
+  g_free (progress->format);
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_progress_parent_class)->finalize (object);
 }
 
-static gint
+static gboolean
 gtk_progress_expose (GtkWidget      *widget,
                     GdkEventExpose *event)
 {
-  g_return_val_if_fail (GTK_IS_PROGRESS (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-
   if (GTK_WIDGET_DRAWABLE (widget))
     gdk_draw_drawable (widget->window,
                       widget->style->black_gc,
@@ -338,9 +287,6 @@ static void
 gtk_progress_size_allocate (GtkWidget     *widget,
                            GtkAllocation *allocation)
 {
-  g_return_if_fail (GTK_IS_PROGRESS (widget));
-  g_return_if_fail (allocation != NULL);
-
   widget->allocation = *allocation;
 
   if (GTK_WIDGET_REALIZED (widget))
@@ -371,6 +317,13 @@ gtk_progress_create_pixmap (GtkProgress *progress)
                                                   widget->allocation.width,
                                                   widget->allocation.height,
                                                   -1);
+
+      /* clear the pixmap for transparent themes */
+      gtk_paint_flat_box (widget->style,
+                          progress->offscreen_pixmap,
+                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                          NULL, widget, "trough", 0, 0, -1, -1);
+      
       GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
     }
 }
@@ -534,8 +487,7 @@ gtk_progress_set_adjustment (GtkProgress   *progress,
       progress->adjustment = adjustment;
       if (adjustment)
         {
-          g_object_ref (adjustment);
-         gtk_object_sink (GTK_OBJECT (adjustment));
+          g_object_ref_sink (adjustment);
           g_signal_connect (adjustment, "changed",
                            G_CALLBACK (gtk_progress_changed),
                            progress);
@@ -652,7 +604,7 @@ gtk_progress_set_show_text (GtkProgress *progress,
 
       gtk_widget_queue_resize (GTK_WIDGET (progress));
 
-      g_object_notify (G_OBJECT (progress), "show_text");
+      g_object_notify (G_OBJECT (progress), "show-text");
     }
 }
 
@@ -671,13 +623,13 @@ gtk_progress_set_text_alignment (GtkProgress *progress,
       if (progress->x_align != x_align)
        {
          progress->x_align = x_align;
-         g_object_notify (G_OBJECT (progress), "text_xalign");
+         g_object_notify (G_OBJECT (progress), "text-xalign");
        }
 
       if (progress->y_align != y_align)
        {
          progress->y_align = y_align;
-         g_object_notify (G_OBJECT (progress), "text_yalign");
+         g_object_notify (G_OBJECT (progress), "text-yalign");
        }
       g_object_thaw_notify (G_OBJECT (progress));
 
@@ -751,6 +703,9 @@ gtk_progress_set_activity_mode (GtkProgress *progress,
       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (progress)))
        gtk_widget_queue_resize (GTK_WIDGET (progress));
 
-      g_object_notify (G_OBJECT (progress), "activity_mode");
+      g_object_notify (G_OBJECT (progress), "activity-mode");
     }
 }
+
+#define __GTK_PROGRESS_C__
+#include "gtkaliasdef.c"