Ejemplo n.º 1
0
        /// <summary>
        /// Removes the element at the specified index of the <see cref="T:System.Collections.ObjectModel.Collection`1" />.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        protected override void RemoveItem(int index)
        {
            Color item;
            ColorCollectionEventArgs e;
            int key;

#if USENAMEHACK
            this.SwatchNames.RemoveAt(index);
#endif

            item = this[index];
            key  = item.ToArgb();

            if (_indexedLookup != null && _indexedLookup.ContainsKey(key))
            {
                lock (_lock)
                {
                    _indexedLookup.Remove(key);
                }
            }

            base.RemoveItem(index);

            e = new ColorCollectionEventArgs(index, item);
            this.OnItemRemoved(e);
            this.OnCollectionChanged(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts an element into the <see cref="T:System.Collections.ObjectModel.Collection`1" /> 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 object to insert.</param>
        protected override void InsertItem(int index, Color item)
        {
            ColorCollectionEventArgs e;
            int key;

            base.InsertItem(index, item);

#if USENAMEHACK
            this.SwatchNames.Insert(index, string.Empty);
#endif
            key = item.ToArgb();

            if (_indexedLookup != null && index == this.Count - 1 && !_indexedLookup.ContainsKey(key))
            {
                lock (_lock)
                {
                    if (!_indexedLookup.ContainsKey(key))
                    {
                        _indexedLookup.Add(key, index);
                    }
                }
            }
            else
            {
                _indexedLookup = null;
            }

            e = new ColorCollectionEventArgs(index, item);
            this.OnItemInserted(e);
            this.OnCollectionChanged(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Replaces the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to replace.</param>
        /// <param name="item">The new value for the element at the specified index.</param>
        protected override void SetItem(int index, Color item)
        {
            ColorCollectionEventArgs e;
            Color oldItem;

            oldItem = this[index];

            if (_indexedLookup != null)
            {
                int key;
                int oldKey;

                key    = item.ToArgb();
                oldKey = oldItem.ToArgb();

                lock (_lock)
                {
                    if (_indexedLookup.ContainsKey(oldKey))
                    {
                        _indexedLookup.Remove(oldKey);
                    }
                    if (!_indexedLookup.ContainsKey(key))
                    {
                        _indexedLookup.Add(key, index);
                    }
                }
            }

            base.SetItem(index, item);

            e = new ColorCollectionEventArgs(index, item);
            this.OnItemReplaced(e);
            this.OnCollectionChanged(e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Raises the <see cref="ItemsCleared" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected virtual void OnItemsCleared(ColorCollectionEventArgs e)
        {
            EventHandler <ColorCollectionEventArgs> handler;

            handler = this.ItemsCleared;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes all elements from the <see cref="T:System.Collections.ObjectModel.Collection`1" />.
        /// </summary>
        protected override void ClearItems()
        {
            ColorCollectionEventArgs e;

            base.ClearItems();

            _indexedLookup = null;

#if USENAMEHACK
            this.SwatchNames.Clear();
#endif

            e = new ColorCollectionEventArgs(-1, Color.Empty);
            this.OnItemInserted(e);
            this.OnCollectionChanged(e);
        }
Ejemplo n.º 6
0
        private void ColorsCollectionItemReplacedHandler(object sender, ColorCollectionEventArgs e)
        {
            ColorCollection collection;
              int index;

              collection = (ColorCollection)sender;
              index = this.ColorIndex;
              if (index != InvalidIndex && collection == this.CustomColors)
              {
            index -= this.Colors.Count;
              }

              if (index >= 0 && index < collection.Count && collection[index] != this.Color)
              {
            Debug.Print("Replacing index {0} with {1}", index, collection[index]);
            this.Color = collection[index];
              }

              this.Invalidate(e.Index);
        }
Ejemplo n.º 7
0
 private void ColorsCollectionChangedHandler(object sender, ColorCollectionEventArgs e)
 {
     this.RefreshColors();
 }
Ejemplo n.º 8
0
 private void ColorCollectionChanged(object sender, ColorCollectionEventArgs e)
 {
     PaletteUpload();
 }