Esempio n. 1
0
        void grid_BeforePaste(object sender, BeforeRangeOperationEventArgs e)
        {
            if (chkPreventPasteEvent.Checked || chkCustomizePaste.Checked)
            {
                e.IsCancelled = true;

                if (chkCustomizePaste.Checked)
                {
                    string text = Clipboard.GetText();

                    object[,] data = RGUtility.ParseTabbedString(text);

                    // set a new range
                    var applyRange = new RangePosition(worksheet.SelectionRange.Row,
                                                       worksheet.SelectionRange.Col,
                                                       data.GetLength(0), data.GetLength(1));

                    worksheet.SetRangeData(applyRange, data);

                    worksheet.SetRangeStyles(applyRange, new WorksheetRangeStyle
                    {
                        Flag      = PlainStyleFlag.BackAll,
                        BackColor = Color.Yellow,
                    });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Copy any remove anything from selected range into Clipboard.
        /// </summary>
        public bool Cut()
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlCut();
            }
            else
            {
                if (!Copy())
                {
                    return(false);
                }

                if (BeforeCut != null)
                {
                    var evtArg = new BeforeRangeOperationEventArgs(this.selectionRange);

                    BeforeCut(this, evtArg);

                    if (evtArg.IsCancelled)
                    {
                        return(false);
                    }
                }

#if EX_SCRIPT
                object scriptReturn = RaiseScriptEvent("oncut");
                if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
                {
                    return(false);
                }
#endif

                if (!HasSettings(WorksheetSettings.Edit_Readonly))
                {
                    if (controlAdapter.ControlInstance is IActionControl actionSupportedControl)
                    {
                        actionSupportedControl.DoAction(this, new RemoveRangeDataAction(currentCopingRange));
                    }
                }

                if (AfterCut != null)
                {
                    AfterCut(this, new RangeEventArgs(this.selectionRange));
                }
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Copy any remove anything from selected range into Clipboard.
        /// </summary>
        public bool Cut()
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlCut();
            }
            else
            {
                if (!Copy())
                {
                    return(false);
                }

                if (BeforeCut != null)
                {
                    var evtArg = new BeforeRangeOperationEventArgs(this.selectionRange);

                    BeforeCut(this, evtArg);

                    if (evtArg.IsCancelled)
                    {
                        return(false);
                    }
                }

#if EX_SCRIPT
                object scriptReturn = RaiseScriptEvent("oncut");
                if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
                {
                    return(false);
                }
#endif

                if (!HasSettings(WorksheetSettings.Edit_Readonly))
                {
                    this.DeleteRangeData(currentCopingRange);
                    this.RemoveRangeStyles(currentCopingRange, PlainStyleFlag.All);
                    this.RemoveRangeBorders(currentCopingRange, BorderPositions.All);
                }

                if (AfterCut != null)
                {
                    AfterCut(this, new RangeEventArgs(this.selectionRange));
                }
            }

            return(true);
        }
Esempio n. 4
0
        private bool RaiseBeforePasteEvent(RangePosition range)
        {
            if (BeforePaste != null)
            {
                var evtArg = new BeforeRangeOperationEventArgs(range);
                BeforePaste(this, evtArg);
                if (evtArg.IsCancelled)
                {
                    return(false);
                }
            }

#if EX_SCRIPT
            object scriptReturn = RaiseScriptEvent("onpaste", new RSRangeObject(this, range));
            if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
            {
                return(false);
            }
#endif // EX_SCRIPT

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Copy data and put into Clipboard.
        /// </summary>
        public bool Copy()
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlCopy();
            }
            else
            {
                this.controlAdapter.ChangeCursor(CursorStyle.Busy);

                try
                {
                    if (BeforeCopy != null)
                    {
                        var evtArg = new BeforeRangeOperationEventArgs(selectionRange);
                        BeforeCopy(this, evtArg);
                        if (evtArg.IsCancelled)
                        {
                            return(false);
                        }
                    }

#if EX_SCRIPT
                    var scriptReturn = RaiseScriptEvent("oncopy");
                    if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
                    {
                        return(false);
                    }
#endif // EX_SCRIPT

                    // highlight current copy range
                    currentCopingRange = selectionRange;

#if WINFORM || WPF
                    DataObject data = new DataObject();
                    data.SetData(ClipBoardDataFormatIdentify,
                                 GetPartialGrid(currentCopingRange, PartialGridCopyFlag.All, ExPartialGridCopyFlag.None, true));

                    string text = StringifyRange(currentCopingRange);
                    if (!string.IsNullOrEmpty(text))
                    {
                        data.SetText(text);
                    }

                    // set object data into clipboard
                    Clipboard.SetDataObject(data);
#endif // WINFORM || WPF

                    if (AfterCopy != null)
                    {
                        AfterCopy(this, new RangeEventArgs(this.selectionRange));
                    }
                }
                catch (Exception ex)
                {
                    this.NotifyExceptionHappen(ex);
                    return(false);
                }
                finally
                {
                    this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault);
                }
            }

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Copy any remove anything from selected range into Clipboard.
        /// </summary>
        /// <param name="byAction">Indicates whether or not perform the cut operation by using an action, which makes the operation can be undone. Default is true.</param>
        /// <returns></returns>
        public bool Cut(bool byAction = true)
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlCut();
            }
            else
            {
                if (!Copy())
                {
                    return(false);
                }

                if (BeforeCut != null)
                {
                    var evtArg = new BeforeRangeOperationEventArgs(this.selectionRange);

                    BeforeCut(this, evtArg);

                    if (evtArg.IsCancelled)
                    {
                        return(false);
                    }
                }

#if EX_SCRIPT
                object scriptReturn = RaiseScriptEvent("oncut");
                if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
                {
                    return(false);
                }
#endif

                if (!HasSettings(WorksheetSettings.Edit_Readonly))
                {
                    DataObject  data        = Clipboard.GetDataObject() as DataObject;
                    PartialGrid partialGrid = data.GetData(ClipBoardDataFormatIdentify) as PartialGrid;

                    int startRow = selectionRange.Row;
                    int startCol = selectionRange.Col;

                    int rows = partialGrid.Rows;
                    int cols = partialGrid.Columns;

                    var range = new RangePosition(startRow, startCol, rows, cols);

                    if (byAction)
                    {
                        DoAction(new CutRangeAction(range, partialGrid));
                    }
                    else
                    {
                        this.DeleteRangeData(range, true);
                        this.RemoveRangeStyles(range, PlainStyleFlag.All);
                        this.RemoveRangeBorders(range, BorderPositions.All);
                    }
                }

                if (AfterCut != null)
                {
                    AfterCut(this, new RangeEventArgs(this.selectionRange));
                }
            }

            return(true);
        }