LCOV - code coverage report
Current view: top level - sc/source/core/data - clipparam.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 46 61 75.4 %
Date: 2014-11-03 Functions: 9 9 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 "clipparam.hxx"
      21             : 
      22             : using ::std::vector;
      23             : 
      24          60 : ScClipParam::ScClipParam() :
      25             :     meDirection(Unspecified),
      26             :     mbCutMode(false),
      27          60 :     mnSourceDocID(0)
      28             : {
      29          60 : }
      30             : 
      31         104 : ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
      32             :     meDirection(Unspecified),
      33             :     mbCutMode(bCutMode),
      34         104 :     mnSourceDocID(0)
      35             : {
      36         104 :     maRanges.Append(rRange);
      37         104 : }
      38             : 
      39          64 : bool ScClipParam::isMultiRange() const
      40             : {
      41          64 :     return maRanges.size() > 1;
      42             : }
      43             : 
      44           2 : SCCOL ScClipParam::getPasteColSize()
      45             : {
      46           2 :     if (maRanges.empty())
      47           0 :         return 0;
      48             : 
      49           2 :     switch (meDirection)
      50             :     {
      51             :         case ScClipParam::Column:
      52             :         {
      53           0 :             SCCOL nColSize = 0;
      54           0 :             for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
      55             :             {
      56           0 :                 ScRange* p = maRanges[ i ];
      57           0 :                 nColSize += p->aEnd.Col() - p->aStart.Col() + 1;
      58             :             }
      59           0 :             return nColSize;
      60             :         }
      61             :         case ScClipParam::Row:
      62             :         {
      63             :             // We assume that all ranges have identical column size.
      64           2 :             const ScRange& rRange = *maRanges.front();
      65           2 :             return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
      66             :         }
      67             :         case ScClipParam::Unspecified:
      68             :         default:
      69             :             ;
      70             :     }
      71           0 :     return 0;
      72             : }
      73             : 
      74           2 : SCROW ScClipParam::getPasteRowSize()
      75             : {
      76           2 :     if (maRanges.empty())
      77           0 :         return 0;
      78             : 
      79           2 :     switch (meDirection)
      80             :     {
      81             :         case ScClipParam::Column:
      82             :         {
      83             :             // We assume that all ranges have identical row size.
      84           0 :             const ScRange& rRange = *maRanges.front();
      85           0 :             return rRange.aEnd.Row() - rRange.aStart.Row() + 1;
      86             :         }
      87             :         case ScClipParam::Row:
      88             :         {
      89           2 :             SCROW nRowSize = 0;
      90           8 :             for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
      91             :             {
      92           6 :                 ScRange* p = maRanges[ i ];
      93           6 :                 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1;
      94             :             }
      95           2 :             return nRowSize;
      96             :         }
      97             :         case ScClipParam::Unspecified:
      98             :         default:
      99             :             ;
     100             :     }
     101           0 :     return 0;
     102             : }
     103             : 
     104         360 : ScRange ScClipParam::getWholeRange() const
     105             : {
     106         360 :     return maRanges.Combine();
     107             : }
     108             : 
     109           2 : void ScClipParam::transpose()
     110             : {
     111           2 :     switch (meDirection)
     112             :     {
     113             :         case Column:
     114           0 :             meDirection = ScClipParam::Row;
     115           0 :         break;
     116             :         case Row:
     117           0 :             meDirection = ScClipParam::Column;
     118           0 :         break;
     119             :         case Unspecified:
     120             :         default:
     121             :             ;
     122             :     }
     123             : 
     124           2 :     ScRangeList aNewRanges;
     125           2 :     if (!maRanges.empty())
     126             :     {
     127           2 :         ScRange* p = maRanges.front();
     128           2 :         SCCOL nColOrigin = p->aStart.Col();
     129           2 :         SCROW nRowOrigin = p->aStart.Row();
     130             : 
     131           4 :         for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
     132             :         {
     133           2 :             p = maRanges[ i ];
     134           2 :             SCCOL nColDelta = p->aStart.Col() - nColOrigin;
     135           2 :             SCROW nRowDelta = p->aStart.Row() - nRowOrigin;
     136           2 :             SCCOL nCol1 = 0;
     137           2 :             SCCOL nCol2 = static_cast<SCCOL>(p->aEnd.Row() - p->aStart.Row());
     138           2 :             SCROW nRow1 = 0;
     139           2 :             SCROW nRow2 = static_cast<SCROW>(p->aEnd.Col() - p->aStart.Col());
     140           2 :             nCol1 += static_cast<SCCOL>(nRowDelta);
     141           2 :             nCol2 += static_cast<SCCOL>(nRowDelta);
     142           2 :             nRow1 += static_cast<SCROW>(nColDelta);
     143           2 :             nRow2 += static_cast<SCROW>(nColDelta);
     144           2 :             aNewRanges.push_back( new ScRange(nCol1, nRow1, p->aStart.Tab(), nCol2, nRow2, p->aStart.Tab() ) );
     145             :         }
     146             :     }
     147           2 :     maRanges = aNewRanges;
     148         230 : }
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10