1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #define _SVX_USE_UNOGLOBALS_ 28 #include <com/sun/star/document/EventObject.hpp> 29 #include <com/sun/star/lang/DisposedException.hpp> 30 #include <vos/mutex.hxx> 31 #include <osl/mutex.hxx> 32 #include <sfx2/dispatch.hxx> 33 #include <sot/clsids.hxx> 34 #include <comphelper/serviceinfohelper.hxx> 35 36 #include <rtl/uuid.h> 37 #include <rtl/memory.h> 38 #include <sfx2/objsh.hxx> 39 #include <svx/svdpool.hxx> 40 #include <svx/svdobj.hxx> 41 #include <svx/svdoole2.hxx> 42 #include <svx/svdpage.hxx> 43 #include <svx/svdmodel.hxx> 44 #include <svx/svdview.hxx> 45 #include <svx/svdpagv.hxx> 46 #include <svx/unopage.hxx> 47 #include "shapeimpl.hxx" 48 #include "svx/globl3d.hxx" 49 #include <svx/polysc3d.hxx> 50 #include <svx/unoprov.hxx> 51 #include <svx/svdopath.hxx> 52 #include "svx/unoapi.hxx" 53 #include <svx/svdomeas.hxx> 54 #include <svx/extrud3d.hxx> 55 #include <svx/lathe3d.hxx> 56 #include <vcl/svapp.hxx> 57 #include <tools/diagnose_ex.h> 58 59 using ::rtl::OUString; 60 using namespace ::vos; 61 using namespace ::cppu; 62 using namespace ::com::sun::star; 63 using namespace ::com::sun::star::uno; 64 using namespace ::com::sun::star::lang; 65 using namespace ::com::sun::star::container; 66 using namespace ::com::sun::star::drawing; 67 68 #define INTERFACE_TYPE( xint ) \ 69 ::getCppuType((const Reference< xint >*)0) 70 71 #define QUERYINT( xint ) \ 72 if( rType == ::getCppuType((const Reference< xint >*)0) ) \ 73 aAny <<= Reference< xint >(this) 74 75 DECLARE_LIST( SvxDrawPageList, SvxDrawPage * ) 76 77 78 /********************************************************************** 79 * class SvxDrawPage * 80 **********************************************************************/ 81 82 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage ); 83 DBG_NAME(SvxDrawPage) 84 SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw() 85 : mrBHelper( getMutex() ) 86 , mpPage( pInPage ) 87 , mpModel( 0 ) 88 { 89 DBG_CTOR(SvxDrawPage,NULL); 90 // Am Broadcaster anmelden 91 if( mpPage ) 92 mpModel = mpPage->GetModel(); 93 if( mpModel ) 94 StartListening( *mpModel ); 95 96 97 // Erzeugen der (hidden) ::com::sun::star::sdbcx::View 98 mpView = new SdrView( mpModel ); 99 if( mpView ) 100 mpView->SetDesignMode(sal_True); 101 } 102 103 //---------------------------------------------------------------------- 104 // Ctor fuer SvxDrawPage_NewInstance() 105 //---------------------------------------------------------------------- 106 SvxDrawPage::SvxDrawPage() throw() 107 : mrBHelper( getMutex() ) 108 , mpPage( NULL ) 109 , mpModel( NULL ) 110 , mpView( NULL ) 111 { 112 DBG_CTOR(SvxDrawPage,NULL); 113 } 114 115 //---------------------------------------------------------------------- 116 SvxDrawPage::~SvxDrawPage() throw() 117 { 118 DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" ); 119 if( !mrBHelper.bDisposed ) 120 { 121 acquire(); 122 dispose(); 123 } 124 DBG_DTOR(SvxDrawPage,NULL); 125 } 126 127 //---------------------------------------------------------------------- 128 129 // XInterface 130 void SvxDrawPage::release() throw() 131 { 132 /* 133 uno::Reference< uno::XInterface > x( xDelegator ); 134 if (! x.is()) 135 { 136 if (osl_decrementInterlockedCount( &m_refCount ) == 0) 137 { 138 if (! mrBHelper.bDisposed) 139 { 140 uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this ); 141 // First dispose 142 try 143 { 144 dispose(); 145 } 146 catch(::com::sun::star::uno::Exception&) 147 { 148 // release should not throw exceptions 149 } 150 151 // only the alive ref holds the object 152 OSL_ASSERT( m_refCount == 1 ); 153 // destroy the object if xHoldAlive decrement the refcount to 0 154 return; 155 } 156 } 157 // restore the reference count 158 osl_incrementInterlockedCount( &m_refCount ); 159 } 160 */ 161 OWeakAggObject::release(); 162 } 163 164 //---------------------------------------------------------------------- 165 166 SvxDrawPage* SvxDrawPage::GetPageForSdrPage( SdrPage* mpPage ) throw() 167 { 168 return getImplementation( mpPage->getUnoPage() ); 169 } 170 171 // XComponent 172 void SvxDrawPage::disposing() throw() 173 { 174 if( mpModel ) 175 { 176 EndListening( *mpModel ); 177 mpModel = NULL; 178 } 179 180 if( mpView ) 181 { 182 delete mpView; 183 mpView = NULL; 184 } 185 mpPage = 0; 186 } 187 188 //---------------------------------------------------------------------- 189 // XComponent 190 //---------------------------------------------------------------------- 191 192 void SvxDrawPage::dispose() 193 { 194 OGuard aSolarGuard( Application::GetSolarMutex() ); 195 196 // An frequently programming error is to release the last 197 // reference to this object in the disposing message. 198 // Make it rubust, hold a self Reference. 199 uno::Reference< lang::XComponent > xSelf( this ); 200 201 // Guard dispose against multible threading 202 // Remark: It is an error to call dispose more than once 203 sal_Bool bDoDispose = sal_False; 204 { 205 osl::MutexGuard aGuard( mrBHelper.rMutex ); 206 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose ) 207 { 208 // only one call go into this section 209 mrBHelper.bInDispose = sal_True; 210 bDoDispose = sal_True; 211 } 212 } 213 214 // Do not hold the mutex because we are broadcasting 215 if( bDoDispose ) 216 { 217 // Create an event with this as sender 218 try 219 { 220 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) ); 221 ::com::sun::star::document::EventObject aEvt; 222 aEvt.Source = xSource; 223 // inform all listeners to release this object 224 // The listener container are automatically cleared 225 mrBHelper.aLC.disposeAndClear( aEvt ); 226 // notify subclasses to do their dispose 227 disposing(); 228 } 229 catch(::com::sun::star::uno::Exception& e) 230 { 231 // catch exception and throw again but signal that 232 // the object was disposed. Dispose should be called 233 // only once. 234 mrBHelper.bDisposed = sal_True; 235 mrBHelper.bInDispose = sal_False; 236 throw e; 237 } 238 239 // the values bDispose and bInDisposing must set in this order. 240 // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard. 241 mrBHelper.bDisposed = sal_True; 242 mrBHelper.bInDispose = sal_False; 243 } 244 245 } 246 247 //---------------------------------------------------------------------- 248 249 void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) 250 { 251 OGuard aGuard( Application::GetSolarMutex() ); 252 253 if( mpModel == 0 ) 254 throw lang::DisposedException(); 255 256 mrBHelper.addListener( ::getCppuType( &aListener ) , aListener ); 257 } 258 259 //---------------------------------------------------------------------- 260 261 void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) 262 { 263 OGuard aGuard( Application::GetSolarMutex() ); 264 265 if( mpModel == 0 ) 266 throw lang::DisposedException(); 267 268 mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener ); 269 } 270 271 //---------------------------------------------------------------------- 272 // SfxListener 273 //---------------------------------------------------------------------- 274 275 void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ ) 276 { 277 /* 278 if( mpModel ) 279 { 280 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint ); 281 if( pSdrHint ) 282 { 283 switch( pSdrHint->GetKind() ) 284 { 285 case HINT_MODELCLEARED: 286 dispose(); 287 break; 288 default: 289 break; 290 } 291 } 292 } 293 */ 294 } 295 296 //---------------------------------------------------------------------- 297 // ::com::sun::star::drawing::XShapes 298 //---------------------------------------------------------------------- 299 300 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape ) 301 { 302 OGuard aGuard( Application::GetSolarMutex() ); 303 304 if ( ( mpModel == NULL ) || ( mpPage == NULL ) ) 305 throw lang::DisposedException(); 306 307 SvxShape* pShape = SvxShape::getImplementation( xShape ); 308 309 if( NULL == pShape ) 310 return; 311 312 SdrObject *pObj = pShape->GetSdrObject(); 313 314 if(!pObj) 315 { 316 pObj = CreateSdrObject( xShape ); 317 ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" ); 318 } 319 else if ( !pObj->IsInserted() ) 320 { 321 pObj->SetModel(mpModel); 322 mpPage->InsertObject( pObj ); 323 } 324 325 pShape->Create( pObj, this ); 326 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" ); 327 328 mpModel->SetChanged(); 329 } 330 331 //---------------------------------------------------------------------- 332 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape ) 333 { 334 OGuard aGuard( Application::GetSolarMutex() ); 335 336 if( (mpModel == 0) || (mpPage == 0) ) 337 throw lang::DisposedException(); 338 339 SvxShape* pShape = SvxShape::getImplementation( xShape ); 340 341 if(pShape) 342 { 343 SdrObject* pObj = pShape->GetSdrObject(); 344 if(pObj) 345 { 346 // SdrObject aus der Page loeschen 347 sal_uInt32 nCount = mpPage->GetObjCount(); 348 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ ) 349 { 350 if(mpPage->GetObj(nNum) == pObj) 351 { 352 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj ); 353 SdrObject::Free( pObj ); 354 break; 355 } 356 } 357 } 358 } 359 360 if( mpModel ) 361 mpModel->SetChanged(); 362 } 363 364 //---------------------------------------------------------------------- 365 // ::com::sun::star::container::XIndexAccess 366 //---------------------------------------------------------------------- 367 368 sal_Int32 SAL_CALL SvxDrawPage::getCount() 369 { 370 OGuard aGuard( Application::GetSolarMutex() ); 371 372 if( (mpModel == 0) || (mpPage == 0) ) 373 throw lang::DisposedException(); 374 375 return( (sal_Int32) mpPage->GetObjCount() ); 376 } 377 378 //---------------------------------------------------------------------- 379 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index ) 380 { 381 OGuard aGuard( Application::GetSolarMutex() ); 382 383 if( (mpModel == 0) || (mpPage == 0) ) 384 throw lang::DisposedException(); 385 386 if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() ) 387 throw lang::IndexOutOfBoundsException(); 388 389 SdrObject* pObj = mpPage->GetObj( Index ); 390 if( pObj == NULL ) 391 throw uno::RuntimeException(); 392 393 394 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY )); 395 } 396 397 398 //---------------------------------------------------------------------- 399 // ::com::sun::star::container::XElementAccess 400 //---------------------------------------------------------------------- 401 402 uno::Type SAL_CALL SvxDrawPage::getElementType() 403 { 404 return INTERFACE_TYPE( drawing::XShape ); 405 } 406 407 //---------------------------------------------------------------------- 408 sal_Bool SAL_CALL SvxDrawPage::hasElements() 409 { 410 OGuard aGuard( Application::GetSolarMutex() ); 411 412 if( (mpModel == 0) || (mpPage == 0) ) 413 throw lang::DisposedException(); 414 415 return mpPage && mpPage->GetObjCount()>0; 416 } 417 418 namespace 419 { 420 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView ) 421 { 422 SvxShape* pShape = SvxShape::getImplementation( _rxShape ); 423 if ( !pShape ) 424 return; 425 426 SdrObject* pObj = pShape->GetSdrObject(); 427 if ( !pObj ) 428 return; 429 430 _rView.MarkObj( pObj, &_rPageView ); 431 } 432 } 433 434 //---------------------------------------------------------------------- 435 // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen 436 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein. 437 //---------------------------------------------------------------------- 438 void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw () 439 { 440 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]"); 441 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 442 443 if(pPageView!=NULL && mpView!=NULL) 444 { 445 mpView->UnmarkAllObj( pPageView ); 446 447 long nCount = aShapes->getCount(); 448 for( long i = 0; i < nCount; i++ ) 449 { 450 uno::Any aAny( aShapes->getByIndex(i) ); 451 Reference< drawing::XShape > xShape; 452 if( aAny >>= xShape ) 453 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView ); 454 } 455 } 456 } 457 458 //---------------------------------------------------------------------- 459 // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen 460 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein. 461 //---------------------------------------------------------------------- 462 void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw() 463 { 464 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]"); 465 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 466 467 if(pPageView!=NULL && mpView != NULL) 468 { 469 mpView->UnmarkAllObj( pPageView ); 470 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView ); 471 } 472 } 473 474 //---------------------------------------------------------------------- 475 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes ) 476 { 477 OGuard aGuard( Application::GetSolarMutex() ); 478 479 if( (mpModel == 0) || (mpPage == 0) ) 480 throw lang::DisposedException(); 481 482 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]"); 483 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 484 485 Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup; 486 if(mpPage==NULL||mpView==NULL||!xShapes.is()) 487 return xShapeGroup; 488 489 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage ); 490 491 _SelectObjectsInView( xShapes, pPageView ); 492 493 mpView->GroupMarked(); 494 495 mpView->AdjustMarkHdl(); 496 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); 497 if( rMarkList.GetMarkCount() == 1 ) 498 { 499 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 500 if( pObj ) 501 xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() ); 502 } 503 504 mpView->HideSdrPage(); 505 506 if( mpModel ) 507 mpModel->SetChanged(); 508 509 return xShapeGroup; 510 } 511 512 //---------------------------------------------------------------------- 513 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup ) 514 { 515 OGuard aGuard( Application::GetSolarMutex() ); 516 517 if( (mpModel == 0) || (mpPage == 0) ) 518 throw lang::DisposedException(); 519 520 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]"); 521 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 522 523 if(mpPage==NULL||mpView==NULL||!aGroup.is()) 524 return; 525 526 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage ); 527 528 Reference< drawing::XShape > xShape( aGroup, UNO_QUERY ); 529 _SelectObjectInView( xShape, pPageView ); 530 mpView->UnGroupMarked(); 531 532 mpView->HideSdrPage(); 533 534 if( mpModel ) 535 mpModel->SetChanged(); 536 } 537 538 //---------------------------------------------------------------------- 539 SdrObject *SvxDrawPage::_CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw() 540 { 541 sal_uInt16 nType; 542 sal_uInt32 nInventor; 543 544 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() ); 545 SdrObject* pNewObj = 0; 546 547 if( nType != 0 ) 548 { 549 awt::Size aSize = xShape->getSize(); 550 aSize.Width += 1; 551 aSize.Height += 1; 552 awt::Point aPos = xShape->getPosition(); 553 Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) ); 554 555 // special cases 556 if( nInventor == SdrInventor ) 557 { 558 switch( nType ) 559 { 560 case OBJ_MEASURE: 561 { 562 pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() ); 563 break; 564 } 565 case OBJ_LINE: 566 { 567 basegfx::B2DPolygon aPoly; 568 aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top())); 569 aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom())); 570 pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly)); 571 break; 572 } 573 } 574 } 575 576 if( pNewObj == NULL ) 577 pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage ); 578 579 if(pNewObj) 580 { 581 pNewObj->SetSnapRect(aRect); 582 583 if( pNewObj->ISA(E3dPolyScene)) 584 { 585 // Szene initialisieren 586 E3dScene* pScene = (E3dScene*)pNewObj; 587 588 double fW = (double)aSize.Width; 589 double fH = (double)aSize.Height; 590 591 Camera3D aCam(pScene->GetCamera()); 592 aCam.SetAutoAdjustProjection(sal_False); 593 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH); 594 basegfx::B3DPoint aLookAt; 595 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0); 596 aCam.SetPosAndLookAt(aCamPos, aLookAt); 597 aCam.SetFocalLength(100.0); 598 aCam.SetDefaults(aCamPos, aLookAt, 10000.0); 599 pScene->SetCamera(aCam); 600 601 pScene->SetRectsDirty(); 602 } 603 else if(pNewObj->ISA(E3dExtrudeObj)) 604 { 605 E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj; 606 basegfx::B2DPolygon aNewPolygon; 607 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0)); 608 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0)); 609 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0)); 610 aNewPolygon.setClosed(true); 611 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon)); 612 613 // #107245# pObj->SetExtrudeCharacterMode(sal_True); 614 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True)); 615 } 616 else if(pNewObj->ISA(E3dLatheObj)) 617 { 618 E3dLatheObj* pObj = (E3dLatheObj*)pNewObj; 619 basegfx::B2DPolygon aNewPolygon; 620 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0)); 621 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0)); 622 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0)); 623 aNewPolygon.setClosed(true); 624 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon)); 625 626 // #107245# pObj->SetLatheCharacterMode(sal_True); 627 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True)); 628 } 629 } 630 } 631 632 return pNewObj; 633 } 634 635 //---------------------------------------------------------------------- 636 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw() 637 { 638 sal_uInt32 nTempType = aSdrShapeIdentifierMap.getId( aName ); 639 640 if( nTempType == UHASHMAP_NOTFOUND ) 641 { 642 if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape")) || 643 aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TableShape")) ) 644 { 645 rInventor = SdrInventor; 646 rType = OBJ_TABLE; 647 } 648 else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.MediaShape" )) ) 649 { 650 rInventor = SdrInventor; 651 rType = OBJ_MEDIA; 652 } 653 } 654 else if(nTempType & E3D_INVENTOR_FLAG) 655 { 656 rInventor = E3dInventor; 657 rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG); 658 } 659 else 660 { 661 rInventor = SdrInventor; 662 rType = (sal_uInt16)nTempType; 663 664 switch( rType ) 665 { 666 case OBJ_FRAME: 667 case OBJ_OLE2_PLUGIN: 668 case OBJ_OLE2_APPLET: 669 rType = OBJ_OLE2; 670 break; 671 } 672 } 673 } 674 675 //---------------------------------------------------------------------- 676 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage ) throw() 677 { 678 SvxShape* pRet = NULL; 679 switch( nInventor ) 680 { 681 case E3dInventor: 682 { 683 switch( nType ) 684 { 685 case E3D_SCENE_ID : 686 case E3D_POLYSCENE_ID : 687 pRet = new Svx3DSceneObject( pObj, mpPage ); 688 break; 689 case E3D_CUBEOBJ_ID : 690 pRet = new Svx3DCubeObject( pObj ); 691 break; 692 case E3D_SPHEREOBJ_ID : 693 pRet = new Svx3DSphereObject( pObj ); 694 break; 695 case E3D_LATHEOBJ_ID : 696 pRet = new Svx3DLatheObject( pObj ); 697 break; 698 case E3D_EXTRUDEOBJ_ID : 699 pRet = new Svx3DExtrudeObject( pObj ); 700 break; 701 case E3D_POLYGONOBJ_ID : 702 pRet = new Svx3DPolygonObject( pObj ); 703 break; 704 default: // unbekanntes 3D-Objekt auf der Page 705 pRet = new SvxShape( pObj ); 706 break; 707 } 708 break; 709 } 710 case SdrInventor: 711 { 712 switch( nType ) 713 { 714 // case OBJ_NONE: 715 // break; 716 case OBJ_GRUP: 717 pRet = new SvxShapeGroup( pObj, mpPage ); 718 break; 719 case OBJ_LINE: 720 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE ); 721 break; 722 case OBJ_RECT: 723 pRet = new SvxShapeRect( pObj ); 724 break; 725 case OBJ_CIRC: 726 case OBJ_SECT: 727 case OBJ_CARC: 728 case OBJ_CCUT: 729 pRet = new SvxShapeCircle( pObj ); 730 break; 731 case OBJ_POLY: 732 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY ); 733 break; 734 case OBJ_PLIN: 735 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN ); 736 break; 737 case OBJ_SPLNLINE: 738 case OBJ_PATHLINE: 739 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE ); 740 break; 741 case OBJ_SPLNFILL: 742 case OBJ_PATHFILL: 743 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL ); 744 break; 745 case OBJ_FREELINE: 746 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE ); 747 break; 748 case OBJ_FREEFILL: 749 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL ); 750 break; 751 case OBJ_CAPTION: 752 pRet = new SvxShapeCaption( pObj ); 753 break; 754 case OBJ_TITLETEXT: 755 case OBJ_OUTLINETEXT: 756 case OBJ_TEXT: 757 pRet = new SvxShapeText( pObj ); 758 break; 759 case OBJ_GRAF: 760 pRet = new SvxGraphicObject( pObj ); 761 break; 762 case OBJ_FRAME: 763 pRet = new SvxFrameShape( pObj ); 764 break; 765 case OBJ_OLE2_APPLET: 766 pRet = new SvxAppletShape( pObj ); 767 break; 768 case OBJ_OLE2_PLUGIN: 769 pRet = new SvxPluginShape( pObj ); 770 break; 771 case OBJ_OLE2: 772 { 773 if( pObj && !pObj->IsEmptyPresObj() && mpPage ) 774 { 775 SdrPage* pSdrPage = mpPage->GetSdrPage(); 776 if( pSdrPage ) 777 { 778 SdrModel* pSdrModel = pSdrPage->GetModel(); 779 if( pSdrModel ) 780 { 781 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist(); 782 if( pPersist ) 783 { 784 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer(). 785 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ); 786 787 // TODO CL->KA: Why is this not working anymore? 788 if( xObject.is() ) 789 { 790 SvGlobalName aClassId( xObject->getClassID() ); 791 792 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID ); 793 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID ); 794 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID ); 795 796 if( aPluginClassId == aClassId ) 797 { 798 pRet = new SvxPluginShape( pObj ); 799 nType = OBJ_OLE2_PLUGIN; 800 } 801 else if( aAppletClassId == aClassId ) 802 { 803 pRet = new SvxAppletShape( pObj ); 804 nType = OBJ_OLE2_APPLET; 805 } 806 else if( aIFrameClassId == aClassId ) 807 { 808 pRet = new SvxFrameShape( pObj ); 809 nType = OBJ_FRAME; 810 } 811 } 812 } 813 } 814 } 815 } 816 if( pRet == NULL ) 817 { 818 pRet = new SvxOle2Shape( pObj, aSvxMapProvider.GetMap(SVXMAP_OLE2), aSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) ); 819 } 820 } 821 break; 822 case OBJ_EDGE: 823 pRet = new SvxShapeConnector( pObj ); 824 break; 825 case OBJ_PATHPOLY: 826 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY ); 827 break; 828 case OBJ_PATHPLIN: 829 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN ); 830 break; 831 case OBJ_PAGE: 832 pRet = new SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_PAGE), aSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) ); 833 break; 834 case OBJ_MEASURE: 835 pRet = new SvxShapeDimensioning( pObj ); 836 break; 837 // case OBJ_DUMMY: 838 // break; 839 case OBJ_UNO: 840 pRet = new SvxShapeControl( pObj ); 841 break; 842 case OBJ_CUSTOMSHAPE: 843 pRet = new SvxCustomShape( pObj ); 844 break; 845 case OBJ_MEDIA: 846 pRet = new SvxMediaShape( pObj ); 847 break; 848 case OBJ_TABLE: 849 pRet = new SvxTableShape( pObj ); 850 break; 851 default: // unbekanntes 2D-Objekt auf der Page 852 DBG_ERROR("Nicht implementierter Starone-Shape erzeugt! [CL]"); 853 pRet = new SvxShapeText( pObj ); 854 break; 855 } 856 break; 857 } 858 default: // Unbekannter Inventor 859 { 860 DBG_ERROR("AW: Unknown Inventor in SvxDrawPage::_CreateShape()"); 861 break; 862 } 863 } 864 865 if(pRet) 866 { 867 sal_uInt32 nObjId = nType; 868 869 if( nInventor == E3dInventor ) 870 nObjId |= E3D_INVENTOR_FLAG; 871 872 switch(nObjId) 873 { 874 case OBJ_CCUT: // Kreisabschnitt 875 case OBJ_CARC: // Kreisbogen 876 case OBJ_SECT: // Kreissektor 877 nObjId = OBJ_CIRC; 878 break; 879 880 case E3D_SCENE_ID | E3D_INVENTOR_FLAG: 881 nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG; 882 break; 883 884 case OBJ_TITLETEXT: 885 case OBJ_OUTLINETEXT: 886 nObjId = OBJ_TEXT; 887 break; 888 } 889 890 pRet->setShapeKind(nObjId); 891 } 892 893 return pRet; 894 } 895 896 //---------------------------------------------------------------------- 897 Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const throw() 898 { 899 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(), 900 pObj->GetObjInventor(), 901 pObj, 902 (SvxDrawPage*)this)); 903 return xShape; 904 } 905 906 //---------------------------------------------------------------------- 907 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw() 908 { 909 SdrObject* pObj = _CreateSdrObject( xShape ); 910 if( pObj && !pObj->IsInserted() ) 911 mpPage->InsertObject( pObj ); 912 913 return pObj; 914 } 915 916 //---------------------------------------------------------------------- 917 // ::com::sun::star::lang::XServiceInfo 918 //---------------------------------------------------------------------- 919 OUString SAL_CALL SvxDrawPage::getImplementationName() 920 { 921 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxDrawPage")); 922 } 923 924 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName ) 925 { 926 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); 927 } 928 929 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() 930 { 931 uno::Sequence< OUString > aSeq( 1 ); 932 aSeq.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection" )); 933 return aSeq; 934 } 935 936 SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor ) throw() 937 { 938 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor ); 939 } 940 941 void SvxDrawPage::ChangeModel( SdrModel* pNewModel ) 942 { 943 if( pNewModel != mpModel ) 944 { 945 if( mpModel ) 946 EndListening( *mpModel ); 947 948 if( pNewModel ) 949 StartListening( *pNewModel ); 950 951 mpModel = pNewModel; 952 953 if( mpView ) 954 { 955 delete mpView; 956 mpView = new SdrView( mpModel ); 957 if( mpView ) 958 mpView->SetDesignMode(sal_True); 959 } 960 } 961 } 962 963 /** returns a StarOffice API wrapper for the given SdrPage */ 964 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw () 965 { 966 if(pPage) 967 { 968 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY ); 969 970 return xDrawPage; 971 } 972 973 return uno::Reference< drawing::XDrawPage >(); 974 } 975 976 /** returns the SdrObject from the given StarOffice API wrapper */ 977 SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw() 978 { 979 if(xDrawPage.is()) 980 { 981 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage ); 982 983 if(pDrawPage) 984 { 985 return pDrawPage->GetSdrPage(); 986 } 987 } 988 989 return NULL; 990 } 991 992 // eof 993