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