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 191445 : UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
61 3058 : SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
62 3058 : : mrBHelper( getMutex() )
63 : , mpPage( pInPage )
64 6116 : , mpModel( 0 )
65 : {
66 : // Am Broadcaster anmelden
67 3058 : if( mpPage )
68 3058 : mpModel = mpPage->GetModel();
69 3058 : if( mpModel )
70 3058 : StartListening( *mpModel );
71 :
72 :
73 : // Erzeugen der (hidden) ::com::sun::star::sdbcx::View
74 3058 : mpView = new SdrView( mpModel );
75 3058 : if( mpView )
76 3058 : mpView->SetDesignMode(true);
77 3058 : }
78 :
79 5716 : SvxDrawPage::~SvxDrawPage() throw()
80 : {
81 : DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" );
82 2858 : if( !mrBHelper.bDisposed )
83 : {
84 105 : acquire();
85 105 : dispose();
86 : }
87 2858 : }
88 :
89 : // XInterface
90 301711 : void SvxDrawPage::release() throw()
91 : {
92 301711 : OWeakAggObject::release();
93 301711 : }
94 :
95 : // XComponent
96 2858 : void SvxDrawPage::disposing() throw()
97 : {
98 2858 : if( mpModel )
99 : {
100 2858 : EndListening( *mpModel );
101 2858 : mpModel = NULL;
102 : }
103 :
104 2858 : if( mpView )
105 : {
106 2858 : delete mpView;
107 2858 : mpView = NULL;
108 : }
109 2858 : mpPage = 0;
110 2858 : }
111 :
112 : // XComponent
113 3842 : void SvxDrawPage::dispose()
114 : throw(::com::sun::star::uno::RuntimeException, std::exception)
115 : {
116 3842 : 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 7684 : 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 3842 : bool bDoDispose = false;
126 : {
127 3842 : osl::MutexGuard aGuard( mrBHelper.rMutex );
128 3842 : if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
129 : {
130 : // only one call go into this section
131 2858 : mrBHelper.bInDispose = sal_True;
132 2858 : bDoDispose = true;
133 3842 : }
134 : }
135 :
136 : // Do not hold the mutex because we are broadcasting
137 3842 : if( bDoDispose )
138 : {
139 : // Create an event with this as sender
140 : try
141 : {
142 2858 : uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
143 5716 : ::com::sun::star::document::EventObject aEvt;
144 2858 : aEvt.Source = xSource;
145 : // inform all listeners to release this object
146 : // The listener container are automaticly cleared
147 2858 : mrBHelper.aLC.disposeAndClear( aEvt );
148 : // notify subclasses to do their dispose
149 5716 : 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 2858 : mrBHelper.bDisposed = sal_True;
164 2858 : mrBHelper.bInDispose = sal_False;
165 3842 : }
166 :
167 3842 : }
168 :
169 35 : 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 35 : SolarMutexGuard aGuard;
172 :
173 35 : if( mpModel == 0 )
174 0 : throw lang::DisposedException();
175 :
176 35 : mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
177 35 : }
178 :
179 35 : 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 35 : SolarMutexGuard aGuard;
182 :
183 35 : if( mpModel == 0 )
184 0 : throw lang::DisposedException();
185 :
186 35 : mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
187 35 : }
188 :
189 : // SfxListener
190 136762 : void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
191 : {
192 136762 : }
193 :
194 2248 : void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
195 : throw( uno::RuntimeException, std::exception )
196 : {
197 2248 : SolarMutexGuard aGuard;
198 :
199 2248 : if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
200 0 : throw lang::DisposedException();
201 :
202 2248 : SvxShape* pShape = SvxShape::getImplementation( xShape );
203 :
204 2248 : if( NULL == pShape )
205 0 : return;
206 :
207 2248 : SdrObject *pObj = pShape->GetSdrObject();
208 :
209 2248 : if(!pObj)
210 : {
211 1973 : pObj = CreateSdrObject( xShape );
212 1973 : ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
213 : }
214 275 : else if ( !pObj->IsInserted() )
215 : {
216 275 : pObj->SetModel(mpModel);
217 275 : mpPage->InsertObject( pObj );
218 : }
219 :
220 2248 : pShape->Create( pObj, this );
221 : OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
222 :
223 2248 : if ( !pObj->IsInserted() )
224 : {
225 0 : pObj->SetModel(mpModel);
226 0 : mpPage->InsertObject( pObj );
227 : }
228 :
229 2248 : mpModel->SetChanged();
230 : }
231 :
232 580 : void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
233 : throw (uno::RuntimeException, std::exception)
234 : {
235 580 : SolarMutexGuard aGuard;
236 :
237 580 : if( (mpModel == 0) || (mpPage == 0) )
238 0 : throw lang::DisposedException();
239 :
240 580 : SvxShape* pShape = SvxShape::getImplementation( xShape );
241 :
242 580 : if(pShape)
243 : {
244 580 : SdrObject* pObj = pShape->GetSdrObject();
245 580 : if(pObj)
246 : {
247 : // SdrObject aus der Page loeschen
248 580 : sal_uInt32 nCount = mpPage->GetObjCount();
249 678 : for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ )
250 : {
251 678 : if(mpPage->GetObj(nNum) == pObj)
252 : {
253 580 : OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
254 580 : SdrObject::Free( pObj );
255 580 : break;
256 : }
257 : }
258 : }
259 : }
260 :
261 580 : if( mpModel )
262 580 : mpModel->SetChanged();
263 580 : }
264 :
265 : // ::com::sun::star::container::XIndexAccess
266 3819 : sal_Int32 SAL_CALL SvxDrawPage::getCount()
267 : throw( uno::RuntimeException, std::exception )
268 : {
269 3819 : SolarMutexGuard aGuard;
270 :
271 3819 : if( (mpModel == 0) || (mpPage == 0) )
272 0 : throw lang::DisposedException();
273 :
274 3819 : return( (sal_Int32) mpPage->GetObjCount() );
275 : }
276 :
277 3089 : uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
278 : throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
279 : {
280 3089 : SolarMutexGuard aGuard;
281 :
282 3089 : if( (mpModel == 0) || (mpPage == 0) )
283 0 : throw lang::DisposedException();
284 :
285 3089 : if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() )
286 7 : throw lang::IndexOutOfBoundsException();
287 :
288 3082 : SdrObject* pObj = mpPage->GetObj( Index );
289 3082 : if( pObj == NULL )
290 0 : throw uno::RuntimeException();
291 :
292 :
293 3082 : return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
294 : }
295 :
296 : // ::com::sun::star::container::XElementAccess
297 5 : uno::Type SAL_CALL SvxDrawPage::getElementType()
298 : throw( uno::RuntimeException, std::exception )
299 : {
300 5 : return INTERFACE_TYPE( drawing::XShape );
301 : }
302 :
303 6 : sal_Bool SAL_CALL SvxDrawPage::hasElements()
304 : throw( uno::RuntimeException, std::exception )
305 : {
306 6 : SolarMutexGuard aGuard;
307 :
308 6 : if( (mpModel == 0) || (mpPage == 0) )
309 0 : throw lang::DisposedException();
310 :
311 6 : return mpPage && mpPage->GetObjCount()>0;
312 : }
313 :
314 : namespace
315 : {
316 46 : void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
317 : {
318 46 : SvxShape* pShape = SvxShape::getImplementation( _rxShape );
319 46 : if ( !pShape )
320 0 : return;
321 :
322 46 : SdrObject* pObj = pShape->GetSdrObject();
323 46 : if ( !pObj )
324 0 : return;
325 :
326 46 : _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 11 : 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 11 : if(pPageView!=NULL && mpView!=NULL)
338 : {
339 11 : mpView->UnmarkAllObj( pPageView );
340 :
341 11 : long nCount = aShapes->getCount();
342 46 : for( long i = 0; i < nCount; i++ )
343 : {
344 35 : uno::Any aAny( aShapes->getByIndex(i) );
345 70 : Reference< drawing::XShape > xShape;
346 35 : if( aAny >>= xShape )
347 35 : lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
348 35 : }
349 : }
350 11 : }
351 :
352 : // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen
353 : // SdrPageView. Dies muss nicht die sichtbare SdrPageView sein.
354 11 : 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 11 : if(pPageView!=NULL && mpView != NULL)
360 : {
361 11 : mpView->UnmarkAllObj( pPageView );
362 11 : lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
363 : }
364 11 : }
365 :
366 5 : Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
367 : throw( uno::RuntimeException, std::exception )
368 : {
369 5 : SolarMutexGuard aGuard;
370 :
371 5 : 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 5 : Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup;
378 5 : if(mpPage==NULL||mpView==NULL||!xShapes.is())
379 0 : return xShapeGroup;
380 :
381 5 : SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
382 :
383 5 : _SelectObjectsInView( xShapes, pPageView );
384 :
385 5 : mpView->GroupMarked();
386 :
387 5 : mpView->AdjustMarkHdl();
388 5 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
389 5 : if( rMarkList.GetMarkCount() == 1 )
390 : {
391 5 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
392 5 : if( pObj )
393 5 : xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
394 : }
395 :
396 5 : mpView->HideSdrPage();
397 :
398 5 : if( mpModel )
399 5 : mpModel->SetChanged();
400 :
401 5 : return xShapeGroup;
402 : }
403 :
404 5 : void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
405 : throw( uno::RuntimeException, std::exception )
406 : {
407 5 : SolarMutexGuard aGuard;
408 :
409 5 : 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 5 : if(mpPage==NULL||mpView==NULL||!aGroup.is())
416 5 : return;
417 :
418 5 : SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
419 :
420 10 : Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
421 5 : _SelectObjectInView( xShape, pPageView );
422 5 : mpView->UnGroupMarked();
423 :
424 5 : mpView->HideSdrPage();
425 :
426 5 : if( mpModel )
427 10 : mpModel->SetChanged();
428 : }
429 :
430 56603 : SdrObject *SvxDrawPage::_CreateSdrObject(const Reference< drawing::XShape > & xShape)
431 : throw (std::exception)
432 : {
433 56603 : sal_uInt16 nType = 0;
434 56603 : sal_uInt32 nInventor = 0;
435 :
436 56603 : GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
437 56603 : SdrObject* pNewObj = 0;
438 :
439 56603 : if( nType != 0 )
440 : {
441 56603 : awt::Size aSize = xShape->getSize();
442 56603 : aSize.Width += 1;
443 56603 : aSize.Height += 1;
444 56603 : awt::Point aPos = xShape->getPosition();
445 56603 : Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
446 :
447 : // special cases
448 56603 : if( nInventor == SdrInventor )
449 : {
450 55124 : switch( nType )
451 : {
452 : case OBJ_MEASURE:
453 : {
454 1 : pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() );
455 1 : break;
456 : }
457 : case OBJ_LINE:
458 : {
459 235 : basegfx::B2DPolygon aPoly;
460 235 : aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top()));
461 235 : aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
462 235 : pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
463 235 : break;
464 : }
465 : }
466 : }
467 :
468 56603 : if( pNewObj == NULL )
469 56367 : pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage );
470 :
471 56603 : if(pNewObj)
472 : {
473 56603 : pNewObj->SetSnapRect(aRect);
474 :
475 56603 : if( pNewObj->ISA(E3dPolyScene))
476 : {
477 : // Szene initialisieren
478 344 : E3dScene* pScene = (E3dScene*)pNewObj;
479 :
480 344 : double fW = (double)aSize.Width;
481 344 : double fH = (double)aSize.Height;
482 :
483 344 : Camera3D aCam(pScene->GetCamera());
484 344 : aCam.SetAutoAdjustProjection(false);
485 344 : aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
486 688 : basegfx::B3DPoint aLookAt;
487 688 : basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
488 344 : aCam.SetPosAndLookAt(aCamPos, aLookAt);
489 344 : aCam.SetFocalLength(100.0);
490 344 : aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
491 344 : pScene->SetCamera(aCam);
492 :
493 688 : pScene->SetRectsDirty();
494 : }
495 56259 : else if(pNewObj->ISA(E3dExtrudeObj))
496 : {
497 933 : E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj;
498 933 : basegfx::B2DPolygon aNewPolygon;
499 933 : aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
500 933 : aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
501 933 : aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
502 933 : aNewPolygon.setClosed(true);
503 933 : pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
504 :
505 : // #107245# pObj->SetExtrudeCharacterMode(sal_True);
506 933 : pObj->SetMergedItem(Svx3DCharacterModeItem(true));
507 : }
508 55326 : else if(pNewObj->ISA(E3dLatheObj))
509 : {
510 48 : E3dLatheObj* pObj = (E3dLatheObj*)pNewObj;
511 48 : basegfx::B2DPolygon aNewPolygon;
512 48 : aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
513 48 : aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
514 48 : aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
515 48 : aNewPolygon.setClosed(true);
516 48 : pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
517 :
518 : // #107245# pObj->SetLatheCharacterMode(sal_True);
519 48 : pObj->SetMergedItem(Svx3DCharacterModeItem(true));
520 : }
521 : }
522 : }
523 :
524 56603 : return pNewObj;
525 : }
526 :
527 56603 : void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw()
528 : {
529 56603 : sal_uInt32 nTempType = UHashMap::getId( aName );
530 :
531 56603 : if( nTempType == UHASHMAP_NOTFOUND )
532 : {
533 6 : if( aName == "com.sun.star.drawing.TableShape" ||
534 2 : aName == "com.sun.star.presentation.TableShape" )
535 : {
536 2 : rInventor = SdrInventor;
537 2 : rType = OBJ_TABLE;
538 : }
539 2 : else if ( aName == "com.sun.star.presentation.MediaShape" )
540 : {
541 2 : rInventor = SdrInventor;
542 2 : rType = OBJ_MEDIA;
543 : }
544 : }
545 56599 : else if(nTempType & E3D_INVENTOR_FLAG)
546 : {
547 1479 : rInventor = E3dInventor;
548 1479 : rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
549 : }
550 : else
551 : {
552 55120 : rInventor = SdrInventor;
553 55120 : rType = (sal_uInt16)nTempType;
554 :
555 55120 : 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 56603 : }
565 :
566 103432 : SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer ) throw()
567 : {
568 103432 : SvxShape* pRet = NULL;
569 103432 : switch( nInventor )
570 : {
571 : case E3dInventor:
572 : {
573 1498 : switch( nType )
574 : {
575 : case E3D_SCENE_ID :
576 : case E3D_POLYSCENE_ID :
577 358 : pRet = new Svx3DSceneObject( pObj, mpPage );
578 358 : break;
579 : case E3D_CUBEOBJ_ID :
580 1 : pRet = new Svx3DCubeObject( pObj );
581 1 : break;
582 : case E3D_SPHEREOBJ_ID :
583 1 : pRet = new Svx3DSphereObject( pObj );
584 1 : break;
585 : case E3D_LATHEOBJ_ID :
586 49 : pRet = new Svx3DLatheObject( pObj );
587 49 : break;
588 : case E3D_EXTRUDEOBJ_ID :
589 934 : pRet = new Svx3DExtrudeObject( pObj );
590 934 : break;
591 : case E3D_POLYGONOBJ_ID :
592 155 : pRet = new Svx3DPolygonObject( pObj );
593 155 : break;
594 : default: // unbekanntes 3D-Objekt auf der Page
595 0 : pRet = new SvxShape( pObj );
596 0 : break;
597 : }
598 1498 : break;
599 : }
600 : case SdrInventor:
601 : {
602 101934 : switch( nType )
603 : {
604 : case OBJ_GRUP:
605 33718 : pRet = new SvxShapeGroup( pObj, mpPage );
606 33718 : break;
607 : case OBJ_LINE:
608 1831 : pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
609 1831 : break;
610 : case OBJ_RECT:
611 13787 : pRet = new SvxShapeRect( pObj );
612 13787 : break;
613 : case OBJ_CIRC:
614 : case OBJ_SECT:
615 : case OBJ_CARC:
616 : case OBJ_CCUT:
617 69 : pRet = new SvxShapeCircle( pObj );
618 69 : break;
619 : case OBJ_POLY:
620 14039 : pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
621 14039 : break;
622 : case OBJ_PLIN:
623 6727 : pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
624 6727 : break;
625 : case OBJ_SPLNLINE:
626 : case OBJ_PATHLINE:
627 58 : pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
628 58 : break;
629 : case OBJ_SPLNFILL:
630 : case OBJ_PATHFILL:
631 531 : pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
632 531 : break;
633 : case OBJ_FREELINE:
634 1 : pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
635 1 : break;
636 : case OBJ_FREEFILL:
637 1 : pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
638 1 : break;
639 : case OBJ_CAPTION:
640 27 : pRet = new SvxShapeCaption( pObj );
641 27 : break;
642 : case OBJ_TITLETEXT:
643 : case OBJ_OUTLINETEXT:
644 : case OBJ_TEXT:
645 20219 : pRet = new SvxShapeText( pObj );
646 20219 : break;
647 : case OBJ_GRAF:
648 415 : pRet = new SvxGraphicObject( pObj, referer );
649 415 : break;
650 : case OBJ_FRAME:
651 1 : pRet = new SvxFrameShape( pObj );
652 1 : break;
653 : case OBJ_OLE2_APPLET:
654 1 : pRet = new SvxAppletShape( pObj );
655 1 : break;
656 : case OBJ_OLE2_PLUGIN:
657 1 : pRet = new SvxPluginShape( pObj );
658 1 : break;
659 : case OBJ_OLE2:
660 : {
661 124 : if( pObj && !pObj->IsEmptyPresObj() && mpPage )
662 : {
663 17 : SdrPage* pSdrPage = mpPage->GetSdrPage();
664 17 : if( pSdrPage )
665 : {
666 17 : SdrModel* pSdrModel = pSdrPage->GetModel();
667 17 : if( pSdrModel )
668 : {
669 17 : ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
670 17 : if( pPersist )
671 : {
672 17 : uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
673 34 : GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
674 :
675 : // TODO CL->KA: Why is this not working anymore?
676 17 : if( xObject.is() )
677 : {
678 16 : SvGlobalName aClassId( xObject->getClassID() );
679 :
680 32 : const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
681 32 : const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
682 32 : const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
683 :
684 16 : if( aPluginClassId == aClassId )
685 : {
686 0 : pRet = new SvxPluginShape( pObj );
687 0 : nType = OBJ_OLE2_PLUGIN;
688 : }
689 16 : else if( aAppletClassId == aClassId )
690 : {
691 0 : pRet = new SvxAppletShape( pObj );
692 0 : nType = OBJ_OLE2_APPLET;
693 : }
694 16 : else if( aIFrameClassId == aClassId )
695 : {
696 0 : pRet = new SvxFrameShape( pObj );
697 0 : nType = OBJ_FRAME;
698 16 : }
699 17 : }
700 : }
701 : }
702 : }
703 : }
704 124 : if( pRet == NULL )
705 : {
706 124 : SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
707 124 : pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
708 : }
709 : }
710 124 : break;
711 : case OBJ_EDGE:
712 61 : pRet = new SvxShapeConnector( pObj );
713 61 : break;
714 : case OBJ_PATHPOLY:
715 1 : pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
716 1 : break;
717 : case OBJ_PATHPLIN:
718 1 : pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
719 1 : break;
720 : case OBJ_PAGE:
721 : {
722 760 : SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
723 760 : pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
724 : }
725 760 : break;
726 : case OBJ_MEASURE:
727 3 : pRet = new SvxShapeDimensioning( pObj );
728 3 : break;
729 : case OBJ_UNO:
730 0 : pRet = new SvxShapeControl( pObj );
731 0 : break;
732 : case OBJ_CUSTOMSHAPE:
733 9531 : pRet = new SvxCustomShape( pObj );
734 9531 : break;
735 : case OBJ_MEDIA:
736 16 : pRet = new SvxMediaShape( pObj, referer );
737 16 : break;
738 : case OBJ_TABLE:
739 10 : pRet = new SvxTableShape( pObj );
740 10 : break;
741 : case OBJ_OPENGL:
742 1 : pRet = new SvxOpenGLObject( pObj );
743 1 : 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 101934 : break;
750 : }
751 : default: // Unbekannter Inventor
752 : {
753 : OSL_FAIL("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
754 0 : break;
755 : }
756 : }
757 :
758 103432 : if(pRet)
759 : {
760 103432 : sal_uInt32 nObjId = nType;
761 :
762 103432 : if( nInventor == E3dInventor )
763 1498 : nObjId |= E3D_INVENTOR_FLAG;
764 :
765 103432 : 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 103432 : pRet->setShapeKind(nObjId);
784 : }
785 :
786 103432 : return pRet;
787 : }
788 :
789 42285 : Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const
790 : throw (std::exception)
791 : {
792 42285 : Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
793 42285 : pObj->GetObjInventor(),
794 : pObj,
795 126855 : (SvxDrawPage*)this));
796 42285 : return xShape;
797 : }
798 :
799 1973 : SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
800 : {
801 1973 : SdrObject* pObj = _CreateSdrObject( xShape );
802 1973 : if( pObj)
803 : {
804 1973 : pObj->SetModel(mpModel);
805 1973 : if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
806 1570 : mpPage->InsertObject( pObj );
807 : }
808 :
809 1973 : 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 119 : uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
825 : {
826 119 : uno::Sequence< OUString > aSeq( 1 );
827 119 : aSeq.getArray()[0] = "com.sun.star.drawing.ShapeCollection";
828 119 : return aSeq;
829 : }
830 :
831 407 : SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, OUString const & referer ) throw()
832 : {
833 407 : 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 49274 : uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
860 : {
861 49274 : if(pPage)
862 : {
863 49259 : uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
864 :
865 49259 : return xDrawPage;
866 : }
867 :
868 15 : return uno::Reference< drawing::XDrawPage >();
869 : }
870 :
871 : /** returns the SdrObject from the given StarOffice API wrapper */
872 11719 : SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
873 : {
874 11719 : if(xDrawPage.is())
875 : {
876 2943 : SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
877 :
878 2943 : if(pDrawPage)
879 : {
880 2943 : return pDrawPage->GetSdrPage();
881 : }
882 : }
883 :
884 8776 : return NULL;
885 : }
886 :
887 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|