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