LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLChangeTrackingImportHelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 418 0.0 %
Date: 2014-04-11 Functions: 0 54 0.0 %
Legend: Lines: hit not hit

          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             : #include "XMLChangeTrackingImportHelper.hxx"
      21             : #include "XMLConverter.hxx"
      22             : #include "formulacell.hxx"
      23             : #include "document.hxx"
      24             : #include "chgviset.hxx"
      25             : #include "rangeutl.hxx"
      26             : #include <tools/datetime.hxx>
      27             : #include <svl/zforlist.hxx>
      28             : #include <sax/tools/converter.hxx>
      29             : 
      30             : #define SC_CHANGE_ID_PREFIX "ct"
      31             : 
      32           0 : ScMyCellInfo::ScMyCellInfo(
      33             :     const ScCellValue& rCell, const OUString& rFormulaAddress, const OUString& rFormula,
      34             :     const formula::FormulaGrammar::Grammar eTempGrammar, const OUString& rInputString,
      35             :     const double& rValue, const sal_uInt16 nTempType, const sal_uInt8 nTempMatrixFlag, const sal_Int32 nTempMatrixCols,
      36             :     const sal_Int32 nTempMatrixRows ) :
      37             :     maCell(rCell),
      38             :     sFormulaAddress(rFormulaAddress),
      39             :     sFormula(rFormula),
      40             :     sInputString(rInputString),
      41             :     fValue(rValue),
      42             :     nMatrixCols(nTempMatrixCols),
      43             :     nMatrixRows(nTempMatrixRows),
      44             :     eGrammar( eTempGrammar),
      45             :     nType(nTempType),
      46           0 :     nMatrixFlag(nTempMatrixFlag)
      47             : {
      48           0 : }
      49             : 
      50           0 : ScMyCellInfo::~ScMyCellInfo() {}
      51             : 
      52           0 : const ScCellValue& ScMyCellInfo::CreateCell( ScDocument* pDoc )
      53             : {
      54           0 :     if (!maCell.isEmpty())
      55           0 :         return maCell;
      56             : 
      57           0 :     if (!sFormula.isEmpty() && !sFormulaAddress.isEmpty())
      58             :     {
      59           0 :         ScAddress aPos;
      60           0 :         sal_Int32 nOffset(0);
      61           0 :         ScRangeStringConverter::GetAddressFromString(aPos, sFormulaAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset);
      62           0 :         maCell.meType = CELLTYPE_FORMULA;
      63           0 :         maCell.mpFormula = new ScFormulaCell(pDoc, aPos, sFormula, eGrammar, nMatrixFlag);
      64           0 :         maCell.mpFormula->SetMatColsRows(static_cast<SCCOL>(nMatrixCols), static_cast<SCROW>(nMatrixRows));
      65             :     }
      66             : 
      67           0 :     if ((nType == NUMBERFORMAT_DATE || nType == NUMBERFORMAT_TIME) && sInputString.isEmpty())
      68             :     {
      69           0 :         sal_uInt32 nFormat(0);
      70           0 :         if (nType == NUMBERFORMAT_DATE)
      71           0 :             nFormat = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_DATE, ScGlobal::eLnge );
      72           0 :         else if (nType == NUMBERFORMAT_TIME)
      73           0 :             nFormat = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_TIME, ScGlobal::eLnge );
      74           0 :         pDoc->GetFormatTable()->GetInputLineString(fValue, nFormat, sInputString);
      75             :     }
      76             : 
      77           0 :     return maCell;
      78             : }
      79             : 
      80           0 : ScMyDeleted::ScMyDeleted()
      81           0 :     : pCellInfo(NULL)
      82             : {
      83           0 : }
      84             : 
      85           0 : ScMyDeleted::~ScMyDeleted()
      86             : {
      87           0 :     delete pCellInfo;
      88           0 : }
      89             : 
      90           0 : ScMyGenerated::ScMyGenerated(ScMyCellInfo* pTempCellInfo, const ScBigRange& aTempBigRange)
      91             :     : aBigRange(aTempBigRange),
      92             :     nID(0),
      93           0 :     pCellInfo(pTempCellInfo)
      94             : {
      95           0 : }
      96             : 
      97           0 : ScMyGenerated::~ScMyGenerated()
      98             : {
      99           0 :     delete pCellInfo;
     100           0 : }
     101             : 
     102           0 : ScMyBaseAction::ScMyBaseAction(const ScChangeActionType nTempActionType)
     103             :     : aDependencies(),
     104             :     aDeletedList(),
     105             :     nActionNumber(0),
     106             :     nRejectingNumber(0),
     107             :     nPreviousAction(0),
     108             :     nActionType(nTempActionType),
     109           0 :     nActionState(SC_CAS_VIRGIN)
     110             : {
     111           0 : }
     112             : 
     113           0 : ScMyBaseAction::~ScMyBaseAction()
     114             : {
     115           0 : }
     116             : 
     117           0 : ScMyInsAction::ScMyInsAction(const ScChangeActionType nActionTypeP)
     118           0 :     : ScMyBaseAction(nActionTypeP)
     119             : {
     120           0 : }
     121             : 
     122           0 : ScMyInsAction::~ScMyInsAction()
     123             : {
     124           0 : }
     125             : 
     126           0 : ScMyDelAction::ScMyDelAction(const ScChangeActionType nActionTypeP)
     127             :     : ScMyBaseAction(nActionTypeP),
     128             :     aGeneratedList(),
     129             :     pInsCutOff(NULL),
     130             :     aMoveCutOffs(),
     131           0 :     nD(0)
     132             : {
     133           0 : }
     134             : 
     135           0 : ScMyDelAction::~ScMyDelAction()
     136             : {
     137           0 :     if (pInsCutOff)
     138           0 :         delete pInsCutOff;
     139           0 : }
     140             : 
     141           0 : ScMyMoveAction::ScMyMoveAction()
     142             :     : ScMyBaseAction(SC_CAT_MOVE),
     143             :     aGeneratedList(),
     144           0 :     pMoveRanges(NULL)
     145             : {
     146           0 : }
     147             : 
     148           0 : ScMyMoveAction::~ScMyMoveAction()
     149             : {
     150           0 :     if (pMoveRanges)
     151           0 :         delete pMoveRanges;
     152           0 : }
     153             : 
     154             : 
     155           0 : ScMyContentAction::ScMyContentAction()
     156             :     : ScMyBaseAction(SC_CAT_CONTENT),
     157           0 :     pCellInfo(NULL)
     158             : {
     159           0 : }
     160             : 
     161           0 : ScMyContentAction::~ScMyContentAction()
     162             : {
     163           0 :     delete pCellInfo;
     164           0 : }
     165             : 
     166           0 : ScMyRejAction::ScMyRejAction()
     167           0 :     : ScMyBaseAction(SC_CAT_REJECT)
     168             : {
     169           0 : }
     170             : 
     171           0 : ScMyRejAction::~ScMyRejAction()
     172             : {
     173           0 : }
     174             : 
     175           0 : ScXMLChangeTrackingImportHelper::ScXMLChangeTrackingImportHelper() :
     176             :     aActions(),
     177             :     pDoc(NULL),
     178             :     pTrack(NULL),
     179             :     pCurrentAction(NULL),
     180             :     sIDPrefix(SC_CHANGE_ID_PREFIX),
     181             :     nMultiSpanned(0),
     182             :     nMultiSpannedSlaveCount(0),
     183           0 :     bChangeTrack(false)
     184             : {
     185           0 :     nPrefixLength = sIDPrefix.getLength();
     186           0 : }
     187             : 
     188           0 : ScXMLChangeTrackingImportHelper::~ScXMLChangeTrackingImportHelper()
     189             : {
     190           0 : }
     191             : 
     192           0 : void ScXMLChangeTrackingImportHelper::StartChangeAction(const ScChangeActionType nActionType)
     193             : {
     194             :     OSL_ENSURE(!pCurrentAction, "a not inserted action");
     195           0 :     switch (nActionType)
     196             :     {
     197             :         case SC_CAT_INSERT_COLS:
     198             :         case SC_CAT_INSERT_ROWS:
     199             :         case SC_CAT_INSERT_TABS:
     200             :         {
     201           0 :             pCurrentAction = new ScMyInsAction(nActionType);
     202             :         }
     203           0 :         break;
     204             :         case SC_CAT_DELETE_COLS:
     205             :         case SC_CAT_DELETE_ROWS:
     206             :         case SC_CAT_DELETE_TABS:
     207             :         {
     208           0 :             pCurrentAction = new ScMyDelAction(nActionType);
     209             :         }
     210           0 :         break;
     211             :         case SC_CAT_MOVE:
     212             :         {
     213           0 :             pCurrentAction = new ScMyMoveAction();
     214             :         }
     215           0 :         break;
     216             :         case SC_CAT_CONTENT:
     217             :         {
     218           0 :             pCurrentAction = new ScMyContentAction();
     219             :         }
     220           0 :         break;
     221             :         case SC_CAT_REJECT:
     222             :         {
     223           0 :             pCurrentAction = new ScMyRejAction();
     224             :         }
     225           0 :         break;
     226             :         default:
     227             :         {
     228             :             // added to avoid warnings
     229             :         }
     230             :     }
     231           0 : }
     232             : 
     233           0 : sal_uInt32 ScXMLChangeTrackingImportHelper::GetIDFromString(const OUString& sID)
     234             : {
     235           0 :     sal_uInt32 nResult(0);
     236           0 :     sal_uInt32 nLength(sID.getLength());
     237           0 :     if (nLength)
     238             :     {
     239           0 :         if (sID.compareTo(sIDPrefix, nPrefixLength) == 0)
     240             :         {
     241           0 :             OUString sValue(sID.copy(nPrefixLength, nLength - nPrefixLength));
     242             :             sal_Int32 nValue;
     243           0 :             ::sax::Converter::convertNumber(nValue, sValue);
     244             :             OSL_ENSURE(nValue > 0, "wrong change action ID");
     245           0 :             nResult = nValue;
     246             :         }
     247             :         else
     248             :         {
     249             :             OSL_FAIL("wrong change action ID");
     250             :         }
     251             :     }
     252           0 :     return nResult;
     253             : }
     254             : 
     255           0 : void ScXMLChangeTrackingImportHelper::SetActionInfo(const ScMyActionInfo& aInfo)
     256             : {
     257           0 :     pCurrentAction->aInfo = aInfo;
     258           0 :     aUsers.insert(aInfo.sUser);
     259           0 : }
     260             : 
     261           0 : void ScXMLChangeTrackingImportHelper::SetPreviousChange(const sal_uInt32 nPreviousAction,
     262             :                             ScMyCellInfo* pCellInfo)
     263             : {
     264             :     OSL_ENSURE(pCurrentAction->nActionType == SC_CAT_CONTENT, "wrong action type");
     265           0 :     ScMyContentAction* pAction = static_cast<ScMyContentAction*>(pCurrentAction);
     266           0 :     pAction->nPreviousAction = nPreviousAction;
     267           0 :     pAction->pCellInfo = pCellInfo;
     268           0 : }
     269             : 
     270           0 : void ScXMLChangeTrackingImportHelper::SetPosition(const sal_Int32 nPosition, const sal_Int32 nCount, const sal_Int32 nTable)
     271             : {
     272             :     OSL_ENSURE(((pCurrentAction->nActionType != SC_CAT_MOVE) &&
     273             :                 (pCurrentAction->nActionType != SC_CAT_CONTENT) &&
     274             :                 (pCurrentAction->nActionType != SC_CAT_REJECT)), "wrong action type");
     275             :     OSL_ENSURE(nCount > 0, "wrong count");
     276           0 :     switch(pCurrentAction->nActionType)
     277             :     {
     278             :         case SC_CAT_INSERT_COLS:
     279             :         case SC_CAT_DELETE_COLS:
     280             :         {
     281             :             pCurrentAction->aBigRange.Set(nPosition, nInt32Min, nTable,
     282           0 :                                         nPosition + nCount - 1, nInt32Max, nTable);
     283             :         }
     284           0 :         break;
     285             :         case SC_CAT_INSERT_ROWS:
     286             :         case SC_CAT_DELETE_ROWS:
     287             :         {
     288             :             pCurrentAction->aBigRange.Set(nInt32Min, nPosition, nTable,
     289           0 :                                         nInt32Max, nPosition + nCount - 1, nTable);
     290             :         }
     291           0 :         break;
     292             :         case SC_CAT_INSERT_TABS:
     293             :         case SC_CAT_DELETE_TABS:
     294             :         {
     295             :             pCurrentAction->aBigRange.Set(nInt32Min, nInt32Min, nPosition,
     296           0 :                                         nInt32Max, nInt32Max, nPosition + nCount - 1);
     297             :         }
     298           0 :         break;
     299             :         default:
     300             :         {
     301             :             // added to avoid warnings
     302             :         }
     303             :     }
     304           0 : }
     305             : 
     306           0 : void ScXMLChangeTrackingImportHelper::AddDeleted(const sal_uInt32 nID)
     307             : {
     308           0 :     ScMyDeleted* pDeleted = new ScMyDeleted();
     309           0 :     pDeleted->nID = nID;
     310           0 :     pCurrentAction->aDeletedList.push_front(pDeleted);
     311           0 : }
     312             : 
     313           0 : void ScXMLChangeTrackingImportHelper::AddDeleted(const sal_uInt32 nID, ScMyCellInfo* pCellInfo)
     314             : {
     315           0 :     ScMyDeleted* pDeleted = new ScMyDeleted();
     316           0 :     pDeleted->nID = nID;
     317           0 :     pDeleted->pCellInfo = pCellInfo;
     318           0 :     pCurrentAction->aDeletedList.push_front(pDeleted);
     319           0 : }
     320             : 
     321           0 : void ScXMLChangeTrackingImportHelper::SetMultiSpanned(const sal_Int16 nTempMultiSpanned)
     322             : {
     323           0 :     if (nTempMultiSpanned)
     324             :     {
     325             :         OSL_ENSURE(((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     326             :                     (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS)), "wrong action type");
     327           0 :         nMultiSpanned = nTempMultiSpanned;
     328           0 :         nMultiSpannedSlaveCount = 0;
     329             :     }
     330           0 : }
     331             : 
     332           0 : void ScXMLChangeTrackingImportHelper::SetInsertionCutOff(const sal_uInt32 nID, const sal_Int32 nPosition)
     333             : {
     334           0 :     if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     335           0 :         (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
     336             :     {
     337           0 :         static_cast<ScMyDelAction*>(pCurrentAction)->pInsCutOff = new ScMyInsertionCutOff(nID, nPosition);
     338             :     }
     339             :     else
     340             :     {
     341             :         OSL_FAIL("wrong action type");
     342             :     }
     343           0 : }
     344             : 
     345           0 : void ScXMLChangeTrackingImportHelper::AddMoveCutOff(const sal_uInt32 nID, const sal_Int32 nStartPosition, const sal_Int32 nEndPosition)
     346             : {
     347           0 :     if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     348           0 :         (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
     349             :     {
     350           0 :         static_cast<ScMyDelAction*>(pCurrentAction)->aMoveCutOffs.push_front(ScMyMoveCutOff(nID, nStartPosition, nEndPosition));
     351             :     }
     352             :     else
     353             :     {
     354             :         OSL_FAIL("wrong action type");
     355             :     }
     356           0 : }
     357             : 
     358           0 : void ScXMLChangeTrackingImportHelper::SetMoveRanges(const ScBigRange& aSourceRange, const ScBigRange& aTargetRange)
     359             : {
     360           0 :     if (pCurrentAction->nActionType == SC_CAT_MOVE)
     361             :     {
     362           0 :          static_cast<ScMyMoveAction*>(pCurrentAction)->pMoveRanges = new ScMyMoveRanges(aSourceRange, aTargetRange);
     363             :     }
     364             :     else
     365             :     {
     366             :         OSL_FAIL("wrong action type");
     367             :     }
     368           0 : }
     369             : 
     370           0 : void ScXMLChangeTrackingImportHelper::GetMultiSpannedRange()
     371             : {
     372           0 :     if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     373           0 :         (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
     374             :     {
     375           0 :         if (nMultiSpannedSlaveCount)
     376             :         {
     377           0 :             static_cast<ScMyDelAction*>(pCurrentAction)->nD = nMultiSpannedSlaveCount;
     378             :         }
     379           0 :         ++nMultiSpannedSlaveCount;
     380           0 :         if (nMultiSpannedSlaveCount >= nMultiSpanned)
     381             :         {
     382           0 :             nMultiSpanned = 0;
     383           0 :             nMultiSpannedSlaveCount = 0;
     384             :         }
     385             :     }
     386             :     else
     387             :     {
     388             :         OSL_FAIL("wrong action type");
     389             :     }
     390           0 : }
     391             : 
     392           0 : void ScXMLChangeTrackingImportHelper::AddGenerated(ScMyCellInfo* pCellInfo, const ScBigRange& aBigRange)
     393             : {
     394           0 :     ScMyGenerated* pGenerated = new ScMyGenerated(pCellInfo, aBigRange);
     395           0 :     if (pCurrentAction->nActionType == SC_CAT_MOVE)
     396             :     {
     397           0 :         static_cast<ScMyMoveAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated);
     398             :     }
     399           0 :     else if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     400           0 :         (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
     401             :     {
     402           0 :         static_cast<ScMyDelAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated);
     403             :     }
     404             :     else
     405             :     {
     406           0 :         delete pGenerated;
     407             :         OSL_FAIL("try to insert a generated action to a wrong action");
     408             :     }
     409           0 : }
     410             : 
     411           0 : void ScXMLChangeTrackingImportHelper::EndChangeAction()
     412             : {
     413           0 :     if (!pCurrentAction)
     414             :     {
     415             :         OSL_FAIL("no current action");
     416           0 :         return;
     417             :     }
     418             : 
     419           0 :     if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
     420           0 :         (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
     421           0 :         GetMultiSpannedRange();
     422             : 
     423           0 :     if  (pCurrentAction->nActionNumber > 0)
     424           0 :         aActions.push_back(pCurrentAction);
     425             :     else
     426             :     {
     427             :         OSL_FAIL("no current action");
     428             :     }
     429             : 
     430           0 :     pCurrentAction = NULL;
     431             : }
     432             : 
     433           0 : void ScXMLChangeTrackingImportHelper::ConvertInfo(const ScMyActionInfo& aInfo, OUString& rUser, DateTime& aDateTime)
     434             : {
     435           0 :     Date aDate(aInfo.aDateTime.Day, aInfo.aDateTime.Month, aInfo.aDateTime.Year);
     436           0 :     Time aTime(aInfo.aDateTime.Hours, aInfo.aDateTime.Minutes, aInfo.aDateTime.Seconds, aInfo.aDateTime.NanoSeconds);
     437           0 :     aDateTime.SetDate( aDate.GetDate() );
     438           0 :     aDateTime.SetTime( aTime.GetTime() );
     439             : 
     440             :     // old files didn't store nanoseconds, enable again
     441           0 :     if ( aInfo.aDateTime.NanoSeconds )
     442           0 :         pTrack->SetTimeNanoSeconds( true );
     443             : 
     444           0 :     const std::set<OUString>& rUsers = pTrack->GetUserCollection();
     445           0 :     std::set<OUString>::const_iterator it = rUsers.find(aInfo.sUser);
     446           0 :     if (it != rUsers.end())
     447             :     {
     448             :         // It's probably pointless to do this.
     449           0 :         rUser = *it;
     450             :     }
     451             :     else
     452           0 :         rUser = aInfo.sUser; // shouldn't happen
     453           0 : }
     454             : 
     455           0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateInsertAction(ScMyInsAction* pAction)
     456             : {
     457           0 :     DateTime aDateTime( Date(0), Time(0) );
     458           0 :     OUString aUser;
     459           0 :     ConvertInfo(pAction->aInfo, aUser, aDateTime);
     460             : 
     461           0 :     OUString sComment (pAction->aInfo.sComment);
     462             : 
     463             :     ScChangeAction* pNewAction = new ScChangeActionIns(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
     464           0 :         pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType);
     465           0 :     return pNewAction;
     466             : }
     467             : 
     468           0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateDeleteAction(ScMyDelAction* pAction)
     469             : {
     470           0 :     DateTime aDateTime( Date(0), Time(0) );
     471           0 :     OUString aUser;
     472           0 :     ConvertInfo(pAction->aInfo, aUser, aDateTime);
     473             : 
     474           0 :     OUString sComment (pAction->aInfo.sComment);
     475             : 
     476             :     ScChangeAction* pNewAction = new ScChangeActionDel(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
     477           0 :         pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType, pAction->nD, pTrack);
     478           0 :     return pNewAction;
     479             : }
     480             : 
     481           0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateMoveAction(ScMyMoveAction* pAction)
     482             : {
     483             :     OSL_ENSURE(pAction->pMoveRanges, "no move ranges");
     484           0 :     if (pAction->pMoveRanges)
     485             :     {
     486           0 :         DateTime aDateTime( Date(0), Time(0) );
     487           0 :         OUString aUser;
     488           0 :         ConvertInfo(pAction->aInfo, aUser, aDateTime);
     489             : 
     490           0 :         OUString sComment (pAction->aInfo.sComment);
     491             : 
     492             :         ScChangeAction* pNewAction = new ScChangeActionMove(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
     493           0 :             pAction->pMoveRanges->aTargetRange, aUser, aDateTime, sComment, pAction->pMoveRanges->aSourceRange , pTrack);
     494           0 :         return pNewAction;
     495             :     }
     496           0 :     return NULL;
     497             : }
     498             : 
     499           0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateRejectionAction(ScMyRejAction* pAction)
     500             : {
     501           0 :     DateTime aDateTime( Date(0), Time(0) );
     502           0 :     OUString aUser;
     503           0 :     ConvertInfo(pAction->aInfo, aUser, aDateTime);
     504             : 
     505           0 :     OUString sComment (pAction->aInfo.sComment);
     506             : 
     507             :     ScChangeAction* pNewAction = new ScChangeActionReject(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
     508           0 :         pAction->aBigRange, aUser, aDateTime, sComment);
     509           0 :     return pNewAction;
     510             : }
     511             : 
     512           0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateContentAction(ScMyContentAction* pAction)
     513             : {
     514           0 :     ScCellValue aCell;
     515           0 :     OUString sInputString;
     516           0 :     if (pAction->pCellInfo)
     517             :     {
     518           0 :         aCell = pAction->pCellInfo->CreateCell(pDoc);
     519           0 :         sInputString = pAction->pCellInfo->sInputString;
     520             :     }
     521             : 
     522           0 :     DateTime aDateTime( Date(0), Time(0) );
     523           0 :     OUString aUser;
     524           0 :     ConvertInfo(pAction->aInfo, aUser, aDateTime);
     525             : 
     526           0 :     OUString sComment (pAction->aInfo.sComment);
     527             : 
     528             :     ScChangeAction* pNewAction = new ScChangeActionContent(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
     529           0 :         pAction->aBigRange, aUser, aDateTime, sComment, aCell, pDoc, sInputString);
     530           0 :     return pNewAction;
     531             : }
     532             : 
     533           0 : void ScXMLChangeTrackingImportHelper::CreateGeneratedActions(ScMyGeneratedList& rList)
     534             : {
     535           0 :     if (!rList.empty())
     536             :     {
     537           0 :         ScMyGeneratedList::iterator aItr(rList.begin());
     538           0 :         ScMyGeneratedList::iterator aEndItr(rList.end());
     539           0 :         while (aItr != aEndItr)
     540             :         {
     541           0 :             if ((*aItr)->nID == 0)
     542             :             {
     543           0 :                 ScCellValue aCell;
     544           0 :                 if ((*aItr)->pCellInfo)
     545           0 :                     aCell = (*aItr)->pCellInfo->CreateCell(pDoc);
     546             : 
     547           0 :                 if (!aCell.isEmpty())
     548             :                 {
     549           0 :                     (*aItr)->nID = pTrack->AddLoadedGenerated(aCell, (*aItr)->aBigRange, (*aItr)->pCellInfo->sInputString);
     550             :                     OSL_ENSURE((*aItr)->nID, "could not insert generated action");
     551           0 :                 }
     552             :             }
     553           0 :             ++aItr;
     554             :         }
     555             :     }
     556           0 : }
     557             : 
     558           0 : void ScXMLChangeTrackingImportHelper::SetDeletionDependencies(ScMyDelAction* pAction, ScChangeActionDel* pDelAct)
     559             : {
     560           0 :     if (!pAction->aGeneratedList.empty())
     561             :     {
     562             :         OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
     563             :             (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
     564             :             (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
     565           0 :         if (pDelAct)
     566             :         {
     567           0 :             ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin());
     568           0 :             ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end());
     569           0 :             while (aItr != aEndItr)
     570             :             {
     571             :                 OSL_ENSURE((*aItr)->nID, "a not inserted generated action");
     572           0 :                 pDelAct->SetDeletedInThis((*aItr)->nID, pTrack);
     573           0 :                 if (*aItr)
     574           0 :                     delete *aItr;
     575           0 :                 aItr = pAction->aGeneratedList.erase(aItr);
     576             :             }
     577             :         }
     578             :     }
     579           0 :     if (pAction->pInsCutOff)
     580             :     {
     581             :         OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
     582             :             (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
     583             :             (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
     584           0 :         ScChangeAction* pChangeAction = pTrack->GetAction(pAction->pInsCutOff->nID);
     585           0 :         if (pChangeAction && pChangeAction->IsInsertType())
     586             :         {
     587           0 :             ScChangeActionIns* pInsAction = static_cast<ScChangeActionIns*>(pChangeAction);
     588           0 :             if (pInsAction && pDelAct)
     589           0 :                 pDelAct->SetCutOffInsert(pInsAction, static_cast<sal_Int16>(pAction->pInsCutOff->nPosition));
     590             :         }
     591             :         else
     592             :         {
     593             :             OSL_FAIL("no cut off insert action");
     594             :         }
     595             :     }
     596           0 :     if (!pAction->aMoveCutOffs.empty())
     597             :     {
     598             :         OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
     599             :             (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
     600             :             (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
     601           0 :         ScMyMoveCutOffs::iterator aItr(pAction->aMoveCutOffs.begin());
     602           0 :         ScMyMoveCutOffs::iterator aEndItr(pAction->aMoveCutOffs.end());
     603           0 :         while(aItr != aEndItr)
     604             :         {
     605           0 :             ScChangeAction* pChangeAction = pTrack->GetAction(aItr->nID);
     606           0 :             if (pChangeAction && (pChangeAction->GetType() == SC_CAT_MOVE))
     607             :             {
     608           0 :                 ScChangeActionMove* pMoveAction = static_cast<ScChangeActionMove*>(pChangeAction);
     609           0 :                 if (pMoveAction && pDelAct)
     610           0 :                     pDelAct->AddCutOffMove(pMoveAction, static_cast<sal_Int16>(aItr->nStartPosition),
     611           0 :                                         static_cast<sal_Int16>(aItr->nEndPosition));
     612             :             }
     613             :             else
     614             :             {
     615             :                 OSL_FAIL("no cut off move action");
     616             :             }
     617           0 :             aItr = pAction->aMoveCutOffs.erase(aItr);
     618             :         }
     619             :     }
     620           0 : }
     621             : 
     622           0 : void ScXMLChangeTrackingImportHelper::SetMovementDependencies(ScMyMoveAction* pAction, ScChangeActionMove* pMoveAct)
     623             : {
     624           0 :     if (!pAction->aGeneratedList.empty())
     625             :     {
     626           0 :         if (pAction->nActionType == SC_CAT_MOVE)
     627             :         {
     628           0 :             if (pMoveAct)
     629             :             {
     630           0 :                 ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin());
     631           0 :                 ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end());
     632           0 :                 while (aItr != aEndItr)
     633             :                 {
     634             :                     OSL_ENSURE((*aItr)->nID, "a not inserted generated action");
     635           0 :                     pMoveAct->SetDeletedInThis((*aItr)->nID, pTrack);
     636           0 :                     if (*aItr)
     637           0 :                         delete *aItr;
     638           0 :                     aItr = pAction->aGeneratedList.erase(aItr);
     639             :                 }
     640             :             }
     641             :         }
     642             :     }
     643           0 : }
     644             : 
     645           0 : void ScXMLChangeTrackingImportHelper::SetContentDependencies(ScMyContentAction* pAction, ScChangeActionContent* pActContent)
     646             : {
     647           0 :     if (!pAction->nPreviousAction)
     648           0 :         return;
     649             : 
     650             :     OSL_ENSURE(pAction->nActionType == SC_CAT_CONTENT, "wrong action type");
     651           0 :     ScChangeAction* pPrevAct = pTrack->GetAction(pAction->nPreviousAction);
     652           0 :     if (!pPrevAct)
     653           0 :         return;
     654             : 
     655           0 :     ScChangeActionContent* pPrevActContent = static_cast<ScChangeActionContent*>(pPrevAct);
     656           0 :     if (!pPrevActContent || !pActContent)
     657           0 :         return;
     658             : 
     659           0 :     pActContent->SetPrevContent(pPrevActContent);
     660           0 :     pPrevActContent->SetNextContent(pActContent);
     661           0 :     const ScCellValue& rOldCell = pActContent->GetOldCell();
     662           0 :     if (rOldCell.isEmpty())
     663           0 :         return;
     664             : 
     665           0 :     pPrevActContent->SetNewCell(rOldCell, pDoc, EMPTY_OUSTRING);
     666             : }
     667             : 
     668           0 : void ScXMLChangeTrackingImportHelper::SetDependencies(ScMyBaseAction* pAction)
     669             : {
     670           0 :     ScChangeAction* pAct = pTrack->GetAction(pAction->nActionNumber);
     671           0 :     if (pAct)
     672             :     {
     673           0 :         if (!pAction->aDependencies.empty())
     674             :         {
     675           0 :             ScMyDependencies::iterator aItr(pAction->aDependencies.begin());
     676           0 :             ScMyDependencies::iterator aEndItr(pAction->aDependencies.end());
     677           0 :             while(aItr != aEndItr)
     678             :             {
     679           0 :                 pAct->AddDependent(*aItr, pTrack);
     680           0 :                 aItr = pAction->aDependencies.erase(aItr);
     681             :             }
     682             :         }
     683           0 :         if (!pAction->aDeletedList.empty())
     684             :         {
     685           0 :             ScMyDeletedList::iterator aItr(pAction->aDeletedList.begin());
     686           0 :             ScMyDeletedList::iterator aEndItr(pAction->aDeletedList.end());
     687           0 :             while(aItr != aEndItr)
     688             :             {
     689           0 :                 pAct->SetDeletedInThis((*aItr)->nID, pTrack);
     690           0 :                 ScChangeAction* pDeletedAct = pTrack->GetAction((*aItr)->nID);
     691           0 :                 if ((pDeletedAct->GetType() == SC_CAT_CONTENT) && (*aItr)->pCellInfo)
     692             :                 {
     693           0 :                     ScChangeActionContent* pContentAct = static_cast<ScChangeActionContent*>(pDeletedAct);
     694           0 :                     if (pContentAct && (*aItr)->pCellInfo)
     695             :                     {
     696           0 :                         const ScCellValue& rCell = (*aItr)->pCellInfo->CreateCell(pDoc);
     697           0 :                         if (!rCell.equalsWithoutFormat(pContentAct->GetNewCell()))
     698             :                         {
     699             :                             // #i40704# Don't overwrite SetNewCell result by calling SetNewValue,
     700             :                             // instead pass the input string to SetNewCell.
     701           0 :                             pContentAct->SetNewCell(rCell, pDoc, (*aItr)->pCellInfo->sInputString);
     702             :                         }
     703             :                     }
     704             :                 }
     705           0 :                 if (*aItr)
     706           0 :                     delete *aItr;
     707           0 :                 aItr = pAction->aDeletedList.erase(aItr);
     708             :             }
     709             :         }
     710           0 :         if ((pAction->nActionType == SC_CAT_DELETE_COLS) ||
     711           0 :             (pAction->nActionType == SC_CAT_DELETE_ROWS))
     712           0 :             SetDeletionDependencies(static_cast<ScMyDelAction*>(pAction), static_cast<ScChangeActionDel*>(pAct));
     713           0 :         else if (pAction->nActionType == SC_CAT_MOVE)
     714           0 :             SetMovementDependencies(static_cast<ScMyMoveAction*>(pAction), static_cast<ScChangeActionMove*>(pAct));
     715           0 :         else if (pAction->nActionType == SC_CAT_CONTENT)
     716           0 :             SetContentDependencies(static_cast<ScMyContentAction*>(pAction), static_cast<ScChangeActionContent*>(pAct));
     717             :     }
     718             :     else
     719             :     {
     720             :         OSL_FAIL("could not find the action");
     721             :     }
     722           0 : }
     723             : 
     724           0 : void ScXMLChangeTrackingImportHelper::SetNewCell(ScMyContentAction* pAction)
     725             : {
     726           0 :     ScChangeAction* pChangeAction = pTrack->GetAction(pAction->nActionNumber);
     727           0 :     if (pChangeAction)
     728             :     {
     729           0 :         ScChangeActionContent* pChangeActionContent = static_cast<ScChangeActionContent*>(pChangeAction);
     730           0 :         if (pChangeActionContent)
     731             :         {
     732           0 :             if (pChangeActionContent->IsTopContent() && !pChangeActionContent->IsDeletedIn())
     733             :             {
     734             :                 sal_Int32 nCol, nRow, nTab, nCol2, nRow2, nTab2;
     735           0 :                 pAction->aBigRange.GetVars(nCol, nRow, nTab, nCol2, nRow2, nTab2);
     736           0 :                 if ((nCol >= 0) && (nCol <= MAXCOL) &&
     737           0 :                     (nRow >= 0) && (nRow <= MAXROW) &&
     738           0 :                     (nTab >= 0) && (nTab <= MAXTAB))
     739             :                 {
     740             :                     ScAddress aAddress (static_cast<SCCOL>(nCol),
     741             :                                         static_cast<SCROW>(nRow),
     742           0 :                                         static_cast<SCTAB>(nTab));
     743           0 :                     ScCellValue aCell;
     744           0 :                     aCell.assign(*pDoc, aAddress);
     745           0 :                     if (!aCell.isEmpty())
     746             :                     {
     747           0 :                         ScCellValue aNewCell;
     748           0 :                         if (aCell.meType != CELLTYPE_FORMULA)
     749             :                         {
     750           0 :                             aNewCell = aCell;
     751           0 :                             pChangeActionContent->SetNewCell(aNewCell, pDoc, EMPTY_OUSTRING);
     752           0 :                             pChangeActionContent->SetNewValue(aCell, pDoc);
     753             :                         }
     754             :                         else
     755             :                         {
     756           0 :                             sal_uInt8 nMatrixFlag = aCell.mpFormula->GetMatrixFlag();
     757           0 :                             OUString sFormula;
     758             :                             // With GRAM_ODFF reference detection is faster on compilation.
     759             :                             /* FIXME: new cell should be created with a clone
     760             :                              * of the token array instead. Any reason why this
     761             :                              * wasn't done? */
     762           0 :                             aCell.mpFormula->GetFormula(sFormula, formula::FormulaGrammar::GRAM_ODFF);
     763             : 
     764             :                             // #i87826# [Collaboration] Rejected move destroys formulas
     765             :                             // FIXME: adjust ScFormulaCell::GetFormula(), so that the right formula string
     766             :                             //        is returned and no further string handling is necessary
     767           0 :                             OUString sFormula2;
     768           0 :                             if ( nMatrixFlag != MM_NONE )
     769             :                             {
     770           0 :                                 sFormula2 = sFormula.copy( 2, sFormula.getLength() - 3 );
     771             :                             }
     772             :                             else
     773             :                             {
     774           0 :                                 sFormula2 = sFormula.copy( 1, sFormula.getLength() - 1 );
     775             :                             }
     776             : 
     777           0 :                             aNewCell.meType = CELLTYPE_FORMULA;
     778           0 :                             aNewCell.mpFormula = new ScFormulaCell(pDoc, aAddress, sFormula2,formula::FormulaGrammar::GRAM_ODFF, nMatrixFlag);
     779           0 :                             if (nMatrixFlag == MM_FORMULA)
     780             :                             {
     781             :                                 SCCOL nCols;
     782             :                                 SCROW nRows;
     783           0 :                                 aCell.mpFormula->GetMatColsRows(nCols, nRows);
     784           0 :                                 aNewCell.mpFormula->SetMatColsRows(nCols, nRows);
     785             :                             }
     786           0 :                             aNewCell.mpFormula->SetInChangeTrack(true);
     787           0 :                             pChangeActionContent->SetNewCell(aNewCell, pDoc, EMPTY_OUSTRING);
     788             :                             // #i40704# don't overwrite the formula string via SetNewValue()
     789           0 :                         }
     790           0 :                     }
     791             :                 }
     792             :                 else
     793             :                 {
     794             :                     OSL_FAIL("wrong cell position");
     795             :                 }
     796             :             }
     797             :         }
     798             :     }
     799           0 : }
     800             : 
     801           0 : void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
     802             : {
     803           0 :     pDoc = pTempDoc;
     804           0 :     if (pDoc)
     805             :     {
     806           0 :         pTrack = new ScChangeTrack(pDoc, aUsers);
     807             :         // old files didn't store nanoseconds, disable until encountered
     808           0 :         pTrack->SetTimeNanoSeconds( false );
     809             : 
     810           0 :         ScMyActions::iterator aItr(aActions.begin());
     811           0 :         ScMyActions::iterator aEndItr(aActions.end());
     812           0 :         while (aItr != aEndItr)
     813             :         {
     814           0 :             ScChangeAction* pAction = NULL;
     815             : 
     816           0 :             switch ((*aItr)->nActionType)
     817             :             {
     818             :                 case SC_CAT_INSERT_COLS:
     819             :                 case SC_CAT_INSERT_ROWS:
     820             :                 case SC_CAT_INSERT_TABS:
     821             :                 {
     822           0 :                     pAction = CreateInsertAction(static_cast<ScMyInsAction*>(*aItr));
     823             :                 }
     824           0 :                 break;
     825             :                 case SC_CAT_DELETE_COLS:
     826             :                 case SC_CAT_DELETE_ROWS:
     827             :                 case SC_CAT_DELETE_TABS:
     828             :                 {
     829           0 :                     ScMyDelAction* pDelAct = static_cast<ScMyDelAction*>(*aItr);
     830           0 :                     pAction = CreateDeleteAction(pDelAct);
     831           0 :                     CreateGeneratedActions(pDelAct->aGeneratedList);
     832             :                 }
     833           0 :                 break;
     834             :                 case SC_CAT_MOVE:
     835             :                 {
     836           0 :                     ScMyMoveAction* pMovAct = static_cast<ScMyMoveAction*>(*aItr);
     837           0 :                     pAction = CreateMoveAction(pMovAct);
     838           0 :                     CreateGeneratedActions(pMovAct->aGeneratedList);
     839             :                 }
     840           0 :                 break;
     841             :                 case SC_CAT_CONTENT:
     842             :                 {
     843           0 :                     pAction = CreateContentAction(static_cast<ScMyContentAction*>(*aItr));
     844             :                 }
     845           0 :                 break;
     846             :                 case SC_CAT_REJECT:
     847             :                 {
     848           0 :                     pAction = CreateRejectionAction(static_cast<ScMyRejAction*>(*aItr));
     849             :                 }
     850           0 :                 break;
     851             :                 default:
     852             :                 {
     853             :                     // added to avoid warnings
     854             :                 }
     855             :             }
     856             : 
     857           0 :             if (pAction)
     858           0 :                 pTrack->AppendLoaded(pAction);
     859             :             else
     860             :             {
     861             :                 OSL_FAIL("no action");
     862             :             }
     863             : 
     864           0 :             ++aItr;
     865             :         }
     866           0 :         if (pTrack->GetLast())
     867           0 :             pTrack->SetActionMax(pTrack->GetLast()->GetActionNumber());
     868             : 
     869           0 :         aItr = aActions.begin();
     870           0 :         aEndItr = aActions.end();
     871           0 :         while (aItr != aEndItr)
     872             :         {
     873           0 :             SetDependencies(*aItr);
     874             : 
     875           0 :             if ((*aItr)->nActionType == SC_CAT_CONTENT)
     876           0 :                 ++aItr;
     877             :             else
     878             :             {
     879           0 :                 if (*aItr)
     880           0 :                     delete (*aItr);
     881           0 :                 aItr = aActions.erase(aItr);
     882             :             }
     883             :         }
     884             : 
     885           0 :         aItr = aActions.begin();
     886           0 :         aEndItr = aActions.end();
     887           0 :         while (aItr != aEndItr)
     888             :         {
     889             :             OSL_ENSURE((*aItr)->nActionType == SC_CAT_CONTENT, "wrong action type");
     890           0 :             SetNewCell(static_cast<ScMyContentAction*>(*aItr));
     891           0 :             if (*aItr)
     892           0 :                 delete (*aItr);
     893           0 :             aItr = aActions.erase(aItr);
     894             :         }
     895           0 :         if (aProtect.getLength())
     896           0 :             pTrack->SetProtection(aProtect);
     897           0 :         else if (pDoc->GetChangeTrack() && pDoc->GetChangeTrack()->IsProtected())
     898           0 :             pTrack->SetProtection(pDoc->GetChangeTrack()->GetProtection());
     899             : 
     900           0 :         if ( pTrack->GetLast() )
     901           0 :             pTrack->SetLastSavedActionNumber(pTrack->GetLast()->GetActionNumber());
     902             : 
     903           0 :         pDoc->SetChangeTrack(pTrack);
     904             :     }
     905           0 : }
     906             : 
     907             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10