xref: /trunk/main/svl/source/items/ptitem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include <svl/ptitem.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/awt/Point.hpp>
34 #include <tools/stream.hxx>
35 
36 #include <svl/poolitem.hxx>
37 #include <svl/memberid.hrc>
38 
39 using namespace ::com::sun::star;
40 // STATIC DATA -----------------------------------------------------------
41 
42 DBG_NAME(SfxPointItem)
43 
44 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
45 #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
46 
47 // -----------------------------------------------------------------------
48 
49 TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
50 
51 // -----------------------------------------------------------------------
52 
53 SfxPointItem::SfxPointItem()
54 {
55 	DBG_CTOR(SfxPointItem, 0);
56 }
57 
58 // -----------------------------------------------------------------------
59 
60 SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
61 	SfxPoolItem( nW ),
62 	aVal( rVal )
63 {
64 	DBG_CTOR(SfxPointItem, 0);
65 }
66 
67 // -----------------------------------------------------------------------
68 
69 SfxPointItem::SfxPointItem( sal_uInt16 nW, SvStream &rStream ) :
70 	SfxPoolItem( nW )
71 {
72 	DBG_CTOR(SfxPointItem, 0);
73 	rStream >> aVal;
74 }
75 
76 // -----------------------------------------------------------------------
77 
78 SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
79 	SfxPoolItem( rItem ),
80 	aVal( rItem.aVal )
81 {
82 	DBG_CTOR(SfxPointItem, 0);
83 }
84 
85 // -----------------------------------------------------------------------
86 
87 SfxItemPresentation SfxPointItem::GetPresentation
88 (
89 	SfxItemPresentation 	/*ePresentation*/,
90 	SfxMapUnit				/*eCoreMetric*/,
91 	SfxMapUnit				/*ePresentationMetric*/,
92 	XubString& 				rText,
93     const IntlWrapper *
94 )	const
95 {
96 	DBG_CHKTHIS(SfxPointItem, 0);
97 	rText = UniString::CreateFromInt32(aVal.X());
98 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
99 	rText += UniString::CreateFromInt32(aVal.Y());
100 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
101 	return SFX_ITEM_PRESENTATION_NAMELESS;
102 }
103 
104 // -----------------------------------------------------------------------
105 
106 int SfxPointItem::operator==( const SfxPoolItem& rItem ) const
107 {
108 	DBG_CHKTHIS(SfxPointItem, 0);
109 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
110 	return ((SfxPointItem&)rItem).aVal == aVal;
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
116 {
117 	DBG_CHKTHIS(SfxPointItem, 0);
118 	return new SfxPointItem( *this );
119 }
120 
121 // -----------------------------------------------------------------------
122 
123 SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const
124 {
125 	DBG_CHKTHIS(SfxPointItem, 0);
126 	Point aStr;
127 	rStream >> aStr;
128 	return new SfxPointItem(Which(), aStr);
129 }
130 
131 // -----------------------------------------------------------------------
132 
133 SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const
134 {
135 	DBG_CHKTHIS(SfxPointItem, 0);
136 	rStream << aVal;
137 	return rStream;
138 }
139 
140 // -----------------------------------------------------------------------
141 
142 sal_Bool SfxPointItem::QueryValue( uno::Any& rVal,
143 							   sal_uInt8 nMemberId ) const
144 {
145     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
146     awt::Point aTmp(aVal.X(), aVal.Y());
147     if( bConvert )
148     {
149         aTmp.X = TWIP_TO_MM100(aTmp.X);
150         aTmp.Y = TWIP_TO_MM100(aTmp.Y);
151     }
152     nMemberId &= ~CONVERT_TWIPS;
153     switch ( nMemberId )
154     {
155         case 0: rVal <<= aTmp; break;
156         case MID_X: rVal <<= aTmp.X; break;
157         case MID_Y: rVal <<= aTmp.Y; break;
158         default: DBG_ERROR("Wrong MemberId!"); return sal_False;
159     }
160 
161 	return sal_True;
162 }
163 
164 // -----------------------------------------------------------------------
165 
166 sal_Bool SfxPointItem::PutValue( const uno::Any& rVal,
167 							 sal_uInt8 nMemberId )
168 {
169     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
170     nMemberId &= ~CONVERT_TWIPS;
171 	sal_Bool bRet = sal_False;
172     awt::Point aValue;
173     sal_Int32 nVal = 0;
174     if ( !nMemberId )
175     {
176         bRet = ( rVal >>= aValue );
177         if( bConvert )
178         {
179             aValue.X = MM100_TO_TWIP(aValue.X);
180             aValue.Y = MM100_TO_TWIP(aValue.Y);
181         }
182     }
183     else
184     {
185         bRet = ( rVal >>= nVal );
186         if( bConvert )
187             nVal = MM100_TO_TWIP( nVal );
188     }
189 
190     if ( bRet )
191     {
192         switch ( nMemberId )
193         {
194             case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
195             case MID_X: aVal.setX( nVal ); break;
196             case MID_Y: aVal.setY( nVal ); break;
197             default: DBG_ERROR("Wrong MemberId!"); return sal_False;
198         }
199     }
200 
201 	return bRet;
202 }
203 
204 
205 
206