]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprogressbar.c
Fix a doc comment
[~andy/gtk] / gtk / gtkprogressbar.c
index d29ae67fe3b520fa14b2ae22b09ad845670afb64..96b316748a53f31603770acf0734cf121a5befe0 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#if HAVE_CONFIG_H
-#  include <config.h>
-#  if STDC_HEADERS
-#    include <string.h>
-#    include <stdio.h>
-#  endif
-#else
-#  include <stdio.h>
-#endif
+#include "config.h"
+
+#include <string.h>
+
+#undef GTK_DISABLE_DEPRECATED
+#define __GTK_PROGRESS_BAR_C__
 
 #include "gtkprogressbar.h"
 #include "gtkprivate.h"
@@ -44,8 +41,6 @@
 #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
 
 enum {
   PROP_0,
@@ -65,8 +60,6 @@ enum {
   PROP_DISCRETE_BLOCKS
 };
 
-static void gtk_progress_bar_class_init    (GtkProgressBarClass *klass);
-static void gtk_progress_bar_init          (GtkProgressBar      *pbar);
 static void gtk_progress_bar_set_property  (GObject             *object,
                                            guint                prop_id,
                                            const GValue        *value,
@@ -75,8 +68,12 @@ 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_style_set     (GtkWidget           *widget,
+                                           GtkStyle            *previous);
 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);
@@ -91,33 +88,7 @@ static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
                                                           guint           blocks);
 
 
-GType
-gtk_progress_bar_get_type (void)
-{
-  static GType progress_bar_type = 0;
-
-  if (!progress_bar_type)
-    {
-      static const GTypeInfo progress_bar_info =
-      {
-       sizeof (GtkProgressBarClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_progress_bar_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkProgressBar),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_progress_bar_init,
-      };
-
-      progress_bar_type =
-       g_type_register_static (GTK_TYPE_PROGRESS, I_("GtkProgressBar"),
-                               &progress_bar_info, 0);
-    }
-
-  return progress_bar_type;
-}
+G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_PROGRESS)
 
 static void
 gtk_progress_bar_class_init (GtkProgressBarClass *class)
@@ -133,7 +104,9 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
   gobject_class->set_property = gtk_progress_bar_set_property;
   gobject_class->get_property = gtk_progress_bar_get_property;
   
+  widget_class->expose_event = gtk_progress_bar_expose;
   widget_class->size_request = gtk_progress_bar_size_request;
+  widget_class->style_set = gtk_progress_bar_style_set;
 
   progress_class->paint = gtk_progress_bar_paint;
   progress_class->update = gtk_progress_bar_real_update;
@@ -170,9 +143,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                    g_param_spec_uint ("activity-step",
                                                      P_("Activity Step"),
                                                      P_("The increment used for each iteration in activity mode (Deprecated)"),
-                                                     -G_MAXUINT,
-                                                     G_MAXUINT,
-                                                     3,
+                                                     0, G_MAXUINT, 3,
                                                      GTK_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class,
@@ -180,9 +151,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                    g_param_spec_uint ("activity-blocks",
                                                      P_("Activity Blocks"),
                                                      P_("The number of blocks which can fit in the progress bar area in activity mode (Deprecated)"),
-                                                     2,
-                                                     G_MAXUINT,
-                                                     5,
+                                                     2, G_MAXUINT, 5,
                                                      GTK_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class,
@@ -190,9 +159,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                    g_param_spec_uint ("discrete-blocks",
                                                      P_("Discrete Blocks"),
                                                      P_("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
-                                                     2,
-                                                     G_MAXUINT,
-                                                     10,
+                                                     2, G_MAXUINT, 10,
                                                      GTK_PARAM_READWRITE));
   
   g_object_class_install_property (gobject_class,
@@ -200,9 +167,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                   g_param_spec_double ("fraction",
                                                        P_("Fraction"),
                                                        P_("The fraction of total work that has been completed"),
-                                                       0.0,
-                                                       1.0,
-                                                       0.0,
+                                                       0.0, 1.0, 0.0,
                                                        GTK_PARAM_READWRITE));  
   
   g_object_class_install_property (gobject_class,
@@ -210,9 +175,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                   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,
+                                                       0.0, 1.0, 0.1,
                                                        GTK_PARAM_READWRITE));  
   
   g_object_class_install_property (gobject_class,
@@ -220,7 +183,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                   g_param_spec_string ("text",
                                                        P_("Text"),
                                                        P_("Text to be displayed in the progress bar"),
-                                                       "%P %%",
+                                                       NULL,
                                                        GTK_PARAM_READWRITE));
 
   /**
@@ -241,11 +204,76 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                   PROP_ELLIPSIZE,
                                    g_param_spec_enum ("ellipsize",
                                                       P_("Ellipsize"),
-                                                      P_("The preferred place to ellipsize the string, if the progressbar does not have enough room to display the entire string, if at all"),
+                                                      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));
 }
 
 static void
@@ -365,7 +393,7 @@ gtk_progress_bar_new (void)
 {
   GtkWidget *pbar;
 
-  pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL);
+  pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
 
   return pbar;
 }
@@ -377,7 +405,7 @@ gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
 
   g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
 
-  pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR,
+  pbar = g_object_new (GTK_TYPE_PROGRESS_BAR,
                         "adjustment", adjustment,
                         NULL);
 
@@ -466,7 +494,7 @@ gtk_progress_bar_real_update (GtkProgress *progress)
                }
            }
        }
-      gtk_progress_bar_paint (progress);
+      pbar->dirty = TRUE;
       gtk_widget_queue_draw (GTK_WIDGET (progress));
     }
   else
@@ -479,12 +507,28 @@ gtk_progress_bar_real_update (GtkProgress *progress)
       if (pbar->in_block != in_block)
        {
          pbar->in_block = in_block;
-         gtk_progress_bar_paint (progress);
+         pbar->dirty = TRUE;
          gtk_widget_queue_draw (GTK_WIDGET (progress));
        }
     }
 }
 
+static gboolean
+gtk_progress_bar_expose (GtkWidget      *widget,
+                    GdkEventExpose *event)
+{
+  GtkProgressBar *pbar;
+
+  g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
+
+  pbar = GTK_PROGRESS_BAR (widget);
+
+  if (GTK_WIDGET_DRAWABLE (widget) && pbar->dirty)
+    gtk_progress_bar_paint (GTK_PROGRESS (pbar));
+
+  return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
+}
+
 static void
 gtk_progress_bar_size_request (GtkWidget      *widget,
                               GtkRequisition *requisition)
@@ -495,15 +539,22 @@ gtk_progress_bar_size_request (GtkWidget      *widget,
   PangoRectangle logical_rect;
   PangoLayout *layout;
   gint width, height;
+  gint xspacing, yspacing;
+  gint min_width, min_height;
 
   g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
   g_return_if_fail (requisition != NULL);
 
+  gtk_widget_style_get (widget,
+                        "xspacing", &xspacing,
+                        "yspacing", &yspacing,
+                        NULL);
+
   progress = GTK_PROGRESS (widget);
   pbar = GTK_PROGRESS_BAR (widget);
 
-  width = 2 * widget->style->xthickness + 3 + 2 * TEXT_SPACING;
-  height = 2 * widget->style->ythickness + 3 + 2 * TEXT_SPACING;
+  width = 2 * widget->style->xthickness + xspacing;
+  height = 2 * widget->style->ythickness + yspacing;
 
   if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
     {
@@ -542,31 +593,29 @@ gtk_progress_bar_size_request (GtkWidget      *widget,
   
   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-    {
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {
-         requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH, width);
-         requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT, height);
-       }
-      else
-       {
-         requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
-         requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
-       }
-    }
+    gtk_widget_style_get (widget,
+                         "min-horizontal-bar-width", &min_width,
+                         "min-horizontal-bar-height", &min_height,
+                         NULL);
   else
-    {
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {         
-         requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH, width);
-         requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT, height);
-       }
-      else
-       {
-         requisition->width = MIN_VERTICAL_BAR_WIDTH;
-         requisition->height = MIN_VERTICAL_BAR_HEIGHT;
-       }
-    }
+    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_style_set (GtkWidget      *widget,
+    GtkStyle *previous)
+{
+  GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
+
+  pbar->dirty = TRUE;
+
+  GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->style_set (widget, previous);
 }
 
 static void
@@ -623,30 +672,52 @@ gtk_progress_bar_act_mode_enter (GtkProgress *progress)
     }
 }
 
+static void
+gtk_progress_bar_get_activity (GtkProgressBar            *pbar,
+                              GtkProgressBarOrientation  orientation,
+                              gint                      *offset,
+                              gint                      *amount)
+{
+  GtkWidget *widget = GTK_WIDGET (pbar);
+
+  *offset = pbar->activity_pos;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      *amount = MAX (2, widget->allocation.width / pbar->activity_blocks);
+      break;
+
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      *amount = MAX (2, widget->allocation.height / pbar->activity_blocks);
+      break;
+    }
+}
+
 static void
 gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
                                 GtkProgressBarOrientation  orientation)
 {
   GtkWidget *widget = GTK_WIDGET (pbar);
   GtkProgress *progress = GTK_PROGRESS (pbar);
-  gint x, y, w, h;
+  GdkRectangle area;
 
   switch (orientation)
     {
     case GTK_PROGRESS_LEFT_TO_RIGHT:
     case GTK_PROGRESS_RIGHT_TO_LEFT:
-      x = pbar->activity_pos;
-      y = widget->style->ythickness;
-      w = MAX (2, widget->allocation.width / pbar->activity_blocks);
-      h = widget->allocation.height - 2 * widget->style->ythickness;
+      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:
-      x = widget->style->xthickness;
-      y = pbar->activity_pos;
-      w = widget->allocation.width - 2 * widget->style->xthickness;
-      h = MAX (2, widget->allocation.height / pbar->activity_blocks);
+      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:
@@ -657,8 +728,8 @@ gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
   gtk_paint_box (widget->style,
                 progress->offscreen_pixmap,
                 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                NULL, widget, "bar",
-                x, y, w, h);
+                &area, widget, "bar",
+                area.x, area.y, area.width, area.height);
 }
 
 static void
@@ -666,8 +737,8 @@ gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
                                   gint                       amount,
                                   GtkProgressBarOrientation  orientation)
 {
+  GdkRectangle area;
   GtkWidget *widget = GTK_WIDGET (pbar);
-  gint x, y, w, h;
 
   if (amount <= 0)
     return;
@@ -676,24 +747,24 @@ gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
     {
     case GTK_PROGRESS_LEFT_TO_RIGHT:
     case GTK_PROGRESS_RIGHT_TO_LEFT:
-      w = amount;
-      h = widget->allocation.height - widget->style->ythickness * 2;
-      y = widget->style->ythickness;
+      area.width = amount;
+      area.height = widget->allocation.height - widget->style->ythickness * 2;
+      area.y = widget->style->ythickness;
       
-      x = widget->style->xthickness;
+      area.x = widget->style->xthickness;
       if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-       x = widget->allocation.width - amount - x;
+       area.x = widget->allocation.width - amount - area.x;
       break;
       
     case GTK_PROGRESS_TOP_TO_BOTTOM:
     case GTK_PROGRESS_BOTTOM_TO_TOP:
-      w = widget->allocation.width - widget->style->xthickness * 2;
-      h = amount;
-      x = widget->style->xthickness;
+      area.width = widget->allocation.width - widget->style->xthickness * 2;
+      area.height = amount;
+      area.x = widget->style->xthickness;
       
-      y = widget->style->ythickness;
+      area.y = widget->style->ythickness;
       if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
-       y = widget->allocation.height - amount - y;
+       area.y = widget->allocation.height - amount - area.y;
       break;
       
     default:
@@ -704,8 +775,8 @@ gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
   gtk_paint_box (widget->style,
                 GTK_PROGRESS (pbar)->offscreen_pixmap,
                 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                NULL, widget, "bar",
-                x, y, w, h);
+                &area, widget, "bar",
+                area.x, area.y, area.width, area.height);
 }
 
 static void
@@ -717,7 +788,8 @@ gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
 
   for (i = 0; i <= pbar->in_block; i++)
     {
-      gint x, y, w, h, space;
+      GdkRectangle area;
+      gint space;
 
       switch (orientation)
        {
@@ -725,26 +797,26 @@ gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
        case GTK_PROGRESS_RIGHT_TO_LEFT:
          space = widget->allocation.width - 2 * widget->style->xthickness;
          
-         x = widget->style->xthickness + (i * space) / pbar->blocks;
-         y = widget->style->ythickness;
-         w = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - x;
-         h = widget->allocation.height - 2 * widget->style->ythickness;
+         area.x = widget->style->xthickness + (i * space) / pbar->blocks;
+         area.y = widget->style->ythickness;
+         area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
+         area.height = widget->allocation.height - 2 * widget->style->ythickness;
 
          if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-           x = widget->allocation.width - w - x;
+           area.x = widget->allocation.width - area.width - area.x;
          break;
          
        case GTK_PROGRESS_TOP_TO_BOTTOM:
        case GTK_PROGRESS_BOTTOM_TO_TOP:
          space = widget->allocation.height - 2 * widget->style->ythickness;
          
-         x = widget->style->xthickness;
-         y = widget->style->ythickness + (i * space) / pbar->blocks;
-         w = widget->allocation.width - 2 * widget->style->xthickness;
-         h = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - y;
+         area.x = widget->style->xthickness;
+         area.y = widget->style->ythickness + (i * space) / pbar->blocks;
+         area.width = widget->allocation.width - 2 * widget->style->xthickness;
+         area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
          
          if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
-           y = widget->allocation.height - h - y;
+           area.y = widget->allocation.height - area.height - area.y;
          break;
 
        default:
@@ -755,27 +827,32 @@ gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
       gtk_paint_box (widget->style,
                     GTK_PROGRESS (pbar)->offscreen_pixmap,
                     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                    NULL, widget, "bar",
-                    x, y, w, h);
+                    &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)
 {
   GtkProgress *progress = GTK_PROGRESS (pbar);
   GtkWidget *widget = GTK_WIDGET (pbar);
-  
   gint x;
   gint y;
   gchar *buf;
   GdkRectangle rect;
   PangoLayout *layout;
   PangoRectangle logical_rect;
-  GdkRectangle prelight_clip, normal_clip;
-  
+  GdkRectangle prelight_clip, start_clip, end_clip;
+  gfloat text_xalign = progress->x_align;
+  gfloat text_yalign = progress->y_align;
+
+  if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
+    text_xalign = 1.0 - text_xalign;
+
   buf = gtk_progress_get_current_text (progress);
   
   layout = gtk_widget_create_pango_layout (widget, buf);
@@ -785,50 +862,86 @@ gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
 
   pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
   
-  x = widget->style->xthickness + 1 +
-    (widget->allocation.width - 2 * widget->style->xthickness -
-     2 - logical_rect.width)
-    * progress->x_align; 
+  x = widget->style->xthickness + 1 + text_xalign *
+      (widget->allocation.width - 2 * widget->style->xthickness -
+       2 - logical_rect.width);
 
-  y = widget->style->ythickness + 1 +
-    (widget->allocation.height - 2 * widget->style->ythickness -
-     2 - logical_rect.height)
-    * progress->y_align;
+  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 = normal_clip = rect;
+  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;
-      normal_clip.x += amount;
-      normal_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:
-      normal_clip.width -= amount;
-      prelight_clip.x += normal_clip.width;
-      prelight_clip.width -= normal_clip.width;
+      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;
-      normal_clip.y += amount;
-      normal_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:
-      normal_clip.height -= amount;
-      prelight_clip.y += normal_clip.height;
-      prelight_clip.height -= normal_clip.height;
+      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,
+                     progress->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,
+                     progress->offscreen_pixmap,
+                     GTK_STATE_NORMAL,
+                     FALSE,
+                     &end_clip,
+                     widget,
+                     "progressbar",
+                     x, y,
+                     layout);
+
   gtk_paint_layout (widget->style,
                    progress->offscreen_pixmap,
                    GTK_STATE_PRELIGHT,
@@ -838,16 +951,6 @@ gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
                    "progressbar",
                    x, y,
                    layout);
-  
-  gtk_paint_layout (widget->style,
-                   progress->offscreen_pixmap,
-                   GTK_STATE_NORMAL,
-                   FALSE,
-                   &normal_clip,
-                   widget,
-                   "progressbar",
-                   x, y,
-                   layout);
 
   g_object_unref (layout);
   g_free (buf);
@@ -888,6 +991,15 @@ gtk_progress_bar_paint (GtkProgress *progress)
       if (progress->activity_mode)
        {
          gtk_progress_bar_paint_activity (pbar, orientation);
+
+         if (GTK_PROGRESS (pbar)->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
        {
@@ -908,11 +1020,13 @@ gtk_progress_bar_paint (GtkProgress *progress)
              gtk_progress_bar_paint_continuous (pbar, amount, orientation);
 
              if (GTK_PROGRESS (pbar)->show_text)
-               gtk_progress_bar_paint_text (pbar, amount, orientation);
+               gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
            }
          else
            gtk_progress_bar_paint_discrete (pbar, orientation);
        }
+
+      pbar->dirty = FALSE;
     }
 }
 
@@ -1033,7 +1147,7 @@ gtk_progress_bar_pulse (GtkProgressBar *pbar)
 /**
  * gtk_progress_bar_set_text:
  * @pbar: a #GtkProgressBar
- * @text: a UTF-8 string
+ * @text: a UTF-8 string, or %NULL 
  * 
  * Causes the given @text to appear superimposed on the progress bar.
  **/
@@ -1267,5 +1381,4 @@ gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
   return pbar->ellipsize;
 }
 
-#define __GTK_PROGRESS_BAR_C__
 #include "gtkaliasdef.c"