LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - clipparam.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 80 25.0 %
Date: 2012-12-17 Functions: 4 8 50.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           2 : ScClipParam::ScClipParam() :
      25             :     meDirection(Unspecified),
      26             :     mbCutMode(false),
      27           2 :     mnSourceDocID(0)
      28             : {
      29           2 : }
      30             : 
      31           6 : ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
      32             :     meDirection(Unspecified),
      33             :     mbCutMode(bCutMode),
      34           6 :     mnSourceDocID(0)
      35             : {
      36           6 :     maRanges.Append(rRange);
      37           6 : }
      38             : 
      39           8 : ScClipParam::ScClipParam(const ScClipParam& r) :
      40             :     maRanges(r.maRanges),
      41             :     meDirection(r.meDirection),
      42             :     mbCutMode(r.mbCutMode),
      43             :     mnSourceDocID(r.mnSourceDocID),
      44           8 :     maProtectedChartRangesVector(r.maProtectedChartRangesVector)
      45             : {
      46           8 : }
      47             : 
      48           0 : bool ScClipParam::isMultiRange() const
      49             : {
      50           0 :     return maRanges.size() > 1;
      51             : }
      52             : 
      53           0 : SCCOL ScClipParam::getPasteColSize()
      54             : {
      55           0 :     if (maRanges.empty())
      56           0 :         return 0;
      57             : 
      58           0 :     switch (meDirection)
      59             :     {
      60             :         case ScClipParam::Column:
      61             :         {
      62           0 :             SCCOL nColSize = 0;
      63           0 :             for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
      64             :             {
      65           0 :                 ScRange* p = maRanges[ i ];
      66           0 :                 nColSize += p->aEnd.Col() - p->aStart.Col() + 1;
      67             :             }
      68           0 :             return nColSize;
      69             :         }
      70             :         case ScClipParam::Row:
      71             :         {
      72             :             // We assume that all ranges have identical column size.
      73           0 :             const ScRange& rRange = *maRanges.front();
      74           0 :             return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
      75             :         }
      76             :         case ScClipParam::Unspecified:
      77             :         default:
      78             :             ;
      79             :     }
      80           0 :     return 0;
      81             : }
      82             : 
      83           0 : SCROW ScClipParam::getPasteRowSize()
      84             : {
      85           0 :     if (maRanges.empty())
      86           0 :         return 0;
      87             : 
      88           0 :     switch (meDirection)
      89             :     {
      90             :         case ScClipParam::Column:
      91             :         {
      92             :             // We assume that all ranges have identical row size.
      93           0 :             const ScRange& rRange = *maRanges.front();
      94           0 :             return rRange.aEnd.Row() - rRange.aStart.Row() + 1;
      95             :         }
      96             :         case ScClipParam::Row:
      97             :         {
      98           0 :             SCROW nRowSize = 0;
      99           0 :             for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
     100             :             {
     101           0 :                 ScRange* p = maRanges[ i ];
     102           0 :                 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1;
     103             :             }
     104           0 :             return nRowSize;
     105             :         }
     106             :         case ScClipParam::Unspecified:
     107             :         default:
     108             :             ;
     109             :     }
     110           0 :     return 0;
     111             : }
     112             : 
     113          12 : ScRange ScClipParam::getWholeRange() const
     114             : {
     115          12 :     ScRange aWhole;
     116          12 :     bool bFirst = true;
     117          24 :     for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
     118             :     {
     119          12 :         const ScRange* p = maRanges[i];
     120          12 :         if (bFirst)
     121             :         {
     122          12 :             aWhole = *p;
     123          12 :             bFirst = false;
     124          12 :             continue;
     125             :         }
     126             : 
     127           0 :         if (aWhole.aStart.Col() > p->aStart.Col())
     128           0 :             aWhole.aStart.SetCol(p->aStart.Col());
     129             : 
     130           0 :         if (aWhole.aStart.Row() > p->aStart.Row())
     131           0 :             aWhole.aStart.SetRow(p->aStart.Row());
     132             : 
     133           0 :         if (aWhole.aEnd.Col() < p->aEnd.Col())
     134           0 :             aWhole.aEnd.SetCol(p->aEnd.Col());
     135             : 
     136           0 :         if (aWhole.aEnd.Row() < p->aEnd.Row())
     137           0 :             aWhole.aEnd.SetRow(p->aEnd.Row());
     138             :     }
     139          12 :     return aWhole;
     140             : }
     141             : 
     142           0 : void ScClipParam::transpose()
     143             : {
     144           0 :     switch (meDirection)
     145             :     {
     146             :         case Column:
     147           0 :             meDirection = ScClipParam::Row;
     148           0 :         break;
     149             :         case Row:
     150           0 :             meDirection = ScClipParam::Column;
     151           0 :         break;
     152             :         case Unspecified:
     153             :         default:
     154             :             ;
     155             :     }
     156             : 
     157           0 :     ScRangeList aNewRanges;
     158           0 :     if (!maRanges.empty())
     159             :     {
     160           0 :         ScRange* p = maRanges.front();
     161           0 :         SCCOL nColOrigin = p->aStart.Col();
     162           0 :         SCROW nRowOrigin = p->aStart.Row();
     163             : 
     164           0 :         for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
     165             :         {
     166           0 :             p = maRanges[ i ];
     167           0 :             SCCOL nColDelta = p->aStart.Col() - nColOrigin;
     168           0 :             SCROW nRowDelta = p->aStart.Row() - nRowOrigin;
     169           0 :             SCCOL nCol1 = 0;
     170           0 :             SCCOL nCol2 = static_cast<SCCOL>(p->aEnd.Row() - p->aStart.Row());
     171           0 :             SCROW nRow1 = 0;
     172           0 :             SCROW nRow2 = static_cast<SCROW>(p->aEnd.Col() - p->aStart.Col());
     173           0 :             nCol1 += static_cast<SCCOL>(nRowDelta);
     174           0 :             nCol2 += static_cast<SCCOL>(nRowDelta);
     175           0 :             nRow1 += static_cast<SCROW>(nColDelta);
     176           0 :             nRow2 += static_cast<SCROW>(nColDelta);
     177           0 :             aNewRanges.push_back( new ScRange(nCol1, nRow1, p->aStart.Tab(), nCol2, nRow2, p->aStart.Tab() ) );
     178             :         }
     179             :     }
     180           0 :     maRanges = aNewRanges;
     181           0 : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10