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