Line data Source code
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 :
22 : #include "unolayer.hxx"
23 : #include <osl/mutex.hxx>
24 :
25 : #include <svx/svdpagv.hxx>
26 : #include <svx/unoshape.hxx>
27 : #include <svx/svdobj.hxx>
28 : #include <comphelper/serviceinfohelper.hxx>
29 :
30 : // folgende fuer InsertSdPage()
31 : #include <svx/svdlayer.hxx>
32 :
33 : #include "DrawDocShell.hxx"
34 : #include <drawdoc.hxx>
35 : #include <unomodel.hxx>
36 : #include "unoprnms.hxx"
37 : #include <com/sun/star/lang/NoSupportException.hpp>
38 : #include <svx/svdpool.hxx>
39 : #include "unohelp.hxx"
40 : #include "FrameView.hxx"
41 : #include "DrawViewShell.hxx"
42 : #include "View.hxx"
43 : #include "ViewShell.hxx"
44 : #include "app.hrc"
45 : #include "strings.hrc"
46 : #include "sdresid.hxx"
47 : #include "glob.hrc"
48 :
49 : #include "unokywds.hxx"
50 : #include "unowcntr.hxx"
51 : #include <vcl/svapp.hxx>
52 :
53 : using namespace ::rtl;
54 : using namespace ::com::sun::star;
55 :
56 : //=============================================================================
57 : // class SdLayer
58 : //=============================================================================
59 :
60 : #define WID_LAYER_LOCKED 1
61 : #define WID_LAYER_PRINTABLE 2
62 : #define WID_LAYER_VISIBLE 3
63 : #define WID_LAYER_NAME 4
64 : #define WID_LAYER_TITLE 5
65 : #define WID_LAYER_DESC 6
66 :
67 70 : const SvxItemPropertySet* ImplGetSdLayerPropertySet()
68 : {
69 : static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] =
70 : {
71 5 : { MAP_CHAR_LEN(UNO_NAME_LAYER_LOCKED), WID_LAYER_LOCKED, &::getBooleanCppuType(), 0, 0 },
72 5 : { MAP_CHAR_LEN(UNO_NAME_LAYER_PRINTABLE), WID_LAYER_PRINTABLE,&::getBooleanCppuType(), 0, 0 },
73 5 : { MAP_CHAR_LEN(UNO_NAME_LAYER_VISIBLE), WID_LAYER_VISIBLE, &::getBooleanCppuType(), 0, 0 },
74 5 : { MAP_CHAR_LEN(UNO_NAME_LAYER_NAME), WID_LAYER_NAME, &::getCppuType((const OUString*)0), 0, 0 },
75 5 : { MAP_CHAR_LEN("Title"), WID_LAYER_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
76 5 : { MAP_CHAR_LEN("Description"), WID_LAYER_DESC, &::getCppuType((const OUString*)0), 0, 0 },
77 : { 0,0,0,0,0,0}
78 100 : };
79 70 : static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
80 70 : return &aSDLayerPropertySet_Impl;
81 : }
82 :
83 265 : String SdLayer::convertToInternalName( const OUString& rName )
84 : {
85 265 : if ( rName == sUNO_LayerName_background )
86 : {
87 14 : return String( SdResId( STR_LAYER_BCKGRND ) );
88 : }
89 251 : else if ( rName == sUNO_LayerName_background_objects )
90 : {
91 87 : return String( SdResId( STR_LAYER_BCKGRNDOBJ ) );
92 : }
93 164 : else if ( rName == sUNO_LayerName_layout )
94 : {
95 133 : return String( SdResId( STR_LAYER_LAYOUT ) );
96 : }
97 31 : else if ( rName == sUNO_LayerName_controls )
98 : {
99 14 : return String( SdResId( STR_LAYER_CONTROLS ) );
100 : }
101 17 : else if ( rName == sUNO_LayerName_measurelines )
102 : {
103 15 : return String( SdResId( STR_LAYER_MEASURELINES ) );
104 : }
105 : else
106 : {
107 2 : return String( rName );
108 : }
109 : }
110 :
111 231 : OUString SdLayer::convertToExternalName( const String& rName )
112 : {
113 231 : if( rName == String( SdResId( STR_LAYER_BCKGRND ) ) )
114 : {
115 7 : return OUString( sUNO_LayerName_background );
116 : }
117 224 : else if( rName == String( SdResId( STR_LAYER_BCKGRNDOBJ ) ) )
118 : {
119 49 : return OUString( sUNO_LayerName_background_objects );
120 : }
121 175 : else if( rName == String( SdResId( STR_LAYER_LAYOUT ) ) )
122 : {
123 159 : return OUString( sUNO_LayerName_layout );
124 : }
125 16 : else if( rName == String( SdResId( STR_LAYER_CONTROLS ) ) )
126 : {
127 7 : return OUString( sUNO_LayerName_controls );
128 : }
129 9 : else if( rName == String( SdResId( STR_LAYER_MEASURELINES ) ) )
130 : {
131 7 : return OUString( sUNO_LayerName_measurelines );
132 : }
133 : else
134 : {
135 2 : return OUString( rName );
136 : }
137 : }
138 :
139 : /** */
140 70 : SdLayer::SdLayer( SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_ ) throw()
141 : : pLayerManager(pLayerManager_)
142 : , mxLayerManager(pLayerManager_)
143 : , pLayer(pSdrLayer_)
144 70 : , pPropSet(ImplGetSdLayerPropertySet())
145 : {
146 70 : }
147 :
148 : /** */
149 140 : SdLayer::~SdLayer() throw()
150 : {
151 140 : }
152 :
153 : // uno helper
154 52 : UNO3_GETIMPLEMENTATION_IMPL( SdLayer );
155 :
156 : // XServiceInfo
157 0 : OUString SAL_CALL SdLayer::getImplementationName()
158 : throw(uno::RuntimeException)
159 : {
160 0 : return OUString( OUString::createFromAscii(sUNO_SdLayer) );
161 : }
162 :
163 0 : sal_Bool SAL_CALL SdLayer::supportsService( const OUString& ServiceName )
164 : throw(uno::RuntimeException)
165 : {
166 0 : return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
167 : }
168 :
169 0 : uno::Sequence< OUString > SAL_CALL SdLayer::getSupportedServiceNames()
170 : throw(uno::RuntimeException)
171 : {
172 0 : OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayer) );
173 0 : uno::Sequence< OUString > aSeq( &aServiceName, 1 );
174 0 : return aSeq;
175 : }
176 :
177 : // beans::XPropertySet
178 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdLayer::getPropertySetInfo( )
179 : throw(uno::RuntimeException)
180 : {
181 0 : SolarMutexGuard aGuard;
182 0 : return pPropSet->getPropertySetInfo();
183 : }
184 :
185 70 : void SAL_CALL SdLayer::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
186 : throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
187 : {
188 70 : SolarMutexGuard aGuard;
189 :
190 70 : if(pLayer == NULL || pLayerManager == NULL)
191 0 : throw lang::DisposedException();
192 :
193 70 : const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
194 :
195 70 : switch( pEntry ? pEntry->nWID : -1 )
196 : {
197 : case WID_LAYER_LOCKED:
198 : {
199 0 : sal_Bool bValue = sal_False;
200 0 : if(!sd::any2bool( aValue, bValue ))
201 0 : throw lang::IllegalArgumentException();
202 0 : set( LOCKED, bValue );
203 0 : break;
204 : }
205 : case WID_LAYER_PRINTABLE:
206 : {
207 0 : sal_Bool bValue = sal_False;
208 0 : if(!sd::any2bool( aValue, bValue ))
209 0 : throw lang::IllegalArgumentException();
210 0 : set( PRINTABLE, bValue );
211 0 : break;
212 : }
213 : case WID_LAYER_VISIBLE:
214 : {
215 0 : sal_Bool bValue = sal_False;
216 0 : if(!sd::any2bool( aValue, bValue ))
217 0 : throw lang::IllegalArgumentException();
218 0 : set( VISIBLE, bValue );
219 0 : break;
220 : }
221 : case WID_LAYER_NAME:
222 : {
223 0 : OUString aName;
224 0 : if(!(aValue >>= aName))
225 0 : throw lang::IllegalArgumentException();
226 :
227 0 : pLayer->SetName(SdLayer::convertToInternalName( aName ) );
228 0 : pLayerManager->UpdateLayerView();
229 0 : break;
230 : }
231 :
232 : case WID_LAYER_TITLE:
233 : {
234 35 : OUString sTitle;
235 35 : if(!(aValue >>= sTitle))
236 0 : throw lang::IllegalArgumentException();
237 :
238 35 : pLayer->SetTitle(sTitle);
239 35 : break;
240 : }
241 :
242 : case WID_LAYER_DESC:
243 : {
244 35 : OUString sDescription;
245 35 : if(!(aValue >>= sDescription))
246 0 : throw lang::IllegalArgumentException();
247 :
248 35 : pLayer->SetDescription(sDescription);
249 35 : break;
250 : }
251 :
252 : default:
253 0 : throw beans::UnknownPropertyException();
254 : }
255 :
256 70 : if( pLayerManager->GetDocShell() )
257 70 : pLayerManager->GetDocShell()->SetModified();
258 70 : }
259 :
260 92 : uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
261 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
262 : {
263 92 : SolarMutexGuard aGuard;
264 :
265 92 : if(pLayer == NULL || pLayerManager == NULL)
266 0 : throw lang::DisposedException();
267 :
268 92 : const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
269 :
270 92 : uno::Any aValue;
271 :
272 92 : switch( pEntry ? pEntry->nWID : -1 )
273 : {
274 : case WID_LAYER_LOCKED:
275 0 : sd::bool2any( get( LOCKED ), aValue );
276 0 : break;
277 : case WID_LAYER_PRINTABLE:
278 0 : sd::bool2any( get( PRINTABLE ), aValue );
279 0 : break;
280 : case WID_LAYER_VISIBLE:
281 0 : sd::bool2any( get( VISIBLE ), aValue );
282 0 : break;
283 : case WID_LAYER_NAME:
284 : {
285 32 : OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
286 32 : aValue <<= aRet;
287 32 : break;
288 : }
289 : case WID_LAYER_TITLE:
290 30 : aValue <<= OUString( pLayer->GetTitle() );
291 30 : break;
292 : case WID_LAYER_DESC:
293 30 : aValue <<= OUString( pLayer->GetDescription() );
294 30 : break;
295 : default:
296 0 : throw beans::UnknownPropertyException();
297 : }
298 :
299 92 : return aValue;
300 : }
301 :
302 0 : void SAL_CALL SdLayer::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
303 0 : void SAL_CALL SdLayer::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
304 0 : void SAL_CALL SdLayer::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
305 0 : void SAL_CALL SdLayer::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
306 :
307 : /** */
308 0 : sal_Bool SdLayer::get( LayerAttribute what ) throw()
309 : {
310 0 : if(pLayer&&pLayerManager)
311 : {
312 : // Try 1. is an arbitrary page open?
313 0 : ::sd::View *pView = pLayerManager->GetView();
314 0 : SdrPageView* pSdrPageView = NULL;
315 0 : if(pView)
316 0 : pSdrPageView = pView->GetSdrPageView();
317 :
318 0 : if(pSdrPageView)
319 : {
320 0 : String aLayerName = pLayer->GetName();
321 0 : switch(what)
322 : {
323 0 : case VISIBLE: return pSdrPageView->IsLayerVisible(aLayerName);
324 0 : case PRINTABLE: return pSdrPageView->IsLayerPrintable(aLayerName);
325 0 : case LOCKED: return pSdrPageView->IsLayerLocked(aLayerName);
326 0 : }
327 : }
328 :
329 : // Try 2. get info from FrameView
330 0 : if(pLayerManager->GetDocShell())
331 : {
332 0 : ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
333 0 : if(pFrameView)
334 0 : switch(what)
335 : {
336 0 : case VISIBLE: return pFrameView->GetVisibleLayers().IsSet(pLayer->GetID());
337 0 : case PRINTABLE: return pFrameView->GetPrintableLayers().IsSet(pLayer->GetID());
338 0 : case LOCKED: return pFrameView->GetLockedLayers().IsSet(pLayer->GetID());
339 : }
340 : }
341 : }
342 0 : return sal_False; //TODO: uno::Exception?
343 : }
344 :
345 0 : void SdLayer::set( LayerAttribute what, sal_Bool flag ) throw()
346 : {
347 0 : if(pLayer&&pLayerManager)
348 : {
349 : // Try 1. is an arbitrary page open?
350 0 : ::sd::View *pView = pLayerManager->GetView();
351 0 : SdrPageView* pSdrPageView = NULL;
352 0 : if(pView)
353 0 : pSdrPageView = pView->GetSdrPageView();
354 :
355 0 : if(pSdrPageView)
356 : {
357 0 : String aLayerName(pLayer->GetName());
358 0 : switch(what)
359 : {
360 0 : case VISIBLE: pSdrPageView->SetLayerVisible(aLayerName,flag);
361 0 : break;
362 0 : case PRINTABLE: pSdrPageView->SetLayerPrintable(aLayerName,flag);
363 0 : break;
364 0 : case LOCKED: pSdrPageView->SetLayerLocked(aLayerName,flag);
365 0 : break;
366 0 : }
367 : }
368 :
369 : // Try 2. get info from FrameView
370 0 : if(pLayerManager->GetDocShell())
371 : {
372 0 : ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
373 :
374 0 : if(pFrameView)
375 : {
376 0 : SetOfByte aNewLayers;
377 0 : switch(what)
378 : {
379 0 : case VISIBLE: aNewLayers = pFrameView->GetVisibleLayers();
380 0 : break;
381 0 : case PRINTABLE: aNewLayers = pFrameView->GetPrintableLayers();
382 0 : break;
383 0 : case LOCKED: aNewLayers = pFrameView->GetLockedLayers();
384 0 : break;
385 : }
386 :
387 0 : aNewLayers.Set(pLayer->GetID(),flag);
388 :
389 0 : switch(what)
390 : {
391 0 : case VISIBLE: pFrameView->SetVisibleLayers(aNewLayers);
392 0 : break;
393 0 : case PRINTABLE: pFrameView->SetPrintableLayers(aNewLayers);
394 0 : break;
395 0 : case LOCKED: pFrameView->SetLockedLayers(aNewLayers);
396 0 : break;
397 : }
398 0 : return;
399 : }
400 : }
401 : }
402 : //TODO: uno::Exception?
403 : }
404 :
405 :
406 :
407 :
408 : //===== ::com::sun::star::container::XChild =================================
409 :
410 0 : uno::Reference<uno::XInterface> SAL_CALL SdLayer::getParent (void)
411 : throw (::com::sun::star::uno::RuntimeException)
412 : {
413 0 : SolarMutexGuard aGuard;
414 :
415 0 : if( pLayerManager == NULL )
416 0 : throw lang::DisposedException();
417 :
418 0 : return uno::Reference<uno::XInterface> (mxLayerManager, uno::UNO_QUERY);
419 : }
420 :
421 :
422 0 : void SAL_CALL SdLayer::setParent (const uno::Reference<uno::XInterface >& )
423 : throw (::com::sun::star::lang::NoSupportException,
424 : ::com::sun::star::uno::RuntimeException)
425 : {
426 0 : throw lang::NoSupportException ();
427 : }
428 :
429 : // XComponent
430 5 : void SAL_CALL SdLayer::dispose( ) throw (uno::RuntimeException)
431 : {
432 5 : pLayerManager = 0;
433 5 : mxLayerManager = 0;
434 5 : pLayer = 0;
435 5 : }
436 :
437 0 : void SAL_CALL SdLayer::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
438 : {
439 : OSL_FAIL("not implemented!");
440 0 : }
441 :
442 0 : void SAL_CALL SdLayer::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
443 : {
444 : OSL_FAIL("not implemented!");
445 0 : }
446 :
447 :
448 : //=============================================================================
449 : // class SdLayerManager
450 : //=============================================================================
451 :
452 : /** */
453 15 : SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
454 15 : :mpModel( &rMyModel)
455 : {
456 15 : mpLayers = new SvUnoWeakContainer;
457 15 : }
458 :
459 : /** */
460 45 : SdLayerManager::~SdLayerManager() throw()
461 : {
462 15 : dispose();
463 30 : }
464 :
465 : // uno helper
466 0 : UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
467 :
468 : // XComponent
469 17 : void SAL_CALL SdLayerManager::dispose( ) throw (uno::RuntimeException)
470 : {
471 17 : mpModel = 0;
472 17 : if( mpLayers )
473 : {
474 15 : mpLayers->dispose();
475 :
476 15 : delete mpLayers;
477 15 : mpLayers = 0;
478 : }
479 17 : }
480 :
481 0 : void SAL_CALL SdLayerManager::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
482 : {
483 : OSL_FAIL("not implemented!");
484 0 : }
485 :
486 0 : void SAL_CALL SdLayerManager::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
487 : {
488 : OSL_FAIL("not implemented!");
489 0 : }
490 :
491 : // XServiceInfo
492 0 : OUString SAL_CALL SdLayerManager::getImplementationName()
493 : throw(uno::RuntimeException)
494 : {
495 0 : return OUString( OUString::createFromAscii(sUNO_SdLayerManager) );
496 : }
497 :
498 0 : sal_Bool SAL_CALL SdLayerManager::supportsService( const OUString& ServiceName )
499 : throw(uno::RuntimeException)
500 : {
501 0 : return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
502 : }
503 :
504 0 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getSupportedServiceNames()
505 : throw(uno::RuntimeException)
506 : {
507 0 : OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayerManager) );
508 0 : uno::Sequence< OUString > aSeq( &aServiceName, 1 );
509 0 : return aSeq;
510 : }
511 :
512 : // XLayerManager
513 1 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
514 : throw(uno::RuntimeException)
515 : {
516 1 : SolarMutexGuard aGuard;
517 :
518 1 : if( mpModel == 0 )
519 0 : throw lang::DisposedException();
520 :
521 1 : uno::Reference< drawing::XLayer > xLayer;
522 :
523 1 : if( mpModel->mpDoc )
524 : {
525 1 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
526 1 : sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
527 1 : sal_Int32 nLayer = nLayerCnt - 2 + 1;
528 1 : String aLayerName;
529 :
530 : // Test for existing names
531 3 : while( aLayerName.Len()==0 || rLayerAdmin.GetLayer( aLayerName, sal_False) )
532 : {
533 1 : aLayerName = String(SdResId(STR_LAYER));
534 1 : aLayerName += OUString::valueOf(nLayer);
535 1 : ++nLayer;
536 : }
537 :
538 1 : SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
539 1 : const sal_Int32 nMax=rLA.GetLayerCount();
540 1 : if (nIndex>nMax) nIndex=nMax;
541 1 : xLayer = GetLayer (rLA.NewLayer(aLayerName,(sal_uInt16)nIndex));
542 1 : mpModel->SetModified();
543 : }
544 1 : return xLayer;
545 : }
546 :
547 1 : void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
548 : throw(container::NoSuchElementException, uno::RuntimeException)
549 : {
550 1 : SolarMutexGuard aGuard;
551 :
552 1 : if( mpModel == 0 )
553 0 : throw lang::DisposedException();
554 :
555 1 : SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
556 :
557 1 : if(pSdLayer && GetView())
558 : {
559 1 : const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
560 1 : GetView()->DeleteLayer( pSdrLayer->GetName() );
561 :
562 1 : UpdateLayerView();
563 : }
564 :
565 1 : mpModel->SetModified();
566 1 : }
567 :
568 1 : void SAL_CALL SdLayerManager::attachShapeToLayer( const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XLayer >& xLayer )
569 : throw(uno::RuntimeException)
570 : {
571 1 : SolarMutexGuard aGuard;
572 :
573 1 : if( mpModel == 0 )
574 0 : throw lang::DisposedException();
575 :
576 1 : SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
577 1 : SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
578 1 : if(pSdrLayer==NULL)
579 1 : return;
580 :
581 1 : SvxShape* pShape = SvxShape::getImplementation( xShape );
582 1 : SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
583 :
584 1 : if(pSdrObject && pSdrLayer )
585 1 : pSdrObject->SetLayer(pSdrLayer->GetID());
586 :
587 1 : mpModel->SetModified();
588 : }
589 :
590 1 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) throw(uno::RuntimeException)
591 : {
592 1 : SolarMutexGuard aGuard;
593 :
594 1 : if( mpModel == 0 )
595 0 : throw lang::DisposedException();
596 :
597 1 : uno::Reference< drawing::XLayer > xLayer;
598 :
599 1 : if(mpModel->mpDoc)
600 : {
601 1 : SvxShape* pShape = SvxShape::getImplementation( xShape );
602 1 : SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
603 1 : if(pObj)
604 : {
605 1 : SdrLayerID aId = pObj->GetLayer();
606 1 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
607 1 : xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
608 : }
609 : }
610 1 : return xLayer;
611 : }
612 :
613 : // XIndexAccess
614 45 : sal_Int32 SAL_CALL SdLayerManager::getCount()
615 : throw(uno::RuntimeException)
616 : {
617 45 : SolarMutexGuard aGuard;
618 :
619 45 : if( mpModel == 0 )
620 0 : throw lang::DisposedException();
621 :
622 45 : if( mpModel->mpDoc )
623 : {
624 45 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
625 45 : return rLayerAdmin.GetLayerCount();
626 : }
627 :
628 0 : return 0;
629 : }
630 :
631 35 : uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
632 : throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
633 : {
634 35 : SolarMutexGuard aGuard;
635 :
636 35 : if( mpModel == 0 )
637 0 : throw lang::DisposedException();
638 :
639 35 : if( nLayer >= getCount() || nLayer < 0 )
640 1 : throw lang::IndexOutOfBoundsException();
641 :
642 34 : uno::Any aAny;
643 :
644 34 : if( mpModel->mpDoc )
645 : {
646 34 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
647 34 : uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
648 34 : aAny <<= xLayer;
649 : }
650 35 : return aAny;
651 : }
652 :
653 :
654 : // XNameAccess
655 37 : uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
656 : throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
657 : {
658 37 : SolarMutexGuard aGuard;
659 :
660 37 : if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
661 0 : throw lang::DisposedException();
662 :
663 37 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
664 37 : SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), sal_False );
665 37 : if( pLayer == NULL )
666 1 : throw container::NoSuchElementException();
667 :
668 36 : return uno::Any( GetLayer (pLayer) );
669 : }
670 :
671 1 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
672 : throw(uno::RuntimeException)
673 : {
674 1 : SolarMutexGuard aGuard;
675 :
676 1 : if( mpModel == 0 )
677 0 : throw lang::DisposedException();
678 :
679 1 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
680 1 : const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
681 :
682 1 : uno::Sequence< OUString > aSeq( nLayerCount );
683 :
684 1 : OUString* pStrings = aSeq.getArray();
685 : SdrLayer* pLayer;
686 :
687 6 : for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
688 : {
689 5 : pLayer = rLayerAdmin.GetLayer( nLayer );
690 5 : if( pLayer )
691 5 : *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
692 : }
693 :
694 1 : return aSeq;
695 : }
696 :
697 37 : sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) throw(uno::RuntimeException)
698 : {
699 37 : SolarMutexGuard aGuard;
700 :
701 37 : if( mpModel == 0 )
702 0 : throw lang::DisposedException();
703 :
704 37 : SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
705 :
706 37 : return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), sal_False );
707 : }
708 :
709 : // XElementAccess
710 1 : uno::Type SAL_CALL SdLayerManager::getElementType()
711 : throw(uno::RuntimeException)
712 : {
713 1 : return ITYPE( drawing::XLayer );
714 : }
715 :
716 1 : sal_Bool SAL_CALL SdLayerManager::hasElements() throw(uno::RuntimeException)
717 : {
718 1 : return getCount() > 0;
719 : }
720 :
721 : /**
722 : * If something was changed at the layers, this methods takes care that the
723 : * changes are made visible in sdbcx::View.
724 : */
725 1 : void SdLayerManager::UpdateLayerView( sal_Bool modify ) const throw()
726 : {
727 1 : if(mpModel->mpDocShell)
728 : {
729 : ::sd::DrawViewShell* pDrViewSh =
730 1 : PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
731 :
732 1 : if(pDrViewSh)
733 : {
734 1 : sal_Bool bLayerMode = pDrViewSh->IsLayerModeActive();
735 1 : pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
736 1 : pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
737 : }
738 :
739 1 : if(modify)
740 1 : mpModel->mpDoc->SetChanged(sal_True);
741 : }
742 1 : }
743 :
744 : /** */
745 2 : ::sd::View* SdLayerManager::GetView() const throw()
746 : {
747 2 : if( mpModel->mpDocShell )
748 : {
749 2 : ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
750 2 : if(pViewSh)
751 2 : return pViewSh->GetView();
752 : }
753 0 : return NULL;
754 : }
755 :
756 :
757 :
758 : namespace
759 : {
760 : /** Compare two pointers to <type>SdrLayer</type> objects.
761 : @param xRef
762 : The implementing SdLayer class provides the first pointer by the
763 : <member>SdLayer::GetSdrLayer</member> method.
764 : @param pSearchData
765 : This void pointer is the second pointer to an <type>SdrLayer</type>
766 : object.
767 : @return
768 : Return </True> if both pointers point to the same object.
769 : */
770 11 : sal_Bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
771 : {
772 11 : uno::Reference<uno::XInterface> xLayer (xRef);
773 11 : if (xLayer.is())
774 : {
775 11 : SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
776 11 : if (pSdLayer != NULL)
777 : {
778 11 : SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
779 11 : if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
780 2 : return sal_True;
781 : }
782 : }
783 9 : return sal_False;
784 : }
785 : }
786 :
787 : /** Use the <member>mpLayers</member> container of weak references to either
788 : retrieve and return a previously created <type>XLayer</type> object for
789 : the given <type>SdrLayer</type> object or create and remember a new one.
790 : */
791 72 : uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
792 : {
793 72 : uno::WeakReference<uno::XInterface> xRef;
794 72 : uno::Reference<drawing::XLayer> xLayer;
795 :
796 : // Search existing xLayer for the given pLayer.
797 72 : if (mpLayers->findRef (xRef, (void*)pLayer, compare_layers))
798 2 : xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
799 :
800 : // Create the xLayer if necessary.
801 72 : if ( ! xLayer.is())
802 : {
803 70 : xLayer = new SdLayer (this, pLayer);
804 :
805 : // Remember the new xLayer for future calls.
806 70 : uno::WeakReference<uno::XInterface> wRef(xLayer);
807 70 : mpLayers->insert(wRef);
808 : }
809 :
810 72 : return xLayer;
811 33 : }
812 :
813 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|