Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / items / pageitem.cxx
blobcd9fef7e5a790ee91d467cceee99928776e42fb4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <tools/stream.hxx>
34 #include <svx/pageitem.hxx>
35 #include <editeng/itemtype.hxx>
36 #include <svx/unomid.hxx>
37 #include <com/sun/star/style/PageStyleLayout.hpp>
38 #include <com/sun/star/style/BreakType.hpp>
39 #include <svl/itemset.hxx>
40 #include <svx/svxitems.hrc>
41 #include <svx/dialmgr.hxx>
43 using namespace ::rtl;
44 using namespace ::com::sun::star;
46 // STATIC DATA -----------------------------------------------------------
48 TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new SvxPageItem(0));
50 /*--------------------------------------------------------------------
51 Beschreibung: Konstruktor
52 --------------------------------------------------------------------*/
54 SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ),
56 eNumType ( SVX_ARABIC ),
57 bLandscape ( sal_False ),
58 eUse ( SVX_PAGE_ALL )
62 /*--------------------------------------------------------------------
63 Beschreibung: Copy-Konstruktor
64 --------------------------------------------------------------------*/
66 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
67 : SfxPoolItem( rItem )
69 eNumType = rItem.eNumType;
70 bLandscape = rItem.bLandscape;
71 eUse = rItem.eUse;
74 /*--------------------------------------------------------------------
75 Beschreibung: Clonen
76 --------------------------------------------------------------------*/
78 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
80 return new SvxPageItem( *this );
83 /*--------------------------------------------------------------------
84 Beschreibung: Abfrage auf Gleichheit
85 --------------------------------------------------------------------*/
87 int SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
89 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
90 const SvxPageItem& rItem = (SvxPageItem&)rAttr;
91 return ( eNumType == rItem.eNumType &&
92 bLandscape == rItem.bLandscape &&
93 eUse == rItem.eUse );
96 inline XubString GetUsageText( const sal_uInt16 eU )
98 if ( eU & SVX_PAGE_LEFT )
99 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
100 if ( eU & SVX_PAGE_RIGHT )
101 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
102 if ( eU & SVX_PAGE_ALL )
103 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
104 if ( eU & SVX_PAGE_MIRROR )
105 return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
106 return String();
109 //------------------------------------------------------------------------
111 SfxItemPresentation SvxPageItem::GetPresentation
113 SfxItemPresentation ePres,
114 SfxMapUnit /*eCoreUnit*/,
115 SfxMapUnit /*ePresUnit*/,
116 XubString& rText, const IntlWrapper *
117 ) const
119 rText.Erase();
121 switch ( ePres )
123 case SFX_ITEM_PRESENTATION_NONE:
124 return SFX_ITEM_PRESENTATION_NONE;
125 case SFX_ITEM_PRESENTATION_NAMELESS:
127 if ( aDescName.Len() )
129 rText = aDescName;
130 rText += cpDelim;
132 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
133 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
134 rText += cpDelim;
135 if ( bLandscape )
136 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
137 else
138 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
139 String aUsageText = GetUsageText( eUse );
140 if (aUsageText.Len())
142 rText += cpDelim;
143 rText += aUsageText;
145 return SFX_ITEM_PRESENTATION_NAMELESS;
147 case SFX_ITEM_PRESENTATION_COMPLETE:
149 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
150 if ( aDescName.Len() )
152 rText += aDescName;
153 rText += cpDelim;
155 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
156 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType);
157 rText += cpDelim;
158 if ( bLandscape )
159 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
160 else
161 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
162 String aUsageText = GetUsageText( eUse );
163 if (aUsageText.Len())
165 rText += cpDelim;
166 rText += aUsageText;
168 return SFX_ITEM_PRESENTATION_COMPLETE;
170 default: ;//prevent warning
172 return SFX_ITEM_PRESENTATION_NONE;
175 //------------------------------------------------------------------------
176 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
178 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
179 nMemberId &= ~CONVERT_TWIPS;
180 switch( nMemberId )
182 case MID_PAGE_NUMTYPE:
184 //! die Konstanten sind nicht mehr in den IDLs ?!?
185 rVal <<= (sal_Int16)( eNumType );
187 break;
188 case MID_PAGE_ORIENTATION:
189 //Landscape= sal_True
190 rVal = Bool2Any(bLandscape);
191 break;
192 case MID_PAGE_LAYOUT :
194 style::PageStyleLayout eRet;
195 switch(eUse & 0x0f)
197 case SVX_PAGE_LEFT : eRet = style::PageStyleLayout_LEFT; break;
198 case SVX_PAGE_RIGHT : eRet = style::PageStyleLayout_RIGHT; break;
199 case SVX_PAGE_ALL : eRet = style::PageStyleLayout_ALL; break;
200 case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
201 default:
202 OSL_FAIL("was fuer ein Layout ist das?");
203 return sal_False;
205 rVal <<= eRet;
207 break;
210 return true;
212 //------------------------------------------------------------------------
213 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
215 switch( nMemberId )
217 case MID_PAGE_NUMTYPE:
219 sal_Int32 nValue = 0;
220 if(!(rVal >>= nValue))
221 return false;
223 eNumType = (SvxNumType)nValue;
225 break;
226 case MID_PAGE_ORIENTATION:
227 bLandscape = Any2Bool(rVal);
228 break;
229 case MID_PAGE_LAYOUT :
231 style::PageStyleLayout eLayout;
232 if(!(rVal >>= eLayout))
234 sal_Int32 nValue = 0;
235 if(!(rVal >>= nValue))
236 return sal_False;
237 eLayout = (style::PageStyleLayout)nValue;
239 eUse &= 0xfff0;
240 switch( eLayout )
242 case style::PageStyleLayout_LEFT : eUse |= SVX_PAGE_LEFT ; break;
243 case style::PageStyleLayout_RIGHT : eUse |= SVX_PAGE_RIGHT; break;
244 case style::PageStyleLayout_ALL : eUse |= SVX_PAGE_ALL ; break;
245 case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
246 default: ;//prevent warning
249 break;
251 return true;
254 //------------------------------------------------------------------------
256 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
258 sal_uInt8 eType;
259 sal_Bool bLand;
260 sal_uInt16 nUse;
262 // UNICODE: rStream >> sStr;
263 XubString sStr = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
265 rStream >> eType;
266 rStream >> bLand;
267 rStream >> nUse;
269 SvxPageItem* pPage = new SvxPageItem( Which() );
270 pPage->SetDescName( sStr );
271 pPage->SetNumType( (SvxNumType)eType );
272 pPage->SetLandscape( bLand );
273 pPage->SetPageUsage( nUse );
274 return pPage;
277 //------------------------------------------------------------------------
279 SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
281 // UNICODE: rStrm << aDescName;
282 rStrm.WriteUniOrByteString(aDescName, rStrm.GetStreamCharSet());
284 rStrm << (sal_uInt8)eNumType << bLandscape << eUse;
285 return rStrm;
288 /*--------------------------------------------------------------------
289 Beschreibung: HeaderFooterSet
290 --------------------------------------------------------------------*/
292 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
294 SfxSetItem( nId, rSet )
298 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
300 SfxSetItem( rItem )
304 SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
306 SfxSetItem( nId, _pSet )
310 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
312 return new SvxSetItem(*this);
315 //------------------------------------------------------------------------
317 SfxItemPresentation SvxSetItem::GetPresentation
319 SfxItemPresentation /*ePres*/,
320 SfxMapUnit /*eCoreUnit*/,
321 SfxMapUnit /*ePresUnit*/,
322 XubString& rText, const IntlWrapper *
323 ) const
325 rText.Erase();
326 return SFX_ITEM_PRESENTATION_NONE;
329 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
331 SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
332 GetItemSet().GetRanges() );
334 _pSet->Load( rStrm );
336 return new SvxSetItem( Which(), *_pSet );
339 SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
341 GetItemSet().Store( rStrm, nItemVersion );
343 return rStrm;
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */