LibreOffice Module svx (master)  1
unopage.cxx
Go to the documentation of this file.
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 <config_features.h>
21 #include <config_feature_desktop.h>
22 
23 #include <com/sun/star/document/EventObject.hpp>
24 #include <com/sun/star/embed/XEmbeddedObject.hpp>
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <o3tl/safeint.hxx>
28 #include <osl/mutex.hxx>
29 #include <comphelper/classids.hxx>
31 #include <comphelper/sequence.hxx>
33 
34 #include <svx/svdpool.hxx>
35 #include <svx/svdobj.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdmodel.hxx>
39 #include <svx/strings.hrc>
40 #include <svx/svdview.hxx>
41 #include <svx/svdpagv.hxx>
42 #include <svx/svdundo.hxx>
43 #include <svx/unopage.hxx>
44 #include "shapeimpl.hxx"
45 #include <svx/dialmgr.hxx>
46 #include <svx/globl3d.hxx>
47 #include <svx/unoprov.hxx>
48 #include <svx/unoapi.hxx>
49 #include <extrud3d.hxx>
50 #include <svx/lathe3d.hxx>
51 #include <svx/scene3d.hxx>
52 #include <vcl/svapp.hxx>
53 #include <tools/diagnose_ex.h>
54 #include <tools/globname.hxx>
55 #include <sal/log.hxx>
56 
57 using namespace ::cppu;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::drawing;
63 
65 
66 SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
67 : mrBHelper(getMutex())
68  ,mpPage(pInPage)
69  ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster
70  ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
71 {
72  mpView->SetDesignMode();
73 }
74 
76 {
77  if( !mrBHelper.bDisposed )
78  {
79  assert(!"SvxDrawPage must be disposed!");
80  acquire();
81  dispose();
82  }
83 }
84 
85 // XInterface
86 void SvxDrawPage::release() throw()
87 {
88  OWeakAggObject::release();
89 }
90 
91 // XComponent
92 void SvxDrawPage::disposing() throw()
93 {
94  if( mpModel )
95  {
96  mpModel = nullptr;
97  }
98 
99  mpView.reset();
100  mpPage = nullptr;
101 }
102 
103 // XComponent
105 {
106  SolarMutexGuard aSolarGuard;
107 
108  // An frequently programming error is to release the last
109  // reference to this object in the disposing message.
110  // Make it robust, hold a self Reference.
111  uno::Reference< lang::XComponent > xSelf( this );
112 
113  // Guard dispose against multiple threading
114  // Remark: It is an error to call dispose more than once
115  bool bDoDispose = false;
116  {
117  osl::MutexGuard aGuard( mrBHelper.rMutex );
119  {
120  // only one call go into this section
121  mrBHelper.bInDispose = true;
122  bDoDispose = true;
123  }
124  }
125 
126  // Do not hold the mutex because we are broadcasting
127  if( bDoDispose )
128  {
129  // Create an event with this as sender
130  try
131  {
132  uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( static_cast<lang::XComponent *>(this) ) );
133  css::document::EventObject aEvt;
134  aEvt.Source = xSource;
135  // inform all listeners to release this object
136  // The listener container are automatically cleared
137  mrBHelper.aLC.disposeAndClear( aEvt );
138  // notify subclasses to do their dispose
139  disposing();
140  }
141  catch(const css::uno::Exception&)
142  {
143  // catch exception and throw again but signal that
144  // the object was disposed. Dispose should be called
145  // only once.
146  osl::MutexGuard aGuard( mrBHelper.rMutex );
147  mrBHelper.bDisposed = true;
148  mrBHelper.bInDispose = false;
149  throw;
150  }
151 
152  osl::MutexGuard aGuard( mrBHelper.rMutex );
153  mrBHelper.bDisposed = true;
154  mrBHelper.bInDispose = false;
155  }
156 
157 }
158 
159 void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
160 {
161  SolarMutexGuard aGuard;
162 
163  if( mpModel == nullptr )
164  throw lang::DisposedException();
165 
166  mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
167 }
168 
169 void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
170 {
171  SolarMutexGuard aGuard;
172 
173  if( mpModel == nullptr )
174  throw lang::DisposedException();
175 
176  mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
177 }
178 
179 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
180 {
181  SolarMutexGuard aGuard;
182 
183  if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
184  throw lang::DisposedException();
185 
186  SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
187 
188  if( nullptr == pShape )
189  return;
190 
191  SdrObject *pObj = pShape->GetSdrObject();
192  bool bNeededToClone(false);
193 
194  if(nullptr != pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
195  {
196  // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
197  // but these use different SdrModels. It was possible before to completely
198  // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
199  // stuff), but is no longer. We need to Clone the SdrObject to the target model
200  // and ::Create a new SvxShape (set SdrObject there, take obver values, ...)
201  SdrObject* pClonedSdrShape(pObj->CloneSdrObject(mpPage->getSdrModelFromSdrPage()));
202  pObj->setUnoShape(nullptr);
203  pClonedSdrShape->setUnoShape(xShape);
204  // pShape->InvalidateSdrObject();
205  // pShape->Create(pClonedSdrShape, this);
206  SdrObject::Free(pObj);
207  pObj = pClonedSdrShape;
208  bNeededToClone = true;
209  }
210 
211  if(!pObj)
212  {
213  pObj = CreateSdrObject( xShape );
214  ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
215  }
216  else if ( !pObj->IsInserted() )
217  {
218  mpPage->InsertObject( pObj );
219 
220  if(bNeededToClone)
221  {
222  // TTTT Unfortunately in SdrObject::SetPage (see there) the
223  // xShape/UnoShape at the newly cloned SDrObject is *removed* again,
224  // so re-set it here, the caller *may need it* (e.g. Writer)
225  uno::Reference< uno::XInterface > xShapeCheck(pObj->getWeakUnoShape());
226 
227  if( !xShapeCheck.is() )
228  {
229  pObj->setUnoShape(xShape);
230  }
231  }
232  }
233 
234  pShape->Create( pObj, this );
235  OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
236 
237  if ( !pObj->IsInserted() )
238  {
239  mpPage->InsertObject( pObj );
240  }
241 
242  mpModel->SetChanged();
243 }
244 
245 void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
246 {
247  add(xShape);
248 }
249 
250 void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
251 {
252  SolarMutexGuard aGuard;
253 
254  if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
255  throw lang::DisposedException();
256 
257  SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
258 
259  if( nullptr == pShape )
260  return;
261 
262  SdrObject *pObj = pShape->GetSdrObject();
263 
264  if(!pObj)
265  {
266  pObj = CreateSdrObject( xShape, true );
267  ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
268  }
269  else if ( !pObj->IsInserted() )
270  {
271  mpPage->InsertObject( pObj, 0 );
272  }
273 
274  pShape->Create( pObj, this );
275  OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
276 
277  if ( !pObj->IsInserted() )
278  {
279  mpPage->InsertObject( pObj, 0 );
280  }
281 
282  mpModel->SetChanged();
283 }
284 
285 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
286 {
287  SolarMutexGuard aGuard;
288 
289  if( (mpModel == nullptr) || (mpPage == nullptr) )
290  throw lang::DisposedException();
291 
292  SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
293 
294  if (pShape)
295  {
296  SdrObject* pObj = pShape->GetSdrObject();
297  if (pObj)
298  {
299  // remove SdrObject from page
300  const size_t nCount = mpPage->GetObjCount();
301  for( size_t nNum = 0; nNum < nCount; ++nNum )
302  {
303  if(mpPage->GetObj(nNum) == pObj)
304  {
305  const bool bUndoEnabled = mpModel->IsUndoEnabled();
306 
307  if (bUndoEnabled)
308  {
309  mpModel->BegUndo(SvxResId(STR_EditDelete),
311 
313  }
314 
315  OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
316 
317  if (!bUndoEnabled)
318  SdrObject::Free(pObj);
319 
320  if (bUndoEnabled)
321  mpModel->EndUndo();
322 
323  break;
324  }
325  }
326  }
327  }
328 
329  mpModel->SetChanged();
330 }
331 
332 void SvxDrawPage::sort( const css::uno::Sequence< sal_Int32 >& sortOrder )
333 {
334  auto newOrder = comphelper::sequenceToContainer<std::vector<sal_Int32>>(sortOrder);
335  mpPage->sort(newOrder);
336 }
337 
338 // css::container::XIndexAccess
339 sal_Int32 SAL_CALL SvxDrawPage::getCount()
340 {
341  SolarMutexGuard aGuard;
342 
343  if( (mpModel == nullptr) || (mpPage == nullptr) )
344  throw lang::DisposedException();
345 
346  return static_cast<sal_Int32>( mpPage->GetObjCount() );
347 }
348 
350 {
351  SolarMutexGuard aGuard;
352 
353  if( (mpModel == nullptr) || (mpPage == nullptr) )
354  throw lang::DisposedException("Model or Page was already disposed!");
355 
356  if ( Index < 0 || o3tl::make_unsigned(Index) >= mpPage->GetObjCount() )
357  throw lang::IndexOutOfBoundsException("Index (" + OUString::number(Index)
358  + ") needs to be a positive integer smaller than the shape count ("
359  + OUString::number(mpPage->GetObjCount()) + ")!");
360 
361  SdrObject* pObj = mpPage->GetObj( Index );
362  if( pObj == nullptr )
363  throw uno::RuntimeException("Runtime exception thrown while getting a ref to the SdrObject at index: "
364  + OUString::number(Index));
365 
366 
367  return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
368 }
369 
370 // css::container::XElementAccess
372 {
374 }
375 
377 {
378  SolarMutexGuard aGuard;
379 
380  if( (mpModel == nullptr) || (mpPage == nullptr) )
381  throw lang::DisposedException();
382 
383  return mpPage && mpPage->GetObjCount()>0;
384 }
385 
386 namespace
387 {
388  void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
389  {
390  SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( _rxShape );
391  if ( !pShape )
392  return;
393 
394  SdrObject* pObj = pShape->GetSdrObject();
395  if ( !pObj )
396  return;
397 
398  _rView.MarkObj( pObj, &_rPageView );
399  }
400 }
401 
402 // ATTENTION: SelectObjectsInView selects the css::drawing::Shapes
403 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
404 void SvxDrawPage::SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
405 {
406  SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
407  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
408 
409  if(pPageView!=nullptr && mpView!=nullptr)
410  {
411  mpView->UnmarkAllObj( pPageView );
412 
413  long nCount = aShapes->getCount();
414  for( long i = 0; i < nCount; i++ )
415  {
416  uno::Any aAny( aShapes->getByIndex(i) );
417  Reference< drawing::XShape > xShape;
418  if( aAny >>= xShape )
419  lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
420  }
421  }
422 }
423 
424 // ATTENTION: SelectObjectInView selects the shape only in the given SdrPageView.
425 // It hasn't to be the visible SdrPageView.
426 void SvxDrawPage::SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
427 {
428  SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
429  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
430 
431  if(pPageView!=nullptr && mpView != nullptr)
432  {
433  mpView->UnmarkAllObj( pPageView );
434  lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
435  }
436 }
437 
438 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
439 {
440  SolarMutexGuard aGuard;
441 
442  if( (mpModel == nullptr) || (mpPage == nullptr) )
443  throw lang::DisposedException();
444 
445  SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
446  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
447 
448  Reference< css::drawing::XShapeGroup > xShapeGroup;
449  if(mpPage==nullptr||mpView==nullptr||!xShapes.is())
450  return xShapeGroup;
451 
452  SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
453 
454  SelectObjectsInView( xShapes, pPageView );
455 
456  mpView->GroupMarked();
457 
458  mpView->AdjustMarkHdl();
459  const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
460  if( rMarkList.GetMarkCount() == 1 )
461  {
462  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
463  if( pObj )
464  xShapeGroup.set( pObj->getUnoShape(), UNO_QUERY );
465  }
466 
467  mpView->HideSdrPage();
468 
469  if( mpModel )
470  mpModel->SetChanged();
471 
472  return xShapeGroup;
473 }
474 
475 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
476 {
477  SolarMutexGuard aGuard;
478 
479  if( (mpModel == nullptr) || (mpPage == nullptr) )
480  throw lang::DisposedException();
481 
482  SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
483  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
484 
485  if(mpPage==nullptr||mpView==nullptr||!aGroup.is())
486  return;
487 
488  SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
489 
490  SelectObjectInView( aGroup, pPageView );
491  mpView->UnGroupMarked();
492 
493  mpView->HideSdrPage();
494 
495  if( mpModel )
496  mpModel->SetChanged();
497 }
498 
499 SdrObject* SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
500 {
501  sal_uInt16 nType = 0;
502  SdrInventor nInventor;
503 
504  GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
505  if (!nType)
506  return nullptr;
507 
508  awt::Size aSize = xShape->getSize();
509  aSize.Width += 1;
510  aSize.Height += 1;
511  awt::Point aPos = xShape->getPosition();
512  tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
513 
515  *mpModel,
516  nInventor,
517  nType,
518  &aRect);
519 
520  if (!pNewObj)
521  return nullptr;
522 
523  if( auto pScene = dynamic_cast<E3dScene* >(pNewObj) )
524  {
525  // initialise scene
526 
527  double fW = static_cast<double>(aSize.Width);
528  double fH = static_cast<double>(aSize.Height);
529 
530  Camera3D aCam(pScene->GetCamera());
531  aCam.SetAutoAdjustProjection(false);
532  aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
533  basegfx::B3DPoint aLookAt;
534  basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
535  aCam.SetPosAndLookAt(aCamPos, aLookAt);
536  aCam.SetFocalLength(100.0);
537  pScene->SetCamera(aCam);
538 
539  pScene->SetRectsDirty();
540  }
541  else if(dynamic_cast<const E3dExtrudeObj* >(pNewObj) != nullptr)
542  {
543  E3dExtrudeObj* pObj = static_cast<E3dExtrudeObj*>(pNewObj);
544  basegfx::B2DPolygon aNewPolygon;
545  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
546  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
547  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
548  aNewPolygon.setClosed(true);
549  pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
550 
551  // #107245# pObj->SetExtrudeCharacterMode(sal_True);
552  pObj->SetMergedItem(Svx3DCharacterModeItem(true));
553  }
554  else if(dynamic_cast<const E3dLatheObj* >(pNewObj) != nullptr)
555  {
556  E3dLatheObj* pObj = static_cast<E3dLatheObj*>(pNewObj);
557  basegfx::B2DPolygon aNewPolygon;
558  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
559  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
560  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
561  aNewPolygon.setClosed(true);
562  pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
563 
564  // #107245# pObj->SetLatheCharacterMode(sal_True);
566  }
567 
568  return pNewObj;
569 }
570 
571 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, SdrInventor& rInventor, const OUString& aName ) throw()
572 {
573  sal_uInt32 nTempType = UHashMap::getId( aName );
574 
575  if( nTempType == UHASHMAP_NOTFOUND )
576  {
577  if( aName == "com.sun.star.drawing.TableShape" ||
578  aName == "com.sun.star.presentation.TableShape" )
579  {
580  rInventor = SdrInventor::Default;
581  rType = OBJ_TABLE;
582  }
583 #if HAVE_FEATURE_AVMEDIA
584  else if ( aName == "com.sun.star.presentation.MediaShape" )
585  {
586  rInventor = SdrInventor::Default;
587  rType = OBJ_MEDIA;
588  }
589 #endif
590  }
591  else if(nTempType & E3D_INVENTOR_FLAG)
592  {
593  rInventor = SdrInventor::E3d;
594  rType = static_cast<sal_uInt16>(nTempType & ~E3D_INVENTOR_FLAG);
595  }
596  else
597  {
598  rInventor = SdrInventor::Default;
599  rType = static_cast<sal_uInt16>(nTempType);
600 
601  switch( rType )
602  {
603  case OBJ_FRAME:
604  case OBJ_OLE2_PLUGIN:
605  case OBJ_OLE2_APPLET:
606  rType = OBJ_OLE2;
607  break;
608  }
609  }
610 }
611 
612 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
613 {
614 #if !HAVE_FEATURE_DESKTOP
615  (void) referer;
616 #endif
617  SvxShape* pRet = nullptr;
618 #if !HAVE_FEATURE_DESKTOP
619  (void)referer;
620 #endif
621 
622  switch( nInventor )
623  {
624  case SdrInventor::E3d:
625  {
626  switch( nType )
627  {
628  case E3D_SCENE_ID :
629  pRet = new Svx3DSceneObject( pObj, mpPage );
630  break;
631  case E3D_CUBEOBJ_ID :
632  pRet = new Svx3DCubeObject( pObj );
633  break;
634  case E3D_SPHEREOBJ_ID :
635  pRet = new Svx3DSphereObject( pObj );
636  break;
637  case E3D_LATHEOBJ_ID :
638  pRet = new Svx3DLatheObject( pObj );
639  break;
640  case E3D_EXTRUDEOBJ_ID :
641  pRet = new Svx3DExtrudeObject( pObj );
642  break;
643  case E3D_POLYGONOBJ_ID :
644  pRet = new Svx3DPolygonObject( pObj );
645  break;
646  default: // unknown 3D-object on page
647  pRet = new SvxShape( pObj );
648  break;
649  }
650  break;
651  }
653  {
654  switch( nType )
655  {
656  case OBJ_GRUP:
657  pRet = new SvxShapeGroup( pObj, mpPage );
658  break;
659  case OBJ_LINE:
660  pRet = new SvxShapePolyPolygon( pObj );
661  break;
662  case OBJ_RECT:
663  pRet = new SvxShapeRect( pObj );
664  break;
665  case OBJ_CIRC:
666  case OBJ_SECT:
667  case OBJ_CARC:
668  case OBJ_CCUT:
669  pRet = new SvxShapeCircle( pObj );
670  break;
671  case OBJ_POLY:
672  pRet = new SvxShapePolyPolygon( pObj );
673  break;
674  case OBJ_PLIN:
675  pRet = new SvxShapePolyPolygon( pObj );
676  break;
677  case OBJ_SPLNLINE:
678  case OBJ_PATHLINE:
679  pRet = new SvxShapePolyPolygon( pObj );
680  break;
681  case OBJ_SPLNFILL:
682  case OBJ_PATHFILL:
683  pRet = new SvxShapePolyPolygon( pObj );
684  break;
685  case OBJ_FREELINE:
686  pRet = new SvxShapePolyPolygon( pObj );
687  break;
688  case OBJ_FREEFILL:
689  pRet = new SvxShapePolyPolygon( pObj );
690  break;
691  case OBJ_CAPTION:
692  pRet = new SvxShapeCaption( pObj );
693  break;
694  case OBJ_TITLETEXT:
695  case OBJ_OUTLINETEXT:
696  case OBJ_TEXT:
697  pRet = new SvxShapeText( pObj );
698  break;
699  case OBJ_GRAF:
700  pRet = new SvxGraphicObject( pObj );
701  break;
702  case OBJ_FRAME:
703  pRet = new SvxFrameShape( pObj );
704  break;
705  case OBJ_OLE2_APPLET:
706  pRet = new SvxAppletShape( pObj );
707  break;
708  case OBJ_OLE2_PLUGIN:
709  pRet = new SvxPluginShape( pObj );
710  break;
711  case OBJ_OLE2:
712  {
713  if( pObj && !pObj->IsEmptyPresObj() && mpPage )
714  {
715  SdrPage* pSdrPage = mpPage->GetSdrPage();
716  if( pSdrPage )
717  {
718  SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
719  ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
720 
721  if( pPersist )
722  {
723  uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
724  GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
725 
726  // TODO CL->KA: Why is this not working anymore?
727  if( xObject.is() )
728  {
729  SvGlobalName aClassId( xObject->getClassID() );
730 
731  const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
732  const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
733  const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
734 
735  if( aPluginClassId == aClassId )
736  {
737  pRet = new SvxPluginShape( pObj );
738  nType = OBJ_OLE2_PLUGIN;
739  }
740  else if( aAppletClassId == aClassId )
741  {
742  pRet = new SvxAppletShape( pObj );
743  nType = OBJ_OLE2_APPLET;
744  }
745  else if( aIFrameClassId == aClassId )
746  {
747  pRet = new SvxFrameShape( pObj );
748  nType = OBJ_FRAME;
749  }
750  }
751  }
752  }
753  }
754  if( pRet == nullptr )
755  {
756  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
757  pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
758  }
759  }
760  break;
761  case OBJ_EDGE:
762  pRet = new SvxShapeConnector( pObj );
763  break;
764  case OBJ_PATHPOLY:
765  pRet = new SvxShapePolyPolygon( pObj );
766  break;
767  case OBJ_PATHPLIN:
768  pRet = new SvxShapePolyPolygon( pObj );
769  break;
770  case OBJ_PAGE:
771  {
772  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
773  pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
774  }
775  break;
776  case OBJ_MEASURE:
777  pRet = new SvxShapeDimensioning( pObj );
778  break;
779  case OBJ_UNO:
780  pRet = new SvxShapeControl( pObj );
781  break;
782  case OBJ_CUSTOMSHAPE:
783  pRet = new SvxCustomShape( pObj );
784  break;
785 #if HAVE_FEATURE_DESKTOP
786  case OBJ_MEDIA:
787  pRet = new SvxMediaShape( pObj, referer );
788  break;
789 #endif
790  case OBJ_TABLE:
791  pRet = new SvxTableShape( pObj );
792  break;
793  default: // unknown 2D-object on page
794  assert(false && "Not implemented Starone-Shape created");
795  pRet = new SvxShapeText( pObj );
796  break;
797  }
798  break;
799  }
800  default: // unknown inventor
801  {
802  assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
803  break;
804  }
805  }
806 
807  if(pRet)
808  {
809  sal_uInt32 nObjId = nType;
810 
811  if( nInventor == SdrInventor::E3d )
812  nObjId |= E3D_INVENTOR_FLAG;
813 
814  switch(nObjId)
815  {
816  case OBJ_CCUT: // segment of circle
817  case OBJ_CARC: // arc of circle
818  case OBJ_SECT: // sector
819  nObjId = OBJ_CIRC;
820  break;
821 
822  case OBJ_TITLETEXT:
823  case OBJ_OUTLINETEXT:
824  nObjId = OBJ_TEXT;
825  break;
826  }
827 
828  pRet->setShapeKind(nObjId);
829  }
830 
831  return pRet;
832 }
833 
834 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
835 {
836  Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
837  pObj->GetObjInventor(),
838  pObj,
839  const_cast<SvxDrawPage*>(this)));
840  return xShape;
841 }
842 
843 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) throw()
844 {
845  SdrObject* pObj = CreateSdrObject_( xShape );
846  if( pObj)
847  {
848  if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
849  {
850  if(bBeginning)
851  mpPage->InsertObject( pObj, 0 );
852  else
853  mpPage->InsertObject( pObj );
854  }
855  }
856 
857  return pObj;
858 }
859 
860 // css::lang::XServiceInfo
862 {
863  return "SvxDrawPage";
864 }
865 
866 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
867 {
868  return cppu::supportsService( this, ServiceName );
869 }
870 
871 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
872 {
873  uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
874  return aSeq;
875 }
876 
877 SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, OUString const & referer)
878 {
879  return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
880 }
881 
883 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
884 {
885  if(pPage)
886  {
887  uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
888 
889  return xDrawPage;
890  }
891 
892  return uno::Reference< drawing::XDrawPage >();
893 }
894 
896 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) throw()
897 {
898  if(xDrawPage.is())
899  {
900  SvxDrawPage* pDrawPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( xDrawPage );
901 
902  if(pDrawPage)
903  {
904  return pDrawPage->GetSdrPage();
905  }
906  }
907 
908  return nullptr;
909 }
910 
911 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetAutoAdjustProjection(bool bAdjust)
Definition: camera3d.hxx:62
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unopage.cxx:371
#define ENSURE_OR_RETURN_VOID(c, m)
const sal_uInt16 E3D_LATHEOBJ_ID
Definition: globl3d.hxx:30
OutlineText, special text object for StarDraw.
Definition: svdobj.hxx:136
void SelectObjectsInView(const css::uno::Reference< css::drawing::XShapes > &aShapes, SdrPageView *pPageView)
Definition: unopage.cxx:404
const css::uno::WeakReference< css::uno::XInterface > & getWeakUnoShape() const
Definition: svdobj.hxx:916
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
size_t GetMarkCount() const
Definition: svdmark.hxx:180
virtual void SAL_CALL addBottom(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:250
virtual void disposing()
Definition: unopage.cxx:92
Universal Network Object packed into SvDraw object.
Definition: svdobj.hxx:146
foreign graphic (StarView Graphic)
Definition: svdobj.hxx:137
UNO3_GETIMPLEMENTATION_IMPL(SvxDrawPage)
natural cubic Spline (ni)
Definition: svdobj.hxx:132
media shape
Definition: svdobj.hxx:148
static SvxShape * CreateShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *pPage=nullptr, OUString const &referer=OUString())
Definition: unopage.cxx:612
Polyline represented by SdrPathObj.
Definition: svdobj.hxx:142
SdrPage * GetSdrPageFromXDrawPage(const uno::Reference< drawing::XDrawPage > &xDrawPage)
returns the SdrObject from the given StarOffice API wrapper
Definition: unopage.cxx:896
const sal_uInt16 E3D_POLYGONOBJ_ID
Definition: globl3d.hxx:32
periodic cubic Spline (ni)
Definition: svdobj.hxx:133
#define SO3_IFRAME_CLASSID
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: unopage.cxx:159
virtual void SAL_CALL remove(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:285
SdrObject * CreateSdrObject(const css::uno::Reference< css::drawing::XShape > &xShape, bool bBeginning=false)
Definition: unopage.cxx:843
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:766
caption object
Definition: svdobj.hxx:140
bool IsInserted() const
Definition: svdobj.hxx:792
size_t GetObjCount() const
Definition: svdpage.cxx:760
static void GetTypeAndInventor(sal_uInt16 &rType, SdrInventor &rInventor, const OUString &aName)
Definition: unopage.cxx:571
void setUnoShape(const css::uno::Reference< css::uno::XInterface > &_rxUnoShape)
Definition: svdobj.cxx:2849
#define SVXMAP_PAGE
Definition: unoprov.hxx:77
SdrInventor
Definition: svdobj.hxx:152
virtual OUString TakeObjNameSingul() const
Definition: svdobj.cxx:1017
measurement object
Definition: svdobj.hxx:144
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
OLE object.
Definition: svdobj.hxx:138
circle cut
Definition: svdobj.hxx:125
static void Free(SdrObject *&_rpObject)
Definition: svdobj.cxx:395
open free-hand line
Definition: svdobj.hxx:130
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:351
void BegUndo()
Definition: svdmodel.cxx:411
polygon, PolyPolygon
Definition: svdobj.hxx:126
object that represents a SdrPage
Definition: svdobj.hxx:143
line
Definition: svdobj.hxx:120
virtual SdrObject * CreateSdrObject_(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: unopage.cxx:499
virtual std::unique_ptr< SdrUndoAction > CreateUndoDeleteObject(SdrObject &rObject, bool bOrdNumDirect=false)
Definition: svdundo.cxx:1664
const sal_Int16 OBJ_OLE2_APPLET
Globals.
Definition: unoprov.hxx:99
custom shape
Definition: svdobj.hxx:147
Polygon/PolyPolygon represented by SdrPathObj.
Definition: svdobj.hxx:141
connector object
Definition: svdobj.hxx:139
virtual css::uno::Reference< css::uno::XInterface > getUnoShape()
Definition: svdobj.cxx:2765
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
virtual void Create(SdrObject *pNewOpj, SvxDrawPage *pNewPage)
Definition: unoshape.cxx:369
continuously activated OLE (PlugIn-Frame or similar)
Definition: svdobj.hxx:145
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: unopage.cxx:169
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdmodel.cxx:545
int nCount
virtual EmbeddedObjectContainer & getEmbeddedObjectContainer() const =0
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
PolyLine.
Definition: svdobj.hxx:127
const sal_uInt16 E3D_SCENE_ID
Definition: globl3d.hxx:25
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
Definition: svdobj.cxx:3043
SdrPage * mpPage
Definition: unopage.hxx:66
circle, ellipse
Definition: svdobj.hxx:122
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1260
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
virtual void SAL_CALL ungroup(const css::uno::Reference< css::drawing::XShapeGroup > &aGroup) override
Definition: unopage.cxx:475
SdPage * mpPage
SdrModel * mpModel
Definition: unopage.hxx:67
SdrPage * GetSdrPage() const
Definition: unopage.hxx:80
object group
Definition: svdobj.hxx:119
bool IsDoNotInsertIntoPageAutomatically() const
Definition: svdobj.hxx:888
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopage.cxx:866
virtual void SAL_CALL add(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:179
int i
void removeListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
Definition: svdmodel.cxx:576
abstract object (SdrObject)
Definition: svdobj.hxx:118
virtual sal_uInt16 GetObjIdentifier() const
Definition: svdobj.cxx:557
void SelectObjectInView(const css::uno::Reference< css::drawing::XShape > &xShape, SdrPageView *pPageView)
Definition: unopage.cxx:426
virtual void SAL_CALL dispose() override
Definition: unopage.cxx:104
std::unique_ptr< SdrView > mpView
Definition: unopage.hxx:68
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
virtual sal_Int32 SAL_CALL getCount() override
Definition: unopage.cxx:339
SvxDrawPage(SdrPage *pPage)
Definition: unopage.cxx:66
unsigned char sal_Bool
const SfxItemPropertyMapEntry * GetMap(sal_uInt16 nPropertyId)
Definition: unoprov.cxx:897
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:272
virtual void SAL_CALL addTop(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:245
css::uno::Type const & get()
void SetMergedItem(const SfxPoolItem &rItem)
Definition: svdobj.cxx:1893
const sal_uInt16 E3D_EXTRUDEOBJ_ID
Definition: globl3d.hxx:29
#define SO3_APPLET_CLASSID
virtual css::uno::Reference< css::drawing::XShape > CreateShape(SdrObject *pObj) const
Definition: unopage.cxx:834
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:429
cppu::OBroadcastHelper mrBHelper
Definition: unopage.hxx:64
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1960
#define SVXMAP_OLE2
Definition: unoprov.hxx:68
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:552
void EndUndo()
Definition: svdmodel.cxx:482
closed Bezier-curve
Definition: svdobj.hxx:129
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:391
#define E3D_INVENTOR_FLAG
Definition: unoprov.hxx:102
circle section
Definition: svdobj.hxx:123
void setClosed(bool bNew)
TitleText, special text object for StarDraw.
Definition: svdobj.hxx:135
void sort(std::vector< sal_Int32 > &sortOrder)
Definition: svdpage.cxx:581
static sal_uInt32 getId(const OUString &rCompareString)
Definition: unoprov.cxx:858
virtual css::uno::Reference< css::drawing::XShapeGroup > SAL_CALL group(const css::uno::Reference< css::drawing::XShapes > &xShapes) override
Definition: unopage.cxx:438
virtual sal_Bool SAL_CALL hasElements() override
Definition: unopage.cxx:376
circle arc
Definition: svdobj.hxx:124
virtual void SAL_CALL release() override
Definition: unopage.cxx:86
static SdrItemPool & GetGlobalDrawObjectItemPool()
Definition: svdobj.cxx:477
#define SAL_WARN_IF(condition, area, stream)
SvxUnoPropertyMapProvider.
Definition: unoprov.hxx:84
OUString aName
virtual ~SvxDrawPage() override
Definition: unopage.cxx:75
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
Definition: svdobj.cxx:973
SdrObject * GetSdrObject() const
Definition: unoshape.hxx:210
#define UHASHMAP_NOTFOUND
class UHashMap
Definition: unoprov.hxx:39
QPRO_FUNC_TYPE nType
uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage(SdrPage *pPage)
returns a StarOffice API wrapper for the given SdrPage
Definition: unopage.cxx:883
Sequence< sal_Int8 > aSeq
virtual OUString SAL_CALL getImplementationName() override
Definition: unopage.cxx:861
UnoViewSharedPtr mpView
const sal_Int16 OBJ_OLE2_PLUGIN
Definition: unoprov.hxx:100
const sal_uInt16 E3D_SPHEREOBJ_ID
Definition: globl3d.hxx:28
const SvxItemPropertySet * GetPropertySet(sal_uInt16 nPropertyId, SfxItemPool &rPool)
Definition: unoprov.cxx:935
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
Definition: svdmrkv.cxx:1671
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
SvxUnoPropertyMapProvider & getSvxMapProvider()
Definition: unoprov.cxx:877
const sal_uInt16 E3D_CUBEOBJ_ID
Definition: globl3d.hxx:27
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: unopage.cxx:349
void setShapeKind(sal_uInt32 nKind)
Definition: unoshape.cxx:251
struct _ADOIndex Index
#define SO3_PLUGIN_CLASSID
virtual void SAL_CALL sort(const css::uno::Sequence< sal_Int32 > &sortOrder) override
Definition: unopage.cxx:332
text object
Definition: svdobj.hxx:134
open Bezier-curve
Definition: svdobj.hxx:128
closed free-hand line
Definition: svdobj.hxx:131
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopage.cxx:871
SvxShape * CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, OUString const &referer)
Creates a StarOffice API wrapper with the given type and inventor Deprecated: This will be replaced w...
Definition: unopage.cxx:877
void SetPolyPoly2D(const basegfx::B2DPolyPolygon &rNew)
Definition: lathe3d.cxx:133
rectangle (round corners optional)
Definition: svdobj.hxx:121
::osl::Mutex & getMutex()
bool IsEmptyPresObj() const
Definition: svdobj.hxx:880
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)