Example #1
0
        private void SelectAll()
        {
            int length = BoundControl.Text == null
                                             ? 0
                                             : BoundControl.Text.Length;

            BoundControl.Select(0, length);
        }
Example #2
0
 private void Update()
 {
     if (!HasParentControlCalledDataBinding)
     {
         return;
     }
     ApplyDataSensitivityRules();
     BindParent();
     BoundControl.DataBind();
 }
Example #3
0
        /// <summary>
        /// Function to bind the input device.
        /// </summary>
        protected override void BindDevice()
        {
            if ((Exclusive) && (!_isExclusive))
            {
                _lastPosition = Cursor.Position;
                UpdateCursorPosition();
                _isExclusive = true;
            }

            if ((!Exclusive) && (_isExclusive))
            {
                _isExclusive = false;
                Position     = BoundControl.PointToClient(Point.Truncate(_lastPosition));
            }

            if (_isBound)
            {
                return;
            }

            UnbindDevice();

            if (_messageFilter != null)
            {
                _messageFilter.RawInputPointingDeviceData += GetRawData;
            }

            _device.UsagePage    = HIDUsagePage.Generic;
            _device.Usage        = (ushort)HIDUsage.Mouse;
            _device.Flags        = RawInputDeviceFlags.None;
            _device.WindowHandle = BoundControl.Handle;

            // Enable background access.
            if (AllowBackground)
            {
                _device.WindowHandle = BoundControl.Handle;
                _device.Flags       |= RawInputDeviceFlags.InputSink;
            }

            // Attempt to register the device.
            if (!Win32API.RegisterRawInputDevices(_device))
            {
                throw new GorgonException(GorgonResult.DriverError, Resources.GORINP_RAW_CANNOT_BIND_POINTING_DEVICE);
            }

            if (!Exclusive)
            {
                BoundControl.MouseLeave += BoundControl_MouseLeave;
            }

            _isBound = true;
        }
Example #4
0
        private PointF _lastPosition;                                   // The last position of the cursor before it was put into exclusive mode.
        #endregion

        #region Methods.
        /// <summary>
        /// Function to update the cursor on the screen if applicable.
        /// </summary>
        private void UpdateCursorPosition()
        {
            // If the window is disposed, then do nothing.
            if (BoundControl == null)
            {
                return;
            }

            // Move the windows cursor to match if not exclusive.
            Cursor.Position =
                BoundControl.PointToScreen(!Exclusive
                                                                   ? Point.Truncate(Position)
                                                                   : new Point(BoundControl.ClientSize.Width / 2, BoundControl.ClientSize.Height / 2));
        }
Example #5
0
        /// <summary>
        /// Function to retrieve and parse the raw pointing device data.
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event data to examine.</param>
        private void GetRawData(object sender, RawInputPointingDeviceEventArgs e)
        {
            if ((BoundControl == null) || (BoundControl.Disposing))
            {
                return;
            }

            if ((_deviceHandle != IntPtr.Zero) && (_deviceHandle != e.Handle))
            {
                return;
            }

            if ((Exclusive) && (!Acquired))
            {
                // Attempt to recapture.
                if (BoundControl.Focused)
                {
                    Acquired = true;
                }
                else
                {
                    return;
                }
            }

            // Do nothing if we're outside and we have exclusive mode turned off.
            if (!Exclusive)
            {
                Point clientPosition = BoundControl.PointToClient(Cursor.Position);

                if (!WindowRectangle.Contains(clientPosition))
                {
                    _outside = true;
                    return;
                }

                if (_outside)
                {
                    // If we're back inside place position at the entry point.
                    _outside = false;
                    Position = clientPosition;
                }
            }

            // Get wheel data.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MouseWheel) != 0)
            {
                OnPointingDeviceWheelMove((short)e.PointingDeviceData.ButtonData);
            }

            // If we're outside of the delay, then restart double click cycle.
            if (_doubleClicker.Milliseconds > DoubleClickDelay)
            {
                _doubleClicker.Reset();
                _clickCount = 0;
            }

            // Get button data.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.LeftDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Left);
                OnPointingDeviceDown(PointingDeviceButtons.Left);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.RightDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Right);
                OnPointingDeviceDown(PointingDeviceButtons.Right);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MiddleDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Middle);
                OnPointingDeviceDown(PointingDeviceButtons.Middle);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button4Down) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Button4);
                OnPointingDeviceDown(PointingDeviceButtons.Button4);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button5Down) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Button5);
                OnPointingDeviceDown(PointingDeviceButtons.Button5);
            }

            // If we have an 'up' event on the buttons, remove the flag.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.LeftUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Left))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Left, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.RightUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Right))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Right, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MiddleUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Middle))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Middle, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button4Up) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Button4))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Button4, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button5Up) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Button5))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Button5, _clickCount);
            }

            // Fire events.
            RelativePosition = new PointF(RelativePosition.X + e.PointingDeviceData.LastX, RelativePosition.Y + e.PointingDeviceData.LastY);
            OnPointingDeviceMove(new PointF(Position.X + e.PointingDeviceData.LastX, Position.Y + e.PointingDeviceData.LastY),
                                 false);
            UpdateCursorPosition();
        }
Example #6
0
 protected override void PostFocus()
 {
     BoundControl.SelectAll();
 }
Example #7
0
 private void control_GotFocus(object sender, EventArgs e)
 {
     BoundControl.SelectAll();
 }
Example #8
0
 private void GalleryCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, BindingInfo bindingInfo, int hwnd)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         foreach (var subbindingInfo in bindingInfo.SubInfos)
         {
             foreach (var item in e.NewItems)
             {
                 BoundControl boundItem = new BoundControl
                 {
                     Binding = new BindingObject(item, subbindingInfo.BindingPath, (eArgs) =>
                     {
                         InvalidateRibbon(bindingInfo.ID);
                     }, true),
                     BindingInfo = subbindingInfo,
                     Hwnd        = hwnd
                 };
                 boundVMControls.Add(boundItem);
             }
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         List <BoundControl> toDelete = new List <BoundControl>();
         foreach (var subbindingInfo in bindingInfo.SubInfos)
         {
             foreach (var item in e.OldItems)
             {
                 foreach (var control in boundVMControls)
                 {
                     if (control.Binding.SourceObject == item)
                     {
                         toDelete.Add(control);
                     }
                 }
             }
         }
         foreach (var item in toDelete)
         {
             boundVMControls.Remove(item);
             item.Dispose();
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         if (sender is System.Collections.IEnumerable items)
         {
             foreach (var subbindingInfo in bindingInfo.SubInfos)
             {
                 foreach (var item in items)
                 {
                     BoundControl boundItem = new BoundControl
                     {
                         Binding = new BindingObject(item, subbindingInfo.BindingPath, (eArgs) =>
                         {
                             InvalidateRibbon(subbindingInfo.ParentID);
                         }, true),
                         BindingInfo = subbindingInfo,
                         Hwnd        = hwnd
                     };
                     boundVMControls.Add(boundItem);
                 }
             }
         }
     }
     InvalidateRibbon(bindingInfo.ID);
 }
Example #9
0
        private void Adapter_VMCreated(object sender, EventArgs e)
        {
            try
            {
                if (e is VMEventArgs vmEventArgs)
                {
                    foreach (var bindingInfo in bindingInfos)
                    {
                        BoundControl boundObject = new BoundControl();
                        switch (bindingInfo.RibbonBindingType)
                        {
                        case RibbonBindingType.TogglePressed:
                        case RibbonBindingType.Visible:
                        case RibbonBindingType.Enabled:
                        case RibbonBindingType.Invalidation:
                            boundObject.Binding = new BindingObject(vmEventArgs.VM, bindingInfo.BindingPath, (eArgs) =>
                            {
                                InvalidateRibbon(bindingInfo.ID);
                            }, true);
                            break;


                        case RibbonBindingType.Command:
                        case RibbonBindingType.ToggleCommand:
                            boundObject.Binding = new BindingObject(vmEventArgs.VM, bindingInfo.BindingPath, null, false);
                            break;

                        case RibbonBindingType.GalleryItemsSource:
                            boundObject.Binding = new BindingObject(vmEventArgs.VM, bindingInfo.BindingPath, (eArgs) =>
                            {
                                var handler = new NotifyCollectionChangedEventHandler((s, eventargs) =>
                                {
                                    var bi = bindingInfo;
                                    GalleryCollectionChanged(s, eventargs, bi, vmEventArgs.HWND);
                                });

                                if (eArgs.NewValue is INotifyCollectionChanged collectionChangedNew)
                                {
                                    collectionChangedNew.CollectionChanged += handler;
                                    handler(collectionChangedNew, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                                }

                                if (eArgs.OldValue is INotifyCollectionChanged collectionChangedOld)
                                {
                                    collectionChangedOld.CollectionChanged -= handler;
                                }
                            }, false);
                            break;

                        default:
                            break;
                        }
                        if (boundObject != null)
                        {
                            boundObject.BindingInfo = bindingInfo;
                            boundObject.Hwnd        = vmEventArgs.HWND;
                            boundVMControls.Add(boundObject);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }