Esempio n. 1
0
        //--------------------------------------------------------------------
        //
        // Public Properties
        //
        //---------------------------------------------------------------------

        #region Static methods

        public static FixedSOMElement CreateFixedSOMElement(FixedPage page, UIElement uiElement, FixedNode fixedNode, int startIndex, int endIndex)
        {
            FixedSOMElement element = null;
            if (uiElement is Glyphs)
            {
                Glyphs glyphs = uiElement as Glyphs;
                if (glyphs.UnicodeString.Length > 0)
                {
                    GlyphRun glyphRun = glyphs.ToGlyphRun();
                    Rect alignmentBox = glyphRun.ComputeAlignmentBox();
                    alignmentBox.Offset(glyphs.OriginX, glyphs.OriginY);
                    GeneralTransform transform = glyphs.TransformToAncestor(page);
                    
                    if (startIndex < 0)
                    {
                        startIndex = 0;
                    }
                    if (endIndex < 0)
                    {
                        endIndex = glyphRun.Characters == null ? 0 : glyphRun.Characters.Count;
                    }
                    element = FixedSOMTextRun.Create(alignmentBox, transform, glyphs, fixedNode, startIndex, endIndex, false);
                }
            }
            else if (uiElement is Image)
            {
                element = FixedSOMImage.Create(page, uiElement as Image, fixedNode);
            }
            else if (uiElement is Path)
            {
                element = FixedSOMImage.Create(page, uiElement as Path, fixedNode);
            }
            return element;
        }
Esempio n. 2
0
 public void BuildNameHashTable(String Name, UIElement e, int indexToFixedNodes)
 {
     if (!_nameHashTable.ContainsKey(Name))
     {
         _nameHashTable.Add(Name,
             new NameHashFixedNode(e,indexToFixedNodes));
     }
 }
Esempio n. 3
0
        public static UIElement GetFocusScope(UIElement element)
        {
            while (element != null && !GetIsFocusScope(element))
            {
                element = (UIElement)(element.LogicalParent ?? element.VisualParent);
            }

            return element;
        }
Esempio n. 4
0
        /// <summary>
        /// Create an instance of the DragValidator class
        /// </summary>
        /// <param name="targetElement">UIElement that represents the source of the drag operation</param>
        public DragValidator(UIElement targetElement)
        {
            Debug.Assert(targetElement != null);

            _targetElement = targetElement;

            _targetElement.MouseLeftButtonDown += new MouseButtonEventHandler(TargetElement_MouseLeftButtonDown);
            _targetElement.MouseLeftButtonUp += new MouseButtonEventHandler(TargetElement_MouseLeftButtonUp);
            _targetElement.MouseMove += new MouseEventHandler(TargetElement_MouseMove);
        }
Esempio n. 5
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors
        
        /// <summary>
        /// C'tor for adorner
        /// </summary>
        /// <param name="scope">
        /// FramwerokElement with TextView to which this element is attached
        /// as adorner.
        /// </param>
        internal ColumnResizeAdorner(UIElement scope) : base(scope)
        {
            Debug.Assert(scope != null);

            // position
            _pen = new Pen(new SolidColorBrush(Colors.LightSlateGray), 2.0);

            _x = Double.NaN;
            _top = Double.NaN;
            _height = Double.NaN;
        }
Esempio n. 6
0
        //------------------------------------------------------------------- 
        //
        // Connstructors 
        // 
        //----------------------------------------------------------------------
 
        #region Constructors
        /// <summary>
        ///    Create a new FixedHighlight for a Glyphs with character offset of
        ///    beginOffset to endOffset, to be rendered with a given brush. 
        /// </summary>
        internal FixedHighlight(UIElement element, int beginOffset, int endOffset, FixedHighlightType t, 
                                Brush foreground, Brush background) 
        {
            Debug.Assert(element != null && beginOffset >= 0 && endOffset >= 0); 
            _element = element;
            _gBeginOffset = beginOffset;
            _gEndOffset = endOffset;
            _type = t; 
            _foregroundBrush = foreground;
            _backgroundBrush = background; 
        } 
Esempio n. 7
0
        /// <summary>
        ///     The colleciton is the children collection of the visualParent. The logicalParent 
        ///     is used to do logical parenting. The flags is used to invalidate 
        ///     the resource properties in the child tree, if an Application object exists.
        /// </summary> 
        /// <param name="visualParent">The element of whom this is a children collection</param>
        /// <param name="logicalParent">The logicalParent of the elements of this collection.
        /// if overriding Panel.CreateUIElementCollection, pass the logicalParent parameter of that method here.
        /// </param> 
        public UIElementCollection(UIElement visualParent, FrameworkElement logicalParent)
        { 
            if (visualParent == null) 
            {
                throw new ArgumentNullException(SR.Get(SRID.Panel_NoNullVisualParent, "visualParent", this.GetType())); 
            }

            _visualChildren = new VisualCollection(visualParent);
            _visualParent = visualParent; 
            _logicalParent = logicalParent;
        } 
Esempio n. 8
0
        public static IDisposable Focus(UIElement element)
        {
            if (!element.Focusable)
            {
                return null;
            }

            UIElement focusScope = GetFocusScope(element);

            if (focusScope != null)
            {
                SetFocusedElement(focusScope, element);
                return new Disposable(() =>
                {
                    if (GetFocusedElement(focusScope) == element)
                    {
                        SetFocusedElement(focusScope, null);
                    }
                });
            }

            return null;
        }
Esempio n. 9
0
 internal static Point Translate(this UIElement fromElement, UIElement toElement, Point fromPoint)
 {
     return fromElement.TransformToVisual(toElement).Transform(fromPoint);
 }
Esempio n. 10
0
        /// <summary>
        /// Writes the attached property Dock to the given element. 
        /// </summary>
        /// <param name="element">UIElement to which to write the attached property.</param> 
        /// <param name="dock">The property value to set</param> 
        /// <seealso cref="DockPanel.DockProperty" />
        public static void SetDock(UIElement element, Dock dock) 
        {
            if (element == null) { throw new ArgumentNullException("element"); }

            element.SetValue(DockProperty, dock); 
        }
Esempio n. 11
0
        public static Dock GetDock(UIElement element)
        { 
            if (element == null) { throw new ArgumentNullException("element"); } 

            return (Dock) element.GetValue(DockProperty); 
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // hit testing to find the inner most UIElement that was hit
        // as well as the containing fixed page. 
        private bool _HitTest(Point pt, out UIElement e)
        {
            e = null;

            HitTestResult result = VisualTreeHelper.HitTest(this.FixedPage, pt);
            DependencyObject v = (result != null) ? result.VisualHit : null;

            while (v != null)
            {
                DependencyObjectType t = v.DependencyObjectType;
                if (t == UIElementType || t.IsSubclassOf(UIElementType))
                {
                    e = (UIElement) v;
                    
                    return true;
                }
                v = VisualTreeHelper.GetParent(v);
            }

            return false;
        }
Esempio n. 13
0
 // This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly)
 internal static void InsertInternalChild(UIElementCollection children, int index, UIElement child)
 {
     children.InsertInternal(index, child);
 }
Esempio n. 14
0
        private void AddFixedNodeInFlow(int index, UIElement e)
        {
            if (_visitedArray[index])
            {
                // this has already been added to the document structure
                // Debug.Assert(false, "An element is referenced in the document structure multiple times");
                return; // ignore this reference
            }
            FixedNode fn = (FixedNode)_fixedNodes[index];

            if (e == null)
            {
                e = _fixedPage.GetElement(fn) as UIElement;
            }

            _visitedArray[index] = true;

            FixedSOMElement somElement = FixedSOMElement.CreateFixedSOMElement(_fixedPage, e, fn, -1, -1);
            if (somElement != null)
            {
                _flowBuilder.AddElement(somElement);
            }

        }
 /// <summary>
 /// Lets the page recalculate the rectangles for this element when its desired 
 /// size has changed. 
 /// </summary>
 public void OnChildDesiredSizeChanged(UIElement child) 
 {
     if (_basePage != null)
     {
         _basePage.OnChildDesiredSizeChanged(child); 
     }
 } 
Esempio n. 16
0
        private static void OnOwnerMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if ((ToolTipService._lastEnterSource != null) && object.ReferenceEquals(ToolTipService._lastEnterSource, e.OriginalSource)) 
            {
                return;
            } 
 
            if (ToolTipService._owner != sender)
            { 
                return;
            }
 
            // close the opened ToolTip or cancel mouse hover
            if (ToolTipService._currentToolTip == null)
            { 
                ToolTipService._openTimer.Stop(); 
                ToolTipService._owner = null;
                ToolTipService._lastEnterSource = null; 
                return;
            }
 
            CloseAutomaticToolTip(null, EventArgs.Empty);
        }
Esempio n. 17
0
        // This method should be executed on the UI thread 
        private static void CloseAutomaticToolTip(object sender, EventArgs e)
        { 
            ToolTipService._closeTimer.Stop();
            Debug.Assert(ToolTipService._currentToolTip != null, "no ToolTip to close");
 
            ToolTipService._currentToolTip.IsOpen = false;
            ToolTipService._currentToolTip = null;
            ToolTipService._owner = null; 
            ToolTipService._lastEnterSource = null; 

            // set last opened timestamp only if the ToolTip is opened by a mouse movement 
            ToolTipService._lastToolTipOpenedTime = DateTime.Now;

        } 
Esempio n. 18
0
 internal static void OnOwnerMouseLeave(object sender, MouseEventArgs e)
 { 
     if (ToolTipService._currentToolTip == null)
     {
         // ToolTip had not been opened yet 
         ToolTipService._openTimer.Stop();
         ToolTipService._owner = null;
         ToolTipService._lastEnterSource = null; 
         return; 
     }
     CloseAutomaticToolTip(null, EventArgs.Empty); 
 }
Esempio n. 19
0
        internal static void OnOwnerMouseEnterInternal(object sender, object source)
        {
            if ((ToolTipService._lastEnterSource != null) && object.ReferenceEquals(ToolTipService._lastEnterSource, source)) 
            {
                // ToolTipService had processed this event once before, when it fired on the child
                // skip it now 
                return; 
            }
 
            UIElement senderElement = (UIElement)sender;
            if (ToolTipService._currentToolTip != null)
            { 
                if (ToolTipService._toolTipDictionary[senderElement] != ToolTipService._currentToolTip)
                {
                    // first close the previous ToolTip if entering nested elements with tooltips 
                    CloseAutomaticToolTip(null, EventArgs.Empty); 
                }
                else 
                {
                    // reentering the same element
                    return; 
                }
            }
 
            ToolTipService._owner = senderElement; 
            ToolTipService._lastEnterSource = source;
 
            Debug.Assert(ToolTipService._currentToolTip == null);

            SetRootVisual(); 

            TimeSpan sinceLastOpen = DateTime.Now - ToolTipService._lastToolTipOpenedTime; 
            if (TimeSpan.Compare(sinceLastOpen, new TimeSpan(0, 0, 0, 0, TOOLTIPSERVICE_betweenShowDelay)) <= 0) 
            {
                // open the ToolTip immediately 
                OpenAutomaticToolTip(null, EventArgs.Empty);
            }
            else 
            {
                // open the ToolTip after the InitialShowDelay interval expires
                if (ToolTipService._openTimer == null) 
                { 
                    ToolTipService._openTimer = new DispatcherTimer();
                    ToolTipService._openTimer.Tick += new EventHandler(OpenAutomaticToolTip); 
                }
                ToolTipService._openTimer.Interval = new TimeSpan(0, 0, 0, 0, TOOLTIPSERVICE_initialShowDelay); 
                ToolTipService._openTimer.Start();
            }
        } 
Esempio n. 20
0
 /// <summary>
 /// Called when a UIElement-derived class which is hosted by a IContentHost changes its DesiredSize
 /// </summary>
 /// <param name="child">
 /// Child element whose DesiredSize has changed
 /// </param>
 protected virtual void OnChildDesiredSizeChangedCore(UIElement child)
 {
     this.OnChildDesiredSizeChanged(child);
 }
Esempio n. 21
0
 /// <summary>
 /// Called when a UIElement-derived class which is hosted by a IContentHost changes its DesiredSize
 /// NOTE: This method already exists for this class and is not specially implemented for IContentHost.
 /// If this method is called through IContentHost for this class it will fire an assert
 /// </summary>
 /// <param name="child">
 /// Child element whose DesiredSize has changed
 /// </param>
 void IContentHost.OnChildDesiredSizeChanged(UIElement child)
 {
     this.OnChildDesiredSizeChangedCore(child);
 }
Esempio n. 22
0
        internal static bool Within(this Point referencePoint, UIElement referenceElement, FrameworkElement targetElement, bool ignoreVertical)
        {
            Point position = referenceElement.Translate(targetElement, referencePoint);

            return position.X > 0 && position.X < targetElement.ActualWidth
                && (ignoreVertical
                    || (position.Y > 0 && position.Y < targetElement.ActualHeight)
                );
        }
Esempio n. 23
0
        /// <summary>
        /// OnChildDesiredSizeChanged
        /// Called from FlowDocumentPage for IContentHost implementation
        /// 



        internal void OnChildDesiredSizeChanged(UIElement child)
        {
            if (_structuralCache != null && _structuralCache.IsFormattedOnce && !_structuralCache.ForceReformat)
            {
                // If executed during formatting process, delay invalidation.
                // This may happen during formatting when text host notifies its about
                // baseline changes.
                if (_structuralCache.IsFormattingInProgress)
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                        new DispatcherOperationCallback(OnChildDesiredSizeChangedAsync), child);
                    return;
                }

                // Get start and end positions
                int childStartIndex = TextContainerHelper.GetCPFromEmbeddedObject(child, ElementEdge.BeforeStart);
                if (childStartIndex < 0)
                {
                    return;
                }

                TextPointer childStart = new TextPointer(_structuralCache.TextContainer.Start);
                childStart.MoveByOffset(childStartIndex);
                TextPointer childEnd = new TextPointer(childStart);
                childEnd.MoveByOffset(TextContainerHelper.EmbeddedObjectLength);

                // Create new DTR for changing UIElement and add it to DRTList.
                DirtyTextRange dtr = new DirtyTextRange(childStartIndex, TextContainerHelper.EmbeddedObjectLength, TextContainerHelper.EmbeddedObjectLength);
                _structuralCache.AddDirtyTextRange(dtr);

                // Notify formatter about content invalidation.
                if (_formatter != null)
                {
                    _formatter.OnContentInvalidated(true, childStart, childEnd);
                }
            }
        }
Esempio n. 24
0
        private static void UnregisterToolTip(UIElement owner)
        {
            Debug.Assert(owner != null, "owner element is required"); 
 
            if (!ToolTipService._toolTipDictionary.ContainsKey(owner))
            { 
                return;
            }
 
            owner.MouseEnter -= new MouseEventHandler(OnOwnerMouseEnter);
            owner.MouseLeave -= new MouseEventHandler(OnOwnerMouseLeave);
            owner.MouseLeftButtonDown -= new MouseButtonEventHandler(OnOwnerMouseLeftButtonDown); 
            owner.KeyDown -= new KeyEventHandler(OnOwnerKeyDown); 

            ToolTip toolTip = ToolTipService._toolTipDictionary[owner]; 
            if (toolTip.IsOpen)
            {
                if (toolTip == ToolTipService._currentToolTip) 
                {
                    // unregistering a currently open automatic toltip
                    // thus need to stop the timer 
                    ToolTipService._closeTimer.Stop(); 
                    ToolTipService._currentToolTip = null;
                    ToolTipService._owner = null; 
                    ToolTipService._lastEnterSource = null;
                }
 
                toolTip.IsOpen = false;
            }
 
            ToolTipService._toolTipDictionary[owner] = null; 
            ToolTipService._toolTipDictionary.Remove(owner);
        } 
Esempio n. 25
0
 /// <summary>
 ///     Fetch the logical/item offset for this child with respect to the top of the
 ///     panel. This is similar to a TransformToAncestor operation. Just works
 ///     in logical units.
 /// </summary>
 protected virtual double GetItemOffsetCore(UIElement child)
 {
     return 0;
 }
Esempio n. 26
0
	public static void SetPlacementTarget(DependencyObject element, UIElement value)
	{
		if (element == null)
		{
			throw new ArgumentNullException ("element");
		}
		
		element.SetValue (ToolTipService.PlacementTargetProperty, value);
	}
Esempio n. 27
0
 internal NameHashFixedNode(UIElement e, int i)
 {
     uiElement = e; index = i;
 }
Esempio n. 28
0
        /// <summary>
        /// Apply a template to the ToggleButton.
        /// </summary> 
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate(); 
 
            object root = GetTemplateChild(ElementRootName);
            Debug.Assert(typeof(FrameworkElement).IsInstanceOfType(root) || (root == null), 
                "The template part RootElement is not an instance of FrameworkElement!");
            _elementRoot = root as FrameworkElement;
 
            object focusVisual = GetTemplateChild(ElementFocusVisualName);
            Debug.Assert(typeof(UIElement).IsInstanceOfType(focusVisual) || (focusVisual == null),
                "The template part FocusVisualElement is not an instance of UIElement!"); 
            _elementFocusVisual = focusVisual as UIElement; 

            object contentFocusVisual = GetTemplateChild(ElementContentFocusVisualName); 
            Debug.Assert(typeof(UIElement).IsInstanceOfType(contentFocusVisual) || (contentFocusVisual == null),
                "The template part ContentFocusVisualElement is not an instance of UIElement!");
            _elementContentFocusVisual = contentFocusVisual as UIElement; 

            // Get the states
            if (_elementRoot != null) 
            { 
                object @checked = _elementRoot.Resources[StateCheckedName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(@checked) || (@checked == null), 
                    "The template part Checked State is not an instance of Storyboard!");
                _stateChecked = @checked as Storyboard;
 
                object indeterminate = _elementRoot.Resources[StateIndeterminateName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(indeterminate) || (indeterminate == null),
                    "The template part Indeterminate State is not an instance of Storyboard!"); 
                _stateIndeterminate = indeterminate as Storyboard; 

                object @unchecked = _elementRoot.Resources[StateNormalName]; 
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(@unchecked) || (@unchecked == null),
                    "The template part Normal State is not an instance of Storyboard!");
                _stateNormal = @unchecked as Storyboard; 

                object mouseOverChecked = _elementRoot.Resources[StateMouseOverCheckedName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(mouseOverChecked) || (mouseOverChecked == null), 
                    "The template part MouseOver Checked State is not an instance of Storyboard!"); 
                _stateMouseOverChecked = mouseOverChecked as Storyboard;
 
                object mouseOverIndeterminate = _elementRoot.Resources[StateMouseOverIndeterminateName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(mouseOverIndeterminate) || (mouseOverIndeterminate == null),
                    "The template part MouseOver Indeterminate State is not an instance of Storyboard!"); 
                _stateMouseOverIndeterminate = mouseOverIndeterminate as Storyboard;

                object mouseOverUnchecked = _elementRoot.Resources[StateMouseOverUncheckedName]; 
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(mouseOverUnchecked) || (mouseOverUnchecked == null), 
                    "The template part MouseOver Unchecked State is not an instance of Storyboard!");
                _stateMouseOverUnchecked = mouseOverUnchecked as Storyboard; 

                object pressedChecked = _elementRoot.Resources[StatePressedCheckedName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(pressedChecked) || (pressedChecked == null), 
                    "The template part Pressed Checked State is not an instance of Storyboard!");
                _statePressedChecked = pressedChecked as Storyboard;
 
                object pressedIndeterminate = _elementRoot.Resources[StatePressedIndeterminateName]; 
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(pressedIndeterminate) || (pressedIndeterminate == null),
                    "The template part Pressed Indeterminate State is not an instance of Storyboard!"); 
                _statePressedIndeterminate = pressedIndeterminate as Storyboard;

                object pressedUnchecked = _elementRoot.Resources[StatePressedUncheckedName]; 
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(pressedUnchecked) || (pressedUnchecked == null),
                    "The template part Pressed Unchecked State is not an instance of Storyboard!");
                _statePressedUnchecked = pressedUnchecked as Storyboard; 
 
                object disabledChecked = _elementRoot.Resources[StateDisabledCheckedName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(disabledChecked) || (disabledChecked == null), 
                    "The template part Disabled Checked State is not an instance of Storyboard!");
                _stateDisabledChecked = disabledChecked as Storyboard;
 
                object disabledIndeterminate = _elementRoot.Resources[StateDisabledIndeterminateName];
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(disabledIndeterminate) || (disabledIndeterminate == null),
                    "The template part Disabled Indeterminate State is not an instance of Storyboard!"); 
                _stateDisabledIndeterminate = disabledIndeterminate as Storyboard; 

                object disabledUnchecked = _elementRoot.Resources[StateDisabledUncheckedName]; 
                Debug.Assert(typeof(Storyboard).IsInstanceOfType(disabledUnchecked) || (disabledUnchecked == null),
                    "The template part Disabled Unchecked State is not an instance of Storyboard!");
                _stateDisabledUnchecked = disabledUnchecked as Storyboard; 
            }

            // Sync the logical and visual states of the control 
            UpdateVisualState(); 
        }
Esempio n. 29
0
		/*
        private static void PositiveValueValidation(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        { 
            if ((int)e.NewValue <= 0)
            { 
                throw new ArgumentException(Resource.ToolTipService_SetTimeoutProperty_InvalidValue, "e");
            }
        } 
		 */
        private static void RegisterToolTip(UIElement owner, object toolTip)
        { 
            Debug.Assert(!ToolTipService._toolTipDictionary.ContainsKey(owner), "duplicate tooltip for the same owner element"); 
            Debug.Assert(owner != null, "ToolTip must have an owner");
            Debug.Assert(toolTip != null, "ToolTip can not be null"); 

            owner.MouseEnter += new MouseEventHandler(OnOwnerMouseEnter);
            owner.MouseLeave += new MouseEventHandler(OnOwnerMouseLeave); 
            owner.MouseLeftButtonDown += new MouseButtonEventHandler(OnOwnerMouseLeftButtonDown);
            owner.KeyDown += new KeyEventHandler(OnOwnerKeyDown);
            ToolTipService._toolTipDictionary[owner] = ConvertToToolTip(toolTip); 
        } 
		private static void AddAutomationPeer(List<AutomationPeer> children, UIElement child)
		{
			if (child != null)
			{
				AutomationPeer peer = FromElement(child);
				if (peer == null)
				{
					peer = CreatePeerForElement(child);
				}

				if (peer != null)
				{
					// In the array that GetChildrenCore returns, which is used by AutomationPeer.EnsureChildren,
					// no null entries are allowed or a NullReferenceException will be thrown from the guts of WPF.
					// This has reproducibly been observed null on certain systems so the null check was added.
					// This may mean that some child controls are missing for automation, but at least the
					// application doesn't crash in normal usage.
					children.Add(peer);
				}
			}
		}