private void HandlePixbufLoaded(FSpot.PixbufCache Cache, FSpot.PixbufCache.CacheEntry entry)
        {
            Gdk.Pixbuf result = entry.ShallowCopyPixbuf();
            int        order  = (int)entry.Data;

            if (result == null)
            {
                return;
            }

            // We have to do the scaling here rather than on load because we need to preserve the
            // Pixbuf option iformation to verify the thumbnail validity later
            int width, height;

            PixbufUtils.Fit(result, ThumbnailWidth, ThumbnailHeight, false, out width, out height);
            if (result.Width > width && result.Height > height)
            {
                //  Log.Debug ("scaling");
                Gdk.Pixbuf temp = PixbufUtils.ScaleDown(result, width, height);
                result.Dispose();
                result = temp;
            }
            else if (result.Width < ThumbnailWidth && result.Height < ThumbnailHeight)
            {
                // FIXME this is a workaround to handle images whose actual size is smaller than
                // the thumbnail size, it needs to be fixed at a different level.
                Gdk.Pixbuf temp = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, ThumbnailWidth, ThumbnailHeight);
                temp.Fill(0x00000000);
                result.CopyArea(0, 0,
                                result.Width, result.Height,
                                temp,
                                (temp.Width - result.Width) / 2,
                                temp.Height - result.Height);

                result.Dispose();
                result = temp;
            }

            Cache.Update(entry, result);
            InvalidateCell(order);
        }
        public CollectionGridView(IBrowsableCollection collection) : base()
        {
            Collection = collection;

            Collection.Changed += (obj) => {
                QueueResize();
            };

            Collection.ItemsChanged += (obj, args) => {
                foreach (int item in args.Items)
                {
                    if (args.Changes.DataChanged)
                    {
                        UpdateThumbnail(item);
                    }
                    InvalidateCell(item);
                }
            };

            Name = "ImageContainer";

            Cache = new FSpot.PixbufCache();
            Cache.OnPixbufLoaded += HandlePixbufLoaded;
        }
        public CollectionGridView(IBrowsableCollection collection)
            : base()
        {
            Collection = collection;

            Collection.Changed += (obj) => {
                QueueResize ();
            };

            Collection.ItemsChanged += (obj, args) => {
                foreach (int item in args.Items) {
                    if (args.Changes.DataChanged)
                        UpdateThumbnail (item);
                    InvalidateCell (item);
                }
            };

            Name = "ImageContainer";

            Cache = new FSpot.PixbufCache ();
            Cache.OnPixbufLoaded += HandlePixbufLoaded;
        }
		protected IconView () : base (null, null)
		{
			cache = new FSpot.PixbufCache ();
			cache.OnPixbufLoaded += HandlePixbufLoaded;

			ScrollAdjustmentsSet += new ScrollAdjustmentsSetHandler (HandleScrollAdjustmentsSet);

			ButtonPressEvent += new ButtonPressEventHandler (HandleButtonPressEvent);
			ButtonReleaseEvent += new ButtonReleaseEventHandler (HandleButtonReleaseEvent);
			KeyPressEvent += new KeyPressEventHandler (HandleKeyPressEvent);
			ScrollEvent += new ScrollEventHandler(HandleScrollEvent);

			Destroyed += HandleDestroyed;

			AddEvents ((int) EventMask.KeyPressMask
			| (int) EventMask.KeyReleaseMask
			| (int) EventMask.PointerMotionMask);

			CanFocus = true;

			//FSpot.Global.ModifyColors (this);
		}