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