Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / XclExpChangeTrack.hxx
blob50e46cd0df827d6d2580a5f6711006c8a1f499d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <memory>
24 #include <stack>
25 #include <tools/datetime.hxx>
26 #include <chgtrack.hxx>
27 #include <document.hxx>
28 #include "xelink.hxx"
29 #include "xestring.hxx"
30 #include "excrecds.hxx"
31 #include "xlformula.hxx"
32 #include "xeformula.hxx"
34 class ExcXmlRecord : public ExcRecord
36 public:
37 virtual std::size_t GetLen() const override;
38 virtual sal_uInt16 GetNum() const override;
39 virtual void Save( XclExpStream& rStrm ) override;
42 // XclExpUserBView - one UserBView record for each user
44 class XclExpUserBView : public ExcRecord
46 private:
47 XclExpString const sUsername;
48 sal_uInt8 aGUID[ 16 ];
50 virtual void SaveCont( XclExpStream& rStrm ) override;
52 public:
53 XclExpUserBView( const OUString& rUsername, const sal_uInt8* pGUID );
55 const sal_uInt8* GetGUID() const { return aGUID; }
57 virtual sal_uInt16 GetNum() const override;
58 virtual std::size_t GetLen() const override;
61 // XclExpUserBViewList - list of UserBView records
63 class XclExpUserBViewList : public ExcEmptyRec
65 private:
66 std::vector<XclExpUserBView> aViews;
68 public:
70 typedef std::vector<XclExpUserBView>::const_iterator const_iterator;
72 XclExpUserBViewList( const ScChangeTrack& rChangeTrack );
73 virtual ~XclExpUserBViewList() override;
75 const_iterator cbegin () { return aViews.cbegin(); }
76 const_iterator cend () { return aViews.cend(); }
78 virtual void Save( XclExpStream& rStrm ) override;
81 // XclExpUsersViewBegin - begin of view block (one per sheet)
83 class XclExpUsersViewBegin : public ExcRecord
85 private:
86 sal_uInt8 aGUID[ 16 ];
87 sal_uInt32 nCurrTab;
89 virtual void SaveCont( XclExpStream& rStrm ) override;
91 public:
92 XclExpUsersViewBegin( const sal_uInt8* pGUID, sal_uInt32 nTab );
93 virtual sal_uInt16 GetNum() const override;
94 virtual std::size_t GetLen() const override;
97 // XclExpUsersViewEnd - end of view block (one per sheet)
99 class XclExpUsersViewEnd : public ExcRecord
101 private:
102 virtual void SaveCont( XclExpStream& rStrm ) override;
104 public:
105 virtual sal_uInt16 GetNum() const override;
106 virtual std::size_t GetLen() const override;
109 // dummy record for "User Names" stream
111 class XclExpChTr0x0191 : public ExcRecord
113 private:
114 virtual void SaveCont( XclExpStream& rStrm ) override;
116 public:
117 virtual sal_uInt16 GetNum() const override;
118 virtual std::size_t GetLen() const override;
121 // dummy record for "User Names" stream
123 class XclExpChTr0x0198 : public ExcRecord
125 private:
126 virtual void SaveCont( XclExpStream& rStrm ) override;
128 public:
129 virtual sal_uInt16 GetNum() const override;
130 virtual std::size_t GetLen() const override;
133 // dummy record for "User Names" stream
135 class XclExpChTr0x0192 : public ExcRecord
137 private:
138 virtual void SaveCont( XclExpStream& rStrm ) override;
140 public:
141 virtual sal_uInt16 GetNum() const override;
142 virtual std::size_t GetLen() const override;
145 // dummy record for "User Names" stream
147 class XclExpChTr0x0197 : public ExcRecord
149 private:
150 virtual void SaveCont( XclExpStream& rStrm ) override;
152 public:
153 virtual sal_uInt16 GetNum() const override;
154 virtual std::size_t GetLen() const override;
157 // dummy record without content
159 class XclExpChTrEmpty : public ExcRecord
161 private:
162 sal_uInt16 const nRecNum;
164 public:
165 XclExpChTrEmpty( sal_uInt16 nNum ) : nRecNum( nNum ) {}
166 virtual ~XclExpChTrEmpty() override;
168 virtual sal_uInt16 GetNum() const override;
169 virtual std::size_t GetLen() const override;
172 // dummy record for "Revision Log" stream
174 class XclExpChTr0x0195 : public ExcRecord
176 private:
177 virtual void SaveCont( XclExpStream& rStrm ) override;
179 public:
180 virtual ~XclExpChTr0x0195() override;
182 virtual sal_uInt16 GetNum() const override;
183 virtual std::size_t GetLen() const override;
186 // dummy record for "Revision Log" stream
188 class XclExpChTr0x0194 : public ExcRecord
190 private:
191 XclExpString const sUsername;
192 DateTime const aDateTime;
194 virtual void SaveCont( XclExpStream& rStrm ) override;
196 public:
197 inline XclExpChTr0x0194( const ScChangeTrack& rChangeTrack );
198 virtual ~XclExpChTr0x0194() override;
200 virtual sal_uInt16 GetNum() const override;
201 virtual std::size_t GetLen() const override;
204 inline XclExpChTr0x0194::XclExpChTr0x0194( const ScChangeTrack& rChangeTrack ) :
205 sUsername( rChangeTrack.GetUser() ),
206 aDateTime( rChangeTrack.GetFixDateTime() )
210 // XclExpChTrHeader - header record, includes action count
212 class XclExpChTrHeader : public ExcRecord
214 private:
215 sal_uInt8 aGUID[ 16 ];
216 sal_uInt32 nCount;
218 virtual void SaveCont( XclExpStream& rStrm ) override;
220 public:
221 XclExpChTrHeader() : nCount( 0 ) {}
222 virtual ~XclExpChTrHeader() override;
224 void SetGUID( const sal_uInt8* pGUID ) { memcpy( aGUID, pGUID, 16 ); }
225 void SetCount( sal_uInt32 nNew ) { nCount = nNew; }
227 virtual sal_uInt16 GetNum() const override;
228 virtual std::size_t GetLen() const override;
230 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
233 class XclExpXmlChTrHeaders : public ExcXmlRecord
235 sal_uInt8 maGUID[16];
236 public:
237 void SetGUID( const sal_uInt8* pGUID );
239 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
242 class XclExpChTrTabIdBuffer;
243 class XclExpChTrAction;
245 class XclExpXmlChTrHeader : public ExcXmlRecord
247 OUString const maUserName;
248 DateTime const maDateTime;
249 sal_uInt8 maGUID[16];
250 sal_Int32 const mnLogNumber;
251 sal_uInt32 mnMinAction;
252 sal_uInt32 mnMaxAction;
254 std::vector<sal_uInt16> maTabBuffer;
255 std::vector<std::unique_ptr<XclExpChTrAction>> maActions;
257 public:
258 XclExpXmlChTrHeader(
259 const OUString& rUserName, const DateTime& rDateTime, const sal_uInt8* pGUID,
260 sal_Int32 nLogNumber, const XclExpChTrTabIdBuffer& rBuf );
262 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
264 void AppendAction( std::unique_ptr<XclExpChTrAction> pAction );
267 // XclExpChTrInfo - header of action group of a user
269 class XclExpChTrInfo : public ExcRecord
271 private:
272 XclExpString const sUsername;
273 DateTime const aDateTime;
274 sal_uInt8 aGUID[ 16 ];
276 virtual void SaveCont( XclExpStream& rStrm ) override;
278 public:
279 XclExpChTrInfo( const OUString& rUsername, const DateTime& rDateTime,
280 const sal_uInt8* pGUID );
282 virtual ~XclExpChTrInfo() override;
284 virtual sal_uInt16 GetNum() const override;
285 virtual std::size_t GetLen() const override;
288 // XclExpChTrTabIdBuffer - buffer for tab id's
290 class XclExpChTrTabIdBuffer
292 private:
293 std::unique_ptr<sal_uInt16[]>
294 pBuffer;
295 sal_uInt16* pLast;
296 sal_uInt16 const nBufSize;
297 sal_uInt16 nLastId;
299 public:
300 XclExpChTrTabIdBuffer( sal_uInt16 nCount );
301 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer& rCopy );
302 ~XclExpChTrTabIdBuffer();
304 void InitFill( sal_uInt16 nIndex );
305 void InitFillup();
307 sal_uInt16 GetId( sal_uInt16 nIndex ) const;
308 void Remove();
310 sal_uInt16 GetBufferCount() const
311 { return static_cast< sal_uInt16 >( (pLast - pBuffer.get()) + 1 ); }
312 void GetBufferCopy( sal_uInt16* pDest ) const
313 { memcpy( pDest, pBuffer.get(), sizeof(sal_uInt16) * GetBufferCount() ); }
316 // XclExpChTrTabId - tab id record
318 class XclExpChTrTabId : public ExcRecord
320 private:
321 std::unique_ptr<sal_uInt16[]> pBuffer;
322 sal_uInt16 nTabCount;
324 void Clear() { pBuffer.reset(); }
326 virtual void SaveCont( XclExpStream& rStrm ) override;
328 public:
329 XclExpChTrTabId( sal_uInt16 nCount ) : nTabCount( nCount ) {}
330 XclExpChTrTabId( const XclExpChTrTabIdBuffer& rBuffer );
331 virtual ~XclExpChTrTabId() override;
333 void Copy( const XclExpChTrTabIdBuffer& rBuffer );
335 virtual sal_uInt16 GetNum() const override;
336 virtual std::size_t GetLen() const override;
339 // XclExpChTrAction - base class for action records
341 class XclExpChTrAction : public ExcRecord
343 private:
344 OUString const sUsername;
345 DateTime aDateTime;
346 sal_uInt32 nIndex; // action number
347 std::unique_ptr<XclExpChTrAction>
348 pAddAction; // additional record for this action
349 bool const bAccepted;
351 protected:
352 const XclExpTabInfo& rTabInfo; // for table num export (sc num -> xcl num)
353 const XclExpChTrTabIdBuffer& rIdBuffer; // for table num export (xcl num -> tab id)
354 sal_uInt32 nLength; // this is not the record size
355 sal_uInt16 nOpCode; // EXC_CHTR_OP_***
356 bool bForceInfo;
358 XclExpChTrAction( const XclExpChTrAction& rCopy );
360 void SetAddAction( XclExpChTrAction* pAction );
361 void AddDependentContents(
362 const ScChangeAction& rAction,
363 const XclExpRoot& rRoot,
364 const ScChangeTrack& rChangeTrack );
366 static inline void Write2DAddress( XclExpStream& rStrm, const ScAddress& rAddress );
367 static inline void Write2DRange( XclExpStream& rStrm, const ScRange& rRange );
368 inline sal_uInt16 GetTabId( SCTAB nTabId ) const;
369 inline void WriteTabId( XclExpStream& rStrm, SCTAB nTabId ) const;
371 // save header data, call SaveActionData()
372 virtual void SaveCont( XclExpStream& rStrm ) override;
373 static std::size_t GetHeaderByteCount() { return 12; }
375 // override to save action data without header, called by SaveCont()
376 virtual void SaveActionData( XclExpStream& rStrm ) const = 0;
377 // override to get action size without header, called by GetLen()
378 virtual std::size_t GetActionByteCount() const = 0;
380 // do something before writing the record
381 virtual void PrepareSaveAction( XclExpStream& rStrm ) const;
382 // do something after writing the record
383 virtual void CompleteSaveAction( XclExpStream& rStrm ) const;
385 bool GetAccepted() const { return bAccepted; }
387 public:
388 XclExpChTrAction(
389 const ScChangeAction& rAction,
390 const XclExpRoot& rRoot,
391 const XclExpChTrTabIdBuffer& rTabIdBuffer,
392 sal_uInt16 nNewOpCode = EXC_CHTR_OP_UNKNOWN );
393 virtual ~XclExpChTrAction() override;
395 const OUString& GetUsername() const { return sUsername; }
396 const DateTime& GetDateTime() const { return aDateTime; }
397 const XclExpChTrTabIdBuffer& GetTabIdBuffer() const { return rIdBuffer; }
398 bool ForceInfoRecord() const { return bForceInfo; }
400 // set own index & return new index
401 // could override to use more indexes per action
402 void SetIndex( sal_uInt32& rIndex );
404 virtual void Save( XclExpStream& rStrm ) override;
405 virtual std::size_t GetLen() const override;
407 XclExpChTrAction* GetAddAction() { return pAddAction.get(); }
408 sal_uInt32 GetActionNumber() const { return nIndex; }
411 inline void XclExpChTrAction::Write2DAddress( XclExpStream& rStrm, const ScAddress& rAddress )
413 rStrm << static_cast<sal_uInt16>(rAddress.Row())
414 << static_cast<sal_uInt16>(rAddress.Col());
417 inline void XclExpChTrAction::Write2DRange( XclExpStream& rStrm, const ScRange& rRange )
419 rStrm << static_cast<sal_uInt16>(rRange.aStart.Row())
420 << static_cast<sal_uInt16>(rRange.aEnd.Row())
421 << static_cast<sal_uInt16>(rRange.aStart.Col())
422 << static_cast<sal_uInt16>(rRange.aEnd.Col());
425 inline sal_uInt16 XclExpChTrAction::GetTabId( SCTAB nTab ) const
427 return rIdBuffer.GetId( rTabInfo.GetXclTab( nTab ) );
430 inline void XclExpChTrAction::WriteTabId( XclExpStream& rStrm, SCTAB nTab ) const
432 rStrm << GetTabId( nTab );
435 // XclExpChTrData - cell content itself
437 struct XclExpChTrData
439 std::unique_ptr<XclExpString> pString;
440 XclExpStringRef mpFormattedString;
441 const ScFormulaCell* mpFormulaCell;
442 XclTokenArrayRef mxTokArr;
443 XclExpRefLog maRefLog;
444 double fValue;
445 sal_Int32 nRKValue;
446 sal_uInt16 nType;
447 std::size_t nSize;
449 XclExpChTrData();
450 ~XclExpChTrData();
451 void Clear();
453 void WriteFormula(
454 XclExpStream& rStrm,
455 const XclExpChTrTabIdBuffer& rTabIdBuffer );
456 void Write(
457 XclExpStream& rStrm,
458 const XclExpChTrTabIdBuffer& rTabIdBuffer );
461 // XclExpChTrCellContent - changed cell content
463 class XclExpChTrCellContent final : public XclExpChTrAction, protected XclExpRoot
465 std::unique_ptr<XclExpChTrData> pOldData;
466 std::unique_ptr<XclExpChTrData> pNewData;
467 sal_uInt16 nOldLength; // this is not the record size
468 ScAddress const aPosition;
470 static void MakeEmptyChTrData( std::unique_ptr<XclExpChTrData>& rpData );
472 void GetCellData(
473 const XclExpRoot& rRoot, const ScCellValue& rScCell, std::unique_ptr<XclExpChTrData>& rpData,
474 sal_uInt32& rXclLength1, sal_uInt16& rXclLength2 );
476 virtual void SaveActionData( XclExpStream& rStrm ) const override;
478 public:
479 XclExpChTrCellContent(
480 const ScChangeActionContent& rAction,
481 const XclExpRoot& rRoot,
482 const XclExpChTrTabIdBuffer& rTabIdBuffer );
483 virtual ~XclExpChTrCellContent() override;
485 virtual sal_uInt16 GetNum() const override;
486 virtual std::size_t GetActionByteCount() const override;
488 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
491 // XclExpChTrInsert - insert/delete columns/rows
493 class XclExpChTrInsert : public XclExpChTrAction
495 bool mbEndOfList;
497 protected:
498 ScRange aRange;
500 XclExpChTrInsert( const XclExpChTrInsert& rCopy );
502 virtual void SaveActionData( XclExpStream& rStrm ) const override;
503 virtual void PrepareSaveAction( XclExpStream& rStrm ) const override;
504 virtual void CompleteSaveAction( XclExpStream& rStrm ) const override;
506 public:
507 XclExpChTrInsert(
508 const ScChangeAction& rAction,
509 const XclExpRoot& rRoot,
510 const XclExpChTrTabIdBuffer& rTabIdBuffer,
511 const ScChangeTrack& rChangeTrack );
512 virtual ~XclExpChTrInsert() override;
514 virtual sal_uInt16 GetNum() const override;
515 virtual std::size_t GetActionByteCount() const override;
517 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
520 // XclExpChTrInsertTab - insert table
522 class XclExpChTrInsertTab : public XclExpChTrAction, protected XclExpRoot
524 private:
525 SCTAB const nTab;
527 protected:
528 virtual void SaveActionData( XclExpStream& rStrm ) const override;
530 public:
531 XclExpChTrInsertTab(
532 const ScChangeAction& rAction,
533 const XclExpRoot& rRoot,
534 const XclExpChTrTabIdBuffer& rTabIdBuffer );
535 virtual ~XclExpChTrInsertTab() override;
537 virtual sal_uInt16 GetNum() const override;
538 virtual std::size_t GetActionByteCount() const override;
540 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
543 // XclExpChTrMoveRange - move cell range
545 class XclExpChTrMoveRange final : public XclExpChTrAction
547 ScRange aSourceRange;
548 ScRange const aDestRange;
550 virtual void SaveActionData( XclExpStream& rStrm ) const override;
551 virtual void PrepareSaveAction( XclExpStream& rStrm ) const override;
552 virtual void CompleteSaveAction( XclExpStream& rStrm ) const override;
554 public:
555 XclExpChTrMoveRange(
556 const ScChangeActionMove& rAction,
557 const XclExpRoot& rRoot,
558 const XclExpChTrTabIdBuffer& rTabIdBuffer,
559 const ScChangeTrack& rChangeTrack );
560 virtual ~XclExpChTrMoveRange() override;
562 virtual sal_uInt16 GetNum() const override;
563 virtual std::size_t GetActionByteCount() const override;
565 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
568 // XclExpChTr0x019A - additional data for delete action
570 class XclExpChTr0x014A : public XclExpChTrInsert
572 protected:
573 virtual void SaveActionData( XclExpStream& rStrm ) const override;
575 public:
576 XclExpChTr0x014A( const XclExpChTrInsert& rAction );
577 virtual ~XclExpChTr0x014A() override;
579 virtual sal_uInt16 GetNum() const override;
580 virtual std::size_t GetActionByteCount() const override;
582 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
585 // XclExpChangeTrack - exports the "Revision Log" stream
587 class XclExpChangeTrack : protected XclExpRoot
589 typedef std::vector<std::unique_ptr<ExcRecord>> RecListType;
590 typedef std::vector<std::unique_ptr<XclExpChTrTabIdBuffer>> TabIdBufferType;
591 RecListType maRecList; // list of "Revision Log" stream records
592 std::stack<XclExpChTrAction*> aActionStack;
593 XclExpChTrTabIdBuffer* pTabIdBuffer;
594 TabIdBufferType maBuffers;
596 ScDocumentUniquePtr xTempDoc; // empty document
598 ScChangeTrack* CreateTempChangeTrack();
599 void PushActionRecord( const ScChangeAction& rAction );
601 bool WriteUserNamesStream();
603 public:
604 XclExpChangeTrack( const XclExpRoot& rRoot );
605 virtual ~XclExpChangeTrack() override;
607 void Write();
608 void WriteXml( XclExpXmlStream& rStrm );
611 #endif
613 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */