1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*40df464eSAndrew Rist * distributed with this work for additional information
6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10*40df464eSAndrew Rist *
11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist *
13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist * software distributed under the License is distributed on an
15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the
17*40df464eSAndrew Rist * specific language governing permissions and limitations
18*40df464eSAndrew Rist * under the License.
19*40df464eSAndrew Rist *
20*40df464eSAndrew Rist *************************************************************/
21*40df464eSAndrew Rist
22*40df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <svl/szitem.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
29cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
30cdf0e10cSrcweir #include <tools/stream.hxx>
31cdf0e10cSrcweir #include <tools/gen.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svl/poolitem.hxx>
34cdf0e10cSrcweir #include <svl/memberid.hrc>
35cdf0e10cSrcweir
36cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
37cdf0e10cSrcweir
38cdf0e10cSrcweir DBG_NAME(SfxSizeItem)
39cdf0e10cSrcweir
40cdf0e10cSrcweir // -----------------------------------------------------------------------
41cdf0e10cSrcweir
42cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SfxSizeItem, SfxPoolItem);
43cdf0e10cSrcweir
44cdf0e10cSrcweir // -----------------------------------------------------------------------
45cdf0e10cSrcweir
SfxSizeItem()46cdf0e10cSrcweir SfxSizeItem::SfxSizeItem()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir DBG_CTOR(SfxSizeItem, 0);
49cdf0e10cSrcweir }
50cdf0e10cSrcweir
51cdf0e10cSrcweir // -----------------------------------------------------------------------
52cdf0e10cSrcweir
SfxSizeItem(sal_uInt16 nW,const Size & rVal)53cdf0e10cSrcweir SfxSizeItem::SfxSizeItem( sal_uInt16 nW, const Size& rVal ) :
54cdf0e10cSrcweir SfxPoolItem( nW ),
55cdf0e10cSrcweir aVal( rVal )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir DBG_CTOR(SfxSizeItem, 0);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
60cdf0e10cSrcweir // -----------------------------------------------------------------------
61cdf0e10cSrcweir
SfxSizeItem(sal_uInt16 nW,SvStream & rStream)62cdf0e10cSrcweir SfxSizeItem::SfxSizeItem( sal_uInt16 nW, SvStream &rStream ) :
63cdf0e10cSrcweir SfxPoolItem( nW )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir DBG_CTOR(SfxSizeItem, 0);
66cdf0e10cSrcweir rStream >> aVal;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir // -----------------------------------------------------------------------
70cdf0e10cSrcweir
SfxSizeItem(const SfxSizeItem & rItem)71cdf0e10cSrcweir SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) :
72cdf0e10cSrcweir SfxPoolItem( rItem ),
73cdf0e10cSrcweir aVal( rItem.aVal )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir DBG_CTOR(SfxSizeItem, 0);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir // -----------------------------------------------------------------------
79cdf0e10cSrcweir
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const80cdf0e10cSrcweir SfxItemPresentation SfxSizeItem::GetPresentation
81cdf0e10cSrcweir (
82cdf0e10cSrcweir SfxItemPresentation /*ePresentation*/,
83cdf0e10cSrcweir SfxMapUnit /*eCoreMetric*/,
84cdf0e10cSrcweir SfxMapUnit /*ePresentationMetric*/,
85cdf0e10cSrcweir XubString& rText,
86cdf0e10cSrcweir const IntlWrapper *
87cdf0e10cSrcweir ) const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir DBG_CHKTHIS(SfxSizeItem, 0);
90cdf0e10cSrcweir rText = UniString::CreateFromInt32(aVal.Width());
91cdf0e10cSrcweir rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
92cdf0e10cSrcweir rText += UniString::CreateFromInt32(aVal.Height());
93cdf0e10cSrcweir rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
94cdf0e10cSrcweir return SFX_ITEM_PRESENTATION_NAMELESS;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir // -----------------------------------------------------------------------
98cdf0e10cSrcweir
operator ==(const SfxPoolItem & rItem) const99cdf0e10cSrcweir int SfxSizeItem::operator==( const SfxPoolItem& rItem ) const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir DBG_CHKTHIS(SfxSizeItem, 0);
102cdf0e10cSrcweir DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
103cdf0e10cSrcweir return ((SfxSizeItem&)rItem).aVal == aVal;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir // -----------------------------------------------------------------------
107cdf0e10cSrcweir
Clone(SfxItemPool *) const108cdf0e10cSrcweir SfxPoolItem* SfxSizeItem::Clone(SfxItemPool *) const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir DBG_CHKTHIS(SfxSizeItem, 0);
111cdf0e10cSrcweir return new SfxSizeItem( *this );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir // -----------------------------------------------------------------------
115cdf0e10cSrcweir
Create(SvStream & rStream,sal_uInt16) const116cdf0e10cSrcweir SfxPoolItem* SfxSizeItem::Create(SvStream &rStream, sal_uInt16 ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir DBG_CHKTHIS(SfxSizeItem, 0);
119cdf0e10cSrcweir Size aStr;
120cdf0e10cSrcweir rStream >> aStr;
121cdf0e10cSrcweir return new SfxSizeItem(Which(), aStr);
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir // -----------------------------------------------------------------------
125cdf0e10cSrcweir
Store(SvStream & rStream,sal_uInt16) const126cdf0e10cSrcweir SvStream& SfxSizeItem::Store(SvStream &rStream, sal_uInt16 ) const
127cdf0e10cSrcweir {
128cdf0e10cSrcweir DBG_CHKTHIS(SfxSizeItem, 0);
129cdf0e10cSrcweir rStream << aVal;
130cdf0e10cSrcweir return rStream;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir // -----------------------------------------------------------------------
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId) const134cdf0e10cSrcweir sal_Bool SfxSizeItem::QueryValue( com::sun::star::uno::Any& rVal,
135cdf0e10cSrcweir sal_uInt8 nMemberId ) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
138cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS;
139cdf0e10cSrcweir
140cdf0e10cSrcweir Size aTmp(aVal);
141cdf0e10cSrcweir if( bConvert )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72;
144cdf0e10cSrcweir aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir switch ( nMemberId )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir case 0:
150cdf0e10cSrcweir {
151cdf0e10cSrcweir rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() );
152cdf0e10cSrcweir break;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir case MID_WIDTH:
155cdf0e10cSrcweir rVal <<= aTmp.getWidth(); break;
156cdf0e10cSrcweir case MID_HEIGHT:
157cdf0e10cSrcweir rVal <<= aTmp.getHeight(); break;
158cdf0e10cSrcweir default: DBG_ERROR("Wrong MemberId!"); return sal_False;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir return sal_True;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir // -----------------------------------------------------------------------
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId)165cdf0e10cSrcweir sal_Bool SfxSizeItem::PutValue( const com::sun::star::uno::Any& rVal,
166cdf0e10cSrcweir sal_uInt8 nMemberId )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
169cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS;
170cdf0e10cSrcweir
171cdf0e10cSrcweir sal_Bool bRet = sal_False;
172cdf0e10cSrcweir com::sun::star::awt::Size aValue;
173cdf0e10cSrcweir sal_Int32 nVal = 0;
174cdf0e10cSrcweir if ( !nMemberId )
175cdf0e10cSrcweir bRet = ( rVal >>= aValue );
176cdf0e10cSrcweir else
177cdf0e10cSrcweir {
178cdf0e10cSrcweir bRet = ( rVal >>= nVal );
179cdf0e10cSrcweir if ( nMemberId == MID_WIDTH )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir aValue.Width = nVal;
182cdf0e10cSrcweir aValue.Height = aVal.Height();
183cdf0e10cSrcweir }
184cdf0e10cSrcweir else
185cdf0e10cSrcweir {
186cdf0e10cSrcweir aValue.Height = nVal;
187cdf0e10cSrcweir aValue.Width = aVal.Width();
188cdf0e10cSrcweir }
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
191cdf0e10cSrcweir if ( bRet )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir Size aTmp( aValue.Width, aValue.Height );
194cdf0e10cSrcweir if( bConvert )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127;
197cdf0e10cSrcweir aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir aVal = aTmp;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir return bRet;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir
207cdf0e10cSrcweir
208