using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Storm.CodeCompletion
{
/// <summary>
/// Class inheriting the TreeNode. Acts as item for the main class, GListBox.
/// </summary>
public class GListBoxItem
: TreeNode, IComparable
{
#region Fields
private string _text = "";
private string _description = "";
private string _declaration = "";
private object _tag = "";
private int _imageIndex = -1;
private MemberType _memberType = MemberType.Normal;
private CompleteType _completeType = CompleteType.Normal;
#endregion
#region Properties
/// <summary>
/// Gets or sets the Text of the GListBoxItem.
/// </summary>
public new string Text
{
get { return base.Text; }
set
{
this._text = value;
base.Text = this._text;
}
}
/// <summary>
/// Gets or sets the Description of the GListBoxItem.
/// The Description is what is showed in the tooltip.
/// </summary>
public string Description
{
get { return this._description; }
set { this._description = value; }
}
/// <summary>
/// Gets or sets the Declaration of the GListBoxItem.
/// The Declaration is what is showed in the tooltip.
/// </summary>
public string Declaration
{
get { return this._declaration; }
set { this._declaration = value; }
}
/// <summary>
/// Gets or sets the ImageIndex of the GListBoxItem.
/// </summary>
public new int ImageIndex
{
get { return base.ImageIndex; }
set
{
this._imageIndex = value;
base.ImageIndex = this._imageIndex;
}
}
/// <summary>
/// Gets or sets the Tag of the GListBoxItem.
/// </summary>
public new object Tag
{
get { return base.Tag; }
set
{
this._tag = value;
base.Tag = this._tag;
}
}
/// <summary>
/// Gets or sets the MemberType of the GListBoxItem.
/// </summary>
public MemberType MemberType
{
get { return this._memberType; }
set { this._memberType = value; }
}
/// <summary>
/// Gets or sets how the GListBoxItem should complete itself.
/// </summary>
public CompleteType CompleteType
{
get { return this._completeType; }
set { this._completeType = value; }
}
#endregion
#region Methods
#region Public
/// <summary>
/// Compares the GListBoxItem to another GListBoxItem.
/// </summary>
/// <param name="obj">Object to compare to.</param>
/// <returns>Variable value depending on how the two GListBoxItems were alike.</returns>
public int CompareTo(object obj)
{
if (((obj) is GListBoxItem))
{
GListBoxItem memberItem = (GListBoxItem)obj;
return (Text.CompareTo(memberItem.Text));
}
else
{
throw new ArgumentException();
}
}
/// <summary>
/// Gets the GListBoxItem typecasted to string.
/// </summary>
/// <returns>GListBoxItem typecasted to string.</returns>
public override string ToString()
{ return this.Text; }
#endregion
#endregion
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
public GListBoxItem()
: this("")
{ }
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
public GListBoxItem(string text)
: this(text, -1)
{ }
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="imageIndex">Image for the GListBoxItem to display.</param>
public GListBoxItem(string text, int imageIndex)
{
this.Text = text;
this.ImageIndex = imageIndex;
}
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="memberType">MemberType value for the GListBoxItem.</param>
public GListBoxItem(string text, MemberType memberType)
{
this.Text = text;
this.MemberType = memberType;
}
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="imageIndex">Image for the GListBoxItem to display.</param>
/// <param name="memberType">MemberType value for the GListBoxItem.</param>
public GListBoxItem(string text, int imageIndex, MemberType memberType)
{
this.Text = text;
this.ImageIndex = imageIndex;
this.MemberType = memberType;
}
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="imageIndex">Image for the GListBoxItem to display.</param>
/// <param name="memberType">MemberType value for the GListBoxItem.</param>
/// <param name="description">Description value for the GListBoxItem.</param>
public GListBoxItem(string text, int imageIndex, MemberType memberType, string description)
{
this.Text = text;
this.ImageIndex = imageIndex;
this.MemberType = memberType;
this.Description = description;
}
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="imageIndex">Image for the GListBoxItem to display.</param>
/// <param name="memberType">MemberType value for the GListBoxItem.</param>
/// <param name="description">Description value for the GListBoxItem.</param>
/// <param name="declaration">Declaration value for the GListBoxItem.</param>
public GListBoxItem(string text, int imageIndex, MemberType memberType,
string description, string declaration)
{
this.Text = text;
this.ImageIndex = imageIndex;
this.MemberType = memberType;
this.Description = description;
this.Declaration = declaration;
}
/// <summary>
/// Initializes the GListBoxItem.
/// </summary>
/// <param name="text">Text for the GListBoxItem to display.</param>
/// <param name="imageIndex">Image for the GListBoxItem to display.</param>
/// <param name="memberType">MemberType value for the GListBoxItem.</param>
/// <param name="description">Description value for the GListBoxItem.</param>
/// <param name="declaration">Declaration value for the GListBoxItem.</param>
/// <param name="completeType">How the GListBoxItem should complete itself.</param>
public GListBoxItem(string text, int imageIndex, MemberType memberType,
string description, string declaration, CompleteType completeType)
{
this.Text = text;
this.ImageIndex = imageIndex;
this.MemberType = memberType;
this.Description = description;
this.Declaration = declaration;
this.CompleteType = completeType;
}
}
/// <summary>
/// Class inheriting from the ListBox control, which consists of GListBoxItems instead of normal ListBoxItems. GListBoxItems are able to have images.
/// </summary>
public class GListBox
: ListBox
{
#region Fields
private ImageList _imageList;
#endregion
#region Properties
/// <summary>
/// Gets or sets the ImageList of the GListBox.
/// </summary>
public ImageList ImageList
{
get { return this._imageList; }
set { this._imageList = value; }
}
#endregion
#region Methods
#region Protected
/// <summary>
/// Draws items in the GListBox.
/// </summary>
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
GListBoxItem item = default(GListBoxItem);
Rectangle bounds = e.Bounds;
Size imageSize = _imageList.ImageSize;
try
{
item = (GListBoxItem)Items[e.Index];
if (item.ImageIndex > -1)
{
this._imageList.Draw(e.Graphics, bounds.Left,
bounds.Top, item.ImageIndex);
e.Graphics.DrawString(item.Text, e.Font, new SolidBrush
(e.ForeColor), bounds.Left + imageSize.Width, bounds.Top);
}
else
{
e.Graphics.DrawString(item.Text, e.Font, new SolidBrush
(e.ForeColor), bounds.Left, bounds.Top);
}
}
catch
{
if ((e.Index != -1))
{
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font,
new SolidBrush(e.ForeColor), bounds.Left, bounds.Top);
}
else
{
e.Graphics.DrawString(this.Text, e.Font, new SolidBrush
(e.ForeColor), bounds.Left, bounds.Top);
}
}
}
#endregion
#endregion
/// <summary>
/// Initializes the GListBox.
/// </summary>
public GListBox()
{ this.DrawMode = DrawMode.OwnerDrawFixed; }
}
}