1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) :
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
>);
50 SfxStringListItem::~SfxStringListItem()
55 std::vector
<OUString
>& SfxStringListItem::GetList()
58 mpList
.reset( new std::vector
<OUString
> );
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*/,
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
));
106 const sal_Int32 nDelimPos
= aStr
.indexOf( '\r', nStart
);
109 if (nStart
<aStr
.getLength())
111 // put last string only if not empty
112 mpList
->push_back(aStr
.copy(nStart
));
117 mpList
->push_back(aStr
.copy(nStart
, nDelimPos
-nStart
));
119 // skip both inserted string and delimiter
120 nStart
= nDelimPos
+ 1 ;
125 OUString
SfxStringListItem::GetString()
130 std::vector
<OUString
>::const_iterator iter
= mpList
->begin();
136 if (iter
== mpList
->end())
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
];
165 bool SfxStringListItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8
)
167 css::uno::Sequence
< OUString
> aValue
;
168 if ( rVal
>>= aValue
)
170 SetStringList( aValue
);
174 OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
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
;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */