// Override the key press event from Xsharp. protected override bool OnKeyPress(KeyName key, ModifierMask modifiers, String str) { bool processed = false; if (sink != null) { // Emit the "KeyDown" event. ToolkitKeys keyData = MapKey(key, modifiers); if (sink.ToolkitKeyDown(keyData)) { processed = true; } // Emit the "KeyChar" event if necessary. if (str != null) { foreach (char ch in str) { // Clean old ASCII DEL (0x7F) if (ch != (char)0x7F) { if (sink != null) // window might be closed by sink.ToolkitKeyDown { if (sink.ToolkitKeyChar(ch)) { processed = true; } } } } } } return(processed); }
// Override the key press event from Xsharp. protected override bool OnKeyPress(KeyName key, ModifierMask modifiers, String str) { bool processed = false; if (sink != null) { // Emit the "KeyDown" event. ToolkitKeys keyData = DrawingWindow.MapKey(key, modifiers); if (sink.ToolkitKeyDown(keyData)) { processed = true; } // Emit the "KeyChar" event if necessary. if (str != null) { foreach (char ch in str) { if (sink.ToolkitKeyChar(ch)) { processed = true; } } } } return(processed); }
public void ToolkitMouseWheel(ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { IToolkitEventSink co = this.mControlWeakRef.Target as IToolkitEventSink; if (null != co) { co.ToolkitMouseWheel(buttons, modifiers, clicks, x, y, delta); } }
// Override the key release event from Xsharp. protected override bool OnKeyRelease(KeyName key, ModifierMask modifiers) { if (sink != null) { // Emit the "KeyUp" event. ToolkitKeys keyData = DrawingWindow.MapKey(key, modifiers); return(sink.ToolkitKeyUp(keyData)); } return(false); }
public bool ToolkitKeyUp(ToolkitKeys key) { IToolkitEventSink co = this.mControlWeakRef.Target as IToolkitEventSink; if (null != co) { return(co.ToolkitKeyUp(key)); } return(false); }
private ToolkitKeys MapKeyToToolkitKeys(int wParam) { ToolkitKeys key = (ToolkitKeys)(wParam & 0xFFFF); if (Win32.Api.GetKeyState(Win32.Api.VirtualKeyType.VK_MENU) < 0) { key |= ToolkitKeys.Alt; } if (Win32.Api.GetKeyState(Win32.Api.VirtualKeyType.VK_CONTROL) < 0) { key |= ToolkitKeys.Control; } if (Win32.Api.GetKeyState(Win32.Api.VirtualKeyType.VK_SHIFT) < 0) { key |= ToolkitKeys.Shift; } return(key); }
// Map an Xsharp key description into a "ToolkitKeys" value. internal static ToolkitKeys MapKey(KeyName key, ModifierMask modifiers) { ToolkitKeys toolkitKey = MapKey(key); if ((modifiers & ModifierMask.ControlMask) != 0) { toolkitKey |= ToolkitKeys.Control; } if ((modifiers & ModifierMask.ShiftMask) != 0) { toolkitKey |= ToolkitKeys.Shift; } if ((modifiers & ModifierMask.Mod1Mask) != 0) { toolkitKey |= ToolkitKeys.Alt; } return(toolkitKey); }
//Map the win32 MouseKeyState to ToolkitKeys. Alt is handled differently private ToolkitKeys MapMouseToToolkitKeys(int wParam) { ToolkitKeys keys = ToolkitKeys.None; Win32.Api.MouseKeyState fwKeys = (Win32.Api.MouseKeyState)(wParam & 0xFFFF); if ((fwKeys & Win32.Api.MouseKeyState.MK_CONTROL) > 0) { keys |= ToolkitKeys.Control; } if ((fwKeys & Win32.Api.MouseKeyState.MK_SHIFT) > 0) { keys |= ToolkitKeys.Shift; } if (Win32.Api.GetKeyState(Win32.Api.VirtualKeyType.VK_MENU) < 0) { keys |= ToolkitKeys.Alt; } return(keys); }
public void ToolkitMouseWheel(ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { IToolkitEventSink co = this.mControlWeakRef.Target as IToolkitEventSink; if( null != co ) { co.ToolkitMouseWheel(buttons, modifiers, clicks, x, y, delta); } }
public bool ToolkitKeyUp(ToolkitKeys key) { IToolkitEventSink co = this.mControlWeakRef.Target as IToolkitEventSink; if( null != co ) { return co.ToolkitKeyUp(key); } return false; }
// Post Mouse Move to the window that needs it. Handle Mouse Enter and Leave protected internal virtual void MouseMove(int msg, int wParam, int lParam) { ToolkitMouseButtons buttons = MapToToolkitMouseButtons(wParam); ToolkitKeys keys = MapMouseToToolkitKeys(wParam); int x, y; DrawingWindow actual; DrawingWindow found = FindDeepestChild(lParam, out x, out y, out actual); // Do Leave and Entered events. if (toolkit.enteredWindow != actual) { if (toolkit.enteredWindow != null) { //Console.WriteLine("DrawingWindow.MouseLeave, " + toolkit.enteredWindow.sink); toolkit.enteredWindow.sink.ToolkitMouseLeave(); toolkit.enteredWindow = null; } if (actual != null) { //Console.WriteLine("DrawingWindow.MouseEnter, " + actual.sink); toolkit.enteredWindow = actual; actual.sink.ToolkitMouseEnter(); } } // If there are no child windows to receive the captured input then give it to the window doing the capturing if (toolkit.capturedWindow != null && found == null) { found = toolkit.capturedWindow; } // If this is the first time over a window, set the capture and try again if (toolkit.capturedTopWindow == null) { if (toolkit.capturedWindow == null) { CaptureTopLevel(this); MouseMove(msg, wParam, lParam); } else { CaptureTopLevel(toolkit.capturedWindow); } return; } Win32.Api.POINT mouse; mouse.x = MouseX(lParam) + DimensionsScreen.X; mouse.y = MouseY(lParam) + DimensionsScreen.Y; DrawingWindow actualWindow = toolkit.DrawingWindow(Win32.Api.WindowFromPoint(mouse)); if (actualWindow != null && actualWindow.topOfhierarchy == toolkit.capturedTopWindow) { // On the window decorations. if (found == null) { CaptureTopLevel(null); } else { // Send the message to the client window found.sink.ToolkitMouseMove(buttons, keys, 0, x, y, 0); } //Console.WriteLine("DrawingWindow.MouseMove, " + (actual==null?"null":actual.sink.ToString()) +", (" + x +", " + y +"), " + buttons +"," + keys ); } else { if (toolkit.capturedWindow == null) { CaptureTopLevel(null); } else { found.sink.ToolkitMouseMove(buttons, keys, 0, x, y, 0); } // ?Send the last mouse move beyond the window (Win NT+ behaviour) } }
// Toolkit event that is emitted for a mouse wheel event. void IToolkitEventSink.ToolkitMouseWheel (ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { if( !Enabled) { // Check Parent Enabled too, not just this Control. if (parent != null) ((IToolkitEventSink)parent).ToolkitMouseWheel(buttons, modifiers, clicks, x + left, y + top, delta); return; } // Convert to client coordinates x += ToolkitDrawOrigin.X - ClientOrigin.X; y += ToolkitDrawOrigin.Y - ClientOrigin.Y; currentModifiers = (Keys)modifiers; DoOnMouseWheel(new MouseEventArgs ((MouseButtons)buttons, clicks, x, y, delta)); }
// Toolkit event that is emitted for a mouse move event. void IToolkitEventSink.ToolkitMouseMove (ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { if(!Enabled) //Check Parent Enabled too, not just this Control. !GetControlFlag(ControlFlags.Enabled)) { if (parent != null) ((IToolkitEventSink)parent).ToolkitMouseMove(buttons, modifiers, clicks, x + left, y + top, delta); return; } // Convert to client coordinates x += ToolkitDrawOrigin.X - ClientOrigin.X; y += ToolkitDrawOrigin.Y - ClientOrigin.Y; mousePosition = PointToScreen(new Point(x, y)); currentModifiers = (Keys)modifiers; OnMouseMove(new MouseEventArgs ((MouseButtons)buttons, clicks, x, y, delta)); }
// Toolkit event that is emitted for a mouse up event. void IToolkitEventSink.ToolkitMouseUp (ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { if(!Enabled) // Check Parent Enabled too, not just this Control. !GetControlFlag(ControlFlags.Enabled)) { if (parent != null) ((IToolkitEventSink)parent).ToolkitMouseUp(buttons, modifiers, clicks, x + left, y + top, delta); return; } // Convert to client coordinates x += ToolkitDrawOrigin.X - ClientOrigin.X; y += ToolkitDrawOrigin.Y - ClientOrigin.Y; mouseButtons = (MouseButtons)buttons; currentModifiers = (Keys)modifiers; if(GetControlFlag(ControlFlags.NotifyDoubleClick)) { OnDoubleClick(EventArgs.Empty); SetControlFlag(ControlFlags.NotifyDoubleClick, false); } else if(GetControlFlag(ControlFlags.NotifyClick)) { OnClick(EventArgs.Empty); SetControlFlag(ControlFlags.NotifyClick, false); } OnMouseUp(new MouseEventArgs ((MouseButtons)buttons, clicks, x, y, delta)); // See if we need to display the context menu. if(mouseButtons == MouseButtons.Right && contextMenu != null) { contextMenu.Show(this, new Point(x, y)); } }
// Toolkit event that is emitted for a mouse down event. void IToolkitEventSink.ToolkitMouseDown (ToolkitMouseButtons buttons, ToolkitKeys modifiers, int clicks, int x, int y, int delta) { if( !Enabled) //Check if this !Enabled OR Parent !Enabled, not just this control. //if(!GetControlFlag(ControlFlags.Enabled)) { if (parent != null) ((IToolkitEventSink)parent).ToolkitMouseDown(buttons, modifiers, clicks, x + left, y + top, delta); return; } // Convert to client coordinates x += ToolkitDrawOrigin.X - ClientOrigin.X; y += ToolkitDrawOrigin.Y - ClientOrigin.Y; mouseButtons = (MouseButtons)buttons; currentModifiers = (Keys)modifiers; ToolkitMouseDown(mouseButtons, currentModifiers, clicks, x, y, delta); }
// Toolkit event that is emitted for a key up event. bool IToolkitEventSink.ToolkitKeyUp(ToolkitKeys key) { // Create a fake key message and dispatch it. currentModifiers = (Keys)key; Message m = Message.CreateKeyMessage (Win32Constants.WM_KEYUP, (Keys)key); if(PreProcessMessage(ref m)) { // The key was dispatched as a dialog or command key. return true; } return ProcessKeyMessage(ref m); }