xref: /AOO41X/main/svl/source/items/intitem.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 
27 #include <svl/intitem.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <tools/bigint.hxx>
30 #include <tools/stream.hxx>
31 #include <svl/metitem.hxx>
32 
33 //============================================================================
34 //
35 //  class SfxByteItem
36 //
37 //============================================================================
38 
39 TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem);
40 
41 //============================================================================
42 // virtual
Create(SvStream & rStream,sal_uInt16) const43 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const
44 {
45     short nValue = 0;
46     rStream >> nValue;
47     return new SfxByteItem(Which(), sal_uInt8(nValue));
48 }
49 
50 //============================================================================
51 //
52 //  class SfxInt16Item
53 //
54 //============================================================================
55 
56 DBG_NAME(SfxInt16Item);
57 
58 //============================================================================
59 TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem);
60 
61 //============================================================================
SfxInt16Item(sal_uInt16 which,SvStream & rStream)62 SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream):
63     SfxPoolItem(which)
64 {
65     DBG_CTOR(SfxInt16Item, 0);
66     short nTheValue = 0;
67     rStream >> nTheValue;
68     m_nValue = nTheValue;
69 }
70 
71 //============================================================================
72 // virtual
operator ==(const SfxPoolItem & rItem) const73 int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
74 {
75     DBG_CHKTHIS(SfxInt16Item, 0);
76     DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type");
77     return m_nValue == SAL_STATIC_CAST(const SfxInt16Item *, &rItem)->
78                         m_nValue;
79 }
80 
81 //============================================================================
82 // virtual
Compare(const SfxPoolItem & rWith) const83 int SfxInt16Item::Compare(const SfxPoolItem & rWith) const
84 {
85     DBG_CHKTHIS(SfxInt16Item, 0);
86     DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type");
87     return SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue
88              < m_nValue ?
89             -1 :
90            SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue
91              == m_nValue ?
92             0 : 1;
93 }
94 
95 //============================================================================
96 // virtual
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const97 SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation,
98                                                   SfxMapUnit, SfxMapUnit,
99                                                   XubString & rText,
100                                                   const IntlWrapper *) const
101 {
102     DBG_CHKTHIS(SfxInt16Item, 0);
103     rText = UniString::CreateFromInt32(m_nValue);
104     return SFX_ITEM_PRESENTATION_NAMELESS;
105 }
106 
107 
108 //============================================================================
109 // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const110 sal_Bool SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
111 {
112     sal_Int16 nValue = m_nValue;
113     rVal <<= nValue;
114     return sal_True;
115 }
116 
117 //============================================================================
118 // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)119 sal_Bool SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 )
120 {
121     sal_Int16 nValue = sal_Int16();
122     if (rVal >>= nValue)
123     {
124         m_nValue = nValue;
125         return sal_True;
126     }
127 
128     DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" );
129     return sal_False;
130 }
131 
132 //============================================================================
133 // virtual
Create(SvStream & rStream,sal_uInt16) const134 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const
135 {
136     DBG_CHKTHIS(SfxInt16Item, 0);
137     return new SfxInt16Item(Which(), rStream);
138 }
139 
140 //============================================================================
141 // virtual
Store(SvStream & rStream,sal_uInt16) const142 SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const
143 {
144     DBG_CHKTHIS(SfxInt16Item, 0);
145     rStream << short(m_nValue);
146     return rStream;
147 }
148 
149 //============================================================================
Clone(SfxItemPool *) const150 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const
151 {
152     DBG_CHKTHIS(SfxInt16Item, 0);
153     return new SfxInt16Item(*this);
154 }
155 
156 //============================================================================
GetMin() const157 sal_Int16 SfxInt16Item::GetMin() const
158 {
159     DBG_CHKTHIS(SfxInt16Item, 0);
160     return -32768;
161 }
162 
163 //============================================================================
GetMax() const164 sal_Int16 SfxInt16Item::GetMax() const
165 {
166     DBG_CHKTHIS(SfxInt16Item, 0);
167     return 32767;
168 }
169 
170 //============================================================================
GetUnit() const171 SfxFieldUnit SfxInt16Item::GetUnit() const
172 {
173     DBG_CHKTHIS(SfxInt16Item, 0);
174     return SFX_FUNIT_NONE;
175 }
176 
177 //============================================================================
178 //
179 //  class SfxUInt16Item
180 //
181 //============================================================================
182 
183 TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item);
184 
185 
186 //============================================================================
187 //
188 //  class SfxInt32Item
189 //
190 //============================================================================
191 
192 TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item);
193 
194 
195 //============================================================================
196 //
197 //  class SfxUInt32Item
198 //
199 //============================================================================
200 
201 TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item);
202 
203 
204 //============================================================================
205 //
206 //  class SfxMetricItem
207 //
208 //============================================================================
209 
210 DBG_NAME(SfxMetricItem);
211 
212 //============================================================================
213 TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item);
214 
215 //============================================================================
SfxMetricItem(sal_uInt16 which,sal_uInt32 nValue)216 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue):
217     SfxInt32Item(which, nValue)
218 {
219     DBG_CTOR(SfxMetricItem, 0);
220 }
221 
222 //============================================================================
SfxMetricItem(sal_uInt16 which,SvStream & rStream)223 SfxMetricItem::SfxMetricItem(sal_uInt16 which, SvStream & rStream):
224     SfxInt32Item(which, rStream)
225 {
226     DBG_CTOR(SfxMetricItem, 0);
227 }
228 
229 //============================================================================
SfxMetricItem(const SfxMetricItem & rItem)230 SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem):
231     SfxInt32Item(rItem)
232 {
233     DBG_CTOR(SfxMetricItem, 0);
234 }
235 
236 //============================================================================
237 // virtual
ScaleMetrics(long nMult,long nDiv)238 int SfxMetricItem::ScaleMetrics(long nMult, long nDiv)
239 {
240     BigInt aTheValue(GetValue());
241     aTheValue *= nMult;
242     aTheValue += nDiv / 2;
243     aTheValue /= nDiv;
244     SetValue(aTheValue);
245     return 1;
246 }
247 
248 //============================================================================
249 // virtual
HasMetrics() const250 int SfxMetricItem::HasMetrics() const
251 {
252     return 1;
253 }
254 
255