LCOV - code coverage report
Current view: top level - sc/source/ui/docshell - docfuncutil.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 44 47 93.6 %
Date: 2014-11-03 Functions: 6 6 100.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 <docfuncutil.hxx>
      21             : #include <document.hxx>
      22             : #include <markdata.hxx>
      23             : #include <undobase.hxx>
      24             : #include <global.hxx>
      25             : #include <undoblk.hxx>
      26             : 
      27             : #include <memory>
      28             : 
      29             : namespace sc {
      30             : 
      31           4 : bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark )
      32             : {
      33           4 :     SCTAB nTabCount = rDoc.GetTableCount();
      34           4 :     ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
      35           8 :     for (; itr != itrEnd && *itr < nTabCount; ++itr)
      36           4 :         if (rDoc.IsTabProtected(*itr))
      37           0 :             return true;
      38             : 
      39           4 :     return false;
      40             : }
      41             : 
      42         154 : ScDocument* DocFuncUtil::createDeleteContentsUndoDoc(
      43             :     ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
      44             :     InsertDeleteFlags nFlags, bool bOnlyMarked )
      45             : {
      46         154 :     std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
      47         154 :     SCTAB nTab = rRange.aStart.Tab();
      48         154 :     pUndoDoc->InitUndo(&rDoc, nTab, nTab);
      49         154 :     SCTAB nTabCount = rDoc.GetTableCount();
      50         154 :     ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
      51         308 :     for (; itr != itrEnd; ++itr)
      52         154 :         if (*itr != nTab)
      53           0 :             pUndoDoc->AddUndoTab( *itr, *itr );
      54         154 :     ScRange aCopyRange = rRange;
      55         154 :     aCopyRange.aStart.SetTab(0);
      56         154 :     aCopyRange.aEnd.SetTab(nTabCount-1);
      57             : 
      58             :     //  in case of "Format/Standard" copy all attributes, because CopyToDocument
      59             :     //  with IDF_HARDATTR only is too time-consuming:
      60         154 :     InsertDeleteFlags nUndoDocFlags = nFlags;
      61         154 :     if (nFlags & IDF_ATTRIB)
      62         116 :         nUndoDocFlags |= IDF_ATTRIB;
      63         154 :     if (nFlags & IDF_EDITATTR)          // Edit-Engine-Attribute
      64           0 :         nUndoDocFlags |= IDF_STRING;    // -> cells will be changed
      65         154 :     if (nFlags & IDF_NOTE)
      66          10 :         nUndoDocFlags |= IDF_CONTENTS;  // copy all cells with their notes
      67             :     // do not copy note captions to undo document
      68         154 :     nUndoDocFlags |= IDF_NOCAPTIONS;
      69         154 :     rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, pUndoDoc.get(), &rMark);
      70             : 
      71         154 :     return pUndoDoc.release();
      72             : }
      73             : 
      74         154 : void DocFuncUtil::addDeleteContentsUndo(
      75             :     svl::IUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark,
      76             :     const ScRange& rRange, ScDocument* pUndoDoc, InsertDeleteFlags nFlags,
      77             :     const boost::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans,
      78             :     bool bMulti, bool bDrawUndo )
      79             : {
      80             :     std::unique_ptr<ScUndoDeleteContents> pUndo(
      81             :         new ScUndoDeleteContents(
      82         154 :             pDocSh, rMark, rRange, pUndoDoc, bMulti, nFlags, bDrawUndo));
      83         154 :     pUndo->SetDataSpans(pSpans);
      84             : 
      85         154 :     pUndoMgr->AddUndoAction(pUndo.release());
      86         154 : }
      87             : 
      88         154 : ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans(
      89             :     const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
      90             : {
      91         154 :     std::unique_ptr<ScSimpleUndo::DataSpansType> pDataSpans(new ScSimpleUndo::DataSpansType);
      92         154 :     ScMarkData::const_iterator it = rMark.begin(), itEnd = rMark.end();
      93         308 :     for (; it != itEnd; ++it)
      94             :     {
      95         154 :         SCTAB nTab = *it;
      96             : 
      97         154 :         SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
      98         154 :         SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
      99             : 
     100             :         std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
     101         154 :             pDataSpans->insert(nTab, new sc::ColumnSpanSet(false));
     102             : 
     103         154 :         if (r.second)
     104             :         {
     105         154 :             sc::ColumnSpanSet* pSet = r.first->second;
     106         154 :             pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
     107             :         }
     108             :     }
     109             : 
     110         154 :     return pDataSpans.release();
     111             : }
     112             : 
     113         228 : }
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10