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