Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / figurelength.cs / 1305600 / figurelength.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Figure length implementation
//
//
// History:
// 06/23/2005 : ghermann - Created - Adapted from GridLength
//
//---------------------------------------------------------------------------
using MS.Internal;
using System.ComponentModel;
using System.Globalization;
using MS.Internal.PtsHost.UnsafeNativeMethods; // PTS restrictions
namespace System.Windows
{
///
/// FigureUnitType enum is used to indicate what kind of value the
/// FigureLength is holding.
///
public enum FigureUnitType
{
///
/// The value indicates that content should be calculated without constraints.
///
Auto = 0,
///
/// The value is expressed as a pixel.
///
Pixel,
///
/// The value is expressed as fraction of column width.
///
Column,
///
/// The value is expressed as a fraction of content width.
///
Content,
///
/// The value is expressed as a fraction of page width.
///
Page,
}
///
/// FigureLength is the type used for height and width on figure element
///
[TypeConverter(typeof(FigureLengthConverter))]
public struct FigureLength : IEquatable
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor, initializes the FigureLength as absolute value in pixels.
///
/// Specifies the number of 'device-independent pixels'
/// (96 pixels-per-inch).
///
/// If pixels parameter is double.NaN
/// or pixels parameter is double.NegativeInfinity
/// or pixels parameter is double.PositiveInfinity .
/// or value parameter is negative .
///
public FigureLength(double pixels)
: this(pixels, FigureUnitType.Pixel)
{
}
///
/// Constructor, initializes the FigureLength and specifies what kind of value
/// it will hold.
///
/// Value to be stored by this FigureLength
/// instance.
/// Type of the value to be stored by this FigureLength
/// instance.
///
/// If the type parameter is FigureUnitType.Auto ,
/// then passed in value is ignored and replaced with 0 .
///
///
/// If value parameter is double.NaN
/// or value parameter is double.NegativeInfinity
/// or value parameter is double.PositiveInfinity .
/// or value parameter is negative .
///
public FigureLength(double value, FigureUnitType type)
{
double maxColumns = PTS.Restrictions.tscColumnRestriction;
double maxPixel = Math.Min(1000000, PTS.MaxPageSize);
if (DoubleUtil.IsNaN(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value"));
}
if (double.IsInfinity(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoInfinity, "value"));
}
if (value < 0.0)
{
throw new ArgumentOutOfRangeException(SR.Get(SRID.InvalidCtorParameterNoNegative, "value"));
}
if ( type != FigureUnitType.Auto
&& type != FigureUnitType.Pixel
&& type != FigureUnitType.Column
&& type != FigureUnitType.Content
&& type != FigureUnitType.Page )
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterUnknownFigureUnitType, "type"));
}
if(value > 1.0 && (type == FigureUnitType.Content || type == FigureUnitType.Page))
{
throw new ArgumentOutOfRangeException("value");
}
if (value > maxColumns && type == FigureUnitType.Column)
{
throw new ArgumentOutOfRangeException("value");
}
if (value > maxPixel && type == FigureUnitType.Pixel)
{
throw new ArgumentOutOfRangeException("value");
}
_unitValue = (type == FigureUnitType.Auto) ? 0.0 : value;
_unitType = type;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Overloaded operator, compares 2 FigureLengths.
///
/// first FigureLength to compare.
/// second FigureLength to compare.
/// true if specified FigureLengths have same value
/// and unit type.
public static bool operator == (FigureLength fl1, FigureLength fl2)
{
return ( fl1.FigureUnitType == fl2.FigureUnitType
&& fl1.Value == fl2.Value );
}
///
/// Overloaded operator, compares 2 FigureLengths.
///
/// first FigureLength to compare.
/// second FigureLength to compare.
/// true if specified FigureLengths have either different value or
/// unit type.
public static bool operator != (FigureLength fl1, FigureLength fl2)
{
return ( fl1.FigureUnitType != fl2.FigureUnitType
|| fl1.Value != fl2.Value );
}
///
/// Compares this instance of FigureLength with another object.
///
/// Reference to an object for comparison.
/// true if this FigureLength instance has the same value
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
if(oCompare is FigureLength)
{
FigureLength l = (FigureLength)oCompare;
return (this == l);
}
else
return false;
}
///
/// Compares this instance of FigureLength with another object.
///
/// FigureLength to compare.
/// true if this FigureLength instance has the same value
/// and unit type as figureLength.
public bool Equals(FigureLength figureLength)
{
return (this == figureLength);
}
///
///
///
///
public override int GetHashCode()
{
return ((int)_unitValue + (int)_unitType);
}
///
/// Returns true if this FigureLength instance holds
/// an absolute (pixel) value.
///
public bool IsAbsolute { get { return (_unitType == FigureUnitType.Pixel); } }
///
/// Returns true if this FigureLength instance is
/// automatic (not specified).
///
public bool IsAuto { get { return (_unitType == FigureUnitType.Auto); } }
///
/// Returns true if this FigureLength instance is column relative.
///
public bool IsColumn { get { return (_unitType == FigureUnitType.Column); } }
///
/// Returns true if this FigureLength instance is content relative.
///
public bool IsContent { get { return (_unitType == FigureUnitType.Content); } }
///
/// Returns true if this FigureLength instance is page relative.
///
public bool IsPage { get { return (_unitType == FigureUnitType.Page); } }
///
/// Returns value part of this FigureLength instance.
///
public double Value { get { return ((_unitType == FigureUnitType.Auto) ? 1.0 : _unitValue); } }
///
/// Returns unit type of this FigureLength instance.
///
public FigureUnitType FigureUnitType { get { return (_unitType); } }
///
/// Returns the string representation of this object.
///
public override string ToString()
{
return FigureLengthConverter.ToString(this, CultureInfo.InvariantCulture);
}
#endregion Public Methods
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private double _unitValue; // unit value storage
private FigureUnitType _unitType; // unit type storage
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Figure length implementation
//
//
// History:
// 06/23/2005 : ghermann - Created - Adapted from GridLength
//
//---------------------------------------------------------------------------
using MS.Internal;
using System.ComponentModel;
using System.Globalization;
using MS.Internal.PtsHost.UnsafeNativeMethods; // PTS restrictions
namespace System.Windows
{
///
/// FigureUnitType enum is used to indicate what kind of value the
/// FigureLength is holding.
///
public enum FigureUnitType
{
///
/// The value indicates that content should be calculated without constraints.
///
Auto = 0,
///
/// The value is expressed as a pixel.
///
Pixel,
///
/// The value is expressed as fraction of column width.
///
Column,
///
/// The value is expressed as a fraction of content width.
///
Content,
///
/// The value is expressed as a fraction of page width.
///
Page,
}
///
/// FigureLength is the type used for height and width on figure element
///
[TypeConverter(typeof(FigureLengthConverter))]
public struct FigureLength : IEquatable
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor, initializes the FigureLength as absolute value in pixels.
///
/// Specifies the number of 'device-independent pixels'
/// (96 pixels-per-inch).
///
/// If pixels parameter is double.NaN
/// or pixels parameter is double.NegativeInfinity
/// or pixels parameter is double.PositiveInfinity .
/// or value parameter is negative .
///
public FigureLength(double pixels)
: this(pixels, FigureUnitType.Pixel)
{
}
///
/// Constructor, initializes the FigureLength and specifies what kind of value
/// it will hold.
///
/// Value to be stored by this FigureLength
/// instance.
/// Type of the value to be stored by this FigureLength
/// instance.
///
/// If the type parameter is FigureUnitType.Auto ,
/// then passed in value is ignored and replaced with 0 .
///
///
/// If value parameter is double.NaN
/// or value parameter is double.NegativeInfinity
/// or value parameter is double.PositiveInfinity .
/// or value parameter is negative .
///
public FigureLength(double value, FigureUnitType type)
{
double maxColumns = PTS.Restrictions.tscColumnRestriction;
double maxPixel = Math.Min(1000000, PTS.MaxPageSize);
if (DoubleUtil.IsNaN(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value"));
}
if (double.IsInfinity(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoInfinity, "value"));
}
if (value < 0.0)
{
throw new ArgumentOutOfRangeException(SR.Get(SRID.InvalidCtorParameterNoNegative, "value"));
}
if ( type != FigureUnitType.Auto
&& type != FigureUnitType.Pixel
&& type != FigureUnitType.Column
&& type != FigureUnitType.Content
&& type != FigureUnitType.Page )
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterUnknownFigureUnitType, "type"));
}
if(value > 1.0 && (type == FigureUnitType.Content || type == FigureUnitType.Page))
{
throw new ArgumentOutOfRangeException("value");
}
if (value > maxColumns && type == FigureUnitType.Column)
{
throw new ArgumentOutOfRangeException("value");
}
if (value > maxPixel && type == FigureUnitType.Pixel)
{
throw new ArgumentOutOfRangeException("value");
}
_unitValue = (type == FigureUnitType.Auto) ? 0.0 : value;
_unitType = type;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Overloaded operator, compares 2 FigureLengths.
///
/// first FigureLength to compare.
/// second FigureLength to compare.
/// true if specified FigureLengths have same value
/// and unit type.
public static bool operator == (FigureLength fl1, FigureLength fl2)
{
return ( fl1.FigureUnitType == fl2.FigureUnitType
&& fl1.Value == fl2.Value );
}
///
/// Overloaded operator, compares 2 FigureLengths.
///
/// first FigureLength to compare.
/// second FigureLength to compare.
/// true if specified FigureLengths have either different value or
/// unit type.
public static bool operator != (FigureLength fl1, FigureLength fl2)
{
return ( fl1.FigureUnitType != fl2.FigureUnitType
|| fl1.Value != fl2.Value );
}
///
/// Compares this instance of FigureLength with another object.
///
/// Reference to an object for comparison.
/// true if this FigureLength instance has the same value
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
if(oCompare is FigureLength)
{
FigureLength l = (FigureLength)oCompare;
return (this == l);
}
else
return false;
}
///
/// Compares this instance of FigureLength with another object.
///
/// FigureLength to compare.
/// true if this FigureLength instance has the same value
/// and unit type as figureLength.
public bool Equals(FigureLength figureLength)
{
return (this == figureLength);
}
///
///
///
///
public override int GetHashCode()
{
return ((int)_unitValue + (int)_unitType);
}
///
/// Returns true if this FigureLength instance holds
/// an absolute (pixel) value.
///
public bool IsAbsolute { get { return (_unitType == FigureUnitType.Pixel); } }
///
/// Returns true if this FigureLength instance is
/// automatic (not specified).
///
public bool IsAuto { get { return (_unitType == FigureUnitType.Auto); } }
///
/// Returns true if this FigureLength instance is column relative.
///
public bool IsColumn { get { return (_unitType == FigureUnitType.Column); } }
///
/// Returns true if this FigureLength instance is content relative.
///
public bool IsContent { get { return (_unitType == FigureUnitType.Content); } }
///
/// Returns true if this FigureLength instance is page relative.
///
public bool IsPage { get { return (_unitType == FigureUnitType.Page); } }
///
/// Returns value part of this FigureLength instance.
///
public double Value { get { return ((_unitType == FigureUnitType.Auto) ? 1.0 : _unitValue); } }
///
/// Returns unit type of this FigureLength instance.
///
public FigureUnitType FigureUnitType { get { return (_unitType); } }
///
/// Returns the string representation of this object.
///
public override string ToString()
{
return FigureLengthConverter.ToString(this, CultureInfo.InvariantCulture);
}
#endregion Public Methods
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private double _unitValue; // unit value storage
private FigureUnitType _unitType; // unit type storage
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CapabilitiesUse.cs
- KerberosSecurityTokenAuthenticator.cs
- TextDecoration.cs
- QuaternionValueSerializer.cs
- ChtmlTextWriter.cs
- ZoneIdentityPermission.cs
- SerializationInfoEnumerator.cs
- ControlUtil.cs
- DrawTreeNodeEventArgs.cs
- UnsafeNativeMethodsPenimc.cs
- InfocardExtendedInformationEntry.cs
- NamespaceEmitter.cs
- XmlProcessingInstruction.cs
- SecurityContext.cs
- DropDownList.cs
- RemotingException.cs
- AQNBuilder.cs
- SpeechRecognitionEngine.cs
- TextControlDesigner.cs
- Model3DGroup.cs
- DataError.cs
- controlskin.cs
- SessionPageStatePersister.cs
- PropertyDescriptorComparer.cs
- WinFormsSpinner.cs
- XmlUtf8RawTextWriter.cs
- ConnectionPoint.cs
- ETagAttribute.cs
- ContextMenu.cs
- SchemaInfo.cs
- PropertyPathWorker.cs
- Compiler.cs
- LinqDataSourceContextData.cs
- CustomAttribute.cs
- FormatterConverter.cs
- FixedDSBuilder.cs
- CryptoProvider.cs
- TypeSystem.cs
- DefaultMemberAttribute.cs
- StorageMappingItemCollection.cs
- HttpWebRequestElement.cs
- CodeBlockBuilder.cs
- XhtmlTextWriter.cs
- XPathBuilder.cs
- FixedTextSelectionProcessor.cs
- PrimarySelectionGlyph.cs
- CommonProperties.cs
- FontCacheLogic.cs
- UpdatePanel.cs
- loginstatus.cs
- DataGrid.cs
- SkipQueryOptionExpression.cs
- Odbc32.cs
- PlanCompilerUtil.cs
- ClientRuntimeConfig.cs
- GridViewSortEventArgs.cs
- DirectoryLocalQuery.cs
- WebSysDescriptionAttribute.cs
- ParsedAttributeCollection.cs
- SynchronousReceiveElement.cs
- EnvelopedPkcs7.cs
- AxisAngleRotation3D.cs
- TreeNodeMouseHoverEvent.cs
- AutoGeneratedFieldProperties.cs
- NonBatchDirectoryCompiler.cs
- DynamicPropertyHolder.cs
- GridViewUpdatedEventArgs.cs
- MenuItemStyleCollection.cs
- Currency.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- RouteUrlExpressionBuilder.cs
- WaitForChangedResult.cs
- PersianCalendar.cs
- Point3DAnimation.cs
- UnmanagedMemoryStreamWrapper.cs
- HierarchicalDataSourceControl.cs
- QilName.cs
- UserControl.cs
- PropertyChangeTracker.cs
- RuleSet.cs
- OneToOneMappingSerializer.cs
- DataServiceQuery.cs
- XmlDataImplementation.cs
- OrderByQueryOptionExpression.cs
- tooltip.cs
- ApplicationInfo.cs
- RuleValidation.cs
- LicenseException.cs
- TriggerActionCollection.cs
- GPPOINTF.cs
- PreservationFileWriter.cs
- HostExecutionContextManager.cs
- SafeBuffer.cs
- GenerateTemporaryAssemblyTask.cs
- StreamWriter.cs
- SecureStringHasher.cs
- Attributes.cs
- MetadataArtifactLoaderResource.cs
- NonVisualControlAttribute.cs
- CaretElement.cs