/src/libreoffice/sd/source/ui/unoidl/unolayer.cxx
Line | Count | Source (jump to first uncovered line) |
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/DisposedException.hpp> |
21 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
22 | | |
23 | | #include <unolayer.hxx> |
24 | | |
25 | | #include <comphelper/extract.hxx> |
26 | | #include <editeng/unoipset.hxx> |
27 | | #include <osl/diagnose.h> |
28 | | #include <svl/itemprop.hxx> |
29 | | #include <svx/svdpagv.hxx> |
30 | | #include <svx/svdobj.hxx> |
31 | | #include <cppuhelper/supportsservice.hxx> |
32 | | |
33 | | // following ones for InsertSdPage() |
34 | | #include <svx/svdlayer.hxx> |
35 | | |
36 | | #include <DrawDocShell.hxx> |
37 | | #include <drawdoc.hxx> |
38 | | #include <unomodel.hxx> |
39 | | #include <unoprnms.hxx> |
40 | | #include <com/sun/star/lang/NoSupportException.hpp> |
41 | | #include <svx/svdpool.hxx> |
42 | | #include <FrameView.hxx> |
43 | | #include <DrawViewShell.hxx> |
44 | | #include <View.hxx> |
45 | | #include <ViewShell.hxx> |
46 | | #include <strings.hrc> |
47 | | #include <sdresid.hxx> |
48 | | |
49 | | #include "unowcntr.hxx" |
50 | | #include <vcl/svapp.hxx> |
51 | | |
52 | | using namespace ::com::sun::star; |
53 | | |
54 | | // class SdLayer |
55 | 4.61k | #define WID_LAYER_LOCKED 1 |
56 | 4.61k | #define WID_LAYER_PRINTABLE 2 |
57 | 4.61k | #define WID_LAYER_VISIBLE 3 |
58 | 2.44k | #define WID_LAYER_NAME 4 |
59 | 4.61k | #define WID_LAYER_TITLE 5 |
60 | 4.61k | #define WID_LAYER_DESC 6 |
61 | | |
62 | | static const SvxItemPropertySet* ImplGetSdLayerPropertySet() |
63 | 2.30k | { |
64 | 2.30k | static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] = |
65 | 2.30k | { |
66 | 2.30k | { u"" UNO_NAME_LAYER_LOCKED ""_ustr, WID_LAYER_LOCKED, cppu::UnoType<bool>::get(), 0, 0 }, |
67 | 2.30k | { u"" UNO_NAME_LAYER_PRINTABLE ""_ustr, WID_LAYER_PRINTABLE,cppu::UnoType<bool>::get(), 0, 0 }, |
68 | 2.30k | { u"" UNO_NAME_LAYER_VISIBLE ""_ustr, WID_LAYER_VISIBLE, cppu::UnoType<bool>::get(), 0, 0 }, |
69 | 2.30k | { u"" UNO_NAME_LAYER_NAME ""_ustr, WID_LAYER_NAME, ::cppu::UnoType<OUString>::get(), 0, 0 }, |
70 | 2.30k | { u"Title"_ustr, WID_LAYER_TITLE, ::cppu::UnoType<OUString>::get(), 0, 0 }, |
71 | 2.30k | { u"Description"_ustr, WID_LAYER_DESC, ::cppu::UnoType<OUString>::get(), 0, 0 }, |
72 | 2.30k | }; |
73 | 2.30k | static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() ); |
74 | 2.30k | return &aSDLayerPropertySet_Impl; |
75 | 2.30k | } |
76 | | |
77 | | SdLayer::SdLayer(SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_) |
78 | 2.30k | : mxLayerManager(pLayerManager_) |
79 | 2.30k | , pLayer(pSdrLayer_) |
80 | 2.30k | , pPropSet(ImplGetSdLayerPropertySet()) |
81 | 2.30k | { |
82 | | // no defaults possible yet, a "set" would overwrite existing information |
83 | | // in view, which is currently needed for saving, because pLayer is not updated |
84 | | // from view. |
85 | 2.30k | } |
86 | | |
87 | | SdLayer::~SdLayer() noexcept |
88 | 2.30k | { |
89 | 2.30k | } |
90 | | |
91 | | // XServiceInfo |
92 | | OUString SAL_CALL SdLayer::getImplementationName() |
93 | 0 | { |
94 | 0 | return u"SdUnoLayer"_ustr; |
95 | 0 | } |
96 | | |
97 | | sal_Bool SAL_CALL SdLayer::supportsService( const OUString& ServiceName ) |
98 | 0 | { |
99 | 0 | return cppu::supportsService( this, ServiceName ); |
100 | 0 | } |
101 | | |
102 | | uno::Sequence< OUString > SAL_CALL SdLayer::getSupportedServiceNames() |
103 | 0 | { |
104 | 0 | return { u"com.sun.star.drawing.Layer"_ustr }; |
105 | 0 | } |
106 | | |
107 | | // beans::XPropertySet |
108 | | uno::Reference< beans::XPropertySetInfo > SAL_CALL SdLayer::getPropertySetInfo( ) |
109 | 0 | { |
110 | 0 | SolarMutexGuard aGuard; |
111 | 0 | return pPropSet->getPropertySetInfo(); |
112 | 0 | } |
113 | | |
114 | | void SAL_CALL SdLayer::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) |
115 | 11.6k | { |
116 | 11.6k | SolarMutexGuard aGuard; |
117 | | |
118 | 11.6k | if(pLayer == nullptr || mxLayerManager == nullptr) |
119 | 0 | throw lang::DisposedException(); |
120 | | |
121 | 11.6k | const SfxItemPropertyMapEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName); |
122 | | |
123 | 11.6k | switch( pEntry ? pEntry->nWID : -1 ) |
124 | 11.6k | { |
125 | 2.30k | case WID_LAYER_LOCKED: |
126 | 2.30k | { |
127 | 2.30k | pLayer->SetLockedODF( cppu::any2bool(aValue) ); |
128 | 2.30k | set(LOCKED, cppu::any2bool(aValue)); // changes the View, if any exists |
129 | 2.30k | break; |
130 | 0 | } |
131 | 2.30k | case WID_LAYER_PRINTABLE: |
132 | 2.30k | { |
133 | 2.30k | pLayer->SetPrintableODF( cppu::any2bool(aValue) ); |
134 | 2.30k | set(PRINTABLE, cppu::any2bool(aValue)); // changes the View, if any exists |
135 | 2.30k | break; |
136 | 0 | } |
137 | 2.30k | case WID_LAYER_VISIBLE: |
138 | 2.30k | { |
139 | 2.30k | pLayer->SetVisibleODF( cppu::any2bool(aValue) ); |
140 | 2.30k | set(VISIBLE, cppu::any2bool(aValue)); // changes the View, if any exists |
141 | 2.30k | break; |
142 | 0 | } |
143 | 138 | case WID_LAYER_NAME: |
144 | 138 | { |
145 | 138 | OUString aName; |
146 | 138 | if(!(aValue >>= aName)) |
147 | 0 | throw lang::IllegalArgumentException(); |
148 | | |
149 | 138 | pLayer->SetName(aName); |
150 | 138 | mxLayerManager->UpdateLayerView(); |
151 | 138 | break; |
152 | 138 | } |
153 | | |
154 | 2.30k | case WID_LAYER_TITLE: |
155 | 2.30k | { |
156 | 2.30k | OUString sTitle; |
157 | 2.30k | if(!(aValue >>= sTitle)) |
158 | 0 | throw lang::IllegalArgumentException(); |
159 | | |
160 | 2.30k | pLayer->SetTitle(sTitle); |
161 | 2.30k | break; |
162 | 2.30k | } |
163 | | |
164 | 2.30k | case WID_LAYER_DESC: |
165 | 2.30k | { |
166 | 2.30k | OUString sDescription; |
167 | 2.30k | if(!(aValue >>= sDescription)) |
168 | 0 | throw lang::IllegalArgumentException(); |
169 | | |
170 | 2.30k | pLayer->SetDescription(sDescription); |
171 | 2.30k | break; |
172 | 2.30k | } |
173 | | |
174 | 0 | default: |
175 | 0 | throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this)); |
176 | 11.6k | } |
177 | | |
178 | 11.6k | if( mxLayerManager->GetDocShell() ) |
179 | 11.6k | mxLayerManager->GetDocShell()->SetModified(); |
180 | 11.6k | } |
181 | | |
182 | | uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName ) |
183 | 0 | { |
184 | 0 | SolarMutexGuard aGuard; |
185 | |
|
186 | 0 | if(pLayer == nullptr || mxLayerManager == nullptr) |
187 | 0 | throw lang::DisposedException(); |
188 | | |
189 | 0 | const SfxItemPropertyMapEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName); |
190 | |
|
191 | 0 | uno::Any aValue; |
192 | |
|
193 | 0 | switch( pEntry ? pEntry->nWID : -1 ) |
194 | 0 | { |
195 | 0 | case WID_LAYER_LOCKED: |
196 | 0 | aValue <<= get( LOCKED ); |
197 | 0 | break; |
198 | 0 | case WID_LAYER_PRINTABLE: |
199 | 0 | aValue <<= get( PRINTABLE ); |
200 | 0 | break; |
201 | 0 | case WID_LAYER_VISIBLE: |
202 | 0 | aValue <<= get( VISIBLE ); |
203 | 0 | break; |
204 | 0 | case WID_LAYER_NAME: |
205 | 0 | { |
206 | 0 | OUString aRet(pLayer->GetName()); |
207 | 0 | aValue <<= aRet; |
208 | 0 | break; |
209 | 0 | } |
210 | 0 | case WID_LAYER_TITLE: |
211 | 0 | aValue <<= pLayer->GetTitle(); |
212 | 0 | break; |
213 | 0 | case WID_LAYER_DESC: |
214 | 0 | aValue <<= pLayer->GetDescription(); |
215 | 0 | break; |
216 | 0 | default: |
217 | 0 | throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this)); |
218 | 0 | } |
219 | | |
220 | 0 | return aValue; |
221 | 0 | } |
222 | | |
223 | 0 | void SAL_CALL SdLayer::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {} |
224 | 0 | void SAL_CALL SdLayer::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {} |
225 | 0 | void SAL_CALL SdLayer::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {} |
226 | 0 | void SAL_CALL SdLayer::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {} |
227 | | |
228 | | bool SdLayer::get( LayerAttribute what ) noexcept |
229 | 0 | { |
230 | 0 | if(pLayer && mxLayerManager.is()) |
231 | 0 | { |
232 | | // Try 1. is an arbitrary page open? |
233 | 0 | ::sd::View *pView = mxLayerManager->GetView(); |
234 | 0 | SdrPageView* pSdrPageView = nullptr; |
235 | 0 | if(pView) |
236 | 0 | pSdrPageView = pView->GetSdrPageView(); |
237 | |
|
238 | 0 | if(pSdrPageView) |
239 | 0 | { |
240 | 0 | OUString aLayerName = pLayer->GetName(); |
241 | 0 | switch(what) |
242 | 0 | { |
243 | 0 | case VISIBLE: return pSdrPageView->IsLayerVisible(aLayerName); |
244 | 0 | case PRINTABLE: return pSdrPageView->IsLayerPrintable(aLayerName); |
245 | 0 | case LOCKED: return pSdrPageView->IsLayerLocked(aLayerName); |
246 | 0 | } |
247 | 0 | } |
248 | | |
249 | | // Try 2. get info from FrameView |
250 | 0 | if(mxLayerManager->GetDocShell()) |
251 | 0 | { |
252 | 0 | ::sd::FrameView *pFrameView = mxLayerManager->GetDocShell()->GetFrameView(); |
253 | 0 | if(pFrameView) |
254 | 0 | switch(what) |
255 | 0 | { |
256 | 0 | case VISIBLE: return pFrameView->GetVisibleLayers().IsSet(pLayer->GetID()); |
257 | 0 | case PRINTABLE: return pFrameView->GetPrintableLayers().IsSet(pLayer->GetID()); |
258 | 0 | case LOCKED: return pFrameView->GetLockedLayers().IsSet(pLayer->GetID()); |
259 | 0 | } |
260 | 0 | } |
261 | | |
262 | | // no view at all, e.g. Draw embedded as OLE in text document, ODF default values |
263 | 0 | switch(what) |
264 | 0 | { |
265 | 0 | case VISIBLE: return true; |
266 | 0 | case PRINTABLE: return true; |
267 | 0 | case LOCKED: return false; |
268 | 0 | } |
269 | |
|
270 | 0 | } |
271 | 0 | return false; //TODO: uno::Exception? |
272 | 0 | } |
273 | | |
274 | | void SdLayer::set( LayerAttribute what, bool flag ) noexcept |
275 | 6.91k | { |
276 | 6.91k | if(!(pLayer && mxLayerManager.is())) |
277 | 0 | return; |
278 | | |
279 | | // Try 1. is an arbitrary page open? |
280 | 6.91k | ::sd::View *pView = mxLayerManager->GetView(); |
281 | 6.91k | SdrPageView* pSdrPageView = nullptr; |
282 | 6.91k | if(pView) |
283 | 0 | pSdrPageView = pView->GetSdrPageView(); |
284 | | |
285 | 6.91k | if(pSdrPageView) |
286 | 0 | { |
287 | 0 | OUString aLayerName(pLayer->GetName()); |
288 | 0 | switch(what) |
289 | 0 | { |
290 | 0 | case VISIBLE: pSdrPageView->SetLayerVisible(aLayerName,flag); |
291 | 0 | break; |
292 | 0 | case PRINTABLE: pSdrPageView->SetLayerPrintable(aLayerName,flag); |
293 | 0 | break; |
294 | 0 | case LOCKED: pSdrPageView->SetLayerLocked(aLayerName,flag); |
295 | 0 | break; |
296 | 0 | } |
297 | 0 | } |
298 | | |
299 | | // Try 2. get info from FrameView |
300 | 6.91k | if(!mxLayerManager->GetDocShell()) |
301 | 0 | return; |
302 | | |
303 | 6.91k | ::sd::FrameView *pFrameView = mxLayerManager->GetDocShell()->GetFrameView(); |
304 | | |
305 | 6.91k | if(!pFrameView) |
306 | 6.91k | return; |
307 | | |
308 | 0 | SdrLayerIDSet aNewLayers; |
309 | 0 | switch(what) |
310 | 0 | { |
311 | 0 | case VISIBLE: aNewLayers = pFrameView->GetVisibleLayers(); |
312 | 0 | break; |
313 | 0 | case PRINTABLE: aNewLayers = pFrameView->GetPrintableLayers(); |
314 | 0 | break; |
315 | 0 | case LOCKED: aNewLayers = pFrameView->GetLockedLayers(); |
316 | 0 | break; |
317 | 0 | } |
318 | | |
319 | 0 | aNewLayers.Set(pLayer->GetID(),flag); |
320 | |
|
321 | 0 | switch(what) |
322 | 0 | { |
323 | 0 | case VISIBLE: pFrameView->SetVisibleLayers(aNewLayers); |
324 | 0 | break; |
325 | 0 | case PRINTABLE: pFrameView->SetPrintableLayers(aNewLayers); |
326 | 0 | break; |
327 | 0 | case LOCKED: pFrameView->SetLockedLayers(aNewLayers); |
328 | 0 | break; |
329 | 0 | } |
330 | 0 | return; |
331 | | //TODO: uno::Exception? |
332 | 0 | } |
333 | | |
334 | | // css::container::XChild |
335 | | uno::Reference<uno::XInterface> SAL_CALL SdLayer::getParent() |
336 | 0 | { |
337 | 0 | SolarMutexGuard aGuard; |
338 | |
|
339 | 0 | if( !mxLayerManager.is() ) |
340 | 0 | throw lang::DisposedException(); |
341 | | |
342 | 0 | return uno::Reference<uno::XInterface> (static_cast<cppu::OWeakObject*>(mxLayerManager.get()), uno::UNO_QUERY); |
343 | 0 | } |
344 | | |
345 | | void SAL_CALL SdLayer::setParent (const uno::Reference<uno::XInterface >& ) |
346 | 0 | { |
347 | 0 | throw lang::NoSupportException (); |
348 | 0 | } |
349 | | |
350 | | // XComponent |
351 | | void SAL_CALL SdLayer::dispose( ) |
352 | 0 | { |
353 | 0 | mxLayerManager.clear(); |
354 | 0 | pLayer = nullptr; |
355 | 0 | } |
356 | | |
357 | | void SAL_CALL SdLayer::addEventListener( const uno::Reference< lang::XEventListener >& ) |
358 | 0 | { |
359 | 0 | OSL_FAIL("not implemented!"); |
360 | 0 | } |
361 | | |
362 | | void SAL_CALL SdLayer::removeEventListener( const uno::Reference< lang::XEventListener >& ) |
363 | 0 | { |
364 | 0 | OSL_FAIL("not implemented!"); |
365 | 0 | } |
366 | | |
367 | | // class SdLayerManager |
368 | | SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) noexcept |
369 | 479 | :mpModel( &rMyModel) |
370 | 479 | { |
371 | 479 | mpLayers.reset(new SvUnoWeakContainer); |
372 | 479 | } |
373 | | |
374 | | SdLayerManager::~SdLayerManager() noexcept |
375 | 479 | { |
376 | 479 | dispose(); |
377 | 479 | } |
378 | | |
379 | | // XComponent |
380 | | void SAL_CALL SdLayerManager::dispose( ) |
381 | 479 | { |
382 | 479 | mpModel = nullptr; |
383 | 479 | if( mpLayers ) |
384 | 479 | { |
385 | 479 | mpLayers->dispose(); |
386 | 479 | mpLayers.reset(); |
387 | 479 | } |
388 | 479 | } |
389 | | |
390 | | void SAL_CALL SdLayerManager::addEventListener( const uno::Reference< lang::XEventListener >& ) |
391 | 0 | { |
392 | 0 | OSL_FAIL("not implemented!"); |
393 | 0 | } |
394 | | |
395 | | void SAL_CALL SdLayerManager::removeEventListener( const uno::Reference< lang::XEventListener >& ) |
396 | 0 | { |
397 | 0 | OSL_FAIL("not implemented!"); |
398 | 0 | } |
399 | | |
400 | | // XServiceInfo |
401 | | OUString SAL_CALL SdLayerManager::getImplementationName() |
402 | 0 | { |
403 | 0 | return u"SdUnoLayerManager"_ustr; |
404 | 0 | } |
405 | | |
406 | | sal_Bool SAL_CALL SdLayerManager::supportsService( const OUString& ServiceName ) |
407 | 0 | { |
408 | 0 | return cppu::supportsService( this, ServiceName ); |
409 | 0 | } |
410 | | |
411 | | uno::Sequence< OUString > SAL_CALL SdLayerManager::getSupportedServiceNames() |
412 | 0 | { |
413 | 0 | return {u"com.sun.star.drawing.LayerManager"_ustr}; |
414 | 0 | } |
415 | | |
416 | | // XLayerManager |
417 | | uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex ) |
418 | 138 | { |
419 | 138 | SolarMutexGuard aGuard; |
420 | | |
421 | 138 | if( mpModel == nullptr ) |
422 | 0 | throw lang::DisposedException(); |
423 | | |
424 | 138 | rtl::Reference< SdLayer > xLayer; |
425 | | |
426 | 138 | if( mpModel->mpDoc ) |
427 | 138 | { |
428 | 138 | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
429 | 138 | sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount(); |
430 | 138 | sal_Int32 nLayer = nLayerCnt - 2 + 1; |
431 | 138 | OUString aLayerName; |
432 | | |
433 | | // Test for existing names |
434 | 276 | while( aLayerName.isEmpty() || rLayerAdmin.GetLayer( aLayerName ) ) |
435 | 138 | { |
436 | 138 | aLayerName = SdResId(STR_LAYER) + OUString::number(nLayer); |
437 | 138 | ++nLayer; |
438 | 138 | } |
439 | | |
440 | 138 | SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin(); |
441 | 138 | const sal_Int32 nMax=rLA.GetLayerCount(); |
442 | 138 | if (nIndex>nMax) nIndex=nMax; |
443 | 138 | xLayer = GetLayer (rLA.NewLayer(aLayerName,static_cast<sal_uInt16>(nIndex))); |
444 | 138 | mpModel->SetModified(); |
445 | 138 | } |
446 | 138 | return xLayer; |
447 | 138 | } |
448 | | |
449 | | void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer ) |
450 | 0 | { |
451 | 0 | SolarMutexGuard aGuard; |
452 | |
|
453 | 0 | if( mpModel == nullptr ) |
454 | 0 | throw lang::DisposedException(); |
455 | | |
456 | 0 | SdLayer* pSdLayer = dynamic_cast<SdLayer*>(xLayer.get()); |
457 | |
|
458 | 0 | if(pSdLayer && GetView()) |
459 | 0 | { |
460 | 0 | const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer(); |
461 | 0 | GetView()->DeleteLayer( pSdrLayer->GetName() ); |
462 | |
|
463 | 0 | UpdateLayerView(); |
464 | 0 | } |
465 | |
|
466 | 0 | mpModel->SetModified(); |
467 | 0 | } |
468 | | |
469 | | void SAL_CALL SdLayerManager::attachShapeToLayer( const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XLayer >& xLayer ) |
470 | 0 | { |
471 | 0 | SolarMutexGuard aGuard; |
472 | |
|
473 | 0 | if( mpModel == nullptr ) |
474 | 0 | throw lang::DisposedException(); |
475 | | |
476 | 0 | SdLayer* pSdLayer = dynamic_cast<SdLayer*>(xLayer.get()); |
477 | 0 | if(pSdLayer==nullptr) |
478 | 0 | return; |
479 | 0 | SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer(); |
480 | 0 | if(pSdrLayer==nullptr) |
481 | 0 | return; |
482 | | |
483 | 0 | SdrObject* pSdrObject = SdrObject::getSdrObjectFromXShape( xShape ); |
484 | |
|
485 | 0 | if(pSdrObject) |
486 | 0 | pSdrObject->SetLayer(pSdrLayer->GetID()); |
487 | |
|
488 | 0 | mpModel->SetModified(); |
489 | 0 | } |
490 | | |
491 | | uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) |
492 | 0 | { |
493 | 0 | SolarMutexGuard aGuard; |
494 | |
|
495 | 0 | if( mpModel == nullptr ) |
496 | 0 | throw lang::DisposedException(); |
497 | | |
498 | 0 | if(!mpModel->mpDoc) |
499 | 0 | return nullptr; |
500 | | |
501 | 0 | SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape ); |
502 | 0 | if(!pObj) |
503 | 0 | return nullptr; |
504 | | |
505 | 0 | SdrLayerID aId = pObj->GetLayer(); |
506 | 0 | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
507 | |
|
508 | 0 | rtl::Reference< SdLayer > xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId)); |
509 | 0 | return xLayer; |
510 | 0 | } |
511 | | |
512 | | // XIndexAccess |
513 | | sal_Int32 SAL_CALL SdLayerManager::getCount() |
514 | 138 | { |
515 | 138 | SolarMutexGuard aGuard; |
516 | | |
517 | 138 | if( mpModel == nullptr ) |
518 | 0 | throw lang::DisposedException(); |
519 | | |
520 | 138 | if( mpModel->mpDoc ) |
521 | 138 | { |
522 | 138 | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
523 | 138 | return rLayerAdmin.GetLayerCount(); |
524 | 138 | } |
525 | | |
526 | 0 | return 0; |
527 | 138 | } |
528 | | |
529 | | uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer ) |
530 | 0 | { |
531 | 0 | SolarMutexGuard aGuard; |
532 | |
|
533 | 0 | if( mpModel == nullptr ) |
534 | 0 | throw lang::DisposedException(); |
535 | | |
536 | 0 | if( nLayer >= getCount() || nLayer < 0 ) |
537 | 0 | throw lang::IndexOutOfBoundsException(); |
538 | | |
539 | 0 | uno::Any aAny; |
540 | |
|
541 | 0 | if( mpModel->mpDoc ) |
542 | 0 | { |
543 | 0 | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
544 | 0 | rtl::Reference<SdLayer> xLayer (GetLayer (rLayerAdmin.GetLayer(static_cast<sal_uInt16>(nLayer)))); |
545 | 0 | aAny <<= uno::Reference<drawing::XLayer>(xLayer); |
546 | 0 | } |
547 | 0 | return aAny; |
548 | 0 | } |
549 | | |
550 | | // XNameAccess |
551 | | uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName ) |
552 | 2.16k | { |
553 | 2.16k | SolarMutexGuard aGuard; |
554 | | |
555 | 2.16k | if( (mpModel == nullptr) || (mpModel->mpDoc == nullptr ) ) |
556 | 0 | throw lang::DisposedException(); |
557 | | |
558 | 2.16k | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
559 | 2.16k | SdrLayer* pLayer = rLayerAdmin.GetLayer(aName); |
560 | 2.16k | if( pLayer == nullptr ) |
561 | 0 | throw container::NoSuchElementException(); |
562 | | |
563 | 2.16k | return uno::Any( css::uno::Reference< css::drawing::XLayer>(GetLayer(pLayer)) ); |
564 | 2.16k | } |
565 | | |
566 | | uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames() |
567 | 0 | { |
568 | 0 | SolarMutexGuard aGuard; |
569 | |
|
570 | 0 | if( mpModel == nullptr ) |
571 | 0 | throw lang::DisposedException(); |
572 | | |
573 | 0 | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
574 | 0 | const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount(); |
575 | |
|
576 | 0 | uno::Sequence< OUString > aSeq( nLayerCount ); |
577 | |
|
578 | 0 | OUString* pStrings = aSeq.getArray(); |
579 | |
|
580 | 0 | for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ ) |
581 | 0 | { |
582 | 0 | SdrLayer* pLayer = rLayerAdmin.GetLayer( nLayer ); |
583 | 0 | if( pLayer ) |
584 | 0 | *pStrings++ = pLayer->GetName(); |
585 | 0 | } |
586 | |
|
587 | 0 | return aSeq; |
588 | 0 | } |
589 | | |
590 | | sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) |
591 | 2.30k | { |
592 | 2.30k | SolarMutexGuard aGuard; |
593 | | |
594 | 2.30k | if( mpModel == nullptr ) |
595 | 0 | throw lang::DisposedException(); |
596 | | |
597 | 2.30k | SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin(); |
598 | | |
599 | 2.30k | return nullptr != rLayerAdmin.GetLayer(aName); |
600 | 2.30k | } |
601 | | |
602 | | // XElementAccess |
603 | | uno::Type SAL_CALL SdLayerManager::getElementType() |
604 | 0 | { |
605 | 0 | return cppu::UnoType<drawing::XLayer>::get(); |
606 | 0 | } |
607 | | |
608 | | sal_Bool SAL_CALL SdLayerManager::hasElements() |
609 | 0 | { |
610 | 0 | return getCount() > 0; |
611 | 0 | } |
612 | | |
613 | | /** |
614 | | * If something was changed at the layers, this methods takes care that the |
615 | | * changes are made visible in sdbcx::View. |
616 | | */ |
617 | | void SdLayerManager::UpdateLayerView() const noexcept |
618 | 138 | { |
619 | 138 | if(!mpModel->mpDocShell) |
620 | 0 | return; |
621 | | |
622 | 138 | ::sd::DrawViewShell* pDrViewSh = dynamic_cast< ::sd::DrawViewShell* >( mpModel->mpDocShell->GetViewShell()); |
623 | | |
624 | 138 | if(pDrViewSh) |
625 | 0 | { |
626 | 0 | bool bLayerMode = pDrViewSh->IsLayerModeActive(); |
627 | 0 | pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode); |
628 | 0 | pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode); |
629 | 0 | } |
630 | | |
631 | 138 | mpModel->mpDoc->SetChanged(); |
632 | 138 | } |
633 | | |
634 | | /** */ |
635 | | ::sd::View* SdLayerManager::GetView() const noexcept |
636 | 6.91k | { |
637 | 6.91k | if( mpModel->mpDocShell ) |
638 | 6.91k | { |
639 | 6.91k | ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell(); |
640 | 6.91k | if(pViewSh) |
641 | 0 | return pViewSh->GetView(); |
642 | 6.91k | } |
643 | 6.91k | return nullptr; |
644 | 6.91k | } |
645 | | |
646 | | /** Use the <member>mpLayers</member> container of weak references to either |
647 | | retrieve and return a previously created <type>XLayer</type> object for |
648 | | the given <type>SdrLayer</type> object or create and remember a new one. |
649 | | */ |
650 | | rtl::Reference<SdLayer> SdLayerManager::GetLayer (SdrLayer* pLayer) |
651 | 2.30k | { |
652 | 2.30k | rtl::Reference<SdLayer> xLayer; |
653 | | |
654 | | // Search existing xLayer for the given pLayer. |
655 | 2.30k | if (mpLayers->findRef(xLayer, pLayer)) |
656 | 0 | return xLayer; |
657 | | |
658 | | // Create the xLayer if necessary. |
659 | 2.30k | xLayer = new SdLayer (this, pLayer); |
660 | | |
661 | | // Remember the new xLayer for future calls. |
662 | 2.30k | mpLayers->insert(xLayer); |
663 | | |
664 | 2.30k | return xLayer; |
665 | 2.30k | } |
666 | | |
667 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |