]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprogress.c
Set this to `$(libexecdir)/pkgconfig'; this is the directory where
[~andy/gtk] / gtk / gtkprogress.c
index ce9267d53e22376666578dcedfc4fd040ad4c4e3..e2d2c6928a06a0ed25ac3c367395bc72240b49a9 100644 (file)
@@ -2,21 +2,28 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * 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
+ * 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 <stdio.h>
 #include <math.h>
 #include <string.h>
@@ -43,7 +50,7 @@ static void gtk_progress_get_arg       (GtkObject        *object,
                                          GtkArg           *arg,
                                          guint             arg_id);
 static void gtk_progress_destroy         (GtkObject        *object);
-static void gtk_progress_finalize        (GtkObject        *object);
+static void gtk_progress_finalize        (GObject          *object);
 static void gtk_progress_realize         (GtkWidget        *widget);
 static gint gtk_progress_expose          (GtkWidget        *widget,
                                          GdkEventExpose   *event);
@@ -62,7 +69,7 @@ gtk_progress_get_type (void)
 
   if (!progress_type)
     {
-      GtkTypeInfo progress_info =
+      static const GtkTypeInfo progress_info =
       {
        "GtkProgress",
        sizeof (GtkProgress),
@@ -83,6 +90,7 @@ gtk_progress_get_type (void)
 static void
 gtk_progress_class_init (GtkProgressClass *class)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
 
@@ -90,6 +98,21 @@ gtk_progress_class_init (GtkProgressClass *class)
   widget_class = (GtkWidgetClass *) class;
   parent_class = gtk_type_class (GTK_TYPE_WIDGET);
 
+  gobject_class->finalize = gtk_progress_finalize;
+
+  object_class->set_arg = gtk_progress_set_arg;
+  object_class->get_arg = gtk_progress_get_arg;
+  object_class->destroy = gtk_progress_destroy;
+
+  widget_class->realize = gtk_progress_realize;
+  widget_class->expose_event = gtk_progress_expose;
+  widget_class->size_allocate = gtk_progress_size_allocate;
+
+  /* to be overridden */
+  class->paint = NULL;
+  class->update = NULL;
+  class->act_mode_enter = NULL;
+
   gtk_object_add_arg_type ("GtkProgress::activity_mode",
                           GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE,
@@ -106,20 +129,6 @@ gtk_progress_class_init (GtkProgressClass *class)
                           GTK_TYPE_FLOAT,
                           GTK_ARG_READWRITE,
                           ARG_TEXT_YALIGN);
-
-  object_class->set_arg = gtk_progress_set_arg;
-  object_class->get_arg = gtk_progress_get_arg;
-  object_class->destroy = gtk_progress_destroy;
-  object_class->finalize = gtk_progress_finalize;
-
-  widget_class->realize = gtk_progress_realize;
-  widget_class->expose_event = gtk_progress_expose;
-  widget_class->size_allocate = gtk_progress_size_allocate;
-
-  /* to be overridden */
-  class->paint = NULL;
-  class->update = NULL;
-  class->act_mode_enter = NULL;
 }
 
 static void
@@ -189,6 +198,7 @@ gtk_progress_init (GtkProgress *progress)
   progress->y_align = 0.5;
   progress->show_text = FALSE;
   progress->activity_mode = FALSE;
+  progress->use_text_format = TRUE;
 }
 
 static void
@@ -238,32 +248,32 @@ gtk_progress_destroy (GtkObject *object)
   progress = GTK_PROGRESS (object);
 
   if (progress->adjustment)
-    gtk_signal_disconnect_by_data (GTK_OBJECT (progress->adjustment),
-                                  progress);
+    {
+      gtk_signal_disconnect_by_data (GTK_OBJECT (progress->adjustment),
+                                    progress);
+      gtk_object_unref (GTK_OBJECT (progress->adjustment));
+      progress->adjustment = NULL;
+    }
 
   GTK_OBJECT_CLASS (parent_class)->destroy (object);
 }
 
 static void
-gtk_progress_finalize (GtkObject *object)
+gtk_progress_finalize (GObject *object)
 {
   GtkProgress *progress;
 
-  g_return_if_fail (object != NULL);
   g_return_if_fail (GTK_IS_PROGRESS (object));
 
   progress = GTK_PROGRESS (object);
 
-  if (progress->adjustment)
-    gtk_object_unref (GTK_OBJECT (GTK_PROGRESS (object)->adjustment));
-  
   if (progress->offscreen_pixmap)
     gdk_pixmap_unref (progress->offscreen_pixmap);
 
   if (progress->format)
     g_free (progress->format);
 
-  GTK_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gint
@@ -325,7 +335,7 @@ gtk_progress_create_pixmap (GtkProgress *progress)
                                                   widget->allocation.width,
                                                   widget->allocation.height,
                                                   -1);
-      GTK_PROGRESS_CLASS (GTK_OBJECT (progress)->klass)->paint (progress);
+      GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
     }
 }
 
@@ -333,7 +343,7 @@ static void
 gtk_progress_value_changed (GtkAdjustment *adjustment,
                            GtkProgress   *progress)
 {
-  GTK_PROGRESS_CLASS (GTK_OBJECT (progress)->klass)->update (progress);
+  GTK_PROGRESS_GET_CLASS (progress)->update (progress);
 }
 
 static gchar *
@@ -348,6 +358,13 @@ gtk_progress_build_string (GtkProgress *progress,
   gchar fmt[10];
 
   src = progress->format;
+
+  /* This is the new supported version of this function */
+  if (!progress->use_text_format)
+    return g_strdup (src);
+
+  /* And here's all the deprecated goo. */
+  
   dest = buf;
  
   while (src && *src)
@@ -488,6 +505,8 @@ gtk_progress_configure (GtkProgress *progress,
   g_return_if_fail (min <= max);
   g_return_if_fail (value >= min && value <= max);
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
   adj = progress->adjustment;
 
   if (fabs (adj->lower - min) > EPSILON || fabs (adj->upper - max) > EPSILON)
@@ -510,6 +529,8 @@ gtk_progress_set_percentage (GtkProgress *progress,
   g_return_if_fail (GTK_IS_PROGRESS (progress));
   g_return_if_fail (percentage >= 0 && percentage <= 1.0);
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
   gtk_progress_set_value (progress, progress->adjustment->lower + percentage * 
                 (progress->adjustment->upper - progress->adjustment->lower));
 }
@@ -520,8 +541,11 @@ gtk_progress_get_current_percentage (GtkProgress *progress)
   g_return_val_if_fail (progress != NULL, 0);
   g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
 
-  return (progress->adjustment->value - progress->adjustment->lower) /
-    (progress->adjustment->upper - progress->adjustment->lower);
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
+
+  return ((progress->adjustment->value - progress->adjustment->lower) /
+         (progress->adjustment->upper - progress->adjustment->lower));
 }
 
 gfloat
@@ -531,6 +555,9 @@ gtk_progress_get_percentage_from_value (GtkProgress *progress,
   g_return_val_if_fail (progress != NULL, 0);
   g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
+
   if (value >= progress->adjustment->lower &&
       value <= progress->adjustment->upper)
     return (value - progress->adjustment->lower) /
@@ -546,6 +573,9 @@ gtk_progress_set_value (GtkProgress *progress,
   g_return_if_fail (progress != NULL);
   g_return_if_fail (GTK_IS_PROGRESS (progress));
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
+
   if (fabs (progress->adjustment->value - value) > EPSILON)
     gtk_adjustment_set_value (progress->adjustment, value);
 }
@@ -556,7 +586,7 @@ gtk_progress_get_value (GtkProgress *progress)
   g_return_val_if_fail (progress != NULL, 0);
   g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
 
-  return progress->adjustment->value;
+  return progress->adjustment ? progress->adjustment->value : 0;
 }
 
 void
@@ -597,11 +627,16 @@ gtk_progress_set_text_alignment (GtkProgress *progress,
 
 void
 gtk_progress_set_format_string (GtkProgress *progress,
-                               gchar       *format)
+                               const gchar *format)
 {
   g_return_if_fail (progress != NULL);
   g_return_if_fail (GTK_IS_PROGRESS (progress));
 
+  /* Turn on format, in case someone called
+   * gtk_progress_bar_set_text() and turned it off.
+   */
+  progress->use_text_format = TRUE;
+  
   if (format)
     {
       if (progress->format)
@@ -619,8 +654,11 @@ gtk_progress_get_current_text (GtkProgress *progress)
   g_return_val_if_fail (progress != NULL, 0);
   g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
+
   return gtk_progress_build_string (progress, progress->adjustment->value,
-                   gtk_progress_get_current_percentage (progress));
+                                   gtk_progress_get_current_percentage (progress));
 }
 
 gchar *
@@ -630,8 +668,11 @@ gtk_progress_get_text_from_value (GtkProgress *progress,
   g_return_val_if_fail (progress != NULL, 0);
   g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
 
+  if (!progress->adjustment)
+    gtk_progress_set_adjustment (progress, NULL);
+
   return gtk_progress_build_string (progress, value,
-                   gtk_progress_get_percentage_from_value (progress, value));
+                                   gtk_progress_get_percentage_from_value (progress, value));
 }
 
 void
@@ -646,8 +687,7 @@ gtk_progress_set_activity_mode (GtkProgress *progress,
       progress->activity_mode = (activity_mode != 0);
 
       if (progress->activity_mode)
-       GTK_PROGRESS_CLASS 
-         (GTK_OBJECT (progress)->klass)->act_mode_enter (progress);
+       GTK_PROGRESS_GET_CLASS (progress)->act_mode_enter (progress);
 
       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (progress)))
        gtk_widget_queue_resize (GTK_WIDGET (progress));