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