xref: /aoo4110/main/svx/source/items/pageitem.cxx (revision b1cdbd2c)
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 	Beschreibung: Konstruktor
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 	Beschreibung: Copy-Konstruktor
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 	Beschreibung: Clonen
73  --------------------------------------------------------------------*/
74 
Clone(SfxItemPool *) const75 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
76 {
77 	return new SvxPageItem( *this );
78 }
79 
80 /*--------------------------------------------------------------------
81 	Beschreibung: Abfrage auf Gleichheit
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 	if ( eU & SVX_PAGE_LEFT )
96 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
97 	if ( eU & SVX_PAGE_RIGHT )
98 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
99 	if ( eU & SVX_PAGE_ALL )
100 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
101 	if ( eU & SVX_PAGE_MIRROR )
102 		return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
103 	return String();
104 }
105 
106 //------------------------------------------------------------------------
107 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const108 SfxItemPresentation SvxPageItem::GetPresentation
109 (
110 	SfxItemPresentation ePres,
111     SfxMapUnit          /*eCoreUnit*/,
112     SfxMapUnit          /*ePresUnit*/,
113     XubString&          rText, const IntlWrapper *
114 )	const
115 {
116 	rText.Erase();
117 
118 	switch ( ePres )
119 	{
120 		case SFX_ITEM_PRESENTATION_NONE:
121 			return SFX_ITEM_PRESENTATION_NONE;
122 		case SFX_ITEM_PRESENTATION_NAMELESS:
123 		{
124 			if ( aDescName.Len() )
125 			{
126 				rText = aDescName;
127 				rText += cpDelim;
128 			}
129 			DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
130 			rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
131 			rText += cpDelim;
132 			if ( bLandscape )
133 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
134 			else
135 				rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
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 += GetUsageText( eUse );
155 			return SFX_ITEM_PRESENTATION_COMPLETE;
156 		}
157         default: ;//prevent warning
158 	}
159 	return SFX_ITEM_PRESENTATION_NONE;
160 }
161 
162 //------------------------------------------------------------------------
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const163 sal_Bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
164 {
165 //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
166     nMemberId &= ~CONVERT_TWIPS;
167 	switch( nMemberId )
168 	{
169 		case MID_PAGE_NUMTYPE:
170 		{
171 			//!	die Konstanten sind nicht mehr in den IDLs ?!?
172 			rVal <<= (sal_Int16)( eNumType );
173 		}
174 		break;
175 		case MID_PAGE_ORIENTATION:
176 			//Landscape= sal_True
177 			rVal = Bool2Any(bLandscape);
178 		break;
179 		case MID_PAGE_LAYOUT     :
180 		{
181 			style::PageStyleLayout eRet;
182 			switch(eUse & 0x0f)
183 			{
184 				case SVX_PAGE_LEFT	: eRet = style::PageStyleLayout_LEFT;	   break;
185 				case SVX_PAGE_RIGHT	: eRet = style::PageStyleLayout_RIGHT;	   break;
186 				case SVX_PAGE_ALL	: eRet = style::PageStyleLayout_ALL;	   break;
187 				case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
188 				default:
189 					DBG_ERROR("was fuer ein Layout ist das?");
190 					return sal_False;
191 			}
192 			rVal <<= eRet;
193 		}
194 		break;
195 	}
196 
197 	return sal_True;
198 }
199 //------------------------------------------------------------------------
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)200 sal_Bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
201 {
202 	switch( nMemberId )
203 	{
204 		case MID_PAGE_NUMTYPE:
205 		{
206 			sal_Int32 nValue = 0;
207 			if(!(rVal >>= nValue))
208 				return sal_False;
209 
210 			eNumType = (SvxNumType)nValue;
211 		}
212 		break;
213 		case MID_PAGE_ORIENTATION:
214 			bLandscape = Any2Bool(rVal);
215 		break;
216 		case MID_PAGE_LAYOUT     :
217 		{
218 			style::PageStyleLayout eLayout;
219 			if(!(rVal >>= eLayout))
220 			{
221 				sal_Int32 nValue = 0;
222 				if(!(rVal >>= nValue))
223 					return sal_False;
224 				eLayout = (style::PageStyleLayout)nValue;
225 			}
226 			eUse &= 0xfff0;
227 			switch( eLayout )
228 			{
229 				case style::PageStyleLayout_LEFT  	 : eUse |= SVX_PAGE_LEFT ; break;
230 				case style::PageStyleLayout_RIGHT   : eUse |= SVX_PAGE_RIGHT; break;
231 				case style::PageStyleLayout_ALL     : eUse |= SVX_PAGE_ALL  ; break;
232 				case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
233                 default: ;//prevent warning
234             }
235 		}
236 		break;
237 	}
238 	return sal_True;
239 }
240 
241 //------------------------------------------------------------------------
242 
Create(SvStream & rStream,sal_uInt16) const243 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
244 {
245 	XubString sStr;
246 	sal_uInt8 eType;
247 	sal_Bool bLand;
248 	sal_uInt16 nUse;
249 
250 	// UNICODE: rStream >> sStr;
251 	rStream.ReadByteString( sStr );
252 
253 	rStream >> eType;
254 	rStream >> bLand;
255 	rStream >> nUse;
256 
257 	SvxPageItem* pPage = new SvxPageItem( Which() );
258 	pPage->SetDescName( sStr );
259 	pPage->SetNumType( (SvxNumType)eType );
260 	pPage->SetLandscape( bLand );
261 	pPage->SetPageUsage( nUse );
262 	return pPage;
263 }
264 
265 //------------------------------------------------------------------------
266 
Store(SvStream & rStrm,sal_uInt16) const267 SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
268 {
269 	// UNICODE: rStrm << aDescName;
270 	rStrm.WriteByteString(aDescName);
271 
272 	rStrm << (sal_uInt8)eNumType << bLandscape << eUse;
273 	return rStrm;
274 }
275 
276 /*--------------------------------------------------------------------
277 	Beschreibung:	HeaderFooterSet
278  --------------------------------------------------------------------*/
279 
SvxSetItem(const sal_uInt16 nId,const SfxItemSet & rSet)280 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
281 
282 	SfxSetItem( nId, rSet )
283 {
284 }
285 
SvxSetItem(const SvxSetItem & rItem)286 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
287 
288 	SfxSetItem( rItem )
289 {
290 }
291 
SvxSetItem(const sal_uInt16 nId,SfxItemSet * _pSet)292 SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
293 
294     SfxSetItem( nId, _pSet )
295 {
296 }
297 
Clone(SfxItemPool *) const298 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
299 {
300 	return new SvxSetItem(*this);
301 }
302 
303 //------------------------------------------------------------------------
304 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const305 SfxItemPresentation SvxSetItem::GetPresentation
306 (
307     SfxItemPresentation /*ePres*/,
308     SfxMapUnit          /*eCoreUnit*/,
309     SfxMapUnit          /*ePresUnit*/,
310     XubString&          rText, const IntlWrapper *
311 )	const
312 {
313 	rText.Erase();
314 	return SFX_ITEM_PRESENTATION_NONE;
315 }
316 
Create(SvStream & rStrm,sal_uInt16) const317 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
318 {
319     SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
320 									   GetItemSet().GetRanges() );
321 
322     _pSet->Load( rStrm );
323 
324     return new SvxSetItem( Which(), *_pSet );
325 }
326 
Store(SvStream & rStrm,sal_uInt16 nItemVersion) const327 SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
328 {
329 	GetItemSet().Store( rStrm, nItemVersion );
330 
331 	return rStrm;
332 }
333 
334 
335