merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / szitem.cxx
blobddfc87032f71c37ec0a8100915f1639738268972
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: szitem.cxx,v $
10 * $Revision: 1.11 $
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/szitem.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <tools/stream.hxx>
38 #include <tools/gen.hxx>
40 #include <svtools/poolitem.hxx>
41 #include "memberid.hrc"
43 // STATIC DATA -----------------------------------------------------------
45 DBG_NAME(SfxSizeItem)
47 // -----------------------------------------------------------------------
49 TYPEINIT1_AUTOFACTORY(SfxSizeItem, SfxPoolItem);
51 // -----------------------------------------------------------------------
53 SfxSizeItem::SfxSizeItem()
55 DBG_CTOR(SfxSizeItem, 0);
58 // -----------------------------------------------------------------------
60 SfxSizeItem::SfxSizeItem( USHORT nW, const Size& rVal ) :
61 SfxPoolItem( nW ),
62 aVal( rVal )
64 DBG_CTOR(SfxSizeItem, 0);
67 // -----------------------------------------------------------------------
69 SfxSizeItem::SfxSizeItem( USHORT nW, SvStream &rStream ) :
70 SfxPoolItem( nW )
72 DBG_CTOR(SfxSizeItem, 0);
73 rStream >> aVal;
76 // -----------------------------------------------------------------------
78 SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) :
79 SfxPoolItem( rItem ),
80 aVal( rItem.aVal )
82 DBG_CTOR(SfxSizeItem, 0);
85 // -----------------------------------------------------------------------
87 SfxItemPresentation SfxSizeItem::GetPresentation
89 SfxItemPresentation /*ePresentation*/,
90 SfxMapUnit /*eCoreMetric*/,
91 SfxMapUnit /*ePresentationMetric*/,
92 XubString& rText,
93 const IntlWrapper *
94 ) const
96 DBG_CHKTHIS(SfxSizeItem, 0);
97 rText = UniString::CreateFromInt32(aVal.Width());
98 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
99 rText += UniString::CreateFromInt32(aVal.Height());
100 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
101 return SFX_ITEM_PRESENTATION_NAMELESS;
104 // -----------------------------------------------------------------------
106 int SfxSizeItem::operator==( const SfxPoolItem& rItem ) const
108 DBG_CHKTHIS(SfxSizeItem, 0);
109 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
110 return ((SfxSizeItem&)rItem).aVal == aVal;
113 // -----------------------------------------------------------------------
115 SfxPoolItem* SfxSizeItem::Clone(SfxItemPool *) const
117 DBG_CHKTHIS(SfxSizeItem, 0);
118 return new SfxSizeItem( *this );
121 // -----------------------------------------------------------------------
123 SfxPoolItem* SfxSizeItem::Create(SvStream &rStream, USHORT ) const
125 DBG_CHKTHIS(SfxSizeItem, 0);
126 Size aStr;
127 rStream >> aStr;
128 return new SfxSizeItem(Which(), aStr);
131 // -----------------------------------------------------------------------
133 SvStream& SfxSizeItem::Store(SvStream &rStream, USHORT ) const
135 DBG_CHKTHIS(SfxSizeItem, 0);
136 rStream << aVal;
137 return rStream;
140 // -----------------------------------------------------------------------
141 BOOL SfxSizeItem::QueryValue( com::sun::star::uno::Any& rVal,
142 BYTE nMemberId ) const
144 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
145 nMemberId &= ~CONVERT_TWIPS;
147 Size aTmp(aVal);
148 if( bConvert )
150 aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72;
151 aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72;
154 switch ( nMemberId )
156 case 0:
158 rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() );
159 break;
161 case MID_WIDTH:
162 rVal <<= aTmp.getWidth(); break;
163 case MID_HEIGHT:
164 rVal <<= aTmp.getHeight(); break;
165 default: DBG_ERROR("Wrong MemberId!"); return FALSE;
168 return TRUE;
171 // -----------------------------------------------------------------------
172 BOOL SfxSizeItem::PutValue( const com::sun::star::uno::Any& rVal,
173 BYTE nMemberId )
175 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
176 nMemberId &= ~CONVERT_TWIPS;
178 BOOL bRet = FALSE;
179 com::sun::star::awt::Size aValue;
180 sal_Int32 nVal = 0;
181 if ( !nMemberId )
182 bRet = ( rVal >>= aValue );
183 else
185 bRet = ( rVal >>= nVal );
186 if ( nMemberId == MID_WIDTH )
188 aValue.Width = nVal;
189 aValue.Height = aVal.Height();
191 else
193 aValue.Height = nVal;
194 aValue.Width = aVal.Width();
198 if ( bRet )
200 Size aTmp( aValue.Width, aValue.Height );
201 if( bConvert )
203 aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127;
204 aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127;
207 aVal = aTmp;
210 return bRet;