1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
31 #include "gtkprogressbar.h"
32 #include "gtkorientable.h"
33 #include "gtkprivate.h"
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
43 struct _GtkProgressBarPrivate
45 GtkOrientation orientation;
50 gdouble pulse_fraction;
56 guint activity_blocks;
59 guint activity_dir : 1;
60 guint activity_mode : 1;
77 static void gtk_progress_bar_set_property (GObject *object,
81 static void gtk_progress_bar_get_property (GObject *object,
85 static void gtk_progress_bar_size_request (GtkWidget *widget,
86 GtkRequisition *requisition);
87 static void gtk_progress_bar_real_update (GtkProgressBar *progress);
88 static gboolean gtk_progress_bar_draw (GtkWidget *widget,
90 static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress);
91 static void gtk_progress_bar_finalize (GObject *object);
92 static void gtk_progress_bar_set_orientation (GtkProgressBar *progress,
93 GtkOrientation orientation);
95 G_DEFINE_TYPE_WITH_CODE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET,
96 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
99 gtk_progress_bar_class_init (GtkProgressBarClass *class)
101 GObjectClass *gobject_class;
102 GtkWidgetClass *widget_class;
104 gobject_class = G_OBJECT_CLASS (class);
105 widget_class = (GtkWidgetClass *) class;
107 gobject_class->set_property = gtk_progress_bar_set_property;
108 gobject_class->get_property = gtk_progress_bar_get_property;
109 gobject_class->finalize = gtk_progress_bar_finalize;
111 widget_class->draw = gtk_progress_bar_draw;
112 widget_class->size_request = gtk_progress_bar_size_request;
114 g_object_class_override_property (gobject_class,
118 g_object_class_install_property (gobject_class,
120 g_param_spec_boolean ("inverted",
122 P_("Invert the direction in which the progress bar grows"),
124 GTK_PARAM_READWRITE));
126 g_object_class_install_property (gobject_class,
128 g_param_spec_double ("fraction",
130 P_("The fraction of total work that has been completed"),
132 GTK_PARAM_READWRITE));
134 g_object_class_install_property (gobject_class,
136 g_param_spec_double ("pulse-step",
138 P_("The fraction of total progress to move the bouncing block when pulsed"),
140 GTK_PARAM_READWRITE));
142 g_object_class_install_property (gobject_class,
144 g_param_spec_string ("text",
146 P_("Text to be displayed in the progress bar"),
148 GTK_PARAM_READWRITE));
150 g_object_class_install_property (gobject_class,
152 g_param_spec_boolean ("show-text",
154 P_("Whether the progress is shown as text."),
156 GTK_PARAM_READWRITE));
159 * GtkProgressBar:ellipsize:
161 * The preferred place to ellipsize the string, if the progressbar does
162 * not have enough room to display the entire string, specified as a
163 * #PangoEllisizeMode.
165 * Note that setting this property to a value other than
166 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
167 * only enough space to display the ellipsis "...". Another means to set a
168 * progressbar's width is gtk_widget_set_size_request().
172 g_object_class_install_property (gobject_class,
174 g_param_spec_enum ("ellipsize",
176 P_("The preferred place to ellipsize the string, if the progress bar "
177 "does not have enough room to display the entire string, if at all."),
178 PANGO_TYPE_ELLIPSIZE_MODE,
179 PANGO_ELLIPSIZE_NONE,
180 GTK_PARAM_READWRITE));
181 gtk_widget_class_install_style_property (widget_class,
182 g_param_spec_int ("xspacing",
184 P_("Extra spacing applied to the width of a progress bar."),
187 gtk_widget_class_install_style_property (widget_class,
188 g_param_spec_int ("yspacing",
190 P_("Extra spacing applied to the height of a progress bar."),
195 * GtkProgressBar:min-horizontal-bar-width:
197 * The minimum horizontal width of the progress bar.
201 gtk_widget_class_install_style_property (widget_class,
202 g_param_spec_int ("min-horizontal-bar-width",
203 P_("Minimum horizontal bar width"),
204 P_("The minimum horizontal width of the progress bar"),
205 1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
208 * GtkProgressBar:min-horizontal-bar-height:
210 * Minimum horizontal height of the progress bar.
214 gtk_widget_class_install_style_property (widget_class,
215 g_param_spec_int ("min-horizontal-bar-height",
216 P_("Minimum horizontal bar height"),
217 P_("Minimum horizontal height of the progress bar"),
218 1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
221 * GtkProgressBar:min-vertical-bar-width:
223 * The minimum vertical width of the progress bar.
227 gtk_widget_class_install_style_property (widget_class,
228 g_param_spec_int ("min-vertical-bar-width",
229 P_("Minimum vertical bar width"),
230 P_("The minimum vertical width of the progress bar"),
231 1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
234 * GtkProgressBar:min-vertical-bar-height:
236 * The minimum vertical height of the progress bar.
240 gtk_widget_class_install_style_property (widget_class,
241 g_param_spec_int ("min-vertical-bar-height",
242 P_("Minimum vertical bar height"),
243 P_("The minimum vertical height of the progress bar"),
244 1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
247 g_type_class_add_private (class, sizeof (GtkProgressBarPrivate));
251 gtk_progress_bar_init (GtkProgressBar *pbar)
253 GtkProgressBarPrivate *priv;
255 pbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (pbar,
256 GTK_TYPE_PROGRESS_BAR,
257 GtkProgressBarPrivate);
262 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
263 priv->inverted = FALSE;
264 priv->pulse_fraction = 0.1;
265 priv->activity_pos = 0;
266 priv->activity_dir = 1;
267 priv->activity_step = 3;
268 priv->activity_blocks = 5;
269 priv->ellipsize = PANGO_ELLIPSIZE_NONE;
270 priv->show_text = FALSE;
273 priv->fraction = 0.0;
275 gtk_widget_set_has_window (GTK_WIDGET (pbar), FALSE);
279 gtk_progress_bar_set_property (GObject *object,
284 GtkProgressBar *pbar;
286 pbar = GTK_PROGRESS_BAR (object);
290 case PROP_ORIENTATION:
291 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
294 gtk_progress_bar_set_inverted (pbar, g_value_get_boolean (value));
297 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
299 case PROP_PULSE_STEP:
300 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
303 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
306 gtk_progress_bar_set_show_text (pbar, g_value_get_boolean (value));
309 gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
318 gtk_progress_bar_get_property (GObject *object,
323 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
324 GtkProgressBarPrivate* priv = pbar->priv;
328 case PROP_ORIENTATION:
329 g_value_set_enum (value, priv->orientation);
332 g_value_set_boolean (value, priv->inverted);
335 g_value_set_double (value, priv->fraction);
337 case PROP_PULSE_STEP:
338 g_value_set_double (value, priv->pulse_fraction);
341 g_value_set_string (value, priv->text);
344 g_value_set_boolean (value, priv->show_text);
347 g_value_set_enum (value, priv->ellipsize);
350 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
356 gtk_progress_bar_new (void)
360 pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
366 gtk_progress_bar_real_update (GtkProgressBar *pbar)
368 GtkProgressBarPrivate *priv;
371 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
374 widget = GTK_WIDGET (pbar);
376 if (priv->activity_mode)
378 GtkAllocation allocation;
382 gtk_widget_get_allocation (widget, &allocation);
383 style = gtk_widget_get_style (widget);
385 /* advance the block */
386 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
388 /* Update our activity step. */
389 priv->activity_step = allocation.width * priv->pulse_fraction;
391 size = MAX (2, allocation.width / priv->activity_blocks);
393 if (priv->activity_dir == 0)
395 priv->activity_pos += priv->activity_step;
396 if (priv->activity_pos + size >= allocation.width - style->xthickness)
398 priv->activity_pos = allocation.width - style->xthickness - size;
399 priv->activity_dir = 1;
404 priv->activity_pos -= priv->activity_step;
405 if (priv->activity_pos <= style->xthickness)
407 priv->activity_pos = style->xthickness;
408 priv->activity_dir = 0;
414 /* Update our activity step. */
415 priv->activity_step = allocation.height * priv->pulse_fraction;
417 size = MAX (2, allocation.height / priv->activity_blocks);
419 if (priv->activity_dir == 0)
421 priv->activity_pos += priv->activity_step;
422 if (priv->activity_pos + size >= allocation.height - style->ythickness)
424 priv->activity_pos = allocation.height - style->ythickness - size;
425 priv->activity_dir = 1;
430 priv->activity_pos -= priv->activity_step;
431 if (priv->activity_pos <= style->ythickness)
433 priv->activity_pos = style->ythickness;
434 priv->activity_dir = 0;
439 gtk_widget_queue_draw (widget);
443 gtk_progress_bar_finalize (GObject *object)
445 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
446 GtkProgressBarPrivate *priv = pbar->priv;
450 G_OBJECT_CLASS (gtk_progress_bar_parent_class)->finalize (object);
454 get_current_text (GtkProgressBar *pbar)
456 GtkProgressBarPrivate *priv = pbar->priv;
459 return g_strdup (priv->text);
461 return g_strdup_printf ("%.0f %%", priv->fraction * 100.0);
465 gtk_progress_bar_size_request (GtkWidget *widget,
466 GtkRequisition *requisition)
468 GtkProgressBar *pbar;
469 GtkProgressBarPrivate *priv;
472 PangoRectangle logical_rect;
475 gint xspacing, yspacing;
476 gint min_width, min_height;
478 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
479 g_return_if_fail (requisition != NULL);
481 style = gtk_widget_get_style (widget);
482 gtk_widget_style_get (widget,
483 "xspacing", &xspacing,
484 "yspacing", &yspacing,
487 pbar = GTK_PROGRESS_BAR (widget);
490 width = 2 * style->xthickness + xspacing;
491 height = 2 * style->ythickness + yspacing;
495 buf = get_current_text (pbar);
496 layout = gtk_widget_create_pango_layout (widget, buf);
498 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
502 PangoContext *context;
503 PangoFontMetrics *metrics;
506 /* The minimum size for ellipsized text is ~ 3 chars */
507 context = pango_layout_get_context (layout);
508 metrics = pango_context_get_metrics (context, style->font_desc, pango_context_get_language (context));
510 char_width = pango_font_metrics_get_approximate_char_width (metrics);
511 pango_font_metrics_unref (metrics);
513 width += PANGO_PIXELS (char_width) * 3;
516 width += logical_rect.width;
518 height += logical_rect.height;
520 g_object_unref (layout);
524 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
525 gtk_widget_style_get (widget,
526 "min-horizontal-bar-width", &min_width,
527 "min-horizontal-bar-height", &min_height,
530 gtk_widget_style_get (widget,
531 "min-vertical-bar-width", &min_width,
532 "min-vertical-bar-height", &min_height,
535 requisition->width = MAX (min_width, width);
536 requisition->height = MAX (min_height, height);
540 gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
542 GtkProgressBarPrivate *priv = pbar->priv;
543 GtkAllocation allocation;
545 GtkWidget *widget = GTK_WIDGET (pbar);
546 GtkOrientation orientation;
549 style = gtk_widget_get_style (widget);
551 orientation = priv->orientation;
552 inverted = priv->inverted;
553 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
555 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
556 inverted = !inverted;
559 /* calculate start pos */
561 if (orientation == GTK_ORIENTATION_HORIZONTAL)
565 priv->activity_pos = style->xthickness;
566 priv->activity_dir = 0;
570 gtk_widget_get_allocation (widget, &allocation);
571 priv->activity_pos = allocation.width - style->xthickness -
572 (allocation.height - style->ythickness * 2);
573 priv->activity_dir = 1;
580 priv->activity_pos = style->ythickness;
581 priv->activity_dir = 0;
585 gtk_widget_get_allocation (widget, &allocation);
586 priv->activity_pos = allocation.height - style->ythickness -
587 (allocation.width - style->xthickness * 2);
588 priv->activity_dir = 1;
594 gtk_progress_bar_get_activity (GtkProgressBar *pbar,
595 GtkOrientation orientation,
599 GtkProgressBarPrivate *priv = pbar->priv;
600 GtkAllocation allocation;
601 GtkWidget *widget = GTK_WIDGET (pbar);
603 *offset = priv->activity_pos;
605 gtk_widget_get_allocation (widget, &allocation);
607 if (orientation == GTK_ORIENTATION_HORIZONTAL)
608 *amount = MAX (2, allocation.width / priv->activity_blocks);
610 *amount = MAX (2, allocation.height / priv->activity_blocks);
614 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
616 GtkOrientation orientation,
622 GtkWidget *widget = GTK_WIDGET (pbar);
625 style = gtk_widget_get_style (widget);
627 if (orientation == GTK_ORIENTATION_HORIZONTAL)
629 gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
630 area.y = style->ythickness;
631 area.height = height - 2 * style->ythickness;
635 gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
636 area.x = style->xthickness;
637 area.width = width - 2 * style->xthickness;
640 gtk_paint_box (style,
642 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
644 area.x, area.y, area.width, area.height);
648 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
651 GtkOrientation orientation,
657 GtkWidget *widget = GTK_WIDGET (pbar);
663 style = gtk_widget_get_style (widget);
665 if (orientation == GTK_ORIENTATION_HORIZONTAL)
668 area.height = height - style->ythickness * 2;
669 area.y = style->ythickness;
671 area.x = style->xthickness;
673 area.x = width - amount - area.x;
677 area.width = width - style->xthickness * 2;
678 area.height = amount;
679 area.x = style->xthickness;
681 area.y = style->ythickness;
683 area.y = height - amount - area.y;
686 gtk_paint_box (style,
688 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
690 area.x, area.y, area.width, area.height);
694 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
698 GtkOrientation orientation,
703 GtkProgressBarPrivate *priv = pbar->priv;
705 GtkWidget *widget = GTK_WIDGET (pbar);
711 PangoRectangle logical_rect;
712 GdkRectangle prelight_clip, start_clip, end_clip;
713 gfloat text_xalign = 0.5;
714 gfloat text_yalign = 0.5;
716 style = gtk_widget_get_style (widget);
718 if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
719 text_xalign = 1.0 - text_xalign;
721 buf = get_current_text (pbar);
723 layout = gtk_widget_create_pango_layout (widget, buf);
724 pango_layout_set_ellipsize (layout, priv->ellipsize);
726 pango_layout_set_width (layout, width * PANGO_SCALE);
728 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
730 x = style->xthickness + 1 + text_xalign * (width - 2 * style->xthickness - 2 - logical_rect.width);
732 y = style->ythickness + 1 + text_yalign * (height - 2 * style->ythickness - 2 - logical_rect.height);
734 rect.x = style->xthickness;
735 rect.y = style->ythickness;
736 rect.width = width - 2 * style->xthickness;
737 rect.height = height - 2 * style->ythickness;
739 prelight_clip = start_clip = end_clip = rect;
741 if (orientation == GTK_ORIENTATION_HORIZONTAL)
746 prelight_clip.x = offset;
747 prelight_clip.width = amount;
748 start_clip.width = prelight_clip.x - start_clip.x;
749 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
750 end_clip.width -= prelight_clip.width + start_clip.width;
755 prelight_clip.x = offset;
757 prelight_clip.x = rect.x + rect.width - amount;
758 prelight_clip.width = amount;
759 start_clip.width = prelight_clip.x - start_clip.x;
760 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
761 end_clip.width -= prelight_clip.width + start_clip.width;
769 prelight_clip.y = offset;
770 prelight_clip.height = amount;
771 start_clip.height = prelight_clip.y - start_clip.y;
772 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
773 end_clip.height -= prelight_clip.height + start_clip.height;
778 prelight_clip.y = offset;
780 prelight_clip.y = rect.y + rect.height - amount;
781 prelight_clip.height = amount;
782 start_clip.height = prelight_clip.y - start_clip.y;
783 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
784 end_clip.height -= prelight_clip.height + start_clip.height;
788 if (start_clip.width > 0 && start_clip.height > 0)
791 gdk_cairo_rectangle (cr, &start_clip);
793 gtk_paint_layout (style,
804 if (end_clip.width > 0 && end_clip.height > 0)
807 gdk_cairo_rectangle (cr, &end_clip);
809 gtk_paint_layout (style,
821 gdk_cairo_rectangle (cr, &prelight_clip);
823 gtk_paint_layout (style,
833 g_object_unref (layout);
838 gtk_progress_bar_draw (GtkWidget *widget,
841 GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
842 GtkProgressBarPrivate *priv = pbar->priv;
843 GtkOrientation orientation;
848 style = gtk_widget_get_style (widget);
850 orientation = priv->orientation;
851 inverted = priv->inverted;
852 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
854 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
855 inverted = !inverted;
857 width = gtk_widget_get_allocated_width (widget);
858 height = gtk_widget_get_allocated_height (widget);
860 gtk_paint_box (style,
862 GTK_STATE_NORMAL, GTK_SHADOW_IN,
867 if (priv->activity_mode)
869 gtk_progress_bar_paint_activity (pbar, cr,
870 orientation, inverted,
878 gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
879 gtk_progress_bar_paint_text (pbar, cr,
881 orientation, inverted,
890 if (orientation == GTK_ORIENTATION_HORIZONTAL)
891 space = width - 2 * style->xthickness;
893 space = height - 2 * style->ythickness;
895 amount = space * gtk_progress_bar_get_fraction (pbar);
897 gtk_progress_bar_paint_continuous (pbar, cr, amount, orientation, inverted, width, height);
900 gtk_progress_bar_paint_text (pbar, cr, -1, amount, orientation, inverted, width, height);
907 gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar,
908 gboolean activity_mode)
910 GtkProgressBarPrivate *priv = pbar->priv;
912 activity_mode = !!activity_mode;
914 if (priv->activity_mode != activity_mode)
916 priv->activity_mode = activity_mode;
918 if (priv->activity_mode)
919 gtk_progress_bar_act_mode_enter (pbar);
921 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
922 gtk_widget_queue_resize (GTK_WIDGET (pbar));
927 * gtk_progress_bar_set_fraction:
928 * @pbar: a #GtkProgressBar
929 * @fraction: fraction of the task that's been completed
931 * Causes the progress bar to "fill in" the given fraction
932 * of the bar. The fraction should be between 0.0 and 1.0,
937 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
940 GtkProgressBarPrivate* priv;
942 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
946 priv->fraction = fraction;
947 gtk_progress_bar_set_activity_mode (pbar, FALSE);
948 gtk_progress_bar_real_update (pbar);
950 g_object_notify (G_OBJECT (pbar), "fraction");
954 * gtk_progress_bar_pulse:
955 * @pbar: a #GtkProgressBar
957 * Indicates that some progress is made, but you don't know how much.
958 * Causes the progress bar to enter "activity mode," where a block
959 * bounces back and forth. Each call to gtk_progress_bar_pulse()
960 * causes the block to move by a little bit (the amount of movement
961 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
964 gtk_progress_bar_pulse (GtkProgressBar *pbar)
966 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
968 gtk_progress_bar_set_activity_mode (pbar, TRUE);
969 gtk_progress_bar_real_update (pbar);
973 * gtk_progress_bar_set_text:
974 * @pbar: a #GtkProgressBar
975 * @text: (allow-none): a UTF-8 string, or %NULL
977 * Causes the given @text to appear superimposed on the progress bar.
980 gtk_progress_bar_set_text (GtkProgressBar *pbar,
983 GtkProgressBarPrivate *priv;
985 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
990 priv->text = text && *text ? g_strdup (text) : NULL;
992 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
993 gtk_widget_queue_resize (GTK_WIDGET (pbar));
995 g_object_notify (G_OBJECT (pbar), "text");
999 * gtk_progress_bar_set_show_text:
1000 * @pbar: a #GtkProgressBar
1001 * @show_text: whether to show superimposed text
1003 * Sets whether the progressbar will show text superimposed
1004 * over the bar. The shown text is either the value of
1005 * the #GtkProgressBar::text property or, if that is %NULL,
1006 * the #GtkProgressBar::fraction value, as a percentage.
1011 gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
1014 GtkProgressBarPrivate *priv;
1016 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1020 show_text = !!show_text;
1022 if (priv->show_text != show_text)
1024 priv->show_text = show_text;
1026 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1027 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1029 g_object_notify (G_OBJECT (pbar), "show-text");
1034 * gtk_progress_bar_get_show_text:
1035 * @pbar: a #GtkProgressBar
1037 * Gets the value of the #GtkProgressBar::show-text property.
1038 * See gtk_progress_bar_set_show_text().
1040 * Returns: %TRUE if text is shown in the progress bar
1045 gtk_progress_bar_get_show_text (GtkProgressBar *pbar)
1047 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1049 return pbar->priv->show_text;
1053 * gtk_progress_bar_set_pulse_step:
1054 * @pbar: a #GtkProgressBar
1055 * @fraction: fraction between 0.0 and 1.0
1057 * Sets the fraction of total progress bar length to move the
1058 * bouncing block for each call to gtk_progress_bar_pulse().
1061 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1064 GtkProgressBarPrivate *priv;
1066 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1070 priv->pulse_fraction = fraction;
1072 g_object_notify (G_OBJECT (pbar), "pulse-step");
1076 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1077 GtkOrientation orientation)
1079 GtkProgressBarPrivate *priv = pbar->priv;
1081 if (priv->orientation != orientation)
1083 priv->orientation = orientation;
1085 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1086 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1091 * gtk_progress_bar_set_inverted:
1092 * @pbar: a #GtkProgressBar
1093 * @inverted: %TRUE to invert the progress bar
1095 * Progress bars normally grow from top to bottom or left to right.
1096 * Inverted progress bars grow in the opposite direction.
1099 gtk_progress_bar_set_inverted (GtkProgressBar *pbar,
1102 GtkProgressBarPrivate *priv;
1104 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1108 if (priv->inverted != inverted)
1110 priv->inverted = inverted;
1112 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1113 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1115 g_object_notify (G_OBJECT (pbar), "inverted");
1120 * gtk_progress_bar_get_text:
1121 * @pbar: a #GtkProgressBar
1123 * Retrieves the text displayed superimposed on the progress bar,
1124 * if any, otherwise %NULL. The return value is a reference
1125 * to the text, not a copy of it, so will become invalid
1126 * if you change the text in the progress bar.
1128 * Return value: text, or %NULL; this string is owned by the widget
1129 * and should not be modified or freed.
1131 G_CONST_RETURN gchar*
1132 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1134 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1136 return pbar->priv->text;
1140 * gtk_progress_bar_get_fraction:
1141 * @pbar: a #GtkProgressBar
1143 * Returns the current fraction of the task that's been completed.
1145 * Return value: a fraction from 0.0 to 1.0
1148 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1150 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1152 return pbar->priv->fraction;
1156 * gtk_progress_bar_get_pulse_step:
1157 * @pbar: a #GtkProgressBar
1159 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1161 * Return value: a fraction from 0.0 to 1.0
1164 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1166 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1168 return pbar->priv->pulse_fraction;
1172 * gtk_progress_bar_get_inverted:
1173 * @pbar: a #GtkProgressBar
1175 * Gets the value set by gtk_progress_bar_set_inverted()
1177 * Return value: %TRUE if the progress bar is inverted
1180 gtk_progress_bar_get_inverted (GtkProgressBar *pbar)
1182 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1184 return pbar->priv->inverted;
1188 * gtk_progress_bar_set_ellipsize:
1189 * @pbar: a #GtkProgressBar
1190 * @mode: a #PangoEllipsizeMode
1192 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1193 * if there is not enough space to render the entire string.
1198 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1199 PangoEllipsizeMode mode)
1201 GtkProgressBarPrivate *priv;
1203 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1204 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1205 mode <= PANGO_ELLIPSIZE_END);
1209 if ((PangoEllipsizeMode)priv->ellipsize != mode)
1211 priv->ellipsize = mode;
1213 g_object_notify (G_OBJECT (pbar), "ellipsize");
1214 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1219 * gtk_progress_bar_get_ellipsize:
1220 * @pbar: a #GtkProgressBar
1222 * Returns the ellipsizing position of the progressbar.
1223 * See gtk_progress_bar_set_ellipsize().
1225 * Return value: #PangoEllipsizeMode
1230 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1232 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1234 return pbar->priv->ellipsize;