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