Esempio n. 1
0
 /// <summary>
 /// Gets the image from the thumbnail cache. If the image is not cached,
 /// null will be returned.
 /// </summary>
 /// <param name="guid">The guid representing this item.</param>
 /// <param name="adaptor">The adaptor of this item.</param>
 /// <param name="key">The key of this item.</param>
 /// <param name="thumbSize">Requested thumbnail size.</param>
 /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
 /// <param name="autoRotate">AutoRotate property of the owner control.</param>
 /// <param name="useWIC">Whether to use WIC.</param>
 /// <param name="clone">true to return a clone of the cached image; otherwise false.</param>
 public Image GetImage(Guid guid, ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC, bool clone)
 {
     if (thumbCache.TryGetValue(guid, out CacheItem item) &&
         item != null &&
         item.Image != null &&
         item.Size == thumbSize &&
         item.UseEmbeddedThumbnails == useEmbeddedThumbnails &&
         item.AutoRotate == autoRotate &&
         item.UseWIC == useWIC)
     {
         return(clone ? (Image)item.Image.Clone() : item.Image);
     }
     else
     {
         string diskCacheKey = adaptor.GetUniqueIdentifier(key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC);
         // Check the disk cache
         using (Stream stream = DiskCache.Read(diskCacheKey))
         {
             if (stream.Length > 0)
             {
                 return(new Bitmap(stream));
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
        /// <summary>
        /// Adds a virtual item to the cache.
        /// </summary>
        /// <param name="guid">The guid representing this item.</param>
        /// <param name="adaptor">The adaptor for this item.</param>
        /// <param name="key">The key of this item.</param>
        /// <param name="thumbSize">Requested thumbnail size.</param>
        /// <param name="thumb">Thumbnail image to add to cache.</param>
        /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        /// <param name="autoRotate">AutoRotate property of the owner control.</param>
        /// <param name="useWIC">Whether to use WIC.</param>
        public void Add(Guid guid, ImageListViewItemAdaptor adaptor, object key, Size thumbSize, Image thumb, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC)
        {
            // Already cached?
            if (thumbCache.TryGetValue(guid, out CacheItem item))
            {
                if (item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails)
                {
                    return;
                }
            }

            // Resize
            thumb = ThumbnailExtractor.FromImage(thumb, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC);

            // Add to cache
            thumbCache.Add(guid, new CacheItem(guid, thumbSize, thumb, CacheState.Cached, useEmbeddedThumbnails, autoRotate, useWIC));

            // Add to disk cache
            using (MemoryStream stream = new MemoryStream())
            {
                string diskCacheKey = adaptor.GetUniqueIdentifier(key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC);
                thumb.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                DiskCache.Write(diskCacheKey, stream);
            }

            // Raise the cache events
            if (mImageListView != null)
            {
                mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize, true);
                mImageListView.Refresh();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheRequest"/> class.
 /// </summary>
 /// <param name="guid">The guid of the item.</param>
 /// <param name="adaptor">The adaptor of this item.</param>
 /// <param name="virtualItemKey">The virtual item key of this item.</param>
 /// <param name="useWIC">Whether to use the Windows Imaging Component.</param>
 public CacheRequest(Guid guid, ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC)
 {
     Guid           = guid;
     Adaptor        = adaptor;
     VirtualItemKey = virtualItemKey;
     UseWIC         = useWIC;
 }
Esempio n. 4
0
        /// <summary>
        /// Adds a virtual item to the <see cref="ImageListViewItemCollection"/>.
        /// </summary>
        /// <param name="key">The key identifying the item.</param>
        /// <param name="text">Text of the item.</param>
        /// <param name="initialThumbnail">The initial thumbnail image for the item.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        public void Add(object key, string text, Image initialThumbnail, ImageListViewItemAdaptor adaptor)
        {
            ImageListViewItem item = new ImageListViewItem(key, text)
            {
                clonedThumbnail = initialThumbnail
            };

            Add(item, adaptor);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheRequest"/> class
 /// for use with a virtual item.
 /// </summary>
 /// <param name="guid">The guid of the ImageListViewItem.</param>
 /// <param name="adaptor">The adaptor of this item.</param>
 /// <param name="key">The public key for the virtual item.</param>
 /// <param name="size">The size of the requested thumbnail.</param>
 /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
 /// <param name="autoRotate">AutoRotate property of the owner control.</param>
 /// <param name="useWIC">Whether to use WIC.</param>
 /// <param name="requestType">Type of this request.</param>
 public CacheRequest(Guid guid, ImageListViewItemAdaptor adaptor, object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC, RequestType requestType)
 {
     Guid                  = guid;
     VirtualItemKey        = key;
     Adaptor               = adaptor;
     Size                  = size;
     UseEmbeddedThumbnails = useEmbeddedThumbnails;
     AutoRotate            = autoRotate;
     UseWIC                = useWIC;
     RequestType           = requestType;
 }
Esempio n. 6
0
        /// <summary>
        /// Adds a range of items to the <see cref="ImageListViewItemCollection"/>.
        /// </summary>
        /// <param name="items">An array of <see cref="ImageListViewItem"/>
        /// to add to the <see cref="ImageListViewItemCollection"/>.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        public void AddRange(ImageListViewItem[] items, ImageListViewItemAdaptor adaptor)
        {
            mImageListView?.SuspendPaint();

            foreach (ImageListViewItem item in items)
            {
                Add(item, adaptor);
            }

            mImageListView?.ResumePaint();
        }
Esempio n. 7
0
        /// <summary>
        /// Adds the virtual item image to the renderer cache queue.
        /// </summary>
        /// <param name="guid">The guid representing this item.</param>
        /// <param name="adaptor">The adaptor of this item.</param>
        /// <param name="key">The key of this item.</param>
        /// <param name="thumbSize">Requested thumbnail size.</param>
        /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        /// <param name="autoRotate">AutoRotate property of the owner control.</param>
        /// <param name="useWIC">Whether to use WIC.</param>
        public void AddToRendererCache(Guid guid, ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC)
        {
            // Already cached?
            if (rendererItem != null && rendererItem.Guid == guid && rendererItem.Image != null && rendererItem.Size == thumbSize && rendererItem.UseEmbeddedThumbnails == useEmbeddedThumbnails && rendererItem.AutoRotate == autoRotate && rendererItem.UseWIC == useWIC)
            {
                return;
            }

            // Add to cache queue
            RunWorker(new CacheRequest(guid, adaptor, key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC, RequestType.Renderer), 1);
        }
Esempio n. 8
0
        /// <summary>
        /// Inserts an item to the <see cref="ImageListViewItemCollection"/> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
        /// <param name="item">The <see cref="ImageListViewItem"/> to
        /// insert into the <see cref="ImageListViewItemCollection"/>.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        public void Insert(int index, ImageListViewItem item, ImageListViewItemAdaptor adaptor)
        {
            InsertInternal(index, item, adaptor);

            if (mImageListView != null)
            {
                if (item.Selected)
                {
                    mImageListView.OnSelectionChangedInternal();
                }
                mImageListView.Refresh();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Adds an item to the <see cref="ImageListViewItemCollection"/>.
        /// </summary>
        /// <param name="item">The <see cref="ImageListViewItem"/> to add to the <see cref="ImageListViewItemCollection"/>.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        public void Add(ImageListViewItem item, ImageListViewItemAdaptor adaptor)
        {
            AddInternal(item, adaptor);

            if (mImageListView != null)
            {
                if (item.Selected)
                {
                    mImageListView.OnSelectionChangedInternal();
                }
                mImageListView.Refresh();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds a virtual item to the cache queue.
        /// </summary>
        /// <param name="guid">The guid representing this item.</param>
        /// <param name="adaptor">he adaptor for this item.</param>
        /// <param name="key">The key of this item.</param>
        /// <param name="thumbSize">Requested thumbnail size.</param>
        /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        /// <param name="autoRotate">AutoRotate property of the owner control.</param>
        /// <param name="useWIC">Whether to use WIC.</param>
        public void Add(Guid guid, ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC, int priority = 0)
        {
            // Already cached?
            if (thumbCache.TryGetValue(guid, out CacheItem item))
            {
                if (item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails)
                {
                    return;
                }
            }

            // Add to cache queue
            RunWorker(new CacheRequest(guid, adaptor, key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC, RequestType.Thumbnail), priority);
        }
Esempio n. 11
0
 /// <summary>
 /// Adds the given item without raising a selection changed event.
 /// </summary>
 /// <param name="item">The <see cref="ImageListViewItem"/> to add.</param>
 /// <param name="adaptor">The adaptor associated with this item.</param>
 /// <returns>true if the item was added; otherwise false.</returns>
 internal bool AddInternal(ImageListViewItem item, ImageListViewItemAdaptor adaptor)
 {
     return(InsertInternal(-1, item, adaptor));
 }
 /// <summary>
 /// Adds the item to the cache queue.
 /// </summary>
 /// <param name="guid">Item guid.</param>
 /// <param name="adaptor">The adaptor for this item.</param>
 /// <param name="virtualItemKey">The virtual item key.</param>
 /// <param name="useWIC">Whether to use the Windows Imaging Component.</param>
 public void Add(Guid guid, ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC)
 {
     // Add to cache queue
     RunWorker(new CacheRequest(guid, adaptor, virtualItemKey, useWIC));
 }
Esempio n. 13
0
 /// <summary>
 /// Adds a virtual item to the <see cref="ImageListViewItemCollection"/>.
 /// </summary>
 /// <param name="key">The key identifying the item.</param>
 /// <param name="text">Text of the item.</param>
 /// <param name="adaptor">The adaptor associated with this item.</param>
 public void Add(object key, string text, ImageListViewItemAdaptor adaptor)
 {
     Add(key, text, null, adaptor);
 }
Esempio n. 14
0
 /// <summary>
 /// Inserts a virtual item to the <see cref="ImageListViewItemCollection"/> at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which the new item should be inserted.</param>
 /// <param name="key">The key identifying the item.</param>
 /// <param name="text">Text of the item.</param>
 /// <param name="adaptor">The adaptor associated with this item.</param>
 public void Insert(int index, object key, string text, ImageListViewItemAdaptor adaptor)
 {
     Insert(index, key, text, null, adaptor);
 }
Esempio n. 15
0
        /// <summary>
        /// Inserts a virtual item to the <see cref="ImageListViewItemCollection"/> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which the new item should be inserted.</param>
        /// <param name="key">The key identifying the item.</param>
        /// <param name="text">Text of the item.</param>
        /// <param name="initialThumbnail">The initial thumbnail image for the item.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        public void Insert(int index, object key, string text, Image initialThumbnail, ImageListViewItemAdaptor adaptor)
        {
            ImageListViewItem item = new ImageListViewItem(key, text)
            {
                clonedThumbnail = initialThumbnail
            };

            Insert(index, item, adaptor);
        }
Esempio n. 16
0
 /// <summary>
 /// Adds an item to the <see cref="ImageListViewItemCollection"/>.
 /// </summary>
 /// <param name="item">The <see cref="ImageListViewItem"/> to add to the <see cref="ImageListViewItemCollection"/>.</param>
 /// <param name="initialThumbnail">The initial thumbnail image for the item.</param>
 /// <param name="adaptor">The adaptor associated with this item.</param>
 public void Add(ImageListViewItem item, Image initialThumbnail, ImageListViewItemAdaptor adaptor)
 {
     item.clonedThumbnail = initialThumbnail;
     Add(item, adaptor);
 }
Esempio n. 17
0
        /// <summary>
        /// Inserts the given item without raising a selection changed event.
        /// </summary>
        /// <param name="index">Insertion index. If index is -1 the item is added to the end of the list.</param>
        /// <param name="item">The <see cref="ImageListViewItem"/> to add.</param>
        /// <param name="adaptor">The adaptor associated with this item.</param>
        /// <returns>true if the item was added; otherwise false.</returns>
        internal bool InsertInternal(int index, ImageListViewItem item, ImageListViewItemAdaptor adaptor)
        {
            if (mImageListView == null)
            {
                return(false);
            }

            // Check if the file already exists
            if (!string.IsNullOrEmpty(item.FileName) && !mImageListView.AllowDuplicateFileNames)
            {
                if (mItems.Exists(a => string.Compare(a.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    return(false);
                }
            }
            item.owner    = this;
            item.mAdaptor = adaptor;
            if (index == -1)
            {
                item.mIndex = mItems.Count;
                mItems.Add(item);
            }
            else
            {
                item.mIndex = index;
                for (int i = index; i < mItems.Count; i++)
                {
                    mItems[i].mIndex++;
                }
                mItems.Insert(index, item);
            }
            lookUp.Add(item.Guid, item);
            collectionModified = true;

            item.mImageListView = mImageListView;

            // Create sub item texts for custom columns
            foreach (ImageListViewColumnHeader header in mImageListView.Columns)
            {
                if (header.Type == ColumnType.Custom)
                {
                    item.AddSubItemText(header.Guid);
                }
            }

            // Add current thumbnail to cache
            if (item.clonedThumbnail != null)
            {
                mImageListView.thumbnailCache.Add(item.Guid, item.Adaptor, item.VirtualItemKey, mImageListView.ThumbnailSize,
                                                  item.clonedThumbnail, mImageListView.UseEmbeddedThumbnails, mImageListView.AutoRotateThumbnails,
                                                  (mImageListView.UseWIC == UseWIC.Auto || mImageListView.UseWIC == UseWIC.ThumbnailsOnly));
                item.clonedThumbnail = null;
            }

            // Add to thumbnail cache
            if (mImageListView.CacheMode == CacheMode.Continuous)
            {
                mImageListView.thumbnailCache.Add(item.Guid, item.Adaptor, item.VirtualItemKey,
                                                  mImageListView.ThumbnailSize, mImageListView.UseEmbeddedThumbnails, mImageListView.AutoRotateThumbnails,
                                                  (mImageListView.UseWIC == UseWIC.Auto || mImageListView.UseWIC == UseWIC.ThumbnailsOnly));
            }

            // Add to details cache
            mImageListView.metadataCache.Add(item.Guid, item.Adaptor, item.VirtualItemKey,
                                             (mImageListView.UseWIC == UseWIC.Auto || mImageListView.UseWIC == UseWIC.DetailsOnly));

            // Add to shell info cache
            string extension = item.extension;

            if (!string.IsNullOrEmpty(extension))
            {
                CacheState state = mImageListView.shellInfoCache.GetCacheState(extension);
                if (state == CacheState.Error && mImageListView.RetryOnError == true)
                {
                    mImageListView.shellInfoCache.Remove(extension);
                    mImageListView.shellInfoCache.Add(extension);
                }
                else if (state == CacheState.Unknown)
                {
                    mImageListView.shellInfoCache.Add(extension);
                }
            }

            // Update groups
            if (mImageListView.GroupsVisible)
            {
                AddRemoveGroupItem(item.Index, true);
            }

            // Raise the add event
            mImageListView.OnItemCollectionChanged(new ItemCollectionChangedEventArgs(CollectionChangeAction.Add, item));

            return(true);
        }