tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / app / rfindlst.cxx
blobff5973fb65f06fd6782682957dc1cb08eb7cd05c
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>
22 #include <utility>
23 #include <svtools/colorcfg.hxx>
24 #include <scmod.hxx>
26 #define SC_RANGECOLORS 8
28 const Color aColNames[SC_RANGECOLORS] =
29 { COL_LIGHTBLUE, COL_LIGHTRED, COL_LIGHTMAGENTA, COL_GREEN,
30 COL_BLUE, COL_RED, COL_MAGENTA, COL_BROWN };
31 const Color aDarkColNames[SC_RANGECOLORS] =
32 { COL_LIGHTBLUE, COL_LIGHTRED, COL_LIGHTMAGENTA, COL_GREEN,
33 Color(0xb4c7dc), Color(0xffa6a6), Color(0xffb66c), Color(0xafd095) }; //light blue/red/orange/green 3
34 static bool bIsDark;
36 ScRangeFindList::ScRangeFindList(OUString aName) :
37 aDocName(std::move( aName )),
38 bHidden( false ),
39 nIndexColor( 0 )
41 bIsDark = ScModule::get()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor.IsDark();
44 Color ScRangeFindList::Insert( const ScRangeFindData &rNew )
46 auto it = std::find_if(maEntries.begin(), maEntries.end(),
47 [&rNew](const ScRangeFindData& rEntry) { return rEntry.aRef == rNew.aRef; });
48 ScRangeFindData insertData(rNew);
49 insertData.nColor = ( it != maEntries.end() ? it->nColor :
50 ScRangeFindList::GetColorName( maEntries.size() ) );
51 maEntries.push_back(insertData);
52 nIndexColor = maEntries.size() - 1;
53 return insertData.nColor;
56 Color ScRangeFindList::GetColorName( const size_t nIndex )
58 return bIsDark ? aDarkColNames[nIndex % SC_RANGECOLORS]
59 : aColNames[nIndex % SC_RANGECOLORS];
62 Color ScRangeFindList::FindColor( const ScRange& rRef, const size_t nIndex )
64 sal_Int32 nOldCntr = 0;
65 sal_Int32 nNewCntr = 0;
66 Color nOldColor(0);
67 Color nNewColor(0);
69 DBG_ASSERT( (nIndex < maEntries.size()), "nIndex out of range!" );
71 nOldColor = maEntries[nIndex].nColor;
72 nNewColor = ScRangeFindList::GetColorName( nIndex );
74 std::vector<ScRangeFindData>::iterator it=maEntries.begin();
75 for( ;it!=maEntries.end(); ++it)
77 if(it->aRef == rRef)
78 break;
80 if (it->nColor == nOldColor )
81 nOldCntr++;
83 if (it->nColor == nNewColor )
84 nNewCntr++;
87 if ( it != maEntries.end() )
88 return it->nColor;
90 if ( nOldCntr == 1 )
91 return nOldColor;
93 if ( nNewCntr > 0 )
94 return ScRangeFindList::GetColorName( ++nIndexColor );
96 return nNewColor;
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */