1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: flddropdown.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <flddropdown.hxx>
36 #ifndef INCLUDED_ALGORITHM
38 #define INCLUDED_ALGORITHM
40 #include <svtools/poolitem.hxx>
43 #include <unofldmid.h>
45 #include <unoprnms.hxx>
47 using namespace com::sun::star
;
52 static String aEmptyString
;
54 SwDropDownFieldType::SwDropDownFieldType()
55 : SwFieldType(RES_DROPDOWN
)
59 SwDropDownFieldType::~SwDropDownFieldType()
63 SwFieldType
* SwDropDownFieldType::Copy() const
65 return new SwDropDownFieldType
;
68 SwDropDownField::SwDropDownField(SwFieldType
* pTyp
)
69 : SwField(pTyp
, 0, LANGUAGE_SYSTEM
)
73 SwDropDownField::SwDropDownField(const SwDropDownField
& rSrc
)
74 : SwField(rSrc
.GetTyp(), rSrc
.GetFormat(), rSrc
.GetLanguage()),
75 aValues(rSrc
.aValues
), aSelectedItem(rSrc
.aSelectedItem
),
76 aName(rSrc
.aName
), aHelp(rSrc
.aHelp
), aToolTip(rSrc
.aToolTip
)
80 SwDropDownField::~SwDropDownField()
84 String
SwDropDownField::Expand() const
86 String sSelect
= GetSelectedItem();
89 vector
<String
>::const_iterator aIt
= aValues
.begin();
90 if ( aIt
!= aValues
.end())
93 //if still no list value is available a default text of 10 spaces is to be set
95 sSelect
.AppendAscii ( RTL_CONSTASCII_STRINGPARAM (" "));
99 SwField
* SwDropDownField::Copy() const
101 return new SwDropDownField(*this);
104 const String
& SwDropDownField::GetPar1() const
106 return GetSelectedItem();
109 String
SwDropDownField::GetPar2() const
114 void SwDropDownField::SetPar1(const String
& rStr
)
116 SetSelectedItem(rStr
);
119 void SwDropDownField::SetPar2(const String
& rName
)
124 void SwDropDownField::SetItems(const vector
<String
> & rItems
)
127 aSelectedItem
= aEmptyString
;
130 void SwDropDownField::SetItems(const uno::Sequence
<OUString
> & rItems
)
134 sal_Int32 aCount
= rItems
.getLength();
135 for (int i
= 0; i
< aCount
; i
++)
136 aValues
.push_back(rItems
[i
]);
138 aSelectedItem
= aEmptyString
;
141 uno::Sequence
<OUString
> SwDropDownField::GetItemSequence() const
143 uno::Sequence
<OUString
> aSeq( aValues
.size() );
144 OUString
* pSeq
= aSeq
.getArray();
146 vector
<String
>::const_iterator aIt
;
148 for (aIt
= aValues
.begin(); aIt
!= aValues
.end(); aIt
++)
150 pSeq
[i
] = rtl::OUString(*aIt
);
158 const String
& SwDropDownField::GetSelectedItem() const
160 return aSelectedItem
;
163 const String
& SwDropDownField::GetName() const
168 const String
& SwDropDownField::GetHelp() const
173 const String
& SwDropDownField::GetToolTip() const
178 BOOL
SwDropDownField::SetSelectedItem(const String
& rItem
)
180 vector
<String
>::const_iterator aIt
=
181 std::find(aValues
.begin(), aValues
.end(), rItem
);
183 if (aIt
!= aValues
.end())
184 aSelectedItem
= *aIt
;
186 aSelectedItem
= String();
188 return (aIt
!= aValues
.end());
191 void SwDropDownField::SetName(const String
& rName
)
196 void SwDropDownField::SetHelp(const String
& rHelp
)
201 void SwDropDownField::SetToolTip(const String
& rToolTip
)
206 BOOL
SwDropDownField::QueryValue(::uno::Any
&rVal
, USHORT nWhich
) const
208 nWhich
&= ~CONVERT_TWIPS
;
211 case FIELD_PROP_PAR1
:
212 rVal
<<= rtl::OUString(GetSelectedItem());
214 case FIELD_PROP_PAR2
:
215 rVal
<<= rtl::OUString(GetName());
217 case FIELD_PROP_PAR3
:
218 rVal
<<= rtl::OUString(GetHelp());
220 case FIELD_PROP_PAR4
:
221 rVal
<<= rtl::OUString(GetToolTip());
223 case FIELD_PROP_STRINGS
:
224 rVal
<<= GetItemSequence();
229 DBG_ERROR("illegal property");
234 BOOL
SwDropDownField::PutValue(const uno::Any
&rVal
,
239 case FIELD_PROP_PAR1
:
242 ::GetString( rVal
, aTmpStr
);
244 SetSelectedItem(aTmpStr
);
248 case FIELD_PROP_PAR2
:
251 ::GetString( rVal
, aTmpStr
);
257 case FIELD_PROP_PAR3
:
260 ::GetString( rVal
, aTmpStr
);
266 case FIELD_PROP_PAR4
:
269 ::GetString( rVal
, aTmpStr
);
275 case FIELD_PROP_STRINGS
:
277 uno::Sequence
<OUString
> aSeq
;
284 DBG_ERROR("illegal property");