xref: /AOO41X/main/svl/source/items/rectitem.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include <svl/rectitem.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/awt/Rectangle.hpp>
34 #include <tools/stream.hxx>
35 
36 #include <svl/poolitem.hxx>
37 #include <svl/memberid.hrc>
38 
39 // STATIC DATA -----------------------------------------------------------
40 
41 DBG_NAME(SfxRectangleItem)
42 
43 
44 // -----------------------------------------------------------------------
45 
46 TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem);
47 
48 // -----------------------------------------------------------------------
49 
50 SfxRectangleItem::SfxRectangleItem()
51 {
52 	DBG_CTOR(SfxRectangleItem, 0);
53 }
54 
55 // -----------------------------------------------------------------------
56 
57 SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const Rectangle& rVal ) :
58 	SfxPoolItem( nW ),
59 	aVal( rVal )
60 {
61 	DBG_CTOR(SfxRectangleItem, 0);
62 }
63 
64 // -----------------------------------------------------------------------
65 
66 SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, SvStream &rStream ) :
67 	SfxPoolItem( nW )
68 {
69 	DBG_CTOR(SfxRectangleItem, 0);
70 	rStream >> aVal;
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) :
76 	SfxPoolItem( rItem ),
77 	aVal( rItem.aVal )
78 {
79 	DBG_CTOR(SfxRectangleItem, 0);
80 }
81 
82 // -----------------------------------------------------------------------
83 
84 SfxItemPresentation SfxRectangleItem::GetPresentation
85 (
86 	SfxItemPresentation 	/*ePresentation*/,
87 	SfxMapUnit				/*eCoreMetric*/,
88 	SfxMapUnit				/*ePresentationMetric*/,
89 	XubString& 				rText,
90     const IntlWrapper *
91 )	const
92 {
93 	DBG_CHKTHIS(SfxRectangleItem, 0);
94 	rText = UniString::CreateFromInt32(aVal.Top());
95 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
96 	rText += UniString::CreateFromInt32(aVal.Left());
97 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
98 	rText += UniString::CreateFromInt32(aVal.Bottom());
99 	rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
100 	rText += UniString::CreateFromInt32(aVal.Right());
101 	return SFX_ITEM_PRESENTATION_NAMELESS;
102 }
103 
104 // -----------------------------------------------------------------------
105 
106 int SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
107 {
108 	DBG_CHKTHIS(SfxRectangleItem, 0);
109 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
110 	return ((SfxRectangleItem&)rItem).aVal == aVal;
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const
116 {
117 	DBG_CHKTHIS(SfxRectangleItem, 0);
118 	return new SfxRectangleItem( *this );
119 }
120 
121 // -----------------------------------------------------------------------
122 
123 SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, sal_uInt16 ) const
124 {
125 	DBG_CHKTHIS(SfxRectangleItem, 0);
126 	Rectangle aStr;
127 	rStream >> aStr;
128 	return new SfxRectangleItem(Which(), aStr);
129 }
130 
131 // -----------------------------------------------------------------------
132 
133 SvStream& SfxRectangleItem::Store(SvStream &rStream, sal_uInt16 ) const
134 {
135 	DBG_CHKTHIS(SfxRectangleItem, 0);
136 	rStream << aVal;
137 	return rStream;
138 }
139 
140 
141 // -----------------------------------------------------------------------
142 sal_Bool SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal,
143 								   sal_uInt8 nMemberId) const
144 {
145 	nMemberId &= ~CONVERT_TWIPS;
146     switch ( nMemberId )
147     {
148         case 0:
149         {
150             rVal <<= com::sun::star::awt::Rectangle( aVal.getX(),
151 											 aVal.getY(),
152 											 aVal.getWidth(),
153 											 aVal.getHeight() );
154             break;
155         }
156         case MID_RECT_LEFT:  rVal <<= aVal.getX(); break;
157         case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
158         case MID_WIDTH: rVal <<= aVal.getWidth(); break;
159         case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
160         default: DBG_ERROR("Wrong MemberID!"); return sal_False;
161     }
162 
163 	return sal_True;
164 }
165 
166 // -----------------------------------------------------------------------
167 sal_Bool SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal,
168 								 sal_uInt8 nMemberId  )
169 {
170 	sal_Bool bRet = sal_False;
171 	nMemberId &= ~CONVERT_TWIPS;
172     com::sun::star::awt::Rectangle aValue;
173     sal_Int32 nVal = 0;
174     if ( !nMemberId )
175         bRet = (rVal >>= aValue);
176     else
177         bRet = (rVal >>= nVal);
178 
179     if ( bRet )
180     {
181         switch ( nMemberId )
182         {
183             case 0:
184                 aVal.setX( aValue.X );
185                 aVal.setY( aValue.Y );
186                 aVal.setWidth( aValue.Width );
187                 aVal.setHeight( aValue.Height );
188                 break;
189             case MID_RECT_LEFT:  aVal.setX( nVal ); break;
190             case MID_RECT_RIGHT: aVal.setY( nVal ); break;
191             case MID_WIDTH: aVal.setWidth( nVal ); break;
192             case MID_HEIGHT: aVal.setHeight( nVal ); break;
193             default: DBG_ERROR("Wrong MemberID!"); return sal_False;
194         }
195     }
196 
197 	return bRet;
198 }
199 
200 
201 
202