Line data Source code
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 <com/sun/star/uno/Any.hxx>
21 : #include <tools/stream.hxx>
22 : #include <svl/cenumitm.hxx>
23 : #include <whassert.hxx>
24 :
25 : #include <comphelper/extract.hxx>
26 :
27 : //============================================================================
28 : //
29 : // class SfxEnumItemInterface
30 : //
31 : //============================================================================
32 :
33 : DBG_NAME(SfxEnumItemInterface)
34 :
35 : //============================================================================
36 490209 : TYPEINIT1(SfxEnumItemInterface, SfxPoolItem)
37 :
38 : //============================================================================
39 : // virtual
40 303375 : int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const
41 : {
42 : SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type");
43 303375 : return GetEnumValue()
44 : == static_cast< const SfxEnumItemInterface * >(&rItem)->
45 303375 : GetEnumValue();
46 : }
47 :
48 : //============================================================================
49 : // virtual
50 : SfxItemPresentation
51 0 : SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit,
52 : SfxMapUnit, XubString & rText,
53 : const IntlWrapper *) const
54 : {
55 0 : rText = XubString::CreateFromInt32(GetEnumValue());
56 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
57 : }
58 :
59 : //============================================================================
60 : // virtual
61 147 : bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8)
62 : const
63 : {
64 147 : rVal <<= sal_Int32(GetEnumValue());
65 147 : return true;
66 : }
67 :
68 : //============================================================================
69 : // virtual
70 1515 : bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal,
71 : sal_uInt8)
72 : {
73 1515 : sal_Int32 nTheValue = 0;
74 :
75 1515 : if ( ::cppu::enum2int( nTheValue, rVal ) )
76 : {
77 1515 : SetEnumValue(sal_uInt16(nTheValue));
78 1515 : return true;
79 : }
80 : OSL_FAIL("SfxEnumItemInterface::PutValue(): Wrong type");
81 0 : return false;
82 : }
83 :
84 : //============================================================================
85 0 : rtl::OUString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const
86 : {
87 : DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
88 0 : return rtl::OUString();
89 : }
90 :
91 : //============================================================================
92 : // virtual
93 0 : sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const
94 : {
95 0 : return nPos;
96 : }
97 :
98 : //============================================================================
99 : // virtual
100 0 : sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const
101 : {
102 0 : sal_uInt16 nCount = GetValueCount();
103 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
104 0 : if (GetValueByPos(i) == nValue)
105 0 : return i;
106 0 : return USHRT_MAX;
107 : }
108 :
109 0 : sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const
110 : {
111 0 : return sal_True;
112 : }
113 :
114 : //============================================================================
115 : // virtual
116 3 : int SfxEnumItemInterface::HasBoolValue() const
117 : {
118 3 : return false;
119 : }
120 :
121 : //============================================================================
122 : // virtual
123 0 : sal_Bool SfxEnumItemInterface::GetBoolValue() const
124 : {
125 0 : return false;
126 : }
127 :
128 : //============================================================================
129 : // virtual
130 0 : void SfxEnumItemInterface::SetBoolValue(sal_Bool)
131 0 : {}
132 :
133 : //============================================================================
134 : //
135 : // class CntEnumItem
136 : //
137 : //============================================================================
138 :
139 : DBG_NAME(CntEnumItem)
140 :
141 : //============================================================================
142 0 : CntEnumItem::CntEnumItem(sal_uInt16 which, SvStream & rStream):
143 0 : SfxEnumItemInterface(which)
144 : {
145 0 : m_nValue = 0;
146 0 : rStream >> m_nValue;
147 0 : }
148 :
149 : //============================================================================
150 490204 : TYPEINIT1(CntEnumItem, SfxEnumItemInterface)
151 :
152 : //============================================================================
153 : // virtual
154 0 : SvStream & CntEnumItem::Store(SvStream & rStream, sal_uInt16) const
155 : {
156 0 : rStream << m_nValue;
157 0 : return rStream;
158 : }
159 :
160 : //============================================================================
161 : // virtual
162 607193 : sal_uInt16 CntEnumItem::GetEnumValue() const
163 : {
164 607193 : return GetValue();
165 : }
166 :
167 : //============================================================================
168 : // virtual
169 1515 : void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue)
170 : {
171 1515 : SetValue(nTheValue);
172 1515 : }
173 :
174 : //============================================================================
175 : //
176 : // class CntBoolItem
177 : //
178 : //============================================================================
179 :
180 : DBG_NAME(CntBoolItem)
181 :
182 : //============================================================================
183 341654 : TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem)
184 :
185 : //============================================================================
186 0 : CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream):
187 0 : SfxPoolItem(which)
188 : {
189 0 : m_bValue = false;
190 0 : rStream >> m_bValue;
191 0 : }
192 :
193 : //============================================================================
194 : // virtual
195 100690 : int CntBoolItem::operator ==(const SfxPoolItem & rItem) const
196 : {
197 : DBG_ASSERT(rItem.ISA(CntBoolItem),
198 : "CntBoolItem::operator ==(): Bad type");
199 100690 : return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue;
200 : }
201 :
202 : //============================================================================
203 : // virtual
204 0 : int CntBoolItem::Compare(const SfxPoolItem & rWith) const
205 : {
206 : DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type");
207 : return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ?
208 0 : 0 : m_bValue ? -1 : 1;
209 : }
210 :
211 : //============================================================================
212 : // virtual
213 0 : SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation,
214 : SfxMapUnit, SfxMapUnit,
215 : UniString & rText,
216 : const IntlWrapper *) const
217 : {
218 0 : rText = GetValueTextByVal(m_bValue);
219 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
220 : }
221 :
222 : //============================================================================
223 : // virtual
224 2769 : bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
225 : {
226 2769 : rVal <<= sal_Bool(m_bValue);
227 2769 : return true;
228 : }
229 :
230 : //============================================================================
231 : // virtual
232 16984 : bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
233 : {
234 16984 : sal_Bool bTheValue = sal_Bool();
235 16984 : if (rVal >>= bTheValue)
236 : {
237 16984 : m_bValue = bTheValue;
238 16984 : return true;
239 : }
240 : OSL_FAIL("CntBoolItem::PutValue(): Wrong type");
241 0 : return false;
242 : }
243 :
244 : //============================================================================
245 : // virtual
246 0 : SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const
247 : {
248 0 : return new CntBoolItem(Which(), rStream);
249 : }
250 :
251 : //============================================================================
252 : // virtual
253 1068 : SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const
254 : {
255 1068 : rStream << m_bValue;
256 1068 : return rStream;
257 : }
258 :
259 : //============================================================================
260 : // virtual
261 0 : SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const
262 : {
263 0 : return new CntBoolItem(*this);
264 : }
265 :
266 : //============================================================================
267 : // virtual
268 0 : sal_uInt16 CntBoolItem::GetValueCount() const
269 : {
270 0 : return 2;
271 : }
272 :
273 : //============================================================================
274 : // virtual
275 0 : rtl::OUString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const
276 : {
277 0 : return bTheValue ? rtl::OUString("TRUE") : rtl::OUString("FALSE");
278 : }
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|