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