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 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: CoEdChangeHistory.C /main/3 1995/10/20 17:06:11 rswiston $
29 * CoEdChangeHistory.cc
31 * Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
33 * Permission to use, copy, modify, distribute, and sell this software
34 * and its documentation for any purpose is hereby granted without
35 * fee, provided that the above copyright notice appear in all copies
36 * and that both that copyright notice and this permission notice
37 * appear in supporting documentation, and that the names of Sun
38 * Microsystems and its subsidiaries not be used in advertising or
39 * publicity pertaining to distribution of the software without
40 * specific, written prior permission. Sun Microsystems and its
41 * subsidiaries make no representations about the suitability of this
42 * software for any purpose. It is provided "as is" without express
43 * or implied warranty.
45 * Sun Microsystems and its subsidiaries disclaim all warranties with
46 * regard to this software, including all implied warranties of
47 * merchantability and fitness. In no event shall Sun Microsystems or
48 * its subsidiaries be liable for any special, indirect or
49 * consequential damages or any damages whatsoever resulting from loss
50 * of use, data or profits, whether in an action of contract,
51 * negligence or other tortious action, arising out of or in
52 * connection with the use or performance of this software.
56 #include "CoEdChangeHistory.h"
59 CoEdChangeHistory() : CoEdTextChangeList()
63 void CoEdChangeHistory::
64 insert( CoEdTextChange *change )
66 CoEdTextChange *curr = _tail;
68 // Find the most recent change in the history that the
69 // incoming change knows of.
72 if (change->knowsOf( *curr )) {
78 // Bump curr to point to the first change that the incoming
79 // change doesn't know of.
87 // The rest of the changes are mutually ignorant with the incoming
88 // change. Find the first one with a greater site id, and
89 // stick this change in front of it.
92 if (*change->_causer < *curr->_causer) {
100 insertBefore( change, curr );
104 CoEdTextChange *CoEdChangeHistory::
105 translate( CoEdTextChange &change )
107 _translateOverEarlierChgs( change );
108 return _translateOverLaterChgs( change );
112 // Modify <change> so that it takes into account any changes ahead of
113 // it in the change history that it does not know about.
115 void CoEdChangeHistory::
116 _translateOverEarlierChgs( CoEdTextChange &change )
118 CoEdTextChange *curr = _head;
119 while (curr != &change) {
120 if (! change.knowsOf( *curr )) {
121 change.translateOver( *curr );
128 // Take <change>, which is assumed to have been inserted into this
129 // ChangeHistory, and adjust the remaining changes in the history
130 // so that they take into account the change inserted ahead of them.
131 // Also, return a new CoEdTextChange that is a translated version
132 // of <change>, suitable for application to a textbuffer that
133 // has already had the remaining changes in the history applied to it.
135 CoEdTextChange *CoEdChangeHistory::
136 _translateOverLaterChgs( const CoEdTextChange &change )
138 CoEdTextChange *xlatdChng = new CoEdTextChange( change );
139 if (xlatdChng == 0) {
143 CoEdTextChange *curr = change._next;
145 curr->interTranslate( *xlatdChng );