Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / demo / CoEd / libCoEd / CoEdTextChange.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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: CoEdTextChange.h /main/3 1995/10/23 09:43:46 rswiston $                                                      */
28 /* -*-C++-*-
29  *
30  * CoEdTextChange.h
31  *
32  * Copyright (c) 1991 by Sun Microsystems.  All Rights Reserved.
33  *
34  * Permission to use, copy, modify, distribute, and sell this software
35  * and its documentation for any purpose is hereby granted without
36  * fee, provided that the above copyright notice appear in all copies
37  * and that both that copyright notice and this permission notice
38  * appear in supporting documentation, and that the names of Sun
39  * Microsystems and its subsidiaries not be used in advertising or
40  * publicity pertaining to distribution of the software without
41  * specific, written prior permission.  Sun Microsystems and its
42  * subsidiaries make no representations about the suitability of this
43  * software for any purpose.  It is provided "as is" without express
44  * or implied warranty.
45  *
46  * Sun Microsystems and its subsidiaries disclaim all warranties with
47  * regard to this software, including all implied warranties of
48  * merchantability and fitness.  In no event shall Sun Microsystems or
49  * its subsidiaries be liable for any special, indirect or
50  * consequential damages or any damages whatsoever resulting from loss
51  * of use, data or profits, whether in an action of contract,
52  * negligence or other tortious action, arising out of or in
53  * connection with the use or performance of this software.
54  */
55
56 #ifndef CoEdTextChange_h
57 #define CoEdTextChange_h
58
59 #define InLibCoEd
60
61 #include "CoEd.h"
62 #include "CoEdTextVersion.h"
63
64 class CoEdTextChange {
65         friend class CoEdTextChangeList;
66         friend class CoEdChangeHistory;
67         friend class CoEdChangeQueue;
68
69     public:
70         CoEdTextChange();
71         CoEdTextChange( long start, long end, const char *text,
72                         const CoEdTextVersion *appliesTo,
73                         const CoEdSiteID *causer, int changeNum );
74         CoEdTextChange( const CoEdTextChange &change );
75         CoEdTextChange( Tt_message msg, CoEdStatus &status );
76         ~CoEdTextChange();
77
78         CoEdStatus      broadcast( const char *path )                   const;
79         int             knowsOfNewerChangesThan(
80                                 const CoEdTextVersion &version )        const
81                                 { return _appliesTo->knowsOfNewerChangesThan(
82                                                         version ); }
83         int             knowsOfNewerChangesThan(
84                                 const CoEdTextChange &change )          const
85                                 { return _appliesTo->knowsOfNewerChangesThan(
86                                                         *change._appliesTo ); }
87         int             knowsOf( const CoEdTextChange &change )         const
88                                 { return _appliesTo->knowsOf( *change._causer,
89                                                         change._changeNum ); }
90         void            interTranslate( CoEdTextChange &chng2Xlate );
91         void            translateOver( const CoEdTextChange &chng2Hurdle );
92         long            adjustPt( long pt, const CoEdSiteID &ptOwner,
93                                   int directionToLean )                 const;
94         void            print( FILE *f );
95         long            charsAddedBy()  const { return _charsAdded; }
96         long            start()         const { return _start; }
97         long            end()           const { return _end; }
98         const char     *text()          const { return _text; }
99         const CoEdSiteID &causer()      const { return *_causer; }
100         int             changeNum()     const { return _changeNum; }
101
102     private:
103         long                    _start;
104         long                    _end;
105         const char             *_text;
106         CoEdTextVersion        *_appliesTo;
107         CoEdSiteID             *_causer;
108         int                     _changeNum;
109         long                    _charsAdded;
110         CoEdTextChange         *_next;
111         CoEdTextChange         *_prev;
112 };
113
114 class CoEdTextChangeList {
115         friend class CoEdChangeHistory;
116         friend class CoEdChangeQueue;
117
118     public:
119         CoEdTextChangeList();
120         ~CoEdTextChangeList();
121
122         void            push( CoEdTextChange *change );
123         void            append( CoEdTextChange *change );
124         void            insertBefore( CoEdTextChange *change1,
125                                       CoEdTextChange *change2 );
126         void            insertAfter( CoEdTextChange *change2,
127                                      CoEdTextChange *change1 );
128         CoEdTextChange *remove( CoEdTextChange *change );
129         void            print( FILE *f, char *indent = "" );
130
131     private:
132         CoEdTextChange *_head;
133         CoEdTextChange *_tail;
134         int             _count;
135 };
136
137 #endif CoEdTextChange_h