gtkprogress.c 19.3 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
2 3 4
 * 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

31
#undef GTK_DISABLE_DEPRECATED
32 33
#define __GTK_PROGRESS_C__

34
#include "gtkprogress.h" 
35
#include "gtkprivate.h" 
Alexander Larsson's avatar
Alexander Larsson committed
36
#include "gtkintl.h"
37
#include "gtkalias.h"
38 39

#define EPSILON  1e-5
40
#define DEFAULT_FORMAT "%P %%"
41

42
enum {
Alexander Larsson's avatar
Alexander Larsson committed
43 44 45 46 47
  PROP_0,
  PROP_ACTIVITY_MODE,
  PROP_SHOW_TEXT,
  PROP_TEXT_XALIGN,
  PROP_TEXT_YALIGN
48 49 50
};


Alexander Larsson's avatar
Alexander Larsson committed
51 52 53 54 55 56 57 58
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);
59
static void gtk_progress_destroy         (GtkObject        *object);
60
static void gtk_progress_finalize        (GObject          *object);
61
static void gtk_progress_realize         (GtkWidget        *widget);
Matthias Clasen's avatar
Matthias Clasen committed
62
static gboolean gtk_progress_expose      (GtkWidget        *widget,
63 64 65 66
				 	  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
67 68
static void gtk_progress_value_changed   (GtkAdjustment    *adjustment,
					  GtkProgress      *progress);
69 70
static void gtk_progress_changed         (GtkAdjustment    *adjustment,
					  GtkProgress      *progress);
71

72
G_DEFINE_ABSTRACT_TYPE (GtkProgress, gtk_progress, GTK_TYPE_WIDGET)
73 74 75 76

static void
gtk_progress_class_init (GtkProgressClass *class)
{
77
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
78 79 80 81 82
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;

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

84 85
  gobject_class->finalize = gtk_progress_finalize;

Alexander Larsson's avatar
Alexander Larsson committed
86 87
  gobject_class->set_property = gtk_progress_set_property;
  gobject_class->get_property = gtk_progress_get_property;
88 89 90 91 92 93 94 95 96 97
  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;
98
  
Alexander Larsson's avatar
Alexander Larsson committed
99 100
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVITY_MODE,
101
                                   g_param_spec_boolean ("activity-mode",
102
							 P_("Activity mode"),
103 104 105
							 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
106
							 FALSE,
107
							 GTK_PARAM_READWRITE));
Alexander Larsson's avatar
Alexander Larsson committed
108 109
  g_object_class_install_property (gobject_class,
                                   PROP_SHOW_TEXT,
110
                                   g_param_spec_boolean ("show-text",
111
							 P_("Show text"),
112
							 P_("Whether the progress is shown as text."),
Alexander Larsson's avatar
Alexander Larsson committed
113
							 FALSE,
114
							 GTK_PARAM_READWRITE));
Alexander Larsson's avatar
Alexander Larsson committed
115 116
  g_object_class_install_property (gobject_class,
				   PROP_TEXT_XALIGN,
117
				   g_param_spec_float ("text-xalign",
118
						       P_("Text x alignment"),
119 120
                                                       P_("The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
						       0.0, 1.0, 0.5,
121
						       GTK_PARAM_READWRITE));  
122
  g_object_class_install_property (gobject_class,
Alexander Larsson's avatar
Alexander Larsson committed
123
				   PROP_TEXT_YALIGN,
124
				   g_param_spec_float ("text-yalign",
125
						       P_("Text y alignment"),
126 127
                                                       P_("The vertical text alignment, from 0 (top) to 1 (bottom)."),
						       0.0, 1.0, 0.5,
128
						       GTK_PARAM_READWRITE));
129 130 131
}

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

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

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

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

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

static void
gtk_progress_realize (GtkWidget *widget)
{
211
  GtkProgress *progress = GTK_PROGRESS (widget);
212 213 214
  GdkWindowAttr attributes;
  gint attributes_mask;

215
  gtk_widget_set_realized (widget, TRUE);
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

  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);
}

240 241 242
static void
gtk_progress_destroy (GtkObject *object)
{
243
  GtkProgress *progress = GTK_PROGRESS (object);
244 245

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

Matthias Clasen's avatar
Matthias Clasen committed
257
  GTK_OBJECT_CLASS (gtk_progress_parent_class)->destroy (object);
258 259
}

260
static void
261
gtk_progress_finalize (GObject *object)
262
{
263
  GtkProgress *progress = GTK_PROGRESS (object);
264 265

  if (progress->offscreen_pixmap)
Manish Singh's avatar
Manish Singh committed
266
    g_object_unref (progress->offscreen_pixmap);
267

268
  g_free (progress->format);
269

Matthias Clasen's avatar
Matthias Clasen committed
270
  G_OBJECT_CLASS (gtk_progress_parent_class)->finalize (object);
271 272
}

Matthias Clasen's avatar
Matthias Clasen committed
273
static gboolean
274 275 276 277
gtk_progress_expose (GtkWidget      *widget,
		     GdkEventExpose *event)
{
  if (GTK_WIDGET_DRAWABLE (widget))
Manish Singh's avatar
Manish Singh committed
278 279 280 281 282 283 284
    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);
285 286 287 288 289 290 291 292 293 294

  return FALSE;
}

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

295
  if (gtk_widget_get_realized (widget))
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    {
      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));

312
  widget = GTK_WIDGET (progress);
313

314 315
  if (gtk_widget_get_realized (widget))
    {
316
      if (progress->offscreen_pixmap)
Manish Singh's avatar
Manish Singh committed
317
	g_object_unref (progress->offscreen_pixmap);
318 319 320 321 322

      progress->offscreen_pixmap = gdk_pixmap_new (widget->window,
						   widget->allocation.width,
						   widget->allocation.height,
						   -1);
323 324 325 326 327 328 329

      /* 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);
      
330
      GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
331 332 333
    }
}

334 335 336 337 338 339 340 341
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
342
    gtk_widget_queue_resize (GTK_WIDGET (progress));
343 344 345 346
  else
    GTK_PROGRESS_GET_CLASS (progress)->update (progress);
}

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

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

  src = progress->format;
366 367 368 369 370 371 372

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

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

      gtk_progress_changed (adjustment, progress);
503 504 505 506
    }
}

void
507
gtk_progress_configure (GtkProgress *progress,
508 509 510
			gdouble      value,
			gdouble      min,
			gdouble      max)
511 512 513 514 515 516 517 518
{
  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);

519 520
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);
521 522 523 524 525 526 527 528 529
  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
530
  gtk_adjustment_value_changed (adj);
531
  if (changed)
Manish Singh's avatar
Manish Singh committed
532
    gtk_adjustment_changed (adj);
533 534 535 536
}

void
gtk_progress_set_percentage (GtkProgress *progress,
537
			     gdouble      percentage)
538 539 540 541
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));
  g_return_if_fail (percentage >= 0 && percentage <= 1.0);

542 543
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);
544 545 546 547
  gtk_progress_set_value (progress, progress->adjustment->lower + percentage * 
		 (progress->adjustment->upper - progress->adjustment->lower));
}

548
gdouble
549 550 551 552
gtk_progress_get_current_percentage (GtkProgress *progress)
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

553 554 555
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

556
  return gtk_progress_get_percentage_from_value (progress, progress->adjustment->value);
557 558
}

559
gdouble
560
gtk_progress_get_percentage_from_value (GtkProgress *progress,
561
					gdouble      value)
562 563 564
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

565 566 567
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

568 569
  if (progress->adjustment->lower < progress->adjustment->upper &&
      value >= progress->adjustment->lower &&
570 571 572 573 574 575 576 577 578
      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,
579
			gdouble      value)
580 581 582
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

583 584 585
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

586 587 588 589
  if (fabs (progress->adjustment->value - value) > EPSILON)
    gtk_adjustment_set_value (progress->adjustment, value);
}

590
gdouble
591 592 593 594
gtk_progress_get_value (GtkProgress *progress)
{
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);

595
  return progress->adjustment ? progress->adjustment->value : 0;
596 597 598 599
}

void
gtk_progress_set_show_text (GtkProgress *progress,
600
			    gboolean     show_text)
601 602 603 604 605 606 607
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

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

608
      gtk_widget_queue_resize (GTK_WIDGET (progress));
Alexander Larsson's avatar
Alexander Larsson committed
609

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

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)
    {
625
      g_object_freeze_notify (G_OBJECT (progress));
Alexander Larsson's avatar
Alexander Larsson committed
626 627 628
      if (progress->x_align != x_align)
	{
	  progress->x_align = x_align;
629
	  g_object_notify (G_OBJECT (progress), "text-xalign");
Alexander Larsson's avatar
Alexander Larsson committed
630 631 632 633 634
	}

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

      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
646
				const gchar *format)
647
{
648 649
  gchar *old_format;
  
650 651
  g_return_if_fail (GTK_IS_PROGRESS (progress));

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

657 658 659 660 661 662 663 664
  old_format = progress->format;

  if (!format)
    format = DEFAULT_FORMAT;

  progress->format = g_strdup (format);
  g_free (old_format);
  
665
  gtk_widget_queue_resize (GTK_WIDGET (progress));
666 667 668 669 670
}

gchar *
gtk_progress_get_current_text (GtkProgress *progress)
{
671
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
672

673 674 675
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

676
  return gtk_progress_build_string (progress, progress->adjustment->value,
677
				    gtk_progress_get_current_percentage (progress));
678 679 680 681
}

gchar *
gtk_progress_get_text_from_value (GtkProgress *progress,
682
				  gdouble      value)
683
{
684
  g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
685

686 687 688
  if (!progress->adjustment)
    gtk_progress_set_adjustment (progress, NULL);

689
  return gtk_progress_build_string (progress, value,
690
				    gtk_progress_get_percentage_from_value (progress, value));
691 692 693 694
}

void
gtk_progress_set_activity_mode (GtkProgress *progress,
695
				gboolean     activity_mode)
696 697 698
{
  g_return_if_fail (GTK_IS_PROGRESS (progress));

699
  if (progress->activity_mode != (activity_mode != FALSE))
700
    {
701
      progress->activity_mode = (activity_mode != FALSE);
702 703

      if (progress->activity_mode)
704
	GTK_PROGRESS_GET_CLASS (progress)->act_mode_enter (progress);
705 706 707

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

709
      g_object_notify (G_OBJECT (progress), "activity-mode");
710 711
    }
}
712 713

#include "gtkaliasdef.c"