コード例 #1
0
        protected virtual bool OnChildrenWillBeRemoved(EventArgs args)
        {
            if (d_itemModel == null)
            {
                return(false);
            }

            var model_args       = (ModelEventArgs)args;
            var itemsToBeRemoved = new List <ModelIndexSelectionState>();

            foreach (var state in d_indexSelectionStates)
            {
                if (state.d_childId >= model_args.d_startId &&
                    state.d_childId <= model_args.d_startId + model_args.d_count)
                {
                    if (d_itemModel.AreIndicesEqual(d_lastSelectedIndex, state.d_selectedIndex))
                    {
                        d_lastSelectedIndex = new ModelIndex(0);
                    }

                    itemsToBeRemoved.Add(state);
                }
            }

            foreach (var state in itemsToBeRemoved)
            {
                d_indexSelectionStates.Remove(state);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Updates the rendering state for the specified \a item using the specified
        /// \a index as the data source.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="index"></param>
        /// <param name="maxWidth"></param>
        /// <param name="totalHeight"></param>
        private void UpdateItem(ListViewItemRenderingState item, ModelIndex index, ref float maxWidth, ref float totalHeight)
        {
            var text           = d_itemModel.GetData(index);
            var isSelected     = IsIndexSelected(index);
            var initialColours = isSelected ? _selectionTextColourRect : d_textColourRect;
            var renderedString = GetRenderedStringParser().Parse(text, GetFont(), initialColours);

            item.d_string = renderedString;
            item.d_index  = index;
            item.d_text   = text;
            item.d_icon   = d_itemModel.GetData(index, ItemDataRole.IDR_Icon);

            var iconSize = Sizef.Zero;

            if (!String.IsNullOrEmpty(item.d_icon))
            {
                iconSize = ImageManager.GetSingleton().Get(item.d_icon).GetRenderedSize();
            }

            var textSize = new Sizef(renderedString.GetHorizontalExtent(this), renderedString.GetVerticalExtent(this));

            item.d_size = new Sizef(iconSize.Width + textSize.Width, Math.Max(iconSize.Height, textSize.Height));

            maxWidth = Math.Max(item.d_size.Width, maxWidth);

            totalHeight += item.d_size.Height;

            item.d_isSelected = isSelected;//IsIndexSelected(index);
        }
コード例 #3
0
        public override int GetChildCount(ModelIndex modelIndex)
        {
            if (modelIndex.d_modelData == null)
            {
                return(d_root.GetChildren().Count);
            }

            return(((GenericItem)modelIndex.d_modelData).GetChildren().Count);
        }
コード例 #4
0
        public override ModelIndex MakeIndex(int child, ModelIndex parentIndex)
        {
            if (parentIndex.d_modelData == null)
            {
                return(new ModelIndex());
            }

            var item = (GenericItem)parentIndex.d_modelData;

            return(MakeValidIndex(child, item.GetChildren()));
        }
コード例 #5
0
        public override int CompareIndices(ModelIndex index1, ModelIndex index2)
        {
            if (!IsValidIndex(index1) || !IsValidIndex(index2) ||
                index1.d_modelData == index2.d_modelData)
            {
                return(0);
            }

            /// TODO: ...
            //if (GetItemForIndex(index1) < GetItemForIndex(index2))
            //    return -1;

            return(GetItemForIndex(index1) == GetItemForIndex(index2) ? 0 : 1);
        }
コード例 #6
0
        public override ModelIndex GetParentIndex(ModelIndex modelIndex)
        {
            if (modelIndex.d_modelData == d_root)
            {
                return(new ModelIndex());
            }

            var item = (GenericItem)modelIndex.d_modelData;

            if (item.GetParent() == null)
            {
                return(GetRootIndex());
            }

            return(new ModelIndex(item.GetParent()));
        }
コード例 #7
0
        private TreeViewItemRenderingState ComputeRenderingStateForIndex(ModelIndex parentIndex, int childId, int nestedLevel, ref float renderedMaxWidth, ref float renderedTotalHeight)
        {
            var index = d_itemModel.MakeIndex(childId, parentIndex);
            var state = new TreeViewItemRenderingState(this)
            {
                d_nestedLevel = nestedLevel,
                d_parentIndex = parentIndex,
                d_childId     = childId
            };

            FillRenderingState(state, index, ref renderedMaxWidth, ref renderedTotalHeight);

            ComputeRenderedChildrenForItem(state, index, ref renderedMaxWidth, ref renderedTotalHeight);

            return(state);
        }
コード例 #8
0
        /// <summary>
        /// Adds the item as child of the specified parent, at the specified position.
        ///
        /// After the addition, the \a parent's node will contain \a item as child
        /// at the \a position.
        /// </summary>
        /// <param name="newItem"></param>
        /// <param name="parentIndex"></param>
        /// <param name="position"></param>
        public virtual void AddItemAtPosition(GenericItem newItem, ModelIndex parentIndex, int position)
        {
            NotifyChildrenWillBeAdded(parentIndex, position, 1);

            var parent = (GenericItem)parentIndex.d_modelData;

            if (position > parent.GetChildren().Count)
            {
                throw new InvalidRequestException("The specified position is out of range.");
            }

            newItem.SetParent(parent);
            parent.GetChildren().Insert(position, newItem);

            NotifyChildrenAdded(parentIndex, position, 1);
        }
コード例 #9
0
        /// <summary>
        /// Ensures that the item specified by the \a index is visible by setting
        /// the proper the vertical and horizontal scrollbars' position.
        /// </summary>
        /// <param name="index"></param>
        public virtual void EnsureIndexIsVisible(ModelIndex index)
        {
            var vertScroll = GetVertScrollbar();
            var horzScroll = GetHorzScrollbar();
            var renderArea = GetViewRenderer().GetViewRenderArea();
            var viewHeight = renderArea.Height;
            var viewWidth  = renderArea.Width;

            var rect   = GetIndexRect(index);
            var bottom = rect.Bottom;
            var top    = rect.Top;

            // account for current scrollbar value
            var currPos = vertScroll.GetScrollPosition();

            top    -= currPos;
            bottom -= currPos;

            // if top is above the view area, or if item is too big to fit
            if ((top < 0.0f) || ((bottom - top) > viewHeight))
            {
                // scroll top of item to top of box.
                vertScroll.SetScrollPosition(currPos + top);
            }
            // if bottom is below the view area
            else if (bottom >= viewHeight)
            {
                // position bottom of item at the bottom of the list
                vertScroll.SetScrollPosition(currPos + bottom - viewHeight);
            }

            var left  = rect.Left - currPos;
            var right = left + rect.Width;

            // if left is left of the view area, or if item too big
            if ((left < renderArea.d_min.X) || ((right - left) > viewWidth))
            {
                // scroll item to left
                horzScroll.SetScrollPosition(currPos + left);
            }
            // if right is right of the view area
            else if (right >= renderArea.d_max.X)
            {
                // scroll item to right of list
                horzScroll.SetScrollPosition(currPos + right - viewWidth);
            }
        }
コード例 #10
0
        protected int GetSelectedIndexPosition(ModelIndex index)
        {
            if (d_itemModel == null)
            {
                return(0);
            }

            for (var i = 0; i < d_indexSelectionStates.Count; ++i)
            {
                if (d_itemModel.AreIndicesEqual(index, d_indexSelectionStates[i].d_selectedIndex))
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #11
0
        protected override Rectf GetIndexRect(ModelIndex index)
        {
            var childId = d_itemModel.GetChildId(index);

            if (childId == -1)
            {
                return(Rectf.Zero);
            }

            var pos = Lunatics.Mathematics.Vector2.Zero;

            for (var i = 0; i < childId; ++i)
            {
                pos.Y += d_items[i].d_size.Height;
            }

            return(new Rectf(pos, d_items[childId].d_size));
        }
コード例 #12
0
        private void ComputeRenderedChildrenForItem(TreeViewItemRenderingState item, ModelIndex index,
                                                    ref float renderedMaxWidth, ref float renderedTotalHeight)
        {
            var childCount = d_itemModel.GetChildCount(index);

            item.d_totalChildCount = childCount;

            if (!item.d_subtreeIsExpanded)
            {
                return;
            }

            for (var child = 0; child < childCount; ++child)
            {
                item.d_children.Add(ComputeRenderingStateForIndex(index, child, item.d_nestedLevel + 1, ref renderedMaxWidth, ref renderedTotalHeight));
            }

            item.SortChildren();
        }
コード例 #13
0
        private void FillRenderingState(TreeViewItemRenderingState item, ModelIndex index, ref float renderedMaxWidth, ref float renderedTotalHeight)
        {
            var text           = d_itemModel.GetData(index);
            var renderedString = GetRenderedStringParser().Parse(text, GetFont(), d_textColourRect);

            item.d_string = renderedString;
            item.d_text   = text;
            item.d_icon   = d_itemModel.GetData(index, ItemDataRole.IDR_Icon);

            item.d_size = new Sizef(renderedString.GetHorizontalExtent(this),
                                    renderedString.GetVerticalExtent(this));

            float indent = GetViewRenderer().GetSubtreeExpanderXIndent(item.d_nestedLevel) + GetViewRenderer().GetSubtreeExpanderSize().Width;

            renderedMaxWidth     = Math.Max(renderedMaxWidth, item.d_size.Width + indent);
            renderedTotalHeight += item.d_size.Height;

            item.d_isSelected = IsIndexSelected(index);
        }
コード例 #14
0
        protected void SetupTooltip(Lunatics.Mathematics.Vector2 position)
        {
            if (d_itemModel == null)
            {
                return;
            }

            var index = IndexAt(position);

            if (d_itemModel.AreIndicesEqual(index, _lastModelIndex))
            {
                return;
            }

            var tooltip = GetTooltip();

            if (tooltip == null)
            {
                return;
            }

            if (tooltip.GetTargetWindow() != this)
            {
                tooltip.SetTargetWindow(this);
            }
            else
            {
                tooltip.PositionSelf();
            }

            _lastModelIndex = index;

            if (!d_itemModel.IsValidIndex(index))
            {
                SetTooltipText("");
            }
            else
            {
                SetTooltipText(d_itemModel.GetData(index, ItemDataRole.IDR_Tooltip));
            }
        }
コード例 #15
0
        /// <summary>
        /// Sets the ItemModel to be used inside this view.
        /// </summary>
        /// <param name="itemModel"></param>
        public virtual void SetModel(ItemModel itemModel)
        {
            if (itemModel == d_itemModel)
            {
                return;
            }

            if (d_itemModel != null)
            {
                DisconnectModelEvents();
                d_lastSelectedIndex = new ModelIndex(0);
            }

            d_itemModel = itemModel;

            ConnectToModelEvents();
            d_indexSelectionStates.Clear();
            d_needsFullRender = true;

            OnSelectionChanged(new ItemViewEventArgs(this));
        }
コード例 #16
0
        public override string GetData(ModelIndex modelIndex, ItemDataRole role = ItemDataRole.IDR_Text)
        {
            if (!IsValidIndex(modelIndex))
            {
                return("");
            }

            var item = (GenericItem)modelIndex.d_modelData;

            if (role == ItemDataRole.IDR_Text)
            {
                return(item.GetText());
            }
            if (role == ItemDataRole.IDR_Icon)
            {
                return(item.GetIcon());
            }
            if (role == ItemDataRole.IDR_Tooltip)
            {
                return("Tooltip for " + item.GetText());
            }

            return("");
        }
コード例 #17
0
        public TreeViewItemRenderingState GetTreeViewItemForIndex(ModelIndex index)
        {
            var idsStack  = new Stack <int>();
            var rootIndex = d_itemModel.GetRootIndex();
            var tempIndex = index;

            // we create a stack of child ids which will allow us to drill back
            // in the right hierarchy.
            do
            {
                var id = d_itemModel.GetChildId(tempIndex);
                if (id == -1)
                {
                    break;
                }

                idsStack.Push(id);
                tempIndex = d_itemModel.GetParentIndex(tempIndex);
            } while (d_itemModel.IsValidIndex(tempIndex) && !d_itemModel.AreIndicesEqual(tempIndex, rootIndex));

            var item = d_rootItemState;

            while (idsStack.Count != 0)
            {
                var childId = idsStack.Pop();

                if (childId >= item.d_children.Count)
                {
                    return(null);
                }

                item = item.d_children[childId];
            }

            return(item);
        }
コード例 #18
0
 /// <summary>
 /// Gets the underlying TGenericItem represented by the given \a index or
 /// NULL if the index does not represent a valid item.
 ///
 /// This method is the inverse of to getIndexForItem(const GenericItem*).
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public virtual T GetItemForIndex(ModelIndex index)
 {
     return((T)index.d_modelData);
 }
コード例 #19
0
 /// <summary>
 /// Returns the Rectf that contains the specified \a index.
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 protected abstract Rectf GetIndexRect(ModelIndex index);
コード例 #20
0
 public override bool AreIndicesEqual(ModelIndex index1, ModelIndex index2)
 {
     return(CompareIndices(index1, index2) == 0);
 }
コード例 #21
0
 public override bool IsValidIndex(ModelIndex modelIndex)
 {
     return(modelIndex.d_modelData != null);
 }
コード例 #22
0
 public virtual bool SetIndexSelectionState(ModelIndex index, bool selected)
 {
     return(HandleSelection(index, selected, d_isMultiSelectEnabled, false));
 }
コード例 #23
0
 public virtual bool IsIndexSelected(ModelIndex index)
 {
     return(GetSelectedIndexPosition(index) != -1);
 }
コード例 #24
0
 public virtual void RemoveItem(ModelIndex index)
 {
     RemoveItem(GetItemForIndex(index));
 }
コード例 #25
0
 /// <summary>
 /// Sets the item specified by the \a index as the currently selected one.
 /// </summary>
 /// <param name="index"></param>
 /// <returns>
 /// True if the index has been successfully selected, false otherwise.
 /// </returns>
 public virtual bool SetSelectedIndex(ModelIndex index)
 {
     // simple calls of this method shouldn't do cumulative selection
     return(HandleSelection(index, true, false, false));
 }
コード例 #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="wnd"></param>
 /// <param name="index"></param>
 public ItemViewEventArgs(ItemView wnd, ModelIndex index)
     : base(wnd)
 {
     d_index = index;
 }
コード例 #27
0
 protected override bool HandleSelection(ModelIndex index, bool shouldSelect, bool isCumulative, bool isRange)
 {
     return(base.HandleSelection(index, shouldSelect, isCumulative, isRange));
 }
コード例 #28
0
        protected virtual bool HandleSelection(ModelIndex index, bool shouldSelect, bool isCumulative, bool isRange)
        {
            if (d_itemModel == null ||
                !d_itemModel.IsValidIndex(index))
            {
                return(false);
            }

            var indexPosition = GetSelectedIndexPosition(index);

            if (indexPosition != -1)
            {
                if (!shouldSelect)
                {
                    d_indexSelectionStates.RemoveAt(/*d_indexSelectionStates.begin() + */ indexPosition);

                    OnSelectionChanged(new ItemViewEventArgs(this, index));
                    return(true);
                }

                // if we select the node again, and we don't cumulate selection, we need
                // to make just that one be selected now
                if (isCumulative)
                {
                    return(true);
                }
            }

            if (!isCumulative)
            {
                d_indexSelectionStates.Clear();
            }

            var parentIndex  = d_itemModel.GetParentIndex(index);
            var endChildId   = d_itemModel.GetChildId(index);
            var startChildId = endChildId;

            if (isRange && isCumulative && d_lastSelectedIndex.d_modelData != null)
            {
                startChildId = d_itemModel.GetChildId(d_lastSelectedIndex);
            }

            for (var id = startChildId; id <= endChildId; ++id)
            {
                var selectionState = new ModelIndexSelectionState
                {
                    d_selectedIndex = d_itemModel.MakeIndex(id, parentIndex)
                };

                // ignore already selected indices
                if (GetSelectedIndexPosition(selectionState.d_selectedIndex) != -1)
                {
                    continue;
                }

                selectionState.d_childId     = id;
                selectionState.d_parentIndex = parentIndex;

                d_indexSelectionStates.Add(selectionState);
            }

            d_lastSelectedIndex = index;

            OnSelectionChanged(new ItemViewEventArgs(this, index));
            return(true);
        }
コード例 #29
0
 public override int GetChildId(ModelIndex modelIndex)
 {
     return(GetChildId(GetItemForIndex(modelIndex)));
 }
コード例 #30
0
 protected override Rectf GetIndexRect(ModelIndex index)
 {
     //TODO: implement for tree view. What do we do for indices in closed subtrees?
     throw new InvalidRequestException("Not implemented for tree view yet.");
 }