xref: /aoo42x/main/sw/inc/redline.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _REDLINE_HXX
28 #define _REDLINE_HXX
29 
30 #include <tools/datetime.hxx>
31 #include <tools/string.hxx>
32 
33 #define _SVSTDARR_USHORTS
34 #include <svl/svstdarr.hxx>
35 #include <pam.hxx>
36 
37 #include <IDocumentRedlineAccess.hxx>
38 
39 #include <svl/smplhint.hxx>
40 
41 class SfxItemSet;
42 class SwView;
43 
44 class SwRedlineExtraData
45 {
46 	SwRedlineExtraData( const SwRedlineExtraData& );
47 	SwRedlineExtraData& operator=( const SwRedlineExtraData& );
48 
49 protected:
50 	SwRedlineExtraData() {}
51 
52 public:
53 	virtual ~SwRedlineExtraData();
54 	virtual SwRedlineExtraData* CreateNew() const = 0;
55 
56 	virtual void Accept( SwPaM& rPam ) const;
57 	virtual void Reject( SwPaM& rPam ) const;
58 	virtual int operator == ( const SwRedlineExtraData& ) const;
59 };
60 
61 class SwRedlineExtraData_FmtColl : public SwRedlineExtraData
62 {
63 	String sFmtNm;
64 	SfxItemSet* pSet;
65 	sal_uInt16 nPoolId;
66 public:
67 	SwRedlineExtraData_FmtColl( const String& rColl, sal_uInt16 nPoolFmtId,
68 								const SfxItemSet* pSet = 0 );
69 	virtual ~SwRedlineExtraData_FmtColl();
70 	virtual SwRedlineExtraData* CreateNew() const;
71 	virtual void Reject( SwPaM& rPam ) const;
72 	virtual int operator == ( const SwRedlineExtraData& ) const;
73 
74 	void SetItemSet( const SfxItemSet& rSet );
75 };
76 
77 class SwRedlineExtraData_Format : public SwRedlineExtraData
78 {
79 	SvUShorts aWhichIds;
80 
81 	SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
82 
83 public:
84 	SwRedlineExtraData_Format( const SfxItemSet& rSet );
85 	virtual ~SwRedlineExtraData_Format();
86 	virtual SwRedlineExtraData* CreateNew() const;
87 	virtual void Reject( SwPaM& rPam ) const;
88 	virtual int operator == ( const SwRedlineExtraData& ) const;
89 };
90 
91 
92 class SW_DLLPUBLIC SwRedlineData
93 {
94 	friend class SwRedline;
95 	SwRedlineData* pNext;		// Verweis auf weitere Daten
96 	SwRedlineExtraData* pExtraData;
97 
98 	String sComment;
99 	DateTime aStamp;
100 	RedlineType_t eType;
101 	sal_uInt16 nAuthor, nSeqNo;
102 
103 public:
104 	SwRedlineData( RedlineType_t eT, sal_uInt16 nAut );
105 	SwRedlineData( const SwRedlineData& rCpy, sal_Bool bCpyNext = sal_True );
106 
107 	// fuer sw3io: pNext/pExtraData gehen in eigenen Besitz ueber!
108 	SwRedlineData( RedlineType_t eT, sal_uInt16 nAut, const DateTime& rDT,
109 				   const String& rCmnt, SwRedlineData* pNxt,
110 					SwRedlineExtraData* pExtraData = 0 );
111 
112 	~SwRedlineData();
113 
114 	int operator==( const SwRedlineData& rCmp ) const
115 		{
116 			return nAuthor == rCmp.nAuthor &&
117 					eType == rCmp.eType &&
118 					sComment == rCmp.sComment &&
119 					(( !pNext && !rCmp.pNext ) ||
120 						( pNext && rCmp.pNext && *pNext == *rCmp.pNext )) &&
121 					(( !pExtraData && !rCmp.pExtraData ) ||
122 						( pExtraData && rCmp.pExtraData &&
123 							*pExtraData == *rCmp.pExtraData ));
124 		}
125 	int operator!=( const SwRedlineData& rCmp ) const
126 		{	return !operator==( rCmp ); }
127 
128 	RedlineType_t GetType() const
129   { return ((RedlineType_t)(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
130 	RedlineType_t GetRealType() const { return eType; }
131 	sal_uInt16 GetAuthor() const 				{ return nAuthor; }
132 	const String& GetComment() const 		{ return sComment; }
133 	const DateTime& GetTimeStamp() const 	{ return aStamp; }
134 	inline const SwRedlineData* Next() const{ return pNext;	}
135 
136     void SetComment( const String& rS )     { sComment = rS; }
137     void SetTimeStamp( const DateTime& rDT ) { aStamp = rDT; }
138 
139     void SetAutoFmtFlag()
140   { eType = (RedlineType_t)(eType | nsRedlineType_t::REDLINE_FORM_AUTOFMT); }
141 	int CanCombine( const SwRedlineData& rCmp ) const
142 		{
143 			return nAuthor == rCmp.nAuthor &&
144 					eType == rCmp.eType &&
145 					sComment == rCmp.sComment &&
146 					GetTimeStamp() == rCmp.GetTimeStamp() &&
147 					(( !pNext && !rCmp.pNext ) ||
148 						( pNext && rCmp.pNext &&
149 						pNext->CanCombine( *rCmp.pNext ))) &&
150 					(( !pExtraData && !rCmp.pExtraData ) ||
151 						( pExtraData && rCmp.pExtraData &&
152 							*pExtraData == *rCmp.pExtraData ));
153 		}
154 
155 	// ExtraData wird kopiert, der Pointer geht also NICHT in den Besitz
156 	// des RedlineObjectes!
157 	void SetExtraData( const SwRedlineExtraData* pData );
158 	const SwRedlineExtraData* GetExtraData() const { return pExtraData; }
159 
160 	// fuers UI-seitige zusammenfassen von Redline-Actionen. Wird z.Z. nur
161 	// fuers Autoformat mit Redline benoetigt. Der Wert != 0 bedeutet dabei,
162 	// das es noch weitere geben kann!
163 	sal_uInt16 GetSeqNo() const 					{ return nSeqNo; }
164 	void SetSeqNo( sal_uInt16 nNo ) 				{ nSeqNo = nNo; }
165 
166     String GetDescr() const;
167 };
168 
169 
170 class SW_DLLPUBLIC SwRedline : public SwPaM
171 {
172 	SwRedlineData* pRedlineData;
173 	SwNodeIndex* pCntntSect;
174 	sal_Bool bDelLastPara : 1;
175 	sal_Bool bIsLastParaDelete : 1;
176 	sal_Bool bIsVisible : 1;
177 
178 	void MoveToSection();
179 	void CopyToSection();
180 	void DelCopyOfSection();
181 	void MoveFromSection();
182 
183 public:
184 	SwRedline( RedlineType_t eType, const SwPaM& rPam );
185 	SwRedline( const SwRedlineData& rData, const SwPaM& rPam );
186 	SwRedline( const SwRedlineData& rData, const SwPosition& rPos );
187 	// fuer sw3io: pData geht in eigenen Besitz ueber!
188 	SwRedline(SwRedlineData* pData, const SwPosition& rPos, sal_Bool bVsbl,
189 			   sal_Bool bDelLP, sal_Bool bIsPD) :
190 		SwPaM( rPos ), pRedlineData( pData ), pCntntSect( 0 ),
191 		bDelLastPara( bDelLP ), bIsLastParaDelete( bIsPD ), bIsVisible( bVsbl )
192 	{}
193 	SwRedline( const SwRedline& );
194 	virtual ~SwRedline();
195 
196 	SwNodeIndex* GetContentIdx() const { return pCntntSect; }
197 	// fuers Undo
198 	void SetContentIdx( const SwNodeIndex* );
199 
200 	sal_Bool IsVisible() const { return bIsVisible; }
201 	sal_Bool IsDelLastPara() const { return bDelLastPara; }
202 
203 	// das sal_Bool besagt, ob nach dem setzen der Pos kein Bereich mehr
204 	// aufgespannt ist. -> sal_True, ansonten Bereich und sal_False
205 	void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = 0 )
206 	{
207 		if( !pSttPtr ) pSttPtr = Start();
208 		*pSttPtr = rPos;
209 	}
210 	void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = 0 )
211 	{
212 		if( !pEndPtr ) pEndPtr = End();
213 		*pEndPtr = rPos;
214 	}
215 	// liegt eine gueltige Selektion vor?
216 	sal_Bool HasValidRange() const;
217 
218 	const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
219 	int operator==( const SwRedlineData& rCmp ) const
220 		{ return *pRedlineData == rCmp; }
221 	int operator!=( const SwRedlineData& rCmp ) const
222 		{ return *pRedlineData != rCmp; }
223 	void SetAutoFmtFlag()				{ pRedlineData->SetAutoFmtFlag(); }
224 
225 	sal_uInt16 GetStackCount() const;
226 	sal_uInt16 GetAuthor( sal_uInt16 nPos = 0) const;
227 	const String& GetAuthorString( sal_uInt16 nPos = 0 ) const;
228 	const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
229     RedlineType_t GetRealType( sal_uInt16 nPos = 0 ) const;
230 	RedlineType_t GetType( sal_uInt16 nPos = 0) const
231   { return ( (RedlineType_t)(GetRealType( nPos ) & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
232 	const String& GetComment( sal_uInt16 nPos = 0 ) const;
233 
234 	void SetComment( const String& rS ) { pRedlineData->SetComment( rS ); }
235 
236 	// ExtraData wird kopiert, der Pointer geht also NICHT in den Besitz
237 	// des RedlineObjectes!
238 	void SetExtraData( const SwRedlineExtraData* pData )
239 		{ pRedlineData->SetExtraData( pData ); }
240 	const SwRedlineExtraData* GetExtraData() const
241 		{ return pRedlineData->GetExtraData(); }
242 
243 	// fuers UI-seitige zusammenfassen von Redline-Actionen. Wird z.Z. nur
244 	// fuers Autoformat mit Redline benoetigt. Der Wert != 0 bedeutet dabei,
245 	// das es noch weitere geben kann!
246 	sal_uInt16 GetSeqNo() const 			{ return pRedlineData->GetSeqNo(); }
247 	void SetSeqNo( sal_uInt16 nNo ) 		{ pRedlineData->SetSeqNo( nNo ); }
248 
249 	// Beim Hide/ShowOriginal wird 2 mal ueber die Liste gelaufen, damit
250 	//	die Del-Redlines per Copy und Delete versteckt werden. Beim Move
251 	//	wird sonst die Attributierung falsch behandelt.
252 	// Alle anderen Aufrufer muessen immer 0 angeben.
253 	void CallDisplayFunc( sal_uInt16 nLoop = 0 );
254 	void Show( sal_uInt16 nLoop = 0 );
255 	void Hide( sal_uInt16 nLoop = 0 );
256 	void ShowOriginal( sal_uInt16 nLoop = 0 );
257 
258     // calculates the intersection with text node number nNdIdx
259     void CalcStartEnd( sal_uLong nNdIdx, sal_uInt16& nStart, sal_uInt16& nEnd ) const;
260 
261     void InvalidateRange();     // das Layout anstossen
262 
263 	sal_Bool IsOwnRedline( const SwRedline& rRedl ) const
264 		{ return GetAuthor() == rRedl.GetAuthor(); }
265 	sal_Bool CanCombine( const SwRedline& rRedl ) const;
266 
267 	void PushData( const SwRedline& rRedl, sal_Bool bOwnAsNext = sal_True );
268 	sal_Bool PopData();
269 
270     // #111827#
271     /**
272        Returns textual description of this a redline data element of
273        this redline.
274 
275        @param nPos index of the redline data element to describe
276 
277        The textual description of the selected element contains the
278        kind of redline and the possibly shortened text of the redline.
279 
280        @return textual description of the selected redline data element
281      */
282     String GetDescr(sal_uInt16 nPos = 0);
283 
284 	int operator==( const SwRedline& ) const;
285 	int operator<( const SwRedline& ) const;
286 };
287 
288 class SW_DLLPUBLIC SwRedlineHint : public SfxHint
289 {
290 #define SWREDLINE_INSERTED	1
291 #define SWREDLINE_REMOVED	2
292 #define SWREDLINE_FOCUS		3
293 #define SWREDLINE_CHANGED	4
294 #define SWREDLINE_LANGUAGE	5
295 
296 	const SwRedline* pRedline;
297 	sal_Int16 nWhich;
298 	const SwView* pView;
299 
300 public:
301 	SwRedlineHint( const SwRedline* p, sal_Int16 n, const SwView* pV = 0)
302 		: pRedline(p)
303 		, nWhich(n)
304 		, pView(pV)
305         {}
306 
307 	TYPEINFO();
308 	const SwRedline* GetRedline() const { return pRedline; }
309 	sal_Int16 Which() const { return nWhich; }
310         const SwView* GetView() const { return pView; }
311 };
312 
313 
314 #endif
315