summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-image.c
blob: 173b1d340cd3b69d06135483e84ef9f1f03cc585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
187
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-image.c - A widget to smoothly display images.

   Copyright (C) 1999, 2000 Eazel, Inc.

   The Gnome 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.

   The Gnome 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
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: Ramiro Estrugo <ramiro@eazel.com>
*/

#include <config.h>

#include "nautilus-image.h"

#include "nautilus-gtk-macros.h"
#include "nautilus-gdk-extensions.h"
#include "nautilus-gtk-extensions.h"
#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-art-gtk-extensions.h"
#include "nautilus-string.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-debug-drawing.h"

/* Arguments */
enum
{
	ARG_0,
	ARG_BACKGROUND_MODE,
	ARG_IS_SMOOTH,
	ARG_PIXBUF,
	ARG_PIXBUF_OPACITY,
	ARG_TILE_HEIGHT,
	ARG_TILE_MODE_HORIZONTAL,
	ARG_TILE_MODE_VERTICAL,
	ARG_TILE_OPACITY,
	ARG_TILE_PIXBUF,
	ARG_TILE_WIDTH
};

/* Signals */
typedef enum
{
	DRAW_BACKGROUND,
	SET_IS_SMOOTH,
	LAST_SIGNAL
} ImageSignal;

/* Signals */
static guint image_signals[LAST_SIGNAL] = { 0 };

/* Detail member struct */
struct _NautilusImageDetails
{
	gboolean is_smooth;

	/* Tile attributes */
	GdkPixbuf *tile_pixbuf;
	int tile_opacity;
	int tile_width;
	int tile_height;
	NautilusSmoothTileMode tile_mode_vertical;
	NautilusSmoothTileMode tile_mode_horizontal;

	/* Pixbuf */
	GdkPixbuf *pixbuf;
	int pixbuf_opacity;

	/* Background */
	NautilusSmoothBackgroundMode background_mode;
	guint32 solid_background_color;
	gboolean never_smooth;
};

/* GtkObjectClass methods */
static void     nautilus_image_initialize_class     (NautilusImageClass  *image_class);
static void     nautilus_image_initialize           (NautilusImage       *image);
static void     nautilus_image_destroy              (GtkObject           *object);
static void     nautilus_image_set_arg              (GtkObject           *object,
						     GtkArg              *arg,
						     guint                arg_id);
static void     nautilus_image_get_arg              (GtkObject           *object,
						     GtkArg              *arg,
						     guint                arg_id);
/* GtkWidgetClass methods */
static void     nautilus_image_size_request         (GtkWidget           *widget,
						     GtkRequisition      *requisition);
static int      nautilus_image_expose_event         (GtkWidget           *widget,
						     GdkEventExpose      *event);

/* NautilusImage signals */
static void     nautilus_image_set_is_smooth_signal (GtkWidget           *widget,
						     gboolean             is_smooth);

/* Private NautilusImage methods */
static ArtIRect image_get_pixbuf_frame              (const NautilusImage *image);
static ArtIRect image_get_pixbuf_bounds             (const NautilusImage *image);
static ArtIRect image_get_tile_frame                (const NautilusImage *image);
static gboolean image_is_smooth                     (const NautilusImage *image);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, GTK_TYPE_MISC)

/* Class init methods */
static void
nautilus_image_initialize_class (NautilusImageClass *image_class)
{
	GtkObjectClass *object_class = GTK_OBJECT_CLASS (image_class);
	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_class);

	/* GtkObjectClass */
	object_class->destroy = nautilus_image_destroy;
	object_class->set_arg = nautilus_image_set_arg;
	object_class->get_arg = nautilus_image_get_arg;
	
	/* GtkWidgetClass */
	widget_class->size_request = nautilus_image_size_request;
	widget_class->expose_event = nautilus_image_expose_event;

	/* NautilusImageClass */
	image_class->set_is_smooth = nautilus_image_set_is_smooth_signal;
	
	/* Signals */
	image_signals[DRAW_BACKGROUND] = gtk_signal_new ("draw_background",
							 GTK_RUN_LAST,
							 object_class->type,
							 0,
							 gtk_marshal_NONE__POINTER_POINTER,
							 GTK_TYPE_NONE, 
							 2,
							 GTK_TYPE_POINTER,
							 GTK_TYPE_POINTER);

	image_signals[SET_IS_SMOOTH] = gtk_signal_new ("set_is_smooth",
						       GTK_RUN_LAST,
						       object_class->type,
						       GTK_SIGNAL_OFFSET (NautilusImageClass, set_is_smooth),
						       gtk_marshal_NONE__BOOL,
						       GTK_TYPE_NONE, 
						       1,
						       GTK_TYPE_BOOL);
	
	gtk_object_class_add_signals (object_class, image_signals, LAST_SIGNAL);

	/* Arguments */
	gtk_object_add_arg_type ("NautilusImage::is_smooth",
				 GTK_TYPE_BOOL,
				 GTK_ARG_READWRITE,
				 ARG_IS_SMOOTH);
	gtk_object_add_arg_type ("NautilusImage::pixbuf",
				 GTK_TYPE_POINTER,
				 GTK_ARG_READWRITE,
				 ARG_PIXBUF);
	gtk_object_add_arg_type ("NautilusImage::pixbuf_opacity",
				 GTK_TYPE_INT,
				 GTK_ARG_READWRITE,
				 ARG_PIXBUF_OPACITY);
	gtk_object_add_arg_type ("NautilusImage::background_mode",
				 GTK_TYPE_UINT,
				 GTK_ARG_READWRITE,
				 ARG_BACKGROUND_MODE);
	gtk_object_add_arg_type ("NautilusImage::tile_pixbuf",
				 GTK_TYPE_POINTER,
				 GTK_ARG_READWRITE,
				 ARG_TILE_PIXBUF);
	gtk_object_add_arg_type ("NautilusImage::tile_opacity",
				 GTK_TYPE_INT,
				 GTK_ARG_READWRITE,
				 ARG_TILE_OPACITY);
	gtk_object_add_arg_type ("NautilusImage::tile_width",
				 GTK_TYPE_INT,
				 GTK_ARG_READWRITE,
				 ARG_TILE_WIDTH);
	gtk_object_add_arg_type ("NautilusImage::tile_height",
				 GTK_TYPE_INT,
				 GTK_ARG_READWRITE,
				 ARG_TILE_HEIGHT);
	gtk_object_add_arg_type ("NautilusImage::tile_mode_vertical",
				 GTK_TYPE_UINT,
				 GTK_ARG_READWRITE,
				 ARG_TILE_MODE_VERTICAL);
	gtk_object_add_arg_type ("NautilusImage::tile_mode_horizontal",
				 GTK_TYPE_UINT,
				 GTK_ARG_READWRITE,
				 ARG_TILE_MODE_HORIZONTAL);

	/* Make this class inherit the same kind of theme stuff as GtkPixmap */
	nautilus_gtk_class_name_make_like_existing_type ("NautilusImage", GTK_TYPE_PIXMAP);

	/* Let the smooth widget machinery know that our class can be smooth */
	nautilus_smooth_widget_register_type (NAUTILUS_TYPE_IMAGE);
}

void
nautilus_image_initialize (NautilusImage *image)
{
	GTK_WIDGET_UNSET_FLAGS (image, GTK_CAN_FOCUS);
	GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);

	image->details = g_new0 (NautilusImageDetails, 1);

	image->details->pixbuf_opacity = NAUTILUS_OPACITY_FULLY_OPAQUE;
	image->details->tile_opacity = NAUTILUS_OPACITY_FULLY_OPAQUE;
 	image->details->tile_width = NAUTILUS_SMOOTH_TILE_EXTENT_FULL;
 	image->details->tile_height = NAUTILUS_SMOOTH_TILE_EXTENT_FULL;
	image->details->tile_mode_vertical = NAUTILUS_SMOOTH_TILE_SELF;
	image->details->tile_mode_horizontal = NAUTILUS_SMOOTH_TILE_SELF;
	image->details->background_mode = NAUTILUS_SMOOTH_BACKGROUND_GTK;

	nautilus_smooth_widget_register (GTK_WIDGET (image));
}

/* GtkObjectClass methods */
static void
nautilus_image_destroy (GtkObject *object)
{
 	NautilusImage *image;
	
	g_return_if_fail (NAUTILUS_IS_IMAGE (object));

	image = NAUTILUS_IMAGE (object);

	nautilus_gdk_pixbuf_unref_if_not_null (image->details->tile_pixbuf);
	image->details->tile_pixbuf = NULL;

	g_free (image->details);

	/* Chain destroy */
	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}

static void
nautilus_image_set_arg (GtkObject *object,
			GtkArg *arg,
			guint arg_id)
{
	NautilusImage *image;
	
	g_return_if_fail (NAUTILUS_IS_IMAGE (object));

 	image = NAUTILUS_IMAGE (object);

 	switch (arg_id)
	{
	case ARG_IS_SMOOTH:
		nautilus_image_set_is_smooth (image, GTK_VALUE_BOOL (*arg));
		break;

	case ARG_PIXBUF_OPACITY:
		nautilus_image_set_pixbuf_opacity (image, GTK_VALUE_INT (*arg));
		break;

	case ARG_BACKGROUND_MODE:
		nautilus_image_set_background_mode (image, GTK_VALUE_UINT (*arg));
		break;

	case ARG_PIXBUF:
		nautilus_image_set_pixbuf (image, (GdkPixbuf *) GTK_VALUE_POINTER (*arg));
		break;

	case ARG_TILE_OPACITY:
		nautilus_image_set_tile_opacity (image, GTK_VALUE_INT (*arg));
		break;

	case ARG_TILE_PIXBUF:
		nautilus_image_set_tile_pixbuf (image, (GdkPixbuf *) GTK_VALUE_POINTER (*arg));
		break;
		
	case ARG_TILE_WIDTH:
		nautilus_image_set_tile_width (image, GTK_VALUE_INT (*arg));
		break;

	case ARG_TILE_HEIGHT:
		nautilus_image_set_tile_height (image, GTK_VALUE_INT (*arg));
		break;

	case ARG_TILE_MODE_VERTICAL:
		nautilus_image_set_tile_mode_vertical (image, GTK_VALUE_UINT (*arg));
		break;

	case ARG_TILE_MODE_HORIZONTAL:
		nautilus_image_set_tile_mode_horizontal (image, GTK_VALUE_UINT (*arg));
		break;

 	default:
		g_assert_not_reached ();
	}
}

static void
nautilus_image_get_arg (GtkObject *object,
			GtkArg *arg,
			guint arg_id)
{
	NautilusImage *image;

	g_return_if_fail (NAUTILUS_IS_IMAGE (object));
	
	image = NAUTILUS_IMAGE (object);

 	switch (arg_id)
	{
	case ARG_IS_SMOOTH:
		GTK_VALUE_BOOL (*arg) = nautilus_image_get_is_smooth (image);
		break;
		
	case ARG_PIXBUF_OPACITY:
		GTK_VALUE_INT (*arg) = nautilus_image_get_pixbuf_opacity (image);
		break;
		
	case ARG_BACKGROUND_MODE:
		GTK_VALUE_UINT (*arg) = nautilus_image_get_background_mode (image);
		break;
		
	case ARG_PIXBUF:
		GTK_VALUE_POINTER (*arg) = nautilus_image_get_pixbuf (image);
		break;

	case ARG_TILE_OPACITY:
		GTK_VALUE_INT (*arg) = nautilus_image_get_tile_opacity (image);
		break;
		
	case ARG_TILE_PIXBUF:
		GTK_VALUE_POINTER (*arg) = nautilus_image_get_tile_pixbuf (image);
		break;

	case ARG_TILE_WIDTH:
		GTK_VALUE_INT (*arg) = nautilus_image_get_tile_width (image);
		break;

	case ARG_TILE_HEIGHT:
		GTK_VALUE_INT (*arg) = nautilus_image_get_tile_height (image);
		break;

	case ARG_TILE_MODE_VERTICAL:
		GTK_VALUE_UINT (*arg) = nautilus_image_get_tile_mode_vertical (image);
		break;

	case ARG_TILE_MODE_HORIZONTAL:
		GTK_VALUE_UINT (*arg) = nautilus_image_get_tile_mode_horizontal (image);
		break;

 	default:
		g_assert_not_reached ();
	}
}

/* GtkWidgetClass methods */
static void
nautilus_image_size_request (GtkWidget *widget,
			     GtkRequisition *requisition)
{
	NautilusImage *image;

	ArtIRect pixbuf_frame;
	ArtIRect tile_frame;
	ArtIRect preferred_frame;

	g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
	g_return_if_fail (requisition != NULL);

 	image = NAUTILUS_IMAGE (widget);
	
	pixbuf_frame = image_get_pixbuf_frame (image);
	tile_frame = image_get_tile_frame (image);
	preferred_frame = nautilus_smooth_widget_get_preferred_frame (widget,
								      &pixbuf_frame,
								      &tile_frame,
								      image->details->tile_width,
								      image->details->tile_height);
   	requisition->width = preferred_frame.x1;
   	requisition->height = preferred_frame.y1;
}

static void
image_paint_pixbuf_callback (GtkWidget *widget,
			     GdkDrawable *destination_drawable,
			     GdkGC *gc,
			     int source_x,
			     int source_y,
			     const ArtIRect *area,
			     gpointer callback_data)
{
	NautilusImage *image;

	g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
	g_return_if_fail (GTK_WIDGET_REALIZED (widget));
	g_return_if_fail (destination_drawable != NULL);
	g_return_if_fail (gc != NULL);
	g_return_if_fail (area != NULL && !art_irect_empty (area));

	image = NAUTILUS_IMAGE (widget);

	g_return_if_fail (nautilus_gdk_pixbuf_is_valid (image->details->pixbuf));
	
	nautilus_gdk_pixbuf_draw_to_drawable (image->details->pixbuf,
					      destination_drawable,
					      gc,
					      source_x,
					      source_y,
					      area,
					      GDK_RGB_DITHER_NONE,
					      GDK_PIXBUF_ALPHA_BILEVEL,
					      NAUTILUS_STANDARD_ALPHA_THRESHHOLD);
}

static void
image_composite_pixbuf_callback (GtkWidget *widget,
				 GdkPixbuf *destination_pixbuf,
				 int source_x,
				 int source_y,
				 const ArtIRect *area,
				 int opacity,
				 gpointer callback_data)
{
	NautilusImage *image;

	g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
	g_return_if_fail (GTK_WIDGET_REALIZED (widget));
	g_return_if_fail (destination_pixbuf != NULL);
	g_return_if_fail (area != NULL && !art_irect_empty (area));

	image = NAUTILUS_IMAGE (widget);

	g_return_if_fail (nautilus_gdk_pixbuf_is_valid (image->details->pixbuf));

	nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (image->details->pixbuf,
						  destination_pixbuf,
						  source_x,
						  source_y,
						  area,
						  opacity,
						  GDK_INTERP_BILINEAR);
}	

static int
nautilus_image_expose_event (GtkWidget *widget,
			     GdkEventExpose *event)
{
 	NautilusImage *image;
	ArtIRect dirty_area;
	ArtIRect screen_dirty_area;

	ArtIRect pixbuf_bounds;
	ArtIRect tile_bounds;

	g_return_val_if_fail (NAUTILUS_IS_IMAGE (widget), TRUE);
	g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
	g_return_val_if_fail (event != NULL, TRUE);
	g_return_val_if_fail (event->window == widget->window, TRUE);
	
 	image = NAUTILUS_IMAGE (widget);

	pixbuf_bounds = image_get_pixbuf_bounds (image);
	tile_bounds = nautilus_smooth_widget_get_tile_bounds (widget,
							      image->details->tile_pixbuf,
							      image->details->tile_width,
							      image->details->tile_height);
	
	/* Check for the dumb case when theres nothing to do */
	if (image->details->pixbuf == NULL && image->details->tile_pixbuf == NULL) {
		return TRUE;
	}

	/* Clip the dirty area to the screen */
	dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area);
	screen_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window,
										 &dirty_area);
	/* Nothing to do */
	if (art_irect_empty (&screen_dirty_area)) {
		return TRUE;
	}

	/* Paint ourselves */
	nautilus_smooth_widget_paint (widget,
				      widget->style->white_gc,
				      image_is_smooth (image),
				      image->details->background_mode,
				      image->details->solid_background_color,
				      image->details->tile_pixbuf,
				      &tile_bounds,
				      image->details->tile_opacity,
				      image->details->tile_mode_vertical,
				      image->details->tile_mode_horizontal,
				      &pixbuf_bounds,
				      image->details->pixbuf_opacity,
				      &screen_dirty_area,
				      image_paint_pixbuf_callback,
				      image_composite_pixbuf_callback,
				      NULL);

	return TRUE;
}

/* NautilusImage signals */
static void
nautilus_image_set_is_smooth_signal (GtkWidget *widget,
				     gboolean is_smooth)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (widget));

	nautilus_image_set_is_smooth (NAUTILUS_IMAGE (widget), is_smooth);
}

/* Private NautilusImage methods */
static ArtIRect
image_get_pixbuf_frame (const NautilusImage *image)
{
	ArtIRect pixbuf_frame;

	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY);

	if (!image->details->pixbuf) {
		return NAUTILUS_ART_IRECT_EMPTY;
	}

	pixbuf_frame.x0 = 0;
	pixbuf_frame.y0 = 0;
	pixbuf_frame.x1 = gdk_pixbuf_get_width (image->details->pixbuf);
	pixbuf_frame.y1 = gdk_pixbuf_get_height (image->details->pixbuf);

	return pixbuf_frame;
}

static ArtIRect
image_get_pixbuf_bounds (const NautilusImage *image)
{
	ArtIRect pixbuf_frame;
	ArtIRect pixbuf_bounds;
	ArtIRect bounds;

	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY);

	pixbuf_frame = image_get_pixbuf_frame (image);

	if (art_irect_empty (&pixbuf_frame)) {
		return NAUTILUS_ART_IRECT_EMPTY;
	}
	
	bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (image));
	
	pixbuf_bounds = nautilus_art_irect_align (&bounds,
						  pixbuf_frame.x1,
						  pixbuf_frame.y1,
						  GTK_MISC (image)->xalign,
						  GTK_MISC (image)->yalign);

	return pixbuf_bounds;
}

static ArtIRect
image_get_tile_frame (const NautilusImage *image)
{
	ArtIRect tile_frame;

	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY);

	if (!image->details->tile_pixbuf) {
		return NAUTILUS_ART_IRECT_EMPTY;
	}

	tile_frame.x0 = 0;
	tile_frame.y0 = 0;
	tile_frame.x1 = gdk_pixbuf_get_width (image->details->tile_pixbuf);
	tile_frame.y1 = gdk_pixbuf_get_height (image->details->tile_pixbuf);

	return tile_frame;
}

gboolean
image_is_smooth (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), FALSE);

	return !image->details->never_smooth && image->details->is_smooth;
}

/* Public NautilusImage methods */
GtkWidget*
nautilus_image_new (const char *file_name)
{
	NautilusImage *image;

	image = NAUTILUS_IMAGE (gtk_widget_new (nautilus_image_get_type (), NULL));
	
	if (file_name != NULL) {
		nautilus_image_set_pixbuf_from_file_name (image, file_name);
	}

	return GTK_WIDGET (image);
}

void
nautilus_image_set_is_smooth (NautilusImage *image,
			      gboolean is_smooth)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));

	if (image->details->never_smooth) {
		return;
	}

	if (image->details->is_smooth == is_smooth) {
		return;
	}

	image->details->is_smooth = is_smooth;

	/* We call queue_resize() instead queue_draw() because
	 * we want the widget's background to be cleared of 
	 * the previous pixbuf, even though the geometry of 
	 * the image does not change.
	 */ 
	gtk_widget_queue_resize (GTK_WIDGET (image));
}

gboolean
nautilus_image_get_is_smooth (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), FALSE);

	return image_is_smooth (image);
}

/**
 * nautilus_image_set_tile_pixbuf:
 *
 * @image: A NautilusImage
 * @pixbuf:          The new tile pixbuf
 *
 * Change the tile pixbuf.  A 'pixbuf' value of NULL, means dont use a
 * tile pixbuf - this is the default behavior for the widget.
 */
void
nautilus_image_set_tile_pixbuf (NautilusImage *image,
				GdkPixbuf *pixbuf)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	
	if (pixbuf != image->details->tile_pixbuf) {
		nautilus_gdk_pixbuf_unref_if_not_null (image->details->tile_pixbuf);
		nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
		
		image->details->tile_pixbuf = pixbuf;

		gtk_widget_queue_draw (GTK_WIDGET (image));
	}
}

/**
 * nautilus_image_get_tile_pixbuf:
 *
 * @image: A NautilusImage
 *
 * Return value: A reference to the tile_pixbuf.  Needs to be unreferenced with 
 * gdk_pixbuf_unref()
 */
GdkPixbuf*
nautilus_image_get_tile_pixbuf (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);

	nautilus_gdk_pixbuf_ref_if_not_null (image->details->tile_pixbuf);
	
	return image->details->tile_pixbuf;
}

void
nautilus_image_set_pixbuf (NautilusImage *image,
			   GdkPixbuf *pixbuf)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));

	if (pixbuf != image->details->pixbuf) {
		nautilus_gdk_pixbuf_unref_if_not_null (image->details->pixbuf);
		nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
		image->details->pixbuf = pixbuf;
		gtk_widget_queue_resize (GTK_WIDGET (image));
	}
}

void
nautilus_image_set_pixbuf_from_file_name (NautilusImage *image,
					  const char *file_name)
{
	GdkPixbuf *pixbuf;

	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (file_name != NULL);

	pixbuf = gdk_pixbuf_new_from_file (file_name);			
	
	if (pixbuf != NULL) {
		nautilus_image_set_pixbuf (image, pixbuf);	
		gdk_pixbuf_unref (pixbuf);
	}
}

GdkPixbuf*
nautilus_image_get_pixbuf (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
	
	nautilus_gdk_pixbuf_ref_if_not_null (image->details->pixbuf);
	
	return image->details->pixbuf;
}

void
nautilus_image_set_pixbuf_opacity (NautilusImage *image,
				   int pixbuf_opacity)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (pixbuf_opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT);
	g_return_if_fail (pixbuf_opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE);

	if (image->details->pixbuf_opacity == pixbuf_opacity) {
		return;
	}

	image->details->pixbuf_opacity = pixbuf_opacity;

	gtk_widget_queue_draw (GTK_WIDGET (image));
}

int
nautilus_image_get_pixbuf_opacity (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_OPACITY_FULLY_OPAQUE);

	return image->details->pixbuf_opacity;
}

void
nautilus_image_set_tile_opacity (NautilusImage *image,
				 int tile_opacity)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT);
	g_return_if_fail (tile_opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE);

	if (image->details->tile_opacity == tile_opacity) {
		return;
	}

	image->details->tile_opacity = tile_opacity;

	gtk_widget_queue_draw (GTK_WIDGET (image));
}

int
nautilus_image_get_tile_opacity (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_OPACITY_FULLY_OPAQUE);

	return image->details->tile_opacity;
}

void
nautilus_image_set_tile_width (NautilusImage *image,
			       int tile_width)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_width >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP);
	
	if (image->details->tile_width == tile_width) {
		return;
	}

	image->details->tile_width = tile_width;

	gtk_widget_queue_resize (GTK_WIDGET (image));
}

/**
 * nautilus_image_get_tile_width:
 *
 * @image: A NautilusImage
 *
 * Return value: The tile width.
 */
int
nautilus_image_get_tile_width (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);

	return image->details->tile_width;
}

void
nautilus_image_set_tile_height (NautilusImage *image,
				int tile_height)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_height >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP);
	
	if (image->details->tile_height == tile_height) {
		return;
	}

	image->details->tile_height = tile_height;

	gtk_widget_queue_resize (GTK_WIDGET (image));
}

/**
 * nautilus_image_get_tile_height:
 *
 * @image: A NautilusImage
 *
 * Return value: The tile height.
 */
int
nautilus_image_get_tile_height (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);

	return image->details->tile_height;
}

void
nautilus_image_set_tile_mode_vertical (NautilusImage *image,
				       NautilusSmoothTileMode tile_mode_vertical)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_mode_vertical >= NAUTILUS_SMOOTH_TILE_SELF);
	g_return_if_fail (tile_mode_vertical <= NAUTILUS_SMOOTH_TILE_ANCESTOR);

	if (image->details->tile_mode_vertical == tile_mode_vertical) {
		return;
	}

	image->details->tile_mode_vertical = tile_mode_vertical;

	gtk_widget_queue_draw (GTK_WIDGET (image));
}

NautilusSmoothTileMode
nautilus_image_get_tile_mode_vertical (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
	
	return image->details->tile_mode_vertical;
}

void
nautilus_image_set_tile_mode_horizontal (NautilusImage *image,
					 NautilusSmoothTileMode tile_mode_horizontal)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_mode_horizontal >= NAUTILUS_SMOOTH_TILE_SELF);
	g_return_if_fail (tile_mode_horizontal <= NAUTILUS_SMOOTH_TILE_ANCESTOR);

	if (image->details->tile_mode_horizontal == tile_mode_horizontal) {
		return;
	}

	image->details->tile_mode_horizontal = tile_mode_horizontal;

	gtk_widget_queue_draw (GTK_WIDGET (image));
}

NautilusSmoothTileMode
nautilus_image_get_tile_mode_horizontal (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
	
	return image->details->tile_mode_horizontal;
}

void
nautilus_image_set_tile_pixbuf_from_file_name (NautilusImage *image,
					       const char *tile_file_name)
{
	GdkPixbuf *tile_pixbuf;

	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (tile_file_name != NULL);

	tile_pixbuf = gdk_pixbuf_new_from_file (tile_file_name);
	
	if (tile_pixbuf != NULL) {
		nautilus_image_set_tile_pixbuf (image, tile_pixbuf);
		gdk_pixbuf_unref (tile_pixbuf);
	}
}

void
nautilus_image_set_background_mode (NautilusImage *image,
				    NautilusSmoothBackgroundMode background_mode)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	g_return_if_fail (background_mode >= NAUTILUS_SMOOTH_BACKGROUND_GTK);
	g_return_if_fail (background_mode <= NAUTILUS_SMOOTH_BACKGROUND_SOLID_COLOR);

	if (image->details->background_mode == background_mode) {
		return;
	}

	image->details->background_mode = background_mode;

	gtk_widget_queue_draw (GTK_WIDGET (image));
}

NautilusSmoothBackgroundMode
nautilus_image_get_background_mode (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
	
	return image->details->background_mode;
}

void
nautilus_image_set_solid_background_color (NautilusImage *image,
					   guint32 solid_background_color)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));
	
	if (image->details->solid_background_color == solid_background_color) {
		return;
	}

	image->details->solid_background_color = solid_background_color;
	
	gtk_widget_queue_draw (GTK_WIDGET (image));
}

guint32
nautilus_image_get_solid_background_color (const NautilusImage *image)
{
	g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
	
	return image->details->solid_background_color;
}

/**
 * nautilus_image_new_solid:
 *
 * @pixbuf: A GdkPixbuf or NULL.
 * @x_alignment: Horizontal alignment.
 * @y_alignment: Vertical alignment.
 * @x_padding: Horizontal padding.
 * @y_padding: Vertical padding.
 * @background_color: Background color.
 * @tile_pixbuf: A GdkPixbuf or NULL.
 *
 * Create an image with a solid background.
 *
 * Return value: The newly allocated NautilusImage with the
 * given attributes.
 */
GtkWidget *
nautilus_image_new_solid (GdkPixbuf *pixbuf,
			  float x_alignment,
			  float y_alignment,
			  int x_padding,
			  int y_padding,
			  guint32 background_color,
			  GdkPixbuf *tile_pixbuf)
{
	NautilusImage *image;

 	image = NAUTILUS_IMAGE (nautilus_image_new (NULL));
	
	if (pixbuf != NULL) {
		nautilus_image_set_pixbuf (image, pixbuf);
	}

	nautilus_image_set_background_mode (image, NAUTILUS_SMOOTH_BACKGROUND_SOLID_COLOR);
	nautilus_image_set_solid_background_color (image, background_color);

	gtk_misc_set_padding (GTK_MISC (image), x_padding, y_padding);
	gtk_misc_set_alignment (GTK_MISC (image), x_alignment, y_alignment);
	
	if (tile_pixbuf != NULL) {
		nautilus_image_set_tile_pixbuf (image, tile_pixbuf);
	}
	
	return GTK_WIDGET (image);
}


/**
 * nautilus_image_set_never_smooth
 *
 * @image: A NautilusImage.
 * @never_smooth: A boolean value indicating whether the image can NEVER be smooth.
 *
 * Force an image to never be smooth.  Calls to nautilus_image_set_is_smooth () will
 * thus be ignored.  This is useful if you want to use a NautilusImage in a situation.
 */
void
nautilus_image_set_never_smooth (NautilusImage *image,
				 gboolean never_smooth)
{
	g_return_if_fail (NAUTILUS_IS_IMAGE (image));

	image->details->never_smooth = never_smooth;
	gtk_widget_queue_resize (GTK_WIDGET (image));
}