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