1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <comphelper/propertysetinfo.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <editeng/unoipset.hxx>
#include <vcl/svapp.hxx>
#include <svx/unopool.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdpool.hxx>
#include <svx/unoshprp.hxx>
#include <svx/xflbstit.hxx>
#include <svx/xflbmtit.hxx>
#include <svx/svdetc.hxx>
#include <editeng/editeng.hxx>
#include <tools/debug.hxx>
#include <memory>
using namespace ::com::sun::star;
using namespace ::cppu;
SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel, rtl::Reference<comphelper::PropertySetInfo> const & xDefaults)
: SvxUnoDrawPool_Base(), PropertySetHelper( xDefaults ), mpModel( pModel )
{
init();
}
SvxUnoDrawPool::~SvxUnoDrawPool() noexcept
{
}
void SvxUnoDrawPool::init()
{
mpDefaultsPool = new SdrItemPool();
rtl::Reference<SfxItemPool> pOutlPool = EditEngine::CreatePool();
mpDefaultsPool->SetSecondaryPool(pOutlPool.get());
SdrModel::SetTextDefaults( mpDefaultsPool.get(), SdrEngineDefaults::GetFontHeight() );
mpDefaultsPool->SetDefaultMetric(SdrEngineDefaults::GetMapUnit());
}
SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) noexcept
{
if( mpModel )
{
return &mpModel->GetItemPool();
}
else
{
if( bReadOnly )
return mpDefaultsPool.get();
else
return nullptr;
}
}
void SvxUnoDrawPool::getAny( SfxItemPool const * pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
{
switch( pEntry->mnHandle )
{
case OWN_ATTR_FILLBMP_MODE:
{
if (pPool->GetUserOrPoolDefaultItem(XATTR_FILLBMP_TILE).GetValue())
{
rValue <<= drawing::BitmapMode_REPEAT;
}
else if (pPool->GetUserOrPoolDefaultItem(XATTR_FILLBMP_STRETCH).GetValue())
{
rValue <<= drawing::BitmapMode_STRETCH;
}
else
{
rValue <<= drawing::BitmapMode_NO_REPEAT;
}
break;
}
default:
{
const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
sal_uInt8 nMemberId = pEntry->mnMemberId;
if( eMapUnit == MapUnit::Map100thMM )
nMemberId &= (~CONVERT_TWIPS);
// Assure, that ID is a Which-ID (it could be a Slot-ID.)
// Thus, convert handle to Which-ID.
pPool->GetUserOrPoolDefaultItem( pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) ) ).QueryValue( rValue, nMemberId );
}
}
// check for needed metric translation
const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
{
SvxUnoConvertToMM( eMapUnit, rValue );
}
// convert int32 to correct enum type if needed
else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
{
sal_Int32 nEnum;
rValue >>= nEnum;
rValue.setValue( &nEnum, pEntry->maType );
}
}
void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
{
uno::Any aValue( rValue );
const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
{
SvxUnoConvertFromMM( eMapUnit, aValue );
}
// Assure, that ID is a Which-ID (it could be a Slot-ID.)
// Thus, convert handle to Which-ID.
const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
switch( nWhich )
{
case OWN_ATTR_FILLBMP_MODE:
do
{
drawing::BitmapMode eMode;
if(!(aValue >>= eMode) )
{
sal_Int32 nMode = 0;
if(!(aValue >>= nMode))
throw lang::IllegalArgumentException();
eMode = static_cast<drawing::BitmapMode>(nMode);
}
pPool->SetUserDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
pPool->SetUserDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
return;
}
while(false);
default:
{
std::unique_ptr<SfxPoolItem> pNewItem( pPool->GetUserOrPoolDefaultItem( nWhich ).Clone() );
sal_uInt8 nMemberId = pEntry->mnMemberId;
if( pPool->GetMetric(nWhich) == MapUnit::Map100thMM )
nMemberId &= (~CONVERT_TWIPS);
if( !pNewItem->PutValue( aValue, nMemberId ) )
throw lang::IllegalArgumentException();
pPool->SetUserDefaultItem( *pNewItem );
}
}
}
void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
{
SolarMutexGuard aGuard;
SfxItemPool* pPool = getModelPool( false );
DBG_ASSERT( pPool, "I need a SfxItemPool!" );
if( nullptr == pPool )
throw beans::UnknownPropertyException( u"no pool, no properties.."_ustr, getXWeak());
while( *ppEntries )
putAny( pPool, *ppEntries++, *pValues++ );
}
void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
{
SolarMutexGuard aGuard;
SfxItemPool* pPool = getModelPool( true );
DBG_ASSERT( pPool, "I need a SfxItemPool!" );
if( nullptr == pPool )
throw beans::UnknownPropertyException( u"no pool, no properties.."_ustr, getXWeak());
while( *ppEntries )
getAny( pPool, *ppEntries++, *pValue++ );
}
void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
{
SolarMutexGuard aGuard;
SfxItemPool* pPool = getModelPool( true );
if( pPool && pPool != mpDefaultsPool.get() )
{
while( *ppEntries )
{
//Assure, that ID is a Which-ID (it could be a Slot-ID.)
// Thus, convert handle to Which-ID.
const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>((*ppEntries)->mnHandle) );
switch( nWhich )
{
case OWN_ATTR_FILLBMP_MODE:
{
// use method <IsStaticDefaultItem(..)> instead of using
// probably incompatible item pool <mpDefaultPool>.
if ( IsStaticDefaultItem( &(pPool->GetUserOrPoolDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
IsStaticDefaultItem( &(pPool->GetUserOrPoolDefaultItem( XATTR_FILLBMP_TILE )) ) )
{
*pStates = beans::PropertyState_DEFAULT_VALUE;
}
else
{
*pStates = beans::PropertyState_DIRECT_VALUE;
}
}
break;
case OWN_ATTR_TEXTCOLUMNS:
if (IsStaticDefaultItem(&pPool->GetUserOrPoolDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_NUMBER)))
&& IsStaticDefaultItem(&pPool->GetUserOrPoolDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_SPACING))))
*pStates = beans::PropertyState_DEFAULT_VALUE;
else
*pStates = beans::PropertyState_DIRECT_VALUE;
break;
default:
//#i18732# - correction:
// use method <IsStaticDefaultItem(..)> instead of using probably
// incompatible item pool <mpDefaultPool>.
const SfxPoolItem& r1 = pPool->GetUserOrPoolDefaultItem( nWhich );
//const SfxPoolItem& r2 = mpDefaultPool->GetUserOrPoolDefaultItem( nWhich );
if ( IsStaticDefaultItem( &r1 ) )
{
*pStates = beans::PropertyState_DEFAULT_VALUE;
}
else
{
*pStates = beans::PropertyState_DIRECT_VALUE;
}
}
pStates++;
ppEntries++;
}
}
else
{
// as long as we have no model, all properties are default
while( *ppEntries++ )
*pStates++ = beans::PropertyState_DEFAULT_VALUE;
return;
}
}
void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
{
SolarMutexGuard aGuard;
SfxItemPool* pPool = getModelPool( true );
// Assure, that ID is a Which-ID (it could be a Slot-ID.)
// Thus, convert handle to Which-ID.
const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
if ( pPool && pPool != mpDefaultsPool.get() )
{
// use method <ResetUserDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>.
pPool->ResetUserDefaultItem( nWhich );
}
}
uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
{
SolarMutexGuard aGuard;
//#i18732# - use method <GetUserDefaultItem(..)> instead of
// using probably incompatible item pool <mpDefaultsPool>
uno::Any aAny;
SfxItemPool* pPool = getModelPool( true );
const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
const SfxPoolItem *pItem = pPool->GetUserDefaultItem ( nWhich );
if (pItem)
{
pItem->QueryValue( aAny, pEntry->mnMemberId );
}
return aAny;
}
// XInterface
uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
{
uno::Any aAny;
if( rType == cppu::UnoType<lang::XServiceInfo>::get())
aAny <<= uno::Reference< lang::XServiceInfo >(this);
else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
aAny <<= uno::Reference< lang::XTypeProvider >(this);
else if( rType == cppu::UnoType<beans::XPropertySet>::get())
aAny <<= uno::Reference< beans::XPropertySet >(this);
else if( rType == cppu::UnoType<beans::XPropertyState>::get())
aAny <<= uno::Reference< beans::XPropertyState >(this);
else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
else
aAny = OWeakObject::queryInterface( rType );
return aAny;
}
uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
{
static const uno::Sequence aTypes {
cppu::UnoType<lang::XServiceInfo>::get(),
cppu::UnoType<lang::XTypeProvider>::get(),
cppu::UnoType<beans::XPropertySet>::get(),
cppu::UnoType<beans::XPropertyState>::get(),
cppu::UnoType<beans::XMultiPropertySet>::get() };
return aTypes;
}
uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
{
return css::uno::Sequence<sal_Int8>();
}
// XServiceInfo
sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const OUString& ServiceName )
{
return cppu::supportsService(this, ServiceName);
}
OUString SAL_CALL SvxUnoDrawPool::getImplementationName()
{
return u"SvxUnoDrawPool"_ustr;
}
uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames( )
{
uno::Sequence<OUString> aSNS { u"com.sun.star.drawing.Defaults"_ustr };
return aSNS;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|