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 throw(::com::sun::star::uno::RuntimeException) 194 { 195 OGuard aSolarGuard( Application::GetSolarMutex() ); 196 197 // An frequently programming error is to release the last 198 // reference to this object in the disposing message. 199 // Make it rubust, hold a self Reference. 200 uno::Reference< lang::XComponent > xSelf( this ); 201 202 // Guard dispose against multible threading 203 // Remark: It is an error to call dispose more than once 204 sal_Bool bDoDispose = sal_False; 205 { 206 osl::MutexGuard aGuard( mrBHelper.rMutex ); 207 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose ) 208 { 209 // only one call go into this section 210 mrBHelper.bInDispose = sal_True; 211 bDoDispose = sal_True; 212 } 213 } 214 215 // Do not hold the mutex because we are broadcasting 216 if( bDoDispose ) 217 { 218 // Create an event with this as sender 219 try 220 { 221 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) ); 222 ::com::sun::star::document::EventObject aEvt; 223 aEvt.Source = xSource; 224 // inform all listeners to release this object 225 // The listener container are automaticly cleared 226 mrBHelper.aLC.disposeAndClear( aEvt ); 227 // notify subclasses to do their dispose 228 disposing(); 229 } 230 catch(::com::sun::star::uno::Exception& e) 231 { 232 // catch exception and throw again but signal that 233 // the object was disposed. Dispose should be called 234 // only once. 235 mrBHelper.bDisposed = sal_True; 236 mrBHelper.bInDispose = sal_False; 237 throw e; 238 } 239 240 // the values bDispose and bInDisposing must set in this order. 241 // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard. 242 mrBHelper.bDisposed = sal_True; 243 mrBHelper.bInDispose = sal_False; 244 } 245 246 } 247 248 //---------------------------------------------------------------------- 249 250 void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException) 251 { 252 OGuard aGuard( Application::GetSolarMutex() ); 253 254 if( mpModel == 0 ) 255 throw lang::DisposedException(); 256 257 mrBHelper.addListener( ::getCppuType( &aListener ) , aListener ); 258 } 259 260 //---------------------------------------------------------------------- 261 262 void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException) 263 { 264 OGuard aGuard( Application::GetSolarMutex() ); 265 266 if( mpModel == 0 ) 267 throw lang::DisposedException(); 268 269 mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener ); 270 } 271 272 //---------------------------------------------------------------------- 273 // SfxListener 274 //---------------------------------------------------------------------- 275 276 void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ ) 277 { 278 /* 279 if( mpModel ) 280 { 281 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint ); 282 if( pSdrHint ) 283 { 284 switch( pSdrHint->GetKind() ) 285 { 286 case HINT_MODELCLEARED: 287 dispose(); 288 break; 289 default: 290 break; 291 } 292 } 293 } 294 */ 295 } 296 297 //---------------------------------------------------------------------- 298 // ::com::sun::star::drawing::XShapes 299 //---------------------------------------------------------------------- 300 301 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape ) 302 throw( uno::RuntimeException ) 303 { 304 OGuard aGuard( Application::GetSolarMutex() ); 305 306 if ( ( mpModel == NULL ) || ( mpPage == NULL ) ) 307 throw lang::DisposedException(); 308 309 SvxShape* pShape = SvxShape::getImplementation( xShape ); 310 311 if( NULL == pShape ) 312 return; 313 314 SdrObject *pObj = pShape->GetSdrObject(); 315 316 if(!pObj) 317 { 318 pObj = CreateSdrObject( xShape ); 319 ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" ); 320 } 321 else if ( !pObj->IsInserted() ) 322 { 323 pObj->SetModel(mpModel); 324 mpPage->InsertObject( pObj ); 325 } 326 327 pShape->Create( pObj, this ); 328 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" ); 329 330 mpModel->SetChanged(); 331 } 332 333 //---------------------------------------------------------------------- 334 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape ) 335 throw( uno::RuntimeException ) 336 { 337 OGuard aGuard( Application::GetSolarMutex() ); 338 339 if( (mpModel == 0) || (mpPage == 0) ) 340 throw lang::DisposedException(); 341 342 SvxShape* pShape = SvxShape::getImplementation( xShape ); 343 344 if(pShape) 345 { 346 SdrObject* pObj = pShape->GetSdrObject(); 347 if(pObj) 348 { 349 // SdrObject aus der Page loeschen 350 sal_uInt32 nCount = mpPage->GetObjCount(); 351 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ ) 352 { 353 if(mpPage->GetObj(nNum) == pObj) 354 { 355 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj ); 356 SdrObject::Free( pObj ); 357 break; 358 } 359 } 360 } 361 } 362 363 if( mpModel ) 364 mpModel->SetChanged(); 365 } 366 367 //---------------------------------------------------------------------- 368 // ::com::sun::star::container::XIndexAccess 369 //---------------------------------------------------------------------- 370 371 sal_Int32 SAL_CALL SvxDrawPage::getCount() 372 throw( uno::RuntimeException ) 373 { 374 OGuard aGuard( Application::GetSolarMutex() ); 375 376 if( (mpModel == 0) || (mpPage == 0) ) 377 throw lang::DisposedException(); 378 379 return( (sal_Int32) mpPage->GetObjCount() ); 380 } 381 382 //---------------------------------------------------------------------- 383 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index ) 384 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 385 { 386 OGuard aGuard( Application::GetSolarMutex() ); 387 388 if( (mpModel == 0) || (mpPage == 0) ) 389 throw lang::DisposedException(); 390 391 if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() ) 392 throw lang::IndexOutOfBoundsException(); 393 394 SdrObject* pObj = mpPage->GetObj( Index ); 395 if( pObj == NULL ) 396 throw uno::RuntimeException(); 397 398 399 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY )); 400 } 401 402 403 //---------------------------------------------------------------------- 404 // ::com::sun::star::container::XElementAccess 405 //---------------------------------------------------------------------- 406 407 uno::Type SAL_CALL SvxDrawPage::getElementType() 408 throw( uno::RuntimeException ) 409 { 410 return INTERFACE_TYPE( drawing::XShape ); 411 } 412 413 //---------------------------------------------------------------------- 414 sal_Bool SAL_CALL SvxDrawPage::hasElements() 415 throw( uno::RuntimeException ) 416 { 417 OGuard aGuard( Application::GetSolarMutex() ); 418 419 if( (mpModel == 0) || (mpPage == 0) ) 420 throw lang::DisposedException(); 421 422 return mpPage && mpPage->GetObjCount()>0; 423 } 424 425 namespace 426 { 427 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView ) 428 { 429 SvxShape* pShape = SvxShape::getImplementation( _rxShape ); 430 if ( !pShape ) 431 return; 432 433 SdrObject* pObj = pShape->GetSdrObject(); 434 if ( !pObj ) 435 return; 436 437 _rView.MarkObj( pObj, &_rPageView ); 438 } 439 } 440 441 //---------------------------------------------------------------------- 442 // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen 443 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein. 444 //---------------------------------------------------------------------- 445 void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw () 446 { 447 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]"); 448 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 449 450 if(pPageView!=NULL && mpView!=NULL) 451 { 452 mpView->UnmarkAllObj( pPageView ); 453 454 long nCount = aShapes->getCount(); 455 for( long i = 0; i < nCount; i++ ) 456 { 457 uno::Any aAny( aShapes->getByIndex(i) ); 458 Reference< drawing::XShape > xShape; 459 if( aAny >>= xShape ) 460 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView ); 461 } 462 } 463 } 464 465 //---------------------------------------------------------------------- 466 // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen 467 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein. 468 //---------------------------------------------------------------------- 469 void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw() 470 { 471 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]"); 472 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 473 474 if(pPageView!=NULL && mpView != NULL) 475 { 476 mpView->UnmarkAllObj( pPageView ); 477 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView ); 478 } 479 } 480 481 //---------------------------------------------------------------------- 482 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes ) 483 throw( uno::RuntimeException ) 484 { 485 OGuard aGuard( Application::GetSolarMutex() ); 486 487 if( (mpModel == 0) || (mpPage == 0) ) 488 throw lang::DisposedException(); 489 490 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]"); 491 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 492 493 Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup; 494 if(mpPage==NULL||mpView==NULL||!xShapes.is()) 495 return xShapeGroup; 496 497 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage ); 498 499 _SelectObjectsInView( xShapes, pPageView ); 500 501 mpView->GroupMarked(); 502 503 mpView->AdjustMarkHdl(); 504 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); 505 if( rMarkList.GetMarkCount() == 1 ) 506 { 507 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 508 if( pObj ) 509 xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() ); 510 } 511 512 mpView->HideSdrPage(); 513 514 if( mpModel ) 515 mpModel->SetChanged(); 516 517 return xShapeGroup; 518 } 519 520 //---------------------------------------------------------------------- 521 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup ) 522 throw( uno::RuntimeException ) 523 { 524 OGuard aGuard( Application::GetSolarMutex() ); 525 526 if( (mpModel == 0) || (mpPage == 0) ) 527 throw lang::DisposedException(); 528 529 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]"); 530 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]"); 531 532 if(mpPage==NULL||mpView==NULL||!aGroup.is()) 533 return; 534 535 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage ); 536 537 Reference< drawing::XShape > xShape( aGroup, UNO_QUERY ); 538 _SelectObjectInView( xShape, pPageView ); 539 mpView->UnGroupMarked(); 540 541 mpView->HideSdrPage(); 542 543 if( mpModel ) 544 mpModel->SetChanged(); 545 } 546 547 //---------------------------------------------------------------------- 548 SdrObject *SvxDrawPage::_CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw() 549 { 550 sal_uInt16 nType; 551 sal_uInt32 nInventor; 552 553 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() ); 554 SdrObject* pNewObj = 0; 555 556 if( nType != 0 ) 557 { 558 awt::Size aSize = xShape->getSize(); 559 aSize.Width += 1; 560 aSize.Height += 1; 561 awt::Point aPos = xShape->getPosition(); 562 Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) ); 563 564 // special cases 565 if( nInventor == SdrInventor ) 566 { 567 switch( nType ) 568 { 569 case OBJ_MEASURE: 570 { 571 pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() ); 572 break; 573 } 574 case OBJ_LINE: 575 { 576 basegfx::B2DPolygon aPoly; 577 aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top())); 578 aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom())); 579 pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly)); 580 break; 581 } 582 } 583 } 584 585 if( pNewObj == NULL ) 586 pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage ); 587 588 if(pNewObj) 589 { 590 pNewObj->SetSnapRect(aRect); 591 592 if( pNewObj->ISA(E3dPolyScene)) 593 { 594 // Szene initialisieren 595 E3dScene* pScene = (E3dScene*)pNewObj; 596 597 double fW = (double)aSize.Width; 598 double fH = (double)aSize.Height; 599 600 Camera3D aCam(pScene->GetCamera()); 601 aCam.SetAutoAdjustProjection(sal_False); 602 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH); 603 basegfx::B3DPoint aLookAt; 604 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0); 605 aCam.SetPosAndLookAt(aCamPos, aLookAt); 606 aCam.SetFocalLength(100.0); 607 aCam.SetDefaults(aCamPos, aLookAt, 10000.0); 608 pScene->SetCamera(aCam); 609 610 pScene->SetRectsDirty(); 611 } 612 else if(pNewObj->ISA(E3dExtrudeObj)) 613 { 614 E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj; 615 basegfx::B2DPolygon aNewPolygon; 616 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0)); 617 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0)); 618 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0)); 619 aNewPolygon.setClosed(true); 620 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon)); 621 622 // #107245# pObj->SetExtrudeCharacterMode(sal_True); 623 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True)); 624 } 625 else if(pNewObj->ISA(E3dLatheObj)) 626 { 627 E3dLatheObj* pObj = (E3dLatheObj*)pNewObj; 628 basegfx::B2DPolygon aNewPolygon; 629 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0)); 630 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0)); 631 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0)); 632 aNewPolygon.setClosed(true); 633 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon)); 634 635 // #107245# pObj->SetLatheCharacterMode(sal_True); 636 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True)); 637 } 638 } 639 } 640 641 return pNewObj; 642 } 643 644 //---------------------------------------------------------------------- 645 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw() 646 { 647 sal_uInt32 nTempType = aSdrShapeIdentifierMap.getId( aName ); 648 649 if( nTempType == UHASHMAP_NOTFOUND ) 650 { 651 if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape")) || 652 aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TableShape")) ) 653 { 654 rInventor = SdrInventor; 655 rType = OBJ_TABLE; 656 } 657 else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.MediaShape" )) ) 658 { 659 rInventor = SdrInventor; 660 rType = OBJ_MEDIA; 661 } 662 } 663 else if(nTempType & E3D_INVENTOR_FLAG) 664 { 665 rInventor = E3dInventor; 666 rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG); 667 } 668 else 669 { 670 rInventor = SdrInventor; 671 rType = (sal_uInt16)nTempType; 672 673 switch( rType ) 674 { 675 case OBJ_FRAME: 676 case OBJ_OLE2_PLUGIN: 677 case OBJ_OLE2_APPLET: 678 rType = OBJ_OLE2; 679 break; 680 } 681 } 682 } 683 684 //---------------------------------------------------------------------- 685 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage ) throw() 686 { 687 SvxShape* pRet = NULL; 688 switch( nInventor ) 689 { 690 case E3dInventor: 691 { 692 switch( nType ) 693 { 694 case E3D_SCENE_ID : 695 case E3D_POLYSCENE_ID : 696 pRet = new Svx3DSceneObject( pObj, mpPage ); 697 break; 698 case E3D_CUBEOBJ_ID : 699 pRet = new Svx3DCubeObject( pObj ); 700 break; 701 case E3D_SPHEREOBJ_ID : 702 pRet = new Svx3DSphereObject( pObj ); 703 break; 704 case E3D_LATHEOBJ_ID : 705 pRet = new Svx3DLatheObject( pObj ); 706 break; 707 case E3D_EXTRUDEOBJ_ID : 708 pRet = new Svx3DExtrudeObject( pObj ); 709 break; 710 case E3D_POLYGONOBJ_ID : 711 pRet = new Svx3DPolygonObject( pObj ); 712 break; 713 default: // unbekanntes 3D-Objekt auf der Page 714 pRet = new SvxShape( pObj ); 715 break; 716 } 717 break; 718 } 719 case SdrInventor: 720 { 721 switch( nType ) 722 { 723 // case OBJ_NONE: 724 // break; 725 case OBJ_GRUP: 726 pRet = new SvxShapeGroup( pObj, mpPage ); 727 break; 728 case OBJ_LINE: 729 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE ); 730 break; 731 case OBJ_RECT: 732 pRet = new SvxShapeRect( pObj ); 733 break; 734 case OBJ_CIRC: 735 case OBJ_SECT: 736 case OBJ_CARC: 737 case OBJ_CCUT: 738 pRet = new SvxShapeCircle( pObj ); 739 break; 740 case OBJ_POLY: 741 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY ); 742 break; 743 case OBJ_PLIN: 744 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN ); 745 break; 746 case OBJ_SPLNLINE: 747 case OBJ_PATHLINE: 748 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE ); 749 break; 750 case OBJ_SPLNFILL: 751 case OBJ_PATHFILL: 752 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL ); 753 break; 754 case OBJ_FREELINE: 755 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE ); 756 break; 757 case OBJ_FREEFILL: 758 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL ); 759 break; 760 case OBJ_CAPTION: 761 pRet = new SvxShapeCaption( pObj ); 762 break; 763 case OBJ_TITLETEXT: 764 case OBJ_OUTLINETEXT: 765 case OBJ_TEXT: 766 pRet = new SvxShapeText( pObj ); 767 break; 768 case OBJ_GRAF: 769 pRet = new SvxGraphicObject( pObj ); 770 break; 771 case OBJ_FRAME: 772 pRet = new SvxFrameShape( pObj ); 773 break; 774 case OBJ_OLE2_APPLET: 775 pRet = new SvxAppletShape( pObj ); 776 break; 777 case OBJ_OLE2_PLUGIN: 778 pRet = new SvxPluginShape( pObj ); 779 break; 780 case OBJ_OLE2: 781 { 782 if( pObj && !pObj->IsEmptyPresObj() && mpPage ) 783 { 784 SdrPage* pSdrPage = mpPage->GetSdrPage(); 785 if( pSdrPage ) 786 { 787 SdrModel* pSdrModel = pSdrPage->GetModel(); 788 if( pSdrModel ) 789 { 790 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist(); 791 if( pPersist ) 792 { 793 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer(). 794 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ); 795 796 // TODO CL->KA: Why is this not working anymore? 797 if( xObject.is() ) 798 { 799 SvGlobalName aClassId( xObject->getClassID() ); 800 801 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID ); 802 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID ); 803 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID ); 804 805 if( aPluginClassId == aClassId ) 806 { 807 pRet = new SvxPluginShape( pObj ); 808 nType = OBJ_OLE2_PLUGIN; 809 } 810 else if( aAppletClassId == aClassId ) 811 { 812 pRet = new SvxAppletShape( pObj ); 813 nType = OBJ_OLE2_APPLET; 814 } 815 else if( aIFrameClassId == aClassId ) 816 { 817 pRet = new SvxFrameShape( pObj ); 818 nType = OBJ_FRAME; 819 } 820 } 821 } 822 } 823 } 824 } 825 if( pRet == NULL ) 826 { 827 pRet = new SvxOle2Shape( pObj, aSvxMapProvider.GetMap(SVXMAP_OLE2), aSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) ); 828 } 829 } 830 break; 831 case OBJ_EDGE: 832 pRet = new SvxShapeConnector( pObj ); 833 break; 834 case OBJ_PATHPOLY: 835 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY ); 836 break; 837 case OBJ_PATHPLIN: 838 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN ); 839 break; 840 case OBJ_PAGE: 841 pRet = new SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_PAGE), aSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) ); 842 break; 843 case OBJ_MEASURE: 844 pRet = new SvxShapeDimensioning( pObj ); 845 break; 846 // case OBJ_DUMMY: 847 // break; 848 case OBJ_UNO: 849 pRet = new SvxShapeControl( pObj ); 850 break; 851 case OBJ_CUSTOMSHAPE: 852 pRet = new SvxCustomShape( pObj ); 853 break; 854 case OBJ_MEDIA: 855 pRet = new SvxMediaShape( pObj ); 856 break; 857 case OBJ_TABLE: 858 pRet = new SvxTableShape( pObj ); 859 break; 860 default: // unbekanntes 2D-Objekt auf der Page 861 DBG_ERROR("Nicht implementierter Starone-Shape erzeugt! [CL]"); 862 pRet = new SvxShapeText( pObj ); 863 break; 864 } 865 break; 866 } 867 default: // Unbekannter Inventor 868 { 869 DBG_ERROR("AW: Unknown Inventor in SvxDrawPage::_CreateShape()"); 870 break; 871 } 872 } 873 874 if(pRet) 875 { 876 sal_uInt32 nObjId = nType; 877 878 if( nInventor == E3dInventor ) 879 nObjId |= E3D_INVENTOR_FLAG; 880 881 switch(nObjId) 882 { 883 case OBJ_CCUT: // Kreisabschnitt 884 case OBJ_CARC: // Kreisbogen 885 case OBJ_SECT: // Kreissektor 886 nObjId = OBJ_CIRC; 887 break; 888 889 case E3D_SCENE_ID | E3D_INVENTOR_FLAG: 890 nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG; 891 break; 892 893 case OBJ_TITLETEXT: 894 case OBJ_OUTLINETEXT: 895 nObjId = OBJ_TEXT; 896 break; 897 } 898 899 pRet->setShapeKind(nObjId); 900 } 901 902 return pRet; 903 } 904 905 //---------------------------------------------------------------------- 906 Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const throw() 907 { 908 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(), 909 pObj->GetObjInventor(), 910 pObj, 911 (SvxDrawPage*)this)); 912 return xShape; 913 } 914 915 //---------------------------------------------------------------------- 916 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw() 917 { 918 SdrObject* pObj = _CreateSdrObject( xShape ); 919 if( pObj && !pObj->IsInserted() ) 920 mpPage->InsertObject( pObj ); 921 922 return pObj; 923 } 924 925 //---------------------------------------------------------------------- 926 // ::com::sun::star::lang::XServiceInfo 927 //---------------------------------------------------------------------- 928 OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException ) 929 { 930 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxDrawPage")); 931 } 932 933 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName ) 934 throw(::com::sun::star::uno::RuntimeException) 935 { 936 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); 937 } 938 939 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException ) 940 { 941 uno::Sequence< OUString > aSeq( 1 ); 942 aSeq.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection" )); 943 return aSeq; 944 } 945 946 SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor ) throw() 947 { 948 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor ); 949 } 950 951 void SvxDrawPage::ChangeModel( SdrModel* pNewModel ) 952 { 953 if( pNewModel != mpModel ) 954 { 955 if( mpModel ) 956 EndListening( *mpModel ); 957 958 if( pNewModel ) 959 StartListening( *pNewModel ); 960 961 mpModel = pNewModel; 962 963 if( mpView ) 964 { 965 delete mpView; 966 mpView = new SdrView( mpModel ); 967 if( mpView ) 968 mpView->SetDesignMode(sal_True); 969 } 970 } 971 } 972 973 /** returns a StarOffice API wrapper for the given SdrPage */ 974 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw () 975 { 976 if(pPage) 977 { 978 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY ); 979 980 return xDrawPage; 981 } 982 983 return uno::Reference< drawing::XDrawPage >(); 984 } 985 986 /** returns the SdrObject from the given StarOffice API wrapper */ 987 SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw() 988 { 989 if(xDrawPage.is()) 990 { 991 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage ); 992 993 if(pDrawPage) 994 { 995 return pDrawPage->GetSdrPage(); 996 } 997 } 998 999 return NULL; 1000 } 1001 1002 // eof 1003