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