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