public RawGenericInputReport(PresentationSource inputSource,
                 GenericEvent genericEvent, UIElement destTarget)
     : base(inputSource, genericEvent.Time)
 {
     InternalEvent = genericEvent;
     Target = destTarget;
 }
        //
        // this was added for aux, behavior needs to change for watch.
        //
        protected internal override void OnChildrenChanged(UIElement added, UIElement removed, int indexAffected)
        {
            base.OnChildrenChanged(added, removed, indexAffected);

            UIElementCollection children = LogicalChildren;
            int last = children.Count - 1;

            // something was added, and it's the topmost. Make sure it is visible before setting focus
            if (added != null && indexAffected == last && Visibility.Visible == added.Visibility)
            {
                Input.Buttons.Focus(added);
                Input.TouchCapture.Capture(added);
            }

            // something was removed and it lost focus to us.
            if (removed != null && this.IsFocused)
            {
                // we still have a window left, so make it focused.
                if (last >= 0)
                {
                    Input.Buttons.Focus(children[last]);
                    Input.TouchCapture.Capture(children[last]);
                }
            }
        }
Example #3
0
        /// <summary>
        ///     Focuses the button input on a particular element.
        /// </summary>
        /// <param name="element">
        ///     The element to focus the button pad on.
        /// </param>
        /// <returns>Element focused to</returns>
        public UIElement Focus(UIElement obj)
        {
            VerifyAccess();

            bool forceToNullIfFailed = false;

            // Make sure that the element is enabled.  This includes all parents.
            bool enabled = true;
            bool visible = true;
            if (obj != null)
            {
                enabled = obj.IsEnabled;
                visible = obj.IsVisible;

                if ((enabled && visible) && forceToNullIfFailed)
                {
                    obj = null;
                    enabled = true;
                    visible = true;
                }
            }

            if ((enabled && visible) && obj != _focus)
            {
                // go ahead and change our internal sense of focus to the desired element.
                ChangeFocus(obj, DateTime.UtcNow);
            }

            return _focus;
        }
Example #4
0
        public static bool Capture(UIElement element, CaptureMode mode)
        {
            if (mode != CaptureMode.None)
            {
                if (element == null)
                {
                    throw new ArgumentException();
                }

                /// Make sure the element is attached
                /// to the MainWindow subtree.
                if (!IsMainWindowChild(element))
                {
                    throw new ArgumentException();
                }

                if (mode == CaptureMode.SubTree)
                {
                    throw new NotImplementedException();
                }

                if (mode == CaptureMode.Element)
                {
                    _captureElement = element;
                }
            }
            else
            {
                _captureElement = null;
            }

            return true;
        }
 public RawTouchInputReport(PresentationSource inputSource,
             DateTime timestamp, byte eventMessage, TouchInput[] touches, UIElement destTarget)
     : base(inputSource, timestamp)
 {
     EventMessage = eventMessage;
     Touches = touches;
     Target = destTarget;
 }
Example #6
0
        public ToolButton(string name, UIElement content)
        {
            this.name = name;

            brushPressed = new SolidColorBrush(ColorUtility.ColorFromRGB(128, 255, 0));
            brushPressed.Opacity = 200;

            Content = content;
        }
Example #7
0
            public void Add(UIElement e)
            {
                if (!_elements.Contains(e))
                {
                    RemoveOrphans(e);
                    _elements.Add(e);
                }

                _layoutManager.NeedsRecalc();
            }
Example #8
0
        /// <summary> 
        /// Reads the pseudo-attached property Dock from the given element.
        /// </summary> 
        /// <param name="element">UIElement from which to read the pseudo-attached property.</param>
        /// <returns>The property's value.</returns>
        public static Dock GetDock(UIElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            int index = DockPropertiesKeys.IndexOf(element);
            if (index != -1)
                return (Dock)DockPropertiesValues[index];

            return Dock.Left;
        }
Example #9
0
 public void RemoveOrphans(UIElement parent)
 {
     int count = _elements.Count;
     for (int index = count - 1; index >= 0; index--)
     {
         UIElement child = (UIElement)_elements[index];
         if (child._parent == parent)
         {
             _elements.RemoveAt(index);
         }
     }
 }
Example #10
0
        private static bool IsMainWindowChild(UIElement element)
        {
            UIElement mainWindow = Application.Current.MainWindow;
            while (element != null)
            {
                if (element == mainWindow)
                    return true;

                element = element.Parent;
            }

            return false;
        }
Example #11
0
        public Button(UIElement content)
        {
            brushUnpressed = new SolidColorBrush(Colors.Black);
            brushUnpressed.Opacity = 10;

            brushPressed = new SolidColorBrush(ColorUtility.ColorFromRGB(128, 255, 0));
            brushPressed.Opacity = 200;

            brushTransparent = new SolidColorBrush(Colors.Red);
            brushTransparent.Opacity = Bitmap.OpacityTransparent;

            border = new Pen(Colors.DarkGray, 1);

            Content = content;
        }
Example #12
0
        public ParameterValue(UIElement ctrl1, UIElement ctrl2)
        {
            HorizontalAlignment = HorizontalAlignment.Stretch;

            ctrl1.HorizontalAlignment = HorizontalAlignment.Left;
            ctrl1.VerticalAlignment = VerticalAlignment.Center;
            Children.Add(ctrl1);
            SetDock(ctrl1, Dock.Left);

            ctrl2.HorizontalAlignment = HorizontalAlignment.Right;
            ctrl2.VerticalAlignment = VerticalAlignment.Center;
            Children.Add(ctrl2);
            SetDock(ctrl2, Dock.Right);

            SetMargin(1);
        }
        public MFTestResults UIElement_RootUIElementTest25()
        {
            Log.Comment("Gets the RootUIElement of child rectangle and panel");
            Log.Comment("Verifies RootUIElement is WindowManager.Instance");
            Log.Comment("Creates a new Panel, creates a rectangle and add it as a child of the panel");
            Log.Comment("Gets the RootUIElement of the new rectangle and panel");
            Log.Comment("Verifies RootUIElement is the new Panle");
            MFTestResults testResult = MFTestResults.Pass;
            Panel p = new Panel();
            Rectangle r = new Rectangle();
            p.Children.Add(r);
            UIElement[] uiElets = new UIElement[] { _rect, _panel, r, p };
            //corresponding root UIElements
            UIElement[] roots = new UIElement[] { WindowManager.Instance, WindowManager.Instance, p, p };
            for (int i = 0; i < uiElets.Length; i++)
            {
                Log.Comment("Getting the RootUIElement of '" +
                    uiElets[i].GetType() + "' and Verifying");
                if (uiElets[i].RootUIElement != roots[i])
                {
                    Log.Comment("Failure : expected RootUIElement '" +
                        roots + "' but got '" + uiElets[i].RootUIElement + "'");
                    testResult = MFTestResults.Fail;
                }
            }

            return testResult;
        }
Example #14
0
        private void ChangeFocus(UIElement focus, DateTime timestamp)
        {
            if (focus != _focus)
            {
                // Update the critical pieces of data.
                UIElement oldFocus = _focus;
                _focus = focus;
                _focusRootUIElement = focus != null ? focus.RootUIElement : null;

                // Adjust the handlers we use to track everything.
                if (oldFocus != null)
                {
                    oldFocus.IsEnabledChanged -= _isEnabledOrVisibleChangedEventHandler;
                    oldFocus.IsVisibleChanged -= _isEnabledOrVisibleChangedEventHandler;
                }

                if (focus != null)
                {
                    focus.IsEnabledChanged += _isEnabledOrVisibleChangedEventHandler;
                    focus.IsVisibleChanged += _isEnabledOrVisibleChangedEventHandler;
                }

                // Send the LostFocus and GotFocus events.
                if (oldFocus != null)
                {
                    FocusChangedEventArgs lostFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus);
                    lostFocus.RoutedEvent = Buttons.LostFocusEvent;
                    lostFocus.Source = oldFocus;

                    _inputManager.ProcessInput(lostFocus);
                }

                if (focus != null)
                {
                    FocusChangedEventArgs gotFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus);
                    gotFocus.RoutedEvent = Buttons.GotFocusEvent;
                    gotFocus.Source = focus;

                    _inputManager.ProcessInput(gotFocus);
                }
            }
        }
 /// <summary>
 /// Strongly typed version of CopyTo
 /// Copies the collection into the Array.
 /// </summary>
 public virtual void CopyTo(UIElement[] array, int index)
 {
     CopyTo((Array)array, index);
 }
 /// <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");
     }
 }
Example #17
0
        public void GetPosition(UIElement relativeTo, int touchIndex, out int x, out int y)
        {
            x = Touches[touchIndex].X;
            y = Touches[touchIndex].Y;

            relativeTo.PointToClient(ref x, ref y);
        }
Example #18
0
 public void Remove(UIElement e)
 {
     _elements.Remove(e);
 }
Example #19
0
        private void getProperArrangeRect(UIElement element, out int x, out int y, out int width, out int height)
        {
            x = element._finalX;
            y = element._finalY;
            width = element._finalWidth;
            height = element._finalHeight;

            // ELements without a parent (top level) get Arrange at DesiredSize
            // if they were measured "to content" (as Constants.MaxExtent indicates).
            // If we arrange the element that is temporarily disconnected
            // so it is not a top-level one, the assumption is that it will be
            // layout-invalidated and/or recomputed by the parent when reconnected.
            if (element.Parent == null)
            {
                int desiredWidth, desiredHeight;
                x = y = 0;
                element.GetDesiredSize(out desiredWidth, out desiredHeight);

                if (element._previousAvailableWidth == Media.Constants.MaxExtent)
                    width = desiredWidth;

                if (element._previousAvailableHeight == Media.Constants.MaxExtent)
                    height = desiredHeight;
            }
        }
        /// <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(UIElement element)
        {
            int indexToRemove = -1;

            _owner.VerifyAccess();

            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++)
                {
                    UIElement child = _items[i + 1];
                    _items[i] = child;
                }

                _items[_size] = null;
            }

            _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(UIElement 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;
            }
        }
        /// <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, UIElement 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.
            //
            value.VerifyAccess();

            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.
            UIElement.PropagateFlags(_owner, UIElement.Flags.IsSubtreeDirtyForRender);
            UIElement.PropagateFlags(value, UIElement.Flags.IsSubtreeDirtyForRender);
            value._flags |= UIElement.Flags.IsDirtyForRender;
            _items[index] = value;
            _version++;

            UIElement.PropagateResumeLayout(value);

            // Fire notifications
            _owner.OnChildrenChanged(value, null /* no removed child */, index);
        }
 public UIElementCollection(UIElement owner)
 {
     Debug.Assert(owner != null);
     _owner = owner;
 }
 public HighlightableListBoxItem(UIElement content)
 {
     this.Child = content;
     this.Background = null;
 }
Example #25
0
        public bool OnEvent(BaseEvent ev)
        {
            InputReport ir  = null;
            InputDevice dev = null;

            /// Process known events, otherwise forward as generic to MainWindow.
            ///

            TouchEvent touchEvent = ev as TouchEvent;

            if (touchEvent != null)
            {
                Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                ///
                ///  Make sure the current event's coordinates are contained in the current
                ///  stylus/touch window, if not then search for the appropriate window
                ///
                if (targetWindow != null && touchEvent.EventMessage == (byte)TouchMessages.Down)
                {
                    int x = 0, y = 0, w, h;
                    int xSrc = touchEvent.Touches[0].X;
                    int ySrc = touchEvent.Touches[0].Y;

                    targetWindow.PointToScreen(ref x, ref y);
                    targetWindow.GetRenderSize(out w, out h);

                    if (!(x <= xSrc && xSrc <= (x + w) &&
                          y <= ySrc && ySrc <= (y + h)))
                    {
                        // only look for different target window if the touch point is inside
                        // the system metrics, otherwise, it may be a touch calibration point
                        // which is translated in the application layer.
                        if (xSrc <= SystemMetrics.ScreenWidth &&
                            ySrc <= SystemMetrics.ScreenHeight)
                        {
                            targetWindow = null;
                        }
                    }
                }

                if (targetWindow == null)
                {
                    //If we can enforce that the first event in the array is always the primary touch, we don't have to
                    //search.
                    targetWindow = WindowManager.Instance.GetPointerTarget(touchEvent.Touches[0].X, touchEvent.Touches[0].Y);
                }

                if (targetWindow != null)
                {
                    _inputManager.TouchDevice.SetTarget(targetWindow);
                }
                else
                {
                    _inputManager.TouchDevice.SetTarget(MainWindow);
                }

                ir =
                    new RawTouchInputReport(
                        null,
                        touchEvent.Time,
                        touchEvent.EventMessage,
                        touchEvent.Touches
                        );

                dev = _inputManager._touchDevice;
            }
            else if (ev is GenericEvent)
            {
                GenericEvent genericEvent = (GenericEvent)ev;

                Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                if (targetWindow == null)
                {
                    targetWindow = WindowManager.Instance.GetPointerTarget(genericEvent.X, genericEvent.Y);
                }

                if (targetWindow != null)
                {
                    _inputManager.GenericDevice.SetTarget(targetWindow);
                }
                else
                {
                    _inputManager.GenericDevice.SetTarget(MainWindow);
                }

                ir = new RawGenericInputReport(
                    null,
                    genericEvent
                    );

                dev = _inputManager._genericDevice;
            }
            else
            {
                /// Unkown event.
            }

            this.Dispatcher.BeginInvoke(_reportInputMethod, new InputReportArgs(dev, ir));

            return(true);
        }
        /// <summary>
        /// Determines whether a element is in the UIElementCollection.
        /// </summary>
        public bool Contains(UIElement 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>
        /// 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, UIElement element)
        {
            _owner.VerifyAccess();

            if (index < 0 || index > _size)
            {
                throw new ArgumentOutOfRangeException("index");
            }

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

            if (((element._parent != null) ||   // Only elements that are not connected to another tree
                (element.GetIsRootElement())))  // 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--)
            {
                UIElement 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();
        }
Example #28
0
        private void markTreeDirtyHelper(UIElement e)
        {
            //now walk down and mark all UIElements dirty
            if (e != null)
            {
                e._flags |= (UIElement.Flags.InvalidMeasure | UIElement.Flags.InvalidArrange);

                UIElementCollection uiec = e._logicalChildren;

                if (uiec != null)
                {
                    for (int i = uiec.Count; i-- > 0; )
                    {
                        markTreeDirtyHelper(uiec[i]);
                    }
                }
            }
        }
 internal Enumerator(UIElementCollection collection)
 {
     _collection = collection;
     _index = -1; // not started.
     _version = _collection._version;
     _currentElement = null;
 }
        /// <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(UIElement element)
        {
            _owner.VerifyAccess();

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

            if (((element._parent != null) ||   // Only visuals that are not connected to another tree
                (element.GetIsRootElement())))  // or a visual target can be added.
            {
                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;
        }
Example #31
0
 public static bool Capture(UIElement element)
 {
     return Capture(element, CaptureMode.Element);
 }