2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: OutlineList.C /main/4 1996/10/04 11:13:58 drk $
26 * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
27 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28 * States. Use of a copyright notice is precautionary only and does not
29 * imply publication or disclosure.
31 * This software contains confidential information and trade secrets of HaL
32 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
33 * without the prior express written permission of HaL Computer Systems, Inc.
35 * RESTRICTED RIGHTS LEGEND
36 * Use, duplication, or disclosure by the Government is subject to
37 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38 * Technical Data and Computer Software clause at DFARS 252.227-7013.
39 * HaL Computer Systems, Inc.
40 * 1315 Dell Avenue, Campbell, CA 95008
45 #define C_OutlineElement
50 #define OUTLINE_ELEMENT(I) ((OutlineElement *)f_list_element[i])
53 // /////////////////////////////////////////////////////////////////
55 // /////////////////////////////////////////////////////////////////
57 OutlineList::OutlineList (int initial_size, int increment,
58 List::grow_method_t grow_method)
59 : List (initial_size, increment, grow_method)
64 // /////////////////////////////////////////////////////////////////
66 // /////////////////////////////////////////////////////////////////
68 OutlineList::~OutlineList ()
70 // recursively nuke lists
74 // /////////////////////////////////////////////////////////////////
75 // count_expanded - return the number expanded below + number here
76 // /////////////////////////////////////////////////////////////////
79 OutlineList::count_expanded (BitHandle data_handle)
83 for (i = 0; i < f_length; i++)
84 if (OUTLINE_ELEMENT(i)->is_expanded (data_handle) &&
85 OUTLINE_ELEMENT(i)->children() != NULL)
86 count += OUTLINE_ELEMENT(i)->f_children->count_expanded (data_handle);
94 // /////////////////////////////////////////////////////////////////////////
95 // copy_selected - copy selected flags from src pos to dest pos
96 // /////////////////////////////////////////////////////////////////////////
99 OutlineList::copy_selected(BitHandle src, BitHandle dest)
101 for (int i = 0 ; i < length(); i++)
103 if (OUTLINE_ELEMENT(i)->is_selected(src))
104 OUTLINE_ELEMENT(i)->set_selected(dest) ;
106 OUTLINE_ELEMENT(i)->unset_selected(dest);
108 if (OUTLINE_ELEMENT(i)->children_cached() &&
109 OUTLINE_ELEMENT(i)->has_children())
110 OUTLINE_ELEMENT(i)->children()->copy_selected(src, dest);
115 // /////////////////////////////////////////////////////////////////////////
116 // copy_expanded - copy expanded flags from src pos to dest pos
117 // /////////////////////////////////////////////////////////////////////////
120 OutlineList::copy_expanded (BitHandle src, BitHandle dest)
122 for (int i = 0 ; i < length(); i++)
124 if (OUTLINE_ELEMENT(i)->is_expanded (src))
125 OUTLINE_ELEMENT(i)->set_expanded (dest);
127 OUTLINE_ELEMENT(i)->set_contracted (dest);
129 if (OUTLINE_ELEMENT(i)->children_cached() &&
130 OUTLINE_ELEMENT(i)->has_children())
131 OUTLINE_ELEMENT(i)->children()->copy_expanded (src, dest);
136 // /////////////////////////////////////////////////////////////////////////
137 // recursive_select - if item is (un)selected, (un)select all children
138 // /////////////////////////////////////////////////////////////////////////
141 OutlineList::recursive_select(BitHandle data_handle)
143 for (int i = 0 ; i < length() ; i++ )
144 if (OUTLINE_ELEMENT(i)->children_cached() &&
145 OUTLINE_ELEMENT(i)->has_children())
147 if (OUTLINE_ELEMENT(i)->is_selected(data_handle))
148 OUTLINE_ELEMENT(i)->children()->select_all(data_handle);
150 OUTLINE_ELEMENT(i)->children()->deselect_all(data_handle);
155 // /////////////////////////////////////////////////////////////////////////
156 // select_all - select all items and same for children
157 // /////////////////////////////////////////////////////////////////////////
160 OutlineList::select_all(BitHandle data_handle)
162 for (int i = 0 ; i < length(); i++)
164 OUTLINE_ELEMENT(i)->set_selected(data_handle);
165 if (OUTLINE_ELEMENT(i)->children_cached() &&
166 OUTLINE_ELEMENT(i)->has_children())
167 OUTLINE_ELEMENT(i)->children()->select_all(data_handle);
173 // /////////////////////////////////////////////////////////////////////////
174 // deselect_all - unselect all items and same for children
175 // /////////////////////////////////////////////////////////////////////////
178 OutlineList::deselect_all(BitHandle data_handle)
180 for (int i = 0 ; i < length(); i++)
182 OUTLINE_ELEMENT(i)->unset_selected(data_handle);
183 if (OUTLINE_ELEMENT(i)->children_cached() &&
184 OUTLINE_ELEMENT(i)->has_children())
185 OUTLINE_ELEMENT(i)->children()->deselect_all(data_handle);
191 // /////////////////////////////////////////////////////////////////
192 // OutlineElement::print - print representation of self
193 // /////////////////////////////////////////////////////////////////
197 #define PRINT_POINTER(PTR) \
198 printf (" PTR = 0x%04lx\n", PTR)
200 #define PRINT_BITS(BITS) \
201 { long bits = BITS; printf (" BITS = 0x%04x", BITS); \
202 for (int i = 0; i < sizeof(BITS) * 8; i++, bits <<= 1) { \
203 if (!(i%8)) putchar (' '); \
204 (bits & (1L << (sizeof(BITS) * 8)-1)) ? putchar('1') : putchar('0'); } \
208 OutlineElement::print ()
211 PRINT_OBJECT (OutlineElement);
212 PRINT_POINTER (f_object);
213 PRINT_POINTER (f_children);
215 PRINT_BITS (f_selected);
216 PRINT_BITS (f_expanded);
217 PRINT_POINTER (f_xm_string);
219 puts ("WARNING: Can't print OutlineElement due to source code restriction.");
224 // /////////////////////////////////////////////////////////////////
226 // /////////////////////////////////////////////////////////////////
229 OutlineList::selected_items (BitHandle data_handle, List *l)
232 l = new List (8, 8, List::GROW_MULTIPLY);
234 for (int i = 0; i < length(); i++)
236 if (OUTLINE_ELEMENT(i)->is_selected (data_handle))
237 l->append (OUTLINE_ELEMENT(i));
238 if (OUTLINE_ELEMENT(i)->children_cached() &&
239 OUTLINE_ELEMENT(i)->has_children())
240 OUTLINE_ELEMENT(i)->children()->selected_items (data_handle, l);