bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / rectitem.cxx
blobbd8e57c66b80199e54fde900ba77a7a7abf67088
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/rectitem.hxx>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <osl/diagnose.h>
25 #include <tools/stream.hxx>
27 #include <svl/poolitem.hxx>
28 #include <svl/memberid.hrc>
30 TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem);
34 SfxRectangleItem::SfxRectangleItem()
40 SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const Rectangle& rVal ) :
41 SfxPoolItem( nW ),
42 aVal( rVal )
48 SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) :
49 SfxPoolItem( rItem ),
50 aVal( rItem.aVal )
56 bool SfxRectangleItem::GetPresentation
58 SfxItemPresentation /*ePresentation*/,
59 SfxMapUnit /*eCoreMetric*/,
60 SfxMapUnit /*ePresentationMetric*/,
61 OUString& rText,
62 const IntlWrapper *
63 ) const
65 rText = OUString::number(aVal.Top()) + ", " +
66 OUString::number(aVal.Left()) + ", " +
67 OUString::number(aVal.Bottom()) + ", " +
68 OUString::number(aVal.Right());
69 return true;
74 bool SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
76 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
77 return static_cast<const SfxRectangleItem&>(rItem).aVal == aVal;
82 SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const
84 return new SfxRectangleItem( *this );
89 SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, sal_uInt16 ) const
91 Rectangle aStr;
92 ReadRectangle( rStream, aStr );
93 return new SfxRectangleItem(Which(), aStr);
98 SvStream& SfxRectangleItem::Store(SvStream &rStream, sal_uInt16 ) const
100 WriteRectangle( rStream, aVal );
101 return rStream;
106 bool SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal,
107 sal_uInt8 nMemberId) const
109 nMemberId &= ~CONVERT_TWIPS;
110 switch ( nMemberId )
112 case 0:
114 rVal <<= com::sun::star::awt::Rectangle( aVal.getX(),
115 aVal.getY(),
116 aVal.getWidth(),
117 aVal.getHeight() );
118 break;
120 case MID_RECT_LEFT: rVal <<= aVal.getX(); break;
121 case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
122 case MID_WIDTH: rVal <<= aVal.getWidth(); break;
123 case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
124 default: OSL_FAIL("Wrong MemberID!"); return false;
127 return true;
131 bool SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal,
132 sal_uInt8 nMemberId )
134 bool bRet = false;
135 nMemberId &= ~CONVERT_TWIPS;
136 com::sun::star::awt::Rectangle aValue;
137 sal_Int32 nVal = 0;
138 if ( !nMemberId )
139 bRet = (rVal >>= aValue);
140 else
141 bRet = (rVal >>= nVal);
143 if ( bRet )
145 switch ( nMemberId )
147 case 0:
148 aVal.setX( aValue.X );
149 aVal.setY( aValue.Y );
150 aVal.setWidth( aValue.Width );
151 aVal.setHeight( aValue.Height );
152 break;
153 case MID_RECT_LEFT: aVal.setX( nVal ); break;
154 case MID_RECT_RIGHT: aVal.setY( nVal ); break;
155 case MID_WIDTH: aVal.setWidth( nVal ); break;
156 case MID_HEIGHT: aVal.setHeight( nVal ); break;
157 default: OSL_FAIL("Wrong MemberID!"); return false;
161 return bRet;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */