bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / szitem.cxx
blob46cff2d7a2adab295b5bac28a8132779e10b8308
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svl/szitem.hxx>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <com/sun/star/awt/Size.hpp>
24 #include <osl/diagnose.h>
25 #include <tools/stream.hxx>
27 #include <svl/poolitem.hxx>
28 #include <svl/memberid.hrc>
30 TYPEINIT1_AUTOFACTORY(SfxSizeItem, SfxPoolItem);
34 SfxSizeItem::SfxSizeItem()
40 SfxSizeItem::SfxSizeItem( sal_uInt16 nW, const Size& rVal ) :
41 SfxPoolItem( nW ),
42 aVal( rVal )
48 SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) :
49 SfxPoolItem( rItem ),
50 aVal( rItem.aVal )
56 bool SfxSizeItem::GetPresentation
58 SfxItemPresentation /*ePresentation*/,
59 SfxMapUnit /*eCoreMetric*/,
60 SfxMapUnit /*ePresentationMetric*/,
61 OUString& rText,
62 const IntlWrapper *
63 ) const
65 rText = OUString::number(aVal.Width()) + ", " + OUString::number(aVal.Height()) + ", ";
66 return true;
71 bool SfxSizeItem::operator==( const SfxPoolItem& rItem ) const
73 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
74 return static_cast<const SfxSizeItem&>(rItem).aVal == aVal;
79 SfxPoolItem* SfxSizeItem::Clone(SfxItemPool *) const
81 return new SfxSizeItem( *this );
86 SfxPoolItem* SfxSizeItem::Create(SvStream &rStream, sal_uInt16 ) const
88 Size aStr;
89 ReadPair( rStream, aStr );
90 return new SfxSizeItem(Which(), aStr);
95 SvStream& SfxSizeItem::Store(SvStream &rStream, sal_uInt16 ) const
97 WritePair( rStream, aVal );
98 return rStream;
102 bool SfxSizeItem::QueryValue( com::sun::star::uno::Any& rVal,
103 sal_uInt8 nMemberId ) const
105 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
106 nMemberId &= ~CONVERT_TWIPS;
108 Size aTmp(aVal);
109 if( bConvert )
111 aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72;
112 aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72;
115 switch ( nMemberId )
117 case 0:
119 rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() );
120 break;
122 case MID_WIDTH:
123 rVal <<= aTmp.getWidth(); break;
124 case MID_HEIGHT:
125 rVal <<= aTmp.getHeight(); break;
126 default: OSL_FAIL("Wrong MemberId!"); return false;
129 return true;
133 bool SfxSizeItem::PutValue( const com::sun::star::uno::Any& rVal,
134 sal_uInt8 nMemberId )
136 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
137 nMemberId &= ~CONVERT_TWIPS;
139 bool bRet = false;
140 com::sun::star::awt::Size aValue;
141 if ( !nMemberId )
142 bRet = ( rVal >>= aValue );
143 else
145 sal_Int32 nVal = 0;
146 bRet = ( rVal >>= nVal );
147 if ( nMemberId == MID_WIDTH )
149 aValue.Width = nVal;
150 aValue.Height = aVal.Height();
152 else
154 aValue.Height = nVal;
155 aValue.Width = aVal.Width();
159 if ( bRet )
161 Size aTmp( aValue.Width, aValue.Height );
162 if( bConvert )
164 aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127;
165 aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127;
168 aVal = aTmp;
171 return bRet;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */