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 {
172 return OUString( OUString::createFromAscii(sUNO_SdLayer) );
173 }
174
supportsService(const OUString & ServiceName)175 sal_Bool SAL_CALL SdLayer::supportsService( const OUString& ServiceName )
176 {
177 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
178 }
179
getSupportedServiceNames()180 uno::Sequence< OUString > SAL_CALL SdLayer::getSupportedServiceNames()
181 {
182 OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayer) );
183 uno::Sequence< OUString > aSeq( &aServiceName, 1 );
184 return aSeq;
185 }
186
187 // beans::XPropertySet
getPropertySetInfo()188 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdLayer::getPropertySetInfo( )
189 {
190 OGuard aGuard( Application::GetSolarMutex() );
191 return pPropSet->getPropertySetInfo();
192 }
193
setPropertyValue(const OUString & aPropertyName,const uno::Any & aValue)194 void SAL_CALL SdLayer::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
195 {
196 OGuard aGuard( Application::GetSolarMutex() );
197
198 if(pLayer == NULL || pLayerManager == NULL)
199 throw lang::DisposedException();
200
201 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
202
203 switch( pEntry ? pEntry->nWID : -1 )
204 {
205 case WID_LAYER_LOCKED:
206 {
207 sal_Bool bValue = sal_False;
208 if(!sd::any2bool( aValue, bValue ))
209 throw lang::IllegalArgumentException();
210 set( LOCKED, bValue );
211 break;
212 }
213 case WID_LAYER_PRINTABLE:
214 {
215 sal_Bool bValue = sal_False;
216 if(!sd::any2bool( aValue, bValue ))
217 throw lang::IllegalArgumentException();
218 set( PRINTABLE, bValue );
219 break;
220 }
221 case WID_LAYER_VISIBLE:
222 {
223 sal_Bool bValue = sal_False;
224 if(!sd::any2bool( aValue, bValue ))
225 throw lang::IllegalArgumentException();
226 set( VISIBLE, bValue );
227 break;
228 }
229 case WID_LAYER_NAME:
230 {
231 OUString aName;
232 if(!(aValue >>= aName))
233 throw lang::IllegalArgumentException();
234
235 pLayer->SetName(SdLayer::convertToInternalName( aName ) );
236 pLayerManager->UpdateLayerView();
237 break;
238 }
239
240 case WID_LAYER_TITLE:
241 {
242 OUString sTitle;
243 if(!(aValue >>= sTitle))
244 throw lang::IllegalArgumentException();
245
246 pLayer->SetTitle(sTitle);
247 break;
248 }
249
250 case WID_LAYER_DESC:
251 {
252 OUString sDescription;
253 if(!(aValue >>= sDescription))
254 throw lang::IllegalArgumentException();
255
256 pLayer->SetDescription(sDescription);
257 break;
258 }
259
260 default:
261 throw beans::UnknownPropertyException();
262 }
263
264 #ifndef SVX_LIGHT
265 if( pLayerManager->GetDocShell() )
266 pLayerManager->GetDocShell()->SetModified();
267 #endif
268 }
269
getPropertyValue(const OUString & PropertyName)270 uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
271 {
272 OGuard aGuard( Application::GetSolarMutex() );
273
274 if(pLayer == NULL || pLayerManager == NULL)
275 throw lang::DisposedException();
276
277 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
278
279 uno::Any aValue;
280
281 switch( pEntry ? pEntry->nWID : -1 )
282 {
283 case WID_LAYER_LOCKED:
284 sd::bool2any( get( LOCKED ), aValue );
285 break;
286 case WID_LAYER_PRINTABLE:
287 sd::bool2any( get( PRINTABLE ), aValue );
288 break;
289 case WID_LAYER_VISIBLE:
290 sd::bool2any( get( VISIBLE ), aValue );
291 break;
292 case WID_LAYER_NAME:
293 {
294 OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
295 aValue <<= aRet;
296 break;
297 }
298 case WID_LAYER_TITLE:
299 aValue <<= OUString( pLayer->GetTitle() );
300 break;
301 case WID_LAYER_DESC:
302 aValue <<= OUString( pLayer->GetDescription() );
303 break;
304 default:
305 throw beans::UnknownPropertyException();
306 }
307
308 return aValue;
309 }
310
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)311 void SAL_CALL SdLayer::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)312 void SAL_CALL SdLayer::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)313 void SAL_CALL SdLayer::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)314 void SAL_CALL SdLayer::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
315
316 /** */
get(LayerAttribute what)317 sal_Bool SdLayer::get( LayerAttribute what ) throw()
318 {
319 if(pLayer&&pLayerManager)
320 {
321 // Versuch 1. ist eine beliebige Seite geoeffnet?
322 ::sd::View *pView = pLayerManager->GetView();
323 SdrPageView* pSdrPageView = NULL;
324 if(pView)
325 pSdrPageView = pView->GetSdrPageView();
326
327 if(pSdrPageView)
328 {
329 String aLayerName = pLayer->GetName();
330 switch(what)
331 {
332 case VISIBLE: return pSdrPageView->IsLayerVisible(aLayerName);
333 case PRINTABLE: return pSdrPageView->IsLayerPrintable(aLayerName);
334 case LOCKED: return pSdrPageView->IsLayerLocked(aLayerName);
335 }
336 }
337
338 #ifndef SVX_LIGHT
339 // Versuch 2. Info von der FrameView besorgen
340 if(pLayerManager->GetDocShell())
341 {
342 ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
343 if(pFrameView)
344 switch(what)
345 {
346 case VISIBLE: return pFrameView->GetVisibleLayers().IsSet(pLayer->GetID());
347 case PRINTABLE: return pFrameView->GetPrintableLayers().IsSet(pLayer->GetID());
348 case LOCKED: return pFrameView->GetLockedLayers().IsSet(pLayer->GetID());
349 }
350 }
351 #endif
352 }
353 return sal_False; //TODO: uno::Exception?
354 }
355
set(LayerAttribute what,sal_Bool flag)356 void SdLayer::set( LayerAttribute what, sal_Bool flag ) throw()
357 {
358 if(pLayer&&pLayerManager)
359 {
360 // Versuch 1. ist eine beliebige Seite geoeffnet?
361 ::sd::View *pView = pLayerManager->GetView();
362 SdrPageView* pSdrPageView = NULL;
363 if(pView)
364 pSdrPageView = pView->GetSdrPageView();
365
366 if(pSdrPageView)
367 {
368 String aLayerName(pLayer->GetName());
369 switch(what)
370 {
371 case VISIBLE: pSdrPageView->SetLayerVisible(aLayerName,flag);
372 break;
373 case PRINTABLE: pSdrPageView->SetLayerPrintable(aLayerName,flag);
374 break;
375 case LOCKED: pSdrPageView->SetLayerLocked(aLayerName,flag);
376 break;
377 }
378 }
379
380 #ifndef SVX_LIGHT
381 // Versuch 2. Info von der FrameView besorgen
382 if(pLayerManager->GetDocShell())
383 {
384 ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
385
386 if(pFrameView)
387 {
388 SetOfByte aNewLayers;
389 switch(what)
390 {
391 case VISIBLE: aNewLayers = pFrameView->GetVisibleLayers();
392 break;
393 case PRINTABLE: aNewLayers = pFrameView->GetPrintableLayers();
394 break;
395 case LOCKED: aNewLayers = pFrameView->GetLockedLayers();
396 break;
397 }
398
399 aNewLayers.Set(pLayer->GetID(),flag);
400
401 switch(what)
402 {
403 case VISIBLE: pFrameView->SetVisibleLayers(aNewLayers);
404 break;
405 case PRINTABLE: pFrameView->SetPrintableLayers(aNewLayers);
406 break;
407 case LOCKED: pFrameView->SetLockedLayers(aNewLayers);
408 break;
409 }
410 return;
411 }
412 }
413 #endif
414 }
415 //TODO: uno::Exception?
416 }
417
418
419
420
421 //===== ::com::sun::star::container::XChild =================================
422
getParent(void)423 uno::Reference<uno::XInterface> SAL_CALL SdLayer::getParent (void)
424 {
425 OGuard aGuard( Application::GetSolarMutex() );
426
427 if( pLayerManager == NULL )
428 throw lang::DisposedException();
429
430 return uno::Reference<uno::XInterface> (mxLayerManager, uno::UNO_QUERY);
431 }
432
433
setParent(const uno::Reference<uno::XInterface> &)434 void SAL_CALL SdLayer::setParent (const uno::Reference<uno::XInterface >& )
435 {
436 throw lang::NoSupportException ();
437 }
438
439 // XComponent
dispose()440 void SAL_CALL SdLayer::dispose( )
441 {
442 pLayerManager = 0;
443 mxLayerManager = 0;
444 pLayer = 0;
445 }
446
addEventListener(const uno::Reference<lang::XEventListener> &)447 void SAL_CALL SdLayer::addEventListener( const uno::Reference< lang::XEventListener >& )
448 {
449 DBG_ERROR("not implemented!");
450 }
451
removeEventListener(const uno::Reference<lang::XEventListener> &)452 void SAL_CALL SdLayer::removeEventListener( const uno::Reference< lang::XEventListener >& )
453 {
454 DBG_ERROR("not implemented!");
455 }
456
457
458 //=============================================================================
459 // class SdLayerManager
460 //=============================================================================
461
462 /** */
SdLayerManager(SdXImpressDocument & rMyModel)463 SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
464 :mpModel( &rMyModel)
465 {
466 mpLayers = new SvUnoWeakContainer;
467 }
468
469 /** */
~SdLayerManager()470 SdLayerManager::~SdLayerManager() throw()
471 {
472 dispose();
473 }
474
475 // uno helper
476 UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
477
478 // XComponent
dispose()479 void SAL_CALL SdLayerManager::dispose( )
480 {
481 mpModel = 0;
482 if( mpLayers )
483 {
484 mpLayers->dispose();
485
486 delete mpLayers;
487 mpLayers = 0;
488 }
489 }
490
addEventListener(const uno::Reference<lang::XEventListener> &)491 void SAL_CALL SdLayerManager::addEventListener( const uno::Reference< lang::XEventListener >& )
492 {
493 DBG_ERROR("not implemented!");
494 }
495
removeEventListener(const uno::Reference<lang::XEventListener> &)496 void SAL_CALL SdLayerManager::removeEventListener( const uno::Reference< lang::XEventListener >& )
497 {
498 DBG_ERROR("not implemented!");
499 }
500
501 // XServiceInfo
getImplementationName()502 OUString SAL_CALL SdLayerManager::getImplementationName()
503 {
504 return OUString( OUString::createFromAscii(sUNO_SdLayerManager) );
505 }
506
supportsService(const OUString & ServiceName)507 sal_Bool SAL_CALL SdLayerManager::supportsService( const OUString& ServiceName )
508 {
509 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
510 }
511
getSupportedServiceNames()512 uno::Sequence< OUString > SAL_CALL SdLayerManager::getSupportedServiceNames()
513 {
514 OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayerManager) );
515 uno::Sequence< OUString > aSeq( &aServiceName, 1 );
516 return aSeq;
517 }
518
519 // XLayerManager
insertNewByIndex(sal_Int32 nIndex)520 uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
521 {
522 OGuard aGuard( Application::GetSolarMutex() );
523
524 if( mpModel == 0 )
525 throw lang::DisposedException();
526
527 uno::Reference< drawing::XLayer > xLayer;
528
529 if( mpModel->mpDoc )
530 {
531 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
532 sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
533 sal_uInt16 nLayer = nLayerCnt - 2 + 1;
534 String aLayerName;
535
536 // Ueberpruefung auf schon vorhandene Namen
537 while( aLayerName.Len()==0 || rLayerAdmin.GetLayer( aLayerName, sal_False) )
538 {
539 aLayerName = String(SdResId(STR_LAYER));
540 aLayerName += String::CreateFromInt32( (sal_Int32)nLayer );
541 nLayer++;
542 }
543
544 SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
545 const sal_Int32 nMax=rLA.GetLayerCount();
546 if (nIndex>nMax) nIndex=nMax;
547 xLayer = GetLayer (rLA.NewLayer(aLayerName,(sal_uInt16)nIndex));
548 mpModel->SetModified();
549 }
550 return xLayer;
551 }
552
remove(const uno::Reference<drawing::XLayer> & xLayer)553 void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
554 {
555 OGuard aGuard( Application::GetSolarMutex() );
556
557 if( mpModel == 0 )
558 throw lang::DisposedException();
559
560 SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
561
562 if(pSdLayer && GetView())
563 {
564 const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
565 GetView()->DeleteLayer( pSdrLayer->GetName() );
566
567 UpdateLayerView();
568 }
569
570 mpModel->SetModified();
571 }
572
attachShapeToLayer(const uno::Reference<drawing::XShape> & xShape,const uno::Reference<drawing::XLayer> & xLayer)573 void SAL_CALL SdLayerManager::attachShapeToLayer( const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XLayer >& xLayer )
574 {
575 OGuard aGuard( Application::GetSolarMutex() );
576
577 if( mpModel == 0 )
578 throw lang::DisposedException();
579
580 SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
581 SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
582 if(pSdrLayer==NULL)
583 return;
584
585 SvxShape* pShape = SvxShape::getImplementation( xShape );
586 SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
587
588 if(pSdrObject && pSdrLayer )
589 pSdrObject->SetLayer(pSdrLayer->GetID());
590
591 mpModel->SetModified();
592 }
593
getLayerForShape(const uno::Reference<drawing::XShape> & xShape)594 uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape )
595 {
596 OGuard aGuard( Application::GetSolarMutex() );
597
598 if( mpModel == 0 )
599 throw lang::DisposedException();
600
601 uno::Reference< drawing::XLayer > xLayer;
602
603 if(mpModel->mpDoc)
604 {
605 SvxShape* pShape = SvxShape::getImplementation( xShape );
606 SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
607 if(pObj)
608 {
609 SdrLayerID aId = pObj->GetLayer();
610 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
611 xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
612 }
613 }
614 return xLayer;
615 }
616
617 // XIndexAccess
getCount()618 sal_Int32 SAL_CALL SdLayerManager::getCount()
619 {
620 OGuard aGuard( Application::GetSolarMutex() );
621
622 if( mpModel == 0 )
623 throw lang::DisposedException();
624
625 if( mpModel->mpDoc )
626 {
627 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
628 return rLayerAdmin.GetLayerCount();
629 }
630
631 return 0;
632 }
633
getByIndex(sal_Int32 nLayer)634 uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
635 {
636 OGuard aGuard( Application::GetSolarMutex() );
637
638 if( mpModel == 0 )
639 throw lang::DisposedException();
640
641 if( nLayer >= getCount() || nLayer < 0 )
642 throw lang::IndexOutOfBoundsException();
643
644 uno::Any aAny;
645
646 if( mpModel->mpDoc )
647 {
648 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
649 uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
650 aAny <<= xLayer;
651 }
652 return aAny;
653 }
654
655
656 // XNameAccess
getByName(const OUString & aName)657 uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
658 {
659 OGuard aGuard( Application::GetSolarMutex() );
660
661 if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
662 throw lang::DisposedException();
663
664 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
665 SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), sal_False );
666 if( pLayer == NULL )
667 throw container::NoSuchElementException();
668
669 return uno::Any( GetLayer (pLayer) );
670 }
671
getElementNames()672 uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
673 {
674 OGuard aGuard( Application::GetSolarMutex() );
675
676 if( mpModel == 0 )
677 throw lang::DisposedException();
678
679 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
680 const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
681
682 uno::Sequence< OUString > aSeq( nLayerCount );
683
684 OUString* pStrings = aSeq.getArray();
685 SdrLayer* pLayer;
686
687 for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
688 {
689 pLayer = rLayerAdmin.GetLayer( nLayer );
690 if( pLayer )
691 *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
692 }
693
694 return aSeq;
695 }
696
hasByName(const OUString & aName)697 sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName )
698 {
699 OGuard aGuard( Application::GetSolarMutex() );
700
701 if( mpModel == 0 )
702 throw lang::DisposedException();
703
704 SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
705
706 return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), sal_False );
707 }
708
709 // XElementAccess
getElementType()710 uno::Type SAL_CALL SdLayerManager::getElementType()
711 {
712 return ITYPE( drawing::XLayer );
713 }
714
hasElements()715 sal_Bool SAL_CALL SdLayerManager::hasElements()
716 {
717 return getCount() > 0;
718 }
719
720 /** Falls an den Layern was geaendert wurde sorgt diese Methode dafuer, das
721 die Aenderungen auch in der sdbcx::View sichtbar gemacht werden */
UpdateLayerView(sal_Bool modify) const722 void SdLayerManager::UpdateLayerView( sal_Bool modify ) const throw()
723 {
724 if(mpModel->mpDocShell)
725 {
726 ::sd::DrawViewShell* pDrViewSh =
727 PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
728
729 if(pDrViewSh)
730 {
731 sal_Bool bLayerMode = pDrViewSh->IsLayerModeActive();
732 pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
733 pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
734 }
735
736 if(modify)
737 mpModel->mpDoc->SetChanged(sal_True);
738 }
739 }
740
741 /** */
GetView() const742 ::sd::View* SdLayerManager::GetView() const throw()
743 {
744 if( mpModel->mpDocShell )
745 {
746 ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
747 if(pViewSh)
748 return pViewSh->GetView();
749 }
750 return NULL;
751 }
752
753
754
755 namespace
756 {
757 /** Compare two pointers to <type>SdrLayer</type> objects.
758 @param xRef
759 The implementing SdLayer class provides the first pointer by the
760 <member>SdLayer::GetSdrLayer</member> method.
761 @param pSearchData
762 This void pointer is the second pointer to an <type>SdrLayer</type>
763 object.
764 @return
765 Return </True> if both pointers point to the same object.
766 */
compare_layers(uno::WeakReference<uno::XInterface> xRef,void * pSearchData)767 sal_Bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
768 {
769 uno::Reference<uno::XInterface> xLayer (xRef);
770 if (xLayer.is())
771 {
772 SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
773 if (pSdLayer != NULL)
774 {
775 SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
776 if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
777 return sal_True;
778 }
779 }
780 return sal_False;
781 }
782 }
783
784 /** Use the <member>mpLayers</member> container of weak references to either
785 retrieve and return a previously created <type>XLayer</type> object for
786 the given <type>SdrLayer</type> object or create and remember a new one.
787 */
GetLayer(SdrLayer * pLayer)788 uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
789 {
790 uno::WeakReference<uno::XInterface> xRef;
791 uno::Reference<drawing::XLayer> xLayer;
792
793 // Search existing xLayer for the given pLayer.
794 if (mpLayers->findRef (xRef, (void*)pLayer, compare_layers))
795 xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
796
797 // Create the xLayer if necessary.
798 if ( ! xLayer.is())
799 {
800 xLayer = new SdLayer (this, pLayer);
801
802 // Remember the new xLayer for future calls.
803 uno::WeakReference<uno::XInterface> wRef(xLayer);
804 mpLayers->insert(wRef);
805 }
806
807 return xLayer;
808 }
809