예제 #1
0
        public bool ReportInput(InputDevice device, InputReport inputReport)
        {
            if (this._isDisposed)
            {
                throw new InvalidOperationException();
            }
            bool flag = false;
            InputReportEventArgs input = new InputReportEventArgs(device, inputReport)
            {
                RoutedEvent = GHIElectronics.TinyCLR.UI.Input.InputManager.PreviewInputReportEvent
            };

            if (this._inputManager != null)
            {
                flag = this._inputManager.ProcessInput(input);
            }
            return(flag);
        }
        /// <summary>
        ///     Reports input to the input manager.
        /// </summary>
        /// <returns>
        ///     Whether or not any event generated as a consequence of this
        ///     event was handled.
        /// </returns>
        // do we really need this?  Make the "providers" call InputManager.ProcessInput themselves.
        // we currently need to map back to providers for other reasons.
        public bool ReportInput(InputDevice device, InputReport inputReport)
        {
            if (this._isDisposed)
            {
                throw new InvalidOperationException();
            }

            var handled = false;

            var input = new InputReportEventArgs(device, inputReport)
            {
                RoutedEvent = InputManager.PreviewInputReportEvent
            };

            if (this._inputManager != null)
            {
                handled = this._inputManager.ProcessInput(input);
            }

            return(handled);
        }
예제 #3
0
        private object ProcessStagingArea(object frame)
        {
            var handled = false;

            // NOTE -- avalon caches the XXXEventArgs.  In our system, the costs are different,
            // so it is probably cheaper for us to just create them, since everything gets created
            // on the heap anyways, and IL is expensive.  we should reconsider this if
            // its a performance impact.

            // Because we can be reentered, we can't just enumerate over the
            // staging area - that could throw an exception if the queue
            // changes underneath us.  Instead, just loop until we find a
            // frame marker or until the staging area is empty.

            try {
                while (this._stagingArea.Count > 0)
                {
                    this._currentStagingStack = this._stagingArea.Dequeue() as Stack;

                    do
                    {
                        var item = (StagingAreaInputItem)this._currentStagingStack.Pop();

                        // Pre-Process the input.  This could modify the staging
                        // area, and it could cancel the processing of this
                        // input event.
                        //

                        var fCanceled = false;

                        var devType = (int)item.Input._inputDevice.DeviceType;

                        if (this.InputDeviceEvents[devType]._preProcessInput != null)
                        {
                            PreProcessInputEventArgs preProcessInputEventArgs;
                            this.InputDeviceEvents[devType]._preProcessInput(this, preProcessInputEventArgs = new PreProcessInputEventArgs(item));

                            fCanceled = preProcessInputEventArgs._canceled;
                        }

                        if (!fCanceled)
                        {
                            // Pre-Notify the input.
                            //
                            this.InputDeviceEvents[devType]._preNotifyInput?.Invoke(this, new NotifyInputEventArgs(item));

                            // Raise the input event being processed.
                            var input = item.Input;

                            // Some input events are explicitly associated with
                            // an element.  Those that are not instead are associated with
                            // the target of the input device for this event.
                            var eventSource = input._source as UIElement;

                            if (eventSource == null && input._inputDevice != null)
                            {
                                eventSource = input._inputDevice.Target;
                            }

                            if (eventSource != null)
                            {
                                eventSource.RaiseEvent(input);
                            }

                            // Post-Notify the input.
                            //
                            this.InputDeviceEvents[devType]._postNotifyInput?.Invoke(this, new NotifyInputEventArgs(item));

                            // Post-Process the input.  This could modify the staging
                            // area.
                            this.InputDeviceEvents[devType]._postProcessInput?.Invoke(this, new ProcessInputEventArgs(item));

                            // PreviewInputReport --> InputReport
                            if (item.Input._routedEvent == InputManager.PreviewInputReportEvent)
                            {
                                if (!item.Input.Handled)
                                {
                                    var previewInputReport = (InputReportEventArgs)item.Input;
                                    var inputReport        = new InputReportEventArgs(previewInputReport.Device, previewInputReport.Report)
                                    {
                                        RoutedEvent = InputManager.InputReportEvent
                                    };

                                    this._currentStagingStack.Push(new StagingAreaInputItem(inputReport, item));
                                }
                            }

                            if (input.Handled)
                            {
                                handled = true;
                            }
                        }
                    } while (this._currentStagingStack.Count > 0);
                }
            }
            finally {
                // It is possible that we can be re-entered by a nested
                // dispatcher frame.  Continue processing the staging
                // area if we need to.
                if (this._stagingArea.Count > 0)
                {
                    // Before we actually start to drain the staging area, we need
                    // to post a work item to process more input.  This enables us
                    // to process more input if we enter a nested pump.
                    this.Dispatcher.BeginInvoke(this._continueProcessingStagingAreaCallback, this.Dispatcher.CurrentFrame);
                }

                this._frameStagingArea.Remove(frame);
            }

            return(handled);
        }
예제 #4
0
        private object ProcessStagingArea(object frame)
        {
            bool flag1 = false;

            try
            {
label_21:
                if (this._stagingArea.Count > 0)
                {
                    this._currentStagingStack = this._stagingArea.Dequeue() as Stack;
                    do
                    {
                        StagingAreaInputItem stagingAreaInputItem = (StagingAreaInputItem)this._currentStagingStack.Pop();
                        bool flag2      = false;
                        int  deviceType = (int)stagingAreaInputItem.Input._inputDevice.DeviceType;
                        if (this.InputDeviceEvents[deviceType]._preProcessInput != null)
                        {
                            PreProcessInputEventArgs processInputEventArgs;
                            this.InputDeviceEvents[deviceType]._preProcessInput((object)this, processInputEventArgs = new PreProcessInputEventArgs(stagingAreaInputItem));
                            flag2 = processInputEventArgs._canceled;
                        }
                        if (!flag2)
                        {
                            NotifyInputEventHandler preNotifyInput = this.InputDeviceEvents[deviceType]._preNotifyInput;
                            if (preNotifyInput != null)
                            {
                                preNotifyInput((object)this, new NotifyInputEventArgs(stagingAreaInputItem));
                            }
                            InputEventArgs input1    = stagingAreaInputItem.Input;
                            UIElement      uiElement = input1._source as UIElement;
                            if (uiElement == null && input1._inputDevice != null)
                            {
                                uiElement = input1._inputDevice.Target;
                            }
                            uiElement?.RaiseEvent((RoutedEventArgs)input1);
                            NotifyInputEventHandler postNotifyInput = this.InputDeviceEvents[deviceType]._postNotifyInput;
                            if (postNotifyInput != null)
                            {
                                postNotifyInput((object)this, new NotifyInputEventArgs(stagingAreaInputItem));
                            }
                            ProcessInputEventHandler postProcessInput = this.InputDeviceEvents[deviceType]._postProcessInput;
                            if (postProcessInput != null)
                            {
                                postProcessInput((object)this, new ProcessInputEventArgs(stagingAreaInputItem));
                            }
                            if (stagingAreaInputItem.Input._routedEvent == InputManager.PreviewInputReportEvent && !stagingAreaInputItem.Input.Handled)
                            {
                                InputReportEventArgs input2 = (InputReportEventArgs)stagingAreaInputItem.Input;
                                InputReportEventArgs inputReportEventArgs = new InputReportEventArgs(input2.Device, input2.Report);
                                inputReportEventArgs.RoutedEvent = InputManager.InputReportEvent;
                                this._currentStagingStack.Push((object)new StagingAreaInputItem((InputEventArgs)inputReportEventArgs, stagingAreaInputItem));
                            }
                            if (input1.Handled)
                            {
                                flag1 = true;
                            }
                        }
                    }while (this._currentStagingStack.Count > 0);
                    goto label_21;
                }
            }
            finally
            {
                if (this._stagingArea.Count > 0)
                {
                    this.Dispatcher.BeginInvoke(this._continueProcessingStagingAreaCallback, (object)this.Dispatcher.CurrentFrame);
                }
                this._frameStagingArea.Remove(frame);
            }
            return((object)flag1);
        }