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