/// <summary> /// Initializes a new instance of the <see cref="ImageListViewCacheThumbnail"/> class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewCacheThumbnail(ImageListView owner) { context = null; bw = new QueuedBackgroundWorker(); bw.ProcessingMode = ProcessingMode.LIFO; bw.IsBackground = true; bw.DoWork += bw_DoWork; bw.RunWorkerCompleted += bw_RunWorkerCompleted; checkProcessingCallback = new SendOrPostCallback(CanContinueProcessing); mImageListView = owner; diskCache = new DiskCache(string.Empty, 100 * 1024 * 1024, DiskCache.SyncBehavior.SyncNone, 32); CacheMode = CacheMode.OnDemand; CacheLimitAsItemCount = 0; CacheLimitAsMemory = 20 * 1024 * 1024; RetryOnError = false; thumbCache = new Dictionary<Guid, CacheItem>(); editCache = new Dictionary<Guid, bool>(); processing = new Dictionary<Guid, bool>(); processingRendererItem = Guid.Empty; processingGalleryItem = Guid.Empty; rendererItem = null; galleryItem = null; MemoryUsed = 0; MemoryUsedByRemoved = 0; removedItems = new List<Guid>(); disposed = false; }
/// <summary> /// Initializes a new instance of the ImageListViewNavigationManager class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewNavigationManager(ImageListView owner) { mImageListView = owner; DraggingSeperator = false; ResizingPane = false; LeftButton = false; RightButton = false; ShiftKey = false; ControlKey = false; HoveredItem = null; HoveredSubItem = -1; HoveredColumn = null; HoveredSeparator = null; SelectedSeparator = null; HoveredPaneBorder = false; MouseSelecting = false; DropTarget = null; DropToRight = false; selfDragging = false; highlightedItems = new Dictionary<ImageListViewItem, bool>(); scrollTimer = new System.Windows.Forms.Timer(); scrollTimer.Interval = 100; scrollTimer.Enabled = false; scrollTimer.Tick += new EventHandler(scrollTimer_Tick); suppressClick = false; }
/// <summary> /// Initializes a new instance of the ImageListViewActionLists class. /// </summary> /// <param name="component">A component related to the DesignerActionList.</param> public ImageListViewActionLists(IComponent component) : base(component) { imageListView = (ImageListView)component; designerService = (DesignerActionUIService)GetService(typeof(DesignerActionUIService)); }
/// <summary> /// Initializes a new instance of the ImageListViewLayoutManager class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewLayoutManager(ImageListView owner) { mImageListView = owner; cachedVisibleItems = new Dictionary<Guid, bool>(); vScrollVisible = false; hScrollVisible = false; Update(); }
/// <summary> /// Initializes a new instance of the ImageListViewColumnHeader class. /// </summary> /// <param name="type">The type of data to display in this column.</param> /// <param name="text">Text of the column header.</param> /// <param name="width">Width in pixels of the column header.</param> /// <param name="displayIndex">Display order of the column.</param> /// <param name="visible">Whether the column is initially visible.</param> public ImageListViewColumnHeader(ColumnType type, string text, int width, int displayIndex, bool visible) { mImageListView = null; owner = null; mGuid = Guid.NewGuid(); mText = text; mType = type; mWidth = width; mVisible = visible; mDisplayIndex = displayIndex; }
/// <summary> /// Initializes a new instance of the <see cref="ImageListViewCacheShellInfo"/> class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewCacheShellInfo(ImageListView owner) { context = null; bw = new QueuedBackgroundWorker (); bw.Threads = 1; bw.IsBackground = true; bw.DoWork += bw_DoWork; bw.RunWorkerCompleted += bw_RunWorkerCompleted; checkProcessingCallback = new SendOrPostCallback (CanContinueProcessing); mImageListView = owner; RetryOnError = false; shellCache = new Dictionary<string, CacheItem> (); processing = new Dictionary<string, bool> (); disposed = false; }
/// <summary> /// Initializes a new instance of the <see cref="ImageListViewCacheShellInfo"/> class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewCacheMetadata(ImageListView owner) { context = null; bw = new QueuedBackgroundWorker (); bw.IsBackground = true; bw.DoWork += bw_DoWork; bw.RunWorkerCompleted += bw_RunWorkerCompleted; checkProcessingCallback = new SendOrPostCallback (CanContinueProcessing); mImageListView = owner; RetryOnError = false; editCache = new Dictionary<Guid, bool> (); processing = new Dictionary<Guid, bool> (); removedItems = new Dictionary<Guid, bool> (); disposed = false; }
/// <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, ImageListView.ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC) { Guid = guid; Adaptor = adaptor; VirtualItemKey = virtualItemKey; UseWIC = useWIC; }
/// <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, ImageListView.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; }
/// <summary> /// Updates group order and name of the item. /// </summary> /// <param name="column">The group column.</param> internal void UpdateGroup(ImageListView.ImageListViewColumnHeader column) { if (column == null) { groupOrder = 0; group = string.Empty; return; } Utility.Tuple<int, string> groupInfo = new Utility.Tuple<int, string>(0, string.Empty); switch (column.Type) { case ColumnType.DateAccessed: groupInfo = Utility.GroupTextDate(DateAccessed); break; case ColumnType.DateCreated: groupInfo = Utility.GroupTextDate(DateCreated); break; case ColumnType.DateModified: groupInfo = Utility.GroupTextDate(DateModified); break; case ColumnType.Dimensions: groupInfo = Utility.GroupTextDimension(Dimensions); break; case ColumnType.FileName: groupInfo = Utility.GroupTextAlpha(FileName); break; case ColumnType.FilePath: groupInfo = Utility.GroupTextAlpha(FilePath); break; case ColumnType.FileSize: groupInfo = Utility.GroupTextFileSize(FileSize); break; case ColumnType.FileType: groupInfo = Utility.GroupTextAlpha(FileType); break; case ColumnType.Name: groupInfo = Utility.GroupTextAlpha(Text); break; case ColumnType.ImageDescription: groupInfo = Utility.GroupTextAlpha(ImageDescription); break; case ColumnType.EquipmentModel: groupInfo = Utility.GroupTextAlpha(EquipmentModel); break; case ColumnType.DateTaken: groupInfo = Utility.GroupTextDate(DateTaken); break; case ColumnType.Artist: groupInfo = Utility.GroupTextAlpha(Artist); break; case ColumnType.Copyright: groupInfo = Utility.GroupTextAlpha(Copyright); break; case ColumnType.UserComment: groupInfo = Utility.GroupTextAlpha(UserComment); break; case ColumnType.Software: groupInfo = Utility.GroupTextAlpha(Software); break; case ColumnType.Custom: groupInfo = Utility.GroupTextAlpha(GetSubItemText(column.Guid)); break; case ColumnType.ISOSpeed: groupInfo = new Utility.Tuple<int, string>(ISOSpeed, ISOSpeed.ToString()); break; case ColumnType.Rating: groupInfo = new Utility.Tuple<int, string>(Rating / 5, (Rating / 5).ToString()); break; case ColumnType.FocalLength: groupInfo = new Utility.Tuple<int, string>((int)FocalLength, FocalLength.ToString()); break; case ColumnType.ExposureTime: groupInfo = new Utility.Tuple<int, string>((int)ExposureTime, ExposureTime.ToString()); break; case ColumnType.FNumber: groupInfo = new Utility.Tuple<int, string>((int)FNumber, FNumber.ToString()); break; case ColumnType.Resolution: groupInfo = new Utility.Tuple<int, string>((int)Resolution.Width, Resolution.Width.ToString()); break; default: groupInfo = new Utility.Tuple<int, string>(0, "Unknown"); break; } groupOrder = groupInfo.Item1; group = groupInfo.Item2; }
/// <summary> /// Initializes a new instance of the ColumnHoverEventArgs class. /// </summary> /// <param name="column">The currently hovered column.</param> /// <param name="previousColumn">The previously hovered column.</param> public ColumnHoverEventArgs(ImageListView.ImageListViewColumnHeader column, ImageListView.ImageListViewColumnHeader previousColumn) { Column = column; PreviousColumn = previousColumn; }
/// <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, ImageListView.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); }
/// <summary> /// Draws the column headers. /// </summary> /// <param name="g">The System.Drawing.Graphics to draw on.</param> /// <param name="column">The ImageListViewColumnHeader to draw.</param> /// <param name="state">The current view state of column.</param> /// <param name="bounds">The bounding rectangle of column in client coordinates.</param> public override void DrawColumnHeader(Graphics g, ImageListView.ImageListViewColumnHeader column, ColumnState state, Rectangle bounds) { // Paint background if ((state & ColumnState.Hovered) != ColumnState.None) { using (Brush bHovered = new LinearGradientBrush(bounds, ImageListView.Colors.ColumnHeaderHoverColor1, ImageListView.Colors.ColumnHeaderHoverColor2, LinearGradientMode.Vertical)) { g.FillRectangle(bHovered, bounds); } } else { using (Brush bNormal = new LinearGradientBrush(bounds, ImageListView.Colors.ColumnHeaderBackColor1, ImageListView.Colors.ColumnHeaderBackColor2, LinearGradientMode.Vertical)) { g.FillRectangle(bNormal, bounds); } } using (Pen pBorder = new Pen(ImageListView.Colors.ColumnSeparatorColor)) { g.DrawLine(pBorder, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); g.DrawLine(pBorder, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1); } using (Pen pBorder = new Pen(Color.FromArgb(252, 252, 252))) { g.DrawRectangle(pBorder, bounds.Left + 1, bounds.Top, bounds.Width - 2, bounds.Height - 2); } // Draw the sort arrow int offset = 4; int width = bounds.Width - 2 * offset; if (ImageListView.SortOrder != SortOrder.None && ((state & ColumnState.SortColumn) != ColumnState.None)) { Image img = null; if (ImageListView.SortOrder == SortOrder.Ascending) img = ImageListViewResources.SortAscending; else if (ImageListView.SortOrder == SortOrder.Descending) img = ImageListViewResources.SortDescending; if (img != null) { g.DrawImageUnscaled(img, bounds.Right - offset - img.Width, bounds.Top + (bounds.Height - img.Height) / 2); width -= img.Width + offset; } } // Text bounds.X += offset; bounds.Width = width; if (bounds.Width > 4) { using (StringFormat sf = new StringFormat()) { sf.FormatFlags = StringFormatFlags.NoWrap; sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; using (SolidBrush bText = new SolidBrush(ImageListView.Colors.ColumnHeaderForeColor)) { g.DrawString(column.Text, (ImageListView.ColumnHeaderFont == null ? ImageListView.Font : ImageListView.ColumnHeaderFont), bText, bounds, sf); } } } }
/// <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, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, Image thumb, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC) { // Already cached? CacheItem item = null; if (thumbCache.TryGetValue(guid, out 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 = GetKey(guid, 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 ColumnEventArgs class. /// </summary> /// <param name="column">The column that is the target of this event.</param> public ColumnEventArgs(ImageListView.ImageListViewColumnHeader column) { Column = column; }
/// <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, ImageListView.ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC) { // Add to cache queue RunWorker (new CacheRequest (guid, adaptor, virtualItemKey, useWIC)); }
/// <summary> /// Draws the column headers. /// </summary> /// <param name="g">The System.Drawing.Graphics to draw on.</param> /// <param name="column">The ImageListViewColumnHeader to draw.</param> /// <param name="state">The current view state of column.</param> /// <param name="bounds">The bounding rectangle of column in client coordinates.</param> public override void DrawColumnHeader(Graphics g, ImageListView.ImageListViewColumnHeader column, ColumnState state, Rectangle bounds) { SortOrder order = SortOrder.None; if (ImageListView.SortOrder != SortOrder.None && ((state & ColumnState.SortColumn) != ColumnState.None)) order = ImageListView.SortOrder; VisualStyleRenderer rBack; if (((state & ColumnState.Hovered) == ColumnState.Hovered) && order != SortOrder.None) rBack = rColumnSortedHovered; else if (((state & ColumnState.Hovered) == ColumnState.Hovered) && order == SortOrder.None) rBack = rColumnHovered; else if (((state & ColumnState.Hovered) == ColumnState.None) && order != SortOrder.None) rBack = rColumnSorted; else rBack = rColumnNormal; VisualStyleRenderer rSort; if (order == SortOrder.Ascending || order == SortOrder.AscendingNatural) rSort = rSortAscending; else rSort = rSortDescending; // Background if (VisualStylesEnabled && rBack != null && rSort != null) { // Background rBack.DrawBackground(g, bounds, bounds); // Sort arrow if (order != SortOrder.None) { Size sz = rSort.GetPartSize(g, System.Windows.Forms.VisualStyles.ThemeSizeType.True); Rectangle sortBounds = new Rectangle(new Point(0, 0), sz); sortBounds.Offset(bounds.X + (bounds.Width - sz.Width) / 2, 0); rSort.DrawBackground(g, sortBounds, sortBounds); } // Text if (bounds.Width > 4) { Rectangle textBounds = bounds; textBounds.Inflate(-3, 0); TextRenderer.DrawText(g, column.Text, SystemFonts.MenuFont, textBounds, SystemColors.ControlText, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping); } } else base.DrawColumnHeader(g, column, state, bounds); }
/// <summary> /// Draws the column headers. /// </summary> /// <param name="g">The System.Drawing.Graphics to draw on.</param> /// <param name="column">The ImageListViewColumnHeader to draw.</param> /// <param name="state">The current view state of column.</param> /// <param name="bounds">The bounding rectangle of column in client coordinates.</param> public override void DrawColumnHeader(Graphics g, ImageListView.ImageListViewColumnHeader column, ColumnState state, Rectangle bounds) { // Paint background if (ImageListView.Focused && ((state & ColumnState.Hovered) == ColumnState.Hovered)) { using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical)) { g.FillRectangle(bHovered, bounds); } } else { using (Brush bNormal = new LinearGradientBrush(bounds, Color.FromArgb(32, SystemColors.Control), Color.FromArgb(196, SystemColors.Control), LinearGradientMode.Vertical)) { g.FillRectangle(bNormal, bounds); } } using (Brush bBorder = new LinearGradientBrush(bounds, Color.FromArgb(196, SystemColors.Control), Color.FromArgb(32, SystemColors.Control), LinearGradientMode.Vertical)) using (Pen pBorder = new Pen(bBorder)) { g.DrawLine(pBorder, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); g.DrawLine(pBorder, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1); } using (Pen pSpep = new Pen(Color.FromArgb(32, SystemColors.Control))) { g.DrawLine(pSpep, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Bottom - 2); g.DrawLine(pSpep, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 2); } // Draw the sort arrow int textOffset = 4; if (ImageListView.SortOrder != SortOrder.None && ((state & ColumnState.SortColumn) != ColumnState.None)) { Image img = null; if (ImageListView.SortOrder == SortOrder.Ascending || ImageListView.SortOrder == SortOrder.AscendingNatural) img = ImageListViewResources.SortAscending; else if (ImageListView.SortOrder == SortOrder.Descending || ImageListView.SortOrder == SortOrder.DescendingNatural) img = ImageListViewResources.SortDescending; if (img != null) { g.DrawImageUnscaled(img, bounds.X + 4, bounds.Top + (bounds.Height - img.Height) / 2); textOffset += img.Width; } } // Text bounds.X += textOffset; bounds.Width -= textOffset; if (bounds.Width > 4) { using (StringFormat sf = new StringFormat()) { sf.FormatFlags = StringFormatFlags.NoWrap; sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; g.DrawString(column.Text, (ImageListView.ColumnHeaderFont == null ? ImageListView.Font : ImageListView.ColumnHeaderFont), SystemBrushes.WindowText, bounds, sf); } } }
/// <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, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC) { // Already cached? CacheItem item = null; if (thumbCache.TryGetValue(guid, out 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)); }
/// <summary> /// Initializes a new instance of the ColumnClickEventArgs class. /// </summary> /// <param name="column">The column that is the target of this event.</param> /// <param name="location">The location of the mouse.</param> /// <param name="buttons">One of the System.Windows.Forms.MouseButtons values /// indicating which mouse button was pressed.</param> public ColumnClickEventArgs(ImageListView.ImageListViewColumnHeader column, Point location, MouseButtons buttons) { Column = column; Location = location; Buttons = buttons; }