lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svl / source / items / rectitem.cxx
blobd481a78df22d37bf41571c29be464254e7b9380c
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.h>
31 SfxPoolItem* SfxRectangleItem::CreateDefault() { return new SfxRectangleItem; }
34 SfxRectangleItem::SfxRectangleItem()
39 SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const tools::Rectangle& rVal ) :
40 SfxPoolItem( nW ),
41 aVal( rVal )
46 bool SfxRectangleItem::GetPresentation
48 SfxItemPresentation /*ePresentation*/,
49 MapUnit /*eCoreMetric*/,
50 MapUnit /*ePresentationMetric*/,
51 OUString& rText,
52 const IntlWrapper&
53 ) const
55 rText = OUString::number(aVal.Top()) + ", " +
56 OUString::number(aVal.Left()) + ", " +
57 OUString::number(aVal.Bottom()) + ", " +
58 OUString::number(aVal.Right());
59 return true;
63 bool SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
65 assert(SfxPoolItem::operator==(rItem));
66 return static_cast<const SfxRectangleItem&>(rItem).aVal == aVal;
70 SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const
72 return new SfxRectangleItem( *this );
76 SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, sal_uInt16 ) const
78 tools::Rectangle aStr;
79 ReadRectangle( rStream, aStr );
80 return new SfxRectangleItem(Which(), aStr);
84 SvStream& SfxRectangleItem::Store(SvStream &rStream, sal_uInt16 ) const
86 WriteRectangle( rStream, aVal );
87 return rStream;
91 bool SfxRectangleItem::QueryValue( css::uno::Any& rVal,
92 sal_uInt8 nMemberId) const
94 nMemberId &= ~CONVERT_TWIPS;
95 switch ( nMemberId )
97 case 0:
99 rVal <<= css::awt::Rectangle( aVal.getX(),
100 aVal.getY(),
101 aVal.getWidth(),
102 aVal.getHeight() );
103 break;
105 case MID_RECT_LEFT: rVal <<= aVal.getX(); break;
106 case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
107 case MID_WIDTH: rVal <<= aVal.getWidth(); break;
108 case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
109 default: OSL_FAIL("Wrong MemberID!"); return false;
112 return true;
116 bool SfxRectangleItem::PutValue( const css::uno::Any& rVal,
117 sal_uInt8 nMemberId )
119 bool bRet = false;
120 nMemberId &= ~CONVERT_TWIPS;
121 css::awt::Rectangle aValue;
122 sal_Int32 nVal = 0;
123 if ( !nMemberId )
124 bRet = (rVal >>= aValue);
125 else
126 bRet = (rVal >>= nVal);
128 if ( bRet )
130 switch ( nMemberId )
132 case 0:
133 aVal.setX( aValue.X );
134 aVal.setY( aValue.Y );
135 aVal.setWidth( aValue.Width );
136 aVal.setHeight( aValue.Height );
137 break;
138 case MID_RECT_LEFT: aVal.setX( nVal ); break;
139 case MID_RECT_RIGHT: aVal.setY( nVal ); break;
140 case MID_WIDTH: aVal.setWidth( nVal ); break;
141 case MID_HEIGHT: aVal.setHeight( nVal ); break;
142 default: OSL_FAIL("Wrong MemberID!"); return false;
146 return bRet;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */