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