~karl-qdh/nux/nux.gtkentry-wrapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#ifndef NODEITEM_H
#define NODEITEM_H

namespace nux
{

  class NodeItem
  {
#ifndef NUX_STANDALONE
    NUX_DECLARE_ROOT_OBJECT_TYPE (NodeItem);
#endif
  public:
    NodeItem();
    virtual ~NodeItem();

    int get_num_child()
    {
      int num = 0;
      NodeItem *item = child_head;

      while (item)
      {
        num++;
        item = item->Next();
      }

      return num;
    }

    NodeItem *FirstSibling ( void );
    NodeItem *LastSibling ( void );
    NodeItem *Prev ( void )
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Prev() );
    }
    NodeItem *Next ( void )
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Next() );
    }
    const NodeItem *Prev ( void ) const;
    const NodeItem *Next ( void ) const;

    NodeItem *FirstChildNode ( void )
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->FirstChildNode() );
    }
    const NodeItem *FirstChildNode ( void ) const
    {
      return child_head;
    };

    NodeItem *LastChildNode ( void )
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->LastChildNode() );
    }
    const NodeItem *LastChildNode ( void ) const
    {
      return child_tail;
    };

    NodeItem *Parent (void)
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Parent() );
    }
    const NodeItem *Parent (void) const
    {
      return parent_node;
    };

    bool FindNode (NodeItem *);

    NodeItem *RootNode()
    {
      return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->RootNode() );
    }
    const NodeItem *RootNode() const;

    int NumChild() const;
    int Depth() const;
    virtual void      PushChildFront ( NodeItem *child );
    virtual void      PushChildBack ( NodeItem *child );
    virtual void      AddNextSibling ( NodeItem *sibling );
    virtual void      AddPrevSibling ( NodeItem *sibling );
    virtual void      Unlink ( void );
    virtual void      Unlink ( NodeItem *child );

    void DeleteTree();

    // Sometimes it may be necessary to skip the child of some elements because the elements takes care of them.
    // See Vector4PropertyItem.
    virtual bool SkipChild() const
    {
      return false;
    }

    void      link_this_to_parent_last ( NodeItem *parent );
    void      link_this_to_parent_first ( NodeItem *parent );
    void      link_this_to_sibling_next ( NodeItem *sibling );
    void      link_this_to_sibling_prev ( NodeItem *sibling );

  protected:
    NodeItem *parent_node;
    NodeItem *child_head;
    NodeItem *child_tail;
    NodeItem *next_sibling;
    NodeItem *prev_sibling;
  };

}

#endif // NODEITEM_H