LibreOffice Module sw (master) 1
flddropdown.cxx
Go to the documentation of this file.
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#include <flddropdown.hxx>
21
22#include <algorithm>
23
24#include <svl/poolitem.hxx>
26
27#include <unofldmid.h>
28
29using namespace com::sun::star;
30
31using std::vector;
32
35{
36}
37
39{
40}
41
42std::unique_ptr<SwFieldType> SwDropDownFieldType::Copy() const
43{
44 return std::make_unique<SwDropDownFieldType>();
45}
46
48 : SwField(pTyp, 0, LANGUAGE_SYSTEM)
49{
50}
51
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)
56{
57}
58
60{
61}
62
63OUString SwDropDownField::ExpandImpl(SwRootFrame const*const) const
64{
65 OUString sSelect = GetSelectedItem();
66 if (sSelect.isEmpty())
67 {
68 vector<OUString>::const_iterator aIt = m_aValues.begin();
69 if ( aIt != m_aValues.end())
70 sSelect = *aIt;
71 }
72 // if still no list value is available a default text of 10 spaces is to be set
73 if (sSelect.isEmpty())
74 sSelect = " ";
75 return sSelect;
76}
77
78std::unique_ptr<SwField> SwDropDownField::Copy() const
79{
80 return std::make_unique<SwDropDownField>(*this);
81}
82
84{
85 return GetSelectedItem();
86}
87
89{
90 return GetName();
91}
92
93void SwDropDownField::SetPar1(const OUString & rStr)
94{
95 SetSelectedItem(rStr);
96}
97
98void SwDropDownField::SetPar2(const OUString & rName)
99{
100 SetName(rName);
101}
102
103void SwDropDownField::SetItems(vector<OUString> && rItems)
104{
105 m_aValues = std::move(rItems);
106 m_aSelectedItem.clear();
107}
108
109void SwDropDownField::SetItems(const uno::Sequence<OUString> & rItems)
110{
111 m_aValues.clear();
112
114
115 m_aSelectedItem.clear();
116}
117
118uno::Sequence<OUString> SwDropDownField::GetItemSequence() const
119{
121}
122
123
124void SwDropDownField::SetSelectedItem(const OUString & rItem)
125{
126 vector<OUString>::const_iterator aIt =
127 std::find(m_aValues.begin(), m_aValues.end(), rItem);
128
129 if (aIt != m_aValues.end())
130 m_aSelectedItem = *aIt;
131 else
132 m_aSelectedItem.clear();
133}
134
135void SwDropDownField::SetName(const OUString & rName)
136{
137 m_aName = rName;
138}
139
140void SwDropDownField::SetHelp(const OUString & rHelp)
141{
142 m_aHelp = rHelp;
143}
144
145void SwDropDownField::SetToolTip(const OUString & rToolTip)
146{
147 m_aToolTip = rToolTip;
148}
149
150bool SwDropDownField::QueryValue(::uno::Any &rVal, sal_uInt16 nWhich) const
151{
152 nWhich &= ~CONVERT_TWIPS;
153 switch( nWhich )
154 {
155 case FIELD_PROP_PAR1:
156 rVal <<= m_aSelectedItem;
157 break;
158 case FIELD_PROP_PAR2:
159 rVal <<= m_aName;
160 break;
161 case FIELD_PROP_PAR3:
162 rVal <<= m_aHelp;
163 break;
164 case FIELD_PROP_PAR4:
165 rVal <<= m_aToolTip;
166 break;
168 rVal <<= GetItemSequence();
169 break;
170
171 default:
172 assert(false);
173 }
174 return true;
175}
176
178 sal_uInt16 nWhich)
179{
180 switch( nWhich )
181 {
182 case FIELD_PROP_PAR1:
183 {
184 OUString aTmpStr;
185 rVal >>= aTmpStr;
186
187 SetSelectedItem(aTmpStr);
188 }
189 break;
190
191 case FIELD_PROP_PAR2:
192 rVal >>= m_aName;
193 break;
194
195 case FIELD_PROP_PAR3:
196 rVal >>= m_aHelp;
197 break;
198
199 case FIELD_PROP_PAR4:
200 rVal >>= m_aToolTip;
201 break;
202
204 {
205 uno::Sequence<OUString> aSeq;
206 rVal >>= aSeq;
207 SetItems(aSeq);
208 }
209 break;
210
211 default:
212 assert(false);
213 }
214 return true;
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual std::unique_ptr< SwFieldType > Copy() const override
Create a copy of this field type.
Definition: flddropdown.cxx:42
virtual ~SwDropDownFieldType() override
Destructor.
Definition: flddropdown.cxx:38
SwDropDownFieldType()
Constructor.
Definition: flddropdown.cxx:33
Dropdown field.
Definition: flddropdown.hxx:59
void SetSelectedItem(const OUString &rItem)
Sets the selected item.
virtual OUString GetPar2() const override
Returns the name of the field.
Definition: flddropdown.cxx:88
virtual ~SwDropDownField() override
Destructor.
Definition: flddropdown.cxx:59
void SetToolTip(const OUString &rToolTip)
Sets the tool tip of the field.
void SetItems(std::vector< OUString > &&rItems)
Sets the items of the dropdown box.
OUString m_aName
the name of the field
Definition: flddropdown.hxx:73
OUString m_aHelp
help text
Definition: flddropdown.hxx:78
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
API: Sets a property value on the dropdown field.
css::uno::Sequence< OUString > GetItemSequence() const
Returns the items of the dropdown box.
virtual OUString GetPar1() const override
Returns the selected value.
Definition: flddropdown.cxx:83
SwDropDownField(SwFieldType *pTyp)
Constructor.
Definition: flddropdown.cxx:47
OUString m_aSelectedItem
the selected item
Definition: flddropdown.hxx:68
const OUString & GetName() const
Returns the name of the field.
virtual void SetPar2(const OUString &rStr) override
Sets the name of the field.
Definition: flddropdown.cxx:98
virtual std::unique_ptr< SwField > Copy() const override
Creates a copy of this field.
Definition: flddropdown.cxx:78
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
API: Gets a property value from the dropdown field.
const OUString & GetSelectedItem() const
Returns the selected item.
void SetHelp(const OUString &rHelp)
Sets the help text of the field.
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Expands the field.
Definition: flddropdown.cxx:63
OUString m_aToolTip
tool tip string
Definition: flddropdown.hxx:83
std::vector< OUString > m_aValues
the possible values (aka items) of the dropdown box
Definition: flddropdown.hxx:63
void SetName(const OUString &rName)
Sets the name of the field.
virtual void SetPar1(const OUString &rStr) override
Sets the selected value.
Definition: flddropdown.cxx:93
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:242
Base class of all fields.
Definition: fldbas.hxx:292
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
SwFieldIds
Definition: fldbas.hxx:45
Sequence< PropertyValue > m_aValues
#define LANGUAGE_SYSTEM
Sequence< sal_Int8 > aSeq
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
OUString m_aName
#define FIELD_PROP_STRINGS
Definition: unofldmid.h:42
#define FIELD_PROP_PAR3
Definition: unofldmid.h:25
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR4
Definition: unofldmid.h:36
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24