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  SvxShape* pRet = nullptr;
615 
616  switch( nInventor )
617  {
618  case SdrInventor::E3d:
619  {
620  switch( nType )
621  {
622  case E3D_SCENE_ID :
623  pRet = new Svx3DSceneObject( pObj, mpPage );
624  break;
625  case E3D_CUBEOBJ_ID :
626  pRet = new Svx3DCubeObject( pObj );
627  break;
628  case E3D_SPHEREOBJ_ID :
629  pRet = new Svx3DSphereObject( pObj );
630  break;
631  case E3D_LATHEOBJ_ID :
632  pRet = new Svx3DLatheObject( pObj );
633  break;
634  case E3D_EXTRUDEOBJ_ID :
635  pRet = new Svx3DExtrudeObject( pObj );
636  break;
637  case E3D_POLYGONOBJ_ID :
638  pRet = new Svx3DPolygonObject( pObj );
639  break;
640  default: // unknown 3D-object on page
641  pRet = new SvxShape( pObj );
642  break;
643  }
644  break;
645  }
647  {
648  switch( nType )
649  {
650  case OBJ_GRUP:
651  pRet = new SvxShapeGroup( pObj, mpPage );
652  break;
653  case OBJ_LINE:
654  pRet = new SvxShapePolyPolygon( pObj );
655  break;
656  case OBJ_RECT:
657  pRet = new SvxShapeRect( pObj );
658  break;
659  case OBJ_CIRC:
660  case OBJ_SECT:
661  case OBJ_CARC:
662  case OBJ_CCUT:
663  pRet = new SvxShapeCircle( pObj );
664  break;
665  case OBJ_POLY:
666  pRet = new SvxShapePolyPolygon( pObj );
667  break;
668  case OBJ_PLIN:
669  pRet = new SvxShapePolyPolygon( pObj );
670  break;
671  case OBJ_SPLNLINE:
672  case OBJ_PATHLINE:
673  pRet = new SvxShapePolyPolygon( pObj );
674  break;
675  case OBJ_SPLNFILL:
676  case OBJ_PATHFILL:
677  pRet = new SvxShapePolyPolygon( pObj );
678  break;
679  case OBJ_FREELINE:
680  pRet = new SvxShapePolyPolygon( pObj );
681  break;
682  case OBJ_FREEFILL:
683  pRet = new SvxShapePolyPolygon( pObj );
684  break;
685  case OBJ_CAPTION:
686  pRet = new SvxShapeCaption( pObj );
687  break;
688  case OBJ_TITLETEXT:
689  case OBJ_OUTLINETEXT:
690  case OBJ_TEXT:
691  pRet = new SvxShapeText( pObj );
692  break;
693  case OBJ_GRAF:
694  pRet = new SvxGraphicObject( pObj );
695  break;
696  case OBJ_FRAME:
697  pRet = new SvxFrameShape( pObj );
698  break;
699  case OBJ_OLE2_APPLET:
700  pRet = new SvxAppletShape( pObj );
701  break;
702  case OBJ_OLE2_PLUGIN:
703  pRet = new SvxPluginShape( pObj );
704  break;
705  case OBJ_OLE2:
706  {
707  if( pObj && !pObj->IsEmptyPresObj() && mpPage )
708  {
709  SdrPage* pSdrPage = mpPage->GetSdrPage();
710  if( pSdrPage )
711  {
712  SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
713  ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
714 
715  if( pPersist )
716  {
717  uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
718  GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
719 
720  // TODO CL->KA: Why is this not working anymore?
721  if( xObject.is() )
722  {
723  SvGlobalName aClassId( xObject->getClassID() );
724 
725  const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
726  const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
727  const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
728 
729  if( aPluginClassId == aClassId )
730  {
731  pRet = new SvxPluginShape( pObj );
732  nType = OBJ_OLE2_PLUGIN;
733  }
734  else if( aAppletClassId == aClassId )
735  {
736  pRet = new SvxAppletShape( pObj );
737  nType = OBJ_OLE2_APPLET;
738  }
739  else if( aIFrameClassId == aClassId )
740  {
741  pRet = new SvxFrameShape( pObj );
742  nType = OBJ_FRAME;
743  }
744  }
745  }
746  }
747  }
748  if( pRet == nullptr )
749  {
750  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
751  pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
752  }
753  }
754  break;
755  case OBJ_EDGE:
756  pRet = new SvxShapeConnector( pObj );
757  break;
758  case OBJ_PATHPOLY:
759  pRet = new SvxShapePolyPolygon( pObj );
760  break;
761  case OBJ_PATHPLIN:
762  pRet = new SvxShapePolyPolygon( pObj );
763  break;
764  case OBJ_PAGE:
765  {
766  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
767  pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
768  }
769  break;
770  case OBJ_MEASURE:
771  pRet = new SvxShapeDimensioning( pObj );
772  break;
773  case OBJ_UNO:
774  pRet = new SvxShapeControl( pObj );
775  break;
776  case OBJ_CUSTOMSHAPE:
777  pRet = new SvxCustomShape( pObj );
778  break;
779  case OBJ_MEDIA:
780  pRet = new SvxMediaShape( pObj, referer );
781  break;
782  case OBJ_TABLE:
783  pRet = new SvxTableShape( pObj );
784  break;
785  default: // unknown 2D-object on page
786  assert(false && "Not implemented Starone-Shape created");
787  pRet = new SvxShapeText( pObj );
788  break;
789  }
790  break;
791  }
792  default: // unknown inventor
793  {
794  assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
795  break;
796  }
797  }
798 
799  if(pRet)
800  {
801  sal_uInt32 nObjId = nType;
802 
803  if( nInventor == SdrInventor::E3d )
804  nObjId |= E3D_INVENTOR_FLAG;
805 
806  switch(nObjId)
807  {
808  case OBJ_CCUT: // segment of circle
809  case OBJ_CARC: // arc of circle
810  case OBJ_SECT: // sector
811  nObjId = OBJ_CIRC;
812  break;
813 
814  case OBJ_TITLETEXT:
815  case OBJ_OUTLINETEXT:
816  nObjId = OBJ_TEXT;
817  break;
818  }
819 
820  pRet->setShapeKind(nObjId);
821  }
822 
823  return pRet;
824 }
825 
826 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
827 {
828  Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
829  pObj->GetObjInventor(),
830  pObj,
831  const_cast<SvxDrawPage*>(this)));
832  return xShape;
833 }
834 
835 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) throw()
836 {
837  SdrObject* pObj = CreateSdrObject_( xShape );
838  if( pObj)
839  {
840  if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
841  {
842  if(bBeginning)
843  mpPage->InsertObject( pObj, 0 );
844  else
845  mpPage->InsertObject( pObj );
846  }
847  }
848 
849  return pObj;
850 }
851 
852 // css::lang::XServiceInfo
854 {
855  return "SvxDrawPage";
856 }
857 
858 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
859 {
860  return cppu::supportsService( this, ServiceName );
861 }
862 
863 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
864 {
865  uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
866  return aSeq;
867 }
868 
869 SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, OUString const & referer)
870 {
871  return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
872 }
873 
875 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
876 {
877  if(pPage)
878  {
879  uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
880 
881  return xDrawPage;
882  }
883 
884  return uno::Reference< drawing::XDrawPage >();
885 }
886 
888 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) throw()
889 {
890  if(xDrawPage.is())
891  {
892  SvxDrawPage* pDrawPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( xDrawPage );
893 
894  if(pDrawPage)
895  {
896  return pDrawPage->GetSdrPage();
897  }
898  }
899 
900  return nullptr;
901 }
902 
903 /* 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:917
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:888
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:835
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
caption object
Definition: svdobj.hxx:140
bool IsInserted() const
Definition: svdobj.hxx:793
size_t GetObjCount() const
Definition: svdpage.cxx:752
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:2855
#define SVXMAP_PAGE
Definition: unoprov.hxx:77
SdrInventor
Definition: svdobj.hxx:152
virtual OUString TakeObjNameSingul() const
Definition: svdobj.cxx:1018
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:396
open free-hand line
Definition: svdobj.hxx:130
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:343
void BegUndo()
Definition: svdmodel.cxx:412
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:2771
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
virtual void Create(SdrObject *pNewOpj, SvxDrawPage *pNewPage)
Definition: unoshape.cxx:369
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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:546
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:3055
SdrPage * mpPage
Definition: unopage.hxx:66
circle, ellipse
Definition: svdobj.hxx:122
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1261
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:889
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopage.cxx:858
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:577
abstract object (SdrObject)
Definition: svdobj.hxx:118
virtual sal_uInt16 GetObjIdentifier() const
Definition: svdobj.cxx:558
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:908
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:273
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:1899
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:826
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:421
cppu::OBroadcastHelper mrBHelper
Definition: unopage.hxx:64
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1961
#define SVXMAP_OLE2
Definition: unoprov.hxx:68
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:553
void EndUndo()
Definition: svdmodel.cxx:483
closed Bezier-curve
Definition: svdobj.hxx:129
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:390
#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:573
static sal_uInt32 getId(const OUString &rCompareString)
Definition: unoprov.cxx:869
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:478
#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:974
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:875
Sequence< sal_Int8 > aSeq
virtual OUString SAL_CALL getImplementationName() override
Definition: unopage.cxx:853
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:946
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
Definition: svdmrkv.cxx:1714
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
SvxUnoPropertyMapProvider & getSvxMapProvider()
Definition: unoprov.cxx:888
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:863
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:869
void SetPolyPoly2D(const basegfx::B2DPolyPolygon &rNew)
Definition: lathe3d.cxx:134
rectangle (round corners optional)
Definition: svdobj.hxx:121
::osl::Mutex & getMutex()
bool IsEmptyPresObj() const
Definition: svdobj.hxx:881
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)