]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprogressbar.c
progressbar: Remove unused update vfunc
[~andy/gtk] / gtk / gtkprogressbar.c
index 86ddec16906c81371dda97b0deb84e647cac840c..5752d70320d7da94c32282a5285fab52e7ba101e 100644 (file)
  * 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.
  */
 
-#include <stdio.h>
+/*
+ * 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 "config.h"
+
+#include <string.h>
+
 #include "gtkprogressbar.h"
-#include "gtksignal.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
 
 
 #define MIN_HORIZONTAL_BAR_WIDTH   150
 #define MIN_HORIZONTAL_BAR_HEIGHT  20
 #define MIN_VERTICAL_BAR_WIDTH     22
 #define MIN_VERTICAL_BAR_HEIGHT    80
-#define MAX_TEXT_LENGTH            80
-#define TEXT_SPACING               2
 
 
-static void gtk_progress_bar_class_init    (GtkProgressBarClass *klass);
-static void gtk_progress_bar_init          (GtkProgressBar      *pbar);
+struct _GtkProgressBarPriv
+{
+  GtkProgressBarOrientation orientation;
+
+  GdkPixmap     *offscreen_pixmap;
+
+  gchar         *text;
+
+  gdouble        fraction;
+  gdouble        pulse_fraction;
+
+  guint          blocks;
+  gint           in_block;
+
+  gint           activity_pos;
+  guint          activity_blocks;
+  guint          activity_step;
+
+  guint          activity_dir  : 1;
+  guint          activity_mode : 1;
+  guint          dirty         : 1;
+  guint          ellipsize     : 3;
+  guint          show_text     : 1;
+};
+
+enum {
+  PROP_0,
+  PROP_FRACTION,
+  PROP_PULSE_STEP,
+  PROP_ORIENTATION,
+  PROP_TEXT,
+  PROP_SHOW_TEXT,
+  PROP_ELLIPSIZE
+};
+
+static void gtk_progress_bar_set_property  (GObject             *object,
+                                            guint                prop_id,
+                                            const GValue        *value,
+                                            GParamSpec          *pspec);
+static void gtk_progress_bar_get_property  (GObject             *object,
+                                            guint                prop_id,
+                                            GValue              *value,
+                                            GParamSpec          *pspec);
+static gboolean gtk_progress_bar_expose    (GtkWidget           *widget,
+                                            GdkEventExpose      *event);
 static void gtk_progress_bar_size_request  (GtkWidget           *widget,
-                                           GtkRequisition      *requisition);
-static void gtk_progress_bar_real_update   (GtkProgress         *progress);
-static void gtk_progress_bar_paint         (GtkProgress         *progress);
-static void gtk_progress_bar_act_mode_enter (GtkProgress        *progress);
+                                            GtkRequisition      *requisition);
+static void gtk_progress_bar_size_allocate (GtkWidget           *widget,
+                                            GtkAllocation       *allocation);
+static void gtk_progress_bar_style_set     (GtkWidget           *widget,
+                                            GtkStyle            *previous);
+static void gtk_progress_bar_real_update   (GtkProgressBar      *progress);
+static void gtk_progress_bar_paint         (GtkProgressBar      *progress);
+static void gtk_progress_bar_act_mode_enter (GtkProgressBar     *progress);
+static void gtk_progress_bar_realize       (GtkWidget           *widget);
+static void gtk_progress_bar_finalize      (GObject             *object);
+static void gtk_progress_bar_create_pixmap (GtkProgressBar      *pbar);
 
 
-guint
-gtk_progress_bar_get_type (void)
-{
-  static guint progress_bar_type = 0;
-
-  if (!progress_bar_type)
-    {
-      GtkTypeInfo progress_bar_info =
-      {
-       "GtkProgressBar",
-       sizeof (GtkProgressBar),
-       sizeof (GtkProgressBarClass),
-       (GtkClassInitFunc) gtk_progress_bar_class_init,
-       (GtkObjectInitFunc) gtk_progress_bar_init,
-        /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL
-      };
-
-      progress_bar_type = gtk_type_unique (gtk_progress_get_type (),
-                                          &progress_bar_info);
-    }
-
-  return progress_bar_type;
-}
+G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET)
 
 static void
 gtk_progress_bar_class_init (GtkProgressBarClass *class)
 {
+  GObjectClass *gobject_class;
   GtkWidgetClass *widget_class;
-  GtkProgressClass *progress_class;
 
+  gobject_class = G_OBJECT_CLASS (class);
   widget_class = (GtkWidgetClass *) class;
-  progress_class = (GtkProgressClass *) class;
 
-  widget_class->size_request = gtk_progress_bar_size_request;
+  gobject_class->set_property = gtk_progress_bar_set_property;
+  gobject_class->get_property = gtk_progress_bar_get_property;
+  gobject_class->finalize = gtk_progress_bar_finalize;
 
-  progress_class->paint = gtk_progress_bar_paint;
-  progress_class->update = gtk_progress_bar_real_update;
-  progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
+  widget_class->realize = gtk_progress_bar_realize;
+  widget_class->expose_event = gtk_progress_bar_expose;
+  widget_class->size_request = gtk_progress_bar_size_request;
+  widget_class->size_allocate = gtk_progress_bar_size_allocate;
+  widget_class->style_set = gtk_progress_bar_style_set;
+
+  class->paint = gtk_progress_bar_paint;
+  class->act_mode_enter = gtk_progress_bar_act_mode_enter;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_ORIENTATION,
+                                   g_param_spec_enum ("orientation",
+                                                      P_("Orientation"),
+                                                      P_("Orientation and growth direction of the progress bar"),
+                                                      GTK_TYPE_PROGRESS_BAR_ORIENTATION,
+                                                      GTK_PROGRESS_LEFT_TO_RIGHT,
+                                                      GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_FRACTION,
+                                   g_param_spec_double ("fraction",
+                                                        P_("Fraction"),
+                                                        P_("The fraction of total work that has been completed"),
+                                                        0.0, 1.0, 0.0,
+                                                        GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_PULSE_STEP,
+                                   g_param_spec_double ("pulse-step",
+                                                        P_("Pulse Step"),
+                                                        P_("The fraction of total progress to move the bouncing block when pulsed"),
+                                                        0.0, 1.0, 0.1,
+                                                        GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_TEXT,
+                                   g_param_spec_string ("text",
+                                                        P_("Text"),
+                                                        P_("Text to be displayed in the progress bar"),
+                                                        NULL,
+                                                        GTK_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHOW_TEXT,
+                                   g_param_spec_boolean ("show-text",
+                                                         P_("Show text"),
+                                                         P_("Whether the progress is shown as text."),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+
+  /**
+   * GtkProgressBar:ellipsize:
+   *
+   * The preferred place to ellipsize the string, if the progressbar does
+   * not have enough room to display the entire string, specified as a
+   * #PangoEllisizeMode.
+   *
+   * Note that setting this property to a value other than
+   * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
+   * only enough space to display the ellipsis "...". Another means to set a
+   * progressbar's width is gtk_widget_set_size_request().
+   *
+   * Since: 2.6
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ELLIPSIZE,
+                                   g_param_spec_enum ("ellipsize",
+                                                      P_("Ellipsize"),
+                                                      P_("The preferred place to ellipsize the string, if the progress bar "
+                                                         "does not have enough room to display the entire string, if at all."),
+                                                      PANGO_TYPE_ELLIPSIZE_MODE,
+                                                      PANGO_ELLIPSIZE_NONE,
+                                                      GTK_PARAM_READWRITE));
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("xspacing",
+                                                             P_("XSpacing"),
+                                                             P_("Extra spacing applied to the width of a progress bar."),
+                                                             0, G_MAXINT, 7,
+                                                             G_PARAM_READWRITE));
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("yspacing",
+                                                             P_("YSpacing"),
+                                                             P_("Extra spacing applied to the height of a progress bar."),
+                                                             0, G_MAXINT, 7,
+                                                             G_PARAM_READWRITE));
+
+  /**
+   * GtkProgressBar:min-horizontal-bar-width:
+   *
+   * The minimum horizontal width of the progress bar.
+   *
+   * Since: 2.14
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("min-horizontal-bar-width",
+                                                             P_("Min horizontal bar width"),
+                                                             P_("The minimum horizontal width of the progress bar"),
+                                                             1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
+                                                             G_PARAM_READWRITE));
+  /**
+   * GtkProgressBar:min-horizontal-bar-height:
+   *
+   * Minimum horizontal height of the progress bar.
+   *
+   * Since: 2.14
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("min-horizontal-bar-height",
+                                                             P_("Min horizontal bar height"),
+                                                             P_("Minimum horizontal height of the progress bar"),
+                                                             1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
+                                                             G_PARAM_READWRITE));
+  /**
+   * GtkProgressBar:min-vertical-bar-width:
+   *
+   * The minimum vertical width of the progress bar.
+   *
+   * Since: 2.14
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("min-vertical-bar-width",
+                                                             P_("Min vertical bar width"),
+                                                             P_("The minimum vertical width of the progress bar"),
+                                                             1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
+                                                             G_PARAM_READWRITE));
+  /**
+   * GtkProgressBar:min-vertical-bar-height:
+   *
+   * The minimum vertical height of the progress bar.
+   *
+   * Since: 2.14
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("min-vertical-bar-height",
+                                                             P_("Min vertical bar height"),
+                                                             P_("The minimum vertical height of the progress bar"),
+                                                             1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
+                                                             G_PARAM_READWRITE));
+
+  g_type_class_add_private (class, sizeof (GtkProgressBarPriv));
 }
 
 static void
 gtk_progress_bar_init (GtkProgressBar *pbar)
 {
-  GTK_WIDGET_SET_FLAGS (pbar, GTK_BASIC);
-
-  pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
-  pbar->blocks = 10;
-  pbar->in_block = -1;
-  pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
-  pbar->activity_pos = 0;
-  pbar->activity_dir = 1;
-  pbar->activity_step = 3;
-  pbar->activity_blocks = 5;
+  GtkProgressBarPriv *priv;
+
+  pbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (pbar,
+                                            GTK_TYPE_PROGRESS_BAR,
+                                            GtkProgressBarPriv);
+  priv = pbar->priv;
+
+  priv->blocks = 10;
+  priv->in_block = -1;
+  priv->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+  priv->pulse_fraction = 0.1;
+  priv->activity_pos = 0;
+  priv->activity_dir = 1;
+  priv->activity_step = 3;
+  priv->activity_blocks = 5;
+  priv->ellipsize = PANGO_ELLIPSIZE_NONE;
+  priv->show_text = FALSE;
+
+  priv->text = NULL;
+  priv->fraction = 0.0;
 }
 
+static void
+gtk_progress_bar_realize (GtkWidget *widget)
+{
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+
+  gtk_widget_set_realized (widget, TRUE);
+
+  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);
+  attributes.event_mask |= 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, widget);
+
+  widget->style = gtk_style_attach (widget->style, widget->window);
+  gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
+
+  gtk_progress_bar_create_pixmap (GTK_PROGRESS_BAR (widget));
+}
 
-GtkWidget *
-gtk_progress_bar_new (void)
+static void
+gtk_progress_bar_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
 {
   GtkProgressBar *pbar;
 
-  pbar = gtk_type_new (gtk_progress_bar_get_type ());
+  pbar = GTK_PROGRESS_BAR (object);
 
-  gtk_progress_bar_construct (pbar, NULL);
-
-  return GTK_WIDGET (pbar);
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
+      break;
+    case PROP_FRACTION:
+      gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
+      break;
+    case PROP_PULSE_STEP:
+      gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
+      break;
+    case PROP_TEXT:
+      gtk_progress_bar_set_text (pbar, g_value_get_string (value));
+      break;
+    case PROP_SHOW_TEXT:
+      gtk_progress_bar_set_show_text (pbar, g_value_get_boolean (value));
+      break;
+    case PROP_ELLIPSIZE:
+      gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
-GtkWidget *
-gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
+static void
+gtk_progress_bar_get_property (GObject      *object,
+                               guint         prop_id,
+                               GValue       *value,
+                               GParamSpec   *pspec)
 {
-  GtkProgressBar *pbar;
+  GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
+  GtkProgressBarPriv* priv = pbar->priv;
 
-  pbar = gtk_type_new (gtk_progress_bar_get_type ());
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      g_value_set_enum (value, priv->orientation);
+      break;
+    case PROP_FRACTION:
+      g_value_set_double (value, priv->fraction);
+      break;
+    case PROP_PULSE_STEP:
+      g_value_set_double (value, priv->pulse_fraction);
+      break;
+    case PROP_TEXT:
+      g_value_set_string (value, priv->text);
+      break;
+    case PROP_SHOW_TEXT:
+      g_value_set_boolean (value, priv->show_text);
+      break;
+    case PROP_ELLIPSIZE:
+      g_value_set_enum (value, priv->ellipsize);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+GtkWidget*
+gtk_progress_bar_new (void)
+{
+  GtkWidget *pbar;
 
-  gtk_progress_bar_construct (pbar, adjustment);
+  pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
 
-  return GTK_WIDGET (pbar);
+  return pbar;
 }
 
-void
-gtk_progress_bar_construct (GtkProgressBar *pbar,
-                           GtkAdjustment  *adjustment)
+static void
+gtk_progress_bar_real_update (GtkProgressBar *pbar)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv *priv;
+  GtkWidget *widget;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (!adjustment)
-    adjustment = (GtkAdjustment *) gtk_adjustment_new (0, 0, 100, 0, 0, 0);
+  priv = pbar->priv;
+  widget = GTK_WIDGET (pbar);
 
-  gtk_progress_set_adjustment (GTK_PROGRESS (pbar), adjustment);
+  if (priv->activity_mode)
+    {
+      guint size;
+
+      /* advance the block */
+      if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
+          priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+        {
+          /* Update our activity step. */
+          priv->activity_step = widget->allocation.width * priv->pulse_fraction;
+
+          size = MAX (2, widget->allocation.width / priv->activity_blocks);
+
+          if (priv->activity_dir == 0)
+            {
+              priv->activity_pos += priv->activity_step;
+              if (priv->activity_pos + size >= widget->allocation.width - widget->style->xthickness)
+                {
+                  priv->activity_pos = widget->allocation.width -
+                    widget->style->xthickness - size;
+                  priv->activity_dir = 1;
+                }
+            }
+          else
+            {
+              priv->activity_pos -= priv->activity_step;
+              if (priv->activity_pos <= widget->style->xthickness)
+                {
+                  priv->activity_pos = widget->style->xthickness;
+                  priv->activity_dir = 0;
+                }
+            }
+        }
+      else
+        {
+          /* Update our activity step. */
+          priv->activity_step = widget->allocation.height * priv->pulse_fraction;
+
+          size = MAX (2, widget->allocation.height / priv->activity_blocks);
+
+          if (priv->activity_dir == 0)
+            {
+              priv->activity_pos += priv->activity_step;
+              if (priv->activity_pos + size >= widget->allocation.height - widget->style->ythickness)
+                {
+                  priv->activity_pos = widget->allocation.height -
+                    widget->style->ythickness - size;
+                  priv->activity_dir = 1;
+                }
+            }
+          else
+            {
+              priv->activity_pos -= priv->activity_step;
+              if (priv->activity_pos <= widget->style->ythickness)
+                {
+                  priv->activity_pos = widget->style->ythickness;
+                  priv->activity_dir = 0;
+                }
+            }
+        }
+    }
+  priv->dirty = TRUE;
+  gtk_widget_queue_draw (widget);
 }
 
 static void
-gtk_progress_bar_real_update (GtkProgress *progress)
+gtk_progress_bar_finalize (GObject *object)
 {
-  GtkProgressBar *pbar;
-  GtkWidget *widget;
+  GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
+  GtkProgressBarPriv *priv = pbar->priv;
+
+  if (priv->offscreen_pixmap)
+    g_object_unref (priv->offscreen_pixmap);
 
-  g_return_if_fail (progress != NULL);
-  g_return_if_fail (GTK_IS_PROGRESS (progress));
+  g_free (priv->text);
+
+  G_OBJECT_CLASS (gtk_progress_bar_parent_class)->finalize (object);
+}
 
-  pbar = GTK_PROGRESS_BAR (progress);
-  widget = GTK_WIDGET (progress);
-  if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
-      GTK_PROGRESS (pbar)->activity_mode)
+static gboolean
+gtk_progress_bar_expose (GtkWidget      *widget,
+                         GdkEventExpose *event)
+{
+  GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
+  GtkProgressBarPriv *priv = pbar->priv;
+
+  if (gtk_widget_is_drawable (widget))
     {
-      if (GTK_PROGRESS (pbar)->activity_mode)
-       {
-         guint size;
-
-         /* advance the block */
-
-         if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-             pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-           {
-             size = MAX (2, widget->allocation.width / pbar->activity_blocks);
-
-             if (pbar->activity_dir == 0)
-               {
-                 pbar->activity_pos += pbar->activity_step;
-                 if (pbar->activity_pos + size >=
-                     widget->allocation.width -
-                     widget->style->klass->xthickness)
-                   {
-                     pbar->activity_pos = widget->allocation.width -
-                       widget->style->klass->xthickness - size;
-                     pbar->activity_dir = 1;
-                   }
-               }
-             else
-               {
-                 pbar->activity_pos -= pbar->activity_step;
-                 if (pbar->activity_pos <= widget->style->klass->xthickness)
-                   {
-                     pbar->activity_pos = widget->style->klass->xthickness;
-                     pbar->activity_dir = 0;
-                   }
-               }
-           }
-         else
-           {
-             size = MAX (2, widget->allocation.height / pbar->activity_blocks);
-
-             if (pbar->activity_dir == 0)
-               {
-                 pbar->activity_pos += pbar->activity_step;
-                 if (pbar->activity_pos + size >=
-                     widget->allocation.height -
-                     widget->style->klass->ythickness)
-                   {
-                     pbar->activity_pos = widget->allocation.height -
-                       widget->style->klass->ythickness - size;
-                     pbar->activity_dir = 1;
-                   }
-               }
-             else
-               {
-                 pbar->activity_pos -= pbar->activity_step;
-                 if (pbar->activity_pos <= widget->style->klass->ythickness)
-                   {
-                     pbar->activity_pos = widget->style->klass->ythickness;
-                     pbar->activity_dir = 0;
-                   }
-               }
-           }
-       }
-      gtk_progress_bar_paint (progress);
-      gtk_widget_queue_draw (GTK_WIDGET (progress));
+      cairo_t *cr;
+
+      if (priv->dirty)
+        gtk_progress_bar_paint (pbar);
+
+      cr = gdk_cairo_create (widget->window);
+      gdk_cairo_set_source_pixmap (cr, priv->offscreen_pixmap, 0, 0);
+      gdk_cairo_rectangle (cr, &event->area);
+      cairo_paint (cr);
+      cairo_destroy (cr);
     }
+
+  return FALSE;
+}
+
+static gchar *
+get_current_text (GtkProgressBar *pbar)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+
+  if (priv->text)
+    return g_strdup (priv->text);
   else
-    {
-      gint in_block;
-      
-      in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
-                            (gfloat)pbar->blocks);
-      
-      if (pbar->in_block != in_block)
-       {
-         pbar->in_block = in_block;
-         gtk_progress_bar_paint (progress);
-         gtk_widget_queue_draw (GTK_WIDGET (progress));
-       }
-    }
+    return g_strdup_printf ("%.0f %%", priv->fraction * 100.0);
 }
 
 static void
 gtk_progress_bar_size_request (GtkWidget      *widget,
-                              GtkRequisition *requisition)
+                               GtkRequisition *requisition)
 {
-  GtkProgress *progress;
   GtkProgressBar *pbar;
+  GtkProgressBarPriv *priv;
   gchar *buf;
+  PangoRectangle logical_rect;
+  PangoLayout *layout;
+  gint width, height;
+  gint xspacing, yspacing;
+  gint min_width, min_height;
 
-  g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
   g_return_if_fail (requisition != NULL);
 
-  progress = GTK_PROGRESS (widget);
+  gtk_widget_style_get (widget,
+                        "xspacing", &xspacing,
+                        "yspacing", &yspacing,
+                        NULL);
+
   pbar = GTK_PROGRESS_BAR (widget);
+  priv = pbar->priv;
 
-  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+  width = 2 * widget->style->xthickness + xspacing;
+  height = 2 * widget->style->ythickness + yspacing;
+
+  if (priv->show_text)
     {
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {
-         buf = gtk_progress_get_text_from_value (progress,
-                                                 progress->adjustment->upper);
-
-         requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH,
-                                   2 * widget->style->klass->xthickness + 3 +
-                                   gdk_text_width (widget->style->font, 
-                                                   buf, strlen (buf)) +
-                                   2 * TEXT_SPACING);
-
-         requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
-                                    2 * widget->style->klass->ythickness + 3 +
-                                    gdk_text_height (widget->style->font, 
-                                                     buf, strlen (buf)) +
-                                    2 * TEXT_SPACING);
-         g_free (buf);
-       }
+      buf = get_current_text (pbar);
+      layout = gtk_widget_create_pango_layout (widget, buf);
+
+      pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+      if (priv->ellipsize)
+        {
+          PangoContext *context;
+          PangoFontMetrics *metrics;
+          gint char_width;
+
+          /* The minimum size for ellipsized text is ~ 3 chars */
+          context = pango_layout_get_context (layout);
+          metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
+
+          char_width = pango_font_metrics_get_approximate_char_width (metrics);
+          pango_font_metrics_unref (metrics);
+
+          width += PANGO_PIXELS (char_width) * 3;
+        }
       else
-       {
-         requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
-         requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
-       }
+        width += logical_rect.width;
+
+      height += logical_rect.height;
+
+      g_object_unref (layout);
+      g_free (buf);
     }
+
+  if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
+      priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+    gtk_widget_style_get (widget,
+                          "min-horizontal-bar-width", &min_width,
+                          "min-horizontal-bar-height", &min_height,
+                          NULL);
   else
+    gtk_widget_style_get (widget,
+                          "min-vertical-bar-width", &min_width,
+                          "min-vertical-bar-height", &min_height,
+                          NULL);
+
+  requisition->width = MAX (min_width, width);
+  requisition->height = MAX (min_height, height);
+}
+
+static void
+gtk_progress_bar_size_allocate (GtkWidget     *widget,
+                                GtkAllocation *allocation)
+{
+  widget->allocation = *allocation;
+
+  if (gtk_widget_get_realized (widget))
     {
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {         
-         buf = gtk_progress_get_text_from_value (progress,
-                                                 progress->adjustment->upper);
-
-         requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH,
-                                   2 * widget->style->klass->xthickness + 3 +
-                                   gdk_text_width (widget->style->font, 
-                                                   buf, strlen (buf)) +
-                                   2 * TEXT_SPACING);
-
-         requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
-                                    2 * widget->style->klass->ythickness + 3 +
-                                    gdk_text_height (widget->style->font, 
-                                                     buf, strlen (buf)) +
-                                    2 * TEXT_SPACING);
-         g_free (buf);
-       }
-      else
-       {
-         requisition->width = MIN_VERTICAL_BAR_WIDTH;
-         requisition->height = MIN_VERTICAL_BAR_HEIGHT;
-       }
+      gdk_window_move_resize (widget->window,
+                              allocation->x, allocation->y,
+                              allocation->width, allocation->height);
+
+      gtk_progress_bar_create_pixmap (GTK_PROGRESS_BAR (widget));
     }
 }
 
 static void
-gtk_progress_bar_act_mode_enter (GtkProgress *progress)
+gtk_progress_bar_create_pixmap (GtkProgressBar *pbar)
 {
-  GtkProgressBar *pbar;
-  GtkWidget *widget;
-  gint size;
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+
+  if (gtk_widget_get_realized (widget))
+    {
+      if (priv->offscreen_pixmap)
+        g_object_unref (priv->offscreen_pixmap);
+
+      priv->offscreen_pixmap = gdk_pixmap_new (widget->window,
+                                               widget->allocation.width,
+                                               widget->allocation.height,
+                                               -1);
+
+      /* clear the pixmap for transparent themes */
+      gtk_paint_flat_box (widget->style,
+                          priv->offscreen_pixmap,
+                          GTK_STATE_NORMAL,
+                          GTK_SHADOW_NONE,
+                          NULL, widget, "trough", 0, 0, -1, -1);
+
+      GTK_PROGRESS_BAR_GET_CLASS (pbar)->paint (pbar);
+    }
+}
+
+static void
+gtk_progress_bar_style_set (GtkWidget *widget,
+                            GtkStyle  *previous)
+{
+  GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
+  GtkProgressBarPriv *priv = pbar->priv;
 
-  pbar = GTK_PROGRESS_BAR (progress);
-  widget = GTK_WIDGET (progress);
+  priv->dirty = TRUE;
 
-  /* calculate start pos */
+  GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->style_set (widget, previous);
+}
 
-  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+static void
+gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  GtkProgressBarOrientation orientation;
+
+  orientation = priv->orientation;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     {
-      size = MAX (2, widget->allocation.width / pbar->activity_blocks);
+      if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+        orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
+      else if (priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+        orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+    }
 
-      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
-       {
-         pbar->activity_pos = widget->style->klass->xthickness;
-         pbar->activity_dir = 0;
-       }
+  /* calculate start pos */
+
+  if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
+      orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+    {
+      if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+        {
+          priv->activity_pos = widget->style->xthickness;
+          priv->activity_dir = 0;
+        }
       else
-       {
-         pbar->activity_pos = widget->allocation.width - 
-           widget->style->klass->xthickness - (widget->allocation.height - 
-               widget->style->klass->ythickness * 2);
-         pbar->activity_dir = 1;
-       }
+        {
+          priv->activity_pos = widget->allocation.width -
+            widget->style->xthickness - (widget->allocation.height -
+                widget->style->ythickness * 2);
+          priv->activity_dir = 1;
+        }
     }
   else
     {
-      size = MAX (2, widget->allocation.height / pbar->activity_blocks);
-
-      if (pbar->orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
-       {
-         pbar->activity_pos = widget->style->klass->ythickness;
-         pbar->activity_dir = 0;
-       }
+      if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
+        {
+          priv->activity_pos = widget->style->ythickness;
+          priv->activity_dir = 0;
+        }
       else
-       {
-         pbar->activity_pos = widget->allocation.height -
-           widget->style->klass->ythickness - (widget->allocation.width - 
-               widget->style->klass->xthickness * 2);
-         pbar->activity_dir = 1;
-       }
+        {
+          priv->activity_pos = widget->allocation.height -
+            widget->style->ythickness - (widget->allocation.width -
+                widget->style->xthickness * 2);
+          priv->activity_dir = 1;
+        }
     }
 }
 
 static void
-gtk_progress_bar_paint (GtkProgress *progress)
+gtk_progress_bar_get_activity (GtkProgressBar            *pbar,
+                               GtkProgressBarOrientation  orientation,
+                               gint                      *offset,
+                               gint                      *amount)
 {
-  GtkProgressBar *pbar;
-  GtkWidget *widget;
-  gint amount;
-  gint block_delta = 0;
-  gint space = 0;
-  gint i;
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+
+  *offset = priv->activity_pos;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      *amount = MAX (2, widget->allocation.width / priv->activity_blocks);
+      break;
+
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      *amount = MAX (2, widget->allocation.height / priv->activity_blocks);
+      break;
+    }
+}
+
+static void
+gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
+                                 GtkProgressBarOrientation  orientation)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  GdkRectangle area;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
+      area.y = widget->style->ythickness;
+      area.height = widget->allocation.height - 2 * widget->style->ythickness;
+      break;
+
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
+      area.x = widget->style->xthickness;
+      area.width = widget->allocation.width - 2 * widget->style->xthickness;
+      break;
+
+    default:
+      return;
+      break;
+    }
+
+  gtk_paint_box (widget->style,
+                 priv->offscreen_pixmap,
+                 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
+                 &area, widget, "bar",
+                 area.x, area.y, area.width, area.height);
+}
+
+static void
+gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
+                                   gint                       amount,
+                                   GtkProgressBarOrientation  orientation)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  GdkRectangle area;
+
+  if (amount <= 0)
+    return;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      area.width = amount;
+      area.height = widget->allocation.height - widget->style->ythickness * 2;
+      area.y = widget->style->ythickness;
+
+      area.x = widget->style->xthickness;
+      if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+        area.x = widget->allocation.width - amount - area.x;
+      break;
+
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      area.width = widget->allocation.width - widget->style->xthickness * 2;
+      area.height = amount;
+      area.x = widget->style->xthickness;
+
+      area.y = widget->style->ythickness;
+      if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
+        area.y = widget->allocation.height - amount - area.y;
+      break;
+
+    default:
+      return;
+      break;
+    }
+
+  gtk_paint_box (widget->style,
+                 priv->offscreen_pixmap,
+                 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
+                 &area, widget, "bar",
+                 area.x, area.y, area.width, area.height);
+}
+
+static void
+gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
+                             gint                       offset,
+                             gint                       amount,
+                             GtkProgressBarOrientation  orientation)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
   gint x;
   gint y;
-  gfloat percentage;
-  gint size;
+  gchar *buf;
+  GdkRectangle rect;
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  GdkRectangle prelight_clip, start_clip, end_clip;
+  gfloat text_xalign = 0.5;
+  gfloat text_yalign = 0.5;
 
-  g_return_if_fail (progress != NULL);
-  g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
+  if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
+    text_xalign = 1.0 - text_xalign;
 
-  pbar = GTK_PROGRESS_BAR (progress);
-  widget = GTK_WIDGET (progress);
+  buf = get_current_text (pbar);
 
-  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-    space = widget->allocation.width -
-      2 * widget->style->klass->xthickness;
-  else
-    space = widget->allocation.height -
-      2 * widget->style->klass->ythickness;
+  layout = gtk_widget_create_pango_layout (widget, buf);
+  pango_layout_set_ellipsize (layout, priv->ellipsize);
+  if (priv->ellipsize)
+    pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
+
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+  x = widget->style->xthickness + 1 + text_xalign *
+      (widget->allocation.width - 2 * widget->style->xthickness -
+       2 - logical_rect.width);
+
+  y = widget->style->ythickness + 1 + text_yalign *
+      (widget->allocation.height - 2 * widget->style->ythickness -
+       2 - logical_rect.height);
+
+  rect.x = widget->style->xthickness;
+  rect.y = widget->style->ythickness;
+  rect.width = widget->allocation.width - 2 * widget->style->xthickness;
+  rect.height = widget->allocation.height - 2 * widget->style->ythickness;
+
+  prelight_clip = start_clip = end_clip = rect;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+      if (offset != -1)
+        prelight_clip.x = offset;
+      prelight_clip.width = amount;
+      start_clip.width = prelight_clip.x - start_clip.x;
+      end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
+      end_clip.width -= prelight_clip.width + start_clip.width;
+      break;
+
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      if (offset != -1)
+        prelight_clip.x = offset;
+      else
+        prelight_clip.x = rect.x + rect.width - amount;
+      prelight_clip.width = amount;
+      start_clip.width = prelight_clip.x - start_clip.x;
+      end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
+      end_clip.width -= prelight_clip.width + start_clip.width;
+      break;
+
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+      if (offset != -1)
+        prelight_clip.y = offset;
+      prelight_clip.height = amount;
+      start_clip.height = prelight_clip.y - start_clip.y;
+      end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
+      end_clip.height -= prelight_clip.height + start_clip.height;
+      break;
+
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      if (offset != -1)
+        prelight_clip.y = offset;
+      else
+        prelight_clip.y = rect.y + rect.height - amount;
+      prelight_clip.height = amount;
+      start_clip.height = prelight_clip.y - start_clip.y;
+      end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
+      end_clip.height -= prelight_clip.height + start_clip.height;
+      break;
+    }
+
+  if (start_clip.width > 0 && start_clip.height > 0)
+    gtk_paint_layout (widget->style,
+                      priv->offscreen_pixmap,
+                      GTK_STATE_NORMAL,
+                      FALSE,
+                      &start_clip,
+                      widget,
+                      "progressbar",
+                      x, y,
+                      layout);
+
+  if (end_clip.width > 0 && end_clip.height > 0)
+    gtk_paint_layout (widget->style,
+                      priv->offscreen_pixmap,
+                      GTK_STATE_NORMAL,
+                      FALSE,
+                      &end_clip,
+                      widget,
+                      "progressbar",
+                      x, y,
+                      layout);
+
+  gtk_paint_layout (widget->style,
+                    priv->offscreen_pixmap,
+                    GTK_STATE_PRELIGHT,
+                    FALSE,
+                    &prelight_clip,
+                    widget,
+                    "progressbar",
+                    x, y,
+                    layout);
+
+  g_object_unref (layout);
+  g_free (buf);
+}
+
+static void
+gtk_progress_bar_paint (GtkProgressBar *pbar)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  GtkProgressBarOrientation orientation;
 
-  percentage = gtk_progress_get_current_percentage (progress);
+  orientation = priv->orientation;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+    {
+      if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+        orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
+      else if (priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+        orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+    }
 
-  if (progress->offscreen_pixmap)
+  if (priv->offscreen_pixmap)
     {
-      gtk_draw_shadow (widget->style,
-                      progress->offscreen_pixmap,
-                      GTK_STATE_NORMAL, GTK_SHADOW_IN, 0, 0,
-                      widget->allocation.width,
-                      widget->allocation.height);
-         
-      gdk_draw_rectangle (progress->offscreen_pixmap,
-                         widget->style->bg_gc[GTK_STATE_ACTIVE], TRUE,
-                         widget->style->klass->xthickness,
-                         widget->style->klass->ythickness,
-                         widget->allocation.width -
-                         widget->style->klass->xthickness * 2,
-                         widget->allocation.height -
-                         widget->style->klass->ythickness * 2);
-
-      if (progress->activity_mode)
-       {
-         if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-             pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-           {
-             size = MAX (2, widget->allocation.width / pbar->activity_blocks);
-
-             gdk_draw_rectangle (progress->offscreen_pixmap,
-                                 widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                 TRUE,
-                                 pbar->activity_pos,
-                                 widget->style->klass->ythickness,
-                                 size,
-                                 widget->allocation.height - 
-                                 widget->style->klass->ythickness * 2);
-             
-             gtk_draw_shadow (widget->style,
-                              progress->offscreen_pixmap,
-                              GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                              pbar->activity_pos,
-                              widget->style->klass->ythickness,
-                              size,
-                              widget->allocation.height -
-                              widget->style->klass->ythickness * 2);
-             return;
-           }
-         else
-           {
-             size = MAX (2, widget->allocation.height / pbar->activity_blocks);
-
-             gdk_draw_rectangle (progress->offscreen_pixmap,
-                                 widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                 TRUE,
-                                 widget->style->klass->xthickness,
-                                 pbar->activity_pos,
-                                 widget->allocation.width - 
-                                 widget->style->klass->xthickness * 2,
-                                 size);
-             
-             gtk_draw_shadow (widget->style,
-                              progress->offscreen_pixmap,
-                              GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                              widget->style->klass->xthickness,
-                              pbar->activity_pos,
-                              widget->allocation.width -
-                              widget->style->klass->xthickness * 2,
-                              size);
-             return;
-           }
-       }
-
-      amount = percentage * space;
-      
-      if (amount > 0)
-       {
-         switch (pbar->orientation)
-           {
-             
-           case GTK_PROGRESS_LEFT_TO_RIGHT:
-             
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gdk_draw_rectangle (progress->offscreen_pixmap,
-                                     widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                     TRUE,
-                                     widget->style->klass->xthickness,
-                                     widget->style->klass->ythickness,
-                                     amount,
-                                     widget->allocation.height - 
-                                     widget->style->klass->ythickness * 2);
-                 gtk_draw_shadow (widget->style,
-                                  progress->offscreen_pixmap,
-                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                  widget->style->klass->xthickness,
-                                  widget->style->klass->ythickness,
-                                  amount,
-                                  widget->allocation.height -
-                                  widget->style->klass->ythickness * 2);
-               }
-             else
-               {
-                 x = widget->style->klass->xthickness;
-                 
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks)
-                       - ((i * space) / pbar->blocks);
-                     
-                     gdk_draw_rectangle 
-                       (progress->offscreen_pixmap,
-                        widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                        TRUE,
-                        x,
-                        widget->style->klass->ythickness,
-                        block_delta,
-                        widget->allocation.height - 
-                        widget->style->klass->ythickness * 2);
-
-                     gtk_draw_shadow (widget->style,
-                                      progress->offscreen_pixmap,
-                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                      x,
-                                      widget->style->klass->ythickness,
-                                      block_delta,
-                                      widget->allocation.height -
-                                      widget->style->klass->ythickness * 2);
-
-                     x +=  block_delta;
-                   }
-               }
-             break;
-
-           case GTK_PROGRESS_RIGHT_TO_LEFT:
-
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gdk_draw_rectangle (progress->offscreen_pixmap,
-                                     widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                     TRUE,
-                                     widget->allocation.width - 
-                                     widget->style->klass->xthickness - amount,
-                                     widget->style->klass->ythickness,
-                                     amount,
-                                     widget->allocation.height - 
-                                     widget->style->klass->ythickness * 2);
-                 gtk_draw_shadow (widget->style,
-                                  progress->offscreen_pixmap,
-                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                  widget->allocation.width - 
-                                  widget->style->klass->xthickness - amount,
-                                  widget->style->klass->ythickness,
-                                  amount,
-                                  widget->allocation.height -
-                                  widget->style->klass->ythickness * 2);
-               }
-             else
-               {
-                 x = widget->allocation.width - 
-                   widget->style->klass->xthickness;
-
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks) -
-                       ((i * space) / pbar->blocks);
-
-                     x -=  block_delta;
-
-                     gdk_draw_rectangle (progress->offscreen_pixmap,
-                                 widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                 TRUE,
-                                 x,
-                                 widget->style->klass->ythickness,
-                                 block_delta,
-                                 widget->allocation.height - 
-                                 widget->style->klass->ythickness * 2);
-
-                     gtk_draw_shadow (widget->style,
-                                      progress->offscreen_pixmap,
-                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                      x,
-                                      widget->style->klass->ythickness,
-                                      block_delta,
-                                      widget->allocation.height -
-                                      widget->style->klass->ythickness * 2);
-                   }
-               }
-             break;
-
-           case GTK_PROGRESS_BOTTOM_TO_TOP:
-
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gdk_draw_rectangle (progress->offscreen_pixmap,
-                                     widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                     TRUE,
-                                     widget->style->klass->xthickness,
-                                     widget->allocation.height - 
-                                     widget->style->klass->ythickness - amount,
-                                     widget->allocation.width - 
-                                     widget->style->klass->xthickness * 2,
-                                     amount);
-                 gtk_draw_shadow (widget->style,
-                                  progress->offscreen_pixmap,
-                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                  widget->style->klass->xthickness,
-                                  widget->allocation.height - 
-                                  widget->style->klass->ythickness - amount,
-                                  widget->allocation.width -
-                                  widget->style->klass->xthickness * 2,
-                                  amount);
-               }
-             else
-               {
-                 y = widget->allocation.height - 
-                   widget->style->klass->ythickness;
-
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks) -
-                       ((i * space) / pbar->blocks);
-                     
-                     y -= block_delta;
-
-                     gdk_draw_rectangle 
-                       (progress->offscreen_pixmap,
-                        widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                        TRUE,
-                        widget->style->klass->xthickness,
-                        y,
-                        widget->allocation.width - 
-                        widget->style->klass->xthickness * 2,
-                        block_delta);
-
-                     gtk_draw_shadow (widget->style,
-                                      progress->offscreen_pixmap,
-                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                      widget->style->klass->xthickness,
-                                      y,
-                                      widget->allocation.width - 
-                                      widget->style->klass->xthickness * 2,
-                                      block_delta);
-                   }
-               }
-             break;
-
-           case GTK_PROGRESS_TOP_TO_BOTTOM:
-
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gdk_draw_rectangle (progress->offscreen_pixmap,
-                                     widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                                     TRUE,
-                                     widget->style->klass->xthickness,
-                                     widget->style->klass->ythickness,
-                                     widget->allocation.width -
-                                     widget->style->klass->xthickness * 2,
-                                     amount);
-                 gtk_draw_shadow (widget->style,
-                                  progress->offscreen_pixmap,
-                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                  widget->style->klass->xthickness,
-                                  widget->style->klass->ythickness,
-                                  widget->allocation.width -
-                                  widget->style->klass->xthickness * 2,
-                                  amount);
-               }
-             else
-               {
-                 y = widget->style->klass->ythickness;
-
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-
-                     block_delta = (((i + 1) * space) / pbar->blocks)
-                       - ((i * space) / pbar->blocks);
-
-                     gdk_draw_rectangle
-                       (progress->offscreen_pixmap,
-                        widget->style->bg_gc[GTK_STATE_PRELIGHT],
-                        TRUE,
-                        widget->style->klass->xthickness,
-                        y,
-                        widget->allocation.width -
-                        widget->style->klass->xthickness * 2,
-                        block_delta);
-
-                     gtk_draw_shadow (widget->style,
-                                      progress->offscreen_pixmap,
-                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                      widget->style->klass->xthickness,
-                                      y,
-                                      widget->allocation.width -
-                                      widget->style->klass->xthickness * 2,
-                                      block_delta);
-
-                     y += block_delta;
-                   }
-               }
-             break;
-
-           default:
-             break;
-           }
-       }
-
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {
-         gint x;
-         gint y;
-         gchar *buf;
-         GdkRectangle rect;
-
-         buf = gtk_progress_get_current_text (progress);
-
-         x = widget->style->klass->xthickness + 1 + 
-           (widget->allocation.width - 2 * widget->style->klass->xthickness -
-            3 - gdk_text_width (widget->style->font, buf, strlen (buf)))
-           * progress->x_align; 
-
-         y = widget->style->font->ascent + 1 +
-           (widget->allocation.height - 2 * widget->style->klass->ythickness -
-            3 - gdk_text_height (widget->style->font, buf, strlen (buf)))
-           * progress->y_align;
-
-         rect.x = widget->style->klass->xthickness + 1;
-         rect.y = widget->style->klass->ythickness + 1;
-         rect.width = widget->allocation.width -
-           2 * widget->style->klass->xthickness - 3;
-         rect.height = widget->allocation.height -
-           2 * widget->style->klass->ythickness - 3;
-
-         gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
-                                    &rect);
-
-         gdk_draw_text (progress->offscreen_pixmap, widget->style->font,
-                        widget->style->fg_gc[widget->state],
-                        x, y, buf, strlen (buf));
-
-         gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
-                                    NULL);
-         g_free (buf);
-       }
+      gtk_paint_box (widget->style,
+                     priv->offscreen_pixmap,
+                     GTK_STATE_NORMAL, GTK_SHADOW_IN,
+                     NULL, widget, "trough",
+                     0, 0,
+                     widget->allocation.width,
+                     widget->allocation.height);
+
+      if (priv->activity_mode)
+        {
+          gtk_progress_bar_paint_activity (pbar, orientation);
+
+          if (priv->show_text)
+            {
+              gint offset;
+              gint amount;
+
+              gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
+              gtk_progress_bar_paint_text (pbar, offset, amount, orientation);
+            }
+        }
+      else
+        {
+          gint amount;
+          gint space;
+
+          if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
+              orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+            space = widget->allocation.width - 2 * widget->style->xthickness;
+          else
+            space = widget->allocation.height - 2 * widget->style->ythickness;
+
+          amount = space * gtk_progress_bar_get_fraction (pbar);
+
+          gtk_progress_bar_paint_continuous (pbar, amount, orientation);
+
+          if (priv->show_text)
+            gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
+        }
+
+      priv->dirty = FALSE;
     }
 }
 
-/*******************************************************************/
+static void
+gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar,
+                                    gboolean        activity_mode)
+{
+  GtkProgressBarPriv *priv = pbar->priv;
+
+  activity_mode = !!activity_mode;
+
+  if (priv->activity_mode != activity_mode)
+    {
+      priv->activity_mode = activity_mode;
+
+      if (priv->activity_mode)
+        GTK_PROGRESS_BAR_GET_CLASS (pbar)->act_mode_enter (pbar);
 
+      if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
+        gtk_widget_queue_resize (GTK_WIDGET (pbar));
+    }
+}
+
+/**
+ * gtk_progress_bar_set_fraction:
+ * @pbar: a #GtkProgressBar
+ * @fraction: fraction of the task that's been completed
+ *
+ * Causes the progress bar to "fill in" the given fraction
+ * of the bar. The fraction should be between 0.0 and 1.0,
+ * inclusive.
+ *
+ **/
 void
-gtk_progress_bar_update (GtkProgressBar *pbar,
-                        gfloat          percentage)
+gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
+                               gdouble         fraction)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv* priv;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  /***********************************************************************
-   *                 Use of this function is deprecated !               * 
-   * Use gtk_progress_set_value or gtk_progress_set_percentage instead.  *
-   ***********************************************************************/
+  priv = pbar->priv;
 
-  gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
+  priv->fraction = fraction;
+  gtk_progress_bar_set_activity_mode (pbar, FALSE);
+  gtk_progress_bar_real_update (pbar);
+
+  g_object_notify (G_OBJECT (pbar), "fraction");
 }
 
+/**
+ * gtk_progress_bar_pulse:
+ * @pbar: a #GtkProgressBar
+ *
+ * Indicates that some progress is made, but you don't know how much.
+ * Causes the progress bar to enter "activity mode," where a block
+ * bounces back and forth. Each call to gtk_progress_bar_pulse()
+ * causes the block to move by a little bit (the amount of movement
+ * per pulse is determined by gtk_progress_bar_set_pulse_step()).
+ **/
 void
-gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
-                                 GtkProgressBarOrientation orientation)
+gtk_progress_bar_pulse (GtkProgressBar *pbar)
 {
-  g_return_if_fail (pbar != NULL);
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (pbar->orientation != orientation)
-    {
-      pbar->orientation = orientation;
+  gtk_progress_bar_set_activity_mode (pbar, TRUE);
+  gtk_progress_bar_real_update (pbar);
+}
 
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
-       gtk_widget_queue_resize (GTK_WIDGET (pbar));
-    }
+/**
+ * gtk_progress_bar_set_text:
+ * @pbar: a #GtkProgressBar
+ * @text: (allow-none): a UTF-8 string, or %NULL
+ *
+ * Causes the given @text to appear superimposed on the progress bar.
+ **/
+void
+gtk_progress_bar_set_text (GtkProgressBar *pbar,
+                           const gchar    *text)
+{
+  GtkProgressBarPriv *priv;
+
+  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
+
+  priv = pbar->priv;
+
+  g_free (priv->text);
+  priv->text = text && *text ? g_strdup (text) : NULL;
+
+  if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
+    gtk_widget_queue_resize (GTK_WIDGET (pbar));
+
+  g_object_notify (G_OBJECT (pbar), "text");
 }
 
+/**
+ * gtk_progress_bar_set_show_text:
+ * @pbar: a #GtkProgressBar
+ * @show_text: whether to show superimposed text
+ *
+ * Sets whether the progressbar will show text superimposed
+ * over the bar. The shown text is either the value of
+ * the #GtkProgressBar::text property or, if that is %NULL,
+ * the #GtkProgressBar::fraction value, as a percentage.
+ *
+ * Since: 3.0
+ */
 void
-gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
-                               GtkProgressBarStyle bar_style)
+gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
+                                gboolean        show_text)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv *priv;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (pbar->bar_style != bar_style)
+  priv = pbar->priv;
+
+  show_text = !!show_text;
+
+  if (priv->show_text != show_text)
     {
-      pbar->bar_style = bar_style;
+      priv->show_text = show_text;
+
+      if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
+        gtk_widget_queue_resize (GTK_WIDGET (pbar));
 
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
-       gtk_widget_queue_resize (GTK_WIDGET (pbar));
+      g_object_notify (G_OBJECT (pbar), "show-text");
     }
 }
 
+/**
+ * gtk_progress_bar_get_show_text:
+ * @pbar: a #GtkProgressBar
+ *
+ * Gets the value of the #GtkProgressBar::show-text property.
+ * See gtk_progress_bar_set_show_text().
+ *
+ * Returns: %TRUE if text is shown in the progress bar
+ *
+ * Since: 3.0
+ */
+gboolean
+gtk_progress_bar_get_show_text (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
+
+  return pbar->priv->show_text;
+}
+
+/**
+ * gtk_progress_bar_set_pulse_step:
+ * @pbar: a #GtkProgressBar
+ * @fraction: fraction between 0.0 and 1.0
+ *
+ * Sets the fraction of total progress bar length to move the
+ * bouncing block for each call to gtk_progress_bar_pulse().
+ **/
 void
-gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
-                                     guint           blocks)
+gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
+                                 gdouble         fraction)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv *priv;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
-  g_return_if_fail (blocks > 1);
 
-  if (pbar->blocks != blocks)
-    {
-      pbar->blocks = blocks;
+  priv = pbar->priv;
 
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
-       gtk_widget_queue_resize (GTK_WIDGET (pbar));
-    }
+  priv->pulse_fraction = fraction;
+
+  g_object_notify (G_OBJECT (pbar), "pulse-step");
 }
 
+/**
+ * gtk_progress_bar_set_orientation:
+ * @pbar: a #GtkProgressBar
+ * @orientation: orientation of the progress bar
+ *
+ * Causes the progress bar to switch to a different orientation
+ * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
+ **/
 void
-gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
-                                    guint           step)
+gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
+                                  GtkProgressBarOrientation orientation)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv *priv;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (pbar->activity_step != step)
-    pbar->activity_step = step;
+  priv = pbar->priv;
+
+  if (priv->orientation != orientation)
+    {
+      priv->orientation = orientation;
+
+      if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
+        gtk_widget_queue_resize (GTK_WIDGET (pbar));
+
+      g_object_notify (G_OBJECT (pbar), "orientation");
+    }
+}
+
+/**
+ * gtk_progress_bar_get_text:
+ * @pbar: a #GtkProgressBar
+ *
+ * Retrieves the text displayed superimposed on the progress bar,
+ * if any, otherwise %NULL. The return value is a reference
+ * to the text, not a copy of it, so will become invalid
+ * if you change the text in the progress bar.
+ *
+ * Return value: text, or %NULL; this string is owned by the widget
+ * and should not be modified or freed.
+ **/
+G_CONST_RETURN gchar*
+gtk_progress_bar_get_text (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
+
+  return pbar->priv->text;
+}
+
+/**
+ * gtk_progress_bar_get_fraction:
+ * @pbar: a #GtkProgressBar
+ *
+ * Returns the current fraction of the task that's been completed.
+ *
+ * Return value: a fraction from 0.0 to 1.0
+ **/
+gdouble
+gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
+
+  return pbar->priv->fraction;
+}
+
+/**
+ * gtk_progress_bar_get_pulse_step:
+ * @pbar: a #GtkProgressBar
+ *
+ * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
+ *
+ * Return value: a fraction from 0.0 to 1.0
+ **/
+gdouble
+gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
+
+  return pbar->priv->pulse_fraction;
+}
+
+/**
+ * gtk_progress_bar_get_orientation:
+ * @pbar: a #GtkProgressBar
+ *
+ * Retrieves the current progress bar orientation.
+ *
+ * Return value: orientation of the progress bar
+ **/
+GtkProgressBarOrientation
+gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
+
+  return pbar->priv->orientation;
 }
 
+/**
+ * gtk_progress_bar_set_ellipsize:
+ * @pbar: a #GtkProgressBar
+ * @mode: a #PangoEllipsizeMode
+ *
+ * Sets the mode used to ellipsize (add an ellipsis: "...") the text
+ * if there is not enough space to render the entire string.
+ *
+ * Since: 2.6
+ **/
 void
-gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
-                                     guint           blocks)
+gtk_progress_bar_set_ellipsize (GtkProgressBar     *pbar,
+                                PangoEllipsizeMode  mode)
 {
-  g_return_if_fail (pbar != NULL);
+  GtkProgressBarPriv *priv;
+
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
-  g_return_if_fail (blocks > 1);
+  g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
+                    mode <= PANGO_ELLIPSIZE_END);
+
+  priv = pbar->priv;
+
+  if ((PangoEllipsizeMode)priv->ellipsize != mode)
+    {
+      priv->ellipsize = mode;
+
+      g_object_notify (G_OBJECT (pbar), "ellipsize");
+      gtk_widget_queue_resize (GTK_WIDGET (pbar));
+    }
+}
+
+/**
+ * gtk_progress_bar_get_ellipsize:
+ * @pbar: a #GtkProgressBar
+ *
+ * Returns the ellipsizing position of the progressbar.
+ * See gtk_progress_bar_set_ellipsize().
+ *
+ * Return value: #PangoEllipsizeMode
+ *
+ * Since: 2.6
+ **/
+PangoEllipsizeMode
+gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
+{
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
 
-  if (pbar->activity_blocks != blocks)
-    pbar->activity_blocks = blocks;
+  return pbar->priv->ellipsize;
 }