xref: /aoo42x/main/sw/inc/redline.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _REDLINE_HXX
24 #define _REDLINE_HXX
25 
26 #include <tools/datetime.hxx>
27 #include <tools/string.hxx>
28 
29 #define _SVSTDARR_USHORTS
30 #include <svl/svstdarr.hxx>
31 #include <pam.hxx>
32 
33 #include <IDocumentRedlineAccess.hxx>
34 
35 #include <svl/smplhint.hxx>
36 
37 class SfxItemSet;
38 class SwView;
39 
40 class SwRedlineExtraData
41 {
42 	SwRedlineExtraData( const SwRedlineExtraData& );
43 	SwRedlineExtraData& operator=( const SwRedlineExtraData& );
44 
45 protected:
SwRedlineExtraData()46 	SwRedlineExtraData() {}
47 
48 public:
49 	virtual ~SwRedlineExtraData();
50 	virtual SwRedlineExtraData* CreateNew() const = 0;
51 
52 	virtual void Accept( SwPaM& rPam ) const;
53 	virtual void Reject( SwPaM& rPam ) const;
54 	virtual int operator == ( const SwRedlineExtraData& ) const;
55 };
56 
57 class SwRedlineExtraData_FmtColl : public SwRedlineExtraData
58 {
59 	String sFmtNm;
60 	SfxItemSet* pSet;
61 	sal_uInt16 nPoolId;
62 public:
63 	SwRedlineExtraData_FmtColl( const String& rColl, sal_uInt16 nPoolFmtId,
64 								const SfxItemSet* pSet = 0 );
65 	virtual ~SwRedlineExtraData_FmtColl();
66 	virtual SwRedlineExtraData* CreateNew() const;
67 	virtual void Reject( SwPaM& rPam ) const;
68 	virtual int operator == ( const SwRedlineExtraData& ) const;
69 
70 	void SetItemSet( const SfxItemSet& rSet );
71 };
72 
73 class SwRedlineExtraData_Format : public SwRedlineExtraData
74 {
75 	SvUShorts aWhichIds;
76 
77 	SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
78 
79 public:
80 	SwRedlineExtraData_Format( const SfxItemSet& rSet );
81 	virtual ~SwRedlineExtraData_Format();
82 	virtual SwRedlineExtraData* CreateNew() const;
83 	virtual void Reject( SwPaM& rPam ) const;
84 	virtual int operator == ( const SwRedlineExtraData& ) const;
85 };
86 
87 
88 class SW_DLLPUBLIC SwRedlineData
89 {
90 	friend class SwRedline;
91 	SwRedlineData* pNext;		// Verweis auf weitere Daten
92 	SwRedlineExtraData* pExtraData;
93 
94 	String sComment;
95 	DateTime aStamp;
96 	RedlineType_t eType;
97 	sal_uInt16 nAuthor, nSeqNo;
98 
99 public:
100 	SwRedlineData( RedlineType_t eT, sal_uInt16 nAut );
101 	SwRedlineData( const SwRedlineData& rCpy, sal_Bool bCpyNext = sal_True );
102 
103 	// fuer sw3io: pNext/pExtraData gehen in eigenen Besitz ueber!
104 	SwRedlineData( RedlineType_t eT, sal_uInt16 nAut, const DateTime& rDT,
105 				   const String& rCmnt, SwRedlineData* pNxt,
106 					SwRedlineExtraData* pExtraData = 0 );
107 
108 	~SwRedlineData();
109 
operator ==(const SwRedlineData & rCmp) const110 	int operator==( const SwRedlineData& rCmp ) const
111 		{
112 			return nAuthor == rCmp.nAuthor &&
113 					eType == rCmp.eType &&
114 					sComment == rCmp.sComment &&
115 					(( !pNext && !rCmp.pNext ) ||
116 						( pNext && rCmp.pNext && *pNext == *rCmp.pNext )) &&
117 					(( !pExtraData && !rCmp.pExtraData ) ||
118 						( pExtraData && rCmp.pExtraData &&
119 							*pExtraData == *rCmp.pExtraData ));
120 		}
operator !=(const SwRedlineData & rCmp) const121 	int operator!=( const SwRedlineData& rCmp ) const
122 		{	return !operator==( rCmp ); }
123 
GetType() const124 	RedlineType_t GetType() const
125   { return ((RedlineType_t)(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
GetRealType() const126 	RedlineType_t GetRealType() const { return eType; }
GetAuthor() const127 	sal_uInt16 GetAuthor() const 				{ return nAuthor; }
GetComment() const128 	const String& GetComment() const 		{ return sComment; }
GetTimeStamp() const129 	const DateTime& GetTimeStamp() const 	{ return aStamp; }
Next() const130 	inline const SwRedlineData* Next() const{ return pNext;	}
131 
SetComment(const String & rS)132     void SetComment( const String& rS )     { sComment = rS; }
SetTimeStamp(const DateTime & rDT)133     void SetTimeStamp( const DateTime& rDT ) { aStamp = rDT; }
134 
SetAutoFmtFlag()135     void SetAutoFmtFlag()
136   { eType = (RedlineType_t)(eType | nsRedlineType_t::REDLINE_FORM_AUTOFMT); }
CanCombine(const SwRedlineData & rCmp) const137 	int CanCombine( const SwRedlineData& rCmp ) const
138 		{
139 			return nAuthor == rCmp.nAuthor &&
140 					eType == rCmp.eType &&
141 					sComment == rCmp.sComment &&
142 					GetTimeStamp() == rCmp.GetTimeStamp() &&
143 					(( !pNext && !rCmp.pNext ) ||
144 						( pNext && rCmp.pNext &&
145 						pNext->CanCombine( *rCmp.pNext ))) &&
146 					(( !pExtraData && !rCmp.pExtraData ) ||
147 						( pExtraData && rCmp.pExtraData &&
148 							*pExtraData == *rCmp.pExtraData ));
149 		}
150 
151 	// ExtraData wird kopiert, der Pointer geht also NICHT in den Besitz
152 	// des RedlineObjectes!
153 	void SetExtraData( const SwRedlineExtraData* pData );
GetExtraData() const154 	const SwRedlineExtraData* GetExtraData() const { return pExtraData; }
155 
156 	// fuers UI-seitige zusammenfassen von Redline-Actionen. Wird z.Z. nur
157 	// fuers Autoformat mit Redline benoetigt. Der Wert != 0 bedeutet dabei,
158 	// das es noch weitere geben kann!
GetSeqNo() const159 	sal_uInt16 GetSeqNo() const 					{ return nSeqNo; }
SetSeqNo(sal_uInt16 nNo)160 	void SetSeqNo( sal_uInt16 nNo ) 				{ nSeqNo = nNo; }
161 
162     String GetDescr() const;
163 };
164 
165 
166 class SW_DLLPUBLIC SwRedline : public SwPaM
167 {
168 	SwRedlineData* pRedlineData;
169 	SwNodeIndex* pCntntSect;
170 	sal_Bool bDelLastPara : 1;
171 	sal_Bool bIsLastParaDelete : 1;
172 	sal_Bool bIsVisible : 1;
173 
174 	void MoveToSection();
175 	void CopyToSection();
176 	void DelCopyOfSection();
177 	void MoveFromSection();
178 
179 public:
180 	SwRedline( RedlineType_t eType, const SwPaM& rPam );
181 	SwRedline( const SwRedlineData& rData, const SwPaM& rPam );
182 	SwRedline( const SwRedlineData& rData, const SwPosition& rPos );
183 	// fuer sw3io: pData geht in eigenen Besitz ueber!
SwRedline(SwRedlineData * pData,const SwPosition & rPos,sal_Bool bVsbl,sal_Bool bDelLP,sal_Bool bIsPD)184 	SwRedline(SwRedlineData* pData, const SwPosition& rPos, sal_Bool bVsbl,
185 			   sal_Bool bDelLP, sal_Bool bIsPD) :
186 		SwPaM( rPos ), pRedlineData( pData ), pCntntSect( 0 ),
187 		bDelLastPara( bDelLP ), bIsLastParaDelete( bIsPD ), bIsVisible( bVsbl )
188 	{}
189 	SwRedline( const SwRedline& );
190 	virtual ~SwRedline();
191 
GetContentIdx() const192 	SwNodeIndex* GetContentIdx() const { return pCntntSect; }
193 	// fuers Undo
194 	void SetContentIdx( const SwNodeIndex* );
195 
IsVisible() const196 	sal_Bool IsVisible() const { return bIsVisible; }
IsDelLastPara() const197 	sal_Bool IsDelLastPara() const { return bDelLastPara; }
198 
199 	// das sal_Bool besagt, ob nach dem setzen der Pos kein Bereich mehr
200 	// aufgespannt ist. -> sal_True, ansonten Bereich und sal_False
SetStart(const SwPosition & rPos,SwPosition * pSttPtr=0)201 	void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = 0 )
202 	{
203 		if( !pSttPtr ) pSttPtr = Start();
204 		*pSttPtr = rPos;
205 	}
SetEnd(const SwPosition & rPos,SwPosition * pEndPtr=0)206 	void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = 0 )
207 	{
208 		if( !pEndPtr ) pEndPtr = End();
209 		*pEndPtr = rPos;
210 	}
211 	// liegt eine gueltige Selektion vor?
212 	sal_Bool HasValidRange() const;
213 
214 	const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
operator ==(const SwRedlineData & rCmp) const215 	int operator==( const SwRedlineData& rCmp ) const
216 		{ return *pRedlineData == rCmp; }
operator !=(const SwRedlineData & rCmp) const217 	int operator!=( const SwRedlineData& rCmp ) const
218 		{ return *pRedlineData != rCmp; }
SetAutoFmtFlag()219 	void SetAutoFmtFlag()				{ pRedlineData->SetAutoFmtFlag(); }
220 
221 	sal_uInt16 GetStackCount() const;
222 	sal_uInt16 GetAuthor( sal_uInt16 nPos = 0) const;
223 	const String& GetAuthorString( sal_uInt16 nPos = 0 ) const;
224 	const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
225     RedlineType_t GetRealType( sal_uInt16 nPos = 0 ) const;
GetType(sal_uInt16 nPos=0) const226 	RedlineType_t GetType( sal_uInt16 nPos = 0) const
227   { return ( (RedlineType_t)(GetRealType( nPos ) & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
228 	const String& GetComment( sal_uInt16 nPos = 0 ) const;
229 
SetComment(const String & rS)230 	void SetComment( const String& rS ) { pRedlineData->SetComment( rS ); }
231 
232 	// ExtraData wird kopiert, der Pointer geht also NICHT in den Besitz
233 	// des RedlineObjectes!
SetExtraData(const SwRedlineExtraData * pData)234 	void SetExtraData( const SwRedlineExtraData* pData )
235 		{ pRedlineData->SetExtraData( pData ); }
GetExtraData() const236 	const SwRedlineExtraData* GetExtraData() const
237 		{ return pRedlineData->GetExtraData(); }
238 
239 	// fuers UI-seitige zusammenfassen von Redline-Actionen. Wird z.Z. nur
240 	// fuers Autoformat mit Redline benoetigt. Der Wert != 0 bedeutet dabei,
241 	// das es noch weitere geben kann!
GetSeqNo() const242 	sal_uInt16 GetSeqNo() const 			{ return pRedlineData->GetSeqNo(); }
SetSeqNo(sal_uInt16 nNo)243 	void SetSeqNo( sal_uInt16 nNo ) 		{ pRedlineData->SetSeqNo( nNo ); }
244 
245 	// Beim Hide/ShowOriginal wird 2 mal ueber die Liste gelaufen, damit
246 	//	die Del-Redlines per Copy und Delete versteckt werden. Beim Move
247 	//	wird sonst die Attributierung falsch behandelt.
248 	// Alle anderen Aufrufer muessen immer 0 angeben.
249 	void CallDisplayFunc( sal_uInt16 nLoop = 0 );
250 	void Show( sal_uInt16 nLoop = 0 );
251 	void Hide( sal_uInt16 nLoop = 0 );
252 	void ShowOriginal( sal_uInt16 nLoop = 0 );
253 
254     // calculates the intersection with text node number nNdIdx
255     void CalcStartEnd( sal_uLong nNdIdx, sal_uInt16& nStart, sal_uInt16& nEnd ) const;
256 
257     void InvalidateRange();     // das Layout anstossen
258 
IsOwnRedline(const SwRedline & rRedl) const259 	sal_Bool IsOwnRedline( const SwRedline& rRedl ) const
260 		{ return GetAuthor() == rRedl.GetAuthor(); }
261 	sal_Bool CanCombine( const SwRedline& rRedl ) const;
262 
263 	void PushData( const SwRedline& rRedl, sal_Bool bOwnAsNext = sal_True );
264 	sal_Bool PopData();
265 
266     // #111827#
267     /**
268        Returns textual description of this a redline data element of
269        this redline.
270 
271        @param nPos index of the redline data element to describe
272 
273        The textual description of the selected element contains the
274        kind of redline and the possibly shortened text of the redline.
275 
276        @return textual description of the selected redline data element
277      */
278     String GetDescr(sal_uInt16 nPos = 0);
279 
280 	int operator==( const SwRedline& ) const;
281 	int operator<( const SwRedline& ) const;
282 };
283 
284 class SW_DLLPUBLIC SwRedlineHint : public SfxHint
285 {
286 #define SWREDLINE_INSERTED	1
287 #define SWREDLINE_REMOVED	2
288 #define SWREDLINE_FOCUS		3
289 #define SWREDLINE_CHANGED	4
290 #define SWREDLINE_LANGUAGE	5
291 
292 	const SwRedline* pRedline;
293 	sal_Int16 nWhich;
294 	const SwView* pView;
295 
296 public:
SwRedlineHint(const SwRedline * p,sal_Int16 n,const SwView * pV=0)297 	SwRedlineHint( const SwRedline* p, sal_Int16 n, const SwView* pV = 0)
298 		: pRedline(p)
299 		, nWhich(n)
300 		, pView(pV)
301         {}
302 
303 	TYPEINFO();
GetRedline() const304 	const SwRedline* GetRedline() const { return pRedline; }
Which() const305 	sal_Int16 Which() const { return nWhich; }
GetView() const306         const SwView* GetView() const { return pView; }
307 };
308 
309 
310 #endif
311