IsEmpty() public method

Determines if the current range is empty
public IsEmpty ( ) : bool
return bool
Example #1
0
 public RangeRegion(Range pRange)
 {
     if (pRange.IsEmpty() == false)
     {
         m_RangeCollection.Add(pRange);
     }
 }
Example #2
0
        /// <summary>
        /// Indicates if the specified range of cells is selected
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual bool Contains(Range p_Range)
        {
            if (p_Range.IsEmpty() || IsEmpty())
            {
                return(false);
            }

            if (p_Range.ColumnsCount == 1 && p_Range.RowsCount == 1)
            {
                return(Contains(p_Range.Start));
            }

            //Range
            for (int i = 0; i < m_RangeCollection.Count; i++)
            {
                if (m_RangeCollection[i].Contains(p_Range))
                {
                    return(true);
                }
            }

            PositionCollection positions = p_Range.GetCellsPositions();

            for (int iPos = 0; iPos < positions.Count; iPos++)
            {
                if (Contains(positions[iPos]) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// Indicates if the specified range of cells is selected
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual bool IntersectsWith(Range p_Range)
        {
            if (p_Range.IsEmpty() || IsEmpty())
            {
                return(false);
            }

            RangeRegion range = Intersect(p_Range);

            return(!range.IsEmpty());
        }
Example #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="addedRange"></param>
 /// <param name="removedRange"></param>
 public RangeRegionChangedEventArgs(Range addedRange, Range removedRange)
 {
     if (addedRange.IsEmpty() == false)
     {
         this.addedRange = new RangeRegion(addedRange);
     }
     if (removedRange.IsEmpty() == false)
     {
         this.removedRange = new RangeRegion(removedRange);
     }
 }
Example #5
0
        public System.Drawing.Rectangle GetDrawingRectangle()
        {
            if (mRange.IsEmpty())
            {
                return(System.Drawing.Rectangle.Empty);
            }

            return(Grid.RangeToRectangle(mRange));

            ////Remove the not visible part
            //Range rngVisible = Grid.GetVisibleRange();
            //Range drawing = mRange.Intersect(rngVisible);

            //if (drawing.IsEmpty() == false)
            //{
            //    return Grid.RangeToRectangle(drawing);
            //}
            //else
            //    return System.Drawing.Rectangle.Empty;
        }
Example #6
0
        private void DrawScrollableArea(PaintEventArgs e, Point scrollableArea)
        {
            Rectangle clipRectangle = new Rectangle(scrollableArea.X, scrollableArea.Y,
                                                    m_Grid.DisplayRectangle.Width - scrollableArea.X, m_Grid.DisplayRectangle.Height - scrollableArea.Y);

            Range range = GetScrollableRange();

            if (range.IsEmpty())
            {
                return;
            }

            if (m_FirstVisibleScrollableRow == -1)
            {
                m_FirstVisibleScrollableRow = FindFirstVisibleRowFromRange(range, out m_FirstVisibleScrollableRowTop);
            }
            if (m_FirstVisibleScrollableColumn == -1)
            {
                m_FirstVisibleScrollableColumn = FindFirstVisibleColumnFromRange(range, out m_FirstVisibleScrollableColumnLeft);
            }

            int lastrow = FindLastVisibleRow(m_FirstVisibleScrollableRow, clipRectangle.Bottom);

            int lastColumn = FindLastVisibleColumn(m_FirstVisibleScrollableColumn, clipRectangle.Right);

            range = new Range(m_FirstVisibleScrollableRow, m_FirstVisibleScrollableColumn, lastrow, lastColumn);

            if (range.IsEmpty())
            {
                return;
            }

            e.Graphics.SetClip(clipRectangle);

            e.Graphics.TranslateTransform(e.Graphics.ClipBounds.X - (scrollableArea.X - m_FirstVisibleScrollableColumnLeft),
                                          e.Graphics.ClipBounds.Y - (scrollableArea.Y - m_FirstVisibleScrollableRowTop), MatrixOrder.Append);

            Rectangle clientRectangle = Rectangle.Round(e.Graphics.ClipBounds);


            using (GraphicsCache grCache = new GraphicsCache(e.Graphics, clientRectangle))
            {
                m_Grid.OnRangePaint(new RangePaintEventArgs(m_Grid, grCache, range),
                                    new Rectangle(0, 0, clipRectangle.Width, clipRectangle.Height));
            }

            e.Graphics.ResetClip();
            e.Graphics.ResetTransform();
        }
Example #7
0
        private void DrawFixedTop(PaintEventArgs e, Point scrollableArea)
        {
            Rectangle clipRectangle = new Rectangle(scrollableArea.X, 0,
                                                    m_Grid.DisplayRectangle.Width - scrollableArea.X, scrollableArea.Y);

            Range fixedTop = m_Grid.RangeAtArea(CellPositionType.FixedTop);

            if (fixedTop.IsEmpty())
            {
                m_FirstVisibleScrollableColumn = -1;
                return;
            }

            m_FirstVisibleScrollableColumn = FindFirstVisibleColumnFromRange(fixedTop, out m_FirstVisibleScrollableColumnLeft);

            if (m_FirstVisibleScrollableColumn == -1)
            {
                return;
            }

            const int firstRow = 0;

            int lastrow = m_Grid.ActualFixedRows - 1;

            int lastColumn = FindLastVisibleColumn(m_FirstVisibleScrollableColumn, clipRectangle.Right);

            fixedTop = new Range(firstRow, m_FirstVisibleScrollableColumn, lastrow, lastColumn);

            if (fixedTop.IsEmpty())
            {
                m_FirstVisibleScrollableColumn = -1;
                return;
            }

            e.Graphics.SetClip(clipRectangle);

            e.Graphics.TranslateTransform(e.Graphics.ClipBounds.X - (scrollableArea.X - m_FirstVisibleScrollableColumnLeft), e.Graphics.ClipBounds.Y,
                                          MatrixOrder.Append);

            Rectangle clientRectangle = Rectangle.Round(e.Graphics.ClipBounds);

            using (GraphicsCache grCache = new GraphicsCache(e.Graphics, clientRectangle))
            {
                m_Grid.OnRangePaint(new RangePaintEventArgs(m_Grid, grCache, fixedTop),
                                    new Rectangle(0, 0, clipRectangle.Width, clipRectangle.Height));
            }
            e.Graphics.ResetClip();
            e.Graphics.ResetTransform();
        }
Example #8
0
 /// <summary>
 /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range.
 /// </summary>
 /// <param name="p_Range1"></param>
 /// <param name="p_Range2"></param>
 /// <returns></returns>
 public static Range GetBounds(Range p_Range1, Range p_Range2)
 {
     if (p_Range1.IsEmpty())
     {
         return(p_Range2);
     }
     else if (p_Range2.IsEmpty())
     {
         return(p_Range1);
     }
     else
     {
         return(new Range(Position.Min(p_Range1.Start, p_Range2.Start),
                          Position.Max(p_Range1.End, p_Range2.End), false));
     }
 }
Example #9
0
        private void DrawFixedTopLeft(PaintEventArgs e)
        {
            Range fixedTopLeft = m_Grid.RangeAtArea(CellPositionType.FixedTopLeft);

            if (!fixedTopLeft.IsEmpty())
            {
                Rectangle clientRectangle = Rectangle.Round(e.Graphics.ClipBounds);

                using (GraphicsCache grCache = new GraphicsCache(e.Graphics, clientRectangle))
                {
                    Rectangle drawRectangle = m_Grid.RangeToRectangle(fixedTopLeft);
                    m_Grid.OnRangePaint(new RangePaintEventArgs(m_Grid, grCache, fixedTopLeft),
                                        drawRectangle);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Returns a non contiguous range of cells of the intersection between the current range and the specified range.
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual RangeRegion Intersect(Range p_Range)
        {
            RangeRegion range = new RangeRegion();

            if (p_Range.IsEmpty() == false && IsEmpty() == false)
            {
                //Range
                for (int i = 0; i < m_RangeCollection.Count; i++)
                {
                    Range intersectRange = p_Range.Intersect(m_RangeCollection[i]);
                    if (intersectRange.IsEmpty() == false)
                    {
                        range.m_RangeCollection.Add(intersectRange);
                    }
                }
            }

            return(range);
        }
Example #11
0
        /// <summary>
        /// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty.
        /// </summary>
        /// <param name="p_Range1"></param>
        /// <param name="p_Range2"></param>
        /// <returns></returns>
        public static Range Intersect(Range p_Range1, Range p_Range2)
        {
            if (p_Range1.IsEmpty() || p_Range2.IsEmpty())
            {
                return(Range.Empty);
            }

            Position startNew = Position.Max(p_Range1.Start, p_Range2.Start);
            Position endNew   = Position.Min(p_Range1.End, p_Range2.End);

            if (startNew.Column > endNew.Column ||
                startNew.Row > endNew.Row)
            {
                return(Range.Empty);
            }
            else
            {
                return(new Range(startNew, endNew, false));
            }
        }
Example #12
0
        /// <summary>
        /// This method converts a Position to the real range of the cell. This is usefull when RowSpan or ColumnSpan is greater than 1.
        /// </summary>
        /// <returns></returns>
        public override Range RangeToCellRange(Range range)
        {
            int x  = range.Start.Column;
            int x1 = range.End.Column;
            int y  = range.Start.Row;
            int y1 = range.End.Row;

            for (int x2 = range.Start.Column; x2 <= range.End.Column; x2++)
            {
                for (int y2 = range.Start.Row; y2 <= range.End.Row; y2++)
                {
                    var   p      = new Position(y2, x2);
                    Range range2 = PositionToCellRange(p);
                    if (range2.IsEmpty())
                    {
                        range2 = new Range(p, p);
                    }
                    if (range2.Start.Column < x)
                    {
                        x = range2.Start.Column;
                    }
                    if (range2.End.Column > x1)
                    {
                        x1 = range2.End.Column;
                    }

                    if (range2.Start.Row < y)
                    {
                        y = range2.Start.Row;
                    }
                    if (range2.End.Row > y1)
                    {
                        y1 = range2.End.Row;
                    }
                }
            }
            return(new Range(y, x, y1, x1));
        }
Example #13
0
		/// <summary>
		/// Force a range of cells to redraw.
		/// </summary>
		/// <param name="range"></param>
		public void InvalidateRange(Range range)
		{
			if (range.IsEmpty())
				return;
			CellPositionType[] types = new CellPositionType[]{
				CellPositionType.FixedLeft,
				CellPositionType.FixedTop,
				CellPositionType.FixedTopLeft,
				CellPositionType.Scrollable
			};
			
			// invalidate eaach position type individually
			// cliping against given range
			foreach (CellPositionType type in types)
			{
				Range visibleRange = RangeAtArea(type);
				// clip our range with visible range
				// so that we wount loop through thousands of rows
				Range clippedRange = Range.Intersect(range, visibleRange);
				if (clippedRange.IsEmpty() == false)
				{
					Rectangle gridRectangle = RangeToRectangle(clippedRange);
					if (gridRectangle.IsEmpty == false)
						Invalidate(gridRectangle, true);
				}
			}
		}
Example #14
0
		/// <summary>
		/// Returns the relative rectangle to the current scrollable area of the specified Range.
		/// Returns a Rectangle.Empty if the Range is not valid.
		/// </summary>
		public Rectangle RangeToRectangle(Range range)
		{
			if (range.IsEmpty())
				return Rectangle.Empty;

			if (range.Start.Column < 0)
				throw new ArgumentOutOfRangeException(string.Format("range.Start.Column was less than zero: {0}", range.Start.Column));
			int x = Columns.GetLeft(range.Start.Column);
			if (range.Start.Row < 0)
				throw new ArgumentOutOfRangeException(string.Format("range.Start.Row was less than zero: {0}", range.Start.Row));
			int y = Rows.GetTop(range.Start.Row);

			Size size = RangeToSize(range);
			if (size.IsEmpty)
				return Rectangle.Empty;

			return new Rectangle(new Point(x, y), size);
		}
Example #15
0
		public Size RangeToSize(Range range)
		{
			if (range.IsEmpty())
				return Size.Empty;

			int width = 0;
			for (int c = range.Start.Column; c <= range.End.Column; c++)
				width += Columns.GetWidth(c);

			int height = 0;
			for (int r = range.Start.Row; r <= range.End.Row; r++)
				height += Rows.GetHeight(r);

			return new Size(width, height);
		}
Example #16
0
		/// <summary>
		/// Auto size the columns and the rows speified
		/// </summary>
		/// <param name="p_RangeToAutoSize"></param>
		public virtual void AutoSizeCells(Range p_RangeToAutoSize)
		{
			SuspendLayout();
			if (p_RangeToAutoSize.IsEmpty() == false)
			{
				Rows.SuspendLayout();
				Columns.SuspendLayout();
				try
				{
					for (int c = p_RangeToAutoSize.End.Column; c >= p_RangeToAutoSize.Start.Column ; c--)
						Columns.AutoSizeColumn(c,false, p_RangeToAutoSize.Start.Row, p_RangeToAutoSize.End.Row);
					for (int r = p_RangeToAutoSize.End.Row; r >= p_RangeToAutoSize.Start.Row ; r--)
						Rows.AutoSizeRow(r, false, p_RangeToAutoSize.Start.Column, p_RangeToAutoSize.End.Column);
				}
				finally
				{
					//aggiorno top e left
					Rows.ResumeLayout();
					Columns.ResumeLayout();
				}

				//Call this method after calculated Bottom and Right
				if (AutoStretchColumnsToFitWidth)
					Columns.StretchToFit();
				if (AutoStretchRowsToFitHeight)
					Rows.StretchToFit();
			}
			ResumeLayout(false);
		}
Example #17
0
        public Rectangle RangeToVisibleRectangle(Range range)
        {
            if (range.IsEmpty())
            {
                return(Rectangle.Empty);
            }
            if (range.Start.Column < 0)
            {
                throw new ArgumentOutOfRangeException(string.Format("range.Start.Column was less than zero: {0}", range.Start.Column));
            }
            if (range.Start.Row < 0)
            {
                throw new ArgumentOutOfRangeException(string.Format("range.Start.Row was less than zero: {0}", range.Start.Row));
            }

            int firstRow = FindFirstVisibleRowFromRange(range);

            if (firstRow < 0)
            {
                return(Rectangle.Empty);
            }

            int actualFixedRows    = m_Grid.ActualFixedRows;
            int actualFixedColumns = m_Grid.ActualFixedColumns;
            int fixedAreaHeight    = m_Grid.GetFixedAreaHeight();
            int fixedAreaWidth     = m_Grid.GetFixedAreaWidth();

            int firstRowAbsoluteTop = m_Grid.Rows.GetAbsoluteTop(firstRow);
            int y      = firstRow < actualFixedRows ? firstRowAbsoluteTop : firstRowAbsoluteTop - m_Grid.CustomScrollPosition.Y;
            int bottom = y + m_Grid.Rows.GetHeight(firstRow);

            if (IsRowHiddenUnderFixedRows(fixedAreaHeight, y, bottom, firstRow, true))
            {
                y = fixedAreaHeight;
            }

            int firstColumn = FindFirstVisibleColumnFromRange(range);

            if (firstColumn < 0)
            {
                return(Rectangle.Empty);
            }

            int firstColumnAbsoluteLeft = m_Grid.Columns.GetAbsoluteLeft(firstColumn);
            int x     = firstColumn < actualFixedColumns ? firstColumnAbsoluteLeft : firstColumnAbsoluteLeft - m_Grid.CustomScrollPosition.X;
            int right = x + m_Grid.Columns.GetWidth(firstColumn);

            if (IsColumnHiddenUnderFixedColumn(fixedAreaWidth, x, right, firstColumn, true))
            {
                x = fixedAreaWidth;
            }

            int lastColumn      = range.End.Column;
            int lastColumnLeft  = GetLeft(firstColumn, firstColumnAbsoluteLeft, lastColumn);
            int lastColumnRight = lastColumnLeft + m_Grid.Columns.GetWidth(lastColumn);
            int width           = lastColumnRight - x;

            if (lastColumn > actualFixedColumns - 1 && IsColumnHiddenUnderFixedColumn(fixedAreaWidth, lastColumnLeft, lastColumnRight, lastColumn, false))
            {
                //lastColumn = actualFixedColumns - 1;
                width = fixedAreaWidth - x;
            }


            int lastRow       = range.End.Row;
            int lastRowTop    = GetTop(firstRow, firstRowAbsoluteTop, lastRow);
            int lastRowBottom = lastRowTop + m_Grid.Rows.GetHeight(lastRow);
            int height        = lastRowBottom - y;

            if (lastRow > actualFixedRows - 1 && IsRowHiddenUnderFixedRows(fixedAreaHeight, lastRowTop, lastRowBottom, lastRow, false))
            {
                //if last row is hidden under fixedRows
                height = fixedAreaHeight - y;
            }

            Size size = new Size(width, height);

            if (size.IsEmpty)
            {
                return(Rectangle.Empty);
            }

            return(new Rectangle(new Point(x, y), size));
        }
Example #18
0
		/// <summary>
		/// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty.
		/// </summary>
		/// <param name="p_Range1"></param>
		/// <param name="p_Range2"></param>
		/// <returns></returns>
		public static Range Intersect(Range p_Range1, Range p_Range2)
		{
			if (p_Range1.IsEmpty() || p_Range2.IsEmpty())
				return Range.Empty;

			Position startNew = Position.Max(p_Range1.Start, p_Range2.Start);
			Position endNew = Position.Min(p_Range1.End, p_Range2.End);

			if (startNew.Column > endNew.Column ||
				startNew.Row > endNew.Row)
				return Range.Empty;
			else
				return new Range(startNew, endNew, false);
		}
Example #19
0
		/// <summary>
		/// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range.
		/// </summary>
		/// <param name="p_Range1"></param>
		/// <param name="p_Range2"></param>
		/// <returns></returns>
		public static Range GetBounds(Range p_Range1, Range p_Range2)
		{
			if (p_Range1.IsEmpty())
				return p_Range2;
			else if (p_Range2.IsEmpty())
				return p_Range1;
			else
				return new Range(Position.Min(p_Range1.Start, p_Range2.Start),
					Position.Max(p_Range1.End, p_Range2.End), false);
		}
Example #20
0
 /// <summary>
 /// Force a range of cells to redraw.
 /// </summary>
 /// <param name="range"></param>
 public void InvalidateRange(Range range)
 {
     range = Range.Intersect(range, CompleteRange); //to ensure the range is valid
     if (range.IsEmpty() == false)
     {
         Rectangle gridRectangle = RangeToRectangle(range);
         if (gridRectangle.IsEmpty == false)
             Invalidate(gridRectangle, true);
     }
 }
Example #21
0
        /// <summary>
        /// Indicates if the specified range of cells is selected
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual bool Contains(Range p_Range)
        {
            if (p_Range.IsEmpty() || IsEmpty())
                return false;

            if (p_Range.ColumnsCount == 1 && p_Range.RowsCount == 1)
                return Contains(p_Range.Start);

            //Range
            for (int i = 0; i < m_RangeCollection.Count; i++)
            {
                if (m_RangeCollection[i].Contains(p_Range))
                    return true;
            }

            PositionCollection positions = p_Range.GetCellsPositions();
            for (int iPos = 0; iPos < positions.Count; iPos++)
            {
                if (Contains(positions[iPos]) == false)
                    return false;
            }
            return true;
        }
Example #22
0
 public RangeRegion(Range pRange)
 {
     if (pRange.IsEmpty() == false)
         m_RangeCollection.Add(pRange);
 }
Example #23
0
        /// <summary>
        /// Returns a non contiguous range of cells of the intersection between the current range and the specified range.
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual RangeRegion Intersect(Range p_Range)
        {
            RangeRegion range = new RangeRegion();

            if (p_Range.IsEmpty() == false && IsEmpty() == false)
            {
                //Range
                for (int i = 0; i < m_RangeCollection.Count; i++)
                {
                    Range intersectRange = p_Range.Intersect(m_RangeCollection[i]);
                    if (intersectRange.IsEmpty() == false)
                        range.m_RangeCollection.Add(intersectRange);
                }
            }

            return range;
        }
Example #24
0
        /// <summary>
        /// Indicates if the specified range of cells is selected
        /// </summary>
        /// <param name="p_Range"></param>
        /// <returns></returns>
        public virtual bool IntersectsWith(Range p_Range)
        {
            if (p_Range.IsEmpty() || IsEmpty())
                return false;

            RangeRegion range = Intersect(p_Range);
            return !range.IsEmpty();
        }
Example #25
0
        /// <summary>
        /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells)
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public RangeRegion Exclude(Range range)
        {
            RangeRegion excluded;

            Range intersection = Intersect(range);

            if (intersection.IsEmpty())
            {
                excluded = new RangeRegion(this);
            }
            else
            {
                excluded = new RangeRegion();

                //Top Left
                if (this.Start.Row < intersection.Start.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1));
                }

                //Top
                if (this.Start.Row < intersection.Start.Row)
                {
                    excluded.Add(new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column));
                }

                //Top Right
                if (this.Start.Row < intersection.Start.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row - 1, this.End.Column));
                }

                //----------

                //Left
                if (this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column - 1));
                }

                //Right
                if (this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column));
                }

                //--------

                //Bottom Left
                if (this.End.Row > intersection.End.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1));
                }

                //Bottom
                if (this.End.Row > intersection.End.Row)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column));
                }

                //Bottom Right
                if (this.End.Row > intersection.End.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column));
                }
            }

            return(excluded);
        }
Example #26
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="addedRange"></param>
		/// <param name="removedRange"></param>
		public RangeRegionChangedEventArgs(Range addedRange, Range removedRange)
		{
			if (addedRange.IsEmpty() == false)
				this.addedRange = new RangeRegion(addedRange);
			if (removedRange.IsEmpty() == false)
				this.removedRange = new RangeRegion(removedRange);
		}
Example #27
0
        public Rectangle RangeToVisibleRectangle(Range range)
        {
            if (range.IsEmpty())
            {
                return(Rectangle.Empty);
            }
            if (range.Start.Column < 0)
            {
                throw new ArgumentOutOfRangeException(string.Format("range.Start.Column was less than zero: {0}", range.Start.Column));
            }
            if (range.Start.Row < 0)
            {
                throw new ArgumentOutOfRangeException(string.Format("range.Start.Row was less than zero: {0}", range.Start.Row));
            }

            int firstRow = FindFirstVisibleRowFromRange(range);

            if (firstRow < 0)
            {
                return(Rectangle.Empty);
            }

            int actualFixedRows = m_Grid.ActualFixedRows;

            int actualFixedColumns = m_Grid.ActualFixedColumns;

            int y = m_Grid.Rows.GetTop(firstRow);

            if (m_Grid.IsRowHiddenUnderFixedRows(firstRow, true))
            {
                y = m_Grid.GetFixedAreaHeight();
            }

            int firstColumn = FindFirstVisibleColumnFromRange(range);

            if (firstColumn < 0)
            {
                return(Rectangle.Empty);
            }

            int x = m_Grid.Columns.GetLeft(firstColumn);

            if (IsColumnHiddenUnderFixedColumn(firstColumn, true))
            {
                x = m_Grid.GetFixedAreaWidth();
            }

            int lastColumn = range.End.Column;

            if (range.End.Column != actualFixedColumns - 1 && m_Grid.IsColumnHiddenUnderFixedColumn(range.End.Column))
            {
                lastColumn = actualFixedColumns - 1;
            }
            int width = m_Grid.Columns.GetRight(lastColumn) - x;

            int lastRow = range.End.Row;

            if (range.End.Row != actualFixedRows - 1 && m_Grid.IsRowHiddenUnderFixedRows(range.End.Row))
            {
                lastRow = actualFixedRows - 1;
            }
            int height = m_Grid.Rows.GetBottom(lastRow) - y;

            Size size = new Size(width, height);

            if (size.IsEmpty)
            {
                return(Rectangle.Empty);
            }

            return(new Rectangle(new Point(x, y), size));
        }
Example #28
0
        /// <summary>
        /// Returns the relative rectangle to the current scrollable area of the specified Range.
        /// Returns a Rectangle.Empty if the Range is not valid. 
        /// </summary>
        public Rectangle RangeToRectangle(Range range)
        {
            if (range.IsEmpty())
                return Rectangle.Empty;

            int x = Columns.GetLeft(range.Start.Column);
            int y = Rows.GetTop(range.Start.Row);

            Size size = RangeToSize(range);
            if (size.IsEmpty)
                return Rectangle.Empty;

            return new Rectangle(new Point(x, y), size);
        }