Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / app / rfindlst.cxx
blob27d873a09f944fe08aa7f557b5c9093d2d62b218
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 "rfindlst.hxx"
21 #include <tools/debug.hxx>
23 #define SC_RANGECOLORS 8
25 static const ColorData aColNames[SC_RANGECOLORS] =
26 { COL_LIGHTBLUE, COL_LIGHTRED, COL_LIGHTMAGENTA, COL_GREEN,
27 COL_BLUE, COL_RED, COL_MAGENTA, COL_BROWN };
29 ScRangeFindList::ScRangeFindList(const OUString& rName) :
30 aDocName( rName ),
31 bHidden( false ),
32 nIndexColor( 0 )
36 ColorData ScRangeFindList::Insert( const ScRangeFindData &rNew )
38 std::vector<ScRangeFindData>::iterator it=maEntries.begin();
39 for( ; it!=maEntries.end(); ++it)
41 if(it->aRef == rNew.aRef)
42 break;
44 ScRangeFindData insertData(rNew);
45 insertData.nColorData = ( it != maEntries.end() ? it->nColorData :
46 ScRangeFindList::GetColorName( maEntries.size() ) );
47 maEntries.push_back(insertData);
48 nIndexColor = maEntries.size() - 1;
49 return insertData.nColorData;
52 ColorData ScRangeFindList::GetColorName( const size_t nIndex )
54 return aColNames[nIndex % SC_RANGECOLORS];
57 ColorData ScRangeFindList::FindColor( const ScRange& rRef, const size_t nIndex )
59 sal_Int32 nOldCntr = 0;
60 sal_Int32 nNewCntr = 0;
61 ColorData nOldColor = 0;
62 ColorData nNewColor = 0;
64 DBG_ASSERT( (nIndex < maEntries.size()), "nIndex out of range!" );
66 nOldColor = maEntries[nIndex].nColorData;
67 nNewColor = ScRangeFindList::GetColorName( nIndex );
69 std::vector<ScRangeFindData>::iterator it=maEntries.begin();
70 for( ;it!=maEntries.end(); ++it)
72 if(it->aRef == rRef)
73 break;
75 if (it->nColorData == nOldColor )
76 nOldCntr++;
78 if (it->nColorData == nNewColor )
79 nNewCntr++;
82 if ( it != maEntries.end() )
83 return it->nColorData;
85 if ( nOldCntr == 1 )
86 return nOldColor;
88 if ( nNewCntr > 0 )
89 return ScRangeFindList::GetColorName( ++nIndexColor );
91 return nNewColor;
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */