예제 #1
0
        private int UpdateItemsRecursive(TreeTableNode root, int nextIndex, int depth)
        {
            foreach (TreeTableNode child in root.Items)
            {
                if (!child.Visible)
                {
                    child.InternalSetVirtualIndex(-1);
                    HideItemsRecursive(child);
                }
                else
                {
                    child.Depth = depth;
                    child.InternalSetVirtualIndex(nextIndex++);
                    m_nodes.Add(child);
                    if (child.Expandable && child.Expanded)
                    {
                        nextIndex = UpdateItemsRecursive(child, nextIndex, depth + 1);
                    }
                    else
                    {
                        HideItemsRecursive(child);
                    }
                }
            }

            return(nextIndex);
        }
예제 #2
0
 private void OnNodeClosed(TreeTableNode node)
 {
     if (!m_updateInProgress && NodeClosed != null)
     {
         NodeClosed(node);
     }
 }
예제 #3
0
 private void HideItemsRecursive(TreeTableNode root)
 {
     foreach (TreeTableNode child in root.Items)
     {
         child.InternalSetVirtualIndex(-1);
         HideItemsRecursive(child);
     }
 }
예제 #4
0
 internal void InternalSetParent(TreeTableNode parent)
 {
     m_parent = parent;
     if (parent == null)
     {
         m_owner = null;
     }
     else
     {
         m_owner = parent.Owner;
     }
 }
예제 #5
0
        internal void NodeChangedExpanded(TreeTableNode item)
        {
            if (item.Expanded)
            {
                OnNodeOpened(item);
            }
            else
            {
                OnNodeClosed(item);
            }

            UpdateItems();
        }
예제 #6
0
        internal void RemoveFromHashRecursive(TreeTableNode root)
        {
            if (root.Key != "")
            {
                System.Diagnostics.Debug.Assert(m_keyhash.ContainsKey(root.Key));
                m_keyhash.Remove(root.Key);
            }

            foreach (TreeTableNode node in root.Items)
            {
                RemoveFromHashRecursive(node);
            }
        }
예제 #7
0
        public TreeTable()
        {
            InitializeComponent();

            m_root = new TreeTableNode();
            m_root.InternalSetOwner(this);

            m_nodes   = new List <TreeTableNode>();
            m_keyhash = new Dictionary <string, TreeTableNode>();

            listView1.BeforeLabelEdit += new LabelEditEventHandler(listView1_BeforeLabelEdit);
            listView1.AfterLabelEdit  += new LabelEditEventHandler(listView1_AfterLabelEdit);
        }
예제 #8
0
        internal void AddToHashRecursive(TreeTableNode root)
        {
            if (root.Key != "")
            {
                System.Diagnostics.Debug.Assert(!m_keyhash.ContainsKey(root.Key));
                m_keyhash.Add(root.Key, root);
            }

            foreach (TreeTableNode node in root.Items)
            {
                AddToHashRecursive(node);
            }
        }
예제 #9
0
        // Walk the tree and assign indexes to every item
        public void UpdateItems()
        {
            if (m_updateInProgress)
            {
                m_updateDirty = true;
            }
            else
            {
                TreeTableNode selItem = listView1.FocusedItem == null ? null : m_nodes[listView1.FocusedItem.Index];                 //listView1.SelectedIndices.Count == 0 ? null : m_nodes[listView1.SelectedIndices[0]];
                TreeTableNode topItem = listView1.TopItem == null ? null : m_nodes[listView1.TopItem.Index];

                listView1.BeginUpdate();
                listView1.SelectedIndices.Clear();
                m_nodes.Clear();

                UpdateItemsRecursive(m_root, 0, 0);
                listView1.VirtualListSize = m_nodes.Count;

                if (selItem != null)
                {
                    while (selItem.VirtualIndex < 0 && selItem != m_root)
                    {
                        selItem = selItem.Parent;
                    }

                    if (selItem != m_root && m_nodes.Contains(selItem))
                    {
                        ListViewItem item = listView1.Items[selItem.VirtualIndex];
                        item.Focused  = true;
                        item.Selected = true;
                        listView1.EnsureVisible(item.Index);
                    }
                }

                if (topItem != null)
                {
                    while (topItem.VirtualIndex < 0 && topItem != m_root)
                    {
                        topItem = topItem.Parent;
                    }

                    if (topItem != m_root && m_nodes.Contains(topItem))
                    {
                        ListViewItem item = listView1.Items[topItem.VirtualIndex];
                        listView1.TopItem = item;
                    }
                }

                listView1.EndUpdate();
            }
        }
예제 #10
0
        private void TreeTable_Click(object sender, EventArgs e)
        {
            Point hitPos             = listView1.PointToClient(Control.MousePosition);
            ListViewHitTestInfo info = listView1.HitTest(hitPos.X, hitPos.Y);

            if (info.Item != null && info.Location == ListViewHitTestLocations.Image)
            {
                TreeTableNode node = (TreeTableNode)info.Item.Tag;
                if (node.Expandable)
                {
                    node.Expanded = !node.Expanded;
                }
            }
        }
예제 #11
0
        internal void NodeChangedKey(TreeTableNode item, string oldKey)
        {
            if (oldKey != "")
            {
                System.Diagnostics.Debug.Assert(m_keyhash.ContainsKey(oldKey));
                m_keyhash.Remove(oldKey);
            }

            if (item.Key != "")
            {
                System.Diagnostics.Debug.Assert(!m_keyhash.ContainsKey(oldKey));
                m_keyhash.Add(item.Key, item);
            }
        }
예제 #12
0
        private void TreeTable_KeyDown(object sender, KeyEventArgs e)
        {
            TreeTableNode selNode;

            if (listView1.VirtualListSize == 0)
            {
                selNode = null;
            }
            else if (listView1.SelectedIndices.Count > 0)
            {
                selNode = m_nodes[listView1.SelectedIndices[0]];
            }
            else
            {
                selNode = m_nodes[0];
            }

            if (selNode != null)
            {
                if (e.KeyCode == Keys.Left)
                {
                    if (selNode.Expanded)
                    {
                        selNode.Expanded = false;
                    }
                    else
                    {
                        TreeTableNode newSelNode = selNode.Parent;
                        if (newSelNode != null && newSelNode != m_root)
                        {
                            listView1.SelectedIndices.Clear();
                            newSelNode.ListItem.Selected = true;
                            newSelNode.ListItem.Focused  = true;
                            listView1.EnsureVisible(newSelNode.VirtualIndex);
                        }
                    }
                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.Right)
                {
                    if (selNode.Expandable && !selNode.Expanded)
                    {
                        selNode.Expanded = true;
                    }

                    e.Handled = true;
                }
            }
        }
예제 #13
0
 internal void InvalidateNode(TreeTableNode node)
 {
     if (node.VirtualIndex >= 0)
     {
         if (m_updateInProgress)
         {
             m_updateDirty = true;
         }
         else
         {
             Rectangle bounds = listView1.GetItemRect(node.VirtualIndex, ItemBoundsPortion.Entire);
             listView1.Invalidate(bounds);
         }
     }
 }
예제 #14
0
        private void TreeTable_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            //e.Item = m_nodes[e.ItemIndex].Item;

            TreeTableNode node = m_nodes[e.ItemIndex];
            ListViewItem  item = new ListViewItem();

            for (int index = 0; index < node.SubItems.Count; ++index)
            {
                TreeTableSubItem             subnode = node.SubItems[index];
                ListViewItem.ListViewSubItem subitem = index == 0 ? item.SubItems[0] : new ListViewItem.ListViewSubItem();

                subitem.Text = subnode.Text;
                if (subnode.ForeColor != null)
                {
                    subitem.ForeColor = subnode.ForeColor;
                }
                if (subnode.Font != null)
                {
                    subitem.Font = subnode.Font;
                }

                if (index > 0)
                {
                    item.SubItems.Add(subitem);
                }
            }

            if (!node.Expandable)
            {
                item.ImageIndex = -1;
            }
            else if (node.Expanded)
            {
                item.ImageIndex = 1;
            }
            else
            {
                item.ImageIndex = 0;
            }

            item.Tag         = node;
            item.IndentCount = node.Depth;

            node.ListItem = item;

            e.Item = item;
        }
예제 #15
0
 internal void NodeChangedExpandable(TreeTableNode node)
 {
     InvalidateNode(node);
 }
예제 #16
0
 internal void NodeReplaced(TreeTableNode oldItem, TreeTableNode newItem)
 {
     RemoveFromHashRecursive(oldItem);
     AddToHashRecursive(newItem);
     UpdateItems();
 }
예제 #17
0
 internal void NodeRemoved(TreeTableNode item)
 {
     RemoveFromHashRecursive(item);
     UpdateItems();
 }
예제 #18
0
 internal void NodeAdded(TreeTableNode item)
 {
     AddToHashRecursive(item);
     UpdateItems();
 }
예제 #19
0
 internal void NodeChangedSubItem(TreeTableNode node)
 {
     InvalidateNode(node);
 }
예제 #20
0
 internal void NodeChangedVisible(TreeTableNode item)
 {
     UpdateItems();
 }
예제 #21
0
 public TreeTableSubItemCollection(TreeTableNode owner)
 {
     m_owner = owner;
     m_list  = new List <TreeTableSubItem>();
 }