nss: upgrade to release 3.73
[LibreOffice.git] / svl / source / items / slstitm.cxx
blob54af346254d691023f7b574e738649a5f9a1c1c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
25 #include <comphelper/sequence.hxx>
26 #include <osl/diagnose.h>
27 #include <rtl/ustrbuf.hxx>
28 #include <tools/lineend.hxx>
30 SfxPoolItem* SfxStringListItem::CreateDefault() { return new SfxStringListItem; }
32 SfxStringListItem::SfxStringListItem()
37 SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<OUString>* pList ) :
38 SfxPoolItem( which )
40 // FIXME: Putting an empty list does not work
41 // Therefore the query after the count is commented out
42 if( pList /*!!! && pList->Count() */ )
44 mpList = std::make_shared<std::vector<OUString>>();
45 *mpList = *pList;
50 SfxStringListItem::~SfxStringListItem()
55 std::vector<OUString>& SfxStringListItem::GetList()
57 if( !mpList )
58 mpList = std::make_shared<std::vector<OUString>>();
59 return *mpList;
62 const std::vector<OUString>& SfxStringListItem::GetList () const
64 return const_cast< SfxStringListItem * >(this)->GetList();
68 bool SfxStringListItem::operator==( const SfxPoolItem& rItem ) const
70 assert(SfxPoolItem::operator==(rItem));
72 const SfxStringListItem& rSSLItem = static_cast<const SfxStringListItem&>(rItem);
74 return mpList == rSSLItem.mpList;
78 bool SfxStringListItem::GetPresentation
80 SfxItemPresentation /*ePresentation*/,
81 MapUnit /*eCoreMetric*/,
82 MapUnit /*ePresentationMetric*/,
83 OUString& rText,
84 const IntlWrapper&
85 ) const
87 rText = "(List)";
88 return false;
91 SfxStringListItem* SfxStringListItem::Clone( SfxItemPool *) const
93 return new SfxStringListItem( *this );
96 void SfxStringListItem::SetString( const OUString& rStr )
98 mpList = std::make_shared<std::vector<OUString>>();
100 sal_Int32 nStart = 0;
101 OUString aStr(convertLineEnd(rStr, LINEEND_CR));
102 for (;;)
104 const sal_Int32 nDelimPos = aStr.indexOf( '\r', nStart );
105 if ( nDelimPos < 0 )
107 if (nStart<aStr.getLength())
109 // put last string only if not empty
110 mpList->push_back(aStr.copy(nStart));
112 break;
115 mpList->push_back(aStr.copy(nStart, nDelimPos-nStart));
117 // skip both inserted string and delimiter
118 nStart = nDelimPos + 1 ;
123 OUString SfxStringListItem::GetString()
125 OUStringBuffer aStr;
126 if ( mpList )
128 for (auto iter = mpList->begin(), end = mpList->end(); iter != end;)
130 aStr.append(*iter);
131 ++iter;
133 if (iter == end)
134 break;
136 aStr.append("\r");
139 return convertLineEnd(aStr.makeStringAndClear(), GetSystemLineEnd());
143 void SfxStringListItem::SetStringList( const css::uno::Sequence< OUString >& rList )
145 mpList = std::make_shared<std::vector<OUString>>();
147 // String belongs to the list
148 comphelper::sequenceToContainer(*mpList, rList);
151 void SfxStringListItem::GetStringList( css::uno::Sequence< OUString >& rList ) const
153 size_t nCount = mpList->size();
155 rList.realloc( nCount );
156 for( size_t i=0; i < nCount; i++ )
157 rList[i] = (*mpList)[i];
160 // virtual
161 bool SfxStringListItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
163 css::uno::Sequence< OUString > aValue;
164 if ( rVal >>= aValue )
166 SetStringList( aValue );
167 return true;
170 OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
171 return false;
174 // virtual
175 bool SfxStringListItem::QueryValue( css::uno::Any& rVal, sal_uInt8 ) const
177 // GetString() is not const!!!
178 SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this );
180 css::uno::Sequence< OUString > aStringList;
181 pThis->GetStringList( aStringList );
182 rVal <<= aStringList;
183 return true;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */