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_realize (GtkWidget *widget);
92 static void gtk_progress_bar_finalize (GObject *object);
93 static void gtk_progress_bar_set_orientation (GtkProgressBar *progress,
94 GtkOrientation orientation);
96 G_DEFINE_TYPE_WITH_CODE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET,
97 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
100 gtk_progress_bar_class_init (GtkProgressBarClass *class)
102 GObjectClass *gobject_class;
103 GtkWidgetClass *widget_class;
105 gobject_class = G_OBJECT_CLASS (class);
106 widget_class = (GtkWidgetClass *) class;
108 gobject_class->set_property = gtk_progress_bar_set_property;
109 gobject_class->get_property = gtk_progress_bar_get_property;
110 gobject_class->finalize = gtk_progress_bar_finalize;
112 widget_class->draw = gtk_progress_bar_draw;
113 widget_class->size_request = gtk_progress_bar_size_request;
115 g_object_class_override_property (gobject_class,
119 g_object_class_install_property (gobject_class,
121 g_param_spec_boolean ("inverted",
123 P_("Invert the direction in which the progress bar grows"),
125 GTK_PARAM_READWRITE));
127 g_object_class_install_property (gobject_class,
129 g_param_spec_double ("fraction",
131 P_("The fraction of total work that has been completed"),
133 GTK_PARAM_READWRITE));
135 g_object_class_install_property (gobject_class,
137 g_param_spec_double ("pulse-step",
139 P_("The fraction of total progress to move the bouncing block when pulsed"),
141 GTK_PARAM_READWRITE));
143 g_object_class_install_property (gobject_class,
145 g_param_spec_string ("text",
147 P_("Text to be displayed in the progress bar"),
149 GTK_PARAM_READWRITE));
151 g_object_class_install_property (gobject_class,
153 g_param_spec_boolean ("show-text",
155 P_("Whether the progress is shown as text."),
157 GTK_PARAM_READWRITE));
160 * GtkProgressBar:ellipsize:
162 * The preferred place to ellipsize the string, if the progressbar does
163 * not have enough room to display the entire string, specified as a
164 * #PangoEllisizeMode.
166 * Note that setting this property to a value other than
167 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
168 * only enough space to display the ellipsis "...". Another means to set a
169 * progressbar's width is gtk_widget_set_size_request().
173 g_object_class_install_property (gobject_class,
175 g_param_spec_enum ("ellipsize",
177 P_("The preferred place to ellipsize the string, if the progress bar "
178 "does not have enough room to display the entire string, if at all."),
179 PANGO_TYPE_ELLIPSIZE_MODE,
180 PANGO_ELLIPSIZE_NONE,
181 GTK_PARAM_READWRITE));
182 gtk_widget_class_install_style_property (widget_class,
183 g_param_spec_int ("xspacing",
185 P_("Extra spacing applied to the width of a progress bar."),
188 gtk_widget_class_install_style_property (widget_class,
189 g_param_spec_int ("yspacing",
191 P_("Extra spacing applied to the height of a progress bar."),
196 * GtkProgressBar:min-horizontal-bar-width:
198 * The minimum horizontal width of the progress bar.
202 gtk_widget_class_install_style_property (widget_class,
203 g_param_spec_int ("min-horizontal-bar-width",
204 P_("Minimum horizontal bar width"),
205 P_("The minimum horizontal width of the progress bar"),
206 1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
209 * GtkProgressBar:min-horizontal-bar-height:
211 * Minimum horizontal height of the progress bar.
215 gtk_widget_class_install_style_property (widget_class,
216 g_param_spec_int ("min-horizontal-bar-height",
217 P_("Minimum horizontal bar height"),
218 P_("Minimum horizontal height of the progress bar"),
219 1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
222 * GtkProgressBar:min-vertical-bar-width:
224 * The minimum vertical width of the progress bar.
228 gtk_widget_class_install_style_property (widget_class,
229 g_param_spec_int ("min-vertical-bar-width",
230 P_("Minimum vertical bar width"),
231 P_("The minimum vertical width of the progress bar"),
232 1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
235 * GtkProgressBar:min-vertical-bar-height:
237 * The minimum vertical height of the progress bar.
241 gtk_widget_class_install_style_property (widget_class,
242 g_param_spec_int ("min-vertical-bar-height",
243 P_("Minimum vertical bar height"),
244 P_("The minimum vertical height of the progress bar"),
245 1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
248 g_type_class_add_private (class, sizeof (GtkProgressBarPrivate));
252 gtk_progress_bar_init (GtkProgressBar *pbar)
254 GtkProgressBarPrivate *priv;
256 pbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (pbar,
257 GTK_TYPE_PROGRESS_BAR,
258 GtkProgressBarPrivate);
263 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
264 priv->inverted = FALSE;
265 priv->pulse_fraction = 0.1;
266 priv->activity_pos = 0;
267 priv->activity_dir = 1;
268 priv->activity_step = 3;
269 priv->activity_blocks = 5;
270 priv->ellipsize = PANGO_ELLIPSIZE_NONE;
271 priv->show_text = FALSE;
274 priv->fraction = 0.0;
276 gtk_widget_set_has_window (GTK_WIDGET (pbar), FALSE);
280 gtk_progress_bar_set_property (GObject *object,
285 GtkProgressBar *pbar;
287 pbar = GTK_PROGRESS_BAR (object);
291 case PROP_ORIENTATION:
292 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
295 gtk_progress_bar_set_inverted (pbar, g_value_get_boolean (value));
298 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
300 case PROP_PULSE_STEP:
301 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
304 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
307 gtk_progress_bar_set_show_text (pbar, g_value_get_boolean (value));
310 gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
319 gtk_progress_bar_get_property (GObject *object,
324 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
325 GtkProgressBarPrivate* priv = pbar->priv;
329 case PROP_ORIENTATION:
330 g_value_set_enum (value, priv->orientation);
333 g_value_set_boolean (value, priv->inverted);
336 g_value_set_double (value, priv->fraction);
338 case PROP_PULSE_STEP:
339 g_value_set_double (value, priv->pulse_fraction);
342 g_value_set_string (value, priv->text);
345 g_value_set_boolean (value, priv->show_text);
348 g_value_set_enum (value, priv->ellipsize);
351 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
357 gtk_progress_bar_new (void)
361 pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
367 gtk_progress_bar_real_update (GtkProgressBar *pbar)
369 GtkProgressBarPrivate *priv;
372 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
375 widget = GTK_WIDGET (pbar);
377 if (priv->activity_mode)
379 GtkAllocation allocation;
383 gtk_widget_get_allocation (widget, &allocation);
384 style = gtk_widget_get_style (widget);
386 /* advance the block */
387 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
389 /* Update our activity step. */
390 priv->activity_step = allocation.width * priv->pulse_fraction;
392 size = MAX (2, allocation.width / priv->activity_blocks);
394 if (priv->activity_dir == 0)
396 priv->activity_pos += priv->activity_step;
397 if (priv->activity_pos + size >= allocation.width - style->xthickness)
399 priv->activity_pos = allocation.width - style->xthickness - size;
400 priv->activity_dir = 1;
405 priv->activity_pos -= priv->activity_step;
406 if (priv->activity_pos <= style->xthickness)
408 priv->activity_pos = style->xthickness;
409 priv->activity_dir = 0;
415 /* Update our activity step. */
416 priv->activity_step = allocation.height * priv->pulse_fraction;
418 size = MAX (2, allocation.height / priv->activity_blocks);
420 if (priv->activity_dir == 0)
422 priv->activity_pos += priv->activity_step;
423 if (priv->activity_pos + size >= allocation.height - style->ythickness)
425 priv->activity_pos = allocation.height - style->ythickness - size;
426 priv->activity_dir = 1;
431 priv->activity_pos -= priv->activity_step;
432 if (priv->activity_pos <= style->ythickness)
434 priv->activity_pos = style->ythickness;
435 priv->activity_dir = 0;
440 gtk_widget_queue_draw (widget);
444 gtk_progress_bar_finalize (GObject *object)
446 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
447 GtkProgressBarPrivate *priv = pbar->priv;
451 G_OBJECT_CLASS (gtk_progress_bar_parent_class)->finalize (object);
455 get_current_text (GtkProgressBar *pbar)
457 GtkProgressBarPrivate *priv = pbar->priv;
460 return g_strdup (priv->text);
462 return g_strdup_printf ("%.0f %%", priv->fraction * 100.0);
466 gtk_progress_bar_size_request (GtkWidget *widget,
467 GtkRequisition *requisition)
469 GtkProgressBar *pbar;
470 GtkProgressBarPrivate *priv;
473 PangoRectangle logical_rect;
476 gint xspacing, yspacing;
477 gint min_width, min_height;
479 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
480 g_return_if_fail (requisition != NULL);
482 style = gtk_widget_get_style (widget);
483 gtk_widget_style_get (widget,
484 "xspacing", &xspacing,
485 "yspacing", &yspacing,
488 pbar = GTK_PROGRESS_BAR (widget);
491 width = 2 * style->xthickness + xspacing;
492 height = 2 * style->ythickness + yspacing;
496 buf = get_current_text (pbar);
497 layout = gtk_widget_create_pango_layout (widget, buf);
499 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
503 PangoContext *context;
504 PangoFontMetrics *metrics;
507 /* The minimum size for ellipsized text is ~ 3 chars */
508 context = pango_layout_get_context (layout);
509 metrics = pango_context_get_metrics (context, style->font_desc, pango_context_get_language (context));
511 char_width = pango_font_metrics_get_approximate_char_width (metrics);
512 pango_font_metrics_unref (metrics);
514 width += PANGO_PIXELS (char_width) * 3;
517 width += logical_rect.width;
519 height += logical_rect.height;
521 g_object_unref (layout);
525 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
526 gtk_widget_style_get (widget,
527 "min-horizontal-bar-width", &min_width,
528 "min-horizontal-bar-height", &min_height,
531 gtk_widget_style_get (widget,
532 "min-vertical-bar-width", &min_width,
533 "min-vertical-bar-height", &min_height,
536 requisition->width = MAX (min_width, width);
537 requisition->height = MAX (min_height, height);
541 gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
543 GtkProgressBarPrivate *priv = pbar->priv;
544 GtkAllocation allocation;
546 GtkWidget *widget = GTK_WIDGET (pbar);
547 GtkOrientation orientation;
550 style = gtk_widget_get_style (widget);
552 orientation = priv->orientation;
553 inverted = priv->inverted;
554 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
556 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
557 inverted = !inverted;
560 /* calculate start pos */
562 if (orientation == GTK_ORIENTATION_HORIZONTAL)
566 priv->activity_pos = style->xthickness;
567 priv->activity_dir = 0;
571 gtk_widget_get_allocation (widget, &allocation);
572 priv->activity_pos = allocation.width - style->xthickness -
573 (allocation.height - style->ythickness * 2);
574 priv->activity_dir = 1;
581 priv->activity_pos = style->ythickness;
582 priv->activity_dir = 0;
586 gtk_widget_get_allocation (widget, &allocation);
587 priv->activity_pos = allocation.height - style->ythickness -
588 (allocation.width - style->xthickness * 2);
589 priv->activity_dir = 1;
595 gtk_progress_bar_get_activity (GtkProgressBar *pbar,
596 GtkOrientation orientation,
600 GtkProgressBarPrivate *priv = pbar->priv;
601 GtkAllocation allocation;
602 GtkWidget *widget = GTK_WIDGET (pbar);
604 *offset = priv->activity_pos;
606 gtk_widget_get_allocation (widget, &allocation);
608 if (orientation == GTK_ORIENTATION_HORIZONTAL)
609 *amount = MAX (2, allocation.width / priv->activity_blocks);
611 *amount = MAX (2, allocation.height / priv->activity_blocks);
615 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
617 GtkOrientation orientation,
623 GtkWidget *widget = GTK_WIDGET (pbar);
626 style = gtk_widget_get_style (widget);
628 if (orientation == GTK_ORIENTATION_HORIZONTAL)
630 gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
631 area.y = style->ythickness;
632 area.height = height - 2 * style->ythickness;
636 gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
637 area.x = style->xthickness;
638 area.width = width - 2 * style->xthickness;
641 gtk_paint_box (style,
643 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
645 area.x, area.y, area.width, area.height);
649 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
652 GtkOrientation orientation,
658 GtkWidget *widget = GTK_WIDGET (pbar);
664 style = gtk_widget_get_style (widget);
666 if (orientation == GTK_ORIENTATION_HORIZONTAL)
669 area.height = height - style->ythickness * 2;
670 area.y = style->ythickness;
672 area.x = style->xthickness;
674 area.x = width - amount - area.x;
678 area.width = width - style->xthickness * 2;
679 area.height = amount;
680 area.x = style->xthickness;
682 area.y = style->ythickness;
684 area.y = height - amount - area.y;
687 gtk_paint_box (style,
689 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
691 area.x, area.y, area.width, area.height);
695 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
699 GtkOrientation orientation,
704 GtkProgressBarPrivate *priv = pbar->priv;
706 GtkWidget *widget = GTK_WIDGET (pbar);
712 PangoRectangle logical_rect;
713 GdkRectangle prelight_clip, start_clip, end_clip;
714 gfloat text_xalign = 0.5;
715 gfloat text_yalign = 0.5;
717 style = gtk_widget_get_style (widget);
719 if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
720 text_xalign = 1.0 - text_xalign;
722 buf = get_current_text (pbar);
724 layout = gtk_widget_create_pango_layout (widget, buf);
725 pango_layout_set_ellipsize (layout, priv->ellipsize);
727 pango_layout_set_width (layout, width * PANGO_SCALE);
729 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
731 x = style->xthickness + 1 + text_xalign * (width - 2 * style->xthickness - 2 - logical_rect.width);
733 y = style->ythickness + 1 + text_yalign * (height - 2 * style->ythickness - 2 - logical_rect.height);
735 rect.x = style->xthickness;
736 rect.y = style->ythickness;
737 rect.width = width - 2 * style->xthickness;
738 rect.height = height - 2 * style->ythickness;
740 prelight_clip = start_clip = end_clip = rect;
742 if (orientation == GTK_ORIENTATION_HORIZONTAL)
747 prelight_clip.x = offset;
748 prelight_clip.width = amount;
749 start_clip.width = prelight_clip.x - start_clip.x;
750 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
751 end_clip.width -= prelight_clip.width + start_clip.width;
756 prelight_clip.x = offset;
758 prelight_clip.x = rect.x + rect.width - amount;
759 prelight_clip.width = amount;
760 start_clip.width = prelight_clip.x - start_clip.x;
761 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
762 end_clip.width -= prelight_clip.width + start_clip.width;
770 prelight_clip.y = offset;
771 prelight_clip.height = amount;
772 start_clip.height = prelight_clip.y - start_clip.y;
773 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
774 end_clip.height -= prelight_clip.height + start_clip.height;
779 prelight_clip.y = offset;
781 prelight_clip.y = rect.y + rect.height - amount;
782 prelight_clip.height = amount;
783 start_clip.height = prelight_clip.y - start_clip.y;
784 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
785 end_clip.height -= prelight_clip.height + start_clip.height;
789 if (start_clip.width > 0 && start_clip.height > 0)
792 gdk_cairo_rectangle (cr, &start_clip);
794 gtk_paint_layout (style,
805 if (end_clip.width > 0 && end_clip.height > 0)
808 gdk_cairo_rectangle (cr, &end_clip);
810 gtk_paint_layout (style,
822 gdk_cairo_rectangle (cr, &prelight_clip);
824 gtk_paint_layout (style,
834 g_object_unref (layout);
839 gtk_progress_bar_draw (GtkWidget *widget,
842 GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
843 GtkProgressBarPrivate *priv = pbar->priv;
844 GtkOrientation orientation;
849 style = gtk_widget_get_style (widget);
851 orientation = priv->orientation;
852 inverted = priv->inverted;
853 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
855 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
856 inverted = !inverted;
858 width = gtk_widget_get_allocated_width (widget);
859 height = gtk_widget_get_allocated_height (widget);
861 gtk_paint_box (style,
863 GTK_STATE_NORMAL, GTK_SHADOW_IN,
868 if (priv->activity_mode)
870 gtk_progress_bar_paint_activity (pbar, cr,
871 orientation, inverted,
879 gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
880 gtk_progress_bar_paint_text (pbar, cr,
882 orientation, inverted,
891 if (orientation == GTK_ORIENTATION_HORIZONTAL)
892 space = width - 2 * style->xthickness;
894 space = height - 2 * style->ythickness;
896 amount = space * gtk_progress_bar_get_fraction (pbar);
898 gtk_progress_bar_paint_continuous (pbar, cr, amount, orientation, inverted, width, height);
901 gtk_progress_bar_paint_text (pbar, cr, -1, amount, orientation, inverted, width, height);
908 gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar,
909 gboolean activity_mode)
911 GtkProgressBarPrivate *priv = pbar->priv;
913 activity_mode = !!activity_mode;
915 if (priv->activity_mode != activity_mode)
917 priv->activity_mode = activity_mode;
919 if (priv->activity_mode)
920 gtk_progress_bar_act_mode_enter (pbar);
922 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
923 gtk_widget_queue_resize (GTK_WIDGET (pbar));
928 * gtk_progress_bar_set_fraction:
929 * @pbar: a #GtkProgressBar
930 * @fraction: fraction of the task that's been completed
932 * Causes the progress bar to "fill in" the given fraction
933 * of the bar. The fraction should be between 0.0 and 1.0,
938 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
941 GtkProgressBarPrivate* priv;
943 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
947 priv->fraction = fraction;
948 gtk_progress_bar_set_activity_mode (pbar, FALSE);
949 gtk_progress_bar_real_update (pbar);
951 g_object_notify (G_OBJECT (pbar), "fraction");
955 * gtk_progress_bar_pulse:
956 * @pbar: a #GtkProgressBar
958 * Indicates that some progress is made, but you don't know how much.
959 * Causes the progress bar to enter "activity mode," where a block
960 * bounces back and forth. Each call to gtk_progress_bar_pulse()
961 * causes the block to move by a little bit (the amount of movement
962 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
965 gtk_progress_bar_pulse (GtkProgressBar *pbar)
967 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
969 gtk_progress_bar_set_activity_mode (pbar, TRUE);
970 gtk_progress_bar_real_update (pbar);
974 * gtk_progress_bar_set_text:
975 * @pbar: a #GtkProgressBar
976 * @text: (allow-none): a UTF-8 string, or %NULL
978 * Causes the given @text to appear superimposed on the progress bar.
981 gtk_progress_bar_set_text (GtkProgressBar *pbar,
984 GtkProgressBarPrivate *priv;
986 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
991 priv->text = text && *text ? g_strdup (text) : NULL;
993 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
994 gtk_widget_queue_resize (GTK_WIDGET (pbar));
996 g_object_notify (G_OBJECT (pbar), "text");
1000 * gtk_progress_bar_set_show_text:
1001 * @pbar: a #GtkProgressBar
1002 * @show_text: whether to show superimposed text
1004 * Sets whether the progressbar will show text superimposed
1005 * over the bar. The shown text is either the value of
1006 * the #GtkProgressBar::text property or, if that is %NULL,
1007 * the #GtkProgressBar::fraction value, as a percentage.
1012 gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
1015 GtkProgressBarPrivate *priv;
1017 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1021 show_text = !!show_text;
1023 if (priv->show_text != show_text)
1025 priv->show_text = show_text;
1027 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1028 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1030 g_object_notify (G_OBJECT (pbar), "show-text");
1035 * gtk_progress_bar_get_show_text:
1036 * @pbar: a #GtkProgressBar
1038 * Gets the value of the #GtkProgressBar::show-text property.
1039 * See gtk_progress_bar_set_show_text().
1041 * Returns: %TRUE if text is shown in the progress bar
1046 gtk_progress_bar_get_show_text (GtkProgressBar *pbar)
1048 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1050 return pbar->priv->show_text;
1054 * gtk_progress_bar_set_pulse_step:
1055 * @pbar: a #GtkProgressBar
1056 * @fraction: fraction between 0.0 and 1.0
1058 * Sets the fraction of total progress bar length to move the
1059 * bouncing block for each call to gtk_progress_bar_pulse().
1062 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1065 GtkProgressBarPrivate *priv;
1067 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1071 priv->pulse_fraction = fraction;
1073 g_object_notify (G_OBJECT (pbar), "pulse-step");
1077 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1078 GtkOrientation orientation)
1080 GtkProgressBarPrivate *priv = pbar->priv;
1082 if (priv->orientation != orientation)
1084 priv->orientation = orientation;
1086 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1087 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1092 * gtk_progress_bar_set_inverted:
1093 * @pbar: a #GtkProgressBar
1094 * @inverted: %TRUE to invert the progress bar
1096 * Progress bars normally grow from top to bottom or left to right.
1097 * Inverted progress bars grow in the opposite direction.
1100 gtk_progress_bar_set_inverted (GtkProgressBar *pbar,
1103 GtkProgressBarPrivate *priv;
1105 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1109 if (priv->inverted != inverted)
1111 priv->inverted = inverted;
1113 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1114 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1116 g_object_notify (G_OBJECT (pbar), "inverted");
1121 * gtk_progress_bar_get_text:
1122 * @pbar: a #GtkProgressBar
1124 * Retrieves the text displayed superimposed on the progress bar,
1125 * if any, otherwise %NULL. The return value is a reference
1126 * to the text, not a copy of it, so will become invalid
1127 * if you change the text in the progress bar.
1129 * Return value: text, or %NULL; this string is owned by the widget
1130 * and should not be modified or freed.
1132 G_CONST_RETURN gchar*
1133 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1135 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1137 return pbar->priv->text;
1141 * gtk_progress_bar_get_fraction:
1142 * @pbar: a #GtkProgressBar
1144 * Returns the current fraction of the task that's been completed.
1146 * Return value: a fraction from 0.0 to 1.0
1149 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1151 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1153 return pbar->priv->fraction;
1157 * gtk_progress_bar_get_pulse_step:
1158 * @pbar: a #GtkProgressBar
1160 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1162 * Return value: a fraction from 0.0 to 1.0
1165 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1167 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1169 return pbar->priv->pulse_fraction;
1173 * gtk_progress_bar_get_inverted:
1174 * @pbar: a #GtkProgressBar
1176 * Gets the value set by gtk_progress_bar_set_inverted()
1178 * Return value: %TRUE if the progress bar is inverted
1181 gtk_progress_bar_get_inverted (GtkProgressBar *pbar)
1183 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1185 return pbar->priv->inverted;
1189 * gtk_progress_bar_set_ellipsize:
1190 * @pbar: a #GtkProgressBar
1191 * @mode: a #PangoEllipsizeMode
1193 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1194 * if there is not enough space to render the entire string.
1199 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1200 PangoEllipsizeMode mode)
1202 GtkProgressBarPrivate *priv;
1204 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1205 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1206 mode <= PANGO_ELLIPSIZE_END);
1210 if ((PangoEllipsizeMode)priv->ellipsize != mode)
1212 priv->ellipsize = mode;
1214 g_object_notify (G_OBJECT (pbar), "ellipsize");
1215 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1220 * gtk_progress_bar_get_ellipsize:
1221 * @pbar: a #GtkProgressBar
1223 * Returns the ellipsizing position of the progressbar.
1224 * See gtk_progress_bar_set_ellipsize().
1226 * Return value: #PangoEllipsizeMode
1231 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1233 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1235 return pbar->priv->ellipsize;