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 
22 #include <com/sun/star/document/EventObject.hpp>
23 #include <com/sun/star/embed/XEmbeddedObject.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <o3tl/safeint.hxx>
27 #include <osl/mutex.hxx>
28 #include <comphelper/classids.hxx>
30 #include <comphelper/sequence.hxx>
32 
33 #include <svx/svdpool.hxx>
34 #include <svx/svdobj.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svx/svdpage.hxx>
37 #include <svx/svdmodel.hxx>
38 #include <svx/strings.hrc>
39 #include <svx/svdview.hxx>
40 #include <svx/svdpagv.hxx>
41 #include <svx/svdundo.hxx>
42 #include <svx/unopage.hxx>
43 #include "shapeimpl.hxx"
45 #include <svx/dialmgr.hxx>
46 #include <svx/svdobjkind.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(m_aMutex)
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() noexcept
87 {
88  OWeakAggObject::release();
89 }
90 
91 // XComponent
92 void SvxDrawPage::disposing() noexcept
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  return;
129 
130  // Create an event with this as sender
131  try
132  {
133  uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( static_cast<lang::XComponent *>(this) ) );
134  css::document::EventObject aEvt;
135  aEvt.Source = xSource;
136  // inform all listeners to release this object
137  // The listener container are automatically cleared
138  mrBHelper.aLC.disposeAndClear( aEvt );
139  // notify subclasses to do their dispose
140  disposing();
141  }
142  catch(const css::uno::Exception&)
143  {
144  // catch exception and throw again but signal that
145  // the object was disposed. Dispose should be called
146  // only once.
147  osl::MutexGuard aGuard( mrBHelper.rMutex );
148  mrBHelper.bDisposed = true;
149  mrBHelper.bInDispose = false;
150  throw;
151  }
152 
153  osl::MutexGuard aGuard( mrBHelper.rMutex );
154  mrBHelper.bDisposed = true;
155  mrBHelper.bInDispose = false;
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::getFromUnoTunnel<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::getFromUnoTunnel<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 
293  if (!pObj)
294  return;
295 
296  // remove SdrObject from page
297  const size_t nCount = mpPage->GetObjCount();
298  for( size_t nNum = 0; nNum < nCount; ++nNum )
299  {
300  if(mpPage->GetObj(nNum) == pObj)
301  {
302  const bool bUndoEnabled = mpModel->IsUndoEnabled();
303 
304  if (bUndoEnabled)
305  {
306  mpModel->BegUndo(SvxResId(STR_EditDelete),
308 
310  }
311 
312  OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
313 
314  if (!bUndoEnabled)
315  SdrObject::Free(pObj);
316 
317  if (bUndoEnabled)
318  mpModel->EndUndo();
319 
320  break;
321  }
322  }
323 
324  mpModel->SetChanged();
325 }
326 
327 void SvxDrawPage::sort( const css::uno::Sequence< sal_Int32 >& sortOrder )
328 {
329  SolarMutexGuard aGuard;
330 
331  if ((mpModel == nullptr) || (mpPage == nullptr))
332  throw lang::DisposedException();
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 Any(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  SdrObject* pObj = SdrObject::getSdrObjectFromXShape( _rxShape );
391  if ( !pObj )
392  return;
393 
394  _rView.MarkObj( pObj, &_rPageView );
395  }
396 }
397 
398 // ATTENTION: SelectObjectsInView selects the css::drawing::Shapes
399 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
400 void SvxDrawPage::SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) noexcept
401 {
402  SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
403  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
404 
405  if(pPageView==nullptr || mpView==nullptr)
406  return;
407 
408  mpView->UnmarkAllObj( pPageView );
409 
410  tools::Long nCount = aShapes->getCount();
411  for( tools::Long i = 0; i < nCount; i++ )
412  {
413  uno::Any aAny( aShapes->getByIndex(i) );
414  Reference< drawing::XShape > xShape;
415  if( aAny >>= xShape )
416  lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
417  }
418 }
419 
420 // ATTENTION: SelectObjectInView selects the shape only in the given SdrPageView.
421 // It hasn't to be the visible SdrPageView.
422 void SvxDrawPage::SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) noexcept
423 {
424  SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
425  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
426 
427  if(pPageView!=nullptr && mpView != nullptr)
428  {
429  mpView->UnmarkAllObj( pPageView );
430  lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
431  }
432 }
433 
434 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
435 {
436  SolarMutexGuard aGuard;
437 
438  if( (mpModel == nullptr) || (mpPage == nullptr) )
439  throw lang::DisposedException();
440 
441  SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
442  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
443 
444  Reference< css::drawing::XShapeGroup > xShapeGroup;
445  if(mpPage==nullptr||mpView==nullptr||!xShapes.is())
446  return xShapeGroup;
447 
448  SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
449 
450  SelectObjectsInView( xShapes, pPageView );
451 
452  mpView->GroupMarked();
453 
454  mpView->AdjustMarkHdl();
455  const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
456  if( rMarkList.GetMarkCount() == 1 )
457  {
458  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
459  if( pObj )
460  xShapeGroup.set( pObj->getUnoShape(), UNO_QUERY );
461  }
462 
463  mpView->HideSdrPage();
464 
465  if( mpModel )
466  mpModel->SetChanged();
467 
468  return xShapeGroup;
469 }
470 
471 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
472 {
473  SolarMutexGuard aGuard;
474 
475  if( (mpModel == nullptr) || (mpPage == nullptr) )
476  throw lang::DisposedException();
477 
478  SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
479  SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
480 
481  if(mpPage==nullptr||mpView==nullptr||!aGroup.is())
482  return;
483 
484  SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
485 
486  SelectObjectInView( aGroup, pPageView );
487  mpView->UnGroupMarked();
488 
489  mpView->HideSdrPage();
490 
491  if( mpModel )
492  mpModel->SetChanged();
493 }
494 
495 SdrObject* SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
496 {
498  SdrInventor nInventor;
499 
500  GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
501  if (nType == SdrObjKind::NONE)
502  return nullptr;
503 
504  awt::Size aSize = xShape->getSize();
505  aSize.Width += 1;
506  aSize.Height += 1;
507  awt::Point aPos = xShape->getPosition();
508  tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
509 
511  *mpModel,
512  nInventor,
513  nType,
514  &aRect);
515 
516  if (!pNewObj)
517  return nullptr;
518 
519  if( auto pScene = dynamic_cast<E3dScene* >(pNewObj) )
520  {
521  // initialise scene
522 
523  double fW = static_cast<double>(aSize.Width);
524  double fH = static_cast<double>(aSize.Height);
525 
526  Camera3D aCam(pScene->GetCamera());
527  aCam.SetAutoAdjustProjection(false);
528  aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
529  basegfx::B3DPoint aLookAt;
530  basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
531  aCam.SetPosAndLookAt(aCamPos, aLookAt);
532  aCam.SetFocalLength(100.0);
533  pScene->SetCamera(aCam);
534 
535  pScene->SetBoundAndSnapRectsDirty();
536  }
537  else if(auto pObj = dynamic_cast<E3dExtrudeObj* >(pNewObj))
538  {
539  basegfx::B2DPolygon aNewPolygon;
540  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
541  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
542  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
543  aNewPolygon.setClosed(true);
544  pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
545 
546  // #107245# pObj->SetExtrudeCharacterMode(sal_True);
548  }
549  else if(auto pLatheObj = dynamic_cast<E3dLatheObj* >(pNewObj))
550  {
551  basegfx::B2DPolygon aNewPolygon;
552  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
553  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
554  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
555  aNewPolygon.setClosed(true);
556  pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
557 
558  // #107245# pObj->SetLatheCharacterMode(sal_True);
559  pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
560  }
561 
562  return pNewObj;
563 }
564 
565 void SvxDrawPage::GetTypeAndInventor( SdrObjKind& rType, SdrInventor& rInventor, const OUString& aName ) noexcept
566 {
567  std::optional<SdrObjKind> nTempType = UHashMap::getId( aName );
568 
569  if( !nTempType )
570  {
571  if( aName == "com.sun.star.drawing.TableShape" ||
572  aName == "com.sun.star.presentation.TableShape" )
573  {
574  rInventor = SdrInventor::Default;
575  rType = SdrObjKind::Table;
576  }
577 #if HAVE_FEATURE_AVMEDIA
578  else if ( aName == "com.sun.star.presentation.MediaShape" )
579  {
580  rInventor = SdrInventor::Default;
581  rType = SdrObjKind::Media;
582  }
583 #endif
584  }
585  else if( IsInventorE3D(*nTempType) )
586  {
587  rInventor = SdrInventor::E3d;
588  rType = *nTempType;
589  }
590  else
591  {
592  rInventor = SdrInventor::Default;
593  rType = *nTempType;
594 
595  switch( rType )
596  {
600  rType = SdrObjKind::OLE2;
601  break;
602  default:
603  break;
604  }
605  }
606 }
607 
609 {
611 
612  switch( nInventor )
613  {
614  case SdrInventor::E3d:
615  {
616  switch( nType )
617  {
618  case SdrObjKind::E3D_Scene :
619  pRet = new Svx3DSceneObject( pObj, mpPage );
620  break;
621  case SdrObjKind::E3D_Cube :
622  pRet = new Svx3DCubeObject( pObj );
623  break;
625  pRet = new Svx3DSphereObject( pObj );
626  break;
627  case SdrObjKind::E3D_Lathe :
628  pRet = new Svx3DLatheObject( pObj );
629  break;
631  pRet = new Svx3DExtrudeObject( pObj );
632  break;
634  pRet = new Svx3DPolygonObject( pObj );
635  break;
636  default: // unknown 3D-object on page
637  assert(false && "the IsInventor3D function must be wrong");
638  pRet = new SvxShape( pObj );
639  break;
640  }
641  break;
642  }
644  {
645  switch( nType )
646  {
647  case SdrObjKind::Group:
648  pRet = new SvxShapeGroup( pObj, mpPage );
649  break;
650  case SdrObjKind::Line:
651  pRet = new SvxShapePolyPolygon( pObj );
652  break;
654  pRet = new SvxShapeRect( pObj );
655  break;
660  pRet = new SvxShapeCircle( pObj );
661  break;
662  case SdrObjKind::Polygon:
663  pRet = new SvxShapePolyPolygon( pObj );
664  break;
666  pRet = new SvxShapePolyPolygon( pObj );
667  break;
670  pRet = new SvxShapePolyPolygon( pObj );
671  break;
674  pRet = new SvxShapePolyPolygon( pObj );
675  break;
677  pRet = new SvxShapePolyPolygon( pObj );
678  break;
680  pRet = new SvxShapePolyPolygon( pObj );
681  break;
682  case SdrObjKind::Caption:
683  pRet = new SvxShapeCaption( pObj );
684  break;
687  case SdrObjKind::Text:
688  pRet = new SvxShapeText( pObj );
689  break;
690  case SdrObjKind::Graphic:
691  pRet = new SvxGraphicObject( pObj );
692  break;
694  pRet = new SvxFrameShape( pObj );
695  break;
697  pRet = new SvxAppletShape( pObj );
698  break;
700  pRet = new SvxPluginShape( pObj );
701  break;
702  case SdrObjKind::OLE2:
703  {
704  if( pObj && !pObj->IsEmptyPresObj() && mpPage )
705  {
706  SdrPage* pSdrPage = mpPage->GetSdrPage();
707  if( pSdrPage )
708  {
709  SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
710  ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
711 
712  if( pPersist )
713  {
714  uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
715  GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
716 
717  // TODO CL->KA: Why is this not working anymore?
718  if( xObject.is() )
719  {
720  SvGlobalName aClassId( xObject->getClassID() );
721 
722  const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
723  const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
724  const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
725 
726  if( aPluginClassId == aClassId )
727  {
728  pRet = new SvxPluginShape( pObj );
729  nType = SdrObjKind::OLE2Plugin;
730  }
731  else if( aAppletClassId == aClassId )
732  {
733  pRet = new SvxAppletShape( pObj );
734  nType = SdrObjKind::OLE2Applet;
735  }
736  else if( aIFrameClassId == aClassId )
737  {
738  pRet = new SvxFrameShape( pObj );
740  }
741  }
742  }
743  }
744  }
745  if( pRet == nullptr )
746  {
747  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
748  pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
749  }
750  }
751  break;
752  case SdrObjKind::Edge:
753  pRet = new SvxShapeConnector( pObj );
754  break;
756  pRet = new SvxShapePolyPolygon( pObj );
757  break;
759  pRet = new SvxShapePolyPolygon( pObj );
760  break;
761  case SdrObjKind::Page:
762  {
763  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
764  pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
765  }
766  break;
767  case SdrObjKind::Measure:
768  pRet = new SvxShapeDimensioning( pObj );
769  break;
770  case SdrObjKind::UNO:
771  pRet = new SvxShapeControl( pObj );
772  break;
774  pRet = new SvxCustomShape( pObj );
775  break;
776  case SdrObjKind::Media:
777  pRet = new SvxMediaShape( pObj, referer );
778  break;
779  case SdrObjKind::Table:
780  pRet = new SvxTableShape( pObj );
781  break;
782  default: // unknown 2D-object on page
783  assert(false && "Not implemented Starone-Shape created");
784  pRet = new SvxShapeText( pObj );
785  break;
786  }
787  break;
788  }
789  default: // unknown inventor
790  {
791  assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
792  break;
793  }
794  }
795 
796  if(pRet)
797  {
798  SdrObjKind nObjId = nType;
799 
800  switch(nObjId)
801  {
802  case SdrObjKind::CircleCut: // segment of circle
803  case SdrObjKind::CircleArc: // arc of circle
804  case SdrObjKind::CircleSection: // sector
806  break;
807 
810  nObjId = SdrObjKind::Text;
811  break;
812  default: ;
813  }
814 
815  pRet->setShapeKind(nObjId);
816  }
817 
818  return pRet;
819 }
820 
821 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
822 {
823  Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
824  pObj->GetObjInventor(),
825  pObj,
826  const_cast<SvxDrawPage*>(this)));
827  return xShape;
828 }
829 
830 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) noexcept
831 {
832  SdrObject* pObj = CreateSdrObject_( xShape );
833  if( pObj)
834  {
835  if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
836  {
837  if(bBeginning)
838  mpPage->InsertObject( pObj, 0 );
839  else
840  mpPage->InsertObject( pObj );
841  }
842  }
843 
844  return pObj;
845 }
846 
847 // css::lang::XServiceInfo
849 {
850  return "SvxDrawPage";
851 }
852 
853 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
854 {
855  return cppu::supportsService( this, ServiceName );
856 }
857 
858 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
859 {
860  uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
861  return aSeq;
862 }
863 
865 {
866  return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
867 }
868 
870 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) noexcept
871 {
872  if(pPage)
873  {
874  uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
875 
876  return xDrawPage;
877  }
878 
879  return uno::Reference< drawing::XDrawPage >();
880 }
881 
883 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) noexcept
884 {
885  if(xDrawPage.is())
886  {
887  SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xDrawPage );
888 
889  if(pDrawPage)
890  {
891  return pDrawPage->GetSdrPage();
892  }
893  }
894 
895  return nullptr;
896 }
897 
898 /* 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)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
OLE object.
size_t GetMarkCount() const
Definition: svdmark.hxx:178
virtual void SAL_CALL addBottom(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:250
UNO3_GETIMPLEMENTATION_IMPL(SvxDrawPage)
media shape
#define SO3_IFRAME_CLASSID
long Long
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: unopage.cxx:159
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
Definition: unoshape.cxx:4018
virtual void SAL_CALL remove(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:285
periodic cubic Spline (ni)
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:807
const css::uno::WeakReference< css::drawing::XShape > & getWeakUnoShape() const
Definition: svdobj.hxx:870
bool IsInserted() const
Definition: svdobj.hxx:739
size_t GetObjCount() const
Definition: svdpage.cxx:801
static void GetTypeAndInventor(SdrObjKind &rType, SdrInventor &rInventor, const OUString &aName) noexcept
Definition: unopage.cxx:565
continuously activated OLE (PlugIn-Frame or similar)
#define SVXMAP_PAGE
Definition: unoprov.hxx:76
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
Definition: svdobj.cxx:3201
SdrInventor
Definition: svdobj.hxx:99
virtual OUString TakeObjNameSingul() const
Definition: svdobj.cxx:1075
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:230
abstract object (SdrObject)
open free-hand line
open Bezier-curve
static void Free(SdrObject *&_rpObject)
Definition: svdobj.cxx:471
virtual SdrObjKind GetObjIdentifier() const
Definition: svdobj.cxx:649
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:329
virtual ~SvxDrawPage() noexcept override
Definition: unopage.cxx:75
void BegUndo()
Definition: svdmodel.cxx:368
closed free-hand line
virtual SdrObject * CreateSdrObject_(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: unopage.cxx:495
SdrObjKind
Definition: svdobjkind.hxx:24
virtual std::unique_ptr< SdrUndoAction > CreateUndoDeleteObject(SdrObject &rObject, bool bOrdNumDirect=false)
Definition: svdundo.cxx:1747
virtual void Create(SdrObject *pNewOpj, SvxDrawPage *pNewPage)
Definition: unoshape.cxx:381
virtual void SAL_CALL release() noexcept override
Definition: unopage.cxx:86
caption object
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:502
measurement object
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
virtual EmbeddedObjectContainer & getEmbeddedObjectContainer() const =0
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
Definition: svdobj.cxx:2879
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr bool IsInventorE3D(SdrObjKind e)
Definition: svdobjkind.hxx:149
std::mutex m_aMutex
SdrPage * mpPage
Definition: unopage.hxx:63
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1154
natural cubic Spline (ni)
void addListener(const keyType &key, const css::uno::Reference< css::uno::XInterface > &r)
foreign graphic (StarView Graphic)
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
virtual void SAL_CALL ungroup(const css::uno::Reference< css::drawing::XShapeGroup > &aGroup) override
Definition: unopage.cxx:471
connector object
SdrModel * mpModel
Definition: unopage.hxx:64
SdrPage * GetSdrPage() const
Definition: unopage.hxx:77
Polygon/PolyPolygon represented by SdrPathObj.
bool IsDoNotInsertIntoPageAutomatically() const
Definition: svdobj.hxx:835
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopage.cxx:853
virtual void SAL_CALL add(const css::uno::Reference< css::drawing::XShape > &xShape) override
Definition: unopage.cxx:179
SdrObject * CreateSdrObject(const css::uno::Reference< css::drawing::XShape > &xShape, bool bBeginning=false) noexcept
Definition: unopage.cxx:830
int i
FPDF_PAGE mpPage
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:533
virtual void SAL_CALL dispose() override
Definition: unopage.cxx:104
std::unique_ptr< SdrView > mpView
Definition: unopage.hxx:65
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
TitleText, special text object for StarDraw.
SvxDrawPage(SdrPage *pPage)
Definition: unopage.cxx:66
unsigned char sal_Bool
const SfxItemPropertyMapEntry * GetMap(sal_uInt16 nPropertyId)
Definition: unoprov.cxx:907
Universal Network Object packed into SvDraw object.
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:279
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:1982
#define SO3_APPLET_CLASSID
polygon, PolyPolygon
circle section
virtual css::uno::Reference< css::drawing::XShape > CreateShape(SdrObject *pObj) const
Definition: unopage.cxx:821
Abstract DrawObject.
Definition: svdobj.hxx:259
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:407
virtual void setUnoShape(const css::uno::Reference< css::drawing::XShape > &_rxUnoShape)
Sets a new UNO representation of the shape.
Definition: svdobj.cxx:2823
cppu::OBroadcastHelper mrBHelper
Definition: unopage.hxx:61
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1856
Polyline represented by SdrPathObj.
#define SVXMAP_OLE2
Definition: unoprov.hxx:67
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:644
static rtl::Reference< SvxShape > CreateShapeByTypeAndInventor(SdrObjKind nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *pPage=nullptr, OUString const &referer=OUString())
Definition: unopage.cxx:608
uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage(SdrPage *pPage) noexcept
returns a StarOffice API wrapper for the given SdrPage
Definition: unopage.cxx:870
void EndUndo()
Definition: svdmodel.cxx:439
SdrPage * GetSdrPageFromXDrawPage(const uno::Reference< drawing::XDrawPage > &xDrawPage) noexcept
returns the SdrObject from the given StarOffice API wrapper
Definition: unopage.cxx:883
rectangle (round corners optional)
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:398
void setClosed(bool bNew)
void sort(std::vector< sal_Int32 > &sortOrder)
Definition: svdpage.cxx:615
virtual css::uno::Reference< css::drawing::XShapeGroup > SAL_CALL group(const css::uno::Reference< css::drawing::XShapes > &xShapes) override
Definition: unopage.cxx:434
virtual sal_Bool SAL_CALL hasElements() override
Definition: unopage.cxx:376
static SdrItemPool & GetGlobalDrawObjectItemPool()
Definition: svdobj.cxx:571
void SelectObjectsInView(const css::uno::Reference< css::drawing::XShapes > &aShapes, SdrPageView *pPageView) noexcept
Definition: unopage.cxx:400
#define SAL_WARN_IF(condition, area, stream)
object group
SvxUnoPropertyMapProvider.
Definition: unoprov.hxx:83
OUString aName
virtual void disposing() noexcept
Definition: unopage.cxx:92
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
Definition: svdobj.cxx:1070
SdrObject * GetSdrObject() const
Definition: unoshape.hxx:204
QPRO_FUNC_TYPE nType
custom shape
Sequence< sal_Int8 > aSeq
virtual OUString SAL_CALL getImplementationName() override
Definition: unopage.cxx:848
UnoViewSharedPtr mpView
const SvxItemPropertySet * GetPropertySet(sal_uInt16 nPropertyId, SfxItemPool &rPool)
Definition: unoprov.cxx:945
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
Definition: svdmrkv.cxx:1920
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:373
static std::optional< SdrObjKind > getId(const OUString &rCompareString)
Definition: unoprov.cxx:876
rtl::Reference< SvxShape > CreateSvxShapeByTypeAndInventor(SdrObjKind 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:864
SvxUnoPropertyMapProvider & getSvxMapProvider()
Definition: unoprov.cxx:886
closed Bezier-curve
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: unopage.cxx:349
void SelectObjectInView(const css::uno::Reference< css::drawing::XShape > &xShape, SdrPageView *pPageView) noexcept
Definition: unopage.cxx:422
struct _ADOIndex Index
#define SO3_PLUGIN_CLASSID
virtual void SAL_CALL sort(const css::uno::Sequence< sal_Int32 > &sortOrder) override
Definition: unopage.cxx:327
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopage.cxx:858
OutlineText, special text object for StarDraw.
object that represents a SdrPage
bool IsEmptyPresObj() const
Definition: svdobj.hxx:827