Ejemplo n.º 1
0
        /// <summary>
        /// Toggles the expanded/collapsed state of the specified tree item.
        /// This will raise the EventSubtreeExpanded or EventSubtreeCollapsed
        /// events based on the current item's state.
        /// </summary>
        /// <param name="item"></param>
        public void ToggleSubtree(TreeViewItemRenderingState item)
        {
            if (d_itemModel == null)
            {
                return;
            }

            item.d_subtreeIsExpanded = !item.d_subtreeIsExpanded;

            var args = new ItemViewEventArgs(this, d_itemModel.MakeIndex(item.d_childId, item.d_parentIndex));

            if (item.d_subtreeIsExpanded)
            {
                ComputeRenderedChildrenForItem(item, d_itemModel.MakeIndex(item.d_childId, item.d_parentIndex), ref d_renderedMaxWidth, ref d_renderedTotalHeight);
                OnSubtreeExpanded(args);
            }
            else
            {
                ClearItemRenderedChildren(item, ref d_renderedTotalHeight);
                OnSubtreeCollapsed(args);
            }

            UpdateScrollbars();
            // we need just a simple invalidation. No need to redo the render state
            // as we modified it ourself directly.
            Invalidate(false);
        }
Ejemplo n.º 2
0
        public override void PrepareForRender()
        {
            base.PrepareForRender();
            //TODO: better way of ignoring the null item model? E.g.: warn? Throw an exception?
            if (d_itemModel == null || !IsDirty())
            {
                return;
            }

            if (d_needsFullRender)
            {
                var rootIndex = d_itemModel.GetRootIndex();
                d_renderedMaxWidth    = 0;
                d_renderedTotalHeight = 0;

                d_rootItemState = new TreeViewItemRenderingState(this)
                {
                    // root item isn't a proper item so it does not have a nested level.
                    d_nestedLevel       = -1,
                    d_subtreeIsExpanded = true
                };


                ComputeRenderedChildrenForItem(d_rootItemState, rootIndex, ref d_renderedMaxWidth, ref d_renderedTotalHeight);
            }
            else
            {
                UpdateRenderingStateForItem(d_rootItemState, ref d_renderedMaxWidth, ref d_renderedTotalHeight);
            }

            UpdateScrollbars();
            SetIsDirty(false);
            d_needsFullRender = false;
        }
Ejemplo n.º 3
0
        public TreeView(string type, string name)
            : base(type, name)
        {
            d_rootItemState         = new TreeViewItemRenderingState(this);
            d_subtreeExpanderMargin = DefaultSubtreeExpanderMargin;

            AddTreeViewProperties();
        }
Ejemplo n.º 4
0
        private void HandleSelectionAction(TreeViewItemRenderingState item, bool togglesExpander)
        {
            if (!togglesExpander)
            {
                return;
            }

            ToggleSubtree(item);
        }
Ejemplo n.º 5
0
        private void ClearItemRenderedChildren(TreeViewItemRenderingState item, ref float renderedTotalHeight)
        {
            foreach (var itor in item.d_children)
            {
                ClearItemRenderedChildren(itor, ref renderedTotalHeight);

                // ??? d_renderedTotalHeight -= item.d_size.d_height;
                renderedTotalHeight -= item.d_size.Height;
            }

            item.d_children.Clear();
            item.SortChildren();
        }
Ejemplo n.º 6
0
        private void UpdateRenderingStateForItem(TreeViewItemRenderingState item, ref float renderedMaxWidth, ref float renderedTotalHeight)
        {
            // subtract the previous height
            renderedTotalHeight -= item.d_size.Height;

            FillRenderingState(item, d_itemModel.MakeIndex(item.d_childId, item.d_parentIndex), ref renderedMaxWidth, ref renderedTotalHeight);

            foreach (var itor in item.d_children)
            {
                itor.d_nestedLevel = item.d_nestedLevel + 1;
                UpdateRenderingStateForItem(itor, ref renderedMaxWidth, ref renderedTotalHeight);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
        public void ExpandSubtreeRecursive(TreeViewItemRenderingState item)
        {
            if (!item.d_subtreeIsExpanded)
            {
                ToggleSubtree(item);
            }

            if (item.d_totalChildCount == 0)
            {
                return;
            }

            foreach (var itor in item.d_children)
            {
                ExpandSubtreeRecursive(itor);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
        private ModelIndex IndexAtRecursive(TreeViewItemRenderingState item, ref float curHeight,
                                            Lunatics.Mathematics.Vector2 windowPosition, ref bool handled,
                                            Action <TreeViewItemRenderingState, bool> action)
        {
            var nextHeight = curHeight + item.d_size.Height;

            if (windowPosition.Y >= curHeight &&
                windowPosition.Y <= nextHeight)
            {
                handled = true;

                var expanderWidth = GetViewRenderer().GetSubtreeExpanderSize().Width;
                var baseX         = GetViewRenderer().GetSubtreeExpanderXIndent(item.d_nestedLevel);
                baseX -= GetHorzScrollbar().GetScrollPosition();
                if (windowPosition.X >= baseX &&
                    windowPosition.X <= baseX + expanderWidth)
                {
                    action(item, true);
                    return(new ModelIndex());
                }

                action(item, false);
                return(new ModelIndex(d_itemModel.MakeIndex(item.d_childId, item.d_parentIndex)));
            }

            curHeight = nextHeight;

            for (var i = 0; i < item.d_renderedChildren.Count; ++i)
            {
                var index = IndexAtRecursive(item.d_renderedChildren[i], ref curHeight, windowPosition, ref handled, action);
                if (handled)
                {
                    return(index);
                }
            }

            return(new ModelIndex());
        }
Ejemplo n.º 12
0
 private void NoopAction(TreeViewItemRenderingState item, bool togglesExpander)
 {
 }