using System;
using System.ComponentModel;
using FastReport.Utils;
using FastReport.Data;
using System.Windows.Forms;
using System.Drawing.Design;
namespace FastReport.Dialog
{
///
/// Base class for list box controls such as ListBoxControl, CheckedListBoxControl.
///
public abstract partial class ListBoxBaseControl : DataFilterBaseControl
{
private string selectedIndexChangedEvent;
private string measureItemEvent;
private string drawItemEvent;
#region Properties
///
/// Occurs when the SelectedIndex property has changed.
/// Wraps the event.
///
public event EventHandler SelectedIndexChanged;
///
/// Occurs when an owner-drawn ListBox is created and the sizes of the list items are determined.
/// Wraps the event.
///
public event MeasureItemEventHandler MeasureItem;
///
/// Occurs when a visual aspect of an owner-drawn ListBox changes.
/// Wraps the event.
///
public event DrawItemEventHandler DrawItem;
private ListBox ListBox
{
get { return Control as ListBox; }
}
///
/// Gets or sets the width of columns in a multicolumn ListBox.
/// Wraps the property.
///
[DefaultValue(0)]
[Category("Behavior")]
public int ColumnWidth
{
get { return ListBox.ColumnWidth; }
set { ListBox.ColumnWidth = value; }
}
///
/// Gets or sets the drawing mode for the control.
/// Wraps the property.
///
[DefaultValue(DrawMode.Normal)]
[Category("Behavior")]
public virtual DrawMode DrawMode
{
get { return ListBox.DrawMode; }
set { ListBox.DrawMode = value; }
}
///
/// Gets or sets the height of an item in the ListBox.
/// Wraps the property.
///
[Category("Behavior")]
public virtual int ItemHeight
{
get { return ListBox.ItemHeight; }
set { ListBox.ItemHeight = value; }
}
///
/// Gets the items of the ListBox.
/// Wraps the property.
///
[Category("Data")]
[Editor("FastReport.TypeEditors.ItemsEditor, FastReport", typeof(UITypeEditor))]
public ListBox.ObjectCollection Items
{
get { return ListBox.Items; }
}
///
/// Gets or sets a value indicating whether the ListBox supports multiple columns.
/// Wraps the property.
///
[DefaultValue(false)]
[Category("Behavior")]
public bool MultiColumn
{
get { return ListBox.MultiColumn; }
set { ListBox.MultiColumn = value; }
}
///
/// Gets or sets the method in which items are selected in the ListBox.
/// Wraps the property.
///
[DefaultValue(SelectionMode.One)]
[Category("Behavior")]
public SelectionMode SelectionMode
{
get { return ListBox.SelectionMode; }
set { ListBox.SelectionMode = value; }
}
///
/// Gets or sets a value indicating whether the items in the ListBox are sorted alphabetically.
/// Wraps the property.
///
[DefaultValue(false)]
[Category("Behavior")]
public bool Sorted
{
get { return ListBox.Sorted; }
set { ListBox.Sorted = value; }
}
///
/// Gets or sets a value indicating whether the ListBox can recognize and expand tab characters when drawing its strings.
/// Wraps the property.
///
[DefaultValue(true)]
[Category("Behavior")]
public bool UseTabStops
{
get { return ListBox.UseTabStops; }
set { ListBox.UseTabStops = value; }
}
///
/// Gets or sets the string that contains all items text.
///
[Browsable(false)]
public virtual string ItemsText
{
get { return Converter.IListToString(Items); }
set { Converter.StringToIList(value, Items); }
}
///
/// Gets or sets the zero-based index of the currently selected item in a ListBox.
/// Wraps the property.
///
[Browsable(false)]
public int SelectedIndex
{
get { return ListBox.SelectedIndex; }
set { ListBox.SelectedIndex = value; }
}
///
/// Gets a collection that contains the zero-based indexes of all currently selected items in the ListBox.
/// Wraps the property.
///
[Browsable(false)]
public ListBox.SelectedIndexCollection SelectedIndices
{
get { return ListBox.SelectedIndices; }
}
///
/// Gets or sets the currently selected item in the ListBox.
/// Wraps the property.
///
[Browsable(false)]
public object SelectedItem
{
get { return ListBox.SelectedItem; }
set { ListBox.SelectedItem = value; }
}
///
/// Gets a collection containing the currently selected items in the ListBox.
/// Wraps the property.
///
[Browsable(false)]
public ListBox.SelectedObjectCollection SelectedItems
{
get { return ListBox.SelectedItems; }
}
///
/// Gets or sets a script method name that will be used to handle the
/// event.
///
[Category("Events")]
public string SelectedIndexChangedEvent
{
get { return selectedIndexChangedEvent; }
set { selectedIndexChangedEvent = value; }
}
///
/// Gets or sets a script method name that will be used to handle the
/// event.
///
[Category("Events")]
public string MeasureItemEvent
{
get { return measureItemEvent; }
set { measureItemEvent = value; }
}
///
/// Gets or sets a script method name that will be used to handle the
/// event.
///
[Category("Events")]
public string DrawItemEvent
{
get { return drawItemEvent; }
set { drawItemEvent = value; }
}
#endregion
#region Private Methods
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
OnSelectedIndexChanged(e);
}
private void ListBox_MeasureItem(object sender, MeasureItemEventArgs e)
{
OnMeasureItem(e);
}
private void ListBox_DrawItem(object sender, DrawItemEventArgs e)
{
OnDrawItem(e);
}
#endregion
#region Protected Methods
///
protected override void AttachEvents()
{
base.AttachEvents();
ListBox.SelectedIndexChanged += new EventHandler(ListBox_SelectedIndexChanged);
ListBox.MeasureItem += new MeasureItemEventHandler(ListBox_MeasureItem);
ListBox.DrawItem += new DrawItemEventHandler(ListBox_DrawItem);
}
///
protected override void DetachEvents()
{
base.DetachEvents();
ListBox.SelectedIndexChanged -= new EventHandler(ListBox_SelectedIndexChanged);
ListBox.MeasureItem -= new MeasureItemEventHandler(ListBox_MeasureItem);
ListBox.DrawItem -= new DrawItemEventHandler(ListBox_DrawItem);
}
///
protected override void FillData(DataSourceBase dataSource, Column column)
{
Items.Clear();
Items.AddRange(GetListOfData(dataSource, column));
if (Items.Count > 0)
SelectedIndex = 0;
}
#endregion
#region Public Methods
///
public override void Serialize(FRWriter writer)
{
ListBoxBaseControl c = writer.DiffObject as ListBoxBaseControl;
base.Serialize(writer);
if (ColumnWidth != c.ColumnWidth)
writer.WriteInt("ColumnWidth", ColumnWidth);
if (DrawMode != c.DrawMode)
writer.WriteValue("DrawMode", DrawMode);
if (ItemHeight != c.ItemHeight)
writer.WriteInt("ItemHeight", ItemHeight);
if (MultiColumn != c.MultiColumn)
writer.WriteBool("MultiColumn", MultiColumn);
if (SelectionMode != c.SelectionMode)
writer.WriteValue("SelectionMode", SelectionMode);
if (Sorted != c.Sorted)
writer.WriteBool("Sorted", Sorted);
if (UseTabStops != c.UseTabStops)
writer.WriteBool("UseTabStops", UseTabStops);
if (ItemsText != c.ItemsText)
writer.WriteStr("ItemsText", ItemsText);
if (SelectedIndexChangedEvent != c.SelectedIndexChangedEvent)
writer.WriteStr("SelectedIndexChangedEvent", SelectedIndexChangedEvent);
if (MeasureItemEvent != c.MeasureItemEvent)
writer.WriteStr("MeasureItemEvent", MeasureItemEvent);
if (DrawItemEvent != c.DrawItemEvent)
writer.WriteStr("DrawItemEvent", DrawItemEvent);
}
///
/// This method fires the SelectedIndexChanged event and the script code connected to the SelectedIndexChangedEvent.
///
/// Event data.
public virtual void OnSelectedIndexChanged(EventArgs e)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged(this, e);
InvokeEvent(SelectedIndexChangedEvent, e);
}
///
/// This method fires the MeasureItem event and the script code connected to the MeasureItemEvent.
///
/// Event data.
public virtual void OnMeasureItem(MeasureItemEventArgs e)
{
if (MeasureItem != null)
MeasureItem(this, e);
InvokeEvent(MeasureItemEvent, e);
}
///
/// This method fires the DrawItem event and the script code connected to the DrawItemEvent.
///
/// Event data.
public virtual void OnDrawItem(DrawItemEventArgs e)
{
if (DrawItem != null)
DrawItem(this, e);
InvokeEvent(DrawItemEvent, e);
}
#endregion
}
}