xref: /aoo42x/main/sw/inc/flddropdown.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SW_FLDDROPDOWN_HXX
28 #define SW_FLDDROPDOWN_HXX
29 
30 #include "com/sun/star/uno/Sequence.hxx"
31 #include "swdllapi.h"
32 #include "fldbas.hxx"
33 
34 #include <vector>
35 
36 /**
37     Field type for dropdown boxes.
38 */
39 class SwDropDownFieldType : public SwFieldType
40 {
41 public:
42     /**
43        Constructor
44     */
45     SwDropDownFieldType();
46 
47     /**
48        Destructor
49     */
50     virtual ~SwDropDownFieldType();
51 
52     /**
53        Create a copy of this field type.
54 
55        @return a copy of this type
56     */
57     virtual SwFieldType * Copy () const;
58 };
59 
60 /**
61    Dropdown field.
62 
63    The dropdown field contains a list of strings. At most one of them
64    can be selected.
65 */
66 class SW_DLLPUBLIC SwDropDownField : public SwField
67 {
68     /**
69        the possible values (aka items) of the dropdown box
70     */
71     std::vector<String> aValues;
72 
73     /**
74       the selected item
75     */
76     String aSelectedItem;
77 
78     /**
79       the name of the field
80     */
81     String aName;
82 
83     /**
84        help text
85      */
86     String aHelp;
87 
88     /**
89        tool tip string
90      */
91     String aToolTip;
92 
93     /**
94        Expands the field.
95 
96        The expanded value of the field is the value of the selected
97        item. If no item is selected, an empty string is returned.
98 
99        @return the expanded value of the field
100     */
101     virtual String Expand() const;
102 
103     /**
104        Creates a copy of this field.
105 
106        @return the copy of this field
107     */
108     virtual SwField * Copy() const;
109 
110 public:
111     /**
112        Constructor
113 
114        @param pTyp field type for this field
115     */
116     SwDropDownField(SwFieldType * pTyp);
117 
118     /**
119        Copy constructor
120 
121        @param rSrc dropdown field to copy
122     */
123     SwDropDownField(const SwDropDownField & rSrc);
124 
125     /**
126        Destructor
127     */
128     virtual ~SwDropDownField();
129 
130     /**
131        Returns the selected value.
132 
133        @see Expand
134 
135        @return the selected value
136     */
137     virtual const String & GetPar1() const;
138 
139     /**
140        Returns the name of the field.
141 
142        @return the name of the field
143     */
144     virtual String GetPar2() const;
145 
146     /**
147        Sets the selected value.
148 
149        If rStr is an item of the field that item will be
150        selected. Otherwise no item will be selected, i.e. the
151        resulting selection will be empty.
152     */
153     virtual void SetPar1(const String & rStr);
154 
155     /**
156        Sets the name of the field.
157 
158        @param rStr the new name of the field
159     */
160     virtual void SetPar2(const String & rStr);
161 
162     /**
163        Sets the items of the dropdown box.
164 
165        After setting the items the selection will be empty.
166 
167        @param rItems the new items
168     */
169     void SetItems(const std::vector<String> & rItems);
170 
171     /**
172        Sets the items of the dropdown box.
173 
174        After setting the items the selection will be empty.
175 
176        @param rItems the new items
177     */
178     void SetItems(const com::sun::star::uno::Sequence<rtl::OUString> & rItems);
179 
180     /**
181         Returns the items of the dropdown box.
182 
183         @return the items of the dropdown box
184     */
185     com::sun::star::uno::Sequence<rtl::OUString> GetItemSequence() const;
186 
187     /**
188        Returns the selected item.
189 
190        @return the selected item
191     */
192     const String & GetSelectedItem() const;
193 
194     /**
195        Returns the name of the field.
196 
197        @return the name of the field
198     */
199     const String & GetName() const;
200 
201     /**
202        Returns the help text of the field.
203 
204        @return the help text of the field
205     */
206     const String & GetHelp() const;
207 
208     /**
209        Returns the tool tip of the field.
210 
211        @return the tool tip of the field
212      */
213     const String & GetToolTip() const;
214 
215     /**
216        Sets the selected item.
217 
218        If rItem is found in this dropdown field it is selected. If
219        rItem is not found the selection will be empty.
220 
221        @param rItem the item to be set
222 
223        @retval sal_True the selected item was successfully set
224        @retval sal_True failure (empty selection)
225     */
226     sal_Bool SetSelectedItem(const String & rItem);
227 
228     /**
229        Sets the name of the field.
230 
231        @param rName the new name of the field
232     */
233     void SetName(const String & rName);
234 
235     /**
236        Sets the help text of the field.
237 
238        @param rHelp    the help text
239     */
240     void SetHelp(const String & rHelp);
241 
242     /**
243        Sets the tool tip of the field.
244 
245        @param rToolTip  the tool tip
246     */
247     void SetToolTip(const String & rToolTip);
248 
249     /**
250        API: Gets a property value from the dropdown field.
251 
252        @param rVal return value
253        @param nMId
254           - FIELD_PROP_PAR1 Get selected item (String)
255           - FIELD_PROP_STRINGS Get all items (Sequence)
256           - FIELD_PROP_PAR3 Get the help text of the field.
257           - FIELD_PROP_PAR4 Get the tool tip of the field.
258     */
259     virtual sal_Bool QueryValue(com::sun::star::uno::Any &rVal, sal_uInt16 nWhichId) const;
260 
261     /**
262        API: Sets a property value on the dropdown field.
263 
264        @param rVal value to set
265        @param nMId
266           - FIELD_PROP_PAR1 Set selected item (String)
267           - FIELD_PROP_STRINGS Set all items (Sequence)
268           - FIELD_PROP_PAR3  Set the help text of the field.
269           - FIELD_PROP_PAR4  Set the tool tip of the field.
270     */
271         virtual sal_Bool PutValue(const com::sun::star::uno::Any &rVal, sal_uInt16 nWhichId);
272 };
273 
274 #endif
275