IsEmpty() public method

Returns true if the current struct is empty
public IsEmpty ( ) : bool
return bool
Beispiel #1
0
 public RangeRegion(Position position)
 {
     if (position.IsEmpty() == false)
     {
         m_RangeCollection.Add(new Range(position));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Move the active cell (focus), moving the row and column as specified. Returns true if the focus can be moved.
        /// Returns false if there aren't any cell to move.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="rowShift"></param>
        /// <param name="colShift"></param>
        /// <returns></returns>
        public bool MoveActiveCell(Position start, int rowShift, int colShift)
        {
            Position newPosition = Position.Empty;

            //If there isn't a current active cell I try to put the focus on the 0, 0 cell.
            if (start.IsEmpty())
            {
                newPosition = new Position(0, 0);
                if (CanReceiveFocus(newPosition))
                {
                    return(Focus(newPosition));
                }
                else
                {
                    start       = newPosition;
                    newPosition = Position.Empty;
                }
            }

            int currentRow = start.Row;
            int currentCol = start.Column;

            currentRow += rowShift;
            currentCol += colShift;

            while (newPosition.IsEmpty() && currentRow < Grid.Rows.Count && currentCol < Grid.Columns.Count &&
                   currentRow >= 0 && currentCol >= 0)
            {
                newPosition = new Position(currentRow, currentCol);

                //verifico che la posizione di partenza non coincida con quella di focus, altrimenti significa che ci stiamo spostando sulla stessa cella perchè usa un RowSpan/ColSpan
                if (Grid.PositionToStartPosition(newPosition) == start)
                {
                    newPosition = Position.Empty;
                }
                else
                {
                    if (CanReceiveFocus(newPosition) == false)
                    {
                        newPosition = Position.Empty;
                    }
                }

                currentRow += rowShift;
                currentCol += colShift;
            }

            if (newPosition.IsEmpty() == false)
            {
                return(Focus(newPosition));
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
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.
        /// For example suppose to have at grid[0,0] a cell with ColumnSpan equal to 2. If you call this method with the position 0,0 returns 0,0-0,1 and if you call this method with 0,1 return again 0,0-0,1.
        /// </summary>
        /// <param name="pPosition"></param>
        /// <returns></returns>
        public override Range PositionToCellRange(Position pPosition)
        {
            if (pPosition.IsEmpty())
            {
                return(Range.Empty);
            }

            Cells.ICell l_Cell = this[pPosition.Row, pPosition.Column];
            if (l_Cell == null)
            {
                return(new Range(pPosition));
            }
            else
            {
                return(l_Cell.Range);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Indicates if the specified cell is selected
        /// </summary>
        /// <param name="p_Cell"></param>
        /// <returns></returns>
        public virtual bool Contains(Position p_Cell)
        {
            if (p_Cell.IsEmpty() || IsEmpty())
            {
                return(false);
            }

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

            return(false);
        }
Beispiel #5
0
        public Range FindDestinationRange(GridVirtual destinationGrid, Position dropDestination)
        {
            if (dropDestination.IsEmpty())
            {
                return(Range.Empty);
            }

            Position destinationStart = new Position(dropDestination.Row + (mSourceRange.Start.Row - mStartDragPosition.Row),
                                                     dropDestination.Column + (mSourceRange.Start.Column - mStartDragPosition.Column));

            destinationStart = Position.Max(destinationStart, new Position(0, 0));

            Range destination = mSourceRange;

            destination.MoveTo(destinationStart);

            destination = destination.Intersect(destinationGrid.CompleteRange);

            return(destination);
        }
Beispiel #6
0
		private void HandleMouseDoubleClick(Position clickPosition, EventArgs e)
		{
			if (clickPosition.IsEmpty() == true)
				return;
			Cells.ICellVirtual mouseDownCell = GetCell(clickPosition);
			if (mouseDownCell != null)
				Controller.OnDoubleClick(new CellContext(this, clickPosition, mouseDownCell), e);
		}
Beispiel #7
0
        /// <summary>
        /// Change the focus of the grid.
        /// The calls order is:
        ///
        /// (the user select CellX)
        /// CellX.FocusEntering
        /// Grid.CellGotFocus(CellX),
        /// CellX.FocusEntered,
        /// [OnFocusRowEntered],
        /// [OnFocusColumnEntered]
        ///
        /// (the user select CellY),
        /// CellY.FocusEntering
        /// CellX.FocusLeaving
        /// Grid.CellLostFocus(CellX),
        /// [OnFocusRowLeaving],
        /// [OnFocusColumnLeaving],
        /// CellX.FocusLeft,
        /// Grid.CellGotFocus(CellY),
        /// CellY.FocusEntered,
        /// [OnFocusRowEntered],
        /// [OnFocusColumnEntered]
        ///
        /// Use Position.Empty to remove the focus cell.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">Reset the other selected cells.</param>
        /// <returns></returns>
        public virtual bool Focus(Position pCellToActivate, bool pResetSelection)
        {
            //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
            bool deselectOtherCells = false;

            if (pCellToActivate.IsEmpty() == false && pResetSelection)
            {
                deselectOtherCells = true;
            }

            pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

            //Questo controllo è necessario altrimenti l'evento verrebbe scatenato due volte per la stessa cella
            if (pCellToActivate != ActivePosition)
            {
                //GotFocus Event Arguments
                Cells.ICellVirtual            newCellToFocus    = Grid.GetCell(pCellToActivate);
                CellContext                   newCellContext    = new CellContext(Grid, pCellToActivate, newCellToFocus);
                ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                //LostFocus Event Arguments
                Cells.ICellVirtual            oldCellFocus       = Grid.GetCell(ActivePosition);
                CellContext                   oldCellContext     = new CellContext(Grid, ActivePosition, oldCellFocus);
                ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                if (newCellToFocus != null)
                {
                    //Cell Focus Entering
                    Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
                    if (gotFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //If the cell can't receive the focus stop the focus operation
                    if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
                    {
                        return(false);
                    }
                }

                //If the focus is already insede the grid (bug maybe in another control) or the new cell is valid
                if (Grid.ContainsFocus || newCellToFocus != null)
                {
                    //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false. This is useful for 2 reason:
                    //	-To validate the editor
                    //	-To check if I can move the focus on another cell
                    bool canFocus = Grid.SetFocusOnCells(true);
                    if (canFocus == false)
                    {
                        return(false);
                    }
                }


                if (oldCellFocus != null)
                {
                    //Cell Focus Leaving
                    Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }
                }

                //Deselect previous selected cells
                if (deselectOtherCells)
                {
                    Clear();
                }

                bool success;
                if (newCellToFocus != null)
                {
                    //Cell Got Focus
                    OnCellGotFocus(gotFocusEventArgs);

                    success = (!gotFocusEventArgs.Cancel);
                }
                else
                {
                    success = true;
                }

                return(success);
            }
            else
            {
                return(true);
            }
        }
Beispiel #8
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.
		/// For example suppose to have at grid[0,0] a cell with ColumnSpan equal to 2. If you call this method with the position 0,0 returns 0,0-0,1 and if you call this method with 0,1 return again 0,0-0,1.
		/// </summary>
		/// <param name="pPosition"></param>
		/// <returns></returns>
		public override Range PositionToCellRange(Position pPosition)
		{
			if (pPosition.IsEmpty())
				return Range.Empty;

			Cells.ICell l_Cell = this[pPosition.Row, pPosition.Column];
			if (l_Cell == null)
				return Range.Empty;
			else
				return l_Cell.Range;
		}
Beispiel #9
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.
		/// For example suppose to have at grid[0,0] a cell with ColumnSpan equal to 2. If you call this method with the position 0,0 returns 0,0-0,1 and if you call this method with 0,1 return again 0,0-0,1.
		/// </summary>
		/// <param name="pPosition"></param>
		/// <returns></returns>
		public virtual Range PositionToCellRange(Position pPosition)
		{
			if (pPosition.IsEmpty())
				return Range.Empty;

			ICellVirtual l_Cell = this.GetCell(pPosition.Row, pPosition.Column);
			if (l_Cell == null)
				return Range.Empty;
			else
				return new Range(pPosition);
			//return new Range(pPosition);
		}
Beispiel #10
0
        /// <summary>
        /// Fired when a cell lost the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellLostFocus(ChangeActivePositionEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            CellContext cellLostContext = new CellContext(Grid, e.OldFocusPosition);

            //Stop the Edit operation
            if (cellLostContext.EndEdit(false) == false)
            {
                e.Cancel = true;
            }

            if (e.Cancel)
            {
                return;
            }

            //evento Lost Focus
            if (CellLostFocus != null)
            {
                CellLostFocus(this, e);
            }
            if (e.Cancel)
            {
                return;
            }

            //Row/Column leaving
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusRow = ActivePosition.Row;

            if (ActivePosition.IsEmpty() == false && focusRow != e.NewFocusPosition.Row)
            {
                RowCancelEventArgs rowArgs = new RowCancelEventArgs(focusRow);
                OnFocusRowLeaving(rowArgs);
                if (rowArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusColumn = ActivePosition.Column;

            if (ActivePosition.IsEmpty() == false && focusColumn != e.NewFocusPosition.Column)
            {
                ColumnCancelEventArgs columnArgs = new ColumnCancelEventArgs(focusColumn);
                OnFocusColumnLeaving(columnArgs);
                if (columnArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }

            //Change the focus cell to Empty
            m_ActivePosition = Position.Empty; //from now the cell doesn't have the focus

            //Cell Focus Left
            Grid.Controller.OnFocusLeft(new CellContext(Grid, e.OldFocusPosition), EventArgs.Empty);
        }
Beispiel #11
0
		/// <summary>
		/// Return the Cell at the specified Row and Col position. This method is called for sort operations and for Move operations. If position is Empty return null. This method calls GetCell(int p_iRow, int p_iCol)
		/// </summary>
		/// <param name="p_Position"></param>
		/// <returns></returns>
		public Cells.ICellVirtual GetCell(Position p_Position)
		{
			if (p_Position.IsEmpty())
				return null;
			else
				return GetCell(p_Position.Row, p_Position.Column);
		}
Beispiel #12
0
		/// <summary>
		/// Returns the type of a cell position
		/// </summary>
		/// <param name="position"></param>
		/// <returns></returns>
		public CellPositionType GetPositionType(Position position)
		{
			if (position.IsEmpty())
				return CellPositionType.Empty;
			else if (position.Row < FixedRows && position.Column < FixedColumns)
				return CellPositionType.FixedTopLeft;
			else if (position.Row < FixedRows)
				return CellPositionType.FixedTop;
			else if (position.Column < FixedColumns)
				return CellPositionType.FixedLeft;
			else
				return CellPositionType.Scrollable;
		}
Beispiel #13
0
		protected override void OnKeyDown(KeyEventArgs e)
		{
			base.OnKeyDown(e);
			m_keybordActivePosition = Selection.ActivePosition;

			if (m_keybordActivePosition.IsEmpty() == false)
			{
				Cells.ICellVirtual focusCell = GetCell(m_keybordActivePosition);
				if (focusCell != null)
					Controller.OnKeyDown(new CellContext(this, m_keybordActivePosition, focusCell), e);
			}

			if (e.Handled == false)
				ProcessSpecialGridKey(e);
		}
Beispiel #14
0
        /// <summary>
        /// Move the active cell (focus), moving the row and column as specified.
        /// Try to set the focus using the first shift, if failed try to use the second shift (rowShift2, colShift2).
        /// If rowShift2 or colShift2 is int.MaxValue the next start position is the maximum row or column, if is int.MinValue 0 is used, otherwise the current position is shifted using the specified value.
        /// This method is usually used for the Tab navigation using this code : MoveActiveCell(0,1,1,0);
        /// Returns true if the focus can be moved.
        /// Returns false if there aren't any cell to move.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="rowShift1"></param>
        /// <param name="colShift1"></param>
        /// <param name="rowShift2"></param>
        /// <param name="colShift2"></param>
        /// <returns></returns>
        public bool MoveActiveCell(Position start, int rowShift1, int colShift1, int rowShift2, int colShift2)
        {
            bool ret = MoveActiveCell(start, rowShift1, colShift1);

            if (ret)
            {
                return(true);
            }
            else
            {
                Position newPosition = Position.Empty;

                //If there isn't a current active cell I try to put the focus on the 0, 0 cell.
                if (start.IsEmpty())
                {
                    newPosition = new Position(0, 0);
                    if (CanReceiveFocus(newPosition))
                    {
                        return(Focus(newPosition));
                    }
                    else
                    {
                        start = newPosition;
                    }
                }

                int row;
                if (rowShift2 == int.MinValue)
                {
                    row = 0;
                }
                else if (rowShift2 == int.MaxValue)
                {
                    row = Grid.Rows.Count - 1;
                }
                else
                {
                    row = start.Row + rowShift2;
                }

                int column;
                if (colShift2 == int.MinValue)
                {
                    column = 0;
                }
                else if (colShift2 == int.MaxValue)
                {
                    column = Grid.Columns.Count - 1;
                }
                else
                {
                    column = start.Column + colShift2;
                }

                newPosition = new Position(row, column);

                if (newPosition == start || Grid.CompleteRange.Contains(newPosition) == false)
                {
                    return(false);
                }

                if (CanReceiveFocus(newPosition))
                {
                    return(Focus(newPosition));
                }
                else
                {
                    start = newPosition;
                }
                return(MoveActiveCell(start, rowShift1, colShift1, rowShift2, colShift2));
            }
        }
Beispiel #15
0
		/// <summary>
		/// Fired when the cell under the mouse change. For internal use only.
		/// </summary>
		/// <param name="p_Cell"></param>
		public virtual void ChangeMouseCell(Position p_Cell)
		{
			if (m_MouseCellPosition != p_Cell)
			{
				//se la cella che sta perdento il mouse è anche quella che ha ricevuto un eventuale evento di MouseDown non scateno il MouseLeave (che invece verrà scatenato dopo il MouseUp)
				if (m_MouseCellPosition.IsEmpty() == false &&
				    m_MouseCellPosition != m_MouseDownPosition)
				{
					Controller.OnMouseLeave(new CellContext(this, m_MouseCellPosition), EventArgs.Empty);
				}

				m_MouseCellPosition = p_Cell;
				if (m_MouseCellPosition.IsEmpty() == false)
				{
					Controller.OnMouseEnter(new CellContext(this, m_MouseCellPosition), EventArgs.Empty);
				}
			}
		}
Beispiel #16
0
        /// <summary>
        /// Indicates if the specified cell is selected
        /// </summary>
        /// <param name="p_Cell"></param>
        /// <returns></returns>
        public virtual bool Contains(Position p_Cell)
        {
            if (p_Cell.IsEmpty() || IsEmpty())
                return false;

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

            return false;
        }
Beispiel #17
0
        /// <summary>
        /// Calculate the destination range for the drop or paste operations.
        /// </summary>
        /// <param name="destinationGrid"></param>
        /// <param name="dropDestination"></param>
        /// <returns></returns>
        public Range FindDestinationRange(GridVirtual destinationGrid, Position dropDestination)
        {
            if (dropDestination.IsEmpty())
                return Range.Empty;

            Position destinationStart = new Position(dropDestination.Row + (mSourceRange.Start.Row - mStartDragPosition.Row),
                dropDestination.Column + (mSourceRange.Start.Column - mStartDragPosition.Column) );

            destinationStart = Position.Max(destinationStart, new Position(0, 0));

            Range destination = mSourceRange;
            destination.MoveTo( destinationStart );

            destination = destination.Intersect(destinationGrid.CompleteRange);

            return destination;
        }