fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / XclExpChangeTrack.hxx
blobdf1e4d7068c02890368e9723e83e4a271ab63923
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 <stack>
24 #include <tools/datetime.hxx>
25 #include <rtl/uuid.h>
26 #include "bigrange.hxx"
27 #include "chgtrack.hxx"
28 #include "xelink.hxx"
29 #include "ftools.hxx"
30 #include "excrecds.hxx"
32 #include <boost/ptr_container/ptr_vector.hpp>
34 class ExcXmlRecord : public ExcRecord
36 public:
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
46 private:
47 XclExpString sUsername;
48 sal_uInt8 aGUID[ 16 ];
50 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
52 public:
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
65 private:
66 std::vector<XclExpUserBView*> aViews;
68 public:
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
91 private:
92 sal_uInt8 aGUID[ 16 ];
93 sal_uInt32 nCurrTab;
95 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
97 public:
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
107 private:
108 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
110 public:
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
119 private:
120 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
122 public:
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
131 private:
132 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
134 public:
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
143 private:
144 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
146 public:
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
155 private:
156 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
158 public:
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
167 private:
168 sal_uInt16 nRecNum;
170 public:
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
182 private:
183 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
185 public:
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
196 private:
197 XclExpString sUsername;
198 DateTime aDateTime;
200 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
202 public:
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
220 private:
221 sal_uInt8 aGUID[ 16 ];
222 sal_uInt32 nCount;
224 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
226 public:
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];
242 public:
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
253 OUString maUserName;
254 DateTime maDateTime;
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;
263 public:
264 XclExpXmlChTrHeader(
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
277 private:
278 XclExpString sUsername;
279 DateTime aDateTime;
280 sal_uInt8 aGUID[ 16 ];
282 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
284 public:
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
298 private:
299 sal_uInt16* pBuffer;
300 sal_uInt16* pLast;
301 sal_uInt16 nBufSize;
302 sal_uInt16 nLastId;
304 public:
305 XclExpChTrTabIdBuffer( sal_uInt16 nCount );
306 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer& rCopy );
307 ~XclExpChTrTabIdBuffer();
309 void InitFill( sal_uInt16 nIndex );
310 void InitFillup();
312 sal_uInt16 GetId( sal_uInt16 nIndex ) const;
313 void Remove();
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
325 private:
326 sal_uInt16* pBuffer;
327 sal_uInt16 nTabCount;
329 inline void Clear() { if( pBuffer ) delete[] pBuffer; pBuffer = NULL; }
331 virtual void SaveCont( XclExpStream& rStrm ) SAL_OVERRIDE;
333 public:
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
349 private:
350 OUString sUsername;
351 DateTime aDateTime;
352 sal_uInt32 nIndex; // action number
353 XclExpChTrAction* pAddAction; // additional record for this action
354 bool bAccepted;
356 protected:
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_***
361 bool bForceInfo;
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; }
392 public:
393 XclExpChTrAction(
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;
449 double fValue;
450 sal_Int32 nRKValue;
451 sal_uInt16 nType;
452 sal_Size nSize;
454 XclExpChTrData();
455 ~XclExpChTrData();
456 void Clear();
458 void WriteFormula(
459 XclExpStream& rStrm,
460 const XclExpChTrTabIdBuffer& rTabIdBuffer );
461 void Write(
462 XclExpStream& rStrm,
463 const XclExpChTrTabIdBuffer& rTabIdBuffer );
466 // XclExpChTrCellContent - changed cell content
468 class XclExpChTrCellContent : public XclExpChTrAction, protected XclExpRoot
470 private:
471 XclExpChTrData* pOldData;
472 XclExpChTrData* pNewData;
473 sal_uInt16 nOldLength; // this is not the record size
475 static void MakeEmptyChTrData( XclExpChTrData*& rpData );
477 protected:
478 ScAddress aPosition;
480 void GetCellData(
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;
486 public:
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
503 bool mbEndOfList;
505 protected:
506 ScRange aRange;
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;
514 public:
515 XclExpChTrInsert(
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
532 private:
533 SCTAB nTab;
535 protected:
536 virtual void SaveActionData( XclExpStream& rStrm ) const SAL_OVERRIDE;
538 public:
539 XclExpChTrInsertTab(
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
555 protected:
556 ScRange aSourceRange;
557 ScRange aDestRange;
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;
563 public:
564 XclExpChTrMoveRange(
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
581 protected:
582 virtual void SaveActionData( XclExpStream& rStrm ) const SAL_OVERRIDE;
584 public:
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
609 bool bValidGUID;
611 ScChangeTrack* CreateTempChangeTrack();
612 void PushActionRecord( const ScChangeAction& rAction );
614 bool WriteUserNamesStream();
616 public:
617 XclExpChangeTrack( const XclExpRoot& rRoot );
618 virtual ~XclExpChangeTrack();
620 void Write();
621 void WriteXml( XclExpXmlStream& rStrm );
624 #endif
626 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */