1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <sal/config.h>
21
22 #include <utility>
23
24 #include <osl/diagnose.h>
25 #include <comphelper/processfactory.hxx>
26 #include <tools/resary.hxx>
27 #include <svx/pageitem.hxx>
28 #include <svx/strarray.hxx>
29 #include <editeng/itemtype.hxx>
30 #include <svx/unomid.hxx>
31 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
32 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
33 #include <com/sun/star/style/NumberingType.hpp>
34 #include <com/sun/star/style/PageStyleLayout.hpp>
35 #include <svl/itemset.hxx>
36 #include <svx/strings.hrc>
37 #include <svx/dialmgr.hxx>
38
39 using namespace ::com::sun::star;
40
CreateDefault()41 SfxPoolItem* SvxPageItem::CreateDefault() { return new SvxPageItem(TypedWhichId<SvxPageItem>(0));}
42
SvxPageItem(const TypedWhichId<SvxPageItem> nId)43 SvxPageItem::SvxPageItem( const TypedWhichId<SvxPageItem> nId )
44 : SfxPoolItem( nId, SfxItemType::SvxPageItemType ),
45
46 eNumType ( SVX_NUM_ARABIC ),
47 bLandscape ( false ),
48 eUse ( SvxPageUsage::All )
49 {
50 }
51
52 // Copy-Ctor
SvxPageItem(const SvxPageItem & rItem)53 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
54 : SfxPoolItem( rItem )
55 {
56 eNumType = rItem.eNumType;
57 bLandscape = rItem.bLandscape;
58 eUse = rItem.eUse;
59 }
60
~SvxPageItem()61 SvxPageItem::~SvxPageItem() {}
62
63 // Clone
Clone(SfxItemPool *) const64 SvxPageItem* SvxPageItem::Clone( SfxItemPool * ) const
65 {
66 return new SvxPageItem( *this );
67 }
68
69 // Test for equality
operator ==(const SfxPoolItem & rAttr) const70 bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
71 {
72 assert(SfxPoolItem::operator==(rAttr));
73 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(rAttr);
74 return ( eNumType == rItem.eNumType &&
75 bLandscape == rItem.bLandscape &&
76 eUse == rItem.eUse );
77 }
78
GetUsageText(const SvxPageUsage eU)79 static OUString GetUsageText( const SvxPageUsage eU )
80 {
81 switch( eU )
82 {
83 case SvxPageUsage::Left : return SvxResId(RID_SVXITEMS_PAGE_USAGE_LEFT);
84 case SvxPageUsage::Right : return SvxResId(RID_SVXITEMS_PAGE_USAGE_RIGHT);
85 case SvxPageUsage::All : return SvxResId(RID_SVXITEMS_PAGE_USAGE_ALL);
86 case SvxPageUsage::Mirror: return SvxResId(RID_SVXITEMS_PAGE_USAGE_MIRROR);
87 default: return OUString();
88 }
89 }
90
91 const TranslateId RID_SVXITEMS_PAGE_NUMS[] =
92 {
93 RID_SVXITEMS_PAGE_NUM_CHR_UPPER,
94 RID_SVXITEMS_PAGE_NUM_CHR_LOWER,
95 RID_SVXITEMS_PAGE_NUM_ROM_UPPER,
96 RID_SVXITEMS_PAGE_NUM_ROM_LOWER,
97 RID_SVXITEMS_PAGE_NUM_ARABIC,
98 RID_SVXITEMS_PAGE_NUM_NONE
99 };
100
101 namespace
102 {
GetNumberingDescription(SvxNumType eNumType)103 OUString GetNumberingDescription(SvxNumType eNumType)
104 {
105 // classic ones, keep displaying the old name
106 if (eNumType <= css::style::NumberingType::NUMBER_NONE)
107 return SvxResId(RID_SVXITEMS_PAGE_NUMS[eNumType]);
108 // new ones, reuse the text used in the numbering dropdown list
109 sal_uInt32 n = SvxNumberingTypeTable::FindIndex(eNumType);
110 if (n != RESARRAY_INDEX_NOTFOUND)
111 return SvxNumberingTypeTable::GetString(n);
112 css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
113 css::uno::Reference<css::text::XDefaultNumberingProvider> xDefNum = css::text::DefaultNumberingProvider::create(xContext);
114 css::uno::Reference<css::text::XNumberingTypeInfo> xInfo(xDefNum, css::uno::UNO_QUERY);
115 if (!xInfo.is())
116 return OUString();
117 return xInfo->getNumberingIdentifier(eNumType);
118 }
119 }
120
GetPresentation(SfxItemPresentation ePres,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const121 bool SvxPageItem::GetPresentation
122 (
123 SfxItemPresentation ePres,
124 MapUnit /*eCoreUnit*/,
125 MapUnit /*ePresUnit*/,
126 OUString& rText, const IntlWrapper&
127 ) const
128 {
129 rText.clear();
130 OUString cpDelimTmp(cpDelim);
131
132 switch ( ePres )
133 {
134 case SfxItemPresentation::Nameless:
135 {
136 if ( !aDescName.isEmpty() )
137 {
138 rText = aDescName + cpDelimTmp;
139 }
140 rText += GetNumberingDescription(eNumType) + cpDelimTmp;
141 if ( bLandscape )
142 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
143 else
144 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
145 OUString aUsageText = GetUsageText( eUse );
146 if (!aUsageText.isEmpty())
147 {
148 rText += cpDelimTmp + aUsageText;
149 }
150 return true;
151 }
152 case SfxItemPresentation::Complete:
153 {
154 rText += SvxResId(RID_SVXITEMS_PAGE_COMPLETE);
155 if ( !aDescName.isEmpty() )
156 {
157 rText += aDescName + cpDelimTmp;
158 }
159 rText += GetNumberingDescription(eNumType) + cpDelimTmp;
160 if ( bLandscape )
161 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
162 else
163 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
164 OUString aUsageText = GetUsageText( eUse );
165 if (!aUsageText.isEmpty())
166 {
167 rText += cpDelimTmp + aUsageText;
168 }
169 return true;
170 }
171 default: ;//prevent warning
172 }
173 return false;
174 }
175
176
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const177 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
178 {
179 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
180 nMemberId &= ~CONVERT_TWIPS;
181 switch( nMemberId )
182 {
183 case MID_PAGE_NUMTYPE:
184 {
185 //! constants aren't in IDLs any more ?!?
186 rVal <<= static_cast<sal_Int16>( eNumType );
187 }
188 break;
189 case MID_PAGE_ORIENTATION:
190 rVal <<= bLandscape;
191 break;
192 case MID_PAGE_LAYOUT :
193 {
194 style::PageStyleLayout eRet;
195 switch(eUse)
196 {
197 case SvxPageUsage::Left : eRet = style::PageStyleLayout_LEFT; break;
198 case SvxPageUsage::Right : eRet = style::PageStyleLayout_RIGHT; break;
199 case SvxPageUsage::All : eRet = style::PageStyleLayout_ALL; break;
200 case SvxPageUsage::Mirror: eRet = style::PageStyleLayout_MIRRORED; break;
201 default:
202 OSL_FAIL("what layout is this?");
203 return false;
204 }
205 rVal <<= eRet;
206 }
207 break;
208 }
209
210 return true;
211 }
212
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)213 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
214 {
215 switch( nMemberId & ~CONVERT_TWIPS )
216 {
217 case MID_PAGE_NUMTYPE:
218 {
219 sal_Int32 nValue = 0;
220 if(!(rVal >>= nValue))
221 return false;
222
223 eNumType = static_cast<SvxNumType>(nValue);
224 }
225 break;
226 case MID_PAGE_ORIENTATION:
227 bLandscape = Any2Bool(rVal);
228 break;
229 case MID_PAGE_LAYOUT :
230 {
231 style::PageStyleLayout eLayout;
232 if(!(rVal >>= eLayout))
233 {
234 sal_Int32 nValue = 0;
235 if(!(rVal >>= nValue))
236 return false;
237 eLayout = static_cast<style::PageStyleLayout>(nValue);
238 }
239 switch( eLayout )
240 {
241 case style::PageStyleLayout_LEFT : eUse = SvxPageUsage::Left ; break;
242 case style::PageStyleLayout_RIGHT : eUse = SvxPageUsage::Right; break;
243 case style::PageStyleLayout_ALL : eUse = SvxPageUsage::All ; break;
244 case style::PageStyleLayout_MIRRORED: eUse = SvxPageUsage::Mirror;break;
245 default: ;//prevent warning
246 }
247 }
248 break;
249 }
250 return true;
251 }
252
253 // HeaderFooterSet
SvxSetItem(const TypedWhichId<SvxSetItem> nId,const SfxItemSet & rSet)254 SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, const SfxItemSet& rSet ) :
255
256 SfxSetItem( nId, rSet )
257 {
258 }
259
SvxSetItem(const SvxSetItem & rItem,SfxItemPool * pPool)260 SvxSetItem::SvxSetItem( const SvxSetItem& rItem, SfxItemPool* pPool ) :
261
262 SfxSetItem( rItem, pPool )
263 {
264 }
265
SvxSetItem(const TypedWhichId<SvxSetItem> nId,SfxItemSet && _pSet)266 SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, SfxItemSet&& _pSet ) :
267
268 SfxSetItem( nId, std::move(_pSet) )
269 {
270 }
271
Clone(SfxItemPool * pPool) const272 SvxSetItem* SvxSetItem::Clone( SfxItemPool * pPool ) const
273 {
274 return new SvxSetItem(*this, pPool);
275 }
276
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const277 bool SvxSetItem::GetPresentation
278 (
279 SfxItemPresentation /*ePres*/,
280 MapUnit /*eCoreUnit*/,
281 MapUnit /*ePresUnit*/,
282 OUString& rText, const IntlWrapper&
283 ) const
284 {
285 rText.clear();
286 return false;
287 }
288
289
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
291