1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 33 #include <com/sun/star/embed/Aspects.hpp> 34 #include <com/sun/star/beans/XPropertySet.hpp> 35 36 //------------------------------------------------------------------------ 37 38 #include <toolkit/helper/vclunohelper.hxx> 39 #include <sot/exchange.hxx> 40 #include <svl/globalnameitem.hxx> 41 #include <sfx2/viewfrm.hxx> 42 #include <sfx2/docfile.hxx> 43 #include <svl/stritem.hxx> 44 #include <svx/svdoole2.hxx> 45 #include <svx/pfiledlg.hxx> 46 #include <tools/urlobj.hxx> 47 #include <vcl/msgbox.hxx> 48 #include <svl/urihelper.hxx> 49 #include <unotools/moduleoptions.hxx> 50 #include <svtools/insdlg.hxx> 51 #include <svtools/soerr.hxx> 52 #include <svx/svxdlg.hxx> 53 #include <sot/clsids.hxx> 54 #include <svx/svdpagv.hxx> 55 #include <svx/svdpage.hxx> 56 #include <svx/svdundo.hxx> 57 #include <sfx2/msgpool.hxx> 58 #include <scmod.hxx> 59 60 // BM/IHA -- 61 #include <cppuhelper/component_context.hxx> 62 #include <comphelper/processfactory.hxx> 63 #include <comphelper/storagehelper.hxx> 64 #include <com/sun/star/beans/XPropertySet.hpp> 65 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp> 66 #include <com/sun/star/frame/XComponentLoader.hpp> 67 #include <com/sun/star/beans/PropertyValue.hpp> 68 #include <com/sun/star/chart2/data/XDataProvider.hpp> 69 #include <com/sun/star/chart2/data/XDataReceiver.hpp> 70 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 71 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 72 #include <com/sun/star/lang/XInitialization.hpp> 73 #include <com/sun/star/frame/XModel.hpp> 74 #include <com/sun/star/chart/ChartDataRowSource.hpp> 75 #include <cppuhelper/bootstrap.hxx> 76 77 using namespace ::com::sun::star; 78 // BM/IHA -- 79 80 // erAck 81 #include "chart2uno.hxx" 82 // erAck 83 84 #include "fuinsert.hxx" 85 #include "tabvwsh.hxx" 86 #include "sc.hrc" 87 #include "chartarr.hxx" 88 #include "docsh.hxx" 89 #include "document.hxx" 90 #include "undotab.hxx" 91 #include "chartlis.hxx" 92 #include "uiitems.hxx" 93 #include "globstr.hrc" 94 #include "drawview.hxx" 95 96 extern SdrObject* pSkipPaintObj; // output.cxx - dieses Objekt nicht zeichnen 97 98 //------------------------------------------------------------------------ 99 100 #define IS_AVAILABLE(WhichId,ppItem) \ 101 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET) 102 103 void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData, 104 const rtl::OUString& rRangeParam ) 105 { 106 ScDocShell* pDocShell = pViewData->GetDocShell(); 107 ScDocument* pScDoc = pDocShell->GetDocument(); 108 109 rtl::OUString aRangeString( rRangeParam ); 110 if ( !aRangeString.getLength() ) 111 { 112 SCCOL nCol1 = 0; 113 SCROW nRow1 = 0; 114 SCTAB nTab1 = 0; 115 SCCOL nCol2 = 0; 116 SCROW nRow2 = 0; 117 SCTAB nTab2 = 0; 118 119 ScMarkData& rMark = pViewData->GetMarkData(); 120 if ( !rMark.IsMarked() ) 121 pViewData->GetView()->MarkDataArea( sal_True ); 122 123 if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE ) 124 { 125 PutInOrder( nCol1, nCol2 ); 126 PutInOrder( nRow1, nRow2 ); 127 if ( nCol2>nCol1 || nRow2>nRow1 ) 128 { 129 ScDocument* pDoc = pViewData->GetDocument(); 130 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 ); 131 132 String aStr; 133 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); 134 aRange.Format( aStr, SCR_ABS_3D, pScDoc ); 135 aRangeString = aStr; 136 } 137 } 138 } 139 140 if ( aRangeString.getLength() ) 141 { 142 // connect to Calc data (if no range string, leave chart alone, with its own data) 143 144 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver; 145 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY ); 146 if( xCompSupp.is()) 147 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY ); 148 OSL_ASSERT( xReceiver.is()); 149 if( xReceiver.is() ) 150 { 151 uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( pScDoc ); 152 xReceiver->attachDataProvider( xDataProvider ); 153 154 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY ); 155 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier ); 156 157 // Same behavior as with old chart: Always assume data series in columns 158 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; 159 bool bHasCategories = false; 160 bool bFirstCellAsLabel = false; 161 162 // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version) 163 ScRangeListRef aRangeListRef( new ScRangeList ); 164 aRangeListRef->Parse( aRangeString, pScDoc ); 165 if ( aRangeListRef->Count() ) 166 { 167 pScDoc->LimitChartIfAll( aRangeListRef ); // limit whole columns/rows to used area 168 169 // update string from modified ranges. The ranges must be in the current formula syntax. 170 String aTmpStr; 171 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, pScDoc, pScDoc->GetAddressConvention() ); 172 aRangeString = aTmpStr; 173 174 ScChartPositioner aChartPositioner( pScDoc, aRangeListRef ); 175 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() ); 176 if( pPositionMap ) 177 { 178 SCSIZE nRowCount = pPositionMap->GetRowCount(); 179 if( 1==nRowCount ) 180 eDataRowSource = chart::ChartDataRowSource_ROWS; 181 } 182 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) 183 { 184 bHasCategories = aChartPositioner.HasRowHeaders(); 185 bFirstCellAsLabel = aChartPositioner.HasColHeaders(); 186 } 187 else // in case the default is changed 188 { 189 bHasCategories = aChartPositioner.HasColHeaders(); 190 bFirstCellAsLabel = aChartPositioner.HasRowHeaders(); 191 } 192 } 193 194 uno::Sequence< beans::PropertyValue > aArgs( 4 ); 195 aArgs[0] = beans::PropertyValue( 196 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1, 197 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE ); 198 aArgs[1] = beans::PropertyValue( 199 ::rtl::OUString::createFromAscii("HasCategories"), -1, 200 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE ); 201 aArgs[2] = beans::PropertyValue( 202 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1, 203 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE ); 204 aArgs[3] = beans::PropertyValue( 205 ::rtl::OUString::createFromAscii("DataRowSource"), -1, 206 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE ); 207 xReceiver->setArguments( aArgs ); 208 209 // don't create chart listener here (range may be modified in chart dialog) 210 } 211 } 212 } 213 214 /************************************************************************* 215 |* 216 |* FuInsertOLE::Konstruktor 217 |* 218 \************************************************************************/ 219 220 FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, 221 SdrModel* pDoc, SfxRequest& rReq) 222 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq) 223 { 224 if( ! rReq.IsAPI() ) 225 rReq.Done(); 226 227 //! hier DLL's initalisieren, damit die Factories existieren? 228 229 uno::Reference < embed::XEmbeddedObject > xObj; 230 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); 231 sal_Bool bIsFromFile = sal_False; 232 ::rtl::OUString aName; 233 234 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; 235 ::rtl::OUString aIconMediaType; 236 uno::Reference< io::XInputStream > xIconMetaFile; 237 238 239 sal_uInt16 nSlot = rReq.GetSlot(); 240 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False ); 241 if ( nSlot == SID_INSERT_OBJECT && pNameItem ) 242 { 243 SvGlobalName aClassName = pNameItem->GetValue(); 244 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName ); 245 } 246 else if ( nSlot == SID_INSERT_SMATH ) 247 { 248 if ( SvtModuleOptions().IsMath() ) 249 { 250 nSlot = SID_INSERT_OBJECT; 251 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName ); 252 rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) ); 253 } 254 } 255 else 256 { 257 SvObjectServerList aServerLst; 258 switch ( nSlot ) 259 { 260 case SID_INSERT_OBJECT : 261 aServerLst.FillInsertObjects(); 262 aServerLst.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen 263 //TODO/LATER: currently no inserting of ClassId into SfxRequest! 264 case SID_INSERT_PLUGIN : 265 case SID_INSERT_FLOATINGFRAME : 266 { 267 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 268 SfxAbstractInsertObjectDialog* pDlg = 269 pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(), 270 xStorage, &aServerLst ); 271 if ( pDlg ) 272 { 273 pDlg->Execute(); 274 xObj = pDlg->GetObject(); 275 276 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType ); 277 if ( xIconMetaFile.is() ) 278 nAspect = embed::Aspects::MSOLE_ICON; 279 280 if ( xObj.is() ) 281 pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName ); 282 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig): 283 bIsFromFile = !pDlg->IsCreateNew(); 284 DELETEZ( pDlg ); 285 } 286 287 break; 288 } 289 case SID_INSERT_SOUND : 290 case SID_INSERT_VIDEO : 291 { 292 // create special filedialog for plugins 293 SvxPluginFileDlg aPluginFileDialog(pWin, nSlot); 294 295 // open filedlg 296 if ( ERRCODE_NONE == aPluginFileDialog.Execute() ) 297 { 298 // get URL 299 INetURLObject aURL; 300 aURL.SetSmartProtocol( INET_PROT_FILE ); 301 if ( aURL.SetURL( aPluginFileDialog.GetPath() ) ) 302 { 303 // create a plugin object 304 ::rtl::OUString aObjName; 305 SvGlobalName aClassId( SO3_PLUGIN_CLASSID ); 306 comphelper::EmbeddedObjectContainer aCnt( xStorage ); 307 xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aObjName ); 308 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) ) 309 { 310 // set properties from dialog 311 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY ); 312 if ( xSet.is() ) 313 { 314 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"), 315 uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) ); 316 } 317 } 318 } 319 else 320 { 321 DBG_ERROR("Invalid URL!"); 322 //! error message 323 //! can this happen??? 324 } 325 } 326 } 327 } 328 } 329 330 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt 331 if (xObj.is()) 332 { 333 pView->UnmarkAll(); 334 335 try 336 { 337 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect ); 338 Size aSize; 339 MapMode aMap100( MAP_100TH_MM ); 340 MapUnit aMapUnit = MAP_100TH_MM; 341 342 if ( nAspect == embed::Aspects::MSOLE_ICON ) 343 { 344 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType ); 345 aSize = aObjRef.GetSize( &aMap100 ); 346 } 347 else 348 { 349 awt::Size aSz; 350 try 351 { 352 aSz = xObj->getVisualAreaSize( nAspect ); 353 } 354 catch( embed::NoVisualAreaSizeException& ) 355 { 356 // the default size will be set later 357 } 358 359 aSize = Size( aSz.Width, aSz.Height ); 360 361 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ); 362 if (aSize.Height() == 0 || aSize.Width() == 0) 363 { 364 // Rechteck mit ausgewogenem Kantenverhaeltnis 365 aSize.Width() = 5000; 366 aSize.Height() = 5000; 367 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit ); 368 aSz.Width = aTmp.Width(); 369 aSz.Height = aTmp.Height(); 370 xObj->setVisualAreaSize( nAspect, aSz ); 371 372 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below 373 aSize = Window::LogicToLogic( aTmp, 374 MapMode( aMapUnit ), aMap100 ); 375 } 376 else 377 aSize = Window::LogicToLogic( aSize, 378 MapMode( aMapUnit ), aMap100 ); 379 } 380 381 // Chart initialisieren ? 382 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) ) 383 lcl_ChartInit( xObj, pViewSh->GetViewData(), rtl::OUString() ); 384 385 ScViewData* pData = pViewSh->GetViewData(); 386 387 Point aPnt = pViewSh->GetInsertPos(); 388 if ( pData->GetDocument()->IsNegativePage( pData->GetTabNo() ) ) 389 aPnt.X() -= aSize.Width(); // move position to left edge 390 Rectangle aRect (aPnt, aSize); 391 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect); 392 393 // Dieses Objekt nicht vor dem Aktivieren zeichnen 394 // (in MarkListHasChanged kommt ein Update) 395 if (!bIsFromFile) 396 pSkipPaintObj = pObj; 397 398 SdrPageView* pPV = pView->GetSdrPageView(); 399 pView->InsertObjectAtView(pObj, *pPV); 400 401 if ( nAspect != embed::Aspects::MSOLE_ICON ) 402 { 403 // #73279# Math objects change their object size during InsertObject. 404 // New size must be set in SdrObject, or a wrong scale will be set at 405 // ActivateObject. 406 407 try 408 { 409 awt::Size aSz = xObj->getVisualAreaSize( nAspect ); 410 411 Size aNewSize( aSz.Width, aSz.Height ); 412 aNewSize = OutputDevice::LogicToLogic( aNewSize, aMapUnit, MAP_100TH_MM ); 413 414 if ( aNewSize != aSize ) 415 { 416 aRect.SetSize( aNewSize ); 417 pObj->SetLogicRect( aRect ); 418 } 419 } 420 catch( embed::NoVisualAreaSizeException& ) 421 {} 422 } 423 424 if ( !rReq.IsAPI() ) 425 { 426 // XXX Activate aus Makro ist toedlich !!! ??? 427 if (bIsFromFile) 428 { 429 // #45012# Objekt ist selektiert, also Draw-Shell aktivieren 430 pViewShell->SetDrawShell( sal_True ); 431 } 432 else 433 { 434 pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW ); 435 pSkipPaintObj = NULL; 436 } 437 } 438 439 rReq.Done(); 440 } 441 catch( uno::Exception& ) 442 { 443 OSL_ASSERT( "May need error handling here!\n" ); 444 } 445 } 446 else 447 rReq.Ignore(); 448 } 449 450 /************************************************************************* 451 |* 452 |* FuInsertOLE::Destruktor 453 |* 454 \************************************************************************/ 455 456 FuInsertOLE::~FuInsertOLE() 457 { 458 } 459 460 /************************************************************************* 461 |* 462 |* FuInsertOLE::Function aktivieren 463 |* 464 \************************************************************************/ 465 466 void FuInsertOLE::Activate() 467 { 468 FuPoor::Activate(); 469 } 470 471 /************************************************************************* 472 |* 473 |* FuInsertOLE::Function deaktivieren 474 |* 475 \************************************************************************/ 476 477 void FuInsertOLE::Deactivate() 478 { 479 FuPoor::Deactivate(); 480 } 481 482 /************************************************************************* 483 |* 484 |* FuInsertChart::Konstruktor 485 |* 486 \************************************************************************/ 487 488 FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, 489 SdrModel* pDoc, SfxRequest& rReq) 490 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq) 491 { 492 const SfxItemSet* pReqArgs = rReq.GetArgs(); 493 494 if( ! rReq.IsAPI() ) 495 rReq.Done(); 496 497 if( SvtModuleOptions().IsChart() ) 498 { 499 // ---------------------------------------- 500 // BM/IHA -- 501 502 // get range 503 ::rtl::OUString aRangeString; 504 ScRange aPositionRange; // cell range for chart positioning 505 if( pReqArgs ) 506 { 507 const SfxPoolItem* pItem; 508 if( IS_AVAILABLE( FN_PARAM_5, &pItem ) ) 509 aRangeString = ::rtl::OUString( ((const SfxStringItem*)pItem)->GetValue()); 510 511 aPositionRange = pViewSh->GetViewData()->GetCurPos(); 512 } 513 else 514 { 515 ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData(); 516 bool bAutomaticMark = false; 517 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() ) 518 { 519 pViewSh->GetViewData()->GetView()->MarkDataArea( sal_True ); 520 bAutomaticMark = true; 521 } 522 523 ScMarkData aMultiMark( rMark ); 524 aMultiMark.MarkToMulti(); 525 526 ScRangeList aRanges; 527 aMultiMark.FillRangeListWithMarks( &aRanges, sal_False ); 528 String aStr; 529 ScDocument* pDocument = pViewSh->GetViewData()->GetDocument(); 530 aRanges.Format( aStr, SCR_ABS_3D, pDocument, pDocument->GetAddressConvention() ); 531 aRangeString = aStr; 532 533 // get "total" range for positioning 534 sal_uLong nCount = aRanges.Count(); 535 if ( nCount > 0 ) 536 { 537 aPositionRange = *aRanges.GetObject(0); 538 for (sal_uLong i=1; i<nCount; i++) 539 aPositionRange.ExtendTo( *aRanges.GetObject(i) ); 540 } 541 542 if(bAutomaticMark) 543 pViewSh->GetViewData()->GetView()->Unmark(); 544 } 545 546 // ---------------------------------------- 547 // adapted old code 548 pView->UnmarkAll(); 549 550 ::rtl::OUString aName; 551 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; 552 553 uno::Reference < embed::XEmbeddedObject > xObj = 554 pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName ); 555 556 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver; 557 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY ); 558 if( xCompSupp.is()) 559 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY ); 560 561 // lock the model to suppress any internal updates 562 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY ); 563 if( xChartModel.is() ) 564 xChartModel->lockControllers(); 565 566 ScRangeListRef aDummy; 567 Rectangle aMarkDest; 568 SCTAB nMarkTab; 569 sal_Bool bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab ); 570 571 // Objekt-Groesse 572 awt::Size aSz = xObj->getVisualAreaSize( nAspect ); 573 Size aSize( aSz.Width, aSz.Height ); 574 575 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ); 576 577 sal_Bool bSizeCh = sal_False; 578 if (bDrawRect && !aMarkDest.IsEmpty()) 579 { 580 aSize = aMarkDest.GetSize(); 581 bSizeCh = sal_True; 582 } 583 if (aSize.Height() <= 0 || aSize.Width() <= 0) 584 { 585 aSize.Width() = 5000; 586 aSize.Height() = 5000; 587 bSizeCh = sal_True; 588 } 589 if (bSizeCh) 590 { 591 aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) ); 592 aSz.Width = aSize.Width(); 593 aSz.Height = aSize.Height(); 594 xObj->setVisualAreaSize( nAspect, aSz ); 595 } 596 597 ScViewData* pData = pViewSh->GetViewData(); 598 ScDocShell* pScDocSh = pData->GetDocShell(); 599 ScDocument* pScDoc = pScDocSh->GetDocument(); 600 sal_Bool bUndo (pScDoc->IsUndoEnabled()); 601 602 if( pReqArgs ) 603 { 604 const SfxPoolItem* pItem; 605 sal_uInt16 nToTable = 0; 606 607 if( IS_AVAILABLE( FN_PARAM_4, &pItem ) ) 608 { 609 if ( pItem->ISA( SfxUInt16Item ) ) 610 nToTable = ((const SfxUInt16Item*)pItem)->GetValue(); 611 else if ( pItem->ISA( SfxBoolItem ) ) 612 { 613 // #46033# in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem 614 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle 615 616 if ( ((const SfxBoolItem*)pItem)->GetValue() ) 617 nToTable = static_cast<sal_uInt16>(pScDoc->GetTableCount()); 618 else 619 nToTable = static_cast<sal_uInt16>(pData->GetTabNo()); 620 } 621 } 622 else 623 { 624 if (bDrawRect) 625 nToTable = static_cast<sal_uInt16>(nMarkTab); 626 rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) ); 627 } 628 629 // auf neue Tabelle ausgeben? 630 if ( nToTable == pScDoc->GetTableCount() ) 631 { 632 // dann los... 633 String aTabName; 634 SCTAB nNewTab = pScDoc->GetTableCount(); 635 636 pScDoc->CreateValidTabName( aTabName ); 637 638 if ( pScDoc->InsertTab( nNewTab, aTabName ) ) 639 { 640 sal_Bool bAppend = sal_True; 641 642 if (bUndo) 643 { 644 pScDocSh->GetUndoManager()->AddUndoAction( 645 new ScUndoInsertTab( pScDocSh, nNewTab, 646 bAppend, aTabName ) ); 647 } 648 649 pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) ); 650 pViewSh->SetTabNo( nNewTab, sal_True ); 651 pScDocSh->PostPaintExtras(); //! erst hinterher ??? 652 } 653 else 654 { 655 DBG_ERROR( "Could not create new table :-/" ); 656 } 657 } 658 else if ( nToTable != pData->GetTabNo() ) 659 { 660 pViewSh->SetTabNo( nToTable, sal_True ); 661 } 662 } 663 664 lcl_ChartInit( xObj, pData, aRangeString ); // set source range, auto-detect column/row headers 665 666 // Objekt-Position 667 668 Point aStart; 669 if ( bDrawRect ) 670 aStart = aMarkDest.TopLeft(); // marked by hand 671 else 672 { 673 // get chart position (from window size and data range) 674 aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange ); 675 } 676 677 Rectangle aRect (aStart, aSize); 678 SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect); 679 680 // Dieses Objekt nicht vor dem Aktivieren zeichnen 681 // (in MarkListHasChanged kommt ein Update) 682 pSkipPaintObj = pObj; 683 684 SdrPageView* pPV = pView->GetSdrPageView(); 685 686 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation 687 688 // use the page instead of the view to insert, so no undo action is created yet 689 SdrPage* pInsPage = pPV->GetPage(); 690 pInsPage->InsertObject( pObj ); 691 pView->UnmarkAllObj(); 692 pView->MarkObj( pObj, pPV ); 693 bool bAddUndo = true; // add undo action later, unless the dialog is canceled 694 695 if (rReq.IsAPI()) 696 { 697 if( xChartModel.is() ) 698 xChartModel->unlockControllers(); 699 } 700 else 701 { 702 //the controller will be unlocked by the dialog when the dialog is told to do so 703 704 // only activate object if not called via API (e.g. macro) 705 pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW ); 706 707 //open wizard 708 //@todo get context from calc if that has one 709 uno::Reference< uno::XComponentContext > xContext( 710 ::cppu::defaultBootstrap_InitialComponentContext() ); 711 if(xContext.is()) 712 { 713 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() ); 714 if(xMCF.is()) 715 { 716 uno::Reference< ui::dialogs::XExecutableDialog > xDialog( 717 xMCF->createInstanceWithContext( 718 rtl::OUString::createFromAscii("com.sun.star.comp.chart2.WizardDialog") 719 , xContext), uno::UNO_QUERY); 720 uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY ); 721 if( xChartModel.is() && xInit.is() ) 722 { 723 uno::Reference< awt::XWindow > xDialogParentWindow(0); 724 // initialize dialog 725 uno::Sequence<uno::Any> aSeq(2); 726 uno::Any* pArray = aSeq.getArray(); 727 beans::PropertyValue aParam1; 728 aParam1.Name = rtl::OUString::createFromAscii("ParentWindow"); 729 aParam1.Value <<= uno::makeAny(xDialogParentWindow); 730 beans::PropertyValue aParam2; 731 aParam2.Name = rtl::OUString::createFromAscii("ChartModel"); 732 aParam2.Value <<= uno::makeAny(xChartModel); 733 pArray[0] <<= uno::makeAny(aParam1); 734 pArray[1] <<= uno::makeAny(aParam2); 735 xInit->initialize( aSeq ); 736 737 // try to set the dialog's position so it doesn't hide the chart 738 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY ); 739 if ( xDialogProps.is() ) 740 { 741 try 742 { 743 //get dialog size: 744 awt::Size aDialogAWTSize; 745 if( xDialogProps->getPropertyValue( ::rtl::OUString::createFromAscii("Size") ) 746 >>= aDialogAWTSize ) 747 { 748 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height ); 749 if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 ) 750 { 751 //calculate and set new position 752 Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect ); 753 xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("Position"), 754 uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) ); 755 } 756 } 757 //tell the dialog to unlock controller 758 xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("UnlockControllersOnExecute"), 759 uno::makeAny( sal_True ) ); 760 761 } 762 catch( uno::Exception& ) 763 { 764 OSL_ASSERT( "Chart wizard couldn't be positioned automatically\n" ); 765 } 766 } 767 768 sal_Int16 nDialogRet = xDialog->execute(); 769 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL ) 770 { 771 // leave OLE inplace mode and unmark 772 OSL_ASSERT( pViewShell ); 773 OSL_ASSERT( pView ); 774 pViewShell->DeactivateOle(); 775 pView->UnmarkAll(); 776 777 // old page view pointer is invalid after switching sheets 778 pPV = pView->GetSdrPageView(); 779 780 // remove the chart 781 OSL_ASSERT( pPV ); 782 SdrPage * pPage( pPV->GetPage()); 783 OSL_ASSERT( pPage ); 784 OSL_ASSERT( pObj ); 785 if( pPage ) 786 pPage->RemoveObject( pObj->GetOrdNum()); 787 788 bAddUndo = false; // don't create the undo action for inserting 789 790 // leave the draw shell 791 pViewShell->SetDrawShell( sal_False ); 792 } 793 else 794 { 795 OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK ); 796 //@todo maybe move chart to different table 797 } 798 } 799 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY ); 800 if( xComponent.is()) 801 xComponent->dispose(); 802 } 803 } 804 } 805 806 if ( bAddUndo ) 807 { 808 // add undo action the same way as in SdrEditView::InsertObjectAtView 809 // (using UndoActionHdl etc.) 810 pView->AddUndo(pDoc->GetSdrUndoFactory().CreateUndoNewObject(*pObj)); 811 } 812 813 // BM/IHA -- 814 } 815 } 816 817 /************************************************************************* 818 |* 819 |* FuInsertChart::Destruktor 820 |* 821 \************************************************************************/ 822 823 FuInsertChart::~FuInsertChart() 824 { 825 } 826 827 /************************************************************************* 828 |* 829 |* FuInsertChart::Function aktivieren 830 |* 831 \************************************************************************/ 832 833 void FuInsertChart::Activate() 834 { 835 FuPoor::Activate(); 836 } 837 838 /************************************************************************* 839 |* 840 |* FuInsertChart::Function deaktivieren 841 |* 842 \************************************************************************/ 843 844 void FuInsertChart::Deactivate() 845 { 846 FuPoor::Deactivate(); 847 } 848 849 850