1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XclExpChangeTrack.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XCLEXPCHANGETRACK_HXX
32 #define SC_XCLEXPCHANGETRACK_HXX
34 #include <tools/debug.hxx>
35 #include <tools/datetime.hxx>
37 #include "bigrange.hxx"
38 #include "chgtrack.hxx"
41 #include "excrecds.hxx"
43 //___________________________________________________________________
47 //___________________________________________________________________
48 // XclExpUserBView - one UserBView record for each user
50 class XclExpUserBView
: public ExcRecord
53 XclExpString sUsername
;
54 sal_uInt8 aGUID
[ 16 ];
56 virtual void SaveCont( XclExpStream
& rStrm
);
59 XclExpUserBView( const String
& rUsername
, const sal_uInt8
* pGUID
);
61 inline const sal_uInt8
* GetGUID() const { return aGUID
; }
63 virtual UINT16
GetNum() const;
64 virtual sal_Size
GetLen() const;
67 //___________________________________________________________________
68 // XclExpUserBViewList - list of UserBView records
70 class XclExpUserBViewList
: public ExcEmptyRec
, private List
73 inline XclExpUserBView
* _First() { return (XclExpUserBView
*) List::First(); }
74 inline XclExpUserBView
* _Next() { return (XclExpUserBView
*) List::Next(); }
77 XclExpUserBViewList( const ScChangeTrack
& rChangeTrack
);
78 virtual ~XclExpUserBViewList();
80 inline const XclExpUserBView
* First() { return (const XclExpUserBView
*) List::First(); }
81 inline const XclExpUserBView
* Next() { return (const XclExpUserBView
*) List::Next(); }
83 virtual void Save( XclExpStream
& rStrm
);
86 //___________________________________________________________________
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
);
98 XclExpUsersViewBegin( const sal_uInt8
* pGUID
, sal_uInt32 nTab
);
99 virtual UINT16
GetNum() const;
100 virtual sal_Size
GetLen() const;
103 //___________________________________________________________________
104 // XclExpUsersViewEnd - end of view block (one per sheet)
106 class XclExpUsersViewEnd
: public ExcRecord
109 virtual void SaveCont( XclExpStream
& rStrm
);
112 virtual UINT16
GetNum() const;
113 virtual sal_Size
GetLen() const;
116 //___________________________________________________________________
117 // dummy record for "User Names" stream
119 class XclExpChTr0x0191
: public ExcRecord
122 virtual void SaveCont( XclExpStream
& rStrm
);
125 virtual UINT16
GetNum() const;
126 virtual sal_Size
GetLen() const;
129 //___________________________________________________________________
130 // dummy record for "User Names" stream
132 class XclExpChTr0x0198
: public ExcRecord
135 virtual void SaveCont( XclExpStream
& rStrm
);
138 virtual UINT16
GetNum() const;
139 virtual sal_Size
GetLen() const;
142 //___________________________________________________________________
143 // dummy record for "User Names" stream
145 class XclExpChTr0x0192
: public ExcRecord
148 virtual void SaveCont( XclExpStream
& rStrm
);
151 virtual UINT16
GetNum() const;
152 virtual sal_Size
GetLen() const;
155 //___________________________________________________________________
156 // dummy record for "User Names" stream
158 class XclExpChTr0x0197
: public ExcRecord
161 virtual void SaveCont( XclExpStream
& rStrm
);
164 virtual UINT16
GetNum() const;
165 virtual sal_Size
GetLen() const;
168 //___________________________________________________________________
169 // dummy record without content
171 class XclExpChTrEmpty
: public ExcRecord
177 inline XclExpChTrEmpty( UINT16 nNum
) : nRecNum( nNum
) {}
178 virtual ~XclExpChTrEmpty();
180 virtual UINT16
GetNum() const;
181 virtual sal_Size
GetLen() const;
184 //___________________________________________________________________
185 // dummy record for "Revision Log" stream
187 class XclExpChTr0x0195
: public ExcRecord
190 virtual void SaveCont( XclExpStream
& rStrm
);
193 virtual ~XclExpChTr0x0195();
195 virtual UINT16
GetNum() const;
196 virtual sal_Size
GetLen() const;
199 //___________________________________________________________________
200 // dummy record for "Revision Log" stream
202 class XclExpChTr0x0194
: public ExcRecord
205 XclExpString sUsername
;
208 virtual void SaveCont( XclExpStream
& rStrm
);
211 inline XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
);
212 virtual ~XclExpChTr0x0194();
214 virtual UINT16
GetNum() const;
215 virtual sal_Size
GetLen() const;
218 inline XclExpChTr0x0194::XclExpChTr0x0194( const ScChangeTrack
& rChangeTrack
) :
219 sUsername( rChangeTrack
.GetUser() ),
220 aDateTime( rChangeTrack
.GetFixDateTime() )
224 //___________________________________________________________________
225 // XclExpChTrHeader - header record, includes action count
227 class XclExpChTrHeader
: public ExcRecord
230 sal_uInt8 aGUID
[ 16 ];
233 virtual void SaveCont( XclExpStream
& rStrm
);
236 inline XclExpChTrHeader() : nCount( 0 ) {}
237 virtual ~XclExpChTrHeader();
239 inline void SetGUID( const sal_uInt8
* pGUID
) { memcpy( aGUID
, pGUID
, 16 ); }
240 inline void SetCount( sal_uInt32 nNew
) { nCount
= nNew
; }
242 virtual UINT16
GetNum() const;
243 virtual sal_Size
GetLen() const;
246 //___________________________________________________________________
247 // XclExpChTrInfo - header of action group of a user
249 class XclExpChTrInfo
: public ExcRecord
252 XclExpString sUsername
;
254 sal_uInt8 aGUID
[ 16 ];
256 virtual void SaveCont( XclExpStream
& rStrm
);
259 inline XclExpChTrInfo(
260 const String
& rUsername
,
261 const DateTime
& rDateTime
,
262 const sal_uInt8
* pGUID
);
263 virtual ~XclExpChTrInfo();
265 virtual UINT16
GetNum() const;
266 virtual sal_Size
GetLen() const;
269 inline XclExpChTrInfo::XclExpChTrInfo( const String
& rUsername
, const DateTime
& rDateTime
, const sal_uInt8
* pGUID
) :
270 sUsername( rUsername
),
271 aDateTime( rDateTime
)
273 memcpy( aGUID
, pGUID
, 16 );
276 //___________________________________________________________________
277 // XclExpChTrTabIdBuffer - buffer for tab id's
279 class XclExpChTrTabIdBuffer
288 XclExpChTrTabIdBuffer( sal_uInt16 nCount
);
289 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer
& rCopy
);
290 ~XclExpChTrTabIdBuffer();
292 void InitFill( sal_uInt16 nIndex
);
295 sal_uInt16
GetId( sal_uInt16 nIndex
) const;
298 inline sal_uInt16
GetBufferCount() const
299 { return static_cast< sal_uInt16
>( (pLast
- pBuffer
) + 1 ); }
300 inline void GetBufferCopy( sal_uInt16
* pDest
) const
301 { memcpy( pDest
, pBuffer
, sizeof(sal_uInt16
) * GetBufferCount() ); }
304 //___________________________________________________________________
305 // XclExpChTrTabIdBufferList
307 class XclExpChTrTabIdBufferList
: private List
310 inline XclExpChTrTabIdBuffer
* First() { return (XclExpChTrTabIdBuffer
*) List::First(); }
311 inline XclExpChTrTabIdBuffer
* Next() { return (XclExpChTrTabIdBuffer
*) List::Next(); }
314 virtual ~XclExpChTrTabIdBufferList();
316 inline void Append( XclExpChTrTabIdBuffer
* pNew
)
317 { List::Insert( pNew
, LIST_APPEND
); }
320 //___________________________________________________________________
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
);
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 UINT16
GetNum() const;
342 virtual sal_Size
GetLen() const;
345 //___________________________________________________________________
346 // XclExpChTrAction - base class for action records
348 class XclExpChTrAction
: public ExcRecord
353 sal_uInt32 nIndex
; // action number
354 XclExpChTrAction
* pAddAction
; // additional record for this action
358 const XclExpTabInfo
& rTabInfo
; // for table num export (sc num -> xcl num)
359 const XclExpChTrTabIdBuffer
& rIdBuffer
; // for table num export (xcl num -> tab id)
360 sal_uInt32 nLength
; // this is not the record size
361 sal_uInt16 nOpCode
; // EXC_CHTR_OP_***
364 XclExpChTrAction( const XclExpChTrAction
& rCopy
);
366 void SetAddAction( XclExpChTrAction
* pAction
);
367 void AddDependentContents(
368 const ScChangeAction
& rAction
,
369 const XclExpRoot
& rRoot
,
370 ScChangeTrack
& rChangeTrack
);
372 inline void Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
) const;
373 inline void Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
) const;
374 inline void WriteTabId( XclExpStream
& rStrm
, SCTAB nTabId
) const;
376 // save header data, call SaveActionData()
377 virtual void SaveCont( XclExpStream
& rStrm
);
378 inline sal_Size
GetHeaderByteCount() const { return 12; }
380 // overload to save action data without header, called by SaveCont()
381 virtual void SaveActionData( XclExpStream
& rStrm
) const = 0;
382 // overload 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;
392 const ScChangeAction
& rAction
,
393 const XclExpRoot
& rRoot
,
394 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
395 sal_uInt16 nNewOpCode
= EXC_CHTR_OP_UNKNOWN
);
396 virtual ~XclExpChTrAction();
398 inline const String
& GetUsername() const { return sUsername
; }
399 inline const DateTime
& GetDateTime() const { return aDateTime
; }
400 inline const XclExpChTrTabIdBuffer
& GetTabIdBuffer() const { return rIdBuffer
; }
401 inline sal_Bool
ForceInfoRecord() const { return bForceInfo
; }
403 // set own index & return new index
404 // could be overloaded to use more indexes per action
405 virtual void SetIndex( sal_uInt32
& rIndex
);
407 virtual void Save( XclExpStream
& rStrm
);
408 virtual sal_Size
GetLen() const;
411 inline void XclExpChTrAction::Write2DAddress( XclExpStream
& rStrm
, const ScAddress
& rAddress
) const
413 rStrm
<< (sal_uInt16
) rAddress
.Row()
414 << (sal_uInt16
) rAddress
.Col();
417 inline void XclExpChTrAction::Write2DRange( XclExpStream
& rStrm
, const ScRange
& rRange
) const
419 rStrm
<< (sal_uInt16
) rRange
.aStart
.Row()
420 << (sal_uInt16
) rRange
.aEnd
.Row()
421 << (sal_uInt16
) rRange
.aStart
.Col()
422 << (sal_uInt16
) rRange
.aEnd
.Col();
425 inline void XclExpChTrAction::WriteTabId( XclExpStream
& rStrm
, SCTAB nTab
) const
427 rStrm
<< rIdBuffer
.GetId( rTabInfo
.GetXclTab( nTab
) );
430 //___________________________________________________________________
431 // XclExpChTrData - cell content itself
433 struct XclExpChTrData
435 XclExpString
* pString
;
436 XclTokenArrayRef mxTokArr
;
437 XclExpRefLog maRefLog
;
449 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
452 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
455 //___________________________________________________________________
456 // XclExpChTrCellContent - changed cell content
458 class XclExpChTrCellContent
: public XclExpChTrAction
, protected XclExpRoot
461 XclExpChTrData
* pOldData
;
462 XclExpChTrData
* pNewData
;
463 sal_uInt16 nOldLength
; // this is not the record size
465 void MakeEmptyChTrData( XclExpChTrData
*& rpData
);
471 const ScBaseCell
* pScCell
,
472 XclExpChTrData
*& rpData
,
473 sal_uInt32
& rXclLength1
,
474 sal_uInt16
& rXclLength2
);
476 virtual void SaveActionData( XclExpStream
& rStrm
) const;
479 XclExpChTrCellContent(
480 const ScChangeActionContent
& rAction
,
481 const XclExpRoot
& rRoot
,
482 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
483 virtual ~XclExpChTrCellContent();
485 virtual UINT16
GetNum() const;
486 virtual sal_Size
GetActionByteCount() const;
489 //___________________________________________________________________
490 // XclExpChTrInsert - insert/delete columns/rows
492 class XclExpChTrInsert
: public XclExpChTrAction
497 XclExpChTrInsert( const XclExpChTrInsert
& rCopy
) :
498 XclExpChTrAction( rCopy
), aRange( rCopy
.aRange
) {}
500 virtual void SaveActionData( XclExpStream
& rStrm
) const;
501 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const;
502 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const;
506 const ScChangeAction
& rAction
,
507 const XclExpRoot
& rRoot
,
508 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
509 ScChangeTrack
& rChangeTrack
);
510 virtual ~XclExpChTrInsert();
512 virtual UINT16
GetNum() const;
513 virtual sal_Size
GetActionByteCount() const;
516 //___________________________________________________________________
517 // XclExpChTrInsertTab - insert table
519 class XclExpChTrInsertTab
: public XclExpChTrAction
, protected XclExpRoot
525 virtual void SaveActionData( XclExpStream
& rStrm
) const;
529 const ScChangeAction
& rAction
,
530 const XclExpRoot
& rRoot
,
531 const XclExpChTrTabIdBuffer
& rTabIdBuffer
);
532 virtual ~XclExpChTrInsertTab();
534 virtual UINT16
GetNum() const;
535 virtual sal_Size
GetActionByteCount() const;
538 //___________________________________________________________________
539 // XclExpChTrMoveRange - move cell range
541 class XclExpChTrMoveRange
: public XclExpChTrAction
544 ScRange aSourceRange
;
547 virtual void SaveActionData( XclExpStream
& rStrm
) const;
548 virtual void PrepareSaveAction( XclExpStream
& rStrm
) const;
549 virtual void CompleteSaveAction( XclExpStream
& rStrm
) const;
553 const ScChangeActionMove
& rAction
,
554 const XclExpRoot
& rRoot
,
555 const XclExpChTrTabIdBuffer
& rTabIdBuffer
,
556 ScChangeTrack
& rChangeTrack
);
557 virtual ~XclExpChTrMoveRange();
559 virtual UINT16
GetNum() const;
560 virtual sal_Size
GetActionByteCount() const;
563 //___________________________________________________________________
564 // XclExpChTr0x019A - additional data for delete action
566 class XclExpChTr0x014A
: public XclExpChTrInsert
569 virtual void SaveActionData( XclExpStream
& rStrm
) const;
572 XclExpChTr0x014A( const XclExpChTrInsert
& rAction
);
573 virtual ~XclExpChTr0x014A();
575 virtual UINT16
GetNum() const;
576 virtual sal_Size
GetActionByteCount() const;
579 //___________________________________________________________________
580 // XclExpChTrActionStack - temporary action stack
582 class XclExpChTrActionStack
: private Stack
585 virtual ~XclExpChTrActionStack();
587 void Push( XclExpChTrAction
* pNewRec
);
588 inline XclExpChTrAction
* Pop() { return (XclExpChTrAction
*) Stack::Pop(); }
594 //___________________________________________________________________
595 // XclExpChTrRecordList - list of "Revision Log" stream records
597 class XclExpChTrRecordList
: private List
600 inline ExcRecord
* First() { return (ExcRecord
*) List::First(); }
601 inline ExcRecord
* Next() { return (ExcRecord
*) List::Next(); }
604 virtual ~XclExpChTrRecordList();
607 void Append( ExcRecord
* pNewRec
);
608 void Save( XclExpStream
& rStrm
);
611 //___________________________________________________________________
612 // XclExpChangeTrack - exports the "Revision Log" stream
614 class XclExpChangeTrack
: protected XclExpRoot
617 XclExpChTrRecordList aRecList
;
618 XclExpChTrActionStack aActionStack
;
619 XclExpChTrTabIdBufferList aTabIdBufferList
;
620 XclExpChTrTabIdBuffer
* pTabIdBuffer
;
622 ScDocument
* pTempDoc
; // empty document
624 sal_uInt32 nNewAction
; // action number, 1-based
625 XclExpChTrHeader
* pHeader
; // header record for last GUID
626 sal_uInt8 aGUID
[ 16 ]; // GUID for action info records
629 ScChangeTrack
* CreateTempChangeTrack();
630 void PushActionRecord( const ScChangeAction
& rAction
);
632 sal_Bool
WriteUserNamesStream();
635 XclExpChangeTrack( const XclExpRoot
& rRoot
);
636 ~XclExpChangeTrack();
641 //___________________________________________________________________