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 class ExcXmlRecord
: public ExcRecord
35 virtual sal_Size
GetLen() const override
;
36 virtual sal_uInt16
GetNum() const override
;
37 virtual void Save( XclExpStream
& rStrm
) override
;
40 // XclExpUserBView - one UserBView record for each user
42 class XclExpUserBView
: public ExcRecord
45 XclExpString sUsername
;
46 sal_uInt8 aGUID
[ 16 ];
48 virtual void SaveCont( XclExpStream
& rStrm
) override
;
51 XclExpUserBView( const OUString
& rUsername
, const sal_uInt8
* pGUID
);
53 inline const sal_uInt8
* GetGUID() const { return aGUID
; }
55 virtual sal_uInt16
GetNum() const override
;
56 virtual sal_Size
GetLen() const override
;
59 // XclExpUserBViewList - list of UserBView records
61 class XclExpUserBViewList
: public ExcEmptyRec
64 std::vector
<XclExpUserBView
*> aViews
;
68 typedef std::vector
<XclExpUserBView
*>::iterator iterator
;
69 typedef std::vector
<XclExpUserBView
*>::const_iterator const_iterator
;
71 XclExpUserBViewList( const ScChangeTrack
& rChangeTrack
);
72 virtual ~XclExpUserBViewList();
74 inline iterator
begin () { return aViews
.begin(); }
75 inline iterator
end () { return aViews
.end(); }
77 virtual void Save( XclExpStream
& rStrm
) override
;
80 // XclExpUsersViewBegin - begin of view block (one per sheet)
82 class XclExpUsersViewBegin
: public ExcRecord
85 sal_uInt8 aGUID
[ 16 ];
88 virtual void SaveCont( XclExpStream
& rStrm
) override
;
91 XclExpUsersViewBegin( const sal_uInt8
* pGUID
, sal_uInt32 nTab
);
92 virtual sal_uInt16
GetNum() const override
;
93 virtual sal_Size
GetLen() const override
;
96 // XclExpUsersViewEnd - end of view block (one per sheet)
98 class XclExpUsersViewEnd
: public ExcRecord
101 virtual void SaveCont( XclExpStream
& rStrm
) override
;
104 virtual sal_uInt16
GetNum() const override
;
105 virtual sal_Size
GetLen() const override
;
108 // dummy record for "User Names" stream
110 class XclExpChTr0x0191
: public ExcRecord
113 virtual void SaveCont( XclExpStream
& rStrm
) override
;
116 virtual sal_uInt16
GetNum() const override
;
117 virtual sal_Size
GetLen() const override
;
120 // dummy record for "User Names" stream
122 class XclExpChTr0x0198
: public ExcRecord
125 virtual void SaveCont( XclExpStream
& rStrm
) override
;
128 virtual sal_uInt16
GetNum() const override
;
129 virtual sal_Size
GetLen() const override
;
132 // dummy record for "User Names" stream
134 class XclExpChTr0x0192
: public ExcRecord
137 virtual void SaveCont( XclExpStream
& rStrm
) override
;
140 virtual sal_uInt16
GetNum() const override
;
141 virtual sal_Size
GetLen() const override
;
144 // dummy record for "User Names" stream
146 class XclExpChTr0x0197
: public ExcRecord
149 virtual void SaveCont( XclExpStream
& rStrm
) override
;
152 virtual sal_uInt16
GetNum() const override
;
153 virtual sal_Size
GetLen() const override
;
156 // dummy record without content
158 class XclExpChTrEmpty
: public ExcRecord
164 inline XclExpChTrEmpty( sal_uInt16 nNum
) : nRecNum( nNum
) {}
165 virtual ~XclExpChTrEmpty();
167 virtual sal_uInt16
GetNum() const override
;
168 virtual sal_Size
GetLen() const override
;
171 // dummy record for "Revision Log" stream
173 class XclExpChTr0x0195
: public ExcRecord
176 virtual void SaveCont( XclExpStream
& rStrm
) override
;
179 virtual ~XclExpChTr0x0195();
181 virtual sal_uInt16
GetNum() const override
;
182 virtual sal_Size
GetLen() const override
;
185 // dummy record for "Revision Log" stream
187 class XclExpChTr0x0194
: public ExcRecord
190 XclExpString sUsername
;
193 virtual void SaveCont( XclExpStream
& rStrm
) override
;
196 inline XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
);
197 virtual ~XclExpChTr0x0194();
199 virtual sal_uInt16
GetNum() const override
;
200 virtual sal_Size
GetLen() const override
;
203 inline XclExpChTr0x0194::XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
) :
204 sUsername( rChangeTrack
.GetUser() ),
205 aDateTime( rChangeTrack
.GetFixDateTime() )
209 // XclExpChTrHeader - header record, includes action count
211 class XclExpChTrHeader
: public ExcRecord
214 sal_uInt8 aGUID
[ 16 ];
217 virtual void SaveCont( XclExpStream
& rStrm
) override
;
220 inline XclExpChTrHeader() : nCount( 0 ) {}
221 virtual ~XclExpChTrHeader();
223 inline void SetGUID( const sal_uInt8
* pGUID
) { memcpy( aGUID
, pGUID
, 16 ); }
224 inline void SetCount( sal_uInt32 nNew
) { nCount
= nNew
; }
226 virtual sal_uInt16
GetNum() const override
;
227 virtual sal_Size
GetLen() const override
;
229 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
232 class XclExpXmlChTrHeaders
: public ExcXmlRecord
234 sal_uInt8 maGUID
[16];
236 void SetGUID( const sal_uInt8
* pGUID
);
238 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
241 class XclExpChTrTabIdBuffer
;
242 class XclExpChTrAction
;
244 class XclExpXmlChTrHeader
: public ExcXmlRecord
248 sal_uInt8 maGUID
[16];
249 sal_Int32 mnLogNumber
;
250 sal_uInt32 mnMinAction
;
251 sal_uInt32 mnMaxAction
;
253 std::vector
<sal_uInt16
> maTabBuffer
;
254 std::vector
<std::unique_ptr
<XclExpChTrAction
>> maActions
;
258 const OUString
& rUserName
, const DateTime
& rDateTime
, const sal_uInt8
* pGUID
,
259 sal_Int32 nLogNumber
, const XclExpChTrTabIdBuffer
& rBuf
);
261 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
263 void AppendAction( std::unique_ptr
<XclExpChTrAction
> pAction
);
266 // XclExpChTrInfo - header of action group of a user
268 class XclExpChTrInfo
: public ExcRecord
271 XclExpString sUsername
;
273 sal_uInt8 aGUID
[ 16 ];
275 virtual void SaveCont( XclExpStream
& rStrm
) override
;
278 XclExpChTrInfo( const OUString
& rUsername
, const DateTime
& rDateTime
,
279 const sal_uInt8
* pGUID
);
281 virtual ~XclExpChTrInfo();
283 virtual sal_uInt16
GetNum() const override
;
284 virtual sal_Size
GetLen() const override
;
287 // XclExpChTrTabIdBuffer - buffer for tab id's
289 class XclExpChTrTabIdBuffer
298 XclExpChTrTabIdBuffer( sal_uInt16 nCount
);
299 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer
& rCopy
);
300 ~XclExpChTrTabIdBuffer();
302 void InitFill( sal_uInt16 nIndex
);
305 sal_uInt16
GetId( sal_uInt16 nIndex
) const;
308 inline sal_uInt16
GetBufferCount() const
309 { return static_cast< sal_uInt16
>( (pLast
- pBuffer
) + 1 ); }
310 inline void GetBufferCopy( sal_uInt16
* pDest
) const
311 { memcpy( pDest
, pBuffer
, sizeof(sal_uInt16
) * GetBufferCount() ); }
314 // XclExpChTrTabId - tab id record
316 class XclExpChTrTabId
: public ExcRecord
320 sal_uInt16 nTabCount
;
322 inline void Clear() { delete[] pBuffer
; pBuffer
= nullptr; }
324 virtual void SaveCont( XclExpStream
& rStrm
) override
;
327 inline XclExpChTrTabId( sal_uInt16 nCount
) :
328 pBuffer( nullptr ), nTabCount( nCount
) {}
329 XclExpChTrTabId( const XclExpChTrTabIdBuffer
& rBuffer
);
330 virtual ~XclExpChTrTabId();
332 void Copy( const XclExpChTrTabIdBuffer
& rBuffer
);
334 virtual sal_uInt16
GetNum() const override
;
335 virtual sal_Size
GetLen() const override
;
338 // XclExpChTrAction - base class for action records
340 class XclExpChTrAction
: public ExcRecord
345 sal_uInt32 nIndex
; // action number
346 XclExpChTrAction
* pAddAction
; // additional record for this action
350 const XclExpTabInfo
& rTabInfo
; // for table num export (sc num -> xcl num)
351 const XclExpChTrTabIdBuffer
& rIdBuffer
; // for table num export (xcl num -> tab id)
352 sal_uInt32 nLength
; // this is not the record size
353 sal_uInt16 nOpCode
; // EXC_CHTR_OP_***
356 XclExpChTrAction( const XclExpChTrAction
& rCopy
);
358 void SetAddAction( XclExpChTrAction
* pAction
);
359 void AddDependentContents(
360 const ScChangeAction
& rAction
,
361 const XclExpRoot
& rRoot
,
362 ScChangeTrack
& rChangeTrack
);
364 static inline void Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
);
365 static inline void Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
);
366 inline sal_uInt16
GetTabId( SCTAB nTabId
) const;
367 inline void WriteTabId( XclExpStream
& rStrm
, SCTAB nTabId
) const;
369 // save header data, call SaveActionData()
370 virtual void SaveCont( XclExpStream
& rStrm
) override
;
371 static inline sal_Size
GetHeaderByteCount() { return 12; }
373 // override to save action data without header, called by SaveCont()
374 virtual void SaveActionData( XclExpStream
& rStrm
) const = 0;
375 // override to get action size without header, called by GetLen()
376 virtual sal_Size
GetActionByteCount() const = 0;
378 // do something before writing the record
379 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const;
380 // do something after writing the record
381 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const;
383 inline bool GetAccepted() const { return bAccepted
; }
387 const ScChangeAction
& rAction
,
388 const XclExpRoot
& rRoot
,
389 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
390 sal_uInt16 nNewOpCode
= EXC_CHTR_OP_UNKNOWN
);
391 virtual ~XclExpChTrAction();
393 inline const OUString
& GetUsername() const { return sUsername
; }
394 inline const DateTime
& GetDateTime() const { return aDateTime
; }
395 inline const XclExpChTrTabIdBuffer
& GetTabIdBuffer() const { return rIdBuffer
; }
396 inline bool ForceInfoRecord() const { return bForceInfo
; }
398 // set own index & return new index
399 // could override to use more indexes per action
400 void SetIndex( sal_uInt32
& rIndex
);
402 virtual void Save( XclExpStream
& rStrm
) override
;
403 virtual sal_Size
GetLen() const override
;
405 inline XclExpChTrAction
* GetAddAction() { return pAddAction
; }
406 inline sal_uInt32
GetActionNumber() const { return nIndex
; }
409 inline void XclExpChTrAction::Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
)
411 rStrm
<< (sal_uInt16
) rAddress
.Row()
412 << (sal_uInt16
) rAddress
.Col();
415 inline void XclExpChTrAction::Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
)
417 rStrm
<< (sal_uInt16
) rRange
.aStart
.Row()
418 << (sal_uInt16
) rRange
.aEnd
.Row()
419 << (sal_uInt16
) rRange
.aStart
.Col()
420 << (sal_uInt16
) rRange
.aEnd
.Col();
423 inline sal_uInt16
XclExpChTrAction::GetTabId( SCTAB nTab
) const
425 return rIdBuffer
.GetId( rTabInfo
.GetXclTab( nTab
) );
428 inline void XclExpChTrAction::WriteTabId( XclExpStream
& rStrm
, SCTAB nTab
) const
430 rStrm
<< GetTabId( nTab
);
433 // XclExpChTrData - cell content itself
435 struct XclExpChTrData
437 XclExpString
* pString
;
438 XclExpStringRef mpFormattedString
;
439 const ScFormulaCell
* mpFormulaCell
;
440 XclTokenArrayRef mxTokArr
;
441 XclExpRefLog maRefLog
;
453 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
456 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
459 // XclExpChTrCellContent - changed cell content
461 class XclExpChTrCellContent
: public XclExpChTrAction
, protected XclExpRoot
464 XclExpChTrData
* pOldData
;
465 XclExpChTrData
* pNewData
;
466 sal_uInt16 nOldLength
; // this is not the record size
468 static void MakeEmptyChTrData( XclExpChTrData
*& rpData
);
474 const XclExpRoot
& rRoot
, const ScCellValue
& rScCell
, XclExpChTrData
*& rpData
,
475 sal_uInt32
& rXclLength1
, sal_uInt16
& rXclLength2
);
477 virtual void SaveActionData( XclExpStream
& rStrm
) const override
;
480 XclExpChTrCellContent(
481 const ScChangeActionContent
& rAction
,
482 const XclExpRoot
& rRoot
,
483 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
484 virtual ~XclExpChTrCellContent();
486 virtual sal_uInt16
GetNum() const override
;
487 virtual sal_Size
GetActionByteCount() const override
;
489 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
492 // XclExpChTrInsert - insert/delete columns/rows
494 class XclExpChTrInsert
: public XclExpChTrAction
501 XclExpChTrInsert( const XclExpChTrInsert
& rCopy
);
503 virtual void SaveActionData( XclExpStream
& rStrm
) const override
;
504 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const override
;
505 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const override
;
509 const ScChangeAction
& rAction
,
510 const XclExpRoot
& rRoot
,
511 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
512 ScChangeTrack
& rChangeTrack
);
513 virtual ~XclExpChTrInsert();
515 virtual sal_uInt16
GetNum() const override
;
516 virtual sal_Size
GetActionByteCount() const override
;
518 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
521 // XclExpChTrInsertTab - insert table
523 class XclExpChTrInsertTab
: public XclExpChTrAction
, protected XclExpRoot
529 virtual void SaveActionData( XclExpStream
& rStrm
) const override
;
533 const ScChangeAction
& rAction
,
534 const XclExpRoot
& rRoot
,
535 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
536 virtual ~XclExpChTrInsertTab();
538 virtual sal_uInt16
GetNum() const override
;
539 virtual sal_Size
GetActionByteCount() const override
;
541 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
544 // XclExpChTrMoveRange - move cell range
546 class XclExpChTrMoveRange
: public XclExpChTrAction
549 ScRange aSourceRange
;
552 virtual void SaveActionData( XclExpStream
& rStrm
) const override
;
553 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const override
;
554 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const override
;
558 const ScChangeActionMove
& rAction
,
559 const XclExpRoot
& rRoot
,
560 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
561 ScChangeTrack
& rChangeTrack
);
562 virtual ~XclExpChTrMoveRange();
564 virtual sal_uInt16
GetNum() const override
;
565 virtual sal_Size
GetActionByteCount() const override
;
567 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
570 // XclExpChTr0x019A - additional data for delete action
572 class XclExpChTr0x014A
: public XclExpChTrInsert
575 virtual void SaveActionData( XclExpStream
& rStrm
) const override
;
578 XclExpChTr0x014A( const XclExpChTrInsert
& rAction
);
579 virtual ~XclExpChTr0x014A();
581 virtual sal_uInt16
GetNum() const override
;
582 virtual sal_Size
GetActionByteCount() const override
;
584 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
587 // XclExpChangeTrack - exports the "Revision Log" stream
589 class XclExpChangeTrack
: protected XclExpRoot
591 typedef std::vector
<std::unique_ptr
<ExcRecord
>> RecListType
;
592 typedef std::vector
<std::unique_ptr
<XclExpChTrTabIdBuffer
>> TabIdBufferType
;
593 RecListType maRecList
; // list of "Revision Log" stream records
594 std::stack
<XclExpChTrAction
*> aActionStack
;
595 XclExpChTrTabIdBuffer
* pTabIdBuffer
;
596 TabIdBufferType maBuffers
;
598 ScDocument
* pTempDoc
; // empty document
600 XclExpChTrHeader
* pHeader
; // header record for last GUID
601 sal_uInt8 aGUID
[ 16 ]; // GUID for action info records
604 ScChangeTrack
* CreateTempChangeTrack();
605 void PushActionRecord( const ScChangeAction
& rAction
);
607 bool WriteUserNamesStream();
610 XclExpChangeTrack( const XclExpRoot
& rRoot
);
611 virtual ~XclExpChangeTrack();
614 void WriteXml( XclExpXmlStream
& rStrm
);
619 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */