LibreOffice Module svl (master) 1
slstitm.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
21#include <svl/slstitm.hxx>
22#include <svl/poolitem.hxx>
23#include <com/sun/star/uno/Any.hxx>
24#include <com/sun/star/uno/Sequence.hxx>
26#include <osl/diagnose.h>
27#include <rtl/ustrbuf.hxx>
28#include <tools/lineend.hxx>
29
31
33{
34}
35
36
37SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<OUString>* pList ) :
38 SfxPoolItem( which )
39{
40 // FIXME: Putting an empty list does not work
41 // Therefore the query after the count is commented out
42 if( pList )
43 {
44 mpList = std::make_shared<std::vector<OUString>>(*pList);
45 }
46}
47
48
50{
51}
52
53
54std::vector<OUString>& SfxStringListItem::GetList()
55{
56 if( !mpList )
57 mpList = std::make_shared<std::vector<OUString>>();
58 return *mpList;
59}
60
61const std::vector<OUString>& SfxStringListItem::GetList () const
62{
63 return const_cast< SfxStringListItem * >(this)->GetList();
64}
65
66
68{
69 assert(SfxPoolItem::operator==(rItem));
70
71 const SfxStringListItem& rSSLItem = static_cast<const SfxStringListItem&>(rItem);
72
73 return mpList == rSSLItem.mpList;
74}
75
76
78(
79 SfxItemPresentation /*ePresentation*/,
80 MapUnit /*eCoreMetric*/,
81 MapUnit /*ePresentationMetric*/,
82 OUString& rText,
83 const IntlWrapper&
84) const
85{
86 rText = "(List)";
87 return false;
88}
89
91{
92 return new SfxStringListItem( *this );
93}
94
95void SfxStringListItem::SetString( const OUString& rStr )
96{
97 mpList = std::make_shared<std::vector<OUString>>();
98
99 OUString aStr(convertLineEnd(rStr, LINEEND_CR));
100 // put last string only if not empty
101 for (sal_Int32 nStart = 0; nStart >= 0 && nStart < aStr.getLength();)
102 mpList->push_back(aStr.getToken(0, '\r', nStart));
103}
104
105
107{
108 OUStringBuffer aStr;
109 if ( mpList )
110 {
111 for (auto iter = mpList->begin(), end = mpList->end(); iter != end;)
112 {
113 aStr.append(*iter);
114 ++iter;
115
116 if (iter == end)
117 break;
118
119 aStr.append(SAL_NEWLINE_STRING);
120 }
121 }
122 return aStr.makeStringAndClear();
123}
124
125
126void SfxStringListItem::SetStringList( const css::uno::Sequence< OUString >& rList )
127{
128 mpList = std::make_shared<std::vector<OUString>>(
129 comphelper::sequenceToContainer<std::vector<OUString>>(rList));
130}
131
132void SfxStringListItem::GetStringList( css::uno::Sequence< OUString >& rList ) const
133{
134 size_t nCount = mpList->size();
135
136 rList.realloc( nCount );
137 auto pList = rList.getArray();
138 for( size_t i=0; i < nCount; i++ )
139 pList[i] = (*mpList)[i];
140}
141
142// virtual
143bool SfxStringListItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
144{
145 css::uno::Sequence< OUString > aValue;
146 if ( rVal >>= aValue )
147 {
148 SetStringList( aValue );
149 return true;
150 }
151
152 OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
153 return false;
154}
155
156// virtual
157bool SfxStringListItem::QueryValue( css::uno::Any& rVal, sal_uInt8 ) const
158{
159 css::uno::Sequence< OUString > aStringList;
161 rVal <<= aStringList;
162 return true;
163}
164
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
virtual SfxStringListItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: slstitm.cxx:90
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: slstitm.cxx:157
void SetString(const OUString &)
Definition: slstitm.cxx:95
OUString GetString()
Definition: slstitm.cxx:106
std::shared_ptr< std::vector< OUString > > mpList
Definition: slstitm.hxx:32
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
This virtual method allows to get a textual representation of the value for the SfxPoolItem subclasse...
Definition: slstitm.cxx:78
static SfxPoolItem * CreateDefault()
Definition: slstitm.cxx:30
virtual ~SfxStringListItem() override
Definition: slstitm.cxx:49
void SetStringList(const css::uno::Sequence< OUString > &rList)
Definition: slstitm.cxx:126
virtual bool operator==(const SfxPoolItem &) const override
Definition: slstitm.cxx:67
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: slstitm.cxx:143
void GetStringList(css::uno::Sequence< OUString > &rList) const
Definition: slstitm.cxx:132
std::vector< OUString > & GetList()
Definition: slstitm.cxx:54
#define SAL_NEWLINE_STRING
int nCount
LINEEND_CR
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
MapUnit
aStr
int i
end
SfxItemPresentation
Definition: poolitem.hxx:72
unsigned char sal_uInt8
const std::u16string_view aStringList[]