LibreOffice Module sc (master)  1
rfindlst.cxx
Go to the documentation of this file.
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 <rfindlst.hxx>
21 #include <tools/debug.hxx>
22 
23 #define SC_RANGECOLORS 8
24 
28 
29 ScRangeFindList::ScRangeFindList(const OUString& rName) :
30  aDocName( rName ),
31  bHidden( false ),
32  nIndexColor( 0 )
33 {
34 }
35 
37 {
38  auto it = std::find_if(maEntries.begin(), maEntries.end(),
39  [&rNew](const ScRangeFindData& rEntry) { return rEntry.aRef == rNew.aRef; });
40  ScRangeFindData insertData(rNew);
41  insertData.nColor = ( it != maEntries.end() ? it->nColor :
43  maEntries.push_back(insertData);
44  nIndexColor = maEntries.size() - 1;
45  return insertData.nColor;
46 }
47 
48 Color ScRangeFindList::GetColorName( const size_t nIndex )
49 {
50  return aColNames[nIndex % SC_RANGECOLORS];
51 }
52 
53 Color ScRangeFindList::FindColor( const ScRange& rRef, const size_t nIndex )
54 {
55  sal_Int32 nOldCntr = 0;
56  sal_Int32 nNewCntr = 0;
57  Color nOldColor(0);
58  Color nNewColor(0);
59 
60  DBG_ASSERT( (nIndex < maEntries.size()), "nIndex out of range!" );
61 
62  nOldColor = maEntries[nIndex].nColor;
63  nNewColor = ScRangeFindList::GetColorName( nIndex );
64 
65  std::vector<ScRangeFindData>::iterator it=maEntries.begin();
66  for( ;it!=maEntries.end(); ++it)
67  {
68  if(it->aRef == rRef)
69  break;
70 
71  if (it->nColor == nOldColor )
72  nOldCntr++;
73 
74  if (it->nColor == nNewColor )
75  nNewCntr++;
76  }
77 
78  if ( it != maEntries.end() )
79  return it->nColor;
80 
81  if ( nOldCntr == 1 )
82  return nOldColor;
83 
84  if ( nNewCntr > 0 )
86 
87  return nNewColor;
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr::Color COL_BROWN(0x80, 0x80, 0x00)
const Color aColNames[SC_RANGECOLORS]
Definition: rfindlst.cxx:25
constexpr::Color COL_RED(0x80, 0x00, 0x00)
constexpr::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr::Color COL_MAGENTA(0x80, 0x00, 0x80)
Color FindColor(const ScRange &rRef, const size_t nIndex)
Definition: rfindlst.cxx:53
std::vector< ScRangeFindData > maEntries
Definition: rfindlst.hxx:43
sal_uInt16 nIndexColor
Definition: rfindlst.hxx:46
ScRangeFindList(const OUString &rName)
Definition: rfindlst.cxx:29
#define DBG_ASSERT(sCon, aError)
#define SC_RANGECOLORS
Definition: rfindlst.cxx:23
constexpr::Color COL_LIGHTMAGENTA(0xFF, 0x00, 0xFF)
static Color GetColorName(const size_t nIndex)
Definition: rfindlst.cxx:48
ScRange aRef
Definition: rfindlst.hxx:31
constexpr::Color COL_GREEN(0x00, 0x80, 0x00)
constexpr::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
constexpr::Color COL_BLUE(0x00, 0x00, 0x80)
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
Color Insert(const ScRangeFindData &rNew)
Definition: rfindlst.cxx:36