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