LibreOffice Module svx (master) 1
pageitem.cxx
Go to the documentation of this file.
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>
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
39using namespace ::com::sun::star;
40
42
44
45 eNumType ( SVX_NUM_ARABIC ),
46 bLandscape ( false ),
47 eUse ( SvxPageUsage::All )
48{
49}
50
51// Copy-Ctor
53 : SfxPoolItem( rItem )
54{
55 eNumType = rItem.eNumType;
56 bLandscape = rItem.bLandscape;
57 eUse = rItem.eUse;
58}
59
61
62// Clone
64{
65 return new SvxPageItem( *this );
66}
67
68// Test for equality
69bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
70{
71 assert(SfxPoolItem::operator==(rAttr));
72 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(rAttr);
73 return ( eNumType == rItem.eNumType &&
74 bLandscape == rItem.bLandscape &&
75 eUse == rItem.eUse );
76}
77
78static OUString GetUsageText( const SvxPageUsage eU )
79{
80 switch( eU )
81 {
82 case SvxPageUsage::Left : return SvxResId(RID_SVXITEMS_PAGE_USAGE_LEFT);
83 case SvxPageUsage::Right : return SvxResId(RID_SVXITEMS_PAGE_USAGE_RIGHT);
84 case SvxPageUsage::All : return SvxResId(RID_SVXITEMS_PAGE_USAGE_ALL);
85 case SvxPageUsage::Mirror: return SvxResId(RID_SVXITEMS_PAGE_USAGE_MIRROR);
86 default: return OUString();
87 }
88}
89
91{
92 RID_SVXITEMS_PAGE_NUM_CHR_UPPER,
93 RID_SVXITEMS_PAGE_NUM_CHR_LOWER,
94 RID_SVXITEMS_PAGE_NUM_ROM_UPPER,
95 RID_SVXITEMS_PAGE_NUM_ROM_LOWER,
96 RID_SVXITEMS_PAGE_NUM_ARABIC,
97 RID_SVXITEMS_PAGE_NUM_NONE
98};
99
100namespace
101{
102 OUString GetNumberingDescription(SvxNumType eNumType)
103 {
104 // classic ones, keep displaying the old name
105 if (eNumType <= css::style::NumberingType::NUMBER_NONE)
106 return SvxResId(RID_SVXITEMS_PAGE_NUMS[eNumType]);
107 // new ones, reuse the text used in the numbering dropdown list
108 sal_uInt32 n = SvxNumberingTypeTable::FindIndex(eNumType);
109 if (n != RESARRAY_INDEX_NOTFOUND)
111 css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
112 css::uno::Reference<css::text::XDefaultNumberingProvider> xDefNum = css::text::DefaultNumberingProvider::create(xContext);
113 css::uno::Reference<css::text::XNumberingTypeInfo> xInfo(xDefNum, css::uno::UNO_QUERY);
114 if (!xInfo.is())
115 return OUString();
116 return xInfo->getNumberingIdentifier(eNumType);
117 }
118}
119
121(
123 MapUnit /*eCoreUnit*/,
124 MapUnit /*ePresUnit*/,
125 OUString& rText, const IntlWrapper&
126) const
127{
128 rText.clear();
129 OUString cpDelimTmp(cpDelim);
130
131 switch ( ePres )
132 {
133 case SfxItemPresentation::Nameless:
134 {
135 if ( !aDescName.isEmpty() )
136 {
137 rText = aDescName + cpDelimTmp;
138 }
139 rText += GetNumberingDescription(eNumType) + cpDelimTmp;
140 if ( bLandscape )
141 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
142 else
143 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
144 OUString aUsageText = GetUsageText( eUse );
145 if (!aUsageText.isEmpty())
146 {
147 rText += cpDelimTmp + aUsageText;
148 }
149 return true;
150 }
151 case SfxItemPresentation::Complete:
152 {
153 rText += SvxResId(RID_SVXITEMS_PAGE_COMPLETE);
154 if ( !aDescName.isEmpty() )
155 {
156 rText += aDescName + cpDelimTmp;
157 }
158 rText += GetNumberingDescription(eNumType) + cpDelimTmp;
159 if ( bLandscape )
160 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
161 else
162 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
163 OUString aUsageText = GetUsageText( eUse );
164 if (!aUsageText.isEmpty())
165 {
166 rText += cpDelimTmp + aUsageText;
167 }
168 return true;
169 }
170 default: ;//prevent warning
171 }
172 return false;
173}
174
175
176bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
177{
178// sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
179 nMemberId &= ~CONVERT_TWIPS;
180 switch( nMemberId )
181 {
182 case MID_PAGE_NUMTYPE:
183 {
185 rVal <<= static_cast<sal_Int16>( eNumType );
186 }
187 break;
189 rVal <<= bLandscape;
190 break;
191 case MID_PAGE_LAYOUT :
192 {
193 style::PageStyleLayout eRet;
194 switch(eUse)
195 {
196 case SvxPageUsage::Left : eRet = style::PageStyleLayout_LEFT; break;
197 case SvxPageUsage::Right : eRet = style::PageStyleLayout_RIGHT; break;
198 case SvxPageUsage::All : eRet = style::PageStyleLayout_ALL; break;
199 case SvxPageUsage::Mirror: eRet = style::PageStyleLayout_MIRRORED; break;
200 default:
201 OSL_FAIL("what layout is this?");
202 return false;
203 }
204 rVal <<= eRet;
205 }
206 break;
207 }
208
209 return true;
210}
211
212bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
213{
214 switch( nMemberId & ~CONVERT_TWIPS )
215 {
216 case MID_PAGE_NUMTYPE:
217 {
218 sal_Int32 nValue = 0;
219 if(!(rVal >>= nValue))
220 return false;
221
222 eNumType = static_cast<SvxNumType>(nValue);
223 }
224 break;
226 bLandscape = Any2Bool(rVal);
227 break;
228 case MID_PAGE_LAYOUT :
229 {
230 style::PageStyleLayout eLayout;
231 if(!(rVal >>= eLayout))
232 {
233 sal_Int32 nValue = 0;
234 if(!(rVal >>= nValue))
235 return false;
236 eLayout = static_cast<style::PageStyleLayout>(nValue);
237 }
238 switch( eLayout )
239 {
240 case style::PageStyleLayout_LEFT : eUse = SvxPageUsage::Left ; break;
241 case style::PageStyleLayout_RIGHT : eUse = SvxPageUsage::Right; break;
242 case style::PageStyleLayout_ALL : eUse = SvxPageUsage::All ; break;
243 case style::PageStyleLayout_MIRRORED: eUse = SvxPageUsage::Mirror;break;
244 default: ;//prevent warning
245 }
246 }
247 break;
248 }
249 return true;
250}
251
252// HeaderFooterSet
254
256{
257}
258
260
261 SfxSetItem( rItem )
262{
263}
264
266
267 SfxSetItem( nId, std::move(_pSet) )
268{
269}
270
272{
273 return new SvxSetItem(*this);
274}
275
277(
278 SfxItemPresentation /*ePres*/,
279 MapUnit /*eCoreUnit*/,
280 MapUnit /*ePresUnit*/,
281 OUString& rText, const IntlWrapper&
282) const
283{
284 rText.clear();
285 return false;
286}
287
288
289/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_uInt32 FindIndex(int nValue)
Definition: strarray.cxx:78
static OUString GetString(sal_uInt32 i)
Definition: strarray.cxx:62
virtual SvxPageItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: pageitem.cxx:63
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: pageitem.cxx:176
virtual bool operator==(const SfxPoolItem &) const override
Definition: pageitem.cxx:69
virtual ~SvxPageItem() override
Definition: pageitem.cxx:60
OUString aDescName
Definition: pageitem.hxx:53
SvxPageItem(const TypedWhichId< SvxPageItem > nId)
Definition: pageitem.cxx:43
bool bLandscape
Definition: pageitem.hxx:55
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: pageitem.cxx:212
SvxPageUsage eUse
Definition: pageitem.hxx:56
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: pageitem.cxx:121
SvxNumType eNumType
Definition: pageitem.hxx:54
static SfxPoolItem * CreateDefault()
Definition: pageitem.cxx:41
virtual SvxSetItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: pageitem.cxx:271
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: pageitem.cxx:277
SvxSetItem(const TypedWhichId< SvxSetItem > nId, const SfxItemSet &rSet)
Definition: pageitem.cxx:253
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
constexpr OUStringLiteral cpDelim
sal_Int64 n
MapUnit
Reference< XComponentContext > getProcessComponentContext()
sal_Int16 nId
static OUString GetUsageText(const SvxPageUsage eU)
Definition: pageitem.cxx:78
const TranslateId RID_SVXITEMS_PAGE_NUMS[]
Definition: pageitem.cxx:90
SvxPageUsage
Definition: pageitem.hxx:33
SfxItemPresentation
#define CONVERT_TWIPS
bool Any2Bool(const css::uno::Any &rValue)
static SfxItemSet & rSet
SvxNumType
SVX_NUM_ARABIC
unsigned char sal_uInt8
#define MID_PAGE_ORIENTATION
Definition: unomid.hxx:24
#define MID_PAGE_LAYOUT
Definition: unomid.hxx:25
#define MID_PAGE_NUMTYPE
Definition: unomid.hxx:23