Exemple #1
0
 /// <summary>
 /// Copy the specified RangeData object the the clipboard
 /// </summary>
 /// <param name="rangeData"></param>
 public static void ClipboardSetData(RangeData rangeData)
 {
     if (rangeData.mClipboardDataObject == null)
     {
         throw new SourceGridException("No data loaded, use the LoadData method");
     }
     System.Windows.Forms.Clipboard.SetDataObject(rangeData.mClipboardDataObject);
 }
Exemple #2
0
        /// <summary>
        /// Load the specified range data into a string array. This method use the cell editor to get the value.
        /// </summary>
        /// <param name="sourceGrid"></param>
        /// <param name="sourceRange"></param>
        /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param>
        public static RangeData LoadData(GridVirtual sourceGrid, Range sourceRange, CutMode cutMode)
        {
            RangeData data = new RangeData(sourceGrid);

            //mCutMode = cutMode;
            data.mSourceRange  = sourceRange;
            data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)];

            int arrayRow = 0;

            for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++)
            {
                int arrayCol = 0;
                for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++)
                {
                    if (sourceGrid.Columns.IsColumnVisible(c) == false)
                    {
                        continue;
                    }
                    Position           posCell     = new Position(r, c);
                    Cells.ICellVirtual cell        = sourceGrid.GetCell(posCell);
                    CellContext        cellContext = new CellContext(sourceGrid, posCell, cell);

                    /*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported())
                     *      data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) );
                     * else if (cell != null)
                     *      data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/
                    if (cell != null)
                    {
                        data.mSourceValues[arrayRow, arrayCol] = cellContext.Value;
                    }
                    arrayCol++;
                }
            }

            //Cut Data
            if (cutMode == CutMode.CutImmediately && sourceGrid != null)
            {
                sourceGrid.ClearValues(new RangeRegion(sourceRange));
            }

            data.mClipboardDataObject = new System.Windows.Forms.DataObject();
            data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data);
            string[,] values = DataToStringArray(sourceGrid, data.mSourceRange);
            data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values));
            return(data);
        }
Exemple #3
0
        /// <summary>
        /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats.
        /// </summary>
        /// <returns></returns>
        public static RangeData ClipboardGetData()
        {
            System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject();
            RangeData rngData = null;

            if (dtObj.GetDataPresent(RANGEDATA_FORMAT))
            {
                rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT);
            }
            else
            {
                if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.Text, true))
                {
                    string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.Text, true);
                    rngData = new RangeData();
                    rngData.LoadData(buffer);
                }
            }

            return(rngData);
        }
Exemple #4
0
        /// <summary>
        /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats.
        /// </summary>
        /// <returns></returns>
        public static RangeData ClipboardGetData()
        {
            System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject();
            RangeData rngData = null;

            if (dtObj.GetDataPresent(RANGEDATA_FORMAT))
            {
                rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT);
            }

            // if RANGEDATA_FORMAT or GetData returns null use string buffer as rngData
            if (rngData == null)
            {
                // get unicode text instead of text
                if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText, true))
                {
                    string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.UnicodeText, true);
                    rngData = new RangeData();
                    rngData.LoadData(buffer);
                }
            }

            return(rngData);
        }
Exemple #5
0
        /// <summary>
        /// Process Delete, Ctrl+C, Ctrl+V, Up, Down, Left, Right, Tab keys 
        /// </summary>
        /// <param name="e"></param>
        public virtual void ProcessSpecialGridKey(KeyEventArgs e)
        {
            if (e.Handled)
                return;

            bool enableArrows,enableTab,enablePageDownUp;
            enableArrows = enableTab = enablePageDownUp = false;

            if ( (SpecialKeys & GridSpecialKeys.Arrows) == GridSpecialKeys.Arrows)
                enableArrows = true;
            if ( (SpecialKeys & GridSpecialKeys.PageDownUp) == GridSpecialKeys.PageDownUp)
                enablePageDownUp = true;
            if ( (SpecialKeys & GridSpecialKeys.Tab) == GridSpecialKeys.Tab)
                enableTab = true;

            bool enableEscape = false;
            if ( (SpecialKeys & GridSpecialKeys.Escape) == GridSpecialKeys.Escape)
                enableEscape = true;
            bool enableEnter = false;
            if ( (SpecialKeys & GridSpecialKeys.Enter) == GridSpecialKeys.Enter)
                enableEnter = true;

            #region Processing keys
            //Escape
            if (e.KeyCode == Keys.Escape && enableEscape)
            {
                CellContext focusCellContext = new CellContext(this, Selection.ActivePosition);
                if (focusCellContext.Cell != null && focusCellContext.IsEditing())
                {
                    if (focusCellContext.EndEdit(true))
                        e.Handled = true;
                }
            }

            //Enter
            if (e.KeyCode == Keys.Enter && enableEnter)
            {
                CellContext focusCellContext = new CellContext(this, Selection.ActivePosition);
                if (focusCellContext.Cell != null && focusCellContext.IsEditing())
                {
                    focusCellContext.EndEdit(false);

                    e.Handled = true;
                }
            }

            //Tab
            if (e.KeyCode == Keys.Tab && enableTab)
            {
                CellContext focusCellContext = new CellContext(this, Selection.ActivePosition);
                if (focusCellContext.Cell != null && focusCellContext.IsEditing())
                {
                    //se l'editing non riesce considero il tasto processato
                    // altrimenti no, in questo modo il tab ha effetto anche per lo spostamento
                    if (focusCellContext.EndEdit(false) == false)
                    {
                        e.Handled = true;
                        return;
                    }
                }
            }
            #endregion

            #region Navigate keys: arrows, tab and PgDown/Up
            if (e.KeyCode == Keys.Down && enableArrows)
            {
                Selection.MoveActiveCell(1, 0);
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Up && enableArrows)
            {
                Selection.MoveActiveCell(-1, 0);
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Right && enableArrows)
            {
                Selection.MoveActiveCell(0, 1);
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Left && enableArrows)
            {
                Selection.MoveActiveCell(0, -1);
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Tab && enableTab)
            {
                //If the tab failed I automatically select the next control in the form (SelectNextControl)

                if (e.Modifiers == Keys.Shift) // backward
                {
                    if (Selection.MoveActiveCell(0, -1, -1, int.MaxValue) == false)
                        FindForm().SelectNextControl(this, false, true, true, true);
                    e.Handled = true;
                }
                else //forward
                {
                    if (Selection.MoveActiveCell(0, 1, 1, int.MinValue) == false)
                        FindForm().SelectNextControl(this, true, true, true, true);
                    e.Handled = true;
                }
            }
            else if ( (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown)
                   && enablePageDownUp)
            {
                Point focusPoint = PositionToRectangle(Selection.ActivePosition).Location;
                focusPoint.Offset(1, 1); //in modo da entrare nella cella

                if (e.KeyCode == Keys.PageDown)
                    CustomScrollPageDown();
                else if (e.KeyCode == Keys.PageUp)
                    CustomScrollPageUp();

                Position newPosition = PositionAtPoint(focusPoint);
                if (Selection.CanReceiveFocus(newPosition))
                    Selection.Focus(newPosition, true);

                e.Handled = true;
            }
            #endregion

            #region Clipboard
            bool pasteEnabled = (ClipboardMode & ClipboardMode.Paste) == ClipboardMode.Paste;
            bool copyEnabled = (ClipboardMode & ClipboardMode.Copy) == ClipboardMode.Copy;
            bool cutEnabled = (ClipboardMode & ClipboardMode.Cut) == ClipboardMode.Cut;
            bool deleteEnabled = (ClipboardMode & ClipboardMode.Delete) == ClipboardMode.Delete;

            RangeRegion selRegion = Selection.GetSelectionRegion();

            //Paste
            if (e.Control && e.KeyCode == Keys.V && pasteEnabled && selRegion.IsEmpty() == false)
            {
                RangeData rngData = RangeData.ClipboardGetData();

                if (rngData != null)
                {
                    Range rng = selRegion.GetRanges()[0];

                    Range destinationRange = rngData.FindDestinationRange(this, rng.Start);

                    rngData.WriteData(this, destinationRange);
                    e.Handled = true;

                    Selection.ResetSelection(true);
                    Selection.SelectRange(destinationRange, true);
                }
            }
            //Copy
            else if (e.Control && e.KeyCode == Keys.C && copyEnabled && selRegion.IsEmpty() == false)
            {
                Range rng = selRegion.GetRanges()[0];

                RangeData data = new RangeData();
                data.LoadData(this, rng, rng.Start, CutMode.None);
                RangeData.ClipboardSetData(data);

                e.Handled = true;
            }
            //Cut
            else if (e.Control && e.KeyCode == Keys.X && cutEnabled && selRegion.IsEmpty() == false)
            {
                Range rng = selRegion.GetRanges()[0];

                RangeData data = new RangeData();
                data.LoadData(this, rng, rng.Start, CutMode.CutImmediately);
                RangeData.ClipboardSetData(data);

                e.Handled = true;
            }
            //Delete
            else if (e.KeyCode == Keys.Delete && deleteEnabled)
            {
                ClearValues(selRegion);

                e.Handled = true;
            }
            #endregion
        }
Exemple #6
0
        /// <summary>
        /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats.
        /// </summary>
        /// <returns></returns>
        public static RangeData ClipboardGetData()
        {
            System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject();
            RangeData rngData = null;
            if (dtObj.GetDataPresent(RANGEDATA_FORMAT))
                rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT);
            else
            {
                if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.Text, true))
                {
                    string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.Text,true);
                    rngData = new RangeData();
                    rngData.LoadData(buffer);
                }
            }

            return rngData;
        }
Exemple #7
0
 /// <summary>
 /// Copy the specified RangeData object the the clipboard
 /// </summary>
 /// <param name="rangeData"></param>
 public static void ClipboardSetData(RangeData rangeData)
 {
     if (rangeData.mClipboardDataObject == null)
         throw new SourceGridException("No data loaded, use the LoadData method");
     System.Windows.Forms.Clipboard.SetDataObject(rangeData.mClipboardDataObject);
 }
Exemple #8
0
		/// <summary>
		/// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats.
		/// </summary>
		/// <returns></returns>
		public static RangeData ClipboardGetData()
		{
			System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject();
			RangeData rngData = null;
			if (dtObj.GetDataPresent(RANGEDATA_FORMAT))
				rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT);

            // if RANGEDATA_FORMAT or GetData returns null use string buffer as rngData
            if (rngData == null)
            {
                // get unicode text instead of text
                if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText, true))
                {
                    string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.UnicodeText, true);
                    rngData = new RangeData();
                    rngData.LoadData(buffer);
                }
            }

			return rngData;
		}
Exemple #9
0
		/// <summary>
		/// Load the specified range data into a string array. This method use the cell editor to get the value.
		/// </summary>
		/// <param name="sourceGrid"></param>
		/// <param name="sourceRange"></param>
		/// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param>
		public static RangeData LoadData(GridVirtual sourceGrid, Range sourceRange, CutMode cutMode)
		{
			RangeData data = new RangeData(sourceGrid);
			//mCutMode = cutMode;
			data.mSourceRange= sourceRange;
			data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)];

			int arrayRow = 0;
			for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++)
			{
				int arrayCol = 0;
				for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++)
				{
					if (sourceGrid.Columns.IsColumnVisible(c) == false)
						continue;
					Position posCell = new Position(r, c);
					Cells.ICellVirtual cell = sourceGrid.GetCell(posCell);
					CellContext cellContext = new CellContext(sourceGrid, posCell, cell);
					/*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported())
						data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) );
					else if (cell != null)
						data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/
                    if (cell != null)
                        data.mSourceValues[arrayRow, arrayCol] = cellContext.Value;
					arrayCol++;
				}
			}

			//Cut Data
			if (cutMode == CutMode.CutImmediately && sourceGrid != null)
			{
				sourceGrid.ClearValues(new RangeRegion(sourceRange));
			}

			data.mClipboardDataObject = new System.Windows.Forms.DataObject();
			data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data);
            string[,] values = DataToStringArray(sourceGrid, data.mSourceRange);
			data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values));
			return data;
		}
Exemple #10
0
        /// <summary>
        /// Load the specified range data into a string array. This method use the cell editor to get the value.
        /// </summary>
        /// <param name="sourceGrid"></param>
        /// <param name="sourceRange"></param>
        /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param>
        public static RangeData LoadData(GridVirtual sourceGrid, Range sourceRange, CutMode cutMode)
        {
            RangeData data = new RangeData(sourceGrid);

            //mCutMode = cutMode;
            data.mSourceRange  = sourceRange;
            data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)];

            int arrayRow = 0;

            for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++)
            {
                int arrayCol = 0;
                for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++)
                {
                    if (sourceGrid.Columns.IsColumnVisible(c) == false)
                    {
                        continue;
                    }
                    Position           posCell     = new Position(r, c);
                    Cells.ICellVirtual cell        = sourceGrid.GetCell(posCell);
                    CellContext        cellContext = new CellContext(sourceGrid, posCell, cell);

                    /*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported())
                     *      data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) );
                     * else if (cell != null)
                     *      data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/

                    //[email protected] : LoadData method is changed to support cut and copy activities.
                    if (cell != null)
                    {
                        if (cutMode == CutMode.CutImmediately)
                        {
                            if ((cell.ClipboardModes & ClipboardMode.Cut) == ClipboardMode.Cut)
                            {
                                data.mSourceValues[arrayRow, arrayCol] = cellContext.Value;
                            }
                        }
                        else if (cutMode == CutMode.None)
                        {
                            if ((cell.ClipboardModes & ClipboardMode.Copy) == ClipboardMode.Copy)
                            {
                                data.mSourceValues[arrayRow, arrayCol] = cellContext.Value;
                            }
                        }
                    }
                    arrayCol++;
                }
            }

            data.mClipboardDataObject = new System.Windows.Forms.DataObject();
            data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data);
            string[,] values = DataToStringArray(sourceGrid, data.mSourceRange);
            data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values));

            //Cut Data
            //[email protected] : Cut operation is moved below the copy operation to retain the data
            if (cutMode == CutMode.CutImmediately && sourceGrid != null)
            {
                sourceGrid.ClearValues(new RangeRegion(sourceRange), ClipboardMode.Cut);
            }

            return(data);
        }