1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) :
48 SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem
& rItem
) :
56 bool SfxRectangleItem::GetPresentation
58 SfxItemPresentation
/*ePresentation*/,
59 SfxMapUnit
/*eCoreMetric*/,
60 SfxMapUnit
/*ePresentationMetric*/,
65 rText
= OUString::number(aVal
.Top()) + ", " +
66 OUString::number(aVal
.Left()) + ", " +
67 OUString::number(aVal
.Bottom()) + ", " +
68 OUString::number(aVal
.Right());
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
92 ReadRectangle( rStream
, aStr
);
93 return new SfxRectangleItem(Which(), aStr
);
98 SvStream
& SfxRectangleItem::Store(SvStream
&rStream
, sal_uInt16
) const
100 WriteRectangle( rStream
, aVal
);
106 bool SfxRectangleItem::QueryValue( com::sun::star::uno::Any
& rVal
,
107 sal_uInt8 nMemberId
) const
109 nMemberId
&= ~CONVERT_TWIPS
;
114 rVal
<<= com::sun::star::awt::Rectangle( aVal
.getX(),
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;
131 bool SfxRectangleItem::PutValue( const com::sun::star::uno::Any
& rVal
,
132 sal_uInt8 nMemberId
)
135 nMemberId
&= ~CONVERT_TWIPS
;
136 com::sun::star::awt::Rectangle aValue
;
139 bRet
= (rVal
>>= aValue
);
141 bRet
= (rVal
>>= nVal
);
148 aVal
.setX( aValue
.X
);
149 aVal
.setY( aValue
.Y
);
150 aVal
.setWidth( aValue
.Width
);
151 aVal
.setHeight( aValue
.Height
);
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;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */