public static void Capture(Control ctrl)
        {
            if (ctrl == null)
                throw new ArgumentNullException();

            capturedCtrl = ctrl;
        }
        /// <summary>
        /// Sets the specified element at the specified index into the child
        /// collection. It also corrects the parent.
        /// Note that the function requires that _item[index] == null and it
        /// also requires that the passed in child is not connected to another UIElement.
        /// </summary>
        /// <exception cref="ArgumentException">If the new child has already a parent or if the slot a the specified index is not null.</exception>
        private void ConnectChild(int index, Control value)
        {
            // Every function that calls this function needs to call VerifyAccess to prevent
            // foreign threads from changing the tree.
            //
            // We also need to ensure that the tree is homogenous with respect
            // to the dispatchers that the elements belong to.
            //
            Debug.Assert(items[index] == null);

            value.Parent = owner;

            // The child might be dirty. Hence we need to propagate dirty information
            // from the parent and from the child.
            //Control.PropagateFlags(_owner, Control.Flags.IsSubtreeDirtyForRender);
            //Control.PropagateFlags(value, Control.Flags.IsSubtreeDirtyForRender);
            //value._flags |= Control.Flags.IsDirtyForRender;
            items[index] = value;
            version++;

            //Control.PropagateResumeLayout(value);

            // Fire notifications
            owner.OnChildrenChanged(value, null /* no removed child */, index);
        }
        /// <summary>
        /// Removes the specified element from the UIElementCollection.
        /// </summary>
        /// <param name="element">The UIElement to remove from the UIElementCollection.</param>
        /// <remarks>
        /// The UIElements that follow the removed UIElements move up to occupy
        /// the vacated spot. The indexes of the UIElements that are moved are
        /// also updated.
        ///
        /// If element is null then the first null entry is removed. Note that removing
        /// a null entry is linear in the size of the collection.
        /// </remarks>
        public void Remove(Control element)
        {
            int indexToRemove = -1;

            if (element != null)
            {
                if (element.Parent != owner)
                {
                    // If the UIElement is not in this collection we silently return without
                    // failing. This is the same behavior that ArrayList implements.
                    return;
                }

                Debug.Assert(element.Parent != null);

                DisconnectChild(indexToRemove = IndexOf(element));
            }
            else
            {
                // This is the case where element == null. We then remove the first null entry.
                for (int i = 0; i < size; i++)
                    if (items[i] == null)
                    {
                        indexToRemove = i;
                        break;
                    }
            }

            if (indexToRemove != -1)
            {
                --size;

                for (int i = indexToRemove; i < size; i++)
                {
                    Control child = items[i + 1];
                    items[i] = child;
                }

                items[size] = null;
            }

            //_owner.InvalidateMeasure();
        }
        /// <summary>
        /// Inserts an element into the UIElementCollection at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which value should be inserted.</param>
        /// <param name="element">The UIElement to insert. </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// index is less than zero.
        ///
        /// -or-
        ///
        /// index is greater than Count.
        /// </exception>
        /// <remarks>
        /// If Count already equals Capacity, the capacity of the
        /// UIElementCollection is increased before the new UIElement
        /// is inserted.
        ///
        /// If index is equal to Count, value is added to the
        /// end of UIElementCollection.
        ///
        /// The UIElements that follow the insertion point move down to
        /// accommodate the new UIElement. The indexes of the UIElements that are
        /// moved are also updated.
        /// </remarks>
        public void Insert(int index, Control element)
        {
            if (index < 0 || index > size)
                throw new ArgumentOutOfRangeException("index");

            if (element == null)
                throw new ArgumentNullException("element");

            if (element.Parent != null)  // or a element target can be added.
                throw new System.ArgumentException("element has parent");

            if ((items == null) || (size == items.Length))
                EnsureCapacity(size + 1);

            for (int i = size - 1; i >= index; i--)
            {
                Control child = items[i];
                items[i + 1] = child;
            }

            items[index] = null;

            size++;
            ConnectChild(index, element);
            // Note SetUIElement that increments the version to ensure proper enumerator
            // functionality.
            //_owner.InvalidateMeasure();
        }
        /// <summary>
        /// Returns the zero-based index of the UIElement. If the UIElement is not
        /// in the UIElementCollection -1 is returned. If null is passed to the method, the index
        /// of the first entry with null is returned. If there is no null entry -1 is returned.
        /// </summary>
        /// <param name="UIElement">The UIElement to locate in the UIElementCollection.</param>
        public int IndexOf(Control element)
        {
            if (element == null || element.Parent == owner)
            {
                for (int i = 0; i < size; i++)
                {
                    if (items[i] == element)
                        return i;
                }

                // not found, return -1
                return -1;
            }
            else
                return -1;
        }
Exemple #6
0
 internal void OnChildrenChanged(Control added, Control removed, int indexAffected)
 {
     if (added != null)
         added.Invalidate();
     else
         Invalidate();
 }
 public virtual bool Contains(Control child)
 {
     return children.IndexOf(child) != -1;
 }
 public ControlCollection2(Control owner)
 {
     this.owner = owner;
 }
        /// <summary>
        /// Appends a UIElement to the end of the UIElementCollection.
        /// </summary>
        /// <param name="visual">The UIElement to be added to the end of the UIElementCollection.</param>
        /// <returns>The UIElementCollection index at which the UIElement has been added.</returns>
        /// <remarks>Adding a null is allowed.</remarks>
        /// <exception cref="ArgumentException">If the new child has already a parent.</exception>
        public int Add(Control element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            if (element.Parent != null)
            {
                throw new System.ArgumentException("element has parent");
            }

            if ((items == null) || (size == items.Length))
                EnsureCapacity(size + 1);

            int addedPosition = size++;
            Debug.Assert(items[addedPosition] == null);

            ConnectChild(addedPosition, element);
            version++;

            // invalidate measure on parent
            //_owner.InvalidateMeasure();

            return addedPosition;
        }
Exemple #10
0
 public RenderTask(Control sender, Rect dirtyArea)
 {
     Sender = sender;
     DirtyArea = dirtyArea;
 }
        /// <summary>
        /// Determines whether a element is in the UIElementCollection.
        /// </summary>
        public bool Contains(Control element)
        {
            if (element == null)
            {
                for (int i = 0; i < _size; i++)
                {
                    if (_items[i] == null)
                    {
                        return true;
                    }
                }

                return false;
            }
            else
            {
                return (element.Parent == _owner);
            }
        }
        private Control FindTouchTarget(Control root, Point p)
        {
            return root.GetValidChildFromScreenPoint(p);

            if (lastEventTarget != null)
            {
                // old:
                Control target = lastEventTarget.GetValidChildFromScreenPoint(p);
                if (target != null)
                    return target;
                else if (lastEventTarget.ContainsScreenPoint(p))
                    return lastEventTarget;
                else
                {
                    Control par = lastEventTarget.GetValidParentFromScreenPoint(p);
                    return par != null ? par.GetValidChildFromScreenPoint(p) : (root != null ? root.GetValidChildFromScreenPoint(p) : null);
                }

                // new:
                //var par = lastEventTarget.GetValidParentFromScreenPoint(p);
                //return par != null ? par.GetValidChildFromScreenPoint(p) : (root != null ? root.GetValidChildFromScreenPoint(p) : null);
            }
            else
                return root.GetValidChildFromScreenPoint(p);
        }
        private Control GetTouchTarget(Point p)
        {
            Control result = null;

            //dt = DateTime.Now;
            if (TouchCapture.Captured != null)
                result = TouchCapture.Captured;
            else if (desktop.Children.Contains(cw))
                return cw;
            //else if (modalWindow != null)
            //    res = FindTouchTarget(modalWindow, p);
            else
                result = FindTouchTarget(desktop, p);
            //ts = DateTime.Now - dt;

            lastEventTarget = result;
            return result;
        }
 public static void ReleaseCapture()
 {
     capturedCtrl = null;
 }
 internal Enumerator(ControlCollection collection)
 {
     _collection = collection;
     _index = -1; // not started.
     _version = _collection.version;
     _currentElement = null;
 }
        /// <summary>
        /// Determines whether a element is in the UIElementCollection.
        /// </summary>
        public bool Contains(Control element)
        {
            if (element == null)
            {
                for (int i = 0; i < size; i++)
                    if (items[i] == null)
                        return true;

                return false;
            }
            else
                return (element.Parent == owner);
        }
 /// <summary>
 /// Advances the enumerator to the next element of the collection.
 /// </summary>
 public bool MoveNext()
 {
     if (_version == _collection.version)
     {
         if ((_index > -2) && (_index < (_collection.size - 1)))
         {
             _index++;
             _currentElement = _collection[_index];
             return true;
         }
         else
         {
             _currentElement = null;
             _index = -2; // -2 <=> reached the end.
             return false;
         }
     }
     else
     {
         throw new InvalidOperationException("collection changed");
     }
 }
 public ControlCollection(Control owner)
 {
     Debug.Assert(owner != null);
     this.owner = owner;
 }
 public virtual void Add(Control child)
 {
     child.Parent = owner;
     int idx = children.Add(child);
     owner.OnChildrenChanged(child, null, idx);
 }
 /// <summary>
 /// Strongly typed version of CopyTo
 /// Copies the collection into the Array.
 /// </summary>
 public virtual void CopyTo(Control[] array, int index)
 {
     CopyTo((Array)array, index);
 }
 public virtual void Remove(Control child)
 {
     int idx = children.IndexOf(child);
     children.Remove(child);
     child.Parent = null;
     owner.OnChildrenChanged(null, child, idx);
 }
        public void SetHub(Control page)
        {
            if (hub != null)
            {
                if (hub is Hub)
                    (hub as Hub).Exit();
                Children.Remove(hub);
                //hub.Visible = false;
            }

            hub = page;
            btnHome.Visible = hub != hubHome;

            hub.Visible = true;
            Children.Add(hub);
        }