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