| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
- //
- // Author:
- // Ravindra ([email protected])
- //
- // $Revision: 1.1 $
- // $Modtime: $
- // $Log: ListViewItem.cs,v $
- // Revision 1.1 2004/09/30 13:24:45 ravindra
- // Initial implementation.
- //
- //
- // NOT COMPLETE
- //
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Runtime.Serialization;
- namespace System.Windows.Forms
- {
- [Serializable]
- public class ListViewItem : ICloneable, ISerializable
- {
- #region Instance Variables
- private Color backColor;
- private Font font = ThemeEngine.Current.DefaultFont;
- private Color foreColor;
- private int imageIndex = -1;
- private bool isChecked = false;
- private bool isFocused = false;
- internal ListView owner;
- private bool selected;
- private int stateImageIndex = -1;
- private ListViewSubItemCollection subItems;
- private object tag;
- private string text;
- private bool useItemStyle = true;
- #endregion Instance Variables
- #region Public Constructors
- public ListViewItem ()
- {
- this.subItems = new ListViewSubItemCollection (this);
- }
- public ListViewItem (string text) : this (text, -1)
- {
- }
- public ListViewItem (string [] items) : this (items, -1)
- {
- }
- public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
- {
- this.subItems = new ListViewSubItemCollection (this);
- this.subItems.AddRange (subItems);
- this.imageIndex = imageIndex;
- }
- public ListViewItem (string text, int imageIndex)
- {
- this.text = text;
- this.imageIndex = imageIndex;
- this.subItems = new ListViewSubItemCollection (this);
- }
- public ListViewItem (string [] items, int imageIndex)
- {
- this.subItems = new ListViewSubItemCollection (this);
- this.subItems.AddRange (items);
- this.imageIndex = imageIndex;
- }
- public ListViewItem (string [] items, int imageIndex, Color foreColor,
- Color backColor, Font font)
- {
- this.subItems = new ListViewSubItemCollection (this);
- this.subItems.AddRange (items);
- this.imageIndex = imageIndex;
- this.foreColor = foreColor;
- this.backColor = backColor;
- this.font = font;
- }
- #endregion // Public Constructors
- #region Public Instance Properties
- public Color BackColor {
- get { return backColor; }
- set { this.backColor = value; }
- }
- public Rectangle Bounds {
- get {
- return GetBounds (ItemBoundsPortion.Entire);
- }
- }
- public bool Checked {
- get { return isChecked; }
- set { isChecked = value; }
- }
- public bool Focused {
- get { return isFocused; }
- set { isFocused = value; }
- }
- public Font Font {
- get { return font; }
- set { font = value; }
- }
- public Color ForeColor {
- get { return foreColor; }
- set { foreColor = value; }
- }
- public int ImageIndex {
- get { return imageIndex; }
- set {
- if (value < -1)
- throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
- imageIndex = value;
- }
- }
- public ImageList ImageList {
- get {
- if (owner == null)
- return null;
- else if (owner.View == View.LargeIcon)
- return owner.largeImageList;
- else
- return owner.smallImageList;
- }
- }
- public int Index {
- get {
- if (owner == null)
- return -1;
- else
- return owner.Items.IndexOf (this);
- }
- }
- public ListView ListView {
- get { return owner; }
- }
- public bool Selected {
- get { return selected; }
- set {
- if (value != selected) {
- selected = value;
- if (owner != null && owner.MultiSelect) {
- if (selected)
- //do we need !owner.SelectedItems.Contains (this))
- owner.SelectedItems.list.Add (this);
- else
- owner.SelectedItems.list.Remove (this);
- }
- }
- }
- }
- public int StateImageIndex {
- get { return stateImageIndex; }
- set {
- if (value < -1 || value > 14)
- throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
- stateImageIndex = value;
- }
- }
- public ListViewSubItemCollection SubItems {
- get { return subItems; }
- }
- public object Tag {
- get { return tag; }
- set { tag = value; }
- }
- public string Text {
- get { return text; }
- set { text = value; }
- }
- public bool UseItemStyleForSubItems {
- get { return useItemStyle; }
- set { useItemStyle = value; }
- }
- #endregion // Public Instance Properties
- #region Public Instance Methods
- public void BeginEdit ()
- {
- // FIXME: TODO
- // if (owner != null && owner.LabelEdit)
- // allow editing
- // else
- // throw new InvalidOperationException ();
- }
- public virtual object Clone ()
- {
- // FIXME: TODO
- return new ListViewItem ();
- }
- public virtual void EnsureVisible ()
- {
- // FIXME: TODO
- }
- public Rectangle GetBounds (ItemBoundsPortion portion)
- {
- // FIXME: TODO
- return new Rectangle (0, 0, 0, 0);
- }
- void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
- {
- // FIXME: TODO
- }
- public virtual void Remove ()
- {
- if (owner != null)
- owner.Items.Remove (this);
- owner = null;
- }
- public override string ToString ()
- {
- return string.Format ("ListViewItem: {{0}}", text);
- }
- #endregion // Public Instance Methods
- #region Protected Methods
- protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
- {
- // FIXME: TODO
- }
- protected virtual void Serialize (SerializationInfo info, StreamingContext context)
- {
- // FIXME: TODO
- }
- #endregion // Protected Methods
- #region Subclasses
- [Serializable]
- public class ListViewSubItem
- {
- private Color backColor;
- private Font font;
- private Color foreColor;
- internal ListViewItem owner;
- private string text;
-
- #region Public Constructors
- public ListViewSubItem ()
- {
- }
- public ListViewSubItem (ListViewItem owner, string text)
- {
- this.owner = owner;
- this.text = text;
- }
- public ListViewSubItem (ListViewItem owner, string text, Color foreColor, Color backColor, Font font)
- {
- this.owner = owner;
- this.text = text;
- this.foreColor = foreColor;
- this.backColor = backColor;
- this.font = font;
- }
- #endregion // Public Constructors
- #region Public Instance Properties
- public Color BackColor {
- get { return backColor; }
- set { backColor = value; }
- }
- public Font Font {
- get { return font; }
- set { font = value; }
- }
- public Color ForeColor {
- get { return foreColor; }
- set { foreColor = value; }
- }
- public string Text {
- get { return text; }
- set { text = value; }
- }
- #endregion // Public Instance Properties
- #region Public Methods
- public void ResetStyle ()
- {
- font = ThemeEngine.Current.DefaultFont;
- backColor = ThemeEngine.Current.DefaultControlBackColor;
- foreColor = ThemeEngine.Current.DefaultControlForeColor;
- }
- public override string ToString ()
- {
- return string.Format ("ListViewSubItem {{0}}", text);
- }
- #endregion // Public Methods
- }
- public class ListViewSubItemCollection : IList, ICollection, IEnumerable
- {
- private ArrayList list;
- internal ListViewItem owner;
- #region Public Constructors
- public ListViewSubItemCollection (ListViewItem owner)
- {
- this.owner = owner;
- this.list = new ArrayList ();
- }
- #endregion // Public Constructors
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return false; }
- }
- public ListViewSubItem this [int index] {
- get { return (ListViewSubItem) list [index]; }
- set {
- value.owner = this.owner;
- list [index] = value;
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set {
- if (! (value is ListViewSubItem))
- throw new ArgumentException("Not of type ListViewSubItem", "value");
- this [index] = (ListViewSubItem) value;
- }
- }
- #endregion // Public Properties
- #region Public Methods
- public ListViewSubItem Add (ListViewSubItem item)
- {
- item.owner = this.owner;
- list.Add (item);
- return item;
- }
- public ListViewSubItem Add (string text)
- {
- ListViewSubItem item = new ListViewSubItem (this.owner, text);
- list.Add (item);
- return item;
- }
- public ListViewSubItem Add (string text, Color foreColor, Color backColor, Font font)
- {
- ListViewSubItem item = new ListViewSubItem (this.owner, text, foreColor, backColor, font);
- list.Add (item);
- return item;
- }
- public void AddRange (ListViewSubItem [] items)
- {
- list.Clear ();
- foreach (ListViewSubItem item in items)
- this.Add (item);
- }
- public void AddRange (string [] items)
- {
- list.Clear ();
- foreach (string item in items)
- this.Add (item);
- }
- public void AddRange (string [] items, Color foreColor, Color backColor, Font font)
- {
- list.Clear ();
- foreach (string item in items)
- this.Add (item, foreColor, backColor, font);
- }
- public virtual void Clear ()
- {
- list.Clear ();
- }
- public bool Contains (ListViewSubItem item)
- {
- return list.Contains (item);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- void ICollection.CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- int IList.Add (object item)
- {
- if (! (item is ListViewSubItem)) {
- throw new ArgumentException("Not of type ListViewSubItem", "item");
- }
- ListViewSubItem subItem = (ListViewSubItem) item;
- subItem.owner = this.owner;
- return list.Add (subItem);
- }
- bool IList.Contains (object subItem)
- {
- if (! (subItem is ListViewSubItem)) {
- throw new ArgumentException("Not of type ListViewSubItem", "subItem");
- }
- return this.Contains ((ListViewSubItem) subItem);
- }
- int IList.IndexOf (object subItem)
- {
- if (! (subItem is ListViewSubItem)) {
- throw new ArgumentException("Not of type ListViewSubItem", "subItem");
- }
- return this.IndexOf ((ListViewSubItem) subItem);
- }
- void IList.Insert (int index, object item)
- {
- if (! (item is ListViewSubItem)) {
- throw new ArgumentException("Not of type ListViewSubItem", "item");
- }
- this.Insert (index, (ListViewSubItem) item);
- }
- void IList.Remove (object item)
- {
- if (! (item is ListViewSubItem)) {
- throw new ArgumentException("Not of type ListViewSubItem", "item");
- }
- this.Remove ((ListViewSubItem) item);
- }
- public int IndexOf (ListViewSubItem subItem)
- {
- return list.IndexOf (subItem);
- }
- public void Insert (int index, ListViewSubItem item)
- {
- item.owner = this.owner;
- list.Insert (index, item);
- }
- public void Remove (ListViewSubItem item)
- {
- list.Remove (item);
- }
- public virtual void RemoveAt (int index)
- {
- list.RemoveAt (index);
- }
- #endregion // Public Methods
- }
- #endregion // Subclasses
- }
- }
|