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 gboolean gtk_progress_bar_expose (GtkWidget *widget,
86 GdkEventExpose *event);
87 static void gtk_progress_bar_size_request (GtkWidget *widget,
88 GtkRequisition *requisition);
89 static void gtk_progress_bar_size_allocate (GtkWidget *widget,
90 GtkAllocation *allocation);
91 static void gtk_progress_bar_real_update (GtkProgressBar *progress);
92 static void gtk_progress_bar_paint (GtkProgressBar *progress);
93 static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress);
94 static void gtk_progress_bar_realize (GtkWidget *widget);
95 static void gtk_progress_bar_finalize (GObject *object);
96 static void gtk_progress_bar_set_orientation (GtkProgressBar *progress,
97 GtkOrientation orientation);
99 G_DEFINE_TYPE_WITH_CODE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET,
100 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
103 gtk_progress_bar_class_init (GtkProgressBarClass *class)
105 GObjectClass *gobject_class;
106 GtkWidgetClass *widget_class;
108 gobject_class = G_OBJECT_CLASS (class);
109 widget_class = (GtkWidgetClass *) class;
111 gobject_class->set_property = gtk_progress_bar_set_property;
112 gobject_class->get_property = gtk_progress_bar_get_property;
113 gobject_class->finalize = gtk_progress_bar_finalize;
115 widget_class->realize = gtk_progress_bar_realize;
116 widget_class->expose_event = gtk_progress_bar_expose;
117 widget_class->size_request = gtk_progress_bar_size_request;
118 widget_class->size_allocate = gtk_progress_bar_size_allocate;
120 g_object_class_override_property (gobject_class,
124 g_object_class_install_property (gobject_class,
126 g_param_spec_boolean ("inverted",
128 P_("Invert the direction in which the progress bar grows"),
130 GTK_PARAM_READWRITE));
132 g_object_class_install_property (gobject_class,
134 g_param_spec_double ("fraction",
136 P_("The fraction of total work that has been completed"),
138 GTK_PARAM_READWRITE));
140 g_object_class_install_property (gobject_class,
142 g_param_spec_double ("pulse-step",
144 P_("The fraction of total progress to move the bouncing block when pulsed"),
146 GTK_PARAM_READWRITE));
148 g_object_class_install_property (gobject_class,
150 g_param_spec_string ("text",
152 P_("Text to be displayed in the progress bar"),
154 GTK_PARAM_READWRITE));
156 g_object_class_install_property (gobject_class,
158 g_param_spec_boolean ("show-text",
160 P_("Whether the progress is shown as text."),
162 GTK_PARAM_READWRITE));
165 * GtkProgressBar:ellipsize:
167 * The preferred place to ellipsize the string, if the progressbar does
168 * not have enough room to display the entire string, specified as a
169 * #PangoEllisizeMode.
171 * Note that setting this property to a value other than
172 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
173 * only enough space to display the ellipsis "...". Another means to set a
174 * progressbar's width is gtk_widget_set_size_request().
178 g_object_class_install_property (gobject_class,
180 g_param_spec_enum ("ellipsize",
182 P_("The preferred place to ellipsize the string, if the progress bar "
183 "does not have enough room to display the entire string, if at all."),
184 PANGO_TYPE_ELLIPSIZE_MODE,
185 PANGO_ELLIPSIZE_NONE,
186 GTK_PARAM_READWRITE));
187 gtk_widget_class_install_style_property (widget_class,
188 g_param_spec_int ("xspacing",
190 P_("Extra spacing applied to the width of a progress bar."),
193 gtk_widget_class_install_style_property (widget_class,
194 g_param_spec_int ("yspacing",
196 P_("Extra spacing applied to the height of a progress bar."),
201 * GtkProgressBar:min-horizontal-bar-width:
203 * The minimum horizontal width of the progress bar.
207 gtk_widget_class_install_style_property (widget_class,
208 g_param_spec_int ("min-horizontal-bar-width",
209 P_("Minimum horizontal bar width"),
210 P_("The minimum horizontal width of the progress bar"),
211 1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
214 * GtkProgressBar:min-horizontal-bar-height:
216 * Minimum horizontal height of the progress bar.
220 gtk_widget_class_install_style_property (widget_class,
221 g_param_spec_int ("min-horizontal-bar-height",
222 P_("Minimum horizontal bar height"),
223 P_("Minimum horizontal height of the progress bar"),
224 1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
227 * GtkProgressBar:min-vertical-bar-width:
229 * The minimum vertical width of the progress bar.
233 gtk_widget_class_install_style_property (widget_class,
234 g_param_spec_int ("min-vertical-bar-width",
235 P_("Minimum vertical bar width"),
236 P_("The minimum vertical width of the progress bar"),
237 1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
240 * GtkProgressBar:min-vertical-bar-height:
242 * The minimum vertical height of the progress bar.
246 gtk_widget_class_install_style_property (widget_class,
247 g_param_spec_int ("min-vertical-bar-height",
248 P_("Minimum vertical bar height"),
249 P_("The minimum vertical height of the progress bar"),
250 1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
253 g_type_class_add_private (class, sizeof (GtkProgressBarPrivate));
257 gtk_progress_bar_init (GtkProgressBar *pbar)
259 GtkProgressBarPrivate *priv;
261 pbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (pbar,
262 GTK_TYPE_PROGRESS_BAR,
263 GtkProgressBarPrivate);
268 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
269 priv->inverted = FALSE;
270 priv->pulse_fraction = 0.1;
271 priv->activity_pos = 0;
272 priv->activity_dir = 1;
273 priv->activity_step = 3;
274 priv->activity_blocks = 5;
275 priv->ellipsize = PANGO_ELLIPSIZE_NONE;
276 priv->show_text = FALSE;
279 priv->fraction = 0.0;
283 gtk_progress_bar_realize (GtkWidget *widget)
285 GtkAllocation allocation;
287 GdkWindowAttr attributes;
288 gint attributes_mask;
290 gtk_widget_set_realized (widget, TRUE);
292 gtk_widget_get_allocation (widget, &allocation);
294 attributes.window_type = GDK_WINDOW_CHILD;
295 attributes.x = allocation.x;
296 attributes.y = allocation.y;
297 attributes.width = allocation.width;
298 attributes.height = allocation.height;
299 attributes.wclass = GDK_INPUT_OUTPUT;
300 attributes.visual = gtk_widget_get_visual (widget);
301 attributes.event_mask = gtk_widget_get_events (widget);
302 attributes.event_mask |= GDK_EXPOSURE_MASK;
304 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
305 window = gdk_window_new (gtk_widget_get_parent_window (widget),
306 &attributes, attributes_mask);
307 gtk_widget_set_window (widget, window);
308 gdk_window_set_user_data (window, widget);
310 gtk_widget_style_attach (widget);
311 gtk_style_set_background (gtk_widget_get_style (widget),
312 window, GTK_STATE_ACTIVE);
316 gtk_progress_bar_set_property (GObject *object,
321 GtkProgressBar *pbar;
323 pbar = GTK_PROGRESS_BAR (object);
327 case PROP_ORIENTATION:
328 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
331 gtk_progress_bar_set_inverted (pbar, g_value_get_boolean (value));
334 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
336 case PROP_PULSE_STEP:
337 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
340 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
343 gtk_progress_bar_set_show_text (pbar, g_value_get_boolean (value));
346 gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
349 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
355 gtk_progress_bar_get_property (GObject *object,
360 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
361 GtkProgressBarPrivate* priv = pbar->priv;
365 case PROP_ORIENTATION:
366 g_value_set_enum (value, priv->orientation);
369 g_value_set_boolean (value, priv->inverted);
372 g_value_set_double (value, priv->fraction);
374 case PROP_PULSE_STEP:
375 g_value_set_double (value, priv->pulse_fraction);
378 g_value_set_string (value, priv->text);
381 g_value_set_boolean (value, priv->show_text);
384 g_value_set_enum (value, priv->ellipsize);
387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
393 gtk_progress_bar_new (void)
397 pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
403 gtk_progress_bar_real_update (GtkProgressBar *pbar)
405 GtkProgressBarPrivate *priv;
408 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
411 widget = GTK_WIDGET (pbar);
413 if (priv->activity_mode)
415 GtkAllocation allocation;
419 gtk_widget_get_allocation (widget, &allocation);
420 style = gtk_widget_get_style (widget);
422 /* advance the block */
423 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
425 /* Update our activity step. */
426 priv->activity_step = allocation.width * priv->pulse_fraction;
428 size = MAX (2, allocation.width / priv->activity_blocks);
430 if (priv->activity_dir == 0)
432 priv->activity_pos += priv->activity_step;
433 if (priv->activity_pos + size >= allocation.width - style->xthickness)
435 priv->activity_pos = allocation.width - style->xthickness - size;
436 priv->activity_dir = 1;
441 priv->activity_pos -= priv->activity_step;
442 if (priv->activity_pos <= style->xthickness)
444 priv->activity_pos = style->xthickness;
445 priv->activity_dir = 0;
451 /* Update our activity step. */
452 priv->activity_step = allocation.height * priv->pulse_fraction;
454 size = MAX (2, allocation.height / priv->activity_blocks);
456 if (priv->activity_dir == 0)
458 priv->activity_pos += priv->activity_step;
459 if (priv->activity_pos + size >= allocation.height - style->ythickness)
461 priv->activity_pos = allocation.height - style->ythickness - size;
462 priv->activity_dir = 1;
467 priv->activity_pos -= priv->activity_step;
468 if (priv->activity_pos <= style->ythickness)
470 priv->activity_pos = style->ythickness;
471 priv->activity_dir = 0;
476 gtk_widget_queue_draw (widget);
480 gtk_progress_bar_finalize (GObject *object)
482 GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
483 GtkProgressBarPrivate *priv = pbar->priv;
487 G_OBJECT_CLASS (gtk_progress_bar_parent_class)->finalize (object);
491 gtk_progress_bar_expose (GtkWidget *widget,
492 GdkEventExpose *event)
494 GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
496 if (gtk_widget_is_drawable (widget))
497 gtk_progress_bar_paint (pbar);
503 get_current_text (GtkProgressBar *pbar)
505 GtkProgressBarPrivate *priv = pbar->priv;
508 return g_strdup (priv->text);
510 return g_strdup_printf ("%.0f %%", priv->fraction * 100.0);
514 gtk_progress_bar_size_request (GtkWidget *widget,
515 GtkRequisition *requisition)
517 GtkProgressBar *pbar;
518 GtkProgressBarPrivate *priv;
521 PangoRectangle logical_rect;
524 gint xspacing, yspacing;
525 gint min_width, min_height;
527 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
528 g_return_if_fail (requisition != NULL);
530 style = gtk_widget_get_style (widget);
531 gtk_widget_style_get (widget,
532 "xspacing", &xspacing,
533 "yspacing", &yspacing,
536 pbar = GTK_PROGRESS_BAR (widget);
539 width = 2 * style->xthickness + xspacing;
540 height = 2 * style->ythickness + yspacing;
544 buf = get_current_text (pbar);
545 layout = gtk_widget_create_pango_layout (widget, buf);
547 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
551 PangoContext *context;
552 PangoFontMetrics *metrics;
555 /* The minimum size for ellipsized text is ~ 3 chars */
556 context = pango_layout_get_context (layout);
557 metrics = pango_context_get_metrics (context, style->font_desc, pango_context_get_language (context));
559 char_width = pango_font_metrics_get_approximate_char_width (metrics);
560 pango_font_metrics_unref (metrics);
562 width += PANGO_PIXELS (char_width) * 3;
565 width += logical_rect.width;
567 height += logical_rect.height;
569 g_object_unref (layout);
573 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
574 gtk_widget_style_get (widget,
575 "min-horizontal-bar-width", &min_width,
576 "min-horizontal-bar-height", &min_height,
579 gtk_widget_style_get (widget,
580 "min-vertical-bar-width", &min_width,
581 "min-vertical-bar-height", &min_height,
584 requisition->width = MAX (min_width, width);
585 requisition->height = MAX (min_height, height);
589 gtk_progress_bar_size_allocate (GtkWidget *widget,
590 GtkAllocation *allocation)
592 gtk_widget_set_allocation (widget, allocation);
594 if (gtk_widget_get_realized (widget))
595 gdk_window_move_resize (gtk_widget_get_window (widget),
596 allocation->x, allocation->y,
597 allocation->width, allocation->height);
601 gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
603 GtkProgressBarPrivate *priv = pbar->priv;
604 GtkAllocation allocation;
606 GtkWidget *widget = GTK_WIDGET (pbar);
607 GtkOrientation orientation;
610 style = gtk_widget_get_style (widget);
612 orientation = priv->orientation;
613 inverted = priv->inverted;
614 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
616 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
617 inverted = !inverted;
620 /* calculate start pos */
622 if (orientation == GTK_ORIENTATION_HORIZONTAL)
626 priv->activity_pos = style->xthickness;
627 priv->activity_dir = 0;
631 gtk_widget_get_allocation (widget, &allocation);
632 priv->activity_pos = allocation.width - style->xthickness -
633 (allocation.height - style->ythickness * 2);
634 priv->activity_dir = 1;
641 priv->activity_pos = style->ythickness;
642 priv->activity_dir = 0;
646 gtk_widget_get_allocation (widget, &allocation);
647 priv->activity_pos = allocation.height - style->ythickness -
648 (allocation.width - style->xthickness * 2);
649 priv->activity_dir = 1;
655 gtk_progress_bar_get_activity (GtkProgressBar *pbar,
656 GtkOrientation orientation,
660 GtkProgressBarPrivate *priv = pbar->priv;
661 GtkAllocation allocation;
662 GtkWidget *widget = GTK_WIDGET (pbar);
664 *offset = priv->activity_pos;
666 gtk_widget_get_allocation (widget, &allocation);
668 if (orientation == GTK_ORIENTATION_HORIZONTAL)
669 *amount = MAX (2, allocation.width / priv->activity_blocks);
671 *amount = MAX (2, allocation.height / priv->activity_blocks);
675 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
676 GtkOrientation orientation,
679 GtkAllocation allocation;
681 GtkWidget *widget = GTK_WIDGET (pbar);
684 style = gtk_widget_get_style (widget);
685 gtk_widget_get_allocation (widget, &allocation);
687 if (orientation == GTK_ORIENTATION_HORIZONTAL)
689 gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
690 area.y = style->ythickness;
691 area.height = allocation.height - 2 * style->ythickness;
695 gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
696 area.x = style->xthickness;
697 area.width = allocation.width - 2 * style->xthickness;
700 gtk_paint_box (style,
701 gtk_widget_get_window (widget),
702 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
703 &area, widget, "bar",
704 area.x, area.y, area.width, area.height);
708 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
710 GtkOrientation orientation,
713 GtkAllocation allocation;
715 GtkWidget *widget = GTK_WIDGET (pbar);
721 style = gtk_widget_get_style (widget);
722 gtk_widget_get_allocation (widget, &allocation);
724 if (orientation == GTK_ORIENTATION_HORIZONTAL)
727 area.height = allocation.height - style->ythickness * 2;
728 area.y = style->ythickness;
730 area.x = style->xthickness;
732 area.x = allocation.width - amount - area.x;
736 area.width = allocation.width - style->xthickness * 2;
737 area.height = amount;
738 area.x = style->xthickness;
740 area.y = style->ythickness;
742 area.y = allocation.height - amount - area.y;
745 gtk_paint_box (style,
746 gtk_widget_get_window (widget),
747 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
748 &area, widget, "bar",
749 area.x, area.y, area.width, area.height);
753 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
756 GtkOrientation orientation,
759 GtkProgressBarPrivate *priv = pbar->priv;
760 GtkAllocation allocation;
762 GtkWidget *widget = GTK_WIDGET (pbar);
768 PangoRectangle logical_rect;
769 GdkRectangle prelight_clip, start_clip, end_clip;
770 gfloat text_xalign = 0.5;
771 gfloat text_yalign = 0.5;
773 style = gtk_widget_get_style (widget);
774 gtk_widget_get_allocation (widget, &allocation);
776 if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
777 text_xalign = 1.0 - text_xalign;
779 buf = get_current_text (pbar);
781 layout = gtk_widget_create_pango_layout (widget, buf);
782 pango_layout_set_ellipsize (layout, priv->ellipsize);
784 pango_layout_set_width (layout, allocation.width * PANGO_SCALE);
786 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
788 x = style->xthickness + 1 + text_xalign * (allocation.width - 2 * style->xthickness - 2 - logical_rect.width);
790 y = style->ythickness + 1 + text_yalign * (allocation.height - 2 * style->ythickness - 2 - logical_rect.height);
792 rect.x = style->xthickness;
793 rect.y = style->ythickness;
794 rect.width = allocation.width - 2 * style->xthickness;
795 rect.height = allocation.height - 2 * style->ythickness;
797 prelight_clip = start_clip = end_clip = rect;
799 if (orientation == GTK_ORIENTATION_HORIZONTAL)
804 prelight_clip.x = offset;
805 prelight_clip.width = amount;
806 start_clip.width = prelight_clip.x - start_clip.x;
807 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
808 end_clip.width -= prelight_clip.width + start_clip.width;
813 prelight_clip.x = offset;
815 prelight_clip.x = rect.x + rect.width - amount;
816 prelight_clip.width = amount;
817 start_clip.width = prelight_clip.x - start_clip.x;
818 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
819 end_clip.width -= prelight_clip.width + start_clip.width;
827 prelight_clip.y = offset;
828 prelight_clip.height = amount;
829 start_clip.height = prelight_clip.y - start_clip.y;
830 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
831 end_clip.height -= prelight_clip.height + start_clip.height;
836 prelight_clip.y = offset;
838 prelight_clip.y = rect.y + rect.height - amount;
839 prelight_clip.height = amount;
840 start_clip.height = prelight_clip.y - start_clip.y;
841 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
842 end_clip.height -= prelight_clip.height + start_clip.height;
846 if (start_clip.width > 0 && start_clip.height > 0)
847 gtk_paint_layout (style,
848 gtk_widget_get_window (widget),
857 if (end_clip.width > 0 && end_clip.height > 0)
858 gtk_paint_layout (style,
859 gtk_widget_get_window (widget),
868 gtk_paint_layout (style,
869 gtk_widget_get_window (widget),
878 g_object_unref (layout);
883 gtk_progress_bar_paint (GtkProgressBar *pbar)
885 GtkProgressBarPrivate *priv = pbar->priv;
886 GtkAllocation allocation;
887 GtkWidget *widget = GTK_WIDGET (pbar);
888 GtkOrientation orientation;
892 style = gtk_widget_get_style (widget);
893 gtk_widget_get_allocation (widget, &allocation);
895 orientation = priv->orientation;
896 inverted = priv->inverted;
897 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
899 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
900 inverted = !inverted;
903 gtk_paint_box (style,
904 gtk_widget_get_window (widget),
905 GTK_STATE_NORMAL, GTK_SHADOW_IN,
906 NULL, widget, "trough",
911 if (priv->activity_mode)
913 gtk_progress_bar_paint_activity (pbar, orientation, inverted);
920 gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
921 gtk_progress_bar_paint_text (pbar, offset, amount, orientation, inverted);
929 if (orientation == GTK_ORIENTATION_HORIZONTAL)
930 space = allocation.width - 2 * style->xthickness;
932 space = allocation.height - 2 * style->ythickness;
934 amount = space * gtk_progress_bar_get_fraction (pbar);
936 gtk_progress_bar_paint_continuous (pbar, amount, orientation, inverted);
939 gtk_progress_bar_paint_text (pbar, -1, amount, orientation, inverted);
944 gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar,
945 gboolean activity_mode)
947 GtkProgressBarPrivate *priv = pbar->priv;
949 activity_mode = !!activity_mode;
951 if (priv->activity_mode != activity_mode)
953 priv->activity_mode = activity_mode;
955 if (priv->activity_mode)
956 gtk_progress_bar_act_mode_enter (pbar);
958 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
959 gtk_widget_queue_resize (GTK_WIDGET (pbar));
964 * gtk_progress_bar_set_fraction:
965 * @pbar: a #GtkProgressBar
966 * @fraction: fraction of the task that's been completed
968 * Causes the progress bar to "fill in" the given fraction
969 * of the bar. The fraction should be between 0.0 and 1.0,
974 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
977 GtkProgressBarPrivate* priv;
979 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
983 priv->fraction = fraction;
984 gtk_progress_bar_set_activity_mode (pbar, FALSE);
985 gtk_progress_bar_real_update (pbar);
987 g_object_notify (G_OBJECT (pbar), "fraction");
991 * gtk_progress_bar_pulse:
992 * @pbar: a #GtkProgressBar
994 * Indicates that some progress is made, but you don't know how much.
995 * Causes the progress bar to enter "activity mode," where a block
996 * bounces back and forth. Each call to gtk_progress_bar_pulse()
997 * causes the block to move by a little bit (the amount of movement
998 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
1001 gtk_progress_bar_pulse (GtkProgressBar *pbar)
1003 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1005 gtk_progress_bar_set_activity_mode (pbar, TRUE);
1006 gtk_progress_bar_real_update (pbar);
1010 * gtk_progress_bar_set_text:
1011 * @pbar: a #GtkProgressBar
1012 * @text: (allow-none): a UTF-8 string, or %NULL
1014 * Causes the given @text to appear superimposed on the progress bar.
1017 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1020 GtkProgressBarPrivate *priv;
1022 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1026 g_free (priv->text);
1027 priv->text = text && *text ? g_strdup (text) : NULL;
1029 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1030 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1032 g_object_notify (G_OBJECT (pbar), "text");
1036 * gtk_progress_bar_set_show_text:
1037 * @pbar: a #GtkProgressBar
1038 * @show_text: whether to show superimposed text
1040 * Sets whether the progressbar will show text superimposed
1041 * over the bar. The shown text is either the value of
1042 * the #GtkProgressBar::text property or, if that is %NULL,
1043 * the #GtkProgressBar::fraction value, as a percentage.
1048 gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
1051 GtkProgressBarPrivate *priv;
1053 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1057 show_text = !!show_text;
1059 if (priv->show_text != show_text)
1061 priv->show_text = show_text;
1063 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1064 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1066 g_object_notify (G_OBJECT (pbar), "show-text");
1071 * gtk_progress_bar_get_show_text:
1072 * @pbar: a #GtkProgressBar
1074 * Gets the value of the #GtkProgressBar::show-text property.
1075 * See gtk_progress_bar_set_show_text().
1077 * Returns: %TRUE if text is shown in the progress bar
1082 gtk_progress_bar_get_show_text (GtkProgressBar *pbar)
1084 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1086 return pbar->priv->show_text;
1090 * gtk_progress_bar_set_pulse_step:
1091 * @pbar: a #GtkProgressBar
1092 * @fraction: fraction between 0.0 and 1.0
1094 * Sets the fraction of total progress bar length to move the
1095 * bouncing block for each call to gtk_progress_bar_pulse().
1098 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1101 GtkProgressBarPrivate *priv;
1103 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1107 priv->pulse_fraction = fraction;
1109 g_object_notify (G_OBJECT (pbar), "pulse-step");
1113 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1114 GtkOrientation orientation)
1116 GtkProgressBarPrivate *priv = pbar->priv;
1118 if (priv->orientation != orientation)
1120 priv->orientation = orientation;
1122 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1123 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1128 * gtk_progress_bar_set_inverted:
1129 * @pbar: a #GtkProgressBar
1130 * @inverted: %TRUE to invert the progress bar
1132 * Progress bars normally grow from top to bottom or left to right.
1133 * Inverted progress bars grow in the opposite direction.
1136 gtk_progress_bar_set_inverted (GtkProgressBar *pbar,
1139 GtkProgressBarPrivate *priv;
1141 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1145 if (priv->inverted != inverted)
1147 priv->inverted = inverted;
1149 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1150 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1152 g_object_notify (G_OBJECT (pbar), "inverted");
1157 * gtk_progress_bar_get_text:
1158 * @pbar: a #GtkProgressBar
1160 * Retrieves the text displayed superimposed on the progress bar,
1161 * if any, otherwise %NULL. The return value is a reference
1162 * to the text, not a copy of it, so will become invalid
1163 * if you change the text in the progress bar.
1165 * Return value: text, or %NULL; this string is owned by the widget
1166 * and should not be modified or freed.
1168 G_CONST_RETURN gchar*
1169 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1171 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1173 return pbar->priv->text;
1177 * gtk_progress_bar_get_fraction:
1178 * @pbar: a #GtkProgressBar
1180 * Returns the current fraction of the task that's been completed.
1182 * Return value: a fraction from 0.0 to 1.0
1185 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1187 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1189 return pbar->priv->fraction;
1193 * gtk_progress_bar_get_pulse_step:
1194 * @pbar: a #GtkProgressBar
1196 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1198 * Return value: a fraction from 0.0 to 1.0
1201 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1203 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1205 return pbar->priv->pulse_fraction;
1209 * gtk_progress_bar_get_inverted:
1210 * @pbar: a #GtkProgressBar
1212 * Gets the value set by gtk_progress_bar_set_inverted()
1214 * Return value: %TRUE if the progress bar is inverted
1217 gtk_progress_bar_get_inverted (GtkProgressBar *pbar)
1219 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
1221 return pbar->priv->inverted;
1225 * gtk_progress_bar_set_ellipsize:
1226 * @pbar: a #GtkProgressBar
1227 * @mode: a #PangoEllipsizeMode
1229 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1230 * if there is not enough space to render the entire string.
1235 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1236 PangoEllipsizeMode mode)
1238 GtkProgressBarPrivate *priv;
1240 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1241 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1242 mode <= PANGO_ELLIPSIZE_END);
1246 if ((PangoEllipsizeMode)priv->ellipsize != mode)
1248 priv->ellipsize = mode;
1250 g_object_notify (G_OBJECT (pbar), "ellipsize");
1251 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1256 * gtk_progress_bar_get_ellipsize:
1257 * @pbar: a #GtkProgressBar
1259 * Returns the ellipsizing position of the progressbar.
1260 * See gtk_progress_bar_set_ellipsize().
1262 * Return value: #PangoEllipsizeMode
1267 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1269 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1271 return pbar->priv->ellipsize;