Пример #1
0
        /// <summary>
        /// Notify this ItemListbox that the given ListItem was just clicked.
        /// Internal function - not to be used from client code.
        /// </summary>
        /// <param name="li"></param>
        /// <param name="cumulativeSelection"></param>
        /// <param name="rangeSelection"></param>
        public override void NotifyItemActivated(ItemEntry li, bool cumulativeSelection, bool rangeSelection)
        {
            var selState = !(li.IsSelected() && _multiSelect);
            var skip     = false;

            // multiselect enabled
            if (_multiSelect)
            {
                var last = _lastSelected;

                // no Control? clear others
                if (cumulativeSelection)
                {
                    ClearAllSelections();
                    if (!selState)
                    {
                        selState = true;
                    }
                }

                // select range if Shift if held, and we have a 'last selection'
                if (last != null && rangeSelection)
                {
                    SelectRange(GetItemIndex(last), GetItemIndex(li));
                    skip = true;
                }
            }
            else
            {
                ClearAllSelections();
            }

            if (!skip)
            {
                li.SetSelectedImpl(selState, false);
                if (selState)
                {
                    _lastSelected = li;
                }
                else if (_lastSelected == li)
                {
                    _lastSelected = null;
                }
            }

            OnSelectionChanged(new WindowEventArgs(this));
        }
Пример #2
0
        /// <summary>
        /// Search the list for an item with the specified text
        /// </summary>
        /// <param name="text">
        /// String object containing the text to be searched for.
        /// </param>
        /// <param name="startItem">
        /// ItemEntry where the search is to begin, the search will not include \a item.  If \a item is
        /// NULL, the search will begin from the first item in the list.
        /// </param>
        /// <returns>
        /// Pointer to the first ItemEntry in the list after \a item that has text matching \a text.  If
        /// no item matches the criteria NULL is returned.
        /// </returns>
        /// <exception cref="InvalidRequestException">
        /// thrown if \a item is not attached to this list box.
        /// </exception>
        public ItemEntry FindItemWithText(string text, ItemEntry startItem)
        {
            // if start_item is NULL begin search at begining, else start at item after start_item
            var index = (startItem == null) ? 0 : (GetItemIndex(startItem) + 1);

            while (index < ListItems.Count)
            {
                // return pointer to this item if it's text matches
                if (ListItems[index].GetText() == text)
                {
                    return(ListItems[index]);
                }

                // no matching text, advance to next item
                index++;
            }

            // no items matched.
            return(null);
        }
        /// <summary>
        /// Scroll the horizontal list position if needed to ensure that the
        /// ItemEntry \a item is, if possible, fully visible witin the
        /// ScrolledItemListBase viewable area.
        /// </summary>
        /// <param name="item">
        /// const reference to an ItemEntry attached to this ScrolledItemListBase
        /// that should be made visible in the view area.
        /// </param>
        public void EnsureItemIsVisibleHorz(ItemEntry item)
        {
            var renderArea = GetItemRenderArea();
            var h          = GetHorzScrollbar();
            var currPos    = h.GetScrollPosition();

            var left  = CoordConverter.AsAbsolute(item.GetXPosition(), GetPixelSize().Width) - currPos;
            var right = left + item.GetItemPixelSize().Width;

            // if left is left of the view area, or if item too big, scroll item to left
            if ((left < renderArea.d_min.X) || ((right - left) > renderArea.Width))
            {
                h.SetScrollPosition(currPos + left);
            }
            // if right is right of the view area, scroll item to right of list
            else if (right >= renderArea.d_max.X)
            {
                h.SetScrollPosition(currPos + right - renderArea.Width);
            }
        }
        /// <summary>
        /// Scroll the vertical list position if needed to ensure that the ItemEntry
        /// \a item is, if possible,  fully visible witin the ScrolledItemListBase
        /// viewable area.
        /// </summary>
        /// <param name="item">
        /// const reference to an ItemEntry attached to this ScrolledItemListBase
        /// that should be made visible in the view area.
        /// </param>
        public void EnsureItemIsVisibleVert(ItemEntry item)
        {
            var renderArea = GetItemRenderArea();
            var v          = GetVertScrollbar();
            var currPos    = v.GetScrollPosition();

            var top    = CoordConverter.AsAbsolute(item.GetYPosition(), GetPixelSize().Height) - currPos;
            var bottom = top + item.GetItemPixelSize().Height;

            // if top is above the view area, or if item is too big, scroll item to top
            if ((top < renderArea.d_min.Y) || ((bottom - top) > renderArea.Height))
            {
                v.SetScrollPosition(currPos + top);
            }
            // if bottom is below the view area, scroll item to bottom of list
            else if (bottom >= renderArea.d_max.Y)
            {
                v.SetScrollPosition(currPos + bottom - renderArea.Height);
            }
        }
Пример #5
0
        /// <summary>
        /// Notify this ItemListbox that the given ListItem just changed selection state.
        /// Internal function - not to be used from client code.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="state"></param>
        public override void NotifyItemSelectState(ItemEntry item, bool state)
        {
            // deselect
            if (!state)
            {
                // clear last selection if this one was it
                if (_lastSelected == item)
                {
                    _lastSelected = null;
                }
            }
            // if we dont support multiselect, we must clear all the other selections
            else if (!_multiSelect)
            {
                ClearAllSelections();
                item.SetSelectedImpl(true, false);
                _lastSelected = item;
            }

            OnSelectionChanged(new WindowEventArgs(this));
        }
Пример #6
0
        /// <summary>
        /// Insert an item into the list before a specified item already in the list.
        /// <para>
        /// Note that if the list is sorted, the item may not end up in the
        /// requested position.
        /// </para>
        /// </summary>
        /// <param name="item">
        /// Pointer to the ItemEntry to be inserted.  Note that it is the passed
        /// object that is added to the list, a copy is not made.  If this parameter
        /// is NULL, nothing happens.
        /// </param>
        /// <param name="position">
        /// Pointer to a ItemEntry that \a item is to be inserted before.  If this
        /// parameter is NULL, the item is inserted at the start of the list.
        /// </param>
        public void InsertItem(ItemEntry item, ItemEntry position)
        {
            if (_sortEnabled)
            {
                AddItem(item);
            }
            else if (item != null && item.OwnerList != this)
            {
                var insPos = position != null?ListItems.IndexOf(position) : 0;

                if (insPos == -1)
                {
                    throw new InvalidRequestException("the specified ItemEntry for parameter 'position' is not attached to this ItemListBase.");
                }

                ListItems.Insert(insPos, item);
                item.OwnerList = this;
                AddChild(item);

                HandleUpdatedItemData();
            }
        }
Пример #7
0
        /// <summary>
        /// Returns a pointer to the next selected item after the item 'start_item' given.
        /// </summary>
        /// <param name="startItem"></param>
        /// <returns></returns>
        /// <remarks>
        /// This member function will search the array from the beginning and will be slow
        /// for large lists, it will not advance the internal counter used by
        /// GetFirstSelectedItem and GetNextSelectedItem either.
        /// </remarks>
        public ItemEntry GetNextSelectedItemAfter(ItemEntry startItem)
        {
            if (startItem == null || !_multiSelect)
            {
                return(null);
            }

            var max = ListItems.Count;
            var i   = GetItemIndex(startItem);

            while (i < max)
            {
                var li = ListItems[i];
                if (li.IsSelected())
                {
                    return(li);
                }
                ++i;
            }

            return(null);
        }
Пример #8
0
        /// <summary>
        /// Add the given ItemEntry to the list.
        /// </summary>
        /// <param name="item">
        /// Pointer to the ItemEntry to be added to the list.  Note that it is the passed object that is added to the
        /// list, a copy is not made.  If this parameter is NULL, nothing happens.
        /// </param>
        public void AddItem(ItemEntry item)
        {
            // make sure the item is valid and that we dont already have it in our list
            if (item != null && item.OwnerList != this)
            {
                // if sorting is enabled, re-sort the list
                if (_sortEnabled)
                {
                    ListItems.Add(item);
                    // TODO: d_listItems.insert(std::upper_bound(d_listItems.begin(), d_listItems.end(), item, getRealSortCallback()), item);
                }
                // just stick it on the end.
                else
                {
                    ListItems.Add(item);
                }

                // make sure it gets added properly
                item.OwnerList = this;
                AddChild(item);
                HandleUpdatedItemData();
            }
        }
Пример #9
0
 /// <summary>
 /// Notify this ItemListBase that the given item just changed selection state.
 /// Internal function - NOT to be used from client code.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="state"></param>
 public virtual void NotifyItemSelectState(ItemEntry item, bool state)
 {
 }
Пример #10
0
 /// <summary>
 ///  Notify this ItemListBase that the given item was just activated.
 /// Internal function - NOT to be used from client code.
 /// </summary>
 /// <param name="item">
 /// </param>
 /// <param name="cumulativeSelection">
 /// True if this entry should cumulate to the previous selection
 /// </param>
 /// <param name="rangeSelection">
 /// True if this entry should do a range selection
 /// </param>
 public virtual void NotifyItemActivated(ItemEntry item, bool cumulativeSelection, bool rangeSelection)
 {
 }
Пример #11
0
 /// <summary>
 /// Return whether the specified ItemEntry is in the List
 /// </summary>
 /// <param name="item"></param>
 /// <returns>
 /// true if ItemEntry \a item is in the list, false if ItemEntry \a item is not in the list.
 /// </returns>
 public bool IsItemInList(ItemEntry item)
 {
     return(item.OwnerList == this);
 }