update dev300-m58
[ooovba.git] / svx / source / items / pageitem.cxx
blobe01db0cffb72348b5d1e3680b970c904cf67c4db
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pageitem.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/stream.hxx>
38 #include <svx/pageitem.hxx>
39 #include <svx/itemtype.hxx>
40 #include <svx/unomid.hxx>
41 #include <com/sun/star/style/PageStyleLayout.hpp>
42 #include <com/sun/star/style/BreakType.hpp>
43 #include <svtools/itemset.hxx>
45 using namespace ::rtl;
46 using namespace ::com::sun::star;
48 // STATIC DATA -----------------------------------------------------------
50 TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new SvxPageItem(0));
52 /*--------------------------------------------------------------------
53 Beschreibung: Konstruktor
54 --------------------------------------------------------------------*/
56 SvxPageItem::SvxPageItem( const USHORT nId ) : SfxPoolItem( nId ),
58 eNumType ( SVX_ARABIC ),
59 bLandscape ( sal_False ),
60 eUse ( SVX_PAGE_ALL )
64 /*--------------------------------------------------------------------
65 Beschreibung: Copy-Konstruktor
66 --------------------------------------------------------------------*/
68 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
69 : SfxPoolItem( rItem )
71 eNumType = rItem.eNumType;
72 bLandscape = rItem.bLandscape;
73 eUse = rItem.eUse;
76 /*--------------------------------------------------------------------
77 Beschreibung: Clonen
78 --------------------------------------------------------------------*/
80 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
82 return new SvxPageItem( *this );
85 /*--------------------------------------------------------------------
86 Beschreibung: Abfrage auf Gleichheit
87 --------------------------------------------------------------------*/
89 int SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
91 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
92 const SvxPageItem& rItem = (SvxPageItem&)rAttr;
93 return ( eNumType == rItem.eNumType &&
94 bLandscape == rItem.bLandscape &&
95 eUse == rItem.eUse );
98 inline XubString GetUsageText( const USHORT eU )
100 if ( eU & SVX_PAGE_LEFT )
101 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
102 if ( eU & SVX_PAGE_RIGHT )
103 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
104 if ( eU & SVX_PAGE_ALL )
105 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
106 if ( eU & SVX_PAGE_MIRROR )
107 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
108 return String();
111 //------------------------------------------------------------------------
113 SfxItemPresentation SvxPageItem::GetPresentation
115 SfxItemPresentation ePres,
116 SfxMapUnit /*eCoreUnit*/,
117 SfxMapUnit /*ePresUnit*/,
118 XubString& rText, const IntlWrapper *
119 ) const
121 rText.Erase();
123 switch ( ePres )
125 case SFX_ITEM_PRESENTATION_NONE:
126 return SFX_ITEM_PRESENTATION_NONE;
127 case SFX_ITEM_PRESENTATION_NAMELESS:
129 if ( aDescName.Len() )
131 rText = aDescName;
132 rText += cpDelim;
134 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
135 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
136 rText += cpDelim;
137 if ( bLandscape )
138 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
139 else
140 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
141 rText += GetUsageText( eUse );
142 return SFX_ITEM_PRESENTATION_NAMELESS;
144 case SFX_ITEM_PRESENTATION_COMPLETE:
146 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
147 if ( aDescName.Len() )
149 rText += aDescName;
150 rText += cpDelim;
152 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
153 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
154 rText += cpDelim;
155 if ( bLandscape )
156 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
157 else
158 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
159 rText += GetUsageText( eUse );
160 return SFX_ITEM_PRESENTATION_COMPLETE;
162 default: ;//prevent warning
164 return SFX_ITEM_PRESENTATION_NONE;
167 //------------------------------------------------------------------------
168 sal_Bool SvxPageItem::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
170 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
171 nMemberId &= ~CONVERT_TWIPS;
172 switch( nMemberId )
174 case MID_PAGE_NUMTYPE:
176 //! die Konstanten sind nicht mehr in den IDLs ?!?
177 rVal <<= (sal_Int16)( eNumType );
179 break;
180 case MID_PAGE_ORIENTATION:
181 //Landscape= sal_True
182 rVal = Bool2Any(bLandscape);
183 break;
184 case MID_PAGE_LAYOUT :
186 style::PageStyleLayout eRet;
187 switch(eUse & 0x0f)
189 case SVX_PAGE_LEFT : eRet = style::PageStyleLayout_LEFT; break;
190 case SVX_PAGE_RIGHT : eRet = style::PageStyleLayout_RIGHT; break;
191 case SVX_PAGE_ALL : eRet = style::PageStyleLayout_ALL; break;
192 case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
193 default:
194 DBG_ERROR("was fuer ein Layout ist das?");
195 return sal_False;
197 rVal <<= eRet;
199 break;
202 return sal_True;
204 //------------------------------------------------------------------------
205 sal_Bool SvxPageItem::PutValue( const uno::Any& rVal, BYTE nMemberId )
207 switch( nMemberId )
209 case MID_PAGE_NUMTYPE:
211 sal_Int32 nValue = 0;
212 if(!(rVal >>= nValue))
213 return sal_False;
215 eNumType = (SvxNumType)nValue;
217 break;
218 case MID_PAGE_ORIENTATION:
219 bLandscape = Any2Bool(rVal);
220 break;
221 case MID_PAGE_LAYOUT :
223 style::PageStyleLayout eLayout;
224 if(!(rVal >>= eLayout))
226 sal_Int32 nValue = 0;
227 if(!(rVal >>= nValue))
228 return sal_False;
229 eLayout = (style::PageStyleLayout)nValue;
231 eUse &= 0xfff0;
232 switch( eLayout )
234 case style::PageStyleLayout_LEFT : eUse |= SVX_PAGE_LEFT ; break;
235 case style::PageStyleLayout_RIGHT : eUse |= SVX_PAGE_RIGHT; break;
236 case style::PageStyleLayout_ALL : eUse |= SVX_PAGE_ALL ; break;
237 case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
238 default: ;//prevent warning
241 break;
243 return sal_True;
246 //------------------------------------------------------------------------
248 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, USHORT ) const
250 XubString sStr;
251 BYTE eType;
252 sal_Bool bLand;
253 USHORT nUse;
255 // UNICODE: rStream >> sStr;
256 rStream.ReadByteString( sStr );
258 rStream >> eType;
259 rStream >> bLand;
260 rStream >> nUse;
262 SvxPageItem* pPage = new SvxPageItem( Which() );
263 pPage->SetDescName( sStr );
264 pPage->SetNumType( (SvxNumType)eType );
265 pPage->SetLandscape( bLand );
266 pPage->SetPageUsage( nUse );
267 return pPage;
270 //------------------------------------------------------------------------
272 SvStream& SvxPageItem::Store( SvStream &rStrm, USHORT /*nItemVersion*/ ) const
274 // UNICODE: rStrm << aDescName;
275 rStrm.WriteByteString(aDescName);
277 rStrm << (BYTE)eNumType << bLandscape << eUse;
278 return rStrm;
281 /*--------------------------------------------------------------------
282 Beschreibung: HeaderFooterSet
283 --------------------------------------------------------------------*/
285 SvxSetItem::SvxSetItem( const USHORT nId, const SfxItemSet& rSet ) :
287 SfxSetItem( nId, rSet )
291 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
293 SfxSetItem( rItem )
297 SvxSetItem::SvxSetItem( const USHORT nId, SfxItemSet* _pSet ) :
299 SfxSetItem( nId, _pSet )
303 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
305 return new SvxSetItem(*this);
308 //------------------------------------------------------------------------
310 SfxItemPresentation SvxSetItem::GetPresentation
312 SfxItemPresentation /*ePres*/,
313 SfxMapUnit /*eCoreUnit*/,
314 SfxMapUnit /*ePresUnit*/,
315 XubString& rText, const IntlWrapper *
316 ) const
318 rText.Erase();
319 return SFX_ITEM_PRESENTATION_NONE;
322 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, USHORT /*nVersion*/) const
324 SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
325 GetItemSet().GetRanges() );
327 _pSet->Load( rStrm );
329 return new SvxSetItem( Which(), *_pSet );
332 SvStream& SvxSetItem::Store(SvStream &rStrm, USHORT nItemVersion) const
334 GetItemSet().Store( rStrm, nItemVersion );
336 return rStrm;