1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include <hintids.hxx>
23 #include <vcl/layout.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/wrkwin.hxx>
27 #include <vcl/jobset.hxx>
28 #include <svl/whiter.hxx>
29 #include <svl/zforlist.hxx>
30 #include <svl/eitem.hxx>
31 #include <svl/stritem.hxx>
32 #include <svl/PasswordHelper.hxx>
33 #include <editeng/adjustitem.hxx>
34 #include <basic/sbx.hxx>
35 #include <unotools/moduleoptions.hxx>
36 #include <unotools/misccfg.hxx>
37 #include <sfx2/request.hxx>
38 #include <sfx2/passwd.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/evntconf.hxx>
42 #include <sfx2/docfilt.hxx>
43 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
44 #include <sfx2/printer.hxx>
45 #include <sfx2/linkmgr.hxx>
46 #include <svl/srchitem.hxx>
47 #include <editeng/flstitem.hxx>
48 #include <sfx2/htmlmode.hxx>
49 #include <svtools/soerr.hxx>
50 #include <comphelper/classids.hxx>
51 #include <basic/basmgr.hxx>
52 #include <basic/sbmod.hxx>
53 #include <swevent.hxx>
54 #include <fmtpdsc.hxx>
55 #include <fmtfsize.hxx>
59 #include <printdata.hxx>
63 #include <PostItMgr.hxx>
67 #include <viewopt.hxx>
69 #include <swmodule.hxx>
70 #include <globdoc.hxx>
71 #include <usrpref.hxx>
72 #include <shellio.hxx>
73 #include <docstyle.hxx>
75 #include <docfunc.hxx>
76 #include <drawdoc.hxx>
77 #include <IDocumentUndoRedo.hxx>
78 #include <IDocumentSettingAccess.hxx>
79 #include <IDocumentLinksAdministration.hxx>
80 #include <IDocumentDeviceAccess.hxx>
81 #include <IDocumentDrawModelAccess.hxx>
82 #include <IDocumentRedlineAccess.hxx>
83 #include <IDocumentStatistics.hxx>
84 #include <IDocumentState.hxx>
85 #include <docstat.hxx>
86 #include <pagedesc.hxx>
89 #include <swbaslnk.hxx>
90 #include <srcview.hxx>
91 #include <ndindex.hxx>
101 #include <globals.hrc>
102 #include <strings.hrc>
105 #include <unotools/fltrcfg.hxx>
106 #include <svtools/htmlcfg.hxx>
107 #include <sfx2/fcontnr.hxx>
108 #include <sfx2/viewfrm.hxx>
109 #include <sfx2/objface.hxx>
110 #include <comphelper/storagehelper.hxx>
113 #include <sfx2/msg.hxx>
114 #include <swslots.hxx>
115 #include <com/sun/star/document/UpdateDocMode.hpp>
117 #include <com/sun/star/document/XDocumentProperties.hpp>
118 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
119 #include <com/sun/star/sdb/DatabaseContext.hpp>
120 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
123 #include <unotextrange.hxx>
125 #include <sfx2/Metadatable.hxx>
126 #include <calbck.hxx>
129 #include <sal/log.hxx>
130 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
132 using namespace ::com::sun::star
;
133 using namespace ::com::sun::star::uno
;
134 using namespace ::com::sun::star::script
;
135 using namespace ::com::sun::star::container
;
137 SFX_IMPL_SUPERCLASS_INTERFACE(SwDocShell
, SfxObjectShell
)
139 void SwDocShell::InitInterface_Impl()
144 SFX_IMPL_OBJECTFACTORY(SwDocShell
, SvGlobalName(SO3_SW_CLASSID
), SfxObjectShellFlags::STD_NORMAL
|SfxObjectShellFlags::HASMENU
, "swriter" )
146 bool SwDocShell::InsertGeneratedStream(SfxMedium
& rMedium
,
147 uno::Reference
<text::XTextRange
> const& xInsertPosition
)
149 SwUnoInternalPaM
aPam(*GetDoc()); // must have doc since called from SwView
150 if (!::sw::XTextRangeToSwPaM(aPam
, xInsertPosition
))
152 // similar to SwView::InsertMedium
153 SwReader
*pReader(nullptr);
154 Reader
*const pRead
= StartConvertFrom(rMedium
, &pReader
, nullptr, &aPam
);
157 ErrCode
const nError
= pReader
->Read(*pRead
);
159 return ERRCODE_NONE
== nError
;
163 Reader
* SwDocShell::StartConvertFrom(SfxMedium
& rMedium
, SwReader
** ppRdr
,
164 SwCursorShell
const *pCursorShell
,
167 bool bAPICall
= false;
168 const SfxPoolItem
* pApiItem
;
169 const SfxItemSet
* pMedSet
;
170 if( nullptr != ( pMedSet
= rMedium
.GetItemSet() ) && SfxItemState::SET
==
171 pMedSet
->GetItemState( FN_API_CALL
, true, &pApiItem
) )
172 bAPICall
= static_cast<const SfxBoolItem
*>(pApiItem
)->GetValue();
174 std::shared_ptr
<const SfxFilter
> pFlt
= rMedium
.GetFilter();
179 ScopedVclPtrInstance
<InfoBox
>(nullptr, SwResId(STR_CANTOPEN
))->Execute();
183 OUString
aFileName( rMedium
.GetName() );
184 SwRead pRead
= SwReaderWriter::GetReader( pFlt
->GetUserData() );
188 if( rMedium
.IsStorage()
189 ? SW_STORAGE_READER
& pRead
->GetReaderType()
190 : SW_STREAM_READER
& pRead
->GetReaderType() )
192 *ppRdr
= pPaM
? new SwReader( rMedium
, aFileName
, *pPaM
) :
194 new SwReader( rMedium
, aFileName
, *pCursorShell
->GetCursor() )
195 : new SwReader( rMedium
, aFileName
, m_xDoc
.get() );
200 // #i30171# set the UpdateDocMode at the SwDocShell
201 const SfxUInt16Item
* pUpdateDocItem
= SfxItemSet::GetItem
<SfxUInt16Item
>(rMedium
.GetItemSet(), SID_UPDATEDOCMODE
, false);
202 m_nUpdateDocMode
= pUpdateDocItem
? pUpdateDocItem
->GetValue() : document::UpdateDocMode::NO_UPDATE
;
204 if (!pFlt
->GetDefaultTemplate().isEmpty())
205 pRead
->SetTemplateName( pFlt
->GetDefaultTemplate() );
207 if( pRead
== ReadAscii
&& nullptr != rMedium
.GetInStream() &&
208 pFlt
->GetUserData() == FILTER_TEXT_DLG
)
211 const SfxItemSet
* pSet
;
212 const SfxPoolItem
* pItem
;
213 if( nullptr != ( pSet
= rMedium
.GetItemSet() ) && SfxItemState::SET
==
214 pSet
->GetItemState( SID_FILE_FILTEROPTIONS
, true, &pItem
) )
215 aOpt
.ReadUserData( static_cast<const SfxStringItem
*>(pItem
)->GetValue() );
218 pRead
->GetReaderOpt().SetASCIIOpts( aOpt
);
225 bool SwDocShell::ConvertFrom( SfxMedium
& rMedium
)
228 SwRead pRead
= StartConvertFrom(rMedium
, &pRdr
);
230 return false; // #129881# return if no reader is found
231 tools::SvRef
<SotStorage
> pStg
=pRead
->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
233 m_xDoc
->setDocAccTitle(OUString());
234 SfxViewFrame
* pFrame1
= SfxViewFrame::GetFirst( this );
237 vcl::Window
* pWindow
= &pFrame1
->GetWindow();
240 vcl::Window
* pSysWin
= pWindow
->GetSystemWindow();
243 pSysWin
->SetAccessibleName(OUString());
247 SwWait
aWait( *this, true );
249 // Suppress SfxProgress, when we are Embedded
250 SW_MOD()->SetEmbeddedLoadSave(
251 SfxObjectCreateMode::EMBEDDED
== GetCreateMode() );
253 pRdr
->GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE
, dynamic_cast< const SwWebDocShell
*>( this ) != nullptr);
255 // Restore the pool default if reading a saved document.
256 m_xDoc
->RemoveAllFormatLanguageDependencies();
258 ErrCode nErr
= pRdr
->Read( *pRead
);
260 // Maybe put away one old Doc
261 if (m_xDoc
.get() != pRdr
->GetDoc())
264 m_xDoc
= pRdr
->GetDoc();
268 if (!m_xBasePool
.is())
269 m_xBasePool
= new SwDocStyleSheetPool( *m_xDoc
, SfxObjectCreateMode::ORGANIZER
== GetCreateMode() );
273 InitDrawModelAndDocShell(this, m_xDoc
? m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
277 SW_MOD()->SetEmbeddedLoadSave( false );
280 bool bOk
= !nErr
.IsError();
282 if (bOk
&& !m_xDoc
->IsInLoadAsynchron())
287 pRead
->setSotStorageRef(pStg
); // #i45333# save sot storage ref in case of recursive calls
292 // Saving the Default-Format, Stg present
293 bool SwDocShell::Save()
295 //#i3370# remove quick help to prevent saving of autocorrection suggestions
297 m_pView
->GetEditWin().StopQuickHelp();
298 SwWait
aWait( *this, true );
300 CalcLayoutForOLEObjects(); // format for OLE objects
302 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
303 if (m_pWrtShell
&& m_xDoc
.get() &&
304 m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
) &&
305 docfunc::AllDrawObjsOnPage(*m_xDoc
))
307 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
, false);
310 ErrCode nErr
= ERR_SWG_WRITE_ERROR
, nVBWarning
= ERRCODE_NONE
;
311 if( SfxObjectShell::Save() )
313 switch( GetCreateMode() )
315 case SfxObjectCreateMode::INTERNAL
:
319 case SfxObjectCreateMode::ORGANIZER
:
322 ::GetXMLWriter( aEmptyOUStr
, GetMedium()->GetBaseURL( true ), xWrt
);
323 xWrt
->SetOrganizerMode( true );
324 SwWriter
aWrt( *GetMedium(), *m_xDoc
);
325 nErr
= aWrt
.Write( xWrt
);
326 xWrt
->SetOrganizerMode( false );
330 case SfxObjectCreateMode::EMBEDDED
:
331 // Suppress SfxProgress, if we are Embedded
332 SW_MOD()->SetEmbeddedLoadSave( true );
335 case SfxObjectCreateMode::STANDARD
:
338 if (m_xDoc
->ContainsMSVBasic())
340 if( SvtFilterOptions::Get().IsLoadWordBasicStorage() )
341 nVBWarning
= GetSaveWarningOfMSVBAStorage( static_cast<SfxObjectShell
&>(*this) );
342 m_xDoc
->SetContainsMSVBasic( false );
345 // End TableBox Edit!
347 m_pWrtShell
->EndAllTableBoxEdit();
350 ::GetXMLWriter( aEmptyOUStr
, GetMedium()->GetBaseURL( true ), xWrt
);
352 bool bLockedView(false);
355 bLockedView
= m_pWrtShell
->IsViewLocked();
356 m_pWrtShell
->LockView( true ); //lock visible section
359 SwWriter
aWrt( *GetMedium(), *m_xDoc
);
360 nErr
= aWrt
.Write( xWrt
);
363 m_pWrtShell
->LockView( bLockedView
);
367 SW_MOD()->SetEmbeddedLoadSave( false );
369 SetError(nErr
? nErr
: nVBWarning
);
371 SfxViewFrame
*const pFrame
=
372 (m_pWrtShell
) ? m_pWrtShell
->GetView().GetViewFrame() : nullptr;
375 pFrame
->GetBindings().SetState(SfxBoolItem(SID_DOC_MODIFIED
, false));
377 return !nErr
.IsError();
380 // Save using the Defaultformat
381 bool SwDocShell::SaveAs( SfxMedium
& rMedium
)
383 SwWait
aWait( *this, true );
384 //#i3370# remove quick help to prevent saving of autocorrection suggestions
386 m_pView
->GetEditWin().StopQuickHelp();
388 //#i91811# mod if we have an active margin window, write back the text
390 m_pView
->GetPostItMgr() &&
391 m_pView
->GetPostItMgr()->HasActiveSidebarWin())
393 m_pView
->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
396 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT
) &&
397 !m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS
))
401 // Task 75666 - is the Document imported by our Microsoft-Filters?
402 std::shared_ptr
<const SfxFilter
> pOldFilter
= GetMedium()->GetFilter();
404 ( pOldFilter
->GetUserData() == FILTER_WW8
||
405 pOldFilter
->GetUserData() == "CWW6" ||
406 pOldFilter
->GetUserData() == "WW6" ) )
408 // when saving it in our own fileformat, then remove the template
409 // name from the docinfo.
410 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
411 GetModel(), uno::UNO_QUERY_THROW
);
412 uno::Reference
<document::XDocumentProperties
> xDocProps
413 = xDPS
->getDocumentProperties();
414 xDocProps
->setTemplateName(OUString());
415 xDocProps
->setTemplateURL(OUString());
416 xDocProps
->setTemplateDate(::util::DateTime());
420 CalcLayoutForOLEObjects(); // format for OLE objects
422 bool bURLChanged
= !GetMedium() || GetMedium()->GetURLObject() != rMedium
.GetURLObject();
423 if (!m_xDoc
->GetDBManager()->getEmbeddedName().isEmpty() && bURLChanged
)
425 // We have an embedded data source definition, need to re-store it,
426 // otherwise relative references will break when the new file is in a
427 // different directory.
428 uno::Reference
<sdb::XDatabaseContext
> xDatabaseContext
= sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
430 const INetURLObject
& rOldURLObject
= GetMedium()->GetURLObject();
431 OUString aURL
= "vnd.sun.star.pkg://";
432 aURL
+= INetURLObject::encode(rOldURLObject
.GetMainURL(INetURLObject::DecodeMechanism::WithCharset
), INetURLObject::PART_AUTHORITY
, INetURLObject::EncodeMechanism::All
);
433 aURL
+= "/" + INetURLObject::encode(m_xDoc
->GetDBManager()->getEmbeddedName(), INetURLObject::PART_FPATH
, INetURLObject::EncodeMechanism::All
);
435 uno::Reference
<sdb::XDocumentDataSource
> xDataSource(xDatabaseContext
->getByName(aURL
), uno::UNO_QUERY
);
436 uno::Reference
<frame::XStorable
> xStorable(xDataSource
->getDatabaseDocument(), uno::UNO_QUERY
);
437 SwDBManager::StoreEmbeddedDataSource(xStorable
, rMedium
.GetOutputStorage(), m_xDoc
->GetDBManager()->getEmbeddedName(), rMedium
.GetName());
441 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
443 m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
) &&
444 docfunc::AllDrawObjsOnPage(*m_xDoc
))
446 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
, false);
449 ErrCode nErr
= ERR_SWG_WRITE_ERROR
, nVBWarning
= ERRCODE_NONE
;
450 uno::Reference
< embed::XStorage
> xStor
= rMedium
.GetOutputStorage();
451 if( SfxObjectShell::SaveAs( rMedium
) )
453 if( GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT
) && dynamic_cast< const SwGlobalDocShell
*>( this ) == nullptr )
455 // The document is closed explicitly, but using SfxObjectShellLock is still more correct here
456 SfxObjectShellLock xDocSh
=
457 new SwGlobalDocShell( SfxObjectCreateMode::INTERNAL
);
458 // the global document can not be a template
459 xDocSh
->SetupStorage( xStor
, SotStorage::GetVersion( xStor
), false );
463 if (m_xDoc
->ContainsMSVBasic())
465 if( SvtFilterOptions::Get().IsLoadWordBasicStorage() )
466 nVBWarning
= GetSaveWarningOfMSVBAStorage( static_cast<SfxObjectShell
&>(*this) );
467 m_xDoc
->SetContainsMSVBasic( false );
472 // End TableBox Edit!
473 m_pWrtShell
->EndAllTableBoxEdit();
475 // Remove invalid signatures.
476 m_pWrtShell
->ValidateAllParagraphSignatures(false);
478 m_pWrtShell
->ClassifyDocPerHighestParagraphClass();
481 // Remember and preserve Modified-Flag without calling the Link
482 // (for OLE; after Statement from MM)
483 const bool bIsModified
= m_xDoc
->getIDocumentState().IsModified();
484 m_xDoc
->GetIDocumentUndoRedo().LockUndoNoModifiedPosition();
485 Link
<bool,void> aOldOLELnk( m_xDoc
->GetOle2Link() );
486 m_xDoc
->SetOle2Link( Link
<bool,void>() );
488 // Suppress SfxProgress when we are Embedded
489 SW_MOD()->SetEmbeddedLoadSave(
490 SfxObjectCreateMode::EMBEDDED
== GetCreateMode() );
493 ::GetXMLWriter( aEmptyOUStr
, rMedium
.GetBaseURL( true ), xWrt
);
495 bool bLockedView(false);
498 bLockedView
= m_pWrtShell
->IsViewLocked();
499 m_pWrtShell
->LockView( true ); //lock visible section
502 SwWriter
aWrt( rMedium
, *m_xDoc
);
503 nErr
= aWrt
.Write( xWrt
);
506 m_pWrtShell
->LockView( bLockedView
);
510 m_xDoc
->getIDocumentState().SetModified();
511 m_xDoc
->GetIDocumentUndoRedo().UnLockUndoNoModifiedPosition();
513 m_xDoc
->SetOle2Link( aOldOLELnk
);
515 SW_MOD()->SetEmbeddedLoadSave( false );
518 m_xDoc
->setRsid( m_xDoc
->getRsid() );
520 m_xDoc
->cleanupUnoCursorTable();
522 SetError(nErr
? nErr
: nVBWarning
);
524 return !nErr
.IsError();
528 static SwSrcView
* lcl_GetSourceView( SwDocShell
const * pSh
)
530 // are we in SourceView?
531 SfxViewFrame
* pVFrame
= SfxViewFrame::GetFirst( pSh
);
532 SfxViewShell
* pViewShell
= pVFrame
? pVFrame
->GetViewShell() : nullptr;
533 return dynamic_cast<SwSrcView
*>( pViewShell
);
536 bool SwDocShell::ConvertTo( SfxMedium
& rMedium
)
538 std::shared_ptr
<const SfxFilter
> pFlt
= rMedium
.GetFilter();
543 SwReaderWriter::GetWriter( pFlt
->GetUserData(), rMedium
.GetBaseURL( true ), xWriter
);
545 { // Filter not available
546 ScopedVclPtrInstance
<InfoBox
>(nullptr, SwResId(STR_DLLNOTFOUND
))->Execute();
550 //#i3370# remove quick help to prevent saving of autocorrection suggestions
552 m_pView
->GetEditWin().StopQuickHelp();
554 //#i91811# mod if we have an active margin window, write back the text
556 m_pView
->GetPostItMgr() &&
557 m_pView
->GetPostItMgr()->HasActiveSidebarWin())
559 m_pView
->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
562 ErrCode nVBWarning
= ERRCODE_NONE
;
564 if (m_xDoc
->ContainsMSVBasic())
566 bool bSave
= pFlt
->GetUserData() == "CWW8"
567 && SvtFilterOptions::Get().IsLoadWordBasicStorage();
571 tools::SvRef
<SotStorage
> xStg
= new SotStorage( rMedium
.GetOutStream(), false );
572 OSL_ENSURE( !xStg
->GetError(), "No storage available for storing VBA macros!" );
573 if ( !xStg
->GetError() )
575 nVBWarning
= SaveOrDelMSVBAStorage( static_cast<SfxObjectShell
&>(*this), *xStg
, bSave
, "Macros" );
577 m_xDoc
->SetContainsMSVBasic( true );
582 // End TableBox Edit!
584 m_pWrtShell
->EndAllTableBoxEdit();
586 if( pFlt
->GetUserData() == "HTML" )
588 #if HAVE_FEATURE_SCRIPTING
589 SvxHtmlOptions
& rHtmlOpt
= SvxHtmlOptions::Get();
590 if( !rHtmlOpt
.IsStarBasic() && rHtmlOpt
.IsStarBasicWarning() && HasBasic() )
592 uno::Reference
< XLibraryContainer
> xLibCont(GetBasicContainer(), UNO_QUERY
);
593 uno::Reference
< XNameAccess
> xLib
;
594 Sequence
<OUString
> aNames
= xLibCont
->getElementNames();
595 const OUString
* pNames
= aNames
.getConstArray();
596 for(sal_Int32 nLib
= 0; nLib
< aNames
.getLength(); nLib
++)
598 Any aLib
= xLibCont
->getByName(pNames
[nLib
]);
602 Sequence
<OUString
> aModNames
= xLib
->getElementNames();
603 if(aModNames
.getLength())
605 SetError(WARN_SWG_HTML_NO_MACROS
);
614 // #i76360# Update document statistics
615 if ( !rMedium
.IsSkipImages() )
616 m_xDoc
->getIDocumentStatistics().UpdateDocStat( false, true );
618 CalcLayoutForOLEObjects(); // format for OLE objects
620 // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
622 m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
) &&
623 docfunc::AllDrawObjsOnPage(*m_xDoc
))
625 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
, false);
628 if( xWriter
->IsStgWriter() &&
629 ( pFlt
->GetUserData() == FILTER_XML
||
630 pFlt
->GetUserData() == FILTER_XMLV
||
631 pFlt
->GetUserData() == FILTER_XMLVW
) )
633 // determine the own Type
634 sal_uInt8 nMyType
= 0;
635 if( dynamic_cast< const SwWebDocShell
*>( this ) != nullptr )
637 else if( dynamic_cast< const SwGlobalDocShell
*>( this ) != nullptr )
640 // determine the desired Type
641 sal_uInt8 nSaveType
= 0;
642 SotClipboardFormatId nSaveClipId
= pFlt
->GetFormat();
643 if( SotClipboardFormatId::STARWRITERWEB_8
== nSaveClipId
||
644 SotClipboardFormatId::STARWRITERWEB_60
== nSaveClipId
||
645 SotClipboardFormatId::STARWRITERWEB_50
== nSaveClipId
||
646 SotClipboardFormatId::STARWRITERWEB_40
== nSaveClipId
)
648 else if( SotClipboardFormatId::STARWRITERGLOB_8
== nSaveClipId
||
649 SotClipboardFormatId::STARWRITERGLOB_8_TEMPLATE
== nSaveClipId
||
650 SotClipboardFormatId::STARWRITERGLOB_60
== nSaveClipId
||
651 SotClipboardFormatId::STARWRITERGLOB_50
== nSaveClipId
||
652 SotClipboardFormatId::STARWRITERGLOB_40
== nSaveClipId
)
655 // Change Flags of the Document accordingly
656 bool bIsHTMLModeSave
= GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
);
657 bool bIsGlobalDocSave
= GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT
);
658 bool bIsGlblDocSaveLinksSave
= GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS
);
659 if( nMyType
!= nSaveType
)
661 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE
, 1 == nSaveType
);
662 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT
, 2 == nSaveType
);
664 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS
, false);
667 // if the target format is storage based, then the output storage must be already created
668 if ( rMedium
.IsStorage() )
670 // set MediaType on target storage
671 // (MediaType will be queried during SaveAs)
675 uno::Reference
< beans::XPropertySet
> xSet( rMedium
.GetStorage(), uno::UNO_QUERY
);
677 xSet
->setPropertyValue("MediaType", uno::makeAny( SotExchange::GetFormatMimeType( nSaveClipId
) ) );
679 catch (const uno::Exception
&)
684 // Now normally save the Document
685 bool bRet
= SaveAs( rMedium
);
687 if( nMyType
!= nSaveType
)
689 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE
, bIsHTMLModeSave
);
690 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT
, bIsGlobalDocSave
);
691 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT_SAVE_LINKS
, bIsGlblDocSaveLinksSave
);
697 if( pFlt
->GetUserData() == FILTER_TEXT_DLG
&&
698 (m_pWrtShell
|| !::lcl_GetSourceView(this)))
702 const SfxItemSet
* pSet
;
703 const SfxPoolItem
* pItem
;
704 if( nullptr != ( pSet
= rMedium
.GetItemSet() ) )
706 if( SfxItemState::SET
== pSet
->GetItemState( SID_FILE_FILTEROPTIONS
,
708 sItemOpt
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
710 if(!sItemOpt
.isEmpty())
711 aOpt
.ReadUserData( sItemOpt
);
713 xWriter
->SetAsciiOptions( aOpt
);
716 // Suppress SfxProgress when we are Embedded
717 SW_MOD()->SetEmbeddedLoadSave(
718 SfxObjectCreateMode::EMBEDDED
== GetCreateMode());
720 // Span Context in order to suppress the Selection's View
722 const OUString
aFileName( rMedium
.GetName() );
724 // No View, so the whole Document!
725 if (m_pWrtShell
&& !Application::IsHeadlessModeEnabled())
727 SwWait
aWait( *this, true );
729 const bool bFormerLockView
= m_pWrtShell
->IsViewLocked();
730 m_pWrtShell
->LockView( true );
731 m_pWrtShell
->StartAllAction();
733 SwWriter
aWrt( rMedium
, *m_pWrtShell
, true );
734 nErrno
= aWrt
.Write( xWriter
, &aFileName
);
735 //JP 16.05.97: In case the SFX revokes the View while saving
738 m_pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
739 m_pWrtShell
->EndAllAction();
741 m_pWrtShell
->LockView( bFormerLockView
);
746 // are we in SourceView?
747 SwSrcView
* pSrcView
= ::lcl_GetSourceView( this );
750 pSrcView
->SaveContentTo(rMedium
);
751 nErrno
= ERRCODE_NONE
;
755 SwWriter
aWrt( rMedium
, *m_xDoc
);
756 nErrno
= aWrt
.Write( xWriter
, &aFileName
);
760 SW_MOD()->SetEmbeddedLoadSave( false );
761 SetError(nErrno
? nErrno
: nVBWarning
);
762 if( !rMedium
.IsStorage() )
763 rMedium
.CloseOutStream();
765 return ! nErrno
.IsError();
769 // do not yet activate, must deliver TRUE
770 bool SwDocShell::SaveCompleted( const uno::Reference
< embed::XStorage
>& xStor
)
772 bool bRet
= SfxObjectShell::SaveCompleted( xStor
);
775 // Do not decide until here, whether Saving was successful or not
777 m_xDoc
->getIDocumentState().SetModified();
779 m_xDoc
->getIDocumentState().ResetModified();
784 bool bResetModified
= IsEnableSetModified();
786 EnableSetModified( false );
788 uno::Sequence
< OUString
> aNames
= m_pOLEChildList
->GetObjectNames();
789 for( sal_Int32 n
= aNames
.getLength(); n
; n
-- )
791 if (!m_pOLEChildList
->MoveEmbeddedObject(aNames
[n
-1], GetEmbeddedObjectContainer()))
793 OSL_FAIL("Copying of objects didn't work!" );
797 DELETEZ(m_pOLEChildList
);
804 // Draw()-Override for OLE2 (Sfx)
805 void SwDocShell::Draw( OutputDevice
* pDev
, const JobSetup
& rSetup
,
808 //fix #25341# Draw should not affect the Modified
809 bool bResetModified
= IsEnableSetModified();
810 if ( bResetModified
)
811 EnableSetModified( false );
813 // When there is a JobSetup connected to the Document, we copy it to
814 // reconnect it after PrtOle2. We don't use an empty JobSetup because
815 // that would only lead to questionable results after expensive
816 // reformatting (Preview!)
817 JobSetup
*pOrig
= nullptr;
818 if ( !rSetup
.GetPrinterName().isEmpty() && ASPECT_THUMBNAIL
!= nAspect
)
820 pOrig
= const_cast<JobSetup
*>(m_xDoc
->getIDocumentDeviceAccess().getJobsetup());
821 if( pOrig
) // then we copy that
822 pOrig
= new JobSetup( *pOrig
);
823 m_xDoc
->getIDocumentDeviceAccess().setJobsetup( rSetup
);
826 tools::Rectangle
aRect( nAspect
== ASPECT_THUMBNAIL
?
827 GetVisArea( nAspect
) : GetVisArea( ASPECT_CONTENT
) );
830 pDev
->SetFillColor();
831 pDev
->SetLineColor();
832 pDev
->SetBackground();
833 const bool bWeb
= dynamic_cast< const SwWebDocShell
*>( this ) != nullptr;
835 SwViewShell::PrtOle2(m_xDoc
.get(), SW_MOD()->GetUsrPref(bWeb
), aOpts
, *pDev
, aRect
);
840 m_xDoc
->getIDocumentDeviceAccess().setJobsetup( *pOrig
);
843 if ( bResetModified
)
847 void SwDocShell::SetVisArea( const tools::Rectangle
&rRect
)
849 tools::Rectangle
aRect( rRect
);
852 Size
aSz( m_pView
->GetDocSz() );
853 aSz
.Width() += DOCUMENTBORDER
; aSz
.Height() += DOCUMENTBORDER
;
854 long nMoveX
= 0, nMoveY
= 0;
855 if ( aRect
.Right() > aSz
.Width() )
856 nMoveX
= aSz
.Width() - aRect
.Right();
857 if ( aRect
.Bottom() > aSz
.Height() )
858 nMoveY
= aSz
.Height() - aRect
.Bottom();
859 aRect
.Move( nMoveX
, nMoveY
);
860 nMoveX
= aRect
.Left() < 0 ? -aRect
.Left() : 0;
861 nMoveY
= aRect
.Top() < 0 ? -aRect
.Top() : 0;
862 aRect
.Move( nMoveX
, nMoveY
);
864 // Calls SfxInPlaceObject::SetVisArea()!
865 m_pView
->SetVisArea( aRect
);
868 SfxObjectShell::SetVisArea( aRect
);
871 tools::Rectangle
SwDocShell::GetVisArea( sal_uInt16 nAspect
) const
873 if ( nAspect
== ASPECT_THUMBNAIL
)
875 // Preview: set VisArea to the first page.
876 SwNodeIndex
aIdx( m_xDoc
->GetNodes().GetEndOfExtras(), 1 );
877 SwContentNode
* pNd
= m_xDoc
->GetNodes().GoNext( &aIdx
);
879 const SwRect aPageRect
= pNd
->FindPageFrameRect();
880 tools::Rectangle
aRect(aPageRect
.SVRect());
882 // tdf#81219 sanitize - nobody is interested in a thumbnail where's
884 if (aRect
.GetHeight() > 2*aRect
.GetWidth())
885 aRect
.SetSize(Size(aRect
.GetWidth(), 2*aRect
.GetWidth()));
886 else if (aRect
.GetWidth() > 2*aRect
.GetHeight())
887 aRect
.SetSize(Size(2*aRect
.GetHeight(), aRect
.GetHeight()));
891 return SfxObjectShell::GetVisArea( nAspect
);
894 Printer
*SwDocShell::GetDocumentPrinter()
896 return m_xDoc
->getIDocumentDeviceAccess().getPrinter( false );
899 OutputDevice
* SwDocShell::GetDocumentRefDev()
901 return m_xDoc
->getIDocumentDeviceAccess().getReferenceDevice( false );
904 void SwDocShell::OnDocumentPrinterChanged( Printer
* pNewPrinter
)
907 GetDoc()->getIDocumentDeviceAccess().setJobsetup( pNewPrinter
->GetJobSetup() );
909 GetDoc()->getIDocumentDeviceAccess().setPrinter( nullptr, true, true );
912 // #i20883# Digital Signatures and Encryption
913 HiddenInformation
SwDocShell::GetHiddenInformationState( HiddenInformation nStates
)
915 // get global state like HiddenInformation::DOCUMENTVERSIONS
916 HiddenInformation nState
= SfxObjectShell::GetHiddenInformationState( nStates
);
918 if ( nStates
& HiddenInformation::RECORDEDCHANGES
)
920 if ( !GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().empty() )
921 nState
|= HiddenInformation::RECORDEDCHANGES
;
923 if ( nStates
& HiddenInformation::NOTES
)
925 OSL_ENSURE( GetWrtShell(), "No SwWrtShell, no information" );
928 SwFieldType
* pType
= GetWrtShell()->GetFieldType( SwFieldIds::Postit
, aEmptyOUStr
);
929 SwIterator
<SwFormatField
,SwFieldType
> aIter( *pType
);
930 SwFormatField
* pFirst
= aIter
.First();
933 if( pFirst
->GetTextField() && pFirst
->IsFieldInDoc() )
935 nState
|= HiddenInformation::NOTES
;
938 pFirst
= aIter
.Next();
946 void SwDocShell::GetState(SfxItemSet
& rSet
)
948 SfxWhichIter
aIter(rSet
);
949 sal_uInt16 nWhich
= aIter
.FirstWhich();
955 case SID_PRINTPREVIEW
:
957 bool bDisable
= IsInPlaceActive();
958 // Disable "multiple layout"
961 SfxViewFrame
*pTmpFrame
= SfxViewFrame::GetFirst(this);
962 while (pTmpFrame
) // Look for Preview
964 if ( dynamic_cast<SwView
*>( pTmpFrame
->GetViewShell() ) &&
965 static_cast<SwView
*>(pTmpFrame
->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() )
970 pTmpFrame
= SfxViewFrame::GetNext(*pTmpFrame
, this);
973 // End of disabled "multiple layout"
975 rSet
.DisableItem( SID_PRINTPREVIEW
);
978 SfxBoolItem
aBool( SID_PRINTPREVIEW
, false );
979 if( dynamic_cast<SwPagePreview
*>( SfxViewShell::Current()) )
980 aBool
.SetValue( true );
987 SfxViewShell
* pCurrView
= GetView() ? static_cast<SfxViewShell
*>(GetView())
988 : SfxViewShell::Current();
989 bool bSourceView
= dynamic_cast<SwSrcView
*>( pCurrView
) != nullptr;
990 rSet
.Put(SfxBoolItem(SID_SOURCEVIEW
, bSourceView
));
994 rSet
.Put(SfxUInt16Item(SID_HTML_MODE
, ::GetHtmlMode(this)));
997 case FN_ABSTRACT_STARIMPRESS
:
998 case FN_OUTLINE_TO_IMPRESS
:
1000 SvtModuleOptions aMOpt
;
1001 if ( !aMOpt
.IsImpress() )
1002 rSet
.DisableItem( nWhich
);
1005 case FN_ABSTRACT_NEWDOC
:
1006 case FN_OUTLINE_TO_CLIPBOARD
:
1008 if ( GetDoc()->GetNodes().GetOutLineNds().empty() )
1009 rSet
.DisableItem( nWhich
);
1012 case SID_BROWSER_MODE
:
1013 case FN_PRINT_LAYOUT
:
1015 bool bState
= GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE
);
1016 if(FN_PRINT_LAYOUT
== nWhich
)
1018 rSet
.Put( SfxBoolItem( nWhich
, bState
));
1022 case FN_NEW_GLOBAL_DOC
:
1023 if ( dynamic_cast< const SwGlobalDocShell
*>( this ) != nullptr )
1024 rSet
.DisableItem( nWhich
);
1027 case FN_NEW_HTML_DOC
:
1028 if( dynamic_cast< const SwWebDocShell
*>( this ) != nullptr )
1029 rSet
.DisableItem( nWhich
);
1033 if( dynamic_cast< const SwWebDocShell
*>( this ) != nullptr )
1034 rSet
.DisableItem( nWhich
);
1037 case SID_ATTR_YEAR2000
:
1039 const SvNumberFormatter
* pFormatr
= m_xDoc
->GetNumberFormatter(false);
1040 rSet
.Put( SfxUInt16Item( nWhich
,
1041 static_cast< sal_uInt16
>(
1042 pFormatr
? pFormatr
->GetYear2000()
1043 : ::utl::MiscCfg().GetYear2000() )));
1046 case SID_ATTR_CHAR_FONTLIST
:
1048 rSet
.Put( SvxFontListItem(m_pFontList
, SID_ATTR_CHAR_FONTLIST
) );
1051 case SID_MAIL_PREPAREEXPORT
:
1053 //check if linked content or possibly hidden content is available
1054 //m_xDoc->UpdateFields( NULL, false );
1055 sfx2::LinkManager
& rLnkMgr
= m_xDoc
->getIDocumentLinksAdministration().GetLinkManager();
1056 const ::sfx2::SvBaseLinks
& rLnks
= rLnkMgr
.GetLinks();
1058 if( !rLnks
.empty() )
1062 //sections with hidden flag, hidden character attribute, hidden paragraph/text or conditional text fields
1063 bRet
= m_xDoc
->HasInvisibleContent();
1065 rSet
.Put( SfxBoolItem( nWhich
, bRet
) );
1068 case SID_NOTEBOOKBAR
:
1070 SfxViewShell
* pViewShell
= GetView()? GetView(): SfxViewShell::Current();
1071 bool bVisible
= sfx2::SfxNotebookBar::StateMethod(pViewShell
->GetViewFrame()->GetBindings(),
1072 "modules/swriter/ui/");
1073 rSet
.Put( SfxBoolItem( SID_NOTEBOOKBAR
, bVisible
) );
1076 case FN_REDLINE_ACCEPT_ALL
:
1077 case FN_REDLINE_REJECT_ALL
:
1079 if (GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().size() == 0)
1080 rSet
.DisableItem(nWhich
);
1084 default: OSL_ENSURE(false,"You cannot get here!");
1087 nWhich
= aIter
.NextWhich();
1092 IMPL_LINK( SwDocShell
, Ole2ModifiedHdl
, bool, bNewStatus
, void )
1094 if( IsEnableSetModified() )
1095 SetModified( bNewStatus
);
1098 // return Pool here, because virtual
1099 SfxStyleSheetBasePool
* SwDocShell::GetStyleSheetPool()
1101 return m_xBasePool
.get();
1104 sfx2::StyleManager
* SwDocShell::GetStyleManager()
1106 return m_pStyleManager
.get();
1109 void SwDocShell::SetView(SwView
* pVw
)
1111 SetViewShell_Impl(pVw
);
1115 m_pWrtShell
= &m_pView
->GetWrtShell();
1117 // Set view-specific redline author.
1118 const OUString
& rRedlineAuthor
= m_pView
->GetRedlineAuthor();
1119 if (!rRedlineAuthor
.isEmpty())
1120 SW_MOD()->SetRedlineAuthor(m_pView
->GetRedlineAuthor());
1123 m_pWrtShell
= nullptr;
1126 void SwDocShell::PrepareReload()
1131 // linked graphics are now loaded on demand.
1132 // Thus, loading of linked graphics no longer needed and necessary for
1133 // the load of document being finished.
1134 void SwDocShell::LoadingFinished()
1137 // Original fix fails after integration of cws xmlsec11:
1138 // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because
1139 // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and
1140 // enables the document modification again.
1141 // Thus, manual modify the document, if it's modified and its links are updated
1142 // before <FinishedLoading(..)> is called.
1143 const bool bHasDocToStayModified( m_xDoc
->getIDocumentState().IsModified() && m_xDoc
->getIDocumentLinksAdministration().LinksUpdated() );
1146 SfxViewFrame
* pVFrame
= SfxViewFrame::GetFirst(this);
1149 SfxViewShell
* pShell
= pVFrame
->GetViewShell();
1150 if(dynamic_cast<SwSrcView
*>( pShell
) )
1151 static_cast<SwSrcView
*>(pShell
)->Load(this);
1155 if ( bHasDocToStayModified
&& !m_xDoc
->getIDocumentState().IsModified() )
1157 m_xDoc
->getIDocumentState().SetModified();
1161 void SwDocShell::SetFormatSpecificCompatibilityOptions( const OUString
& rFilterTypeName
)
1163 //Enable MS Word-compatibility trailing blanks option for MS Word files
1164 if ( rFilterTypeName
== "writer_MS_Word_95" ||
1165 rFilterTypeName
== "writer_MS_Word_97" ||
1166 rFilterTypeName
== "writer_MS_Word_2003_XML" ||
1167 rFilterTypeName
== "writer_MS_Word_2007" ||
1168 rFilterTypeName
== "writer_MS_Word_2007_Template" ||
1169 rFilterTypeName
== "writer_Rich_Text_Format" )
1171 GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS
, true );
1175 // a Transfer is cancelled (is called from SFX)
1176 void SwDocShell::CancelTransfers()
1178 // Cancel all links from LinkManager
1179 m_xDoc
->getIDocumentLinksAdministration().GetLinkManager().CancelTransfers();
1180 SfxObjectShell::CancelTransfers();
1183 SwEditShell
* SwDocShell::GetEditShell()
1188 SwFEShell
* SwDocShell::GetFEShell()
1193 void SwDocShell::RemoveOLEObjects()
1195 SwIterator
<SwContentNode
,SwFormatColl
> aIter( *m_xDoc
->GetDfltGrfFormatColl() );
1196 for( SwContentNode
* pNd
= aIter
.First(); pNd
; pNd
= aIter
.Next() )
1198 SwOLENode
* pOLENd
= pNd
->GetOLENode();
1199 if( pOLENd
&& ( pOLENd
->IsOLEObjectDeleted() ||
1200 pOLENd
->IsInGlobalDocSection() ) )
1202 if (!m_pOLEChildList
)
1203 m_pOLEChildList
= new comphelper::EmbeddedObjectContainer
;
1205 OUString aObjName
= pOLENd
->GetOLEObj().GetCurrentPersistName();
1206 GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName
, *m_pOLEChildList
);
1211 // When a document is loaded, SwDoc::PrtOLENotify is called to update
1212 // the sizes of math objects. However, for objects that do not have a
1213 // SwFrame at this time, only a flag is set (bIsOLESizeInvalid) and the
1214 // size change takes place later, while calculating the layout in the
1215 // idle handler. If this document is saved now, it is saved with invalid
1216 // sizes. For this reason, the layout has to be calculated before a document is
1217 // saved, but of course only id there are OLE objects with bOLESizeInvalid set.
1218 void SwDocShell::CalcLayoutForOLEObjects()
1223 SwIterator
<SwContentNode
,SwFormatColl
> aIter( *m_xDoc
->GetDfltGrfFormatColl() );
1224 for( SwContentNode
* pNd
= aIter
.First(); pNd
; pNd
= aIter
.Next() )
1226 SwOLENode
* pOLENd
= pNd
->GetOLENode();
1227 if( pOLENd
&& pOLENd
->IsOLESizeInvalid() )
1229 m_pWrtShell
->CalcLayout();
1235 // #i42634# Overwrites SfxObjectShell::UpdateLinks
1236 // This new function is necessary to trigger update of links in docs
1237 // read by the binary filter:
1238 void SwDocShell::UpdateLinks()
1240 GetDoc()->getIDocumentLinksAdministration().UpdateLinks();
1241 // #i50703# Update footnote numbers
1242 SwTextFootnote::SetUniqueSeqRefNo( *GetDoc() );
1243 SwNodeIndex
aTmp( GetDoc()->GetNodes() );
1244 GetDoc()->GetFootnoteIdxs().UpdateFootnote( aTmp
);
1247 uno::Reference
< frame::XController
>
1248 SwDocShell::GetController()
1250 css::uno::Reference
< css::frame::XController
> aRet
;
1251 // #i82346# No view in page preview
1253 aRet
= GetView()->GetController();
1257 static const char* s_EventNames
[] =
1259 "OnPageCountChange",
1261 "OnMailMergeFinished",
1263 "OnFieldMergeFinished",
1266 static sal_Int32
const s_nEvents(SAL_N_ELEMENTS(s_EventNames
));
1268 Sequence
< OUString
> SwDocShell::GetEventNames()
1270 Sequence
< OUString
> aRet
= SfxObjectShell::GetEventNames();
1271 sal_Int32 nLen
= aRet
.getLength();
1272 aRet
.realloc(nLen
+ 6);
1273 OUString
* pNames
= aRet
.getArray();
1274 pNames
[nLen
++] = GetEventName(0);
1275 pNames
[nLen
++] = GetEventName(1);
1276 pNames
[nLen
++] = GetEventName(2);
1277 pNames
[nLen
++] = GetEventName(3);
1278 pNames
[nLen
++] = GetEventName(4);
1279 pNames
[nLen
] = GetEventName(5);
1284 OUString
SwDocShell::GetEventName( sal_Int32 nIndex
)
1286 if (nIndex
< s_nEvents
)
1288 return OUString::createFromAscii(s_EventNames
[nIndex
]);
1293 const ::sfx2::IXmlIdRegistry
* SwDocShell::GetXmlIdRegistry() const
1295 return m_xDoc
.get() ? &m_xDoc
->GetXmlIdRegistry() : nullptr;
1298 bool SwDocShell::IsChangeRecording() const
1302 return bool(m_pWrtShell
->GetRedlineFlags() & RedlineFlags::On
);
1305 bool SwDocShell::HasChangeRecordProtection() const
1309 return m_pWrtShell
->getIDocumentRedlineAccess().GetRedlinePassword().getLength() > 0;
1312 void SwDocShell::SetChangeRecording( bool bActivate
)
1314 RedlineFlags nOn
= bActivate
? RedlineFlags::On
: RedlineFlags::NONE
;
1315 RedlineFlags nMode
= m_pWrtShell
->GetRedlineFlags();
1316 m_pWrtShell
->SetRedlineFlagsAndCheckInsMode( (nMode
& ~RedlineFlags::On
) | nOn
);
1319 void SwDocShell::SetProtectionPassword( const OUString
&rNewPassword
)
1321 const SfxAllItemSet
aSet( GetPool() );
1322 const SfxPoolItem
* pItem
= nullptr;
1324 IDocumentRedlineAccess
& rIDRA
= m_pWrtShell
->getIDocumentRedlineAccess();
1325 Sequence
< sal_Int8
> aPasswd
= rIDRA
.GetRedlinePassword();
1326 if (SfxItemState::SET
== aSet
.GetItemState(FN_REDLINE_PROTECT
, false, &pItem
)
1327 && static_cast<const SfxBoolItem
*>(pItem
)->GetValue() == (aPasswd
.getLength() > 0))
1330 if (!rNewPassword
.isEmpty())
1332 // when password protection is applied change tracking must always be active
1333 SetChangeRecording( true );
1335 Sequence
< sal_Int8
> aNewPasswd
;
1336 SvPasswordHelper::GetHashPassword( aNewPasswd
, rNewPassword
);
1337 rIDRA
.SetRedlinePassword( aNewPasswd
);
1341 rIDRA
.SetRedlinePassword( Sequence
< sal_Int8
>() );
1345 bool SwDocShell::GetProtectionHash( /*out*/ css::uno::Sequence
< sal_Int8
> &rPasswordHash
)
1349 const SfxAllItemSet
aSet( GetPool() );
1350 const SfxItemSet
* pArgs
= &aSet
;
1351 const SfxPoolItem
* pItem
= nullptr;
1353 IDocumentRedlineAccess
& rIDRA
= m_pWrtShell
->getIDocumentRedlineAccess();
1354 Sequence
< sal_Int8
> aPasswdHash( rIDRA
.GetRedlinePassword() );
1355 if (pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( FN_REDLINE_PROTECT
, false, &pItem
)
1356 && static_cast<const SfxBoolItem
*>(pItem
)->GetValue() == (aPasswdHash
.getLength() != 0))
1358 rPasswordHash
= aPasswdHash
;
1364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */