//#########################################################################################
//★★★★★★★ http://www.cnpopsoft.com [华普软件] ★★★★★★★
//★★★★★★★ 华普软件 - VB & C#.NET 专业论文与源码荟萃! ★★★★★★★
//#########################################################################################
/*
* Copyright ?2005, Mathew Hall
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace XPTable.Models
{
///
/// Represents the position of a Cell in a Table
///
[Serializable(),
StructLayout(LayoutKind.Sequential)]
public struct CellPos
{
#region Class Data
///
/// Repsesents a null CellPos
///
public static readonly CellPos Empty = new CellPos(-1, -1);
///
/// The Row index of this CellPos
///
private int row;
///
/// The Column index of this CellPos
///
private int column;
#endregion
#region Constructor
///
/// Initializes a new instance of the CellPos class with the specified
/// row index and column index
///
/// The Row index of the CellPos
/// The Column index of the CellPos
public CellPos(int row, int column)
{
this.row = row;
this.column = column;
}
#endregion
#region Methods
///
/// Translates this CellPos by the specified amount
///
/// The amount to offset the row index
/// The amount to offset the column index
public void Offset(int rows, int columns)
{
this.row += rows;
this.column += columns;
}
///
/// Tests whether obj is a CellPos structure with the same values as
/// this CellPos structure
///
/// The Object to test
/// This method returns true if obj is a CellPos structure
/// and its Row and Column properties are equal to the corresponding
/// properties of this CellPos structure; otherwise, false
public override bool Equals(object obj)
{
if (!(obj is CellPos))
{
return false;
}
CellPos cellPos = (CellPos) obj;
if (cellPos.Row == this.Row)
{
return (cellPos.Column == this.Column);
}
return false;
}
///
/// Returns the hash code for this CellPos structure
///
/// An integer that represents the hashcode for this
/// CellPos
public override int GetHashCode()
{
return (this.Row ^ ((this.Column << 13) | (this.Column >> 0x13)));
}
///
/// Converts the attributes of this CellPos to a human-readable string
///
/// A string that contains the row and column indexes of this
/// CellPos structure
public override string ToString()
{
return "CellPos: (" + this.Row + "," + this.Column + ")";
}
#endregion
#region Properties
///
/// Gets or sets the Row index of this CellPos
///
public int Row
{
get
{
return this.row;
}
set
{
this.row = value;
}
}
///
/// Gets or sets the Column index of this CellPos
///
public int Column
{
get
{
return this.column;
}
set
{
this.column = value;
}
}
///
/// Tests whether any numeric properties of this CellPos have
/// values of -1
///
[Browsable(false)]
public bool IsEmpty
{
get
{
return (this.Row == -1 || this.Column == -1);
}
}
#endregion
#region Operators
///
/// Tests whether two CellPos structures have equal Row and Column
/// properties
///
/// The CellPos structure that is to the left
/// of the equality operator
/// The CellPos structure that is to the right
/// of the equality operator
/// This operator returns true if the two CellPos structures
/// have equal Row and Column properties
public static bool operator ==(CellPos left, CellPos right)
{
if (left.Row == right.Row)
{
return (left.Column == right.Column);
}
return false;
}
///
/// Tests whether two CellPos structures differ in their Row and
/// Column properties
///
/// The CellPos structure that is to the left
/// of the equality operator
/// The CellPos structure that is to the right
/// of the equality operator
/// This operator returns true if any of the Row and Column
/// properties of the two CellPos structures are unequal; otherwise
/// false
public static bool operator !=(CellPos left, CellPos right)
{
return !(left == right);
}
#endregion
}
}