示例#1
0
        public InputDeviceHelper(DependencyObject context)
        {
            if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
            {
                throw new InvalidOperationException("The calling thread must be STA!");
            }

            Dispatcher = Dispatcher.CurrentDispatcher;

            var keys = Enum.GetValues(typeof(Key)).Cast <Key>().ToArray();

            _kbState = new Dictionary <Key, bool>(keys.Length);
            foreach (var key in keys)
            {
                _kbState[key] = false;
            }

            var mouseButtons = Enum.GetValues(typeof(MouseButton)).Cast <MouseButton>().ToArray();

            _mbState = new Dictionary <MouseButton, bool>(mouseButtons.Length);
            foreach (var button in mouseButtons)
            {
                _mbState[button] = false;
            }

            Keyboard.AddKeyUpHandler(context, OnKeyStateChanged);
            Keyboard.AddKeyDownHandler(context, OnKeyStateChanged);
            Keyboard.AddLostKeyboardFocusHandler(context, OnKeyboardFocusChanged);
            Mouse.AddMouseUpHandler(context, OnMouseButtonStateChanged);
            Mouse.AddMouseDownHandler(context, OnMouseButtonStateChanged);
        }
示例#2
0
 public AxisWindow(Axis axis)
 {
     DataContext = new AxisViewModel(axis);
     InitializeComponent();
     Mouse.Device.RawMouseMove += new Mouse.RawMouseMoveHandler(Mouse_Move);
     Keyboard.AddKeyDownHandler(this, new KeyEventHandler(Keyboard_KeyDown));
 }
示例#3
0
        private void renterLibNumber_GotFocus(object sender, RoutedEventArgs e)
        {
            readDataFlag = true;

            Keyboard.AddKeyDownHandler(renterLibNumber, keyDownHandler);
            Keyboard.AddKeyUpHandler(renterLibNumber, keyUpHandler);
        }
 public DocumentNavigatorWindow(DockingManager manager)
     : this()
 {
     _manager = manager;
     Keyboard.AddKeyUpHandler(this, new KeyEventHandler(this.OnKeyUp));
     Keyboard.AddKeyDownHandler(this, new KeyEventHandler(this.OnKeyDown));
 }
示例#5
0
        /// <summary>
        /// Construct new MapZoom object that manages the RenderTransform of the given target object.
        /// The target object must have a parent container.
        /// </summary>
        /// <param name="target">The target object we will be zooming.</param>
        public MapZoom(FrameworkElement target)
        {
            this._container = target.Parent  as ScrollViewer;
            this._target    = target;

            _target.MouseMove  += new MouseEventHandler(OnMouseMove);
            _target.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);

            Keyboard.AddKeyDownHandler(_target, new KeyEventHandler(OnKeyDown));
            Keyboard.AddKeyUpHandler(_target, new KeyEventHandler(OnKeyUp));

            //_target.Focusable = true;
            //_target.Focus();

            _scale = _target.LayoutTransform as ScaleTransform;
            if (_scale == null)
            {
                _target.LayoutTransform = _scale = new ScaleTransform();
            }
            this._zoom = this._newZoom = _scale.ScaleX;

            // track changes made by the ScrolLViewer.
            //this._translate.Changed += new EventHandler(OnTranslateChanged);
            this._scale.Changed += new EventHandler(OnScaleChanged);
        }
示例#6
0
 /// <summary>
 /// Handle the user clicking the change shortcut button
 /// </summary>
 private void BtnChangeShortcut_Click(object sender, RoutedEventArgs e)
 {
     // Listen for a key and then set that as teh shortcut?
     Keyboard.AddKeyDownHandler(this, KeyboardShortcut_KeyDownEvent);
     btnChangeShortcut.Content   = "Press any key";
     btnChangeShortcut.IsEnabled = false;
 }
示例#7
0
 public DropDownButton()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
     //case 166525 : Do no inherit an implicit style of Button
     this.InheritanceBehavior = InheritanceBehavior.SkipToThemeNow;
 }
示例#8
0
 private void control_Loaded(object sender, RoutedEventArgs e)
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         var w = Window.GetWindow(this);
         Keyboard.AddKeyDownHandler(w, KeyDownHandler);
     }
 }
示例#9
0
        public ColorPickerDropDown()
        {
            Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OutsideControl_Click);
            Keyboard.AddKeyDownHandler(this, OutsideControl_KeyDown);

            AddHandler(ColorPickerDropDown.MouseLeaveEvent,
                       new RoutedEventHandler(DropDown_MouseLeave));
        }
示例#10
0
        private void StartButton_OnClick(object sender, RoutedEventArgs e)
        {
            _handler = new KeyEventHandler(Form1_KeyDown);

            Keyboard.AddKeyDownHandler(Main, _handler);

            StopButton.IsEnabled  = true;
            StartButton.IsEnabled = false;
        }
示例#11
0
        public DropDownButton()
        {
            Keyboard.AddKeyDownHandler(this, this.OnKeyDown);
            Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, this.OnMouseDownOutsideCapturedElement);

            this.mVisibilityTimer           = new Timer();
            this.mVisibilityTimer.Elapsed  += this.OnVisibilityTimerElapsed;
            this.mVisibilityTimer.AutoReset = false;
        }
示例#12
0
文件: AutoScroll.cs 项目: sispd/Wider
 /// <summary>
 /// Construct new AutoScroll object that will scroll the given target object within it's container
 /// by attaching to the mouse events of the container.
 /// </summary>
 /// <param name="target">The target object to scroll</param>
 /// <param name="zoom">The master MapZoom object that manages the actual render transform</param>
 public AutoScroll(FrameworkElement target, MapZoom zoom)
 {
     _container             = target.Parent as Panel;
     _container.MouseDown  += new MouseButtonEventHandler(OnMouseDown);
     _container.MouseMove  += new MouseEventHandler(OnMouseMove);
     _container.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);
     Keyboard.AddKeyDownHandler(_container, new KeyEventHandler(OnKeyDown));
     _zoom = zoom;
 }
 /// <summary>
 /// Construct new AutoScroll object that will scroll the given target object within it's container
 /// by attaching to the mouse events of the container.
 /// </summary>
 /// <param name="target">The target object to scroll</param>
 /// <param name="zoom">The master MapZoom object that manages the actual render transform</param>
 public MesAutoScroll(IMesContentCanvas target, IMesMapZoom zoom)
 {
     _container             = ((MesContentCanvas)target).Parent as Panel;
     _container.MouseDown  += new MouseButtonEventHandler(OnMouseDown);
     _container.MouseMove  += new MouseEventHandler(OnMouseMove);
     _container.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);
     Keyboard.AddKeyDownHandler(_container, new KeyEventHandler(OnKeyDown));
     _zoom = (MesMapZoom)zoom;
 }
示例#14
0
        public ColorPicker()
        {
#if VS2008
            this.RecentColors = new ObservableCollection <ColorItem>();
#else
            this.SetCurrentValue(ColorPicker.RecentColorsProperty, new ObservableCollection <ColorItem>());
#endif

            Keyboard.AddKeyDownHandler(this, OnKeyDown);
            Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
        }
示例#15
0
        public DropDown()
        {
            Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, CapturedMouse_Click);
            Mouse.AddPreviewMouseMoveHandler(this, CapturedMouse_Move);

            Keyboard.AddKeyDownHandler(this, CapturedKeyboard_KeyDown);

            AddHandler(DropDown.MouseLeaveEvent,
                       new RoutedEventHandler(PopUp_MouseLeave));

            InitializeDelegateDictionary();
        }
示例#16
0
        public GraphControl()
        {
            guid = IdManager.getGuid();

            this.Focusable = true;
            Keyboard.Focus(this);
            Keyboard.AddKeyDownHandler(this, OnKeyDown);
            Keyboard.AddKeyUpHandler(this, OnKeyUp);

            brush = new SolidColorBrush();
            nodes = new List <Node>()
            {
                new Node(50, 50, 150, 100, "SampleNode", new HandleConstruct(HandleType.Input, HandleDataType.Path), new HandleConstruct(HandleType.Input, HandleDataType.Bool), new HandleConstruct(HandleType.Output, HandleDataType.Path), new HandleConstruct(HandleType.Output, HandleDataType.Bool)),
                new Node(100, 50, 150, 100, "SampleNode", new HandleConstruct(HandleType.Input, HandleDataType.Path), new HandleConstruct(HandleType.Input, HandleDataType.Bool), new HandleConstruct(HandleType.Output, HandleDataType.Path), new HandleConstruct(HandleType.Output, HandleDataType.Bool)),
                new Node(150, 50, 150, 100, "SampleNode", new HandleConstruct(HandleType.Input, HandleDataType.Path), new HandleConstruct(HandleType.Input, HandleDataType.Bool), new HandleConstruct(HandleType.Output, HandleDataType.Path), new HandleConstruct(HandleType.Output, HandleDataType.Bool)),
            };

            mousePos = new Point(0, 0);

            _inserter = new Inserter(new Size(150, 250));
            _inserter.AddNodeElement <Node>("Base Node");
            _inserter.AddNodeElement <Node>("Folder/Node");
            _inserter.AddNodeElement <Node>("Folder/Folder2/Sample Node");
            _inserter.AddNodeElement <Node>("1");
            _inserter.AddNodeElement <Node>("2");
            _inserter.AddNodeElement <Node>("3");
            _inserter.AddNodeElement <Node>("4");
            _inserter.AddNodeElement <Node>("5");
            _inserter.AddNodeElement <Node>("6");
            _inserter.AddNodeElement <Node>("7");
            _inserter.AddNodeElement <Node>("8");
            _inserter.AddNodeElement <Node>("9");
            _inserter.AddNodeElement <Node>("10");
            _inserter.AddNodeElement <Node>("11");
            _inserter.AddNodeElement <Node>("12");
            _inserter.AddNodeElement <Node>("13");
            _inserter.AddNodeElement <Node>("14");

            // var y = Serialisation.SerialzeGraph(this);
            // Console.WriteLine(y);

            Serialisation.DeserializeGraph(
                "{\"id\":15658816,\"offset\":\"0,0\",\"nodes\":[{\"id\":1484882,\"pos\":\"50,50\",\"size\":\"150,100\",\"handles\":[{\"id\":51717130,\"HandleType\":0,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":76566748,\"HandleType\":0,\"HandleDataType\":3,\"connectedTo\":-1},{\"id\":62435764,\"HandleType\":1,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":50246420,\"HandleType\":1,\"HandleDataType\":3,\"connectedTo\":-1}]},{\"id\":46016738,\"pos\":\"100,50\",\"size\":\"150,100\",\"handles\":[{\"id\":26722482,\"HandleType\":0,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":55123457,\"HandleType\":0,\"HandleDataType\":3,\"connectedTo\":-1},{\"id\":43477822,\"HandleType\":1,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":45107328,\"HandleType\":1,\"HandleDataType\":3,\"connectedTo\":-1}]},{\"id\":84178410,\"pos\":\"150,50\",\"size\":\"150,100\",\"handles\":[{\"id\":10713050,\"HandleType\":0,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":1532512,\"HandleType\":0,\"HandleDataType\":3,\"connectedTo\":-1},{\"id\":34662742,\"HandleType\":1,\"HandleDataType\":0,\"connectedTo\":-1},{\"id\":22373670,\"HandleType\":1,\"HandleDataType\":3,\"connectedTo\":-1}]}]}"
                , this);
        }
示例#17
0
        void AddSpaceObjectEvents(Control so2)
        {
            so2.Loaded    += new RoutedEventHandler(SpaceObject_loaded);
            so2.Unloaded  += new RoutedEventHandler(SpaceObject_unloaded);
            so2.MouseDown += new MouseButtonEventHandler(SpaceObject_MouseDown);
            so2.MouseUp   += new MouseButtonEventHandler(SpaceObject_MouseUp);
            so2.KeyDown   += new KeyEventHandler(Canvas_KeyDown);
            so2.KeyUp     += new KeyEventHandler(Canvas_KeyUp);
            Keyboard.AddKeyDownHandler(so2, Canvas_KeyDown);
            Keyboard.AddKeyUpHandler(so2, Canvas_KeyUp);
            SpaceObject so = so2 as SpaceObject;

            if (so != null)
            {
                so.LocationChanged += new EventHandler(SpaceObject_LocationChanged);
            }
            so2.ContextMenu = ObjectMenu;
        }
示例#18
0
        /// <summary>
        /// Construct new MapZoom object that manages the RenderTransform of the given target object.
        /// The target object must have a parent container.
        /// </summary>
        /// <param name="target">The target object we will be zooming.</param>
        public MapZoom(FrameworkElement target)
        {
            this._container = target.Parent as FrameworkElement;
            this._target    = target;

            _container.MouseMove  += new MouseEventHandler(OnMouseMove);
            _container.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);

            Keyboard.AddKeyDownHandler(_container, new KeyEventHandler(OnKeyDown));
            Keyboard.AddKeyUpHandler(_container, new KeyEventHandler(OnKeyUp));

            _container.Focusable = true;
            _container.Focus();

            // Try and reuse the existing TransformGroup if we can.
            TransformGroup g = target.RenderTransform as TransformGroup;

            if (g != null)
            {
                this._scale     = g.Children.Count > 1 ? g.Children[0] as ScaleTransform : null;
                this._translate = g.Children.Count > 0 ? g.Children[1] as TranslateTransform : null;
                if (this._scale == null || this._translate == null)
                {
                    g = null; // then the TransformGroup cannot be re-used
                }
            }
            if (g == null)
            {
                g           = new TransformGroup();
                this._scale = new ScaleTransform(1, 1);
                g.Children.Add(this._scale);
                this._translate = new TranslateTransform();
                g.Children.Add(this._translate);
                target.RenderTransform = g;
            }

            this._zoom = this._newZoom = _scale.ScaleX;

            // track changes made by the ScrolLViewer.
            this._translate.Changed += new EventHandler(OnTranslateChanged);
            this._scale.Changed     += new EventHandler(OnScaleChanged);
        }
示例#19
0
        private void Initialize(FrameworkElement target)
        {
            _container = target.Parent as FrameworkElement;
            _target    = target;

            _container.MouseMove  += new MouseEventHandler(OnMouseMove);
            _container.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);

            Keyboard.AddKeyDownHandler(_container, new KeyEventHandler(OnKeyDown));
            Keyboard.AddKeyUpHandler(_container, new KeyEventHandler(OnKeyUp));

            _container.Focusable = true;
            _container.Focus();

            // Try and reuse the existing TransformGroup if we can.
            if (target.RenderTransform is TransformGroup g)
            {
                _scale     = g.Children.Count > 1 ? g.Children[0] as ScaleTransform : null;
                _translate = g.Children.Count > 0 ? g.Children[1] as TranslateTransform : null;
                if (_scale == null || _translate == null)
                {
                    g = null; // then the TransformGroup cannot be re-used
                }
            }
            else
            //if (g == null)
            {
                g      = new TransformGroup();
                _scale = new ScaleTransform(1, 1);
                g.Children.Add(_scale);
                _translate = new TranslateTransform();
                g.Children.Add(_translate);
                target.RenderTransform = g;
            }

            _value = _newZoom = _scale.ScaleX;

            // track changes made by the ScrolLViewer.
            _translate.Changed += new EventHandler(OnTranslateChanged);
            _scale.Changed     += new EventHandler(OnScaleChanged);
        }
示例#20
0
        private void ControlLoaded([NotNull] object sender, [NotNull] RoutedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            Loaded -= ControlLoaded;

            if (Target == null)
            {
                Target = this.GetAncestor <IContextProvider>() as DependencyObject;
            }

            if (Target == null)
            {
                Target = this.GetAncestor <UserControl>();
            }

            if (Target == null)
            {
                Target = this.GetAncestor <Window>();
            }

            if (Target == null)
            {
                return;
            }

            if (UsePreviewEvent)
            {
                Keyboard.AddPreviewKeyDownHandler(Target, HandleKeyDown);
            }
            else
            {
                Keyboard.AddKeyDownHandler(Target, HandleKeyDown);
            }
        }
示例#21
0
 public DropDownButton()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
 public DateTimePicker()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
示例#23
0
 public ColorPicker()
 {
     RecentColors = new ObservableCollection <ColorItem>();
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
示例#24
0
 public MainWindow()
 {
     InitializeComponent();
     Keyboard.AddKeyDownHandler(Window, (object o, KeyEventArgs a) => { KeyList.Items.Add(a.Key); });
 }
 public CalculatorUpDown()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
示例#26
0
 public KeyboardManager(DependencyObject dependencyObject)
 {
     Keyboard.AddKeyDownHandler(dependencyObject, KeyEventHandler);
     Keyboard.AddKeyUpHandler(dependencyObject, KeyUpHandler);
 }
示例#27
0
        /// <summary>
        /// Отвязка и привязка событий к мыше и клавиатуре в зависимости от выбранного типа интрумента
        /// </summary>
        public void SetToolType(DrawToolType type)
        {
            switch (this.ToolType)
            {
            case DrawToolType.Pointer:
                Mouse.RemoveMouseDownHandler(this.window, this.toolMouseDown);
                Mouse.RemoveMouseUpHandler(this.window, this.toolMouseUp);
                Mouse.RemoveMouseMoveHandler(this.window, this.toolMouseMove);
                Keyboard.RemoveKeyDownHandler(this.window, this.toolKeyDown);
                Keyboard.RemoveKeyUpHandler(this.window, this.toolKeyUp);
                Mouse.RemoveMouseDownHandler(this.dotsControl, this.dotsControl_MouseDown);
                Mouse.RemoveMouseUpHandler(this.dotsControl, this.dotsControl_MouseUp);
                Mouse.RemoveMouseMoveHandler(this.dotsControl, this.dotsControl_MouseMove);
                this.selectShapes(null);
                break;

            case DrawToolType.Polyline:
                Mouse.RemoveMouseDownHandler(this.canvas, this.polylineToolMouseDown);
                Mouse.RemoveMouseUpHandler(this.window, this.polylineToolMouseUp);
                Mouse.RemoveMouseMoveHandler(this.window, this.polylineToolMouseMove);
                this.canvas.Cursor = null;
                this.lastShape     = null;
                break;

            case DrawToolType.Rectangle:
                Mouse.RemoveMouseDownHandler(this.canvas, this.rectangleToolMouseDown);
                Mouse.RemoveMouseUpHandler(this.window, this.rectangleToolMouseMouseUp);
                Mouse.RemoveMouseMoveHandler(this.window, this.rectangleToolMouseMove);
                this.canvas.Cursor = null;
                this.lastShape     = null;
                break;

            case DrawToolType.Delete:
                Mouse.RemoveMouseDownHandler(this.canvas, this.deleteToolMouseDown);
                Mouse.RemoveMouseMoveHandler(this.window, this.deleteToolMouseMove);
                if (this.lastShape != null)
                {
                    this.lastShape.SetDeletingStyle(false);
                    this.lastShape = null;
                }
                break;
            }

            this.ToolType = type;

            switch (this.ToolType)
            {
            case DrawToolType.Pointer:
                Mouse.AddMouseDownHandler(this.dotsControl, this.dotsControl_MouseDown);
                Mouse.AddMouseUpHandler(this.dotsControl, this.dotsControl_MouseUp);
                Mouse.AddMouseDownHandler(this.window, this.toolMouseDown);
                Mouse.AddMouseUpHandler(this.window, this.toolMouseUp);
                Mouse.AddMouseMoveHandler(this.window, this.toolMouseMove);
                Mouse.AddMouseMoveHandler(this.dotsControl, this.dotsControl_MouseMove);
                Keyboard.AddKeyDownHandler(this.window, this.toolKeyDown);
                Keyboard.AddKeyUpHandler(this.window, this.toolKeyUp);
                break;

            case DrawToolType.Polyline:
                Mouse.AddMouseDownHandler(this.canvas, this.polylineToolMouseDown);
                Mouse.AddMouseUpHandler(this.window, this.polylineToolMouseUp);
                Mouse.AddMouseMoveHandler(this.window, this.polylineToolMouseMove);
                this.canvas.Cursor = Cursors.Cross;
                break;

            case DrawToolType.Rectangle:
                Mouse.AddMouseDownHandler(this.canvas, this.rectangleToolMouseDown);
                Mouse.AddMouseUpHandler(this.window, this.rectangleToolMouseMouseUp);
                Mouse.AddMouseMoveHandler(this.window, this.rectangleToolMouseMove);
                this.canvas.Cursor = Cursors.Cross;
                break;

            case DrawToolType.Delete:
                Mouse.AddMouseDownHandler(this.canvas, this.deleteToolMouseDown);
                Mouse.AddMouseMoveHandler(this.window, this.deleteToolMouseMove);
                break;
            }
        }
示例#28
0
 public MultiLineTextEditor()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
示例#29
0
 public TimePicker()
 {
     DateTimeFormatInfo = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentCulture);
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
 }
示例#30
0
 public CheckComboBox()
 {
     Keyboard.AddKeyDownHandler(this, OnKeyDown);
     Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
     _displayMemberPathValuesChangeHelper = new ValueChangeHelper(this.OnDisplayMemberPathValuesChanged);
 }