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