Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / pageitem.cxx
blob93239ea3d5b19fca4a09e914085f152b9dffb577
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 <sal/config.h>
22 #include <utility>
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>
39 using namespace ::com::sun::star;
41 SfxPoolItem* SvxPageItem::CreateDefault() { return new SvxPageItem(TypedWhichId<SvxPageItem>(0));}
43 SvxPageItem::SvxPageItem( const TypedWhichId<SvxPageItem> nId ) : SfxPoolItem( nId ),
45 eNumType ( SVX_NUM_ARABIC ),
46 bLandscape ( false ),
47 eUse ( SvxPageUsage::All )
51 // Copy-Ctor
52 SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
53 : SfxPoolItem( rItem )
55 eNumType = rItem.eNumType;
56 bLandscape = rItem.bLandscape;
57 eUse = rItem.eUse;
60 SvxPageItem::~SvxPageItem() {}
62 // Clone
63 SvxPageItem* SvxPageItem::Clone( SfxItemPool * ) const
65 return new SvxPageItem( *this );
68 // Test for equality
69 bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
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 );
78 static OUString GetUsageText( const SvxPageUsage eU )
80 switch( eU )
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();
90 const TranslateId RID_SVXITEMS_PAGE_NUMS[] =
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
100 namespace
102 OUString GetNumberingDescription(SvxNumType eNumType)
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)
110 return SvxNumberingTypeTable::GetString(n);
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);
120 bool SvxPageItem::GetPresentation
122 SfxItemPresentation ePres,
123 MapUnit /*eCoreUnit*/,
124 MapUnit /*ePresUnit*/,
125 OUString& rText, const IntlWrapper&
126 ) const
128 rText.clear();
129 OUString cpDelimTmp(cpDelim);
131 switch ( ePres )
133 case SfxItemPresentation::Nameless:
135 if ( !aDescName.isEmpty() )
137 rText = aDescName + cpDelimTmp;
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())
147 rText += cpDelimTmp + aUsageText;
149 return true;
151 case SfxItemPresentation::Complete:
153 rText += SvxResId(RID_SVXITEMS_PAGE_COMPLETE);
154 if ( !aDescName.isEmpty() )
156 rText += aDescName + cpDelimTmp;
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())
166 rText += cpDelimTmp + aUsageText;
168 return true;
170 default: ;//prevent warning
172 return false;
176 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
178 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
179 nMemberId &= ~CONVERT_TWIPS;
180 switch( nMemberId )
182 case MID_PAGE_NUMTYPE:
184 //! constants aren't in IDLs any more ?!?
185 rVal <<= static_cast<sal_Int16>( eNumType );
187 break;
188 case MID_PAGE_ORIENTATION:
189 rVal <<= bLandscape;
190 break;
191 case MID_PAGE_LAYOUT :
193 style::PageStyleLayout eRet;
194 switch(eUse)
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;
204 rVal <<= eRet;
206 break;
209 return true;
212 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
214 switch( nMemberId & ~CONVERT_TWIPS )
216 case MID_PAGE_NUMTYPE:
218 sal_Int32 nValue = 0;
219 if(!(rVal >>= nValue))
220 return false;
222 eNumType = static_cast<SvxNumType>(nValue);
224 break;
225 case MID_PAGE_ORIENTATION:
226 bLandscape = Any2Bool(rVal);
227 break;
228 case MID_PAGE_LAYOUT :
230 style::PageStyleLayout eLayout;
231 if(!(rVal >>= eLayout))
233 sal_Int32 nValue = 0;
234 if(!(rVal >>= nValue))
235 return false;
236 eLayout = static_cast<style::PageStyleLayout>(nValue);
238 switch( eLayout )
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
247 break;
249 return true;
252 // HeaderFooterSet
253 SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, const SfxItemSet& rSet ) :
255 SfxSetItem( nId, rSet )
259 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) :
261 SfxSetItem( rItem )
265 SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, SfxItemSet&& _pSet ) :
267 SfxSetItem( nId, std::move(_pSet) )
271 SvxSetItem* SvxSetItem::Clone( SfxItemPool * ) const
273 return new SvxSetItem(*this);
276 bool SvxSetItem::GetPresentation
278 SfxItemPresentation /*ePres*/,
279 MapUnit /*eCoreUnit*/,
280 MapUnit /*ePresUnit*/,
281 OUString& rText, const IntlWrapper&
282 ) const
284 rText.clear();
285 return false;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */