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