Пример #1
0
        public bool GetScrollPositionToShowCell(Position position, List <int> visibleColumns, List <int> visibleRows, out Point newScrollPosition)
        {
            CellPositionType posType          = m_Grid.GetPositionType(position);
            Rectangle        displayRectangle = m_Grid.DisplayRectangle;

            bool isFixedLeft = posType == CellPositionType.FixedLeft || posType == CellPositionType.FixedTopLeft;
            int  x;

            if (visibleColumns.Contains(position.Column)) //Is x visible
            {
                x = m_Grid.CustomScrollPosition.X;
            }
            else
            {
                if (isFixedLeft)
                {
                    x = 0;
                }
                else
                {
                    x = position.Column - m_Grid.ActualFixedColumns;
                }

                //Check if the scrollable positioin if not outside the valid area
                int maxX = m_Grid.GetScrollColumns(displayRectangle.Width);
                if (x > maxX)
                {
                    x = maxX;
                }
            }

            bool isFixedTop = posType == CellPositionType.FixedTop || posType == CellPositionType.FixedTopLeft;
            int  y;

            if (visibleRows.Contains(position.Row)) //Is y visible
            {
                y = m_Grid.CustomScrollPosition.Y;
                //[email protected]:CHDOC00123837: it works as expected without changing y value. the calculation in this method doesn't seem right
                //y = m_Grid.ExtendTopRowByHiddenRows(y);
            }
            else
            {
                //MICK(15): add direction dependent procedure of finding y (and x should be too).
                //It means that when you go from bottom to top, the selected item will be at top,
                //              (this already happens, so this part is not changed)
                //              when you go from top to bottom, the selected item will be at bottom,
                // y (and x) value is adjusted accordingly
                if (m_Grid.CustomScrollPosition.Y + m_Grid.ActualFixedRows > position.Row)
                {
                    //MICK(16): direction bottom to top
                    if (isFixedTop)
                    {
                        y = 0;
                    }
                    else
                    {
                        y = position.Row - m_Grid.FixedRows;
                    }

                    //Check if the scrollable positioin if not outside the valid area
                    int maxY = m_Grid.GetScrollRows(displayRectangle.Height);
                    if (y > maxY)
                    {
                        y = maxY;
                    }
                    //[email protected]:CHDOC00123837: it works as expected without changing y value. the calculation in this method doesn't seem right
                    //MICK(21)
                    //y = m_Grid.ExtendTopRowByHiddenRows(y);
                }
                else
                {
                    //MICK(17): direction from top to bottom
                    y = m_Grid.GetTopVisibleRowFromBottomRow(position.Row) - m_Grid.ActualFixedRows;
                    //[email protected]: CHDOC00123837: it works as expected without changing y value. the calculation in this method doesn't seem right
                    //y = m_Grid.ExtendTopRowByHiddenRows(y);
                }
            }

            newScrollPosition = new Point(x, y);

            return(true);
        }
Пример #2
0
		/// <summary>
		/// Returns a visible area range, which is a bit
		/// expanded to the left and top
		/// </summary>
		/// <param name="areaType"></param>
		/// <returns></returns>
		public Range RangeAtAreaExpanded(CellPositionType areaType)
		{
			Range range = RangeAtArea(areaType);
			// decrease visible row by 1, so that selection top row would not be drawn
			// if selection start somewhere outside the screen
			if (range.IsEmpty() == false)
			{
				int startRow = range.Start.Row > 0 ? range.Start.Row -1 : 0;
				int startCol = range.Start.Column > 0 ? range.Start.Column - 1 : 0;
				range = new Range(
					new Position(startRow, startCol),
					range.End);
			}
			return range;
		}
Пример #3
0
		/// <summary>
		/// Get the range of cells at the specified dispaly area.
		/// This method consider only the visible cells using the current scroll position.
		/// Returns a single Range for the specified grid area (scrollable, fixedtop, fixedleft, fixedtopleft).
		/// Returns Range.Empty if there isn't a valid range in the specified area.
		/// </summary>
		public Range RangeAtArea(CellPositionType areaType)
		{
			if (areaType == CellPositionType.FixedTopLeft)
			{
				if (FixedRows > 0 && Rows.Count >= FixedRows &&
				    FixedColumns > 0 && Columns.Count >= FixedColumns)
					return new Range(0, 0, FixedRows - 1, FixedColumns - 1);
				else
					return Range.Empty;
			}
			else if (areaType == CellPositionType.FixedLeft)
			{
				int actualFixed = FixedColumns;
				if (actualFixed > Columns.Count)
					actualFixed = Columns.Count;

				if (actualFixed <= 0)
					return Range.Empty;

				int? firstRow = Rows.FirstVisibleScrollableRow;
				int? lastRow = Rows.LastVisibleScrollableRow;

				if (firstRow == null || lastRow == null)
					return Range.Empty;

				return new Range(firstRow.Value, 0, lastRow.Value, actualFixed - 1);
			}
			else if (areaType == CellPositionType.FixedTop)
			{
				int actualFixed = FixedRows;
				if (actualFixed > Rows.Count)
					actualFixed = Rows.Count;

				if (actualFixed <= 0)
					return Range.Empty;

				int? firstCol = Columns.FirstVisibleScrollableColumn;
				int? lastCol = Columns.LastVisibleScrollableColumn;

				if (firstCol == null || lastCol == null)
					return Range.Empty;

				return new Range(0, firstCol.Value, actualFixed - 1, lastCol.Value);
			}
			else if (areaType == CellPositionType.Scrollable)
			{
				int? firstRow = Rows.FirstVisibleScrollableRow;
				int? lastRow = Rows.LastVisibleScrollableRow;

				int? firstCol = Columns.FirstVisibleScrollableColumn;
				int? lastCol = Columns.LastVisibleScrollableColumn;

				if (firstRow == null || firstCol == null ||
				    lastRow == null || lastCol == null)
					return Range.Empty;

				return new Range(firstRow.Value, firstCol.Value,
				                 lastRow.Value, lastCol.Value);
			}
			else
				throw new SourceGridException("Invalid areaType");
		}
Пример #4
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);
				}
			}
		}
Пример #5
0
        public bool GetScrollPositionToShowCell(Position position, List <int> columns, List <int> rows, out Point newScrollPosition)
        {
            newScrollPosition = m_Grid.CustomScrollPosition;
            if (!m_Grid.IsPositionValid(position))
            {
                return(false);
            }

            CellPositionType posType          = m_Grid.GetPositionType(position);
            Rectangle        displayRectangle = m_Grid.DisplayRectangle;

            bool isFixedLeft = posType == CellPositionType.FixedLeft || posType == CellPositionType.FixedTopLeft;
            int  x           = m_Grid.CustomScrollPosition.X;

            if (!columns.Contains(position.Column))
            {
                if (isFixedLeft)
                {
                    x = 0;
                }
                else if (columns.Count > m_Grid.ActualFixedColumns)
                {
                    if (position.Column < columns[m_Grid.ActualFixedColumns])
                    {
                        x = m_Grid.Columns.GetAbsoluteLeft(position.Column) - m_Grid.GetFixedAreaWidth();
                    }
                    else
                    {
                        x = m_Grid.Columns.GetAbsoluteRight(position.Column) - displayRectangle.Width;
                    }
                }
                else
                {
                    x = m_Grid.Columns.GetAbsoluteLeft(position.Column) - m_Grid.GetFixedAreaWidth();
                }
            }

            bool isFixedTop = posType == CellPositionType.FixedTop || posType == CellPositionType.FixedTopLeft;
            int  y          = m_Grid.CustomScrollPosition.Y;

            if (!rows.Contains(position.Row))
            {
                if (isFixedTop)
                {
                    y = 0;
                }
                else if (rows.Count > m_Grid.ActualFixedRows)
                {
                    if (position.Row < rows[m_Grid.ActualFixedRows])
                    {
                        y = m_Grid.Rows.GetAbsoluteTop(position.Row) - m_Grid.GetFixedAreaHeight();
                    }
                    else
                    {
                        y = m_Grid.Rows.GetAbsoluteBottom(position.Row) - displayRectangle.Height;
                    }
                }
                else
                {
                    y = m_Grid.Rows.GetAbsoluteTop(position.Row) - m_Grid.GetFixedAreaHeight();
                }
            }

            newScrollPosition = new Point(x, y);

            return(true);
        }