]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprogressbar.c
draw text twice, once with the prelight state and clipped to the progress
[~andy/gtk] / gtk / gtkprogressbar.c
index 6e0f8441f28b1e42419cb1b83d2499220f8e3b51..94aefc1049d243242023fcfb42aaa95f22fdbbbc 100644 (file)
@@ -35,7 +35,6 @@
 #endif
 
 #include "gtkprogressbar.h"
-#include "gtksignal.h"
 #include "gtkintl.h"
 
 
@@ -79,27 +78,39 @@ 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);
 
+static void gtk_progress_bar_set_bar_style_internal       (GtkProgressBar *pbar,
+                                                          GtkProgressBarStyle style);
+static void gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
+                                                          guint           blocks);
+static void gtk_progress_bar_set_activity_step_internal   (GtkProgressBar *pbar,
+                                                          guint           step);
+static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
+                                                          guint           blocks);
 
-GtkType
+
+GType
 gtk_progress_bar_get_type (void)
 {
-  static GtkType progress_bar_type = 0;
+  static GType progress_bar_type = 0;
 
   if (!progress_bar_type)
     {
-      static const GtkTypeInfo progress_bar_info =
+      static const GTypeInfo 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
+       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 = gtk_type_unique (GTK_TYPE_PROGRESS, &progress_bar_info);
+      progress_bar_type =
+       g_type_register_static (GTK_TYPE_PROGRESS, "GtkProgressBar",
+                               &progress_bar_info, 0);
     }
 
   return progress_bar_type;
@@ -137,7 +148,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                    PROP_ORIENTATION,
                                    g_param_spec_enum ("orientation",
                                                      _("Orientation"),
-                                                     _("Orientation and growth of the progress bar"),
+                                                     _("Orientation and growth direction of the progress bar"),
                                                      GTK_TYPE_PROGRESS_BAR_ORIENTATION,
                                                      GTK_PROGRESS_LEFT_TO_RIGHT,
                                                      G_PARAM_READWRITE));
@@ -175,7 +186,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
                                    PROP_DISCRETE_BLOCKS,
                                    g_param_spec_uint ("discrete_blocks",
                                                      _("Discrete Blocks"),
-                                                     _("The number of discrete blocks in a progress bar (when shown in the discrete style"),
+                                                     _("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
                                                      2,
                                                      G_MAXUINT,
                                                      10,
@@ -245,16 +256,16 @@ gtk_progress_bar_set_property (GObject      *object,
       gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
       break;
     case PROP_BAR_STYLE:
-      gtk_progress_bar_set_bar_style (pbar, g_value_get_enum (value));
+      gtk_progress_bar_set_bar_style_internal (pbar, g_value_get_enum (value));
       break;
     case PROP_ACTIVITY_STEP:
-      gtk_progress_bar_set_activity_step (pbar, g_value_get_uint (value));
+      gtk_progress_bar_set_activity_step_internal (pbar, g_value_get_uint (value));
       break;
     case PROP_ACTIVITY_BLOCKS:
-      gtk_progress_bar_set_activity_blocks (pbar, g_value_get_uint (value));
+      gtk_progress_bar_set_activity_blocks_internal (pbar, g_value_get_uint (value));
       break;
     case PROP_DISCRETE_BLOCKS:
-      gtk_progress_bar_set_discrete_blocks (pbar, g_value_get_uint (value));
+      gtk_progress_bar_set_discrete_blocks_internal (pbar, g_value_get_uint (value));
       break;
     case PROP_FRACTION:
       gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
@@ -284,7 +295,7 @@ gtk_progress_bar_get_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_ADJUSTMENT:
-      g_value_set_object (value, G_OBJECT (GTK_PROGRESS (pbar)->adjustment));
+      g_value_set_object (value, GTK_PROGRESS (pbar)->adjustment);
       break;
     case PROP_ORIENTATION:
       g_value_set_enum (value, pbar->orientation);
@@ -459,12 +470,15 @@ gtk_progress_bar_size_request (GtkWidget      *widget,
 
   if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
     {
+      if (!progress->adjustment)
+       gtk_progress_set_adjustment (progress, NULL);
+
       buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
 
       layout = gtk_widget_create_pango_layout (widget, buf);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
          
-      g_object_unref (G_OBJECT (layout));
+      g_object_unref (layout);
       g_free (buf);
     }
   
@@ -513,18 +527,28 @@ gtk_progress_bar_act_mode_enter (GtkProgress *progress)
   GtkProgressBar *pbar;
   GtkWidget *widget;
   gint size;
+  GtkProgressBarOrientation orientation;
 
   pbar = GTK_PROGRESS_BAR (progress);
   widget = GTK_WIDGET (progress);
 
+  orientation = pbar->orientation;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
+    {
+      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+       orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
+      else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+       orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+    }
+  
   /* calculate start pos */
 
-  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+  if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
+      orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
     {
       size = MAX (2, widget->allocation.width / pbar->activity_blocks);
 
-      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+      if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
        {
          pbar->activity_pos = widget->style->xthickness;
          pbar->activity_dir = 0;
@@ -541,7 +565,7 @@ gtk_progress_bar_act_mode_enter (GtkProgress *progress)
     {
       size = MAX (2, widget->allocation.height / pbar->activity_blocks);
 
-      if (pbar->orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
+      if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
        {
          pbar->activity_pos = widget->style->ythickness;
          pbar->activity_dir = 0;
@@ -557,34 +581,253 @@ gtk_progress_bar_act_mode_enter (GtkProgress *progress)
 }
 
 static void
-gtk_progress_bar_paint (GtkProgress *progress)
+gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
+                                GtkProgressBarOrientation  orientation)
 {
-  GtkProgressBar *pbar;
-  GtkWidget *widget;
-  gint amount;
-  gint block_delta = 0;
-  gint space = 0;
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  GtkProgress *progress = GTK_PROGRESS (pbar);
+  gint x, y, w, h;
+
+  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;
+      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);
+      break;
+
+    default:
+      return;
+      break;
+    }
+
+  gtk_paint_box (widget->style,
+                progress->offscreen_pixmap,
+                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
+                NULL, widget, "bar",
+                x, y, w, h);
+}
+
+static void
+gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
+                                  gint                       amount,
+                                  GtkProgressBarOrientation  orientation)
+{
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  gint x, y, w, h;
+
+  if (amount <= 0)
+    return;
+
+  switch (orientation)
+    {
+    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;
+      
+      x = widget->style->xthickness;
+      if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+       x = widget->allocation.width - amount - 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;
+      
+      y = widget->style->ythickness;
+      if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
+       y = widget->allocation.height - amount - y;
+      break;
+      
+    default:
+      return;
+      break;
+    }
+  
+  gtk_paint_box (widget->style,
+                GTK_PROGRESS (pbar)->offscreen_pixmap,
+                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
+                NULL, widget, "bar",
+                x, y, w, h);
+}
+
+static void
+gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
+                                GtkProgressBarOrientation  orientation)
+{
+  GtkWidget *widget = GTK_WIDGET (pbar);
   gint i;
+
+  for (i = 0; i <= pbar->in_block; i++)
+    {
+      gint x, y, w, h, space;
+
+      switch (orientation)
+       {
+       case GTK_PROGRESS_LEFT_TO_RIGHT:
+       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;
+
+         if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+           x = widget->allocation.width - w - 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;
+         
+         if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
+           y = widget->allocation.height - h - y;
+         break;
+
+       default:
+         return;
+         break;
+       }
+      
+      gtk_paint_box (widget->style,
+                    GTK_PROGRESS (pbar)->offscreen_pixmap,
+                    GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
+                    NULL, widget, "bar",
+                    x, y, w, h);
+    }
+}
+
+static void
+gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
+                            gint                       amount,
+                            GtkProgressBarOrientation  orientation)
+{
+  GtkProgress *progress = GTK_PROGRESS (pbar);
+  GtkWidget *widget = GTK_WIDGET (pbar);
+  
   gint x;
   gint y;
-  gdouble percentage;
-  gint size;
+  gchar *buf;
+  GdkRectangle rect;
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  GdkRectangle prelight_clip, normal_clip;
+  
+  buf = gtk_progress_get_current_text (progress);
+  
+  layout = gtk_widget_create_pango_layout (widget, buf);
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+  
+  x = widget->style->xthickness + 1 + 
+    (widget->allocation.width - 2 * widget->style->xthickness -
+     3 - logical_rect.width)
+    * progress->x_align; 
+
+  y = widget->style->ythickness + 1 +
+    (widget->allocation.height - 2 * widget->style->ythickness -
+     3 - logical_rect.height)
+    * progress->y_align;
+
+  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;
+
+  switch (orientation)
+    {
+    case GTK_PROGRESS_LEFT_TO_RIGHT:
+      prelight_clip.width = amount;
+      normal_clip.x += amount;
+      normal_clip.width -= amount;
+      break;
+      
+    case GTK_PROGRESS_RIGHT_TO_LEFT:
+      normal_clip.width -= amount;
+      prelight_clip.x += normal_clip.width;
+      prelight_clip.width -= normal_clip.width;
+      break;
+       
+    case GTK_PROGRESS_TOP_TO_BOTTOM:
+      prelight_clip.height = amount;
+      normal_clip.y += amount;
+      normal_clip.height -= amount;
+      break;
+      
+    case GTK_PROGRESS_BOTTOM_TO_TOP:
+      normal_clip.height -= amount;
+      prelight_clip.y += normal_clip.height;
+      prelight_clip.height -= normal_clip.height;
+      break;
+    }
+  
+  gtk_paint_layout (widget->style,
+                   progress->offscreen_pixmap,
+                   GTK_STATE_PRELIGHT,
+                   FALSE,
+                   &prelight_clip,
+                   widget,
+                   "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);
+}
+
+static void
+gtk_progress_bar_paint (GtkProgress *progress)
+{
+  GtkProgressBar *pbar;
+  GtkWidget *widget;
+
+  GtkProgressBarOrientation orientation;
 
   g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
 
   pbar = GTK_PROGRESS_BAR (progress);
   widget = GTK_WIDGET (progress);
 
-  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
-      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
-    space = widget->allocation.width -
-      2 * widget->style->xthickness;
-  else
-    space = widget->allocation.height -
-      2 * widget->style->ythickness;
-
-  percentage = gtk_progress_get_current_percentage (progress);
-
+  orientation = pbar->orientation;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
+    {
+      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
+       orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
+      else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
+       orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
+    }
   if (progress->offscreen_pixmap)
     {
       gtk_paint_box (widget->style,
@@ -597,248 +840,94 @@ gtk_progress_bar_paint (GtkProgress *progress)
       
       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);
-             
-             gtk_paint_box (widget->style,
-                            progress->offscreen_pixmap,
-                            GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                            NULL, widget, "bar",
-                            pbar->activity_pos,
-                            widget->style->ythickness,
-                            size,
-                            widget->allocation.height - widget->style->ythickness * 2);
-             return;
-           }
-         else
-           {
-             size = MAX (2, widget->allocation.height / pbar->activity_blocks);
-             
-             gtk_paint_box (widget->style,
-                            progress->offscreen_pixmap,
-                            GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                            NULL, widget, "bar",
-                            widget->style->xthickness,
-                            pbar->activity_pos,
-                            widget->allocation.width - widget->style->xthickness * 2,
-                            size);
-             return;
-           }
+         gtk_progress_bar_paint_activity (pbar, orientation);
        }
-      
-      amount = percentage * space;
-      
-      if (amount > 0)
+      else
        {
-         switch (pbar->orientation)
+         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_get_current_percentage (GTK_PROGRESS (pbar));
+         
+         if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
            {
-             
-           case GTK_PROGRESS_LEFT_TO_RIGHT:
-             
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gtk_paint_box (widget->style,
-                                progress->offscreen_pixmap,
-                                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                NULL, widget, "bar",
-                                widget->style->xthickness,
-                                widget->style->ythickness,
-                                amount,
-                                widget->allocation.height - widget->style->ythickness * 2);
-               }
-             else
-               {
-                 x = widget->style->xthickness;
-                 
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks)
-                       - ((i * space) / pbar->blocks);
-                     
-                     gtk_paint_box (widget->style,
-                                    progress->offscreen_pixmap,
-                                    GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                    NULL, widget, "bar",
-                                    x,
-                                    widget->style->ythickness,
-                                    block_delta,
-                                    widget->allocation.height - widget->style->ythickness * 2);
-                     
-                     x +=  block_delta;
-                   }
-               }
-             break;
-             
-           case GTK_PROGRESS_RIGHT_TO_LEFT:
-             
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gtk_paint_box (widget->style,
-                                progress->offscreen_pixmap,
-                                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                NULL, widget, "bar",
-                                widget->allocation.width - 
-                                widget->style->xthickness - amount,
-                                widget->style->ythickness,
-                                amount,
-                                widget->allocation.height -
-                                widget->style->ythickness * 2);
-               }
-             else
-               {
-                 x = widget->allocation.width - 
-                   widget->style->xthickness;
-                 
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks) -
-                       ((i * space) / pbar->blocks);
-                     
-                     x -=  block_delta;
-                     
-                     gtk_paint_box (widget->style,
-                                    progress->offscreen_pixmap,
-                                    GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                    NULL, widget, "bar",
-                                    x,
-                                    widget->style->ythickness,
-                                    block_delta,
-                                    widget->allocation.height -
-                                    widget->style->ythickness * 2);
-                   }
-               }
-             break;
-
-           case GTK_PROGRESS_BOTTOM_TO_TOP:
+             gtk_progress_bar_paint_continuous (pbar, amount, orientation);
 
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gtk_paint_box (widget->style,
-                                progress->offscreen_pixmap,
-                                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                NULL, widget, "bar",
-                                widget->style->xthickness,
-                                widget->allocation.height - 
-                                widget->style->ythickness - amount,
-                                widget->allocation.width -
-                                widget->style->xthickness * 2,
-                                amount);
-               }
-             else
-               {
-                 y = widget->allocation.height - 
-                   widget->style->ythickness;
-                 
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     block_delta = (((i + 1) * space) / pbar->blocks) -
-                       ((i * space) / pbar->blocks);
-                     
-                     y -= block_delta;
-                     
-                     gtk_paint_box (widget->style,
-                                    progress->offscreen_pixmap,
-                                    GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                    NULL, widget, "bar",
-                                    widget->style->xthickness,
-                                    y,
-                                    widget->allocation.width - 
-                                    widget->style->xthickness * 2,
-                                    block_delta);
-                   }
-               }
-             break;
-             
-           case GTK_PROGRESS_TOP_TO_BOTTOM:
-             
-             if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
-               {
-                 gtk_paint_box (widget->style,
-                                progress->offscreen_pixmap,
-                                GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                NULL, widget, "bar",
-                                widget->style->xthickness,
-                                widget->style->ythickness,
-                                widget->allocation.width -
-                                widget->style->xthickness * 2,
-                                amount);
-               }
-             else
-               {
-                 y = widget->style->ythickness;
-                 
-                 for (i = 0; i <= pbar->in_block; i++)
-                   {
-                     
-                     block_delta = (((i + 1) * space) / pbar->blocks)
-                       - ((i * space) / pbar->blocks);
-                     
-                     gtk_paint_box (widget->style,
-                                    progress->offscreen_pixmap,
-                                    GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
-                                    NULL, widget, "bar",
-                                    widget->style->xthickness,
-                                    y,
-                                    widget->allocation.width -
-                                    widget->style->xthickness * 2,
-                                    block_delta);
-                     
-                     y += block_delta;
-                   }
-               }
-             break;
-             
-           default:
-             break;
+             if (GTK_PROGRESS (pbar)->show_text)
+               gtk_progress_bar_paint_text (pbar, amount, orientation);
            }
+         else
+           gtk_progress_bar_paint_discrete (pbar, orientation);
        }
-      
-      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
-       {
-         gint x;
-         gint y;
-         gchar *buf;
-         GdkRectangle rect;
-         PangoLayout *layout;
-         PangoRectangle logical_rect;
+    }
+}
 
-         buf = gtk_progress_get_current_text (progress);
+static void
+gtk_progress_bar_set_bar_style_internal (GtkProgressBar     *pbar,
+                                        GtkProgressBarStyle bar_style)
+{
+  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-         layout = gtk_widget_create_pango_layout (widget, buf);
-         pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-         
-         x = widget->style->xthickness + 1 + 
-           (widget->allocation.width - 2 * widget->style->xthickness -
-            3 - logical_rect.width)
-           * progress->x_align; 
-
-         y = widget->style->ythickness + 1 +
-           (widget->allocation.height - 2 * widget->style->ythickness -
-            3 - logical_rect.height)
-           * progress->y_align;
-
-         rect.x = widget->style->xthickness + 1;
-         rect.y = widget->style->ythickness + 1;
-         rect.width = widget->allocation.width -
-           2 * widget->style->xthickness - 3;
-         rect.height = widget->allocation.height -
-           2 * widget->style->ythickness - 3;
-      
-          gtk_paint_layout (widget->style,
-                            progress->offscreen_pixmap,
-                            GTK_WIDGET_STATE (widget),
-                           FALSE,
-                            &rect,
-                            widget,
-                            "progressbar",
-                            x, y,
-                            layout);
-
-          g_object_unref (G_OBJECT (layout));
-         g_free (buf);
-       }
+  if (pbar->bar_style != bar_style)
+    {
+      pbar->bar_style = bar_style;
+
+      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
+       gtk_widget_queue_resize (GTK_WIDGET (pbar));
+
+      g_object_notify (G_OBJECT (pbar), "bar_style");
+    }
+}
+
+static void
+gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
+                                              guint           blocks)
+{
+  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
+  g_return_if_fail (blocks > 1);
+
+  if (pbar->blocks != blocks)
+    {
+      pbar->blocks = blocks;
+
+      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
+       gtk_widget_queue_resize (GTK_WIDGET (pbar));
+
+      g_object_notify (G_OBJECT (pbar), "discrete_blocks");
+    }
+}
+
+static void
+gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
+                                            guint           step)
+{
+  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
+
+  if (pbar->activity_step != step)
+    {
+      pbar->activity_step = step;
+      g_object_notify (G_OBJECT (pbar), "activity_step");
+    }
+}
+
+static void
+gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
+                                              guint           blocks)
+{
+  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
+  g_return_if_fail (blocks > 1);
+
+  if (pbar->activity_blocks != blocks)
+    {
+      pbar->activity_blocks = blocks;
+      g_object_notify (G_OBJECT (pbar), "activity_blocks");
     }
 }
 
@@ -907,20 +996,15 @@ gtk_progress_bar_set_text (GtkProgressBar *pbar,
 {
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
   
-  /* We don't support formats in this interface */
-  GTK_PROGRESS (pbar)->use_text_format = FALSE;
+  gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
+  gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
+  
+  /* We don't support formats in this interface, but turn
+   * them back on for NULL, which should put us back to
+   * the initial state.
+   */
+  GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
   
-  if (text && *text)
-    {
-      gtk_progress_set_show_text (GTK_PROGRESS (pbar), TRUE);
-      gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
-    }
-  else
-    {
-      gtk_progress_set_show_text (GTK_PROGRESS (pbar), FALSE);
-      gtk_progress_set_format_string (GTK_PROGRESS (pbar), "");
-    }
-
   g_object_notify (G_OBJECT (pbar), "text");
 }
 
@@ -990,7 +1074,8 @@ gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
  * 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; don't free the string
+ * 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)
@@ -1057,15 +1142,7 @@ gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
 {
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (pbar->bar_style != bar_style)
-    {
-      pbar->bar_style = bar_style;
-
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
-       gtk_widget_queue_resize (GTK_WIDGET (pbar));
-
-      g_object_notify (G_OBJECT (pbar), "bar_style");
-    }
+  gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
 }
 
 void
@@ -1075,15 +1152,7 @@ gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
   g_return_if_fail (blocks > 1);
 
-  if (pbar->blocks != blocks)
-    {
-      pbar->blocks = blocks;
-
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
-       gtk_widget_queue_resize (GTK_WIDGET (pbar));
-
-      g_object_notify (G_OBJECT (pbar), "discrete_blocks");
-    }
+  gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
 }
 
 void
@@ -1092,11 +1161,7 @@ gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
 {
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
 
-  if (pbar->activity_step != step)
-    {
-      pbar->activity_step = step;
-      g_object_notify (G_OBJECT (pbar), "activity_step");
-    }
+  gtk_progress_bar_set_activity_step_internal (pbar, step);
 }
 
 void
@@ -1106,9 +1171,5 @@ gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
   g_return_if_fail (blocks > 1);
 
-  if (pbar->activity_blocks != blocks)
-    {
-      pbar->activity_blocks = blocks;
-      g_object_notify (G_OBJECT (pbar), "activity_blocks");
-    }
+  gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);
 }