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"
38 #include "gtkprivate.h"
43 #define MIN_HORIZONTAL_BAR_WIDTH 150
44 #define MIN_HORIZONTAL_BAR_HEIGHT 20
45 #define MIN_VERTICAL_BAR_WIDTH 22
46 #define MIN_VERTICAL_BAR_HEIGHT 80
47 #define MAX_TEXT_LENGTH 80
48 #define TEXT_SPACING 2
68 static void gtk_progress_bar_set_property (GObject *object,
72 static void gtk_progress_bar_get_property (GObject *object,
76 static gboolean gtk_progress_bar_expose (GtkWidget *widget,
77 GdkEventExpose *event);
78 static void gtk_progress_bar_size_request (GtkWidget *widget,
79 GtkRequisition *requisition);
80 static void gtk_progress_bar_real_update (GtkProgress *progress);
81 static void gtk_progress_bar_paint (GtkProgress *progress);
82 static void gtk_progress_bar_act_mode_enter (GtkProgress *progress);
84 static void gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
85 GtkProgressBarStyle style);
86 static void gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
88 static void gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
90 static void gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
94 G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_PROGRESS)
97 gtk_progress_bar_class_init (GtkProgressBarClass *class)
99 GObjectClass *gobject_class;
100 GtkWidgetClass *widget_class;
101 GtkProgressClass *progress_class;
103 gobject_class = G_OBJECT_CLASS (class);
104 widget_class = (GtkWidgetClass *) class;
105 progress_class = (GtkProgressClass *) class;
107 gobject_class->set_property = gtk_progress_bar_set_property;
108 gobject_class->get_property = gtk_progress_bar_get_property;
110 widget_class->expose_event = gtk_progress_bar_expose;
111 widget_class->size_request = gtk_progress_bar_size_request;
113 progress_class->paint = gtk_progress_bar_paint;
114 progress_class->update = gtk_progress_bar_real_update;
115 progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
117 g_object_class_install_property (gobject_class,
119 g_param_spec_object ("adjustment",
121 P_("The GtkAdjustment connected to the progress bar (Deprecated)"),
123 GTK_PARAM_READWRITE));
125 g_object_class_install_property (gobject_class,
127 g_param_spec_enum ("orientation",
129 P_("Orientation and growth direction of the progress bar"),
130 GTK_TYPE_PROGRESS_BAR_ORIENTATION,
131 GTK_PROGRESS_LEFT_TO_RIGHT,
132 GTK_PARAM_READWRITE));
134 g_object_class_install_property (gobject_class,
136 g_param_spec_enum ("bar-style",
138 P_("Specifies the visual style of the bar in percentage mode (Deprecated)"),
139 GTK_TYPE_PROGRESS_BAR_STYLE,
140 GTK_PROGRESS_CONTINUOUS,
141 GTK_PARAM_READWRITE));
143 g_object_class_install_property (gobject_class,
145 g_param_spec_uint ("activity-step",
147 P_("The increment used for each iteration in activity mode (Deprecated)"),
151 GTK_PARAM_READWRITE));
153 g_object_class_install_property (gobject_class,
154 PROP_ACTIVITY_BLOCKS,
155 g_param_spec_uint ("activity-blocks",
156 P_("Activity Blocks"),
157 P_("The number of blocks which can fit in the progress bar area in activity mode (Deprecated)"),
161 GTK_PARAM_READWRITE));
163 g_object_class_install_property (gobject_class,
164 PROP_DISCRETE_BLOCKS,
165 g_param_spec_uint ("discrete-blocks",
166 P_("Discrete Blocks"),
167 P_("The number of discrete blocks in a progress bar (when shown in the discrete style)"),
171 GTK_PARAM_READWRITE));
173 g_object_class_install_property (gobject_class,
175 g_param_spec_double ("fraction",
177 P_("The fraction of total work that has been completed"),
181 GTK_PARAM_READWRITE));
183 g_object_class_install_property (gobject_class,
185 g_param_spec_double ("pulse-step",
187 P_("The fraction of total progress to move the bouncing block when pulsed"),
191 GTK_PARAM_READWRITE));
193 g_object_class_install_property (gobject_class,
195 g_param_spec_string ("text",
197 P_("Text to be displayed in the progress bar"),
199 GTK_PARAM_READWRITE));
202 * GtkProgressBar:ellipsize:
204 * The preferred place to ellipsize the string, if the progressbar does
205 * not have enough room to display the entire string, specified as a
206 * #PangoEllisizeMode.
208 * Note that setting this property to a value other than
209 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
210 * only enough space to display the ellipsis "...". Another means to set a
211 * progressbar's width is gtk_widget_set_size_request().
215 g_object_class_install_property (gobject_class,
217 g_param_spec_enum ("ellipsize",
219 P_("The preferred place to ellipsize the string, if the progressbar does not have enough room to display the entire string, if at all"),
220 PANGO_TYPE_ELLIPSIZE_MODE,
221 PANGO_ELLIPSIZE_NONE,
222 GTK_PARAM_READWRITE));
227 gtk_progress_bar_init (GtkProgressBar *pbar)
229 pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
232 pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
233 pbar->pulse_fraction = 0.1;
234 pbar->activity_pos = 0;
235 pbar->activity_dir = 1;
236 pbar->activity_step = 3;
237 pbar->activity_blocks = 5;
238 pbar->ellipsize = PANGO_ELLIPSIZE_NONE;
242 gtk_progress_bar_set_property (GObject *object,
247 GtkProgressBar *pbar;
249 pbar = GTK_PROGRESS_BAR (object);
253 case PROP_ADJUSTMENT:
254 gtk_progress_set_adjustment (GTK_PROGRESS (pbar),
255 GTK_ADJUSTMENT (g_value_get_object (value)));
257 case PROP_ORIENTATION:
258 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
261 gtk_progress_bar_set_bar_style_internal (pbar, g_value_get_enum (value));
263 case PROP_ACTIVITY_STEP:
264 gtk_progress_bar_set_activity_step_internal (pbar, g_value_get_uint (value));
266 case PROP_ACTIVITY_BLOCKS:
267 gtk_progress_bar_set_activity_blocks_internal (pbar, g_value_get_uint (value));
269 case PROP_DISCRETE_BLOCKS:
270 gtk_progress_bar_set_discrete_blocks_internal (pbar, g_value_get_uint (value));
273 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
275 case PROP_PULSE_STEP:
276 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
279 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
282 gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291 gtk_progress_bar_get_property (GObject *object,
296 GtkProgressBar *pbar;
298 pbar = GTK_PROGRESS_BAR (object);
302 case PROP_ADJUSTMENT:
303 g_value_set_object (value, GTK_PROGRESS (pbar)->adjustment);
305 case PROP_ORIENTATION:
306 g_value_set_enum (value, pbar->orientation);
309 g_value_set_enum (value, pbar->bar_style);
311 case PROP_ACTIVITY_STEP:
312 g_value_set_uint (value, pbar->activity_step);
314 case PROP_ACTIVITY_BLOCKS:
315 g_value_set_uint (value, pbar->activity_blocks);
317 case PROP_DISCRETE_BLOCKS:
318 g_value_set_uint (value, pbar->blocks);
321 g_value_set_double (value, gtk_progress_get_current_percentage (GTK_PROGRESS (pbar)));
323 case PROP_PULSE_STEP:
324 g_value_set_double (value, pbar->pulse_fraction);
327 g_value_set_string (value, gtk_progress_bar_get_text (pbar));
330 g_value_set_enum (value, pbar->ellipsize);
333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 gtk_progress_bar_new (void)
343 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL);
349 gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
353 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
355 pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR,
356 "adjustment", adjustment,
363 gtk_progress_bar_real_update (GtkProgress *progress)
365 GtkProgressBar *pbar;
368 g_return_if_fail (GTK_IS_PROGRESS (progress));
370 pbar = GTK_PROGRESS_BAR (progress);
371 widget = GTK_WIDGET (progress);
373 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
374 GTK_PROGRESS (pbar)->activity_mode)
376 if (GTK_PROGRESS (pbar)->activity_mode)
380 /* advance the block */
382 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
383 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
385 /* Update our activity step. */
387 pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
389 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
391 if (pbar->activity_dir == 0)
393 pbar->activity_pos += pbar->activity_step;
394 if (pbar->activity_pos + size >=
395 widget->allocation.width -
396 widget->style->xthickness)
398 pbar->activity_pos = widget->allocation.width -
399 widget->style->xthickness - size;
400 pbar->activity_dir = 1;
405 pbar->activity_pos -= pbar->activity_step;
406 if (pbar->activity_pos <= widget->style->xthickness)
408 pbar->activity_pos = widget->style->xthickness;
409 pbar->activity_dir = 0;
415 /* Update our activity step. */
417 pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
419 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
421 if (pbar->activity_dir == 0)
423 pbar->activity_pos += pbar->activity_step;
424 if (pbar->activity_pos + size >=
425 widget->allocation.height -
426 widget->style->ythickness)
428 pbar->activity_pos = widget->allocation.height -
429 widget->style->ythickness - size;
430 pbar->activity_dir = 1;
435 pbar->activity_pos -= pbar->activity_step;
436 if (pbar->activity_pos <= widget->style->ythickness)
438 pbar->activity_pos = widget->style->ythickness;
439 pbar->activity_dir = 0;
445 gtk_widget_queue_draw (GTK_WIDGET (progress));
451 in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
452 (gdouble)pbar->blocks);
454 if (pbar->in_block != in_block)
456 pbar->in_block = in_block;
458 gtk_widget_queue_draw (GTK_WIDGET (progress));
464 gtk_progress_bar_expose (GtkWidget *widget,
465 GdkEventExpose *event)
467 GtkProgressBar *pbar;
469 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
471 pbar = GTK_PROGRESS_BAR (widget);
473 if (GTK_WIDGET_DRAWABLE (widget) && pbar->dirty)
474 gtk_progress_bar_paint (GTK_PROGRESS (pbar));
476 return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
480 gtk_progress_bar_size_request (GtkWidget *widget,
481 GtkRequisition *requisition)
483 GtkProgress *progress;
484 GtkProgressBar *pbar;
486 PangoRectangle logical_rect;
490 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
491 g_return_if_fail (requisition != NULL);
493 progress = GTK_PROGRESS (widget);
494 pbar = GTK_PROGRESS_BAR (widget);
496 width = 2 * widget->style->xthickness + 3 + 2 * TEXT_SPACING;
497 height = 2 * widget->style->ythickness + 3 + 2 * TEXT_SPACING;
499 if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
501 if (!progress->adjustment)
502 gtk_progress_set_adjustment (progress, NULL);
504 buf = gtk_progress_get_text_from_value (progress, progress->adjustment->upper);
506 layout = gtk_widget_create_pango_layout (widget, buf);
508 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
512 PangoContext *context;
513 PangoFontMetrics *metrics;
516 /* The minimum size for ellipsized text is ~ 3 chars */
517 context = pango_layout_get_context (layout);
518 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
520 char_width = pango_font_metrics_get_approximate_char_width (metrics);
521 pango_font_metrics_unref (metrics);
523 width += PANGO_PIXELS (char_width) * 3;
526 width += logical_rect.width;
528 height += logical_rect.height;
530 g_object_unref (layout);
534 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
535 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
537 requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH, width);
538 requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT, height);
542 requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH, width);
543 requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT, height);
548 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
550 GtkProgressBar *pbar;
552 GtkProgressBarOrientation orientation;
554 pbar = GTK_PROGRESS_BAR (progress);
555 widget = GTK_WIDGET (progress);
557 orientation = pbar->orientation;
558 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
560 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
561 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
562 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
563 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
566 /* calculate start pos */
568 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
569 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
571 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
573 pbar->activity_pos = widget->style->xthickness;
574 pbar->activity_dir = 0;
578 pbar->activity_pos = widget->allocation.width -
579 widget->style->xthickness - (widget->allocation.height -
580 widget->style->ythickness * 2);
581 pbar->activity_dir = 1;
586 if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
588 pbar->activity_pos = widget->style->ythickness;
589 pbar->activity_dir = 0;
593 pbar->activity_pos = widget->allocation.height -
594 widget->style->ythickness - (widget->allocation.width -
595 widget->style->xthickness * 2);
596 pbar->activity_dir = 1;
602 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
603 GtkProgressBarOrientation orientation)
605 GtkWidget *widget = GTK_WIDGET (pbar);
606 GtkProgress *progress = GTK_PROGRESS (pbar);
611 case GTK_PROGRESS_LEFT_TO_RIGHT:
612 case GTK_PROGRESS_RIGHT_TO_LEFT:
613 area.x = pbar->activity_pos;
614 area.y = widget->style->ythickness;
615 area.width = MAX (2, widget->allocation.width / pbar->activity_blocks);
616 area.height = widget->allocation.height - 2 * widget->style->ythickness;
619 case GTK_PROGRESS_TOP_TO_BOTTOM:
620 case GTK_PROGRESS_BOTTOM_TO_TOP:
621 area.x = widget->style->xthickness;
622 area.y = pbar->activity_pos;
623 area.width = widget->allocation.width - 2 * widget->style->xthickness;
624 area.height = MAX (2, widget->allocation.height / pbar->activity_blocks);
632 gtk_paint_box (widget->style,
633 progress->offscreen_pixmap,
634 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
635 &area, widget, "bar",
636 area.x, area.y, area.width, area.height);
640 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
642 GtkProgressBarOrientation orientation)
645 GtkWidget *widget = GTK_WIDGET (pbar);
652 case GTK_PROGRESS_LEFT_TO_RIGHT:
653 case GTK_PROGRESS_RIGHT_TO_LEFT:
655 area.height = widget->allocation.height - widget->style->ythickness * 2;
656 area.y = widget->style->ythickness;
658 area.x = widget->style->xthickness;
659 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
660 area.x = widget->allocation.width - amount - area.x;
663 case GTK_PROGRESS_TOP_TO_BOTTOM:
664 case GTK_PROGRESS_BOTTOM_TO_TOP:
665 area.width = widget->allocation.width - widget->style->xthickness * 2;
666 area.height = amount;
667 area.x = widget->style->xthickness;
669 area.y = widget->style->ythickness;
670 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
671 area.y = widget->allocation.height - amount - area.y;
679 gtk_paint_box (widget->style,
680 GTK_PROGRESS (pbar)->offscreen_pixmap,
681 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
682 &area, widget, "bar",
683 area.x, area.y, area.width, area.height);
687 gtk_progress_bar_paint_discrete (GtkProgressBar *pbar,
688 GtkProgressBarOrientation orientation)
690 GtkWidget *widget = GTK_WIDGET (pbar);
693 for (i = 0; i <= pbar->in_block; i++)
700 case GTK_PROGRESS_LEFT_TO_RIGHT:
701 case GTK_PROGRESS_RIGHT_TO_LEFT:
702 space = widget->allocation.width - 2 * widget->style->xthickness;
704 area.x = widget->style->xthickness + (i * space) / pbar->blocks;
705 area.y = widget->style->ythickness;
706 area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
707 area.height = widget->allocation.height - 2 * widget->style->ythickness;
709 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
710 area.x = widget->allocation.width - area.width - area.x;
713 case GTK_PROGRESS_TOP_TO_BOTTOM:
714 case GTK_PROGRESS_BOTTOM_TO_TOP:
715 space = widget->allocation.height - 2 * widget->style->ythickness;
717 area.x = widget->style->xthickness;
718 area.y = widget->style->ythickness + (i * space) / pbar->blocks;
719 area.width = widget->allocation.width - 2 * widget->style->xthickness;
720 area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
722 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
723 area.y = widget->allocation.height - area.height - area.y;
731 gtk_paint_box (widget->style,
732 GTK_PROGRESS (pbar)->offscreen_pixmap,
733 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
734 &area, widget, "bar",
735 area.x, area.y, area.width, area.height);
740 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
742 GtkProgressBarOrientation orientation)
744 GtkProgress *progress = GTK_PROGRESS (pbar);
745 GtkWidget *widget = GTK_WIDGET (pbar);
752 PangoRectangle logical_rect;
753 GdkRectangle prelight_clip, normal_clip;
755 buf = gtk_progress_get_current_text (progress);
757 layout = gtk_widget_create_pango_layout (widget, buf);
758 pango_layout_set_ellipsize (layout, pbar->ellipsize);
760 pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
762 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
764 x = widget->style->xthickness + 1 +
765 (widget->allocation.width - 2 * widget->style->xthickness -
766 2 - logical_rect.width)
769 y = widget->style->ythickness + 1 +
770 (widget->allocation.height - 2 * widget->style->ythickness -
771 2 - logical_rect.height)
774 rect.x = widget->style->xthickness;
775 rect.y = widget->style->ythickness;
776 rect.width = widget->allocation.width - 2 * widget->style->xthickness;
777 rect.height = widget->allocation.height - 2 * widget->style->ythickness;
779 prelight_clip = normal_clip = rect;
783 case GTK_PROGRESS_LEFT_TO_RIGHT:
784 prelight_clip.width = amount;
785 normal_clip.x += amount;
786 normal_clip.width -= amount;
789 case GTK_PROGRESS_RIGHT_TO_LEFT:
790 normal_clip.width -= amount;
791 prelight_clip.x += normal_clip.width;
792 prelight_clip.width -= normal_clip.width;
795 case GTK_PROGRESS_TOP_TO_BOTTOM:
796 prelight_clip.height = amount;
797 normal_clip.y += amount;
798 normal_clip.height -= amount;
801 case GTK_PROGRESS_BOTTOM_TO_TOP:
802 normal_clip.height -= amount;
803 prelight_clip.y += normal_clip.height;
804 prelight_clip.height -= normal_clip.height;
808 gtk_paint_layout (widget->style,
809 progress->offscreen_pixmap,
818 gtk_paint_layout (widget->style,
819 progress->offscreen_pixmap,
828 g_object_unref (layout);
833 gtk_progress_bar_paint (GtkProgress *progress)
835 GtkProgressBar *pbar;
838 GtkProgressBarOrientation orientation;
840 g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
842 pbar = GTK_PROGRESS_BAR (progress);
843 widget = GTK_WIDGET (progress);
845 orientation = pbar->orientation;
846 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
848 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
849 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
850 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
851 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
854 if (progress->offscreen_pixmap)
856 gtk_paint_box (widget->style,
857 progress->offscreen_pixmap,
858 GTK_STATE_NORMAL, GTK_SHADOW_IN,
859 NULL, widget, "trough",
861 widget->allocation.width,
862 widget->allocation.height);
864 if (progress->activity_mode)
866 gtk_progress_bar_paint_activity (pbar, orientation);
873 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
874 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
875 space = widget->allocation.width - 2 * widget->style->xthickness;
877 space = widget->allocation.height - 2 * widget->style->ythickness;
880 gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
882 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
884 gtk_progress_bar_paint_continuous (pbar, amount, orientation);
886 if (GTK_PROGRESS (pbar)->show_text)
887 gtk_progress_bar_paint_text (pbar, amount, orientation);
890 gtk_progress_bar_paint_discrete (pbar, orientation);
898 gtk_progress_bar_set_bar_style_internal (GtkProgressBar *pbar,
899 GtkProgressBarStyle bar_style)
901 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
903 if (pbar->bar_style != bar_style)
905 pbar->bar_style = bar_style;
907 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
908 gtk_widget_queue_resize (GTK_WIDGET (pbar));
910 g_object_notify (G_OBJECT (pbar), "bar-style");
915 gtk_progress_bar_set_discrete_blocks_internal (GtkProgressBar *pbar,
918 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
919 g_return_if_fail (blocks > 1);
921 if (pbar->blocks != blocks)
923 pbar->blocks = blocks;
925 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
926 gtk_widget_queue_resize (GTK_WIDGET (pbar));
928 g_object_notify (G_OBJECT (pbar), "discrete-blocks");
933 gtk_progress_bar_set_activity_step_internal (GtkProgressBar *pbar,
936 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
938 if (pbar->activity_step != step)
940 pbar->activity_step = step;
941 g_object_notify (G_OBJECT (pbar), "activity-step");
946 gtk_progress_bar_set_activity_blocks_internal (GtkProgressBar *pbar,
949 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
950 g_return_if_fail (blocks > 1);
952 if (pbar->activity_blocks != blocks)
954 pbar->activity_blocks = blocks;
955 g_object_notify (G_OBJECT (pbar), "activity-blocks");
959 /*******************************************************************/
962 * gtk_progress_bar_set_fraction:
963 * @pbar: a #GtkProgressBar
964 * @fraction: fraction of the task that's been completed
966 * Causes the progress bar to "fill in" the given fraction
967 * of the bar. The fraction should be between 0.0 and 1.0,
972 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
975 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
977 /* If we know the percentage, we don't want activity mode. */
978 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
980 /* We use the deprecated GtkProgress interface internally.
981 * Once everything's been deprecated for a good long time,
982 * we can clean up all this code.
984 gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
986 g_object_notify (G_OBJECT (pbar), "fraction");
990 * gtk_progress_bar_pulse:
991 * @pbar: a #GtkProgressBar
993 * Indicates that some progress is made, but you don't know how much.
994 * Causes the progress bar to enter "activity mode," where a block
995 * bounces back and forth. Each call to gtk_progress_bar_pulse()
996 * causes the block to move by a little bit (the amount of movement
997 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
1000 gtk_progress_bar_pulse (GtkProgressBar *pbar)
1002 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1004 /* If we don't know the percentage, we must want activity mode. */
1005 gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
1008 gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
1012 * gtk_progress_bar_set_text:
1013 * @pbar: a #GtkProgressBar
1014 * @text: a UTF-8 string, or %NULL
1016 * Causes the given @text to appear superimposed on the progress bar.
1019 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1022 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1024 gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
1025 gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
1027 /* We don't support formats in this interface, but turn
1028 * them back on for NULL, which should put us back to
1029 * the initial state.
1031 GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
1033 g_object_notify (G_OBJECT (pbar), "text");
1037 * gtk_progress_bar_set_pulse_step:
1038 * @pbar: a #GtkProgressBar
1039 * @fraction: fraction between 0.0 and 1.0
1041 * Sets the fraction of total progress bar length to move the
1042 * bouncing block for each call to gtk_progress_bar_pulse().
1045 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1048 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1050 pbar->pulse_fraction = fraction;
1052 g_object_notify (G_OBJECT (pbar), "pulse-step");
1056 gtk_progress_bar_update (GtkProgressBar *pbar,
1059 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1061 /* Use of gtk_progress_bar_update() is deprecated !
1062 * Use gtk_progress_bar_set_percentage ()
1065 gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
1069 * gtk_progress_bar_set_orientation:
1070 * @pbar: a #GtkProgressBar
1071 * @orientation: orientation of the progress bar
1073 * Causes the progress bar to switch to a different orientation
1074 * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
1077 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1078 GtkProgressBarOrientation orientation)
1080 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1082 if (pbar->orientation != orientation)
1084 pbar->orientation = orientation;
1086 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
1087 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1089 g_object_notify (G_OBJECT (pbar), "orientation");
1094 * gtk_progress_bar_get_text:
1095 * @pbar: a #GtkProgressBar
1097 * Retrieves the text displayed superimposed on the progress bar,
1098 * if any, otherwise %NULL. The return value is a reference
1099 * to the text, not a copy of it, so will become invalid
1100 * if you change the text in the progress bar.
1102 * Return value: text, or %NULL; this string is owned by the widget
1103 * and should not be modified or freed.
1105 G_CONST_RETURN gchar*
1106 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1108 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1110 if (GTK_PROGRESS (pbar)->use_text_format)
1113 return GTK_PROGRESS (pbar)->format;
1117 * gtk_progress_bar_get_fraction:
1118 * @pbar: a #GtkProgressBar
1120 * Returns the current fraction of the task that's been completed.
1122 * Return value: a fraction from 0.0 to 1.0
1125 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1127 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1129 return gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
1133 * gtk_progress_bar_get_pulse_step:
1134 * @pbar: a #GtkProgressBar
1136 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1138 * Return value: a fraction from 0.0 to 1.0
1141 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1143 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1145 return pbar->pulse_fraction;
1149 * gtk_progress_bar_get_orientation:
1150 * @pbar: a #GtkProgressBar
1152 * Retrieves the current progress bar orientation.
1154 * Return value: orientation of the progress bar
1156 GtkProgressBarOrientation
1157 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1159 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1161 return pbar->orientation;
1165 gtk_progress_bar_set_bar_style (GtkProgressBar *pbar,
1166 GtkProgressBarStyle bar_style)
1168 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1170 gtk_progress_bar_set_bar_style_internal (pbar, bar_style);
1174 gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
1177 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1178 g_return_if_fail (blocks > 1);
1180 gtk_progress_bar_set_discrete_blocks_internal (pbar, blocks);
1184 gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
1187 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1189 gtk_progress_bar_set_activity_step_internal (pbar, step);
1193 gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
1196 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1197 g_return_if_fail (blocks > 1);
1199 gtk_progress_bar_set_activity_blocks_internal (pbar, blocks);
1203 * gtk_progress_bar_set_ellipsize:
1204 * @pbar: a #GtkProgressBar
1205 * @mode: a #PangoEllipsizeMode
1207 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1208 * if there is not enough space to render the entire string.
1213 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1214 PangoEllipsizeMode mode)
1216 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1217 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1218 mode <= PANGO_ELLIPSIZE_END);
1220 if ((PangoEllipsizeMode)pbar->ellipsize != mode)
1222 pbar->ellipsize = mode;
1224 g_object_notify (G_OBJECT (pbar), "ellipsize");
1225 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1230 * gtk_progress_bar_get_ellipsize:
1231 * @pbar: a #GtkProgressBar
1233 * Returns the ellipsizing position of the progressbar.
1234 * See gtk_progress_bar_set_ellipsize().
1236 * Return value: #PangoEllipsizeMode
1241 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1243 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1245 return pbar->ellipsize;
1248 #define __GTK_PROGRESS_BAR_C__
1249 #include "gtkaliasdef.c"