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