]> Pileus Git - ~andy/gtk/blob - gtk/gtkprogressbar.c
documented necessary changes for 1.4 transition.
[~andy/gtk] / gtk / gtkprogressbar.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #if HAVE_CONFIG_H
28 #  include <config.h>
29 #  if STDC_HEADERS
30 #    include <string.h>
31 #    include <stdio.h>
32 #  endif
33 #else
34 #  include <stdio.h>
35 #endif
36
37 #include "gtkprogressbar.h"
38 #include "gtksignal.h"
39
40
41 #define MIN_HORIZONTAL_BAR_WIDTH   150
42 #define MIN_HORIZONTAL_BAR_HEIGHT  20
43 #define MIN_VERTICAL_BAR_WIDTH     22
44 #define MIN_VERTICAL_BAR_HEIGHT    80
45 #define MAX_TEXT_LENGTH            80
46 #define TEXT_SPACING               2
47
48 enum {
49   ARG_0,
50   ARG_ADJUSTMENT,
51   ARG_ORIENTATION,
52   ARG_BAR_STYLE,
53   ARG_ACTIVITY_STEP,
54   ARG_ACTIVITY_BLOCKS,
55   ARG_DISCRETE_BLOCKS
56 };
57
58 static void gtk_progress_bar_class_init    (GtkProgressBarClass *klass);
59 static void gtk_progress_bar_init          (GtkProgressBar      *pbar);
60 static void gtk_progress_bar_set_arg       (GtkObject           *object,
61                                             GtkArg              *arg,
62                                             guint                arg_id);
63 static void gtk_progress_bar_get_arg       (GtkObject           *object,
64                                             GtkArg              *arg,
65                                             guint                arg_id);
66 static void gtk_progress_bar_size_request  (GtkWidget           *widget,
67                                             GtkRequisition      *requisition);
68 static void gtk_progress_bar_real_update   (GtkProgress         *progress);
69 static void gtk_progress_bar_paint         (GtkProgress         *progress);
70 static void gtk_progress_bar_act_mode_enter (GtkProgress        *progress);
71
72
73 GtkType
74 gtk_progress_bar_get_type (void)
75 {
76   static GtkType progress_bar_type = 0;
77
78   if (!progress_bar_type)
79     {
80       static const GtkTypeInfo progress_bar_info =
81       {
82         "GtkProgressBar",
83         sizeof (GtkProgressBar),
84         sizeof (GtkProgressBarClass),
85         (GtkClassInitFunc) gtk_progress_bar_class_init,
86         (GtkObjectInitFunc) gtk_progress_bar_init,
87         /* reserved_1 */ NULL,
88         /* reserved_2 */ NULL,
89         (GtkClassInitFunc) NULL
90       };
91
92       progress_bar_type = gtk_type_unique (GTK_TYPE_PROGRESS, &progress_bar_info);
93     }
94
95   return progress_bar_type;
96 }
97
98 static void
99 gtk_progress_bar_class_init (GtkProgressBarClass *class)
100 {
101   GtkObjectClass *object_class;
102   GtkWidgetClass *widget_class;
103   GtkProgressClass *progress_class;
104   
105   object_class = (GtkObjectClass *) class;
106   widget_class = (GtkWidgetClass *) class;
107   progress_class = (GtkProgressClass *) class;
108   
109   gtk_object_add_arg_type ("GtkProgressBar::adjustment",
110                            GTK_TYPE_ADJUSTMENT,
111                            GTK_ARG_READWRITE,
112                            ARG_ADJUSTMENT);
113   gtk_object_add_arg_type ("GtkProgressBar::orientation",
114                            GTK_TYPE_PROGRESS_BAR_ORIENTATION,
115                            GTK_ARG_READWRITE,
116                            ARG_ORIENTATION);
117   gtk_object_add_arg_type ("GtkProgressBar::bar_style",
118                            GTK_TYPE_PROGRESS_BAR_STYLE,
119                            GTK_ARG_READWRITE,
120                            ARG_BAR_STYLE);
121   gtk_object_add_arg_type ("GtkProgressBar::activity_step",
122                            GTK_TYPE_UINT,
123                            GTK_ARG_READWRITE,
124                            ARG_ACTIVITY_STEP);
125   gtk_object_add_arg_type ("GtkProgressBar::activity_blocks",
126                            GTK_TYPE_UINT,
127                            GTK_ARG_READWRITE,
128                            ARG_ACTIVITY_BLOCKS);
129   gtk_object_add_arg_type ("GtkProgressBar::discrete_blocks",
130                            GTK_TYPE_UINT,
131                            GTK_ARG_READWRITE,
132                            ARG_DISCRETE_BLOCKS);
133
134   object_class->set_arg = gtk_progress_bar_set_arg;
135   object_class->get_arg = gtk_progress_bar_get_arg;
136
137   widget_class->size_request = gtk_progress_bar_size_request;
138
139   progress_class->paint = gtk_progress_bar_paint;
140   progress_class->update = gtk_progress_bar_real_update;
141   progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
142 }
143
144 static void
145 gtk_progress_bar_init (GtkProgressBar *pbar)
146 {
147   pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
148   pbar->blocks = 10;
149   pbar->in_block = -1;
150   pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
151   pbar->activity_pos = 0;
152   pbar->activity_dir = 1;
153   pbar->activity_step = 3;
154   pbar->activity_blocks = 5;
155 }
156
157 static void
158 gtk_progress_bar_set_arg (GtkObject           *object,
159                           GtkArg              *arg,
160                           guint                arg_id)
161 {
162   GtkProgressBar *pbar;
163
164   pbar = GTK_PROGRESS_BAR (object);
165
166   switch (arg_id)
167     {
168     case ARG_ADJUSTMENT:
169       gtk_progress_set_adjustment (GTK_PROGRESS (pbar), GTK_VALUE_POINTER (*arg));
170       break;
171     case ARG_ORIENTATION:
172       gtk_progress_bar_set_orientation (pbar, GTK_VALUE_ENUM (*arg));
173       break;
174     case ARG_BAR_STYLE:
175       gtk_progress_bar_set_bar_style (pbar, GTK_VALUE_ENUM (*arg));
176       break;
177     case ARG_ACTIVITY_STEP:
178       gtk_progress_bar_set_activity_step (pbar, GTK_VALUE_UINT (*arg));
179       break;
180     case ARG_ACTIVITY_BLOCKS:
181       gtk_progress_bar_set_activity_blocks (pbar, GTK_VALUE_UINT (*arg));
182       break;
183     case ARG_DISCRETE_BLOCKS:
184       gtk_progress_bar_set_discrete_blocks (pbar, GTK_VALUE_UINT (*arg));
185       break;
186     default:
187       break;
188     }
189 }
190
191 static void
192 gtk_progress_bar_get_arg (GtkObject           *object,
193                           GtkArg              *arg,
194                           guint                arg_id)
195 {
196   GtkProgressBar *pbar;
197
198   pbar = GTK_PROGRESS_BAR (object);
199
200   switch (arg_id)
201     {
202     case ARG_ADJUSTMENT:
203       GTK_VALUE_POINTER (*arg) = GTK_PROGRESS (pbar)->adjustment;
204       break;
205     case ARG_ORIENTATION:
206       GTK_VALUE_ENUM (*arg) = pbar->orientation;
207       break;
208     case ARG_BAR_STYLE:
209       GTK_VALUE_ENUM (*arg) = pbar->bar_style;
210       break;
211     case ARG_ACTIVITY_STEP:
212       GTK_VALUE_UINT (*arg) = pbar->activity_step;
213       break;
214     case ARG_ACTIVITY_BLOCKS:
215       GTK_VALUE_UINT (*arg) = pbar->activity_blocks;
216       break;
217     case ARG_DISCRETE_BLOCKS:
218       GTK_VALUE_UINT (*arg) = pbar->blocks;
219       break;
220     default:
221       arg->type = GTK_TYPE_INVALID;
222       break;
223     }
224 }
225
226 GtkWidget*
227 gtk_progress_bar_new (void)
228 {
229   GtkWidget *pbar;
230
231   pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL);
232
233   return pbar;
234 }
235
236 GtkWidget*
237 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
238 {
239   GtkWidget *pbar;
240
241   g_return_val_if_fail (adjustment != NULL, NULL);
242   g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
243
244   pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR,
245                          "adjustment", adjustment,
246                          NULL);
247
248   return pbar;
249 }
250
251 static void
252 gtk_progress_bar_real_update (GtkProgress *progress)
253 {
254   GtkProgressBar *pbar;
255   GtkWidget *widget;
256
257   g_return_if_fail (progress != NULL);
258   g_return_if_fail (GTK_IS_PROGRESS (progress));
259
260   pbar = GTK_PROGRESS_BAR (progress);
261   widget = GTK_WIDGET (progress);
262  
263   if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
264       GTK_PROGRESS (pbar)->activity_mode)
265     {
266       if (GTK_PROGRESS (pbar)->activity_mode)
267         {
268           guint size;
269
270           /* advance the block */
271
272           if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
273               pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
274             {
275               size = MAX (2, widget->allocation.width / pbar->activity_blocks);
276
277               if (pbar->activity_dir == 0)
278                 {
279                   pbar->activity_pos += pbar->activity_step;
280                   if (pbar->activity_pos + size >=
281                       widget->allocation.width -
282                       widget->style->klass->xthickness)
283                     {
284                       pbar->activity_pos = widget->allocation.width -
285                         widget->style->klass->xthickness - size;
286                       pbar->activity_dir = 1;
287                     }
288                 }
289               else
290                 {
291                   pbar->activity_pos -= pbar->activity_step;
292                   if (pbar->activity_pos <= widget->style->klass->xthickness)
293                     {
294                       pbar->activity_pos = widget->style->klass->xthickness;
295                       pbar->activity_dir = 0;
296                     }
297                 }
298             }
299           else
300             {
301               size = MAX (2, widget->allocation.height / pbar->activity_blocks);
302
303               if (pbar->activity_dir == 0)
304                 {
305                   pbar->activity_pos += pbar->activity_step;
306                   if (pbar->activity_pos + size >=
307                       widget->allocation.height -
308                       widget->style->klass->ythickness)
309                     {
310                       pbar->activity_pos = widget->allocation.height -
311                         widget->style->klass->ythickness - size;
312                       pbar->activity_dir = 1;
313                     }
314                 }
315               else
316                 {
317                   pbar->activity_pos -= pbar->activity_step;
318                   if (pbar->activity_pos <= widget->style->klass->ythickness)
319                     {
320                       pbar->activity_pos = widget->style->klass->ythickness;
321                       pbar->activity_dir = 0;
322                     }
323                 }
324             }
325         }
326       gtk_progress_bar_paint (progress);
327       gtk_widget_queue_draw (GTK_WIDGET (progress));
328     }
329   else
330     {
331       gint in_block;
332       
333       in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
334                              (gfloat)pbar->blocks);
335       
336       if (pbar->in_block != in_block)
337         {
338           pbar->in_block = in_block;
339           gtk_progress_bar_paint (progress);
340           gtk_widget_queue_draw (GTK_WIDGET (progress));
341         }
342     }
343 }
344
345 static void
346 gtk_progress_bar_size_request (GtkWidget      *widget,
347                                GtkRequisition *requisition)
348 {
349   GtkProgress *progress;
350   GtkProgressBar *pbar;
351   gchar *buf;
352
353   g_return_if_fail (widget != NULL);
354   g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
355   g_return_if_fail (requisition != NULL);
356
357   progress = GTK_PROGRESS (widget);
358   pbar = GTK_PROGRESS_BAR (widget);
359
360   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
361       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
362     {
363       if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
364         {
365           buf = gtk_progress_get_text_from_value (progress,
366                                                   progress->adjustment->upper);
367
368           requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH,
369                                     2 * widget->style->klass->xthickness + 3 +
370                                     gdk_text_width (widget->style->font, 
371                                                     buf, strlen (buf)) +
372                                     2 * TEXT_SPACING);
373
374           requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
375                                      2 * widget->style->klass->ythickness + 3 +
376                                      gdk_text_height (widget->style->font, 
377                                                       buf, strlen (buf)) +
378                                      2 * TEXT_SPACING);
379           g_free (buf);
380         }
381       else
382         {
383           requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
384           requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
385         }
386     }
387   else
388     {
389       if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
390         {         
391           buf = gtk_progress_get_text_from_value (progress,
392                                                   progress->adjustment->upper);
393
394           requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH,
395                                     2 * widget->style->klass->xthickness + 3 +
396                                     gdk_text_width (widget->style->font, 
397                                                     buf, strlen (buf)) +
398                                     2 * TEXT_SPACING);
399
400           requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
401                                      2 * widget->style->klass->ythickness + 3 +
402                                      gdk_text_height (widget->style->font, 
403                                                       buf, strlen (buf)) +
404                                      2 * TEXT_SPACING);
405           g_free (buf);
406         }
407       else
408         {
409           requisition->width = MIN_VERTICAL_BAR_WIDTH;
410           requisition->height = MIN_VERTICAL_BAR_HEIGHT;
411         }
412     }
413 }
414
415 static void
416 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
417 {
418   GtkProgressBar *pbar;
419   GtkWidget *widget;
420   gint size;
421
422   pbar = GTK_PROGRESS_BAR (progress);
423   widget = GTK_WIDGET (progress);
424
425   /* calculate start pos */
426
427   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
428       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
429     {
430       size = MAX (2, widget->allocation.width / pbar->activity_blocks);
431
432       if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
433         {
434           pbar->activity_pos = widget->style->klass->xthickness;
435           pbar->activity_dir = 0;
436         }
437       else
438         {
439           pbar->activity_pos = widget->allocation.width - 
440             widget->style->klass->xthickness - (widget->allocation.height - 
441                 widget->style->klass->ythickness * 2);
442           pbar->activity_dir = 1;
443         }
444     }
445   else
446     {
447       size = MAX (2, widget->allocation.height / pbar->activity_blocks);
448
449       if (pbar->orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
450         {
451           pbar->activity_pos = widget->style->klass->ythickness;
452           pbar->activity_dir = 0;
453         }
454       else
455         {
456           pbar->activity_pos = widget->allocation.height -
457             widget->style->klass->ythickness - (widget->allocation.width - 
458                 widget->style->klass->xthickness * 2);
459           pbar->activity_dir = 1;
460         }
461     }
462 }
463
464 static void
465 gtk_progress_bar_paint (GtkProgress *progress)
466 {
467   GtkProgressBar *pbar;
468   GtkWidget *widget;
469   gint amount;
470   gint block_delta = 0;
471   gint space = 0;
472   gint i;
473   gint x;
474   gint y;
475   gfloat percentage;
476   gint size;
477
478   g_return_if_fail (progress != NULL);
479   g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
480
481   pbar = GTK_PROGRESS_BAR (progress);
482   widget = GTK_WIDGET (progress);
483
484   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
485       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
486     space = widget->allocation.width -
487       2 * widget->style->klass->xthickness;
488   else
489     space = widget->allocation.height -
490       2 * widget->style->klass->ythickness;
491
492   percentage = gtk_progress_get_current_percentage (progress);
493
494   if (progress->offscreen_pixmap)
495     {
496       gtk_paint_box (widget->style,
497                      progress->offscreen_pixmap,
498                      GTK_STATE_NORMAL, GTK_SHADOW_IN, 
499                      NULL, widget, "trough",
500                      0, 0,
501                      widget->allocation.width,
502                      widget->allocation.height);
503       
504       if (progress->activity_mode)
505         {
506           if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
507               pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
508             {
509               size = MAX (2, widget->allocation.width / pbar->activity_blocks);
510               
511               gtk_paint_box (widget->style,
512                              progress->offscreen_pixmap,
513                              GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
514                              NULL, widget, "bar",
515                              pbar->activity_pos,
516                              widget->style->klass->ythickness,
517                              size,
518                              widget->allocation.height - widget->style->klass->ythickness * 2);
519               return;
520             }
521           else
522             {
523               size = MAX (2, widget->allocation.height / pbar->activity_blocks);
524               
525               gtk_paint_box (widget->style,
526                              progress->offscreen_pixmap,
527                              GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
528                              NULL, widget, "bar",
529                              widget->style->klass->xthickness,
530                              pbar->activity_pos,
531                              widget->allocation.width - widget->style->klass->xthickness * 2,
532                              size);
533               return;
534             }
535         }
536       
537       amount = percentage * space;
538       
539       if (amount > 0)
540         {
541           switch (pbar->orientation)
542             {
543               
544             case GTK_PROGRESS_LEFT_TO_RIGHT:
545               
546               if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
547                 {
548                   gtk_paint_box (widget->style,
549                                  progress->offscreen_pixmap,
550                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
551                                  NULL, widget, "bar",
552                                  widget->style->klass->xthickness,
553                                  widget->style->klass->ythickness,
554                                  amount,
555                                  widget->allocation.height - widget->style->klass->ythickness * 2);
556                 }
557               else
558                 {
559                   x = widget->style->klass->xthickness;
560                   
561                   for (i = 0; i <= pbar->in_block; i++)
562                     {
563                       block_delta = (((i + 1) * space) / pbar->blocks)
564                         - ((i * space) / pbar->blocks);
565                       
566                       gtk_paint_box (widget->style,
567                                      progress->offscreen_pixmap,
568                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
569                                      NULL, widget, "bar",
570                                      x,
571                                      widget->style->klass->ythickness,
572                                      block_delta,
573                                      widget->allocation.height - widget->style->klass->ythickness * 2);
574                       
575                       x +=  block_delta;
576                     }
577                 }
578               break;
579               
580             case GTK_PROGRESS_RIGHT_TO_LEFT:
581               
582               if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
583                 {
584                   gtk_paint_box (widget->style,
585                                  progress->offscreen_pixmap,
586                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
587                                  NULL, widget, "bar",
588                                  widget->allocation.width - 
589                                  widget->style->klass->xthickness - amount,
590                                  widget->style->klass->ythickness,
591                                  amount,
592                                  widget->allocation.height -
593                                  widget->style->klass->ythickness * 2);
594                 }
595               else
596                 {
597                   x = widget->allocation.width - 
598                     widget->style->klass->xthickness;
599                   
600                   for (i = 0; i <= pbar->in_block; i++)
601                     {
602                       block_delta = (((i + 1) * space) / pbar->blocks) -
603                         ((i * space) / pbar->blocks);
604                       
605                       x -=  block_delta;
606                       
607                       gtk_paint_box (widget->style,
608                                      progress->offscreen_pixmap,
609                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
610                                      NULL, widget, "bar",
611                                      x,
612                                      widget->style->klass->ythickness,
613                                      block_delta,
614                                      widget->allocation.height -
615                                      widget->style->klass->ythickness * 2);
616                     }
617                 }
618               break;
619
620             case GTK_PROGRESS_BOTTOM_TO_TOP:
621
622               if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
623                 {
624                   gtk_paint_box (widget->style,
625                                  progress->offscreen_pixmap,
626                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
627                                  NULL, widget, "bar",
628                                  widget->style->klass->xthickness,
629                                  widget->allocation.height - 
630                                  widget->style->klass->ythickness - amount,
631                                  widget->allocation.width -
632                                  widget->style->klass->xthickness * 2,
633                                  amount);
634                 }
635               else
636                 {
637                   y = widget->allocation.height - 
638                     widget->style->klass->ythickness;
639                   
640                   for (i = 0; i <= pbar->in_block; i++)
641                     {
642                       block_delta = (((i + 1) * space) / pbar->blocks) -
643                         ((i * space) / pbar->blocks);
644                       
645                       y -= block_delta;
646                       
647                       gtk_paint_box (widget->style,
648                                      progress->offscreen_pixmap,
649                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
650                                      NULL, widget, "bar",
651                                      widget->style->klass->xthickness,
652                                      y,
653                                      widget->allocation.width - 
654                                      widget->style->klass->xthickness * 2,
655                                      block_delta);
656                     }
657                 }
658               break;
659               
660             case GTK_PROGRESS_TOP_TO_BOTTOM:
661               
662               if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
663                 {
664                   gtk_paint_box (widget->style,
665                                  progress->offscreen_pixmap,
666                                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
667                                  NULL, widget, "bar",
668                                  widget->style->klass->xthickness,
669                                  widget->style->klass->ythickness,
670                                  widget->allocation.width -
671                                  widget->style->klass->xthickness * 2,
672                                  amount);
673                 }
674               else
675                 {
676                   y = widget->style->klass->ythickness;
677                   
678                   for (i = 0; i <= pbar->in_block; i++)
679                     {
680                       
681                       block_delta = (((i + 1) * space) / pbar->blocks)
682                         - ((i * space) / pbar->blocks);
683                       
684                       gtk_paint_box (widget->style,
685                                      progress->offscreen_pixmap,
686                                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
687                                      NULL, widget, "bar",
688                                      widget->style->klass->xthickness,
689                                      y,
690                                      widget->allocation.width -
691                                      widget->style->klass->xthickness * 2,
692                                      block_delta);
693                       
694                       y += block_delta;
695                     }
696                 }
697               break;
698               
699             default:
700               break;
701             }
702         }
703       
704       if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
705         {
706           gint x;
707           gint y;
708           gchar *buf;
709           GdkRectangle rect;
710
711           buf = gtk_progress_get_current_text (progress);
712
713           x = widget->style->klass->xthickness + 1 + 
714             (widget->allocation.width - 2 * widget->style->klass->xthickness -
715              3 - gdk_text_width (widget->style->font, buf, strlen (buf)))
716             * progress->x_align; 
717
718           y = widget->style->font->ascent + 1 +
719             (widget->allocation.height - 2 * widget->style->klass->ythickness -
720              3 - gdk_text_height (widget->style->font, buf, strlen (buf)))
721             * progress->y_align;
722
723           rect.x = widget->style->klass->xthickness + 1;
724           rect.y = widget->style->klass->ythickness + 1;
725           rect.width = widget->allocation.width -
726             2 * widget->style->klass->xthickness - 3;
727           rect.height = widget->allocation.height -
728             2 * widget->style->klass->ythickness - 3;
729
730           gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
731                                      &rect);
732
733           gdk_draw_text (progress->offscreen_pixmap, widget->style->font,
734                          widget->style->fg_gc[widget->state],
735                          x, y, buf, strlen (buf));
736
737           gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
738                                      NULL);
739           g_free (buf);
740         }
741     }
742 }
743
744 /*******************************************************************/
745
746 void
747 gtk_progress_bar_update (GtkProgressBar *pbar,
748                          gfloat          percentage)
749 {
750   g_return_if_fail (pbar != NULL);
751   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
752
753   /***********************************************************************
754    *          Use of gtk_progress_bar_update() is deprecated !           * 
755    * Use gtk_progress_set_value or gtk_progress_set_percentage instead.  *
756    ***********************************************************************/
757
758   gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
759 }
760
761 void
762 gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
763                                   GtkProgressBarOrientation orientation)
764 {
765   g_return_if_fail (pbar != NULL);
766   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
767
768   if (pbar->orientation != orientation)
769     {
770       pbar->orientation = orientation;
771
772       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
773         gtk_widget_queue_resize (GTK_WIDGET (pbar));
774     }
775 }
776
777 void
778 gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
779                                 GtkProgressBarStyle bar_style)
780 {
781   g_return_if_fail (pbar != NULL);
782   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
783
784   if (pbar->bar_style != bar_style)
785     {
786       pbar->bar_style = bar_style;
787
788       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
789         gtk_widget_queue_resize (GTK_WIDGET (pbar));
790     }
791 }
792
793 void
794 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
795                                       guint           blocks)
796 {
797   g_return_if_fail (pbar != NULL);
798   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
799   g_return_if_fail (blocks > 1);
800
801   if (pbar->blocks != blocks)
802     {
803       pbar->blocks = blocks;
804
805       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
806         gtk_widget_queue_resize (GTK_WIDGET (pbar));
807     }
808 }
809
810 void
811 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
812                                     guint           step)
813 {
814   g_return_if_fail (pbar != NULL);
815   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
816
817   if (pbar->activity_step != step)
818     pbar->activity_step = step;
819 }
820
821 void
822 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
823                                       guint           blocks)
824 {
825   g_return_if_fail (pbar != NULL);
826   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
827   g_return_if_fail (blocks > 1);
828
829   if (pbar->activity_blocks != blocks)
830     pbar->activity_blocks = blocks;
831 }