Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_XCLEXPCHANGETRACK_HXX
21 : #define SC_XCLEXPCHANGETRACK_HXX
22 :
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"
31 :
32 : //___________________________________________________________________
33 :
34 : class ScBaseCell;
35 :
36 : //___________________________________________________________________
37 : // XclExpUserBView - one UserBView record for each user
38 :
39 0 : class XclExpUserBView : public ExcRecord
40 : {
41 : private:
42 : XclExpString sUsername;
43 : sal_uInt8 aGUID[ 16 ];
44 :
45 : virtual void SaveCont( XclExpStream& rStrm );
46 :
47 : public:
48 : XclExpUserBView( const String& rUsername, const sal_uInt8* pGUID );
49 :
50 0 : inline const sal_uInt8* GetGUID() const { return aGUID; }
51 :
52 : virtual sal_uInt16 GetNum() const;
53 : virtual sal_Size GetLen() const;
54 : };
55 :
56 : //___________________________________________________________________
57 : // XclExpUserBViewList - list of UserBView records
58 :
59 : class XclExpUserBViewList : public ExcEmptyRec
60 : {
61 : private:
62 : std::vector<XclExpUserBView*> aViews;
63 :
64 : public:
65 :
66 : typedef std::vector<XclExpUserBView*>::iterator iterator;
67 : typedef std::vector<XclExpUserBView*>::const_iterator const_iterator;
68 :
69 : XclExpUserBViewList( const ScChangeTrack& rChangeTrack );
70 : virtual ~XclExpUserBViewList();
71 :
72 0 : inline iterator begin () { return aViews.begin(); }
73 :
74 0 : inline iterator end () { return aViews.end(); }
75 :
76 : inline const_iterator begin () const { return aViews.begin(); }
77 :
78 : inline const_iterator end () const { return aViews.end(); }
79 :
80 : virtual void Save( XclExpStream& rStrm );
81 : };
82 :
83 : //___________________________________________________________________
84 : // XclExpUsersViewBegin - begin of view block (one per sheet)
85 :
86 0 : class XclExpUsersViewBegin : public ExcRecord
87 : {
88 : private:
89 : sal_uInt8 aGUID[ 16 ];
90 : sal_uInt32 nCurrTab;
91 :
92 : virtual void SaveCont( XclExpStream& rStrm );
93 :
94 : public:
95 : XclExpUsersViewBegin( const sal_uInt8* pGUID, sal_uInt32 nTab );
96 : virtual sal_uInt16 GetNum() const;
97 : virtual sal_Size GetLen() const;
98 : };
99 :
100 : //___________________________________________________________________
101 : // XclExpUsersViewEnd - end of view block (one per sheet)
102 :
103 0 : class XclExpUsersViewEnd : public ExcRecord
104 : {
105 : private:
106 : virtual void SaveCont( XclExpStream& rStrm );
107 :
108 : public:
109 : virtual sal_uInt16 GetNum() const;
110 : virtual sal_Size GetLen() const;
111 : };
112 :
113 : //___________________________________________________________________
114 : // dummy record for "User Names" stream
115 :
116 0 : class XclExpChTr0x0191 : public ExcRecord
117 : {
118 : private:
119 : virtual void SaveCont( XclExpStream& rStrm );
120 :
121 : public:
122 : virtual sal_uInt16 GetNum() const;
123 : virtual sal_Size GetLen() const;
124 : };
125 :
126 : //___________________________________________________________________
127 : // dummy record for "User Names" stream
128 :
129 0 : class XclExpChTr0x0198 : public ExcRecord
130 : {
131 : private:
132 : virtual void SaveCont( XclExpStream& rStrm );
133 :
134 : public:
135 : virtual sal_uInt16 GetNum() const;
136 : virtual sal_Size GetLen() const;
137 : };
138 :
139 : //___________________________________________________________________
140 : // dummy record for "User Names" stream
141 :
142 0 : class XclExpChTr0x0192 : public ExcRecord
143 : {
144 : private:
145 : virtual void SaveCont( XclExpStream& rStrm );
146 :
147 : public:
148 : virtual sal_uInt16 GetNum() const;
149 : virtual sal_Size GetLen() const;
150 : };
151 :
152 : //___________________________________________________________________
153 : // dummy record for "User Names" stream
154 :
155 0 : class XclExpChTr0x0197 : public ExcRecord
156 : {
157 : private:
158 : virtual void SaveCont( XclExpStream& rStrm );
159 :
160 : public:
161 : virtual sal_uInt16 GetNum() const;
162 : virtual sal_Size GetLen() const;
163 : };
164 :
165 : //___________________________________________________________________
166 : // dummy record without content
167 :
168 : class XclExpChTrEmpty : public ExcRecord
169 : {
170 : private:
171 : sal_uInt16 nRecNum;
172 :
173 : public:
174 0 : inline XclExpChTrEmpty( sal_uInt16 nNum ) : nRecNum( nNum ) {}
175 : virtual ~XclExpChTrEmpty();
176 :
177 : virtual sal_uInt16 GetNum() const;
178 : virtual sal_Size GetLen() const;
179 : };
180 :
181 : //___________________________________________________________________
182 : // dummy record for "Revision Log" stream
183 :
184 0 : class XclExpChTr0x0195 : public ExcRecord
185 : {
186 : private:
187 : virtual void SaveCont( XclExpStream& rStrm );
188 :
189 : public:
190 : virtual ~XclExpChTr0x0195();
191 :
192 : virtual sal_uInt16 GetNum() const;
193 : virtual sal_Size GetLen() const;
194 : };
195 :
196 : //___________________________________________________________________
197 : // dummy record for "Revision Log" stream
198 :
199 : class XclExpChTr0x0194 : public ExcRecord
200 : {
201 : private:
202 : XclExpString sUsername;
203 : DateTime aDateTime;
204 :
205 : virtual void SaveCont( XclExpStream& rStrm );
206 :
207 : public:
208 : inline XclExpChTr0x0194( const ScChangeTrack& rChangeTrack );
209 : virtual ~XclExpChTr0x0194();
210 :
211 : virtual sal_uInt16 GetNum() const;
212 : virtual sal_Size GetLen() const;
213 : };
214 :
215 0 : inline XclExpChTr0x0194::XclExpChTr0x0194( const ScChangeTrack& rChangeTrack ) :
216 0 : sUsername( rChangeTrack.GetUser() ),
217 0 : aDateTime( rChangeTrack.GetFixDateTime() )
218 : {
219 0 : }
220 :
221 : //___________________________________________________________________
222 : // XclExpChTrHeader - header record, includes action count
223 :
224 : class XclExpChTrHeader : public ExcRecord
225 : {
226 : private:
227 : sal_uInt8 aGUID[ 16 ];
228 : sal_uInt32 nCount;
229 :
230 : virtual void SaveCont( XclExpStream& rStrm );
231 :
232 : public:
233 0 : inline XclExpChTrHeader() : nCount( 0 ) {}
234 : virtual ~XclExpChTrHeader();
235 :
236 0 : inline void SetGUID( const sal_uInt8* pGUID ) { memcpy( aGUID, pGUID, 16 ); }
237 0 : inline void SetCount( sal_uInt32 nNew ) { nCount = nNew; }
238 :
239 : virtual sal_uInt16 GetNum() const;
240 : virtual sal_Size GetLen() const;
241 :
242 : virtual void SaveXml( XclExpXmlStream& rStrm );
243 : };
244 :
245 : //___________________________________________________________________
246 : // XclExpChTrInfo - header of action group of a user
247 :
248 : class XclExpChTrInfo : public ExcRecord
249 : {
250 : private:
251 : XclExpString sUsername;
252 : sal_Int32 mnLogNumber;
253 : DateTime aDateTime;
254 : sal_uInt8 aGUID[ 16 ];
255 :
256 : virtual void SaveCont( XclExpStream& rStrm );
257 :
258 : public:
259 : inline XclExpChTrInfo(
260 : const String& rUsername,
261 : const DateTime& rDateTime,
262 : const sal_uInt8* pGUID,
263 : sal_Int32 nLogNumber );
264 : virtual ~XclExpChTrInfo();
265 :
266 : virtual sal_uInt16 GetNum() const;
267 : virtual sal_Size GetLen() const;
268 :
269 : virtual void SaveXml( XclExpXmlStream& rStrm );
270 : };
271 :
272 0 : inline XclExpChTrInfo::XclExpChTrInfo( const String& rUsername, const DateTime& rDateTime, const sal_uInt8* pGUID, sal_Int32 nLogNumber ) :
273 : sUsername( rUsername ),
274 : mnLogNumber( nLogNumber ),
275 0 : aDateTime( rDateTime )
276 : {
277 0 : memcpy( aGUID, pGUID, 16 );
278 0 : }
279 :
280 : //___________________________________________________________________
281 : // XclExpChTrTabIdBuffer - buffer for tab id's
282 :
283 : class XclExpChTrTabIdBuffer
284 : {
285 : private:
286 : sal_uInt16* pBuffer;
287 : sal_uInt16* pLast;
288 : sal_uInt16 nBufSize;
289 : sal_uInt16 nLastId;
290 :
291 : public:
292 : XclExpChTrTabIdBuffer( sal_uInt16 nCount );
293 : XclExpChTrTabIdBuffer( const XclExpChTrTabIdBuffer& rCopy );
294 : ~XclExpChTrTabIdBuffer();
295 :
296 : void InitFill( sal_uInt16 nIndex );
297 : void InitFillup();
298 :
299 : sal_uInt16 GetId( sal_uInt16 nIndex ) const;
300 : void Remove();
301 :
302 0 : inline sal_uInt16 GetBufferCount() const
303 0 : { return static_cast< sal_uInt16 >( (pLast - pBuffer) + 1 ); }
304 0 : inline void GetBufferCopy( sal_uInt16* pDest ) const
305 0 : { memcpy( pDest, pBuffer, sizeof(sal_uInt16) * GetBufferCount() ); }
306 : };
307 :
308 : //___________________________________________________________________
309 : // XclExpChTrTabId - tab id record
310 :
311 : class XclExpChTrTabId : public ExcRecord
312 : {
313 : private:
314 : sal_uInt16* pBuffer;
315 : sal_uInt16 nTabCount;
316 : bool mbInRevisionHeaders;
317 :
318 1 : inline void Clear() { if( pBuffer ) delete[] pBuffer; pBuffer = NULL; }
319 :
320 : virtual void SaveCont( XclExpStream& rStrm );
321 :
322 : public:
323 1 : inline XclExpChTrTabId( sal_uInt16 nCount ) :
324 1 : pBuffer( NULL ), nTabCount( nCount ), mbInRevisionHeaders( false ) {}
325 : XclExpChTrTabId( const XclExpChTrTabIdBuffer& rBuffer, bool bInRevisionHeaders = false );
326 : virtual ~XclExpChTrTabId();
327 :
328 : void Copy( const XclExpChTrTabIdBuffer& rBuffer );
329 :
330 : virtual sal_uInt16 GetNum() const;
331 : virtual sal_Size GetLen() const;
332 :
333 : virtual void SaveXml( XclExpXmlStream& rStrm );
334 : };
335 :
336 : //___________________________________________________________________
337 : // XclExpChTrAction - base class for action records
338 :
339 : class XclExpChTrAction : public ExcRecord
340 : {
341 : private:
342 : String sUsername;
343 : DateTime aDateTime;
344 : sal_uInt32 nIndex; // action number
345 : XclExpChTrAction* pAddAction; // additional record for this action
346 : sal_Bool bAccepted;
347 :
348 : protected:
349 : const XclExpTabInfo& rTabInfo; // for table num export (sc num -> xcl num)
350 : const XclExpChTrTabIdBuffer& rIdBuffer; // for table num export (xcl num -> tab id)
351 : sal_uInt32 nLength; // this is not the record size
352 : sal_uInt16 nOpCode; // EXC_CHTR_OP_***
353 : sal_Bool bForceInfo;
354 :
355 : XclExpChTrAction( const XclExpChTrAction& rCopy );
356 :
357 : void SetAddAction( XclExpChTrAction* pAction );
358 : void AddDependentContents(
359 : const ScChangeAction& rAction,
360 : const XclExpRoot& rRoot,
361 : ScChangeTrack& rChangeTrack );
362 :
363 : inline void Write2DAddress( XclExpStream& rStrm, const ScAddress& rAddress ) const;
364 : inline void Write2DRange( XclExpStream& rStrm, const ScRange& rRange ) const;
365 : inline sal_uInt16 GetTabId( SCTAB nTabId ) const;
366 : inline void WriteTabId( XclExpStream& rStrm, SCTAB nTabId ) const;
367 :
368 : // save header data, call SaveActionData()
369 : virtual void SaveCont( XclExpStream& rStrm );
370 0 : inline sal_Size GetHeaderByteCount() const { return 12; }
371 :
372 : // overload to save action data without header, called by SaveCont()
373 : virtual void SaveActionData( XclExpStream& rStrm ) const = 0;
374 : // overload to get action size without header, called by GetLen()
375 : virtual sal_Size GetActionByteCount() const = 0;
376 :
377 : // do something before writing the record
378 : virtual void PrepareSaveAction( XclExpStream& rStrm ) const;
379 : // do something after writing the record
380 : virtual void CompleteSaveAction( XclExpStream& rStrm ) const;
381 :
382 0 : inline sal_uInt32 GetActionNumber() const { return nIndex; }
383 0 : inline sal_Bool GetAccepted() const { return bAccepted; }
384 :
385 : public:
386 : XclExpChTrAction(
387 : const ScChangeAction& rAction,
388 : const XclExpRoot& rRoot,
389 : const XclExpChTrTabIdBuffer& rTabIdBuffer,
390 : sal_uInt16 nNewOpCode = EXC_CHTR_OP_UNKNOWN );
391 : virtual ~XclExpChTrAction();
392 :
393 0 : inline const String& GetUsername() const { return sUsername; }
394 0 : inline const DateTime& GetDateTime() const { return aDateTime; }
395 0 : inline const XclExpChTrTabIdBuffer& GetTabIdBuffer() const { return rIdBuffer; }
396 0 : inline sal_Bool ForceInfoRecord() const { return bForceInfo; }
397 :
398 : // set own index & return new index
399 : // could be overloaded to use more indexes per action
400 : virtual void SetIndex( sal_uInt32& rIndex );
401 :
402 : virtual void Save( XclExpStream& rStrm );
403 : virtual sal_Size GetLen() const;
404 :
405 0 : inline XclExpChTrAction* GetAddAction() { return pAddAction; }
406 : };
407 :
408 0 : inline void XclExpChTrAction::Write2DAddress( XclExpStream& rStrm, const ScAddress& rAddress ) const
409 : {
410 0 : rStrm << (sal_uInt16) rAddress.Row()
411 0 : << (sal_uInt16) rAddress.Col();
412 0 : }
413 :
414 0 : inline void XclExpChTrAction::Write2DRange( XclExpStream& rStrm, const ScRange& rRange ) const
415 : {
416 0 : rStrm << (sal_uInt16) rRange.aStart.Row()
417 0 : << (sal_uInt16) rRange.aEnd.Row()
418 0 : << (sal_uInt16) rRange.aStart.Col()
419 0 : << (sal_uInt16) rRange.aEnd.Col();
420 0 : }
421 :
422 0 : inline sal_uInt16 XclExpChTrAction::GetTabId( SCTAB nTab ) const
423 : {
424 0 : return rIdBuffer.GetId( rTabInfo.GetXclTab( nTab ) );
425 : }
426 :
427 0 : inline void XclExpChTrAction::WriteTabId( XclExpStream& rStrm, SCTAB nTab ) const
428 : {
429 0 : rStrm << GetTabId( nTab );
430 0 : }
431 :
432 : //___________________________________________________________________
433 : // XclExpChTrData - cell content itself
434 :
435 : struct XclExpChTrData
436 : {
437 : XclExpString* pString;
438 : XclExpStringRef mpFormattedString;
439 : const ScFormulaCell* mpFormulaCell;
440 : XclTokenArrayRef mxTokArr;
441 : XclExpRefLog maRefLog;
442 : double fValue;
443 : sal_Int32 nRKValue;
444 : sal_uInt16 nType;
445 : sal_Size nSize;
446 :
447 : XclExpChTrData();
448 : ~XclExpChTrData();
449 : void Clear();
450 :
451 : void WriteFormula(
452 : XclExpStream& rStrm,
453 : const XclExpChTrTabIdBuffer& rTabIdBuffer );
454 : void Write(
455 : XclExpStream& rStrm,
456 : const XclExpChTrTabIdBuffer& rTabIdBuffer );
457 : };
458 :
459 : //___________________________________________________________________
460 : // XclExpChTrCellContent - changed cell content
461 :
462 : class XclExpChTrCellContent : public XclExpChTrAction, protected XclExpRoot
463 : {
464 : private:
465 : XclExpChTrData* pOldData;
466 : XclExpChTrData* pNewData;
467 : sal_uInt16 nOldLength; // this is not the record size
468 :
469 : void MakeEmptyChTrData( XclExpChTrData*& rpData );
470 :
471 : protected:
472 : ScAddress aPosition;
473 :
474 : void GetCellData(
475 : const XclExpRoot& rRoot,
476 : const ScBaseCell* pScCell,
477 : XclExpChTrData*& rpData,
478 : sal_uInt32& rXclLength1,
479 : sal_uInt16& rXclLength2 );
480 :
481 : virtual void SaveActionData( XclExpStream& rStrm ) const;
482 :
483 : public:
484 : XclExpChTrCellContent(
485 : const ScChangeActionContent& rAction,
486 : const XclExpRoot& rRoot,
487 : const XclExpChTrTabIdBuffer& rTabIdBuffer );
488 : virtual ~XclExpChTrCellContent();
489 :
490 : virtual sal_uInt16 GetNum() const;
491 : virtual sal_Size GetActionByteCount() const;
492 :
493 : virtual void SaveXml( XclExpXmlStream& rStrm );
494 : };
495 :
496 : //___________________________________________________________________
497 : // XclExpChTrInsert - insert/delete columns/rows
498 :
499 : class XclExpChTrInsert : public XclExpChTrAction
500 : {
501 : protected:
502 : ScRange aRange;
503 :
504 0 : XclExpChTrInsert( const XclExpChTrInsert& rCopy ) :
505 0 : XclExpChTrAction( rCopy ), aRange( rCopy.aRange ) {}
506 :
507 : virtual void SaveActionData( XclExpStream& rStrm ) const;
508 : virtual void PrepareSaveAction( XclExpStream& rStrm ) const;
509 : virtual void CompleteSaveAction( XclExpStream& rStrm ) const;
510 :
511 : public:
512 : XclExpChTrInsert(
513 : const ScChangeAction& rAction,
514 : const XclExpRoot& rRoot,
515 : const XclExpChTrTabIdBuffer& rTabIdBuffer,
516 : ScChangeTrack& rChangeTrack );
517 : virtual ~XclExpChTrInsert();
518 :
519 : virtual sal_uInt16 GetNum() const;
520 : virtual sal_Size GetActionByteCount() const;
521 :
522 : virtual void SaveXml( XclExpXmlStream& rStrm );
523 : };
524 :
525 : //___________________________________________________________________
526 : // XclExpChTrInsertTab - insert table
527 :
528 : class XclExpChTrInsertTab : public XclExpChTrAction, protected XclExpRoot
529 : {
530 : private:
531 : SCTAB nTab;
532 :
533 : protected:
534 : virtual void SaveActionData( XclExpStream& rStrm ) const;
535 :
536 : public:
537 : XclExpChTrInsertTab(
538 : const ScChangeAction& rAction,
539 : const XclExpRoot& rRoot,
540 : const XclExpChTrTabIdBuffer& rTabIdBuffer );
541 : virtual ~XclExpChTrInsertTab();
542 :
543 : virtual sal_uInt16 GetNum() const;
544 : virtual sal_Size GetActionByteCount() const;
545 :
546 : virtual void SaveXml( XclExpXmlStream& rStrm );
547 : };
548 :
549 : //___________________________________________________________________
550 : // XclExpChTrMoveRange - move cell range
551 :
552 : class XclExpChTrMoveRange : public XclExpChTrAction
553 : {
554 : protected:
555 : ScRange aSourceRange;
556 : ScRange aDestRange;
557 :
558 : virtual void SaveActionData( XclExpStream& rStrm ) const;
559 : virtual void PrepareSaveAction( XclExpStream& rStrm ) const;
560 : virtual void CompleteSaveAction( XclExpStream& rStrm ) const;
561 :
562 : public:
563 : XclExpChTrMoveRange(
564 : const ScChangeActionMove& rAction,
565 : const XclExpRoot& rRoot,
566 : const XclExpChTrTabIdBuffer& rTabIdBuffer,
567 : ScChangeTrack& rChangeTrack );
568 : virtual ~XclExpChTrMoveRange();
569 :
570 : virtual sal_uInt16 GetNum() const;
571 : virtual sal_Size GetActionByteCount() const;
572 :
573 : virtual void SaveXml( XclExpXmlStream& rStrm );
574 : };
575 :
576 : //___________________________________________________________________
577 : // XclExpChTr0x019A - additional data for delete action
578 :
579 : class XclExpChTr0x014A : public XclExpChTrInsert
580 : {
581 : protected:
582 : virtual void SaveActionData( XclExpStream& rStrm ) const;
583 :
584 : public:
585 : XclExpChTr0x014A( const XclExpChTrInsert& rAction );
586 : virtual ~XclExpChTr0x014A();
587 :
588 : virtual sal_uInt16 GetNum() const;
589 : virtual sal_Size GetActionByteCount() const;
590 :
591 : virtual void SaveXml( XclExpXmlStream& rStrm );
592 : };
593 :
594 : //___________________________________________________________________
595 : // XclExpChangeTrack - exports the "Revision Log" stream
596 :
597 : class XclExpChangeTrack : protected XclExpRoot
598 : {
599 : private:
600 : std::vector<ExcRecord*> aRecList; // list of "Revision Log" stream records
601 : std::stack<XclExpChTrAction*> aActionStack;
602 : XclExpChTrTabIdBuffer* pTabIdBuffer;
603 : std::vector<XclExpChTrTabIdBuffer*> maBuffers;
604 :
605 : ScDocument* pTempDoc; // empty document
606 :
607 : XclExpChTrHeader* pHeader; // header record for last GUID
608 : sal_uInt8 aGUID[ 16 ]; // GUID for action info records
609 : sal_Bool bValidGUID;
610 :
611 : ScChangeTrack* CreateTempChangeTrack();
612 : void PushActionRecord( const ScChangeAction& rAction );
613 :
614 : sal_Bool WriteUserNamesStream();
615 :
616 : public:
617 : XclExpChangeTrack( const XclExpRoot& rRoot );
618 : ~XclExpChangeTrack();
619 :
620 : void Write();
621 : void WriteXml( XclExpXmlStream& rStrm );
622 : };
623 :
624 : //___________________________________________________________________
625 :
626 : #endif
627 :
628 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|