// // 2002-2005 AlphaSierraPapa // GNU General Public License // // $Revision$ // using System; using System.Drawing; namespace ICSharpCode.SharpDevelop.Dom { [Serializable] public struct DomRegion : IComparable, IComparable { readonly int beginLine; readonly int endLine; readonly int beginColumn; readonly int endColumn; public readonly static DomRegion Empty = new DomRegion(-1, -1); public bool IsEmpty { get { return BeginLine <= 0; } } public int BeginLine { get { return beginLine; } } /// /// if the end line is == -1 the end column is -1 too /// this stands for an unknwon end /// public int EndLine { get { return endLine; } } public int BeginColumn { get { return beginColumn; } } /// /// if the end column is == -1 the end line is -1 too /// this stands for an unknwon end /// public int EndColumn { get { return endColumn; } } public DomRegion(Point start, Point end) : this(start.Y, start.X, end.Y, end.X) { } public DomRegion(Point start) : this(start.Y, start.X) { } public DomRegion(int beginLine, int beginColumn, int endLine, int endColumn) { this.beginLine = beginLine; this.beginColumn = beginColumn; this.endLine = endLine; this.endColumn = endColumn; } public DomRegion(int beginLine, int beginColumn) { this.beginLine = beginLine; this.beginColumn = beginColumn; this.endLine = -1; this.endColumn = -1; } /// /// Returns true, if the given coordinates (row, column) are in the region. /// This method assumes that for an unknown end the end line is == -1 /// public bool IsInside(int row, int column) { return row >= BeginLine && (row <= EndLine || EndLine == -1) && (row != BeginLine || column >= BeginColumn) && (row != EndLine || column <= EndColumn); } public override string ToString() { return String.Format("[Region: BeginLine = {0}, EndLine = {1}, BeginColumn = {2}, EndColumn = {3}]", beginLine, endLine, beginColumn, endColumn); } public int CompareTo(DomRegion value) { int cmp; if (0 != (cmp = (BeginLine - value.BeginLine))) { return cmp; } if (0 != (cmp = (BeginColumn - value.BeginColumn))) { return cmp; } if (0 != (cmp = (EndLine - value.EndLine))) { return cmp; } return EndColumn - value.EndColumn; } int IComparable.CompareTo(object value) { return CompareTo((DomRegion)value); } } }