Пример #1
0
        /// <summary>
        /// Adds an item to the list.
        /// </summary>
        /// <param name="item">Index at which to add the item.</param>
        /// <param name="a">Item to add.</param>
        /// <returns>true if successful.</returns>
        public bool Add(string item, Availability a)
        {
            if (itemsArray.Count < maxNumberOfItems)
            {
                CustomListItem listItem;
                listItem = new CustomListItem(this, item, this.UniqueId, a);
                itemsArray.Add(listItem);

                // Initialize the selection if necessary.
                if (currentSelection < 0)
                {
                    currentSelection    = 0;
                    listItem.IsSelected = true;
                }
                this.Invalidate(); // update to draw new added item

                // Raise a UI Automation event.
                if (myListProvider != null)
                {
                    ListProvider.OnStructureChangeAdd(listItem.Container);
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Removes an item from the list.
        /// </summary>
        /// <param name="itemIndex">Index of the item.</param>
        /// <returns>true if successful.</returns>
        public bool Remove(int itemIndex)
        {
            if ((this.ItemCount == minNumberOfItems) || (itemIndex <= -1) || (itemIndex >= this.ItemCount))
            {
                // If the number of items in the list is already at minimum,
                // no additional items can be removed.
                return(false);
            }
            CustomListItem itemToBeRemoved = (CustomListItem)itemsArray[itemIndex];

            // Notify the provider that item it going to be destroyed.
            itemToBeRemoved.IsAlive = false;

            // Force refresh.
            this.Invalidate();

            // Raise notification.
            if (myListProvider != null)
            {
                ListProvider.OnStructureChangeRemove(itemToBeRemoved.Container);
            }
            itemsArray.RemoveAt(itemIndex);
            currentSelection = 0;  // Reset selection to first item.

            return(true);
        }
Пример #3
0
 /// <summary>
 /// Responds to a selection change by raising an event.
 /// </summary>
 /// <param name="listItem">The item that has been selected.</param>
 public static void OnSelectionChange(CustomListItem listItem)
 {
     if (AutomationInteropProvider.ClientsAreListening)
     {
         AutomationEventArgs args = new AutomationEventArgs(SelectionItemPatternIdentifiers.ElementSelectedEvent);
         AutomationInteropProvider.RaiseAutomationEvent(SelectionItemPatternIdentifiers.ElementSelectedEvent,
                                                        listItem.Provider, args);
     }
 }
Пример #4
0
 /// <summary>
 /// Responds to a focus change by raising an event.
 /// </summary>
 /// <param name="listItem">The item that has received focus.</param>
 public static void OnFocusChange(CustomListItem listItem)
 {
     if (AutomationInteropProvider.ClientsAreListening)
     {
         AutomationEventArgs args = new AutomationEventArgs(
             AutomationElementIdentifiers.AutomationFocusChangedEvent);
         AutomationInteropProvider.RaiseAutomationEvent(
             AutomationElementIdentifiers.AutomationFocusChangedEvent,
             listItem.Provider, args);
     }
 }
Пример #5
0
        /// <summary>
        /// Responds to Paint event.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // Use SystemBrushes for colors of a control.
            System.Drawing.Brush backgroundBrush = SystemBrushes.Window;
            System.Drawing.Brush focusedBrush;
            if (this.Focused)
            {
                focusedBrush = SystemBrushes.Highlight;
            }
            else
            {
                focusedBrush = new SolidBrush(Color.DarkGray);
            }
            e.Graphics.FillRectangle(backgroundBrush, DisplayRectangle);

            // Colors for online/offline image.
            System.Drawing.Brush itemOnBrush  = Brushes.Green;
            System.Drawing.Brush itemOffBrush = Brushes.Red;

            System.Drawing.Font itemTextFont = SystemFonts.DefaultFont;

            System.Drawing.Brush itemInk         = SystemBrushes.ControlText;
            System.Drawing.Brush selectedItemInk = SystemBrushes.HighlightText;

            // Loop through items to draw their text onto screen
            for (int i = 0; i < itemsArray.Count; i++)
            {
                System.Drawing.Point pt       = new System.Drawing.Point(DisplayRectangle.Left + 2, DisplayRectangle.Top + (i * itemHeight));
                CustomListItem       listItem = ((CustomListItem)itemsArray[i]);
                Rectangle            rc       = GetRectForItem(i);
                rc = new Rectangle(rc.X, rc.Y + 2, imageWidth, imageHeight);
                if (listItem.Status == Availability.Online)
                {
                    e.Graphics.FillRectangle(itemOnBrush, rc);
                }
                else
                {
                    e.Graphics.FillRectangle(itemOffBrush, rc);
                }
                rc = new Rectangle(rc.X + textIndent, rc.Y - 2, listWidth - textIndent, itemHeight);
                if (i == SelectedIndex)
                {
                    e.Graphics.FillRectangle(focusedBrush, rc);
                    e.Graphics.DrawString(listItem.Text, itemTextFont, selectedItemInk, rc);
                }
                else
                {
                    // Item not selected.
                    e.Graphics.DrawString(listItem.Text, itemTextFont, itemInk, rc);
                }
            }
            e.Dispose();
        }
Пример #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="rootProvider">UI Automation provider for the
 /// fragment root (the containing list).</param>
 /// <param name="thisItem">The control that owns this provider.</param>
 public ListItemProvider(ListProvider rootProvider, CustomListItem thisItem)
 {
     ContainingListProvider = rootProvider;
     ListItemControl        = thisItem;
 }
Пример #7
0
 /// <summary>
 /// Gets the index of the specified item.
 /// </summary>
 /// <param name="listItem">The item.</param>
 /// <returns>The zero-based index.</returns>
 public int ItemIndex(CustomListItem listItem)
 {
     // Allows CustomListItem to requery its index, as it can change.
     return(itemsArray.IndexOf(listItem));
 }
Пример #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="rootProvider">
 /// UI Automation provider for the fragment root (the containing list).
 /// </param>
 /// <param name="thisItem">The control that owns this provider.</param>
 public ListItemProvider(ListProvider rootProvider, CustomListItem thisItem)
 {
     containerListProvider = rootProvider;
     listItemControl       = thisItem;
     selectedItems         = new ArrayList();
 }