gtkprogressbar.c 18.9 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* 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
 * modify it under the terms of the GNU Library General Public
 * 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
15
16
17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19
20

#include <stdio.h>
Elliot Lee's avatar
Elliot Lee committed
21
#include "gtkprogressbar.h"
22
#include "gtksignal.h"
Elliot Lee's avatar
Elliot Lee committed
23
24


25
26
27
28
29
30
#define MIN_HORIZONTAL_BAR_WIDTH   150
#define MIN_HORIZONTAL_BAR_HEIGHT  20
#define MIN_VERTICAL_BAR_WIDTH     22
#define MIN_VERTICAL_BAR_HEIGHT    80
#define MAX_TEXT_LENGTH            80
#define TEXT_SPACING               2
Elliot Lee's avatar
Elliot Lee committed
31
32
33
34


static void gtk_progress_bar_class_init    (GtkProgressBarClass *klass);
static void gtk_progress_bar_init          (GtkProgressBar      *pbar);
35
36
37
38
39
static void gtk_progress_bar_size_request  (GtkWidget           *widget,
					    GtkRequisition      *requisition);
static void gtk_progress_bar_real_update   (GtkProgress         *progress);
static void gtk_progress_bar_paint         (GtkProgress         *progress);
static void gtk_progress_bar_act_mode_enter (GtkProgress        *progress);
Elliot Lee's avatar
Elliot Lee committed
40
41
42


guint
43
gtk_progress_bar_get_type (void)
Elliot Lee's avatar
Elliot Lee committed
44
45
46
47
48
49
50
51
52
53
54
55
{
  static guint progress_bar_type = 0;

  if (!progress_bar_type)
    {
      GtkTypeInfo progress_bar_info =
      {
	"GtkProgressBar",
	sizeof (GtkProgressBar),
	sizeof (GtkProgressBarClass),
	(GtkClassInitFunc) gtk_progress_bar_class_init,
	(GtkObjectInitFunc) gtk_progress_bar_init,
56
        /* reserved_1 */ NULL,
57
        /* reserved_2 */ NULL,
58
        (GtkClassInitFunc) NULL
Elliot Lee's avatar
Elliot Lee committed
59
60
      };

61
62
      progress_bar_type = gtk_type_unique (gtk_progress_get_type (),
					   &progress_bar_info);
Elliot Lee's avatar
Elliot Lee committed
63
64
65
66
67
68
69
70
71
    }

  return progress_bar_type;
}

static void
gtk_progress_bar_class_init (GtkProgressBarClass *class)
{
  GtkWidgetClass *widget_class;
72
73
74
75
  GtkProgressClass *progress_class;

  widget_class = (GtkWidgetClass *) class;
  progress_class = (GtkProgressClass *) class;
Elliot Lee's avatar
Elliot Lee committed
76

77
  widget_class->size_request = gtk_progress_bar_size_request;
Elliot Lee's avatar
Elliot Lee committed
78

79
80
81
  progress_class->paint = gtk_progress_bar_paint;
  progress_class->update = gtk_progress_bar_real_update;
  progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
Elliot Lee's avatar
Elliot Lee committed
82
83
84
85
86
87
88
}

static void
gtk_progress_bar_init (GtkProgressBar *pbar)
{
  GTK_WIDGET_SET_FLAGS (pbar, GTK_BASIC);

89
90
91
92
93
94
95
  pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
  pbar->blocks = 10;
  pbar->in_block = -1;
  pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
  pbar->activity_pos = 0;
  pbar->activity_dir = 1;
  pbar->activity_step = 3;
96
  pbar->activity_blocks = 5;
Elliot Lee's avatar
Elliot Lee committed
97
98
99
}


100
GtkWidget *
101
gtk_progress_bar_new (void)
Elliot Lee's avatar
Elliot Lee committed
102
{
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  GtkProgressBar *pbar;

  pbar = gtk_type_new (gtk_progress_bar_get_type ());

  gtk_progress_bar_construct (pbar, NULL);

  return GTK_WIDGET (pbar);
}

GtkWidget *
gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment)
{
  GtkProgressBar *pbar;

  pbar = gtk_type_new (gtk_progress_bar_get_type ());

  gtk_progress_bar_construct (pbar, adjustment);

  return GTK_WIDGET (pbar);
Elliot Lee's avatar
Elliot Lee committed
122
123
124
}

void
125
126
gtk_progress_bar_construct (GtkProgressBar *pbar,
			    GtkAdjustment  *adjustment)
Elliot Lee's avatar
Elliot Lee committed
127
128
129
130
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));

131
132
  if (!adjustment)
    adjustment = (GtkAdjustment *) gtk_adjustment_new (0, 0, 100, 0, 0, 0);
Elliot Lee's avatar
Elliot Lee committed
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  gtk_progress_set_adjustment (GTK_PROGRESS (pbar), adjustment);
}

static void
gtk_progress_bar_real_update (GtkProgress *progress)
{
  GtkProgressBar *pbar;
  GtkWidget *widget;

  g_return_if_fail (progress != NULL);
  g_return_if_fail (GTK_IS_PROGRESS (progress));

  pbar = GTK_PROGRESS_BAR (progress);
  widget = GTK_WIDGET (progress);
 
  if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
      GTK_PROGRESS (pbar)->activity_mode)
Elliot Lee's avatar
Elliot Lee committed
151
    {
152
153
154
155
156
157
158
159
160
      if (GTK_PROGRESS (pbar)->activity_mode)
	{
	  guint size;

	  /* advance the block */

	  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
	      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
	    {
161
	      size = MAX (2, widget->allocation.width / pbar->activity_blocks);
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

	      if (pbar->activity_dir == 0)
		{
		  pbar->activity_pos += pbar->activity_step;
		  if (pbar->activity_pos + size >=
		      widget->allocation.width -
		      widget->style->klass->xthickness)
		    {
		      pbar->activity_pos = widget->allocation.width -
			widget->style->klass->xthickness - size;
		      pbar->activity_dir = 1;
		    }
		}
	      else
		{
		  pbar->activity_pos -= pbar->activity_step;
		  if (pbar->activity_pos <= widget->style->klass->xthickness)
		    {
		      pbar->activity_pos = widget->style->klass->xthickness;
		      pbar->activity_dir = 0;
		    }
		}
	    }
	  else
	    {
187
	      size = MAX (2, widget->allocation.height / pbar->activity_blocks);
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

	      if (pbar->activity_dir == 0)
		{
		  pbar->activity_pos += pbar->activity_step;
		  if (pbar->activity_pos + size >=
		      widget->allocation.height -
		      widget->style->klass->ythickness)
		    {
		      pbar->activity_pos = widget->allocation.height -
			widget->style->klass->ythickness - size;
		      pbar->activity_dir = 1;
		    }
		}
	      else
		{
		  pbar->activity_pos -= pbar->activity_step;
		  if (pbar->activity_pos <= widget->style->klass->ythickness)
		    {
		      pbar->activity_pos = widget->style->klass->ythickness;
		      pbar->activity_dir = 0;
		    }
		}
	    }
	}
      gtk_progress_bar_paint (progress);
      gtk_widget_queue_draw (GTK_WIDGET (progress));
    }
  else
    {
      gint in_block;
      
      in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
			     (gfloat)pbar->blocks);
      
      if (pbar->in_block != in_block)
	{
	  pbar->in_block = in_block;
	  gtk_progress_bar_paint (progress);
	  gtk_widget_queue_draw (GTK_WIDGET (progress));
	}
Elliot Lee's avatar
Elliot Lee committed
228
229
230
231
    }
}

static void
232
233
gtk_progress_bar_size_request (GtkWidget      *widget,
			       GtkRequisition *requisition)
Elliot Lee's avatar
Elliot Lee committed
234
{
235
  GtkProgress *progress;
Elliot Lee's avatar
Elliot Lee committed
236
  GtkProgressBar *pbar;
237
  gchar *buf;
Elliot Lee's avatar
Elliot Lee committed
238
239
240

  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
241
  g_return_if_fail (requisition != NULL);
Elliot Lee's avatar
Elliot Lee committed
242

243
  progress = GTK_PROGRESS (widget);
Elliot Lee's avatar
Elliot Lee committed
244
245
  pbar = GTK_PROGRESS_BAR (widget);

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
    {
      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
	{
	  buf = gtk_progress_get_text_from_value (progress,
						  progress->adjustment->upper);

	  requisition->width = MAX (MIN_HORIZONTAL_BAR_WIDTH,
				    2 * widget->style->klass->xthickness + 3 +
				    gdk_text_width (widget->style->font, 
						    buf, strlen (buf)) +
				    2 * TEXT_SPACING);

	  requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
				     2 * widget->style->klass->ythickness + 3 +
				     gdk_text_height (widget->style->font, 
						      buf, strlen (buf)) +
				     2 * TEXT_SPACING);
	  g_free (buf);
	}
      else
	{
	  requisition->width = MIN_HORIZONTAL_BAR_WIDTH;
	  requisition->height = MIN_HORIZONTAL_BAR_HEIGHT;
	}
    }
  else
    {
      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
	{	  
	  buf = gtk_progress_get_text_from_value (progress,
						  progress->adjustment->upper);

	  requisition->width = MAX (MIN_VERTICAL_BAR_WIDTH,
				    2 * widget->style->klass->xthickness + 3 +
				    gdk_text_width (widget->style->font, 
						    buf, strlen (buf)) +
				    2 * TEXT_SPACING);

	  requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
				     2 * widget->style->klass->ythickness + 3 +
				     gdk_text_height (widget->style->font, 
						      buf, strlen (buf)) +
				     2 * TEXT_SPACING);
	  g_free (buf);
	}
      else
	{
	  requisition->width = MIN_VERTICAL_BAR_WIDTH;
	  requisition->height = MIN_VERTICAL_BAR_HEIGHT;
	}
    }
}
Elliot Lee's avatar
Elliot Lee committed
300

301
302
303
304
305
static void
gtk_progress_bar_act_mode_enter (GtkProgress *progress)
{
  GtkProgressBar *pbar;
  GtkWidget *widget;
306
  gint size;
Elliot Lee's avatar
Elliot Lee committed
307

308
309
  pbar = GTK_PROGRESS_BAR (progress);
  widget = GTK_WIDGET (progress);
Elliot Lee's avatar
Elliot Lee committed
310

311
  /* calculate start pos */
Elliot Lee's avatar
Elliot Lee committed
312

313
314
315
  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
    {
316
317
      size = MAX (2, widget->allocation.width / pbar->activity_blocks);

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
	{
	  pbar->activity_pos = widget->style->klass->xthickness;
	  pbar->activity_dir = 0;
	}
      else
	{
	  pbar->activity_pos = widget->allocation.width - 
	    widget->style->klass->xthickness - (widget->allocation.height - 
		widget->style->klass->ythickness * 2);
	  pbar->activity_dir = 1;
	}
    }
  else
    {
333
334
      size = MAX (2, widget->allocation.height / pbar->activity_blocks);

335
336
337
338
339
340
341
342
343
344
345
346
347
      if (pbar->orientation == GTK_PROGRESS_TOP_TO_BOTTOM)
	{
	  pbar->activity_pos = widget->style->klass->ythickness;
	  pbar->activity_dir = 0;
	}
      else
	{
	  pbar->activity_pos = widget->allocation.height -
	    widget->style->klass->ythickness - (widget->allocation.width - 
		widget->style->klass->xthickness * 2);
	  pbar->activity_dir = 1;
	}
    }
Elliot Lee's avatar
Elliot Lee committed
348
349
350
}

static void
351
gtk_progress_bar_paint (GtkProgress *progress)
Elliot Lee's avatar
Elliot Lee committed
352
{
353
354
355
356
357
358
359
360
361
  GtkProgressBar *pbar;
  GtkWidget *widget;
  gint amount;
  gint block_delta = 0;
  gint space = 0;
  gint i;
  gint x;
  gint y;
  gfloat percentage;
362
  gint size;
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

  g_return_if_fail (progress != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));

  pbar = GTK_PROGRESS_BAR (progress);
  widget = GTK_WIDGET (progress);

  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
    space = widget->allocation.width -
      2 * widget->style->klass->xthickness;
  else
    space = widget->allocation.height -
      2 * widget->style->klass->ythickness;

  percentage = gtk_progress_get_current_percentage (progress);

  if (progress->offscreen_pixmap)
    {
382
383
384
385
386
387
388
389
      gtk_paint_box (widget->style,
		     progress->offscreen_pixmap,
		     GTK_STATE_NORMAL, GTK_SHADOW_IN, 
		     NULL, widget, "trough",
		     0, 0,
		     widget->allocation.width,
		     widget->allocation.height);
      
390
391
392
393
394
      if (progress->activity_mode)
	{
	  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
	      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
	    {
395
	      size = MAX (2, widget->allocation.width / pbar->activity_blocks);
396
	      
397
398
399
400
401
402
403
404
	      gtk_paint_box (widget->style,
			     progress->offscreen_pixmap,
			     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
			     NULL, widget, "bar",
			     pbar->activity_pos,
			     widget->style->klass->ythickness,
			     size,
			     widget->allocation.height - widget->style->klass->ythickness * 2);
405
406
407
408
	      return;
	    }
	  else
	    {
409
	      size = MAX (2, widget->allocation.height / pbar->activity_blocks);
410
	      
411
412
413
414
415
416
417
418
	      gtk_paint_box (widget->style,
			     progress->offscreen_pixmap,
			     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
			     NULL, widget, "bar",
			     widget->style->klass->xthickness,
			     pbar->activity_pos,
			     widget->allocation.width - widget->style->klass->xthickness * 2,
			     size);
419
420
421
	      return;
	    }
	}
422
      
423
424
425
426
427
428
429
430
431
432
433
      amount = percentage * space;
      
      if (amount > 0)
	{
	  switch (pbar->orientation)
	    {
	      
	    case GTK_PROGRESS_LEFT_TO_RIGHT:
	      
	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
		{
434
435
436
437
438
439
440
441
		  gtk_paint_box (widget->style,
				 progress->offscreen_pixmap,
				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				 NULL, widget, "bar",
				 widget->style->klass->xthickness,
				 widget->style->klass->ythickness,
				 amount,
				 widget->allocation.height - widget->style->klass->ythickness * 2);
442
443
444
445
446
447
448
449
450
451
		}
	      else
		{
		  x = widget->style->klass->xthickness;
		  
		  for (i = 0; i <= pbar->in_block; i++)
		    {
		      block_delta = (((i + 1) * space) / pbar->blocks)
			- ((i * space) / pbar->blocks);
		      
452
453
454
455
456
457
458
459
460
		      gtk_paint_box (widget->style,
				     progress->offscreen_pixmap,
				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				     NULL, widget, "bar",
				     x,
				     widget->style->klass->ythickness,
				     block_delta,
				     widget->allocation.height - widget->style->klass->ythickness * 2);
		      
461
462
463
464
		      x +=  block_delta;
		    }
		}
	      break;
465
	      
466
	    case GTK_PROGRESS_RIGHT_TO_LEFT:
467
	      
468
469
	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
		{
470
471
472
473
474
475
476
477
478
479
		  gtk_paint_box (widget->style,
				 progress->offscreen_pixmap,
				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				 NULL, widget, "bar",
				 widget->allocation.width - 
				 widget->style->klass->xthickness - amount,
				 widget->style->klass->ythickness,
				 amount,
				 widget->allocation.height -
				 widget->style->klass->ythickness * 2);
480
481
482
483
484
		}
	      else
		{
		  x = widget->allocation.width - 
		    widget->style->klass->xthickness;
485
		  
486
487
488
489
		  for (i = 0; i <= pbar->in_block; i++)
		    {
		      block_delta = (((i + 1) * space) / pbar->blocks) -
			((i * space) / pbar->blocks);
490
		      
491
		      x -=  block_delta;
492
493
494
495
496
497
498
499
500
501
		      
		      gtk_paint_box (widget->style,
				     progress->offscreen_pixmap,
				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				     NULL, widget, "bar",
				     x,
				     widget->style->klass->ythickness,
				     block_delta,
				     widget->allocation.height -
				     widget->style->klass->ythickness * 2);
502
503
504
505
506
507
508
509
		    }
		}
	      break;

	    case GTK_PROGRESS_BOTTOM_TO_TOP:

	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
		{
510
511
512
513
514
515
516
517
518
519
		  gtk_paint_box (widget->style,
				 progress->offscreen_pixmap,
				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				 NULL, widget, "bar",
				 widget->style->klass->xthickness,
				 widget->allocation.height - 
				 widget->style->klass->ythickness - amount,
				 widget->allocation.width -
				 widget->style->klass->xthickness * 2,
				 amount);
520
521
522
523
524
		}
	      else
		{
		  y = widget->allocation.height - 
		    widget->style->klass->ythickness;
525
		  
526
527
528
529
530
531
		  for (i = 0; i <= pbar->in_block; i++)
		    {
		      block_delta = (((i + 1) * space) / pbar->blocks) -
			((i * space) / pbar->blocks);
		      
		      y -= block_delta;
532
533
534
535
536
537
538
539
540
541
		      
		      gtk_paint_box (widget->style,
				     progress->offscreen_pixmap,
				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				     NULL, widget, "bar",
				     widget->style->klass->xthickness,
				     y,
				     widget->allocation.width - 
				     widget->style->klass->xthickness * 2,
				     block_delta);
542
543
544
		    }
		}
	      break;
545
	      
546
	    case GTK_PROGRESS_TOP_TO_BOTTOM:
547
	      
548
549
	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
		{
550
551
552
553
554
555
556
557
558
		  gtk_paint_box (widget->style,
				 progress->offscreen_pixmap,
				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				 NULL, widget, "bar",
				 widget->style->klass->xthickness,
				 widget->style->klass->ythickness,
				 widget->allocation.width -
				 widget->style->klass->xthickness * 2,
				 amount);
559
560
561
562
		}
	      else
		{
		  y = widget->style->klass->ythickness;
563
		  
564
565
		  for (i = 0; i <= pbar->in_block; i++)
		    {
566
		      
567
568
		      block_delta = (((i + 1) * space) / pbar->blocks)
			- ((i * space) / pbar->blocks);
569
570
571
572
573
574
575
576
577
578
579
		      
		      gtk_paint_box (widget->style,
				     progress->offscreen_pixmap,
				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
				     NULL, widget, "bar",
				     widget->style->klass->xthickness,
				     y,
				     widget->allocation.width -
				     widget->style->klass->xthickness * 2,
				     block_delta);
		      
580
581
582
583
		      y += block_delta;
		    }
		}
	      break;
584
	      
585
586
587
588
	    default:
	      break;
	    }
	}
589
      
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
      if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)
	{
	  gint x;
	  gint y;
	  gchar *buf;
	  GdkRectangle rect;

	  buf = gtk_progress_get_current_text (progress);

	  x = widget->style->klass->xthickness + 1 + 
	    (widget->allocation.width - 2 * widget->style->klass->xthickness -
	     3 - gdk_text_width (widget->style->font, buf, strlen (buf)))
	    * progress->x_align; 

	  y = widget->style->font->ascent + 1 +
	    (widget->allocation.height - 2 * widget->style->klass->ythickness -
	     3 - gdk_text_height (widget->style->font, buf, strlen (buf)))
	    * progress->y_align;

	  rect.x = widget->style->klass->xthickness + 1;
	  rect.y = widget->style->klass->ythickness + 1;
	  rect.width = widget->allocation.width -
	    2 * widget->style->klass->xthickness - 3;
	  rect.height = widget->allocation.height -
	    2 * widget->style->klass->ythickness - 3;

	  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
				     &rect);

	  gdk_draw_text (progress->offscreen_pixmap, widget->style->font,
			 widget->style->fg_gc[widget->state],
			 x, y, buf, strlen (buf));

	  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
				     NULL);
	  g_free (buf);
 	}
Elliot Lee's avatar
Elliot Lee committed
627
628
629
    }
}

630
631
632
633
634
/*******************************************************************/

void
gtk_progress_bar_update (GtkProgressBar *pbar,
			 gfloat          percentage)
Elliot Lee's avatar
Elliot Lee committed
635
{
636
637
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
Elliot Lee's avatar
Elliot Lee committed
638

639
640
641
642
  /***********************************************************************
   *                 Use of this function is deprecated !	         * 
   * Use gtk_progress_set_value or gtk_progress_set_percentage instead.  *
   ***********************************************************************/
Elliot Lee's avatar
Elliot Lee committed
643

644
645
646
647
648
649
650
651
652
653
654
  gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);
}

void
gtk_progress_bar_set_orientation (GtkProgressBar           *pbar,
				  GtkProgressBarOrientation orientation)
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));

  if (pbar->orientation != orientation)
Elliot Lee's avatar
Elliot Lee committed
655
    {
656
      pbar->orientation = orientation;
Elliot Lee's avatar
Elliot Lee committed
657

658
659
      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
	gtk_widget_queue_resize (GTK_WIDGET (pbar));
Elliot Lee's avatar
Elliot Lee committed
660
661
662
    }
}

663
664
665
void
gtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,
				GtkProgressBarStyle bar_style)
Elliot Lee's avatar
Elliot Lee committed
666
667
668
669
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));

670
  if (pbar->bar_style != bar_style)
Elliot Lee's avatar
Elliot Lee committed
671
    {
672
      pbar->bar_style = bar_style;
Elliot Lee's avatar
Elliot Lee committed
673

674
675
      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
	gtk_widget_queue_resize (GTK_WIDGET (pbar));
Elliot Lee's avatar
Elliot Lee committed
676
677
678
    }
}

679
void
680
681
gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,
				      guint           blocks)
Elliot Lee's avatar
Elliot Lee committed
682
683
684
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
685
  g_return_if_fail (blocks > 1);
Elliot Lee's avatar
Elliot Lee committed
686

687
  if (pbar->blocks != blocks)
Elliot Lee's avatar
Elliot Lee committed
688
    {
689
      pbar->blocks = blocks;
Elliot Lee's avatar
Elliot Lee committed
690

691
692
693
694
      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))
	gtk_widget_queue_resize (GTK_WIDGET (pbar));
    }
}
Elliot Lee's avatar
Elliot Lee committed
695

696
697
698
699
700
701
void
gtk_progress_bar_set_activity_step (GtkProgressBar *pbar,
                                    guint           step)
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
Elliot Lee's avatar
Elliot Lee committed
702

703
704
  if (pbar->activity_step != step)
    pbar->activity_step = step;
Elliot Lee's avatar
Elliot Lee committed
705
}
706
707
708
709
710
711
712
713
714
715
716
717

void
gtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,
				      guint           blocks)
{
  g_return_if_fail (pbar != NULL);
  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
  g_return_if_fail (blocks > 1);

  if (pbar->activity_blocks != blocks)
    pbar->activity_blocks = blocks;
}