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