|
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using OGCLib;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("OGCComboBoxLib")]
[assembly: AssemblyDescription("This assembly contains classes for the combo box element.")]
[assembly: AssemblyCompany("Igor Ladnik")]
[assembly: AssemblyProduct("Open Group Control")]
[assembly: AssemblyVersion("1.2.*")]
namespace OGCComboBoxLib
{
///////////////////////////////////////////////////////////////////////////////////
// Class CBComboBox
///////////////////////////////////////////////////////////////////////////////////
public class OGCComboBox : ComboBox, IElement
{
// Variables
private int id;
private OGControl ogControl = null;
// Specify positions of element for hrizontal and vertical orientation of control
private Point horizPosition;
private Point vertPosition;
// Number of element's states
private int statesMax = 0;
// State Transition matrix
private int[,] aiControlStateTransition = null;
// false - if SetCurrentState(int currentState) method of element has not been called yet.
// true - otherwise
private bool selectionChanged = false;
private bool justStarted = true;
// CONSTRUCTOR
public OGCComboBox(OGControl ogControl)
{
this.ogControl = ogControl;
Visible = false;
}
// METHODS
// Virtual
protected override void OnSelectionChangeCommitted(EventArgs ea)
{
selectionChanged = true;
}
protected override void OnSelectedValueChanged(EventArgs ea)
{
if (null != ogControl && selectionChanged)
{
ogControl.HitElement = this;
ogControl.ChangeState(GetNewControlState());
}
selectionChanged = false;
}
// IElement implementation methods
public void Initialize(string name, Point horizPosition, Point vertPosition, Size size)
{
if (null != ogControl)
{
Name = name;
id = ogControl.VisualElementsNumber;
this.horizPosition = horizPosition;
this.vertPosition = vertPosition;
this.horizPosition.Y += ogControl.CaptionHeight;
this.vertPosition.Y += ogControl.CaptionHeight;
UpdateGeometry();
Size = size;
Visible = true;
}
}
public void SetControlStateTransitionElement(int currCtrlState, int currState,
int nextCtrlState)
{
if (null == aiControlStateTransition)
{
aiControlStateTransition = new int[ogControl.ControlStatesMax, statesMax];
for (int i=0; i<ogControl.ControlStatesMax; i++)
for (int j=0; j<statesMax; j++)
aiControlStateTransition[i, j] = -1;
}
aiControlStateTransition[currCtrlState, currState] = nextCtrlState;
}
public int AddState(string name, string pictureName, string ext)
{
Items.Add(name);
return ++statesMax;
}
public int GetNewControlState()
{
if (null != ogControl && null != aiControlStateTransition)
return aiControlStateTransition[ogControl.CurrentState, SelectedIndex];
return -1;
}
public void SetCurrentState(int currentState)
{
if (-1 < currentState && Items.Count > currentState)
{
SelectedIndex = currentState;
Update();
}
if (-1 == currentState && justStarted)
{
SelectedIndex = 0;
Update();
}
justStarted = false;
}
public bool HasImage()
{
return false;
}
public string GetName()
{
return Name;
}
public int GetId()
{
return id;
}
public string GetStateName()
{
return SelectedItem.ToString();
}
public int GetNextStatesNum()
{
return Items.Count;
}
public void UpdateGeometry()
{
Point position = OGCLib.Orientation.Horizontal == ogControl.GetOrientation()
? horizPosition : vertPosition;
Left = position.X;
Top = position.Y;
}
public void Draw(Graphics grfx, bool show)
{
Visible = show;
}
public bool HitTest(MouseEventArgs mea)
{
return false;
}
}
///////////////////////////////////////////////////////////////////////////////////
// Class Factory
///////////////////////////////////////////////////////////////////////////////////
public class Factory : IFactory
{
public IElement CreateElement(OGControl ogControl)
{
OGCComboBox comboBox = new OGCComboBox(ogControl);
ogControl.Controls.Add(comboBox);
return comboBox;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.