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: chgtrack.hxx,v $
10 * $Revision: 1.31.32.4 $
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_CHGTRACK_HXX
32 #define SC_CHGTRACK_HXX
35 #include <tools/string.hxx>
36 #include <tools/datetime.hxx>
37 #include <tools/table.hxx>
38 #include <tools/stack.hxx>
39 #include <tools/queue.hxx>
40 #include <tools/mempool.hxx>
41 #include <tools/link.hxx>
42 #include <svtools/lstner.hxx>
44 #include "bigrange.hxx"
45 #include "collect.hxx"
48 #ifdef SC_CHGTRACK_CXX
50 #include "refupdat.hxx"
53 #define DEBUG_CHANGETRACK 0
60 enum ScChangeActionType
75 enum ScChangeActionState
83 enum ScChangeActionClipMode
93 // --- ScChangeActionLinkEntry ---------------------------------------------
95 // Fuegt sich selbst am Beginn einer Kette ein, bzw. vor einem anderen
96 // LinkEntry, on delete selbstaendiges ausklinken auch des gelinkten.
97 // ppPrev == &previous->pNext oder Adresse des Pointers auf Beginn der Kette,
100 class ScChangeAction
;
102 class ScChangeActionLinkEntry
104 // not implemented, prevent usage
105 ScChangeActionLinkEntry(
106 const ScChangeActionLinkEntry
& );
107 ScChangeActionLinkEntry
& operator=( const ScChangeActionLinkEntry
& );
111 ScChangeActionLinkEntry
* pNext
;
112 ScChangeActionLinkEntry
** ppPrev
;
113 ScChangeAction
* pAction
;
114 ScChangeActionLinkEntry
* pLink
;
118 DECL_FIXEDMEMPOOL_NEWDEL( ScChangeActionLinkEntry
)
120 ScChangeActionLinkEntry(
121 ScChangeActionLinkEntry
** ppPrevP
,
122 ScChangeAction
* pActionP
)
129 pNext
->ppPrev
= &pNext
;
133 virtual ~ScChangeActionLinkEntry()
135 ScChangeActionLinkEntry
* p
= pLink
;
142 void SetLink( ScChangeActionLinkEntry
* pLinkP
)
148 pLinkP
->pLink
= this;
165 if ( ( *ppPrev
= pNext
) != NULL
)
166 pNext
->ppPrev
= ppPrev
;
167 ppPrev
= NULL
; // not inserted
171 void Insert( ScChangeActionLinkEntry
** ppPrevP
)
176 if ( (pNext
= *ppPrevP
) )
177 pNext
->ppPrev
= &pNext
;
182 const ScChangeActionLinkEntry
* GetLink() const { return pLink
; }
183 ScChangeActionLinkEntry
* GetLink() { return pLink
; }
184 const ScChangeActionLinkEntry
* GetNext() const { return pNext
; }
185 ScChangeActionLinkEntry
* GetNext() { return pNext
; }
186 const ScChangeAction
* GetAction() const { return pAction
; }
187 ScChangeAction
* GetAction() { return pAction
; }
188 #if DEBUG_CHANGETRACK
189 String
ToString() const;
190 #endif // DEBUG_CHANGETRACK
193 // --- ScChangeActionCellListEntry -----------------------------------------
194 // this is only for the XML Export in the hxx
195 class ScChangeActionContent
;
197 class ScChangeActionCellListEntry
199 friend class ScChangeAction
;
200 friend class ScChangeActionDel
;
201 friend class ScChangeActionMove
;
202 friend class ScChangeTrack
;
204 ScChangeActionCellListEntry
* pNext
;
205 ScChangeActionContent
* pContent
;
207 ScChangeActionCellListEntry(
208 ScChangeActionContent
* pContentP
,
209 ScChangeActionCellListEntry
* pNextP
)
211 pContent( pContentP
)
215 const ScChangeActionCellListEntry
* GetNext() const { return pNext
; } // this is only for the XML Export public
216 const ScChangeActionContent
* GetContent() const { return pContent
; } // this is only for the XML Export public
218 DECL_FIXEDMEMPOOL_NEWDEL( ScChangeActionCellListEntry
)
221 // --- ScChangeAction -------------------------------------------------------
224 class ScChangeActionIns
;
225 class ScChangeActionDel
;
226 class ScChangeActionContent
;
230 friend class ScChangeTrack
;
231 friend class ScChangeActionIns
;
232 friend class ScChangeActionDel
;
233 friend class ScChangeActionMove
;
234 friend class ScChangeActionContent
;
236 // not implemented, prevent usage
237 ScChangeAction( const ScChangeAction
& );
238 ScChangeAction
& operator=( const ScChangeAction
& );
242 ScBigRange aBigRange
; // Ins/Del/MoveTo/ContentPos
243 DateTime aDateTime
; //! UTC
244 String aUser
; // wer war's
245 String aComment
; // Benutzerkommentar
246 ScChangeAction
* pNext
; // naechster in Kette
247 ScChangeAction
* pPrev
; // vorheriger in Kette
248 ScChangeActionLinkEntry
* pLinkAny
; // irgendwelche Links
249 ScChangeActionLinkEntry
* pLinkDeletedIn
; // Zuordnung zu
251 // druebergemoveten oder
254 ScChangeActionLinkEntry
* pLinkDeleted
; // Links zu geloeschten
255 ScChangeActionLinkEntry
* pLinkDependent
; // Links zu abhaengigen
258 ScChangeActionType eType
;
259 ScChangeActionState eState
;
262 ScChangeAction( ScChangeActionType
,
265 // only to be used in the XML import
266 ScChangeAction( ScChangeActionType
,
269 const ULONG nRejectAction
,
270 const ScChangeActionState eState
,
271 const DateTime
& aDateTime
,
273 const String
& aComment
);
274 // only to be used in the XML import
275 ScChangeAction( ScChangeActionType
,
277 const ULONG nAction
);
279 virtual ~ScChangeAction();
281 String
GetRefString( const ScBigRange
&,
282 ScDocument
*, BOOL bFlag3D
= FALSE
) const;
284 void SetActionNumber( ULONG n
) { nAction
= n
; }
285 void SetRejectAction( ULONG n
) { nRejectAction
= n
; }
286 void SetUser( const String
& r
) { aUser
= r
; }
287 void SetType( ScChangeActionType e
) { eType
= e
; }
288 void SetState( ScChangeActionState e
) { eState
= e
; }
291 ScBigRange
& GetBigRange() { return aBigRange
; }
293 ScChangeActionLinkEntry
* AddLink( ScChangeAction
* p
,
294 ScChangeActionLinkEntry
* pL
)
296 ScChangeActionLinkEntry
* pLnk
=
297 new ScChangeActionLinkEntry(
302 void RemoveAllAnyLinks();
304 virtual ScChangeActionLinkEntry
* GetDeletedIn() const
305 { return pLinkDeletedIn
; }
306 virtual ScChangeActionLinkEntry
** GetDeletedInAddress()
307 { return &pLinkDeletedIn
; }
308 ScChangeActionLinkEntry
* AddDeletedIn( ScChangeAction
* p
)
310 return new ScChangeActionLinkEntry(
311 GetDeletedInAddress(), p
);
313 BOOL
RemoveDeletedIn( const ScChangeAction
* );
314 void RemoveAllDeletedIn();
315 void SetDeletedIn( ScChangeAction
* );
317 ScChangeActionLinkEntry
* AddDeleted( ScChangeAction
* p
)
319 return new ScChangeActionLinkEntry(
322 void RemoveAllDeleted();
324 ScChangeActionLinkEntry
* AddDependent( ScChangeAction
* p
)
326 return new ScChangeActionLinkEntry(
327 &pLinkDependent
, p
);
329 void RemoveAllDependent();
331 void RemoveAllLinks();
333 virtual void AddContent( ScChangeActionContent
* ) = 0;
334 virtual void DeleteCellEntries() = 0;
336 virtual void UpdateReference( const ScChangeTrack
*,
337 UpdateRefMode
, const ScBigRange
&,
338 INT32 nDx
, INT32 nDy
, INT32 nDz
);
341 virtual BOOL
Reject( ScDocument
* ) = 0;
342 void RejectRestoreContents( ScChangeTrack
*,
343 SCsCOL nDx
, SCsROW nDy
);
345 // used in Reject() instead of IsRejectable()
346 BOOL
IsInternalRejectable() const;
348 // Derived classes that hold a pointer to the
349 // ChangeTrack must return that. Otherwise NULL.
350 virtual const ScChangeTrack
* GetChangeTrack() const = 0;
354 BOOL
IsInsertType() const
356 return eType
== SC_CAT_INSERT_COLS
||
357 eType
== SC_CAT_INSERT_ROWS
||
358 eType
== SC_CAT_INSERT_TABS
;
360 BOOL
IsDeleteType() const
362 return eType
== SC_CAT_DELETE_COLS
||
363 eType
== SC_CAT_DELETE_ROWS
||
364 eType
== SC_CAT_DELETE_TABS
;
366 BOOL
IsVirgin() const
367 { return eState
== SC_CAS_VIRGIN
; }
368 BOOL
IsAccepted() const
369 { return eState
== SC_CAS_ACCEPTED
; }
370 BOOL
IsRejected() const
371 { return eState
== SC_CAS_REJECTED
; }
373 // Action rejects another Action
374 BOOL
IsRejecting() const
375 { return nRejectAction
!= 0; }
377 // ob Action im Dokument sichtbar ist
378 BOOL
IsVisible() const;
380 // ob Action anfassbar ist
381 BOOL
IsTouchable() const;
383 // ob Action ein Eintrag in Dialog-Root ist
384 BOOL
IsDialogRoot() const;
386 // ob ein Eintrag im Dialog aufklappbar sein soll
387 BOOL
IsDialogParent() const;
389 // ob Action ein Delete ist, unter dem
390 // aufgeklappt mehrere einzelne Deletes sind
391 BOOL
IsMasterDelete() const;
393 // ob Action akzeptiert/selektiert/abgelehnt
395 BOOL
IsClickable() const;
397 // ob Action abgelehnt werden kann
398 BOOL
IsRejectable() const;
400 const ScBigRange
& GetBigRange() const { return aBigRange
; }
401 SC_DLLPUBLIC DateTime
GetDateTime() const; // local time
402 const DateTime
& GetDateTimeUTC() const // UTC time
403 { return aDateTime
; }
404 const String
& GetUser() const { return aUser
; }
405 const String
& GetComment() const { return aComment
; }
406 ScChangeActionType
GetType() const { return eType
; }
407 ScChangeActionState
GetState() const { return eState
; }
408 ULONG
GetActionNumber() const { return nAction
; }
409 ULONG
GetRejectAction() const { return nRejectAction
; }
411 ScChangeAction
* GetNext() const { return pNext
; }
412 ScChangeAction
* GetPrev() const { return pPrev
; }
414 BOOL
IsDeletedIn() const
415 { return GetDeletedIn() != NULL
; }
416 BOOL
IsDeleted() const
417 { return IsDeleteType() || IsDeletedIn(); }
418 BOOL
IsDeletedIn( const ScChangeAction
* ) const;
419 BOOL
IsDeletedInDelType( ScChangeActionType
) const;
421 const ScChangeActionLinkEntry
* GetFirstDeletedEntry() const
422 { return pLinkDeleted
; }
423 const ScChangeActionLinkEntry
* GetFirstDependentEntry() const
424 { return pLinkDependent
; }
425 BOOL
HasDependent() const
426 { return pLinkDependent
!= NULL
; }
427 BOOL
HasDeleted() const
428 { return pLinkDeleted
!= NULL
; }
430 // Description wird an String angehaengt.
431 // Mit bSplitRange wird bei Delete nur
432 // eine Spalte/Zeile beruecksichtigt (fuer
433 // Auflistung der einzelnen Eintraege).
434 virtual void GetDescription( String
&, ScDocument
*,
435 BOOL bSplitRange
= FALSE
, bool bWarning
= true ) const;
437 virtual void GetRefString( String
&, ScDocument
*,
438 BOOL bFlag3D
= FALSE
) const;
440 // fuer DocumentMerge altes Datum einer anderen
441 // Action setzen, mit GetDateTimeUTC geholt
442 void SetDateTimeUTC( const DateTime
& rDT
)
445 // Benutzerkommentar setzen
446 void SetComment( const String
& rStr
)
449 // only to be used in the XML import
450 void SetDeletedInThis( ULONG nActionNumber
,
451 const ScChangeTrack
* pTrack
);
452 // only to be used in the XML import
453 void AddDependent( ULONG nActionNumber
,
454 const ScChangeTrack
* pTrack
);
455 #if DEBUG_CHANGETRACK
456 String
ToString( ScDocument
* pDoc
) const;
457 #endif // DEBUG_CHANGETRACK
461 // --- ScChangeActionIns ----------------------------------------------------
463 class ScChangeActionIns
: public ScChangeAction
465 friend class ScChangeTrack
;
467 ScChangeActionIns( const ScRange
& rRange
);
468 virtual ~ScChangeActionIns();
470 virtual void AddContent( ScChangeActionContent
* ) {}
471 virtual void DeleteCellEntries() {}
473 virtual BOOL
Reject( ScDocument
* );
475 virtual const ScChangeTrack
* GetChangeTrack() const { return 0; }
478 ScChangeActionIns(const ULONG nActionNumber
,
479 const ScChangeActionState eState
,
480 const ULONG nRejectingNumber
,
481 const ScBigRange
& aBigRange
,
483 const DateTime
& aDateTime
,
484 const String
&sComment
,
485 const ScChangeActionType eType
); // only to use in the XML import
487 virtual void GetDescription( String
&, ScDocument
*,
488 BOOL bSplitRange
= FALSE
, bool bWarning
= true ) const;
492 // --- ScChangeActionDel ----------------------------------------------------
494 class ScChangeActionMove
;
496 class ScChangeActionDelMoveEntry
: public ScChangeActionLinkEntry
498 friend class ScChangeActionDel
;
499 friend class ScChangeTrack
;
505 ScChangeActionDelMoveEntry(
506 ScChangeActionDelMoveEntry
** ppPrevP
,
507 ScChangeActionMove
* pMove
,
508 short nFrom
, short nTo
)
509 : ScChangeActionLinkEntry(
510 (ScChangeActionLinkEntry
**)
512 (ScChangeAction
*) pMove
),
513 nCutOffFrom( nFrom
),
517 ScChangeActionDelMoveEntry
* GetNext()
519 return (ScChangeActionDelMoveEntry
*)
520 ScChangeActionLinkEntry::GetNext();
522 ScChangeActionMove
* GetMove()
524 return (ScChangeActionMove
*)
525 ScChangeActionLinkEntry::GetAction();
529 const ScChangeActionDelMoveEntry
* GetNext() const
531 return (const ScChangeActionDelMoveEntry
*)
532 ScChangeActionLinkEntry::GetNext();
534 const ScChangeActionMove
* GetMove() const
536 return (const ScChangeActionMove
*)
537 ScChangeActionLinkEntry::GetAction();
539 short GetCutOffFrom() const { return nCutOffFrom
; }
540 short GetCutOffTo() const { return nCutOffTo
; }
544 class ScChangeActionDel
: public ScChangeAction
546 friend class ScChangeTrack
;
547 friend void ScChangeAction::Accept();
549 ScChangeTrack
* pTrack
;
550 ScChangeActionCellListEntry
* pFirstCell
;
551 ScChangeActionIns
* pCutOff
; // abgeschnittener Insert
552 short nCutOff
; // +: Start -: End
553 ScChangeActionDelMoveEntry
* pLinkMove
;
557 ScChangeActionDel( const ScRange
& rRange
,
558 SCsCOL nDx
, SCsROW nDy
, ScChangeTrack
* );
559 virtual ~ScChangeActionDel();
561 ScChangeActionIns
* GetCutOffInsert() { return pCutOff
; }
563 virtual void AddContent( ScChangeActionContent
* );
564 virtual void DeleteCellEntries();
566 void UndoCutOffMoves();
567 void UndoCutOffInsert();
569 virtual void UpdateReference( const ScChangeTrack
*,
570 UpdateRefMode
, const ScBigRange
&,
571 INT32 nDx
, INT32 nDy
, INT32 nDz
);
573 virtual BOOL
Reject( ScDocument
* );
575 virtual const ScChangeTrack
* GetChangeTrack() const { return pTrack
; }
578 ScChangeActionDel(const ULONG nActionNumber
,
579 const ScChangeActionState eState
,
580 const ULONG nRejectingNumber
,
581 const ScBigRange
& aBigRange
,
583 const DateTime
& aDateTime
,
584 const String
&sComment
,
585 const ScChangeActionType eType
,
587 ScChangeTrack
* pTrack
); // only to use in the XML import
588 // wich of nDx and nDy is set is depend on the type
590 // ob dieses das unterste einer Reihe (oder
592 BOOL
IsBaseDelete() const;
594 // ob dieses das oberste einer Reihe (oder
596 BOOL
IsTopDelete() const;
598 // ob dieses ein Teil einer Reihe ist
599 BOOL
IsMultiDelete() const;
601 // ob es eine Col ist, die zu einem TabDelete gehoert
602 BOOL
IsTabDeleteCol() const;
604 SCsCOL
GetDx() const { return nDx
; }
605 SCsROW
GetDy() const { return nDy
; }
606 ScBigRange
GetOverAllRange() const; // BigRange + (nDx, nDy)
608 const ScChangeActionCellListEntry
* GetFirstCellEntry() const
609 { return pFirstCell
; }
610 const ScChangeActionDelMoveEntry
* GetFirstMoveEntry() const
611 { return pLinkMove
; }
612 const ScChangeActionIns
* GetCutOffInsert() const { return pCutOff
; }
613 short GetCutOffCount() const { return nCutOff
; }
615 virtual void GetDescription( String
&, ScDocument
*,
616 BOOL bSplitRange
= FALSE
, bool bWarning
= true ) const;
617 void SetCutOffInsert( ScChangeActionIns
* p
, short n
)
618 { pCutOff
= p
; nCutOff
= n
; } // only to use in the XML import
619 // this should be protected, but for the XML import it is public
620 // only to use in the XML import
621 // this should be protected, but for the XML import it is public
622 ScChangeActionDelMoveEntry
* AddCutOffMove( ScChangeActionMove
* pMove
,
623 short nFrom
, short nTo
)
625 return new ScChangeActionDelMoveEntry(
626 &pLinkMove
, pMove
, nFrom
, nTo
);
631 // --- ScChangeActionMove ---------------------------------------------------
633 class ScChangeActionMove
: public ScChangeAction
635 friend class ScChangeTrack
;
636 friend class ScChangeActionDel
;
638 ScBigRange aFromRange
;
639 ScChangeTrack
* pTrack
;
640 ScChangeActionCellListEntry
* pFirstCell
;
641 ULONG nStartLastCut
; // fuer PasteCut Undo
644 ScChangeActionMove( const ScRange
& rFromRange
,
645 const ScRange
& rToRange
,
646 ScChangeTrack
* pTrackP
)
647 : ScChangeAction( SC_CAT_MOVE
, rToRange
),
648 aFromRange( rFromRange
),
654 virtual ~ScChangeActionMove();
656 virtual void AddContent( ScChangeActionContent
* );
657 virtual void DeleteCellEntries();
659 ScBigRange
& GetFromRange() { return aFromRange
; }
661 void SetStartLastCut( ULONG nVal
) { nStartLastCut
= nVal
; }
662 ULONG
GetStartLastCut() const { return nStartLastCut
; }
663 void SetEndLastCut( ULONG nVal
) { nEndLastCut
= nVal
; }
664 ULONG
GetEndLastCut() const { return nEndLastCut
; }
666 virtual void UpdateReference( const ScChangeTrack
*,
667 UpdateRefMode
, const ScBigRange
&,
668 INT32 nDx
, INT32 nDy
, INT32 nDz
);
670 virtual BOOL
Reject( ScDocument
* );
672 virtual const ScChangeTrack
* GetChangeTrack() const { return pTrack
; }
675 using ScChangeAction::GetRefString
;
678 ScChangeActionMove(const ULONG nActionNumber
,
679 const ScChangeActionState eState
,
680 const ULONG nRejectingNumber
,
681 const ScBigRange
& aToBigRange
,
683 const DateTime
& aDateTime
,
684 const String
&sComment
,
685 const ScBigRange
& aFromBigRange
,
686 ScChangeTrack
* pTrack
); // only to use in the XML import
687 const ScChangeActionCellListEntry
* GetFirstCellEntry() const
688 { return pFirstCell
; } // only to use in the XML export
690 const ScBigRange
& GetFromRange() const { return aFromRange
; }
691 SC_DLLPUBLIC
void GetDelta( INT32
& nDx
, INT32
& nDy
, INT32
& nDz
) const;
693 virtual void GetDescription( String
&, ScDocument
*,
694 BOOL bSplitRange
= FALSE
, bool bWarning
= true ) const;
696 virtual void GetRefString( String
&, ScDocument
*,
697 BOOL bFlag3D
= FALSE
) const;
701 // --- ScChangeActionContent ------------------------------------------------
703 enum ScChangeActionContentCellType
713 class ScChangeActionContent
: public ScChangeAction
715 friend class ScChangeTrack
;
719 ScBaseCell
* pOldCell
;
720 ScBaseCell
* pNewCell
;
721 ScChangeActionContent
* pNextContent
; // an gleicher Position
722 ScChangeActionContent
* pPrevContent
;
723 ScChangeActionContent
* pNextInSlot
; // in gleichem Slot
724 ScChangeActionContent
** ppPrevInSlot
;
726 void InsertInSlot( ScChangeActionContent
** pp
)
731 if ( ( pNextInSlot
= *pp
) != NULL
)
732 pNextInSlot
->ppPrevInSlot
= &pNextInSlot
;
736 void RemoveFromSlot()
740 if ( ( *ppPrevInSlot
= pNextInSlot
) != NULL
)
741 pNextInSlot
->ppPrevInSlot
= ppPrevInSlot
;
742 ppPrevInSlot
= NULL
; // not inserted
745 ScChangeActionContent
* GetNextInSlot() { return pNextInSlot
; }
749 static void GetStringOfCell( String
& rStr
,
750 const ScBaseCell
* pCell
,
751 const ScDocument
* pDoc
,
752 const ScAddress
& rPos
);
754 static void GetStringOfCell( String
& rStr
,
755 const ScBaseCell
* pCell
,
756 const ScDocument
* pDoc
,
759 static void SetValue( String
& rStr
, ScBaseCell
*& pCell
,
760 const ScAddress
& rPos
,
761 const ScBaseCell
* pOrgCell
,
762 const ScDocument
* pFromDoc
,
763 ScDocument
* pToDoc
);
765 static void SetValue( String
& rStr
, ScBaseCell
*& pCell
,
767 const ScBaseCell
* pOrgCell
,
768 const ScDocument
* pFromDoc
,
769 ScDocument
* pToDoc
);
771 static void SetCell( String
& rStr
, ScBaseCell
* pCell
,
772 ULONG nFormat
, const ScDocument
* pDoc
);
774 static BOOL
NeedsNumberFormat( const ScBaseCell
* );
776 void SetValueString( String
& rValue
,
777 ScBaseCell
*& pCell
, const String
& rStr
,
780 void GetValueString( String
& rStr
,
781 const String
& rValue
,
782 const ScBaseCell
* pCell
) const;
784 void GetFormulaString( String
& rStr
,
785 const ScFormulaCell
* pCell
) const;
787 virtual void AddContent( ScChangeActionContent
* ) {}
788 virtual void DeleteCellEntries() {}
790 virtual void UpdateReference( const ScChangeTrack
*,
791 UpdateRefMode
, const ScBigRange
&,
792 INT32 nDx
, INT32 nDy
, INT32 nDz
);
794 virtual BOOL
Reject( ScDocument
* );
796 virtual const ScChangeTrack
* GetChangeTrack() const { return 0; }
798 // pRejectActions!=NULL: reject actions get
799 // stacked, no SetNewValue, no Append
800 BOOL
Select( ScDocument
*, ScChangeTrack
*,
801 BOOL bOldest
, Stack
* pRejectActions
);
803 void PutValueToDoc( ScBaseCell
*, const String
&,
804 ScDocument
*, SCsCOL nDx
, SCsROW nDy
) const;
807 using ScChangeAction::GetRefString
;
811 DECL_FIXEDMEMPOOL_NEWDEL( ScChangeActionContent
)
813 ScChangeActionContent( const ScRange
& rRange
)
814 : ScChangeAction( SC_CAT_CONTENT
, rRange
),
817 pNextContent( NULL
),
818 pPrevContent( NULL
),
822 ScChangeActionContent(const ULONG nActionNumber
,
823 const ScChangeActionState eState
,
824 const ULONG nRejectingNumber
,
825 const ScBigRange
& aBigRange
,
827 const DateTime
& aDateTime
,
828 const String
&sComment
,
829 ScBaseCell
* pOldCell
,
831 const String
& sOldValue
); // to use for XML Import
832 ScChangeActionContent(const ULONG nActionNumber
,
833 ScBaseCell
* pNewCell
,
834 const ScBigRange
& aBigRange
,
836 const String
& sNewValue
); // to use for XML Import of Generated Actions
837 virtual ~ScChangeActionContent();
839 ScChangeActionContent
* GetNextContent() const { return pNextContent
; }
840 ScChangeActionContent
* GetPrevContent() const { return pPrevContent
; }
841 ScChangeActionContent
* GetTopContent() const;
842 BOOL
IsTopContent() const
843 { return pNextContent
== NULL
; }
845 virtual ScChangeActionLinkEntry
* GetDeletedIn() const;
846 virtual ScChangeActionLinkEntry
** GetDeletedInAddress();
848 void PutOldValueToDoc( ScDocument
*,
849 SCsCOL nDx
, SCsROW nDy
) const;
850 void PutNewValueToDoc( ScDocument
*,
851 SCsCOL nDx
, SCsROW nDy
) const;
853 void SetOldValue( const ScBaseCell
*,
854 const ScDocument
* pFromDoc
,
857 void SetOldValue( const ScBaseCell
*,
858 const ScDocument
* pFromDoc
,
859 ScDocument
* pToDoc
);
860 void SetNewValue( const ScBaseCell
*, ScDocument
* );
862 // Used in import filter AppendContentOnTheFly,
863 // takes ownership of cells.
864 void SetOldNewCells( ScBaseCell
* pOldCell
,
865 ULONG nOldFormat
, ScBaseCell
* pNewCell
,
866 ULONG nNewFormat
, ScDocument
* pDoc
);
868 // Use this only in the XML import,
869 // takes ownership of cell.
870 void SetNewCell( ScBaseCell
* pCell
, ScDocument
* pDoc
, const String
& rFormatted
);
872 // These functions should be protected but for
873 // the XML import they are public.
874 void SetNextContent( ScChangeActionContent
* p
)
875 { pNextContent
= p
; }
876 void SetPrevContent( ScChangeActionContent
* p
)
877 { pPrevContent
= p
; }
879 // moeglichst nicht verwenden,
880 // setzt nur String bzw. generiert Formelzelle
881 void SetOldValue( const String
& rOld
, ScDocument
* );
882 void SetNewValue( const String
& rNew
, ScDocument
* );
884 void GetOldString( String
& ) const;
885 void GetNewString( String
& ) const;
886 const ScBaseCell
* GetOldCell() const { return pOldCell
; }
887 const ScBaseCell
* GetNewCell() const { return pNewCell
; }
888 virtual void GetDescription( String
&, ScDocument
*,
889 BOOL bSplitRange
= FALSE
, bool bWarning
= true ) const;
890 virtual void GetRefString( String
&, ScDocument
*,
891 BOOL bFlag3D
= FALSE
) const;
893 static ScChangeActionContentCellType
GetContentCellType( const ScBaseCell
* );
896 BOOL
IsMatrixOrigin() const
898 return GetContentCellType( GetNewCell() )
901 BOOL
IsMatrixReference() const
903 return GetContentCellType( GetNewCell() )
907 BOOL
IsOldMatrixOrigin() const
909 return GetContentCellType( GetOldCell() )
912 BOOL
IsOldMatrixReference() const
914 return GetContentCellType( GetOldCell() )
921 // --- ScChangeActionReject -------------------------------------------------
925 class ScChangeActionReject
: public ScChangeAction
927 friend class ScChangeTrack
;
928 friend class ScChangeActionContent
;
930 ScChangeActionReject( ULONG nReject
)
931 : ScChangeAction( SC_CAT_REJECT
, ScRange() )
933 SetRejectAction( nReject
);
934 SetState( SC_CAS_ACCEPTED
);
937 virtual void AddContent( ScChangeActionContent
* ) {}
938 virtual void DeleteCellEntries() {}
940 virtual BOOL
Reject( ScDocument
* ) { return FALSE
; }
942 virtual const ScChangeTrack
* GetChangeTrack() const { return 0; }
945 ScChangeActionReject(const ULONG nActionNumber
,
946 const ScChangeActionState eState
,
947 const ULONG nRejectingNumber
,
948 const ScBigRange
& aBigRange
,
950 const DateTime
& aDateTime
,
951 const String
&sComment
); // only to use in the XML import
955 // --- ScChangeTrack --------------------------------------------------------
957 enum ScChangeTrackMsgType
960 SC_CTM_APPEND
, // Actions angehaengt
961 SC_CTM_REMOVE
, // Actions weggenommen
962 SC_CTM_CHANGE
, // Actions geaendert
963 SC_CTM_PARENT
// war kein Parent und ist jetzt einer
966 struct ScChangeTrackMsgInfo
968 DECL_FIXEDMEMPOOL_NEWDEL( ScChangeTrackMsgInfo
)
970 ScChangeTrackMsgType eMsgType
;
975 // MsgQueue fuer Benachrichtigung via ModifiedLink
976 DECLARE_QUEUE( ScChangeTrackMsgQueue
, ScChangeTrackMsgInfo
* )
977 DECLARE_STACK( ScChangeTrackMsgStack
, ScChangeTrackMsgInfo
* )
979 enum ScChangeTrackMergeState
988 // zusaetzlich zu pFirst/pNext/pLast/pPrev eine Table, um schnell sowohl
989 // per ActionNumber als auch ueber Liste zugreifen zu koennen
990 DECLARE_TABLE( ScChangeActionTable
, ScChangeAction
* )
992 // Intern generierte Actions beginnen bei diesem Wert (fast alle Bits gesetzt)
993 // und werden runtergezaehlt, um sich in einer Table wertemaessig nicht mit den
994 // "normalen" Actions in die Quere zu kommen.
995 #define SC_CHGTRACK_GENERATED_START ((UINT32) 0xfffffff0)
997 // SfxListener an der Applikation, um Aenderungen des Usernamens mitzubekommen
999 class ScChangeTrack
: public SfxListener
1001 friend void ScChangeAction::RejectRestoreContents( ScChangeTrack
*, SCsCOL
, SCsROW
);
1002 friend BOOL
ScChangeActionDel::Reject( ScDocument
* pDoc
);
1003 friend void ScChangeActionDel::DeleteCellEntries();
1004 friend void ScChangeActionMove::DeleteCellEntries();
1005 friend BOOL
ScChangeActionMove::Reject( ScDocument
* pDoc
);
1007 static const SCROW nContentRowsPerSlot
;
1008 static const SCSIZE nContentSlots
;
1010 com::sun::star::uno::Sequence
< sal_Int8
> aProtectPass
;
1011 ScChangeActionTable aTable
;
1012 ScChangeActionTable aGeneratedTable
;
1013 ScChangeActionTable aPasteCutTable
;
1014 ScChangeTrackMsgQueue aMsgQueue
;
1015 ScChangeTrackMsgStack aMsgStackTmp
;
1016 ScChangeTrackMsgStack aMsgStackFinal
;
1017 ScStrCollection aUserCollection
;
1020 ScRange aInDeleteRange
;
1021 DateTime aFixDateTime
;
1022 ScChangeAction
* pFirst
;
1023 ScChangeAction
* pLast
;
1024 ScChangeActionContent
* pFirstGeneratedDelContent
;
1025 ScChangeActionContent
** ppContentSlots
;
1026 ScChangeActionMove
* pLastCutMove
;
1027 ScChangeActionLinkEntry
* pLinkInsertCol
;
1028 ScChangeActionLinkEntry
* pLinkInsertRow
;
1029 ScChangeActionLinkEntry
* pLinkInsertTab
;
1030 ScChangeActionLinkEntry
* pLinkMove
;
1031 ScChangeTrackMsgInfo
* pBlockModifyMsg
;
1034 ULONG nGeneratedMin
;
1035 ULONG nMarkLastSaved
;
1036 ULONG nStartLastCut
;
1039 ScChangeTrackMergeState eMergeState
;
1040 USHORT nLoadedFileFormatVersion
;
1046 BOOL bUseFixDateTime
;
1047 BOOL bTime100thSeconds
;
1049 // not implemented, prevent usage
1050 ScChangeTrack( const ScChangeTrack
& );
1051 ScChangeTrack
& operator=( const ScChangeTrack
& );
1053 #ifdef SC_CHGTRACK_CXX
1054 static SCROW
InitContentRowsPerSlot();
1056 // TRUE if one is MM_FORMULA and the other is
1057 // not, or if both are and range differs
1058 static BOOL
IsMatrixFormulaRangeDifferent(
1059 const ScBaseCell
* pOldCell
,
1060 const ScBaseCell
* pNewCell
);
1062 virtual void Notify( SfxBroadcaster
&, const SfxHint
& );
1065 void SetLoadSave( BOOL bVal
) { bLoadSave
= bVal
; }
1066 void SetInDeleteRange( const ScRange
& rRange
)
1067 { aInDeleteRange
= rRange
; }
1068 void SetInDelete( BOOL bVal
)
1069 { bInDelete
= bVal
; }
1070 void SetInDeleteTop( BOOL bVal
)
1071 { bInDeleteTop
= bVal
; }
1072 void SetInDeleteUndo( BOOL bVal
)
1073 { bInDeleteUndo
= bVal
; }
1074 void SetInPasteCut( BOOL bVal
)
1075 { bInPasteCut
= bVal
; }
1076 void SetMergeState( ScChangeTrackMergeState eState
)
1077 { eMergeState
= eState
; }
1078 ScChangeTrackMergeState
GetMergeState() const { return eMergeState
; }
1079 void SetLastMerge( ULONG nVal
) { nLastMerge
= nVal
; }
1080 ULONG
GetLastMerge() const { return nLastMerge
; }
1082 void SetLastCutMoveRange( const ScRange
&, ScDocument
* );
1084 // ModifyMsg blockweise und nicht einzeln erzeugen
1085 void StartBlockModify( ScChangeTrackMsgType
,
1086 ULONG nStartAction
);
1087 void EndBlockModify( ULONG nEndAction
);
1089 void AddDependentWithNotify( ScChangeAction
* pParent
,
1090 ScChangeAction
* pDependent
);
1092 void Dependencies( ScChangeAction
* );
1093 void UpdateReference( ScChangeAction
*, BOOL bUndo
);
1094 void UpdateReference( ScChangeAction
** ppFirstAction
,
1095 ScChangeAction
* pAct
, BOOL bUndo
);
1096 void Append( ScChangeAction
* pAppend
, ULONG nAction
);
1097 SC_DLLPUBLIC
void AppendDeleteRange( const ScRange
&,
1098 ScDocument
* pRefDoc
, SCsTAB nDz
,
1099 ULONG nRejectingInsert
);
1100 void AppendOneDeleteRange( const ScRange
& rOrgRange
,
1101 ScDocument
* pRefDoc
,
1102 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
,
1103 ULONG nRejectingInsert
);
1104 void LookUpContents( const ScRange
& rOrgRange
,
1105 ScDocument
* pRefDoc
,
1106 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
1107 void Remove( ScChangeAction
* );
1108 void MasterLinks( ScChangeAction
* );
1110 // Content on top an Position
1111 ScChangeActionContent
* SearchContentAt( const ScBigAddress
&,
1112 ScChangeAction
* pButNotThis
) const;
1113 void DeleteGeneratedDelContent(
1114 ScChangeActionContent
* );
1115 ScChangeActionContent
* GenerateDelContent( const ScAddress
&,
1117 const ScDocument
* pFromDoc
);
1118 void DeleteCellEntries(
1119 ScChangeActionCellListEntry
*&,
1120 ScChangeAction
* pDeletor
);
1122 // Action und alle abhaengigen rejecten,
1123 // Table stammt aus vorherigem GetDependents,
1124 // ist nur bei Insert und Move (MasterType)
1125 // noetig, kann ansonsten NULL sein.
1126 // bRecursion == Aufruf aus Reject mit Table
1127 BOOL
Reject( ScChangeAction
*,
1128 ScChangeActionTable
*, BOOL bRecursion
);
1130 #endif // SC_CHGTRACK_CXX
1132 void ClearMsgQueue();
1136 static SCSIZE
ComputeContentSlot( INT32 nRow
)
1138 if ( nRow
< 0 || nRow
> MAXROW
)
1139 return nContentSlots
- 1;
1140 return static_cast< SCSIZE
>( nRow
/ nContentRowsPerSlot
);
1143 SC_DLLPUBLIC
ScChangeTrack( ScDocument
* );
1144 ScChangeTrack( ScDocument
*,
1145 const ScStrCollection
& ); // only to use in the XML import
1146 SC_DLLPUBLIC
virtual ~ScChangeTrack();
1149 ScChangeActionContent
* GetFirstGenerated() const { return pFirstGeneratedDelContent
; }
1150 ScChangeAction
* GetFirst() const { return pFirst
; }
1151 ScChangeAction
* GetLast() const { return pLast
; }
1152 ULONG
GetActionMax() const { return nActionMax
; }
1153 BOOL
IsGenerated( ULONG nAction
) const
1154 { return nAction
>= nGeneratedMin
; }
1155 ScChangeAction
* GetAction( ULONG nAction
) const
1156 { return aTable
.Get( nAction
); }
1157 ScChangeAction
* GetGenerated( ULONG nGenerated
) const
1158 { return aGeneratedTable
.Get( nGenerated
); }
1159 ScChangeAction
* GetActionOrGenerated( ULONG nAction
) const
1161 return IsGenerated( nAction
) ?
1162 GetGenerated( nAction
) :
1163 GetAction( nAction
);
1165 ULONG
GetLastSavedActionNumber() const
1166 { return nMarkLastSaved
; }
1167 void SetLastSavedActionNumber(ULONG nNew
)
1168 { nMarkLastSaved
= nNew
; }
1169 ScChangeAction
* GetLastSaved() const
1170 { return aTable
.Get( nMarkLastSaved
); }
1171 ScChangeActionContent
** GetContentSlots() const { return ppContentSlots
; }
1173 BOOL
IsLoadSave() const { return bLoadSave
; }
1174 const ScRange
& GetInDeleteRange() const
1175 { return aInDeleteRange
; }
1176 BOOL
IsInDelete() const { return bInDelete
; }
1177 BOOL
IsInDeleteTop() const { return bInDeleteTop
; }
1178 BOOL
IsInDeleteUndo() const { return bInDeleteUndo
; }
1179 BOOL
IsInPasteCut() const { return bInPasteCut
; }
1180 SC_DLLPUBLIC
void SetUser( const String
& );
1181 const String
& GetUser() const { return aUser
; }
1182 const ScStrCollection
& GetUserCollection() const
1183 { return aUserCollection
; }
1184 ScDocument
* GetDocument() const { return pDoc
; }
1185 // for import filter
1186 const DateTime
& GetFixDateTime() const { return aFixDateTime
; }
1188 // set this if the date/time set with
1189 // SetFixDateTime...() shall be applied to
1191 void SetUseFixDateTime( BOOL bVal
)
1192 { bUseFixDateTime
= bVal
; }
1193 // for MergeDocument, apply original date/time as UTC
1194 void SetFixDateTimeUTC( const DateTime
& rDT
)
1195 { aFixDateTime
= rDT
; }
1196 // for import filter, apply original date/time as local time
1197 void SetFixDateTimeLocal( const DateTime
& rDT
)
1198 { aFixDateTime
= rDT
; aFixDateTime
.ConvertToUTC(); }
1200 void Append( ScChangeAction
* );
1202 // pRefDoc may be NULL => no lookup of contents
1203 // => no generation of deleted contents
1204 SC_DLLPUBLIC
void AppendDeleteRange( const ScRange
&,
1205 ScDocument
* pRefDoc
,
1206 ULONG
& nStartAction
, ULONG
& nEndAction
,
1208 // nDz: Multi-TabDel, LookUpContent ist
1209 // um -nDz verschoben zu suchen
1211 // nachdem neuer Wert im Dokument gesetzt wurde,
1212 // alter Wert aus RefDoc/UndoDoc
1213 void AppendContent( const ScAddress
& rPos
,
1214 ScDocument
* pRefDoc
);
1215 // nachdem neue Werte im Dokument gesetzt wurden,
1216 // alte Werte aus RefDoc/UndoDoc
1217 void AppendContentRange( const ScRange
& rRange
,
1218 ScDocument
* pRefDoc
,
1219 ULONG
& nStartAction
, ULONG
& nEndAction
,
1220 ScChangeActionClipMode eMode
= SC_CACM_NONE
);
1221 // nachdem neuer Wert im Dokument gesetzt wurde,
1222 // alter Wert aus pOldCell, nOldFormat,
1223 // RefDoc==NULL => Doc
1224 void AppendContent( const ScAddress
& rPos
,
1225 const ScBaseCell
* pOldCell
,
1226 ULONG nOldFormat
, ScDocument
* pRefDoc
= NULL
);
1227 // nachdem neuer Wert im Dokument gesetzt wurde,
1228 // alter Wert aus pOldCell, Format aus Doc
1229 void AppendContent( const ScAddress
& rPos
,
1230 const ScBaseCell
* pOldCell
);
1231 // nachdem neue Werte im Dokument gesetzt wurden,
1232 // alte Werte aus RefDoc/UndoDoc.
1233 // Alle Contents, wo im RefDoc eine Zelle steht.
1234 void AppendContentsIfInRefDoc( ScDocument
* pRefDoc
,
1235 ULONG
& nStartAction
, ULONG
& nEndAction
);
1237 // Meant for import filter, creates and inserts
1238 // an unconditional content action of the two
1239 // cells without querying the document, not
1240 // even for number formats (though the number
1241 // formatter of the document may be used).
1242 // The action is returned and may be used to
1243 // set user name, description, date/time et al.
1244 // Takes ownership of the cells!
1245 SC_DLLPUBLIC ScChangeActionContent
* AppendContentOnTheFly( const ScAddress
& rPos
,
1246 ScBaseCell
* pOldCell
,
1247 ScBaseCell
* pNewCell
,
1248 ULONG nOldFormat
= 0,
1249 ULONG nNewFormat
= 0 );
1251 // die folgenden beiden nur benutzen wenn's
1252 // nicht anders geht (setzen nur String fuer
1253 // NewValue bzw. Formelerzeugung)
1255 // bevor neuer Wert im Dokument gesetzt wird
1256 void AppendContent( const ScAddress
& rPos
,
1257 const String
& rNewValue
,
1258 ScBaseCell
* pOldCell
);
1260 SC_DLLPUBLIC
void AppendInsert( const ScRange
& );
1262 // pRefDoc may be NULL => no lookup of contents
1263 // => no generation of deleted contents
1264 SC_DLLPUBLIC
void AppendMove( const ScRange
& rFromRange
,
1265 const ScRange
& rToRange
,
1266 ScDocument
* pRefDoc
);
1271 nStartLastCut
= nEndLastCut
= 0;
1274 delete pLastCutMove
;
1275 pLastCutMove
= NULL
;
1278 BOOL
HasLastCut() const
1280 return nEndLastCut
> 0 &&
1281 nStartLastCut
<= nEndLastCut
&&
1285 SC_DLLPUBLIC
void Undo( ULONG nStartAction
, ULONG nEndAction
, bool bMerge
= false );
1287 // fuer MergeDocument, Referenzen anpassen,
1288 //! darf nur in einem temporaer geoeffneten
1289 //! Dokument verwendet werden, der Track
1290 //! ist danach verhunzt
1291 void MergePrepare( ScChangeAction
* pFirstMerge
, bool bShared
= false );
1292 void MergeOwn( ScChangeAction
* pAct
, ULONG nFirstMerge
, bool bShared
= false );
1293 static BOOL
MergeIgnore( const ScChangeAction
&, ULONG nFirstMerge
);
1295 // Abhaengige in Table einfuegen.
1296 // Bei Insert sind es echte Abhaengige,
1297 // bei Move abhaengige Contents im FromRange
1298 // und geloeschte im ToRange bzw. Inserts in
1299 // FromRange oder ToRange,
1300 // bei Delete eine Liste der geloeschten,
1301 // bei Content andere Contents an gleicher
1302 // Position oder MatrixReferences zu MatrixOrigin.
1303 // Mit bListMasterDelete werden unter einem
1304 // MasterDelete alle zu diesem Delete gehoerenden
1305 // Deletes einer Reihe gelistet.
1306 // Mit bAllFlat werden auch alle Abhaengigen
1307 // der Abhaengigen flach eingefuegt.
1308 SC_DLLPUBLIC
void GetDependents( ScChangeAction
*,
1309 ScChangeActionTable
&,
1310 BOOL bListMasterDelete
= FALSE
,
1311 BOOL bAllFlat
= FALSE
) const;
1313 // Reject visible Action (und abhaengige)
1314 BOOL
Reject( ScChangeAction
*, bool bShared
= false );
1316 // Accept visible Action (und abhaengige)
1317 SC_DLLPUBLIC BOOL
Accept( ScChangeAction
* );
1319 void AcceptAll(); // alle Virgins
1320 BOOL
RejectAll(); // alle Virgins
1322 // Selektiert einen Content von mehreren an
1323 // gleicher Position und akzeptiert diesen und
1324 // die aelteren, rejected die neueren.
1325 // Mit bOldest==TRUE wird der erste OldValue
1326 // einer Virgin-Content-Kette restauriert.
1327 BOOL
SelectContent( ScChangeAction
*,
1328 BOOL bOldest
= FALSE
);
1330 // wenn ModifiedLink gesetzt, landen
1331 // Aenderungen in ScChangeTrackMsgQueue
1332 void SetModifiedLink( const Link
& r
)
1333 { aModifiedLink
= r
; ClearMsgQueue(); }
1334 const Link
& GetModifiedLink() const { return aModifiedLink
; }
1335 ScChangeTrackMsgQueue
& GetMsgQueue() { return aMsgQueue
; }
1337 void NotifyModified( ScChangeTrackMsgType eMsgType
,
1338 ULONG nStartAction
, ULONG nEndAction
);
1340 USHORT
GetLoadedFileFormatVersion() const
1341 { return nLoadedFileFormatVersion
; }
1343 ULONG
AddLoadedGenerated(ScBaseCell
* pOldCell
,
1344 const ScBigRange
& aBigRange
, const String
& sNewValue
); // only to use in the XML import
1345 void AppendLoaded( ScChangeAction
* pAppend
); // this is only for the XML import public, it should be protected
1346 void SetActionMax(ULONG nTempActionMax
)
1347 { nActionMax
= nTempActionMax
; } // only to use in the XML import
1349 void SetProtection( const com::sun::star::uno::Sequence
< sal_Int8
>& rPass
)
1350 { aProtectPass
= rPass
; }
1351 com::sun::star::uno::Sequence
< sal_Int8
> GetProtection() const
1352 { return aProtectPass
; }
1353 BOOL
IsProtected() const
1354 { return aProtectPass
.getLength() != 0; }
1356 // If time stamps of actions of this
1357 // ChangeTrack and a second one are to be
1358 // compared including 100th seconds.
1359 void SetTime100thSeconds( BOOL bVal
)
1360 { bTime100thSeconds
= bVal
; }
1361 BOOL
IsTime100thSeconds() const
1362 { return bTime100thSeconds
; }
1364 void AppendCloned( ScChangeAction
* pAppend
);
1365 SC_DLLPUBLIC ScChangeTrack
* Clone( ScDocument
* pDocument
) const;
1366 void MergeActionState( ScChangeAction
* pAct
, const ScChangeAction
* pOtherAct
);
1367 #if DEBUG_CHANGETRACK
1368 String
ToString() const;
1369 #endif // DEBUG_CHANGETRACK