Example #1
0
        /// <summary>
        /// Move forward selection
        /// </summary>
        public void MoveSelectionForward()
        {
            if (SelectionMovedForward != null)
            {
                var arg = new SelectionMovedForwardEventArgs();
                SelectionMovedForward(this, arg);
                if (arg.IsCancelled)
                {
                    return;
                }
            }

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

            switch (selectionForwardDirection)
            {
            case SelectionForwardDirection.Right:
            {
                if (this.selEnd.Col < this.cols.Count - 1)
                {
                    MoveSelectionRight();
                }
                else
                {
                    if (this.selEnd.Row < this.rows.Count - 1)
                    {
                        this.selEnd.Col = 0;
                        MoveSelectionDown();
                    }
                }
            }
            break;

            case SelectionForwardDirection.Down:
            {
                if (this.selEnd.Row < this.rows.Count - 1)
                {
                    this.selEnd.Col = this.focusReturnColumn;

                    MoveSelectionDown();
                }
                else
                {
                    if (this.selEnd.Col < this.cols.Count - 1)
                    {
                        this.selEnd.Row = 0;
                        MoveSelectionRight();
                    }
                }
            }
            break;
            }
        }
Example #2
0
        public RSColumnObject(Worksheet sheet, ColumnHeader colHeader)
        {
            this.sheet     = sheet;
            this.colHeader = colHeader;

            this["width"] = new ExternalProperty(
                () => colHeader.Width,
                (v) => colHeader.Width = (ushort)ScriptRunningMachine.GetIntValue(v));

            this["visible"] = new ExternalProperty(
                () => colHeader.IsVisible,
                (v) => colHeader.IsVisible = ScriptRunningMachine.GetBoolValue(v));
        }
Example #3
0
        public RSRowObject(Worksheet sheet, RowHeader rowHeader)
        {
            this.sheet     = sheet;
            this.rowHeader = rowHeader;

            this["height"] = new ExternalProperty(
                () => rowHeader.Height,
                (v) => rowHeader.Height = (ushort)ScriptRunningMachine.GetIntValue(v));

            this["visible"] = new ExternalProperty(
                () => rowHeader.IsVisible,
                (v) => rowHeader.IsVisible = ScriptRunningMachine.GetBoolValue(v));
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
        /// <summary>
        /// Move backward selection
        /// </summary>
        public void MoveSelectionBackward()
        {
            if (SelectionMovedBackward != null)
            {
                var arg = new SelectionMovedBackwardEventArgs();
                SelectionMovedBackward(this, arg);
                if (arg.IsCancelled)
                {
                    return;
                }
            }

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

            switch (selectionForwardDirection)
            {
            case SelectionForwardDirection.Right:
            {
                if (selEnd.Col > 0)
                {
                    MoveSelectionLeft();
                }
            }
            break;

            case SelectionForwardDirection.Down:
            {
                if (selEnd.Row > 0)
                {
                    MoveSelectionUp();
                }
            }
            break;
            }
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
0
        internal bool StartEdit(Cell cell, string newText)
        {
            // abort if either spreadsheet or cell is readonly
            if (this.HasSettings(WorksheetSettings.Edit_Readonly) ||
                cell == null || cell.IsReadOnly)
            {
                return(false);
            }

            if (this.focusPos != cell.Position)
            {
                this.FocusPos = cell.Position;
            }
            else
            {
                this.ScrollToCell(cell);
            }

            string editText = null;

            if (newText == null)
            {
                if (!string.IsNullOrEmpty(cell.InnerFormula))
                {
                    editText = "=" + cell.InnerFormula;
                }
                else if (cell.InnerData is string)
                {
                    editText = (string)cell.InnerData;
                }
#if DRAWING && RICHTEXT
                else if (cell.InnerData is Drawing.RichText)
                {
                    editText = ((Drawing.RichText)cell.InnerData).ToString();
                }
#endif // DRAWING && RICHTEXT
                else
                {
                    editText = Convert.ToString(cell.InnerData);
                }

                this.backupData = editText;
            }
            else
            {
                editText = newText;

                this.backupData = cell.DisplayText;
            }

            if (cell.DataFormat == CellDataFormatFlag.Percent &&
                this.HasSettings(WorksheetSettings.Edit_FriendlyPercentInput))
            {
                double val;

                if (double.TryParse(editText, out val))
                {
                    editText = (newText == null ? (val * 100) : val) + "%";
                }
            }

            if (BeforeCellEdit != null)
            {
                CellBeforeEditEventArgs arg = new CellBeforeEditEventArgs(cell)
                {
                    EditText = editText,
                };

                BeforeCellEdit(this, arg);

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

                editText = arg.EditText;
            }

#if EX_SCRIPT
            // v0.8.2: 'beforeCellEdit' renamed to 'onCellEdit'
            // v0.8.5: 'onCellEdit' renamed to 'oncelledit'
            object scriptReturn = RaiseScriptEvent("oncelledit", new RSCellObject(this, cell.InternalPos, cell));
            if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn))
            {
                return(false);
            }
#endif

            if (cell.body != null)
            {
                bool canContinue = cell.body.OnStartEdit();
                if (!canContinue)
                {
                    return(false);
                }
            }

            if (currentEditingCell != null)
            {
                EndEdit(this.controlAdapter.GetEditControlText());
            }

            this.currentEditingCell = cell;

            this.controlAdapter.SetEditControlText(editText);

            if (cell.DataFormat == CellDataFormatFlag.Percent && editText.EndsWith("%"))
            {
                this.controlAdapter.SetEditControlCaretPos(editText.Length - 1);
            }

            RGFloat x = 0;

            RGFloat width = (cell.Width - 1) * this.renderScaleFactor;

            int cellIndentSize = 0;

            //if ((cell.InnerStyle.Flag & PlainStyleFlag.Indent) == PlainStyleFlag.Indent)
            //{
            //indentSize = (int)Math.Round(cell.InnerStyle.Indent * this.indentSize * this.scaleFactor);
            //width -= indentSize;
            //}

#if WINFORM
            if (width < cell.TextBounds.Width)
            {
                width = cell.TextBounds.Width;
            }
#elif WPF
            // why + 6 ?
            if (width < cell.TextBounds.Width)
            {
                width = cell.TextBounds.Width + 6;
            }
#endif

            width--;
            //width = (width - 1);

            RGFloat scale = this.renderScaleFactor;

            #region Horizontal alignment
            switch (cell.RenderHorAlign)
            {
            default:
            case ReoGridRenderHorAlign.Left:
                this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Left);
                x = cell.Left * scale + 1 + cellIndentSize;
                break;

            case ReoGridRenderHorAlign.Center:
                this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center);
                x = (cell.Left * scale + (((cell.Width - 1) * scale - 1) - width) / 2) + 1;
                break;

            case ReoGridRenderHorAlign.Right:
                this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Right);
                x = (cell.Right - 1) * scale - width - cellIndentSize;
                break;
            }

            if (cell.InnerStyle.HAlign == ReoGridHorAlign.DistributedIndent)
            {
                this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center);
            }
            #endregion             // Horizontal alignment

            RGFloat y = cell.Top * scale + 1;

            //this.viewportController.CellPositionToControl(

            var activeViewport = viewportController.FocusView as IViewport;

            int boxX = (int)Math.Round(x + viewportController.FocusView.Left - (activeViewport == null ? 0 : (activeViewport.ViewLeft * scale)));
            int boxY = (int)Math.Round(y + viewportController.FocusView.Top - (activeViewport == null ? 0 : (activeViewport.ViewTop * scale)));

            RGFloat height = (cell.Height - 1) * scale - 1;

            if (!cell.IsMergedCell && cell.InnerStyle.TextWrapMode != TextWrapMode.NoWrap)
            {
                if (height < cell.TextBounds.Height)
                {
                    height = cell.TextBounds.Height;
                }
            }

            int offsetHeight = 0;            // (int)Math.Round(height);// (int)Math.Round(height + 2 - (cell.Height));

            if (offsetHeight > 0)
            {
                switch (cell.InnerStyle.VAlign)
                {
                case ReoGridVerAlign.Top:
                    break;

                default:
                case ReoGridVerAlign.Middle:
                    boxY -= offsetHeight / 2;
                    break;

                case ReoGridVerAlign.Bottom:
                    boxY -= offsetHeight;
                    break;
                }
            }

            Rectangle rect = new Rectangle(boxX, boxY, width, height);

            this.controlAdapter.ShowEditControl(rect, cell);

            return(true);
        }
Example #10
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);
        }