xref: /trunk/main/svx/source/unodraw/unopage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define _SVX_USE_UNOGLOBALS_
32*cdf0e10cSrcweir #include <com/sun/star/document/EventObject.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
34*cdf0e10cSrcweir #include <vos/mutex.hxx>
35*cdf0e10cSrcweir #include <osl/mutex.hxx>
36*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
37*cdf0e10cSrcweir #include <sot/clsids.hxx>
38*cdf0e10cSrcweir #include <comphelper/serviceinfohelper.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <rtl/uuid.h>
41*cdf0e10cSrcweir #include <rtl/memory.h>
42*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
43*cdf0e10cSrcweir #include <svx/svdpool.hxx>
44*cdf0e10cSrcweir #include <svx/svdobj.hxx>
45*cdf0e10cSrcweir #include <svx/svdoole2.hxx>
46*cdf0e10cSrcweir #include <svx/svdpage.hxx>
47*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
48*cdf0e10cSrcweir #include <svx/svdview.hxx>
49*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
50*cdf0e10cSrcweir #include <svx/unopage.hxx>
51*cdf0e10cSrcweir #include "shapeimpl.hxx"
52*cdf0e10cSrcweir #include "svx/globl3d.hxx"
53*cdf0e10cSrcweir #include <svx/polysc3d.hxx>
54*cdf0e10cSrcweir #include <svx/unoprov.hxx>
55*cdf0e10cSrcweir #include <svx/svdopath.hxx>
56*cdf0e10cSrcweir #include "svx/unoapi.hxx"
57*cdf0e10cSrcweir #include <svx/svdomeas.hxx>
58*cdf0e10cSrcweir #include <svx/extrud3d.hxx>
59*cdf0e10cSrcweir #include <svx/lathe3d.hxx>
60*cdf0e10cSrcweir #include <vcl/svapp.hxx>
61*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using ::rtl::OUString;
64*cdf0e10cSrcweir using namespace ::vos;
65*cdf0e10cSrcweir using namespace ::cppu;
66*cdf0e10cSrcweir using namespace ::com::sun::star;
67*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
68*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
69*cdf0e10cSrcweir using namespace ::com::sun::star::container;
70*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir #define INTERFACE_TYPE( xint ) \
73*cdf0e10cSrcweir     ::getCppuType((const Reference< xint >*)0)
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir #define QUERYINT( xint ) \
76*cdf0e10cSrcweir     if( rType == ::getCppuType((const Reference< xint >*)0) ) \
77*cdf0e10cSrcweir         aAny <<= Reference< xint >(this)
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir DECLARE_LIST( SvxDrawPageList, SvxDrawPage * )
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir /**********************************************************************
83*cdf0e10cSrcweir * class SvxDrawPage                                                   *
84*cdf0e10cSrcweir **********************************************************************/
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
87*cdf0e10cSrcweir DBG_NAME(SvxDrawPage)
88*cdf0e10cSrcweir SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
89*cdf0e10cSrcweir : mrBHelper( getMutex() )
90*cdf0e10cSrcweir , mpPage( pInPage )
91*cdf0e10cSrcweir , mpModel( 0 )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     DBG_CTOR(SvxDrawPage,NULL);
94*cdf0e10cSrcweir     // Am Broadcaster anmelden
95*cdf0e10cSrcweir     if( mpPage )
96*cdf0e10cSrcweir         mpModel = mpPage->GetModel();
97*cdf0e10cSrcweir     if( mpModel )
98*cdf0e10cSrcweir         StartListening( *mpModel );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     // Erzeugen der (hidden) ::com::sun::star::sdbcx::View
102*cdf0e10cSrcweir     mpView = new SdrView( mpModel );
103*cdf0e10cSrcweir     if( mpView )
104*cdf0e10cSrcweir         mpView->SetDesignMode(sal_True);
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir //----------------------------------------------------------------------
108*cdf0e10cSrcweir // Ctor fuer SvxDrawPage_NewInstance()
109*cdf0e10cSrcweir //----------------------------------------------------------------------
110*cdf0e10cSrcweir SvxDrawPage::SvxDrawPage() throw()
111*cdf0e10cSrcweir : mrBHelper( getMutex() )
112*cdf0e10cSrcweir , mpPage( NULL )
113*cdf0e10cSrcweir , mpModel( NULL )
114*cdf0e10cSrcweir , mpView( NULL )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     DBG_CTOR(SvxDrawPage,NULL);
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //----------------------------------------------------------------------
120*cdf0e10cSrcweir SvxDrawPage::~SvxDrawPage() throw()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" );
123*cdf0e10cSrcweir     if( !mrBHelper.bDisposed )
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         acquire();
126*cdf0e10cSrcweir         dispose();
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     DBG_DTOR(SvxDrawPage,NULL);
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir //----------------------------------------------------------------------
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir // XInterface
134*cdf0e10cSrcweir void SvxDrawPage::release() throw()
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir /*
137*cdf0e10cSrcweir     uno::Reference< uno::XInterface > x( xDelegator );
138*cdf0e10cSrcweir     if (! x.is())
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         if (osl_decrementInterlockedCount( &m_refCount ) == 0)
141*cdf0e10cSrcweir         {
142*cdf0e10cSrcweir             if (! mrBHelper.bDisposed)
143*cdf0e10cSrcweir             {
144*cdf0e10cSrcweir                 uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this );
145*cdf0e10cSrcweir                 // First dispose
146*cdf0e10cSrcweir                 try
147*cdf0e10cSrcweir                 {
148*cdf0e10cSrcweir                     dispose();
149*cdf0e10cSrcweir                 }
150*cdf0e10cSrcweir                 catch(::com::sun::star::uno::Exception&)
151*cdf0e10cSrcweir                 {
152*cdf0e10cSrcweir                     // release should not throw exceptions
153*cdf0e10cSrcweir                 }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir                 // only the alive ref holds the object
156*cdf0e10cSrcweir                 OSL_ASSERT( m_refCount == 1 );
157*cdf0e10cSrcweir                 // destroy the object if xHoldAlive decrement the refcount to 0
158*cdf0e10cSrcweir                 return;
159*cdf0e10cSrcweir             }
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir         // restore the reference count
162*cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir */
165*cdf0e10cSrcweir     OWeakAggObject::release();
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //----------------------------------------------------------------------
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir SvxDrawPage* SvxDrawPage::GetPageForSdrPage( SdrPage* mpPage ) throw()
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     return getImplementation( mpPage->getUnoPage() );
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir // XComponent
176*cdf0e10cSrcweir void SvxDrawPage::disposing() throw()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     if( mpModel )
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         EndListening( *mpModel );
181*cdf0e10cSrcweir         mpModel = NULL;
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     if( mpView )
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir         delete mpView;
187*cdf0e10cSrcweir         mpView = NULL;
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir     mpPage = 0;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir //----------------------------------------------------------------------
193*cdf0e10cSrcweir // XComponent
194*cdf0e10cSrcweir //----------------------------------------------------------------------
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void SvxDrawPage::dispose()
197*cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     OGuard aSolarGuard( Application::GetSolarMutex() );
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     // An frequently programming error is to release the last
202*cdf0e10cSrcweir     // reference to this object in the disposing message.
203*cdf0e10cSrcweir     // Make it rubust, hold a self Reference.
204*cdf0e10cSrcweir     uno::Reference< lang::XComponent > xSelf( this );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     // Guard dispose against multible threading
207*cdf0e10cSrcweir     // Remark: It is an error to call dispose more than once
208*cdf0e10cSrcweir     sal_Bool bDoDispose = sal_False;
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir     osl::MutexGuard aGuard( mrBHelper.rMutex );
211*cdf0e10cSrcweir     if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         // only one call go into this section
214*cdf0e10cSrcweir         mrBHelper.bInDispose = sal_True;
215*cdf0e10cSrcweir         bDoDispose = sal_True;
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     // Do not hold the mutex because we are broadcasting
220*cdf0e10cSrcweir     if( bDoDispose )
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         // Create an event with this as sender
223*cdf0e10cSrcweir         try
224*cdf0e10cSrcweir         {
225*cdf0e10cSrcweir             uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
226*cdf0e10cSrcweir             ::com::sun::star::document::EventObject aEvt;
227*cdf0e10cSrcweir             aEvt.Source = xSource;
228*cdf0e10cSrcweir             // inform all listeners to release this object
229*cdf0e10cSrcweir             // The listener container are automaticly cleared
230*cdf0e10cSrcweir             mrBHelper.aLC.disposeAndClear( aEvt );
231*cdf0e10cSrcweir             // notify subclasses to do their dispose
232*cdf0e10cSrcweir             disposing();
233*cdf0e10cSrcweir         }
234*cdf0e10cSrcweir         catch(::com::sun::star::uno::Exception& e)
235*cdf0e10cSrcweir         {
236*cdf0e10cSrcweir             // catch exception and throw again but signal that
237*cdf0e10cSrcweir             // the object was disposed. Dispose should be called
238*cdf0e10cSrcweir             // only once.
239*cdf0e10cSrcweir             mrBHelper.bDisposed = sal_True;
240*cdf0e10cSrcweir             mrBHelper.bInDispose = sal_False;
241*cdf0e10cSrcweir             throw e;
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir         // the values bDispose and bInDisposing must set in this order.
245*cdf0e10cSrcweir         // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
246*cdf0e10cSrcweir         mrBHelper.bDisposed = sal_True;
247*cdf0e10cSrcweir         mrBHelper.bInDispose = sal_False;
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir //----------------------------------------------------------------------
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     if( mpModel == 0 )
259*cdf0e10cSrcweir         throw lang::DisposedException();
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //----------------------------------------------------------------------
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     if( mpModel == 0 )
271*cdf0e10cSrcweir         throw lang::DisposedException();
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir //----------------------------------------------------------------------
277*cdf0e10cSrcweir // SfxListener
278*cdf0e10cSrcweir //----------------------------------------------------------------------
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir /*
283*cdf0e10cSrcweir     if( mpModel )
284*cdf0e10cSrcweir     {
285*cdf0e10cSrcweir         const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
286*cdf0e10cSrcweir         if( pSdrHint )
287*cdf0e10cSrcweir         {
288*cdf0e10cSrcweir             switch( pSdrHint->GetKind() )
289*cdf0e10cSrcweir             {
290*cdf0e10cSrcweir             case HINT_MODELCLEARED:
291*cdf0e10cSrcweir                 dispose();
292*cdf0e10cSrcweir                 break;
293*cdf0e10cSrcweir             default:
294*cdf0e10cSrcweir                 break;
295*cdf0e10cSrcweir             }
296*cdf0e10cSrcweir         }
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir */
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir //----------------------------------------------------------------------
302*cdf0e10cSrcweir // ::com::sun::star::drawing::XShapes
303*cdf0e10cSrcweir //----------------------------------------------------------------------
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
306*cdf0e10cSrcweir     throw( uno::RuntimeException )
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
311*cdf0e10cSrcweir         throw lang::DisposedException();
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     SvxShape* pShape = SvxShape::getImplementation( xShape );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     if( NULL == pShape )
316*cdf0e10cSrcweir         return;
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     SdrObject *pObj = pShape->GetSdrObject();
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     if(!pObj)
321*cdf0e10cSrcweir     {
322*cdf0e10cSrcweir         pObj = CreateSdrObject( xShape );
323*cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir     else if ( !pObj->IsInserted() )
326*cdf0e10cSrcweir     {
327*cdf0e10cSrcweir         pObj->SetModel(mpModel);
328*cdf0e10cSrcweir         mpPage->InsertObject( pObj );
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     pShape->Create( pObj, this );
332*cdf0e10cSrcweir     OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     mpModel->SetChanged();
335*cdf0e10cSrcweir }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir //----------------------------------------------------------------------
338*cdf0e10cSrcweir void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
339*cdf0e10cSrcweir     throw( uno::RuntimeException )
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
344*cdf0e10cSrcweir         throw lang::DisposedException();
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     SvxShape* pShape = SvxShape::getImplementation( xShape );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     if(pShape)
349*cdf0e10cSrcweir     {
350*cdf0e10cSrcweir         SdrObject*  pObj = pShape->GetSdrObject();
351*cdf0e10cSrcweir         if(pObj)
352*cdf0e10cSrcweir         {
353*cdf0e10cSrcweir             // SdrObject aus der Page loeschen
354*cdf0e10cSrcweir             sal_uInt32 nCount = mpPage->GetObjCount();
355*cdf0e10cSrcweir             for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ )
356*cdf0e10cSrcweir             {
357*cdf0e10cSrcweir                 if(mpPage->GetObj(nNum) == pObj)
358*cdf0e10cSrcweir                 {
359*cdf0e10cSrcweir                     OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
360*cdf0e10cSrcweir                     SdrObject::Free( pObj );
361*cdf0e10cSrcweir                     break;
362*cdf0e10cSrcweir                 }
363*cdf0e10cSrcweir             }
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     if( mpModel )
368*cdf0e10cSrcweir         mpModel->SetChanged();
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir //----------------------------------------------------------------------
372*cdf0e10cSrcweir // ::com::sun::star::container::XIndexAccess
373*cdf0e10cSrcweir //----------------------------------------------------------------------
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir sal_Int32 SAL_CALL SvxDrawPage::getCount()
376*cdf0e10cSrcweir     throw( uno::RuntimeException )
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
381*cdf0e10cSrcweir         throw lang::DisposedException();
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     return( (sal_Int32) mpPage->GetObjCount() );
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir //----------------------------------------------------------------------
387*cdf0e10cSrcweir uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
388*cdf0e10cSrcweir     throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
393*cdf0e10cSrcweir         throw lang::DisposedException();
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() )
396*cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     SdrObject* pObj = mpPage->GetObj( Index );
399*cdf0e10cSrcweir     if( pObj == NULL )
400*cdf0e10cSrcweir         throw uno::RuntimeException();
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir //----------------------------------------------------------------------
408*cdf0e10cSrcweir // ::com::sun::star::container::XElementAccess
409*cdf0e10cSrcweir //----------------------------------------------------------------------
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir uno::Type SAL_CALL SvxDrawPage::getElementType()
412*cdf0e10cSrcweir     throw( uno::RuntimeException )
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir     return INTERFACE_TYPE( drawing::XShape );
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir //----------------------------------------------------------------------
418*cdf0e10cSrcweir sal_Bool SAL_CALL SvxDrawPage::hasElements()
419*cdf0e10cSrcweir     throw( uno::RuntimeException )
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
424*cdf0e10cSrcweir         throw lang::DisposedException();
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     return mpPage && mpPage->GetObjCount()>0;
427*cdf0e10cSrcweir }
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir namespace
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir     void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
432*cdf0e10cSrcweir     {
433*cdf0e10cSrcweir         SvxShape* pShape = SvxShape::getImplementation( _rxShape );
434*cdf0e10cSrcweir         if ( !pShape )
435*cdf0e10cSrcweir             return;
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         SdrObject* pObj = pShape->GetSdrObject();
438*cdf0e10cSrcweir         if ( !pObj )
439*cdf0e10cSrcweir             return;
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir         _rView.MarkObj( pObj, &_rPageView );
442*cdf0e10cSrcweir     }
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir //----------------------------------------------------------------------
446*cdf0e10cSrcweir // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen
447*cdf0e10cSrcweir //         SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein.
448*cdf0e10cSrcweir //----------------------------------------------------------------------
449*cdf0e10cSrcweir void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
450*cdf0e10cSrcweir {
451*cdf0e10cSrcweir     DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
452*cdf0e10cSrcweir     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir     if(pPageView!=NULL && mpView!=NULL)
455*cdf0e10cSrcweir     {
456*cdf0e10cSrcweir         mpView->UnmarkAllObj( pPageView );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir         long nCount = aShapes->getCount();
459*cdf0e10cSrcweir         for( long i = 0; i < nCount; i++ )
460*cdf0e10cSrcweir         {
461*cdf0e10cSrcweir             uno::Any aAny( aShapes->getByIndex(i) );
462*cdf0e10cSrcweir             Reference< drawing::XShape > xShape;
463*cdf0e10cSrcweir             if( aAny >>= xShape )
464*cdf0e10cSrcweir                 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
465*cdf0e10cSrcweir         }
466*cdf0e10cSrcweir     }
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir //----------------------------------------------------------------------
470*cdf0e10cSrcweir // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen
471*cdf0e10cSrcweir //         SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein.
472*cdf0e10cSrcweir //----------------------------------------------------------------------
473*cdf0e10cSrcweir void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
476*cdf0e10cSrcweir     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir     if(pPageView!=NULL && mpView != NULL)
479*cdf0e10cSrcweir     {
480*cdf0e10cSrcweir         mpView->UnmarkAllObj( pPageView );
481*cdf0e10cSrcweir         lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
482*cdf0e10cSrcweir     }
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir //----------------------------------------------------------------------
486*cdf0e10cSrcweir Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
487*cdf0e10cSrcweir     throw( uno::RuntimeException )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
492*cdf0e10cSrcweir         throw lang::DisposedException();
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
495*cdf0e10cSrcweir     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir     Reference< ::com::sun::star::drawing::XShapeGroup >  xShapeGroup;
498*cdf0e10cSrcweir     if(mpPage==NULL||mpView==NULL||!xShapes.is())
499*cdf0e10cSrcweir         return xShapeGroup;
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir     _SelectObjectsInView( xShapes, pPageView );
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir     mpView->GroupMarked();
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     mpView->AdjustMarkHdl();
508*cdf0e10cSrcweir     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
509*cdf0e10cSrcweir     if( rMarkList.GetMarkCount() == 1 )
510*cdf0e10cSrcweir     {
511*cdf0e10cSrcweir         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
512*cdf0e10cSrcweir         if( pObj )
513*cdf0e10cSrcweir              xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
514*cdf0e10cSrcweir     }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir     mpView->HideSdrPage();
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir     if( mpModel )
519*cdf0e10cSrcweir         mpModel->SetChanged();
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir     return xShapeGroup;
522*cdf0e10cSrcweir }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir //----------------------------------------------------------------------
525*cdf0e10cSrcweir void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
526*cdf0e10cSrcweir     throw( uno::RuntimeException )
527*cdf0e10cSrcweir {
528*cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     if( (mpModel == 0) || (mpPage == 0) )
531*cdf0e10cSrcweir         throw lang::DisposedException();
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
534*cdf0e10cSrcweir     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     if(mpPage==NULL||mpView==NULL||!aGroup.is())
537*cdf0e10cSrcweir         return;
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir     SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
542*cdf0e10cSrcweir     _SelectObjectInView( xShape, pPageView );
543*cdf0e10cSrcweir     mpView->UnGroupMarked();
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir     mpView->HideSdrPage();
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     if( mpModel )
548*cdf0e10cSrcweir         mpModel->SetChanged();
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir //----------------------------------------------------------------------
552*cdf0e10cSrcweir SdrObject *SvxDrawPage::_CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
553*cdf0e10cSrcweir {
554*cdf0e10cSrcweir     sal_uInt16 nType;
555*cdf0e10cSrcweir     sal_uInt32 nInventor;
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
558*cdf0e10cSrcweir     SdrObject* pNewObj = 0;
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir     if( nType != 0 )
561*cdf0e10cSrcweir     {
562*cdf0e10cSrcweir         awt::Size aSize = xShape->getSize();
563*cdf0e10cSrcweir         aSize.Width += 1;
564*cdf0e10cSrcweir         aSize.Height += 1;
565*cdf0e10cSrcweir         awt::Point aPos = xShape->getPosition();
566*cdf0e10cSrcweir         Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir         // special cases
569*cdf0e10cSrcweir         if( nInventor == SdrInventor )
570*cdf0e10cSrcweir         {
571*cdf0e10cSrcweir             switch( nType )
572*cdf0e10cSrcweir             {
573*cdf0e10cSrcweir             case OBJ_MEASURE:
574*cdf0e10cSrcweir                 {
575*cdf0e10cSrcweir                     pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() );
576*cdf0e10cSrcweir                     break;
577*cdf0e10cSrcweir                 }
578*cdf0e10cSrcweir             case OBJ_LINE:
579*cdf0e10cSrcweir                 {
580*cdf0e10cSrcweir                     basegfx::B2DPolygon aPoly;
581*cdf0e10cSrcweir                     aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top()));
582*cdf0e10cSrcweir                     aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
583*cdf0e10cSrcweir                     pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
584*cdf0e10cSrcweir                     break;
585*cdf0e10cSrcweir                 }
586*cdf0e10cSrcweir             }
587*cdf0e10cSrcweir         }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir         if( pNewObj == NULL )
590*cdf0e10cSrcweir             pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir         if(pNewObj)
593*cdf0e10cSrcweir         {
594*cdf0e10cSrcweir             pNewObj->SetSnapRect(aRect);
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir             if( pNewObj->ISA(E3dPolyScene))
597*cdf0e10cSrcweir             {
598*cdf0e10cSrcweir                 // Szene initialisieren
599*cdf0e10cSrcweir                 E3dScene* pScene = (E3dScene*)pNewObj;
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir                 double fW = (double)aSize.Width;
602*cdf0e10cSrcweir                 double fH = (double)aSize.Height;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir                 Camera3D aCam(pScene->GetCamera());
605*cdf0e10cSrcweir                 aCam.SetAutoAdjustProjection(sal_False);
606*cdf0e10cSrcweir                 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
607*cdf0e10cSrcweir                 basegfx::B3DPoint aLookAt;
608*cdf0e10cSrcweir                 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
609*cdf0e10cSrcweir                 aCam.SetPosAndLookAt(aCamPos, aLookAt);
610*cdf0e10cSrcweir                 aCam.SetFocalLength(100.0);
611*cdf0e10cSrcweir                 aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
612*cdf0e10cSrcweir                 pScene->SetCamera(aCam);
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir                 pScene->SetRectsDirty();
615*cdf0e10cSrcweir             }
616*cdf0e10cSrcweir             else if(pNewObj->ISA(E3dExtrudeObj))
617*cdf0e10cSrcweir             {
618*cdf0e10cSrcweir                 E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj;
619*cdf0e10cSrcweir                 basegfx::B2DPolygon aNewPolygon;
620*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
621*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
622*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
623*cdf0e10cSrcweir                 aNewPolygon.setClosed(true);
624*cdf0e10cSrcweir                 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir                 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
627*cdf0e10cSrcweir                 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
628*cdf0e10cSrcweir             }
629*cdf0e10cSrcweir             else if(pNewObj->ISA(E3dLatheObj))
630*cdf0e10cSrcweir             {
631*cdf0e10cSrcweir                 E3dLatheObj* pObj = (E3dLatheObj*)pNewObj;
632*cdf0e10cSrcweir                 basegfx::B2DPolygon aNewPolygon;
633*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
634*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
635*cdf0e10cSrcweir                 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
636*cdf0e10cSrcweir                 aNewPolygon.setClosed(true);
637*cdf0e10cSrcweir                 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir                 // #107245# pObj->SetLatheCharacterMode(sal_True);
640*cdf0e10cSrcweir                 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
641*cdf0e10cSrcweir             }
642*cdf0e10cSrcweir         }
643*cdf0e10cSrcweir     }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     return pNewObj;
646*cdf0e10cSrcweir }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir //----------------------------------------------------------------------
649*cdf0e10cSrcweir void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw()
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir     sal_uInt32 nTempType = aSdrShapeIdentifierMap.getId( aName );
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir     if( nTempType == UHASHMAP_NOTFOUND )
654*cdf0e10cSrcweir     {
655*cdf0e10cSrcweir         if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape")) ||
656*cdf0e10cSrcweir             aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TableShape")) )
657*cdf0e10cSrcweir         {
658*cdf0e10cSrcweir             rInventor = SdrInventor;
659*cdf0e10cSrcweir             rType = OBJ_TABLE;
660*cdf0e10cSrcweir         }
661*cdf0e10cSrcweir         else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.MediaShape" )) )
662*cdf0e10cSrcweir         {
663*cdf0e10cSrcweir             rInventor = SdrInventor;
664*cdf0e10cSrcweir             rType = OBJ_MEDIA;
665*cdf0e10cSrcweir         }
666*cdf0e10cSrcweir     }
667*cdf0e10cSrcweir     else if(nTempType & E3D_INVENTOR_FLAG)
668*cdf0e10cSrcweir     {
669*cdf0e10cSrcweir         rInventor = E3dInventor;
670*cdf0e10cSrcweir         rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
671*cdf0e10cSrcweir     }
672*cdf0e10cSrcweir     else
673*cdf0e10cSrcweir     {
674*cdf0e10cSrcweir         rInventor = SdrInventor;
675*cdf0e10cSrcweir         rType = (sal_uInt16)nTempType;
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir         switch( rType )
678*cdf0e10cSrcweir         {
679*cdf0e10cSrcweir             case OBJ_FRAME:
680*cdf0e10cSrcweir             case OBJ_OLE2_PLUGIN:
681*cdf0e10cSrcweir             case OBJ_OLE2_APPLET:
682*cdf0e10cSrcweir                 rType = OBJ_OLE2;
683*cdf0e10cSrcweir                 break;
684*cdf0e10cSrcweir         }
685*cdf0e10cSrcweir     }
686*cdf0e10cSrcweir }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir //----------------------------------------------------------------------
689*cdf0e10cSrcweir SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage ) throw()
690*cdf0e10cSrcweir {
691*cdf0e10cSrcweir     SvxShape* pRet = NULL;
692*cdf0e10cSrcweir     switch( nInventor )
693*cdf0e10cSrcweir     {
694*cdf0e10cSrcweir         case E3dInventor:
695*cdf0e10cSrcweir         {
696*cdf0e10cSrcweir             switch( nType )
697*cdf0e10cSrcweir             {
698*cdf0e10cSrcweir                 case E3D_SCENE_ID :
699*cdf0e10cSrcweir                 case E3D_POLYSCENE_ID :
700*cdf0e10cSrcweir                     pRet = new Svx3DSceneObject( pObj, mpPage );
701*cdf0e10cSrcweir                     break;
702*cdf0e10cSrcweir                 case E3D_CUBEOBJ_ID :
703*cdf0e10cSrcweir                     pRet = new Svx3DCubeObject( pObj );
704*cdf0e10cSrcweir                     break;
705*cdf0e10cSrcweir                 case E3D_SPHEREOBJ_ID :
706*cdf0e10cSrcweir                     pRet = new Svx3DSphereObject( pObj );
707*cdf0e10cSrcweir                     break;
708*cdf0e10cSrcweir                 case E3D_LATHEOBJ_ID :
709*cdf0e10cSrcweir                     pRet = new Svx3DLatheObject( pObj );
710*cdf0e10cSrcweir                     break;
711*cdf0e10cSrcweir                 case E3D_EXTRUDEOBJ_ID :
712*cdf0e10cSrcweir                     pRet = new Svx3DExtrudeObject( pObj );
713*cdf0e10cSrcweir                     break;
714*cdf0e10cSrcweir                 case E3D_POLYGONOBJ_ID :
715*cdf0e10cSrcweir                     pRet = new Svx3DPolygonObject( pObj );
716*cdf0e10cSrcweir                     break;
717*cdf0e10cSrcweir                 default: // unbekanntes 3D-Objekt auf der Page
718*cdf0e10cSrcweir                     pRet = new SvxShape( pObj );
719*cdf0e10cSrcweir                     break;
720*cdf0e10cSrcweir             }
721*cdf0e10cSrcweir             break;
722*cdf0e10cSrcweir         }
723*cdf0e10cSrcweir         case SdrInventor:
724*cdf0e10cSrcweir         {
725*cdf0e10cSrcweir             switch( nType )
726*cdf0e10cSrcweir             {
727*cdf0e10cSrcweir //              case OBJ_NONE:
728*cdf0e10cSrcweir //                  break;
729*cdf0e10cSrcweir                 case OBJ_GRUP:
730*cdf0e10cSrcweir                     pRet = new SvxShapeGroup( pObj, mpPage );
731*cdf0e10cSrcweir                     break;
732*cdf0e10cSrcweir                 case OBJ_LINE:
733*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
734*cdf0e10cSrcweir                     break;
735*cdf0e10cSrcweir                 case OBJ_RECT:
736*cdf0e10cSrcweir                     pRet = new SvxShapeRect( pObj );
737*cdf0e10cSrcweir                     break;
738*cdf0e10cSrcweir                 case OBJ_CIRC:
739*cdf0e10cSrcweir                 case OBJ_SECT:
740*cdf0e10cSrcweir                 case OBJ_CARC:
741*cdf0e10cSrcweir                 case OBJ_CCUT:
742*cdf0e10cSrcweir                     pRet = new SvxShapeCircle( pObj );
743*cdf0e10cSrcweir                     break;
744*cdf0e10cSrcweir                 case OBJ_POLY:
745*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
746*cdf0e10cSrcweir                     break;
747*cdf0e10cSrcweir                 case OBJ_PLIN:
748*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
749*cdf0e10cSrcweir                     break;
750*cdf0e10cSrcweir                 case OBJ_SPLNLINE:
751*cdf0e10cSrcweir                 case OBJ_PATHLINE:
752*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
753*cdf0e10cSrcweir                     break;
754*cdf0e10cSrcweir                 case OBJ_SPLNFILL:
755*cdf0e10cSrcweir                 case OBJ_PATHFILL:
756*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
757*cdf0e10cSrcweir                     break;
758*cdf0e10cSrcweir                 case OBJ_FREELINE:
759*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
760*cdf0e10cSrcweir                     break;
761*cdf0e10cSrcweir                 case OBJ_FREEFILL:
762*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
763*cdf0e10cSrcweir                     break;
764*cdf0e10cSrcweir                 case OBJ_CAPTION:
765*cdf0e10cSrcweir                     pRet = new SvxShapeCaption( pObj );
766*cdf0e10cSrcweir                     break;
767*cdf0e10cSrcweir                 case OBJ_TITLETEXT:
768*cdf0e10cSrcweir                 case OBJ_OUTLINETEXT:
769*cdf0e10cSrcweir                 case OBJ_TEXT:
770*cdf0e10cSrcweir                     pRet = new SvxShapeText( pObj );
771*cdf0e10cSrcweir                     break;
772*cdf0e10cSrcweir                 case OBJ_GRAF:
773*cdf0e10cSrcweir                     pRet = new SvxGraphicObject( pObj );
774*cdf0e10cSrcweir                     break;
775*cdf0e10cSrcweir                 case OBJ_FRAME:
776*cdf0e10cSrcweir                     pRet = new SvxFrameShape( pObj );
777*cdf0e10cSrcweir                     break;
778*cdf0e10cSrcweir                 case OBJ_OLE2_APPLET:
779*cdf0e10cSrcweir                     pRet = new SvxAppletShape( pObj );
780*cdf0e10cSrcweir                     break;
781*cdf0e10cSrcweir                 case OBJ_OLE2_PLUGIN:
782*cdf0e10cSrcweir                     pRet = new SvxPluginShape( pObj );
783*cdf0e10cSrcweir                     break;
784*cdf0e10cSrcweir                  case OBJ_OLE2:
785*cdf0e10cSrcweir                      {
786*cdf0e10cSrcweir                         if( pObj && !pObj->IsEmptyPresObj() && mpPage )
787*cdf0e10cSrcweir                         {
788*cdf0e10cSrcweir                             SdrPage* pSdrPage = mpPage->GetSdrPage();
789*cdf0e10cSrcweir                             if( pSdrPage )
790*cdf0e10cSrcweir                             {
791*cdf0e10cSrcweir                                 SdrModel* pSdrModel = pSdrPage->GetModel();
792*cdf0e10cSrcweir                                 if( pSdrModel )
793*cdf0e10cSrcweir                                 {
794*cdf0e10cSrcweir                                     ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
795*cdf0e10cSrcweir                                     if( pPersist )
796*cdf0e10cSrcweir                                     {
797*cdf0e10cSrcweir                                         uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
798*cdf0e10cSrcweir                                                 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir                                         // TODO CL->KA: Why is this not working anymore?
801*cdf0e10cSrcweir                                         if( xObject.is() )
802*cdf0e10cSrcweir                                         {
803*cdf0e10cSrcweir                                             SvGlobalName aClassId( xObject->getClassID() );
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir                                             const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
806*cdf0e10cSrcweir                                             const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
807*cdf0e10cSrcweir                                             const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir                                             if( aPluginClassId == aClassId )
810*cdf0e10cSrcweir                                             {
811*cdf0e10cSrcweir                                                 pRet = new SvxPluginShape( pObj );
812*cdf0e10cSrcweir                                                 nType = OBJ_OLE2_PLUGIN;
813*cdf0e10cSrcweir                                             }
814*cdf0e10cSrcweir                                             else if( aAppletClassId == aClassId )
815*cdf0e10cSrcweir                                             {
816*cdf0e10cSrcweir                                                 pRet = new SvxAppletShape( pObj );
817*cdf0e10cSrcweir                                                 nType = OBJ_OLE2_APPLET;
818*cdf0e10cSrcweir                                             }
819*cdf0e10cSrcweir                                             else if( aIFrameClassId == aClassId )
820*cdf0e10cSrcweir                                             {
821*cdf0e10cSrcweir                                                 pRet = new SvxFrameShape( pObj );
822*cdf0e10cSrcweir                                                 nType = OBJ_FRAME;
823*cdf0e10cSrcweir                                             }
824*cdf0e10cSrcweir                                         }
825*cdf0e10cSrcweir                                     }
826*cdf0e10cSrcweir                                 }
827*cdf0e10cSrcweir                             }
828*cdf0e10cSrcweir                         }
829*cdf0e10cSrcweir                         if( pRet == NULL )
830*cdf0e10cSrcweir                         {
831*cdf0e10cSrcweir                             pRet = new SvxOle2Shape( pObj, aSvxMapProvider.GetMap(SVXMAP_OLE2),  aSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
832*cdf0e10cSrcweir                         }
833*cdf0e10cSrcweir                      }
834*cdf0e10cSrcweir                     break;
835*cdf0e10cSrcweir                 case OBJ_EDGE:
836*cdf0e10cSrcweir                     pRet = new SvxShapeConnector( pObj );
837*cdf0e10cSrcweir                     break;
838*cdf0e10cSrcweir                 case OBJ_PATHPOLY:
839*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
840*cdf0e10cSrcweir                     break;
841*cdf0e10cSrcweir                 case OBJ_PATHPLIN:
842*cdf0e10cSrcweir                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
843*cdf0e10cSrcweir                     break;
844*cdf0e10cSrcweir                 case OBJ_PAGE:
845*cdf0e10cSrcweir                     pRet = new SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_PAGE),  aSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
846*cdf0e10cSrcweir                     break;
847*cdf0e10cSrcweir                 case OBJ_MEASURE:
848*cdf0e10cSrcweir                     pRet = new SvxShapeDimensioning( pObj );
849*cdf0e10cSrcweir                     break;
850*cdf0e10cSrcweir //              case OBJ_DUMMY:
851*cdf0e10cSrcweir //                  break;
852*cdf0e10cSrcweir                 case OBJ_UNO:
853*cdf0e10cSrcweir                     pRet = new SvxShapeControl( pObj );
854*cdf0e10cSrcweir                     break;
855*cdf0e10cSrcweir                 case OBJ_CUSTOMSHAPE:
856*cdf0e10cSrcweir                     pRet = new SvxCustomShape( pObj );
857*cdf0e10cSrcweir                     break;
858*cdf0e10cSrcweir                 case OBJ_MEDIA:
859*cdf0e10cSrcweir                     pRet = new SvxMediaShape( pObj );
860*cdf0e10cSrcweir                     break;
861*cdf0e10cSrcweir                 case OBJ_TABLE:
862*cdf0e10cSrcweir                     pRet = new SvxTableShape( pObj );
863*cdf0e10cSrcweir                     break;
864*cdf0e10cSrcweir                 default: // unbekanntes 2D-Objekt auf der Page
865*cdf0e10cSrcweir                     DBG_ERROR("Nicht implementierter Starone-Shape erzeugt! [CL]");
866*cdf0e10cSrcweir                     pRet = new SvxShapeText( pObj );
867*cdf0e10cSrcweir                     break;
868*cdf0e10cSrcweir             }
869*cdf0e10cSrcweir             break;
870*cdf0e10cSrcweir         }
871*cdf0e10cSrcweir         default: // Unbekannter Inventor
872*cdf0e10cSrcweir         {
873*cdf0e10cSrcweir             DBG_ERROR("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
874*cdf0e10cSrcweir             break;
875*cdf0e10cSrcweir         }
876*cdf0e10cSrcweir     }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir     if(pRet)
879*cdf0e10cSrcweir     {
880*cdf0e10cSrcweir         sal_uInt32 nObjId = nType;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir         if( nInventor == E3dInventor )
883*cdf0e10cSrcweir             nObjId |= E3D_INVENTOR_FLAG;
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir         switch(nObjId)
886*cdf0e10cSrcweir         {
887*cdf0e10cSrcweir         case OBJ_CCUT:          // Kreisabschnitt
888*cdf0e10cSrcweir         case OBJ_CARC:          // Kreisbogen
889*cdf0e10cSrcweir         case OBJ_SECT:          // Kreissektor
890*cdf0e10cSrcweir             nObjId = OBJ_CIRC;
891*cdf0e10cSrcweir             break;
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir         case E3D_SCENE_ID | E3D_INVENTOR_FLAG:
894*cdf0e10cSrcweir             nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG;
895*cdf0e10cSrcweir             break;
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir         case OBJ_TITLETEXT:
898*cdf0e10cSrcweir         case OBJ_OUTLINETEXT:
899*cdf0e10cSrcweir             nObjId = OBJ_TEXT;
900*cdf0e10cSrcweir             break;
901*cdf0e10cSrcweir         }
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir         pRet->setShapeKind(nObjId);
904*cdf0e10cSrcweir     }
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir     return pRet;
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir //----------------------------------------------------------------------
910*cdf0e10cSrcweir Reference< drawing::XShape >  SvxDrawPage::_CreateShape( SdrObject *pObj ) const throw()
911*cdf0e10cSrcweir {
912*cdf0e10cSrcweir     Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
913*cdf0e10cSrcweir                                               pObj->GetObjInventor(),
914*cdf0e10cSrcweir                                               pObj,
915*cdf0e10cSrcweir                                               (SvxDrawPage*)this));
916*cdf0e10cSrcweir     return xShape;
917*cdf0e10cSrcweir }
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir //----------------------------------------------------------------------
920*cdf0e10cSrcweir SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
921*cdf0e10cSrcweir {
922*cdf0e10cSrcweir     SdrObject* pObj = _CreateSdrObject( xShape );
923*cdf0e10cSrcweir     if( pObj && !pObj->IsInserted() )
924*cdf0e10cSrcweir         mpPage->InsertObject( pObj );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir     return pObj;
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir //----------------------------------------------------------------------
930*cdf0e10cSrcweir // ::com::sun::star::lang::XServiceInfo
931*cdf0e10cSrcweir //----------------------------------------------------------------------
932*cdf0e10cSrcweir OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException )
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxDrawPage"));
935*cdf0e10cSrcweir }
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
938*cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
939*cdf0e10cSrcweir {
940*cdf0e10cSrcweir     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
941*cdf0e10cSrcweir }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException )
944*cdf0e10cSrcweir {
945*cdf0e10cSrcweir     uno::Sequence< OUString > aSeq( 1 );
946*cdf0e10cSrcweir     aSeq.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection" ));
947*cdf0e10cSrcweir     return aSeq;
948*cdf0e10cSrcweir }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor ) throw()
951*cdf0e10cSrcweir {
952*cdf0e10cSrcweir     return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor );
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir     if( pNewModel != mpModel )
958*cdf0e10cSrcweir     {
959*cdf0e10cSrcweir         if( mpModel )
960*cdf0e10cSrcweir             EndListening( *mpModel );
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir         if( pNewModel )
963*cdf0e10cSrcweir             StartListening( *pNewModel );
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir         mpModel = pNewModel;
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir         if( mpView )
968*cdf0e10cSrcweir         {
969*cdf0e10cSrcweir             delete mpView;
970*cdf0e10cSrcweir             mpView = new SdrView( mpModel );
971*cdf0e10cSrcweir             if( mpView )
972*cdf0e10cSrcweir                 mpView->SetDesignMode(sal_True);
973*cdf0e10cSrcweir         }
974*cdf0e10cSrcweir     }
975*cdf0e10cSrcweir }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir /** returns a StarOffice API wrapper for the given SdrPage */
978*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
979*cdf0e10cSrcweir {
980*cdf0e10cSrcweir     if(pPage)
981*cdf0e10cSrcweir     {
982*cdf0e10cSrcweir         uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir         return xDrawPage;
985*cdf0e10cSrcweir     }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir     return uno::Reference< drawing::XDrawPage >();
988*cdf0e10cSrcweir }
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir /** returns the SdrObject from the given StarOffice API wrapper */
991*cdf0e10cSrcweir SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
992*cdf0e10cSrcweir {
993*cdf0e10cSrcweir     if(xDrawPage.is())
994*cdf0e10cSrcweir     {
995*cdf0e10cSrcweir         SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir         if(pDrawPage)
998*cdf0e10cSrcweir         {
999*cdf0e10cSrcweir             return pDrawPage->GetSdrPage();
1000*cdf0e10cSrcweir         }
1001*cdf0e10cSrcweir     }
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     return NULL;
1004*cdf0e10cSrcweir }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir // eof
1007