public static Size FromPixels(PresentationSource source, Size pixelSize) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return (Size)source.CompositionTarget.TransformFromDevice.Transform((Vector)pixelSize); }
public KinectTouchDevice(int id, PresentationSource source) : base(id) { this.Position = new Point(); this.TouchState = TouchState.Up; this.SetActiveSource(source); }
internal RawStylusInputReport( InputMode mode, int timestamp, PresentationSource inputSource, PenContext penContext, RawStylusActions actions, int tabletDeviceId, int stylusDeviceId, int[] data) : base(inputSource, InputType.Stylus, mode, timestamp) { // Validate parameters if (!RawStylusActionsHelper.IsValid(actions)) { throw new InvalidEnumArgumentException(SR.Get(SRID.Enum_Invalid, "actions")); } if (data == null && actions != RawStylusActions.InRange) { throw new ArgumentNullException("data"); } _penContext = new SecurityCriticalDataClass<PenContext>(penContext); _actions = actions; _tabletDeviceId = tabletDeviceId; _stylusDeviceId = stylusDeviceId; _data = data; _isSynchronize = false; }
public static Point ToPixels(PresentationSource source, Point wpfSize) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return (Point)source.CompositionTarget.TransformToDevice.Transform((Vector)wpfSize); }
internal static Rect ElementToRoot(Rect rectElement, Visual element, PresentationSource presentationSource) { GeneralTransform transformElementToRoot = element.TransformToAncestor(presentationSource.RootVisual); Rect rectRoot = transformElementToRoot.TransformBounds(rectElement); return rectRoot; }
public static int GetResolution(PresentationSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } int res = (int)(96 * source.CompositionTarget.TransformToDevice.M11); return res; }
public static Point TryClientToRoot(Point point, PresentationSource source, bool throwOnError, out bool success) { success = default(bool); object[] parameters = new object[] { point, source, throwOnError, success }; Point result = (Point)tryClientToRootMethod.Invoke(null, parameters); success = (bool)parameters[3]; return result; }
public PresentationSourceTreeItem(PresentationSource presentationSource, TreeModel model, TreeType treeType) : base(presentationSource, null, model, 0) { Name = "PresentationSource"; IsExpanded = true; _treeType = treeType; _presentationSource = presentationSource; }
public KinectMultiTouchDevice(IHandDataSource handDataSource, FrameworkElement area) { this.touchDevices = new Dictionary<int, KinectTouchDevice>(); this.TargetSize = new Size(area.ActualWidth, area.ActualHeight); this.presentationSource = PresentationSource.FromVisual(area); this.handDataSource = handDataSource; handDataSource.NewDataAvailable += new Core.NewDataHandler<HandCollection>(handDataSource_NewDataAvailable); area.SizeChanged += new SizeChangedEventHandler(area_SizeChanged); }
internal static Rect RootToClient(Rect rectRoot, PresentationSource presentationSource) { CompositionTarget target = presentationSource.CompositionTarget; Matrix matrixRootTransform = PointUtil.GetVisualTransform(target.RootVisual); Rect rectRootUntransformed = Rect.Transform(rectRoot, matrixRootTransform); Matrix matrixDPI = target.TransformToDevice; Rect rectClient = Rect.Transform(rectRootUntransformed, matrixDPI); return rectClient; }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource, IInputElement element, IInputElement oldParent) { _oldSource = new SecurityCriticalData<PresentationSource>(oldSource); _newSource = new SecurityCriticalData<PresentationSource>(newSource); _element = element; _oldParent = oldParent; }
/// <summary> /// Constructs ad instance of the RawAppCommandInputReport class. /// </summary> /// <param name="inputSource"> /// The input source that provided this input. /// </param> /// <param name="mode"> /// The mode in which the input is being provided. /// </param> /// <param name="timestamp"> /// The time when the input occured. /// </param> /// <param name="appCommand"> /// The Application Command associated. /// </param> /// <param name="device"> /// The device that generated the app command. /// </param> /// <param name="inputType">the input device that generated the input event</param> internal RawAppCommandInputReport( PresentationSource inputSource, InputMode mode, int timestamp, int appCommand, InputType device, InputType inputType) : base(inputSource, inputType, mode, timestamp) { _appCommand = appCommand; _device = device; }
internal PenContexts(StylusLogic stylusLogic, PresentationSource inputSource) { HwndSource hwndSource = inputSource as HwndSource; if(hwndSource == null || IntPtr.Zero == (hwndSource).CriticalHandle) { throw new InvalidOperationException(SR.Get(SRID.Stylus_PenContextFailure)); } _stylusLogic = stylusLogic; _inputSource = new SecurityCriticalData<HwndSource>(hwndSource); }
public static Point RootToClient(Point point, PresentationSource presentationSource) { // point = ApplyVisualTransform(point, presentationSource.RootVisual, false); // Convert from measure units into pixels. point = presentationSource.CompositionTarget.TransformToDevice.Transform(point); return point; }
protected InputReport(PresentationSource inputSource, InputType type, InputMode mode, int timestamp) { if (inputSource == null) throw new ArgumentNullException("inputSource"); Validate_InputType( type ); Validate_InputMode( mode ); _inputSource= new SecurityCriticalData<PresentationSource>(inputSource); _type = type; _mode = mode; _timestamp = timestamp; }
public MultitouchInputProvider(PresentationSource source) { this.source = source; contactsQueue = new Queue<RawMultitouchReport>(); inputManagerProcessInput = InputManagerProcessInput; contactHandler = new ContactHandler(((HwndSource)source).Handle); contactHandler.ContactMoved += HandleContact; contactHandler.ContactRemoved += HandleContact; contactHandler.NewContact += HandleContact; inputManager = InputManager.Current; multitouchLogic = MultitouchLogic.Current; }
public MotionTrackingDevice(Window window, MotionTrackingScreen screen) : base() { if (window == null) throw new ArgumentNullException("window"); if (screen == null) throw new ArgumentNullException("screen"); this.screen = screen; this.rootWindow = window; _activeSource = PresentationSource.FromVisual(window); Activate(); }
/// <summary> /// Constructs ad instance of the RawKeyboardInputReport class. /// </summary> /// <param name="inputSource"> /// The input source that provided this input. /// </param> /// <param name="mode"> /// The mode in which the input is being provided. /// </param> /// <param name="timestamp"> /// The time when the input occured. /// </param> /// <param name="isDeadCharacter"> /// True if the char code is a dead char. /// </param> /// <param name="isSystemCharacter"> /// True if the char code is a system char. /// </param> /// <param name="isControlCharacter"> /// True if the char code is a control char. /// </param> /// <param name="characterCode"> /// The character code. /// </param> public RawTextInputReport( PresentationSource inputSource, InputMode mode, int timestamp, bool isDeadCharacter, bool isSystemCharacter, bool isControlCharacter, char characterCode) : base(inputSource, InputType.Text, mode, timestamp) { _isDeadCharacter = isDeadCharacter; _isSystemCharacter = isSystemCharacter; _isControlCharacter = isControlCharacter; _characterCode = characterCode; }
public RawUIStateInputReport( PresentationSource inputSource, InputMode mode, int timestamp, RawUIStateActions action, RawUIStateTargets targets) : base(inputSource, InputType.Keyboard, mode, timestamp) { if (!IsValidRawUIStateAction(action)) throw new System.ComponentModel.InvalidEnumArgumentException("action", (int)action, typeof(RawUIStateActions)); if (!IsValidRawUIStateTargets(targets)) throw new System.ComponentModel.InvalidEnumArgumentException("targets", (int)targets, typeof(RawUIStateTargets)); _action = action; _targets = targets; }
private static IntPtr GetWindowHandleFromElement(System.Windows.FrameworkElement element) { System.Windows.PresentationSource isource = System.Windows.PresentationSource.FromVisual(element); if (isource == null) { //throw new Exception( "Could not get PresentationSource." ); GlobalLog.LogEvidence(new Exception("Could not get PresentationSource.")); } IWin32Window iwin = (IWin32Window)isource; if (iwin == null) { //throw new Exception( "Could not get IWin32Window." ); GlobalLog.LogEvidence(new Exception("Could not get IWin32Window.")); } return(iwin.Handle); }
public RawKeyboardInputReport( PresentationSource inputSource, InputMode mode, int timestamp, RawKeyboardActions actions, int scanCode, bool isExtendedKey, bool isSystemKey, int virtualKey, IntPtr extraInformation) : base(inputSource, InputType.Keyboard, mode, timestamp) { if (!IsValidRawKeyboardActions(actions)) throw new System.ComponentModel.InvalidEnumArgumentException("actions", (int)actions, typeof(RawKeyboardActions)); _actions = actions; _scanCode = scanCode; _isExtendedKey = isExtendedKey; _isSystemKey = isSystemKey; _virtualKey = virtualKey; _extraInformation = new SecurityCriticalData<IntPtr>(extraInformation); }
public static Point TryClientToRoot(Point point, PresentationSource presentationSource, bool throwOnError, out bool success) { // Only do if we allow throwing on error or have a valid PresentationSource and CompositionTarget. if (throwOnError || (presentationSource != null && presentationSource.CompositionTarget != null && !presentationSource.CompositionTarget.IsDisposed)) { // Convert from pixels into measure units. point = presentationSource.CompositionTarget.TransformFromDevice.Transform(point); // point = TryApplyVisualTransform(point, presentationSource.RootVisual, true, throwOnError, out success); } else { success = false; return new Point(0,0); } return point; }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource) { }
private static void AddElementToWatchList(DependencyObject element) { if (_watchers.Add(element)) { element.SetValue(CachedSourceProperty, new SecurityCriticalDataForMultipleGetAndSet <PresentationSource>(PresentationSource.FindSource(element))); element.SetValue(GetsSourceChangedEventProperty, true); } }
/// <summary> /// Controls call this to leave menu mode. ///</summary> public void PopMenuMode(PresentationSource menuSite) { if (menuSite == null) { throw new ArgumentNullException("menuSite"); } menuSite.VerifyAccess(); if (_menuModeCount <= 0) { throw new InvalidOperationException(); } menuSite.PopMenuMode(); _menuModeCount -= 1; if (0 == _menuModeCount) { EventHandler leaveMenuMode = LeaveMenuMode; if (null != leaveMenuMode) { leaveMenuMode(null, EventArgs.Empty); } } }
/// <summary> /// Controls call this to enter menu mode. ///</summary> public void PushMenuMode(PresentationSource menuSite) { if (menuSite == null) { throw new ArgumentNullException("menuSite"); } menuSite.VerifyAccess(); menuSite.PushMenuMode(); _menuModeCount += 1; if (1 == _menuModeCount) { EventHandler enterMenuMode = EnterMenuMode; if (null != enterMenuMode) { enterMenuMode(null, EventArgs.Empty); } } }
private Rect CalculateAssignedRC(PresentationSource source) { Rect rectElement = new Rect(m_elementAttachedTo.RenderSize); Rect rectRoot = RectUtil.ElementToRoot(rectElement, m_elementAttachedTo, source); return RectUtil.RootToClient(rectRoot, source); }
static bool WindowBoundsValidAnyScreen(PresentationSource source, Rect bounds) { foreach (var screen in System.Windows.Forms.Screen.AllScreens) { var wa = screen.WorkingArea; var i = new Rect(wa.X, wa.Y, wa.Width, wa.Height); i.Transform(source.CompositionTarget.TransformFromDevice); i.Intersect(bounds); if (i.Width > 10 && i.Height > 10) return true; } return false; }
static bool WindowBoundsValid(PresentationSource source, Rect bounds) { var i = Rect.Intersect(bounds, SystemParameters.WorkArea); if (i.Width > 10 && i.Height > 10) return true; // the fallback method must not be inlined to avoid loading System.Drawing and System.Windows.Forms in the common code path return WindowBoundsValidAnyScreen(source, bounds); }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource, IInputElement element, IInputElement oldParent) { }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource) { throw new NotImplementedException(); }
public KinectMultiTouchDevice(IHandDataSource handDataSource, PresentationSource presentationSource, Size targetSize) { this.presentationSource = presentationSource; this.TargetSize = targetSize; }
protected void RootChanged(Visual oldRoot, Visual newRoot) { PresentationSource oldSource = null; if (oldRoot == newRoot) { return; } // Always clear the RootSourceProperty on the old root. if (oldRoot != null) { oldSource = CriticalGetPresentationSourceFromElement(oldRoot, RootSourceProperty); oldRoot.ClearValue(RootSourceProperty); } // Always set the SourceProperty on the new root. if (newRoot != null) { newRoot.SetValue(RootSourceProperty, new SecurityCriticalDataForMultipleGetAndSet <PresentationSource>(this)); } UIElement oldRootUIElement = oldRoot as UIElement; UIElement newRootUIElement = newRoot as UIElement; // The IsVisible property can only be true if root visual is connected to a presentation source. // For Read-Only force-inherited properties, use a private update method. if (oldRootUIElement != null) { oldRootUIElement.UpdateIsVisibleCache(); } if (newRootUIElement != null) { newRootUIElement.UpdateIsVisibleCache(); } // Broadcast the Unloaded event starting at the old root visual if (oldRootUIElement != null) { oldRootUIElement.OnPresentationSourceChanged(false); } // Broadcast the Loaded event starting at the root visual if (newRootUIElement != null) { newRootUIElement.OnPresentationSourceChanged(true); } // To fire PresentationSourceChanged when the RootVisual changes; // rather than simulate a "parent" pointer change, we just walk the // collection of all nodes that need the event. foreach (DependencyObject element in _watchers) { // We only need to update those elements that are in the // same context as this presentation source. if (element.Dispatcher == Dispatcher) { PresentationSource testSource = CriticalGetPresentationSourceFromElement(element, CachedSourceProperty); // 1) If we are removing the rootvisual, then fire on any node whos old // PresetationSource was the oldSource. // 2) If we are attaching a rootvisual then fire on any node whos old // PresentationSource is null; if (oldSource == testSource || null == testSource) { UpdateSourceOfElement(element, null, null); } } } }
///////////////////////////////////////////////////////////////////// internal static IInputElement GlobalHitTest(PresentationSource inputSource, Point pt) { return MouseDevice.GlobalHitTest(pt, inputSource); }
internal IInputElement FindTarget(PresentationSource inputSource, Point position) { IInputElement stylusOver = null; switch (_captureMode) { case CaptureMode.None: { stylusOver = GlobalHitTest(inputSource, position); // We understand UIElements and ContentElements. // If we are over something else (like a raw visual) // find the containing element. if (!InputElement.IsValid(stylusOver)) stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject); } break; case CaptureMode.Element: // stylusOver = _stylusCapture; break; case CaptureMode.SubTree: { IInputElement stylusCapture = InputElement.GetContainingInputElement(_stylusCapture as DependencyObject); if ( stylusCapture != null && inputSource != null ) { // We need to re-hit-test to get the "real" UIElement we are over. // This allows us to have our capture-to-subtree span multiple windows. // GlobalHitTest always returns an IInputElement, so we are sure to have one. stylusOver = GlobalHitTest(inputSource, position); } if (stylusOver != null && !InputElement.IsValid(stylusOver)) stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject); // Make sure that the element we hit is acutally underneath // our captured element. Because we did a global hit test, we // could have hit an element in a completely different window. // // Note that we support the child being in a completely different window. // So we use the GetUIParent method instead of just looking at // visual/content parents. if (stylusOver != null) { IInputElement ieTest = stylusOver; UIElement eTest = null; ContentElement ceTest = null; while (ieTest != null && ieTest != stylusCapture) { eTest = ieTest as UIElement; if(eTest != null) { ieTest = InputElement.GetContainingInputElement(eTest.GetUIParent(true)); } else { ceTest = ieTest as ContentElement; // Should never fail. ieTest = InputElement.GetContainingInputElement(ceTest.GetUIParent(true)); } } // If we missed the capture point, we didn't hit anything. if (ieTest != stylusCapture) { stylusOver = _stylusCapture; } } else { // We didn't hit anything. Consider the stylus over the capture point. stylusOver = _stylusCapture; } } break; } return stylusOver; }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource, IInputElement element, IInputElement oldParent) { throw new NotImplementedException(); }
private PresentationSource DetermineValidSource(PresentationSource inputSource, StylusPointCollection stylusPoints, PenContexts penContextsOfPoints) { HwndSource hwndSource = (HwndSource)inputSource; // See if window has been closed or is invalid if (inputSource.CompositionTarget == null || inputSource.CompositionTarget.IsDisposed || hwndSource == null || hwndSource.IsHandleNull) { PresentationSource newSource = null; // use capture as fallback first if (_stylusCapture != null) { DependencyObject containingVisual = InputElement.GetContainingVisual(_stylusCapture as DependencyObject); PresentationSource capturedSource = PresentationSource.CriticalFromVisual(containingVisual); if (capturedSource != null && capturedSource.CompositionTarget != null && !capturedSource.CompositionTarget.IsDisposed) { newSource = capturedSource; // Good new source to use! } } // Now try last screen point hittesting to find a new window/PresetationSource. if (newSource == null && stylusPoints != null) { Point ptScreen; // If we have the last penContext then we can remap the coordinates properly. // Otherwise we just use the last stylus mouse location to figure out a PresenationSource. if (penContextsOfPoints != null) { ptScreen = _stylusLogic.DeviceUnitsFromMeasureUnits((Point)stylusPoints[0]); // map from window to screen (ie - add the window location). ptScreen.Offset(penContextsOfPoints.DestroyedLocation.X, penContextsOfPoints.DestroyedLocation.Y); } else { ptScreen = _lastMouseScreenLocation; } IntPtr hwndHit = UnsafeNativeMethods.WindowFromPoint((int)ptScreen.X, (int)ptScreen.Y); if (hwndHit != IntPtr.Zero) { HwndSource newHwndSource = HwndSource.CriticalFromHwnd(hwndHit); if (newHwndSource != null && newHwndSource.Dispatcher == Dispatcher) { newSource = newHwndSource; } } } return newSource; } else { return inputSource; } }
public SourceChangedEventArgs(PresentationSource oldSource, PresentationSource newSource) : this(oldSource, newSource, null, null) { }