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

Generated by: LCOV version 1.10