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"
42 #define MIN_HORIZONTAL_BAR_WIDTH 150
43 #define MIN_HORIZONTAL_BAR_HEIGHT 20
44 #define MIN_VERTICAL_BAR_WIDTH 22
45 #define MIN_VERTICAL_BAR_HEIGHT 80
46 #define MAX_TEXT_LENGTH 80
47 #define TEXT_SPACING 2
67 static void gtk_progress_bar_class_init (GtkProgressBarClass *klass);
68 static void gtk_progress_bar_init (GtkProgressBar *pbar);
69 static void gtk_progress_bar_set_property (GObject *object,
73 static void gtk_progress_bar_get_property (GObject *object,
77 static void gtk_progress_bar_size_request (GtkWidget *widget,
78 GtkRequisition *requisition);
79 static void gtk_progress_bar_real_update (GtkProgress *progress);
80 static void gtk_progress_bar_paint (GtkProgress *progress);
81 static void gtk_progress_bar_act_mode_enter (GtkProgress *progress);
83 static void gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
84 GtkProgressBarStyle style);
85 static void gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
87 static void gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
89 static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
94 gtk_progress_bar_get_type (void)
96 static GType progress_bar_type = 0;
98 if (!progress_bar_type)
100 static const GTypeInfo progress_bar_info =
102 sizeof (GtkProgressBarClass),
103 NULL, /* base_init */
104 NULL, /* base_finalize */
105 (GClassInitFunc) gtk_progress_bar_class_init,
106 NULL, /* class_finalize */
107 NULL, /* class_data */
108 sizeof (GtkProgressBar),
110 (GInstanceInitFunc) gtk_progress_bar_init,
114 g_type_register_static (GTK_TYPE_PROGRESS, "GtkProgressBar",
115 &progress_bar_info, 0);
118 return progress_bar_type;
122 gtk_progress_bar_class_init (GtkProgressBarClass *class)
124 GObjectClass *gobject_class;
125 GtkWidgetClass *widget_class;
126 GtkProgressClass *progress_class;
128 gobject_class = G_OBJECT_CLASS (class);
129 widget_class = (GtkWidgetClass *) class;
130 progress_class = (GtkProgressClass *) class;
132 gobject_class->set_property = gtk_progress_bar_set_property;
133 gobject_class->get_property = gtk_progress_bar_get_property;
135 widget_class->size_request = gtk_progress_bar_size_request;
137 progress_class->paint = gtk_progress_bar_paint;
138 progress_class->update = gtk_progress_bar_real_update;
139 progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
141 g_object_class_install_property (gobject_class,
143 g_param_spec_object ("adjustment",
145 P_("The GtkAdjustment connected to the progress bar (Deprecated)"),
149 g_object_class_install_property (gobject_class,
151 g_param_spec_enum ("orientation",
153 P_("Orientation and growth direction of the progress bar"),
154 GTK_TYPE_PROGRESS_BAR_ORIENTATION,
155 GTK_PROGRESS_LEFT_TO_RIGHT,
158 g_object_class_install_property (gobject_class,
160 g_param_spec_enum ("bar-style",
162 P_("Specifies the visual style of the bar in percentage mode (Deprecated)"),
163 GTK_TYPE_PROGRESS_BAR_STYLE,
164 GTK_PROGRESS_CONTINUOUS,
167 g_object_class_install_property (gobject_class,
169 g_param_spec_uint ("activity-step",
171 P_("The increment used for each iteration in activity mode (Deprecated)"),
177 g_object_class_install_property (gobject_class,
178 PROP_ACTIVITY_BLOCKS,
179 g_param_spec_uint ("activity-blocks",
180 P_("Activity Blocks"),
181 P_("The number of blocks which can fit in the progress bar area in activity mode (Deprecated)"),
187 g_object_class_install_property (gobject_class,
188 PROP_DISCRETE_BLOCKS,
189 g_param_spec_uint ("discrete-blocks",
190 P_("Discrete Blocks"),
191 P_("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
197 g_object_class_install_property (gobject_class,
199 g_param_spec_double ("fraction",
201 P_("The fraction of total work that has been completed"),
207 g_object_class_install_property (gobject_class,
209 g_param_spec_double ("pulse-step",
211 P_("The fraction of total progress to move the bouncing block when pulsed"),
217 g_object_class_install_property (gobject_class,
219 g_param_spec_string ("text",
221 P_("Text to be displayed in the progress bar"),
226 * GtkProgressBar:ellipsize:
228 * The preferred place to ellipsize the string, if the progressbar does
229 * not have enough room to display the entire string, specified as a
230 * #PangoEllisizeMode.
232 * Note that setting this property to a value other than
233 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
234 * only enough space to display the ellipsis "...". Another means to set a
235 * progressbar's width is gtk_widget_set_size_request().
239 g_object_class_install_property (gobject_class,
241 g_param_spec_enum ("ellipsize",
243 P_("The preferred place to ellipsize the string, if the progressbar does not have enough room to display the entire string, if at all"),
244 PANGO_TYPE_ELLIPSIZE_MODE,
245 PANGO_ELLIPSIZE_NONE,
251 gtk_progress_bar_init (GtkProgressBar *pbar)
253 pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
256 pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
257 pbar->pulse_fraction = 0.1;
258 pbar->activity_pos = 0;
259 pbar->activity_dir = 1;
260 pbar->activity_step = 3;
261 pbar->activity_blocks = 5;
262 pbar->ellipsize = PANGO_ELLIPSIZE_NONE;
266 gtk_progress_bar_set_property (GObject *object,
271 GtkProgressBar *pbar;
273 pbar = GTK_PROGRESS_BAR (object);
277 case PROP_ADJUSTMENT:
278 gtk_progress_set_adjustment (GTK_PROGRESS (pbar),
279 GTK_ADJUSTMENT (g_value_get_object (value)));
281 case PROP_ORIENTATION:
282 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
285 gtk_progress_bar_set_bar_style_internal (pbar, g_value_get_enum (value));
287 case PROP_ACTIVITY_STEP:
288 gtk_progress_bar_set_activity_step_internal (pbar, g_value_get_uint (value));
290 case PROP_ACTIVITY_BLOCKS:
291 gtk_progress_bar_set_activity_blocks_internal (pbar, g_value_get_uint (value));
293 case PROP_DISCRETE_BLOCKS:
294 gtk_progress_bar_set_discrete_blocks_internal (pbar, g_value_get_uint (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_ellipsize (pbar, g_value_get_enum (value));
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 gtk_progress_bar_get_property (GObject *object,
320 GtkProgressBar *pbar;
322 pbar = GTK_PROGRESS_BAR (object);
326 case PROP_ADJUSTMENT:
327 g_value_set_object (value, GTK_PROGRESS (pbar)->adjustment);
329 case PROP_ORIENTATION:
330 g_value_set_enum (value, pbar->orientation);
333 g_value_set_enum (value, pbar->bar_style);
335 case PROP_ACTIVITY_STEP:
336 g_value_set_uint (value, pbar->activity_step);
338 case PROP_ACTIVITY_BLOCKS:
339 g_value_set_uint (value, pbar->activity_blocks);
341 case PROP_DISCRETE_BLOCKS:
342 g_value_set_uint (value, pbar->blocks);
345 g_value_set_double (value, gtk_progress_get_current_percentage (GTK_PROGRESS (pbar)));
347 case PROP_PULSE_STEP:
348 g_value_set_double (value, pbar->pulse_fraction);
351 g_value_set_string (value, gtk_progress_bar_get_text (pbar));
354 g_value_set_enum (value, pbar->ellipsize);
357 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
363 gtk_progress_bar_new (void)
367 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL);
373 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
377 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
379 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR,
380 "adjustment", adjustment,
387 gtk_progress_bar_real_update (GtkProgress *progress)
389 GtkProgressBar *pbar;
392 g_return_if_fail (GTK_IS_PROGRESS (progress));
394 pbar = GTK_PROGRESS_BAR (progress);
395 widget = GTK_WIDGET (progress);
397 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
398 GTK_PROGRESS (pbar)->activity_mode)
400 if (GTK_PROGRESS (pbar)->activity_mode)
404 /* advance the block */
406 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
407 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
409 /* Update our activity step. */
411 pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
413 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
415 if (pbar->activity_dir == 0)
417 pbar->activity_pos += pbar->activity_step;
418 if (pbar->activity_pos + size >=
419 widget->allocation.width -
420 widget->style->xthickness)
422 pbar->activity_pos = widget->allocation.width -
423 widget->style->xthickness - size;
424 pbar->activity_dir = 1;
429 pbar->activity_pos -= pbar->activity_step;
430 if (pbar->activity_pos <= widget->style->xthickness)
432 pbar->activity_pos = widget->style->xthickness;
433 pbar->activity_dir = 0;
439 /* Update our activity step. */
441 pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
443 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
445 if (pbar->activity_dir == 0)
447 pbar->activity_pos += pbar->activity_step;
448 if (pbar->activity_pos + size >=
449 widget->allocation.height -
450 widget->style->ythickness)
452 pbar->activity_pos = widget->allocation.height -
453 widget->style->ythickness - size;
454 pbar->activity_dir = 1;
459 pbar->activity_pos -= pbar->activity_step;
460 if (pbar->activity_pos <= widget->style->ythickness)
462 pbar->activity_pos = widget->style->ythickness;
463 pbar->activity_dir = 0;
468 gtk_progress_bar_paint (progress);
469 gtk_widget_queue_draw (GTK_WIDGET (progress));
475 in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
476 (gdouble)pbar->blocks);
478 if (pbar->in_block != in_block)
480 pbar->in_block = in_block;
481 gtk_progress_bar_paint (progress);
482 gtk_widget_queue_draw (GTK_WIDGET (progress));
488 gtk_progress_bar_size_request (GtkWidget *widget,
489 GtkRequisition *requisition)
491 GtkProgress *progress;
492 GtkProgressBar *pbar;
494 PangoRectangle logical_rect;
498 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
499 g_return_if_fail (requisition != NULL);
501 progress = GTK_PROGRESS (widget);
502 pbar = GTK_PROGRESS_BAR (widget);
504 width = 2 * widget->style->xthickness + 3 + 2 * TEXT_SPACING;
505 height = 2 * widget->style->ythickness + 3 + 2 * TEXT_SPACING;
507 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
509 if (!progress->adjustment)
510 gtk_progress_set_adjustment (progress, NULL);
512 buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
514 layout = gtk_widget_create_pango_layout (widget, buf);
516 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
520 PangoContext *context;
521 PangoFontMetrics *metrics;
524 /* The minimum size for ellipsized text is ~ 3 chars */
525 context = pango_layout_get_context (layout);
526 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
528 char_width = pango_font_metrics_get_approximate_char_width (metrics);
529 pango_font_metrics_unref (metrics);
531 width += PANGO_PIXELS (char_width) * 3;
534 width += logical_rect.width;
536 height += logical_rect.height;
538 g_object_unref (layout);
542 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
543 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
545 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
547 requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH, width);
548 requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT, height);
552 requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
553 requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
558 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
560 requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH, width);
561 requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT, height);
565 requisition->width = MIN_VERTICAL_BAR_WIDTH;
566 requisition->height = MIN_VERTICAL_BAR_HEIGHT;
572 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
574 GtkProgressBar *pbar;
577 GtkProgressBarOrientation orientation;
579 pbar = GTK_PROGRESS_BAR (progress);
580 widget = GTK_WIDGET (progress);
582 orientation = pbar->orientation;
583 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
585 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
586 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
587 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
588 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
591 /* calculate start pos */
593 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
594 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
596 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
598 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
600 pbar->activity_pos = widget->style->xthickness;
601 pbar->activity_dir = 0;
605 pbar->activity_pos = widget->allocation.width -
606 widget->style->xthickness - (widget->allocation.height -
607 widget->style->ythickness * 2);
608 pbar->activity_dir = 1;
613 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
615 if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
617 pbar->activity_pos = widget->style->ythickness;
618 pbar->activity_dir = 0;
622 pbar->activity_pos = widget->allocation.height -
623 widget->style->ythickness - (widget->allocation.width -
624 widget->style->xthickness * 2);
625 pbar->activity_dir = 1;
631 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
632 GtkProgressBarOrientation orientation)
634 GtkWidget *widget = GTK_WIDGET (pbar);
635 GtkProgress *progress = GTK_PROGRESS (pbar);
640 case GTK_PROGRESS_LEFT_TO_RIGHT:
641 case GTK_PROGRESS_RIGHT_TO_LEFT:
642 x = pbar->activity_pos;
643 y = widget->style->ythickness;
644 w = MAX (2, widget->allocation.width / pbar->activity_blocks);
645 h = widget->allocation.height - 2 * widget->style->ythickness;
648 case GTK_PROGRESS_TOP_TO_BOTTOM:
649 case GTK_PROGRESS_BOTTOM_TO_TOP:
650 x = widget->style->xthickness;
651 y = pbar->activity_pos;
652 w = widget->allocation.width - 2 * widget->style->xthickness;
653 h = MAX (2, widget->allocation.height / pbar->activity_blocks);
661 gtk_paint_box (widget->style,
662 progress->offscreen_pixmap,
663 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
669 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
671 GtkProgressBarOrientation orientation)
673 GtkWidget *widget = GTK_WIDGET (pbar);
681 case GTK_PROGRESS_LEFT_TO_RIGHT:
682 case GTK_PROGRESS_RIGHT_TO_LEFT:
684 h = widget->allocation.height - widget->style->ythickness * 2;
685 y = widget->style->ythickness;
687 x = widget->style->xthickness;
688 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
689 x = widget->allocation.width - amount - x;
692 case GTK_PROGRESS_TOP_TO_BOTTOM:
693 case GTK_PROGRESS_BOTTOM_TO_TOP:
694 w = widget->allocation.width - widget->style->xthickness * 2;
696 x = widget->style->xthickness;
698 y = widget->style->ythickness;
699 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
700 y = widget->allocation.height - amount - y;
708 gtk_paint_box (widget->style,
709 GTK_PROGRESS (pbar)->offscreen_pixmap,
710 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
716 gtk_progress_bar_paint_discrete (GtkProgressBar *pbar,
717 GtkProgressBarOrientation orientation)
719 GtkWidget *widget = GTK_WIDGET (pbar);
722 for (i = 0; i <= pbar->in_block; i++)
724 gint x, y, w, h, space;
728 case GTK_PROGRESS_LEFT_TO_RIGHT:
729 case GTK_PROGRESS_RIGHT_TO_LEFT:
730 space = widget->allocation.width - 2 * widget->style->xthickness;
732 x = widget->style->xthickness + (i * space) / pbar->blocks;
733 y = widget->style->ythickness;
734 w = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - x;
735 h = widget->allocation.height - 2 * widget->style->ythickness;
737 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
738 x = widget->allocation.width - w - x;
741 case GTK_PROGRESS_TOP_TO_BOTTOM:
742 case GTK_PROGRESS_BOTTOM_TO_TOP:
743 space = widget->allocation.height - 2 * widget->style->ythickness;
745 x = widget->style->xthickness;
746 y = widget->style->ythickness + (i * space) / pbar->blocks;
747 w = widget->allocation.width - 2 * widget->style->xthickness;
748 h = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - y;
750 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
751 y = widget->allocation.height - h - y;
759 gtk_paint_box (widget->style,
760 GTK_PROGRESS (pbar)->offscreen_pixmap,
761 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
768 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
770 GtkProgressBarOrientation orientation)
772 GtkProgress *progress = GTK_PROGRESS (pbar);
773 GtkWidget *widget = GTK_WIDGET (pbar);
780 PangoRectangle logical_rect;
781 GdkRectangle prelight_clip, normal_clip;
783 buf = gtk_progress_get_current_text (progress);
785 layout = gtk_widget_create_pango_layout (widget, buf);
786 pango_layout_set_ellipsize (layout, pbar->ellipsize);
788 pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
790 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
792 x = widget->style->xthickness + 1 +
793 (widget->allocation.width - 2 * widget->style->xthickness -
794 2 - logical_rect.width)
797 y = widget->style->ythickness + 1 +
798 (widget->allocation.height - 2 * widget->style->ythickness -
799 2 - logical_rect.height)
802 rect.x = widget->style->xthickness;
803 rect.y = widget->style->ythickness;
804 rect.width = widget->allocation.width - 2 * widget->style->xthickness;
805 rect.height = widget->allocation.height - 2 * widget->style->ythickness;
807 prelight_clip = normal_clip = rect;
811 case GTK_PROGRESS_LEFT_TO_RIGHT:
812 prelight_clip.width = amount;
813 normal_clip.x += amount;
814 normal_clip.width -= amount;
817 case GTK_PROGRESS_RIGHT_TO_LEFT:
818 normal_clip.width -= amount;
819 prelight_clip.x += normal_clip.width;
820 prelight_clip.width -= normal_clip.width;
823 case GTK_PROGRESS_TOP_TO_BOTTOM:
824 prelight_clip.height = amount;
825 normal_clip.y += amount;
826 normal_clip.height -= amount;
829 case GTK_PROGRESS_BOTTOM_TO_TOP:
830 normal_clip.height -= amount;
831 prelight_clip.y += normal_clip.height;
832 prelight_clip.height -= normal_clip.height;
836 gtk_paint_layout (widget->style,
837 progress->offscreen_pixmap,
846 gtk_paint_layout (widget->style,
847 progress->offscreen_pixmap,
856 g_object_unref (layout);
861 gtk_progress_bar_paint (GtkProgress *progress)
863 GtkProgressBar *pbar;
866 GtkProgressBarOrientation orientation;
868 g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
870 pbar = GTK_PROGRESS_BAR (progress);
871 widget = GTK_WIDGET (progress);
873 orientation = pbar->orientation;
874 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
876 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
877 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
878 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
879 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
882 if (progress->offscreen_pixmap)
884 gtk_paint_box (widget->style,
885 progress->offscreen_pixmap,
886 GTK_STATE_NORMAL, GTK_SHADOW_IN,
887 NULL, widget, "trough",
889 widget->allocation.width,
890 widget->allocation.height);
892 if (progress->activity_mode)
894 gtk_progress_bar_paint_activity (pbar, orientation);
901 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
902 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
903 space = widget->allocation.width - 2 * widget->style->xthickness;
905 space = widget->allocation.height - 2 * widget->style->ythickness;
908 gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
910 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
912 gtk_progress_bar_paint_continuous (pbar, amount, orientation);
914 if (GTK_PROGRESS (pbar)->show_text)
915 gtk_progress_bar_paint_text (pbar, amount, orientation);
918 gtk_progress_bar_paint_discrete (pbar, orientation);
924 gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
925 GtkProgressBarStyle bar_style)
927 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
929 if (pbar->bar_style != bar_style)
931 pbar->bar_style = bar_style;
933 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
934 gtk_widget_queue_resize (GTK_WIDGET (pbar));
936 g_object_notify (G_OBJECT (pbar), "bar_style");
941 gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
944 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
945 g_return_if_fail (blocks > 1);
947 if (pbar->blocks != blocks)
949 pbar->blocks = blocks;
951 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
952 gtk_widget_queue_resize (GTK_WIDGET (pbar));
954 g_object_notify (G_OBJECT (pbar), "discrete_blocks");
959 gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
962 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
964 if (pbar->activity_step != step)
966 pbar->activity_step = step;
967 g_object_notify (G_OBJECT (pbar), "activity_step");
972 gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
975 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
976 g_return_if_fail (blocks > 1);
978 if (pbar->activity_blocks != blocks)
980 pbar->activity_blocks = blocks;
981 g_object_notify (G_OBJECT (pbar), "activity_blocks");
985 /*******************************************************************/
988 * gtk_progress_bar_set_fraction:
989 * @pbar: a #GtkProgressBar
990 * @fraction: fraction of the task that's been completed
992 * Causes the progress bar to "fill in" the given fraction
993 * of the bar. The fraction should be between 0.0 and 1.0,
998 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
1001 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1003 /* If we know the percentage, we don't want activity mode. */
1004 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
1006 /* We use the deprecated GtkProgress interface internally.
1007 * Once everything's been deprecated for a good long time,
1008 * we can clean up all this code.
1010 gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
1012 g_object_notify (G_OBJECT (pbar), "fraction");
1016 * gtk_progress_bar_pulse:
1017 * @pbar: a #GtkProgressBar
1019 * Indicates that some progress is made, but you don't know how much.
1020 * Causes the progress bar to enter "activity mode," where a block
1021 * bounces back and forth. Each call to gtk_progress_bar_pulse()
1022 * causes the block to move by a little bit (the amount of movement
1023 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
1026 gtk_progress_bar_pulse (GtkProgressBar *pbar)
1028 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1030 /* If we don't know the percentage, we must want activity mode. */
1031 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
1034 gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
1038 * gtk_progress_bar_set_text:
1039 * @pbar: a #GtkProgressBar
1040 * @text: a UTF-8 string
1042 * Causes the given @text to appear superimposed on the progress bar.
1045 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1048 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1050 gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
1051 gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
1053 /* We don't support formats in this interface, but turn
1054 * them back on for NULL, which should put us back to
1055 * the initial state.
1057 GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
1059 g_object_notify (G_OBJECT (pbar), "text");
1063 * gtk_progress_bar_set_pulse_step:
1064 * @pbar: a #GtkProgressBar
1065 * @fraction: fraction between 0.0 and 1.0
1067 * Sets the fraction of total progress bar length to move the
1068 * bouncing block for each call to gtk_progress_bar_pulse().
1071 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1074 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1076 pbar->pulse_fraction = fraction;
1078 g_object_notify (G_OBJECT (pbar), "pulse_step");
1082 gtk_progress_bar_update (GtkProgressBar *pbar,
1085 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1087 /* Use of gtk_progress_bar_update() is deprecated !
1088 * Use gtk_progress_bar_set_percentage ()
1091 gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
1095 * gtk_progress_bar_set_orientation:
1096 * @pbar: a #GtkProgressBar
1097 * @orientation: orientation of the progress bar
1099 * Causes the progress bar to switch to a different orientation
1100 * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
1103 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1104 GtkProgressBarOrientation orientation)
1106 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1108 if (pbar->orientation != orientation)
1110 pbar->orientation = orientation;
1112 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1113 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1115 g_object_notify (G_OBJECT (pbar), "orientation");
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 if (GTK_PROGRESS (pbar)->use_text_format)
1139 return GTK_PROGRESS (pbar)->format;
1143 * gtk_progress_bar_get_fraction:
1144 * @pbar: a #GtkProgressBar
1146 * Returns the current fraction of the task that's been completed.
1148 * Return value: a fraction from 0.0 to 1.0
1151 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1153 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1155 return gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1159 * gtk_progress_bar_get_pulse_step:
1160 * @pbar: a #GtkProgressBar
1162 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1164 * Return value: a fraction from 0.0 to 1.0
1167 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1169 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1171 return pbar->pulse_fraction;
1175 * gtk_progress_bar_get_orientation:
1176 * @pbar: a #GtkProgressBar
1178 * Retrieves the current progress bar orientation.
1180 * Return value: orientation of the progress bar
1182 GtkProgressBarOrientation
1183 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1185 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1187 return pbar->orientation;
1191 gtk_progress_bar_set_bar_style (GtkProgressBar *pbar,
1192 GtkProgressBarStyle bar_style)
1194 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1196 gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
1200 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
1203 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1204 g_return_if_fail (blocks > 1);
1206 gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
1210 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
1213 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1215 gtk_progress_bar_set_activity_step_internal (pbar, step);
1219 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
1222 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1223 g_return_if_fail (blocks > 1);
1225 gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);
1229 * gtk_progress_bar_set_ellipsize:
1230 * @pbar: a #GtkProgressBar
1231 * @mode: a #PangoEllipsizeMode
1233 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1234 * if there is not enough space to render the entire string.
1239 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1240 PangoEllipsizeMode mode)
1242 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1243 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1244 mode <= PANGO_ELLIPSIZE_END);
1246 if ((PangoEllipsizeMode)pbar->ellipsize != mode)
1248 pbar->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->ellipsize;
1274 #define __GTK_PROGRESS_BAR_C__
1275 #include "gtkaliasdef.c"