xref: /trunk/main/svx/source/items/pageitem.cxx (revision 9a2b2495)
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_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/stream.hxx>
29 
30 
31 #include <svx/pageitem.hxx>
32 #include <editeng/itemtype.hxx>
33 #include <svx/unomid.hxx>
34 #include <com/sun/star/style/PageStyleLayout.hpp>
35 #include <com/sun/star/style/BreakType.hpp>
36 #include <svl/itemset.hxx>
37 #include <svx/svxitems.hrc>
38 #include <svx/dialmgr.hxx>
39 
40 using namespace ::rtl;
41 using namespace ::com::sun::star;
42 
43 // STATIC DATA -----------------------------------------------------------
44 
45 TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new SvxPageItem(0));
46 
47 /*--------------------------------------------------------------------
48 	Description: Constructor
49  --------------------------------------------------------------------*/
50 
SvxPageItem(const sal_uInt16 nId)51 SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ),
52 
53 	eNumType	( SVX_ARABIC ),
54 	bLandscape	( sal_False ),
55 	eUse		( SVX_PAGE_ALL )
56 {
57 }
58 
59 /*--------------------------------------------------------------------
60 	Description: Copy-Constructor
61  --------------------------------------------------------------------*/
62 
SvxPageItem(const SvxPageItem & rItem)63 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
64 	: SfxPoolItem( rItem )
65 {
66 	eNumType 	= rItem.eNumType;
67 	bLandscape 	= rItem.bLandscape;
68 	eUse 		= rItem.eUse;
69 }
70 
71 /*--------------------------------------------------------------------
72 	Description: Clone
73  --------------------------------------------------------------------*/
74 
Clone(SfxItemPool *) const75 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
76 {
77 	return new SvxPageItem( *this );
78 }
79 
80 /*--------------------------------------------------------------------
81 	Description: Query on equality
82  --------------------------------------------------------------------*/
83 
operator ==(const SfxPoolItem & rAttr) const84 int SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
85 {
86 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
87 	const SvxPageItem& rItem = (SvxPageItem&)rAttr;
88 	return ( eNumType 	== rItem.eNumType 	&&
89 			 bLandscape == rItem.bLandscape &&
90 			 eUse 		== rItem.eUse );
91 }
92 
GetUsageText(const sal_uInt16 eU)93 inline XubString GetUsageText( const sal_uInt16 eU )
94 {
95 	switch( eU & 0x000f )
96 	{
97 		case SVX_PAGE_LEFT:		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
98 		case SVX_PAGE_RIGHT:	return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
99 		case SVX_PAGE_ALL:		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
100 		case SVX_PAGE_MIRROR:	return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
101 		default: return String();
102 	}
103 }
104 
105 //------------------------------------------------------------------------
106 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const107 SfxItemPresentation SvxPageItem::GetPresentation
108 (
109 	SfxItemPresentation	ePres,
110 	SfxMapUnit			/*eCoreUnit*/,
111 	SfxMapUnit			/*ePresUnit*/,
112 	XubString&			rText, const IntlWrapper *
113 )	const
114 {
115 	rText.Erase();
116 
117 	switch( ePres )
118 	{
119 		case SFX_ITEM_PRESENTATION_NONE:
120 			return SFX_ITEM_PRESENTATION_NONE;
121 		case SFX_ITEM_PRESENTATION_NAMELESS:
122 		{
123 			if ( aDescName.Len() )
124 			{
125 				rText = aDescName;
126 				rText += cpDelim;
127 			}
128 			DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
129 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
130 			rText += cpDelim;
131 			if ( bLandscape )
132 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
133 			else
134 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
135 			rText += cpDelim;
136 			rText += GetUsageText( eUse );
137 			return SFX_ITEM_PRESENTATION_NAMELESS;
138 		}
139 		case SFX_ITEM_PRESENTATION_COMPLETE:
140 		{
141 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
142 			if ( aDescName.Len() )
143 			{
144 				rText += aDescName;
145 				rText += cpDelim;
146 			}
147 			DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
148 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
149 			rText += cpDelim;
150 			if ( bLandscape )
151 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
152 			else
153 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
154 			rText += cpDelim;
155 			rText += GetUsageText( eUse );
156 			return SFX_ITEM_PRESENTATION_COMPLETE;
157 		}
158 		default: ; // prevent warning
159 	}
160 	return SFX_ITEM_PRESENTATION_NONE;
161 }
162 
163 //------------------------------------------------------------------------
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const164 sal_Bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
165 {
166 //	sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
167 	nMemberId &= ~CONVERT_TWIPS;
168 	switch( nMemberId )
169 	{
170 		case MID_PAGE_NUMTYPE:
171 		{
172 			//!	die Konstanten sind nicht mehr in den IDLs ?!?
173 			rVal <<= (sal_Int16)( eNumType );
174 		}
175 		break;
176 		case MID_PAGE_ORIENTATION:
177 			//Landscape= sal_True
178 			rVal = Bool2Any(bLandscape);
179 		break;
180 		case MID_PAGE_LAYOUT :
181 		{
182 			style::PageStyleLayout eRet;
183 			switch( eUse & 0x0f )
184 			{
185 				case SVX_PAGE_LEFT:		eRet = style::PageStyleLayout_LEFT;		break;
186 				case SVX_PAGE_RIGHT:	eRet = style::PageStyleLayout_RIGHT;	break;
187 				case SVX_PAGE_ALL:		eRet = style::PageStyleLayout_ALL;		break;
188 				case SVX_PAGE_MIRROR:	eRet = style::PageStyleLayout_MIRRORED;	break;
189 				default:
190 					DBG_ERROR("What kind of layout is this?");
191 					return sal_False;
192 			}
193 			rVal <<= eRet;
194 		}
195 		break;
196 	}
197 
198 	return sal_True;
199 }
200 //------------------------------------------------------------------------
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)201 sal_Bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
202 {
203 	switch( nMemberId )
204 	{
205 		case MID_PAGE_NUMTYPE:
206 		{
207 			sal_Int32 nValue = 0;
208 			if(!(rVal >>= nValue))
209 				return sal_False;
210 
211 			eNumType = (SvxNumType)nValue;
212 		}
213 		break;
214 		case MID_PAGE_ORIENTATION:
215 			bLandscape = Any2Bool(rVal);
216 		break;
217 		case MID_PAGE_LAYOUT :
218 		{
219 			style::PageStyleLayout eLayout;
220 			if(!(rVal >>= eLayout))
221 			{
222 				sal_Int32 nValue = 0;
223 				if(!(rVal >>= nValue))
224 					return sal_False;
225 				eLayout = (style::PageStyleLayout)nValue;
226 			}
227 			eUse &= 0xfff0;
228 			switch( eLayout )
229 			{
230 				case style::PageStyleLayout_LEFT:		eUse |= SVX_PAGE_LEFT ;		break;
231 				case style::PageStyleLayout_RIGHT:		eUse |= SVX_PAGE_RIGHT ;	break;
232 				case style::PageStyleLayout_ALL:		eUse |= SVX_PAGE_ALL ;		break;
233 				case style::PageStyleLayout_MIRRORED:	eUse |= SVX_PAGE_MIRROR ;	break;
234 				default: ; // prevent warning
235 			}
236 		}
237 		break;
238 	}
239 	return sal_True;
240 }
241 
242 //------------------------------------------------------------------------
243 
Create(SvStream & rStream,sal_uInt16) const244 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
245 {
246 	XubString sStr;
247 	sal_uInt8 eType;
248 	sal_Bool bLand;
249 	sal_uInt16 nUse;
250 
251 	// UNICODE: rStream >> sStr;
252 	rStream.ReadByteString( sStr );
253 
254 	rStream >> eType;
255 	rStream >> bLand;
256 	rStream >> nUse;
257 
258 	SvxPageItem* pPage = new SvxPageItem( Which() );
259 	pPage->SetDescName( sStr );
260 	pPage->SetNumType( (SvxNumType)eType );
261 	pPage->SetLandscape( bLand );
262 	pPage->SetPageUsage( nUse );
263 	return pPage;
264 }
265 
266 //------------------------------------------------------------------------
267 
Store(SvStream & rStrm,sal_uInt16) const268 SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
269 {
270 	// UNICODE: rStrm << aDescName;
271 	rStrm.WriteByteString(aDescName);
272 
273 	rStrm << (sal_uInt8)eNumType << bLandscape << eUse;
274 	return rStrm;
275 }
276 
277 /*--------------------------------------------------------------------
278 	Description: HeaderFooterSet
279  --------------------------------------------------------------------*/
280 
SvxSetItem(const sal_uInt16 nId,const SfxItemSet & rSet)281 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
282 
283 	SfxSetItem( nId, rSet )
284 {
285 }
286 
SvxSetItem(const SvxSetItem & rItem)287 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
288 
289 	SfxSetItem( rItem )
290 {
291 }
292 
SvxSetItem(const sal_uInt16 nId,SfxItemSet * _pSet)293 SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
294 
295 	SfxSetItem( nId, _pSet )
296 {
297 }
298 
Clone(SfxItemPool *) const299 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
300 {
301 	return new SvxSetItem(*this);
302 }
303 
304 //------------------------------------------------------------------------
305 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const306 SfxItemPresentation SvxSetItem::GetPresentation
307 (
308 	SfxItemPresentation	/*ePres*/,
309 	SfxMapUnit			/*eCoreUnit*/,
310 	SfxMapUnit			/*ePresUnit*/,
311 	XubString&			rText, const IntlWrapper *
312 )	const
313 {
314 	rText.Erase();
315 	return SFX_ITEM_PRESENTATION_NONE;
316 }
317 
Create(SvStream & rStrm,sal_uInt16) const318 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
319 {
320 	SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
321 										 GetItemSet().GetRanges() );
322 
323 	_pSet->Load( rStrm );
324 
325 	return new SvxSetItem( Which(), *_pSet );
326 }
327 
Store(SvStream & rStrm,sal_uInt16 nItemVersion) const328 SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
329 {
330 	GetItemSet().Store( rStrm, nItemVersion );
331 
332 	return rStrm;
333 }
334 
335 /* vim: set noet sw=4 ts=4: */
336