示例#1
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        { 
            // This is all very sketchy...
            // 
            // Tablet can support multiple stylus devices concurrently.  They can each 
            // be over a different element.  They all update the IsStylusOver property,
            // which calls into here, but ends up using the "current" stylus device, 
            // instead of each using their own device.  Worse, all of these will end up
            // writing to the same bits in the UIElement.  They are going to step all over
            // each other.
            if(Stylus.CurrentStylusDevice == null) 
            {
                return; 
            } 

            StylusEventArgs stylusEventArgs = new StylusEventArgs(Stylus.CurrentStylusDevice, Environment.TickCount); 
            stylusEventArgs.RoutedEvent = oldValue ? Stylus.StylusLeaveEvent : Stylus.StylusEnterEvent;

            if (uie != null)
            { 
                uie.RaiseEvent(stylusEventArgs);
            } 
            else if (ce != null) 
            {
                ce.RaiseEvent(stylusEventArgs); 
            }
            else if (uie3D != null)
            {
                uie3D.RaiseEvent(stylusEventArgs); 
            }
        } 
示例#2
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        {
            // This is all very sketchy...
            //
            // Tablet can support multiple stylus devices concurrently.  They can each
            // be over a different element.  They all update the IsStylusOver property,
            // which calls into here, but ends up using the "current" stylus device,
            // instead of each using their own device.  Worse, all of these will end up
            // writing to the same bits in the UIElement.  They are going to step all over
            // each other.
            if (Stylus.CurrentStylusDevice == null)
            {
                return;
            }

            StylusEventArgs stylusEventArgs = new StylusEventArgs(Stylus.CurrentStylusDevice, Environment.TickCount);

            stylusEventArgs.RoutedEvent = oldValue ? Stylus.StylusLeaveEvent : Stylus.StylusEnterEvent;

            if (uie != null)
            {
                uie.RaiseEvent(stylusEventArgs);
            }
            else if (ce != null)
            {
                ce.RaiseEvent(stylusEventArgs);
            }
            else if (uie3D != null)
            {
                uie3D.RaiseEvent(stylusEventArgs);
            }
        }
示例#3
0
        /// <summary>
        ///     Adds a handler for the SourceChanged event to the element.
        /// </summary>
        /// <param name="element">The element to add the handler too.</param>
        /// <param name="handler">The hander to add.</param>
        /// <remarks>
        ///     Even though this is a routed event handler, there are special
        ///     restrictions placed on this event.
        ///     1) You cannot use the UIElement or ContentElement AddHandler() method.
        ///     2) Class handlers are not allowed.
        ///     3) The handlers will receive the SourceChanged event even if it was handled.
        ///     Callers must have UIPermission(UIPermissionWindow.AllWindows) to call this API.
        /// </remarks>
        public static void AddSourceChangedHandler(IInputElement element, SourceChangedEventHandler handler)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // Either UIElement or ContentElement
            if (!InputElement.IsValid(element))
            {
                throw new ArgumentException(SR.Get(SRID.Invalid_IInputElement), "element");
            }
            DependencyObject o = (DependencyObject)element;

            //             o.VerifyAccess();


            // I would rather throw an exception here, but the CLR doesn't
            // so we won't either.
            if (handler != null)
            {
                FrugalObjectList <RoutedEventHandlerInfo> info;

                if (InputElement.IsUIElement(o))
                {
                    UIElement uie = o as UIElement;
                    uie.AddHandler(SourceChangedEvent, handler);
                    info = uie.EventHandlersStore[SourceChangedEvent];
                    if (1 == info.Count)
                    {
                        uie.VisualAncestorChanged += new Visual.AncestorChangedEventHandler(uie.OnVisualAncestorChanged);
                        AddElementToWatchList(uie);
                    }
                }
                else if (InputElement.IsUIElement3D(o))
                {
                    UIElement3D uie3D = o as UIElement3D;
                    uie3D.AddHandler(SourceChangedEvent, handler);
                    info = uie3D.EventHandlersStore[SourceChangedEvent];
                    if (1 == info.Count)
                    {
                        uie3D.VisualAncestorChanged += new Visual.AncestorChangedEventHandler(uie3D.OnVisualAncestorChanged);
                        AddElementToWatchList(uie3D);
                    }
                }
                else
                {
                    ContentElement ce = o as ContentElement;
                    ce.AddHandler(SourceChangedEvent, handler);
                    info = ce.EventHandlersStore[SourceChangedEvent];
                    if (1 == info.Count)
                    {
                        AddElementToWatchList(ce);
                    }
                }
            }
        }
 ///
 public UIElement3DAutomationPeer(UIElement3D owner)
 {
     if(owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     
     _owner = owner;
 }
 ///<summary>
 /// This static helper creates an AutomationPeer for the specified element and 
 /// caches it - that means the created peer is going to live long and shadow the
 /// element for its lifetime. The peer will be used by Automation to proxy the element, and
 /// to fire events to the Automation when something happens with the element.
 /// The created peer is returned from this method and also from subsequent calls to this method
 /// and <seealso cref="FromElement"/>. The type of the peer is determined by the 
 /// <seealso cref="UIElement3D.OnCreateAutomationPeer"/> virtual callback. If UIElement3D does not
 /// implement the callback, there will be no peer and this method will return 'null' (in other
 /// words, there is no such thing as a 'default peer').
 ///</summary>
 public static AutomationPeer CreatePeerForElement(UIElement3D element)
 {
     if(element == null)
     {
         throw new ArgumentNullException("element");
     }
     
     return element.CreateAutomationPeer();
 }
        ///
        public static AutomationPeer FromElement(UIElement3D element)
        {
            if(element == null)
            {
                throw new ArgumentNullException("element");
            }

            return element.GetAutomationPeer();
        }
示例#7
0
        /////////////////////////////////////////////////////////////////////

        private static void SetFlag(UIElement uie, ContentElement ce, UIElement3D uie3D, CoreFlags flag, bool value)
        {
            if (uie != null)
            {
                uie.WriteFlag(flag, value);
            }
            else if (ce != null)
            {
                ce.WriteFlag(flag, value);
            }
            else if (uie3D != null)
            {
                uie3D.WriteFlag(flag, value);
            }
        }
示例#8
0
        /////////////////////////////////////////////////////////////////////

        private static bool IsFlagSet(UIElement uie, ContentElement ce, UIElement3D uie3D, CoreFlags flag)
        {
            if (uie != null)
            {
                return(uie.ReadFlag(flag));
            }
            else if (ce != null)
            {
                return(ce.ReadFlag(flag));
            }
            else if (uie3D != null)
            {
                return(uie3D.ReadFlag(flag));
            }

            return(false);
        }
示例#9
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        {
            // Before we fire the mouse event we need to figure if the notification is still relevant.
            // This is because it is possible that the mouse state has changed during the previous
            // property engine callout. Example: Consider a MessageBox being displayed during the
            // IsMouseOver OnPropertyChanged override.

            bool shouldFireNotification = false;

            if (uie != null)
            {
                shouldFireNotification = (!oldValue && uie.IsMouseOver) || (oldValue && !uie.IsMouseOver);
            }
            else if (ce != null)
            {
                shouldFireNotification = (!oldValue && ce.IsMouseOver) || (oldValue && !ce.IsMouseOver);
            }
            else if (uie3D != null)
            {
                shouldFireNotification = (!oldValue && uie3D.IsMouseOver) || (oldValue && !uie3D.IsMouseOver);
            }

            if (shouldFireNotification)
            {
                MouseEventArgs mouseEventArgs = new MouseEventArgs(Mouse.PrimaryDevice, Environment.TickCount, Mouse.PrimaryDevice.StylusDevice);
                mouseEventArgs.RoutedEvent = oldValue ? Mouse.MouseLeaveEvent : Mouse.MouseEnterEvent;

                if (uie != null)
                {
                    uie.RaiseEvent(mouseEventArgs);
                }
                else if (ce != null)
                {
                    ce.RaiseEvent(mouseEventArgs);
                }
                else if (uie3D != null)
                {
                    uie3D.RaiseEvent(mouseEventArgs);
                }
            }
        }
示例#10
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        {
            DependencyPropertyChangedEventArgs args =
                new DependencyPropertyChangedEventArgs(
                    UIElement.IsKeyboardFocusWithinProperty,
                    BooleanBoxes.Box(oldValue),
                    BooleanBoxes.Box(!oldValue));

            if (uie != null)
            {
                uie.RaiseIsKeyboardFocusWithinChanged(args);
            }
            else if (ce != null)
            {
                ce.RaiseIsKeyboardFocusWithinChanged(args);
            }
            else if (uie3D != null)
            {
                uie3D.RaiseIsKeyboardFocusWithinChanged(args);
            }
        }
示例#11
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        {
            DependencyPropertyChangedEventArgs args = 
                    new DependencyPropertyChangedEventArgs(
                        UIElement.IsKeyboardFocusWithinProperty, 
                        BooleanBoxes.Box(oldValue), 
                        BooleanBoxes.Box(!oldValue));
            
            if (uie != null)
            {
                uie.RaiseIsKeyboardFocusWithinChanged(args);
            }
            else if (ce != null)
            {
                ce.RaiseIsKeyboardFocusWithinChanged(args);
            }
            else if (uie3D != null)
            {
                uie3D.RaiseIsKeyboardFocusWithinChanged(args);
            }
        }
示例#12
0
        /////////////////////////////////////////////////////////////////////

        internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
        {
            // Before we fire the mouse event we need to figure if the notification is still relevant. 
            // This is because it is possible that the mouse state has changed during the previous 
            // property engine callout. Example: Consider a MessageBox being displayed during the 
            // IsMouseOver OnPropertyChanged override.
            
            bool shouldFireNotification = false;
            if (uie != null)
            {
                shouldFireNotification = (!oldValue && uie.IsMouseOver) || (oldValue && !uie.IsMouseOver);
            }
            else if (ce != null)
            {
                shouldFireNotification = (!oldValue && ce.IsMouseOver) || (oldValue && !ce.IsMouseOver);
            }
            else if (uie3D != null)
            {
                shouldFireNotification = (!oldValue && uie3D.IsMouseOver) || (oldValue && !uie3D.IsMouseOver);
            }

            if (shouldFireNotification)
            {
                MouseEventArgs mouseEventArgs = new MouseEventArgs(Mouse.PrimaryDevice, Environment.TickCount, Mouse.PrimaryDevice.StylusDevice);
                mouseEventArgs.RoutedEvent = oldValue ? Mouse.MouseLeaveEvent : Mouse.MouseEnterEvent;

                if (uie != null)
                {
                    uie.RaiseEvent(mouseEventArgs);
                }
                else if (ce != null)
                {
                    ce.RaiseEvent(mouseEventArgs);
                }
                else if (uie3D != null)
                {
                    uie3D.RaiseEvent(mouseEventArgs);
                }
            }
        }
示例#13
0
 internal abstract void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue);
 internal abstract void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue);
        /////////////////////////////////////////////////////////////////////

        private static void CastElement(DependencyObject o, out UIElement uie, out ContentElement ce, out UIElement3D uie3D)
        {
            uie = o as UIElement;
            ce = (uie != null) ? null : o as ContentElement;
            uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
        }
        /////////////////////////////////////////////////////////////////////

        private static bool IsFlagSet(UIElement uie, ContentElement ce, UIElement3D uie3D, CoreFlags flag)
        {
            if (uie != null)
            {
                return uie.ReadFlag(flag);
            }
            else if (ce != null)
            {
                return ce.ReadFlag(flag);
            }
            else if (uie3D != null)
            {
                return uie3D.ReadFlag(flag);
            }

            return false;
        }
        /////////////////////////////////////////////////////////////////////

        private static void SetFlag(UIElement uie, ContentElement ce, UIElement3D uie3D, CoreFlags flag, bool value)
        {
            if (uie != null)
            {
                uie.WriteFlag(flag, value);
            }
            else if (ce != null)
            {
                ce.WriteFlag(flag, value);
            }
            else if (uie3D != null)
            {
                uie3D.WriteFlag(flag, value);
            }
        }
        /////////////////////////////////////////////////////////////////////

        private static bool BlockReverseInheritance(UIElement uie, ContentElement ce, UIElement3D uie3D)
        {
            if (uie != null)
            {
                return uie.BlockReverseInheritance();
            }
            else if (ce != null)
            {
                return ce.BlockReverseInheritance();
            }
            else if (uie3D != null)
            {
                return uie3D.BlockReverseInheritance();
            }

            return false;
        }
示例#19
0
        /////////////////////////////////////////////////////////////////////

        private static void CastElement(DependencyObject o, out UIElement uie, out ContentElement ce, out UIElement3D uie3D)
        {
            uie   = o as UIElement;
            ce    = (uie != null) ? null : o as ContentElement;
            uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
        }
示例#20
0
 private static void CastInputElement(IInputElement element, out UIElement uiElement, out ContentElement contentElement, out UIElement3D uiElement3D)
 {
     uiElement = element as UIElement;
     contentElement = (uiElement == null) ? element as ContentElement : null;
     uiElement3D = ((uiElement == null) && (contentElement == null)) ? element as UIElement3D : null;
 }
 internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue)
 {
 }
示例#22
0
        // Also called by FrameworkContentElement
        internal static void SynchronizeForceInheritProperties(
            UIElement        uiElement,
            ContentElement   contentElement,
            UIElement3D      uiElement3D,
            DependencyObject parent)
        {
            if(uiElement != null || uiElement3D != null)
            {
                bool parentValue = (bool) parent.GetValue(IsEnabledProperty);
                if(!parentValue)
                {
                    // For Read/Write force-inherited properties, use the standard coersion pattern.
                    //
                    // The IsEnabled property must be coerced false if the parent is false.
                    if (uiElement != null)
                    {
                        uiElement.CoerceValue(IsEnabledProperty);
                    }
                    else
                    {
                        uiElement3D.CoerceValue(IsEnabledProperty);
                    }
                }

                parentValue = (bool) parent.GetValue(IsHitTestVisibleProperty);
                if(!parentValue)
                {
                    // For Read/Write force-inherited properties, use the standard coersion pattern.
                    //
                    // The IsHitTestVisible property must be coerced false if the parent is false.
                    if (uiElement != null)
                    {
                        uiElement.CoerceValue(IsHitTestVisibleProperty);
                    }
                    else
                    {
                        uiElement3D.CoerceValue(IsHitTestVisibleProperty);
                    }
                }

                parentValue = (bool) parent.GetValue(IsVisibleProperty);
                if(parentValue)
                {
                    // For Read-Only force-inherited properties, use a private update method.
                    //
                    // The IsVisible property can only be true if the parent is true.
                    if (uiElement != null)
                    {
                        uiElement.UpdateIsVisibleCache();
                    }
                    else
                    {
                        uiElement3D.UpdateIsVisibleCache();
                    }
                }
            }
            else if(contentElement != null)
            {
                bool parentValue = (bool) parent.GetValue(IsEnabledProperty);
                if(!parentValue)
                {
                    // The IsEnabled property must be coerced false if the parent is false.
                    contentElement.CoerceValue(IsEnabledProperty);
                }
            }
        }
示例#23
0
        /// <summary>
        ///     Removes a handler for the SourceChanged event to the element.
        /// </summary>
        /// <param name="e">The element to remove the handler from.</param>
        /// <param name="handler">The hander to remove.</param>
        /// <remarks>
        ///     Even though this is a routed event handler, there are special
        ///     restrictions placed on this event.
        ///     1) You cannot use the UIElement or ContentElement RemoveHandler() method.
        /// </remarks>
        public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEventHandler handler)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (!InputElement.IsValid(e))
            {
                throw new ArgumentException(SR.Get(SRID.Invalid_IInputElement), "e");
            }
            DependencyObject o = (DependencyObject)e;

            //             o.VerifyAccess();

            // I would rather throw an exception here, but the CLR doesn't
            // so we won't either.
            if (handler != null)
            {
                FrugalObjectList <RoutedEventHandlerInfo> info = null;
                EventHandlersStore store;

                // Either UIElement or ContentElement.
                if (InputElement.IsUIElement(o))
                {
                    UIElement uie = o as UIElement;
                    uie.RemoveHandler(SourceChangedEvent, handler);
                    store = uie.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        uie.VisualAncestorChanged -= new Visual.AncestorChangedEventHandler(uie.OnVisualAncestorChanged);;
                        RemoveElementFromWatchList(uie);
                    }
                }
                else if (InputElement.IsUIElement3D(o))
                {
                    UIElement3D uie3D = o as UIElement3D;
                    uie3D.RemoveHandler(SourceChangedEvent, handler);
                    store = uie3D.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        uie3D.VisualAncestorChanged -= new Visual.AncestorChangedEventHandler(uie3D.OnVisualAncestorChanged);;
                        RemoveElementFromWatchList(uie3D);
                    }
                }
                else
                {
                    ContentElement ce = o as ContentElement;
                    ce.RemoveHandler(SourceChangedEvent, handler);
                    store = ce.EventHandlersStore;
                    if (store != null)
                    {
                        info = store[SourceChangedEvent];
                    }
                    if (info == null || info.Count == 0)
                    {
                        RemoveElementFromWatchList(ce);
                    }
                }
            }
        }
        internal static bool InvalidateAutomationPeer(
            DependencyObject o, 
            out UIElement e, 
            out ContentElement ce, 
            out UIElement3D e3d)
        {
            e = null;
            ce = null;
            e3d = null;
            
            AutomationPeer ap = null;
            
            e = o as UIElement;
            if (e != null)
            {
                if (e.HasAutomationPeer == true)
                    ap = e.GetAutomationPeer();
            }
            else
            {
                ce = o as ContentElement;
                if (ce != null)
                {
                    if (ce.HasAutomationPeer == true)
                        ap = ce.GetAutomationPeer();
                }
                else
                {
                    e3d = o as UIElement3D;
                    if (e3d != null)
                    {
                        if (e3d.HasAutomationPeer == true)
                            ap = e3d.GetAutomationPeer();
                    }
                }
            }

            if (ap != null)
            {
                ap.InvalidateAncestorsRecursive();
            
                // Check for parent being non-null while stopping as we don't want to stop in between due to peers not connected to AT
                // those peers sometimes gets created to serve for various patterns.
                // e.g: ScrollViewAutomationPeer for Scroll Pattern in case of ListBox.
                if (ap.GetParent() != null)
                    return false;
            }

            return true;
        }
        private static bool ValidateUIElement3DForCapture(UIElement3D element)
        {
            if (element.IsEnabled == false)
                return false;

            if (element.IsVisible == false)
                return false;

            if (element.IsHitTestVisible == false)
                return false;

            return true;
        }
示例#26
0
        /////////////////////////////////////////////////////////////////////

        private static bool BlockReverseInheritance(UIElement uie, ContentElement ce, UIElement3D uie3D)
        {
            if (uie != null)
            {
                return(uie.BlockReverseInheritance());
            }
            else if (ce != null)
            {
                return(ce.BlockReverseInheritance());
            }
            else if (uie3D != null)
            {
                return(uie3D.BlockReverseInheritance());
            }

            return(false);
        }