1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XCLEXPCHANGETRACK_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XCLEXPCHANGETRACK_HXX
24 #include <tools/datetime.hxx>
26 #include "bigrange.hxx"
27 #include "chgtrack.hxx"
30 #include "excrecds.hxx"
32 #include <boost/ptr_container/ptr_vector.hpp>
34 class ExcXmlRecord
: public ExcRecord
37 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
38 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
39 virtual void Save( XclExpStream
& rStrm
) SAL_OVERRIDE
;
42 // XclExpUserBView - one UserBView record for each user
44 class XclExpUserBView
: public ExcRecord
47 XclExpString sUsername
;
48 sal_uInt8 aGUID
[ 16 ];
50 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
53 XclExpUserBView( const OUString
& rUsername
, const sal_uInt8
* pGUID
);
55 inline const sal_uInt8
* GetGUID() const { return aGUID
; }
57 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
58 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
61 // XclExpUserBViewList - list of UserBView records
63 class XclExpUserBViewList
: public ExcEmptyRec
66 std::vector
<XclExpUserBView
*> aViews
;
70 typedef std::vector
<XclExpUserBView
*>::iterator iterator
;
71 typedef std::vector
<XclExpUserBView
*>::const_iterator const_iterator
;
73 XclExpUserBViewList( const ScChangeTrack
& rChangeTrack
);
74 virtual ~XclExpUserBViewList();
76 inline iterator
begin () { return aViews
.begin(); }
78 inline iterator
end () { return aViews
.end(); }
80 inline const_iterator
begin () const { return aViews
.begin(); }
82 inline const_iterator
end () const { return aViews
.end(); }
84 virtual void Save( XclExpStream
& rStrm
) SAL_OVERRIDE
;
87 // XclExpUsersViewBegin - begin of view block (one per sheet)
89 class XclExpUsersViewBegin
: public ExcRecord
92 sal_uInt8 aGUID
[ 16 ];
95 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
98 XclExpUsersViewBegin( const sal_uInt8
* pGUID
, sal_uInt32 nTab
);
99 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
100 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
103 // XclExpUsersViewEnd - end of view block (one per sheet)
105 class XclExpUsersViewEnd
: public ExcRecord
108 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
111 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
112 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
115 // dummy record for "User Names" stream
117 class XclExpChTr0x0191
: public ExcRecord
120 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
123 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
124 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
127 // dummy record for "User Names" stream
129 class XclExpChTr0x0198
: public ExcRecord
132 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
135 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
136 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
139 // dummy record for "User Names" stream
141 class XclExpChTr0x0192
: public ExcRecord
144 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
147 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
148 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
151 // dummy record for "User Names" stream
153 class XclExpChTr0x0197
: public ExcRecord
156 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
159 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
160 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
163 // dummy record without content
165 class XclExpChTrEmpty
: public ExcRecord
171 inline XclExpChTrEmpty( sal_uInt16 nNum
) : nRecNum( nNum
) {}
172 virtual ~XclExpChTrEmpty();
174 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
175 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
178 // dummy record for "Revision Log" stream
180 class XclExpChTr0x0195
: public ExcRecord
183 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
186 virtual ~XclExpChTr0x0195();
188 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
189 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
192 // dummy record for "Revision Log" stream
194 class XclExpChTr0x0194
: public ExcRecord
197 XclExpString sUsername
;
200 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
203 inline XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
);
204 virtual ~XclExpChTr0x0194();
206 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
207 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
210 inline XclExpChTr0x0194::XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
) :
211 sUsername( rChangeTrack
.GetUser() ),
212 aDateTime( rChangeTrack
.GetFixDateTime() )
216 // XclExpChTrHeader - header record, includes action count
218 class XclExpChTrHeader
: public ExcRecord
221 sal_uInt8 aGUID
[ 16 ];
224 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
227 inline XclExpChTrHeader() : nCount( 0 ) {}
228 virtual ~XclExpChTrHeader();
230 inline void SetGUID( const sal_uInt8
* pGUID
) { memcpy( aGUID
, pGUID
, 16 ); }
231 inline void SetCount( sal_uInt32 nNew
) { nCount
= nNew
; }
233 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
234 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
236 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
239 class XclExpXmlChTrHeaders
: public ExcXmlRecord
241 sal_uInt8 maGUID
[16];
243 void SetGUID( const sal_uInt8
* pGUID
);
245 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
248 class XclExpChTrTabIdBuffer
;
249 class XclExpChTrAction
;
251 class XclExpXmlChTrHeader
: public ExcXmlRecord
255 sal_uInt8 maGUID
[16];
256 sal_Int32 mnLogNumber
;
257 sal_uInt32 mnMinAction
;
258 sal_uInt32 mnMaxAction
;
260 std::vector
<sal_uInt16
> maTabBuffer
;
261 std::vector
<XclExpChTrAction
*> maActions
;
265 const OUString
& rUserName
, const DateTime
& rDateTime
, const sal_uInt8
* pGUID
,
266 sal_Int32 nLogNumber
, const XclExpChTrTabIdBuffer
& rBuf
);
268 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
270 void AppendAction( XclExpChTrAction
* pAction
);
273 // XclExpChTrInfo - header of action group of a user
275 class XclExpChTrInfo
: public ExcRecord
278 XclExpString sUsername
;
280 sal_uInt8 aGUID
[ 16 ];
282 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
285 XclExpChTrInfo( const OUString
& rUsername
, const DateTime
& rDateTime
,
286 const sal_uInt8
* pGUID
);
288 virtual ~XclExpChTrInfo();
290 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
291 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
294 // XclExpChTrTabIdBuffer - buffer for tab id's
296 class XclExpChTrTabIdBuffer
305 XclExpChTrTabIdBuffer( sal_uInt16 nCount
);
306 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer
& rCopy
);
307 ~XclExpChTrTabIdBuffer();
309 void InitFill( sal_uInt16 nIndex
);
312 sal_uInt16
GetId( sal_uInt16 nIndex
) const;
315 inline sal_uInt16
GetBufferCount() const
316 { return static_cast< sal_uInt16
>( (pLast
- pBuffer
) + 1 ); }
317 inline void GetBufferCopy( sal_uInt16
* pDest
) const
318 { memcpy( pDest
, pBuffer
, sizeof(sal_uInt16
) * GetBufferCount() ); }
321 // XclExpChTrTabId - tab id record
323 class XclExpChTrTabId
: public ExcRecord
327 sal_uInt16 nTabCount
;
329 inline void Clear() { if( pBuffer
) delete[] pBuffer
; pBuffer
= NULL
; }
331 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
334 inline XclExpChTrTabId( sal_uInt16 nCount
) :
335 pBuffer( NULL
), nTabCount( nCount
) {}
336 XclExpChTrTabId( const XclExpChTrTabIdBuffer
& rBuffer
);
337 virtual ~XclExpChTrTabId();
339 void Copy( const XclExpChTrTabIdBuffer
& rBuffer
);
341 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
342 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
345 // XclExpChTrAction - base class for action records
347 class XclExpChTrAction
: public ExcRecord
352 sal_uInt32 nIndex
; // action number
353 XclExpChTrAction
* pAddAction
; // additional record for this action
357 const XclExpTabInfo
& rTabInfo
; // for table num export (sc num -> xcl num)
358 const XclExpChTrTabIdBuffer
& rIdBuffer
; // for table num export (xcl num -> tab id)
359 sal_uInt32 nLength
; // this is not the record size
360 sal_uInt16 nOpCode
; // EXC_CHTR_OP_***
363 XclExpChTrAction( const XclExpChTrAction
& rCopy
);
365 void SetAddAction( XclExpChTrAction
* pAction
);
366 void AddDependentContents(
367 const ScChangeAction
& rAction
,
368 const XclExpRoot
& rRoot
,
369 ScChangeTrack
& rChangeTrack
);
371 static inline void Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
);
372 static inline void Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
);
373 inline sal_uInt16
GetTabId( SCTAB nTabId
) const;
374 inline void WriteTabId( XclExpStream
& rStrm
, SCTAB nTabId
) const;
376 // save header data, call SaveActionData()
377 virtual void SaveCont( XclExpStream
& rStrm
) SAL_OVERRIDE
;
378 static inline sal_Size
GetHeaderByteCount() { return 12; }
380 // override to save action data without header, called by SaveCont()
381 virtual void SaveActionData( XclExpStream
& rStrm
) const = 0;
382 // override to get action size without header, called by GetLen()
383 virtual sal_Size
GetActionByteCount() const = 0;
385 // do something before writing the record
386 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const;
387 // do something after writing the record
388 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const;
390 inline bool GetAccepted() const { return bAccepted
; }
394 const ScChangeAction
& rAction
,
395 const XclExpRoot
& rRoot
,
396 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
397 sal_uInt16 nNewOpCode
= EXC_CHTR_OP_UNKNOWN
);
398 virtual ~XclExpChTrAction();
400 inline const OUString
& GetUsername() const { return sUsername
; }
401 inline const DateTime
& GetDateTime() const { return aDateTime
; }
402 inline const XclExpChTrTabIdBuffer
& GetTabIdBuffer() const { return rIdBuffer
; }
403 inline bool ForceInfoRecord() const { return bForceInfo
; }
405 // set own index & return new index
406 // could override to use more indexes per action
407 void SetIndex( sal_uInt32
& rIndex
);
409 virtual void Save( XclExpStream
& rStrm
) SAL_OVERRIDE
;
410 virtual sal_Size
GetLen() const SAL_OVERRIDE
;
412 inline XclExpChTrAction
* GetAddAction() { return pAddAction
; }
413 inline sal_uInt32
GetActionNumber() const { return nIndex
; }
416 inline void XclExpChTrAction::Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
)
418 rStrm
<< (sal_uInt16
) rAddress
.Row()
419 << (sal_uInt16
) rAddress
.Col();
422 inline void XclExpChTrAction::Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
)
424 rStrm
<< (sal_uInt16
) rRange
.aStart
.Row()
425 << (sal_uInt16
) rRange
.aEnd
.Row()
426 << (sal_uInt16
) rRange
.aStart
.Col()
427 << (sal_uInt16
) rRange
.aEnd
.Col();
430 inline sal_uInt16
XclExpChTrAction::GetTabId( SCTAB nTab
) const
432 return rIdBuffer
.GetId( rTabInfo
.GetXclTab( nTab
) );
435 inline void XclExpChTrAction::WriteTabId( XclExpStream
& rStrm
, SCTAB nTab
) const
437 rStrm
<< GetTabId( nTab
);
440 // XclExpChTrData - cell content itself
442 struct XclExpChTrData
444 XclExpString
* pString
;
445 XclExpStringRef mpFormattedString
;
446 const ScFormulaCell
* mpFormulaCell
;
447 XclTokenArrayRef mxTokArr
;
448 XclExpRefLog maRefLog
;
460 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
463 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
466 // XclExpChTrCellContent - changed cell content
468 class XclExpChTrCellContent
: public XclExpChTrAction
, protected XclExpRoot
471 XclExpChTrData
* pOldData
;
472 XclExpChTrData
* pNewData
;
473 sal_uInt16 nOldLength
; // this is not the record size
475 static void MakeEmptyChTrData( XclExpChTrData
*& rpData
);
481 const XclExpRoot
& rRoot
, const ScCellValue
& rScCell
, XclExpChTrData
*& rpData
,
482 sal_uInt32
& rXclLength1
, sal_uInt16
& rXclLength2
);
484 virtual void SaveActionData( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
487 XclExpChTrCellContent(
488 const ScChangeActionContent
& rAction
,
489 const XclExpRoot
& rRoot
,
490 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
491 virtual ~XclExpChTrCellContent();
493 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
494 virtual sal_Size
GetActionByteCount() const SAL_OVERRIDE
;
496 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
499 // XclExpChTrInsert - insert/delete columns/rows
501 class XclExpChTrInsert
: public XclExpChTrAction
508 XclExpChTrInsert( const XclExpChTrInsert
& rCopy
);
510 virtual void SaveActionData( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
511 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
512 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
516 const ScChangeAction
& rAction
,
517 const XclExpRoot
& rRoot
,
518 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
519 ScChangeTrack
& rChangeTrack
);
520 virtual ~XclExpChTrInsert();
522 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
523 virtual sal_Size
GetActionByteCount() const SAL_OVERRIDE
;
525 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
528 // XclExpChTrInsertTab - insert table
530 class XclExpChTrInsertTab
: public XclExpChTrAction
, protected XclExpRoot
536 virtual void SaveActionData( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
540 const ScChangeAction
& rAction
,
541 const XclExpRoot
& rRoot
,
542 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
543 virtual ~XclExpChTrInsertTab();
545 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
546 virtual sal_Size
GetActionByteCount() const SAL_OVERRIDE
;
548 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
551 // XclExpChTrMoveRange - move cell range
553 class XclExpChTrMoveRange
: public XclExpChTrAction
556 ScRange aSourceRange
;
559 virtual void SaveActionData( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
560 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
561 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
565 const ScChangeActionMove
& rAction
,
566 const XclExpRoot
& rRoot
,
567 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
568 ScChangeTrack
& rChangeTrack
);
569 virtual ~XclExpChTrMoveRange();
571 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
572 virtual sal_Size
GetActionByteCount() const SAL_OVERRIDE
;
574 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
577 // XclExpChTr0x019A - additional data for delete action
579 class XclExpChTr0x014A
: public XclExpChTrInsert
582 virtual void SaveActionData( XclExpStream
& rStrm
) const SAL_OVERRIDE
;
585 XclExpChTr0x014A( const XclExpChTrInsert
& rAction
);
586 virtual ~XclExpChTr0x014A();
588 virtual sal_uInt16
GetNum() const SAL_OVERRIDE
;
589 virtual sal_Size
GetActionByteCount() const SAL_OVERRIDE
;
591 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
594 // XclExpChangeTrack - exports the "Revision Log" stream
596 class XclExpChangeTrack
: protected XclExpRoot
598 typedef boost::ptr_vector
<ExcRecord
> RecListType
;
599 typedef boost::ptr_vector
<XclExpChTrTabIdBuffer
> TabIdBufferType
;
600 RecListType maRecList
; // list of "Revision Log" stream records
601 std::stack
<XclExpChTrAction
*> aActionStack
;
602 XclExpChTrTabIdBuffer
* pTabIdBuffer
;
603 TabIdBufferType maBuffers
;
605 ScDocument
* pTempDoc
; // empty document
607 XclExpChTrHeader
* pHeader
; // header record for last GUID
608 sal_uInt8 aGUID
[ 16 ]; // GUID for action info records
611 ScChangeTrack
* CreateTempChangeTrack();
612 void PushActionRecord( const ScChangeAction
& rAction
);
614 bool WriteUserNamesStream();
617 XclExpChangeTrack( const XclExpRoot
& rRoot
);
618 virtual ~XclExpChangeTrack();
621 void WriteXml( XclExpXmlStream
& rStrm
);
626 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */