/// <summary> /// Determines whether all color values of the specified /// ImageListViewColor are equal to this instance. /// </summary> /// <param name="obj">The object to compare with this instance.</param> /// <returns>true if the two instances have the same color values; /// otherwise false.</returns> public override bool Equals(object obj) { if (obj == null) { throw new NullReferenceException(); } ImageListViewColor other = obj as ImageListViewColor; if (other == null) { return(false); } foreach (PropertyInfo info in typeof(ImageListViewColor).GetProperties()) { // Walk through color properties if (info.PropertyType == typeof(Color)) { // Compare colors Color color1 = (Color)info.GetValue(this, null); Color color2 = (Color)info.GetValue(other, null); if (color1 != color2) { return(false); } } } return(true); }
/// <summary> /// Returns a string that represents this instance. /// </summary> /// <returns> /// A string that represents this instance. /// </returns> public override string ToString() { ImageListViewColor colors = this; // First check if the color matches a predefined color setting foreach (MemberInfo info in typeof(ImageListViewColor).GetMembers(BindingFlags.Static | BindingFlags.Public)) { if (info.MemberType == MemberTypes.Property) { PropertyInfo propertyInfo = (PropertyInfo)info; if (propertyInfo.PropertyType == typeof(ImageListViewColor)) { ImageListViewColor presetValue = (ImageListViewColor)propertyInfo.GetValue(null, null); // If the color setting is equal to a preset value // return the name of the preset if (colors.Equals(presetValue)) { return(string.Format("({0})", propertyInfo.Name)); } } } } // Serialize all colors which are different from the default setting List <string> lines = new List <string>(); foreach (PropertyInfo info in typeof(ImageListViewColor).GetProperties()) { // Walk through color properties if (info.PropertyType == typeof(Color)) { // Get property name string name = info.Name; // Get the current value Color color = (Color)info.GetValue(colors, null); // Find the default value atribute Attribute[] attributes = (Attribute[])info.GetCustomAttributes(typeof(DefaultValueAttribute), false); if (attributes.Length != 0) { // Get the default value DefaultValueAttribute attribute = (DefaultValueAttribute)attributes[0]; Color defaultColor = (Color)attribute.Value; // Serialize only if colors are different if (color != defaultColor) { lines.Add(string.Format("{0} = {1}", name, color.Name)); } } } } return(string.Join("; ", lines.ToArray())); }
/// <summary> /// Copies color values from the given object. /// </summary> /// <param name="source">The source object.</param> public void CopyFrom(ImageListViewColor source) { foreach (PropertyInfo info in typeof(ImageListViewColor).GetProperties()) { // Walk through color properties if (info.PropertyType == typeof(Color)) { Color color = (Color)info.GetValue(source, null); info.SetValue(this, color, null); } } }
/// <summary> /// Initializes a new instance of the ImageListViewColor class /// from its string representation. /// </summary> /// <param name="definition">String representation of the object.</param> public ImageListViewColor(string definition) : this() { try { // First check if the color matches a predefined color setting foreach (MemberInfo info in typeof(ImageListViewColor).GetMembers(BindingFlags.Static | BindingFlags.Public)) { if (info.MemberType == MemberTypes.Property) { PropertyInfo propertyInfo = (PropertyInfo)info; if (propertyInfo.PropertyType == typeof(ImageListViewColor)) { // If the color setting is equal to a preset value // return the preset if (definition == string.Format("({0})", propertyInfo.Name) || definition == propertyInfo.Name) { ImageListViewColor presetValue = (ImageListViewColor)propertyInfo.GetValue(null, null); CopyFrom(presetValue); return; } } } } // Convert color values foreach (string line in definition.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { // Read the color setting string[] pair = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries); string name = pair[0].Trim(); Color color = Color.FromName(pair[1].Trim()); // Set the property value PropertyInfo property = typeof(ImageListViewColor).GetProperty(name); property.SetValue(this, color, null); } } catch { throw new ArgumentException("Invalid string format", "definition"); } }
/// <summary> /// Converts the given value object to the specified type, /// using the specified context and culture information. /// </summary> /// <param name="context">Format context.</param> /// <param name="culture">The culture info. If null is passed, the current culture is assumed.</param> /// <param name="value">The objct to convert.</param> /// <param name="destinationType">The type to convert to.</param> /// <returns>An object that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value != null && value is ImageListViewColor) { ImageListViewColor colors = (ImageListViewColor)value; if (destinationType == typeof(string)) { return(colors.ToString()); } else if (destinationType == typeof(InstanceDescriptor)) { // Used by the designer serializer ConstructorInfo consInfo = typeof(ImageListViewColor).GetConstructor(new Type[] { typeof(string) }); return(new InstanceDescriptor(consInfo, new object[] { colors.ToString() })); } } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Sets the color palette to noir colors. /// </summary> private static ImageListViewColor GetNoirTheme() { ImageListViewColor c = new ImageListViewColor(); // control c.ControlBackColor = Color.Black; c.DisabledBackColor = Color.Black; // item c.BackColor = Color.FromArgb(0x31, 0x31, 0x31); c.ForeColor = Color.LightGray; c.BorderColor = Color.DarkGray; c.UnFocusedColor1 = Color.FromArgb(16, SystemColors.GrayText); c.UnFocusedColor2 = Color.FromArgb(64, SystemColors.GrayText); c.UnFocusedBorderColor = Color.FromArgb(128, SystemColors.GrayText); c.UnFocusedForeColor = Color.LightGray; c.HoverColor1 = Color.FromArgb(64, Color.White); c.HoverColor2 = Color.FromArgb(16, Color.White); c.HoverBorderColor = Color.FromArgb(64, SystemColors.Highlight); c.SelectedColor1 = Color.FromArgb(64, 96, 160); c.SelectedColor2 = Color.FromArgb(64, 64, 96, 160); c.SelectedBorderColor = Color.FromArgb(128, SystemColors.Highlight); c.SelectedForeColor = Color.LightGray; c.DisabledColor1 = Color.FromArgb(0, SystemColors.GrayText); c.DisabledColor2 = Color.FromArgb(32, SystemColors.GrayText); c.DisabledBorderColor = Color.FromArgb(96, SystemColors.GrayText); c.DisabledForeColor = Color.LightGray; c.InsertionCaretColor = Color.FromArgb(96, 144, 240); // thumbnails & pane c.ImageInnerBorderColor = Color.FromArgb(128, Color.White); c.ImageOuterBorderColor = Color.FromArgb(128, Color.Gray); // details view c.CellForeColor = Color.WhiteSmoke; c.ColumnHeaderBackColor1 = Color.FromArgb(32, 128, 128, 128); c.ColumnHeaderBackColor2 = Color.FromArgb(196, 128, 128, 128); c.ColumnHeaderHoverColor1 = Color.FromArgb(64, 96, 144, 240); c.ColumnHeaderHoverColor2 = Color.FromArgb(196, 96, 144, 240); c.ColumnHeaderForeColor = Color.White; c.ColumnSelectColor = Color.FromArgb(96, 128, 128, 128); c.ColumnSeparatorColor = Color.Gold; c.AlternateBackColor = Color.FromArgb(0x31, 0x31, 0x31); c.AlternateCellForeColor = Color.WhiteSmoke; // image pane c.PaneBackColor = Color.FromArgb(0x31, 0x31, 0x31); c.PaneSeparatorColor = Color.Gold; c.PaneLabelColor = SystemColors.GrayText; // selection rectangke c.SelectionRectangleColor1 = Color.FromArgb(160, 96, 144, 240); c.SelectionRectangleColor2 = Color.FromArgb(32, 96, 144, 240); c.SelectionRectangleBorderColor = Color.FromArgb(64, 96, 144, 240); return c; }
/// <summary> /// Sets the color palette to mandarin colors. /// </summary> private static ImageListViewColor GetMandarinTheme() { ImageListViewColor c = new ImageListViewColor(); // control c.ControlBackColor = Color.White; c.DisabledBackColor = Color.FromArgb(220, 220, 220); // item c.BackColor = Color.White; c.ForeColor = Color.FromArgb(60, 60, 60); c.BorderColor = Color.FromArgb(187, 190, 183); c.UnFocusedColor1 = Color.FromArgb(235, 235, 235); c.UnFocusedColor2 = Color.FromArgb(217, 217, 217); c.UnFocusedBorderColor = Color.FromArgb(168, 169, 161); c.UnFocusedForeColor = Color.FromArgb(40, 40, 40); c.HoverColor1 = Color.Transparent; c.HoverColor2 = Color.Transparent; c.HoverBorderColor = Color.Transparent; c.SelectedColor1 = Color.FromArgb(244, 125, 77); c.SelectedColor2 = Color.FromArgb(235, 110, 60); c.SelectedBorderColor = Color.FromArgb(240, 119, 70); c.SelectedForeColor = Color.White; c.DisabledColor1 = Color.FromArgb(217, 217, 217); c.DisabledColor2 = Color.FromArgb(197, 197, 197); c.DisabledBorderColor = Color.FromArgb(128, 128, 128); c.DisabledForeColor = Color.FromArgb(128, 128, 128); c.InsertionCaretColor = Color.FromArgb(240, 119, 70); // thumbnails & pane c.ImageInnerBorderColor = Color.Transparent; c.ImageOuterBorderColor = Color.White; // details view c.CellForeColor = Color.FromArgb(60, 60, 60); c.ColumnHeaderBackColor1 = Color.FromArgb(247, 247, 247); c.ColumnHeaderBackColor2 = Color.FromArgb(235, 235, 235); c.ColumnHeaderHoverColor1 = Color.White; c.ColumnHeaderHoverColor2 = Color.FromArgb(245, 245, 245); c.ColumnHeaderForeColor = Color.FromArgb(60, 60, 60); c.ColumnSelectColor = Color.FromArgb(34, 128, 128, 128); c.ColumnSeparatorColor = Color.FromArgb(106, 128, 128, 128); c.mAlternateBackColor = Color.FromArgb(234, 234, 234); c.mAlternateCellForeColor = Color.FromArgb(40, 40, 40); // image pane c.PaneBackColor = Color.White; c.PaneSeparatorColor = Color.FromArgb(216, 216, 216); c.PaneLabelColor = Color.FromArgb(156, 156, 156); // selection rectangle c.SelectionRectangleColor1 = Color.FromArgb(64, 240, 116, 68); c.SelectionRectangleColor2 = Color.FromArgb(64, 240, 116, 68); c.SelectionRectangleBorderColor = Color.FromArgb(240, 119, 70); return c; }
/// <summary> /// Sets the renderer for this instance. /// </summary> /// <param name="renderer">An <see cref="ImageListViewRenderer"/> to assign to the control.</param> /// <param name="keepColors">true to keep current colors; otherwise false.</param> public void SetRenderer(ImageListViewRenderer renderer, bool keepColors) { if (renderer == null) throw new ArgumentNullException("renderer"); ImageListViewRenderer oldRenderer = mRenderer; mRenderer = renderer; mRenderer.ImageListView = this; if (!keepColors) { ImageListViewColor[] preferredColors = mRenderer.PreferredColors; if (preferredColors != null) mColors = preferredColors[0]; else mColors = ImageListViewColor.Default; } if (oldRenderer != null) oldRenderer.Dispose(); if (layoutManager != null) layoutManager.Update(true); Refresh(); }
/// <summary> /// Initializes a new instance of the ImageListView class. /// </summary> public ImageListView() { // Renderer parameters controlSuspended = false; rendererSuspendCount = 0; rendererNeedsPaint = true; mColors = ImageListViewColor.Default; SetRenderer(new ImageListViewRenderer()); // Property defaults AutoRotateThumbnails = true; AllowCheckBoxClick = true; AllowColumnClick = true; AllowColumnResize = true; AllowDrag = false; AllowDuplicateFileNames = false; AllowPaneResize = true; mBorderStyle = BorderStyle.Fixed3D; mCacheMode = CacheMode.OnDemand; mCacheLimitAsItemCount = 0; mCacheLimitAsMemory = 20 * 1024 * 1024; mColumns = new ImageListViewColumnHeaderCollection(this); resources = new ResourceManager("ImageGlass.ImageListView.ImageListViewResources", typeof(ImageListView).Assembly); mDefaultImage = resources.GetObject("DefaultImage") as Image; mErrorImage = resources.GetObject("ErrorImage") as Image; mRatingImage = resources.GetObject("RatingImage") as Image; mEmptyRatingImage = resources.GetObject("EmptyRatingImage") as Image; GroupHeaderFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold); ColumnHeaderFont = new Font("Microsoft Sans Serif", 8.25f); mIntegralScroll = false; mItems = new ImageListViewItemCollection(this); MultiSelect = true; mPaneWidth = 240; mRetryOnError = true; mSelectedItems = new ImageListViewSelectedItemCollection(this); mCheckedItems = new ImageListViewCheckedItemCollection(this); mSortColumn = 0; mGroupColumn = 0; mSortOrder = SortOrder.None; mGroupOrder = SortOrder.None; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.Selectable | ControlStyles.UserMouse, true); ScrollBars = true; ShellIconFallback = true; Size = new Size(120, 100); mShowCheckBoxes = false; mCheckBoxAlignment = ContentAlignment.BottomRight; mCheckBoxPadding = new Size(2, 2); mShowFileIcons = false; mIconAlignment = ContentAlignment.TopRight; mIconPadding = new Size(2, 2); Text = string.Empty; mThumbnailSize = new Size(96, 96); mUseEmbeddedThumbnails = UseEmbeddedThumbnails.Auto; mUseWIC = UseWIC.Auto; mView = View.Thumbnails; mViewOffset = new Point(0, 0); mShowScrollBars = true; mEnableKeyNavigation = true; // Child controls hScrollBar = new HScrollBar(); vScrollBar = new VScrollBar(); hScrollBar.Visible = false; vScrollBar.Visible = false; hScrollBar.Scroll += hScrollBar_Scroll; vScrollBar.Scroll += vScrollBar_Scroll; Controls.Add(hScrollBar); Controls.Add(vScrollBar); // Groups groups = new ImageListViewGroupCollection(this); showGroups = false; // Lazy refresh timer lazyRefreshTimer = new System.Timers.Timer(); lazyRefreshTimer.Interval = ImageListViewRenderer.LazyRefreshInterval; lazyRefreshTimer.Enabled = false; lazyRefreshTimer.Elapsed += lazyRefreshTimer_Tick; lazyRefreshCallback = new RefreshDelegateInternal(Refresh); // Helpers layoutManager = new ImageListViewLayoutManager(this); navigationManager = new ImageListViewNavigationManager(this); // Cache nabagers defaultAdaptor = new ImageListViewItemAdaptors.FileSystemAdaptor(); thumbnailCache = new ImageListViewCacheThumbnail(this); shellInfoCache = new ImageListViewCacheShellInfo(this); metadataCache = new ImageListViewCacheMetadata(this); disposed = false; }
/// <summary> /// Sets the color palette to noir colors. /// </summary> private static ImageListViewColor GetNoirTheme() { ImageListViewColor c = new ImageListViewColor(); // control c.ControlBackColor = Color.Black; c.DisabledBackColor = Color.Black; // item c.BackColor = Color.FromArgb(0x31, 0x31, 0x31); c.ForeColor = Color.LightGray; c.BorderColor = Color.DarkGray; c.UnFocusedColor1 = Color.FromArgb(16, SystemColors.GrayText); c.UnFocusedColor2 = Color.FromArgb(64, SystemColors.GrayText); c.UnFocusedBorderColor = Color.FromArgb(128, SystemColors.GrayText); c.UnFocusedForeColor = Color.LightGray; c.HoverColor1 = Color.FromArgb(64, Color.White); c.HoverColor2 = Color.FromArgb(16, Color.White); c.HoverBorderColor = Color.FromArgb(64, SystemColors.Highlight); c.SelectedColor1 = Color.FromArgb(64, 96, 160); c.SelectedColor2 = Color.FromArgb(64, 64, 96, 160); c.SelectedBorderColor = Color.FromArgb(128, SystemColors.Highlight); c.SelectedForeColor = Color.LightGray; c.DisabledColor1 = Color.FromArgb(0, SystemColors.GrayText); c.DisabledColor2 = Color.FromArgb(32, SystemColors.GrayText); c.DisabledBorderColor = Color.FromArgb(96, SystemColors.GrayText); c.DisabledForeColor = Color.LightGray; c.InsertionCaretColor = Color.FromArgb(96, 144, 240); // thumbnails & pane c.ImageInnerBorderColor = Color.FromArgb(128, Color.White); c.ImageOuterBorderColor = Color.FromArgb(128, Color.Gray); // details view c.CellForeColor = Color.WhiteSmoke; c.ColumnHeaderBackColor1 = Color.FromArgb(32, 128, 128, 128); c.ColumnHeaderBackColor2 = Color.FromArgb(196, 128, 128, 128); c.ColumnHeaderHoverColor1 = Color.FromArgb(64, 96, 144, 240); c.ColumnHeaderHoverColor2 = Color.FromArgb(196, 96, 144, 240); c.ColumnHeaderForeColor = Color.White; c.ColumnSelectColor = Color.FromArgb(96, 128, 128, 128); c.ColumnSeparatorColor = Color.Gold; c.AlternateBackColor = Color.FromArgb(0x31, 0x31, 0x31); c.AlternateCellForeColor = Color.WhiteSmoke; // image pane c.PaneBackColor = Color.FromArgb(0x31, 0x31, 0x31); c.PaneSeparatorColor = Color.Gold; c.PaneLabelColor = SystemColors.GrayText; // selection rectangke c.SelectionRectangleColor1 = Color.FromArgb(160, 96, 144, 240); c.SelectionRectangleColor2 = Color.FromArgb(32, 96, 144, 240); c.SelectionRectangleBorderColor = Color.FromArgb(64, 96, 144, 240); return(c); }
/// <summary> /// Sets the color palette to mandarin colors. /// </summary> private static ImageListViewColor GetMandarinTheme() { ImageListViewColor c = new ImageListViewColor(); // control c.ControlBackColor = Color.White; c.DisabledBackColor = Color.FromArgb(220, 220, 220); // item c.BackColor = Color.White; c.ForeColor = Color.FromArgb(60, 60, 60); c.BorderColor = Color.FromArgb(187, 190, 183); c.UnFocusedColor1 = Color.FromArgb(235, 235, 235); c.UnFocusedColor2 = Color.FromArgb(217, 217, 217); c.UnFocusedBorderColor = Color.FromArgb(168, 169, 161); c.UnFocusedForeColor = Color.FromArgb(40, 40, 40); c.HoverColor1 = Color.Transparent; c.HoverColor2 = Color.Transparent; c.HoverBorderColor = Color.Transparent; c.SelectedColor1 = Color.FromArgb(244, 125, 77); c.SelectedColor2 = Color.FromArgb(235, 110, 60); c.SelectedBorderColor = Color.FromArgb(240, 119, 70); c.SelectedForeColor = Color.White; c.DisabledColor1 = Color.FromArgb(217, 217, 217); c.DisabledColor2 = Color.FromArgb(197, 197, 197); c.DisabledBorderColor = Color.FromArgb(128, 128, 128); c.DisabledForeColor = Color.FromArgb(128, 128, 128); c.InsertionCaretColor = Color.FromArgb(240, 119, 70); // thumbnails & pane c.ImageInnerBorderColor = Color.Transparent; c.ImageOuterBorderColor = Color.White; // details view c.CellForeColor = Color.FromArgb(60, 60, 60); c.ColumnHeaderBackColor1 = Color.FromArgb(247, 247, 247); c.ColumnHeaderBackColor2 = Color.FromArgb(235, 235, 235); c.ColumnHeaderHoverColor1 = Color.White; c.ColumnHeaderHoverColor2 = Color.FromArgb(245, 245, 245); c.ColumnHeaderForeColor = Color.FromArgb(60, 60, 60); c.ColumnSelectColor = Color.FromArgb(34, 128, 128, 128); c.ColumnSeparatorColor = Color.FromArgb(106, 128, 128, 128); c.mAlternateBackColor = Color.FromArgb(234, 234, 234); c.mAlternateCellForeColor = Color.FromArgb(40, 40, 40); // image pane c.PaneBackColor = Color.White; c.PaneSeparatorColor = Color.FromArgb(216, 216, 216); c.PaneLabelColor = Color.FromArgb(156, 156, 156); // selection rectangle c.SelectionRectangleColor1 = Color.FromArgb(64, 240, 116, 68); c.SelectionRectangleColor2 = Color.FromArgb(64, 240, 116, 68); c.SelectionRectangleBorderColor = Color.FromArgb(240, 119, 70); return(c); }