~ubuntu-branches/ubuntu/edgy/glui/edgy

« back to all changes in this revision

Viewing changes to glui_node.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2001-09-23 12:57:28 UTC
  • Revision ID: james.westby@ubuntu.com-20010923125728-qbts7xit2eg1ogo2
Tags: upstream-2.1.0.beta
ImportĀ upstreamĀ versionĀ 2.1.0.beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
  
 
3
  GLUI User Interface Toolkit
 
4
  ---------------------------
 
5
 
 
6
     glui_node.cpp - linked-list tree structure
 
7
 
 
8
 
 
9
          --------------------------------------------------
 
10
 
 
11
  Copyright (c) 1998 Paul Rademacher
 
12
 
 
13
  This program is freely distributable without licensing fees and is
 
14
  provided without guarantee or warrantee expressed or implied. This
 
15
  program is -not- in the public domain.
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
 
 
20
#include "glui.h"
 
21
#include "stdinc.h"
 
22
 
 
23
/********************************************* GLUI_Node::first() *******/
 
24
/* Returns first sibling in 'this' node's sibling list                  */
 
25
 
 
26
GLUI_Node   *GLUI_Node::first_sibling( void )
 
27
{
 
28
  if ( parent_node == NULL )  
 
29
    return this;           /* root node has no siblings */
 
30
  else
 
31
    return parent_node->child_head;
 
32
}
 
33
 
 
34
 
 
35
/******************************************** GLUI_Node::next() ********/
 
36
/* Returns next sibling in 'this' node's sibling list                  */
 
37
 
 
38
GLUI_Node    *GLUI_Node::next( void )
 
39
{
 
40
  return next_sibling;
 
41
}
 
42
 
 
43
 
 
44
/******************************************** GLUI_Node::prev() ********/
 
45
/* Returns prev sibling in 'this' node's sibling list                  */
 
46
 
 
47
GLUI_Node    *GLUI_Node::prev( void )
 
48
{
 
49
  return prev_sibling;
 
50
}
 
51
 
 
52
 
 
53
/********************************************* GLUI_Node::last() *******/
 
54
/* Returns last sibling in 'this' node's sibling list                  */
 
55
 
 
56
GLUI_Node   *GLUI_Node::last_sibling( void )
 
57
{
 
58
  if ( parent_node == NULL )
 
59
    return this;            /* root node has no siblings */
 
60
  else
 
61
    return parent_node->child_tail;
 
62
}
 
63
 
 
64
 
 
65
/*************************** GLUI_Node::link_this_to_parent_last() *******/
 
66
/* Links as last child of parent                                         */
 
67
 
 
68
void   GLUI_Node::link_this_to_parent_last( GLUI_Node *new_parent )
 
69
{
 
70
  if ( new_parent->child_tail == NULL ) {   /* parent has no children */
 
71
    new_parent->child_head = this;
 
72
    new_parent->child_tail = this;
 
73
    this->parent_node      = new_parent;
 
74
    this->parent_node      = new_parent;
 
75
  }
 
76
  else {                                 /* parent has children */
 
77
    new_parent->child_tail->next_sibling = this;
 
78
    this->prev_sibling                   = new_parent->child_tail;
 
79
    new_parent->child_tail               = this;
 
80
    this->parent_node                    = new_parent;
 
81
  }
 
82
}
 
83
 
 
84
 
 
85
/*************************** GLUI_Node::link_this_to_parent_first() *******/
 
86
/* Links as first child of parent                                         */
 
87
 
 
88
void   GLUI_Node::link_this_to_parent_first( GLUI_Node *new_parent )
 
89
{
 
90
  if ( new_parent->child_head == NULL ) {   /* parent has no children */
 
91
    new_parent->child_head               = this;
 
92
    new_parent->child_tail               = this;
 
93
    this->parent_node                    = new_parent;
 
94
  }
 
95
  else {                                 /* parent has children */
 
96
    new_parent->child_head->prev_sibling = this;
 
97
    this->next_sibling                   = new_parent->child_head;
 
98
    new_parent->child_head               = this;
 
99
    this->parent_node                    = new_parent;
 
100
  }
 
101
}
 
102
 
 
103
/**************************** GLUI_Node::link_this_to_sibling_next() *****/
 
104
 
 
105
void   GLUI_Node::link_this_to_sibling_next( GLUI_Node *sibling )
 
106
{
 
107
  if ( sibling->next_sibling == NULL ) {    /* node has no next sibling */
 
108
    sibling->next_sibling  = this;
 
109
    this->prev_sibling     = sibling;
 
110
 
 
111
    /* This was the parent's last child, so update that as well */
 
112
    if ( sibling->parent_node  != NULL ) {
 
113
      sibling->parent_node->child_tail = this;
 
114
    }
 
115
  }
 
116
  else {                            /* node already has a next sibling */
 
117
    sibling->next_sibling->prev_sibling = this;
 
118
    this->next_sibling                  = sibling->next_sibling;
 
119
    sibling->next_sibling               = this;
 
120
    this->prev_sibling                  = sibling;
 
121
  }
 
122
 
 
123
  this->parent_node = sibling->parent_node;
 
124
}
 
125
 
 
126
 
 
127
/**************************** GLUI_Node::link_this_to_sibling_prev() *****/
 
128
 
 
129
void   GLUI_Node::link_this_to_sibling_prev( GLUI_Node *sibling )
 
130
{
 
131
  if ( sibling->prev_sibling == NULL ) {    /* node has no prev sibling */
 
132
    sibling->prev_sibling  = this;
 
133
    this->next_sibling     = sibling;
 
134
 
 
135
    /* This was the parent's first child, so update that as well */
 
136
    if ( sibling->parent_node  != NULL ) {
 
137
      sibling->parent_node->child_head = this;
 
138
    }
 
139
  }
 
140
  else {                            /* node already has a prev sibling */
 
141
    sibling->prev_sibling->next_sibling = this;
 
142
    this->prev_sibling                  = sibling->prev_sibling;
 
143
    sibling->prev_sibling               = this;
 
144
    this->next_sibling                  = sibling;
 
145
  }
 
146
 
 
147
  this->parent_node = sibling->parent_node;
 
148
}
 
149
 
 
150
/**************************************** GLUI_Node::unlink() **************/
 
151
 
 
152
void   GLUI_Node::unlink( void )
 
153
{
 
154
  /* Unlink from prev sibling */
 
155
  if ( this->prev_sibling != NULL ) {
 
156
    this->prev_sibling->next_sibling = this->next_sibling;
 
157
  }
 
158
  else {                 /* No prev sibling: this was parent's first child */
 
159
    this->parent_node->child_head = this->next_sibling;
 
160
  }
 
161
 
 
162
  /* Unlink from next sibling */
 
163
  if ( this->next_sibling != NULL ) {
 
164
    this->next_sibling->prev_sibling = this->prev_sibling;
 
165
  }
 
166
  else {                /* No next sibling: this was parent's last child */
 
167
    this->parent_node->child_tail = this->prev_sibling;
 
168
  }
 
169
 
 
170
  this->parent_node  = NULL;
 
171
  this->next_sibling = NULL;
 
172
  this->prev_sibling = NULL;
 
173
  this->child_head   = NULL;
 
174
  this->child_tail   = NULL;
 
175
}