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 .
20 #include <flddropdown.hxx>
24 #include <svl/poolitem.hxx>
25 #include <comphelper/sequence.hxx>
27 #include <unofldmid.h>
29 using namespace com::sun::star
;
33 SwDropDownFieldType::SwDropDownFieldType()
34 : SwFieldType(SwFieldIds::Dropdown
)
38 SwDropDownFieldType::~SwDropDownFieldType()
42 std::unique_ptr
<SwFieldType
> SwDropDownFieldType::Copy() const
44 return std::make_unique
<SwDropDownFieldType
>();
47 SwDropDownField::SwDropDownField(SwFieldType
* pTyp
)
48 : SwField(pTyp
, 0, LANGUAGE_SYSTEM
)
52 SwDropDownField::SwDropDownField(const SwDropDownField
& rSrc
)
53 : SwField(rSrc
.GetTyp(), rSrc
.GetFormat(), rSrc
.GetLanguage()),
54 m_aValues(rSrc
.m_aValues
), m_aSelectedItem(rSrc
.m_aSelectedItem
),
55 m_aName(rSrc
.m_aName
), m_aHelp(rSrc
.m_aHelp
), m_aToolTip(rSrc
.m_aToolTip
)
59 SwDropDownField::~SwDropDownField()
63 OUString
SwDropDownField::ExpandImpl(SwRootFrame
const*const) const
65 OUString sSelect
= GetSelectedItem();
66 if (sSelect
.isEmpty())
68 vector
<OUString
>::const_iterator aIt
= m_aValues
.begin();
69 if ( aIt
!= m_aValues
.end())
72 // if still no list value is available a default text of 10 spaces is to be set
73 if (sSelect
.isEmpty())
78 std::unique_ptr
<SwField
> SwDropDownField::Copy() const
80 return std::make_unique
<SwDropDownField
>(*this);
83 OUString
SwDropDownField::GetPar1() const
85 return GetSelectedItem();
88 OUString
SwDropDownField::GetPar2() const
93 void SwDropDownField::SetPar1(const OUString
& rStr
)
95 SetSelectedItem(rStr
);
98 void SwDropDownField::SetPar2(const OUString
& rName
)
103 void SwDropDownField::SetItems(vector
<OUString
> && rItems
)
105 m_aValues
= std::move(rItems
);
106 m_aSelectedItem
.clear();
109 void SwDropDownField::SetItems(const uno::Sequence
<OUString
> & rItems
)
113 comphelper::sequenceToContainer(m_aValues
, rItems
);
115 m_aSelectedItem
.clear();
118 uno::Sequence
<OUString
> SwDropDownField::GetItemSequence() const
120 return comphelper::containerToSequence(m_aValues
);
124 void SwDropDownField::SetSelectedItem(const OUString
& rItem
)
126 vector
<OUString
>::const_iterator aIt
=
127 std::find(m_aValues
.begin(), m_aValues
.end(), rItem
);
129 if (aIt
!= m_aValues
.end())
130 m_aSelectedItem
= *aIt
;
132 m_aSelectedItem
.clear();
135 void SwDropDownField::SetName(const OUString
& rName
)
140 void SwDropDownField::SetHelp(const OUString
& rHelp
)
145 void SwDropDownField::SetToolTip(const OUString
& rToolTip
)
147 m_aToolTip
= rToolTip
;
150 bool SwDropDownField::QueryValue(::uno::Any
&rVal
, sal_uInt16 nWhich
) const
152 nWhich
&= ~CONVERT_TWIPS
;
155 case FIELD_PROP_PAR1
:
156 rVal
<<= m_aSelectedItem
;
158 case FIELD_PROP_PAR2
:
161 case FIELD_PROP_PAR3
:
164 case FIELD_PROP_PAR4
:
167 case FIELD_PROP_STRINGS
:
168 rVal
<<= GetItemSequence();
177 bool SwDropDownField::PutValue(const uno::Any
&rVal
,
182 case FIELD_PROP_PAR1
:
187 SetSelectedItem(aTmpStr
);
191 case FIELD_PROP_PAR2
:
195 case FIELD_PROP_PAR3
:
199 case FIELD_PROP_PAR4
:
203 case FIELD_PROP_STRINGS
:
205 uno::Sequence
<OUString
> aSeq
;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */