OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / OutlineElement.hh
1 /*
2  * $XConsortium: OutlineElement.hh /main/4 1996/08/30 17:21:04 drk $
3  *
4  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22 class OutlineList;
23
24 class OutlineElement : public FolioObject
25 {
26 friend class OutlineList;
27   
28 public: // functions
29   DEF_CLASS (OutlineElement);
30
31   OutlineElement (OutlineList *children = NULL)
32     : f_children (children),
33       f_xm_string (NULL), f_children_flag (0),
34       f_string_creator (0), f_display_flag (1),
35       f_level (0)
36   { children_valid ((children != NULL) ? TRUE : FALSE); }
37
38   ~OutlineElement();
39
40   inline bool has_children();
41
42   virtual OutlineList *children()
43     { return (f_children); }
44   virtual void set_children (OutlineList *children)
45     { f_children = children;
46       children_valid (TRUE); }
47
48   bool children_cached()
49     { return (children_valid()); }
50
51   virtual void display() = 0;
52
53   unsigned char level()
54     { return (f_level); }
55   void level (unsigned char level)
56     { f_level = level; }
57   
58   bool is_selected (BitHandle handle)
59     { return f_selected.is_set (handle); }
60
61   void set_selected (BitHandle handle)
62     { f_selected.set (handle) ; }
63
64   void unset_selected (BitHandle handle)
65     { f_selected.unset (handle); }
66
67   bool is_expanded (BitHandle handle)
68     { return f_expanded.is_set (handle); }
69
70   bool is_contracted (BitHandle handle)
71     { return !f_expanded.is_set (handle) ; }
72
73   void set_expanded (BitHandle handle)
74     { f_expanded.set (handle); }
75
76   void set_contracted (BitHandle handle)
77     { f_expanded.unset (handle); }
78   
79   void set_xm_string (void *xm_string)
80     { f_xm_string = xm_string; }
81   void *xm_string()
82     { return (f_xm_string); }
83
84   void string_creator (u_int creator_id)
85     { f_string_creator = creator_id; }
86   u_int string_creator()
87     { return (f_string_creator); }
88
89 #ifdef DEBUG
90   void print();
91 #endif
92
93   unsigned char display_flag()
94     { return (f_display_flag); }
95   void display_flag (unsigned char flag)
96     { f_display_flag = flag; }
97
98 protected: // functions
99   bool children_valid()
100     { return ((f_children_flag & CHILDREN_VALID_BIT) != 0); }
101   void children_valid (bool setting)
102     { f_children_flag = (setting ? f_children_flag | CHILDREN_VALID_BIT :
103                                    f_children_flag & ~CHILDREN_VALID_BIT);
104     }
105   bool has_children_valid()
106     { return ((f_children_flag & HAS_CHILDREN_VALID_BIT) != 0); }
107   void has_children_valid (bool setting)
108     { f_children_flag = (setting ? f_children_flag | HAS_CHILDREN_VALID_BIT :
109                                    f_children_flag & ~HAS_CHILDREN_VALID_BIT);
110     }
111   virtual bool has_children_internal()
112     { return (children() != NULL); }
113   void has_children (bool setting)
114     { f_children_flag = (setting ? f_children_flag | HAS_CHILDREN_BIT :
115                                    f_children_flag & ~HAS_CHILDREN_BIT);
116     }
117
118 protected: // variables
119   OutlineList *f_children;  // Each outline element may have a list of children
120   
121   BitField      f_selected ;
122   BitField      f_expanded ;
123
124   // NOTE: xm_string temporary until R2
125   void        *f_xm_string;
126   unsigned char f_children_flag;
127   enum { CHILDREN_VALID_BIT = 0x01,
128          HAS_CHILDREN_VALID_BIT = 0x02, HAS_CHILDREN_BIT = 0x04 };
129   u_int f_string_creator;
130
131   unsigned char f_display_flag;  // Able to be displayed on activate [rtp]
132   unsigned char f_level;    // Level this element is at, zero-based
133 };
134
135
136 inline bool
137 OutlineElement::has_children()
138 {
139   // Only calculate value of has_children once since it might be expensive. 
140   if (!has_children_valid())
141     {
142       has_children (has_children_internal());
143       has_children_valid (TRUE);
144     }
145
146   return ((f_children_flag & HAS_CHILDREN_BIT) != 0);
147 }
148