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