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: PropertySetHelper( xDefaults ), mpModel( pModel )
44{
45 init();
46}
47
49{
50}
51
53{
56 mpDefaultsPool->SetSecondaryPool(pOutlPool.get());
57
60 mpDefaultsPool->FreezeIdRanges();
61}
62
64{
65 if( mpModel )
66 {
67 return &mpModel->GetItemPool();
68 }
69 else
70 {
71 if( bReadOnly )
72 return mpDefaultsPool.get();
73 else
74 return nullptr;
75 }
76}
77
78void SvxUnoDrawPool::getAny( SfxItemPool const * pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
79{
80 switch( pEntry->mnHandle )
81 {
83 {
84 if (pPool->GetDefaultItem(XATTR_FILLBMP_TILE).GetValue())
85 {
86 rValue <<= drawing::BitmapMode_REPEAT;
87 }
88 else if (pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH).GetValue())
89 {
90 rValue <<= drawing::BitmapMode_STRETCH;
91 }
92 else
93 {
94 rValue <<= drawing::BitmapMode_NO_REPEAT;
95 }
96 break;
97 }
98 default:
99 {
100 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
101
102 sal_uInt8 nMemberId = pEntry->mnMemberId;
103 if( eMapUnit == MapUnit::Map100thMM )
104 nMemberId &= (~CONVERT_TWIPS);
105
106 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
107 // Thus, convert handle to Which-ID.
108 pPool->GetDefaultItem( pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) ) ).QueryValue( rValue, nMemberId );
109 }
110 }
111
112
113 // check for needed metric translation
114 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
115 if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
116 {
117 SvxUnoConvertToMM( eMapUnit, rValue );
118 }
119 // convert int32 to correct enum type if needed
120 else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
121 {
122 sal_Int32 nEnum;
123 rValue >>= nEnum;
124
125 rValue.setValue( &nEnum, pEntry->maType );
126 }
127}
128
130{
131 uno::Any aValue( rValue );
132
133 const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
134 if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
135 {
136 SvxUnoConvertFromMM( eMapUnit, aValue );
137 }
138
139 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
140 // Thus, convert handle to Which-ID.
141 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
142 switch( nWhich )
143 {
145 do
146 {
147 drawing::BitmapMode eMode;
148 if(!(aValue >>= eMode) )
149 {
150 sal_Int32 nMode = 0;
151 if(!(aValue >>= nMode))
152 throw lang::IllegalArgumentException();
153
154 eMode = static_cast<drawing::BitmapMode>(nMode);
155 }
156
157 pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
158 pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
159 return;
160 }
161 while(false);
162
163 default:
164 {
165 std::unique_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
166 sal_uInt8 nMemberId = pEntry->mnMemberId;
167 if( pPool->GetMetric(nWhich) == MapUnit::Map100thMM )
168 nMemberId &= (~CONVERT_TWIPS);
169
170 if( !pNewItem->PutValue( aValue, nMemberId ) )
171 throw lang::IllegalArgumentException();
172
173 pPool->SetPoolDefaultItem( *pNewItem );
174 }
175 }
176}
177
179{
180 SolarMutexGuard aGuard;
181
182 SfxItemPool* pPool = getModelPool( false );
183
184 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
185 if( nullptr == pPool )
186 throw beans::UnknownPropertyException( "no pool, no properties..", getXWeak());
187
188 while( *ppEntries )
189 putAny( pPool, *ppEntries++, *pValues++ );
190}
191
193{
194 SolarMutexGuard aGuard;
195
196 SfxItemPool* pPool = getModelPool( true );
197
198 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
199 if( nullptr == pPool )
200 throw beans::UnknownPropertyException( "no pool, no properties..", getXWeak());
201
202 while( *ppEntries )
203 getAny( pPool, *ppEntries++, *pValue++ );
204}
205
206void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
207{
208 SolarMutexGuard aGuard;
209
210 SfxItemPool* pPool = getModelPool( true );
211
212 if( pPool && pPool != mpDefaultsPool.get() )
213 {
214 while( *ppEntries )
215 {
216 //Assure, that ID is a Which-ID (it could be a Slot-ID.)
217 // Thus, convert handle to Which-ID.
218 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>((*ppEntries)->mnHandle) );
219
220 switch( nWhich )
221 {
223 {
224 // use method <IsStaticDefaultItem(..)> instead of using
225 // probably incompatible item pool <mpDefaultPool>.
228 {
229 *pStates = beans::PropertyState_DEFAULT_VALUE;
230 }
231 else
232 {
233 *pStates = beans::PropertyState_DIRECT_VALUE;
234 }
235 }
236 break;
240 *pStates = beans::PropertyState_DEFAULT_VALUE;
241 else
242 *pStates = beans::PropertyState_DIRECT_VALUE;
243 break;
244 default:
245 //#i18732# - correction:
246 // use method <IsStaticDefaultItem(..)> instead of using probably
247 // incompatible item pool <mpDefaultPool>.
248 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
249 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
250
251 if ( IsStaticDefaultItem( &r1 ) )
252 {
253 *pStates = beans::PropertyState_DEFAULT_VALUE;
254 }
255 else
256 {
257 *pStates = beans::PropertyState_DIRECT_VALUE;
258 }
259 }
260
261 pStates++;
262 ppEntries++;
263 }
264 }
265 else
266 {
267 // as long as we have no model, all properties are default
268 while( *ppEntries++ )
269 *pStates++ = beans::PropertyState_DEFAULT_VALUE;
270 return;
271 }
272}
273
275{
276 SolarMutexGuard aGuard;
277
278 SfxItemPool* pPool = getModelPool( true );
279
280 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
281 // Thus, convert handle to Which-ID.
282 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
283 if ( pPool && pPool != mpDefaultsPool.get() )
284 {
285 // use method <ResetPoolDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>.
286 pPool->ResetPoolDefaultItem( nWhich );
287 }
288}
289
291{
292 SolarMutexGuard aGuard;
293 //#i18732# - use method <GetPoolDefaultItem(..)> instead of
294 // using probably incompatible item pool <mpDefaultsPool>
295 uno::Any aAny;
296 SfxItemPool* pPool = getModelPool( true );
297 const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) );
298 const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
299 if (pItem)
300 {
301 pItem->QueryValue( aAny, pEntry->mnMemberId );
302 }
303
304 return aAny;
305}
306
307// XInterface
308
310{
311 return OWeakAggObject::queryInterface( rType );
312}
313
315{
316 uno::Any aAny;
317
319 aAny <<= uno::Reference< lang::XServiceInfo >(this);
320 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
321 aAny <<= uno::Reference< lang::XTypeProvider >(this);
322 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
323 aAny <<= uno::Reference< beans::XPropertySet >(this);
325 aAny <<= uno::Reference< beans::XPropertyState >(this);
327 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
328 else
329 aAny = OWeakAggObject::queryAggregation( rType );
330
331 return aAny;
332}
333
334uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
335{
336 static const uno::Sequence aTypes {
343 return aTypes;
344}
345
346uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
347{
348 return css::uno::Sequence<sal_Int8>();
349}
350
351// XServiceInfo
352sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const OUString& ServiceName )
353{
355}
356
358{
359 return "SvxUnoDrawPool";
360}
361
362uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames( )
363{
364 uno::Sequence<OUString> aSNS { "com.sun.star.drawing.Defaults" };
365 return aSNS;
366}
367
368/* 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
SvxUnoDrawPool(SdrModel *pModel, rtl::Reference< comphelper::PropertySetInfo > const &xDefaults)
Definition: unopool.cxx:42
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: unopool.cxx:309
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: unopool.cxx:334
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: unopool.cxx:346
virtual void putAny(SfxItemPool *pPool, const comphelper::PropertyMapEntry *pEntry, const css::uno::Any &rValue)
Definition: unopool.cxx:129
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:63
static void getAny(SfxItemPool const *pPool, const comphelper::PropertyMapEntry *pEntry, css::uno::Any &rValue)
Definition: unopool.cxx:78
virtual void _getPropertyStates(const comphelper::PropertyMapEntry **ppEntries, css::beans::PropertyState *pStates) override
Definition: unopool.cxx:206
virtual void _getPropertyValues(const comphelper::PropertyMapEntry **ppEntries, css::uno::Any *pValue) override
Definition: unopool.cxx:192
void init()
Definition: unopool.cxx:52
virtual void _setPropertyToDefault(const comphelper::PropertyMapEntry *pEntry) override
Definition: unopool.cxx:274
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: unopool.cxx:314
virtual OUString SAL_CALL getImplementationName() override
Definition: unopool.cxx:357
virtual ~SvxUnoDrawPool() noexcept override
Definition: unopool.cxx:48
virtual void _setPropertyValues(const comphelper::PropertyMapEntry **ppEntries, const css::uno::Any *pValues) override
Definition: unopool.cxx:178
virtual css::uno::Any _getPropertyDefault(const comphelper::PropertyMapEntry *pEntry) override
Definition: unopool.cxx:290
rtl::Reference< SfxItemPool > mpDefaultsPool
Definition: unopool.hxx:91
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopool.cxx:352
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopool.cxx:362
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
#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[]