merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / unoidl / unolayer.cxx
blobc076aa05eef9cdbec71afcb5f63f4189e0afe507
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unolayer.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
35 #include "unolayer.hxx"
36 #include <osl/mutex.hxx>
37 #include <vos/mutex.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <svx/unoshape.hxx>
41 #include <svx/svdobj.hxx>
43 // folgende fuer InsertSdPage()
44 #include <svx/svdlayer.hxx>
46 #ifndef SVX_LIGHT
47 #ifndef SD_DRAW_DOC_SHELL_HXX
48 #include "DrawDocShell.hxx"
49 #endif
50 #endif
51 #include <drawdoc.hxx>
52 #include <unomodel.hxx>
53 #include "unoprnms.hxx"
54 #include <com/sun/star/lang/NoSupportException.hpp>
56 #include "unohelp.hxx"
57 #include "FrameView.hxx"
58 #include "DrawViewShell.hxx"
59 #include "View.hxx"
60 #include "ViewShell.hxx"
61 #include "app.hrc"
62 #include "strings.hrc"
63 #include "sdresid.hxx"
64 #include "glob.hrc"
66 #include "unokywds.hxx"
67 #include "unowcntr.hxx"
68 #include <vcl/svapp.hxx>
70 using namespace ::rtl;
71 using namespace ::vos;
72 using namespace ::com::sun::star;
74 //=============================================================================
75 // class SdLayer
76 //=============================================================================
78 #define WID_LAYER_LOCKED 1
79 #define WID_LAYER_PRINTABLE 2
80 #define WID_LAYER_VISIBLE 3
81 #define WID_LAYER_NAME 4
82 #define WID_LAYER_TITLE 5
83 #define WID_LAYER_DESC 6
85 const SvxItemPropertySet* ImplGetSdLayerPropertySet()
87 static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] =
89 { MAP_CHAR_LEN(UNO_NAME_LAYER_LOCKED), WID_LAYER_LOCKED, &::getBooleanCppuType(), 0, 0 },
90 { MAP_CHAR_LEN(UNO_NAME_LAYER_PRINTABLE), WID_LAYER_PRINTABLE,&::getBooleanCppuType(), 0, 0 },
91 { MAP_CHAR_LEN(UNO_NAME_LAYER_VISIBLE), WID_LAYER_VISIBLE, &::getBooleanCppuType(), 0, 0 },
92 { MAP_CHAR_LEN(UNO_NAME_LAYER_NAME), WID_LAYER_NAME, &::getCppuType((const OUString*)0), 0, 0 },
93 { MAP_CHAR_LEN("Title"), WID_LAYER_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
94 { MAP_CHAR_LEN("Description"), WID_LAYER_DESC, &::getCppuType((const OUString*)0), 0, 0 },
95 { 0,0,0,0,0,0}
97 static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl );
98 return &aSDLayerPropertySet_Impl;
101 String SdLayer::convertToInternalName( const OUString& rName )
103 if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_LayerName_background) ) )
105 return String( SdResId( STR_LAYER_BCKGRND ) );
107 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_LayerName_background_objects) ) )
109 return String( SdResId( STR_LAYER_BCKGRNDOBJ ) );
111 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_LayerName_layout) ) )
113 return String( SdResId( STR_LAYER_LAYOUT ) );
115 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_LayerName_controls) ) )
117 return String( SdResId( STR_LAYER_CONTROLS ) );
119 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_LayerName_measurelines) ) )
121 return String( SdResId( STR_LAYER_MEASURELINES ) );
123 else
125 return String( rName );
129 OUString SdLayer::convertToExternalName( const String& rName )
131 const String aCompare( rName );
132 if( rName == String( SdResId( STR_LAYER_BCKGRND ) ) )
134 return OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_LayerName_background) );
136 else if( rName == String( SdResId( STR_LAYER_BCKGRNDOBJ ) ) )
138 return OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_LayerName_background_objects) );
140 else if( rName == String( SdResId( STR_LAYER_LAYOUT ) ) )
142 return OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_LayerName_layout) );
144 else if( rName == String( SdResId( STR_LAYER_CONTROLS ) ) )
146 return OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_LayerName_controls) );
148 else if( rName == String( SdResId( STR_LAYER_MEASURELINES ) ) )
150 return OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_LayerName_measurelines) );
152 else
154 return OUString( rName );
158 /** */
159 SdLayer::SdLayer( SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_ ) throw()
160 : pLayerManager(pLayerManager_)
161 , mxLayerManager(pLayerManager_)
162 , pLayer(pSdrLayer_)
163 , pPropSet(ImplGetSdLayerPropertySet())
167 /** */
168 SdLayer::~SdLayer() throw()
172 // uno helper
173 UNO3_GETIMPLEMENTATION_IMPL( SdLayer );
175 // XServiceInfo
176 OUString SAL_CALL SdLayer::getImplementationName()
177 throw(uno::RuntimeException)
179 return OUString( OUString::createFromAscii(sUNO_SdLayer) );
182 sal_Bool SAL_CALL SdLayer::supportsService( const OUString& ServiceName )
183 throw(uno::RuntimeException)
185 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
188 uno::Sequence< OUString > SAL_CALL SdLayer::getSupportedServiceNames()
189 throw(uno::RuntimeException)
191 OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayer) );
192 uno::Sequence< OUString > aSeq( &aServiceName, 1 );
193 return aSeq;
196 // beans::XPropertySet
197 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdLayer::getPropertySetInfo( )
198 throw(uno::RuntimeException)
200 OGuard aGuard( Application::GetSolarMutex() );
201 return pPropSet->getPropertySetInfo();
204 void SAL_CALL SdLayer::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
205 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
207 OGuard aGuard( Application::GetSolarMutex() );
209 if(pLayer == NULL || pLayerManager == NULL)
210 throw lang::DisposedException();
212 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
214 switch( pEntry ? pEntry->nWID : -1 )
216 case WID_LAYER_LOCKED:
218 sal_Bool bValue = sal_False;
219 if(!sd::any2bool( aValue, bValue ))
220 throw lang::IllegalArgumentException();
221 set( LOCKED, bValue );
222 break;
224 case WID_LAYER_PRINTABLE:
226 sal_Bool bValue = sal_False;
227 if(!sd::any2bool( aValue, bValue ))
228 throw lang::IllegalArgumentException();
229 set( PRINTABLE, bValue );
230 break;
232 case WID_LAYER_VISIBLE:
234 sal_Bool bValue = sal_False;
235 if(!sd::any2bool( aValue, bValue ))
236 throw lang::IllegalArgumentException();
237 set( VISIBLE, bValue );
238 break;
240 case WID_LAYER_NAME:
242 OUString aName;
243 if(!(aValue >>= aName))
244 throw lang::IllegalArgumentException();
246 pLayer->SetName(SdLayer::convertToInternalName( aName ) );
247 pLayerManager->UpdateLayerView();
248 break;
251 case WID_LAYER_TITLE:
253 OUString sTitle;
254 if(!(aValue >>= sTitle))
255 throw lang::IllegalArgumentException();
257 pLayer->SetTitle(sTitle);
258 break;
261 case WID_LAYER_DESC:
263 OUString sDescription;
264 if(!(aValue >>= sDescription))
265 throw lang::IllegalArgumentException();
267 pLayer->SetDescription(sDescription);
268 break;
271 default:
272 throw beans::UnknownPropertyException();
275 #ifndef SVX_LIGHT
276 if( pLayerManager->GetDocShell() )
277 pLayerManager->GetDocShell()->SetModified();
278 #endif
281 uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
282 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
284 OGuard aGuard( Application::GetSolarMutex() );
286 if(pLayer == NULL || pLayerManager == NULL)
287 throw lang::DisposedException();
289 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
291 uno::Any aValue;
293 switch( pEntry ? pEntry->nWID : -1 )
295 case WID_LAYER_LOCKED:
296 sd::bool2any( get( LOCKED ), aValue );
297 break;
298 case WID_LAYER_PRINTABLE:
299 sd::bool2any( get( PRINTABLE ), aValue );
300 break;
301 case WID_LAYER_VISIBLE:
302 sd::bool2any( get( VISIBLE ), aValue );
303 break;
304 case WID_LAYER_NAME:
306 OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
307 aValue <<= aRet;
308 break;
310 case WID_LAYER_TITLE:
311 aValue <<= OUString( pLayer->GetTitle() );
312 break;
313 case WID_LAYER_DESC:
314 aValue <<= OUString( pLayer->GetDescription() );
315 break;
316 default:
317 throw beans::UnknownPropertyException();
320 return aValue;
323 void SAL_CALL SdLayer::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
324 void SAL_CALL SdLayer::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
325 void SAL_CALL SdLayer::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
326 void SAL_CALL SdLayer::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
328 /** */
329 sal_Bool SdLayer::get( LayerAttribute what ) throw()
331 if(pLayer&&pLayerManager)
333 // Versuch 1. ist eine beliebige Seite geoeffnet?
334 ::sd::View *pView = pLayerManager->GetView();
335 SdrPageView* pSdrPageView = NULL;
336 if(pView)
337 pSdrPageView = pView->GetSdrPageView();
339 if(pSdrPageView)
341 String aLayerName = pLayer->GetName();
342 switch(what)
344 case VISIBLE: return pSdrPageView->IsLayerVisible(aLayerName);
345 case PRINTABLE: return pSdrPageView->IsLayerPrintable(aLayerName);
346 case LOCKED: return pSdrPageView->IsLayerLocked(aLayerName);
350 #ifndef SVX_LIGHT
351 // Versuch 2. Info von der FrameView besorgen
352 if(pLayerManager->GetDocShell())
354 ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
355 if(pFrameView)
356 switch(what)
358 case VISIBLE: return pFrameView->GetVisibleLayers().IsSet(pLayer->GetID());
359 case PRINTABLE: return pFrameView->GetPrintableLayers().IsSet(pLayer->GetID());
360 case LOCKED: return pFrameView->GetLockedLayers().IsSet(pLayer->GetID());
363 #endif
365 return sal_False; //TODO: uno::Exception?
368 void SdLayer::set( LayerAttribute what, sal_Bool flag ) throw()
370 if(pLayer&&pLayerManager)
372 // Versuch 1. ist eine beliebige Seite geoeffnet?
373 ::sd::View *pView = pLayerManager->GetView();
374 SdrPageView* pSdrPageView = NULL;
375 if(pView)
376 pSdrPageView = pView->GetSdrPageView();
378 if(pSdrPageView)
380 String aLayerName(pLayer->GetName());
381 switch(what)
383 case VISIBLE: pSdrPageView->SetLayerVisible(aLayerName,flag);
384 break;
385 case PRINTABLE: pSdrPageView->SetLayerPrintable(aLayerName,flag);
386 break;
387 case LOCKED: pSdrPageView->SetLayerLocked(aLayerName,flag);
388 break;
392 #ifndef SVX_LIGHT
393 // Versuch 2. Info von der FrameView besorgen
394 if(pLayerManager->GetDocShell())
396 ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
398 if(pFrameView)
400 SetOfByte aNewLayers;
401 switch(what)
403 case VISIBLE: aNewLayers = pFrameView->GetVisibleLayers();
404 break;
405 case PRINTABLE: aNewLayers = pFrameView->GetPrintableLayers();
406 break;
407 case LOCKED: aNewLayers = pFrameView->GetLockedLayers();
408 break;
411 aNewLayers.Set(pLayer->GetID(),flag);
413 switch(what)
415 case VISIBLE: pFrameView->SetVisibleLayers(aNewLayers);
416 break;
417 case PRINTABLE: pFrameView->SetPrintableLayers(aNewLayers);
418 break;
419 case LOCKED: pFrameView->SetLockedLayers(aNewLayers);
420 break;
422 return;
425 #endif
427 //TODO: uno::Exception?
433 //===== ::com::sun::star::container::XChild =================================
435 uno::Reference<uno::XInterface> SAL_CALL SdLayer::getParent (void)
436 throw (::com::sun::star::uno::RuntimeException)
438 OGuard aGuard( Application::GetSolarMutex() );
440 if( pLayerManager == NULL )
441 throw lang::DisposedException();
443 return uno::Reference<uno::XInterface> (mxLayerManager, uno::UNO_QUERY);
447 void SAL_CALL SdLayer::setParent (const uno::Reference<uno::XInterface >& )
448 throw (::com::sun::star::lang::NoSupportException,
449 ::com::sun::star::uno::RuntimeException)
451 throw lang::NoSupportException ();
454 // XComponent
455 void SAL_CALL SdLayer::dispose( ) throw (uno::RuntimeException)
457 pLayerManager = 0;
458 mxLayerManager = 0;
459 pLayer = 0;
462 void SAL_CALL SdLayer::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
464 DBG_ERROR("not implemented!");
467 void SAL_CALL SdLayer::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
469 DBG_ERROR("not implemented!");
473 //=============================================================================
474 // class SdLayerManager
475 //=============================================================================
477 /** */
478 SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
479 :mpModel( &rMyModel)
481 mpLayers = new SvUnoWeakContainer;
484 /** */
485 SdLayerManager::~SdLayerManager() throw()
487 dispose();
490 // uno helper
491 UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
493 // XComponent
494 void SAL_CALL SdLayerManager::dispose( ) throw (uno::RuntimeException)
496 mpModel = 0;
497 if( mpLayers )
499 mpLayers->dispose();
501 delete mpLayers;
502 mpLayers = 0;
506 void SAL_CALL SdLayerManager::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
508 DBG_ERROR("not implemented!");
511 void SAL_CALL SdLayerManager::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException)
513 DBG_ERROR("not implemented!");
516 // XServiceInfo
517 OUString SAL_CALL SdLayerManager::getImplementationName()
518 throw(uno::RuntimeException)
520 return OUString( OUString::createFromAscii(sUNO_SdLayerManager) );
523 sal_Bool SAL_CALL SdLayerManager::supportsService( const OUString& ServiceName )
524 throw(uno::RuntimeException)
526 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
529 uno::Sequence< OUString > SAL_CALL SdLayerManager::getSupportedServiceNames()
530 throw(uno::RuntimeException)
532 OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayerManager) );
533 uno::Sequence< OUString > aSeq( &aServiceName, 1 );
534 return aSeq;
537 // XLayerManager
538 uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
539 throw(uno::RuntimeException)
541 OGuard aGuard( Application::GetSolarMutex() );
543 if( mpModel == 0 )
544 throw lang::DisposedException();
546 uno::Reference< drawing::XLayer > xLayer;
548 if( mpModel->mpDoc )
550 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
551 sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
552 sal_uInt16 nLayer = nLayerCnt - 2 + 1;
553 String aLayerName;
555 // Ueberpruefung auf schon vorhandene Namen
556 while( aLayerName.Len()==0 || rLayerAdmin.GetLayer( aLayerName, sal_False) )
558 aLayerName = String(SdResId(STR_LAYER));
559 aLayerName += String::CreateFromInt32( (sal_Int32)nLayer );
560 nLayer++;
563 SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
564 const sal_Int32 nMax=rLA.GetLayerCount();
565 if (nIndex>nMax) nIndex=nMax;
566 xLayer = GetLayer (rLA.NewLayer(aLayerName,(USHORT)nIndex));
567 mpModel->SetModified();
569 return xLayer;
572 void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
573 throw(container::NoSuchElementException, uno::RuntimeException)
575 OGuard aGuard( Application::GetSolarMutex() );
577 if( mpModel == 0 )
578 throw lang::DisposedException();
580 SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
582 if(pSdLayer && GetView())
584 const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
585 GetView()->DeleteLayer( pSdrLayer->GetName() );
587 UpdateLayerView();
590 mpModel->SetModified();
593 void SAL_CALL SdLayerManager::attachShapeToLayer( const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XLayer >& xLayer )
594 throw(uno::RuntimeException)
596 OGuard aGuard( Application::GetSolarMutex() );
598 if( mpModel == 0 )
599 throw lang::DisposedException();
601 SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
602 SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
603 if(pSdrLayer==NULL)
604 return;
606 SvxShape* pShape = SvxShape::getImplementation( xShape );
607 SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
609 if(pSdrObject && pSdrLayer )
610 pSdrObject->SetLayer(pSdrLayer->GetID());
612 mpModel->SetModified();
615 uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) throw(uno::RuntimeException)
617 OGuard aGuard( Application::GetSolarMutex() );
619 if( mpModel == 0 )
620 throw lang::DisposedException();
622 uno::Reference< drawing::XLayer > xLayer;
624 if(mpModel->mpDoc)
626 SvxShape* pShape = SvxShape::getImplementation( xShape );
627 SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
628 if(pObj)
630 SdrLayerID aId = pObj->GetLayer();
631 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
632 xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
635 return xLayer;
638 // XIndexAccess
639 sal_Int32 SAL_CALL SdLayerManager::getCount()
640 throw(uno::RuntimeException)
642 OGuard aGuard( Application::GetSolarMutex() );
644 if( mpModel == 0 )
645 throw lang::DisposedException();
647 if( mpModel->mpDoc )
649 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
650 return rLayerAdmin.GetLayerCount();
653 return 0;
656 uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
657 throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
659 OGuard aGuard( Application::GetSolarMutex() );
661 if( mpModel == 0 )
662 throw lang::DisposedException();
664 if( nLayer >= getCount() || nLayer < 0 )
665 throw lang::IndexOutOfBoundsException();
667 uno::Any aAny;
669 if( mpModel->mpDoc )
671 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
672 uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
673 aAny <<= xLayer;
675 return aAny;
679 // XNameAccess
680 uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
681 throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
683 OGuard aGuard( Application::GetSolarMutex() );
685 if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
686 throw lang::DisposedException();
688 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
689 SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), FALSE );
690 if( pLayer == NULL )
691 throw container::NoSuchElementException();
693 return uno::Any( GetLayer (pLayer) );
696 uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
697 throw(uno::RuntimeException)
699 OGuard aGuard( Application::GetSolarMutex() );
701 if( mpModel == 0 )
702 throw lang::DisposedException();
704 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
705 const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
707 uno::Sequence< OUString > aSeq( nLayerCount );
709 OUString* pStrings = aSeq.getArray();
710 SdrLayer* pLayer;
712 for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
714 pLayer = rLayerAdmin.GetLayer( nLayer );
715 if( pLayer )
716 *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
719 return aSeq;
722 sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) throw(uno::RuntimeException)
724 OGuard aGuard( Application::GetSolarMutex() );
726 if( mpModel == 0 )
727 throw lang::DisposedException();
729 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
731 return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), FALSE );
734 // XElementAccess
735 uno::Type SAL_CALL SdLayerManager::getElementType()
736 throw(uno::RuntimeException)
738 return ITYPE( drawing::XLayer );
741 sal_Bool SAL_CALL SdLayerManager::hasElements() throw(uno::RuntimeException)
743 return getCount() > 0;
746 /** Falls an den Layern was geaendert wurde sorgt diese Methode dafuer, das
747 die Aenderungen auch in der sdbcx::View sichtbar gemacht werden */
748 void SdLayerManager::UpdateLayerView( sal_Bool modify ) const throw()
750 if(mpModel->mpDocShell)
752 ::sd::DrawViewShell* pDrViewSh =
753 PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
755 if(pDrViewSh)
757 sal_Bool bLayerMode = pDrViewSh->IsLayerModeActive();
758 pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
759 pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
762 if(modify)
763 mpModel->mpDoc->SetChanged(sal_True);
767 /** */
768 ::sd::View* SdLayerManager::GetView() const throw()
770 if( mpModel->mpDocShell )
772 ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
773 if(pViewSh)
774 return pViewSh->GetView();
776 return NULL;
781 namespace
783 /** Compare two pointers to <type>SdrLayer</type> objects.
784 @param xRef
785 The implementing SdLayer class provides the first pointer by the
786 <member>SdLayer::GetSdrLayer</member> method.
787 @param pSearchData
788 This void pointer is the second pointer to an <type>SdrLayer</type>
789 object.
790 @return
791 Return </True> if both pointers point to the same object.
793 sal_Bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
795 uno::Reference<uno::XInterface> xLayer (xRef);
796 if (xLayer.is())
798 SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
799 if (pSdLayer != NULL)
801 SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
802 if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
803 return sal_True;
806 return sal_False;
810 /** Use the <member>mpLayers</member> container of weak references to either
811 retrieve and return a previously created <type>XLayer</type> object for
812 the given <type>SdrLayer</type> object or create and remember a new one.
814 uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
816 uno::WeakReference<uno::XInterface> xRef;
817 uno::Reference<drawing::XLayer> xLayer;
819 // Search existing xLayer for the given pLayer.
820 if (mpLayers->findRef (xRef, (void*)pLayer, compare_layers))
821 xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
823 // Create the xLayer if necessary.
824 if ( ! xLayer.is())
826 xLayer = new SdLayer (this, pLayer);
828 // Remember the new xLayer for future calls.
829 xRef = uno::Reference<uno::XInterface> (xLayer, uno::UNO_QUERY);
830 mpLayers->insert (xRef);
833 return xLayer;