xref: /trunk/main/svl/source/items/ptitem.cxx (revision 40df464e)
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/ptitem.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/awt/Point.hpp>
30 #include <tools/stream.hxx>
31 
32 #include <svl/poolitem.hxx>
33 #include <svl/memberid.hrc>
34 
35 using namespace ::com::sun::star;
36 // STATIC DATA -----------------------------------------------------------
37 
38 DBG_NAME(SfxPointItem)
39 
40 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
41 #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
42 
43 // -----------------------------------------------------------------------
44 
45 TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
46 
47 // -----------------------------------------------------------------------
48 
SfxPointItem()49 SfxPointItem::SfxPointItem()
50 {
51 	DBG_CTOR(SfxPointItem, 0);
52 }
53 
54 // -----------------------------------------------------------------------
55 
SfxPointItem(sal_uInt16 nW,const Point & rVal)56 SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
57 	SfxPoolItem( nW ),
58 	aVal( rVal )
59 {
60 	DBG_CTOR(SfxPointItem, 0);
61 }
62 
63 // -----------------------------------------------------------------------
64 
SfxPointItem(sal_uInt16 nW,SvStream & rStream)65 SfxPointItem::SfxPointItem( sal_uInt16 nW, SvStream &rStream ) :
66 	SfxPoolItem( nW )
67 {
68 	DBG_CTOR(SfxPointItem, 0);
69 	rStream >> aVal;
70 }
71 
72 // -----------------------------------------------------------------------
73 
SfxPointItem(const SfxPointItem & rItem)74 SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
75 	SfxPoolItem( rItem ),
76 	aVal( rItem.aVal )
77 {
78 	DBG_CTOR(SfxPointItem, 0);
79 }
80 
81 // -----------------------------------------------------------------------
82 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const83 SfxItemPresentation SfxPointItem::GetPresentation
84 (
85 	SfxItemPresentation 	/*ePresentation*/,
86 	SfxMapUnit				/*eCoreMetric*/,
87 	SfxMapUnit				/*ePresentationMetric*/,
88 	XubString& 				rText,
89     const IntlWrapper *
90 )	const
91 {
92 	DBG_CHKTHIS(SfxPointItem, 0);
93 	rText = UniString::CreateFromInt32(aVal.X());
94 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
95 	rText += UniString::CreateFromInt32(aVal.Y());
96 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
97 	return SFX_ITEM_PRESENTATION_NAMELESS;
98 }
99 
100 // -----------------------------------------------------------------------
101 
operator ==(const SfxPoolItem & rItem) const102 int SfxPointItem::operator==( const SfxPoolItem& rItem ) const
103 {
104 	DBG_CHKTHIS(SfxPointItem, 0);
105 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
106 	return ((SfxPointItem&)rItem).aVal == aVal;
107 }
108 
109 // -----------------------------------------------------------------------
110 
Clone(SfxItemPool *) const111 SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
112 {
113 	DBG_CHKTHIS(SfxPointItem, 0);
114 	return new SfxPointItem( *this );
115 }
116 
117 // -----------------------------------------------------------------------
118 
Create(SvStream & rStream,sal_uInt16) const119 SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const
120 {
121 	DBG_CHKTHIS(SfxPointItem, 0);
122 	Point aStr;
123 	rStream >> aStr;
124 	return new SfxPointItem(Which(), aStr);
125 }
126 
127 // -----------------------------------------------------------------------
128 
Store(SvStream & rStream,sal_uInt16) const129 SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const
130 {
131 	DBG_CHKTHIS(SfxPointItem, 0);
132 	rStream << aVal;
133 	return rStream;
134 }
135 
136 // -----------------------------------------------------------------------
137 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const138 sal_Bool SfxPointItem::QueryValue( uno::Any& rVal,
139 							   sal_uInt8 nMemberId ) const
140 {
141     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
142     awt::Point aTmp(aVal.X(), aVal.Y());
143     if( bConvert )
144     {
145         aTmp.X = TWIP_TO_MM100(aTmp.X);
146         aTmp.Y = TWIP_TO_MM100(aTmp.Y);
147     }
148     nMemberId &= ~CONVERT_TWIPS;
149     switch ( nMemberId )
150     {
151         case 0: rVal <<= aTmp; break;
152         case MID_X: rVal <<= aTmp.X; break;
153         case MID_Y: rVal <<= aTmp.Y; break;
154         default: DBG_ERROR("Wrong MemberId!"); return sal_False;
155     }
156 
157 	return sal_True;
158 }
159 
160 // -----------------------------------------------------------------------
161 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)162 sal_Bool SfxPointItem::PutValue( const uno::Any& rVal,
163 							 sal_uInt8 nMemberId )
164 {
165     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
166     nMemberId &= ~CONVERT_TWIPS;
167 	sal_Bool bRet = sal_False;
168     awt::Point aValue;
169     sal_Int32 nVal = 0;
170     if ( !nMemberId )
171     {
172         bRet = ( rVal >>= aValue );
173         if( bConvert )
174         {
175             aValue.X = MM100_TO_TWIP(aValue.X);
176             aValue.Y = MM100_TO_TWIP(aValue.Y);
177         }
178     }
179     else
180     {
181         bRet = ( rVal >>= nVal );
182         if( bConvert )
183             nVal = MM100_TO_TWIP( nVal );
184     }
185 
186     if ( bRet )
187     {
188         switch ( nMemberId )
189         {
190             case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
191             case MID_X: aVal.setX( nVal ); break;
192             case MID_Y: aVal.setY( nVal ); break;
193             default: DBG_ERROR("Wrong MemberId!"); return sal_False;
194         }
195     }
196 
197 	return bRet;
198 }
199 
200 
201 
202