xref: /AOO41X/main/svx/source/items/pageitem.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/stream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/pageitem.hxx>
32cdf0e10cSrcweir #include <editeng/itemtype.hxx>
33cdf0e10cSrcweir #include <svx/unomid.hxx>
34cdf0e10cSrcweir #include <com/sun/star/style/PageStyleLayout.hpp>
35cdf0e10cSrcweir #include <com/sun/star/style/BreakType.hpp>
36cdf0e10cSrcweir #include <svl/itemset.hxx>
37cdf0e10cSrcweir #include <svx/svxitems.hrc>
38cdf0e10cSrcweir #include <svx/dialmgr.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::rtl;
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new  SvxPageItem(0));
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /*--------------------------------------------------------------------
48cdf0e10cSrcweir 	Beschreibung: Konstruktor
49cdf0e10cSrcweir  --------------------------------------------------------------------*/
50cdf0e10cSrcweir 
51cdf0e10cSrcweir SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ),
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	eNumType	( SVX_ARABIC ),
54cdf0e10cSrcweir 	bLandscape	( sal_False ),
55cdf0e10cSrcweir 	eUse		( SVX_PAGE_ALL )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /*--------------------------------------------------------------------
60cdf0e10cSrcweir 	Beschreibung: Copy-Konstruktor
61cdf0e10cSrcweir  --------------------------------------------------------------------*/
62cdf0e10cSrcweir 
63cdf0e10cSrcweir SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
64cdf0e10cSrcweir 	: SfxPoolItem( rItem )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	eNumType 	= rItem.eNumType;
67cdf0e10cSrcweir 	bLandscape 	= rItem.bLandscape;
68cdf0e10cSrcweir 	eUse 		= rItem.eUse;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /*--------------------------------------------------------------------
72cdf0e10cSrcweir 	Beschreibung: Clonen
73cdf0e10cSrcweir  --------------------------------------------------------------------*/
74cdf0e10cSrcweir 
75cdf0e10cSrcweir SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	return new SvxPageItem( *this );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir /*--------------------------------------------------------------------
81cdf0e10cSrcweir 	Beschreibung: Abfrage auf Gleichheit
82cdf0e10cSrcweir  --------------------------------------------------------------------*/
83cdf0e10cSrcweir 
84cdf0e10cSrcweir int SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
87cdf0e10cSrcweir 	const SvxPageItem& rItem = (SvxPageItem&)rAttr;
88cdf0e10cSrcweir 	return ( eNumType 	== rItem.eNumType 	&&
89cdf0e10cSrcweir 			 bLandscape == rItem.bLandscape &&
90cdf0e10cSrcweir 			 eUse 		== rItem.eUse );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir inline XubString GetUsageText( const sal_uInt16 eU )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	if ( eU & SVX_PAGE_LEFT )
96cdf0e10cSrcweir 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
97cdf0e10cSrcweir 	if ( eU & SVX_PAGE_RIGHT )
98cdf0e10cSrcweir 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
99cdf0e10cSrcweir 	if ( eU & SVX_PAGE_ALL )
100cdf0e10cSrcweir 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
101cdf0e10cSrcweir 	if ( eU & SVX_PAGE_MIRROR )
102cdf0e10cSrcweir 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
103cdf0e10cSrcweir 	return String();
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //------------------------------------------------------------------------
107cdf0e10cSrcweir 
108cdf0e10cSrcweir SfxItemPresentation SvxPageItem::GetPresentation
109cdf0e10cSrcweir (
110cdf0e10cSrcweir 	SfxItemPresentation ePres,
111cdf0e10cSrcweir     SfxMapUnit          /*eCoreUnit*/,
112cdf0e10cSrcweir     SfxMapUnit          /*ePresUnit*/,
113cdf0e10cSrcweir     XubString&          rText, const IntlWrapper *
114cdf0e10cSrcweir )	const
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	rText.Erase();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	switch ( ePres )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		case SFX_ITEM_PRESENTATION_NONE:
121cdf0e10cSrcweir 			return SFX_ITEM_PRESENTATION_NONE;
122cdf0e10cSrcweir 		case SFX_ITEM_PRESENTATION_NAMELESS:
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			if ( aDescName.Len() )
125cdf0e10cSrcweir 			{
126cdf0e10cSrcweir 				rText = aDescName;
127cdf0e10cSrcweir 				rText += cpDelim;
128cdf0e10cSrcweir 			}
129cdf0e10cSrcweir 			DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
130cdf0e10cSrcweir 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
131cdf0e10cSrcweir 			rText += cpDelim;
132cdf0e10cSrcweir 			if ( bLandscape )
133cdf0e10cSrcweir 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
134cdf0e10cSrcweir 			else
135cdf0e10cSrcweir 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
136cdf0e10cSrcweir 			rText += GetUsageText( eUse );
137cdf0e10cSrcweir 			return SFX_ITEM_PRESENTATION_NAMELESS;
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 		case SFX_ITEM_PRESENTATION_COMPLETE:
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
142cdf0e10cSrcweir 			if ( aDescName.Len() )
143cdf0e10cSrcweir 			{
144cdf0e10cSrcweir 				rText += aDescName;
145cdf0e10cSrcweir 				rText += cpDelim;
146cdf0e10cSrcweir 			}
147cdf0e10cSrcweir 			DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
148cdf0e10cSrcweir 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
149cdf0e10cSrcweir 			rText += cpDelim;
150cdf0e10cSrcweir 			if ( bLandscape )
151cdf0e10cSrcweir 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
152cdf0e10cSrcweir 			else
153cdf0e10cSrcweir 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
154cdf0e10cSrcweir 			rText += GetUsageText( eUse );
155cdf0e10cSrcweir 			return SFX_ITEM_PRESENTATION_COMPLETE;
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir         default: ;//prevent warning
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NONE;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //------------------------------------------------------------------------
163cdf0e10cSrcweir sal_Bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
166cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
167cdf0e10cSrcweir 	switch( nMemberId )
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		case MID_PAGE_NUMTYPE:
170cdf0e10cSrcweir 		{
171cdf0e10cSrcweir 			//!	die Konstanten sind nicht mehr in den IDLs ?!?
172cdf0e10cSrcweir 			rVal <<= (sal_Int16)( eNumType );
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 		break;
175cdf0e10cSrcweir 		case MID_PAGE_ORIENTATION:
176cdf0e10cSrcweir 			//Landscape= sal_True
177cdf0e10cSrcweir 			rVal = Bool2Any(bLandscape);
178cdf0e10cSrcweir 		break;
179cdf0e10cSrcweir 		case MID_PAGE_LAYOUT     :
180cdf0e10cSrcweir 		{
181cdf0e10cSrcweir 			style::PageStyleLayout eRet;
182cdf0e10cSrcweir 			switch(eUse & 0x0f)
183cdf0e10cSrcweir 			{
184cdf0e10cSrcweir 				case SVX_PAGE_LEFT	: eRet = style::PageStyleLayout_LEFT;	   break;
185cdf0e10cSrcweir 				case SVX_PAGE_RIGHT	: eRet = style::PageStyleLayout_RIGHT;	   break;
186cdf0e10cSrcweir 				case SVX_PAGE_ALL	: eRet = style::PageStyleLayout_ALL;	   break;
187cdf0e10cSrcweir 				case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
188cdf0e10cSrcweir 				default:
189cdf0e10cSrcweir 					DBG_ERROR("was fuer ein Layout ist das?");
190cdf0e10cSrcweir 					return sal_False;
191cdf0e10cSrcweir 			}
192cdf0e10cSrcweir 			rVal <<= eRet;
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 		break;
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	return sal_True;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir //------------------------------------------------------------------------
200cdf0e10cSrcweir sal_Bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	switch( nMemberId )
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		case MID_PAGE_NUMTYPE:
205cdf0e10cSrcweir 		{
206cdf0e10cSrcweir 			sal_Int32 nValue = 0;
207cdf0e10cSrcweir 			if(!(rVal >>= nValue))
208cdf0e10cSrcweir 				return sal_False;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 			eNumType = (SvxNumType)nValue;
211cdf0e10cSrcweir 		}
212cdf0e10cSrcweir 		break;
213cdf0e10cSrcweir 		case MID_PAGE_ORIENTATION:
214cdf0e10cSrcweir 			bLandscape = Any2Bool(rVal);
215cdf0e10cSrcweir 		break;
216cdf0e10cSrcweir 		case MID_PAGE_LAYOUT     :
217cdf0e10cSrcweir 		{
218cdf0e10cSrcweir 			style::PageStyleLayout eLayout;
219cdf0e10cSrcweir 			if(!(rVal >>= eLayout))
220cdf0e10cSrcweir 			{
221cdf0e10cSrcweir 				sal_Int32 nValue = 0;
222cdf0e10cSrcweir 				if(!(rVal >>= nValue))
223cdf0e10cSrcweir 					return sal_False;
224cdf0e10cSrcweir 				eLayout = (style::PageStyleLayout)nValue;
225cdf0e10cSrcweir 			}
226cdf0e10cSrcweir 			eUse &= 0xfff0;
227cdf0e10cSrcweir 			switch( eLayout )
228cdf0e10cSrcweir 			{
229cdf0e10cSrcweir 				case style::PageStyleLayout_LEFT  	 : eUse |= SVX_PAGE_LEFT ; break;
230cdf0e10cSrcweir 				case style::PageStyleLayout_RIGHT   : eUse |= SVX_PAGE_RIGHT; break;
231cdf0e10cSrcweir 				case style::PageStyleLayout_ALL     : eUse |= SVX_PAGE_ALL  ; break;
232cdf0e10cSrcweir 				case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
233cdf0e10cSrcweir                 default: ;//prevent warning
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir 		}
236cdf0e10cSrcweir 		break;
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 	return sal_True;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir //------------------------------------------------------------------------
242cdf0e10cSrcweir 
243cdf0e10cSrcweir SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	XubString sStr;
246cdf0e10cSrcweir 	sal_uInt8 eType;
247cdf0e10cSrcweir 	sal_Bool bLand;
248cdf0e10cSrcweir 	sal_uInt16 nUse;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	// UNICODE: rStream >> sStr;
251cdf0e10cSrcweir 	rStream.ReadByteString( sStr );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	rStream >> eType;
254cdf0e10cSrcweir 	rStream >> bLand;
255cdf0e10cSrcweir 	rStream >> nUse;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	SvxPageItem* pPage = new SvxPageItem( Which() );
258cdf0e10cSrcweir 	pPage->SetDescName( sStr );
259cdf0e10cSrcweir 	pPage->SetNumType( (SvxNumType)eType );
260cdf0e10cSrcweir 	pPage->SetLandscape( bLand );
261cdf0e10cSrcweir 	pPage->SetPageUsage( nUse );
262cdf0e10cSrcweir 	return pPage;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir //------------------------------------------------------------------------
266cdf0e10cSrcweir 
267cdf0e10cSrcweir SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	// UNICODE: rStrm << aDescName;
270cdf0e10cSrcweir 	rStrm.WriteByteString(aDescName);
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	rStrm << (sal_uInt8)eNumType << bLandscape << eUse;
273cdf0e10cSrcweir 	return rStrm;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir /*--------------------------------------------------------------------
277cdf0e10cSrcweir 	Beschreibung:	HeaderFooterSet
278cdf0e10cSrcweir  --------------------------------------------------------------------*/
279cdf0e10cSrcweir 
280cdf0e10cSrcweir SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 	SfxSetItem( nId, rSet )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	SfxSetItem( rItem )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     SfxSetItem( nId, _pSet )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
299cdf0e10cSrcweir {
300cdf0e10cSrcweir 	return new SvxSetItem(*this);
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir //------------------------------------------------------------------------
304cdf0e10cSrcweir 
305cdf0e10cSrcweir SfxItemPresentation SvxSetItem::GetPresentation
306cdf0e10cSrcweir (
307cdf0e10cSrcweir     SfxItemPresentation /*ePres*/,
308cdf0e10cSrcweir     SfxMapUnit          /*eCoreUnit*/,
309cdf0e10cSrcweir     SfxMapUnit          /*ePresUnit*/,
310cdf0e10cSrcweir     XubString&          rText, const IntlWrapper *
311cdf0e10cSrcweir )	const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	rText.Erase();
314cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NONE;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
320cdf0e10cSrcweir 									   GetItemSet().GetRanges() );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     _pSet->Load( rStrm );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     return new SvxSetItem( Which(), *_pSet );
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
328cdf0e10cSrcweir {
329cdf0e10cSrcweir 	GetItemSet().Store( rStrm, nItemVersion );
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	return rStrm;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
335