]> Pileus Git - ~andy/gtk/blob - gtk/gtkprogressbar.c
build with GTK_DISABLE_DEPRECATED again.
[~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 Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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-2000.  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 #include "config.h"
28
29 #include <string.h>
30
31 #undef GTK_DISABLE_DEPRECATED
32 #define __GTK_PROGRESS_BAR_C__
33
34 #include "gtkprogressbar.h"
35 #include "gtkprivate.h"
36 #include "gtkintl.h"
37 #include "gtkalias.h"
38
39
40 #define MIN_HORIZONTAL_BAR_WIDTH   150
41 #define MIN_HORIZONTAL_BAR_HEIGHT  20
42 #define MIN_VERTICAL_BAR_WIDTH     22
43 #define MIN_VERTICAL_BAR_HEIGHT    80
44
45 enum {
46   PROP_0,
47
48   /* Supported args */
49   PROP_FRACTION,
50   PROP_PULSE_STEP,
51   PROP_ORIENTATION,
52   PROP_TEXT,
53   PROP_ELLIPSIZE,
54   
55   /* Deprecated args */
56   PROP_ADJUSTMENT,
57   PROP_BAR_STYLE,
58   PROP_ACTIVITY_STEP,
59   PROP_ACTIVITY_BLOCKS,
60   PROP_DISCRETE_BLOCKS
61 };
62
63 static void gtk_progress_bar_set_property  (GObject             *object,
64                                             guint                prop_id,
65                                             const GValue        *value,
66                                             GParamSpec          *pspec);
67 static void gtk_progress_bar_get_property  (GObject             *object,
68                                             guint                prop_id,
69                                             GValue              *value,
70                                             GParamSpec          *pspec);
71 static gboolean gtk_progress_bar_expose    (GtkWidget           *widget,
72                                             GdkEventExpose      *event);
73 static void gtk_progress_bar_size_request  (GtkWidget           *widget,
74                                             GtkRequisition      *requisition);
75 static void gtk_progress_bar_style_set     (GtkWidget           *widget,
76                                             GtkStyle            *previous);
77 static void gtk_progress_bar_real_update   (GtkProgress         *progress);
78 static void gtk_progress_bar_paint         (GtkProgress         *progress);
79 static void gtk_progress_bar_act_mode_enter (GtkProgress        *progress);
80
81 static void gtk_progress_bar_set_bar_style_internal       (GtkProgressBar *pbar,
82                                                            GtkProgressBarStyle style);
83 static void gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
84                                                            guint           blocks);
85 static void gtk_progress_bar_set_activity_step_internal   (GtkProgressBar *pbar,
86                                                            guint           step);
87 static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
88                                                            guint           blocks);
89
90
91 G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_PROGRESS)
92
93 static void
94 gtk_progress_bar_class_init (GtkProgressBarClass *class)
95 {
96   GObjectClass *gobject_class;
97   GtkWidgetClass *widget_class;
98   GtkProgressClass *progress_class;
99   
100   gobject_class = G_OBJECT_CLASS (class);
101   widget_class = (GtkWidgetClass *) class;
102   progress_class = (GtkProgressClass *) class;
103
104   gobject_class->set_property = gtk_progress_bar_set_property;
105   gobject_class->get_property = gtk_progress_bar_get_property;
106   
107   widget_class->expose_event = gtk_progress_bar_expose;
108   widget_class->size_request = gtk_progress_bar_size_request;
109   widget_class->style_set = gtk_progress_bar_style_set;
110
111   progress_class->paint = gtk_progress_bar_paint;
112   progress_class->update = gtk_progress_bar_real_update;
113   progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
114
115   g_object_class_install_property (gobject_class,
116                                    PROP_ADJUSTMENT,
117                                    g_param_spec_object ("adjustment",
118                                                         P_("Adjustment"),
119                                                         P_("The GtkAdjustment connected to the progress bar (Deprecated)"),
120                                                         GTK_TYPE_ADJUSTMENT,
121                                                         GTK_PARAM_READWRITE));
122
123   g_object_class_install_property (gobject_class,
124                                    PROP_ORIENTATION,
125                                    g_param_spec_enum ("orientation",
126                                                       P_("Orientation"),
127                                                       P_("Orientation and growth direction of the progress bar"),
128                                                       GTK_TYPE_PROGRESS_BAR_ORIENTATION,
129                                                       GTK_PROGRESS_LEFT_TO_RIGHT,
130                                                       GTK_PARAM_READWRITE));
131
132   g_object_class_install_property (gobject_class,
133                                    PROP_BAR_STYLE,
134                                    g_param_spec_enum ("bar-style",
135                                                       P_("Bar style"),
136                                                       P_("Specifies the visual style of the bar in percentage mode (Deprecated)"),
137                                                       GTK_TYPE_PROGRESS_BAR_STYLE,
138                                                       GTK_PROGRESS_CONTINUOUS,
139                                                       GTK_PARAM_READWRITE));
140
141   g_object_class_install_property (gobject_class,
142                                    PROP_ACTIVITY_STEP,
143                                    g_param_spec_uint ("activity-step",
144                                                       P_("Activity Step"),
145                                                       P_("The increment used for each iteration in activity mode (Deprecated)"),
146                                                       0, G_MAXUINT, 3,
147                                                       GTK_PARAM_READWRITE));
148
149   g_object_class_install_property (gobject_class,
150                                    PROP_ACTIVITY_BLOCKS,
151                                    g_param_spec_uint ("activity-blocks",
152                                                       P_("Activity Blocks"),
153                                                       P_("The number of blocks which can fit in the progress bar area in activity mode (Deprecated)"),
154                                                       2, G_MAXUINT, 5,
155                                                       GTK_PARAM_READWRITE));
156
157   g_object_class_install_property (gobject_class,
158                                    PROP_DISCRETE_BLOCKS,
159                                    g_param_spec_uint ("discrete-blocks",
160                                                       P_("Discrete Blocks"),
161                                                       P_("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
162                                                       2, G_MAXUINT, 10,
163                                                       GTK_PARAM_READWRITE));
164   
165   g_object_class_install_property (gobject_class,
166                                    PROP_FRACTION,
167                                    g_param_spec_double ("fraction",
168                                                         P_("Fraction"),
169                                                         P_("The fraction of total work that has been completed"),
170                                                         0.0, 1.0, 0.0,
171                                                         GTK_PARAM_READWRITE));  
172   
173   g_object_class_install_property (gobject_class,
174                                    PROP_PULSE_STEP,
175                                    g_param_spec_double ("pulse-step",
176                                                         P_("Pulse Step"),
177                                                         P_("The fraction of total progress to move the bouncing block when pulsed"),
178                                                         0.0, 1.0, 0.1,
179                                                         GTK_PARAM_READWRITE));  
180   
181   g_object_class_install_property (gobject_class,
182                                    PROP_TEXT,
183                                    g_param_spec_string ("text",
184                                                         P_("Text"),
185                                                         P_("Text to be displayed in the progress bar"),
186                                                         NULL,
187                                                         GTK_PARAM_READWRITE));
188
189   /**
190    * GtkProgressBar:ellipsize:
191    *
192    * The preferred place to ellipsize the string, if the progressbar does 
193    * not have enough room to display the entire string, specified as a 
194    * #PangoEllisizeMode. 
195    *
196    * Note that setting this property to a value other than 
197    * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests 
198    * only enough space to display the ellipsis "...". Another means to set a 
199    * progressbar's width is gtk_widget_set_size_request().
200    *
201    * Since: 2.6
202    */
203   g_object_class_install_property (gobject_class,
204                                    PROP_ELLIPSIZE,
205                                    g_param_spec_enum ("ellipsize",
206                                                       P_("Ellipsize"),
207                                                       P_("The preferred place to ellipsize the string, if the progress bar "
208                                                          "does not have enough room to display the entire string, if at all."),
209                                                       PANGO_TYPE_ELLIPSIZE_MODE,
210                                                       PANGO_ELLIPSIZE_NONE,
211                                                       GTK_PARAM_READWRITE));
212   gtk_widget_class_install_style_property (widget_class,
213                                            g_param_spec_int ("xspacing",
214                                                              P_("XSpacing"),
215                                                              P_("Extra spacing applied to the width of a progress bar."),
216                                                              0, G_MAXINT, 7,
217                                                              G_PARAM_READWRITE));
218   gtk_widget_class_install_style_property (widget_class,
219                                            g_param_spec_int ("yspacing",
220                                                              P_("YSpacing"),
221                                                              P_("Extra spacing applied to the height of a progress bar."),
222                                                              0, G_MAXINT, 7,
223                                                              G_PARAM_READWRITE));
224
225   /**
226    * GtkProgressBar:min-horizontal-bar-width:
227    *
228    * The minimum horizontal width of the progress bar.
229    *
230    * Since: 2.14
231    */
232   gtk_widget_class_install_style_property (widget_class,
233                                            g_param_spec_int ("min-horizontal-bar-width",
234                                                              P_("Min horizontal bar width"),
235                                                              P_("The minimum horizontal width of the progress bar"),
236                                                              1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
237                                                              G_PARAM_READWRITE));
238   /**
239    * GtkProgressBar:min-horizontal-bar-height:
240    *
241    * Minimum horizontal height of the progress bar.
242    *
243    * Since: 2.14
244    */
245   gtk_widget_class_install_style_property (widget_class,
246                                            g_param_spec_int ("min-horizontal-bar-height",
247                                                              P_("Min horizontal bar height"),
248                                                              P_("Minimum horizontal height of the progress bar"),
249                                                              1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
250                                                              G_PARAM_READWRITE));
251   /**
252    * GtkProgressBar:min-vertical-bar-width:
253    *
254    * The minimum vertical width of the progress bar.
255    *
256    * Since: 2.14
257    */
258   gtk_widget_class_install_style_property (widget_class,
259                                            g_param_spec_int ("min-vertical-bar-width",
260                                                              P_("Min vertical bar width"),
261                                                              P_("The minimum vertical width of the progress bar"),
262                                                              1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
263                                                              G_PARAM_READWRITE));
264   /**
265    * GtkProgressBar:min-vertical-bar-height:
266    *
267    * The minimum vertical height of the progress bar.
268    *
269    * Since: 2.14
270    */
271   gtk_widget_class_install_style_property (widget_class,
272                                            g_param_spec_int ("min-vertical-bar-height",
273                                                              P_("Min vertical bar height"),
274                                                              P_("The minimum vertical height of the progress bar"),
275                                                              1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
276                                                              G_PARAM_READWRITE));
277 }
278
279 static void
280 gtk_progress_bar_init (GtkProgressBar *pbar)
281 {
282   pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
283   pbar->blocks = 10;
284   pbar->in_block = -1;
285   pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
286   pbar->pulse_fraction = 0.1;
287   pbar->activity_pos = 0;
288   pbar->activity_dir = 1;
289   pbar->activity_step = 3;
290   pbar->activity_blocks = 5;
291   pbar->ellipsize = PANGO_ELLIPSIZE_NONE;
292 }
293
294 static void
295 gtk_progress_bar_set_property (GObject      *object,
296                                guint         prop_id,
297                                const GValue *value,
298                                GParamSpec   *pspec)
299 {
300   GtkProgressBar *pbar;
301
302   pbar = GTK_PROGRESS_BAR (object);
303
304   switch (prop_id)
305     {
306     case PROP_ADJUSTMENT:
307       gtk_progress_set_adjustment (GTK_PROGRESS (pbar),
308                                    GTK_ADJUSTMENT (g_value_get_object (value)));
309       break;
310     case PROP_ORIENTATION:
311       gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
312       break;
313     case PROP_BAR_STYLE:
314       gtk_progress_bar_set_bar_style_internal (pbar, g_value_get_enum (value));
315       break;
316     case PROP_ACTIVITY_STEP:
317       gtk_progress_bar_set_activity_step_internal (pbar, g_value_get_uint (value));
318       break;
319     case PROP_ACTIVITY_BLOCKS:
320       gtk_progress_bar_set_activity_blocks_internal (pbar, g_value_get_uint (value));
321       break;
322     case PROP_DISCRETE_BLOCKS:
323       gtk_progress_bar_set_discrete_blocks_internal (pbar, g_value_get_uint (value));
324       break;
325     case PROP_FRACTION:
326       gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
327       break;
328     case PROP_PULSE_STEP:
329       gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
330       break;
331     case PROP_TEXT:
332       gtk_progress_bar_set_text (pbar, g_value_get_string (value));
333       break;
334     case PROP_ELLIPSIZE:
335       gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
336       break;
337     default:
338       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339       break;
340     }
341 }
342
343 static void
344 gtk_progress_bar_get_property (GObject      *object,
345                                guint         prop_id,
346                                GValue       *value,
347                                GParamSpec   *pspec)
348 {
349   GtkProgressBar *pbar;
350
351   pbar = GTK_PROGRESS_BAR (object);
352
353   switch (prop_id)
354     {
355     case PROP_ADJUSTMENT:
356       g_value_set_object (value, GTK_PROGRESS (pbar)->adjustment);
357       break;
358     case PROP_ORIENTATION:
359       g_value_set_enum (value, pbar->orientation);
360       break;
361     case PROP_BAR_STYLE:
362       g_value_set_enum (value, pbar->bar_style);
363       break;
364     case PROP_ACTIVITY_STEP:
365       g_value_set_uint (value, pbar->activity_step);
366       break;
367     case PROP_ACTIVITY_BLOCKS:
368       g_value_set_uint (value, pbar->activity_blocks);
369       break;
370     case PROP_DISCRETE_BLOCKS:
371       g_value_set_uint (value, pbar->blocks);
372       break;
373     case PROP_FRACTION:
374       g_value_set_double (value, gtk_progress_get_current_percentage (GTK_PROGRESS (pbar)));
375       break;
376     case PROP_PULSE_STEP:
377       g_value_set_double (value, pbar->pulse_fraction);
378       break;
379     case PROP_TEXT:
380       g_value_set_string (value, gtk_progress_bar_get_text (pbar));
381       break;
382     case PROP_ELLIPSIZE:
383       g_value_set_enum (value, pbar->ellipsize);
384       break;
385     default:
386       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
387       break;
388     }
389 }
390
391 GtkWidget*
392 gtk_progress_bar_new (void)
393 {
394   GtkWidget *pbar;
395
396   pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
397
398   return pbar;
399 }
400
401 GtkWidget*
402 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
403 {
404   GtkWidget *pbar;
405
406   g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
407
408   pbar = g_object_new (GTK_TYPE_PROGRESS_BAR,
409                          "adjustment", adjustment,
410                          NULL);
411
412   return pbar;
413 }
414
415 static void
416 gtk_progress_bar_real_update (GtkProgress *progress)
417 {
418   GtkProgressBar *pbar;
419   GtkWidget *widget;
420
421   g_return_if_fail (GTK_IS_PROGRESS (progress));
422
423   pbar = GTK_PROGRESS_BAR (progress);
424   widget = GTK_WIDGET (progress);
425  
426   if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
427       GTK_PROGRESS (pbar)->activity_mode)
428     {
429       if (GTK_PROGRESS (pbar)->activity_mode)
430         {
431           guint size;
432           
433           /* advance the block */
434
435           if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
436               pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
437             {
438               /* Update our activity step. */
439               
440               pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
441               
442               size = MAX (2, widget->allocation.width / pbar->activity_blocks);
443
444               if (pbar->activity_dir == 0)
445                 {
446                   pbar->activity_pos += pbar->activity_step;
447                   if (pbar->activity_pos + size >=
448                       widget->allocation.width -
449                       widget->style->xthickness)
450                     {
451                       pbar->activity_pos = widget->allocation.width -
452                         widget->style->xthickness - size;
453                       pbar->activity_dir = 1;
454                     }
455                 }
456               else
457                 {
458                   pbar->activity_pos -= pbar->activity_step;
459                   if (pbar->activity_pos <= widget->style->xthickness)
460                     {
461                       pbar->activity_pos = widget->style->xthickness;
462                       pbar->activity_dir = 0;
463                     }
464                 }
465             }
466           else
467             {
468               /* Update our activity step. */
469               
470               pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
471               
472               size = MAX (2, widget->allocation.height / pbar->activity_blocks);
473
474               if (pbar->activity_dir == 0)
475                 {
476                   pbar->activity_pos += pbar->activity_step;
477                   if (pbar->activity_pos + size >=
478                       widget->allocation.height -
479                       widget->style->ythickness)
480                     {
481                       pbar->activity_pos = widget->allocation.height -
482                         widget->style->ythickness - size;
483                       pbar->activity_dir = 1;
484                     }
485                 }
486               else
487                 {
488                   pbar->activity_pos -= pbar->activity_step;
489                   if (pbar->activity_pos <= widget->style->ythickness)
490                     {
491                       pbar->activity_pos = widget->style->ythickness;
492                       pbar->activity_dir = 0;
493                     }
494                 }
495             }
496         }
497       pbar->dirty = TRUE;
498       gtk_widget_queue_draw (GTK_WIDGET (progress));
499     }
500   else
501     {
502       gint in_block;
503       
504       in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
505                              (gdouble)pbar->blocks);
506       
507       if (pbar->in_block != in_block)
508         {
509           pbar->in_block = in_block;
510           pbar->dirty = TRUE;
511           gtk_widget_queue_draw (GTK_WIDGET (progress));
512         }
513     }
514 }
515
516 static gboolean
517 gtk_progress_bar_expose (GtkWidget      *widget,
518                      GdkEventExpose *event)
519 {
520   GtkProgressBar *pbar;
521
522   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
523
524   pbar = GTK_PROGRESS_BAR (widget);
525
526   if (GTK_WIDGET_DRAWABLE (widget) && pbar->dirty)
527     gtk_progress_bar_paint (GTK_PROGRESS (pbar));
528
529   return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
530 }
531
532 static void
533 gtk_progress_bar_size_request (GtkWidget      *widget,
534                                GtkRequisition *requisition)
535 {
536   GtkProgress *progress;
537   GtkProgressBar *pbar;
538   gchar *buf;
539   PangoRectangle logical_rect;
540   PangoLayout *layout;
541   gint width, height;
542   gint xspacing, yspacing;
543   gint min_width, min_height;
544
545   g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
546   g_return_if_fail (requisition != NULL);
547
548   gtk_widget_style_get (widget,
549                         "xspacing", &xspacing,
550                         "yspacing", &yspacing,
551                         NULL);
552
553   progress = GTK_PROGRESS (widget);
554   pbar = GTK_PROGRESS_BAR (widget);
555
556   width = 2 * widget->style->xthickness + xspacing;
557   height = 2 * widget->style->ythickness + yspacing;
558
559   if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
560     {
561       if (!progress->adjustment)
562         gtk_progress_set_adjustment (progress, NULL);
563
564       buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
565
566       layout = gtk_widget_create_pango_layout (widget, buf);
567
568       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
569           
570       if (pbar->ellipsize)
571         {
572           PangoContext *context;
573           PangoFontMetrics *metrics;
574           gint char_width;
575           
576           /* The minimum size for ellipsized text is ~ 3 chars */
577           context = pango_layout_get_context (layout);
578           metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
579           
580           char_width = pango_font_metrics_get_approximate_char_width (metrics);
581           pango_font_metrics_unref (metrics);
582           
583           width += PANGO_PIXELS (char_width) * 3;
584         }
585       else
586         width += logical_rect.width;
587       
588       height += logical_rect.height;
589
590       g_object_unref (layout);
591       g_free (buf);
592     }
593   
594   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
595       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
596     gtk_widget_style_get (widget,
597                           "min-horizontal-bar-width", &min_width,
598                           "min-horizontal-bar-height", &min_height,
599                           NULL);
600   else
601     gtk_widget_style_get (widget,
602                           "min-vertical-bar-width", &min_width,
603                           "min-vertical-bar-height", &min_height,
604                           NULL);
605
606   requisition->width = MAX (min_width, width);
607   requisition->height = MAX (min_height, height);
608 }
609
610 static void
611 gtk_progress_bar_style_set (GtkWidget      *widget,
612     GtkStyle *previous)
613 {
614   GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
615
616   pbar->dirty = TRUE;
617
618   GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->style_set (widget, previous);
619 }
620
621 static void
622 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
623 {
624   GtkProgressBar *pbar;
625   GtkWidget *widget;
626   GtkProgressBarOrientation orientation;
627
628   pbar = GTK_PROGRESS_BAR (progress);
629   widget = GTK_WIDGET (progress);
630
631   orientation = pbar->orientation;
632   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
633     {
634       if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
635         orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
636       else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
637         orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
638     }
639   
640   /* calculate start pos */
641
642   if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
643       orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
644     {
645       if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
646         {
647           pbar->activity_pos = widget->style->xthickness;
648           pbar->activity_dir = 0;
649         }
650       else
651         {
652           pbar->activity_pos = widget->allocation.width - 
653             widget->style->xthickness - (widget->allocation.height - 
654                 widget->style->ythickness * 2);
655           pbar->activity_dir = 1;
656         }
657     }
658   else
659     {
660       if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
661         {
662           pbar->activity_pos = widget->style->ythickness;
663           pbar->activity_dir = 0;
664         }
665       else
666         {
667           pbar->activity_pos = widget->allocation.height -
668             widget->style->ythickness - (widget->allocation.width - 
669                 widget->style->xthickness * 2);
670           pbar->activity_dir = 1;
671         }
672     }
673 }
674
675 static void
676 gtk_progress_bar_get_activity (GtkProgressBar            *pbar,
677                                GtkProgressBarOrientation  orientation,
678                                gint                      *offset,
679                                gint                      *amount)
680 {
681   GtkWidget *widget = GTK_WIDGET (pbar);
682
683   *offset = pbar->activity_pos;
684
685   switch (orientation)
686     {
687     case GTK_PROGRESS_LEFT_TO_RIGHT:
688     case GTK_PROGRESS_RIGHT_TO_LEFT:
689       *amount = MAX (2, widget->allocation.width / pbar->activity_blocks);
690       break;
691
692     case GTK_PROGRESS_TOP_TO_BOTTOM:
693     case GTK_PROGRESS_BOTTOM_TO_TOP:
694       *amount = MAX (2, widget->allocation.height / pbar->activity_blocks);
695       break;
696     }
697 }
698
699 static void
700 gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
701                                  GtkProgressBarOrientation  orientation)
702 {
703   GtkWidget *widget = GTK_WIDGET (pbar);
704   GtkProgress *progress = GTK_PROGRESS (pbar);
705   GdkRectangle area;
706
707   switch (orientation)
708     {
709     case GTK_PROGRESS_LEFT_TO_RIGHT:
710     case GTK_PROGRESS_RIGHT_TO_LEFT:
711       gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
712       area.y = widget->style->ythickness;
713       area.height = widget->allocation.height - 2 * widget->style->ythickness;
714       break;
715
716     case GTK_PROGRESS_TOP_TO_BOTTOM:
717     case GTK_PROGRESS_BOTTOM_TO_TOP:
718       gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
719       area.x = widget->style->xthickness;
720       area.width = widget->allocation.width - 2 * widget->style->xthickness;
721       break;
722
723     default:
724       return;
725       break;
726     }
727
728   gtk_paint_box (widget->style,
729                  progress->offscreen_pixmap,
730                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
731                  &area, widget, "bar",
732                  area.x, area.y, area.width, area.height);
733 }
734
735 static void
736 gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
737                                    gint                       amount,
738                                    GtkProgressBarOrientation  orientation)
739 {
740   GdkRectangle area;
741   GtkWidget *widget = GTK_WIDGET (pbar);
742
743   if (amount <= 0)
744     return;
745
746   switch (orientation)
747     {
748     case GTK_PROGRESS_LEFT_TO_RIGHT:
749     case GTK_PROGRESS_RIGHT_TO_LEFT:
750       area.width = amount;
751       area.height = widget->allocation.height - widget->style->ythickness * 2;
752       area.y = widget->style->ythickness;
753       
754       area.x = widget->style->xthickness;
755       if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
756         area.x = widget->allocation.width - amount - area.x;
757       break;
758       
759     case GTK_PROGRESS_TOP_TO_BOTTOM:
760     case GTK_PROGRESS_BOTTOM_TO_TOP:
761       area.width = widget->allocation.width - widget->style->xthickness * 2;
762       area.height = amount;
763       area.x = widget->style->xthickness;
764       
765       area.y = widget->style->ythickness;
766       if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
767         area.y = widget->allocation.height - amount - area.y;
768       break;
769       
770     default:
771       return;
772       break;
773     }
774   
775   gtk_paint_box (widget->style,
776                  GTK_PROGRESS (pbar)->offscreen_pixmap,
777                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
778                  &area, widget, "bar",
779                  area.x, area.y, area.width, area.height);
780 }
781
782 static void
783 gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
784                                  GtkProgressBarOrientation  orientation)
785 {
786   GtkWidget *widget = GTK_WIDGET (pbar);
787   gint i;
788
789   for (i = 0; i <= pbar->in_block; i++)
790     {
791       GdkRectangle area;
792       gint space;
793
794       switch (orientation)
795         {
796         case GTK_PROGRESS_LEFT_TO_RIGHT:
797         case GTK_PROGRESS_RIGHT_TO_LEFT:
798           space = widget->allocation.width - 2 * widget->style->xthickness;
799           
800           area.x = widget->style->xthickness + (i * space) / pbar->blocks;
801           area.y = widget->style->ythickness;
802           area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
803           area.height = widget->allocation.height - 2 * widget->style->ythickness;
804
805           if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
806             area.x = widget->allocation.width - area.width - area.x;
807           break;
808           
809         case GTK_PROGRESS_TOP_TO_BOTTOM:
810         case GTK_PROGRESS_BOTTOM_TO_TOP:
811           space = widget->allocation.height - 2 * widget->style->ythickness;
812           
813           area.x = widget->style->xthickness;
814           area.y = widget->style->ythickness + (i * space) / pbar->blocks;
815           area.width = widget->allocation.width - 2 * widget->style->xthickness;
816           area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
817           
818           if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
819             area.y = widget->allocation.height - area.height - area.y;
820           break;
821
822         default:
823           return;
824           break;
825         }
826       
827       gtk_paint_box (widget->style,
828                      GTK_PROGRESS (pbar)->offscreen_pixmap,
829                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
830                      &area, widget, "bar",
831                      area.x, area.y, area.width, area.height);
832     }
833 }
834
835 static void
836 gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
837                              gint                       offset,
838                              gint                       amount,
839                              GtkProgressBarOrientation  orientation)
840 {
841   GtkProgress *progress = GTK_PROGRESS (pbar);
842   GtkWidget *widget = GTK_WIDGET (pbar);
843   gint x;
844   gint y;
845   gchar *buf;
846   GdkRectangle rect;
847   PangoLayout *layout;
848   PangoRectangle logical_rect;
849   GdkRectangle prelight_clip, start_clip, end_clip;
850   gfloat text_xalign = progress->x_align;
851   gfloat text_yalign = progress->y_align;
852
853   if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
854     text_xalign = 1.0 - text_xalign;
855
856   buf = gtk_progress_get_current_text (progress);
857   
858   layout = gtk_widget_create_pango_layout (widget, buf);
859   pango_layout_set_ellipsize (layout, pbar->ellipsize);
860   if (pbar->ellipsize)
861     pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
862
863   pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
864   
865   x = widget->style->xthickness + 1 + text_xalign *
866       (widget->allocation.width - 2 * widget->style->xthickness -
867        2 - logical_rect.width);
868
869   y = widget->style->ythickness + 1 + text_yalign *
870       (widget->allocation.height - 2 * widget->style->ythickness -
871        2 - logical_rect.height);
872
873   rect.x = widget->style->xthickness;
874   rect.y = widget->style->ythickness;
875   rect.width = widget->allocation.width - 2 * widget->style->xthickness;
876   rect.height = widget->allocation.height - 2 * widget->style->ythickness;
877
878   prelight_clip = start_clip = end_clip = rect;
879
880   switch (orientation)
881     {
882     case GTK_PROGRESS_LEFT_TO_RIGHT:
883       if (offset != -1)
884         prelight_clip.x = offset;
885       prelight_clip.width = amount;
886       start_clip.width = prelight_clip.x - start_clip.x;
887       end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
888       end_clip.width -= prelight_clip.width + start_clip.width;
889       break;
890       
891     case GTK_PROGRESS_RIGHT_TO_LEFT:
892       if (offset != -1)
893         prelight_clip.x = offset;
894       else
895         prelight_clip.x = rect.x + rect.width - amount;
896       prelight_clip.width = amount;
897       start_clip.width = prelight_clip.x - start_clip.x;
898       end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
899       end_clip.width -= prelight_clip.width + start_clip.width;
900       break;
901        
902     case GTK_PROGRESS_TOP_TO_BOTTOM:
903       if (offset != -1)
904         prelight_clip.y = offset;
905       prelight_clip.height = amount;
906       start_clip.height = prelight_clip.y - start_clip.y;
907       end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
908       end_clip.height -= prelight_clip.height + start_clip.height;
909       break;
910       
911     case GTK_PROGRESS_BOTTOM_TO_TOP:
912       if (offset != -1)
913         prelight_clip.y = offset;
914       else
915         prelight_clip.y = rect.y + rect.height - amount;
916       prelight_clip.height = amount;
917       start_clip.height = prelight_clip.y - start_clip.y;
918       end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
919       end_clip.height -= prelight_clip.height + start_clip.height;
920       break;
921     }
922
923   if (start_clip.width > 0 && start_clip.height > 0)
924     gtk_paint_layout (widget->style,
925                       progress->offscreen_pixmap,
926                       GTK_STATE_NORMAL,
927                       FALSE,
928                       &start_clip,
929                       widget,
930                       "progressbar",
931                       x, y,
932                       layout);
933
934   if (end_clip.width > 0 && end_clip.height > 0)
935     gtk_paint_layout (widget->style,
936                       progress->offscreen_pixmap,
937                       GTK_STATE_NORMAL,
938                       FALSE,
939                       &end_clip,
940                       widget,
941                       "progressbar",
942                       x, y,
943                       layout);
944
945   gtk_paint_layout (widget->style,
946                     progress->offscreen_pixmap,
947                     GTK_STATE_PRELIGHT,
948                     FALSE,
949                     &prelight_clip,
950                     widget,
951                     "progressbar",
952                     x, y,
953                     layout);
954
955   g_object_unref (layout);
956   g_free (buf);
957 }
958
959 static void
960 gtk_progress_bar_paint (GtkProgress *progress)
961 {
962   GtkProgressBar *pbar;
963   GtkWidget *widget;
964
965   GtkProgressBarOrientation orientation;
966
967   g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
968
969   pbar = GTK_PROGRESS_BAR (progress);
970   widget = GTK_WIDGET (progress);
971
972   orientation = pbar->orientation;
973   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
974     {
975       if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
976         orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
977       else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
978         orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
979     }
980  
981   if (progress->offscreen_pixmap)
982     {
983       gtk_paint_box (widget->style,
984                      progress->offscreen_pixmap,
985                      GTK_STATE_NORMAL, GTK_SHADOW_IN, 
986                      NULL, widget, "trough",
987                      0, 0,
988                      widget->allocation.width,
989                      widget->allocation.height);
990       
991       if (progress->activity_mode)
992         {
993           gtk_progress_bar_paint_activity (pbar, orientation);
994
995           if (GTK_PROGRESS (pbar)->show_text)
996             {
997               gint offset;
998               gint amount;
999
1000               gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
1001               gtk_progress_bar_paint_text (pbar, offset, amount, orientation);
1002             }
1003         }
1004       else
1005         {
1006           gint amount;
1007           gint space;
1008           
1009           if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
1010               orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
1011             space = widget->allocation.width - 2 * widget->style->xthickness;
1012           else
1013             space = widget->allocation.height - 2 * widget->style->ythickness;
1014           
1015           amount = space *
1016             gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1017           
1018           if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
1019             {
1020               gtk_progress_bar_paint_continuous (pbar, amount, orientation);
1021
1022               if (GTK_PROGRESS (pbar)->show_text)
1023                 gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
1024             }
1025           else
1026             gtk_progress_bar_paint_discrete (pbar, orientation);
1027         }
1028
1029       pbar->dirty = FALSE;
1030     }
1031 }
1032
1033 static void
1034 gtk_progress_bar_set_bar_style_internal (GtkProgressBar     *pbar,
1035                                          GtkProgressBarStyle bar_style)
1036 {
1037   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1038
1039   if (pbar->bar_style != bar_style)
1040     {
1041       pbar->bar_style = bar_style;
1042
1043       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1044         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1045
1046       g_object_notify (G_OBJECT (pbar), "bar-style");
1047     }
1048 }
1049
1050 static void
1051 gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
1052                                                guint           blocks)
1053 {
1054   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1055   g_return_if_fail (blocks > 1);
1056
1057   if (pbar->blocks != blocks)
1058     {
1059       pbar->blocks = blocks;
1060
1061       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1062         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1063
1064       g_object_notify (G_OBJECT (pbar), "discrete-blocks");
1065     }
1066 }
1067
1068 static void
1069 gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
1070                                              guint           step)
1071 {
1072   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1073
1074   if (pbar->activity_step != step)
1075     {
1076       pbar->activity_step = step;
1077       g_object_notify (G_OBJECT (pbar), "activity-step");
1078     }
1079 }
1080
1081 static void
1082 gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
1083                                                guint           blocks)
1084 {
1085   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1086   g_return_if_fail (blocks > 1);
1087
1088   if (pbar->activity_blocks != blocks)
1089     {
1090       pbar->activity_blocks = blocks;
1091       g_object_notify (G_OBJECT (pbar), "activity-blocks");
1092     }
1093 }
1094
1095 /*******************************************************************/
1096
1097 /**
1098  * gtk_progress_bar_set_fraction:
1099  * @pbar: a #GtkProgressBar
1100  * @fraction: fraction of the task that's been completed
1101  * 
1102  * Causes the progress bar to "fill in" the given fraction
1103  * of the bar. The fraction should be between 0.0 and 1.0,
1104  * inclusive.
1105  * 
1106  **/
1107 void
1108 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
1109                                gdouble         fraction)
1110 {
1111   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1112
1113   /* If we know the percentage, we don't want activity mode. */
1114   gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
1115   
1116   /* We use the deprecated GtkProgress interface internally.
1117    * Once everything's been deprecated for a good long time,
1118    * we can clean up all this code.
1119    */
1120   gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
1121
1122   g_object_notify (G_OBJECT (pbar), "fraction");
1123 }
1124
1125 /**
1126  * gtk_progress_bar_pulse:
1127  * @pbar: a #GtkProgressBar
1128  * 
1129  * Indicates that some progress is made, but you don't know how much.
1130  * Causes the progress bar to enter "activity mode," where a block
1131  * bounces back and forth. Each call to gtk_progress_bar_pulse()
1132  * causes the block to move by a little bit (the amount of movement
1133  * per pulse is determined by gtk_progress_bar_set_pulse_step()).
1134  **/
1135 void
1136 gtk_progress_bar_pulse (GtkProgressBar *pbar)
1137 {  
1138   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1139
1140   /* If we don't know the percentage, we must want activity mode. */
1141   gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
1142
1143   /* Sigh. */
1144   gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
1145 }
1146
1147 /**
1148  * gtk_progress_bar_set_text:
1149  * @pbar: a #GtkProgressBar
1150  * @text: a UTF-8 string, or %NULL 
1151  * 
1152  * Causes the given @text to appear superimposed on the progress bar.
1153  **/
1154 void
1155 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1156                            const gchar    *text)
1157 {
1158   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1159   
1160   gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
1161   gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
1162   
1163   /* We don't support formats in this interface, but turn
1164    * them back on for NULL, which should put us back to
1165    * the initial state.
1166    */
1167   GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
1168   
1169   g_object_notify (G_OBJECT (pbar), "text");
1170 }
1171
1172 /**
1173  * gtk_progress_bar_set_pulse_step:
1174  * @pbar: a #GtkProgressBar
1175  * @fraction: fraction between 0.0 and 1.0
1176  * 
1177  * Sets the fraction of total progress bar length to move the
1178  * bouncing block for each call to gtk_progress_bar_pulse().
1179  **/
1180 void
1181 gtk_progress_bar_set_pulse_step   (GtkProgressBar *pbar,
1182                                    gdouble         fraction)
1183 {
1184   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1185   
1186   pbar->pulse_fraction = fraction;
1187
1188   g_object_notify (G_OBJECT (pbar), "pulse-step");
1189 }
1190
1191 void
1192 gtk_progress_bar_update (GtkProgressBar *pbar,
1193                          gdouble         percentage)
1194 {
1195   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1196
1197   /* Use of gtk_progress_bar_update() is deprecated ! 
1198    * Use gtk_progress_bar_set_percentage ()
1199    */   
1200
1201   gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
1202 }
1203
1204 /**
1205  * gtk_progress_bar_set_orientation:
1206  * @pbar: a #GtkProgressBar
1207  * @orientation: orientation of the progress bar
1208  * 
1209  * Causes the progress bar to switch to a different orientation
1210  * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top). 
1211  **/
1212 void
1213 gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
1214                                   GtkProgressBarOrientation orientation)
1215 {
1216   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1217
1218   if (pbar->orientation != orientation)
1219     {
1220       pbar->orientation = orientation;
1221
1222       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1223         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1224
1225       g_object_notify (G_OBJECT (pbar), "orientation");
1226     }
1227 }
1228
1229 /**
1230  * gtk_progress_bar_get_text:
1231  * @pbar: a #GtkProgressBar
1232  * 
1233  * Retrieves the text displayed superimposed on the progress bar,
1234  * if any, otherwise %NULL. The return value is a reference
1235  * to the text, not a copy of it, so will become invalid
1236  * if you change the text in the progress bar.
1237  * 
1238  * Return value: text, or %NULL; this string is owned by the widget
1239  * and should not be modified or freed.
1240  **/
1241 G_CONST_RETURN gchar*
1242 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1243 {
1244   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1245
1246   if (GTK_PROGRESS (pbar)->use_text_format)
1247     return NULL;
1248   else
1249     return GTK_PROGRESS (pbar)->format;
1250 }
1251
1252 /**
1253  * gtk_progress_bar_get_fraction:
1254  * @pbar: a #GtkProgressBar
1255  * 
1256  * Returns the current fraction of the task that's been completed.
1257  * 
1258  * Return value: a fraction from 0.0 to 1.0
1259  **/
1260 gdouble
1261 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1262 {
1263   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1264
1265   return gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1266 }
1267
1268 /**
1269  * gtk_progress_bar_get_pulse_step:
1270  * @pbar: a #GtkProgressBar
1271  * 
1272  * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1273  * 
1274  * Return value: a fraction from 0.0 to 1.0
1275  **/
1276 gdouble
1277 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1278 {
1279   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1280
1281   return pbar->pulse_fraction;
1282 }
1283
1284 /**
1285  * gtk_progress_bar_get_orientation:
1286  * @pbar: a #GtkProgressBar
1287  * 
1288  * Retrieves the current progress bar orientation.
1289  * 
1290  * Return value: orientation of the progress bar
1291  **/
1292 GtkProgressBarOrientation
1293 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1294 {
1295   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1296
1297   return pbar->orientation;
1298 }
1299
1300 void
1301 gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
1302                                 GtkProgressBarStyle bar_style)
1303 {
1304   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1305
1306   gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
1307 }
1308
1309 void
1310 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
1311                                       guint           blocks)
1312 {
1313   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1314   g_return_if_fail (blocks > 1);
1315
1316   gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
1317 }
1318
1319 void
1320 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
1321                                     guint           step)
1322 {
1323   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1324
1325   gtk_progress_bar_set_activity_step_internal (pbar, step);
1326 }
1327
1328 void
1329 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
1330                                       guint           blocks)
1331 {
1332   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1333   g_return_if_fail (blocks > 1);
1334
1335   gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);
1336 }
1337
1338 /**
1339  * gtk_progress_bar_set_ellipsize:
1340  * @pbar: a #GtkProgressBar
1341  * @mode: a #PangoEllipsizeMode
1342  *
1343  * Sets the mode used to ellipsize (add an ellipsis: "...") the text 
1344  * if there is not enough space to render the entire string.
1345  *
1346  * Since: 2.6
1347  **/
1348 void
1349 gtk_progress_bar_set_ellipsize (GtkProgressBar     *pbar,
1350                                 PangoEllipsizeMode  mode)
1351 {
1352   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1353   g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE && 
1354                     mode <= PANGO_ELLIPSIZE_END);
1355   
1356   if ((PangoEllipsizeMode)pbar->ellipsize != mode)
1357     {
1358       pbar->ellipsize = mode;
1359
1360       g_object_notify (G_OBJECT (pbar), "ellipsize");
1361       gtk_widget_queue_resize (GTK_WIDGET (pbar));
1362     }
1363 }
1364
1365 /**
1366  * gtk_progress_bar_get_ellipsize:
1367  * @pbar: a #GtkProgressBar
1368  *
1369  * Returns the ellipsizing position of the progressbar. 
1370  * See gtk_progress_bar_set_ellipsize().
1371  *
1372  * Return value: #PangoEllipsizeMode
1373  *
1374  * Since: 2.6
1375  **/
1376 PangoEllipsizeMode 
1377 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1378 {
1379   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1380
1381   return pbar->ellipsize;
1382 }
1383
1384 #include "gtkaliasdef.c"