1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/lang/XServiceInfo.hpp>
21 #include <com/sun/star/beans/PropertyState.hpp>
23 #include <comphelper/propertysetinfo.hxx>
24 #include <cppuhelper/supportsservice.hxx>
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>
39 using namespace ::com::sun::star
;
40 using namespace ::cppu
;
42 static rtl::Reference
<comphelper::PropertySetInfo
> const & getDefaults(SvxUnoDrawPoolDefaults nServiceId
)
46 case SvxUnoDrawPoolDefaults::Drawing
: return SvxPropertySetInfoPool::getDrawingDefaults();
47 case SvxUnoDrawPoolDefaults::Writer
: return SvxPropertySetInfoPool::getWriterDrawingDefaults();
48 default: std::abort();
52 SvxUnoDrawPool::SvxUnoDrawPool(SdrModel
* pModel
, SvxUnoDrawPoolDefaults nServiceId
)
53 : PropertySetHelper( getDefaults(nServiceId
) ), mpModel( pModel
)
59 SvxUnoDrawPool::SvxUnoDrawPool(SdrModel
* pModel
)
60 : PropertySetHelper( SvxPropertySetInfoPool::getDrawingDefaults() ), mpModel( pModel
)
65 SvxUnoDrawPool::~SvxUnoDrawPool() noexcept
69 void SvxUnoDrawPool::init()
71 mpDefaultsPool
= new SdrItemPool();
72 rtl::Reference
<SfxItemPool
> pOutlPool
= EditEngine::CreatePool();
73 mpDefaultsPool
->SetSecondaryPool(pOutlPool
.get());
75 SdrModel::SetTextDefaults( mpDefaultsPool
.get(), SdrEngineDefaults::GetFontHeight() );
76 mpDefaultsPool
->SetDefaultMetric(SdrEngineDefaults::GetMapUnit());
77 mpDefaultsPool
->FreezeIdRanges();
80 SfxItemPool
* SvxUnoDrawPool::getModelPool( bool bReadOnly
) noexcept
84 return &mpModel
->GetItemPool();
89 return mpDefaultsPool
.get();
95 void SvxUnoDrawPool::getAny( SfxItemPool
const * pPool
, const comphelper::PropertyMapEntry
* pEntry
, uno::Any
& rValue
)
97 switch( pEntry
->mnHandle
)
99 case OWN_ATTR_FILLBMP_MODE
:
101 if (pPool
->GetDefaultItem(XATTR_FILLBMP_TILE
).GetValue())
103 rValue
<<= drawing::BitmapMode_REPEAT
;
105 else if (pPool
->GetDefaultItem(XATTR_FILLBMP_STRETCH
).GetValue())
107 rValue
<<= drawing::BitmapMode_STRETCH
;
111 rValue
<<= drawing::BitmapMode_NO_REPEAT
;
117 const MapUnit eMapUnit
= pPool
->GetMetric(static_cast<sal_uInt16
>(pEntry
->mnHandle
));
119 sal_uInt8 nMemberId
= pEntry
->mnMemberId
;
120 if( eMapUnit
== MapUnit::Map100thMM
)
121 nMemberId
&= (~CONVERT_TWIPS
);
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
);
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
)
134 SvxUnoConvertToMM( eMapUnit
, rValue
);
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() )
142 rValue
.setValue( &nEnum
, pEntry
->maType
);
146 void SvxUnoDrawPool::putAny( SfxItemPool
* pPool
, const comphelper::PropertyMapEntry
* pEntry
, const uno::Any
& rValue
)
148 uno::Any
aValue( rValue
);
150 const MapUnit eMapUnit
= pPool
->GetMetric(static_cast<sal_uInt16
>(pEntry
->mnHandle
));
151 if(pEntry
->mnMoreFlags
& PropertyMoreFlags::METRIC_ITEM
&& eMapUnit
!= MapUnit::Map100thMM
)
153 SvxUnoConvertFromMM( eMapUnit
, aValue
);
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
) );
161 case OWN_ATTR_FILLBMP_MODE
:
164 drawing::BitmapMode eMode
;
165 if(!(aValue
>>= eMode
) )
168 if(!(aValue
>>= nMode
))
169 throw lang::IllegalArgumentException();
171 eMode
= static_cast<drawing::BitmapMode
>(nMode
);
174 pPool
->SetPoolDefaultItem( XFillBmpStretchItem( eMode
== drawing::BitmapMode_STRETCH
) );
175 pPool
->SetPoolDefaultItem( XFillBmpTileItem( eMode
== drawing::BitmapMode_REPEAT
) );
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
);
187 if( !pNewItem
->PutValue( aValue
, nMemberId
) )
188 throw lang::IllegalArgumentException();
190 pPool
->SetPoolDefaultItem( *pNewItem
);
195 void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
197 SolarMutexGuard aGuard
;
199 SfxItemPool
* pPool
= getModelPool( false );
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));
206 putAny( pPool
, *ppEntries
++, *pValues
++ );
209 void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
211 SolarMutexGuard aGuard
;
213 SfxItemPool
* pPool
= getModelPool( true );
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));
220 getAny( pPool
, *ppEntries
++, *pValue
++ );
223 void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry
** ppEntries
, beans::PropertyState
* pStates
)
225 SolarMutexGuard aGuard
;
227 SfxItemPool
* pPool
= getModelPool( true );
229 if( pPool
&& pPool
!= mpDefaultsPool
.get() )
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
) );
239 case OWN_ATTR_FILLBMP_MODE
:
241 // use method <IsStaticDefaultItem(..)> instead of using
242 // probably incompatible item pool <mpDefaultPool>.
243 if ( IsStaticDefaultItem( &(pPool
->GetDefaultItem( XATTR_FILLBMP_STRETCH
)) ) ||
244 IsStaticDefaultItem( &(pPool
->GetDefaultItem( XATTR_FILLBMP_TILE
)) ) )
246 *pStates
= beans::PropertyState_DEFAULT_VALUE
;
250 *pStates
= beans::PropertyState_DIRECT_VALUE
;
254 case OWN_ATTR_TEXTCOLUMNS
:
255 if (IsStaticDefaultItem(&pPool
->GetDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_NUMBER
)))
256 && IsStaticDefaultItem(&pPool
->GetDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_SPACING
))))
257 *pStates
= beans::PropertyState_DEFAULT_VALUE
;
259 *pStates
= beans::PropertyState_DIRECT_VALUE
;
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 );
268 if ( IsStaticDefaultItem( &r1
) )
270 *pStates
= beans::PropertyState_DEFAULT_VALUE
;
274 *pStates
= beans::PropertyState_DIRECT_VALUE
;
284 // as long as we have no model, all properties are default
285 while( *ppEntries
++ )
286 *pStates
++ = beans::PropertyState_DEFAULT_VALUE
;
291 void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry
* pEntry
)
293 SolarMutexGuard aGuard
;
295 SfxItemPool
* pPool
= getModelPool( true );
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() )
302 // use method <ResetPoolDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>.
303 pPool
->ResetPoolDefaultItem( nWhich
);
307 uno::Any
SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry
* pEntry
)
309 SolarMutexGuard aGuard
;
310 //#i18732# - use method <GetPoolDefaultItem(..)> instead of
311 // using probably incompatible item pool <mpDefaultsPool>
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
);
318 pItem
->QueryValue( aAny
, pEntry
->mnMemberId
);
326 uno::Any SAL_CALL
SvxUnoDrawPool::queryInterface( const uno::Type
& rType
)
328 return OWeakAggObject::queryInterface( rType
);
331 uno::Any SAL_CALL
SvxUnoDrawPool::queryAggregation( const uno::Type
& rType
)
335 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
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);
341 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
342 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
343 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
344 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
346 aAny
= OWeakAggObject::queryAggregation( rType
);
351 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoDrawPool::getTypes()
353 static const uno::Sequence aTypes
{
354 cppu::UnoType
<uno::XAggregation
>::get(),
355 cppu::UnoType
<lang::XServiceInfo
>::get(),
356 cppu::UnoType
<lang::XTypeProvider
>::get(),
357 cppu::UnoType
<beans::XPropertySet
>::get(),
358 cppu::UnoType
<beans::XPropertyState
>::get(),
359 cppu::UnoType
<beans::XMultiPropertySet
>::get() };
363 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoDrawPool::getImplementationId()
365 return css::uno::Sequence
<sal_Int8
>();
369 sal_Bool SAL_CALL
SvxUnoDrawPool::supportsService( const OUString
& ServiceName
)
371 return cppu::supportsService(this, ServiceName
);
374 OUString SAL_CALL
SvxUnoDrawPool::getImplementationName()
376 return "SvxUnoDrawPool";
379 uno::Sequence
< OUString
> SAL_CALL
SvxUnoDrawPool::getSupportedServiceNames( )
381 uno::Sequence
<OUString
> aSNS
{ "com.sun.star.drawing.Defaults" };
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */