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 <tools/stream.hxx>
26 #include <svl/poolitem.hxx>
27 #include <svl/memberid.hrc>
29 // STATIC DATA -----------------------------------------------------------
33 // -----------------------------------------------------------------------
35 TYPEINIT1_AUTOFACTORY(SfxSizeItem
, SfxPoolItem
);
37 // -----------------------------------------------------------------------
39 SfxSizeItem::SfxSizeItem()
41 DBG_CTOR(SfxSizeItem
, 0);
44 // -----------------------------------------------------------------------
46 SfxSizeItem::SfxSizeItem( sal_uInt16 nW
, const Size
& rVal
) :
50 DBG_CTOR(SfxSizeItem
, 0);
53 // -----------------------------------------------------------------------
55 SfxSizeItem::SfxSizeItem( const SfxSizeItem
& rItem
) :
59 DBG_CTOR(SfxSizeItem
, 0);
62 // -----------------------------------------------------------------------
64 SfxItemPresentation
SfxSizeItem::GetPresentation
66 SfxItemPresentation
/*ePresentation*/,
67 SfxMapUnit
/*eCoreMetric*/,
68 SfxMapUnit
/*ePresentationMetric*/,
73 DBG_CHKTHIS(SfxSizeItem
, 0);
74 rText
= OUString::number(aVal
.Width()) + ", " + OUString::number(aVal
.Height()) + ", ";
75 return SFX_ITEM_PRESENTATION_NAMELESS
;
78 // -----------------------------------------------------------------------
80 int SfxSizeItem::operator==( const SfxPoolItem
& rItem
) const
82 DBG_CHKTHIS(SfxSizeItem
, 0);
83 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
84 return ((SfxSizeItem
&)rItem
).aVal
== aVal
;
87 // -----------------------------------------------------------------------
89 SfxPoolItem
* SfxSizeItem::Clone(SfxItemPool
*) const
91 DBG_CHKTHIS(SfxSizeItem
, 0);
92 return new SfxSizeItem( *this );
95 // -----------------------------------------------------------------------
97 SfxPoolItem
* SfxSizeItem::Create(SvStream
&rStream
, sal_uInt16
) const
99 DBG_CHKTHIS(SfxSizeItem
, 0);
102 return new SfxSizeItem(Which(), aStr
);
105 // -----------------------------------------------------------------------
107 SvStream
& SfxSizeItem::Store(SvStream
&rStream
, sal_uInt16
) const
109 DBG_CHKTHIS(SfxSizeItem
, 0);
114 // -----------------------------------------------------------------------
115 bool SfxSizeItem::QueryValue( com::sun::star::uno::Any
& rVal
,
116 sal_uInt8 nMemberId
) const
118 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
119 nMemberId
&= ~CONVERT_TWIPS
;
124 aTmp
.Height() = ( aTmp
.Height() * 127 + 36) / 72;
125 aTmp
.Width() = ( aTmp
.Width() * 127 + 36) / 72;
132 rVal
<<= com::sun::star::awt::Size( aTmp
.getWidth(), aTmp
.getHeight() );
136 rVal
<<= aTmp
.getWidth(); break;
138 rVal
<<= aTmp
.getHeight(); break;
139 default: OSL_FAIL("Wrong MemberId!"); return false;
145 // -----------------------------------------------------------------------
146 bool SfxSizeItem::PutValue( const com::sun::star::uno::Any
& rVal
,
147 sal_uInt8 nMemberId
)
149 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
150 nMemberId
&= ~CONVERT_TWIPS
;
153 com::sun::star::awt::Size aValue
;
155 bRet
= ( rVal
>>= aValue
);
159 bRet
= ( rVal
>>= nVal
);
160 if ( nMemberId
== MID_WIDTH
)
163 aValue
.Height
= aVal
.Height();
167 aValue
.Height
= nVal
;
168 aValue
.Width
= aVal
.Width();
174 Size
aTmp( aValue
.Width
, aValue
.Height
);
177 aTmp
.Height() = ( aTmp
.Height() * 72 + 63) / 127;
178 aTmp
.Width() = ( aTmp
.Width() * 72 + 63) / 127;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */