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  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::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  return;
411 
412  mpView->UnmarkAllObj( pPageView );
413 
414  long nCount = aShapes->getCount();
415  for( long i = 0; i < nCount; i++ )
416  {
417  uno::Any aAny( aShapes->getByIndex(i) );
418  Reference< drawing::XShape > xShape;
419  if( aAny >>= xShape )
420  lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
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(auto pObj = dynamic_cast<E3dExtrudeObj* >(pNewObj))
542  {
543  basegfx::B2DPolygon aNewPolygon;
544  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
545  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
546  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
547  aNewPolygon.setClosed(true);
548  pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
549 
550  // #107245# pObj->SetExtrudeCharacterMode(sal_True);
552  }
553  else if(auto pLatheObj = dynamic_cast<E3dLatheObj* >(pNewObj))
554  {
555  basegfx::B2DPolygon aNewPolygon;
556  aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
557  aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
558  aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
559  aNewPolygon.setClosed(true);
560  pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
561 
562  // #107245# pObj->SetLatheCharacterMode(sal_True);
563  pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
564  }
565 
566  return pNewObj;
567 }
568 
569 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, SdrInventor& rInventor, const OUString& aName ) throw()
570 {
571  sal_uInt32 nTempType = UHashMap::getId( aName );
572 
573  if( nTempType == UHASHMAP_NOTFOUND )
574  {
575  if( aName == "com.sun.star.drawing.TableShape" ||
576  aName == "com.sun.star.presentation.TableShape" )
577  {
578  rInventor = SdrInventor::Default;
579  rType = OBJ_TABLE;
580  }
581 #if HAVE_FEATURE_AVMEDIA
582  else if ( aName == "com.sun.star.presentation.MediaShape" )
583  {
584  rInventor = SdrInventor::Default;
585  rType = OBJ_MEDIA;
586  }
587 #endif
588  }
589  else if(nTempType & E3D_INVENTOR_FLAG)
590  {
591  rInventor = SdrInventor::E3d;
592  rType = static_cast<sal_uInt16>(nTempType & ~E3D_INVENTOR_FLAG);
593  }
594  else
595  {
596  rInventor = SdrInventor::Default;
597  rType = static_cast<sal_uInt16>(nTempType);
598 
599  switch( rType )
600  {
601  case OBJ_FRAME:
602  case OBJ_OLE2_PLUGIN:
603  case OBJ_OLE2_APPLET:
604  rType = OBJ_OLE2;
605  break;
606  }
607  }
608 }
609 
610 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
611 {
612  SvxShape* pRet = nullptr;
613 
614  switch( nInventor )
615  {
616  case SdrInventor::E3d:
617  {
618  switch( nType )
619  {
620  case E3D_SCENE_ID :
621  pRet = new Svx3DSceneObject( pObj, mpPage );
622  break;
623  case E3D_CUBEOBJ_ID :
624  pRet = new Svx3DCubeObject( pObj );
625  break;
626  case E3D_SPHEREOBJ_ID :
627  pRet = new Svx3DSphereObject( pObj );
628  break;
629  case E3D_LATHEOBJ_ID :
630  pRet = new Svx3DLatheObject( pObj );
631  break;
632  case E3D_EXTRUDEOBJ_ID :
633  pRet = new Svx3DExtrudeObject( pObj );
634  break;
635  case E3D_POLYGONOBJ_ID :
636  pRet = new Svx3DPolygonObject( pObj );
637  break;
638  default: // unknown 3D-object on page
639  pRet = new SvxShape( pObj );
640  break;
641  }
642  break;
643  }
645  {
646  switch( nType )
647  {
648  case OBJ_GRUP:
649  pRet = new SvxShapeGroup( pObj, mpPage );
650  break;
651  case OBJ_LINE:
652  pRet = new SvxShapePolyPolygon( pObj );
653  break;
654  case OBJ_RECT:
655  pRet = new SvxShapeRect( pObj );
656  break;
657  case OBJ_CIRC:
658  case OBJ_SECT:
659  case OBJ_CARC:
660  case OBJ_CCUT:
661  pRet = new SvxShapeCircle( pObj );
662  break;
663  case OBJ_POLY:
664  pRet = new SvxShapePolyPolygon( pObj );
665  break;
666  case OBJ_PLIN:
667  pRet = new SvxShapePolyPolygon( pObj );
668  break;
669  case OBJ_SPLNLINE:
670  case OBJ_PATHLINE:
671  pRet = new SvxShapePolyPolygon( pObj );
672  break;
673  case OBJ_SPLNFILL:
674  case OBJ_PATHFILL:
675  pRet = new SvxShapePolyPolygon( pObj );
676  break;
677  case OBJ_FREELINE:
678  pRet = new SvxShapePolyPolygon( pObj );
679  break;
680  case OBJ_FREEFILL:
681  pRet = new SvxShapePolyPolygon( pObj );
682  break;
683  case OBJ_CAPTION:
684  pRet = new SvxShapeCaption( pObj );
685  break;
686  case OBJ_TITLETEXT:
687  case OBJ_OUTLINETEXT:
688  case OBJ_TEXT:
689  pRet = new SvxShapeText( pObj );
690  break;
691  case OBJ_GRAF:
692  pRet = new SvxGraphicObject( pObj );
693  break;
694  case OBJ_FRAME:
695  pRet = new SvxFrameShape( pObj );
696  break;
697  case OBJ_OLE2_APPLET:
698  pRet = new SvxAppletShape( pObj );
699  break;
700  case OBJ_OLE2_PLUGIN:
701  pRet = new SvxPluginShape( pObj );
702  break;
703  case OBJ_OLE2:
704  {
705  if( pObj && !pObj->IsEmptyPresObj() && mpPage )
706  {
707  SdrPage* pSdrPage = mpPage->GetSdrPage();
708  if( pSdrPage )
709  {
710  SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
711  ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
712 
713  if( pPersist )
714  {
715  uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
716  GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
717 
718  // TODO CL->KA: Why is this not working anymore?
719  if( xObject.is() )
720  {
721  SvGlobalName aClassId( xObject->getClassID() );
722 
723  const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
724  const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
725  const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
726 
727  if( aPluginClassId == aClassId )
728  {
729  pRet = new SvxPluginShape( pObj );
730  nType = OBJ_OLE2_PLUGIN;
731  }
732  else if( aAppletClassId == aClassId )
733  {
734  pRet = new SvxAppletShape( pObj );
735  nType = OBJ_OLE2_APPLET;
736  }
737  else if( aIFrameClassId == aClassId )
738  {
739  pRet = new SvxFrameShape( pObj );
740  nType = OBJ_FRAME;
741  }
742  }
743  }
744  }
745  }
746  if( pRet == nullptr )
747  {
748  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
749  pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
750  }
751  }
752  break;
753  case OBJ_EDGE:
754  pRet = new SvxShapeConnector( pObj );
755  break;
756  case OBJ_PATHPOLY:
757  pRet = new SvxShapePolyPolygon( pObj );
758  break;
759  case OBJ_PATHPLIN:
760  pRet = new SvxShapePolyPolygon( pObj );
761  break;
762  case OBJ_PAGE:
763  {
764  SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
765  pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
766  }
767  break;
768  case OBJ_MEASURE:
769  pRet = new SvxShapeDimensioning( pObj );
770  break;
771  case OBJ_UNO:
772  pRet = new SvxShapeControl( pObj );
773  break;
774  case OBJ_CUSTOMSHAPE:
775  pRet = new SvxCustomShape( pObj );
776  break;
777  case OBJ_MEDIA:
778  pRet = new SvxMediaShape( pObj, referer );
779  break;
780  case OBJ_TABLE:
781  pRet = new SvxTableShape( pObj );
782  break;
783  default: // unknown 2D-object on page
784  assert(false && "Not implemented Starone-Shape created");
785  pRet = new SvxShapeText( pObj );
786  break;
787  }
788  break;
789  }
790  default: // unknown inventor
791  {
792  assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
793  break;
794  }
795  }
796 
797  if(pRet)
798  {
799  sal_uInt32 nObjId = nType;
800 
801  if( nInventor == SdrInventor::E3d )
802  nObjId |= E3D_INVENTOR_FLAG;
803 
804  switch(nObjId)
805  {
806  case OBJ_CCUT: // segment of circle
807  case OBJ_CARC: // arc of circle
808  case OBJ_SECT: // sector
809  nObjId = OBJ_CIRC;
810  break;
811 
812  case OBJ_TITLETEXT:
813  case OBJ_OUTLINETEXT:
814  nObjId = OBJ_TEXT;
815  break;
816  }
817 
818  pRet->setShapeKind(nObjId);
819  }
820 
821  return pRet;
822 }
823 
824 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
825 {
826  Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
827  pObj->GetObjInventor(),
828  pObj,
829  const_cast<SvxDrawPage*>(this)));
830  return xShape;
831 }
832 
833 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) throw()
834 {
835  SdrObject* pObj = CreateSdrObject_( xShape );
836  if( pObj)
837  {
838  if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
839  {
840  if(bBeginning)
841  mpPage->InsertObject( pObj, 0 );
842  else
843  mpPage->InsertObject( pObj );
844  }
845  }
846 
847  return pObj;
848 }
849 
850 // css::lang::XServiceInfo
852 {
853  return "SvxDrawPage";
854 }
855 
856 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
857 {
858  return cppu::supportsService( this, ServiceName );
859 }
860 
861 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
862 {
863  uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
864  return aSeq;
865 }
866 
867 SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, OUString const & referer)
868 {
869  return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
870 }
871 
873 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
874 {
875  if(pPage)
876  {
877  uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
878 
879  return xDrawPage;
880  }
881 
882  return uno::Reference< drawing::XDrawPage >();
883 }
884 
886 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) throw()
887 {
888  if(xDrawPage.is())
889  {
890  SvxDrawPage* pDrawPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( xDrawPage );
891 
892  if(pDrawPage)
893  {
894  return pDrawPage->GetSdrPage();
895  }
896  }
897 
898  return nullptr;
899 }
900 
901 /* 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:137
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:918
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:147
foreign graphic (StarView Graphic)
Definition: svdobj.hxx:138
UNO3_GETIMPLEMENTATION_IMPL(SvxDrawPage)
natural cubic Spline (ni)
Definition: svdobj.hxx:133
media shape
Definition: svdobj.hxx:149
static SvxShape * CreateShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *pPage=nullptr, OUString const &referer=OUString())
Definition: unopage.cxx:610
Polyline represented by SdrPathObj.
Definition: svdobj.hxx:143
SdrPage * GetSdrPageFromXDrawPage(const uno::Reference< drawing::XDrawPage > &xDrawPage)
returns the SdrObject from the given StarOffice API wrapper
Definition: unopage.cxx:886
const sal_uInt16 E3D_POLYGONOBJ_ID
Definition: globl3d.hxx:32
periodic cubic Spline (ni)
Definition: svdobj.hxx:134
#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:833
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
caption object
Definition: svdobj.hxx:141
bool IsInserted() const
Definition: svdobj.hxx:794
size_t GetObjCount() const
Definition: svdpage.cxx:752
static void GetTypeAndInventor(sal_uInt16 &rType, SdrInventor &rInventor, const OUString &aName)
Definition: unopage.cxx:569
void setUnoShape(const css::uno::Reference< css::uno::XInterface > &_rxUnoShape)
Definition: svdobj.cxx:2856
#define SVXMAP_PAGE
Definition: unoprov.hxx:77
SdrInventor
Definition: svdobj.hxx:153
virtual OUString TakeObjNameSingul() const
Definition: svdobj.cxx:1018
measurement object
Definition: svdobj.hxx:145
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
OLE object.
Definition: svdobj.hxx:139
circle cut
Definition: svdobj.hxx:126
static void Free(SdrObject *&_rpObject)
Definition: svdobj.cxx:396
open free-hand line
Definition: svdobj.hxx:131
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:127
object that represents a SdrPage
Definition: svdobj.hxx:144
line
Definition: svdobj.hxx:121
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:148
Polygon/PolyPolygon represented by SdrPathObj.
Definition: svdobj.hxx:142
connector object
Definition: svdobj.hxx:140
virtual css::uno::Reference< css::uno::XInterface > getUnoShape()
Definition: svdobj.cxx:2772
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
virtual void Create(SdrObject *pNewOpj, SvxDrawPage *pNewPage)
Definition: unoshape.cxx:396
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
continuously activated OLE (PlugIn-Frame or similar)
Definition: svdobj.hxx:146
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:128
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:3056
SdrPage * mpPage
Definition: unopage.hxx:66
circle, ellipse
Definition: svdobj.hxx:123
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
SdrModel * mpModel
Definition: unopage.hxx:67
SdrPage * GetSdrPage() const
Definition: unopage.hxx:80
object group
Definition: svdobj.hxx:120
bool IsDoNotInsertIntoPageAutomatically() const
Definition: svdobj.hxx:890
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopage.cxx:856
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:119
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:1900
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:824
Abstract DrawObject.
Definition: svdobj.hxx:313
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:130
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:390
#define E3D_INVENTOR_FLAG
Definition: unoprov.hxx:102
circle section
Definition: svdobj.hxx:124
void setClosed(bool bNew)
TitleText, special text object for StarDraw.
Definition: svdobj.hxx:136
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:125
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:873
Sequence< sal_Int8 > aSeq
virtual OUString SAL_CALL getImplementationName() override
Definition: unopage.cxx:851
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:1703
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:278
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:135
open Bezier-curve
Definition: svdobj.hxx:129
closed free-hand line
Definition: svdobj.hxx:132
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopage.cxx:861
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:867
rectangle (round corners optional)
Definition: svdobj.hxx:122
::osl::Mutex & getMutex()
bool IsEmptyPresObj() const
Definition: svdobj.hxx:882
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)