1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
45 SvxPageItem::SvxPageItem( const SvxPageItem
& rItem
)
46 : SfxPoolItem( rItem
)
48 eNumType
= rItem
.eNumType
;
49 bLandscape
= rItem
.bLandscape
;
54 SfxPoolItem
* SvxPageItem::Clone( SfxItemPool
* ) const
56 return new SvxPageItem( *this );
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
&&
69 inline OUString
GetUsageText( const sal_uInt16 eU
)
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
*
92 OUString cpDelimTmp
= OUString(cpDelim
);
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
;
105 rText
+= SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE
);
107 rText
+= SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE
);
108 OUString aUsageText
= GetUsageText( eUse
);
109 if (!aUsageText
.isEmpty())
111 rText
+= cpDelimTmp
+ aUsageText
;
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
;
125 rText
+= SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_TRUE
);
127 rText
+= SVX_RESSTR(RID_SVXITEMS_PAGE_LAND_FALSE
);
128 OUString aUsageText
= GetUsageText( eUse
);
129 if (!aUsageText
.isEmpty())
131 rText
+= cpDelimTmp
+ aUsageText
;
135 default: ;//prevent warning
141 bool SvxPageItem::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
143 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
144 nMemberId
&= ~CONVERT_TWIPS
;
147 case MID_PAGE_NUMTYPE
:
149 //! constants aren't in IDLs any more ?!?
150 rVal
<<= (sal_Int16
)( eNumType
);
153 case MID_PAGE_ORIENTATION
:
154 //Landscape= sal_True
155 rVal
= Bool2Any(bLandscape
);
157 case MID_PAGE_LAYOUT
:
159 style::PageStyleLayout eRet
;
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;
167 OSL_FAIL("what layout is this?");
178 bool SvxPageItem::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
182 case MID_PAGE_NUMTYPE
:
184 sal_Int32 nValue
= 0;
185 if(!(rVal
>>= nValue
))
188 eNumType
= (SvxNumType
)nValue
;
191 case MID_PAGE_ORIENTATION
:
192 bLandscape
= Any2Bool(rVal
);
194 case MID_PAGE_LAYOUT
:
196 style::PageStyleLayout eLayout
;
197 if(!(rVal
>>= eLayout
))
199 sal_Int32 nValue
= 0;
200 if(!(rVal
>>= nValue
))
202 eLayout
= (style::PageStyleLayout
)nValue
;
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
221 SfxPoolItem
* SvxPageItem::Create( SvStream
& rStream
, sal_uInt16
) const
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
);
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
);
254 SvxSetItem::SvxSetItem( const sal_uInt16 nId
, const SfxItemSet
& rSet
) :
256 SfxSetItem( nId
, rSet
)
260 SvxSetItem::SvxSetItem( const SvxSetItem
& 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
*
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
);
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */