* 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>
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);
if (!progress_type)
{
- GtkTypeInfo progress_info =
+ static const GtkTypeInfo progress_info =
{
"GtkProgress",
sizeof (GtkProgress),
static void
gtk_progress_class_init (GtkProgressClass *class)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkObjectClass *object_class;
GtkWidgetClass *widget_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,
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
progress->y_align = 0.5;
progress->show_text = FALSE;
progress->activity_mode = FALSE;
+ progress->use_text_format = TRUE;
}
static void
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
widget->allocation.width,
widget->allocation.height,
-1);
- GTK_PROGRESS_CLASS (GTK_OBJECT (progress)->klass)->paint (progress);
+ GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
}
}
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 *
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)
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)
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));
}
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
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) /
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);
}
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
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)
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 *
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
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));