merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / inc / XclExpChangeTrack.hxx
bloba9ece3dc47f7c140dc2f9feb07c629570ff4f1b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XclExpChangeTrack.hxx,v $
10 * $Revision: 1.20 $
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>
36 #include <rtl/uuid.h>
37 #include "bigrange.hxx"
38 #include "chgtrack.hxx"
39 #include "xelink.hxx"
40 #include "ftools.hxx"
41 #include "excrecds.hxx"
43 //___________________________________________________________________
45 class ScBaseCell;
47 //___________________________________________________________________
48 // XclExpUserBView - one UserBView record for each user
50 class XclExpUserBView : public ExcRecord
52 private:
53 XclExpString sUsername;
54 sal_uInt8 aGUID[ 16 ];
56 virtual void SaveCont( XclExpStream& rStrm );
58 public:
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
72 private:
73 inline XclExpUserBView* _First() { return (XclExpUserBView*) List::First(); }
74 inline XclExpUserBView* _Next() { return (XclExpUserBView*) List::Next(); }
76 public:
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
91 private:
92 sal_uInt8 aGUID[ 16 ];
93 sal_uInt32 nCurrTab;
95 virtual void SaveCont( XclExpStream& rStrm );
97 public:
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
108 private:
109 virtual void SaveCont( XclExpStream& rStrm );
111 public:
112 virtual UINT16 GetNum() const;
113 virtual sal_Size GetLen() const;
116 //___________________________________________________________________
117 // dummy record for "User Names" stream
119 class XclExpChTr0x0191 : public ExcRecord
121 private:
122 virtual void SaveCont( XclExpStream& rStrm );
124 public:
125 virtual UINT16 GetNum() const;
126 virtual sal_Size GetLen() const;
129 //___________________________________________________________________
130 // dummy record for "User Names" stream
132 class XclExpChTr0x0198 : public ExcRecord
134 private:
135 virtual void SaveCont( XclExpStream& rStrm );
137 public:
138 virtual UINT16 GetNum() const;
139 virtual sal_Size GetLen() const;
142 //___________________________________________________________________
143 // dummy record for "User Names" stream
145 class XclExpChTr0x0192 : public ExcRecord
147 private:
148 virtual void SaveCont( XclExpStream& rStrm );
150 public:
151 virtual UINT16 GetNum() const;
152 virtual sal_Size GetLen() const;
155 //___________________________________________________________________
156 // dummy record for "User Names" stream
158 class XclExpChTr0x0197 : public ExcRecord
160 private:
161 virtual void SaveCont( XclExpStream& rStrm );
163 public:
164 virtual UINT16 GetNum() const;
165 virtual sal_Size GetLen() const;
168 //___________________________________________________________________
169 // dummy record without content
171 class XclExpChTrEmpty : public ExcRecord
173 private:
174 UINT16 nRecNum;
176 public:
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
189 private:
190 virtual void SaveCont( XclExpStream& rStrm );
192 public:
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
204 private:
205 XclExpString sUsername;
206 DateTime aDateTime;
208 virtual void SaveCont( XclExpStream& rStrm );
210 public:
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
229 private:
230 sal_uInt8 aGUID[ 16 ];
231 sal_uInt32 nCount;
233 virtual void SaveCont( XclExpStream& rStrm );
235 public:
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
251 private:
252 XclExpString sUsername;
253 DateTime aDateTime;
254 sal_uInt8 aGUID[ 16 ];
256 virtual void SaveCont( XclExpStream& rStrm );
258 public:
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
281 private:
282 sal_uInt16* pBuffer;
283 sal_uInt16* pLast;
284 sal_uInt16 nBufSize;
285 sal_uInt16 nLastId;
287 public:
288 XclExpChTrTabIdBuffer( sal_uInt16 nCount );
289 XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer& rCopy );
290 ~XclExpChTrTabIdBuffer();
292 void InitFill( sal_uInt16 nIndex );
293 void InitFillup();
295 sal_uInt16 GetId( sal_uInt16 nIndex ) const;
296 void Remove();
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
309 private:
310 inline XclExpChTrTabIdBuffer* First() { return (XclExpChTrTabIdBuffer*) List::First(); }
311 inline XclExpChTrTabIdBuffer* Next() { return (XclExpChTrTabIdBuffer*) List::Next(); }
313 public:
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
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 );
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 UINT16 GetNum() const;
342 virtual sal_Size GetLen() const;
345 //___________________________________________________________________
346 // XclExpChTrAction - base class for action records
348 class XclExpChTrAction : public ExcRecord
350 private:
351 String sUsername;
352 DateTime aDateTime;
353 sal_uInt32 nIndex; // action number
354 XclExpChTrAction* pAddAction; // additional record for this action
355 sal_Bool bAccepted;
357 protected:
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_***
362 sal_Bool bForceInfo;
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;
390 public:
391 XclExpChTrAction(
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;
438 double fValue;
439 sal_Int32 nRKValue;
440 sal_uInt16 nType;
441 sal_Size nSize;
443 XclExpChTrData();
444 ~XclExpChTrData();
445 void Clear();
447 void WriteFormula(
448 XclExpStream& rStrm,
449 const XclExpChTrTabIdBuffer& rTabIdBuffer );
450 void Write(
451 XclExpStream& rStrm,
452 const XclExpChTrTabIdBuffer& rTabIdBuffer );
455 //___________________________________________________________________
456 // XclExpChTrCellContent - changed cell content
458 class XclExpChTrCellContent : public XclExpChTrAction, protected XclExpRoot
460 private:
461 XclExpChTrData* pOldData;
462 XclExpChTrData* pNewData;
463 sal_uInt16 nOldLength; // this is not the record size
465 void MakeEmptyChTrData( XclExpChTrData*& rpData );
467 protected:
468 ScAddress aPosition;
470 void GetCellData(
471 const ScBaseCell* pScCell,
472 XclExpChTrData*& rpData,
473 sal_uInt32& rXclLength1,
474 sal_uInt16& rXclLength2 );
476 virtual void SaveActionData( XclExpStream& rStrm ) const;
478 public:
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
494 protected:
495 ScRange aRange;
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;
504 public:
505 XclExpChTrInsert(
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
521 private:
522 SCTAB nTab;
524 protected:
525 virtual void SaveActionData( XclExpStream& rStrm ) const;
527 public:
528 XclExpChTrInsertTab(
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
543 protected:
544 ScRange aSourceRange;
545 ScRange aDestRange;
547 virtual void SaveActionData( XclExpStream& rStrm ) const;
548 virtual void PrepareSaveAction( XclExpStream& rStrm ) const;
549 virtual void CompleteSaveAction( XclExpStream& rStrm ) const;
551 public:
552 XclExpChTrMoveRange(
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
568 protected:
569 virtual void SaveActionData( XclExpStream& rStrm ) const;
571 public:
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
584 public:
585 virtual ~XclExpChTrActionStack();
587 void Push( XclExpChTrAction* pNewRec );
588 inline XclExpChTrAction* Pop() { return (XclExpChTrAction*) Stack::Pop(); }
590 private:
591 using Stack::Push;
594 //___________________________________________________________________
595 // XclExpChTrRecordList - list of "Revision Log" stream records
597 class XclExpChTrRecordList : private List
599 private:
600 inline ExcRecord* First() { return (ExcRecord*) List::First(); }
601 inline ExcRecord* Next() { return (ExcRecord*) List::Next(); }
603 public:
604 virtual ~XclExpChTrRecordList();
606 using List::Count;
607 void Append( ExcRecord* pNewRec );
608 void Save( XclExpStream& rStrm );
611 //___________________________________________________________________
612 // XclExpChangeTrack - exports the "Revision Log" stream
614 class XclExpChangeTrack : protected XclExpRoot
616 private:
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
627 sal_Bool bValidGUID;
629 ScChangeTrack* CreateTempChangeTrack();
630 void PushActionRecord( const ScChangeAction& rAction );
632 sal_Bool WriteUserNamesStream();
634 public:
635 XclExpChangeTrack( const XclExpRoot& rRoot );
636 ~XclExpChangeTrack();
638 void Write();
641 //___________________________________________________________________
643 #endif