xref: /AOO41X/main/svl/source/items/ptitem.cxx (revision 40df464ee80f942fd2baf5effc726656f4be12a0)
1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*40df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*40df464eSAndrew Rist  * distributed with this work for additional information
6*40df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*40df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist  * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*40df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*40df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist  * software distributed under the License is distributed on an
15*40df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*40df464eSAndrew Rist  * specific language governing permissions and limitations
18*40df464eSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*40df464eSAndrew Rist  *************************************************************/
21*40df464eSAndrew Rist 
22*40df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svl/ptitem.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
29cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
30cdf0e10cSrcweir #include <tools/stream.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <svl/poolitem.hxx>
33cdf0e10cSrcweir #include <svl/memberid.hrc>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
37cdf0e10cSrcweir 
38cdf0e10cSrcweir DBG_NAME(SfxPointItem)
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
41cdf0e10cSrcweir #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // -----------------------------------------------------------------------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // -----------------------------------------------------------------------
48cdf0e10cSrcweir 
SfxPointItem()49cdf0e10cSrcweir SfxPointItem::SfxPointItem()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	DBG_CTOR(SfxPointItem, 0);
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // -----------------------------------------------------------------------
55cdf0e10cSrcweir 
SfxPointItem(sal_uInt16 nW,const Point & rVal)56cdf0e10cSrcweir SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
57cdf0e10cSrcweir 	SfxPoolItem( nW ),
58cdf0e10cSrcweir 	aVal( rVal )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	DBG_CTOR(SfxPointItem, 0);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // -----------------------------------------------------------------------
64cdf0e10cSrcweir 
SfxPointItem(sal_uInt16 nW,SvStream & rStream)65cdf0e10cSrcweir SfxPointItem::SfxPointItem( sal_uInt16 nW, SvStream &rStream ) :
66cdf0e10cSrcweir 	SfxPoolItem( nW )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	DBG_CTOR(SfxPointItem, 0);
69cdf0e10cSrcweir 	rStream >> aVal;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // -----------------------------------------------------------------------
73cdf0e10cSrcweir 
SfxPointItem(const SfxPointItem & rItem)74cdf0e10cSrcweir SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
75cdf0e10cSrcweir 	SfxPoolItem( rItem ),
76cdf0e10cSrcweir 	aVal( rItem.aVal )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	DBG_CTOR(SfxPointItem, 0);
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // -----------------------------------------------------------------------
82cdf0e10cSrcweir 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const83cdf0e10cSrcweir SfxItemPresentation SfxPointItem::GetPresentation
84cdf0e10cSrcweir (
85cdf0e10cSrcweir 	SfxItemPresentation 	/*ePresentation*/,
86cdf0e10cSrcweir 	SfxMapUnit				/*eCoreMetric*/,
87cdf0e10cSrcweir 	SfxMapUnit				/*ePresentationMetric*/,
88cdf0e10cSrcweir 	XubString& 				rText,
89cdf0e10cSrcweir     const IntlWrapper *
90cdf0e10cSrcweir )	const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	DBG_CHKTHIS(SfxPointItem, 0);
93cdf0e10cSrcweir 	rText = UniString::CreateFromInt32(aVal.X());
94cdf0e10cSrcweir 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
95cdf0e10cSrcweir 	rText += UniString::CreateFromInt32(aVal.Y());
96cdf0e10cSrcweir 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
97cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NAMELESS;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // -----------------------------------------------------------------------
101cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rItem) const102cdf0e10cSrcweir int SfxPointItem::operator==( const SfxPoolItem& rItem ) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	DBG_CHKTHIS(SfxPointItem, 0);
105cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
106cdf0e10cSrcweir 	return ((SfxPointItem&)rItem).aVal == aVal;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // -----------------------------------------------------------------------
110cdf0e10cSrcweir 
Clone(SfxItemPool *) const111cdf0e10cSrcweir SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	DBG_CHKTHIS(SfxPointItem, 0);
114cdf0e10cSrcweir 	return new SfxPointItem( *this );
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // -----------------------------------------------------------------------
118cdf0e10cSrcweir 
Create(SvStream & rStream,sal_uInt16) const119cdf0e10cSrcweir SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	DBG_CHKTHIS(SfxPointItem, 0);
122cdf0e10cSrcweir 	Point aStr;
123cdf0e10cSrcweir 	rStream >> aStr;
124cdf0e10cSrcweir 	return new SfxPointItem(Which(), aStr);
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir // -----------------------------------------------------------------------
128cdf0e10cSrcweir 
Store(SvStream & rStream,sal_uInt16) const129cdf0e10cSrcweir SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	DBG_CHKTHIS(SfxPointItem, 0);
132cdf0e10cSrcweir 	rStream << aVal;
133cdf0e10cSrcweir 	return rStream;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // -----------------------------------------------------------------------
137cdf0e10cSrcweir 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const138cdf0e10cSrcweir sal_Bool SfxPointItem::QueryValue( uno::Any& rVal,
139cdf0e10cSrcweir 							   sal_uInt8 nMemberId ) const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
142cdf0e10cSrcweir     awt::Point aTmp(aVal.X(), aVal.Y());
143cdf0e10cSrcweir     if( bConvert )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         aTmp.X = TWIP_TO_MM100(aTmp.X);
146cdf0e10cSrcweir         aTmp.Y = TWIP_TO_MM100(aTmp.Y);
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
149cdf0e10cSrcweir     switch ( nMemberId )
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         case 0: rVal <<= aTmp; break;
152cdf0e10cSrcweir         case MID_X: rVal <<= aTmp.X; break;
153cdf0e10cSrcweir         case MID_Y: rVal <<= aTmp.Y; break;
154cdf0e10cSrcweir         default: DBG_ERROR("Wrong MemberId!"); return sal_False;
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	return sal_True;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // -----------------------------------------------------------------------
161cdf0e10cSrcweir 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)162cdf0e10cSrcweir sal_Bool SfxPointItem::PutValue( const uno::Any& rVal,
163cdf0e10cSrcweir 							 sal_uInt8 nMemberId )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
166cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
167cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
168cdf0e10cSrcweir     awt::Point aValue;
169cdf0e10cSrcweir     sal_Int32 nVal = 0;
170cdf0e10cSrcweir     if ( !nMemberId )
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         bRet = ( rVal >>= aValue );
173cdf0e10cSrcweir         if( bConvert )
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             aValue.X = MM100_TO_TWIP(aValue.X);
176cdf0e10cSrcweir             aValue.Y = MM100_TO_TWIP(aValue.Y);
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     else
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         bRet = ( rVal >>= nVal );
182cdf0e10cSrcweir         if( bConvert )
183cdf0e10cSrcweir             nVal = MM100_TO_TWIP( nVal );
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     if ( bRet )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         switch ( nMemberId )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
191cdf0e10cSrcweir             case MID_X: aVal.setX( nVal ); break;
192cdf0e10cSrcweir             case MID_Y: aVal.setY( nVal ); break;
193cdf0e10cSrcweir             default: DBG_ERROR("Wrong MemberId!"); return sal_False;
194cdf0e10cSrcweir         }
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	return bRet;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202