xref: /AOO41X/main/svl/source/items/cenumitm.cxx (revision 40df464ee80f942fd2baf5effc726656f4be12a0)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 #include <com/sun/star/uno/Any.hxx>
27 #include <tools/stream.hxx>
28 #include <svl/cenumitm.hxx>
29 #include <whassert.hxx>
30 
31 #ifndef _CPPUHELPER_EXTRACT_HXX_
32 #include <comphelper/extract.hxx>
33 #endif
34 
35 //============================================================================
36 //
37 //  class SfxEnumItemInterface
38 //
39 //============================================================================
40 
41 DBG_NAME(SfxEnumItemInterface)
42 
43 //============================================================================
44 TYPEINIT1(SfxEnumItemInterface, SfxPoolItem)
45 
46 //============================================================================
47 // virtual
48 int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const
49 {
50     SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type");
51     return GetEnumValue()
52                == static_cast< const SfxEnumItemInterface * >(&rItem)->
53                       GetEnumValue();
54 }
55 
56 //============================================================================
57 // virtual
58 SfxItemPresentation
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const59 SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit,
60                                       SfxMapUnit, XubString & rText,
61                                       const IntlWrapper *) const
62 {
63     rText = XubString::CreateFromInt32(GetEnumValue());
64     return SFX_ITEM_PRESENTATION_NAMELESS;
65 }
66 
67 //============================================================================
68 // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const69 sal_Bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8)
70     const
71 {
72     rVal <<= sal_Int32(GetEnumValue());
73     return true;
74 }
75 
76 //============================================================================
77 // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)78 sal_Bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal,
79                                     sal_uInt8)
80 {
81     sal_Int32 nTheValue = 0;
82 
83     if ( ::cppu::enum2int( nTheValue, rVal ) )
84     {
85         SetEnumValue(sal_uInt16(nTheValue));
86         return true;
87     }
88     DBG_ERROR("SfxEnumItemInterface::PutValue(): Wrong type");
89     return false;
90 }
91 
92 //============================================================================
GetValueTextByPos(sal_uInt16) const93 XubString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const
94 {
95     DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
96     return XubString();
97 }
98 
99 //============================================================================
100 // virtual
GetValueByPos(sal_uInt16 nPos) const101 sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const
102 {
103     return nPos;
104 }
105 
106 //============================================================================
107 // virtual
GetPosByValue(sal_uInt16 nValue) const108 sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const
109 {
110     sal_uInt16 nCount = GetValueCount();
111     for (sal_uInt16 i = 0; i < nCount; ++i)
112         if (GetValueByPos(i) == nValue)
113             return i;
114     return USHRT_MAX;
115 }
116 
IsEnabled(sal_uInt16) const117 sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const
118 {
119     return sal_True;
120 }
121 
122 //============================================================================
123 // virtual
HasBoolValue() const124 int SfxEnumItemInterface::HasBoolValue() const
125 {
126     return false;
127 }
128 
129 //============================================================================
130 // virtual
GetBoolValue() const131 sal_Bool SfxEnumItemInterface::GetBoolValue() const
132 {
133     return false;
134 }
135 
136 //============================================================================
137 // virtual
SetBoolValue(sal_Bool)138 void SfxEnumItemInterface::SetBoolValue(sal_Bool)
139 {}
140 
141 //============================================================================
142 //
143 //  class CntEnumItem
144 //
145 //============================================================================
146 
DBG_NAME(CntEnumItem)147 DBG_NAME(CntEnumItem)
148 
149 //============================================================================
150 CntEnumItem::CntEnumItem(sal_uInt16 which, SvStream & rStream):
151     SfxEnumItemInterface(which)
152 {
153     m_nValue = 0;
154     rStream >> m_nValue;
155 }
156 
157 //============================================================================
TYPEINIT1(CntEnumItem,SfxEnumItemInterface)158 TYPEINIT1(CntEnumItem, SfxEnumItemInterface)
159 
160 //============================================================================
161 // virtual
162 SvStream & CntEnumItem::Store(SvStream & rStream, sal_uInt16) const
163 {
164     rStream << m_nValue;
165     return rStream;
166 }
167 
168 //============================================================================
169 // virtual
GetEnumValue() const170 sal_uInt16 CntEnumItem::GetEnumValue() const
171 {
172     return GetValue();
173 }
174 
175 //============================================================================
176 // virtual
SetEnumValue(sal_uInt16 nTheValue)177 void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue)
178 {
179     SetValue(nTheValue);
180 }
181 
182 //============================================================================
183 //
184 //  class CntBoolItem
185 //
186 //============================================================================
187 
188 DBG_NAME(CntBoolItem)
189 
190 //============================================================================
TYPEINIT1_AUTOFACTORY(CntBoolItem,SfxPoolItem)191 TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem)
192 
193 //============================================================================
194 CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream):
195     SfxPoolItem(which)
196 {
197     m_bValue = false;
198     rStream >> m_bValue;
199 }
200 
201 //============================================================================
202 // virtual
operator ==(const SfxPoolItem & rItem) const203 int CntBoolItem::operator ==(const SfxPoolItem & rItem) const
204 {
205     DBG_ASSERT(rItem.ISA(CntBoolItem),
206                "CntBoolItem::operator ==(): Bad type");
207     return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue;
208 }
209 
210 //============================================================================
211 // virtual
Compare(const SfxPoolItem & rWith) const212 int CntBoolItem::Compare(const SfxPoolItem & rWith) const
213 {
214     DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type");
215     return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ?
216                0 : m_bValue ? -1 : 1;
217 }
218 
219 //============================================================================
220 // virtual
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,UniString & rText,const IntlWrapper *) const221 SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation,
222                                                  SfxMapUnit, SfxMapUnit,
223                                                  UniString & rText,
224                                                  const IntlWrapper *) const
225 {
226     rText = GetValueTextByVal(m_bValue);
227     return SFX_ITEM_PRESENTATION_NAMELESS;
228 }
229 
230 //============================================================================
231 // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const232 sal_Bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
233 {
234     rVal <<= sal_Bool(m_bValue);
235     return true;
236 }
237 
238 //============================================================================
239 // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)240 sal_Bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
241 {
242     sal_Bool bTheValue = sal_Bool();
243     if (rVal >>= bTheValue)
244     {
245         m_bValue = bTheValue;
246         return true;
247     }
248     DBG_ERROR("CntBoolItem::PutValue(): Wrong type");
249     return false;
250 }
251 
252 //============================================================================
253 // virtual
Create(SvStream & rStream,sal_uInt16) const254 SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const
255 {
256     return new CntBoolItem(Which(), rStream);
257 }
258 
259 //============================================================================
260 // virtual
Store(SvStream & rStream,sal_uInt16) const261 SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const
262 {
263     rStream << m_bValue;
264     return rStream;
265 }
266 
267 //============================================================================
268 // virtual
Clone(SfxItemPool *) const269 SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const
270 {
271     return new CntBoolItem(*this);
272 }
273 
274 //============================================================================
275 // virtual
GetValueCount() const276 sal_uInt16 CntBoolItem::GetValueCount() const
277 {
278     return 2;
279 }
280 
281 //============================================================================
282 // virtual
GetValueTextByVal(sal_Bool bTheValue) const283 UniString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const
284 {
285     return
286         bTheValue ?
287             UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_True")) :
288             UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_False"));
289 }
290 
291