tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / invmerge.cxx
bloba08222197793495c5eda9350b85691a9fe23e97b
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 <osl/diagnose.h>
22 #include <invmerge.hxx>
24 ScInvertMerger::ScInvertMerger( ::std::vector< tools::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 )
43 return;
45 // also join vertically if there are non-adjacent columns involved
47 size_t nComparePos = 0;
48 while ( nComparePos < pRects->size() )
50 tools::Rectangle aCompRect = (*pRects)[nComparePos];
51 sal_Int32 nBottom = aCompRect.Bottom();
52 size_t nOtherPos = nComparePos + 1;
54 while ( nOtherPos < pRects->size() )
56 tools::Rectangle aOtherRect = (*pRects)[nOtherPos];
57 if ( aOtherRect.Top() > nBottom + 1 )
59 // rectangles are sorted, so we can stop searching
60 break;
62 if ( aOtherRect.Top() == nBottom + 1 &&
63 aOtherRect.Left() == aCompRect.Left() &&
64 aOtherRect.Right() == aCompRect.Right() )
66 // extend first rectangle
67 nBottom = aOtherRect.Bottom();
68 aCompRect.SetBottom( nBottom );
69 (*pRects)[nComparePos].SetBottom( nBottom );
71 // remove second rectangle
72 pRects->erase( pRects->begin() + nOtherPos );
74 // continue at unmodified nOtherPos
76 else
77 ++nOtherPos;
80 ++nComparePos;
84 void ScInvertMerger::FlushTotal()
86 if( aTotalRect.IsEmpty() )
87 return; // nothing to do
89 if ( pRects )
90 pRects->push_back( aTotalRect );
92 aTotalRect.SetEmpty();
95 void ScInvertMerger::FlushLine()
97 if( aLineRect.IsEmpty() )
98 return; // nothing to do
100 if ( aTotalRect.IsEmpty() )
102 aTotalRect = aLineRect; // start new total rect
104 else
106 if ( aLineRect.Left() == aTotalRect.Left() &&
107 aLineRect.Right() == aTotalRect.Right() &&
108 aLineRect.Top() == aTotalRect.Bottom() + 1 )
110 // extend total rect
111 aTotalRect.SetBottom( aLineRect.Bottom() );
113 else
115 FlushTotal(); // draw old total rect
116 aTotalRect = aLineRect; // and start new one
120 aLineRect.SetEmpty();
123 void ScInvertMerger::AddRect( const tools::Rectangle& rRect )
125 tools::Rectangle aJustified = rRect;
126 if ( rRect.Left() > rRect.Right() ) // switch for RTL layout
128 aJustified.SetLeft( rRect.Right() );
129 aJustified.SetRight( rRect.Left() );
132 if ( aLineRect.IsEmpty() )
134 aLineRect = aJustified; // start new line rect
136 else
138 bool bDone = false;
139 if ( aJustified.Top() == aLineRect.Top() &&
140 aJustified.Bottom() == aLineRect.Bottom() )
142 // try to extend line rect
143 if ( aJustified.Left() == aLineRect.Right() + 1 )
145 aLineRect.SetRight( aJustified.Right() );
146 bDone = true;
148 else if ( aJustified.Right() + 1 == aLineRect.Left() ) // for RTL layout
150 aLineRect.SetLeft( aJustified.Left() );
151 bDone = true;
154 if (!bDone)
156 FlushLine(); // use old line rect for total rect
157 aLineRect = aJustified; // and start new one
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */