LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/view - invmerge.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 66 0.0 %
Date: 2012-12-27 Functions: 0 6 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 <vcl/window.hxx>
      21             : 
      22             : #include "invmerge.hxx"
      23             : 
      24             : //------------------------------------------------------------------
      25             : 
      26           0 : ScInvertMerger::ScInvertMerger( ::std::vector< Rectangle >* pRectangles ) :
      27           0 :     pRects( pRectangles )
      28             : {
      29             :     //  collect rectangles instead of inverting
      30           0 : }
      31             : 
      32           0 : ScInvertMerger::~ScInvertMerger()
      33             : {
      34           0 :     Flush();
      35           0 : }
      36             : 
      37           0 : void ScInvertMerger::Flush()
      38             : {
      39           0 :     FlushLine();
      40           0 :     FlushTotal();
      41             : 
      42             :     OSL_ENSURE( aLineRect.IsEmpty() && aTotalRect.IsEmpty(), "Flush: not empty" );
      43             : 
      44           0 :     if ( pRects )
      45             :     {
      46             :         //
      47             :         // also join vertically if there are non-adjacent columns involved
      48             :         //
      49             : 
      50           0 :         size_t nComparePos = 0;
      51           0 :         while ( nComparePos < pRects->size() )
      52             :         {
      53           0 :             Rectangle aCompRect = (*pRects)[nComparePos];
      54           0 :             sal_Int32 nBottom = aCompRect.Bottom();
      55           0 :             size_t nOtherPos = nComparePos + 1;
      56             : 
      57           0 :             while ( nOtherPos < pRects->size() )
      58             :             {
      59           0 :                 Rectangle aOtherRect = (*pRects)[nOtherPos];
      60           0 :                 if ( aOtherRect.Top() > nBottom + 1 )
      61             :                 {
      62             :                     // rectangles are sorted, so we can stop searching
      63             :                     break;
      64             :                 }
      65           0 :                 if ( aOtherRect.Top() == nBottom + 1 &&
      66           0 :                      aOtherRect.Left() == aCompRect.Left() &&
      67           0 :                      aOtherRect.Right() == aCompRect.Right() )
      68             :                 {
      69             :                     // extend first rectangle
      70           0 :                     nBottom = aOtherRect.Bottom();
      71           0 :                     aCompRect.Bottom() = nBottom;
      72           0 :                     (*pRects)[nComparePos].Bottom() = nBottom;
      73             : 
      74             :                     // remove second rectangle
      75           0 :                     pRects->erase( pRects->begin() + nOtherPos );
      76             : 
      77             :                     // continue at unmodified nOtherPos
      78             :                 }
      79             :                 else
      80           0 :                     ++nOtherPos;
      81             :             }
      82             : 
      83           0 :             ++nComparePos;
      84             :         }
      85             :     }
      86           0 : }
      87             : 
      88           0 : void ScInvertMerger::FlushTotal()
      89             : {
      90           0 :     if( aTotalRect.IsEmpty() )
      91           0 :         return;                         // nothing to do
      92             : 
      93           0 :     if ( pRects )
      94           0 :         pRects->push_back( aTotalRect );
      95             : 
      96           0 :     aTotalRect.SetEmpty();
      97             : }
      98             : 
      99           0 : void ScInvertMerger::FlushLine()
     100             : {
     101           0 :     if( aLineRect.IsEmpty() )
     102           0 :         return;                         // nothing to do
     103             : 
     104           0 :     if ( aTotalRect.IsEmpty() )
     105             :     {
     106           0 :         aTotalRect = aLineRect;         // start new total rect
     107             :     }
     108             :     else
     109             :     {
     110           0 :         if ( aLineRect.Left()  == aTotalRect.Left()  &&
     111           0 :              aLineRect.Right() == aTotalRect.Right() &&
     112           0 :              aLineRect.Top()   == aTotalRect.Bottom() + 1 )
     113             :         {
     114             :             // extend total rect
     115           0 :             aTotalRect.Bottom() = aLineRect.Bottom();
     116             :         }
     117             :         else
     118             :         {
     119           0 :             FlushTotal();                   // draw old total rect
     120           0 :             aTotalRect = aLineRect;         // and start new one
     121             :         }
     122             :     }
     123             : 
     124           0 :     aLineRect.SetEmpty();
     125             : }
     126             : 
     127           0 : void ScInvertMerger::AddRect( const Rectangle& rRect )
     128             : {
     129           0 :     Rectangle aJustified = rRect;
     130           0 :     if ( rRect.Left() > rRect.Right() )     // switch for RTL layout
     131             :     {
     132           0 :         aJustified.Left() = rRect.Right();
     133           0 :         aJustified.Right() = rRect.Left();
     134             :     }
     135             : 
     136           0 :     if ( aLineRect.IsEmpty() )
     137             :     {
     138           0 :         aLineRect = aJustified;             // start new line rect
     139             :     }
     140             :     else
     141             :     {
     142           0 :         sal_Bool bDone = false;
     143           0 :         if ( aJustified.Top()    == aLineRect.Top()    &&
     144           0 :              aJustified.Bottom() == aLineRect.Bottom() )
     145             :         {
     146             :             // try to extend line rect
     147           0 :             if ( aJustified.Left() == aLineRect.Right() + 1 )
     148             :             {
     149           0 :                 aLineRect.Right() = aJustified.Right();
     150           0 :                 bDone = sal_True;
     151             :             }
     152           0 :             else if ( aJustified.Right() + 1 == aLineRect.Left() )  // for RTL layout
     153             :             {
     154           0 :                 aLineRect.Left() = aJustified.Left();
     155           0 :                 bDone = sal_True;
     156             :             }
     157             :         }
     158           0 :         if (!bDone)
     159             :         {
     160           0 :             FlushLine();                // use old line rect for total rect
     161           0 :             aLineRect = aJustified;     // and start new one
     162             :         }
     163             :     }
     164           0 : }
     165             : 
     166             : 
     167             : 
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10