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