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