]> Pileus Git - ~andy/gtk/blob - gtk/gtkprogressbar.c
[annotations] Add allow-none
[~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 /**
402  * gtk_progress_bar_new_with_adjustment:
403  * @adjustment: (allow-none):
404  *
405  * Creates a new #GtkProgressBar with an associated #GtkAdjustment.
406  *
407  * Returns: (transfer none): a #GtkProgressBar.
408  */
409 GtkWidget*
410 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
411 {
412   GtkWidget *pbar;
413
414   g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
415
416   pbar = g_object_new (GTK_TYPE_PROGRESS_BAR,
417                          "adjustment", adjustment,
418                          NULL);
419
420   return pbar;
421 }
422
423 static void
424 gtk_progress_bar_real_update (GtkProgress *progress)
425 {
426   GtkProgressBar *pbar;
427   GtkWidget *widget;
428
429   g_return_if_fail (GTK_IS_PROGRESS (progress));
430
431   pbar = GTK_PROGRESS_BAR (progress);
432   widget = GTK_WIDGET (progress);
433  
434   if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
435       GTK_PROGRESS (pbar)->activity_mode)
436     {
437       if (GTK_PROGRESS (pbar)->activity_mode)
438         {
439           guint size;
440           
441           /* advance the block */
442
443           if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
444               pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
445             {
446               /* Update our activity step. */
447               
448               pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
449               
450               size = MAX (2, widget->allocation.width / pbar->activity_blocks);
451
452               if (pbar->activity_dir == 0)
453                 {
454                   pbar->activity_pos += pbar->activity_step;
455                   if (pbar->activity_pos + size >=
456                       widget->allocation.width -
457                       widget->style->xthickness)
458                     {
459                       pbar->activity_pos = widget->allocation.width -
460                         widget->style->xthickness - size;
461                       pbar->activity_dir = 1;
462                     }
463                 }
464               else
465                 {
466                   pbar->activity_pos -= pbar->activity_step;
467                   if (pbar->activity_pos <= widget->style->xthickness)
468                     {
469                       pbar->activity_pos = widget->style->xthickness;
470                       pbar->activity_dir = 0;
471                     }
472                 }
473             }
474           else
475             {
476               /* Update our activity step. */
477               
478               pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
479               
480               size = MAX (2, widget->allocation.height / pbar->activity_blocks);
481
482               if (pbar->activity_dir == 0)
483                 {
484                   pbar->activity_pos += pbar->activity_step;
485                   if (pbar->activity_pos + size >=
486                       widget->allocation.height -
487                       widget->style->ythickness)
488                     {
489                       pbar->activity_pos = widget->allocation.height -
490                         widget->style->ythickness - size;
491                       pbar->activity_dir = 1;
492                     }
493                 }
494               else
495                 {
496                   pbar->activity_pos -= pbar->activity_step;
497                   if (pbar->activity_pos <= widget->style->ythickness)
498                     {
499                       pbar->activity_pos = widget->style->ythickness;
500                       pbar->activity_dir = 0;
501                     }
502                 }
503             }
504         }
505       pbar->dirty = TRUE;
506       gtk_widget_queue_draw (GTK_WIDGET (progress));
507     }
508   else
509     {
510       gint in_block;
511       
512       in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
513                              (gdouble)pbar->blocks);
514       
515       if (pbar->in_block != in_block)
516         {
517           pbar->in_block = in_block;
518           pbar->dirty = TRUE;
519           gtk_widget_queue_draw (GTK_WIDGET (progress));
520         }
521     }
522 }
523
524 static gboolean
525 gtk_progress_bar_expose (GtkWidget      *widget,
526                      GdkEventExpose *event)
527 {
528   GtkProgressBar *pbar;
529
530   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
531
532   pbar = GTK_PROGRESS_BAR (widget);
533
534   if (GTK_WIDGET_DRAWABLE (widget) && pbar->dirty)
535     gtk_progress_bar_paint (GTK_PROGRESS (pbar));
536
537   return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
538 }
539
540 static void
541 gtk_progress_bar_size_request (GtkWidget      *widget,
542                                GtkRequisition *requisition)
543 {
544   GtkProgress *progress;
545   GtkProgressBar *pbar;
546   gchar *buf;
547   PangoRectangle logical_rect;
548   PangoLayout *layout;
549   gint width, height;
550   gint xspacing, yspacing;
551   gint min_width, min_height;
552
553   g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
554   g_return_if_fail (requisition != NULL);
555
556   gtk_widget_style_get (widget,
557                         "xspacing", &xspacing,
558                         "yspacing", &yspacing,
559                         NULL);
560
561   progress = GTK_PROGRESS (widget);
562   pbar = GTK_PROGRESS_BAR (widget);
563
564   width = 2 * widget->style->xthickness + xspacing;
565   height = 2 * widget->style->ythickness + yspacing;
566
567   if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
568     {
569       if (!progress->adjustment)
570         gtk_progress_set_adjustment (progress, NULL);
571
572       buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
573
574       layout = gtk_widget_create_pango_layout (widget, buf);
575
576       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
577           
578       if (pbar->ellipsize)
579         {
580           PangoContext *context;
581           PangoFontMetrics *metrics;
582           gint char_width;
583           
584           /* The minimum size for ellipsized text is ~ 3 chars */
585           context = pango_layout_get_context (layout);
586           metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
587           
588           char_width = pango_font_metrics_get_approximate_char_width (metrics);
589           pango_font_metrics_unref (metrics);
590           
591           width += PANGO_PIXELS (char_width) * 3;
592         }
593       else
594         width += logical_rect.width;
595       
596       height += logical_rect.height;
597
598       g_object_unref (layout);
599       g_free (buf);
600     }
601   
602   if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
603       pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
604     gtk_widget_style_get (widget,
605                           "min-horizontal-bar-width", &min_width,
606                           "min-horizontal-bar-height", &min_height,
607                           NULL);
608   else
609     gtk_widget_style_get (widget,
610                           "min-vertical-bar-width", &min_width,
611                           "min-vertical-bar-height", &min_height,
612                           NULL);
613
614   requisition->width = MAX (min_width, width);
615   requisition->height = MAX (min_height, height);
616 }
617
618 static void
619 gtk_progress_bar_style_set (GtkWidget      *widget,
620     GtkStyle *previous)
621 {
622   GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
623
624   pbar->dirty = TRUE;
625
626   GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->style_set (widget, previous);
627 }
628
629 static void
630 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
631 {
632   GtkProgressBar *pbar;
633   GtkWidget *widget;
634   GtkProgressBarOrientation orientation;
635
636   pbar = GTK_PROGRESS_BAR (progress);
637   widget = GTK_WIDGET (progress);
638
639   orientation = pbar->orientation;
640   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
641     {
642       if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
643         orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
644       else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
645         orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
646     }
647   
648   /* calculate start pos */
649
650   if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
651       orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
652     {
653       if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
654         {
655           pbar->activity_pos = widget->style->xthickness;
656           pbar->activity_dir = 0;
657         }
658       else
659         {
660           pbar->activity_pos = widget->allocation.width - 
661             widget->style->xthickness - (widget->allocation.height - 
662                 widget->style->ythickness * 2);
663           pbar->activity_dir = 1;
664         }
665     }
666   else
667     {
668       if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
669         {
670           pbar->activity_pos = widget->style->ythickness;
671           pbar->activity_dir = 0;
672         }
673       else
674         {
675           pbar->activity_pos = widget->allocation.height -
676             widget->style->ythickness - (widget->allocation.width - 
677                 widget->style->xthickness * 2);
678           pbar->activity_dir = 1;
679         }
680     }
681 }
682
683 static void
684 gtk_progress_bar_get_activity (GtkProgressBar            *pbar,
685                                GtkProgressBarOrientation  orientation,
686                                gint                      *offset,
687                                gint                      *amount)
688 {
689   GtkWidget *widget = GTK_WIDGET (pbar);
690
691   *offset = pbar->activity_pos;
692
693   switch (orientation)
694     {
695     case GTK_PROGRESS_LEFT_TO_RIGHT:
696     case GTK_PROGRESS_RIGHT_TO_LEFT:
697       *amount = MAX (2, widget->allocation.width / pbar->activity_blocks);
698       break;
699
700     case GTK_PROGRESS_TOP_TO_BOTTOM:
701     case GTK_PROGRESS_BOTTOM_TO_TOP:
702       *amount = MAX (2, widget->allocation.height / pbar->activity_blocks);
703       break;
704     }
705 }
706
707 static void
708 gtk_progress_bar_paint_activity (GtkProgressBar            *pbar,
709                                  GtkProgressBarOrientation  orientation)
710 {
711   GtkWidget *widget = GTK_WIDGET (pbar);
712   GtkProgress *progress = GTK_PROGRESS (pbar);
713   GdkRectangle area;
714
715   switch (orientation)
716     {
717     case GTK_PROGRESS_LEFT_TO_RIGHT:
718     case GTK_PROGRESS_RIGHT_TO_LEFT:
719       gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
720       area.y = widget->style->ythickness;
721       area.height = widget->allocation.height - 2 * widget->style->ythickness;
722       break;
723
724     case GTK_PROGRESS_TOP_TO_BOTTOM:
725     case GTK_PROGRESS_BOTTOM_TO_TOP:
726       gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
727       area.x = widget->style->xthickness;
728       area.width = widget->allocation.width - 2 * widget->style->xthickness;
729       break;
730
731     default:
732       return;
733       break;
734     }
735
736   gtk_paint_box (widget->style,
737                  progress->offscreen_pixmap,
738                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
739                  &area, widget, "bar",
740                  area.x, area.y, area.width, area.height);
741 }
742
743 static void
744 gtk_progress_bar_paint_continuous (GtkProgressBar            *pbar,
745                                    gint                       amount,
746                                    GtkProgressBarOrientation  orientation)
747 {
748   GdkRectangle area;
749   GtkWidget *widget = GTK_WIDGET (pbar);
750
751   if (amount <= 0)
752     return;
753
754   switch (orientation)
755     {
756     case GTK_PROGRESS_LEFT_TO_RIGHT:
757     case GTK_PROGRESS_RIGHT_TO_LEFT:
758       area.width = amount;
759       area.height = widget->allocation.height - widget->style->ythickness * 2;
760       area.y = widget->style->ythickness;
761       
762       area.x = widget->style->xthickness;
763       if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
764         area.x = widget->allocation.width - amount - area.x;
765       break;
766       
767     case GTK_PROGRESS_TOP_TO_BOTTOM:
768     case GTK_PROGRESS_BOTTOM_TO_TOP:
769       area.width = widget->allocation.width - widget->style->xthickness * 2;
770       area.height = amount;
771       area.x = widget->style->xthickness;
772       
773       area.y = widget->style->ythickness;
774       if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
775         area.y = widget->allocation.height - amount - area.y;
776       break;
777       
778     default:
779       return;
780       break;
781     }
782   
783   gtk_paint_box (widget->style,
784                  GTK_PROGRESS (pbar)->offscreen_pixmap,
785                  GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
786                  &area, widget, "bar",
787                  area.x, area.y, area.width, area.height);
788 }
789
790 static void
791 gtk_progress_bar_paint_discrete (GtkProgressBar            *pbar,
792                                  GtkProgressBarOrientation  orientation)
793 {
794   GtkWidget *widget = GTK_WIDGET (pbar);
795   gint i;
796
797   for (i = 0; i <= pbar->in_block; i++)
798     {
799       GdkRectangle area;
800       gint space;
801
802       switch (orientation)
803         {
804         case GTK_PROGRESS_LEFT_TO_RIGHT:
805         case GTK_PROGRESS_RIGHT_TO_LEFT:
806           space = widget->allocation.width - 2 * widget->style->xthickness;
807           
808           area.x = widget->style->xthickness + (i * space) / pbar->blocks;
809           area.y = widget->style->ythickness;
810           area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
811           area.height = widget->allocation.height - 2 * widget->style->ythickness;
812
813           if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
814             area.x = widget->allocation.width - area.width - area.x;
815           break;
816           
817         case GTK_PROGRESS_TOP_TO_BOTTOM:
818         case GTK_PROGRESS_BOTTOM_TO_TOP:
819           space = widget->allocation.height - 2 * widget->style->ythickness;
820           
821           area.x = widget->style->xthickness;
822           area.y = widget->style->ythickness + (i * space) / pbar->blocks;
823           area.width = widget->allocation.width - 2 * widget->style->xthickness;
824           area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
825           
826           if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
827             area.y = widget->allocation.height - area.height - area.y;
828           break;
829
830         default:
831           return;
832           break;
833         }
834       
835       gtk_paint_box (widget->style,
836                      GTK_PROGRESS (pbar)->offscreen_pixmap,
837                      GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
838                      &area, widget, "bar",
839                      area.x, area.y, area.width, area.height);
840     }
841 }
842
843 static void
844 gtk_progress_bar_paint_text (GtkProgressBar            *pbar,
845                              gint                       offset,
846                              gint                       amount,
847                              GtkProgressBarOrientation  orientation)
848 {
849   GtkProgress *progress = GTK_PROGRESS (pbar);
850   GtkWidget *widget = GTK_WIDGET (pbar);
851   gint x;
852   gint y;
853   gchar *buf;
854   GdkRectangle rect;
855   PangoLayout *layout;
856   PangoRectangle logical_rect;
857   GdkRectangle prelight_clip, start_clip, end_clip;
858   gfloat text_xalign = progress->x_align;
859   gfloat text_yalign = progress->y_align;
860
861   if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
862     text_xalign = 1.0 - text_xalign;
863
864   buf = gtk_progress_get_current_text (progress);
865   
866   layout = gtk_widget_create_pango_layout (widget, buf);
867   pango_layout_set_ellipsize (layout, pbar->ellipsize);
868   if (pbar->ellipsize)
869     pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
870
871   pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
872   
873   x = widget->style->xthickness + 1 + text_xalign *
874       (widget->allocation.width - 2 * widget->style->xthickness -
875        2 - logical_rect.width);
876
877   y = widget->style->ythickness + 1 + text_yalign *
878       (widget->allocation.height - 2 * widget->style->ythickness -
879        2 - logical_rect.height);
880
881   rect.x = widget->style->xthickness;
882   rect.y = widget->style->ythickness;
883   rect.width = widget->allocation.width - 2 * widget->style->xthickness;
884   rect.height = widget->allocation.height - 2 * widget->style->ythickness;
885
886   prelight_clip = start_clip = end_clip = rect;
887
888   switch (orientation)
889     {
890     case GTK_PROGRESS_LEFT_TO_RIGHT:
891       if (offset != -1)
892         prelight_clip.x = offset;
893       prelight_clip.width = amount;
894       start_clip.width = prelight_clip.x - start_clip.x;
895       end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
896       end_clip.width -= prelight_clip.width + start_clip.width;
897       break;
898       
899     case GTK_PROGRESS_RIGHT_TO_LEFT:
900       if (offset != -1)
901         prelight_clip.x = offset;
902       else
903         prelight_clip.x = rect.x + rect.width - amount;
904       prelight_clip.width = amount;
905       start_clip.width = prelight_clip.x - start_clip.x;
906       end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
907       end_clip.width -= prelight_clip.width + start_clip.width;
908       break;
909        
910     case GTK_PROGRESS_TOP_TO_BOTTOM:
911       if (offset != -1)
912         prelight_clip.y = offset;
913       prelight_clip.height = amount;
914       start_clip.height = prelight_clip.y - start_clip.y;
915       end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
916       end_clip.height -= prelight_clip.height + start_clip.height;
917       break;
918       
919     case GTK_PROGRESS_BOTTOM_TO_TOP:
920       if (offset != -1)
921         prelight_clip.y = offset;
922       else
923         prelight_clip.y = rect.y + rect.height - amount;
924       prelight_clip.height = amount;
925       start_clip.height = prelight_clip.y - start_clip.y;
926       end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
927       end_clip.height -= prelight_clip.height + start_clip.height;
928       break;
929     }
930
931   if (start_clip.width > 0 && start_clip.height > 0)
932     gtk_paint_layout (widget->style,
933                       progress->offscreen_pixmap,
934                       GTK_STATE_NORMAL,
935                       FALSE,
936                       &start_clip,
937                       widget,
938                       "progressbar",
939                       x, y,
940                       layout);
941
942   if (end_clip.width > 0 && end_clip.height > 0)
943     gtk_paint_layout (widget->style,
944                       progress->offscreen_pixmap,
945                       GTK_STATE_NORMAL,
946                       FALSE,
947                       &end_clip,
948                       widget,
949                       "progressbar",
950                       x, y,
951                       layout);
952
953   gtk_paint_layout (widget->style,
954                     progress->offscreen_pixmap,
955                     GTK_STATE_PRELIGHT,
956                     FALSE,
957                     &prelight_clip,
958                     widget,
959                     "progressbar",
960                     x, y,
961                     layout);
962
963   g_object_unref (layout);
964   g_free (buf);
965 }
966
967 static void
968 gtk_progress_bar_paint (GtkProgress *progress)
969 {
970   GtkProgressBar *pbar;
971   GtkWidget *widget;
972
973   GtkProgressBarOrientation orientation;
974
975   g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
976
977   pbar = GTK_PROGRESS_BAR (progress);
978   widget = GTK_WIDGET (progress);
979
980   orientation = pbar->orientation;
981   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
982     {
983       if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
984         orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
985       else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
986         orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
987     }
988  
989   if (progress->offscreen_pixmap)
990     {
991       gtk_paint_box (widget->style,
992                      progress->offscreen_pixmap,
993                      GTK_STATE_NORMAL, GTK_SHADOW_IN, 
994                      NULL, widget, "trough",
995                      0, 0,
996                      widget->allocation.width,
997                      widget->allocation.height);
998       
999       if (progress->activity_mode)
1000         {
1001           gtk_progress_bar_paint_activity (pbar, orientation);
1002
1003           if (GTK_PROGRESS (pbar)->show_text)
1004             {
1005               gint offset;
1006               gint amount;
1007
1008               gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
1009               gtk_progress_bar_paint_text (pbar, offset, amount, orientation);
1010             }
1011         }
1012       else
1013         {
1014           gint amount;
1015           gint space;
1016           
1017           if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
1018               orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
1019             space = widget->allocation.width - 2 * widget->style->xthickness;
1020           else
1021             space = widget->allocation.height - 2 * widget->style->ythickness;
1022           
1023           amount = space *
1024             gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1025           
1026           if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
1027             {
1028               gtk_progress_bar_paint_continuous (pbar, amount, orientation);
1029
1030               if (GTK_PROGRESS (pbar)->show_text)
1031                 gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
1032             }
1033           else
1034             gtk_progress_bar_paint_discrete (pbar, orientation);
1035         }
1036
1037       pbar->dirty = FALSE;
1038     }
1039 }
1040
1041 static void
1042 gtk_progress_bar_set_bar_style_internal (GtkProgressBar     *pbar,
1043                                          GtkProgressBarStyle bar_style)
1044 {
1045   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1046
1047   if (pbar->bar_style != bar_style)
1048     {
1049       pbar->bar_style = bar_style;
1050
1051       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1052         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1053
1054       g_object_notify (G_OBJECT (pbar), "bar-style");
1055     }
1056 }
1057
1058 static void
1059 gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
1060                                                guint           blocks)
1061 {
1062   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1063   g_return_if_fail (blocks > 1);
1064
1065   if (pbar->blocks != blocks)
1066     {
1067       pbar->blocks = blocks;
1068
1069       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1070         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1071
1072       g_object_notify (G_OBJECT (pbar), "discrete-blocks");
1073     }
1074 }
1075
1076 static void
1077 gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
1078                                              guint           step)
1079 {
1080   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1081
1082   if (pbar->activity_step != step)
1083     {
1084       pbar->activity_step = step;
1085       g_object_notify (G_OBJECT (pbar), "activity-step");
1086     }
1087 }
1088
1089 static void
1090 gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
1091                                                guint           blocks)
1092 {
1093   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1094   g_return_if_fail (blocks > 1);
1095
1096   if (pbar->activity_blocks != blocks)
1097     {
1098       pbar->activity_blocks = blocks;
1099       g_object_notify (G_OBJECT (pbar), "activity-blocks");
1100     }
1101 }
1102
1103 /*******************************************************************/
1104
1105 /**
1106  * gtk_progress_bar_set_fraction:
1107  * @pbar: a #GtkProgressBar
1108  * @fraction: fraction of the task that's been completed
1109  * 
1110  * Causes the progress bar to "fill in" the given fraction
1111  * of the bar. The fraction should be between 0.0 and 1.0,
1112  * inclusive.
1113  * 
1114  **/
1115 void
1116 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
1117                                gdouble         fraction)
1118 {
1119   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1120
1121   /* If we know the percentage, we don't want activity mode. */
1122   gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
1123   
1124   /* We use the deprecated GtkProgress interface internally.
1125    * Once everything's been deprecated for a good long time,
1126    * we can clean up all this code.
1127    */
1128   gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
1129
1130   g_object_notify (G_OBJECT (pbar), "fraction");
1131 }
1132
1133 /**
1134  * gtk_progress_bar_pulse:
1135  * @pbar: a #GtkProgressBar
1136  * 
1137  * Indicates that some progress is made, but you don't know how much.
1138  * Causes the progress bar to enter "activity mode," where a block
1139  * bounces back and forth. Each call to gtk_progress_bar_pulse()
1140  * causes the block to move by a little bit (the amount of movement
1141  * per pulse is determined by gtk_progress_bar_set_pulse_step()).
1142  **/
1143 void
1144 gtk_progress_bar_pulse (GtkProgressBar *pbar)
1145 {  
1146   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1147
1148   /* If we don't know the percentage, we must want activity mode. */
1149   gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
1150
1151   /* Sigh. */
1152   gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
1153 }
1154
1155 /**
1156  * gtk_progress_bar_set_text:
1157  * @pbar: a #GtkProgressBar
1158  * @text: (allow-none): a UTF-8 string, or %NULL 
1159  * 
1160  * Causes the given @text to appear superimposed on the progress bar.
1161  **/
1162 void
1163 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1164                            const gchar    *text)
1165 {
1166   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1167   
1168   gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
1169   gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
1170   
1171   /* We don't support formats in this interface, but turn
1172    * them back on for NULL, which should put us back to
1173    * the initial state.
1174    */
1175   GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
1176   
1177   g_object_notify (G_OBJECT (pbar), "text");
1178 }
1179
1180 /**
1181  * gtk_progress_bar_set_pulse_step:
1182  * @pbar: a #GtkProgressBar
1183  * @fraction: fraction between 0.0 and 1.0
1184  * 
1185  * Sets the fraction of total progress bar length to move the
1186  * bouncing block for each call to gtk_progress_bar_pulse().
1187  **/
1188 void
1189 gtk_progress_bar_set_pulse_step   (GtkProgressBar *pbar,
1190                                    gdouble         fraction)
1191 {
1192   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1193   
1194   pbar->pulse_fraction = fraction;
1195
1196   g_object_notify (G_OBJECT (pbar), "pulse-step");
1197 }
1198
1199 void
1200 gtk_progress_bar_update (GtkProgressBar *pbar,
1201                          gdouble         percentage)
1202 {
1203   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1204
1205   /* Use of gtk_progress_bar_update() is deprecated ! 
1206    * Use gtk_progress_bar_set_percentage ()
1207    */   
1208
1209   gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
1210 }
1211
1212 /**
1213  * gtk_progress_bar_set_orientation:
1214  * @pbar: a #GtkProgressBar
1215  * @orientation: orientation of the progress bar
1216  * 
1217  * Causes the progress bar to switch to a different orientation
1218  * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top). 
1219  **/
1220 void
1221 gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
1222                                   GtkProgressBarOrientation orientation)
1223 {
1224   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1225
1226   if (pbar->orientation != orientation)
1227     {
1228       pbar->orientation = orientation;
1229
1230       if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1231         gtk_widget_queue_resize (GTK_WIDGET (pbar));
1232
1233       g_object_notify (G_OBJECT (pbar), "orientation");
1234     }
1235 }
1236
1237 /**
1238  * gtk_progress_bar_get_text:
1239  * @pbar: a #GtkProgressBar
1240  * 
1241  * Retrieves the text displayed superimposed on the progress bar,
1242  * if any, otherwise %NULL. The return value is a reference
1243  * to the text, not a copy of it, so will become invalid
1244  * if you change the text in the progress bar.
1245  * 
1246  * Return value: text, or %NULL; this string is owned by the widget
1247  * and should not be modified or freed.
1248  **/
1249 G_CONST_RETURN gchar*
1250 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1251 {
1252   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1253
1254   if (GTK_PROGRESS (pbar)->use_text_format)
1255     return NULL;
1256   else
1257     return GTK_PROGRESS (pbar)->format;
1258 }
1259
1260 /**
1261  * gtk_progress_bar_get_fraction:
1262  * @pbar: a #GtkProgressBar
1263  * 
1264  * Returns the current fraction of the task that's been completed.
1265  * 
1266  * Return value: a fraction from 0.0 to 1.0
1267  **/
1268 gdouble
1269 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1270 {
1271   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1272
1273   return gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1274 }
1275
1276 /**
1277  * gtk_progress_bar_get_pulse_step:
1278  * @pbar: a #GtkProgressBar
1279  * 
1280  * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1281  * 
1282  * Return value: a fraction from 0.0 to 1.0
1283  **/
1284 gdouble
1285 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1286 {
1287   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1288
1289   return pbar->pulse_fraction;
1290 }
1291
1292 /**
1293  * gtk_progress_bar_get_orientation:
1294  * @pbar: a #GtkProgressBar
1295  * 
1296  * Retrieves the current progress bar orientation.
1297  * 
1298  * Return value: orientation of the progress bar
1299  **/
1300 GtkProgressBarOrientation
1301 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1302 {
1303   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1304
1305   return pbar->orientation;
1306 }
1307
1308 void
1309 gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
1310                                 GtkProgressBarStyle bar_style)
1311 {
1312   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1313
1314   gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
1315 }
1316
1317 void
1318 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
1319                                       guint           blocks)
1320 {
1321   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1322   g_return_if_fail (blocks > 1);
1323
1324   gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
1325 }
1326
1327 void
1328 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
1329                                     guint           step)
1330 {
1331   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1332
1333   gtk_progress_bar_set_activity_step_internal (pbar, step);
1334 }
1335
1336 void
1337 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
1338                                       guint           blocks)
1339 {
1340   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1341   g_return_if_fail (blocks > 1);
1342
1343   gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);
1344 }
1345
1346 /**
1347  * gtk_progress_bar_set_ellipsize:
1348  * @pbar: a #GtkProgressBar
1349  * @mode: a #PangoEllipsizeMode
1350  *
1351  * Sets the mode used to ellipsize (add an ellipsis: "...") the text 
1352  * if there is not enough space to render the entire string.
1353  *
1354  * Since: 2.6
1355  **/
1356 void
1357 gtk_progress_bar_set_ellipsize (GtkProgressBar     *pbar,
1358                                 PangoEllipsizeMode  mode)
1359 {
1360   g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1361   g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE && 
1362                     mode <= PANGO_ELLIPSIZE_END);
1363   
1364   if ((PangoEllipsizeMode)pbar->ellipsize != mode)
1365     {
1366       pbar->ellipsize = mode;
1367
1368       g_object_notify (G_OBJECT (pbar), "ellipsize");
1369       gtk_widget_queue_resize (GTK_WIDGET (pbar));
1370     }
1371 }
1372
1373 /**
1374  * gtk_progress_bar_get_ellipsize:
1375  * @pbar: a #GtkProgressBar
1376  *
1377  * Returns the ellipsizing position of the progressbar. 
1378  * See gtk_progress_bar_set_ellipsize().
1379  *
1380  * Return value: #PangoEllipsizeMode
1381  *
1382  * Since: 2.6
1383  **/
1384 PangoEllipsizeMode 
1385 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1386 {
1387   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1388
1389   return pbar->ellipsize;
1390 }
1391
1392 #include "gtkaliasdef.c"