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