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_sd.hxx" 26 27 #include "fuinsert.hxx" 28 29 #include <comphelper/storagehelper.hxx> 30 #include <comphelper/processfactory.hxx> 31 #include <toolkit/helper/vclunohelper.hxx> 32 #include <svx/svxdlg.hxx> 33 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 34 #include <com/sun/star/embed/Aspects.hpp> 35 #include <com/sun/star/beans/XPropertySet.hpp> 36 #include <com/sun/star/chart2/XChartDocument.hpp> 37 #include <com/sun/star/drawing/FillStyle.hpp> 38 39 #include <tools/urlobj.hxx> 40 #include <svl/urihelper.hxx> 41 #include <sfx2/msgpool.hxx> 42 #include <svtools/sores.hxx> 43 #include <svtools/insdlg.hxx> 44 #include <sfx2/request.hxx> 45 #include <svl/globalnameitem.hxx> 46 #include <unotools/pathoptions.hxx> 47 #include <svx/pfiledlg.hxx> 48 #include <svx/dialogs.hrc> 49 #include <sfx2/linkmgr.hxx> 50 #include <svx/svdetc.hxx> 51 #include <avmedia/mediawindow.hxx> 52 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX 53 #include <unotools/ucbstreamhelper.hxx> 54 #endif 55 #include <sfx2/printer.hxx> 56 #include <sot/clsids.hxx> 57 #include <svtools/sfxecode.hxx> 58 #include <svtools/transfer.hxx> 59 #include <svl/urlbmk.hxx> 60 #include <svx/svdobj.hxx> 61 #include <svx/svdograf.hxx> 62 #include <svx/svdoole2.hxx> 63 #include <svx/svdomedia.hxx> 64 #ifndef _EDITENG_HXX //autogen 65 #include <editeng/editeng.hxx> 66 #endif 67 #include <sot/storage.hxx> 68 #include <sot/formats.hxx> 69 #include <svx/svdpagv.hxx> 70 #ifndef _MSGBOX_HXX //autogen 71 #include <vcl/msgbox.hxx> 72 #endif 73 #include <sfx2/opengrf.hxx> 74 #include <sfx2/viewfrm.hxx> 75 #include <svx/charthelper.hxx> 76 77 #include "app.hrc" 78 #include "misc.hxx" 79 #include "sdresid.hxx" 80 #include "View.hxx" 81 #include "app.hxx" 82 #include "Window.hxx" 83 #include "drawview.hxx" 84 #include "DrawViewShell.hxx" 85 #include "DrawDocShell.hxx" 86 #include "GraphicDocShell.hxx" 87 #include "strings.hrc" 88 #include "drawdoc.hxx" 89 #include "sdgrffilter.hxx" 90 #include "sdxfer.hxx" 91 #include <vcl/svapp.hxx> 92 #include "undo/undoobjects.hxx" 93 #include "glob.hrc" 94 95 using namespace com::sun::star; 96 97 namespace sd { 98 99 TYPEINIT1( FuInsertGraphic, FuPoor ); 100 TYPEINIT1( FuInsertClipboard, FuPoor ); 101 TYPEINIT1( FuInsertOLE, FuPoor ); 102 TYPEINIT1( FuInsertAVMedia, FuPoor ); 103 104 /************************************************************************* 105 |* 106 |* FuInsertGraphic::Konstruktor 107 |* 108 \************************************************************************/ 109 110 FuInsertGraphic::FuInsertGraphic ( 111 ViewShell* pViewSh, 112 ::sd::Window* pWin, 113 ::sd::View* pView, 114 SdDrawDocument* pDoc, 115 SfxRequest& rReq) 116 : FuPoor(pViewSh, pWin, pView, pDoc, rReq) 117 { 118 } 119 120 FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 121 { 122 FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) ); 123 xFunc->DoExecute(rReq); 124 return xFunc; 125 } 126 127 #ifdef _MSC_VER 128 #pragma optimize ( "", off ) 129 #endif 130 131 void FuInsertGraphic::DoExecute( SfxRequest& ) 132 { 133 SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC)); 134 135 if( aDlg.Execute() == GRFILTER_OK ) 136 { 137 Graphic aGraphic; 138 int nError = aDlg.GetGraphic(aGraphic); 139 if( nError == GRFILTER_OK ) 140 { 141 if( mpViewShell && mpViewShell->ISA(DrawViewShell)) 142 { 143 sal_Int8 nAction = DND_ACTION_COPY; 144 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ); 145 bool bSelectionReplaced(false); 146 147 if( pPickObj ) 148 { 149 nAction = DND_ACTION_LINK; 150 } 151 else if(1 == mpView->GetMarkedObjectCount()) 152 { 153 pPickObj = mpView->GetMarkedObjectByIndex(0); 154 nAction = DND_ACTION_MOVE; 155 bSelectionReplaced = true; 156 } 157 158 Point aPos; 159 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() ); 160 aPos = aRect.Center(); 161 aPos = mpWindow->PixelToLogic(aPos); 162 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL); 163 164 if(pGrafObj && aDlg.IsAsLink()) 165 { 166 // store link only? 167 String aFltName(aDlg.GetCurrentFilter()); 168 String aPath(aDlg.GetPath()); 169 pGrafObj->SetGraphicLink(aPath, aFltName); 170 } 171 172 if(bSelectionReplaced && pGrafObj) 173 { 174 mpView->MarkObj(pGrafObj, mpView->GetSdrPageView()); 175 } 176 } 177 } 178 else 179 { 180 SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter()->GetLastError().nStreamError ); 181 } 182 } 183 } 184 185 #ifdef _MSC_VER 186 #pragma optimize ( "", on ) 187 #endif 188 189 /************************************************************************* 190 |* 191 |* FuInsertClipboard::Konstruktor 192 |* 193 \************************************************************************/ 194 195 FuInsertClipboard::FuInsertClipboard ( 196 ViewShell* pViewSh, 197 ::sd::Window* pWin, 198 ::sd::View* pView, 199 SdDrawDocument* pDoc, 200 SfxRequest& rReq) 201 : FuPoor(pViewSh, pWin, pView, pDoc, rReq) 202 { 203 } 204 205 FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 206 { 207 FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) ); 208 xFunc->DoExecute(rReq); 209 return xFunc; 210 } 211 212 void FuInsertClipboard::DoExecute( SfxRequest& ) 213 { 214 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) ); 215 sal_uLong nFormatId; 216 217 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 218 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() ); 219 if ( pDlg ) 220 { 221 const String aEmptyString; 222 ::com::sun::star::datatransfer::DataFlavor aFlavor; 223 224 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString ); 225 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString ); 226 pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString ); 227 pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString ); 228 pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString ); 229 pDlg->Insert( FORMAT_BITMAP, aEmptyString ); 230 pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString ); 231 pDlg->Insert( FORMAT_STRING, aEmptyString ); 232 pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString ); 233 pDlg->Insert( FORMAT_RTF, aEmptyString ); 234 pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString ); 235 236 //TODO/MBA: testing 237 nFormatId = pDlg->GetFormat( aDataHelper ); 238 if( nFormatId && aDataHelper.GetTransferable().is() ) 239 { 240 sal_Int8 nAction = DND_ACTION_COPY; 241 242 if( !mpView->InsertData( aDataHelper, 243 mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ), 244 nAction, sal_False, nFormatId ) && 245 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) ) 246 { 247 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell); 248 INetBookmark aINetBookmark( aEmptyStr, aEmptyStr ); 249 250 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) && 251 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) || 252 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) && 253 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) || 254 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) && 255 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) ) 256 { 257 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL ); 258 } 259 } 260 } 261 262 delete pDlg; 263 } 264 } 265 266 267 /************************************************************************* 268 |* 269 |* FuInsertOLE::Konstruktor 270 |* 271 \************************************************************************/ 272 273 FuInsertOLE::FuInsertOLE ( 274 ViewShell* pViewSh, 275 ::sd::Window* pWin, 276 ::sd::View* pView, 277 SdDrawDocument* pDoc, 278 SfxRequest& rReq) 279 : FuPoor(pViewSh, pWin, pView, pDoc, rReq) 280 { 281 } 282 283 FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 284 { 285 FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) ); 286 xFunc->DoExecute(rReq); 287 return xFunc; 288 } 289 290 void FuInsertOLE::DoExecute( SfxRequest& rReq ) 291 { 292 if ( nSlotId == SID_ATTR_TABLE || 293 nSlotId == SID_INSERT_DIAGRAM || 294 nSlotId == SID_INSERT_MATH ) 295 { 296 PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT; 297 298 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind ); 299 300 /********************************************************************** 301 * Diagramm oder StarCalc-Tabelle einfuegen 302 **********************************************************************/ 303 304 ::rtl::OUString aObjName; 305 SvGlobalName aName; 306 if (nSlotId == SID_INSERT_DIAGRAM) 307 aName = SvGlobalName( SO3_SCH_CLASSID); 308 else if (nSlotId == SID_ATTR_TABLE) 309 aName = SvGlobalName(SO3_SC_CLASSID); 310 else if (nSlotId == SID_INSERT_MATH) 311 aName = SvGlobalName(SO3_SM_CLASSID); 312 313 uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()-> 314 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName ); 315 if ( xObj.is() ) 316 { 317 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; 318 319 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ); 320 321 Rectangle aRect; 322 if( pPickObj ) 323 { 324 aRect = pPickObj->GetLogicRect(); 325 326 awt::Size aSz; 327 aSz.Width = aRect.GetWidth(); 328 aSz.Height = aRect.GetHeight(); 329 xObj->setVisualAreaSize( nAspect, aSz ); 330 } 331 else 332 { 333 awt::Size aSz; 334 try 335 { 336 aSz = xObj->getVisualAreaSize( nAspect ); 337 } 338 catch ( embed::NoVisualAreaSizeException& ) 339 { 340 // the default size will be set later 341 } 342 343 Size aSize( aSz.Width, aSz.Height ); 344 345 if (aSize.Height() == 0 || aSize.Width() == 0) 346 { 347 // Rechteck mit ausgewogenem Kantenverhaeltnis 348 aSize.Width() = 14100; 349 aSize.Height() = 10000; 350 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit ); 351 aSz.Width = aTmp.Width(); 352 aSz.Height = aTmp.Height(); 353 xObj->setVisualAreaSize( nAspect, aSz ); 354 } 355 else 356 { 357 aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM); 358 } 359 360 Point aPos; 361 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() ); 362 aPos = aWinRect.Center(); 363 aPos = mpWindow->PixelToLogic(aPos); 364 aPos.X() -= aSize.Width() / 2; 365 aPos.Y() -= aSize.Height() / 2; 366 aRect = Rectangle(aPos, aSize); 367 } 368 369 SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect ); 370 SdrPageView* pPV = mpView->GetSdrPageView(); 371 372 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj 373 if( pPickObj ) 374 { 375 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage()); 376 if(pPage && pPage->IsPresObj(pPickObj)) 377 { 378 pPage->InsertPresObj( pOleObj, ePresObjKind ); 379 pOleObj->SetUserCall(pPickObj->GetUserCall()); 380 } 381 } 382 383 bool bRet = true; 384 if( pPickObj ) 385 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True ); 386 else 387 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER); 388 389 if( bRet ) 390 { 391 if (nSlotId == SID_INSERT_DIAGRAM) 392 { 393 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarChart" ) ) ); 394 } 395 else if (nSlotId == SID_ATTR_TABLE) 396 { 397 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarCalc" ) ) ); 398 } 399 else if (nSlotId == SID_INSERT_MATH) 400 { 401 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) ) ); 402 } 403 404 //HMHmpView->HideMarkHdl(); 405 pOleObj->SetLogicRect(aRect); 406 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) ); 407 awt::Size aVisualSize; 408 aVisualSize.Width = aTmp.Width(); 409 aVisualSize.Height = aTmp.Height(); 410 xObj->setVisualAreaSize( nAspect, aVisualSize ); 411 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW); 412 413 if (nSlotId == SID_INSERT_DIAGRAM) 414 { 415 // note, that this call modified the chart model which 416 // results in a change notification. So call this after 417 // everything else is finished. 418 ChartHelper::AdaptDefaultsForChart( xObj ); 419 } 420 } 421 } 422 else 423 { 424 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL, 425 aEmptyStr ) ); 426 } 427 } 428 else 429 { 430 /********************************************************************** 431 * Objekt einfuegen 432 **********************************************************************/ 433 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; 434 sal_Bool bCreateNew = sal_False; 435 uno::Reference < embed::XEmbeddedObject > xObj; 436 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); 437 SvObjectServerList aServerLst; 438 ::rtl::OUString aName; 439 440 ::rtl::OUString aIconMediaType; 441 uno::Reference< io::XInputStream > xIconMetaFile; 442 443 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False ); 444 if ( nSlotId == SID_INSERT_OBJECT && pNameItem ) 445 { 446 SvGlobalName aClassName = pNameItem->GetValue(); 447 xObj = mpViewShell->GetViewFrame()->GetObjectShell()-> 448 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName ); 449 } 450 else 451 { 452 switch ( nSlotId ) 453 { 454 case SID_INSERT_OBJECT : 455 { 456 aServerLst.FillInsertObjects(); 457 if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) 458 { 459 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() ); 460 } 461 else 462 { 463 aServerLst.Remove( DrawDocShell::Factory().GetClassId() ); 464 } 465 466 // intentionally no break! 467 } 468 case SID_INSERT_PLUGIN : 469 case SID_INSERT_FLOATINGFRAME : 470 { 471 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 472 SfxAbstractInsertObjectDialog* pDlg = 473 pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(), 474 xStorage, &aServerLst ); 475 if ( pDlg ) 476 { 477 pDlg->Execute(); 478 bCreateNew = pDlg->IsCreateNew(); 479 xObj = pDlg->GetObject(); 480 481 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType ); 482 if ( xIconMetaFile.is() ) 483 nAspect = embed::Aspects::MSOLE_ICON; 484 485 if ( xObj.is() ) 486 mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName ); 487 DELETEZ( pDlg ); 488 } 489 490 break; 491 } 492 case SID_INSERT_SOUND : 493 case SID_INSERT_VIDEO : 494 { 495 // create special filedialog for plugins 496 SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId); 497 if( ERRCODE_NONE == aPluginFileDialog.Execute () ) 498 { 499 // get URL 500 String aStrURL(aPluginFileDialog.GetPath()); 501 INetURLObject aURL( aStrURL, INET_PROT_FILE ); 502 if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) 503 { 504 // create a plugin object 505 xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName ); 506 } 507 508 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) ) 509 { 510 // set properties from dialog 511 uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY ); 512 if ( xSup.is() ) 513 { 514 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY ); 515 if ( xSet.is() ) 516 { 517 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"), 518 uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) ); 519 } 520 } 521 } 522 else 523 { 524 // PlugIn konnte nicht erzeugt werden 525 String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) ); 526 String aMask; 527 aMask += sal_Unicode('%'); 528 aStrErr.SearchAndReplace( aMask, aStrURL ); 529 ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute(); 530 } 531 } 532 } 533 } 534 } 535 536 try 537 { 538 if (xObj.is()) 539 { 540 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE 541 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) ) 542 // aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) ); 543 544 sal_Bool bInsertNewObject = sal_True; 545 546 Size aSize; 547 MapUnit aMapUnit = MAP_100TH_MM; 548 if ( nAspect != embed::Aspects::MSOLE_ICON ) 549 { 550 awt::Size aSz; 551 try 552 { 553 aSz = xObj->getVisualAreaSize( nAspect ); 554 } 555 catch( embed::NoVisualAreaSizeException& ) 556 { 557 // the default size will be set later 558 } 559 560 aSize =Size( aSz.Width, aSz.Height ); 561 562 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ); 563 if (aSize.Height() == 0 || aSize.Width() == 0) 564 { 565 // Rechteck mit ausgewogenem Kantenverhaeltnis 566 aSize.Width() = 14100; 567 aSize.Height() = 10000; 568 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit ); 569 aSz.Width = aTmp.Width(); 570 aSz.Height = aTmp.Height(); 571 xObj->setVisualAreaSize( nAspect, aSz ); 572 } 573 else 574 { 575 aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM); 576 } 577 } 578 579 if ( mpView->AreObjectsMarked() ) 580 { 581 /********************************************************** 582 * Ist ein leeres OLE-Objekt vorhanden? 583 **********************************************************/ 584 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); 585 586 if (rMarkList.GetMarkCount() == 1) 587 { 588 SdrMark* pMark = rMarkList.GetMark(0); 589 SdrObject* pObj = pMark->GetMarkedSdrObj(); 590 591 if (pObj->GetObjInventor() == SdrInventor && 592 pObj->GetObjIdentifier() == OBJ_OLE2) 593 { 594 if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() ) 595 { 596 /************************************************** 597 * Das leere OLE-Objekt bekommt ein neues IPObj 598 **************************************************/ 599 bInsertNewObject = sal_False; 600 pObj->SetEmptyPresObj(sal_False); 601 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL); 602 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj); 603 ( (SdrOle2Obj*) pObj)->SetPersistName(aName); 604 ( (SdrOle2Obj*) pObj)->SetName(aName); 605 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect); 606 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect(); 607 608 //HMHmpView->HideMarkHdl(); 609 610 if ( nAspect == embed::Aspects::MSOLE_ICON ) 611 { 612 if( xIconMetaFile.is() ) 613 ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType ); 614 } 615 else 616 { 617 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit ); 618 awt::Size aSz( aTmp.Width(), aTmp.Height() ); 619 xObj->setVisualAreaSize( nAspect, aSz ); 620 } 621 } 622 } 623 } 624 } 625 626 if (bInsertNewObject) 627 { 628 /************************************************************** 629 * Ein neues OLE-Objekt wird erzeugt 630 **************************************************************/ 631 SdrPageView* pPV = mpView->GetSdrPageView(); 632 Size aPageSize = pPV->GetPage()->GetSize(); 633 634 // get the size from the iconified object 635 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect ); 636 if ( nAspect == embed::Aspects::MSOLE_ICON ) 637 { 638 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType ); 639 MapMode aMapMode( MAP_100TH_MM ); 640 aSize = aObjRef.GetSize( &aMapMode ); 641 } 642 643 Point aPnt ((aPageSize.Width() - aSize.Width()) / 2, 644 (aPageSize.Height() - aSize.Height()) / 2); 645 Rectangle aRect (aPnt, aSize); 646 647 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect); 648 649 if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) ) 650 { 651 // #73279# Math objects change their object size during InsertObject. 652 // New size must be set in SdrObject, or a wrong scale will be set at 653 // ActivateObject. 654 655 if ( nAspect != embed::Aspects::MSOLE_ICON ) 656 { 657 try 658 { 659 awt::Size aSz = xObj->getVisualAreaSize( nAspect ); 660 661 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ), 662 MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) ); 663 if ( aNewSize != aSize ) 664 { 665 aRect.SetSize( aNewSize ); 666 pObj->SetLogicRect( aRect ); 667 } 668 } 669 catch( embed::NoVisualAreaSizeException& ) 670 {} 671 } 672 673 if (bCreateNew) 674 { 675 //HMHmpView->HideMarkHdl(); 676 pObj->SetLogicRect(aRect); 677 678 if ( nAspect != embed::Aspects::MSOLE_ICON ) 679 { 680 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit ); 681 awt::Size aSz( aTmp.Width(), aTmp.Height() ); 682 xObj->setVisualAreaSize( nAspect, aSz ); 683 } 684 685 mpViewShell->ActivateObject(pObj, SVVERB_SHOW); 686 } 687 688 Size aVisSizePixel = mpWindow->GetOutputSizePixel(); 689 Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) ); 690 mpViewShell->VisAreaChanged(aVisAreaWin); 691 mpDocSh->SetVisArea(aVisAreaWin); 692 } 693 } 694 } 695 } 696 catch (uno::Exception&) 697 { 698 // For some reason the object can not be inserted. For example 699 // because it is password protected and is not properly unlocked. 700 } 701 } 702 } 703 704 705 /************************************************************************* 706 |* 707 |* FuInsertAVMedia::Konstruktor 708 |* 709 \************************************************************************/ 710 711 FuInsertAVMedia::FuInsertAVMedia( 712 ViewShell* pViewSh, 713 ::sd::Window* pWin, 714 ::sd::View* pView, 715 SdDrawDocument* pDoc, 716 SfxRequest& rReq) 717 : FuPoor(pViewSh, pWin, pView, pDoc, rReq) 718 { 719 } 720 721 FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 722 { 723 FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) ); 724 xFunc->DoExecute(rReq); 725 return xFunc; 726 } 727 728 void FuInsertAVMedia::DoExecute( SfxRequest& rReq ) 729 { 730 ::rtl::OUString aURL; 731 const SfxItemSet* pReqArgs = rReq.GetArgs(); 732 bool bAPI = false; 733 734 if( pReqArgs ) 735 { 736 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) ); 737 738 if( pStringItem ) 739 { 740 aURL = pStringItem->GetValue(); 741 bAPI = aURL.getLength(); 742 } 743 } 744 745 if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow, aURL ) ) 746 { 747 Size aPrefSize; 748 749 if( mpWindow ) 750 mpWindow->EnterWait(); 751 752 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) ) 753 { 754 if( mpWindow ) 755 mpWindow->LeaveWait(); 756 757 if( !bAPI ) 758 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow ); 759 } 760 else 761 { 762 Point aPos; 763 Size aSize; 764 sal_Int8 nAction = DND_ACTION_COPY; 765 766 if( aPrefSize.Width() && aPrefSize.Height() ) 767 { 768 if( mpWindow ) 769 aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM ); 770 else 771 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM ); 772 } 773 else 774 aSize = Size( 5000, 5000 ); 775 776 if( mpWindow ) 777 { 778 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() ); 779 aPos.X() -= aSize.Width() >> 1; 780 aPos.Y() -= aSize.Height() >> 1; 781 } 782 783 mpView->InsertMediaURL( aURL, nAction, aPos, aSize ) ; 784 785 if( mpWindow ) 786 mpWindow->LeaveWait(); 787 } 788 } 789 } 790 791 } // end of namespace sd 792