// (c) 2003-2005 Datron, Inc. All rights reserved. http://www.blix.net
using System;
using System.Runtime.Serialization;
using UITestingFramework;
namespace freeBlix
{
[Serializable]
public class PaintState: CaseState, ISerializable, IColorCollection, ILeft, ITop, IRight, IBottom, IWidth, IHeight, IPaintStateCollection
{
#region Fields
private System.Drawing.Bitmap _Offscreen;
private RectangleColorSample _ColorSample;
private int _Left;
private int _Top;
private int _Right;
private int _Bottom;
private int _Width;
private int _Height;
private PaintStateCollection _States;
private string _ControlType;
#endregion
#region PaintState()
public PaintState()
{
_States = new PaintStateCollection();
}
#endregion
#region ExtractTestValues
public override void ExtractTestValues()
{
Control control = (Control) TestObject;
_ControlType = control.GetType().Name;
_ColorSample = new RectangleColorSample(control, _Offscreen);
if (((IBounds) control).Bounds is Rectangle)
{
Rectangle rectangle = (Rectangle) ((IBounds)control).Bounds;
_Left = rectangle.Left;
_Top = rectangle.Top;
_Right = rectangle.Right;
_Bottom = rectangle.Bottom;
_Width = rectangle.Width;
_Height = rectangle.Height;
}
_States.Clear();
if (control is ControlOverlay)
{
ControlOverlay controlOverlay = (ControlOverlay) control;
foreach (Control childControl in ((IChildren)controlOverlay).Children.Controls)
{
PaintState childState = new PaintState();
childState.Offscreen = _Offscreen;
childState.TestObject = childControl;
childState.ExtractTestValues();
_States.Add(childState);
}
}
}
#endregion
#region ControlType
public string ControlType
{
get
{
return _ControlType;
}
}
#endregion
#region Offscreen
public System.Drawing.Bitmap Offscreen
{
get
{
return _Offscreen;
}
set
{
_Offscreen = value;
}
}
#endregion
#region IColorCollection
ColorCollection IColorCollection.Colors
{
get
{
if (_ColorSample != null)
return _ColorSample.Colors;
else
return new ColorCollection();
}
}
#endregion
#region ILeft
int ILeft.Left
{
get
{
return _Left;
}
}
#endregion
#region ITop
int ITop.Top
{
get
{
return _Top;
}
}
#endregion
#region IWidth
int IWidth.Width
{
get
{
return _Width;
}
}
#endregion
#region IHeight
int IHeight.Height
{
get
{
return _Height;
}
}
#endregion
#region IRight
int IRight.Right
{
get
{
return _Right;
}
}
#endregion
#region IBottom
int IBottom.Bottom
{
get
{
return _Bottom;
}
}
#endregion
#region IPaintStateCollection
PaintStateCollection IPaintStateCollection.States
{
get
{
return _States;
}
}
#endregion
#region ISerializable
protected PaintState(SerializationInfo aInfo, StreamingContext aContext)
{
_ColorSample = (RectangleColorSample) aInfo.GetValue("_ColorSample", typeof(RectangleColorSample));
_States = (PaintStateCollection) aInfo.GetValue("_States", typeof(PaintStateCollection));
_ControlType = (string) aInfo.GetValue("_ControlType", typeof(string));
_Left = (int) aInfo.GetValue("_Left", typeof(int));
_Top = (int) aInfo.GetValue("_Top", typeof(int));
_Right = (int) aInfo.GetValue("_Right", typeof(int));
_Bottom = (int) aInfo.GetValue("_Bottom", typeof(int));
_Width = (int) aInfo.GetValue("_Width", typeof(int));
_Height = (int) aInfo.GetValue("_Height", typeof(int));
}
public override void GetObjectData(SerializationInfo aInfo, StreamingContext aContext)
{
aInfo.AddValue("_ColorSample", _ColorSample);
aInfo.AddValue("_States", _States);
aInfo.AddValue("_ControlType", _ControlType);
aInfo.AddValue("_Left", _Left);
aInfo.AddValue("_Top", _Top);
aInfo.AddValue("_Right", _Right);
aInfo.AddValue("_Bottom", _Bottom);
aInfo.AddValue("_Width", _Width);
aInfo.AddValue("_Height", _Height);
}
#endregion
}
}