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