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