bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svl / source / items / slstitm.cxx
blobe366badc816720869efc5ca6ab9bbe834908a738
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 <osl/diagnose.h>
26 #include <tools/stream.hxx>
27 #include <stringio.hxx>
28 #include <rtl/ustrbuf.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.reset(new std::vector<OUString>);
45 *mpList = *pList;
50 SfxStringListItem::~SfxStringListItem()
55 std::vector<OUString>& SfxStringListItem::GetList()
57 if( !mpList )
58 mpList.reset( new 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;
92 SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const
94 return new SfxStringListItem( *this );
98 void SfxStringListItem::SetString( const OUString& rStr )
100 mpList.reset( new std::vector<OUString> );
102 sal_Int32 nStart = 0;
103 OUString aStr(convertLineEnd(rStr, LINEEND_CR));
104 for (;;)
106 const sal_Int32 nDelimPos = aStr.indexOf( '\r', nStart );
107 if ( nDelimPos < 0 )
109 if (nStart<aStr.getLength())
111 // put last string only if not empty
112 mpList->push_back(aStr.copy(nStart));
114 break;
117 mpList->push_back(aStr.copy(nStart, nDelimPos-nStart));
119 // skip both inserted string and delimiter
120 nStart = nDelimPos + 1 ;
125 OUString SfxStringListItem::GetString()
127 OUStringBuffer aStr;
128 if ( mpList )
130 std::vector<OUString>::const_iterator iter = mpList->begin();
131 for (;;)
133 aStr.append(*iter);
134 ++iter;
136 if (iter == mpList->end())
137 break;
139 aStr.append("\r");
142 return convertLineEnd(aStr.makeStringAndClear(), GetSystemLineEnd());
146 void SfxStringListItem::SetStringList( const css::uno::Sequence< OUString >& rList )
148 mpList.reset(new std::vector<OUString>);
150 // String belongs to the list
151 for ( sal_Int32 n = 0; n < rList.getLength(); n++ )
152 mpList->push_back(rList[n]);
155 void SfxStringListItem::GetStringList( css::uno::Sequence< OUString >& rList ) const
157 size_t nCount = mpList->size();
159 rList.realloc( nCount );
160 for( size_t i=0; i < nCount; i++ )
161 rList[i] = (*mpList)[i];
164 // virtual
165 bool SfxStringListItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
167 css::uno::Sequence< OUString > aValue;
168 if ( rVal >>= aValue )
170 SetStringList( aValue );
171 return true;
174 OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
175 return false;
178 // virtual
179 bool SfxStringListItem::QueryValue( css::uno::Any& rVal, sal_uInt8 ) const
181 // GetString() is not const!!!
182 SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this );
184 css::uno::Sequence< OUString > aStringList;
185 pThis->GetStringList( aStringList );
186 rVal <<= aStringList;
187 return true;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */