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/.
37 #include "gtkprogressbar.h"
41 #define MIN_HORIZONTAL_BAR_WIDTH 150
42 #define MIN_HORIZONTAL_BAR_HEIGHT 20
43 #define MIN_VERTICAL_BAR_WIDTH 22
44 #define MIN_VERTICAL_BAR_HEIGHT 80
45 #define MAX_TEXT_LENGTH 80
46 #define TEXT_SPACING 2
65 static void gtk_progress_bar_class_init (GtkProgressBarClass *klass);
66 static void gtk_progress_bar_init (GtkProgressBar *pbar);
67 static void gtk_progress_bar_set_property (GObject *object,
71 static void gtk_progress_bar_get_property (GObject *object,
75 static void gtk_progress_bar_size_request (GtkWidget *widget,
76 GtkRequisition *requisition);
77 static void gtk_progress_bar_real_update (GtkProgress *progress);
78 static void gtk_progress_bar_paint (GtkProgress *progress);
79 static void gtk_progress_bar_act_mode_enter (GtkProgress *progress);
81 static void gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
82 GtkProgressBarStyle style);
83 static void gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
85 static void gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
87 static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
92 gtk_progress_bar_get_type (void)
94 static GType progress_bar_type = 0;
96 if (!progress_bar_type)
98 static const GTypeInfo progress_bar_info =
100 sizeof (GtkProgressBarClass),
101 NULL, /* base_init */
102 NULL, /* base_finalize */
103 (GClassInitFunc) gtk_progress_bar_class_init,
104 NULL, /* class_finalize */
105 NULL, /* class_data */
106 sizeof (GtkProgressBar),
108 (GInstanceInitFunc) gtk_progress_bar_init,
112 g_type_register_static (GTK_TYPE_PROGRESS, "GtkProgressBar",
113 &progress_bar_info, 0);
116 return progress_bar_type;
120 gtk_progress_bar_class_init (GtkProgressBarClass *class)
122 GObjectClass *gobject_class;
123 GtkWidgetClass *widget_class;
124 GtkProgressClass *progress_class;
126 gobject_class = G_OBJECT_CLASS (class);
127 widget_class = (GtkWidgetClass *) class;
128 progress_class = (GtkProgressClass *) class;
130 gobject_class->set_property = gtk_progress_bar_set_property;
131 gobject_class->get_property = gtk_progress_bar_get_property;
133 widget_class->size_request = gtk_progress_bar_size_request;
135 progress_class->paint = gtk_progress_bar_paint;
136 progress_class->update = gtk_progress_bar_real_update;
137 progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
139 g_object_class_install_property (gobject_class,
141 g_param_spec_object ("adjustment",
143 _("The GtkAdjustment connected to the progress bar (Deprecated)"),
147 g_object_class_install_property (gobject_class,
149 g_param_spec_enum ("orientation",
151 _("Orientation and growth direction of the progress bar"),
152 GTK_TYPE_PROGRESS_BAR_ORIENTATION,
153 GTK_PROGRESS_LEFT_TO_RIGHT,
156 g_object_class_install_property (gobject_class,
158 g_param_spec_enum ("bar_style",
160 _("Specifies the visual style of the bar in percentage mode (Deprecated)"),
161 GTK_TYPE_PROGRESS_BAR_STYLE,
162 GTK_PROGRESS_CONTINUOUS,
165 g_object_class_install_property (gobject_class,
167 g_param_spec_uint ("activity_step",
169 _("The increment used for each iteration in activity mode (Deprecated)"),
175 g_object_class_install_property (gobject_class,
176 PROP_ACTIVITY_BLOCKS,
177 g_param_spec_uint ("activity_blocks",
178 _("Activity Blocks"),
179 _("The number of blocks which can fit in the progress bar area in activity mode (Deprecated)"),
185 g_object_class_install_property (gobject_class,
186 PROP_DISCRETE_BLOCKS,
187 g_param_spec_uint ("discrete_blocks",
188 _("Discrete Blocks"),
189 _("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
195 g_object_class_install_property (gobject_class,
197 g_param_spec_double ("fraction",
199 _("The fraction of total work that has been completed"),
205 g_object_class_install_property (gobject_class,
207 g_param_spec_double ("pulse_step",
209 _("The fraction of total progress to move the bouncing block when pulsed"),
215 g_object_class_install_property (gobject_class,
217 g_param_spec_string ("text",
219 _("Text to be displayed in the progress bar"),
226 gtk_progress_bar_init (GtkProgressBar *pbar)
228 pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
231 pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
232 pbar->pulse_fraction = 0.1;
233 pbar->activity_pos = 0;
234 pbar->activity_dir = 1;
235 pbar->activity_step = 3;
236 pbar->activity_blocks = 5;
240 gtk_progress_bar_set_property (GObject *object,
245 GtkProgressBar *pbar;
247 pbar = GTK_PROGRESS_BAR (object);
251 case PROP_ADJUSTMENT:
252 gtk_progress_set_adjustment (GTK_PROGRESS (pbar),
253 GTK_ADJUSTMENT (g_value_get_object (value)));
255 case PROP_ORIENTATION:
256 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
259 gtk_progress_bar_set_bar_style_internal (pbar, g_value_get_enum (value));
261 case PROP_ACTIVITY_STEP:
262 gtk_progress_bar_set_activity_step_internal (pbar, g_value_get_uint (value));
264 case PROP_ACTIVITY_BLOCKS:
265 gtk_progress_bar_set_activity_blocks_internal (pbar, g_value_get_uint (value));
267 case PROP_DISCRETE_BLOCKS:
268 gtk_progress_bar_set_discrete_blocks_internal (pbar, g_value_get_uint (value));
271 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
273 case PROP_PULSE_STEP:
274 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
277 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286 gtk_progress_bar_get_property (GObject *object,
291 GtkProgressBar *pbar;
293 pbar = GTK_PROGRESS_BAR (object);
297 case PROP_ADJUSTMENT:
298 g_value_set_object (value, GTK_PROGRESS (pbar)->adjustment);
300 case PROP_ORIENTATION:
301 g_value_set_enum (value, pbar->orientation);
304 g_value_set_enum (value, pbar->bar_style);
306 case PROP_ACTIVITY_STEP:
307 g_value_set_uint (value, pbar->activity_step);
309 case PROP_ACTIVITY_BLOCKS:
310 g_value_set_uint (value, pbar->activity_blocks);
312 case PROP_DISCRETE_BLOCKS:
313 g_value_set_uint (value, pbar->blocks);
316 g_value_set_double (value, gtk_progress_get_current_percentage (GTK_PROGRESS (pbar)));
318 case PROP_PULSE_STEP:
319 g_value_set_double (value, pbar->pulse_fraction);
322 g_value_set_string (value, gtk_progress_bar_get_text (pbar));
325 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
331 gtk_progress_bar_new (void)
335 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL);
341 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
345 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
347 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR,
348 "adjustment", adjustment,
355 gtk_progress_bar_real_update (GtkProgress *progress)
357 GtkProgressBar *pbar;
360 g_return_if_fail (GTK_IS_PROGRESS (progress));
362 pbar = GTK_PROGRESS_BAR (progress);
363 widget = GTK_WIDGET (progress);
365 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
366 GTK_PROGRESS (pbar)->activity_mode)
368 if (GTK_PROGRESS (pbar)->activity_mode)
372 /* advance the block */
374 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
375 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
377 /* Update our activity step. */
379 pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
381 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
383 if (pbar->activity_dir == 0)
385 pbar->activity_pos += pbar->activity_step;
386 if (pbar->activity_pos + size >=
387 widget->allocation.width -
388 widget->style->xthickness)
390 pbar->activity_pos = widget->allocation.width -
391 widget->style->xthickness - size;
392 pbar->activity_dir = 1;
397 pbar->activity_pos -= pbar->activity_step;
398 if (pbar->activity_pos <= widget->style->xthickness)
400 pbar->activity_pos = widget->style->xthickness;
401 pbar->activity_dir = 0;
407 /* Update our activity step. */
409 pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
411 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
413 if (pbar->activity_dir == 0)
415 pbar->activity_pos += pbar->activity_step;
416 if (pbar->activity_pos + size >=
417 widget->allocation.height -
418 widget->style->ythickness)
420 pbar->activity_pos = widget->allocation.height -
421 widget->style->ythickness - size;
422 pbar->activity_dir = 1;
427 pbar->activity_pos -= pbar->activity_step;
428 if (pbar->activity_pos <= widget->style->ythickness)
430 pbar->activity_pos = widget->style->ythickness;
431 pbar->activity_dir = 0;
436 gtk_progress_bar_paint (progress);
437 gtk_widget_queue_draw (GTK_WIDGET (progress));
443 in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
444 (gdouble)pbar->blocks);
446 if (pbar->in_block != in_block)
448 pbar->in_block = in_block;
449 gtk_progress_bar_paint (progress);
450 gtk_widget_queue_draw (GTK_WIDGET (progress));
456 gtk_progress_bar_size_request (GtkWidget *widget,
457 GtkRequisition *requisition)
459 GtkProgress *progress;
460 GtkProgressBar *pbar;
462 PangoRectangle logical_rect;
465 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
466 g_return_if_fail (requisition != NULL);
468 progress = GTK_PROGRESS (widget);
469 pbar = GTK_PROGRESS_BAR (widget);
471 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
473 if (!progress->adjustment)
474 gtk_progress_set_adjustment (progress, NULL);
476 buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
478 layout = gtk_widget_create_pango_layout (widget, buf);
479 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
481 g_object_unref (layout);
485 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
486 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
488 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
490 requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH,
491 2 * widget->style->xthickness + 3 +
492 logical_rect.width + 2 * TEXT_SPACING);
494 requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
495 2 * widget->style->ythickness + 3 +
496 logical_rect.height + 2 * TEXT_SPACING);
500 requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
501 requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
506 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
508 requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH,
509 2 * widget->style->xthickness + 3 +
510 logical_rect.width + 2 * TEXT_SPACING);
512 requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
513 2 * widget->style->ythickness + 3 +
514 logical_rect.height + 2 * TEXT_SPACING);
518 requisition->width = MIN_VERTICAL_BAR_WIDTH;
519 requisition->height = MIN_VERTICAL_BAR_HEIGHT;
525 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
527 GtkProgressBar *pbar;
530 GtkProgressBarOrientation orientation;
532 pbar = GTK_PROGRESS_BAR (progress);
533 widget = GTK_WIDGET (progress);
535 orientation = pbar->orientation;
536 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
538 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
539 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
540 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
541 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
544 /* calculate start pos */
546 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
547 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
549 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
551 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
553 pbar->activity_pos = widget->style->xthickness;
554 pbar->activity_dir = 0;
558 pbar->activity_pos = widget->allocation.width -
559 widget->style->xthickness - (widget->allocation.height -
560 widget->style->ythickness * 2);
561 pbar->activity_dir = 1;
566 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
568 if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
570 pbar->activity_pos = widget->style->ythickness;
571 pbar->activity_dir = 0;
575 pbar->activity_pos = widget->allocation.height -
576 widget->style->ythickness - (widget->allocation.width -
577 widget->style->xthickness * 2);
578 pbar->activity_dir = 1;
584 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
585 GtkProgressBarOrientation orientation)
587 GtkWidget *widget = GTK_WIDGET (pbar);
588 GtkProgress *progress = GTK_PROGRESS (pbar);
593 case GTK_PROGRESS_LEFT_TO_RIGHT:
594 case GTK_PROGRESS_RIGHT_TO_LEFT:
595 x = pbar->activity_pos;
596 y = widget->style->ythickness;
597 w = MAX (2, widget->allocation.width / pbar->activity_blocks);
598 h = widget->allocation.height - 2 * widget->style->ythickness;
601 case GTK_PROGRESS_TOP_TO_BOTTOM:
602 case GTK_PROGRESS_BOTTOM_TO_TOP:
603 x = widget->style->xthickness;
604 y = pbar->activity_pos;
605 w = widget->allocation.width - 2 * widget->style->xthickness;
606 h = MAX (2, widget->allocation.height / pbar->activity_blocks);
614 gtk_paint_box (widget->style,
615 progress->offscreen_pixmap,
616 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
622 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
624 GtkProgressBarOrientation orientation)
626 GtkWidget *widget = GTK_WIDGET (pbar);
634 case GTK_PROGRESS_LEFT_TO_RIGHT:
635 case GTK_PROGRESS_RIGHT_TO_LEFT:
637 h = widget->allocation.height - widget->style->ythickness * 2;
638 y = widget->style->ythickness;
640 x = widget->style->xthickness;
641 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
642 x = widget->allocation.width - amount - x;
645 case GTK_PROGRESS_TOP_TO_BOTTOM:
646 case GTK_PROGRESS_BOTTOM_TO_TOP:
647 w = widget->allocation.width - widget->style->xthickness * 2;
649 x = widget->style->xthickness;
651 y = widget->style->ythickness;
652 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
653 y = widget->allocation.height - amount - y;
661 gtk_paint_box (widget->style,
662 GTK_PROGRESS (pbar)->offscreen_pixmap,
663 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
669 gtk_progress_bar_paint_discrete (GtkProgressBar *pbar,
670 GtkProgressBarOrientation orientation)
672 GtkWidget *widget = GTK_WIDGET (pbar);
675 for (i = 0; i <= pbar->in_block; i++)
677 gint x, y, w, h, space;
681 case GTK_PROGRESS_LEFT_TO_RIGHT:
682 case GTK_PROGRESS_RIGHT_TO_LEFT:
683 space = widget->allocation.width - 2 * widget->style->xthickness;
685 x = widget->style->xthickness + (i * space) / pbar->blocks;
686 y = widget->style->ythickness;
687 w = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - x;
688 h = widget->allocation.height - 2 * widget->style->ythickness;
690 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
691 x = widget->allocation.width - w - x;
694 case GTK_PROGRESS_TOP_TO_BOTTOM:
695 case GTK_PROGRESS_BOTTOM_TO_TOP:
696 space = widget->allocation.height - 2 * widget->style->ythickness;
698 x = widget->style->xthickness;
699 y = widget->style->ythickness + (i * space) / pbar->blocks;
700 w = widget->allocation.width - 2 * widget->style->xthickness;
701 h = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - y;
703 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
704 y = widget->allocation.height - h - y;
712 gtk_paint_box (widget->style,
713 GTK_PROGRESS (pbar)->offscreen_pixmap,
714 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
721 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
723 GtkProgressBarOrientation orientation)
725 GtkProgress *progress = GTK_PROGRESS (pbar);
726 GtkWidget *widget = GTK_WIDGET (pbar);
733 PangoRectangle logical_rect;
734 GdkRectangle prelight_clip, normal_clip;
736 buf = gtk_progress_get_current_text (progress);
738 layout = gtk_widget_create_pango_layout (widget, buf);
739 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
741 x = widget->style->xthickness + 1 +
742 (widget->allocation.width - 2 * widget->style->xthickness -
743 2 - logical_rect.width)
746 y = widget->style->ythickness + 1 +
747 (widget->allocation.height - 2 * widget->style->ythickness -
748 2 - logical_rect.height)
751 rect.x = widget->style->xthickness;
752 rect.y = widget->style->ythickness;
753 rect.width = widget->allocation.width - 2 * widget->style->xthickness;
754 rect.height = widget->allocation.height - 2 * widget->style->ythickness;
756 prelight_clip = normal_clip = rect;
760 case GTK_PROGRESS_LEFT_TO_RIGHT:
761 prelight_clip.width = amount;
762 normal_clip.x += amount;
763 normal_clip.width -= amount;
766 case GTK_PROGRESS_RIGHT_TO_LEFT:
767 normal_clip.width -= amount;
768 prelight_clip.x += normal_clip.width;
769 prelight_clip.width -= normal_clip.width;
772 case GTK_PROGRESS_TOP_TO_BOTTOM:
773 prelight_clip.height = amount;
774 normal_clip.y += amount;
775 normal_clip.height -= amount;
778 case GTK_PROGRESS_BOTTOM_TO_TOP:
779 normal_clip.height -= amount;
780 prelight_clip.y += normal_clip.height;
781 prelight_clip.height -= normal_clip.height;
785 gtk_paint_layout (widget->style,
786 progress->offscreen_pixmap,
795 gtk_paint_layout (widget->style,
796 progress->offscreen_pixmap,
805 g_object_unref (layout);
810 gtk_progress_bar_paint (GtkProgress *progress)
812 GtkProgressBar *pbar;
815 GtkProgressBarOrientation orientation;
817 g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
819 pbar = GTK_PROGRESS_BAR (progress);
820 widget = GTK_WIDGET (progress);
822 orientation = pbar->orientation;
823 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
825 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
826 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
827 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
828 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
831 if (progress->offscreen_pixmap)
833 gtk_paint_box (widget->style,
834 progress->offscreen_pixmap,
835 GTK_STATE_NORMAL, GTK_SHADOW_IN,
836 NULL, widget, "trough",
838 widget->allocation.width,
839 widget->allocation.height);
841 if (progress->activity_mode)
843 gtk_progress_bar_paint_activity (pbar, orientation);
850 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
851 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
852 space = widget->allocation.width - 2 * widget->style->xthickness;
854 space = widget->allocation.height - 2 * widget->style->ythickness;
857 gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
859 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
861 gtk_progress_bar_paint_continuous (pbar, amount, orientation);
863 if (GTK_PROGRESS (pbar)->show_text)
864 gtk_progress_bar_paint_text (pbar, amount, orientation);
867 gtk_progress_bar_paint_discrete (pbar, orientation);
873 gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
874 GtkProgressBarStyle bar_style)
876 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
878 if (pbar->bar_style != bar_style)
880 pbar->bar_style = bar_style;
882 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
883 gtk_widget_queue_resize (GTK_WIDGET (pbar));
885 g_object_notify (G_OBJECT (pbar), "bar_style");
890 gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
893 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
894 g_return_if_fail (blocks > 1);
896 if (pbar->blocks != blocks)
898 pbar->blocks = blocks;
900 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
901 gtk_widget_queue_resize (GTK_WIDGET (pbar));
903 g_object_notify (G_OBJECT (pbar), "discrete_blocks");
908 gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
911 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
913 if (pbar->activity_step != step)
915 pbar->activity_step = step;
916 g_object_notify (G_OBJECT (pbar), "activity_step");
921 gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
924 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
925 g_return_if_fail (blocks > 1);
927 if (pbar->activity_blocks != blocks)
929 pbar->activity_blocks = blocks;
930 g_object_notify (G_OBJECT (pbar), "activity_blocks");
934 /*******************************************************************/
937 * gtk_progress_bar_set_fraction:
938 * @pbar: a #GtkProgressBar
939 * @fraction: fraction of the task that's been completed
941 * Causes the progress bar to "fill in" the given fraction
942 * of the bar. The fraction should be between 0.0 and 1.0,
947 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
950 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
952 /* If we know the percentage, we don't want activity mode. */
953 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
955 /* We use the deprecated GtkProgress interface internally.
956 * Once everything's been deprecated for a good long time,
957 * we can clean up all this code.
959 gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
961 g_object_notify (G_OBJECT (pbar), "fraction");
965 * gtk_progress_bar_pulse:
966 * @pbar: a #GtkProgressBar
968 * Indicates that some progress is made, but you don't know how much.
969 * Causes the progress bar to enter "activity mode," where a block
970 * bounces back and forth. Each call to gtk_progress_bar_pulse()
971 * causes the block to move by a little bit (the amount of movement
972 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
975 gtk_progress_bar_pulse (GtkProgressBar *pbar)
977 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
979 /* If we don't know the percentage, we must want activity mode. */
980 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
983 gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
987 * gtk_progress_bar_set_text:
988 * @pbar: a #GtkProgressBar
989 * @text: a UTF-8 string
991 * Causes the given @text to appear superimposed on the progress bar.
994 gtk_progress_bar_set_text (GtkProgressBar *pbar,
997 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
999 gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
1000 gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
1002 /* We don't support formats in this interface, but turn
1003 * them back on for NULL, which should put us back to
1004 * the initial state.
1006 GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
1008 g_object_notify (G_OBJECT (pbar), "text");
1012 * gtk_progress_bar_set_pulse_step:
1013 * @pbar: a #GtkProgressBar
1014 * @fraction: fraction between 0.0 and 1.0
1016 * Sets the fraction of total progress bar length to move the
1017 * bouncing block for each call to gtk_progress_bar_pulse().
1020 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1023 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1025 pbar->pulse_fraction = fraction;
1027 g_object_notify (G_OBJECT (pbar), "pulse_step");
1031 gtk_progress_bar_update (GtkProgressBar *pbar,
1034 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1036 /* Use of gtk_progress_bar_update() is deprecated !
1037 * Use gtk_progress_bar_set_percentage ()
1040 gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
1044 * gtk_progress_bar_set_orientation:
1045 * @pbar: a #GtkProgressBar
1046 * @orientation: orientation of the progress bar
1048 * Causes the progress bar to switch to a different orientation
1049 * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
1052 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1053 GtkProgressBarOrientation orientation)
1055 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1057 if (pbar->orientation != orientation)
1059 pbar->orientation = orientation;
1061 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1062 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1064 g_object_notify (G_OBJECT (pbar), "orientation");
1069 * gtk_progress_bar_get_text:
1070 * @pbar: a #GtkProgressBar
1072 * Retrieves the text displayed superimposed on the progress bar,
1073 * if any, otherwise %NULL. The return value is a reference
1074 * to the text, not a copy of it, so will become invalid
1075 * if you change the text in the progress bar.
1077 * Return value: text, or %NULL; this string is owned by the widget
1078 * and should not be modified or freed.
1080 G_CONST_RETURN gchar*
1081 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1083 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1085 if (GTK_PROGRESS (pbar)->use_text_format)
1088 return GTK_PROGRESS (pbar)->format;
1092 * gtk_progress_bar_get_fraction:
1093 * @pbar: a #GtkProgressBar
1095 * Returns the current fraction of the task that's been completed.
1097 * Return value: a fraction from 0.0 to 1.0
1100 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1102 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1104 return gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1108 * gtk_progress_bar_get_pulse_step:
1109 * @pbar: a #GtkProgressBar
1111 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1113 * Return value: a fraction from 0.0 to 1.0
1116 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1118 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1120 return pbar->pulse_fraction;
1124 * gtk_progress_bar_get_orientation:
1125 * @pbar: a #GtkProgressBar
1127 * Retrieves the current progress bar orientation.
1129 * Return value: orientation of the progress bar
1131 GtkProgressBarOrientation
1132 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1134 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1136 return pbar->orientation;
1140 gtk_progress_bar_set_bar_style (GtkProgressBar *pbar,
1141 GtkProgressBarStyle bar_style)
1143 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1145 gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
1149 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
1152 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1153 g_return_if_fail (blocks > 1);
1155 gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
1159 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
1162 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1164 gtk_progress_bar_set_activity_step_internal (pbar, step);
1168 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
1171 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1172 g_return_if_fail (blocks > 1);
1174 gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);