Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Range"/> class.
        /// </summary>
        /// <param name="p_StartRow">The start row.</param>
        /// <param name="p_StartCol">The start column.</param>
        /// <param name="p_EndRow">The end row.</param>
        /// <param name="p_EndCol">The end column.</param>
        public Range(int p_StartRow, int p_StartCol, int p_EndRow, int p_EndCol)
        {
            start = new Position(p_StartRow, p_StartCol);
              end = new Position(p_EndRow, p_EndCol);

              Normalize();
        }
 /// <summary>
 /// Returns a position with the smaller Row and the smaller column
 /// </summary>
 /// <param name="position1">The position1.</param>
 /// <param name="position2">The position2.</param>
 /// <returns></returns>
 public static Position MergeMinor(Position position1, Position position2)
 {
     int l_Row, l_Col;
       if (position1.Row < position2.Row)
       {
     l_Row = position1.Row;
       }
       else
       {
     l_Row = position2.Row;
       }
       if (position1.Column < position2.Column)
       {
     l_Col = position1.Column;
       }
       else
       {
     l_Col = position2.Column;
       }
       return new Position(l_Row, l_Col);
 }
 /// <summary>
 /// Adds an element with the specified key and value to this ControlToPositionAssociation.
 /// </summary>
 /// <param name="key">
 /// The Control key of the element to add.
 /// </param>
 /// <param name="value">
 /// The Position value of the element to add.
 /// </param>
 public virtual void Add(Control key, Position value)
 {
     this.Dictionary.Add(key, value);
 }
Exemple #4
0
        /// <summary>
        /// Returns true if the specified cell position is present in the current range.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <returns>
        /// <c>true</c> if the range contains the specified position; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(Position position)
        {
            int l_Row = position.Row;
              int l_Col = position.Column;

              return l_Row >= start.Row && l_Row <= end.Row &&
              l_Col >= start.Column && l_Col <= end.Column;
        }
Exemple #5
0
        /// <summary>
        /// Check and fix the range to always have Start smaller than End
        /// </summary>
        private void Normalize()
        {
            int l_MinRow, l_MinCol, l_MaxRow, l_MaxCol;

              if (start.Row < end.Row)
              {
            l_MinRow = start.Row;
              }
              else
              {
            l_MinRow = end.Row;
              }

              if (start.Column < end.Column)
              {
            l_MinCol = start.Column;
              }
              else
              {
            l_MinCol = end.Column;
              }

              if (start.Row > end.Row)
              {
            l_MaxRow = start.Row;
              }
              else
              {
            l_MaxRow = end.Row;
              }

              if (start.Column > end.Column)
              {
            l_MaxCol = start.Column;
              }
              else
              {
            l_MaxCol = end.Column;
              }

              start = new Position(l_MinRow, l_MinCol);
              end = new Position(l_MaxRow, l_MaxCol);
        }
Exemple #6
0
 /// <summary>
 /// Get the Rectangle of the cell respect all the scrollable area. Using the Cell Row/Col Span.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <returns></returns>
 public override Rectangle PositionToAbsoluteRect(Position position)
 {
     ICell l_Cell = this[position.Row, position.Column];
       if (l_Cell != null)
       {
     return base.RangeToAbsoluteRect(l_Cell.Range);
       }
       else
       {
     return base.PositionToAbsoluteRect(position);
       }
 }
Exemple #7
0
 /// <summary>
 /// Draw the specified Cell
 /// </summary>
 /// <param name="p_Panel">The panel.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
 /// <param name="p_Cell">The cell.</param>
 /// <param name="p_CellPosition">The cell position.</param>
 /// <param name="p_PanelDrawRectangle">The panel draw rectangle.</param>
 protected override void PaintCell(GridSubPanel p_Panel, PaintEventArgs e, Cells.ICellVirtual p_Cell, Position p_CellPosition, Rectangle p_PanelDrawRectangle)
 {
     ICell l_Cell = (ICell)p_Cell;
       Range l_CellRange = l_Cell.Range;
       if (l_CellRange.RowsCount == 1 && l_CellRange.ColumnsCount == 1)
       {
     base.PaintCell(p_Panel, e, p_Cell, p_CellPosition, p_PanelDrawRectangle);
       }
       else // Row/Col Span > 1
       {
     Rectangle l_Rect = p_Panel.RectangleGridToPanel(PositionToDisplayRect(l_CellRange.Start));
     base.PaintCell(p_Panel, e, p_Cell, l_CellRange.Start, l_Rect);
       }
 }
        /// <summary>
        /// Invert the selection when mode selection is row
        /// </summary>
        public void InvertSelectionRows()
        {
            this.grid.Redraw = false;

              List<Range> l_RangeCollection = new List<Range>();
              bool start_found = false;
              Position l_startPos = Position.Empty;
              for (int i = 1; i < grid.RowsCount; ++i)
              {
            if (start_found == false && this.ContainsRow(i) == false)
            {
              l_startPos = new Position(i, 0);
              start_found = true;
            }

            if (start_found == true && this.ContainsRow(i) == true)
            {
              Position l_endPos = new Position(i - 1, grid.ColumnsCount - 1);
              l_RangeCollection.Add(new Range(l_startPos, l_endPos));
              start_found = false;
            }
              }

              if (start_found == true)
              {
            Position l_endPos = new Position(this.grid.RowsCount - 1, this.grid.ColumnsCount - 1);
            l_RangeCollection.Add(new Range(l_startPos, l_endPos));
              }

              Clear();
              this.grid.SetFocusCell(Position.Empty);

              foreach (Range range in l_RangeCollection)
              {
            AddRange(range);
              }

              this.grid.Redraw = true;
        }
 /// <summary>
 /// Deselect and remove from the collection the specified cell
 /// </summary>
 /// <param name="p_Cell">The cell.</param>
 public void Remove(Position p_Cell)
 {
     RemoveRange(new Range(p_Cell));
 }
        /// <summary>
        /// Deselect all cells except that specified.
        /// </summary>
        /// <param name="p_CellLeaveThisCellSelected">The cell to leave selected.</param>
        public void Clear(Position p_CellLeaveThisCellSelected)
        {
            if (Count > 0)
              {
            rangeList.Clear();

            rangeList.Add(new Range(p_CellLeaveThisCellSelected));

            OnSelectionChange(new SelectionChangedEventArgs(SelectionChangedEventType.Clear, Range.Empty));
              }
        }
        /// <summary>
        /// Indicates whether the specified cell is selected.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        /// <c>true</c> if the selection contains the specified cell; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(Position cell)
        {
            if (cell.IsEmpty())
              {
            return false;
              }

              for (int r = 0; r < rangeList.Count; r++)
              {
            if (this[r].Contains(cell))
            {
              return true;
            }
              }

              return false;
        }
 /// <summary>
 /// Select the specified cell and add the cell to the collection.
 /// </summary>
 /// <param name="cell">The cell.</param>
 public void Add(Position cell)
 {
     AddRange(new Range(cell));
 }
        private void RemoveRangeCell(Range l_RangeToDeselect)
        {
            bool selectionChanged = false;
              if (l_RangeToDeselect.Start == l_RangeToDeselect.End && Contains(l_RangeToDeselect.Start))
              {
            rangeList.Remove(l_RangeToDeselect);
            selectionChanged = true;
              }
              // here we check whether the l_RangeToDeselect is a subset of a row
              else if (l_RangeToDeselect.Start.Row == l_RangeToDeselect.End.Row)
              {
            int row = l_RangeToDeselect.Start.Row;
            for (int col = l_RangeToDeselect.Start.Column; col <= l_RangeToDeselect.End.Column; ++col)
            {
              Position position = new Position(row, col);
              if (Contains(position))
              {
            rangeList.Remove(new Range(position));
            selectionChanged = true;
              }
            }
              }
              // here we check whether the l_RangeToDeselect is a subset of a column
              else if (l_RangeToDeselect.Start.Column == l_RangeToDeselect.End.Column)
              {
            int col = l_RangeToDeselect.Start.Column;
            for (int row = l_RangeToDeselect.Start.Row; row <= l_RangeToDeselect.End.Row; ++row)
            {
              Position position = new Position(row, col);
              if (Contains(position))
              {
            rangeList.Remove(new Range(position));
            selectionChanged = true;
              }
            }
              }

              if (selectionChanged)
              {
            OnSelectionChange(new SelectionChangedEventArgs(SelectionChangedEventType.Remove, l_RangeToDeselect));
              }
        }
Exemple #14
0
 /// <summary>
 /// Whether the position.s are equal.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <returns></returns>
 public bool Equals(Position position)
 {
     return column == position.column && row == position.row;
 }
Exemple #15
0
 /// <summary>
 /// Get the real position for the specified position. For example when position is a merged cell this method returns the starting position of the merged cells.
 /// Usually this method returns the same cell specified as parameter. This method is used for processing arrow keys, to find a valid cell when the focus is in a merged cell.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <returns></returns>
 public override Position GetStartingPosition(Position position)
 {
     ICell l_tmp = (ICell)GetCell(position);
       if (l_tmp != null)
       {
     return l_tmp.Range.Start;
       }
       else
       {
     return position;
       }
 }
 private Range AddRangeCell(Range l_RangeToSelect)
 {
     bool isFound = false;
       if (l_RangeToSelect.Start == l_RangeToSelect.End && !Contains(l_RangeToSelect.Start))
       {
     rangeList.Add(l_RangeToSelect);
     isFound = true;
       }
       // here we check whether the l_RangeToSelect is a subset of a row
       else if (l_RangeToSelect.Start.Row == l_RangeToSelect.End.Row)
       {
     int row = l_RangeToSelect.Start.Row;
     for (int col = l_RangeToSelect.Start.Column; col <= l_RangeToSelect.End.Column; ++col)
     {
       Position position = new Position(row, col);
       if (!Contains(position))
       {
     rangeList.Add(new Range(position));
     isFound = true;
       }
     }
       }
       // here we check whether the l_RangeToSelect is a subset of a column
       else if (l_RangeToSelect.Start.Column == l_RangeToSelect.End.Column)
       {
     int col = l_RangeToSelect.Start.Column;
     for (int row = l_RangeToSelect.Start.Row; row <= l_RangeToSelect.End.Row; ++row)
     {
       Position position = new Position(row, col);
       if (!Contains(position))
       {
     rangeList.Add(new Range(position));
     isFound = true;
       }
     }
       }
       else // This is a rectangle.
       {
     for (int row = l_RangeToSelect.Start.Row; row <= l_RangeToSelect.End.Row; ++row)
     {
       for (int col = l_RangeToSelect.Start.Column; col <= l_RangeToSelect.End.Column; ++col)
       {
     Position position = new Position(row, col);
     if (!Contains(position))
     {
       rangeList.Add(new Range(position));
       isFound = true;
     }
       }
     }
       }
       if (isFound)
       {
     OnSelectionChange(new SelectionChangedEventArgs(SelectionChangedEventType.Add, l_RangeToSelect));
       }
       return l_RangeToSelect;
 }
Exemple #17
0
 /// <summary>
 /// Force a cell to redraw. If Redraw is set to false this function has no effects.
 /// If ColSpan or RowSpan is greater than 0 this function invalidate the complete range with InvalidateRange
 /// </summary>
 /// <param name="position">The position.</param>
 public override void InvalidateCell(Position position)
 {
     ICell l_Cell = this[position.Row, position.Column];
       if (l_Cell == null)
       {
     base.InvalidateCell(position);
       }
       else
       {
     InvalidateRange(l_Cell.Range);
       }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionKeyEventArgs"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="cell">The cell.</param>
 /// <param name="keyArge">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
 public PositionKeyEventArgs(Position position, Cells.ICellVirtual cell, KeyEventArgs keyArge)
     : base(position, cell)
 {
     this.keyArgs = keyArge;
 }
Exemple #19
0
        /// <summary>
        /// Change the focus of the grid. The calls order is: (the user select CellX) Grid.CellGotFocus(CellX), CellX.Enter, (the user select CellY), Grid.CellLostFocus(CellX), CellX.Leave, Grid.CellGotFocus(CellY), CellY.Enter
        /// </summary>
        /// <param name="p_CellToSetFocus">Must be a valid cell linked to the grid or null of you want to remove the focus</param>
        /// <param name="p_DeselectOtherCells">True to deselect others selected cells</param>
        /// <returns>Return true if the grid can select the cell specified, otherwise false</returns>
        public override bool SetFocusCell(Position p_CellToSetFocus, bool p_DeselectOtherCells)
        {
            if (EnableRowColSpan == false || p_CellToSetFocus.IsEmpty())
              {
            return base.SetFocusCell(p_CellToSetFocus, p_DeselectOtherCells);
              }

              ICell l_Cell = this[p_CellToSetFocus.Row, p_CellToSetFocus.Column];
              if (l_Cell != null)
              {
            return base.SetFocusCell(l_Cell.Range.Start, p_DeselectOtherCells);
              }
              else
              {
            return base.SetFocusCell(p_CellToSetFocus, p_DeselectOtherCells);
              }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionEventArgs"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="p_Cell">The cell.</param>
 public PositionEventArgs(Position position, Cells.ICellVirtual p_Cell)
 {
     this.position = position;
       this.cell = p_Cell;
 }
Exemple #21
0
        private Range(Position p_Start, Position p_End, bool p_bCheck)
        {
            start = p_Start;
              end = p_End;

              if (p_bCheck)
              {
            Normalize();
              }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionKeyPressEventArgs"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="p_Cell">The cell.</param>
 /// <param name="p_KeyPressArge">The <see cref="System.Windows.Forms.KeyPressEventArgs"/> instance containing the event data.</param>
 public PositionKeyPressEventArgs(Position position, Cells.ICellVirtual p_Cell, System.Windows.Forms.KeyPressEventArgs p_KeyPressArge)
     : base(position, p_Cell)
 {
     this.keyPressArgs = p_KeyPressArge;
       this.isControlPressed = Control.ModifierKeys == Keys.Control;
       this.isShiftPressed = Control.ModifierKeys == Keys.Shift;
 }
Exemple #23
0
 /// <summary>
 /// Move the current range to the specified position, leaving the current ColumnsCount and RowsCount
 /// </summary>
 /// <param name="p_StartPosition">The start position.</param>
 public void MoveTo(Position p_StartPosition)
 {
     int l_ColCount = ColumnsCount;
       int l_RowCount = RowsCount;
       this.start = p_StartPosition;
       RowsCount = l_RowCount;
       ColumnsCount = l_ColCount;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionMouseEventArgs"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="p_Cell">The cell.</param>
 /// <param name="p_MouseArgs">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
 public PositionMouseEventArgs(Position position, Cells.ICellVirtual p_Cell, MouseEventArgs p_MouseArgs)
     : base(position, p_Cell)
 {
     this.mouseArgs = p_MouseArgs;
 }
Exemple #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Range"/> class.
 /// </summary>
 /// <param name="p_Start">The start.</param>
 /// <param name="p_End">The end.</param>
 public Range(Position p_Start, Position p_End)
     : this(p_Start, p_End, true)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionContextMenuEventArgs"/> class.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <param name="p_Cell">The cell.</param>
 /// <param name="p_ContextMenu">The context menu itmes.</param>
 public PositionContextMenuEventArgs(Position position, Cells.ICellVirtual p_Cell, List<MenuItem> p_ContextMenu)
     : base(position, p_Cell)
 {
     this.contextMenu = p_ContextMenu;
 }
Exemple #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Range"/> class.
 /// Construct a Range of a single cell
 /// </summary>
 /// <param name="p_SinglePosition">The single position.</param>
 public Range(Position p_SinglePosition)
     : this(p_SinglePosition, p_SinglePosition, false)
 {
 }
Exemple #28
0
        /// <summary>
        /// Returns or set a cell at the specified row and column.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="column">The column.</param>
        /// <remarks>
        /// If you get an ICell position occupied by a row/col span cell, and EnableRowColSpan is
        /// true, this method returns the cell with Row/Col span.
        /// </remarks>
        /// <returns>The cell at the specified row and column</returns>
        public ICell this[int row, int column]
        {
            get
              {
            if (EnableRowColSpan == false)
            {
              return this.cells[row, column];
            }
            else // enable Row Col Span search
            {
              ICell l_RetCell = this.cells[row, column];
              if (l_RetCell == null)
              {
            int l_StartRow = row;
            int l_StartCol;
            if (column == 0)
            {
              l_StartCol = 0;
              if (l_StartRow > 0)
              {
                l_StartRow--;
              }
            }
            else
            {
              l_StartCol = column - 1;
            }

            int l_EndCol = column;
            int l_EndRow;
            if (row == 0)
            {
              l_EndRow = 0;
              if (l_EndCol > 0)
              {
                l_EndCol--;
              }
            }
            else
            {
              l_EndRow = row - 1;
            }

            Position l_ReqPos = new Position(row, column);

            // ciclo fino a che non raggiungo la fine della griglia (con un massimo di MaxSpanSearch)
            for (int l_Search = 0; l_Search < maximumSpanSearch; l_Search++)
            {
              bool isAllFull = true;

              // ciclo sulla diagonale
              for (int r = l_StartRow, c = l_StartCol; r >= l_EndRow && c <= l_EndCol; r--, c++)
              {
                if (this.cells[r, c] != null)
                {
                  if (this.cells[r, c].ContainsPosition(l_ReqPos)) // se la cella richiesta fa parte di questa cella
                  {
                    return this.cells[r, c];
                  }
                  else
                  {
                    isAllFull &= true;
                  }
                }
                else
                {
                  isAllFull = false;
                }
              }

              if (isAllFull)
              {
                return null;
              }

              if (l_StartCol > 0)
              {
                l_StartCol--;
              }
              else
              {
                l_StartRow--;
              }

              if (l_EndRow > 0)
              {
                l_EndRow--;
              }
              else
              {
                l_EndCol--;
              }

              if (l_EndCol < 0 || l_StartRow < 0)
              {
                return null;
              }
            }

            return null;
              }
              else
              {
            return l_RetCell;
              }
            }
              }
              set
              {
            InsertCell(row, column, value);
              }
        }
 /// <summary>
 /// Determines whether this ControlToPositionAssociation contains a specific value.
 /// </summary>
 /// <param name="value">
 /// The Position value to locate in this ControlToPositionAssociation.
 /// </param>
 /// <returns>
 /// true if this ControlToPositionAssociation contains an element with the specified value;
 /// otherwise, false.
 /// </returns>
 public virtual bool ContainsValue(Position value)
 {
     foreach (Position item in this.Dictionary.Values)
       {
     if (item == value)
     {
       return true;
     }
       }
       return false;
 }
        private void rows_RowsRemoved(object sender, IndexRangeEventArgs e)
        {
            Range l_RemovedRange = new Range(e.StartIndex, 0, e.StartIndex + e.Count - 1, ColumnsCount - 1);

              if (l_RemovedRange.Contains(FocusCellPosition))
              {
            SetFocusCell(Position.Empty);
              }
              if (l_RemovedRange.Contains(mouseCellPosition))
              {
            mouseCellPosition = Position.Empty;
              }
              if (l_RemovedRange.Contains(mouseDownPosition))
              {
            mouseDownPosition = Position.Empty;
              }
        }