示例#1
0
        public static BitmapSource Get()
        {
            if (Clipboard.ContainsImage())
            {
                var clipboardData = Clipboard.GetDataObject();

                if (clipboardData != null)
                {
                    if (clipboardData.GetDataPresent(DataFormats.Bitmap))
                    {
                        var bitmap  = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                        var hBitmap = bitmap.GetHbitmap();

                        try
                        {
                            return(Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                        }
                        finally
                        {
                            DeleteObject(hBitmap);
                        }
                    }
                }
            }

            return(null);
        }
        private static bool HasClipboardPowerpointSlideContent()
        {
            var data = Clipboard.GetDataObject();

            if (data == null)
            {
                return(false);
            }
            var formats = data.GetFormats();

            return(formats.Any(f => f.StartsWith("PowerPoint")));
        }
示例#3
0
        /// <summary>
        /// Copy data from Clipboard and put on grid.
        ///
        /// Currently ReoGrid supports the following types of source from the clipboard.
        ///  - Data from another ReoGrid instance
        ///  - Plain/Unicode Text from any Windows Applications
        ///  - Tabbed Plain/Unicode Data from Excel or similar applications
        ///
        /// When data copied from another ReoGrid instance, and the destination range
        /// is bigger than the source, ReoGrid will try to repeat putting data to fill
        /// the destination range entirely.
        ///
        /// Todo: Copy border and cell style from Excel.
        /// </summary>
        public bool Paste()
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlPaste();
            }
            else
            {
                // Paste method will always perform action to do paste

                // do nothing if in readonly mode
                if (this.HasSettings(WorksheetSettings.Edit_Readonly)
                    // or selection is empty
                    || this.selectionRange.IsEmpty)
                {
                    return(false);
                }

                try
                {
                    this.controlAdapter.ChangeCursor(CursorStyle.Busy);

                    PartialGrid partialGrid   = null;
                    string      clipboardText = null;

#if WINFORM || WPF
                    DataObject data = Clipboard.GetDataObject() as DataObject;
                    if (data != null)
                    {
                        partialGrid = data.GetData(ClipBoardDataFormatIdentify) as PartialGrid;

                        if (data.ContainsText())
                        {
                            clipboardText = data.GetText();
                        }
                    }
#elif ANDROID
#endif // WINFORM || WPF

                    if (partialGrid != null)
                    {
                        #region Partial Grid Pasting
                        int startRow = selectionRange.Row;
                        int startCol = selectionRange.Col;

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

                        int rowRepeat = 1;
                        int colRepeat = 1;

                        if (selectionRange.Rows % partialGrid.Rows == 0)
                        {
                            rows      = selectionRange.Rows;
                            rowRepeat = selectionRange.Rows / partialGrid.Rows;
                        }
                        if (selectionRange.Cols % partialGrid.Columns == 0)
                        {
                            cols      = selectionRange.Cols;
                            colRepeat = selectionRange.Cols / partialGrid.Columns;
                        }

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

                        if (!RaiseBeforePasteEvent(targetRange))
                        {
                            return(false);
                        }

                        if (targetRange.EndRow >= this.rows.Count ||
                            targetRange.EndCol >= this.cols.Count)
                        {
                            // TODO: paste range overflow
                            // need to notify user-code to handle this
                            return(false);
                        }

                        // check whether the range to be pasted contains readonly cell
                        if (this.CheckRangeReadonly(targetRange))
                        {
                            this.NotifyExceptionHappen(new OperationOnReadonlyCellException("specified range contains readonly cell"));
                            return(false);
                        }

                        // check any intersected merge-range in partial grid
                        //
                        bool cancelPerformPaste = false;

                        if (partialGrid.Cells != null)
                        {
                            try
                            {
                                #region Check repeated intersected ranges
                                for (int rr = 0; rr < rowRepeat; rr++)
                                {
                                    for (int cc = 0; cc < colRepeat; cc++)
                                    {
                                        partialGrid.Cells.Iterate((row, col, cell) =>
                                        {
                                            if (cell.IsMergedCell)
                                            {
                                                for (int r = startRow; r < cell.MergeEndPos.Row - cell.InternalRow + startRow + 1; r++)
                                                {
                                                    for (int c = startCol; c < cell.MergeEndPos.Col - cell.InternalCol + startCol + 1; c++)
                                                    {
                                                        int tr = r + rr * partialGrid.Rows;
                                                        int tc = c + cc * partialGrid.Columns;

                                                        var existedCell = cells[tr, tc];

                                                        if (existedCell != null)
                                                        {
                                                            if (
                                                                // cell is a part of merged cell
                                                                (existedCell.Rowspan == 0 && existedCell.Colspan == 0)
                                                                // cell is merged cell
                                                                || existedCell.IsMergedCell)
                                                            {
                                                                throw new RangeIntersectionException(selectionRange);
                                                            }
                                                            // cell is readonly
                                                            else if (existedCell.IsReadOnly)
                                                            {
                                                                throw new CellDataReadonlyException(cell.InternalPos);
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            return(Math.Min(cell.Colspan, (short)1));
                                        });
                                    }
                                }
                                #endregion                                 // Check repeated intersected ranges
                            }
                            catch (Exception ex)
                            {
                                cancelPerformPaste = true;

                                // raise event to notify user-code there is error happened during paste operation
                                if (OnPasteError != null)
                                {
                                    OnPasteError(this, new RangeOperationErrorEventArgs(selectionRange, ex));
                                }
                            }
                        }

                        if (!cancelPerformPaste)
                        {
                            DoAction(new SetPartialGridAction(new RangePosition(
                                                                  startRow, startCol, rows, cols), partialGrid));
                        }

                        #endregion                         // Partial Grid Pasting
                    }
                    else if (!string.IsNullOrEmpty(clipboardText))
                    {
                        #region Plain Text Pasting
                        var arrayData = RGUtility.ParseTabbedString(clipboardText);

                        int rows = Math.Max(selectionRange.Rows, arrayData.GetLength(0));
                        int cols = Math.Max(selectionRange.Cols, arrayData.GetLength(1));

                        var targetRange = new RangePosition(selectionRange.Row, selectionRange.Col, rows, cols);
                        if (!RaiseBeforePasteEvent(targetRange))
                        {
                            return(false);
                        }

                        if (this.controlAdapter != null)
                        {
                            var actionSupportedControl = this.controlAdapter.ControlInstance as IActionControl;

                            if (actionSupportedControl != null)
                            {
                                actionSupportedControl.DoAction(this, new SetRangeDataAction(targetRange, arrayData));
                            }
                        }
                        #endregion                         // Plain Text Pasting
                    }
                }
                catch (Exception ex)
                {
                    // raise event to notify user-code there is error happened during paste operation
                    //if (OnPasteError != null)
                    //{
                    //	OnPasteError(this, new RangeOperationErrorEventArgs(selectionRange, ex));
                    //}
                    this.NotifyExceptionHappen(ex);
                }
                finally
                {
                    this.controlAdapter.ChangeCursor(CursorStyle.Selection);

                    RequestInvalidate();
                }

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

            return(true);
        }
示例#4
0
        public static async Task <bool> ReadAloud(FunctionArgs args)
        {
            string action = args["action"];

            switch (action)
            {
            case "pause":
                App.Current.Logger.LogError("ReadAloud: pause not supported");
                break;

            case "stop":
            case "play":
                Functions.speechPlayer?.Stop();
                Functions.speechPlayer?.Dispose();
                Functions.speechPlayer = null;

                if (action == "stop")
                {
                    break;
                }

                App.Current.Logger.LogDebug("ReadAloud: Storing clipboard");
                IDataObject?clipboardData = Clipboard.GetDataObject();
                Dictionary <string, object?>?dataStored = null;
                if (clipboardData != null)
                {
                    dataStored = clipboardData.GetFormats()
                                 .ToDictionary(format => format, format => (object?)clipboardData.GetData(format, false));
                }

                Clipboard.Clear();

                // Get the selection
                App.Current.Logger.LogDebug("ReadAloud: Getting selected text");
                await SelectionReader.Default.GetSelectedText(System.Windows.Forms.SendKeys.SendWait);

                string text = Clipboard.GetText();

                // Restore the clipboard
                App.Current.Logger.LogDebug("ReadAloud: Restoring clipboard");
                Clipboard.Clear();
                dataStored?.Where(kv => kv.Value != null).ToList()
                .ForEach(kv => Clipboard.SetData(kv.Key, kv.Value));

                // Talk the talk
                SpeechSynthesizer     synth  = new SpeechSynthesizer();
                SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);

                speechPlayer = new SoundPlayer(stream.AsStream());
                speechPlayer.LoadCompleted += (o, args) =>
                {
                    speechPlayer.Play();
                };

                speechPlayer.LoadAsync();

                break;
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// Copy data from Clipboard and put on grid.
        ///
        /// Currently ReoGrid supports the following types of source from the clipboard.
        ///  - Data from another ReoGrid instance
        ///  - Plain/Unicode Text from any Windows Applications
        ///  - Tabbed Plain/Unicode Data from Excel or similar applications
        ///
        /// When data copied from another ReoGrid instance, and the destination range
        /// is bigger than the source, ReoGrid will try to repeat putting data to fill
        /// the destination range entirely.
        ///
        /// Todo: Copy border and cell style from Excel.
        /// </summary>
        public bool Paste()
        {
            if (IsEditing)
            {
                this.controlAdapter.EditControlPaste();
            }
            else
            {
                // Paste method will always perform action to do paste

                // do nothing if in readonly mode
                if (this.HasSettings(WorksheetSettings.Edit_Readonly)
                    // or selection is empty
                    || this.selectionRange.IsEmpty)
                {
                    return(false);
                }

                try
                {
                    this.controlAdapter.ChangeCursor(CursorStyle.Busy);

                    PartialGrid partialGrid   = null;
                    string      clipboardText = null;

#if WINFORM || WPF
                    DataObject data = Clipboard.GetDataObject() as DataObject;
                    if (data != null)
                    {
                        partialGrid = data.GetData(ClipBoardDataFormatIdentify) as PartialGrid;

                        if (data.ContainsText())
                        {
                            clipboardText = data.GetText();
                        }
                    }
#elif ANDROID
#endif // WINFORM || WPF

                    if (partialGrid != null)
                    {
                        #region Partial Grid Pasting
                        int startRow = selectionRange.Row;
                        int startCol = selectionRange.Col;

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

                        int rowRepeat = 1;
                        int colRepeat = 1;

                        if (selectionRange.Rows % partialGrid.Rows == 0)
                        {
                            rows      = selectionRange.Rows;
                            rowRepeat = selectionRange.Rows / partialGrid.Rows;
                        }
                        if (selectionRange.Cols % partialGrid.Columns == 0)
                        {
                            cols      = selectionRange.Cols;
                            colRepeat = selectionRange.Cols / partialGrid.Columns;
                        }

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

                        if (!RaiseBeforePasteEvent(targetRange))
                        {
                            return(false);
                        }

                        if (targetRange.EndRow >= this.rows.Count ||
                            targetRange.EndCol >= this.cols.Count)
                        {
                            // TODO: paste range overflow
                            // need to notify user-code to handle this
                            return(false);
                        }

                        // check whether the range to be pasted contains readonly cell
                        if (this.CheckRangeReadonly(targetRange))
                        {
                            this.NotifyExceptionHappen(new OperationOnReadonlyCellException("specified range contains readonly cell"));
                            return(false);
                        }

                        DoAction(new SetPartialGridAction(new RangePosition(
                                                              startRow, startCol, rows, cols), partialGrid));

                        #endregion                         // Partial Grid Pasting
                    }
                    else if (!string.IsNullOrEmpty(clipboardText))
                    {
                        #region Plain Text Pasting
                        var arrayData = RGUtility.ParseTabbedString(clipboardText);

                        int rows = Math.Max(selectionRange.Rows, arrayData.GetLength(0));
                        int cols = Math.Max(selectionRange.Cols, arrayData.GetLength(1));

                        var targetRange = new RangePosition(selectionRange.Row, selectionRange.Col, rows, cols);
                        if (!RaiseBeforePasteEvent(targetRange))
                        {
                            return(false);
                        }

                        if (this.controlAdapter != null)
                        {
                            var actionSupportedControl = this.controlAdapter.ControlInstance as IActionControl;

                            if (actionSupportedControl != null)
                            {
                                actionSupportedControl.DoAction(this, new SetRangeDataAction(targetRange, arrayData));
                            }
                        }
                        #endregion                         // Plain Text Pasting
                    }
                }
                catch (Exception ex)
                {
                    // raise event to notify user-code there is error happened during paste operation
                    //if (OnPasteError != null)
                    //{
                    //	OnPasteError(this, new RangeOperationErrorEventArgs(selectionRange, ex));
                    //}
                    this.NotifyExceptionHappen(ex);
                }
                finally
                {
                    this.controlAdapter.ChangeCursor(CursorStyle.Selection);

                    RequestInvalidate();
                }

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

            return(true);
        }
示例#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);
        }
示例#7
0
 public override bool MatchesClipboard() // TODO: fix equality check
 {
     return(Clipboard.ContainsImage() && BitmapExtension.GetImageFromDataObject(new SerializableDataObject(Clipboard.GetDataObject()).GetDataObject()).ToBytes().SequenceEqual(BitmapExtension.GetImageFromDataObject(dataObject.GetDataObject()).ToBytes()));
 }