merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / ptitem.cxx
blob7c6c9b9a07557c80c134fd3ecf1d7bf2a70bfcc7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ptitem.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <svtools/ptitem.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/awt/Point.hpp>
37 #include <tools/stream.hxx>
39 #include <svtools/poolitem.hxx>
40 #include "memberid.hrc"
42 using namespace ::com::sun::star;
43 // STATIC DATA -----------------------------------------------------------
45 DBG_NAME(SfxPointItem)
47 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
48 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
50 // -----------------------------------------------------------------------
52 TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem);
54 // -----------------------------------------------------------------------
56 SfxPointItem::SfxPointItem()
58 DBG_CTOR(SfxPointItem, 0);
61 // -----------------------------------------------------------------------
63 SfxPointItem::SfxPointItem( USHORT nW, const Point& rVal ) :
64 SfxPoolItem( nW ),
65 aVal( rVal )
67 DBG_CTOR(SfxPointItem, 0);
70 // -----------------------------------------------------------------------
72 SfxPointItem::SfxPointItem( USHORT nW, SvStream &rStream ) :
73 SfxPoolItem( nW )
75 DBG_CTOR(SfxPointItem, 0);
76 rStream >> aVal;
79 // -----------------------------------------------------------------------
81 SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) :
82 SfxPoolItem( rItem ),
83 aVal( rItem.aVal )
85 DBG_CTOR(SfxPointItem, 0);
88 // -----------------------------------------------------------------------
90 SfxItemPresentation SfxPointItem::GetPresentation
92 SfxItemPresentation /*ePresentation*/,
93 SfxMapUnit /*eCoreMetric*/,
94 SfxMapUnit /*ePresentationMetric*/,
95 XubString& rText,
96 const IntlWrapper *
97 ) const
99 DBG_CHKTHIS(SfxPointItem, 0);
100 rText = UniString::CreateFromInt32(aVal.X());
101 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
102 rText += UniString::CreateFromInt32(aVal.Y());
103 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
104 return SFX_ITEM_PRESENTATION_NAMELESS;
107 // -----------------------------------------------------------------------
109 int SfxPointItem::operator==( const SfxPoolItem& rItem ) const
111 DBG_CHKTHIS(SfxPointItem, 0);
112 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
113 return ((SfxPointItem&)rItem).aVal == aVal;
116 // -----------------------------------------------------------------------
118 SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const
120 DBG_CHKTHIS(SfxPointItem, 0);
121 return new SfxPointItem( *this );
124 // -----------------------------------------------------------------------
126 SfxPoolItem* SfxPointItem::Create(SvStream &rStream, USHORT ) const
128 DBG_CHKTHIS(SfxPointItem, 0);
129 Point aStr;
130 rStream >> aStr;
131 return new SfxPointItem(Which(), aStr);
134 // -----------------------------------------------------------------------
136 SvStream& SfxPointItem::Store(SvStream &rStream, USHORT ) const
138 DBG_CHKTHIS(SfxPointItem, 0);
139 rStream << aVal;
140 return rStream;
143 // -----------------------------------------------------------------------
145 BOOL SfxPointItem::QueryValue( uno::Any& rVal,
146 BYTE nMemberId ) const
148 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
149 awt::Point aTmp(aVal.X(), aVal.Y());
150 if( bConvert )
152 aTmp.X = TWIP_TO_MM100(aTmp.X);
153 aTmp.Y = TWIP_TO_MM100(aTmp.Y);
155 nMemberId &= ~CONVERT_TWIPS;
156 switch ( nMemberId )
158 case 0: rVal <<= aTmp; break;
159 case MID_X: rVal <<= aTmp.X; break;
160 case MID_Y: rVal <<= aTmp.Y; break;
161 default: DBG_ERROR("Wrong MemberId!"); return FALSE;
164 return TRUE;
167 // -----------------------------------------------------------------------
169 BOOL SfxPointItem::PutValue( const uno::Any& rVal,
170 BYTE nMemberId )
172 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
173 nMemberId &= ~CONVERT_TWIPS;
174 BOOL bRet = FALSE;
175 awt::Point aValue;
176 sal_Int32 nVal = 0;
177 if ( !nMemberId )
179 bRet = ( rVal >>= aValue );
180 if( bConvert )
182 aValue.X = MM100_TO_TWIP(aValue.X);
183 aValue.Y = MM100_TO_TWIP(aValue.Y);
186 else
188 bRet = ( rVal >>= nVal );
189 if( bConvert )
190 nVal = MM100_TO_TWIP( nVal );
193 if ( bRet )
195 switch ( nMemberId )
197 case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
198 case MID_X: aVal.setX( nVal ); break;
199 case MID_Y: aVal.setY( nVal ); break;
200 default: DBG_ERROR("Wrong MemberId!"); return FALSE;
204 return bRet;