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/XEmbeddedObject.hpp> 29 #include <com/sun/star/frame/XComponentLoader.hpp> 30 31 32 using namespace ::com::sun::star; 33 34 // INCLUDE --------------------------------------------------------------- 35 #include <math.h> // prevent conflict between exception and std::exception 36 37 #include "scitems.hxx" 38 #include <sfx2/fcontnr.hxx> 39 #include <editeng/eeitem.hxx> 40 #include <sfx2/objface.hxx> 41 #include <sfx2/app.hxx> 42 #include <sfx2/bindings.hxx> 43 #include <sfx2/docfile.hxx> 44 #include <sfx2/docfilt.hxx> 45 #include <svtools/ehdl.hxx> 46 #include <basic/sbxcore.hxx> 47 #include <sfx2/printer.hxx> 48 #include <sfx2/request.hxx> 49 #include <svtools/sfxecode.hxx> 50 #include <svx/ofaitem.hxx> 51 #include <sot/formats.hxx> 52 #include <svl/whiter.hxx> 53 #include <vcl/msgbox.hxx> 54 #include <vcl/waitobj.hxx> 55 #include <tools/multisel.hxx> 56 #include <svx/dataaccessdescriptor.hxx> 57 #include <svx/drawitem.hxx> 58 #include <svx/fmview.hxx> 59 #include <svx/pageitem.hxx> 60 #include <svx/svditer.hxx> 61 #include <svx/svdpage.hxx> 62 #include <svx/fmshell.hxx> 63 #include <svtools/xwindowitem.hxx> 64 #include <sfx2/passwd.hxx> 65 #include <sfx2/filedlghelper.hxx> 66 #include <sfx2/docinsert.hxx> 67 #include <svl/PasswordHelper.hxx> 68 #include <svl/documentlockfile.hxx> 69 #include <svl/sharecontrolfile.hxx> 70 71 #include <comphelper/processfactory.hxx> 72 #include "docuno.hxx" 73 74 #include <com/sun/star/sdbc/XResultSet.hpp> 75 #include "docsh.hxx" 76 #include "docshimp.hxx" 77 #include "docfunc.hxx" 78 #include "sc.hrc" 79 #include "stlsheet.hxx" 80 #include "stlpool.hxx" 81 #include "appoptio.hxx" 82 #include "globstr.hrc" 83 #include "global.hxx" 84 //CHINA001 #include "styledlg.hxx" 85 //CHINA001 #include "hfedtdlg.hxx" 86 #include "dbdocfun.hxx" 87 #include "printfun.hxx" // DrawToDev 88 #include "viewdata.hxx" 89 #include "tabvwsh.hxx" 90 #include "impex.hxx" 91 #include "attrib.hxx" 92 //CHINA001 #include "corodlg.hxx" 93 #include "undodat.hxx" 94 #include "autostyl.hxx" 95 #include "undocell.hxx" 96 #include "undotab.hxx" 97 #include "inputhdl.hxx" 98 #include "dbcolect.hxx" 99 #include "servobj.hxx" 100 #include "rangenam.hxx" 101 #include "scmod.hxx" 102 //CHINA001 #include "scendlg.hxx" 103 #include "chgviset.hxx" 104 #include "reffact.hxx" 105 #include "chartlis.hxx" 106 #include "chartpos.hxx" 107 #include "waitoff.hxx" 108 #include "tablink.hxx" // ScDocumentLoader statics 109 #include "drwlayer.hxx" 110 #include "docoptio.hxx" 111 #include "undostyl.hxx" 112 #include "rangeseq.hxx" 113 #include "chgtrack.hxx" 114 #include "printopt.hxx" 115 #include <com/sun/star/document/UpdateDocMode.hpp> 116 #include "scresid.hxx" //add by CHINA001 117 #include "scabstdlg.hxx" //CHINA001 118 #include "externalrefmgr.hxx" 119 #include "sharedocdlg.hxx" 120 #include "conditio.hxx" 121 #include "sheetevents.hxx" 122 123 //------------------------------------------------------------------ 124 125 #define IS_SHARE_HEADER(set) \ 126 ((SfxBoolItem&) \ 127 ((SvxSetItem&)(set).Get(ATTR_PAGE_HEADERSET)).GetItemSet(). \ 128 Get(ATTR_PAGE_SHARED)).GetValue() 129 130 #define IS_SHARE_FOOTER(set) \ 131 ((SfxBoolItem&) \ 132 ((SvxSetItem&)(set).Get(ATTR_PAGE_FOOTERSET)).GetItemSet(). \ 133 Get(ATTR_PAGE_SHARED)).GetValue() 134 135 #define IS_AVAILABLE(WhichId,ppItem) \ 136 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET) 137 138 #define SC_PREVIEW_SIZE_X 10000 139 #define SC_PREVIEW_SIZE_Y 12400 140 141 142 //------------------------------------------------------------------ 143 144 void ScDocShell::Execute( SfxRequest& rReq ) 145 { 146 // SID_SC_RANGE (Range), 147 // SID_SC_CELLTEXT (CellText), 148 // SID_SC_CELLS (Cells) - removed (old Basic) 149 150 const SfxItemSet* pReqArgs = rReq.GetArgs(); 151 SfxBindings* pBindings = GetViewBindings(); 152 sal_Bool bUndo (aDocument.IsUndoEnabled()); 153 154 sal_uInt16 nSlot = rReq.GetSlot(); 155 switch ( nSlot ) 156 { 157 case SID_SC_SETTEXT: 158 { 159 const SfxPoolItem* pColItem; 160 const SfxPoolItem* pRowItem; 161 const SfxPoolItem* pTabItem; 162 const SfxPoolItem* pTextItem; 163 if( pReqArgs && IS_AVAILABLE( FN_PARAM_1, &pColItem ) && 164 IS_AVAILABLE( FN_PARAM_2, &pRowItem ) && 165 IS_AVAILABLE( FN_PARAM_3, &pTabItem ) && 166 IS_AVAILABLE( SID_SC_SETTEXT, &pTextItem ) ) 167 { 168 // Parameter sind 1-based !!! 169 SCCOL nCol = ((SfxInt16Item*)pColItem)->GetValue() - 1; 170 SCROW nRow = ((SfxInt32Item*)pRowItem)->GetValue() - 1; 171 SCTAB nTab = ((SfxInt16Item*)pTabItem)->GetValue() - 1; 172 173 SCTAB nTabCount = aDocument.GetTableCount(); 174 if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) ) 175 { 176 if ( aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) ) 177 { 178 String aVal = ((const SfxStringItem*)pTextItem)->GetValue(); 179 aDocument.SetString( nCol, nRow, nTab, aVal ); 180 181 PostPaintCell( nCol, nRow, nTab ); 182 SetDocumentModified(); 183 184 rReq.Done(); 185 break; 186 } 187 else // geschuetzte Zelle 188 { 189 SbxBase::SetError( SbxERR_BAD_PARAMETER ); //! welchen Fehler ? 190 break; 191 } 192 } 193 } 194 SbxBase::SetError( SbxERR_NO_OBJECT ); 195 } 196 break; 197 198 case SID_SBA_IMPORT: 199 { 200 if (pReqArgs) 201 { 202 const SfxPoolItem* pItem; 203 svx::ODataAccessDescriptor aDesc; 204 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET ) 205 { 206 uno::Any aAny = static_cast<const SfxUsrAnyItem*>(pItem)->GetValue(); 207 uno::Sequence<beans::PropertyValue> aProperties; 208 if ( aAny >>= aProperties ) 209 aDesc.initializeFrom( aProperties ); 210 } 211 212 String sTarget; 213 if ( pReqArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET ) 214 sTarget = ((const SfxStringItem*)pItem)->GetValue(); 215 216 sal_Bool bIsNewArea = sal_True; // Default sal_True (keine Nachfrage) 217 if ( pReqArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET ) 218 bIsNewArea = ((const SfxBoolItem*)pItem)->GetValue(); 219 220 // bei Bedarf neuen Datenbankbereich anlegen 221 sal_Bool bMakeArea = sal_False; 222 if (bIsNewArea) 223 { 224 ScDBCollection* pDBColl = aDocument.GetDBCollection(); 225 sal_uInt16 nDummy; 226 if ( !pDBColl || !pDBColl->SearchName( sTarget, nDummy ) ) 227 { 228 ScAddress aPos; 229 if ( aPos.Parse( sTarget, &aDocument, aDocument.GetAddressConvention() ) & SCA_VALID ) 230 { 231 bMakeArea = sal_True; 232 if (bUndo) 233 { 234 String aStrImport = ScGlobal::GetRscString( STR_UNDO_IMPORTDATA ); 235 GetUndoManager()->EnterListAction( aStrImport, aStrImport ); 236 } 237 238 ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, SC_DBSEL_KEEP ); 239 DBG_ASSERT(pDBData, "kann DB-Daten nicht anlegen"); 240 sTarget = pDBData->GetName(); 241 } 242 } 243 } 244 245 // nachfragen, bevor alter DB-Bereich ueberschrieben wird 246 sal_Bool bDo = sal_True; 247 if (!bIsNewArea) 248 { 249 String aTemplate = ScGlobal::GetRscString( STR_IMPORT_REPLACE ); 250 String aMessage = aTemplate.GetToken( 0, '#' ); 251 aMessage += sTarget; 252 aMessage += aTemplate.GetToken( 1, '#' ); 253 254 QueryBox aBox( 0, WinBits(WB_YES_NO | WB_DEF_YES), aMessage ); 255 bDo = ( aBox.Execute() == RET_YES ); 256 } 257 258 if (bDo) 259 { 260 ScDBDocFunc(*this).UpdateImport( sTarget, aDesc ); 261 rReq.Done(); 262 263 // UpdateImport aktualisiert auch die internen Operationen 264 } 265 else 266 rReq.Ignore(); 267 268 if ( bMakeArea && bUndo) 269 GetUndoManager()->LeaveListAction(); 270 } 271 else 272 { 273 DBG_ERROR( "arguments expected" ); 274 } 275 } 276 break; 277 278 case SID_CHART_SOURCE: 279 case SID_CHART_ADDSOURCE: 280 if (pReqArgs) 281 { 282 ScDocument* pDoc = GetDocument(); 283 // sal_Bool bUndo (pDoc->IsUndoEnabled()); 284 const SfxPoolItem* pItem; 285 String aChartName, aRangeName; 286 287 ScRange aSingleRange; 288 ScRangeListRef aRangeListRef; 289 sal_Bool bMultiRange = sal_False; 290 291 sal_Bool bColHeaders = sal_True; 292 sal_Bool bRowHeaders = sal_True; 293 sal_Bool bColInit = sal_False; 294 sal_Bool bRowInit = sal_False; 295 sal_Bool bAddRange = (nSlot == SID_CHART_ADDSOURCE); 296 297 if( IS_AVAILABLE( SID_CHART_NAME, &pItem ) ) 298 aChartName = ((const SfxStringItem*)pItem)->GetValue(); 299 300 if( IS_AVAILABLE( SID_CHART_SOURCE, &pItem ) ) 301 aRangeName = ((const SfxStringItem*)pItem)->GetValue(); 302 303 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 304 { 305 bColHeaders = ((const SfxBoolItem*)pItem)->GetValue(); 306 bColInit = sal_True; 307 } 308 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) ) 309 { 310 bRowHeaders = ((const SfxBoolItem*)pItem)->GetValue(); 311 bRowInit = sal_True; 312 } 313 314 ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0); 315 sal_Bool bValid = ( aSingleRange.ParseAny( aRangeName, pDoc, aDetails ) & SCA_VALID ) != 0; 316 if (!bValid) 317 { 318 aRangeListRef = new ScRangeList; 319 aRangeListRef->Parse( aRangeName, pDoc ); 320 if ( aRangeListRef->Count() ) 321 { 322 bMultiRange = sal_True; 323 aSingleRange = *aRangeListRef->GetObject(0); // fuer Header 324 bValid = sal_True; 325 } 326 else 327 aRangeListRef.Clear(); 328 } 329 330 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); 331 if (pViewSh && bValid && aChartName.Len() != 0 ) 332 { 333 Window* pParent = pViewSh->GetDialogParent(); 334 335 SCCOL nCol1 = aSingleRange.aStart.Col(); 336 SCROW nRow1 = aSingleRange.aStart.Row(); 337 SCCOL nCol2 = aSingleRange.aEnd.Col(); 338 SCROW nRow2 = aSingleRange.aEnd.Row(); 339 SCTAB nTab = aSingleRange.aStart.Tab(); 340 341 //! immer oder gar nicht begrenzen ??? 342 if (!bMultiRange) 343 aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 ); 344 345 // Dialog fuer Spalten/Zeilenkoepfe 346 sal_Bool bOk = sal_True; 347 if ( !bAddRange && ( !bColInit || !bRowInit ) ) 348 { 349 ScChartPositioner aChartPositioner( &aDocument, nTab, nCol1,nRow1, nCol2,nRow2 ); 350 if (!bColInit) 351 bColHeaders = aChartPositioner.HasColHeaders(); 352 if (!bRowInit) 353 bRowHeaders = aChartPositioner.HasRowHeaders(); 354 355 //CHINA001 ScColRowLabelDlg aDlg( pParent, bRowHeaders, bColHeaders ); 356 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 357 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 358 359 AbstractScColRowLabelDlg* pDlg = pFact->CreateScColRowLabelDlg( pParent, RID_SCDLG_CHARTCOLROW, bRowHeaders, bColHeaders); 360 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 361 if ( pDlg->Execute() == RET_OK ) //CHINA001 if ( aDlg.Execute() == RET_OK ) 362 { 363 bColHeaders = pDlg->IsRow(); //CHINA001 bColHeaders = aDlg.IsRow(); // Spaltenkoepfe = 1. Zeile 364 bRowHeaders = pDlg->IsCol(); //CHINA001 bRowHeaders = aDlg.IsCol(); 365 366 rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders)); 367 rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders)); 368 } 369 else 370 bOk = sal_False; 371 delete pDlg; //CHINA001 372 } 373 374 if (bOk) // ausfuehren 375 { 376 if (bMultiRange) 377 { 378 if (bUndo) 379 { 380 GetUndoManager()->AddUndoAction( 381 new ScUndoChartData( this, aChartName, aRangeListRef, 382 bColHeaders, bRowHeaders, bAddRange ) ); 383 } 384 aDocument.UpdateChartArea( aChartName, aRangeListRef, 385 bColHeaders, bRowHeaders, bAddRange ); 386 } 387 else 388 { 389 ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); 390 if (bUndo) 391 { 392 GetUndoManager()->AddUndoAction( 393 new ScUndoChartData( this, aChartName, aNewRange, 394 bColHeaders, bRowHeaders, bAddRange ) ); 395 } 396 aDocument.UpdateChartArea( aChartName, aNewRange, 397 bColHeaders, bRowHeaders, bAddRange ); 398 } 399 } 400 } 401 else 402 { 403 DBG_ERROR("UpdateChartArea: keine ViewShell oder falsche Daten"); 404 } 405 rReq.Done(); 406 } 407 else 408 { 409 DBG_ERROR("SID_CHART_SOURCE ohne Argumente"); 410 } 411 break; 412 413 case FID_AUTO_CALC: 414 { 415 sal_Bool bNewVal; 416 const SfxPoolItem* pItem; 417 if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) ) 418 bNewVal = ((const SfxBoolItem*)pItem)->GetValue(); 419 else 420 bNewVal = !aDocument.GetAutoCalc(); // Toggle fuer Menue 421 aDocument.SetAutoCalc( bNewVal ); 422 SetDocumentModified(); 423 if (pBindings) 424 { 425 pBindings->Invalidate( FID_AUTO_CALC ); 426 // pBindings->Invalidate( FID_RECALC ); // jetzt immer enabled 427 } 428 rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) ); 429 rReq.Done(); 430 } 431 break; 432 case FID_RECALC: 433 DoRecalc( rReq.IsAPI() ); 434 rReq.Done(); 435 break; 436 case FID_HARD_RECALC: 437 DoHardRecalc( rReq.IsAPI() ); 438 rReq.Done(); 439 break; 440 case SID_UPDATETABLINKS: 441 { 442 ScDocument* pDoc = GetDocument(); 443 444 ScLkUpdMode nSet=pDoc->GetLinkMode(); 445 446 sal_uInt16 nDlgRet=RET_NO; 447 if(nSet==LM_UNKNOWN) 448 { 449 ScAppOptions aAppOptions=SC_MOD()->GetAppOptions(); 450 nSet=aAppOptions.GetLinkMode(); 451 } 452 453 if (nCanUpdate == com::sun::star::document::UpdateDocMode::NO_UPDATE) 454 nSet = LM_NEVER; 455 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::QUIET_UPDATE && 456 nSet == LM_ON_DEMAND) 457 nSet = LM_NEVER; 458 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::FULL_UPDATE) 459 nSet = LM_ALWAYS; 460 461 if(nSet==LM_ON_DEMAND) 462 { 463 QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES), 464 ScGlobal::GetRscString(STR_RELOAD_TABLES) ); 465 466 nDlgRet=aBox.Execute(); 467 } 468 469 if (nDlgRet == RET_YES || nSet==LM_ALWAYS) 470 { 471 ReloadTabLinks(); 472 aDocument.UpdateExternalRefLinks(); 473 aDocument.UpdateDdeLinks(); 474 aDocument.UpdateAreaLinks(); 475 476 //! Test, ob Fehler 477 rReq.Done(); 478 } 479 else 480 rReq.Ignore(); 481 } 482 break; 483 484 case SID_REIMPORT_AFTER_LOAD: 485 { 486 // wird nach dem Laden aufgerufen, wenn DB-Bereiche mit 487 // weggelassenen Daten enthalten sind 488 489 sal_Bool bDone = sal_False; 490 ScDBCollection* pDBColl = aDocument.GetDBCollection(); 491 492 if ((nCanUpdate != com::sun::star::document::UpdateDocMode::NO_UPDATE) && 493 (nCanUpdate != com::sun::star::document::UpdateDocMode::QUIET_UPDATE)) 494 { 495 ScRange aRange; 496 ScTabViewShell* pViewSh = GetBestViewShell(); 497 DBG_ASSERT(pViewSh,"SID_REIMPORT_AFTER_LOAD: keine View"); 498 if (pViewSh && pDBColl) 499 { 500 QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES), 501 ScGlobal::GetRscString(STR_REIMPORT_AFTER_LOAD) ); 502 if (aBox.Execute() == RET_YES) 503 { 504 for (sal_uInt16 i=0; i<pDBColl->GetCount(); i++) 505 { 506 ScDBData* pDBData = (*pDBColl)[i]; 507 if ( pDBData->IsStripData() && 508 pDBData->HasImportParam() && !pDBData->HasImportSelection() ) 509 { 510 pDBData->GetArea(aRange); 511 pViewSh->MarkRange(aRange); 512 513 // Import und interne Operationen wie SID_REFRESH_DBAREA 514 // (Abfrage auf Import hier nicht noetig) 515 516 ScImportParam aImportParam; 517 pDBData->GetImportParam( aImportParam ); 518 sal_Bool bContinue = pViewSh->ImportData( aImportParam ); 519 pDBData->SetImportParam( aImportParam ); 520 521 // markieren (Groesse kann sich geaendert haben) 522 pDBData->GetArea(aRange); 523 pViewSh->MarkRange(aRange); 524 525 if ( bContinue ) // #41905# Fehler beim Import -> Abbruch 526 { 527 // interne Operationen, wenn welche gespeichert 528 529 if ( pDBData->HasQueryParam() || pDBData->HasSortParam() || 530 pDBData->HasSubTotalParam() ) 531 pViewSh->RepeatDB(); 532 533 // Pivottabellen die den Bereich als Quelldaten haben 534 535 RefreshPivotTables(aRange); 536 } 537 } 538 } 539 bDone = sal_True; 540 } 541 } 542 } 543 544 if ( !bDone && pDBColl ) 545 { 546 // wenn nicht, dann aber die abhaengigen Formeln updaten 547 //! auch fuer einzelne Bereiche, die nicht aktualisiert werden koennen 548 549 aDocument.CalcAll(); //! nur die abhaengigen 550 PostDataChanged(); 551 } 552 553 if (bDone) 554 rReq.Done(); 555 else 556 rReq.Ignore(); 557 } 558 break; 559 560 561 case SID_AUTO_STYLE: 562 DBG_ERROR("use ScAutoStyleHint instead of SID_AUTO_STYLE"); 563 break; 564 565 case SID_GET_COLORTABLE: 566 { 567 // passende ColorTable ist per PutItem gesetzt worden 568 const SvxColorTableItem* pColItem = static_cast< const SvxColorTableItem* >(GetItem(SID_COLOR_TABLE)); 569 XColorListSharedPtr aTable = pColItem->GetColorTable(); 570 571 rReq.SetReturnValue(SvxColorTableItem(aTable, SID_GET_COLORTABLE)); 572 } 573 break; 574 575 case FID_CHG_RECORD: 576 { 577 ScDocument* pDoc = GetDocument(); 578 if(pDoc!=NULL) 579 { 580 // get argument (recorded macro) 581 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FID_CHG_RECORD, sal_False ); 582 sal_Bool bDo = sal_True; 583 584 // xmlsec05/06: 585 // getting real parent window when called from Security-Options TP 586 Window* pParent = NULL; 587 const SfxPoolItem* pParentItem; 588 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) ) 589 pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr(); 590 591 // desired state 592 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack(); 593 sal_Bool bActivateTracking = (pChangeTrack == 0); // toggle 594 if ( pItem ) 595 bActivateTracking = pItem->GetValue(); // from argument 596 597 if ( !bActivateTracking ) 598 { 599 if ( !pItem ) 600 { 601 // no dialog on playing the macro 602 WarningBox aBox( pParent ? pParent : GetActiveDialogParent(), 603 WinBits(WB_YES_NO | WB_DEF_NO), 604 ScGlobal::GetRscString( STR_END_REDLINING ) ); 605 bDo = ( aBox.Execute() == RET_YES ); 606 } 607 608 if ( bDo ) 609 { 610 if ( pChangeTrack->IsProtected() ) 611 bDo = ExecuteChangeProtectionDialog( NULL ); 612 if ( bDo ) 613 { 614 pDoc->EndChangeTracking(); 615 PostPaintGridAll(); 616 } 617 } 618 } 619 else 620 { 621 pDoc->StartChangeTracking(); 622 ScChangeViewSettings aChangeViewSet; 623 aChangeViewSet.SetShowChanges(sal_True); 624 pDoc->SetChangeViewSettings(aChangeViewSet); 625 } 626 627 if ( bDo ) 628 { 629 UpdateAcceptChangesDialog(); 630 631 // Slots invalidieren 632 if (pBindings) 633 pBindings->InvalidateAll(sal_False); 634 if ( !pItem ) 635 rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) ); 636 rReq.Done(); 637 } 638 else 639 rReq.Ignore(); 640 } 641 } 642 break; 643 644 case SID_CHG_PROTECT : 645 { 646 Window* pParent = NULL; 647 const SfxPoolItem* pParentItem; 648 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) ) 649 pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr(); 650 if ( ExecuteChangeProtectionDialog( pParent ) ) 651 { 652 rReq.Done(); 653 SetDocumentModified(); 654 } 655 else 656 rReq.Ignore(); 657 } 658 break; 659 660 case SID_DOCUMENT_MERGE: 661 case SID_DOCUMENT_COMPARE: 662 { 663 sal_Bool bDo = sal_True; 664 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); 665 if ( pChangeTrack && !pImpl->bIgnoreLostRedliningWarning ) 666 { 667 if ( nSlot == SID_DOCUMENT_COMPARE ) 668 { //! old changes trace will be lost 669 WarningBox aBox( GetActiveDialogParent(), 670 WinBits(WB_YES_NO | WB_DEF_NO), 671 ScGlobal::GetRscString( STR_END_REDLINING ) ); 672 if( aBox.Execute() == RET_YES ) 673 bDo = ExecuteChangeProtectionDialog( NULL, sal_True ); 674 else 675 bDo = sal_False; 676 } 677 else // merge might reject some actions 678 bDo = ExecuteChangeProtectionDialog( NULL, sal_True ); 679 } 680 if ( !bDo ) 681 { 682 rReq.Ignore(); 683 break; 684 } 685 SfxApplication* pApp = SFX_APP(); 686 const SfxPoolItem* pItem; 687 SfxMedium* pMed = NULL; 688 if ( pReqArgs && 689 pReqArgs->GetItemState( SID_FILE_NAME, sal_True, &pItem ) == SFX_ITEM_SET && 690 pItem->ISA(SfxStringItem) ) 691 { 692 String aFileName = ((const SfxStringItem*)pItem)->GetValue(); 693 694 String aFilterName; 695 if ( pReqArgs->GetItemState( SID_FILTER_NAME, sal_True, &pItem ) == SFX_ITEM_SET && 696 pItem->ISA(SfxStringItem) ) 697 { 698 aFilterName = ((const SfxStringItem*)pItem)->GetValue(); 699 } 700 String aOptions; 701 if ( pReqArgs->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) == SFX_ITEM_SET && 702 pItem->ISA(SfxStringItem) ) 703 { 704 aOptions = ((const SfxStringItem*)pItem)->GetValue(); 705 } 706 short nVersion = 0; 707 if ( pReqArgs->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET && 708 pItem->ISA(SfxInt16Item) ) 709 { 710 nVersion = ((const SfxInt16Item*)pItem)->GetValue(); 711 } 712 713 // kein Filter angegeben -> Detection 714 if ( !aFilterName.Len() ) 715 ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, sal_True, sal_False ); 716 717 // filter name from dialog contains application prefix, 718 // GetFilter needs name without the prefix. 719 ScDocumentLoader::RemoveAppPrefix( aFilterName ); 720 721 const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName ); 722 SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() ); 723 if ( aOptions.Len() ) 724 pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) ); 725 if ( nVersion != 0 ) 726 pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) ); 727 pMed = new SfxMedium( aFileName, STREAM_STD_READ, sal_False, pFilter, pSet ); 728 } 729 else 730 { 731 // start file dialog asynchronous 732 pImpl->bIgnoreLostRedliningWarning = true; 733 delete pImpl->pRequest; 734 pImpl->pRequest = new SfxRequest( rReq ); 735 delete pImpl->pDocInserter; 736 pImpl->pDocInserter = new ::sfx2::DocumentInserter( 737 0, String::CreateFromAscii( ScDocShell::Factory().GetShortName() ), 0 ); 738 pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) ); 739 return ; 740 } 741 742 if ( pMed ) // nun wirklich ausfuehren... 743 { 744 SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() ); 745 746 // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here 747 ScDocShell* pOtherDocSh = new ScDocShell; 748 SfxObjectShellLock aDocShTablesRef = pOtherDocSh; 749 pOtherDocSh->DoLoad( pMed ); 750 sal_uLong nErr = pOtherDocSh->GetErrorCode(); 751 if (nErr) 752 ErrorHandler::HandleError( nErr ); // auch Warnings 753 754 if ( !pOtherDocSh->GetError() ) // nur Errors 755 { 756 sal_Bool bHadTrack = ( aDocument.GetChangeTrack() != NULL ); 757 sal_uLong nStart = 0; 758 if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack ) 759 { 760 nStart = pChangeTrack->GetActionMax() + 1; 761 } 762 763 if ( nSlot == SID_DOCUMENT_COMPARE ) 764 CompareDocument( *pOtherDocSh->GetDocument() ); 765 else 766 MergeDocument( *pOtherDocSh->GetDocument() ); 767 768 // show "accept changes" dialog 769 //! get view for this document! 770 if ( !IsDocShared() ) 771 { 772 SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 773 if ( pViewFrm ) 774 { 775 pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId(), sal_True ); //@51669 776 } 777 if ( pBindings ) 778 { 779 pBindings->Invalidate( FID_CHG_ACCEPT ); 780 } 781 } 782 783 rReq.SetReturnValue( SfxInt32Item( nSlot, 0 ) ); //! ??????? 784 rReq.Done(); 785 786 if (!bHadTrack) // neu eingeschaltet -> auch anzeigen 787 { 788 ScChangeViewSettings* pOldSet = aDocument.GetChangeViewSettings(); 789 if ( !pOldSet || !pOldSet->ShowChanges() ) 790 { 791 ScChangeViewSettings aChangeViewSet; 792 aChangeViewSet.SetShowChanges(sal_True); 793 aDocument.SetChangeViewSettings(aChangeViewSet); 794 } 795 } 796 else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack ) 797 { 798 sal_uLong nEnd = pChangeTrack->GetActionMax(); 799 if ( nEnd >= nStart ) 800 { 801 // only show changes from merged document 802 ScChangeViewSettings aChangeViewSet; 803 aChangeViewSet.SetShowChanges( sal_True ); 804 aChangeViewSet.SetShowAccepted( sal_True ); 805 aChangeViewSet.SetHasActionRange( true ); 806 aChangeViewSet.SetTheActionRange( nStart, nEnd ); 807 aDocument.SetChangeViewSettings( aChangeViewSet ); 808 809 // update view 810 PostPaintExtras(); 811 PostPaintGridAll(); 812 } 813 } 814 } 815 pOtherDocSh->DoClose(); // delete passiert mit der Ref 816 } 817 } 818 break; 819 820 case SID_DELETE_SCENARIO: 821 if (pReqArgs) 822 { 823 const SfxPoolItem* pItem; 824 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET ) 825 { 826 if ( pItem->ISA(SfxStringItem) ) 827 { 828 String aName = ((const SfxStringItem*)pItem)->GetValue(); 829 SCTAB nTab; 830 if (aDocument.GetTable( aName, nTab )) 831 { 832 // DeleteTable von viewfunc nach docfunc verschieben! 833 834 ScTabViewShell* pSh = GetBestViewShell(); 835 if ( pSh ) 836 { 837 //! SetTabNo in DeleteTable weglassen? 838 SCTAB nDispTab = pSh->GetViewData()->GetTabNo(); 839 pSh->DeleteTable( nTab ); 840 pSh->SetTabNo(nDispTab); 841 rReq.Done(); 842 } 843 } 844 } 845 } 846 } 847 break; 848 849 case SID_EDIT_SCENARIO: 850 { 851 const SfxPoolItem* pItem; 852 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET ) 853 { 854 if ( pItem->ISA(SfxStringItem) ) 855 { 856 String aName = ((const SfxStringItem*)pItem)->GetValue(); 857 SCTAB nTab; 858 if (aDocument.GetTable( aName, nTab )) 859 { 860 if (aDocument.IsScenario(nTab)) 861 { 862 String aComment; 863 Color aColor; 864 sal_uInt16 nFlags; 865 aDocument.GetScenarioData( nTab, aComment, aColor, nFlags ); 866 867 // Determine if the Sheet that the Scenario was created on 868 // is protected. But first we need to find that Sheet. 869 // Rewind back to the actual sheet. 870 SCTAB nActualTab = nTab; 871 do 872 { 873 nActualTab--; 874 } 875 while(aDocument.IsScenario(nActualTab)); 876 sal_Bool bSheetProtected = aDocument.IsTabProtected(nActualTab); 877 878 //! anderen Titel am Dialog setzen 879 //CHINA001 ScNewScenarioDlg* pNewDlg = 880 //CHINA001 new ScNewScenarioDlg( GetActiveDialogParent(), aName, sal_True, bSheetProtected); 881 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 882 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 883 884 AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( GetActiveDialogParent(), aName, RID_SCDLG_NEWSCENARIO, sal_True,bSheetProtected); 885 DBG_ASSERT(pNewDlg, "Dialog create fail!");//CHINA001 886 pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags ); 887 if ( pNewDlg->Execute() == RET_OK ) 888 { 889 pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags ); 890 ModifyScenario( nTab, aName, aComment, aColor, nFlags ); 891 rReq.Done(); 892 } 893 delete pNewDlg; 894 } 895 } 896 } 897 } 898 } 899 break; 900 901 case SID_ATTR_YEAR2000 : 902 { 903 const SfxPoolItem* pItem; 904 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET ) 905 { 906 if ( pItem->ISA(SfxUInt16Item) ) 907 { 908 sal_uInt16 nY2k = ((SfxUInt16Item*)pItem)->GetValue(); 909 // immer an den DocOptions setzen, damit das auch fuer SO50 910 // gespeichert wird (und alle Abfragen bisher auch darauf laufen). 911 // SetDocOptions propagiert das an den NumberFormatter 912 ScDocOptions aDocOpt( aDocument.GetDocOptions() ); 913 aDocOpt.SetYear2000( nY2k ); 914 aDocument.SetDocOptions( aDocOpt ); 915 // die FormShell soll es mitbekommen 916 ScTabViewShell* pSh = GetBestViewShell(); 917 if ( pSh ) 918 { 919 FmFormShell* pFSh = pSh->GetFormShell(); 920 if ( pFSh ) 921 pFSh->SetY2KState( nY2k ); 922 } 923 } 924 } 925 } 926 break; 927 928 case SID_SHARE_DOC: 929 { 930 ScViewData* pViewData = GetViewData(); 931 if ( !pViewData ) 932 { 933 rReq.Ignore(); 934 break; 935 } 936 937 ScShareDocumentDlg aDlg( GetActiveDialogParent(), pViewData ); 938 if ( aDlg.Execute() == RET_OK ) 939 { 940 bool bSetShared = aDlg.IsShareDocumentChecked(); 941 if ( bSetShared != static_cast< bool >( IsDocShared() ) ) 942 { 943 if ( bSetShared ) 944 { 945 bool bContinue = true; 946 if ( HasName() ) 947 { 948 QueryBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ), 949 ScGlobal::GetRscString( STR_DOC_WILLBESAVED ) ); 950 if ( aBox.Execute() == RET_NO ) 951 { 952 bContinue = false; 953 } 954 } 955 if ( bContinue ) 956 { 957 EnableSharedSettings( true ); 958 959 SC_MOD()->SetInSharedDocSaving( true ); 960 if ( !SwitchToShared( sal_True, sal_True ) ) 961 { 962 // TODO/LATER: what should be done in case the switch has failed? 963 // for example in case the user has cancelled the saveAs operation 964 } 965 966 SC_MOD()->SetInSharedDocSaving( false ); 967 968 InvalidateName(); 969 GetUndoManager()->Clear(); 970 971 ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() ); 972 if ( pTabView ) 973 { 974 pTabView->UpdateLayerLocks(); 975 } 976 } 977 } 978 else 979 { 980 uno::Reference< frame::XModel > xModel; 981 try 982 { 983 // load shared file 984 xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW ); 985 uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW ); 986 987 // check if shared flag is set in shared file 988 bool bShared = false; 989 ScModelObj* pDocObj = ScModelObj::getImplementation( xModel ); 990 if ( pDocObj ) 991 { 992 ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() ); 993 if ( pDocShell ) 994 { 995 bShared = pDocShell->HasSharedXMLFlagSet(); 996 } 997 } 998 999 // #i87870# check if shared status was disabled and enabled again 1000 bool bOwnEntry = false; 1001 try 1002 { 1003 ::svt::ShareControlFile aControlFile( GetSharedFileURL() ); 1004 bOwnEntry = aControlFile.HasOwnEntry(); 1005 } 1006 catch ( uno::Exception& ) 1007 { 1008 } 1009 1010 if ( bShared && bOwnEntry ) 1011 { 1012 uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW ); 1013 if ( xStorable->isReadonly() ) 1014 { 1015 xCloseable->close( sal_True ); 1016 1017 String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) ); 1018 try 1019 { 1020 ::svt::DocumentLockFile aLockFile( GetSharedFileURL() ); 1021 uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData(); 1022 if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID ) 1023 { 1024 if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() > 0 ) 1025 { 1026 aUserName = aData[LOCKFILE_OOOUSERNAME_ID]; 1027 } 1028 else if ( aData[LOCKFILE_SYSUSERNAME_ID].getLength() > 0 ) 1029 { 1030 aUserName = aData[LOCKFILE_SYSUSERNAME_ID]; 1031 } 1032 } 1033 } 1034 catch ( uno::Exception& ) 1035 { 1036 } 1037 String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_TRY_LATER ) ); 1038 aMessage.SearchAndReplaceAscii( "%1", aUserName ); 1039 1040 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ), aMessage ); 1041 aBox.Execute(); 1042 } 1043 else 1044 { 1045 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ), 1046 ScGlobal::GetRscString( STR_DOC_DISABLESHARED ) ); 1047 if ( aBox.Execute() == RET_YES ) 1048 { 1049 xCloseable->close( sal_True ); 1050 1051 if ( !SwitchToShared( sal_False, sal_True ) ) 1052 { 1053 // TODO/LATER: what should be done in case the switch has failed? 1054 // for example in case the user has cancelled the saveAs operation 1055 } 1056 1057 EnableSharedSettings( false ); 1058 1059 if ( pBindings ) 1060 { 1061 pBindings->ExecuteSynchron( SID_SAVEDOC ); 1062 } 1063 1064 ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() ); 1065 if ( pTabView ) 1066 { 1067 pTabView->UpdateLayerLocks(); 1068 } 1069 } 1070 else 1071 { 1072 xCloseable->close( sal_True ); 1073 } 1074 } 1075 } 1076 else 1077 { 1078 xCloseable->close( sal_True ); 1079 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ), 1080 ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) ); 1081 aBox.Execute(); 1082 } 1083 } 1084 catch ( uno::Exception& ) 1085 { 1086 DBG_ERROR( "SID_SHARE_DOC: caught exception\n" ); 1087 SC_MOD()->SetInSharedDocSaving( false ); 1088 1089 try 1090 { 1091 uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); 1092 xClose->close( sal_True ); 1093 } 1094 catch ( uno::Exception& ) 1095 { 1096 } 1097 } 1098 } 1099 } 1100 } 1101 rReq.Done(); 1102 } 1103 break; 1104 1105 default: 1106 { 1107 // kleiner (?) Hack -> forward der Slots an TabViewShell 1108 ScTabViewShell* pSh = GetBestViewShell(); 1109 if ( pSh ) 1110 pSh->Execute( rReq ); 1111 else 1112 SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT ); 1113 } 1114 } 1115 } 1116 1117 1118 //------------------------------------------------------------------ 1119 1120 void UpdateAcceptChangesDialog() 1121 { 1122 // update "accept changes" dialog 1123 //! notify all views 1124 SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 1125 if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) ) 1126 { 1127 SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT ); 1128 if ( pChild ) 1129 ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg(); 1130 } 1131 } 1132 1133 //------------------------------------------------------------------ 1134 1135 sal_Bool ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected ) 1136 { 1137 sal_Bool bDone = sal_False; 1138 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); 1139 if ( pChangeTrack ) 1140 { 1141 sal_Bool bProtected = pChangeTrack->IsProtected(); 1142 if ( bJustQueryIfProtected && !bProtected ) 1143 return sal_True; 1144 1145 String aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) ); 1146 String aText( ScResId( SCSTR_PASSWORD ) ); 1147 String aPassword; 1148 1149 SfxPasswordDialog* pDlg = new SfxPasswordDialog( 1150 _pParent ? _pParent : GetActiveDialogParent(), &aText ); 1151 pDlg->SetText( aTitle ); 1152 pDlg->SetMinLen( 1 ); 1153 pDlg->SetHelpId( GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand() ); 1154 pDlg->SetEditHelpId( HID_CHG_PROTECT ); 1155 if ( !bProtected ) 1156 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM ); 1157 if ( pDlg->Execute() == RET_OK ) 1158 aPassword = pDlg->GetPassword(); 1159 delete pDlg; 1160 1161 if ( aPassword.Len() ) 1162 { 1163 if ( bProtected ) 1164 { 1165 if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) ) 1166 { 1167 if ( bJustQueryIfProtected ) 1168 bDone = sal_True; 1169 else 1170 pChangeTrack->SetProtection( 1171 com::sun::star::uno::Sequence< sal_Int8 > (0) ); 1172 } 1173 else 1174 { 1175 InfoBox aBox( GetActiveDialogParent(), 1176 String( ScResId( SCSTR_WRONGPASSWORD ) ) ); 1177 aBox.Execute(); 1178 } 1179 } 1180 else 1181 { 1182 com::sun::star::uno::Sequence< sal_Int8 > aPass; 1183 SvPasswordHelper::GetHashPassword( aPass, aPassword ); 1184 pChangeTrack->SetProtection( aPass ); 1185 } 1186 if ( bProtected != pChangeTrack->IsProtected() ) 1187 { 1188 UpdateAcceptChangesDialog(); 1189 bDone = sal_True; 1190 } 1191 } 1192 } 1193 else if ( bJustQueryIfProtected ) 1194 bDone = sal_True; 1195 return bDone; 1196 } 1197 1198 1199 //------------------------------------------------------------------ 1200 1201 void ScDocShell::DoRecalc( sal_Bool bApi ) 1202 { 1203 sal_Bool bDone = sal_False; 1204 ScTabViewShell* pSh = GetBestViewShell(); 1205 if ( pSh ) 1206 { 1207 ScInputHandler* pHdl = SC_MOD()->GetInputHdl(pSh); 1208 if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi ) 1209 { 1210 pHdl->FormulaPreview(); // Teilergebnis als QuickHelp 1211 bDone = sal_True; 1212 } 1213 else 1214 { 1215 pSh->UpdateInputLine(); // InputEnterHandler 1216 pSh->UpdateInputHandler(); 1217 } 1218 } 1219 if (!bDone) // sonst Dokument neu berechnen 1220 { 1221 WaitObject aWaitObj( GetActiveDialogParent() ); 1222 aDocument.CalcFormulaTree(); 1223 if ( pSh ) 1224 pSh->UpdateCharts(sal_True); 1225 1226 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) ); 1227 1228 // #47939# Wenn es Charts gibt, dann alles painten, damit nicht 1229 // PostDataChanged und die Charts nacheinander kommen und Teile 1230 // doppelt gepainted werden. 1231 1232 ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection(); 1233 if ( pCharts && pCharts->GetCount() ) 1234 PostPaintGridAll(); 1235 else 1236 PostDataChanged(); 1237 } 1238 } 1239 1240 void ScDocShell::DoHardRecalc( sal_Bool /* bApi */ ) 1241 { 1242 WaitObject aWaitObj( GetActiveDialogParent() ); 1243 ScTabViewShell* pSh = GetBestViewShell(); 1244 if ( pSh ) 1245 { 1246 pSh->UpdateInputLine(); // InputEnterHandler 1247 pSh->UpdateInputHandler(); 1248 } 1249 aDocument.CalcAll(); 1250 GetDocFunc().DetectiveRefresh(); // erzeugt eigenes Undo 1251 if ( pSh ) 1252 pSh->UpdateCharts(sal_True); 1253 1254 // set notification flags for "calculate" event (used in SFX_HINT_DATACHANGED broadcast) 1255 // (might check for the presence of any formulas on each sheet) 1256 SCTAB nTabCount = aDocument.GetTableCount(); 1257 SCTAB nTab; 1258 if (aDocument.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true )) // search also for VBA hendler 1259 for (nTab=0; nTab<nTabCount; nTab++) 1260 aDocument.SetCalcNotification(nTab); 1261 1262 // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally 1263 // in addition to SFX_HINT_DATACHANGED. 1264 aDocument.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL ) ); 1265 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) ); 1266 1267 // use hard recalc also to disable stream-copying of all sheets 1268 // (somewhat consistent with charts) 1269 for (nTab=0; nTab<nTabCount; nTab++) 1270 if (aDocument.IsStreamValid(nTab)) 1271 aDocument.SetStreamValid(nTab, sal_False); 1272 1273 PostPaintGridAll(); 1274 } 1275 1276 //------------------------------------------------------------------ 1277 1278 void ScDocShell::DoAutoStyle( const ScRange& rRange, const String& rStyle ) 1279 { 1280 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1281 ScStyleSheet* pStyleSheet = 1282 pStylePool->FindCaseIns( rStyle, SFX_STYLE_FAMILY_PARA ); 1283 if (!pStyleSheet) 1284 pStyleSheet = (ScStyleSheet*) 1285 pStylePool->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA ); 1286 if (pStyleSheet) 1287 { 1288 DBG_ASSERT(rRange.aStart.Tab() == rRange.aEnd.Tab(), 1289 "DoAutoStyle mit mehreren Tabellen"); 1290 SCTAB nTab = rRange.aStart.Tab(); 1291 SCCOL nStartCol = rRange.aStart.Col(); 1292 SCROW nStartRow = rRange.aStart.Row(); 1293 SCCOL nEndCol = rRange.aEnd.Col(); 1294 SCROW nEndRow = rRange.aEnd.Row(); 1295 aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet ); 1296 aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab ); 1297 PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PAINT_GRID ); 1298 } 1299 } 1300 1301 //------------------------------------------------------------------ 1302 1303 void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint ) 1304 { 1305 sal_uInt16 nId = rHint.GetHint(); 1306 const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet(); 1307 if (!pStyle) 1308 return; 1309 1310 if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PAGE ) 1311 { 1312 if ( nId == SFX_STYLESHEET_MODIFIED ) 1313 { 1314 ScDocShellModificator aModificator( *this ); 1315 1316 String aNewName = pStyle->GetName(); 1317 String aOldName = aNewName; 1318 sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended); // Name geaendert? 1319 if (bExtended) 1320 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName(); 1321 1322 if ( aNewName != aOldName ) 1323 aDocument.RenamePageStyleInUse( aOldName, aNewName ); 1324 1325 SCTAB nTabCount = aDocument.GetTableCount(); 1326 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 1327 if (aDocument.GetPageStyle(nTab) == aNewName) // schon auf neu angepasst 1328 { 1329 aDocument.PageStyleModified( nTab, aNewName ); 1330 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab ); 1331 aPrintFunc.UpdatePages(); 1332 } 1333 1334 aModificator.SetDocumentModified(); 1335 1336 if (bExtended) 1337 { 1338 SfxBindings* pBindings = GetViewBindings(); 1339 if (pBindings) 1340 { 1341 pBindings->Invalidate( SID_STATUS_PAGESTYLE ); 1342 pBindings->Invalidate( SID_STYLE_FAMILY4 ); 1343 pBindings->Invalidate( FID_RESET_PRINTZOOM ); 1344 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT ); 1345 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT ); 1346 } 1347 } 1348 } 1349 } 1350 else if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PARA ) 1351 { 1352 if ( nId == SFX_STYLESHEET_MODIFIED) 1353 { 1354 String aNewName = pStyle->GetName(); 1355 String aOldName = aNewName; 1356 sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended); 1357 if (bExtended) 1358 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName(); 1359 if ( aNewName != aOldName ) 1360 { 1361 ScConditionalFormatList* pList = aDocument.GetCondFormList(); 1362 if (pList) 1363 pList->RenameCellStyle( aOldName,aNewName ); 1364 } 1365 } 1366 } 1367 1368 // alles andere geht ueber Slots... 1369 } 1370 1371 // wie in printfun.cxx 1372 #define ZOOM_MIN 10 1373 1374 void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages ) 1375 { 1376 sal_Bool bUndo(aDocument.IsUndoEnabled()); 1377 String aStyleName = aDocument.GetPageStyle( nTab ); 1378 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1379 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE ); 1380 DBG_ASSERT( pStyleSheet, "PageStyle not found" ); 1381 if ( pStyleSheet ) 1382 { 1383 ScDocShellModificator aModificator( *this ); 1384 1385 SfxItemSet& rSet = pStyleSheet->GetItemSet(); 1386 if (bUndo) 1387 { 1388 sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue(); 1389 sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue(); 1390 GetUndoManager()->AddUndoAction( new ScUndoPrintZoom( 1391 this, nTab, nOldScale, nOldPages, nScale, nPages ) ); 1392 } 1393 1394 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) ); 1395 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) ); 1396 1397 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab ); 1398 aPrintFunc.UpdatePages(); 1399 aModificator.SetDocumentModified(); 1400 1401 SfxBindings* pBindings = GetViewBindings(); 1402 if (pBindings) 1403 pBindings->Invalidate( FID_RESET_PRINTZOOM ); 1404 } 1405 } 1406 1407 sal_Bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) 1408 { 1409 sal_Bool bChange = sal_False; 1410 SCTAB nTab = rRange.aStart.Tab(); 1411 1412 String aStyleName = aDocument.GetPageStyle( nTab ); 1413 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1414 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE ); 1415 DBG_ASSERT( pStyleSheet, "PageStyle not found" ); 1416 if ( pStyleSheet ) 1417 { 1418 SfxItemSet& rSet = pStyleSheet->GetItemSet(); 1419 sal_Bool bHeaders = ((const SfxBoolItem&)rSet.Get(ATTR_PAGE_HEADERS)).GetValue(); 1420 sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue(); 1421 sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue(); 1422 const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab ); 1423 const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab ); 1424 1425 // benoetigte Skalierung fuer Selektion ausrechnen 1426 1427 sal_uInt16 nNewScale = nOldScale; 1428 1429 long nBlkTwipsX = 0; 1430 if (bHeaders) 1431 nBlkTwipsX += (long) PRINT_HEADER_WIDTH; 1432 SCCOL nStartCol = rRange.aStart.Col(); 1433 SCCOL nEndCol = rRange.aEnd.Col(); 1434 if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() ) 1435 { 1436 for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ ) 1437 nBlkTwipsX += aDocument.GetColWidth( i, nTab ); 1438 if ( nStartCol <= pRepeatCol->aEnd.Col() ) 1439 nStartCol = pRepeatCol->aEnd.Col() + 1; 1440 } 1441 // legacy compilers' own scope for i 1442 { 1443 for ( SCCOL i=nStartCol; i<=nEndCol; i++ ) 1444 nBlkTwipsX += aDocument.GetColWidth( i, nTab ); 1445 } 1446 1447 long nBlkTwipsY = 0; 1448 if (bHeaders) 1449 nBlkTwipsY += (long) PRINT_HEADER_HEIGHT; 1450 SCROW nStartRow = rRange.aStart.Row(); 1451 SCROW nEndRow = rRange.aEnd.Row(); 1452 if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() ) 1453 { 1454 nBlkTwipsY += aDocument.GetRowHeight( pRepeatRow->aStart.Row(), 1455 pRepeatRow->aEnd.Row(), nTab ); 1456 if ( nStartRow <= pRepeatRow->aEnd.Row() ) 1457 nStartRow = pRepeatRow->aEnd.Row() + 1; 1458 } 1459 nBlkTwipsY += aDocument.GetRowHeight( nStartRow, nEndRow, nTab ); 1460 1461 Size aPhysPage; 1462 long nHdr, nFtr; 1463 ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab ); 1464 aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr ); 1465 nBlkTwipsY += nHdr + nFtr; 1466 1467 if ( nBlkTwipsX == 0 ) // #100639# hidden columns/rows may lead to 0 1468 nBlkTwipsX = 1; 1469 if ( nBlkTwipsY == 0 ) 1470 nBlkTwipsY = 1; 1471 1472 long nNeeded = Min( aPhysPage.Width() * 100 / nBlkTwipsX, 1473 aPhysPage.Height() * 100 / nBlkTwipsY ); 1474 if ( nNeeded < ZOOM_MIN ) 1475 nNeeded = ZOOM_MIN; // Begrenzung 1476 if ( nNeeded < (long) nNewScale ) 1477 nNewScale = (sal_uInt16) nNeeded; 1478 1479 bChange = ( nNewScale != nOldScale || nOldPages != 0 ); 1480 if ( bChange ) 1481 SetPrintZoom( nTab, nNewScale, 0 ); 1482 } 1483 return bChange; 1484 } 1485 1486 void ScDocShell::PageStyleModified( const String& rStyleName, sal_Bool bApi ) 1487 { 1488 ScDocShellModificator aModificator( *this ); 1489 1490 sal_Bool bWarn = sal_False; 1491 1492 SCTAB nTabCount = aDocument.GetTableCount(); 1493 SCTAB nUseTab = MAXTAB+1; 1494 for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++) 1495 if ( aDocument.GetPageStyle(nTab) == rStyleName && 1496 ( !bApi || aDocument.GetPageSize(nTab).Width() ) ) 1497 nUseTab = nTab; 1498 // bei bApi nur, wenn Umbrueche schon angezeigt 1499 1500 if (ValidTab(nUseTab)) // nicht verwendet -> nichts zu tun 1501 { 1502 ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab ); //! ohne CountPages auskommen 1503 if (!aPrintFunc.UpdatePages()) // setzt Umbrueche auf allen Tabs 1504 bWarn = sal_True; 1505 1506 if (bWarn && !bApi) 1507 { 1508 ScWaitCursorOff aWaitOff( GetActiveDialogParent() ); 1509 InfoBox aInfoBox(GetActiveDialogParent(), 1510 ScGlobal::GetRscString(STR_PRINT_INVALID_AREA)); 1511 aInfoBox.Execute(); 1512 } 1513 } 1514 1515 aModificator.SetDocumentModified(); 1516 1517 SfxBindings* pBindings = GetViewBindings(); 1518 if (pBindings) 1519 { 1520 pBindings->Invalidate( FID_RESET_PRINTZOOM ); 1521 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT ); 1522 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT ); 1523 } 1524 } 1525 1526 void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller, 1527 SfxRequest& rReq, 1528 SCTAB nCurTab ) 1529 { 1530 const SfxItemSet* pReqArgs = rReq.GetArgs(); 1531 1532 switch ( rReq.GetSlot() ) 1533 { 1534 case SID_STATUS_PAGESTYLE: // Click auf StatusBar-Control 1535 case SID_FORMATPAGE: 1536 { 1537 if ( pReqArgs != NULL ) 1538 { 1539 } 1540 else if ( pReqArgs == NULL ) 1541 { 1542 sal_Bool bUndo(aDocument.IsUndoEnabled()); 1543 String aOldName = aDocument.GetPageStyle( nCurTab ); 1544 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1545 SfxStyleSheetBase* pStyleSheet 1546 = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE ); 1547 1548 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 1549 1550 if ( pStyleSheet ) 1551 { 1552 ScStyleSaveData aOldData; 1553 if (bUndo) 1554 aOldData.InitFromStyle( pStyleSheet ); 1555 1556 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); 1557 1558 //CHINA001 ScStyleDlg* pDlg = new ScStyleDlg( GetActiveDialogParent(), 1559 //CHINA001 *pStyleSheet, 1560 //CHINA001 RID_SCDLG_STYLES_PAGE ); 1561 //CHINA001 1562 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 1563 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 1564 1565 SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE ); 1566 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 1567 1568 if ( pDlg->Execute() == RET_OK ) 1569 { 1570 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); 1571 1572 WaitObject aWait( GetActiveDialogParent() ); 1573 1574 String aNewName = pStyleSheet->GetName(); 1575 if ( aNewName != aOldName && 1576 aDocument.RenamePageStyleInUse( aOldName, aNewName ) ) 1577 { 1578 SfxBindings* pBindings = GetViewBindings(); 1579 if (pBindings) 1580 { 1581 pBindings->Invalidate( SID_STATUS_PAGESTYLE ); 1582 pBindings->Invalidate( FID_RESET_PRINTZOOM ); 1583 } 1584 } 1585 1586 if ( pOutSet ) 1587 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet ); 1588 1589 // merken fuer GetState(): 1590 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn ); 1591 rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT ); 1592 1593 ScStyleSaveData aNewData; 1594 aNewData.InitFromStyle( pStyleSheet ); 1595 if (bUndo) 1596 { 1597 GetUndoManager()->AddUndoAction( 1598 new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE, 1599 aOldData, aNewData ) ); 1600 } 1601 1602 PageStyleModified( aNewName, sal_False ); 1603 rReq.Done(); 1604 } 1605 delete pDlg; 1606 1607 rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY ); 1608 } 1609 } 1610 } 1611 break; 1612 1613 case SID_HFEDIT: 1614 { 1615 if ( pReqArgs != NULL ) 1616 { 1617 } 1618 else if ( pReqArgs == NULL ) 1619 { 1620 String aStr( aDocument.GetPageStyle( nCurTab ) ); 1621 1622 ScStyleSheetPool* pStylePool 1623 = aDocument.GetStyleSheetPool(); 1624 1625 SfxStyleSheetBase* pStyleSheet 1626 = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE ); 1627 1628 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 1629 1630 if ( pStyleSheet ) 1631 { 1632 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); 1633 1634 SvxPageUsage eUsage = 1635 SvxPageUsage( ((const SvxPageItem&) 1636 rStyleSet.Get( ATTR_PAGE )). 1637 GetPageUsage() ); 1638 sal_Bool bShareHeader = IS_SHARE_HEADER(rStyleSet); 1639 sal_Bool bShareFooter = IS_SHARE_FOOTER(rStyleSet); 1640 sal_uInt16 nResId = 0; 1641 1642 switch ( eUsage ) 1643 { 1644 case SVX_PAGE_LEFT: 1645 case SVX_PAGE_RIGHT: 1646 { 1647 if ( bHeaderOn && bFooterOn ) 1648 nResId = RID_SCDLG_HFEDIT; 1649 else if ( SVX_PAGE_RIGHT == eUsage ) 1650 { 1651 if ( !bHeaderOn && bFooterOn ) 1652 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER; 1653 else if ( bHeaderOn && !bFooterOn ) 1654 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER; 1655 } 1656 else 1657 { 1658 // #69193a# respect "shared" setting 1659 if ( !bHeaderOn && bFooterOn ) 1660 nResId = bShareFooter ? 1661 RID_SCDLG_HFEDIT_RIGHTFOOTER : 1662 RID_SCDLG_HFEDIT_LEFTFOOTER; 1663 else if ( bHeaderOn && !bFooterOn ) 1664 nResId = bShareHeader ? 1665 RID_SCDLG_HFEDIT_RIGHTHEADER : 1666 RID_SCDLG_HFEDIT_LEFTHEADER; 1667 } 1668 } 1669 break; 1670 1671 case SVX_PAGE_MIRROR: 1672 case SVX_PAGE_ALL: 1673 default: 1674 { 1675 if ( !bShareHeader && !bShareFooter ) 1676 { 1677 if ( bHeaderOn && bFooterOn ) 1678 nResId = RID_SCDLG_HFEDIT_ALL; 1679 else if ( !bHeaderOn && bFooterOn ) 1680 nResId = RID_SCDLG_HFEDIT_FOOTER; 1681 else if ( bHeaderOn && !bFooterOn ) 1682 nResId = RID_SCDLG_HFEDIT_HEADER; 1683 } 1684 else if ( bShareHeader && bShareFooter ) 1685 { 1686 if ( bHeaderOn && bFooterOn ) 1687 nResId = RID_SCDLG_HFEDIT; 1688 else 1689 { 1690 if ( !bHeaderOn && bFooterOn ) 1691 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER; 1692 else if ( bHeaderOn && !bFooterOn ) 1693 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER; 1694 } 1695 } 1696 else if ( !bShareHeader && bShareFooter ) 1697 { 1698 if ( bHeaderOn && bFooterOn ) 1699 nResId = RID_SCDLG_HFEDIT_SFTR; 1700 else if ( !bHeaderOn && bFooterOn ) 1701 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER; 1702 else if ( bHeaderOn && !bFooterOn ) 1703 nResId = RID_SCDLG_HFEDIT_HEADER; 1704 } 1705 else if ( bShareHeader && !bShareFooter ) 1706 { 1707 if ( bHeaderOn && bFooterOn ) 1708 nResId = RID_SCDLG_HFEDIT_SHDR; 1709 else if ( !bHeaderOn && bFooterOn ) 1710 nResId = RID_SCDLG_HFEDIT_FOOTER; 1711 else if ( bHeaderOn && !bFooterOn ) 1712 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER; 1713 } 1714 } 1715 } 1716 1717 //CHINA001 ScHFEditDlg* pDlg 1718 //CHINA001 = new ScHFEditDlg( SFX_APP()->GetViewFrame(), 1719 //CHINA001 GetActiveDialogParent(), 1720 //CHINA001 rStyleSet, 1721 //CHINA001 aStr, 1722 //CHINA001 nResId ); 1723 //CHINA001 1724 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 1725 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 1726 1727 SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(), 1728 GetActiveDialogParent(), 1729 rStyleSet, 1730 aStr, 1731 RID_SCDLG_HFEDIT, nResId); 1732 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 1733 if ( pDlg->Execute() == RET_OK ) 1734 { 1735 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); 1736 1737 if ( pOutSet ) 1738 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet ); 1739 1740 SetDocumentModified(); 1741 rReq.Done(); 1742 } 1743 delete pDlg; 1744 } 1745 } 1746 } 1747 break; 1748 1749 default: 1750 break; 1751 } 1752 } 1753 1754 void ScDocShell::GetStatePageStyle( SfxViewShell& /* rCaller */, 1755 SfxItemSet& rSet, 1756 SCTAB nCurTab ) 1757 { 1758 SfxWhichIter aIter(rSet); 1759 sal_uInt16 nWhich = aIter.FirstWhich(); 1760 while ( nWhich ) 1761 { 1762 switch (nWhich) 1763 { 1764 case SID_STATUS_PAGESTYLE: 1765 rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) ); 1766 break; 1767 1768 case SID_HFEDIT: 1769 { 1770 String aStr = aDocument.GetPageStyle( nCurTab ); 1771 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1772 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE ); 1773 1774 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 1775 1776 if ( pStyleSheet ) 1777 { 1778 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); 1779 1780 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn ); 1781 1782 if ( !bHeaderOn && !bFooterOn ) 1783 rSet.DisableItem( nWhich ); 1784 } 1785 } 1786 break; 1787 } 1788 1789 nWhich = aIter.NextWhich(); 1790 } 1791 } 1792 1793 void ScDocShell::GetState( SfxItemSet &rSet ) 1794 { 1795 SfxWhichIter aIter(rSet); 1796 sal_uInt16 nWhich = aIter.FirstWhich(); 1797 while ( nWhich ) 1798 { 1799 switch (nWhich) 1800 { 1801 case FID_AUTO_CALC: 1802 if ( (sal_Bool) aDocument.GetHardRecalcState() ) 1803 rSet.DisableItem( nWhich ); 1804 else 1805 rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) ); 1806 break; 1807 1808 case FID_CHG_RECORD: 1809 if ( IsDocShared() ) 1810 rSet.DisableItem( nWhich ); 1811 else 1812 rSet.Put( SfxBoolItem( nWhich, 1813 aDocument.GetChangeTrack() != NULL ) ); 1814 break; 1815 1816 case SID_CHG_PROTECT: 1817 { 1818 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); 1819 if ( pChangeTrack && !IsDocShared() ) 1820 rSet.Put( SfxBoolItem( nWhich, 1821 pChangeTrack->IsProtected() ) ); 1822 else 1823 rSet.DisableItem( nWhich ); 1824 } 1825 break; 1826 1827 case SID_DOCUMENT_COMPARE: 1828 { 1829 if ( IsDocShared() ) 1830 { 1831 rSet.DisableItem( nWhich ); 1832 } 1833 } 1834 break; 1835 1836 // Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein. 1837 // Recalc fuer das Doc war mal wegen #29898# disabled, wenn AutoCalc an war, 1838 // ist jetzt wegen #41540# aber auch immer enabled. 1839 // case FID_RECALC: 1840 // if ( aDocument.GetAutoCalc() ) 1841 // rSet.DisableItem( nWhich ); 1842 // break; 1843 1844 case SID_TABLES_COUNT: 1845 rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) ); 1846 break; 1847 1848 case SID_ATTR_YEAR2000 : 1849 rSet.Put( SfxUInt16Item( nWhich, 1850 aDocument.GetDocOptions().GetYear2000() ) ); 1851 break; 1852 1853 case SID_SHARE_DOC: 1854 { 1855 if ( IsReadOnly() ) 1856 { 1857 rSet.DisableItem( nWhich ); 1858 } 1859 } 1860 break; 1861 1862 default: 1863 { 1864 } 1865 break; 1866 } 1867 1868 nWhich = aIter.NextWhich(); 1869 } 1870 } 1871 1872 void ScDocShell::GetSbxState( SfxItemSet &rSet ) 1873 { 1874 // SID_SC_SELECTION (Selection), 1875 // SID_SC_ACTIVECELL (ActiveCell), 1876 // SID_SC_ACTIVETAB (ActiveTable), 1877 // SID_TABLES_GET (Tables), 1878 // SID_PIVOT_GET (DataPilotTables) - removed (old Basic) 1879 1880 // 1881 // Wenn hier Slots von der View-Shell executed werden, muss auch der 1882 // GetState weitergeleitet werden! 1883 // 1884 1885 ScTabViewShell* pVisibleSh = GetBestViewShell(); // sichtbare View 1886 if ( pVisibleSh ) 1887 pVisibleSh->GetState( rSet ); 1888 } 1889 1890 void __EXPORT ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect ) 1891 { 1892 // bIsOle = sal_True; // jetzt ueber den CreateMode 1893 1894 SCTAB nVisTab = aDocument.GetVisibleTab(); 1895 if (!aDocument.HasTable(nVisTab)) 1896 return; 1897 1898 sal_uLong nOldLayoutMode = pDev->GetLayoutMode(); 1899 pDev->SetLayoutMode( TEXT_LAYOUT_DEFAULT ); // even if it's the same, to get the metafile action 1900 1901 if ( nAspect == ASPECT_THUMBNAIL ) 1902 { 1903 Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL ); 1904 ScViewData aTmpData( this, NULL ); 1905 aTmpData.SetTabNo(nVisTab); 1906 aDocument.SnapVisArea( aBoundRect ); 1907 aTmpData.SetScreen( aBoundRect ); 1908 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True ); 1909 } 1910 else 1911 { 1912 Rectangle aBoundRect = SfxObjectShell::GetVisArea(); 1913 ScViewData aTmpData( this, NULL ); 1914 aTmpData.SetTabNo(nVisTab); 1915 aDocument.SnapVisArea( aBoundRect ); 1916 aTmpData.SetScreen( aBoundRect ); 1917 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True ); 1918 } 1919 1920 pDev->SetLayoutMode( nOldLayoutMode ); 1921 } 1922 1923 Rectangle __EXPORT ScDocShell::GetVisArea( sal_uInt16 nAspect ) const 1924 { 1925 SfxObjectCreateMode eShellMode = GetCreateMode(); 1926 if ( eShellMode == SFX_CREATE_MODE_ORGANIZER ) 1927 { 1928 // ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind 1929 // leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet 1930 return Rectangle(); 1931 } 1932 1933 if( nAspect == ASPECT_THUMBNAIL ) 1934 { 1935 // Rectangle aArea( 0,0, 3175,3175 ); // 120x120 Pixel in 1:1 1936 Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X,SC_PREVIEW_SIZE_Y ); 1937 sal_Bool bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() ); 1938 if ( bNegativePage ) 1939 ScDrawLayer::MirrorRectRTL( aArea ); 1940 aDocument.SnapVisArea( aArea ); 1941 return aArea; 1942 } 1943 else if( nAspect == ASPECT_CONTENT && eShellMode != SFX_CREATE_MODE_EMBEDDED ) 1944 { 1945 // Visarea holen wie nach Load 1946 1947 SCTAB nVisTab = aDocument.GetVisibleTab(); 1948 if (!aDocument.HasTable(nVisTab)) 1949 { 1950 nVisTab = 0; 1951 ((ScDocShell*)this)->aDocument.SetVisibleTab(nVisTab); 1952 } 1953 SCCOL nStartCol; 1954 SCROW nStartRow; 1955 aDocument.GetDataStart( nVisTab, nStartCol, nStartRow ); 1956 SCCOL nEndCol; 1957 SCROW nEndRow; 1958 aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow ); 1959 if (nStartCol>nEndCol) 1960 nStartCol = nEndCol; 1961 if (nStartRow>nEndRow) 1962 nStartRow = nEndRow; 1963 Rectangle aNewArea = ((ScDocument&)aDocument) 1964 .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab ); 1965 //TODO/LATER: different methods for setting VisArea?! 1966 ((ScDocShell*)this)->SfxObjectShell::SetVisArea( aNewArea ); 1967 return aNewArea; 1968 } 1969 else 1970 return SfxObjectShell::GetVisArea( nAspect ); 1971 } 1972 1973 void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet, 1974 SCTAB nCurTab, 1975 sal_Bool& rbHeader, 1976 sal_Bool& rbFooter ) 1977 { 1978 if ( !pStyleSet ) 1979 { 1980 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool(); 1981 SfxStyleSheetBase* pStyleSheet = pStylePool-> 1982 Find( aDocument.GetPageStyle( nCurTab ), 1983 SFX_STYLE_FAMILY_PAGE ); 1984 1985 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 1986 1987 if ( pStyleSheet ) 1988 pStyleSet = &pStyleSheet->GetItemSet(); 1989 else 1990 rbHeader = rbFooter = sal_False; 1991 } 1992 1993 DBG_ASSERT( pStyleSet, "PageStyle-Set not found! :-(" ); 1994 1995 //-------------------------------------------------------------------- 1996 1997 const SvxSetItem* pSetItem = NULL; 1998 const SfxItemSet* pSet = NULL; 1999 2000 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_HEADERSET ); 2001 pSet = &pSetItem->GetItemSet(); 2002 rbHeader = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue(); 2003 2004 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_FOOTERSET ); 2005 pSet = &pSetItem->GetItemSet(); 2006 rbFooter = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue(); 2007 } 2008 2009 long __EXPORT ScDocShell::DdeGetData( const String& rItem, 2010 const String& rMimeType, 2011 ::com::sun::star::uno::Any & rValue ) 2012 { 2013 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ) ) 2014 { 2015 if( rItem.EqualsIgnoreCaseAscii( "Format" ) ) 2016 { 2017 ByteString aFmtByte( aDdeTextFmt, gsl_getSystemTextEncoding() ); 2018 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >( 2019 (sal_Int8*)aFmtByte.GetBuffer(), 2020 aFmtByte.Len() + 1 ); 2021 return 1; 2022 } 2023 ScImportExport aObj( &aDocument, rItem ); 2024 if ( !aObj.IsRef() ) 2025 return 0; // ungueltiger Bereich 2026 2027 if( aDdeTextFmt.GetChar(0) == 'F' ) 2028 aObj.SetFormulas( sal_True ); 2029 if( aDdeTextFmt.EqualsAscii( "SYLK" ) || 2030 aDdeTextFmt.EqualsAscii( "FSYLK" ) ) 2031 { 2032 ByteString aData; 2033 if( aObj.ExportByteString( aData, gsl_getSystemTextEncoding(), 2034 SOT_FORMATSTR_ID_SYLK ) ) 2035 { 2036 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >( 2037 (sal_Int8*)aData.GetBuffer(), 2038 aData.Len() + 1 ); 2039 return 1; 2040 } 2041 else 2042 return 0; 2043 } 2044 if( aDdeTextFmt.EqualsAscii( "CSV" ) || 2045 aDdeTextFmt.EqualsAscii( "FCSV" ) ) 2046 aObj.SetSeparator( ',' ); 2047 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) ); 2048 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0; 2049 } 2050 2051 ScImportExport aObj( &aDocument, rItem ); 2052 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) ); 2053 if( aObj.IsRef() ) 2054 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0; 2055 return 0; 2056 } 2057 2058 long __EXPORT ScDocShell::DdeSetData( const String& rItem, 2059 const String& rMimeType, 2060 const ::com::sun::star::uno::Any & rValue ) 2061 { 2062 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType )) 2063 { 2064 if( rItem.EqualsIgnoreCaseAscii( "Format" ) ) 2065 { 2066 if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, gsl_getSystemTextEncoding() ) ) 2067 { 2068 aDdeTextFmt.ToUpperAscii(); 2069 return 1; 2070 } 2071 return 0; 2072 } 2073 ScImportExport aObj( &aDocument, rItem ); 2074 if( aDdeTextFmt.GetChar(0) == 'F' ) 2075 aObj.SetFormulas( sal_True ); 2076 if( aDdeTextFmt.EqualsAscii( "SYLK" ) || 2077 aDdeTextFmt.EqualsAscii( "FSYLK" ) ) 2078 { 2079 String aData; 2080 if ( ScByteSequenceToString::GetString( aData, rValue, gsl_getSystemTextEncoding() ) ) 2081 { 2082 return aObj.ImportString( aData, SOT_FORMATSTR_ID_SYLK ) ? 1 : 0; 2083 } 2084 return 0; 2085 } 2086 if( aDdeTextFmt.EqualsAscii( "CSV" ) || 2087 aDdeTextFmt.EqualsAscii( "FCSV" ) ) 2088 aObj.SetSeparator( ',' ); 2089 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0; 2090 } 2091 ScImportExport aObj( &aDocument, rItem ); 2092 if( aObj.IsRef() ) 2093 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0; 2094 return 0; 2095 } 2096 2097 ::sfx2::SvLinkSource* __EXPORT ScDocShell::DdeCreateLinkSource( const String& rItem ) 2098 { 2099 // only check for valid item string - range is parsed again in ScServerObject ctor 2100 2101 // named range? 2102 String aPos = rItem; 2103 ScRangeName* pRange = aDocument.GetRangeName(); 2104 if( pRange ) 2105 { 2106 sal_uInt16 nPos; 2107 if( pRange->SearchName( aPos, nPos ) ) 2108 { 2109 ScRangeData* pData = (*pRange)[ nPos ]; 2110 if( pData->HasType( RT_REFAREA ) 2111 || pData->HasType( RT_ABSAREA ) 2112 || pData->HasType( RT_ABSPOS ) ) 2113 pData->GetSymbol( aPos ); // continue with the name's contents 2114 } 2115 } 2116 2117 // Address in DDE function must be always parsed as CONV_OOO so that it 2118 // would always work regardless of current address convension. We do this 2119 // because the address item in a DDE entry is *not* normalized when saved 2120 // into ODF. 2121 ScRange aRange; 2122 bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & SCA_VALID) || 2123 (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & SCA_VALID) ); 2124 2125 ScServerObject* pObj = NULL; // NULL = error 2126 if ( bValid ) 2127 pObj = new ScServerObject( this, rItem ); 2128 2129 // GetLinkManager()->InsertServer() is in the ScServerObject ctor 2130 2131 return pObj; 2132 } 2133 2134 //------------------------------------------------------------------ 2135 2136 ScViewData* ScDocShell::GetViewData() 2137 { 2138 SfxViewShell* pCur = SfxViewShell::Current(); 2139 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pCur); 2140 return pViewSh ? pViewSh->GetViewData() : NULL; 2141 } 2142 2143 //------------------------------------------------------------------ 2144 2145 SCTAB ScDocShell::GetCurTab() 2146 { 2147 //! this must be made non-static and use a ViewShell from this document! 2148 2149 ScViewData* pViewData = GetViewData(); 2150 2151 return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0); 2152 } 2153 2154 ScTabViewShell* ScDocShell::GetBestViewShell( sal_Bool bOnlyVisible ) 2155 { 2156 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); 2157 // falsches Doc? 2158 if( pViewSh && pViewSh->GetViewData()->GetDocShell() != this ) 2159 pViewSh = NULL; 2160 if( !pViewSh ) 2161 { 2162 // 1. ViewShell suchen 2163 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible ); 2164 if( pFrame ) 2165 { 2166 SfxViewShell* p = pFrame->GetViewShell(); 2167 pViewSh = PTR_CAST(ScTabViewShell,p); 2168 } 2169 } 2170 return pViewSh; 2171 } 2172 2173 SfxBindings* ScDocShell::GetViewBindings() 2174 { 2175 // used to invalidate slots after changes to this document 2176 2177 SfxViewShell* pViewSh = GetBestViewShell(); 2178 if (pViewSh) 2179 return &pViewSh->GetViewFrame()->GetBindings(); 2180 else 2181 return NULL; 2182 } 2183 2184 //------------------------------------------------------------------ 2185 2186 ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo ) // static 2187 { 2188 ScDocShell* pFound = NULL; 2189 SfxObjectShell* pShell = SfxObjectShell::GetFirst(); 2190 sal_uInt16 nShellCnt = 0; 2191 2192 while ( pShell && !pFound ) 2193 { 2194 if ( pShell->Type() == TYPE(ScDocShell) ) 2195 { 2196 if ( nShellCnt == nDocNo ) 2197 pFound = (ScDocShell*) pShell; 2198 else 2199 ++nShellCnt; 2200 } 2201 pShell = SfxObjectShell::GetNext( *pShell ); 2202 } 2203 2204 return pFound; 2205 } 2206 2207 //------------------------------------------------------------------ 2208 2209 IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg ) 2210 { 2211 DBG_ASSERT( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" ); 2212 DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" ); 2213 2214 if ( ERRCODE_NONE == _pFileDlg->GetError() ) 2215 { 2216 sal_uInt16 nSlot = pImpl->pRequest->GetSlot(); 2217 SfxMedium* pMed = pImpl->pDocInserter->CreateMedium(); 2218 // #i87094# If a .odt was selected pMed is NULL. 2219 if (pMed) 2220 { 2221 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); 2222 if ( SID_DOCUMENT_COMPARE == nSlot ) 2223 { 2224 if ( pMed->GetFilter() ) 2225 pImpl->pRequest->AppendItem( 2226 SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); 2227 String sOptions = ScDocumentLoader::GetOptions( *pMed ); 2228 if ( sOptions.Len() > 0 ) 2229 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) ); 2230 } 2231 const SfxPoolItem* pItem = NULL; 2232 SfxItemSet* pSet = pMed->GetItemSet(); 2233 if ( pSet && 2234 pSet->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET && 2235 pItem->ISA( SfxInt16Item ) ) 2236 { 2237 pImpl->pRequest->AppendItem( *pItem ); 2238 } 2239 2240 Execute( *(pImpl->pRequest) ); 2241 } 2242 } 2243 2244 pImpl->bIgnoreLostRedliningWarning = false; 2245 return 0; 2246 } 2247 2248 //------------------------------------------------------------------ 2249 2250 void ScDocShell::EnableSharedSettings( bool bEnable ) 2251 { 2252 SetDocumentModified(); 2253 2254 if ( bEnable ) 2255 { 2256 aDocument.EndChangeTracking(); 2257 aDocument.StartChangeTracking(); 2258 2259 // hide accept or reject changes dialog 2260 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId(); 2261 SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 2262 if ( pViewFrame && pViewFrame->HasChildWindow( nId ) ) 2263 { 2264 pViewFrame->ToggleChildWindow( nId ); 2265 SfxBindings* pBindings = GetViewBindings(); 2266 if ( pBindings ) 2267 { 2268 pBindings->Invalidate( FID_CHG_ACCEPT ); 2269 } 2270 } 2271 } 2272 else 2273 { 2274 aDocument.EndChangeTracking(); 2275 } 2276 2277 ScChangeViewSettings aChangeViewSet; 2278 aChangeViewSet.SetShowChanges( sal_False ); 2279 aDocument.SetChangeViewSettings( aChangeViewSet ); 2280 } 2281 2282 uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument() 2283 { 2284 uno::Reference< frame::XModel > xModel; 2285 try 2286 { 2287 SC_MOD()->SetInSharedDocLoading( true ); 2288 uno::Reference< lang::XMultiServiceFactory > xFactory( 2289 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 2290 uno::Reference< frame::XComponentLoader > xLoader( 2291 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ), 2292 uno::UNO_QUERY_THROW ); 2293 uno::Sequence < beans::PropertyValue > aArgs( 1 ); 2294 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Hidden" ); 2295 aArgs[0].Value <<= sal_True; 2296 2297 if ( GetMedium() ) 2298 { 2299 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False); 2300 if ( pPasswordItem && pPasswordItem->GetValue().Len() ) 2301 { 2302 aArgs.realloc( 2 ); 2303 aArgs[1].Name = ::rtl::OUString::createFromAscii( "Password" ); 2304 aArgs[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() ); 2305 } 2306 } 2307 2308 xModel.set( 2309 xLoader->loadComponentFromURL( GetSharedFileURL(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, aArgs ), 2310 uno::UNO_QUERY_THROW ); 2311 SC_MOD()->SetInSharedDocLoading( false ); 2312 } 2313 catch ( uno::Exception& ) 2314 { 2315 DBG_ERROR( "ScDocShell::LoadSharedDocument(): caught exception\n" ); 2316 SC_MOD()->SetInSharedDocLoading( false ); 2317 try 2318 { 2319 uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); 2320 xClose->close( sal_True ); 2321 return uno::Reference< frame::XModel >(); 2322 } 2323 catch ( uno::Exception& ) 2324 { 2325 return uno::Reference< frame::XModel >(); 2326 } 2327 } 2328 return xModel; 2329 } 2330