LibreOffice Module tools (master) 1
multisel.hxx
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#ifndef INCLUDED_TOOLS_MULTISEL_HXX
20#define INCLUDED_TOOLS_MULTISEL_HXX
21
22#include <tools/toolsdllapi.h>
23#include <tools/gen.hxx>
24#include <rtl/ustring.hxx>
25
26#include <cstddef>
27#include <vector>
29
30#define SFX_ENDOFSELECTION (-1)
31
33{
34private:
35 std::vector< Range >
36 aSels; // array of SV-selections
37 Range aTotRange; // total range of indexes
38 std::size_t nCurSubSel; // index in aSels of current selected index
39 sal_Int32 nCurIndex; // current selected entry
40 sal_Int32 nSelCount; // number of selected indexes
41 bool bCurValid; // are nCurIndex and nCurSubSel valid
42
43 TOOLS_DLLPRIVATE void ImplClear();
44 TOOLS_DLLPRIVATE std::size_t ImplFindSubSelection( sal_Int32 nIndex ) const;
45 TOOLS_DLLPRIVATE void ImplMergeSubSelections( sal_Int32 nPos1, std::size_t nPos2 );
46
47public:
49 MultiSelection( const MultiSelection& rOrig );
50 MultiSelection( const Range& rRange );
52
53 MultiSelection& operator= ( const MultiSelection& rOrig );
54
55 void SelectAll( bool bSelect = true );
56 bool Select( sal_Int32 nIndex, bool bSelect = true );
57 void Select( const Range& rIndexRange, bool bSelect = true );
58 bool IsSelected( sal_Int32 nIndex ) const;
59 bool IsAllSelected() const
60 { return nSelCount == aTotRange.Len(); }
61 sal_Int32 GetSelectCount() const { return nSelCount; }
62
63 void SetTotalRange( const Range& rTotRange );
64 void Insert( sal_Int32 nIndex, sal_Int32 nCount = 1 );
65 void Remove( sal_Int32 nIndex );
66 void Reset();
67
68 const Range& GetTotalRange() const { return aTotRange; }
69 sal_Int32 FirstSelected();
70 sal_Int32 LastSelected();
71 sal_Int32 NextSelected();
72
73 sal_Int32 GetRangeCount() const { return aSels.size(); }
74 const Range& GetRange( sal_Int32 nRange ) const { return aSels[nRange]; }
75};
76
78{
79 struct Range
80 {
81 sal_Int32 nFirst;
82 sal_Int32 nLast;
83
84 Range( sal_Int32 i_nFirst, sal_Int32 i_nLast ) : nFirst( i_nFirst ), nLast( i_nLast ) {}
85 };
86 std::vector< StringRangeEnumerator::Range > maSequence;
87 sal_Int32 mnCount;
88 sal_Int32 mnMin;
89 sal_Int32 mnMax;
90 sal_Int32 mnOffset;
92
93 bool setRange( std::u16string_view i_rNewRange );
94 bool insertRange( sal_Int32 nFirst, sal_Int32 nLast, bool bSequence );
95 void insertJoinedRanges( const std::vector< sal_Int32 >& rNumbers );
96 bool checkValue( sal_Int32, const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues = nullptr ) const;
97public:
99 {
102 sal_Int32 nRangeIndex;
103 sal_Int32 nCurrent;
104
107 const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues,
108 sal_Int32 i_nRange,
109 sal_Int32 i_nCurrent )
110 : pEnumerator( i_pEnum ), pPossibleValues( i_pPossibleValues )
111 , nRangeIndex( i_nRange ), nCurrent( i_nCurrent ) {}
112
113 public:
115 sal_Int32 operator*() const { return nCurrent;}
116 bool operator==(const Iterator&) const;
117 bool operator!=(const Iterator& i_rComp) const
118 { return ! (*this == i_rComp); }
119 };
120
122
123 StringRangeEnumerator( std::u16string_view i_rInput,
124 sal_Int32 i_nMinNumber,
125 sal_Int32 i_nMaxNumber,
126 sal_Int32 i_nLogicalOffset = -1
127 );
128
129 sal_Int32 size() const { return mnCount; }
130 Iterator begin( const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues = nullptr ) const;
131 Iterator end( const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues = nullptr ) const;
132
133 bool hasValue( sal_Int32 nValue, const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues = nullptr ) const;
134
159 static bool getRangesFromString( std::u16string_view i_rPageRange,
160 std::vector< sal_Int32 >& o_rPageVector,
161 sal_Int32 i_nMinNumber,
162 sal_Int32 i_nMaxNumber,
163 sal_Int32 i_nLogicalOffset = -1,
164 o3tl::sorted_vector< sal_Int32 > const * i_pPossibleValues = nullptr
165 );
166};
167
168#endif
169
170/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const BigInt &rVal1, const BigInt &rVal2)
Definition: bigint.cxx:806
Range aTotRange
Definition: multisel.hxx:37
const Range & GetTotalRange() const
Definition: multisel.hxx:68
sal_Int32 GetSelectCount() const
Definition: multisel.hxx:61
const Range & GetRange(sal_Int32 nRange) const
Definition: multisel.hxx:74
sal_Int32 GetRangeCount() const
Definition: multisel.hxx:73
bool IsAllSelected() const
Definition: multisel.hxx:59
std::size_t nCurSubSel
Definition: multisel.hxx:38
sal_Int32 nCurIndex
Definition: multisel.hxx:39
std::vector< Range > aSels
Definition: multisel.hxx:36
sal_Int32 nSelCount
Definition: multisel.hxx:40
Definition: gen.hxx:351
tools::Long Len() const
Definition: gen.hxx:358
const o3tl::sorted_vector< sal_Int32 > * pPossibleValues
Definition: multisel.hxx:101
Iterator(const StringRangeEnumerator *i_pEnum, const o3tl::sorted_vector< sal_Int32 > *i_pPossibleValues, sal_Int32 i_nRange, sal_Int32 i_nCurrent)
Definition: multisel.hxx:106
const StringRangeEnumerator * pEnumerator
Definition: multisel.hxx:100
sal_Int32 operator*() const
Definition: multisel.hxx:115
bool operator!=(const Iterator &i_rComp) const
Definition: multisel.hxx:117
bool hasValue(sal_Int32 nValue, const o3tl::sorted_vector< sal_Int32 > *i_pPossibleValues=nullptr) const
Definition: multisel.cxx:634
sal_Int32 size() const
Definition: multisel.hxx:129
static bool getRangesFromString(std::u16string_view i_rPageRange, std::vector< sal_Int32 > &o_rPageVector, sal_Int32 i_nMinNumber, sal_Int32 i_nMaxNumber, sal_Int32 i_nLogicalOffset=-1, o3tl::sorted_vector< sal_Int32 > const *i_pPossibleValues=nullptr)
i_rPageRange: the string to be changed into a sequence of numbers valid format example "5-3,...
Definition: multisel.cxx:720
std::vector< StringRangeEnumerator::Range > maSequence
Definition: multisel.hxx:86
Iterator end(const o3tl::sorted_vector< sal_Int32 > *i_pPossibleValues=nullptr) const
Definition: multisel.cxx:715
Iterator begin(const o3tl::sorted_vector< sal_Int32 > *i_pPossibleValues=nullptr) const
Definition: multisel.cxx:704
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
SotClipboardFormatId & operator++(SotClipboardFormatId &eFormat)
Range(sal_Int32 i_nFirst, sal_Int32 i_nLast)
Definition: multisel.hxx:84
#define TOOLS_DLLPRIVATE
Definition: toolsdllapi.h:30
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
#define SAL_WARN_UNUSED