gtkprogress.c 19.3 KB
Newer Older
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17 18 19
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

20
/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27
#include <config.h>
28 29
#include <math.h>
#include <string.h>
30
#undef GTK_DISABLE_DEPRECATED
31
#include "gtkprogress.h" 
32
#include "gtkprivate.h" 
Alexander Larsson's avatar
Alexander Larsson committed
33
#include "gtkintl.h"
34
#include "gtkalias.h"
35 36

#define EPSILON  1e-5
37
#define DEFAULT_FORMAT "%P %%"
38

39
enum {
Alexander Larsson's avatar
Alexander Larsson committed
40 41 42 43 44
  PROP_0,
  PROP_ACTIVITY_MODE,
  PROP_SHOW_TEXT,
  PROP_TEXT_XALIGN,
  PROP_TEXT_YALIGN
45 46 47
};


Alexander Larsson's avatar
Alexander Larsson committed
48 49 50 51 52 53 54 55
static void gtk_progress_set_property    (GObject          *object,
					  guint             prop_id,
					  const GValue     *value,
					  GParamSpec       *pspec);
static void gtk_progress_get_property    (GObject          *object,
					  guint             prop_id,
					  GValue           *value,
					  GParamSpec       *pspec);
56
static void gtk_progress_destroy         (GtkObject        *object);
57
static void gtk_progress_finalize        (GObject          *object);
58
static void gtk_progress_realize         (GtkWidget        *widget);
Matthias Clasen's avatar
Matthias Clasen committed
59
static gboolean gtk_progress_expose      (GtkWidget        *widget,
60 61 62 63
				 	  GdkEventExpose   *event);
static void gtk_progress_size_allocate   (GtkWidget        *widget,
				 	  GtkAllocation    *allocation);
static void gtk_progress_create_pixmap   (GtkProgress      *progress);
Manish Singh's avatar
Manish Singh committed
64 65
static void gtk_progress_value_changed   (GtkAdjustment    *adjustment,
					  GtkProgress      *progress);
66 67
static void gtk_progress_changed         (GtkAdjustment    *adjustment,
					  GtkProgress      *progress);
68

Matthias Clasen's avatar
Matthias Clasen committed
69
G_DEFINE_TYPE (GtkProgress, gtk_progress, GTK_TYPE_WIDGET)
70 71 72 73

static void
gtk_progress_class_init (GtkProgressClass *class)
{
74
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
75 76 77 78 79
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;

  object_class = (GtkObjectClass *) class;
  widget_class = (GtkWidgetClass *) class;
Manish Singh's avatar
Manish Singh committed
80

81 82
  gobject_class->finalize = gtk_progress_finalize;

Alexander Larsson's avatar
Alexander Larsson committed
83 84
  gobject_class->set_property = gtk_progress_set_property;
  gobject_class->get_property = gtk_progress_get_property;
85 86 87 88 89 90 91 92 93 94
  object_class->destroy = gtk_progress_destroy;

  widget_class->realize = gtk_progress_realize;
  widget_class->expose_event = gtk_progress_expose;
  widget_class->size_allocate = gtk_progress_size_allocate;

  /* to be overridden */
  class->paint = NULL;
  class->update = NULL;
  class->act_mode_enter = NULL;
95
  
Alexander Larsson's avatar
Alexander Larsson committed
96 97
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVITY_MODE,
98
                                   g_param_spec_boolean ("activity-mode",
99
							 P_("Activity mode"),
100 101 102
							 P_("If TRUE, the GtkProgress is in activity mode, meaning that it signals "
                                                            "something is happening, but not how much of the activity is finished. "
                                                            "This is used when you're doing something but don't know how long it will take."),
Alexander Larsson's avatar
Alexander Larsson committed
103
							 FALSE,
104
							 GTK_PARAM_READWRITE));
Alexander Larsson's avatar
Alexander Larsson committed
105 106
  g_object_class_install_property (gobject_class,
                                   PROP_SHOW_TEXT,
107
                                   g_param_spec_boolean ("show-text",
108
							 P_("Show text"),
109
							 P_("Whether the progress is shown as text."),
Alexander Larsson's avatar
Alexander Larsson committed
110
							 FALSE,
111
							 GTK_PARAM_READWRITE));
Alexander Larsson's avatar
Alexander Larsson committed
112 113
  g_object_class_install_property (gobject_class,
				   PROP_TEXT_XALIGN,
114
				   g_param_spec_float ("text-xalign",
115
						       P_("Text x alignment"),
116 117
                                                       P_("The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
						       0.0, 1.0, 0.5,
118
						       GTK_PARAM_READWRITE));  
119
  g_object_class_install_property (gobject_class,
Alexander Larsson's avatar
Alexander Larsson committed
120
				   PROP_TEXT_YALIGN,
121
				   g_param_spec_float ("text-yalign",
122
						       P_("Text y alignment"),
123 124
                                                       P_("The vertical text alignment, from 0 (top) to 1 (bottom)."),
						       0.0, 1.0, 0.5,
125
						       GTK_PARAM_READWRITE));
126 127 128
}

static void
Alexander Larsson's avatar
Alexander Larsson committed
129 130 131 132
gtk_progress_set_property (GObject      *object,
			   guint         prop_id,
			   const GValue *value,
			   GParamSpec   *pspec)
133
{
134 135 136
  GtkProgress *progress;
  
  progress = GTK_PROGRESS (object);
137

Alexander Larsson's avatar
Alexander Larsson committed
138
  switch (prop_id)
139
    {
Alexander Larsson's avatar
Alexander Larsson committed
140 141
    case PROP_ACTIVITY_MODE:
      gtk_progress_set_activity_mode (progress, g_value_get_boolean (value));
142
      break;
Alexander Larsson's avatar
Alexander Larsson committed
143 144
    case PROP_SHOW_TEXT:
      gtk_progress_set_show_text (progress, g_value_get_boolean (value));
145
      break;
Alexander Larsson's avatar
Alexander Larsson committed
146 147 148 149
    case PROP_TEXT_XALIGN:
      gtk_progress_set_text_alignment (progress,
				       g_value_get_float (value),
				       progress->y_align);
150
      break;
Alexander Larsson's avatar
Alexander Larsson committed
151 152 153 154
    case PROP_TEXT_YALIGN:
      gtk_progress_set_text_alignment (progress,
				       progress->x_align,
				       g_value_get_float (value));
155 156
      break;
    default:
Alexander Larsson's avatar
Alexander Larsson committed
157
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158 159 160 161 162
      break;
    }
}

static void
Alexander Larsson's avatar
Alexander Larsson committed
163 164 165 166
gtk_progress_get_property (GObject      *object,
			   guint         prop_id,
			   GValue       *value,
			   GParamSpec   *pspec)
167 168 169 170 171
{
  GtkProgress *progress;
  
  progress = GTK_PROGRESS (object);

Alexander Larsson's avatar
Alexander Larsson committed
172
  switch (prop_id)
173
    {
Alexander Larsson's avatar
Alexander Larsson committed
174 175
    case PROP_ACTIVITY_MODE:
      g_value_set_boolean (value, (progress->activity_mode != FALSE));
176
      break;
Alexander Larsson's avatar
Alexander Larsson committed
177 178
    case PROP_SHOW_TEXT:
      g_value_set_boolean (value, (progress->show_text != FALSE));
179
      break;
Alexander Larsson's avatar
Alexander Larsson committed
180 181
    case PROP_TEXT_XALIGN:
      g_value_set_float (value, progress->x_align);
182
      break;
Alexander Larsson's avatar
Alexander Larsson committed
183 184
    case PROP_TEXT_YALIGN:
      g_value_set_float (value, progress->y_align);
185 186
      break;
    default:
Alexander Larsson's avatar
Alexander Larsson committed
187
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
188 189 190 191 192 193 194 195
      break;
    }
}

static void
gtk_progress_init (GtkProgress *progress)
{
  progress->adjustment = NULL;
196
  progress->offscreen_pixmap = NULL;
197
  progress->format = g_strdup (DEFAULT_FORMAT);
198 199 200 201
  progress->x_align = 0.5;
  progress->y_align = 0.5;
  progress->show_text = FALSE;
  progress->activity_mode = FALSE;
202
  progress->use_text_format = TRUE;
203 204 205 206 207
}

static void
gtk_progress_realize (GtkWidget *widget)
{
208
  GtkProgress *progress = GTK_PROGRESS (widget);
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
  GdkWindowAttr attributes;
  gint attributes_mask;

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget);
  attributes.event_mask |= GDK_EXPOSURE_MASK;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
				   &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, progress);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);

  gtk_progress_create_pixmap (progress);
}

237 238 239
static void
gtk_progress_destroy (GtkObject *object)
{
240
  GtkProgress *progress = GTK_PROGRESS (object);
241 242

  if (progress->adjustment)
243
    {
Manish Singh's avatar
Manish Singh committed
244 245 246
      g_signal_handlers_disconnect_by_func (progress->adjustment,
					    gtk_progress_value_changed,
					    progress);
247 248 249
      g_signal_handlers_disconnect_by_func (progress->adjustment,
					    gtk_progress_changed,
					    progress);
Manish Singh's avatar
Manish Singh committed
250
      g_object_unref (progress->adjustment);
251 252
      progress->adjustment = NULL;
    }
253

Matthias Clasen's avatar
Matthias Clasen committed
254
  GTK_OBJECT_CLASS (gtk_progress_parent_class)->destroy (object);
255 256
}

257
static void
258
gtk_progress_finalize (GObject *object)
259
{
260
  GtkProgress *progress = GTK_PROGRESS (object);
261 262

  if (progress->offscreen_pixmap)
Manish Singh's avatar
Manish Singh committed
263
    g_object_unref (progress->offscreen_pixmap);
264

265
  g_free (progress->format);
266

Matthias Clasen's avatar
Matthias Clasen committed
267
  G_OBJECT_CLASS (gtk_progress_parent_class)->finalize (object);
268 269
}

Matthias Clasen's avatar
Matthias Clasen committed
270
static gboolean
271 272 273 274
gtk_progress_expose (GtkWidget      *widget,
		     GdkEventExpose *event)
{
  if (GTK_WIDGET_DRAWABLE (widget))
Manish Singh's avatar
Manish Singh committed
275 276 277 278 279 280 281
    gdk_draw_drawable (widget->window,
		       widget->style->black_gc,
		       GTK_PROGRESS (widget)->offscreen_pixmap,
		       event->area.x, event->area.y,
		       event->area.x, event->area.y,
		       event->area.width,
		       event->area.height);
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

  return FALSE;
}

static void
gtk_progress_size_allocate (GtkWidget     *widget,
			    GtkAllocation *allocation)
{
  widget->allocation = *allocation;

  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_move_resize (widget->window,
			      allocation->x, allocation->y,
			      allocation->width, allocation->height);

      gtk_progress_create_pixmap (GTK_PROGRESS (widget));
    }
}

static void
gtk_progress_create_pixmap (GtkProgress *progress)
{
  GtkWidget *widget;

  g_return_if_fail (GTK_IS_PROGRESS (progress));

  if (GTK_WIDGET_REALIZED (progress))
    {
      widget = GTK_WIDGET (progress);

      if (progress->offscreen_pixmap)
Manish Singh's avatar
Manish Singh committed
314
	g_object_unref (progress->offscreen_pixmap);
315 316 317 318 319

      progress->offscreen_pixmap = gdk_pixmap_new (widget->window,
						   widget->allocation.width,
						   widget->allocation.height,
						   -1);
320 321 322 323 324 325 326

      /* clear the pixmap for transparent themes */
      gtk_paint_flat_box (widget->style,
                          progress->offscreen_pixmap,
                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                          NULL, widget, "trough", 0, 0, -1, -1);
      
327
      GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
328 329 330
    }
}

331 332 333 334 335 336 337 338
static void
gtk_progress_changed (GtkAdjustment *adjustment,
		      GtkProgress   *progress)
{
  /* A change in the value of adjustment->upper can change
   * the size request
   */
  if (progress->use_text_format && progress->show_text)
Sven Neumann's avatar
Sven Neumann committed
339
    gtk_widget_queue_resize (GTK_WIDGET (progress));
340 341 342 343
  else
    GTK_PROGRESS_GET_CLASS (progress)->update (progress);
}

344 345 346 347
static void
gtk_progress_value_changed (GtkAdjustment *adjustment,
			    GtkProgress   *progress)
{
348
  GTK_PROGRESS_GET_CLASS (progress)->update (progress);
349 350 351 352
}

static gchar *
gtk_progress_build_string (GtkProgress *progress,
353 354
			   gdouble      value,
			   gdouble      percentage)
355 356 357 358 359 360 361 362
{
  gchar buf[256] = { 0 };
  gchar tmp[256] = { 0 };
  gchar *src;
  gchar *dest;
  gchar fmt[10];

  src = progress->format;
363 364 365 366 367 368 369

  /* This is the new supported version of this function */
  if (!progress->use_text_format)
    return g_strdup (src);

  /* And here's all the deprecated goo. */
  
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
  dest = buf;
 
  while (src && *src)
    {
      if (*src != '%')
	{
	  *dest = *src;
	  dest++;
	}
      else
	{
	  gchar c;
	  gint digits;

	  c = *(src + sizeof(gchar));
	  digits = 0;

	  if (c >= '0' && c <= '2')
	    {
	      digits = (gint) (c - '0');
	      src++;
	      c = *(src + sizeof(gchar));
	    }

	  switch (c)
	    {
	    case '%':
	      *dest = '%';
	      src++;
	      dest++;
	      break;
	    case 'p':
	    case 'P':
	      if (digits)
		{
405 406
		  g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
		  g_snprintf (tmp, sizeof (tmp), fmt, 100 * percentage);
407 408
		}
	      else
409
		g_snprintf (tmp, sizeof (tmp), "%.0f", 100 * percentage);
410 411 412 413 414 415 416 417
	      strcat (buf, tmp);
	      dest = &(buf[strlen (buf)]);
	      src++;
	      break;
	    case 'v':
	    case 'V':
	      if (digits)
		{
418 419
		  g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
		  g_snprintf (tmp, sizeof (tmp), fmt, value);
420 421
		}
	      else
422
		g_snprintf (tmp, sizeof (tmp), "%.0f", value);
423 424 425 426 427 428 429 430
	      strcat (buf, tmp);
	      dest = &(buf[strlen (buf)]);
	      src++;
	      break;
	    case 'l':
	    case 'L':
	      if (digits)
		{
431 432
		  g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
		  g_snprintf (tmp, sizeof (tmp), fmt, progress->adjustment->lower);
433 434
		}
	      else
435
		g_snprintf (tmp, sizeof (tmp), "%.0f", progress->adjustment->lower);
436 437 438 439 440 441 442 443
	      strcat (buf, tmp);
	      dest = &(buf[strlen (buf)]);
	      src++;
	      break;
	    case 'u':
	    case 'U':
	      if (digits)
		{
444 445
		  g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
		  g_snprintf (tmp, sizeof (tmp), fmt, progress->adjustment->upper);
446 447
		}
	      else
448
		g_snprintf (tmp, sizeof (tmp), "%.0f", progress->adjustment->upper);
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	      strcat (buf, tmp);
	      dest = &(buf[strlen (buf)]);
	      src++;
	      break;
	    default:
	      break;
	    }
	}
      src++;
    }

  return g_strdup (buf);
}

/***************************************************************/

void
gtk_progress_set_adjustment (GtkProgress   *progress,
			     GtkAdjustment *adjustment)
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));
470 471 472
  if (adjustment)
    g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
  else
473
    adjustment = (GtkAdjustment*) gtk_adjustment_new (0, 0, 100, 0, 0, 0);
474 475 476 477 478

  if (progress->adjustment != adjustment)
    {
      if (progress->adjustment)
        {
479 480 481
	  g_signal_handlers_disconnect_by_func (progress->adjustment,
						gtk_progress_changed,
						progress);
Manish Singh's avatar
Manish Singh committed
482 483 484 485
	  g_signal_handlers_disconnect_by_func (progress->adjustment,
						gtk_progress_value_changed,
						progress);
          g_object_unref (progress->adjustment);
486 487 488 489
        }
      progress->adjustment = adjustment;
      if (adjustment)
        {
490
          g_object_ref_sink (adjustment);
491 492 493
          g_signal_connect (adjustment, "changed",
			    G_CALLBACK (gtk_progress_changed),
			    progress);
Manish Singh's avatar
Manish Singh committed
494 495 496
          g_signal_connect (adjustment, "value_changed",
			    G_CALLBACK (gtk_progress_value_changed),
			    progress);
497
        }
498 499

      gtk_progress_changed (adjustment, progress);
500 501 502 503
    }
}

void
504
gtk_progress_configure (GtkProgress *progress,
505 506 507
			gdouble      value,
			gdouble      min,
			gdouble      max)
508 509 510 511 512 513 514 515
{
  GtkAdjustment *adj;
  gboolean changed = FALSE;

  g_return_if_fail (GTK_IS_PROGRESS (progress));
  g_return_if_fail (min <= max);
  g_return_if_fail (value >= min && value <= max);

516 517
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);
518 519 520 521 522 523 524 525 526
  adj = progress->adjustment;

  if (fabs (adj->lower - min) > EPSILON || fabs (adj->upper - max) > EPSILON)
    changed = TRUE;

  adj->value = value;
  adj->lower = min;
  adj->upper = max;

Manish Singh's avatar
Manish Singh committed
527
  gtk_adjustment_value_changed (adj);
528
  if (changed)
Manish Singh's avatar
Manish Singh committed
529
    gtk_adjustment_changed (adj);
530 531 532 533
}

void
gtk_progress_set_percentage (GtkProgress *progress,
534
			     gdouble      percentage)
535 536 537 538
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));
  g_return_if_fail (percentage >= 0 && percentage <= 1.0);

539 540
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);
541 542 543 544
  gtk_progress_set_value (progress, progress->adjustment->lower + percentage * 
		 (progress->adjustment->upper - progress->adjustment->lower));
}

545
gdouble
546 547 548 549
gtk_progress_get_current_percentage (GtkProgress *progress)
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

550 551 552
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

553
  return gtk_progress_get_percentage_from_value (progress, progress->adjustment->value);
554 555
}

556
gdouble
557
gtk_progress_get_percentage_from_value (GtkProgress *progress,
558
					gdouble      value)
559 560 561
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

562 563 564
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

565 566
  if (progress->adjustment->lower < progress->adjustment->upper &&
      value >= progress->adjustment->lower &&
567 568 569 570 571 572 573 574 575
      value <= progress->adjustment->upper)
    return (value - progress->adjustment->lower) /
      (progress->adjustment->upper - progress->adjustment->lower);
  else
    return 0.0;
}

void
gtk_progress_set_value (GtkProgress *progress,
576
			gdouble      value)
577 578 579
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

580 581 582
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

583 584 585 586
  if (fabs (progress->adjustment->value - value) > EPSILON)
    gtk_adjustment_set_value (progress->adjustment, value);
}

587
gdouble
588 589 590 591
gtk_progress_get_value (GtkProgress *progress)
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

592
  return progress->adjustment ? progress->adjustment->value : 0;
593 594 595 596
}

void
gtk_progress_set_show_text (GtkProgress *progress,
597
			    gboolean     show_text)
598 599 600 601 602 603 604
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

  if (progress->show_text != show_text)
    {
      progress->show_text = show_text;

605
      gtk_widget_queue_resize (GTK_WIDGET (progress));
Alexander Larsson's avatar
Alexander Larsson committed
606

607
      g_object_notify (G_OBJECT (progress), "show-text");
608 609 610 611 612 613 614 615 616 617 618 619 620 621
    }
}

void
gtk_progress_set_text_alignment (GtkProgress *progress,
				 gfloat       x_align,
				 gfloat       y_align)
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));
  g_return_if_fail (x_align >= 0.0 && x_align <= 1.0);
  g_return_if_fail (y_align >= 0.0 && y_align <= 1.0);

  if (progress->x_align != x_align || progress->y_align != y_align)
    {
Hans Breuer's avatar
Hans Breuer committed
622
      g_object_freeze_notify (G_OBJECT (progress));
Alexander Larsson's avatar
Alexander Larsson committed
623 624 625
      if (progress->x_align != x_align)
	{
	  progress->x_align = x_align;
626
	  g_object_notify (G_OBJECT (progress), "text-xalign");
Alexander Larsson's avatar
Alexander Larsson committed
627 628 629 630 631
	}

      if (progress->y_align != y_align)
	{
	  progress->y_align = y_align;
632
	  g_object_notify (G_OBJECT (progress), "text-yalign");
Alexander Larsson's avatar
Alexander Larsson committed
633
	}
Hans Breuer's avatar
Hans Breuer committed
634
      g_object_thaw_notify (G_OBJECT (progress));
635 636 637 638 639 640 641 642

      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (progress)))
	gtk_widget_queue_resize (GTK_WIDGET (progress));
    }
}

void
gtk_progress_set_format_string (GtkProgress *progress,
Owen Taylor's avatar
Owen Taylor committed
643
				const gchar *format)
644
{
645 646
  gchar *old_format;
  
647 648
  g_return_if_fail (GTK_IS_PROGRESS (progress));

649 650 651 652
  /* Turn on format, in case someone called
   * gtk_progress_bar_set_text() and turned it off.
   */
  progress->use_text_format = TRUE;
653

654 655 656 657 658 659 660 661
  old_format = progress->format;

  if (!format)
    format = DEFAULT_FORMAT;

  progress->format = g_strdup (format);
  g_free (old_format);
  
662
  gtk_widget_queue_resize (GTK_WIDGET (progress));
663 664 665 666 667
}

gchar *
gtk_progress_get_current_text (GtkProgress *progress)
{
Matthias Clasen's avatar
Matthias Clasen committed
668
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
669

670 671 672
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

673
  return gtk_progress_build_string (progress, progress->adjustment->value,
674
				    gtk_progress_get_current_percentage (progress));
675 676 677 678
}

gchar *
gtk_progress_get_text_from_value (GtkProgress *progress,
679
				  gdouble      value)
680
{
Matthias Clasen's avatar
Matthias Clasen committed
681
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
682

683 684 685
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

686
  return gtk_progress_build_string (progress, value,
687
				    gtk_progress_get_percentage_from_value (progress, value));
688 689 690 691
}

void
gtk_progress_set_activity_mode (GtkProgress *progress,
692
				gboolean     activity_mode)
693 694 695
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

696
  if (progress->activity_mode != (activity_mode != FALSE))
697
    {
698
      progress->activity_mode = (activity_mode != FALSE);
699 700

      if (progress->activity_mode)
701
	GTK_PROGRESS_GET_CLASS (progress)->act_mode_enter (progress);
702 703 704

      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (progress)))
	gtk_widget_queue_resize (GTK_WIDGET (progress));
Alexander Larsson's avatar
Alexander Larsson committed
705

706
      g_object_notify (G_OBJECT (progress), "activity-mode");
707 708
    }
}
709 710 711

#define __GTK_PROGRESS_C__
#include "gtkaliasdef.c"