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
23 /* $XConsortium: CmdList.C /main/3 1995/11/06 15:59:50 rswiston $ */
27 * RESTRICTED CONFIDENTIAL INFORMATION:
29 * The information in this document is subject to special
30 * restrictions in a confidential disclosure agreement bertween
31 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
32 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33 * Sun's specific written approval. This documment and all copies
34 * and derivative works thereof must be returned or destroyed at
37 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 ///////////////////////////////////////////////////////////////////////////////
42 //////////////////////////////////////////////////////////////////////////////
43 // This example code is from the book:
45 // Object-Oriented Programming with C++ and OSF/Motif
48 // Prentice Hall, 1992
51 // Copyright 1991 by Prentice Hall
52 // All Rights Reserved
54 // Permission to use, copy, modify, and distribute this software for
55 // any purpose except publication and without fee is hereby granted, provided
56 // that the above copyright notice appear in all copies of the software.
57 ///////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////
62 // CmdList.C: Maintain a list of Cmd objects
63 ////////////////////////////////////////////////////////////
65 ////////////////////////////////////////////////////////////
66 // MODIFIED TO INHERIT FROM CMD - not described in Book
67 ///////////////////////////////////////////////////////////
72 CmdList::CmdList() : Cmd("CmdList", "CmdList", 1)
79 CmdList::CmdList(char *name, char *label ) : Cmd(name, label, 1)
81 // The list is initially empty
94 void CmdList::add ( Cmd *cmd )
99 // CmdList can only be undone if all Cmds it contains can be undone
104 // Allocate a list large enough for one more element
106 newList = new Cmd*[_numElements + 1];
108 // Copy the contents of the previous list to
111 for( i = 0; i < _numElements; i++)
112 newList[i] = _contents[i];
119 // Make the new list the current list
123 // Add the command to the list and update the list size.
125 _contents[_numElements] = cmd;
130 Cmd *CmdList::operator[] ( int index )
132 // Return the indexed element
134 return _contents[index];
140 for( int i = 0; i < _numElements; i++)
141 _contents[i]->execute();
144 void CmdList::undoit()
147 for( int i = _numElements - 1; i >=0; i--)
148 _contents[i]->undo();