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