GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / szitem.cxx
blob78f1ada2059e57f76fcb0c206b3bdca77f938c5b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 -----------------------------------------------------------
31 DBG_NAME(SfxSizeItem)
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 ) :
47 SfxPoolItem( nW ),
48 aVal( rVal )
50 DBG_CTOR(SfxSizeItem, 0);
53 // -----------------------------------------------------------------------
55 SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) :
56 SfxPoolItem( rItem ),
57 aVal( rItem.aVal )
59 DBG_CTOR(SfxSizeItem, 0);
62 // -----------------------------------------------------------------------
64 SfxItemPresentation SfxSizeItem::GetPresentation
66 SfxItemPresentation /*ePresentation*/,
67 SfxMapUnit /*eCoreMetric*/,
68 SfxMapUnit /*ePresentationMetric*/,
69 OUString& rText,
70 const IntlWrapper *
71 ) const
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);
100 Size aStr;
101 rStream >> aStr;
102 return new SfxSizeItem(Which(), aStr);
105 // -----------------------------------------------------------------------
107 SvStream& SfxSizeItem::Store(SvStream &rStream, sal_uInt16 ) const
109 DBG_CHKTHIS(SfxSizeItem, 0);
110 rStream << aVal;
111 return rStream;
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;
121 Size aTmp(aVal);
122 if( bConvert )
124 aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72;
125 aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72;
128 switch ( nMemberId )
130 case 0:
132 rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() );
133 break;
135 case MID_WIDTH:
136 rVal <<= aTmp.getWidth(); break;
137 case MID_HEIGHT:
138 rVal <<= aTmp.getHeight(); break;
139 default: OSL_FAIL("Wrong MemberId!"); return false;
142 return true;
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;
152 bool bRet = false;
153 com::sun::star::awt::Size aValue;
154 if ( !nMemberId )
155 bRet = ( rVal >>= aValue );
156 else
158 sal_Int32 nVal = 0;
159 bRet = ( rVal >>= nVal );
160 if ( nMemberId == MID_WIDTH )
162 aValue.Width = nVal;
163 aValue.Height = aVal.Height();
165 else
167 aValue.Height = nVal;
168 aValue.Width = aVal.Width();
172 if ( bRet )
174 Size aTmp( aValue.Width, aValue.Height );
175 if( bConvert )
177 aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127;
178 aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127;
181 aVal = aTmp;
184 return bRet;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */