bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / items / pageitem.cxx
blobce4a265895fe2d534240dcc3b0d775cd990ed2f7
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 ::rtl;
33 using namespace ::com::sun::star;
35 // STATIC DATA -----------------------------------------------------------
37 TYPEINIT1_FACTORY( SvxPageItem, SfxPoolItem , new SvxPageItem(0));
39 /*--------------------------------------------------------------------
40 Beschreibung: Konstruktor
41 --------------------------------------------------------------------*/
43 SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ),
45 eNumType ( SVX_ARABIC ),
46 bLandscape ( sal_False ),
47 eUse ( SVX_PAGE_ALL )
51 /*--------------------------------------------------------------------
52 Beschreibung: Copy-Konstruktor
53 --------------------------------------------------------------------*/
55 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
56 : SfxPoolItem( rItem )
58 eNumType = rItem.eNumType;
59 bLandscape = rItem.bLandscape;
60 eUse = rItem.eUse;
63 /*--------------------------------------------------------------------
64 Beschreibung: Clonen
65 --------------------------------------------------------------------*/
67 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const
69 return new SvxPageItem( *this );
72 /*--------------------------------------------------------------------
73 Beschreibung: Abfrage auf Gleichheit
74 --------------------------------------------------------------------*/
76 int SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
78 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
79 const SvxPageItem& rItem = (SvxPageItem&)rAttr;
80 return ( eNumType == rItem.eNumType &&
81 bLandscape == rItem.bLandscape &&
82 eUse == rItem.eUse );
85 inline XubString GetUsageText( const sal_uInt16 eU )
87 switch( eU & 0x000f )
89 case SVX_PAGE_LEFT : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_LEFT);
90 case SVX_PAGE_RIGHT : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_RIGHT);
91 case SVX_PAGE_ALL : return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_ALL);
92 case SVX_PAGE_MIRROR: return SVX_RESSTR(RID_SVXITEMS_PAGE_USAGE_MIRROR);
93 default: return String();
97 //------------------------------------------------------------------------
99 SfxItemPresentation SvxPageItem::GetPresentation
101 SfxItemPresentation ePres,
102 SfxMapUnit /*eCoreUnit*/,
103 SfxMapUnit /*ePresUnit*/,
104 OUString& rText, const IntlWrapper *
105 ) const
107 rText = OUString();
108 OUString cpDelimTmp = OUString(cpDelim);
110 switch ( ePres )
112 case SFX_ITEM_PRESENTATION_NONE:
113 return SFX_ITEM_PRESENTATION_NONE;
114 case SFX_ITEM_PRESENTATION_NAMELESS:
116 if ( aDescName.Len() )
118 rText = aDescName + cpDelimTmp;
120 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
121 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType) + cpDelimTmp;
122 if ( bLandscape )
123 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
124 else
125 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
126 String aUsageText = GetUsageText( eUse );
127 if (aUsageText.Len())
129 rText += cpDelimTmp + aUsageText;
131 return SFX_ITEM_PRESENTATION_NAMELESS;
133 case SFX_ITEM_PRESENTATION_COMPLETE:
135 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_COMPLETE);
136 if ( aDescName.Len() )
138 rText += aDescName + cpDelimTmp;
140 DBG_ASSERT( eNumType <= SVX_NUMBER_NONE, "enum overflow" );
141 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_NUM_BEGIN + eNumType) + cpDelimTmp;
142 if ( bLandscape )
143 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE);
144 else
145 rText += SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE);
146 String aUsageText = GetUsageText( eUse );
147 if (aUsageText.Len())
149 rText += cpDelimTmp + aUsageText;
151 return SFX_ITEM_PRESENTATION_COMPLETE;
153 default: ;//prevent warning
155 return SFX_ITEM_PRESENTATION_NONE;
158 //------------------------------------------------------------------------
159 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
161 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
162 nMemberId &= ~CONVERT_TWIPS;
163 switch( nMemberId )
165 case MID_PAGE_NUMTYPE:
167 //! die Konstanten sind nicht mehr in den IDLs ?!?
168 rVal <<= (sal_Int16)( eNumType );
170 break;
171 case MID_PAGE_ORIENTATION:
172 //Landscape= sal_True
173 rVal = Bool2Any(bLandscape);
174 break;
175 case MID_PAGE_LAYOUT :
177 style::PageStyleLayout eRet;
178 switch(eUse & 0x0f)
180 case SVX_PAGE_LEFT : eRet = style::PageStyleLayout_LEFT; break;
181 case SVX_PAGE_RIGHT : eRet = style::PageStyleLayout_RIGHT; break;
182 case SVX_PAGE_ALL : eRet = style::PageStyleLayout_ALL; break;
183 case SVX_PAGE_MIRROR: eRet = style::PageStyleLayout_MIRRORED; break;
184 default:
185 OSL_FAIL("was fuer ein Layout ist das?");
186 return sal_False;
188 rVal <<= eRet;
190 break;
193 return true;
195 //------------------------------------------------------------------------
196 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
198 switch( nMemberId )
200 case MID_PAGE_NUMTYPE:
202 sal_Int32 nValue = 0;
203 if(!(rVal >>= nValue))
204 return false;
206 eNumType = (SvxNumType)nValue;
208 break;
209 case MID_PAGE_ORIENTATION:
210 bLandscape = Any2Bool(rVal);
211 break;
212 case MID_PAGE_LAYOUT :
214 style::PageStyleLayout eLayout;
215 if(!(rVal >>= eLayout))
217 sal_Int32 nValue = 0;
218 if(!(rVal >>= nValue))
219 return sal_False;
220 eLayout = (style::PageStyleLayout)nValue;
222 eUse &= 0xfff0;
223 switch( eLayout )
225 case style::PageStyleLayout_LEFT : eUse |= SVX_PAGE_LEFT ; break;
226 case style::PageStyleLayout_RIGHT : eUse |= SVX_PAGE_RIGHT; break;
227 case style::PageStyleLayout_ALL : eUse |= SVX_PAGE_ALL ; break;
228 case style::PageStyleLayout_MIRRORED: eUse |= SVX_PAGE_MIRROR;break;
229 default: ;//prevent warning
232 break;
234 return true;
237 //------------------------------------------------------------------------
239 SfxPoolItem* SvxPageItem::Create( SvStream& rStream, sal_uInt16 ) const
241 sal_uInt8 eType;
242 sal_Bool bLand;
243 sal_uInt16 nUse;
245 // UNICODE: rStream >> sStr;
246 XubString sStr = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
248 rStream >> eType;
249 rStream >> bLand;
250 rStream >> nUse;
252 SvxPageItem* pPage = new SvxPageItem( Which() );
253 pPage->SetDescName( sStr );
254 pPage->SetNumType( (SvxNumType)eType );
255 pPage->SetLandscape( bLand );
256 pPage->SetPageUsage( nUse );
257 return pPage;
260 //------------------------------------------------------------------------
262 SvStream& SvxPageItem::Store( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
264 // UNICODE: rStrm << aDescName;
265 rStrm.WriteUniOrByteString(aDescName, rStrm.GetStreamCharSet());
267 rStrm << (sal_uInt8)eNumType << bLandscape << eUse;
268 return rStrm;
271 /*--------------------------------------------------------------------
272 Beschreibung: HeaderFooterSet
273 --------------------------------------------------------------------*/
275 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) :
277 SfxSetItem( nId, rSet )
281 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
283 SfxSetItem( rItem )
287 SvxSetItem::SvxSetItem( const sal_uInt16 nId, SfxItemSet* _pSet ) :
289 SfxSetItem( nId, _pSet )
293 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const
295 return new SvxSetItem(*this);
298 //------------------------------------------------------------------------
300 SfxItemPresentation SvxSetItem::GetPresentation
302 SfxItemPresentation /*ePres*/,
303 SfxMapUnit /*eCoreUnit*/,
304 SfxMapUnit /*ePresUnit*/,
305 OUString& rText, const IntlWrapper *
306 ) const
308 rText = OUString();
309 return SFX_ITEM_PRESENTATION_NONE;
312 SfxPoolItem* SvxSetItem::Create(SvStream &rStrm, sal_uInt16 /*nVersion*/) const
314 SfxItemSet* _pSet = new SfxItemSet( *GetItemSet().GetPool(),
315 GetItemSet().GetRanges() );
317 _pSet->Load( rStrm );
319 return new SvxSetItem( Which(), *_pSet );
322 SvStream& SvxSetItem::Store(SvStream &rStrm, sal_uInt16 nItemVersion) const
324 GetItemSet().Store( rStrm, nItemVersion );
326 return rStrm;
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */