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