Exemplo n.º 1
0
        /// <summary>
        /// Removes a node from a specific point in the array
        /// </summary>
        /// <param name="index"></param>
        public void RemoveNodeAt(int index)
        {
            if (_nodes == null)
            {
                return;
            }
            if (_nodes.Length == 1)
            {
                _nodes = null;
            }
            else
            {
                var tmp = new TreeviewNode[_nodes.Length];
                int c   = 0;
                for (int i = 0; i < _nodes.Length; i++)
                {
                    if (i != index)
                    {
                        tmp[c++] = _nodes[i];
                    }
                }
                _nodes = tmp;
            }

            Invalidate();
        }
Exemplo n.º 2
0
 protected virtual void OnNodeTap(TreeviewNode node, point e)
 {
     if (NodeTapped != null)
     {
         NodeTapped(node, e);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a subnode from a specific point in the array
        /// </summary>
        /// <param name="index"></param>
        public void RemoveNodeAt(int index)
        {
            if (_nodes == null)
            {
                return;
            }
            if (_nodes.Length == 1)
            {
                _nodes = null;
            }
            else
            {
                var tmp = new TreeviewNode[_nodes.Length];
                int c   = 0;
                for (int i = 0; i < _nodes.Length; i++)
                {
                    if (i != index)
                    {
                        tmp[c++] = _nodes[i];
                    }
                }
                _nodes = tmp;
            }

            Expanded = _expanded; // Automatically updates for 0 nodes
        }
Exemplo n.º 4
0
 protected virtual void OnNodeExpanded(object sender, TreeviewNode node)
 {
     if (NodeExpanded != null)
     {
         NodeExpanded(sender, node);
     }
 }
Exemplo n.º 5
0
 protected override void TouchDownMessage(object sender, point point, ref bool handled)
 {
     if (_nodes != null)
     {
         TreeviewNode node = NodeFromPoint(point);
         if (node != null)
         {
             node.PenDown = true;
         }
     }
 }
Exemplo n.º 6
0
 private void ResetChildrenBounds(TreeviewNode node)
 {
     for (int i = 0; i < node.Length; i++)
     {
         node.Nodes[i].Bounds = new rect(0, 0, 0, 0);
         if (node.Nodes[i].Length > 0)
         {
             ResetChildrenBounds(node.Nodes[i]);
         }
     }
 }
Exemplo n.º 7
0
 private void SetChildrenPen(TreeviewNode node)
 {
     node.PenDown = false;
     for (int i = 0; i < node.Length; i++)
     {
         node.Nodes[i].PenDown = false;
         if (node.Nodes[i].Length > 0)
         {
             SetChildrenPen(node.Nodes[i]);
         }
     }
 }
Exemplo n.º 8
0
 private void SetChildrenSelected(TreeviewNode node)
 {
     _selNode      = null;
     node.Selected = false;
     for (int i = 0; i < node.Length; i++)
     {
         node.Nodes[i].Selected = false;
         if (node.Nodes[i].Length > 0)
         {
             SetChildrenSelected(node.Nodes[i]);
         }
     }
 }
Exemplo n.º 9
0
        protected override void TouchUpMessage(object sender, point point, ref bool handled)
        {
            if (_nodes != null)
            {
                // Get Selected Node
                TreeviewNode node    = NodeFromPoint(point);
                int          icoSize = _font.Height;
                if (node != null)
                {
                    var ecRect = new rect(node.Bounds.X, node.Bounds.Y, icoSize, icoSize);
                    if (ecRect.Contains(point) && node.PenDown)
                    {
                        /*node.Expanded = !node._expanded;
                         * if (!node._expanded)
                         * ResetChildrenBounds(node);*/
                        node.Expanded = !node.Expanded;
                        if (!node.Expanded)
                        {
                            ResetChildrenBounds(node);
                        }

                        Invalidate();
                    }
                    else
                    {
                        // Reset States
                        if (!node.Selected && node.PenDown)
                        {
                            for (int i = 0; i < _nodes.Length; i++)
                            {
                                ResetNodesState(_nodes[i]);
                            }
                            node.Selected = true;
                            _selNode      = node;
                            Invalidate();
                        }
                        OnNodeTap(node, point);
                    }
                }

                // Reset Pen States
                for (int i = 0; i < _nodes.Length; i++)
                {
                    SetChildrenPen(_nodes[i]);
                }
            }
            base.TouchUpMessage(sender, point, ref handled);
        }
Exemplo n.º 10
0
        private void ResetNodesState(TreeviewNode topNode)
        {
            _selNode         = null;
            topNode.Selected = false;
            topNode.PenDown  = false;

            for (int i = 0; i < topNode.Length; i++)
            {
                topNode.Nodes[i].Selected = false;
                topNode.Nodes[i].PenDown  = false;
                if (topNode.Nodes[i].Length > 0)
                {
                    SetChildrenSelected(topNode.Nodes[i]);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Removes a specific node
        /// </summary>
        /// <param name="node"></param>
        public void RemoveNode(TreeviewNode node)
        {
            if (_nodes == null)
            {
                return;
            }

            for (int i = 0; i < _nodes.Length; i++)
            {
                if (_nodes[i] == node)
                {
                    RemoveNodeAt(i);
                    return;
                }
            }
        }
Exemplo n.º 12
0
        private point RenderSubNodes(TreeviewNode node, int x, int y, int icoSize)
        {
            int maxX = x;

            for (int i = 0; i < node.Length; i++)
            {
                int tH;
                int tW;
                _font.ComputeExtent(node.Nodes[i].Text, out tW, out tH);
                node.Nodes[i].Bounds = new rect(x, y, Width + (x - Left), _font.Height + 8);

                if (maxX < tW + icoSize + 20 + x)
                {
                    maxX = tW + icoSize + 20 + x;
                }

                if (y + _font.Height + 4 > 0 && y < Top + Height)
                {
                    // Draw Icon if node has children
                    if (node.Nodes[i].Length > 0)
                    {
                        Core.Screen.DrawRectangle(Colors.DarkGray, 1, x + 2, y + 2, icoSize - 4, icoSize - 4, 0, 0, Colors.Ghost, x + 2, y + 2, Colors.LightGray, x + 2, y + 6, 256);
                        Core.Screen.DrawTextInRect((node.Nodes[i].Expanded) ? "-" : "+", x + 2, y + 4, icoSize - 4, _font.Height, Bitmap.DT_AlignmentCenter, Colors.Charcoal, _font);
                    }

                    // Draw Node Text
                    Core.Screen.DrawTextInRect(node.Nodes[i].Text, x + icoSize + 4, y + 4, tW, _font.Height, Bitmap.DT_TrimmingCharacterEllipsis,
                                               (node.Nodes[i].Selected) ? _selColor : _color, _font);
                }

                y += icoSize + 4;

                if (node.Nodes[i].Expanded)
                {
                    point e = RenderSubNodes(node.Nodes[i], x + icoSize, y, icoSize);
                    y = e.Y;
                    if (e.X > maxX)
                    {
                        maxX = e.X;
                    }
                }
            }

            return(new point(maxX, y));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Adds a node
        /// </summary>
        /// <param name="node"></param>
        public void AddNode(TreeviewNode node)
        {
            node.Container = this;

            if (_nodes == null)
            {
                _nodes = new[] { node };
            }
            else
            {
                var tmp = new TreeviewNode[_nodes.Length + 1];
                Array.Copy(_nodes, tmp, _nodes.Length);
                tmp[tmp.Length - 1] = node;
                _nodes = tmp;
            }

            Invalidate();
        }
Exemplo n.º 14
0
 private TreeviewNode CheckNodePoint(TreeviewNode node, point e)
 {
     for (int i = 0; i < node.Length; i++)
     {
         if (node.Nodes[i].Bounds.Contains(e))
         {
             return(node.Nodes[i]);
         }
         if (node.Nodes[i].Length > 0)
         {
             TreeviewNode subnode = CheckNodePoint(node.Nodes[i], e);
             if (subnode != null)
             {
                 return(subnode);
             }
         }
     }
     return(null);
 }
Exemplo n.º 15
0
 private TreeviewNode NodeFromPoint(point e)
 {
     for (int i = 0; i < _nodes.Length; i++)
     {
         if (_nodes[i].Bounds.Contains(e))
         {
             return(_nodes[i]);
         }
         if (_nodes[i].Length > 0)
         {
             TreeviewNode node = CheckNodePoint(_nodes[i], e);
             if (node != null)
             {
                 return(node);
             }
         }
     }
     return(null);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Adds a subnode
        /// </summary>
        /// <param name="node"></param>
        public void AddNode(TreeviewNode node)
        {
            node.Parent    = this;
            node.Container = _container;

            if (_nodes == null)
            {
                _nodes = new[] { node };
            }
            else
            {
                var tmp = new TreeviewNode[_nodes.Length + 1];
                Array.Copy(_nodes, tmp, _nodes.Length);
                tmp[tmp.Length - 1] = node;
                _nodes = tmp;
            }

            if (_expanded || _nodes.Length == 1 && _container != null)
            {
                _container.Invalidate();
            }
        }
Exemplo n.º 17
0
 protected internal void ChildExpanded(TreeviewNode node)
 {
     OnNodeExpanded(this, node);
 }