bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / pageitem.cxx
blobb92e9469fea360986557cfe40e3668291371fb29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/stream.hxx>
23 #include <svx/pageitem.hxx>
24 #include <editeng/itemtype.hxx>
25 #include <svx/unomid.hxx>
26 #include <com/sun/star/style/PageStyleLayout.hpp>
27 #include <com/sun/star/style/BreakType.hpp>
28 #include <svl/itemset.hxx>
29 #include <svx/svxitems.hrc>
30 #include <svx/dialmgr.hxx>
32 using namespace ::com::sun::star;
34 TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new SvxPageItem(0));
36 SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ),
38 eNumType ( SVX_ARABIC ),
39 bLandscape ( false ),
40 eUse ( SVX_PAGE_ALL )
44 // Copy-Ctor
45 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
46 : SfxPoolItem( rItem )
48 eNumType = rItem.eNumType;
49 bLandscape = rItem.bLandscape;
50 eUse = rItem.eUse;
53 // Clone
54 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
56 return new SvxPageItem( *this );
59 // Test for equality
60 bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
62 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
63 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(rAttr);
64 return ( eNumType == rItem.eNumType &&
65 bLandscape == rItem.bLandscape &&
66 eUse == rItem.eUse );
69 inline OUString GetUsageText( const sal_uInt16 eU )
71 switch( eU & 0x000f )
73 case SVX_PAGE_LEFT : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
74 case SVX_PAGE_RIGHT : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
75 case SVX_PAGE_ALL : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
76 case SVX_PAGE_MIRROR: return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
77 default: return OUString();
83 bool SvxPageItem::GetPresentation
85 SfxItemPresentation ePres,
86 SfxMapUnit /*eCoreUnit*/,
87 SfxMapUnit /*ePresUnit*/,
88 OUString& rText, const IntlWrapper *
89 ) const
91 rText.clear();
92 OUString cpDelimTmp = OUString(cpDelim);
94 switch ( ePres )
96 case SFX_ITEM_PRESENTATION_NAMELESS:
98 if ( !aDescName.isEmpty() )
100 rText = aDescName + cpDelimTmp;
102 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
103 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType) + cpDelimTmp;
104 if ( bLandscape )
105 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
106 else
107 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
108 OUString aUsageText = GetUsageText( eUse );
109 if (!aUsageText.isEmpty())
111 rText += cpDelimTmp + aUsageText;
113 return true;
115 case SFX_ITEM_PRESENTATION_COMPLETE:
117 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
118 if ( !aDescName.isEmpty() )
120 rText += aDescName + cpDelimTmp;
122 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
123 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType) + cpDelimTmp;
124 if ( bLandscape )
125 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
126 else
127 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
128 OUString aUsageText = GetUsageText( eUse );
129 if (!aUsageText.isEmpty())
131 rText += cpDelimTmp + aUsageText;
133 return true;
135 default: ;//prevent warning
137 return false;
141 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
143 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
144 nMemberId &= ~CONVERT_TWIPS;
145 switch( nMemberId )
147 case MID_PAGE_NUMTYPE:
149 //! constants aren't in IDLs any more ?!?
150 rVal <<= (sal_Int16)( eNumType );
152 break;
153 case MID_PAGE_ORIENTATION:
154 //Landscape= sal_True
155 rVal = Bool2Any(bLandscape);
156 break;
157 case MID_PAGE_LAYOUT :
159 style::PageStyleLayout eRet;
160 switch(eUse & 0x0f)
162 case SVX_PAGE_LEFT : eRet = style::PageStyleLayout_LEFT; break;
163 case SVX_PAGE_RIGHT : eRet = style::PageStyleLayout_RIGHT; break;
164 case SVX_PAGE_ALL : eRet = style::PageStyleLayout_ALL; break;
165 case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
166 default:
167 OSL_FAIL("what layout is this?");
168 return false;
170 rVal <<= eRet;
172 break;
175 return true;
178 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
180 switch( nMemberId )
182 case MID_PAGE_NUMTYPE:
184 sal_Int32 nValue = 0;
185 if(!(rVal >>= nValue))
186 return false;
188 eNumType = (SvxNumType)nValue;
190 break;
191 case MID_PAGE_ORIENTATION:
192 bLandscape = Any2Bool(rVal);
193 break;
194 case MID_PAGE_LAYOUT :
196 style::PageStyleLayout eLayout;
197 if(!(rVal >>= eLayout))
199 sal_Int32 nValue = 0;
200 if(!(rVal >>= nValue))
201 return false;
202 eLayout = (style::PageStyleLayout)nValue;
204 eUse &= 0xfff0;
205 switch( eLayout )
207 case style::PageStyleLayout_LEFT : eUse |= SVX_PAGE_LEFT ; break;
208 case style::PageStyleLayout_RIGHT : eUse |= SVX_PAGE_RIGHT; break;
209 case style::PageStyleLayout_ALL : eUse |= SVX_PAGE_ALL ; break;
210 case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
211 default: ;//prevent warning
214 break;
216 return true;
221 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
223 sal_uInt8 eType;
224 bool bLand;
225 sal_uInt16 nUse;
227 // UNICODE: rStream >> sStr;
228 OUString sStr = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
230 rStream.ReadUChar( eType );
231 rStream.ReadCharAsBool( bLand );
232 rStream.ReadUInt16( nUse );
234 SvxPageItem* pPage = new SvxPageItem( Which() );
235 pPage->SetDescName( sStr );
236 pPage->SetNumType( (SvxNumType)eType );
237 pPage->SetLandscape( bLand );
238 pPage->SetPageUsage( nUse );
239 return pPage;
244 SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
246 // UNICODE: rStrm << aDescName;
247 rStrm.WriteUniOrByteString(aDescName, rStrm.GetStreamCharSet());
249 rStrm.WriteUChar( eNumType ).WriteBool( bLandscape ).WriteUInt16( eUse );
250 return rStrm;
253 // HeaderFooterSet
254 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
256 SfxSetItem( nId, rSet )
260 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
262 SfxSetItem( rItem )
266 SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
268 SfxSetItem( nId, _pSet )
272 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
274 return new SvxSetItem(*this);
279 bool SvxSetItem::GetPresentation
281 SfxItemPresentation /*ePres*/,
282 SfxMapUnit /*eCoreUnit*/,
283 SfxMapUnit /*ePresUnit*/,
284 OUString& rText, const IntlWrapper *
285 ) const
287 rText.clear();
288 return false;
291 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
293 SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
294 GetItemSet().GetRanges() );
296 _pSet->Load( rStrm );
298 return new SvxSetItem( Which(), *_pSet );
301 SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
303 GetItemSet().Store( rStrm, nItemVersion );
305 return rStrm;
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */