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_sw.hxx" 26 27 #include <hintids.hxx> 28 #include <rtl/logfile.hxx> 29 #include <vcl/msgbox.hxx> 30 #include <vcl/svapp.hxx> 31 #include <vcl/wrkwin.hxx> 32 #include <vcl/jobset.hxx> 33 #include <tools/urlobj.hxx> 34 #include <svl/whiter.hxx> 35 #include <svl/zforlist.hxx> 36 #include <svl/eitem.hxx> 37 #include <svl/stritem.hxx> 38 #include <svl/PasswordHelper.hxx> 39 #include <editeng/adjitem.hxx> 40 #include <basic/sbx.hxx> 41 #include <unotools/moduleoptions.hxx> 42 #include <unotools/misccfg.hxx> 43 #include <sfx2/request.hxx> 44 #include <sfx2/passwd.hxx> 45 #include <sfx2/bindings.hxx> 46 #include <sfx2/docfile.hxx> 47 #include <sfx2/evntconf.hxx> 48 #include <sfx2/docfilt.hxx> 49 #include <sfx2/printer.hxx> 50 #include <sfx2/linkmgr.hxx> 51 #include <svl/srchitem.hxx> 52 #include <editeng/flstitem.hxx> 53 #include <svx/htmlmode.hxx> 54 #include <svtools/soerr.hxx> 55 #include <sot/clsids.hxx> 56 #include <basic/basmgr.hxx> 57 #include <basic/sbmod.hxx> 58 #include <swevent.hxx> 59 #include <fmtpdsc.hxx> 60 #include <fmtfsize.hxx> 61 #include <fmtfld.hxx> 62 #include <node.hxx> 63 #include <swwait.hxx> 64 #include <printdata.hxx> 65 #include <frmatr.hxx> 66 #include <view.hxx> // fuer die aktuelle Sicht 67 #include <edtwin.hxx> 68 #include <PostItMgr.hxx> 69 #include <wrtsh.hxx> // Verbindung zur Core 70 #include <docsh.hxx> // Dokumenterzeugung 71 #include <basesh.hxx> 72 #include <viewopt.hxx> 73 #include <wdocsh.hxx> 74 #include <swmodule.hxx> 75 #include <globdoc.hxx> 76 #include <usrpref.hxx> 77 #include <shellio.hxx> // I/O 78 #include <docstyle.hxx> 79 #include <doc.hxx> 80 #include <unotxdoc.hxx> 81 #include <IDocumentUndoRedo.hxx> 82 #include <docstat.hxx> 83 #include <pagedesc.hxx> 84 #include <pview.hxx> 85 #include <mdiexp.hxx> 86 #include <swbaslnk.hxx> 87 #include <srcview.hxx> 88 #include <ndindex.hxx> 89 #include <ndole.hxx> 90 #include <swcli.hxx> 91 #include <txtftn.hxx> 92 #include <ftnidx.hxx> 93 #include <fldbas.hxx> 94 #include <docary.hxx> 95 #include <swerror.h> // Fehlermeldungen 96 #include <helpid.h> 97 #include <cmdid.h> 98 #include <globals.hrc> 99 #include <app.hrc> 100 101 #include <cfgid.h> 102 #include <unotools/moduleoptions.hxx> 103 #include <unotools/fltrcfg.hxx> 104 #include <svtools/htmlcfg.hxx> 105 #include <sfx2/fcontnr.hxx> 106 #include <sfx2/objface.hxx> 107 #include <comphelper/storagehelper.hxx> 108 109 #define SwDocShell 110 #include <sfx2/msg.hxx> 111 #include <swslots.hxx> 112 #include <com/sun/star/document/UpdateDocMode.hpp> 113 114 #include <com/sun/star/document/XDocumentProperties.hpp> 115 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 116 117 #include <unomid.h> 118 119 #include <sfx2/Metadatable.hxx> 120 #include <switerator.hxx> 121 122 using rtl::OUString; 123 using namespace ::com::sun::star; 124 using namespace ::com::sun::star::uno; 125 using namespace ::com::sun::star::script; 126 using namespace ::com::sun::star::container; 127 128 129 SFX_IMPL_INTERFACE( SwDocShell, SfxObjectShell, SW_RES(0) ) 130 { 131 SFX_CHILDWINDOW_REGISTRATION( SID_HYPERLINK_INSERT ); 132 } 133 134 TYPEINIT2(SwDocShell, SfxObjectShell, SfxListener); 135 136 //------------------------------------------------------------------------- 137 SFX_IMPL_OBJECTFACTORY(SwDocShell, SvGlobalName(SO3_SW_CLASSID), SFXOBJECTSHELL_STD_NORMAL|SFXOBJECTSHELL_HASMENU, "swriter" ) 138 139 /*-------------------------------------------------------------------- 140 Beschreibung: Laden vorbereiten 141 --------------------------------------------------------------------*/ 142 143 144 Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr, 145 SwCrsrShell *pCrsrShell, 146 SwPaM* pPaM ) 147 { 148 sal_Bool bAPICall = sal_False; 149 const SfxPoolItem* pApiItem; 150 const SfxItemSet* pMedSet; 151 if( 0 != ( pMedSet = rMedium.GetItemSet() ) && SFX_ITEM_SET == 152 pMedSet->GetItemState( FN_API_CALL, sal_True, &pApiItem ) ) 153 bAPICall = ((const SfxBoolItem*)pApiItem)->GetValue(); 154 155 const SfxFilter* pFlt = rMedium.GetFilter(); 156 if( !pFlt ) 157 { 158 if(!bAPICall) 159 { 160 InfoBox( 0, SW_RESSTR(STR_CANTOPEN)).Execute(); 161 } 162 return 0; 163 } 164 String aFileName( rMedium.GetName() ); 165 SwRead pRead = SwReaderWriter::GetReader( pFlt->GetUserData() ); 166 if( !pRead ) 167 return 0; 168 169 if( rMedium.IsStorage() 170 ? SW_STORAGE_READER & pRead->GetReaderType() 171 : SW_STREAM_READER & pRead->GetReaderType() ) 172 { 173 *ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) : 174 pCrsrShell ? 175 new SwReader( rMedium, aFileName, *pCrsrShell->GetCrsr() ) 176 : new SwReader( rMedium, aFileName, pDoc ); 177 } 178 else 179 return 0; 180 181 // PassWord Checken 182 String aPasswd; 183 if ((*ppRdr)->NeedsPasswd( *pRead )) 184 { 185 if(!bAPICall) 186 { 187 SfxPasswordDialog* pPasswdDlg = 188 new SfxPasswordDialog( 0 ); 189 if(RET_OK == pPasswdDlg->Execute()) 190 aPasswd = pPasswdDlg->GetPassword(); 191 } 192 else 193 { 194 const SfxItemSet* pSet = rMedium.GetItemSet(); 195 const SfxPoolItem *pPassItem; 196 if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pPassItem)) 197 aPasswd = ((const SfxStringItem *)pPassItem)->GetValue(); 198 } 199 200 if (!(*ppRdr)->CheckPasswd( aPasswd, *pRead )) 201 { 202 InfoBox( 0, SW_RES(MSG_ERROR_PASSWD)).Execute(); 203 delete *ppRdr; 204 return 0; 205 } 206 } 207 208 // #i30171# set the UpdateDocMode at the SwDocShell 209 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False); 210 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE; 211 212 if( pFlt->GetDefaultTemplate().Len() ) 213 pRead->SetTemplateName( pFlt->GetDefaultTemplate() ); 214 215 if( pRead == ReadAscii && 0 != rMedium.GetInStream() && 216 pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) ) 217 { 218 SwAsciiOptions aOpt; 219 const SfxItemSet* pSet; 220 const SfxPoolItem* pItem; 221 if( 0 != ( pSet = rMedium.GetItemSet() ) && SFX_ITEM_SET == 222 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) ) 223 aOpt.ReadUserData( ((const SfxStringItem*)pItem)->GetValue() ); 224 225 if( pRead ) 226 pRead->GetReaderOpt().SetASCIIOpts( aOpt ); 227 } 228 229 return pRead; 230 } 231 232 /*-------------------------------------------------------------------- 233 Beschreibung: Laden 234 --------------------------------------------------------------------*/ 235 236 sal_Bool SwDocShell::ConvertFrom( SfxMedium& rMedium ) 237 { 238 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::ConvertFrom" ); 239 240 SwReader* pRdr; 241 SwRead pRead = StartConvertFrom(rMedium, &pRdr); 242 if (!pRead) 243 return sal_False; // #129881# return if no reader is found 244 SotStorageRef pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls 245 246 SwWait aWait( *this, sal_True ); 247 248 // SfxProgress unterdruecken, wenn man Embedded ist 249 SW_MOD()->SetEmbeddedLoadSave( 250 SFX_CREATE_MODE_EMBEDDED == GetCreateMode() ); 251 252 pRdr->GetDoc()->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell)); 253 254 /* #106748# Restore the pool default if reading a saved document. */ 255 pDoc->RemoveAllFmtLanguageDependencies(); 256 257 sal_uLong nErr = pRdr->Read( *pRead ); 258 259 // Evtl. ein altes Doc weg 260 if ( pDoc != pRdr->GetDoc() ) 261 { 262 if( pDoc ) 263 RemoveLink(); 264 pDoc = pRdr->GetDoc(); 265 266 AddLink(); 267 268 if ( !mxBasePool.is() ) 269 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); 270 } 271 272 UpdateFontList(); 273 InitDraw(); 274 275 delete pRdr; 276 277 SW_MOD()->SetEmbeddedLoadSave( sal_False ); 278 279 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 280 sal_Bool bOk = !IsError( nErr ); 281 282 // --> OD 2006-11-07 #i59688# 283 // // StartFinishedLoading rufen. Nicht bei asynchronen Filtern! 284 // // Diese muessen das selbst rufen! 285 // if( bOk && !pDoc->IsInLoadAsynchron() ) 286 // StartLoadFinishedTimer(); 287 if ( bOk && !pDoc->IsInLoadAsynchron() ) 288 { 289 LoadingFinished(); 290 } 291 // <-- 292 293 pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls 294 295 return bOk; 296 } 297 298 /*-------------------------------------------------------------------- 299 Beschreibung: Sichern des Default-Formats, Stg vorhanden 300 --------------------------------------------------------------------*/ 301 302 303 sal_Bool SwDocShell::Save() 304 { 305 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::Save" ); 306 //#i3370# remove quick help to prevent saving of autocorrection suggestions 307 if(pView) 308 pView->GetEditWin().StopQuickHelp(); 309 SwWait aWait( *this, sal_True ); 310 311 CalcLayoutForOLEObjects(); // format for OLE objets 312 // --> OD 2006-03-17 #i62875# 313 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible 314 if ( pWrtShell && pDoc && 315 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && 316 docfunc::AllDrawObjsOnPage( *pDoc ) ) 317 { 318 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); 319 } 320 // <-- 321 322 sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE; 323 if( SfxObjectShell::Save() ) 324 { 325 switch( GetCreateMode() ) 326 { 327 case SFX_CREATE_MODE_INTERNAL: 328 nErr = 0; 329 break; 330 331 case SFX_CREATE_MODE_ORGANIZER: 332 { 333 WriterRef xWrt; 334 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt ); 335 xWrt->SetOrganizerMode( sal_True ); 336 SwWriter aWrt( *GetMedium(), *pDoc ); 337 nErr = aWrt.Write( xWrt ); 338 xWrt->SetOrganizerMode( sal_False ); 339 } 340 break; 341 342 case SFX_CREATE_MODE_EMBEDDED: 343 // SfxProgress unterdruecken, wenn man Embedded ist 344 SW_MOD()->SetEmbeddedLoadSave( sal_True ); 345 // kein break; 346 347 case SFX_CREATE_MODE_STANDARD: 348 case SFX_CREATE_MODE_PREVIEW: 349 default: 350 { 351 if( pDoc->ContainsMSVBasic() ) 352 { 353 //TODO/MBA: it looks as that this code can be removed! 354 //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() ); 355 //aTmp.SaveOrDelMSVBAStorage( sal_False, aEmptyStr ); 356 if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() ) 357 nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) (*this) ); 358 pDoc->SetContainsMSVBasic( sal_False ); 359 } 360 361 // TabellenBox Edit beenden! 362 if( pWrtShell ) 363 pWrtShell->EndAllTblBoxEdit(); 364 365 WriterRef xWrt; 366 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt ); 367 368 sal_Bool bLockedView(sal_False); 369 if ( pWrtShell ) 370 { 371 bLockedView = pWrtShell->IsViewLocked(); 372 pWrtShell->LockView( sal_True ); //lock visible section 373 } 374 375 SwWriter aWrt( *GetMedium(), *pDoc ); 376 nErr = aWrt.Write( xWrt ); 377 378 if ( pWrtShell ) 379 pWrtShell->LockView( bLockedView ); 380 } 381 break; 382 } 383 SW_MOD()->SetEmbeddedLoadSave( sal_False ); 384 } 385 SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 386 387 SfxViewFrame* pFrm = pWrtShell ? pWrtShell->GetView().GetViewFrame() : 0; 388 if( pFrm ) 389 { 390 pFrm->GetBindings().SetState( SfxStringItem( SID_DOC_MODIFIED, ' ' )); 391 } 392 return !IsError( nErr ); 393 } 394 395 /*-------------------------------------------------------------------- 396 Beschreibung: Sichern im Defaultformat 397 --------------------------------------------------------------------*/ 398 399 400 sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium ) 401 { 402 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SaveAs" ); 403 404 SwWait aWait( *this, sal_True ); 405 //#i3370# remove quick help to prevent saving of autocorrection suggestions 406 if(pView) 407 pView->GetEditWin().StopQuickHelp(); 408 409 //#i91811# mod if we have an active margin window, write back the text 410 if ( pView && 411 pView->GetPostItMgr() && 412 pView->GetPostItMgr()->HasActiveSidebarWin() ) 413 { 414 pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin(); 415 } 416 417 if( pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && 418 !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS) ) 419 RemoveOLEObjects(); 420 421 { 422 // Task 75666 - is the Document imported by our Microsoft-Filters? 423 const SfxFilter* pOldFilter = GetMedium()->GetFilter(); 424 if( pOldFilter && 425 ( pOldFilter->GetUserData().EqualsAscii( FILTER_WW8 ) || 426 pOldFilter->GetUserData().EqualsAscii( "CWW6" ) || 427 pOldFilter->GetUserData().EqualsAscii( "WW6" ) || 428 pOldFilter->GetUserData().EqualsAscii( "WW1" ) )) 429 { 430 // when saving it in our own fileformat, then remove the template 431 // name from the docinfo. 432 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 433 GetModel(), uno::UNO_QUERY_THROW); 434 uno::Reference<document::XDocumentProperties> xDocProps 435 = xDPS->getDocumentProperties(); 436 xDocProps->setTemplateName(::rtl::OUString::createFromAscii("")); 437 xDocProps->setTemplateURL(::rtl::OUString::createFromAscii("")); 438 xDocProps->setTemplateDate(::util::DateTime()); 439 } 440 } 441 442 CalcLayoutForOLEObjects(); // format for OLE objets 443 // --> OD 2006-03-17 #i62875# 444 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible 445 if ( pWrtShell && pDoc && 446 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && 447 docfunc::AllDrawObjsOnPage( *pDoc ) ) 448 { 449 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); 450 } 451 // <-- 452 453 sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE; 454 uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage(); 455 if( SfxObjectShell::SaveAs( rMedium ) ) 456 { 457 if( GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && !ISA( SwGlobalDocShell ) ) 458 { 459 // This is to set the correct class id if SaveAs is 460 // called from SwDoc::SplitDoc to save a normal doc as 461 // global doc. In this case, SaveAs is called at a 462 // normal doc shell, therefore, SfxInplaceObject::SaveAs 463 // will set the wrong class id. 464 SvGlobalName aClassName; 465 String aAppName, aLongUserName, aUserName; 466 467 // The document is closed explicitly, but using SfxObjectShellLock is still more correct here 468 SfxObjectShellLock xDocSh = 469 new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL ); 470 // the global document can not be a template 471 xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), sal_False ); 472 xDocSh->DoClose(); 473 } 474 475 if( pDoc->ContainsMSVBasic() ) 476 { 477 //TODO/MBA: it looks as that this code can be removed! 478 //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() ); 479 //aTmp.SaveOrDelMSVBAStorage( sal_False, aEmptyStr ); 480 if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() ) 481 nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) *this ); 482 pDoc->SetContainsMSVBasic( sal_False ); 483 } 484 485 // TabellenBox Edit beenden! 486 if( pWrtShell ) 487 pWrtShell->EndAllTblBoxEdit(); 488 489 // Modified-Flag merken und erhalten ohne den Link zu Callen 490 // (fuer OLE; nach Anweisung von MM) 491 sal_Bool bIsModified = pDoc->IsModified(); 492 pDoc->GetIDocumentUndoRedo().LockUndoNoModifiedPosition(); 493 Link aOldOLELnk( pDoc->GetOle2Link() ); 494 pDoc->SetOle2Link( Link() ); 495 496 // SfxProgress unterdruecken, wenn man Embedded ist 497 SW_MOD()->SetEmbeddedLoadSave( 498 SFX_CREATE_MODE_EMBEDDED == GetCreateMode() ); 499 500 WriterRef xWrt; 501 ::GetXMLWriter( aEmptyStr, rMedium.GetBaseURL( true ), xWrt ); 502 503 sal_Bool bLockedView(sal_False); 504 if ( pWrtShell ) 505 { 506 bLockedView = pWrtShell->IsViewLocked(); 507 pWrtShell->LockView( sal_True ); //lock visible section 508 } 509 510 SwWriter aWrt( rMedium, *pDoc ); 511 nErr = aWrt.Write( xWrt ); 512 513 if ( pWrtShell ) 514 pWrtShell->LockView( bLockedView ); 515 516 if( bIsModified ) 517 { 518 pDoc->SetModified(); 519 pDoc->GetIDocumentUndoRedo().UnLockUndoNoModifiedPosition(); 520 } 521 pDoc->SetOle2Link( aOldOLELnk ); 522 523 SW_MOD()->SetEmbeddedLoadSave( sal_False ); 524 } 525 SetError( nErr ? nErr : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 526 527 return !IsError( nErr ); 528 } 529 530 /*-------------------------------------------------------------------- 531 Beschreibung: Sichern aller Formate 532 --------------------------------------------------------------------*/ 533 SwSrcView* lcl_GetSourceView( SwDocShell* pSh ) 534 { 535 // sind wir in der SourceView? 536 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( pSh ); 537 SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; 538 return PTR_CAST( SwSrcView, pViewShell); 539 } 540 541 sal_Bool SwDocShell::ConvertTo( SfxMedium& rMedium ) 542 { 543 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::ConvertTo" ); 544 const SfxFilter* pFlt = rMedium.GetFilter(); 545 if( !pFlt ) 546 return sal_False; 547 548 WriterRef xWriter; 549 SwReaderWriter::GetWriter( pFlt->GetUserData(), rMedium.GetBaseURL( true ), xWriter ); 550 if( !xWriter.Is() ) 551 { // Der Filter ist nicht vorhanden 552 InfoBox( 0, 553 SW_RESSTR(STR_DLLNOTFOUND) ).Execute(); 554 return sal_False; 555 } 556 557 //#i3370# remove quick help to prevent saving of autocorrection suggestions 558 if(pView) 559 pView->GetEditWin().StopQuickHelp(); 560 561 //#i91811# mod if we have an active margin window, write back the text 562 if ( pView && 563 pView->GetPostItMgr() && 564 pView->GetPostItMgr()->HasActiveSidebarWin() ) 565 { 566 pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin(); 567 } 568 569 sal_uLong nVBWarning = 0; 570 571 if( pDoc->ContainsMSVBasic() ) 572 { 573 sal_Bool bSave = pFlt->GetUserData().EqualsAscii( "CWW8" ) 574 && SvtFilterOptions::Get()->IsLoadWordBasicStorage(); 575 576 if ( bSave ) 577 { 578 SvStorageRef xStg = new SotStorage( rMedium.GetOutStream(), sal_False ); 579 DBG_ASSERT( !xStg->GetError(), "No storage available for storing VBA macros!" ); 580 if ( !xStg->GetError() ) 581 { 582 nVBWarning = SaveOrDelMSVBAStorage( (SfxObjectShell&) *this, *xStg, bSave, String::CreateFromAscii("Macros") ); 583 xStg->Commit(); 584 pDoc->SetContainsMSVBasic( sal_True ); 585 } 586 } 587 } 588 589 // TabellenBox Edit beenden! 590 if( pWrtShell ) 591 pWrtShell->EndAllTblBoxEdit(); 592 593 if( pFlt->GetUserData().EqualsAscii( "HTML") ) 594 { 595 SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get(); 596 if( !pHtmlOpt->IsStarBasic() && pHtmlOpt->IsStarBasicWarning() && HasBasic() ) 597 { 598 uno::Reference< XLibraryContainer > xLibCont(GetBasicContainer(), UNO_QUERY); 599 uno::Reference< XNameAccess > xLib; 600 Sequence<rtl::OUString> aNames = xLibCont->getElementNames(); 601 const rtl::OUString* pNames = aNames.getConstArray(); 602 for(sal_Int32 nLib = 0; nLib < aNames.getLength(); nLib++) 603 { 604 Any aLib = xLibCont->getByName(pNames[nLib]); 605 aLib >>= xLib; 606 if(xLib.is()) 607 { 608 Sequence<rtl::OUString> aModNames = xLib->getElementNames(); 609 if(aModNames.getLength()) 610 { 611 SetError(WARN_SWG_HTML_NO_MACROS, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 612 break; 613 } 614 } 615 } 616 } 617 UpdateDocInfoForSave(); 618 } 619 620 // --> FME 2007-5-7 #i76360# Update document statistics 621 SwDocStat aDocStat( pDoc->GetDocStat() );; 622 pDoc->UpdateDocStat( aDocStat ); 623 // <-- 624 CalcLayoutForOLEObjects(); // format for OLE objets 625 // --> OD 2006-03-17 #i62875# 626 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible 627 if ( pWrtShell && pDoc && 628 pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && 629 docfunc::AllDrawObjsOnPage( *pDoc ) ) 630 { 631 pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); 632 } 633 // <-- 634 635 if( xWriter->IsStgWriter() && 636 ( /*xWriter->IsSw3Writer() ||*/ 637 pFlt->GetUserData().EqualsAscii( FILTER_XML ) || 638 pFlt->GetUserData().EqualsAscii( FILTER_XMLV ) || 639 pFlt->GetUserData().EqualsAscii( FILTER_XMLVW ) ) ) 640 { 641 // eigenen Typ ermitteln 642 sal_uInt8 nMyType = 0; 643 if( ISA( SwWebDocShell) ) 644 nMyType = 1; 645 else if( ISA( SwGlobalDocShell) ) 646 nMyType = 2; 647 648 // gewuenschten Typ ermitteln 649 sal_uInt8 nSaveType = 0; 650 sal_uLong nSaveClipId = pFlt->GetFormat(); 651 if( SOT_FORMATSTR_ID_STARWRITERWEB_8 == nSaveClipId || 652 SOT_FORMATSTR_ID_STARWRITERWEB_60 == nSaveClipId || 653 SOT_FORMATSTR_ID_STARWRITERWEB_50 == nSaveClipId || 654 SOT_FORMATSTR_ID_STARWRITERWEB_40 == nSaveClipId ) 655 nSaveType = 1; 656 else if( SOT_FORMATSTR_ID_STARWRITERGLOB_8 == nSaveClipId || 657 SOT_FORMATSTR_ID_STARWRITERGLOB_60 == nSaveClipId || 658 SOT_FORMATSTR_ID_STARWRITERGLOB_50 == nSaveClipId || 659 SOT_FORMATSTR_ID_STARWRITERGLOB_40 == nSaveClipId ) 660 nSaveType = 2; 661 662 // Flags am Dokument entsprechend umsetzen 663 sal_Bool bIsHTMLModeSave = GetDoc()->get(IDocumentSettingAccess::HTML_MODE); 664 sal_Bool bIsGlobalDocSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT); 665 sal_Bool bIsGlblDocSaveLinksSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS); 666 if( nMyType != nSaveType ) 667 { 668 GetDoc()->set(IDocumentSettingAccess::HTML_MODE, 1 == nSaveType); 669 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, 2 == nSaveType); 670 if( 2 != nSaveType ) 671 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false); 672 } 673 674 // if the target format is storage based, then the output storage must be already created 675 if ( rMedium.IsStorage() ) 676 { 677 // set MediaType on target storage 678 // (MediaType will be queried during SaveAs) 679 try 680 { 681 // TODO/MBA: testing 682 uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY ); 683 if ( xSet.is() ) 684 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("MediaType"), uno::makeAny( ::rtl::OUString( SotExchange::GetFormatMimeType( nSaveClipId ) ) ) ); 685 } 686 catch ( uno::Exception& ) 687 { 688 } 689 } 690 691 // Jetzt das Dokument normal speichern 692 sal_Bool bRet = SaveAs( rMedium ); 693 694 if( nMyType != nSaveType ) 695 { 696 GetDoc()->set(IDocumentSettingAccess::HTML_MODE, bIsHTMLModeSave ); 697 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, bIsGlobalDocSave); 698 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave); 699 } 700 701 return bRet; 702 } 703 704 if( pFlt->GetUserData().EqualsAscii( FILTER_TEXT_DLG ) && 705 ( pWrtShell || !::lcl_GetSourceView( this ) )) 706 { 707 SwAsciiOptions aOpt; 708 String sItemOpt; 709 const SfxItemSet* pSet; 710 const SfxPoolItem* pItem; 711 if( 0 != ( pSet = rMedium.GetItemSet() ) ) 712 { 713 if( SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS, 714 sal_True, &pItem ) ) 715 sItemOpt = ((const SfxStringItem*)pItem)->GetValue(); 716 } 717 if(sItemOpt.Len()) 718 aOpt.ReadUserData( sItemOpt ); 719 720 xWriter->SetAsciiOptions( aOpt ); 721 } 722 723 // SfxProgress unterdruecken, wenn man Embedded ist 724 SW_MOD()->SetEmbeddedLoadSave( 725 SFX_CREATE_MODE_EMBEDDED == GetCreateMode()); 726 727 // Kontext aufspannen, um die Anzeige der Selektion zu unterbinden 728 sal_uLong nErrno; 729 String aFileName( rMedium.GetName() ); 730 731 //Keine View also das ganze Dokument! 732 if ( pWrtShell ) 733 { 734 SwWait aWait( *this, sal_True ); 735 // --> OD 2009-12-31 #i106906# 736 const sal_Bool bFormerLockView = pWrtShell->IsViewLocked(); 737 pWrtShell->LockView( sal_True ); 738 // <-- 739 pWrtShell->StartAllAction(); 740 pWrtShell->Push(); 741 SwWriter aWrt( rMedium, *pWrtShell, sal_True ); 742 nErrno = aWrt.Write( xWriter, &aFileName ); 743 //JP 16.05.97: falls der SFX uns die View waehrend des speicherns 744 // entzieht 745 if( pWrtShell ) 746 { 747 pWrtShell->Pop(sal_False); 748 pWrtShell->EndAllAction(); 749 // --> OD 2009-12-31 #i106906# 750 pWrtShell->LockView( bFormerLockView ); 751 // <-- 752 } 753 } 754 else 755 { 756 // sind wir in der SourceView? 757 SwSrcView* pSrcView = ::lcl_GetSourceView( this ); 758 if( pSrcView ) 759 { 760 pSrcView->SaveContentTo(rMedium); 761 nErrno = 0; 762 } 763 else 764 { 765 SwWriter aWrt( rMedium, *pDoc ); 766 nErrno = aWrt.Write( xWriter, &aFileName ); 767 } 768 } 769 770 SW_MOD()->SetEmbeddedLoadSave( sal_False ); 771 SetError( nErrno ? nErrno : nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 772 if( !rMedium.IsStorage() ) 773 rMedium.CloseOutStream(); 774 775 return !IsError( nErrno ); 776 } 777 778 /*-------------------------------------------------------------------- 779 Beschreibung: Haende weg 780 --------------------------------------------------------------------*/ 781 782 783 /*-------------------------------------------------------------------- 784 Beschreibung: ??? noch nicht zu aktivieren, muss sal_True liefern 785 --------------------------------------------------------------------*/ 786 787 788 sal_Bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor ) 789 { 790 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SaveCompleted" ); 791 sal_Bool bRet = SfxObjectShell::SaveCompleted( xStor ); 792 if( bRet ) 793 { 794 // erst hier entscheiden, ob das Speichern geklappt hat oder nicht 795 if( IsModified() ) 796 pDoc->SetModified(); 797 else 798 pDoc->ResetModified(); 799 } 800 801 if( pOLEChildList ) 802 { 803 sal_Bool bResetModified = IsEnableSetModified(); 804 if( bResetModified ) 805 EnableSetModified( sal_False ); 806 807 uno::Sequence < rtl::OUString > aNames = pOLEChildList->GetObjectNames(); 808 for( sal_Int32 n = aNames.getLength(); n; n-- ) 809 { 810 if ( !pOLEChildList->MoveEmbeddedObject( aNames[n-1], GetEmbeddedObjectContainer() ) ) 811 { 812 DBG_ERROR( "Copying of objects didn't work!" ); 813 } 814 815 //SvPersist* pPersist = this; 816 //SvInfoObjectRef aRef( pInfList->GetObject( --n )); 817 //pPersist->Move( &aRef, aRef->GetStorageName() ); 818 } 819 820 DELETEZ( pOLEChildList ); 821 if( bResetModified ) 822 EnableSetModified( sal_True ); 823 } 824 825 // #121125#, #122868# 826 // Clean up rendering data created by the usage of <XRenderable> interface 827 // of <SwXDocument> (e.g. export to PDF) and which is not cleaned up by 828 // "rendering the last page". 829 // This is needed to restore former <ViewOptions>. This is performed via 830 // a <ViewShell> reference hold by the rendering data. The rendering data 831 // also needs to loose the hold <ViewShell> reference. Otherwise, the application 832 // will crash on closing the document. 833 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY); 834 ((SwXTextDocument*)xDoc.get())->CleanUpRenderingData(); 835 836 return bRet; 837 } 838 839 /*-------------------------------------------------------------------- 840 Beschreibung: Draw()-Overload fuer OLE2 (Sfx) 841 --------------------------------------------------------------------*/ 842 843 void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup, 844 sal_uInt16 nAspect ) 845 { 846 //fix #25341# Draw sollte das Modified nicht beeinflussen 847 sal_Bool bResetModified; 848 if ( sal_True == (bResetModified = IsEnableSetModified()) ) 849 EnableSetModified( sal_False ); 850 851 //sollte am Document ein JobSetup haengen, dann kopieren wir uns diesen, 852 //um nach dem PrtOle2 diesen wieder am Doc zu verankern. 853 //Einen leeren JobSetup setzen wir nicht ein, denn der wuerde nur zu 854 //fragwuerdigem Ergebnis nach teurer Neuformatierung fuehren (Preview!) 855 JobSetup *pOrig = 0; 856 if ( rSetup.GetPrinterName().Len() && ASPECT_THUMBNAIL != nAspect ) 857 { 858 pOrig = const_cast<JobSetup*>(pDoc->getJobsetup()); 859 if( pOrig ) // dann kopieren wir uns den 860 pOrig = new JobSetup( *pOrig ); 861 pDoc->setJobsetup( rSetup ); 862 } 863 864 Rectangle aRect( nAspect == ASPECT_THUMBNAIL ? 865 GetVisArea( nAspect ) : GetVisArea( ASPECT_CONTENT ) ); 866 867 pDev->Push(); 868 pDev->SetFillColor(); 869 pDev->SetLineColor(); 870 pDev->SetBackground(); 871 sal_Bool bWeb = 0 != PTR_CAST(SwWebDocShell, this); 872 SwPrintData aOpts; 873 ViewShell::PrtOle2( pDoc, SW_MOD()->GetUsrPref(bWeb), aOpts, pDev, aRect ); 874 pDev->Pop(); 875 876 if( pOrig ) 877 { 878 pDoc->setJobsetup( *pOrig ); 879 delete pOrig; 880 } 881 if ( bResetModified ) 882 EnableSetModified( sal_True ); 883 } 884 885 886 void SwDocShell::SetVisArea( const Rectangle &rRect ) 887 { 888 Rectangle aRect( rRect ); 889 if ( pView ) 890 { 891 Size aSz( pView->GetDocSz() ); 892 aSz.Width() += DOCUMENTBORDER; aSz.Height() += DOCUMENTBORDER; 893 long nMoveX = 0, nMoveY = 0; 894 if ( aRect.Right() > aSz.Width() ) 895 nMoveX = aSz.Width() - aRect.Right(); 896 if ( aRect.Bottom() > aSz.Height() ) 897 nMoveY = aSz.Height() - aRect.Bottom(); 898 aRect.Move( nMoveX, nMoveY ); 899 nMoveX = aRect.Left() < 0 ? -aRect.Left() : 0; 900 nMoveY = aRect.Top() < 0 ? -aRect.Top() : 0; 901 aRect.Move( nMoveX, nMoveY ); 902 903 //Ruft das SfxInPlaceObject::SetVisArea()! 904 pView->SetVisArea( aRect, sal_True ); 905 } 906 else 907 SfxObjectShell::SetVisArea( aRect ); 908 } 909 910 911 Rectangle SwDocShell::GetVisArea( sal_uInt16 nAspect ) const 912 { 913 if ( nAspect == ASPECT_THUMBNAIL ) 914 { 915 //PreView: VisArea auf die erste Seite einstellen. 916 SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 1 ); 917 SwCntntNode* pNd = pDoc->GetNodes().GoNext( &aIdx ); 918 919 const SwRect aPageRect = pNd->FindPageFrmRect( sal_False, 0, sal_False ); 920 return aPageRect.SVRect(); 921 } 922 return SfxObjectShell::GetVisArea( nAspect ); 923 } 924 925 Printer *SwDocShell::GetDocumentPrinter() 926 { 927 return pDoc->getPrinter( false ); 928 } 929 930 OutputDevice* SwDocShell::GetDocumentRefDev() 931 { 932 return pDoc->getReferenceDevice( false ); 933 } 934 935 void SwDocShell::OnDocumentPrinterChanged( Printer * pNewPrinter ) 936 { 937 if ( pNewPrinter ) 938 GetDoc()->setJobsetup( pNewPrinter->GetJobSetup() ); 939 else 940 GetDoc()->setPrinter( 0, true, true ); 941 } 942 943 sal_uLong SwDocShell::GetMiscStatus() const 944 { 945 return SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE; 946 } 947 948 // --> FME 2004-08-05 #i20883# Digital Signatures and Encryption 949 sal_uInt16 SwDocShell::GetHiddenInformationState( sal_uInt16 nStates ) 950 { 951 // get global state like HIDDENINFORMATION_DOCUMENTVERSIONS 952 sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates ); 953 954 if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES ) 955 { 956 if ( GetDoc()->GetRedlineTbl().Count() ) 957 nState |= HIDDENINFORMATION_RECORDEDCHANGES; 958 } 959 if ( nStates & HIDDENINFORMATION_NOTES ) 960 { 961 ASSERT( GetWrtShell(), "No SwWrtShell, no information" ) 962 if ( GetWrtShell() ) 963 { 964 SwFieldType* pType = GetWrtShell()->GetFldType( RES_POSTITFLD, aEmptyStr ); 965 SwIterator<SwFmtFld,SwFieldType> aIter( *pType ); 966 SwFmtFld* pFirst = aIter.First(); 967 while( pFirst ) 968 { 969 if( pFirst->GetTxtFld() && pFirst->IsFldInDoc() ) 970 { 971 nState |= HIDDENINFORMATION_NOTES; 972 break; 973 } 974 pFirst = aIter.Next(); 975 } 976 } 977 } 978 979 return nState; 980 } 981 // <-- 982 983 984 /*-------------------------------------------------------------------- 985 Beschreibung: 986 --------------------------------------------------------------------*/ 987 988 989 void SwDocShell::GetState(SfxItemSet& rSet) 990 { 991 SfxWhichIter aIter(rSet); 992 sal_uInt16 nWhich = aIter.FirstWhich(); 993 994 while (nWhich) 995 { 996 switch (nWhich) 997 { 998 case SID_PRINTPREVIEW: 999 { 1000 sal_Bool bDisable = IsInPlaceActive(); 1001 // Disable "multiple layout" 1002 if ( !bDisable ) 1003 { 1004 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this); 1005 while (pTmpFrm) // Preview suchen 1006 { 1007 if ( PTR_CAST(SwView, pTmpFrm->GetViewShell()) && 1008 ((SwView*)pTmpFrm->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() ) 1009 { 1010 bDisable = sal_True; 1011 break; 1012 } 1013 pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this); 1014 } 1015 } 1016 // End of disabled "multiple layout" 1017 if ( bDisable ) 1018 rSet.DisableItem( SID_PRINTPREVIEW ); 1019 else 1020 { 1021 SfxBoolItem aBool( SID_PRINTPREVIEW, sal_False ); 1022 if( PTR_CAST( SwPagePreView, SfxViewShell::Current()) ) 1023 aBool.SetValue( sal_True ); 1024 rSet.Put( aBool ); 1025 } 1026 } 1027 break; 1028 case SID_SOURCEVIEW: 1029 { 1030 SfxViewShell* pCurrView = GetView() ? (SfxViewShell*)GetView() 1031 : SfxViewShell::Current(); 1032 sal_Bool bSourceView = 0 != PTR_CAST(SwSrcView, pCurrView); 1033 rSet.Put(SfxBoolItem(SID_SOURCEVIEW, bSourceView)); 1034 } 1035 break; 1036 case SID_HTML_MODE: 1037 rSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this))); 1038 break; 1039 1040 case FN_ABSTRACT_STARIMPRESS: 1041 case FN_OUTLINE_TO_IMPRESS: 1042 { 1043 SvtModuleOptions aMOpt; 1044 if ( !aMOpt.IsImpress() ) 1045 rSet.DisableItem( nWhich ); 1046 } 1047 /* no break here */ 1048 case FN_ABSTRACT_NEWDOC: 1049 case FN_OUTLINE_TO_CLIPBOARD: 1050 { 1051 if ( !GetDoc()->GetNodes().GetOutLineNds().Count() ) 1052 rSet.DisableItem( nWhich ); 1053 } 1054 break; 1055 case SID_BROWSER_MODE: 1056 case FN_PRINT_LAYOUT: 1057 { 1058 sal_Bool bState = GetDoc()->get(IDocumentSettingAccess::BROWSE_MODE); 1059 if(FN_PRINT_LAYOUT == nWhich) 1060 bState = !bState; 1061 rSet.Put( SfxBoolItem( nWhich, bState)); 1062 } 1063 break; 1064 1065 case FN_NEW_GLOBAL_DOC: 1066 if ( ISA(SwGlobalDocShell) ) 1067 rSet.DisableItem( nWhich ); 1068 break; 1069 1070 case FN_NEW_HTML_DOC: 1071 if( ISA( SwWebDocShell ) ) 1072 rSet.DisableItem( nWhich ); 1073 break; 1074 1075 case SID_ATTR_YEAR2000: 1076 { 1077 const SvNumberFormatter* pFmtr = pDoc->GetNumberFormatter(sal_False); 1078 rSet.Put( SfxUInt16Item( nWhich, 1079 static_cast< sal_uInt16 >( 1080 pFmtr ? pFmtr->GetYear2000() 1081 : ::utl::MiscCfg().GetYear2000() ))); 1082 } 1083 break; 1084 case SID_ATTR_CHAR_FONTLIST: 1085 { 1086 rSet.Put( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) ); 1087 } 1088 break; 1089 case SID_MAIL_PREPAREEXPORT: 1090 { 1091 //check if linked content or possibly hidden content is available 1092 //pDoc->UpdateFlds( NULL, false ); 1093 sfx2::LinkManager& rLnkMgr = pDoc->GetLinkManager(); 1094 const ::sfx2::SvBaseLinks& rLnks = rLnkMgr.GetLinks(); 1095 sal_Bool bRet = sal_False; 1096 if( rLnks.Count() ) 1097 bRet = sal_True; 1098 else 1099 { 1100 //sections with hidden flag, hidden character attribute, hidden paragraph/text or conditional text fields 1101 bRet = pDoc->HasInvisibleContent(); 1102 } 1103 rSet.Put( SfxBoolItem( nWhich, bRet ) ); 1104 } 1105 break; 1106 1107 default: DBG_ASSERT(!this,"Hier darfst Du nicht hinein!"); 1108 1109 } 1110 nWhich = aIter.NextWhich(); 1111 } 1112 } 1113 1114 /*-------------------------------------------------------------------- 1115 Beschreibung: OLE-Hdls 1116 --------------------------------------------------------------------*/ 1117 1118 1119 IMPL_LINK( SwDocShell, Ole2ModifiedHdl, void *, p ) 1120 { 1121 // vom Doc wird der Status mitgegeben (siehe doc.cxx) 1122 // Bit 0: -> alter Zustand 1123 // Bit 1: -> neuer Zustand 1124 long nStatus = (long)p; 1125 if( IsEnableSetModified() ) 1126 SetModified( (nStatus & 2) ? sal_True : sal_False ); 1127 return 0; 1128 } 1129 1130 /*-------------------------------------------------------------------- 1131 Beschreibung: Pool returnen Hier weil virtuelll 1132 --------------------------------------------------------------------*/ 1133 1134 1135 SfxStyleSheetBasePool* SwDocShell::GetStyleSheetPool() 1136 { 1137 return mxBasePool.get(); 1138 } 1139 1140 1141 void SwDocShell::SetView(SwView* pVw) 1142 { 1143 if(0 != (pView = pVw)) 1144 { 1145 pWrtShell = &pView->GetWrtShell(); 1146 } 1147 else 1148 { 1149 pWrtShell = 0; 1150 } 1151 } 1152 1153 1154 void SwDocShell::PrepareReload() 1155 { 1156 ::DelAllGrfCacheEntries( pDoc ); 1157 } 1158 1159 // linked graphics are now loaded on demand. 1160 // Thus, loading of linked graphics no longer needed and necessary for 1161 // the load of document being finished. 1162 void SwDocShell::LoadingFinished() 1163 { 1164 // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because 1165 // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and 1166 // enables the document modification again. 1167 // Thus, manuell modify the document, if its modified and its links are updated 1168 // before <FinishedLoading(..)> is called. 1169 const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() ); 1170 FinishedLoading( SFX_LOADED_ALL ); 1171 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this); 1172 if(pVFrame) 1173 { 1174 SfxViewShell* pShell = pVFrame->GetViewShell(); 1175 if(PTR_CAST(SwSrcView, pShell)) 1176 ((SwSrcView*)pShell)->Load(this); 1177 } 1178 1179 if ( bHasDocToStayModified && !pDoc->IsModified() ) 1180 { 1181 pDoc->SetModified(); 1182 } 1183 } 1184 1185 // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen) 1186 void SwDocShell::CancelTransfers() 1187 { 1188 // alle Links vom LinkManager Canceln 1189 aFinishedTimer.Stop(); 1190 pDoc->GetLinkManager().CancelTransfers(); 1191 SfxObjectShell::CancelTransfers(); 1192 } 1193 1194 SwFEShell* SwDocShell::GetFEShell() 1195 { 1196 return pWrtShell; 1197 } 1198 1199 void SwDocShell::RemoveOLEObjects() 1200 { 1201 SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() ); 1202 for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) 1203 { 1204 SwOLENode* pOLENd = pNd->GetOLENode(); 1205 if( pOLENd && ( pOLENd->IsOLEObjectDeleted() || 1206 pOLENd->IsInGlobalDocSection() ) ) 1207 { 1208 if( !pOLEChildList ) 1209 pOLEChildList = new comphelper::EmbeddedObjectContainer; 1210 1211 ::rtl::OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName(); 1212 GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList ); 1213 } 1214 } 1215 } 1216 1217 // When a document is loaded, SwDoc::PrtOLENotify is called to update 1218 // the sizes of math objects. However, for objects that do not have a 1219 // SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the 1220 // size change takes place later, while calculating the layout in the 1221 // idle handler. If this document is saved now, it is saved with invalid 1222 // sizes. For this reason, the layout has to be calculated before a document is 1223 // saved, but of course only id there are OLE objects with bOLESizeInvalid set. 1224 void SwDocShell::CalcLayoutForOLEObjects() 1225 { 1226 if( !pWrtShell ) 1227 return; 1228 1229 SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() ); 1230 for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) 1231 { 1232 SwOLENode* pOLENd = pNd->GetOLENode(); 1233 if( pOLENd && pOLENd->IsOLESizeInvalid() ) 1234 { 1235 pWrtShell->CalcLayout(); 1236 break; 1237 } 1238 } 1239 } 1240 1241 1242 // --> FME 2005-02-25 #i42634# Overwrites SfxObjectShell::UpdateLinks 1243 // This new function is necessary to trigger update of links in docs 1244 // read by the binary filter: 1245 void SwDocShell::UpdateLinks() 1246 { 1247 GetDoc()->UpdateLinks(sal_True); 1248 // --> FME 2005-07-27 #i50703# Update footnote numbers 1249 SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() ); 1250 SwNodeIndex aTmp( GetDoc()->GetNodes() ); 1251 GetDoc()->GetFtnIdxs().UpdateFtn( aTmp ); 1252 // <-- 1253 } 1254 1255 uno::Reference< frame::XController > 1256 SwDocShell::GetController() 1257 { 1258 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet; 1259 // --> FME 2007-10-15 #i82346# No view in page preview 1260 if ( GetView() ) 1261 // <-- 1262 aRet = GetView()->GetController(); 1263 return aRet; 1264 } 1265 1266 /* -----------------------------12.02.01 12:08-------------------------------- 1267 1268 ---------------------------------------------------------------------------*/ 1269 static const char* s_EventNames[] = 1270 { 1271 "OnPageCountChange", 1272 "OnMailMerge", 1273 "OnMailMergeFinished", 1274 "OnFieldMerge", 1275 "OnFieldMergeFinished", 1276 "OnLayoutFinished" 1277 }; 1278 static sal_Int32 const s_nEvents(sizeof(s_EventNames)/sizeof(s_EventNames[0])); 1279 1280 Sequence< OUString > SwDocShell::GetEventNames() 1281 { 1282 Sequence< OUString > aRet = SfxObjectShell::GetEventNames(); 1283 sal_Int32 nLen = aRet.getLength(); 1284 aRet.realloc(nLen + 6); 1285 OUString* pNames = aRet.getArray(); 1286 pNames[nLen++] = GetEventName(0); 1287 pNames[nLen++] = GetEventName(1); 1288 pNames[nLen++] = GetEventName(2); 1289 pNames[nLen++] = GetEventName(3); 1290 pNames[nLen++] = GetEventName(4); 1291 pNames[nLen] = GetEventName(5); 1292 1293 return aRet; 1294 } 1295 1296 rtl::OUString SwDocShell::GetEventName( sal_Int32 nIndex ) 1297 { 1298 if (nIndex < s_nEvents) 1299 { 1300 return ::rtl::OUString::createFromAscii(s_EventNames[nIndex]); 1301 } 1302 return rtl::OUString(); 1303 } 1304 1305 const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const 1306 { 1307 return pDoc ? &pDoc->GetXmlIdRegistry() : 0; 1308 } 1309 1310 1311 bool SwDocShell::IsChangeRecording() const 1312 { 1313 return (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0; 1314 } 1315 1316 1317 bool SwDocShell::HasChangeRecordProtection() const 1318 { 1319 return pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0; 1320 } 1321 1322 1323 void SwDocShell::SetChangeRecording( bool bActivate ) 1324 { 1325 sal_uInt16 nOn = bActivate ? nsRedlineMode_t::REDLINE_ON : 0; 1326 sal_uInt16 nMode = pWrtShell->GetRedlineMode(); 1327 pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn); 1328 } 1329 1330 1331 bool SwDocShell::SetProtectionPassword( const String &rNewPassword ) 1332 { 1333 const SfxAllItemSet aSet( GetPool() ); 1334 const SfxItemSet* pArgs = &aSet; 1335 const SfxPoolItem* pItem = NULL; 1336 1337 IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess(); 1338 Sequence< sal_Int8 > aPasswd = pIDRA->GetRedlinePassword(); 1339 if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem ) 1340 && ((SfxBoolItem*)pItem)->GetValue() == (aPasswd.getLength() > 0)) 1341 return false; 1342 1343 bool bRes = false; 1344 1345 if (rNewPassword.Len()) 1346 { 1347 // when password protection is applied change tracking must always be active 1348 SetChangeRecording( true ); 1349 1350 Sequence< sal_Int8 > aNewPasswd; 1351 SvPasswordHelper::GetHashPassword( aNewPasswd, rNewPassword ); 1352 pIDRA->SetRedlinePassword( aNewPasswd ); 1353 bRes = true; 1354 } 1355 else 1356 { 1357 pIDRA->SetRedlinePassword( Sequence< sal_Int8 >() ); 1358 bRes = true; 1359 } 1360 1361 return bRes; 1362 } 1363 1364 1365 bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) 1366 { 1367 bool bRes = false; 1368 1369 const SfxAllItemSet aSet( GetPool() ); 1370 const SfxItemSet* pArgs = &aSet; 1371 const SfxPoolItem* pItem = NULL; 1372 1373 IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess(); 1374 Sequence< sal_Int8 > aPasswdHash( pIDRA->GetRedlinePassword() ); 1375 if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem ) 1376 && ((SfxBoolItem*)pItem)->GetValue() == (aPasswdHash.getLength() != 0)) 1377 return false; 1378 rPasswordHash = aPasswdHash; 1379 bRes = true; 1380 1381 return bRes; 1382 } 1383 1384 1385