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 #undef GTK_DISABLE_DEPRECATED
32 #define __GTK_PROGRESS_BAR_C__
34 #include "gtkprogressbar.h"
35 #include "gtkprivate.h"
40 #define MIN_HORIZONTAL_BAR_WIDTH 150
41 #define MIN_HORIZONTAL_BAR_HEIGHT 20
42 #define MIN_VERTICAL_BAR_WIDTH 22
43 #define MIN_VERTICAL_BAR_HEIGHT 80
57 static void gtk_progress_bar_set_property (GObject *object,
61 static void gtk_progress_bar_get_property (GObject *object,
65 static gboolean gtk_progress_bar_expose (GtkWidget *widget,
66 GdkEventExpose *event);
67 static void gtk_progress_bar_size_request (GtkWidget *widget,
68 GtkRequisition *requisition);
69 static void gtk_progress_bar_style_set (GtkWidget *widget,
71 static void gtk_progress_bar_real_update (GtkProgress *progress);
72 static void gtk_progress_bar_paint (GtkProgress *progress);
73 static void gtk_progress_bar_act_mode_enter (GtkProgress *progress);
80 } GtkProgressBarPrivate;
82 #define GTK_PROGRESS_BAR_GET_PRIVATE(o) \
83 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PROGRESS_BAR, GtkProgressBarPrivate))
85 G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_PROGRESS)
88 gtk_progress_bar_class_init (GtkProgressBarClass *class)
90 GObjectClass *gobject_class;
91 GtkWidgetClass *widget_class;
92 GtkProgressClass *progress_class;
94 gobject_class = G_OBJECT_CLASS (class);
95 widget_class = (GtkWidgetClass *) class;
96 progress_class = (GtkProgressClass *) class;
98 gobject_class->set_property = gtk_progress_bar_set_property;
99 gobject_class->get_property = gtk_progress_bar_get_property;
101 widget_class->expose_event = gtk_progress_bar_expose;
102 widget_class->size_request = gtk_progress_bar_size_request;
103 widget_class->style_set = gtk_progress_bar_style_set;
105 progress_class->paint = gtk_progress_bar_paint;
106 progress_class->update = gtk_progress_bar_real_update;
107 progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
109 g_object_class_install_property (gobject_class,
111 g_param_spec_enum ("orientation",
113 P_("Orientation and growth direction of the progress bar"),
114 GTK_TYPE_PROGRESS_BAR_ORIENTATION,
115 GTK_PROGRESS_LEFT_TO_RIGHT,
116 GTK_PARAM_READWRITE));
118 g_object_class_install_property (gobject_class,
120 g_param_spec_double ("fraction",
122 P_("The fraction of total work that has been completed"),
124 GTK_PARAM_READWRITE));
126 g_object_class_install_property (gobject_class,
128 g_param_spec_double ("pulse-step",
130 P_("The fraction of total progress to move the bouncing block when pulsed"),
132 GTK_PARAM_READWRITE));
134 g_object_class_install_property (gobject_class,
136 g_param_spec_string ("text",
138 P_("Text to be displayed in the progress bar"),
140 GTK_PARAM_READWRITE));
143 * GtkProgressBar:ellipsize:
145 * The preferred place to ellipsize the string, if the progressbar does
146 * not have enough room to display the entire string, specified as a
147 * #PangoEllisizeMode.
149 * Note that setting this property to a value other than
150 * %PANGO_ELLIPSIZE_NONE has the side-effect that the progressbar requests
151 * only enough space to display the ellipsis "...". Another means to set a
152 * progressbar's width is gtk_widget_set_size_request().
156 g_object_class_install_property (gobject_class,
158 g_param_spec_enum ("ellipsize",
160 P_("The preferred place to ellipsize the string, if the progress bar "
161 "does not have enough room to display the entire string, if at all."),
162 PANGO_TYPE_ELLIPSIZE_MODE,
163 PANGO_ELLIPSIZE_NONE,
164 GTK_PARAM_READWRITE));
165 gtk_widget_class_install_style_property (widget_class,
166 g_param_spec_int ("xspacing",
168 P_("Extra spacing applied to the width of a progress bar."),
171 gtk_widget_class_install_style_property (widget_class,
172 g_param_spec_int ("yspacing",
174 P_("Extra spacing applied to the height of a progress bar."),
179 * GtkProgressBar:min-horizontal-bar-width:
181 * The minimum horizontal width of the progress bar.
185 gtk_widget_class_install_style_property (widget_class,
186 g_param_spec_int ("min-horizontal-bar-width",
187 P_("Min horizontal bar width"),
188 P_("The minimum horizontal width of the progress bar"),
189 1, G_MAXINT, MIN_HORIZONTAL_BAR_WIDTH,
192 * GtkProgressBar:min-horizontal-bar-height:
194 * Minimum horizontal height of the progress bar.
198 gtk_widget_class_install_style_property (widget_class,
199 g_param_spec_int ("min-horizontal-bar-height",
200 P_("Min horizontal bar height"),
201 P_("Minimum horizontal height of the progress bar"),
202 1, G_MAXINT, MIN_HORIZONTAL_BAR_HEIGHT,
205 * GtkProgressBar:min-vertical-bar-width:
207 * The minimum vertical width of the progress bar.
211 gtk_widget_class_install_style_property (widget_class,
212 g_param_spec_int ("min-vertical-bar-width",
213 P_("Min vertical bar width"),
214 P_("The minimum vertical width of the progress bar"),
215 1, G_MAXINT, MIN_VERTICAL_BAR_WIDTH,
218 * GtkProgressBar:min-vertical-bar-height:
220 * The minimum vertical height of the progress bar.
224 gtk_widget_class_install_style_property (widget_class,
225 g_param_spec_int ("min-vertical-bar-height",
226 P_("Min vertical bar height"),
227 P_("The minimum vertical height of the progress bar"),
228 1, G_MAXINT, MIN_VERTICAL_BAR_HEIGHT,
231 g_type_class_add_private (class, sizeof (GtkProgressBarPrivate));
235 gtk_progress_bar_init (GtkProgressBar *pbar)
237 GtkProgressBarPrivate* priv;
239 pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
242 pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
243 pbar->pulse_fraction = 0.1;
244 pbar->activity_pos = 0;
245 pbar->activity_dir = 1;
246 pbar->activity_step = 3;
247 pbar->activity_blocks = 5;
248 pbar->ellipsize = PANGO_ELLIPSIZE_NONE;
250 /* FIXME: Put priv in the structure once we break ABI */
251 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
253 priv->fraction = 0.0;
257 gtk_progress_bar_set_property (GObject *object,
262 GtkProgressBar *pbar;
264 pbar = GTK_PROGRESS_BAR (object);
268 case PROP_ORIENTATION:
269 gtk_progress_bar_set_orientation (pbar, g_value_get_enum (value));
272 gtk_progress_bar_set_fraction (pbar, g_value_get_double (value));
274 case PROP_PULSE_STEP:
275 gtk_progress_bar_set_pulse_step (pbar, g_value_get_double (value));
278 gtk_progress_bar_set_text (pbar, g_value_get_string (value));
281 gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 gtk_progress_bar_get_property (GObject *object,
295 GtkProgressBar *pbar;
296 GtkProgressBarPrivate* priv;
298 pbar = GTK_PROGRESS_BAR (object);
299 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
303 case PROP_ORIENTATION:
304 g_value_set_enum (value, pbar->orientation);
307 g_value_set_double (value, priv->fraction);
309 case PROP_PULSE_STEP:
310 g_value_set_double (value, pbar->pulse_fraction);
313 g_value_set_string (value, priv->text);
316 g_value_set_enum (value, pbar->ellipsize);
319 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
325 gtk_progress_bar_new (void)
329 pbar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL);
335 gtk_progress_bar_real_update (GtkProgress *progress)
337 GtkProgressBar *pbar;
340 g_return_if_fail (GTK_IS_PROGRESS (progress));
342 pbar = GTK_PROGRESS_BAR (progress);
343 widget = GTK_WIDGET (progress);
345 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
346 GTK_PROGRESS (pbar)->activity_mode)
348 if (GTK_PROGRESS (pbar)->activity_mode)
352 /* advance the block */
354 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
355 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
357 /* Update our activity step. */
359 pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
361 size = MAX (2, widget->allocation.width / pbar->activity_blocks);
363 if (pbar->activity_dir == 0)
365 pbar->activity_pos += pbar->activity_step;
366 if (pbar->activity_pos + size >=
367 widget->allocation.width -
368 widget->style->xthickness)
370 pbar->activity_pos = widget->allocation.width -
371 widget->style->xthickness - size;
372 pbar->activity_dir = 1;
377 pbar->activity_pos -= pbar->activity_step;
378 if (pbar->activity_pos <= widget->style->xthickness)
380 pbar->activity_pos = widget->style->xthickness;
381 pbar->activity_dir = 0;
387 /* Update our activity step. */
389 pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
391 size = MAX (2, widget->allocation.height / pbar->activity_blocks);
393 if (pbar->activity_dir == 0)
395 pbar->activity_pos += pbar->activity_step;
396 if (pbar->activity_pos + size >=
397 widget->allocation.height -
398 widget->style->ythickness)
400 pbar->activity_pos = widget->allocation.height -
401 widget->style->ythickness - size;
402 pbar->activity_dir = 1;
407 pbar->activity_pos -= pbar->activity_step;
408 if (pbar->activity_pos <= widget->style->ythickness)
410 pbar->activity_pos = widget->style->ythickness;
411 pbar->activity_dir = 0;
417 gtk_widget_queue_draw (GTK_WIDGET (progress));
423 in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
424 (gdouble)pbar->blocks);
426 if (pbar->in_block != in_block)
428 pbar->in_block = in_block;
430 gtk_widget_queue_draw (GTK_WIDGET (progress));
436 gtk_progress_bar_expose (GtkWidget *widget,
437 GdkEventExpose *event)
439 GtkProgressBar *pbar;
441 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
443 pbar = GTK_PROGRESS_BAR (widget);
445 if (pbar->dirty && gtk_widget_is_drawable (widget))
446 gtk_progress_bar_paint (GTK_PROGRESS (pbar));
448 return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
452 gtk_progress_bar_size_request (GtkWidget *widget,
453 GtkRequisition *requisition)
455 GtkProgressBar *pbar;
456 GtkProgressBarPrivate *priv;
458 PangoRectangle logical_rect;
461 gint xspacing, yspacing;
462 gint min_width, min_height;
464 g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
465 g_return_if_fail (requisition != NULL);
467 gtk_widget_style_get (widget,
468 "xspacing", &xspacing,
469 "yspacing", &yspacing,
472 pbar = GTK_PROGRESS_BAR (widget);
473 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
475 width = 2 * widget->style->xthickness + xspacing;
476 height = 2 * widget->style->ythickness + yspacing;
478 if ((buf = priv->text))
480 layout = gtk_widget_create_pango_layout (widget, buf);
482 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
486 PangoContext *context;
487 PangoFontMetrics *metrics;
490 /* The minimum size for ellipsized text is ~ 3 chars */
491 context = pango_layout_get_context (layout);
492 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
494 char_width = pango_font_metrics_get_approximate_char_width (metrics);
495 pango_font_metrics_unref (metrics);
497 width += PANGO_PIXELS (char_width) * 3;
500 width += logical_rect.width;
502 height += logical_rect.height;
504 g_object_unref (layout);
507 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
508 pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
509 gtk_widget_style_get (widget,
510 "min-horizontal-bar-width", &min_width,
511 "min-horizontal-bar-height", &min_height,
514 gtk_widget_style_get (widget,
515 "min-vertical-bar-width", &min_width,
516 "min-vertical-bar-height", &min_height,
519 requisition->width = MAX (min_width, width);
520 requisition->height = MAX (min_height, height);
524 gtk_progress_bar_style_set (GtkWidget *widget,
527 GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
531 GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->style_set (widget, previous);
535 gtk_progress_bar_act_mode_enter (GtkProgress *progress)
537 GtkProgressBar *pbar;
539 GtkProgressBarOrientation orientation;
541 pbar = GTK_PROGRESS_BAR (progress);
542 widget = GTK_WIDGET (progress);
544 orientation = pbar->orientation;
545 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
547 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
548 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
549 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
550 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
553 /* calculate start pos */
555 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
556 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
558 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
560 pbar->activity_pos = widget->style->xthickness;
561 pbar->activity_dir = 0;
565 pbar->activity_pos = widget->allocation.width -
566 widget->style->xthickness - (widget->allocation.height -
567 widget->style->ythickness * 2);
568 pbar->activity_dir = 1;
573 if (orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
575 pbar->activity_pos = widget->style->ythickness;
576 pbar->activity_dir = 0;
580 pbar->activity_pos = widget->allocation.height -
581 widget->style->ythickness - (widget->allocation.width -
582 widget->style->xthickness * 2);
583 pbar->activity_dir = 1;
589 gtk_progress_bar_get_activity (GtkProgressBar *pbar,
590 GtkProgressBarOrientation orientation,
594 GtkWidget *widget = GTK_WIDGET (pbar);
596 *offset = pbar->activity_pos;
600 case GTK_PROGRESS_LEFT_TO_RIGHT:
601 case GTK_PROGRESS_RIGHT_TO_LEFT:
602 *amount = MAX (2, widget->allocation.width / pbar->activity_blocks);
605 case GTK_PROGRESS_TOP_TO_BOTTOM:
606 case GTK_PROGRESS_BOTTOM_TO_TOP:
607 *amount = MAX (2, widget->allocation.height / pbar->activity_blocks);
613 gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
614 GtkProgressBarOrientation orientation)
616 GtkWidget *widget = GTK_WIDGET (pbar);
617 GtkProgress *progress = GTK_PROGRESS (pbar);
622 case GTK_PROGRESS_LEFT_TO_RIGHT:
623 case GTK_PROGRESS_RIGHT_TO_LEFT:
624 gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
625 area.y = widget->style->ythickness;
626 area.height = widget->allocation.height - 2 * widget->style->ythickness;
629 case GTK_PROGRESS_TOP_TO_BOTTOM:
630 case GTK_PROGRESS_BOTTOM_TO_TOP:
631 gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
632 area.x = widget->style->xthickness;
633 area.width = widget->allocation.width - 2 * widget->style->xthickness;
641 gtk_paint_box (widget->style,
642 progress->offscreen_pixmap,
643 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
644 &area, widget, "bar",
645 area.x, area.y, area.width, area.height);
649 gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
651 GtkProgressBarOrientation orientation)
654 GtkWidget *widget = GTK_WIDGET (pbar);
661 case GTK_PROGRESS_LEFT_TO_RIGHT:
662 case GTK_PROGRESS_RIGHT_TO_LEFT:
664 area.height = widget->allocation.height - widget->style->ythickness * 2;
665 area.y = widget->style->ythickness;
667 area.x = widget->style->xthickness;
668 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
669 area.x = widget->allocation.width - amount - area.x;
672 case GTK_PROGRESS_TOP_TO_BOTTOM:
673 case GTK_PROGRESS_BOTTOM_TO_TOP:
674 area.width = widget->allocation.width - widget->style->xthickness * 2;
675 area.height = amount;
676 area.x = widget->style->xthickness;
678 area.y = widget->style->ythickness;
679 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
680 area.y = widget->allocation.height - amount - area.y;
688 gtk_paint_box (widget->style,
689 GTK_PROGRESS (pbar)->offscreen_pixmap,
690 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
691 &area, widget, "bar",
692 area.x, area.y, area.width, area.height);
696 gtk_progress_bar_paint_discrete (GtkProgressBar *pbar,
697 GtkProgressBarOrientation orientation)
699 GtkWidget *widget = GTK_WIDGET (pbar);
702 for (i = 0; i <= pbar->in_block; i++)
709 case GTK_PROGRESS_LEFT_TO_RIGHT:
710 case GTK_PROGRESS_RIGHT_TO_LEFT:
711 space = widget->allocation.width - 2 * widget->style->xthickness;
713 area.x = widget->style->xthickness + (i * space) / pbar->blocks;
714 area.y = widget->style->ythickness;
715 area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
716 area.height = widget->allocation.height - 2 * widget->style->ythickness;
718 if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
719 area.x = widget->allocation.width - area.width - area.x;
722 case GTK_PROGRESS_TOP_TO_BOTTOM:
723 case GTK_PROGRESS_BOTTOM_TO_TOP:
724 space = widget->allocation.height - 2 * widget->style->ythickness;
726 area.x = widget->style->xthickness;
727 area.y = widget->style->ythickness + (i * space) / pbar->blocks;
728 area.width = widget->allocation.width - 2 * widget->style->xthickness;
729 area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
731 if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
732 area.y = widget->allocation.height - area.height - area.y;
740 gtk_paint_box (widget->style,
741 GTK_PROGRESS (pbar)->offscreen_pixmap,
742 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
743 &area, widget, "bar",
744 area.x, area.y, area.width, area.height);
749 gtk_progress_bar_paint_text (GtkProgressBar *pbar,
752 GtkProgressBarOrientation orientation)
754 GtkProgress *progress = GTK_PROGRESS (pbar);
755 GtkWidget *widget = GTK_WIDGET (pbar);
761 PangoRectangle logical_rect;
762 GdkRectangle prelight_clip, start_clip, end_clip;
763 gfloat text_xalign = progress->x_align;
764 gfloat text_yalign = progress->y_align;
766 if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
767 text_xalign = 1.0 - text_xalign;
769 buf = gtk_progress_get_current_text (progress);
771 layout = gtk_widget_create_pango_layout (widget, buf);
772 pango_layout_set_ellipsize (layout, pbar->ellipsize);
774 pango_layout_set_width (layout, widget->allocation.width * PANGO_SCALE);
776 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
778 x = widget->style->xthickness + 1 + text_xalign *
779 (widget->allocation.width - 2 * widget->style->xthickness -
780 2 - logical_rect.width);
782 y = widget->style->ythickness + 1 + text_yalign *
783 (widget->allocation.height - 2 * widget->style->ythickness -
784 2 - logical_rect.height);
786 rect.x = widget->style->xthickness;
787 rect.y = widget->style->ythickness;
788 rect.width = widget->allocation.width - 2 * widget->style->xthickness;
789 rect.height = widget->allocation.height - 2 * widget->style->ythickness;
791 prelight_clip = start_clip = end_clip = rect;
795 case GTK_PROGRESS_LEFT_TO_RIGHT:
797 prelight_clip.x = offset;
798 prelight_clip.width = amount;
799 start_clip.width = prelight_clip.x - start_clip.x;
800 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
801 end_clip.width -= prelight_clip.width + start_clip.width;
804 case GTK_PROGRESS_RIGHT_TO_LEFT:
806 prelight_clip.x = offset;
808 prelight_clip.x = rect.x + rect.width - amount;
809 prelight_clip.width = amount;
810 start_clip.width = prelight_clip.x - start_clip.x;
811 end_clip.x = start_clip.x + start_clip.width + prelight_clip.width;
812 end_clip.width -= prelight_clip.width + start_clip.width;
815 case GTK_PROGRESS_TOP_TO_BOTTOM:
817 prelight_clip.y = offset;
818 prelight_clip.height = amount;
819 start_clip.height = prelight_clip.y - start_clip.y;
820 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
821 end_clip.height -= prelight_clip.height + start_clip.height;
824 case GTK_PROGRESS_BOTTOM_TO_TOP:
826 prelight_clip.y = offset;
828 prelight_clip.y = rect.y + rect.height - amount;
829 prelight_clip.height = amount;
830 start_clip.height = prelight_clip.y - start_clip.y;
831 end_clip.y = start_clip.y + start_clip.height + prelight_clip.height;
832 end_clip.height -= prelight_clip.height + start_clip.height;
836 if (start_clip.width > 0 && start_clip.height > 0)
837 gtk_paint_layout (widget->style,
838 progress->offscreen_pixmap,
847 if (end_clip.width > 0 && end_clip.height > 0)
848 gtk_paint_layout (widget->style,
849 progress->offscreen_pixmap,
858 gtk_paint_layout (widget->style,
859 progress->offscreen_pixmap,
868 g_object_unref (layout);
873 gtk_progress_bar_paint (GtkProgress *progress)
875 GtkProgressBar *pbar;
876 GtkProgressBarPrivate *priv;
879 GtkProgressBarOrientation orientation;
881 g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
883 pbar = GTK_PROGRESS_BAR (progress);
884 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
885 widget = GTK_WIDGET (progress);
887 orientation = pbar->orientation;
888 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
890 if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
891 orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
892 else if (pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
893 orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
896 if (progress->offscreen_pixmap)
898 gtk_paint_box (widget->style,
899 progress->offscreen_pixmap,
900 GTK_STATE_NORMAL, GTK_SHADOW_IN,
901 NULL, widget, "trough",
903 widget->allocation.width,
904 widget->allocation.height);
906 if (progress->activity_mode)
908 gtk_progress_bar_paint_activity (pbar, orientation);
915 gtk_progress_bar_get_activity (pbar, orientation, &offset, &amount);
916 gtk_progress_bar_paint_text (pbar, offset, amount, orientation);
924 if (orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
925 orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
926 space = widget->allocation.width - 2 * widget->style->xthickness;
928 space = widget->allocation.height - 2 * widget->style->ythickness;
931 gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
933 if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
935 gtk_progress_bar_paint_continuous (pbar, amount, orientation);
938 gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
941 gtk_progress_bar_paint_discrete (pbar, orientation);
949 /*******************************************************************/
952 * gtk_progress_bar_set_fraction:
953 * @pbar: a #GtkProgressBar
954 * @fraction: fraction of the task that's been completed
956 * Causes the progress bar to "fill in" the given fraction
957 * of the bar. The fraction should be between 0.0 and 1.0,
962 gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
965 GtkProgressBarPrivate* priv;
967 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
969 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
970 priv->fraction = fraction;
972 g_object_notify (G_OBJECT (pbar), "fraction");
976 * gtk_progress_bar_pulse:
977 * @pbar: a #GtkProgressBar
979 * Indicates that some progress is made, but you don't know how much.
980 * Causes the progress bar to enter "activity mode," where a block
981 * bounces back and forth. Each call to gtk_progress_bar_pulse()
982 * causes the block to move by a little bit (the amount of movement
983 * per pulse is determined by gtk_progress_bar_set_pulse_step()).
986 gtk_progress_bar_pulse (GtkProgressBar *pbar)
988 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
990 GTK_PROGRESS_GET_CLASS (pbar)->act_mode_enter (GTK_PROGRESS (pbar));
991 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
992 gtk_widget_queue_resize (GTK_WIDGET (pbar));
995 gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
999 * gtk_progress_bar_set_text:
1000 * @pbar: a #GtkProgressBar
1001 * @text: (allow-none): a UTF-8 string, or %NULL
1003 * Causes the given @text to appear superimposed on the progress bar.
1006 gtk_progress_bar_set_text (GtkProgressBar *pbar,
1009 GtkProgressBarPrivate *priv;
1011 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1013 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
1014 g_free (priv->text);
1015 priv->text = text && *text ? g_strdup (text) : NULL;
1017 g_object_notify (G_OBJECT (pbar), "text");
1021 * gtk_progress_bar_set_pulse_step:
1022 * @pbar: a #GtkProgressBar
1023 * @fraction: fraction between 0.0 and 1.0
1025 * Sets the fraction of total progress bar length to move the
1026 * bouncing block for each call to gtk_progress_bar_pulse().
1029 gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar,
1032 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1034 pbar->pulse_fraction = fraction;
1036 g_object_notify (G_OBJECT (pbar), "pulse-step");
1040 * gtk_progress_bar_set_orientation:
1041 * @pbar: a #GtkProgressBar
1042 * @orientation: orientation of the progress bar
1044 * Causes the progress bar to switch to a different orientation
1045 * (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
1048 gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
1049 GtkProgressBarOrientation orientation)
1051 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1053 if (pbar->orientation != orientation)
1055 pbar->orientation = orientation;
1057 if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
1058 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1060 g_object_notify (G_OBJECT (pbar), "orientation");
1065 * gtk_progress_bar_get_text:
1066 * @pbar: a #GtkProgressBar
1068 * Retrieves the text displayed superimposed on the progress bar,
1069 * if any, otherwise %NULL. The return value is a reference
1070 * to the text, not a copy of it, so will become invalid
1071 * if you change the text in the progress bar.
1073 * Return value: text, or %NULL; this string is owned by the widget
1074 * and should not be modified or freed.
1076 G_CONST_RETURN gchar*
1077 gtk_progress_bar_get_text (GtkProgressBar *pbar)
1079 GtkProgressBarPrivate* priv;
1081 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL);
1083 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
1088 * gtk_progress_bar_get_fraction:
1089 * @pbar: a #GtkProgressBar
1091 * Returns the current fraction of the task that's been completed.
1093 * Return value: a fraction from 0.0 to 1.0
1096 gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
1098 GtkProgressBarPrivate* priv;
1100 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1102 priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
1103 return priv->fraction;
1107 * gtk_progress_bar_get_pulse_step:
1108 * @pbar: a #GtkProgressBar
1110 * Retrieves the pulse step set with gtk_progress_bar_set_pulse_step()
1112 * Return value: a fraction from 0.0 to 1.0
1115 gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
1117 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1119 return pbar->pulse_fraction;
1123 * gtk_progress_bar_get_orientation:
1124 * @pbar: a #GtkProgressBar
1126 * Retrieves the current progress bar orientation.
1128 * Return value: orientation of the progress bar
1130 GtkProgressBarOrientation
1131 gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
1133 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0);
1135 return pbar->orientation;
1139 * gtk_progress_bar_set_ellipsize:
1140 * @pbar: a #GtkProgressBar
1141 * @mode: a #PangoEllipsizeMode
1143 * Sets the mode used to ellipsize (add an ellipsis: "...") the text
1144 * if there is not enough space to render the entire string.
1149 gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
1150 PangoEllipsizeMode mode)
1152 g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
1153 g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE &&
1154 mode <= PANGO_ELLIPSIZE_END);
1156 if ((PangoEllipsizeMode)pbar->ellipsize != mode)
1158 pbar->ellipsize = mode;
1160 g_object_notify (G_OBJECT (pbar), "ellipsize");
1161 gtk_widget_queue_resize (GTK_WIDGET (pbar));
1166 * gtk_progress_bar_get_ellipsize:
1167 * @pbar: a #GtkProgressBar
1169 * Returns the ellipsizing position of the progressbar.
1170 * See gtk_progress_bar_set_ellipsize().
1172 * Return value: #PangoEllipsizeMode
1177 gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
1179 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE);
1181 return pbar->ellipsize;
1184 #include "gtkaliasdef.c"