LibreOffice Module svx (master) 1
unopool.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 <com/sun/star/lang/XServiceInfo.hpp>
21#include <com/sun/star/beans/PropertyState.hpp>
22
25#include <vcl/svapp.hxx>
26#include <svx/unopool.hxx>
27#include <svx/svdmodel.hxx>
28#include <svx/svdpool.hxx>
29#include <svx/unoprov.hxx>
30#include <svx/unoshprp.hxx>
31#include <svx/xflbstit.hxx>
32#include <svx/xflbmtit.hxx>
33#include <svx/svdetc.hxx>
34#include <editeng/editeng.hxx>
35#include <tools/debug.hxx>
36
37#include <memory>
38
39using namespace ::com::sun::star;
40using namespace ::cppu;
41
43{
44 switch (nServiceId)
45 {
46 case SvxUnoDrawPoolDefaults::Drawing: return SvxPropertySetInfoPool::getDrawingDefaults();
47 case SvxUnoDrawPoolDefaults::Writer: return SvxPropertySetInfoPool::getWriterDrawingDefaults();
48 default: std::abort();
49 }
50}
51
53: PropertySetHelper( getDefaults(nServiceId) ), mpModel( pModel )
54{
55 init();
56}
57
58/* deprecated */
60: PropertySetHelper( SvxPropertySetInfoPool::getDrawingDefaults() ), mpModel( pModel )
61{
62 init();
63}
64
66{
67}
68
70{
73 mpDefaultsPool->SetSecondaryPool(pOutlPool.get());
74
77 mpDefaultsPool->FreezeIdRanges();
78}
79
81{
82 if( mpModel )
83 {
84 return &mpModel->GetItemPool();
85 }
86 else
87 {
88 if( bReadOnly )
89 return mpDefaultsPool.get();
90 else
91 return nullptr;
92 }
93}
94
95void SvxUnoDrawPool::getAny( SfxItemPool const * pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
96{
97 switch( pEntry->mnHandle )
98 {
100 {
101 if (pPool->GetDefaultItem(XATTR_FILLBMP_TILE).GetValue())
102 {
103 rValue <<= drawing::BitmapMode_REPEAT;
104 }
105 else if (pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH).GetValue())
106 {
107 rValue <<= drawing::BitmapMode_STRETCH;
108 }
109 else
110 {
111 rValue <<= drawing::BitmapMode_NO_REPEAT;
112 }
113 break;
114 }
115 default:
116 {
117 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
118
119 sal_uInt8 nMemberId = pEntry->mnMemberId;
120 if( eMapUnit == MapUnit::Map100thMM )
121 nMemberId &= (~CONVERT_TWIPS);
122
123 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
124 // Thus, convert handle to Which-ID.
125 pPool->GetDefaultItem( pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) ) ).QueryValue( rValue, nMemberId );
126 }
127 }
128
129
130 // check for needed metric translation
131 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
132 if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
133 {
134 SvxUnoConvertToMM( eMapUnit, rValue );
135 }
136 // convert int32 to correct enum type if needed
137 else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
138 {
139 sal_Int32 nEnum;
140 rValue >>= nEnum;
141
142 rValue.setValue( &nEnum, pEntry->maType );
143 }
144}
145
147{
148 uno::Any aValue( rValue );
149
150 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
151 if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
152 {
153 SvxUnoConvertFromMM( eMapUnit, aValue );
154 }
155
156 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
157 // Thus, convert handle to Which-ID.
158 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
159 switch( nWhich )
160 {
162 do
163 {
164 drawing::BitmapMode eMode;
165 if(!(aValue >>= eMode) )
166 {
167 sal_Int32 nMode = 0;
168 if(!(aValue >>= nMode))
169 throw lang::IllegalArgumentException();
170
171 eMode = static_cast<drawing::BitmapMode>(nMode);
172 }
173
174 pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
175 pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
176 return;
177 }
178 while(false);
179
180 default:
181 {
182 std::unique_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
183 sal_uInt8 nMemberId = pEntry->mnMemberId;
184 if( pPool->GetMetric(nWhich) == MapUnit::Map100thMM )
185 nMemberId &= (~CONVERT_TWIPS);
186
187 if( !pNewItem->PutValue( aValue, nMemberId ) )
188 throw lang::IllegalArgumentException();
189
190 pPool->SetPoolDefaultItem( *pNewItem );
191 }
192 }
193}
194
196{
197 SolarMutexGuard aGuard;
198
199 SfxItemPool* pPool = getModelPool( false );
200
201 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
202 if( nullptr == pPool )
203 throw beans::UnknownPropertyException( "no pool, no properties..", static_cast<cppu::OWeakObject*>(this));
204
205 while( *ppEntries )
206 putAny( pPool, *ppEntries++, *pValues++ );
207}
208
210{
211 SolarMutexGuard aGuard;
212
213 SfxItemPool* pPool = getModelPool( true );
214
215 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
216 if( nullptr == pPool )
217 throw beans::UnknownPropertyException( "no pool, no properties..", static_cast<cppu::OWeakObject*>(this));
218
219 while( *ppEntries )
220 getAny( pPool, *ppEntries++, *pValue++ );
221}
222
223void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
224{
225 SolarMutexGuard aGuard;
226
227 SfxItemPool* pPool = getModelPool( true );
228
229 if( pPool && pPool != mpDefaultsPool.get() )
230 {
231 while( *ppEntries )
232 {
233 //Assure, that ID is a Which-ID (it could be a Slot-ID.)
234 // Thus, convert handle to Which-ID.
235 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>((*ppEntries)->mnHandle) );
236
237 switch( nWhich )
238 {
240 {
241 // use method <IsStaticDefaultItem(..)> instead of using
242 // probably incompatible item pool <mpDefaultPool>.
245 {
246 *pStates = beans::PropertyState_DEFAULT_VALUE;
247 }
248 else
249 {
250 *pStates = beans::PropertyState_DIRECT_VALUE;
251 }
252 }
253 break;
257 *pStates = beans::PropertyState_DEFAULT_VALUE;
258 else
259 *pStates = beans::PropertyState_DIRECT_VALUE;
260 break;
261 default:
262 //#i18732# - correction:
263 // use method <IsStaticDefaultItem(..)> instead of using probably
264 // incompatible item pool <mpDefaultPool>.
265 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
266 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
267
268 if ( IsStaticDefaultItem( &r1 ) )
269 {
270 *pStates = beans::PropertyState_DEFAULT_VALUE;
271 }
272 else
273 {
274 *pStates = beans::PropertyState_DIRECT_VALUE;
275 }
276 }
277
278 pStates++;
279 ppEntries++;
280 }
281 }
282 else
283 {
284 // as long as we have no model, all properties are default
285 while( *ppEntries++ )
286 *pStates++ = beans::PropertyState_DEFAULT_VALUE;
287 return;
288 }
289}
290
292{
293 SolarMutexGuard aGuard;
294
295 SfxItemPool* pPool = getModelPool( true );
296
297 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
298 // Thus, convert handle to Which-ID.
299 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
300 if ( pPool && pPool != mpDefaultsPool.get() )
301 {
302 // use method <ResetPoolDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>.
303 pPool->ResetPoolDefaultItem( nWhich );
304 }
305}
306
308{
309 SolarMutexGuard aGuard;
310 //#i18732# - use method <GetPoolDefaultItem(..)> instead of
311 // using probably incompatible item pool <mpDefaultsPool>
312 uno::Any aAny;
313 SfxItemPool* pPool = getModelPool( true );
314 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
315 const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
316 if (pItem)
317 {
318 pItem->QueryValue( aAny, pEntry->mnMemberId );
319 }
320
321 return aAny;
322}
323
324// XInterface
325
327{
328 return OWeakAggObject::queryInterface( rType );
329}
330
332{
333 uno::Any aAny;
334
336 aAny <<= uno::Reference< lang::XServiceInfo >(this);
337 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
338 aAny <<= uno::Reference< lang::XTypeProvider >(this);
339 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
340 aAny <<= uno::Reference< beans::XPropertySet >(this);
342 aAny <<= uno::Reference< beans::XPropertyState >(this);
344 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
345 else
346 aAny = OWeakAggObject::queryAggregation( rType );
347
348 return aAny;
349}
350
351uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
352{
353 static const uno::Sequence aTypes {
360 return aTypes;
361}
362
363uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
364{
365 return css::uno::Sequence<sal_Int8>();
366}
367
368// XServiceInfo
369sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const OUString& ServiceName )
370{
372}
373
375{
376 return "SvxUnoDrawPool";
377}
378
379uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames( )
380{
381 uno::Sequence<OUString> aSNS { "com.sun.star.drawing.Defaults" };
382 return aSNS;
383}
384
385/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
static rtl::Reference< SfxItemPool > CreatePool()
void SetTextDefaults() const
Definition: svdmodel.cxx:611
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
void SetPoolDefaultItem(const SfxPoolItem &)
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: unopool.cxx:326
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: unopool.cxx:351
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: unopool.cxx:363
virtual void putAny(SfxItemPool *pPool, const comphelper::PropertyMapEntry *pEntry, const css::uno::Any &rValue)
Definition: unopool.cxx:146
virtual SfxItemPool * getModelPool(bool bReadOnly) noexcept
This returns the item pool from the given model, or the default pool if there is no model and bReadOn...
Definition: unopool.cxx:80
static void getAny(SfxItemPool const *pPool, const comphelper::PropertyMapEntry *pEntry, css::uno::Any &rValue)
Definition: unopool.cxx:95
virtual void _getPropertyStates(const comphelper::PropertyMapEntry **ppEntries, css::beans::PropertyState *pStates) override
Definition: unopool.cxx:223
virtual void _getPropertyValues(const comphelper::PropertyMapEntry **ppEntries, css::uno::Any *pValue) override
Definition: unopool.cxx:209
void init()
Definition: unopool.cxx:69
virtual void _setPropertyToDefault(const comphelper::PropertyMapEntry *pEntry) override
Definition: unopool.cxx:291
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: unopool.cxx:331
virtual OUString SAL_CALL getImplementationName() override
Definition: unopool.cxx:374
virtual ~SvxUnoDrawPool() noexcept override
Definition: unopool.cxx:65
virtual void _setPropertyValues(const comphelper::PropertyMapEntry **ppEntries, const css::uno::Any *pValues) override
Definition: unopool.cxx:195
virtual css::uno::Any _getPropertyDefault(const comphelper::PropertyMapEntry *pEntry) override
Definition: unopool.cxx:307
rtl::Reference< SfxItemPool > mpDefaultsPool
Definition: unopool.hxx:97
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopool.cxx:369
SvxUnoDrawPool(SdrModel *pModel, SvxUnoDrawPoolDefaults nServiceId)
Definition: unopool.cxx:52
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopool.cxx:379
css::uno::Type const & get()
#define DBG_ASSERT(sCon, aError)
bool bReadOnly
Mode eMode
MapUnit
size_t GetFontHeight()
Definition: svdetc.hxx:75
MapUnit GetMapUnit()
Definition: svdetc.hxx:80
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool IsStaticDefaultItem(const SfxPoolItem *pItem)
PropertyMoreFlags mnMoreFlags
void setValue(Type type, object value)
constexpr TypedWhichId< SfxInt16Item > SDRATTR_TEXTCOLUMNS_NUMBER(SDRATTR_TEXTCOLUMNS_FIRST+0)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_TEXTCOLUMNS_SPACING(SDRATTR_TEXTCOLUMNS_FIRST+1)
unsigned char sal_uInt8
unsigned char sal_Bool
void SvxUnoConvertToMM(const MapUnit eSourceMapUnit, uno::Any &rMetric) noexcept
void SvxUnoConvertFromMM(const MapUnit eDestinationMapUnit, uno::Any &rMetric) noexcept
static rtl::Reference< comphelper::PropertySetInfo > const & getDefaults(SvxUnoDrawPoolDefaults nServiceId)
Definition: unopool.cxx:42
SvxUnoDrawPoolDefaults
Definition: unopool.hxx:33
#define OWN_ATTR_FILLBMP_MODE
Definition: unoshprp.hxx:114
#define OWN_ATTR_TEXTCOLUMNS
Definition: unoshprp.hxx:197
constexpr TypedWhichId< XFillBmpStretchItem > XATTR_FILLBMP_STRETCH(XATTR_FILL_FIRST+16)
constexpr TypedWhichId< XFillBmpTileItem > XATTR_FILLBMP_TILE(XATTR_FILL_FIRST+7)
const SvXMLTokenMapEntry aTypes[]