1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) :
48 SfxSizeItem::SfxSizeItem( const SfxSizeItem
& rItem
) :
56 bool SfxSizeItem::GetPresentation
58 SfxItemPresentation
/*ePresentation*/,
59 SfxMapUnit
/*eCoreMetric*/,
60 SfxMapUnit
/*ePresentationMetric*/,
65 rText
= OUString::number(aVal
.Width()) + ", " + OUString::number(aVal
.Height()) + ", ";
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
89 ReadPair( rStream
, aStr
);
90 return new SfxSizeItem(Which(), aStr
);
95 SvStream
& SfxSizeItem::Store(SvStream
&rStream
, sal_uInt16
) const
97 WritePair( rStream
, aVal
);
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
;
111 aTmp
.Height() = ( aTmp
.Height() * 127 + 36) / 72;
112 aTmp
.Width() = ( aTmp
.Width() * 127 + 36) / 72;
119 rVal
<<= com::sun::star::awt::Size( aTmp
.getWidth(), aTmp
.getHeight() );
123 rVal
<<= aTmp
.getWidth(); break;
125 rVal
<<= aTmp
.getHeight(); break;
126 default: OSL_FAIL("Wrong MemberId!"); return false;
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
;
140 com::sun::star::awt::Size aValue
;
142 bRet
= ( rVal
>>= aValue
);
146 bRet
= ( rVal
>>= nVal
);
147 if ( nMemberId
== MID_WIDTH
)
150 aValue
.Height
= aVal
.Height();
154 aValue
.Height
= nVal
;
155 aValue
.Width
= aVal
.Width();
161 Size
aTmp( aValue
.Width
, aValue
.Height
);
164 aTmp
.Height() = ( aTmp
.Height() * 72 + 63) / 127;
165 aTmp
.Width() = ( aTmp
.Width() * 72 + 63) / 127;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */