Exemplo n.º 1
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            var newValue = value;

            if (!(e.Alt || e.Control || e.Shift))
            {
                if (e.KeyCode == Keys.Up)
                {
                    if (!TriColorValueHelper.IsFirst(newValue))
                    {
                        newValue  = TriColorValueHelper.PreviousValue(newValue);
                        e.Handled = true;
                    }
                }
                else if (e.KeyCode == Keys.Down)
                {
                    if (!TriColorValueHelper.IsLast(newValue))
                    {
                        newValue  = TriColorValueHelper.NextValue(newValue);
                        e.Handled = true;
                    }
                }
            }
            Value = newValue;
        }
        public static TriColorValue NextValue(TriColorValue value)
        {
            if (IsLast(value))
            {
                throw new ArgumentOutOfRangeException();
            }

            value++;
            return(value);
        }
        public static TriColorValue PreviousValue(TriColorValue value)
        {
            if (IsFirst(value))
            {
                throw new ArgumentOutOfRangeException();
            }

            value--;
            return value;
        }
        public static TriColorValue PreviousValue(TriColorValue value)
        {
            if (IsFirst(value))
            {
                throw new ArgumentOutOfRangeException();
            }

            value--;
            return(value);
        }
        public static TriColorValue NextValue(TriColorValue value)
        {
            if (IsLast(value))
            {
                throw new ArgumentOutOfRangeException();
            }

            value++;
            return value;
        }
Exemplo n.º 6
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            TriColorValue newValue;;

            if (ValueFromPoint(e.Location, out newValue))
            {
                Value = newValue;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find the rectangle (in client coordinates) for a given value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Rectangle RectFromValue(TriColorValue value)
        {
            switch (value)
            {
            case TriColorValue.Red: return(RedRect);

            case TriColorValue.Yellow: return(YellowRect);

            case TriColorValue.Green: return(GreenRect);
            }
            return(Rectangle.Empty);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Find the rectangle corresponding to a given value
        /// </summary>
        private Rectangle RectForValue(TriColorValue value)
        {
            Rectangle rect;

            switch (value)
            {
            case TriColorValue.Red: rect = RedRect; break;

            case TriColorValue.Yellow: rect = YellowRect; break;

            case TriColorValue.Green: rect = GreenRect; break;

            default: rect = new Rectangle(); break;
            }
            return(rect);
        }
Exemplo n.º 9
0
        // Raise appropriate events for the value changing
        public void RaiseEventsForNewValue(TriColorValue oldValue, TriColorValue newValue)
        {
            // Since we support Value pattern, raise a PropertyChanged(Value) event
            // Values are represented as strings.
            NativeMethods.UiaRaiseAutomationPropertyChangedEvent(this,
                                                                 UIA_PropertyIds.UIA_ValueValuePropertyId,
                                                                 oldValue.ToString(),
                                                                 newValue.ToString());

            // Since we support Selection pattern, raise a SelectionChanged event.
            // Since a top-level AutomationEvent exists for this event, we raise it,
            // rather than raising PropertyChanged(Selection)
            NativeMethods.UiaRaiseAutomationEvent(
                this,
                UIA_EventIds.UIA_SelectionItem_ElementSelectedEventId);
        }
        public TriColorFragmentProvider(TriColorControl control, IRawElementProviderFragmentRoot root, TriColorValue value)
            : base((IRawElementProviderFragment)root /* parent */, root /* fragmentRoot */)
        {
            _control = control;
            _value   = value;

            // Populate static properties
            //
            // In a production app, Name should be localized
            AddStaticProperty(UIA_PropertyIds.UIA_NamePropertyId, _value.ToString());
            AddStaticProperty(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_CustomControlTypeId);
            // In a production app, LocalizedControlType should be localized
            AddStaticProperty(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "tri-color item");
            AddStaticProperty(UIA_PropertyIds.UIA_ProviderDescriptionPropertyId, "UIASamples: Tri-Color Fragment Provider");
            AddStaticProperty(UIA_PropertyIds.UIA_AutomationIdPropertyId, _value.ToString());
            AddStaticProperty(UIA_PropertyIds.UIA_IsKeyboardFocusablePropertyId, false);
            AddStaticProperty(UIA_PropertyIds.UIA_IsControlElementPropertyId, true);
            AddStaticProperty(UIA_PropertyIds.UIA_IsContentElementPropertyId, false);
        }
        public TriColorFragmentProvider(TriColorControl control, IRawElementProviderFragmentRoot root, TriColorValue value)
            : base((IRawElementProviderFragment) root /* parent */, root /* fragmentRoot */)
        {
            _control = control;
            _value = value;

            // Populate static properties
            //
            // In a production app, Name should be localized
            AddStaticProperty(UIA_PropertyIds.UIA_NamePropertyId, _value.ToString());
            AddStaticProperty(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_CustomControlTypeId);
            // In a production app, LocalizedControlType should be localized
            AddStaticProperty(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "tri-color item");
            AddStaticProperty(UIA_PropertyIds.UIA_ProviderDescriptionPropertyId, "UIASamples: Tri-Color Fragment Provider");
            AddStaticProperty(UIA_PropertyIds.UIA_AutomationIdPropertyId, _value.ToString());
            AddStaticProperty(UIA_PropertyIds.UIA_IsKeyboardFocusablePropertyId, false);
            AddStaticProperty(UIA_PropertyIds.UIA_IsControlElementPropertyId, true);
            AddStaticProperty(UIA_PropertyIds.UIA_IsContentElementPropertyId, false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Find the value for a given point on the control
        /// </summary>
        /// <param name="ptClient">Point in client coordinates</param>
        /// <param name="value">Value for point</param>
        /// <returns>true if value was found</returns>
        public bool ValueFromPoint(Point ptClient, out TriColorValue value)
        {
            value = TriColorValue.Red;
            var found = false;

            if (RedRect.Contains(ptClient))
            {
                value = TriColorValue.Red;
                found = true;
            }
            else if (YellowRect.Contains(ptClient))
            {
                value = TriColorValue.Yellow;
                found = true;
            }
            else if (GreenRect.Contains(ptClient))
            {
                value = TriColorValue.Green;
                found = true;
            }
            return(found);
        }
 public static bool IsLast(TriColorValue value)
 {
     return (value == TriColorValue.Green);
 }
 public static bool IsFirst(TriColorValue value)
 {
     return(value == TriColorValue.Red);
 }
 /// <summary>
 /// Find the rectangle (in client coordinates) for a given value
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public Rectangle RectFromValue(TriColorValue value)
 {
     switch (value)
     {
         case TriColorValue.Red: return RedRect;
         case TriColorValue.Yellow: return YellowRect;
         case TriColorValue.Green: return GreenRect;
     }
     return Rectangle.Empty;
 }
 /// <summary>
 /// Find the value for a given point on the control
 /// </summary>
 /// <param name="ptClient">Point in client coordinates</param>
 /// <param name="value">Value for point</param>
 /// <returns>true if value was found</returns>
 public bool ValueFromPoint(Point ptClient, out TriColorValue value)
 {
     value = TriColorValue.Red;
     var found = false;
     if (RedRect.Contains(ptClient))
     {
         value = TriColorValue.Red;
         found = true;
     }
     else if (YellowRect.Contains(ptClient))
     {
         value = TriColorValue.Yellow;
         found = true;
     }
     else if (GreenRect.Contains(ptClient))
     {
         value = TriColorValue.Green;
         found = true;
     }
     return found;
 }
 public static bool IsFirst(TriColorValue value)
 {
     return (value == TriColorValue.Red);
 }
 /// <summary>
 /// Find the rectangle corresponding to a given value
 /// </summary>
 private Rectangle RectForValue(TriColorValue value)
 {
     Rectangle rect;
     switch (value)
     {
         case TriColorValue.Red: rect = RedRect; break;
         case TriColorValue.Yellow: rect = YellowRect; break;
         case TriColorValue.Green: rect = GreenRect; break;
         default: rect = new Rectangle(); break;
     }
     return rect;
 }
        // Raise appropriate events for the value changing
        public void RaiseEventsForNewValue(TriColorValue oldValue, TriColorValue newValue)
        {
            // Since we support Value pattern, raise a PropertyChanged(Value) event
            // Values are represented as strings.
            NativeMethods.UiaRaiseAutomationPropertyChangedEvent(this,
                                                                 UIA_PropertyIds.UIA_ValueValuePropertyId,
                                                                 oldValue.ToString(),
                                                                 newValue.ToString());

            // Since we support Selection pattern, raise a SelectionChanged event.
            // Since a top-level AutomationEvent exists for this event, we raise it,
            // rather than raising PropertyChanged(Selection)
            NativeMethods.UiaRaiseAutomationEvent(
                this,
                UIA_EventIds.UIA_SelectionItem_ElementSelectedEventId);
        }
 public static bool IsLast(TriColorValue value)
 {
     return(value == TriColorValue.Green);
 }