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