merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / rectitem.cxx
blob582c4f98611b9b961ac47515ca0dc55d1bb45a9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rectitem.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <svtools/rectitem.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/awt/Rectangle.hpp>
37 #include <tools/stream.hxx>
39 #include <svtools/poolitem.hxx>
40 #include "memberid.hrc"
42 // STATIC DATA -----------------------------------------------------------
44 DBG_NAME(SfxRectangleItem)
47 // -----------------------------------------------------------------------
49 TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem);
51 // -----------------------------------------------------------------------
53 SfxRectangleItem::SfxRectangleItem()
55 DBG_CTOR(SfxRectangleItem, 0);
58 // -----------------------------------------------------------------------
60 SfxRectangleItem::SfxRectangleItem( USHORT nW, const Rectangle& rVal ) :
61 SfxPoolItem( nW ),
62 aVal( rVal )
64 DBG_CTOR(SfxRectangleItem, 0);
67 // -----------------------------------------------------------------------
69 SfxRectangleItem::SfxRectangleItem( USHORT nW, SvStream &rStream ) :
70 SfxPoolItem( nW )
72 DBG_CTOR(SfxRectangleItem, 0);
73 rStream >> aVal;
76 // -----------------------------------------------------------------------
78 SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) :
79 SfxPoolItem( rItem ),
80 aVal( rItem.aVal )
82 DBG_CTOR(SfxRectangleItem, 0);
85 // -----------------------------------------------------------------------
87 SfxItemPresentation SfxRectangleItem::GetPresentation
89 SfxItemPresentation /*ePresentation*/,
90 SfxMapUnit /*eCoreMetric*/,
91 SfxMapUnit /*ePresentationMetric*/,
92 XubString& rText,
93 const IntlWrapper *
94 ) const
96 DBG_CHKTHIS(SfxRectangleItem, 0);
97 rText = UniString::CreateFromInt32(aVal.Top());
98 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
99 rText += UniString::CreateFromInt32(aVal.Left());
100 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
101 rText += UniString::CreateFromInt32(aVal.Bottom());
102 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
103 rText += UniString::CreateFromInt32(aVal.Right());
104 return SFX_ITEM_PRESENTATION_NAMELESS;
107 // -----------------------------------------------------------------------
109 int SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
111 DBG_CHKTHIS(SfxRectangleItem, 0);
112 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
113 return ((SfxRectangleItem&)rItem).aVal == aVal;
116 // -----------------------------------------------------------------------
118 SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const
120 DBG_CHKTHIS(SfxRectangleItem, 0);
121 return new SfxRectangleItem( *this );
124 // -----------------------------------------------------------------------
126 SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, USHORT ) const
128 DBG_CHKTHIS(SfxRectangleItem, 0);
129 Rectangle aStr;
130 rStream >> aStr;
131 return new SfxRectangleItem(Which(), aStr);
134 // -----------------------------------------------------------------------
136 SvStream& SfxRectangleItem::Store(SvStream &rStream, USHORT ) const
138 DBG_CHKTHIS(SfxRectangleItem, 0);
139 rStream << aVal;
140 return rStream;
144 // -----------------------------------------------------------------------
145 BOOL SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal,
146 BYTE nMemberId) const
148 nMemberId &= ~CONVERT_TWIPS;
149 switch ( nMemberId )
151 case 0:
153 rVal <<= com::sun::star::awt::Rectangle( aVal.getX(),
154 aVal.getY(),
155 aVal.getWidth(),
156 aVal.getHeight() );
157 break;
159 case MID_RECT_LEFT: rVal <<= aVal.getX(); break;
160 case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
161 case MID_WIDTH: rVal <<= aVal.getWidth(); break;
162 case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
163 default: DBG_ERROR("Wrong MemberID!"); return FALSE;
166 return TRUE;
169 // -----------------------------------------------------------------------
170 BOOL SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal,
171 BYTE nMemberId )
173 BOOL bRet = FALSE;
174 nMemberId &= ~CONVERT_TWIPS;
175 com::sun::star::awt::Rectangle aValue;
176 sal_Int32 nVal = 0;
177 if ( !nMemberId )
178 bRet = (rVal >>= aValue);
179 else
180 bRet = (rVal >>= nVal);
182 if ( bRet )
184 switch ( nMemberId )
186 case 0:
187 aVal.setX( aValue.X );
188 aVal.setY( aValue.Y );
189 aVal.setWidth( aValue.Width );
190 aVal.setHeight( aValue.Height );
191 break;
192 case MID_RECT_LEFT: aVal.setX( nVal ); break;
193 case MID_RECT_RIGHT: aVal.setY( nVal ); break;
194 case MID_WIDTH: aVal.setWidth( nVal ); break;
195 case MID_HEIGHT: aVal.setHeight( nVal ); break;
196 default: DBG_ERROR("Wrong MemberID!"); return FALSE;
200 return bRet;