2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 09:51:50 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2013-10-23 19:15:52 +02:00
|
|
|
#ifndef INCLUDED_TOOLS_MULTISEL_HXX
|
|
|
|
#define INCLUDED_TOOLS_MULTISEL_HXX
|
2007-04-11 19:14:35 +00:00
|
|
|
|
2013-11-09 15:37:43 -06:00
|
|
|
#include <tools/toolsdllapi.h>
|
2007-04-11 19:14:35 +00:00
|
|
|
#include <tools/gen.hxx>
|
2012-01-03 15:13:13 +01:00
|
|
|
#include <rtl/ustring.hxx>
|
2007-04-11 19:14:35 +00:00
|
|
|
|
2009-07-08 16:27:08 +00:00
|
|
|
#include <vector>
|
2009-07-09 14:01:10 +00:00
|
|
|
#include <set>
|
2009-07-08 16:27:08 +00:00
|
|
|
|
2017-12-13 13:07:28 +02:00
|
|
|
#define SFX_ENDOFSELECTION SAL_MAX_INT32
|
2007-04-11 19:14:35 +00:00
|
|
|
|
2017-01-27 14:41:46 +02:00
|
|
|
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC MultiSelection
|
2007-04-11 19:14:35 +00:00
|
|
|
{
|
|
|
|
private:
|
2018-01-10 12:30:15 +02:00
|
|
|
std::vector< Range >
|
|
|
|
aSels; // array of SV-selections
|
2007-04-11 19:14:35 +00:00
|
|
|
Range aTotRange; // total range of indexes
|
2017-12-13 13:07:28 +02:00
|
|
|
sal_Int32 nCurSubSel; // index in aSels of current selected index
|
|
|
|
sal_Int32 nCurIndex; // current selected entry
|
|
|
|
sal_Int32 nSelCount; // number of selected indexes
|
2013-06-29 23:57:38 -05:00
|
|
|
bool bCurValid; // are nCurIndex and nCurSubSel valid
|
2007-04-11 19:14:35 +00:00
|
|
|
|
|
|
|
TOOLS_DLLPRIVATE void ImplClear();
|
2017-12-13 13:07:28 +02:00
|
|
|
TOOLS_DLLPRIVATE sal_Int32 ImplFindSubSelection( sal_Int32 nIndex ) const;
|
|
|
|
TOOLS_DLLPRIVATE void ImplMergeSubSelections( sal_Int32 nPos1, sal_Int32 nPos2 );
|
2007-04-11 19:14:35 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MultiSelection();
|
|
|
|
MultiSelection( const MultiSelection& rOrig );
|
|
|
|
MultiSelection( const Range& rRange );
|
|
|
|
~MultiSelection();
|
|
|
|
|
|
|
|
MultiSelection& operator= ( const MultiSelection& rOrig );
|
|
|
|
|
2013-06-29 23:57:38 -05:00
|
|
|
void SelectAll( bool bSelect = true );
|
2017-12-13 13:07:28 +02:00
|
|
|
bool Select( sal_Int32 nIndex, bool bSelect = true );
|
2013-06-29 23:57:38 -05:00
|
|
|
void Select( const Range& rIndexRange, bool bSelect = true );
|
2017-12-13 13:07:28 +02:00
|
|
|
bool IsSelected( sal_Int32 nIndex ) const;
|
2013-06-29 23:57:38 -05:00
|
|
|
bool IsAllSelected() const
|
2017-12-13 13:07:28 +02:00
|
|
|
{ return nSelCount == aTotRange.Len(); }
|
|
|
|
sal_Int32 GetSelectCount() const { return nSelCount; }
|
2007-04-11 19:14:35 +00:00
|
|
|
|
|
|
|
void SetTotalRange( const Range& rTotRange );
|
2017-12-13 13:07:28 +02:00
|
|
|
void Insert( sal_Int32 nIndex, sal_Int32 nCount = 1 );
|
|
|
|
void Remove( sal_Int32 nIndex );
|
2016-12-12 10:02:23 +00:00
|
|
|
void Reset();
|
2007-04-11 19:14:35 +00:00
|
|
|
|
|
|
|
const Range& GetTotalRange() const { return aTotRange; }
|
2017-12-13 13:07:28 +02:00
|
|
|
sal_Int32 FirstSelected();
|
|
|
|
sal_Int32 LastSelected();
|
|
|
|
sal_Int32 NextSelected();
|
2007-04-11 19:14:35 +00:00
|
|
|
|
2017-12-13 13:07:28 +02:00
|
|
|
sal_Int32 GetRangeCount() const { return aSels.size(); }
|
2018-01-10 12:30:15 +02:00
|
|
|
const Range& GetRange( sal_Int32 nRange ) const { return aSels[nRange]; }
|
2007-04-11 19:14:35 +00:00
|
|
|
};
|
|
|
|
|
2017-01-27 14:41:46 +02:00
|
|
|
class SAL_WARN_UNUSED TOOLS_DLLPUBLIC StringRangeEnumerator
|
2009-07-08 16:27:08 +00:00
|
|
|
{
|
2009-07-10 13:52:54 +00:00
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
sal_Int32 nFirst;
|
|
|
|
sal_Int32 nLast;
|
|
|
|
|
|
|
|
Range( sal_Int32 i_nFirst, sal_Int32 i_nLast ) : nFirst( i_nFirst ), nLast( i_nLast ) {}
|
|
|
|
};
|
|
|
|
std::vector< StringRangeEnumerator::Range > maSequence;
|
|
|
|
sal_Int32 mnCount;
|
|
|
|
sal_Int32 mnMin;
|
|
|
|
sal_Int32 mnMax;
|
|
|
|
sal_Int32 mnOffset;
|
2011-10-23 17:45:34 +04:00
|
|
|
bool mbValidInput;
|
2009-07-10 13:52:54 +00:00
|
|
|
|
2016-03-01 08:45:39 +02:00
|
|
|
bool setRange( const OUString& i_rNewRange );
|
2016-04-01 14:23:45 +02:00
|
|
|
bool insertRange( sal_Int32 nFirst, sal_Int32 nLast, bool bSequence );
|
2018-01-19 13:23:27 +02:00
|
|
|
void insertJoinedRanges( const std::vector< sal_Int32 >& rNumbers );
|
2015-11-10 10:26:25 +01:00
|
|
|
bool checkValue( sal_Int32, const std::set< sal_Int32 >* i_pPossibleValues = nullptr ) const;
|
2009-07-08 16:27:08 +00:00
|
|
|
public:
|
2009-07-10 13:52:54 +00:00
|
|
|
class TOOLS_DLLPUBLIC Iterator
|
|
|
|
{
|
|
|
|
const StringRangeEnumerator* pEnumerator;
|
|
|
|
const std::set< sal_Int32 >* pPossibleValues;
|
|
|
|
sal_Int32 nRangeIndex;
|
|
|
|
sal_Int32 nCurrent;
|
|
|
|
|
|
|
|
friend class StringRangeEnumerator;
|
|
|
|
Iterator( const StringRangeEnumerator* i_pEnum,
|
|
|
|
const std::set< sal_Int32 >* i_pPossibleValues,
|
|
|
|
sal_Int32 i_nRange,
|
|
|
|
sal_Int32 i_nCurrent )
|
|
|
|
: pEnumerator( i_pEnum ), pPossibleValues( i_pPossibleValues )
|
|
|
|
, nRangeIndex( i_nRange ), nCurrent( i_nCurrent ) {}
|
2012-08-13 23:33:49 +02:00
|
|
|
|
2009-07-10 13:52:54 +00:00
|
|
|
public:
|
|
|
|
Iterator& operator++();
|
2014-06-09 10:09:42 +02:00
|
|
|
sal_Int32 operator*() const { return nCurrent;}
|
2009-07-10 13:52:54 +00:00
|
|
|
bool operator==(const Iterator&) const;
|
|
|
|
bool operator!=(const Iterator& i_rComp) const
|
|
|
|
{ return ! (*this == i_rComp); }
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class StringRangeEnumerator::Iterator;
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
StringRangeEnumerator( const OUString& i_rInput,
|
2011-10-23 17:45:34 +04:00
|
|
|
sal_Int32 i_nMinNumber,
|
|
|
|
sal_Int32 i_nMaxNumber,
|
2009-07-10 13:52:54 +00:00
|
|
|
sal_Int32 i_nLogicalOffset = -1
|
|
|
|
);
|
2009-07-08 16:27:08 +00:00
|
|
|
|
2011-10-08 22:24:21 +04:00
|
|
|
sal_Int32 size() const { return mnCount; }
|
2015-11-10 10:26:25 +01:00
|
|
|
Iterator begin( const std::set< sal_Int32 >* i_pPossibleValues = nullptr ) const;
|
|
|
|
Iterator end( const std::set< sal_Int32 >* i_pPossibleValues = nullptr ) const;
|
2009-07-08 16:27:08 +00:00
|
|
|
|
2015-11-10 10:26:25 +01:00
|
|
|
bool hasValue( sal_Int32 nValue, const std::set< sal_Int32 >* i_pPossibleValues = nullptr ) const;
|
2009-07-08 16:27:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
i_rPageRange: the string to be changed into a sequence of numbers
|
|
|
|
valid format example "5-3,9,9,7-8" ; instead of ',' ';' or ' ' are allowed as well
|
|
|
|
o_rPageVector: the output sequence of numbers
|
|
|
|
i_nLogicalOffset: an offset to be applied to each number in the string before inserting it in the resulting sequence
|
|
|
|
example: a user enters page numbers from 1 to n (since that is logical)
|
|
|
|
of course usable page numbers in code would start from 0 and end at n-1
|
|
|
|
so the logical offset would be -1
|
2011-10-23 17:45:34 +04:00
|
|
|
i_nMinNumber: the minimum allowed number
|
|
|
|
i_nMaxNumber: the maximum allowed number
|
2009-07-08 16:27:08 +00:00
|
|
|
|
|
|
|
@returns: true if the input string was valid, o_rPageVector will contain the resulting sequence
|
2011-10-23 17:45:34 +04:00
|
|
|
false if the input string was invalid, o_rPageVector will contain
|
|
|
|
the sequence that parser is able to extract
|
2009-07-08 16:27:08 +00:00
|
|
|
|
|
|
|
behavior:
|
|
|
|
- only non-negative sequence numbers are allowed
|
|
|
|
- only non-negative values in the input string are allowed
|
2011-10-23 17:45:34 +04:00
|
|
|
- the string "-3" means the sequence i_nMinNumber to 3
|
|
|
|
- the string "3-" means the sequence 3 to i_nMaxNumber
|
|
|
|
- the string "-" means the sequence i_nMinNumber to i_nMaxNumber
|
|
|
|
- single number that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be ignored
|
|
|
|
- range that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be adjusted
|
2009-07-08 16:27:08 +00:00
|
|
|
*/
|
2013-04-07 12:06:47 +02:00
|
|
|
static bool getRangesFromString( const OUString& i_rPageRange,
|
2009-07-08 16:27:08 +00:00
|
|
|
std::vector< sal_Int32 >& o_rPageVector,
|
2011-10-23 17:45:34 +04:00
|
|
|
sal_Int32 i_nMinNumber,
|
|
|
|
sal_Int32 i_nMaxNumber,
|
2009-07-09 14:01:10 +00:00
|
|
|
sal_Int32 i_nLogicalOffset = -1,
|
2016-07-12 10:56:22 +02:00
|
|
|
std::set< sal_Int32 > const * i_pPossibleValues = nullptr
|
2009-07-08 16:27:08 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2012-08-13 23:14:08 +02:00
|
|
|
#endif
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|