1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: szitem.cxx,v $
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 -----------------------------------------------------------
47 // -----------------------------------------------------------------------
49 TYPEINIT1_AUTOFACTORY(SfxSizeItem
, SfxPoolItem
);
51 // -----------------------------------------------------------------------
53 SfxSizeItem::SfxSizeItem()
55 DBG_CTOR(SfxSizeItem
, 0);
58 // -----------------------------------------------------------------------
60 SfxSizeItem::SfxSizeItem( USHORT nW
, const Size
& rVal
) :
64 DBG_CTOR(SfxSizeItem
, 0);
67 // -----------------------------------------------------------------------
69 SfxSizeItem::SfxSizeItem( USHORT nW
, SvStream
&rStream
) :
72 DBG_CTOR(SfxSizeItem
, 0);
76 // -----------------------------------------------------------------------
78 SfxSizeItem::SfxSizeItem( const SfxSizeItem
& rItem
) :
82 DBG_CTOR(SfxSizeItem
, 0);
85 // -----------------------------------------------------------------------
87 SfxItemPresentation
SfxSizeItem::GetPresentation
89 SfxItemPresentation
/*ePresentation*/,
90 SfxMapUnit
/*eCoreMetric*/,
91 SfxMapUnit
/*ePresentationMetric*/,
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);
128 return new SfxSizeItem(Which(), aStr
);
131 // -----------------------------------------------------------------------
133 SvStream
& SfxSizeItem::Store(SvStream
&rStream
, USHORT
) const
135 DBG_CHKTHIS(SfxSizeItem
, 0);
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
;
150 aTmp
.Height() = ( aTmp
.Height() * 127 + 36) / 72;
151 aTmp
.Width() = ( aTmp
.Width() * 127 + 36) / 72;
158 rVal
<<= com::sun::star::awt::Size( aTmp
.getWidth(), aTmp
.getHeight() );
162 rVal
<<= aTmp
.getWidth(); break;
164 rVal
<<= aTmp
.getHeight(); break;
165 default: DBG_ERROR("Wrong MemberId!"); return FALSE
;
171 // -----------------------------------------------------------------------
172 BOOL
SfxSizeItem::PutValue( const com::sun::star::uno::Any
& rVal
,
175 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
176 nMemberId
&= ~CONVERT_TWIPS
;
179 com::sun::star::awt::Size aValue
;
182 bRet
= ( rVal
>>= aValue
);
185 bRet
= ( rVal
>>= nVal
);
186 if ( nMemberId
== MID_WIDTH
)
189 aValue
.Height
= aVal
.Height();
193 aValue
.Height
= nVal
;
194 aValue
.Width
= aVal
.Width();
200 Size
aTmp( aValue
.Width
, aValue
.Height
);
203 aTmp
.Height() = ( aTmp
.Height() * 72 + 63) / 127;
204 aTmp
.Width() = ( aTmp
.Width() * 72 + 63) / 127;