Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / invmerge.cxx
blob01f960010ac240bc38bd02bf36338a547b42f5e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/window.hxx>
22 #include "invmerge.hxx"
24 ScInvertMerger::ScInvertMerger( ::std::vector< Rectangle >* pRectangles ) :
25 pRects( pRectangles )
27 // collect rectangles instead of inverting
30 ScInvertMerger::~ScInvertMerger()
32 Flush();
35 void ScInvertMerger::Flush()
37 FlushLine();
38 FlushTotal();
40 OSL_ENSURE( aLineRect.IsEmpty() && aTotalRect.IsEmpty(), "Flush: not empty" );
42 if ( pRects )
45 // also join vertically if there are non-adjacent columns involved
48 size_t nComparePos = 0;
49 while ( nComparePos < pRects->size() )
51 Rectangle aCompRect = (*pRects)[nComparePos];
52 sal_Int32 nBottom = aCompRect.Bottom();
53 size_t nOtherPos = nComparePos + 1;
55 while ( nOtherPos < pRects->size() )
57 Rectangle aOtherRect = (*pRects)[nOtherPos];
58 if ( aOtherRect.Top() > nBottom + 1 )
60 // rectangles are sorted, so we can stop searching
61 break;
63 if ( aOtherRect.Top() == nBottom + 1 &&
64 aOtherRect.Left() == aCompRect.Left() &&
65 aOtherRect.Right() == aCompRect.Right() )
67 // extend first rectangle
68 nBottom = aOtherRect.Bottom();
69 aCompRect.Bottom() = nBottom;
70 (*pRects)[nComparePos].Bottom() = nBottom;
72 // remove second rectangle
73 pRects->erase( pRects->begin() + nOtherPos );
75 // continue at unmodified nOtherPos
77 else
78 ++nOtherPos;
81 ++nComparePos;
86 void ScInvertMerger::FlushTotal()
88 if( aTotalRect.IsEmpty() )
89 return; // nothing to do
91 if ( pRects )
92 pRects->push_back( aTotalRect );
94 aTotalRect.SetEmpty();
97 void ScInvertMerger::FlushLine()
99 if( aLineRect.IsEmpty() )
100 return; // nothing to do
102 if ( aTotalRect.IsEmpty() )
104 aTotalRect = aLineRect; // start new total rect
106 else
108 if ( aLineRect.Left() == aTotalRect.Left() &&
109 aLineRect.Right() == aTotalRect.Right() &&
110 aLineRect.Top() == aTotalRect.Bottom() + 1 )
112 // extend total rect
113 aTotalRect.Bottom() = aLineRect.Bottom();
115 else
117 FlushTotal(); // draw old total rect
118 aTotalRect = aLineRect; // and start new one
122 aLineRect.SetEmpty();
125 void ScInvertMerger::AddRect( const Rectangle& rRect )
127 Rectangle aJustified = rRect;
128 if ( rRect.Left() > rRect.Right() ) // switch for RTL layout
130 aJustified.Left() = rRect.Right();
131 aJustified.Right() = rRect.Left();
134 if ( aLineRect.IsEmpty() )
136 aLineRect = aJustified; // start new line rect
138 else
140 bool bDone = false;
141 if ( aJustified.Top() == aLineRect.Top() &&
142 aJustified.Bottom() == aLineRect.Bottom() )
144 // try to extend line rect
145 if ( aJustified.Left() == aLineRect.Right() + 1 )
147 aLineRect.Right() = aJustified.Right();
148 bDone = true;
150 else if ( aJustified.Right() + 1 == aLineRect.Left() ) // for RTL layout
152 aLineRect.Left() = aJustified.Left();
153 bDone = true;
156 if (!bDone)
158 FlushLine(); // use old line rect for total rect
159 aLineRect = aJustified; // and start new one
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */