Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / app / docsh2.cxx
blob4de0e8eae7ed874d6673581ebb314a283c70d964
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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 <osl/diagnose.h>
23 #include <com/sun/star/drawing/ModuleDispatcher.hpp>
24 #include <com/sun/star/frame/DispatchHelper.hpp>
25 #include <ooo/vba/word/XDocument.hpp>
26 #include <comphelper/fileformat.h>
27 #include <comphelper/processfactory.hxx>
28 #include <comphelper/propertyvalue.hxx>
29 #include <comphelper/string.hxx>
31 #include <sal/log.hxx>
32 #include <edtwin.hxx>
33 #include <tools/urlobj.hxx>
34 #include <unotools/tempfile.hxx>
35 #include <unotools/configmgr.hxx>
36 #include <vcl/errinf.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/weld.hxx>
39 #include <svl/eitem.hxx>
40 #include <svl/macitem.hxx>
41 #include <unotools/pathoptions.hxx>
42 #include <vcl/transfer.hxx>
43 #include <sfx2/dinfdlg.hxx>
44 #include <sfx2/request.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/new.hxx>
47 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
48 #include <sfx2/filedlghelper.hxx>
49 #include <sfx2/printer.hxx>
50 #include <sfx2/evntconf.hxx>
51 #include <sfx2/docfile.hxx>
52 #include <sfx2/docfilt.hxx>
53 #include <svx/dialogs.hrc>
54 #include <svx/drawitem.hxx>
55 #include <editeng/svxacorr.hxx>
56 #include <svx/fmshell.hxx>
57 #include <sfx2/linkmgr.hxx>
58 #include <sfx2/classificationhelper.hxx>
59 #include <sfx2/watermarkitem.hxx>
61 #include <svx/ofaitem.hxx>
62 #include <SwSmartTagMgr.hxx>
63 #include <sfx2/app.hxx>
64 #include <basic/sbstar.hxx>
65 #include <basic/basmgr.hxx>
66 #include <comphelper/classids.hxx>
67 #include <fmtcol.hxx>
68 #include <istype.hxx>
69 #include <view.hxx>
70 #include <docsh.hxx>
71 #include <docary.hxx>
72 #include <wrtsh.hxx>
73 #include <rootfrm.hxx>
74 #include <fldbas.hxx>
75 #include <viewopt.hxx>
76 #include <globdoc.hxx>
77 #include <fldwrap.hxx>
78 #include <redlndlg.hxx>
79 #include <doc.hxx>
80 #include <IDocumentUndoRedo.hxx>
81 #include <IDocumentSettingAccess.hxx>
82 #include <IDocumentDeviceAccess.hxx>
83 #include <IDocumentLinksAdministration.hxx>
84 #include <IDocumentFieldsAccess.hxx>
85 #include <IDocumentStatistics.hxx>
86 #include <IDocumentLayoutAccess.hxx>
87 #include <IDocumentRedlineAccess.hxx>
88 #include <IDocumentState.hxx>
89 #include <shellio.hxx>
90 #include <pview.hxx>
91 #include <srcview.hxx>
92 #include <wdocsh.hxx>
93 #include <unotxdoc.hxx>
94 #include <acmplwrd.hxx>
95 #include <swmodule.hxx>
96 #include <unobaseclass.hxx>
97 #include <swwait.hxx>
98 #include <swcli.hxx>
100 #include <cmdid.h>
101 #include <helpids.h>
102 #include <strings.hrc>
103 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
104 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
105 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
106 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
107 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
108 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
109 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
110 #include <com/sun/star/script/vba/VBAEventId.hpp>
111 #include <editeng/acorrcfg.hxx>
112 #include <officecfg/Office/Security.hxx>
113 #include <officecfg/Office/Common.hxx>
115 #include <sfx2/fcontnr.hxx>
116 #include <svx/ClassificationDialog.hxx>
117 #include <svtools/embedhlp.hxx>
119 #include <swabstdlg.hxx>
120 #include <watermarkdialog.hxx>
122 #include <ndtxt.hxx>
123 #include <iodetect.hxx>
125 #include <memory>
127 using namespace ::com::sun::star::ui::dialogs;
128 using namespace ::com::sun::star::lang;
129 using namespace ::com::sun::star::uno;
130 using namespace ::com::sun::star;
131 using namespace ::sfx2;
133 // create DocInfo (virtual)
134 std::shared_ptr<SfxDocumentInfoDialog> SwDocShell::CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet &rSet)
136 std::shared_ptr<SfxDocumentInfoDialog> xDlg = std::make_shared<SfxDocumentInfoDialog>(pParent, rSet);
137 //only with statistics, when this document is being shown, not
138 //from within the Doc-Manager
139 SwDocShell* pDocSh = static_cast<SwDocShell*>( SfxObjectShell::Current());
140 if( pDocSh == this )
142 //Not for SourceView.
143 SfxViewShell *pVSh = SfxViewShell::Current();
144 if ( pVSh && dynamic_cast< const SwSrcView *>( pVSh ) == nullptr )
146 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
147 xDlg->AddFontTabPage();
148 xDlg->AddTabPage("writerstats", SwResId(STR_DOC_STAT), pFact->GetTabPageCreatorFunc(RID_SW_TP_DOC_STAT));
151 return xDlg;
154 void SwDocShell::ToggleLayoutMode(SwView* pView)
156 OSL_ENSURE( pView, "SwDocShell::ToggleLayoutMode, pView is null." );
158 const SwViewOption& rViewOptions = *pView->GetWrtShell().GetViewOptions();
160 //TODO: Should HideWhitespace flag be saved in the document settings?
161 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, rViewOptions.getBrowseMode());
162 UpdateFontList(); // Why is this necessary here?
164 pView->GetViewFrame().GetBindings().Invalidate(FN_SHADOWCURSOR);
165 if( !GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) )
166 pView->SetPrinter( GetDoc()->getIDocumentDeviceAccess().getPrinter( false ), SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP );
167 GetDoc()->CheckDefaultPageFormat();
168 SfxViewFrame *pTmpFrame = SfxViewFrame::GetFirst(this, false);
169 while (pTmpFrame)
171 if( pTmpFrame != &pView->GetViewFrame() )
173 pTmpFrame->DoClose();
174 pTmpFrame = SfxViewFrame::GetFirst(this, false);
176 else
177 pTmpFrame = SfxViewFrame::GetNext(*pTmpFrame, this, false);
180 pView->GetWrtShell().InvalidateLayout(true);
182 pView->RecheckBrowseMode();
184 pView->SetNewWindowAllowed(!rViewOptions.getBrowseMode());
187 // update text fields on document properties changes
188 void SwDocShell::DoFlushDocInfo()
190 if (!m_xDoc)
191 return;
193 bool bUnlockView(true);
194 if (m_pWrtShell)
196 bUnlockView = !m_pWrtShell->IsViewLocked();
197 m_pWrtShell->LockView( true ); // lock visible section
198 m_pWrtShell->StartAllAction();
201 m_xDoc->getIDocumentStatistics().DocInfoChgd(IsEnableSetModified());
203 if (m_pWrtShell)
205 m_pWrtShell->EndAllAction();
206 if (bUnlockView)
208 m_pWrtShell->LockView( false );
213 static void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint )
215 using namespace com::sun::star::script::vba::VBAEventId;
216 const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
217 if ( !pSfxEventHint )
218 return;
220 uno::Sequence< uno::Any > aArgs;
221 switch( pSfxEventHint->GetEventId() )
223 case SfxEventHintId::CreateDoc:
224 xVbaEvents->processVbaEvent(AUTO_NEW, aArgs);
225 xVbaEvents->processVbaEvent(DOCUMENT_NEW, aArgs);
226 break;
227 case SfxEventHintId::OpenDoc:
228 xVbaEvents->processVbaEvent(AUTO_OPEN, aArgs);
229 xVbaEvents->processVbaEvent(DOCUMENT_OPEN, aArgs);
230 break;
231 default: break;
235 // Notification on DocInfo changes
236 void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
238 if (!m_xDoc)
240 return ;
243 uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents =
244 m_xDoc->GetVbaEventProcessor();
245 if( xVbaEvents.is() )
246 lcl_processCompatibleSfxHint( xVbaEvents, rHint );
248 if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
250 switch( pSfxEventHint->GetEventId() )
252 case SfxEventHintId::ActivateDoc:
253 case SfxEventHintId::CreateDoc:
254 case SfxEventHintId::OpenDoc:
256 uno::Sequence< css::uno::Any > aArgs;
257 SW_MOD()->CallAutomationApplicationEventSinks( "DocumentChange", aArgs );
258 break;
260 default:
261 break;
264 switch( pSfxEventHint->GetEventId() )
266 case SfxEventHintId::CreateDoc:
268 uno::Any aDocument;
269 aDocument <<= mxAutomationDocumentObject;
270 uno::Sequence< uno::Any > aArgs{ aDocument };
271 SW_MOD()->CallAutomationApplicationEventSinks( "NewDocument", aArgs );
273 break;
274 case SfxEventHintId::OpenDoc:
276 uno::Any aDocument;
277 aDocument <<= mxAutomationDocumentObject;
278 uno::Sequence< uno::Any > aArgs{ aDocument };
279 SW_MOD()->CallAutomationApplicationEventSinks( "DocumentOpen", aArgs );
281 break;
282 default:
283 break;
287 sal_uInt16 nAction = 0;
288 auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
289 if( pEventHint && pEventHint->GetEventId() == SfxEventHintId::LoadFinished )
291 // #i38126# - own action id
292 nAction = 3;
294 else
296 // switch for more actions
297 if( rHint.GetId() == SfxHintId::TitleChanged)
299 if( GetMedium() )
300 nAction = 2;
304 if( !nAction )
305 return;
307 bool bUnlockView = true; //initializing prevents warning
308 if (m_pWrtShell)
310 bUnlockView = !m_pWrtShell->IsViewLocked();
311 m_pWrtShell->LockView( true ); //lock visible section
312 m_pWrtShell->StartAllAction();
314 switch( nAction )
316 case 2:
317 m_xDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::Filename )->UpdateFields();
318 break;
319 // #i38126# - own action for event LOADFINISHED
320 // in order to avoid a modified document.
321 // #i41679# - Also for the instance of <SwDoc>
322 // it has to be assured, that it's not modified.
323 // Perform the same as for action id 1, but disable <SetModified>.
324 case 3:
326 const bool bResetModified = IsEnableSetModified();
327 if ( bResetModified )
328 EnableSetModified( false );
329 // #i41679#
330 const bool bIsDocModified = m_xDoc->getIDocumentState().IsModified();
331 // TODO: is the ResetModified() below because of only the direct call from DocInfoChgd, or does UpdateFields() set it too?
333 m_xDoc->getIDocumentStatistics().DocInfoChgd(false);
335 // #i41679#
336 if ( !bIsDocModified )
337 m_xDoc->getIDocumentState().ResetModified();
338 if ( bResetModified )
339 EnableSetModified();
341 break;
344 if (m_pWrtShell)
346 m_pWrtShell->EndAllAction();
347 if( bUnlockView )
348 m_pWrtShell->LockView( false );
352 // Notification Close Doc
353 bool SwDocShell::PrepareClose( bool bUI )
355 bool bRet = SfxObjectShell::PrepareClose( bUI );
357 // If we are going to close it at this point, let potential DocumentBeforeClose event handlers
358 // in Automation clients veto it.
359 if (bRet && m_xDoc && IsInPrepareClose())
361 uno::Any aDocument;
362 aDocument <<= mxAutomationDocumentObject;
364 uno::Sequence<uno::Any> aArgs{ // Arg 0: Document
365 aDocument,
366 // Arg 1: Cancel
367 uno::Any(false)
370 SW_MOD()->CallAutomationApplicationEventSinks( "DocumentBeforeClose", aArgs );
372 // If the Cancel argument was set to True by an event handler, return false.
373 bool bCancel(false);
374 aArgs[1] >>= bCancel;
375 if (bCancel)
376 bRet = false;
379 if( bRet )
380 EndListening( *this );
382 if (m_xDoc && IsInPrepareClose())
384 uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents =
385 m_xDoc->GetVbaEventProcessor();
386 if( xVbaEvents.is() )
388 using namespace com::sun::star::script::vba::VBAEventId;
389 uno::Sequence< uno::Any > aNoArgs;
390 xVbaEvents->processVbaEvent(AUTO_CLOSE, aNoArgs);
391 xVbaEvents->processVbaEvent(DOCUMENT_CLOSE, aNoArgs);
394 return bRet;
397 void SwDocShell::Execute(SfxRequest& rReq)
399 const SfxItemSet* pArgs = rReq.GetArgs();
400 const SfxPoolItem* pItem;
401 sal_uInt16 nWhich = rReq.GetSlot();
402 bool bDone = false;
403 switch ( nWhich )
405 case SID_AUTO_CORRECT_DLG:
407 SvxSwAutoFormatFlags* pAFlags = &SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags();
408 SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords();
410 bool bOldLocked = rACW.IsLockWordLstLocked(),
411 bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords;
413 rACW.SetLockWordLstLocked( true );
415 editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList().createNonOwningCopy() );
416 pAFlags->m_pAutoCompleteList = &aTmpLst;
418 SfxApplication* pApp = SfxGetpApp();
419 SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SfxCallMode::SYNCHRON, pApp->GetPool());
420 SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, true );
421 aAppReq.AppendItem(aSwOptions);
423 pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get();
425 SfxItemSetFixed<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS> aSet( pApp->GetPool() );
426 aSet.Put( aSwOptions );
428 const SfxBoolItem* pOpenSmartTagOptionsItem = nullptr;
429 if( pArgs && (pOpenSmartTagOptionsItem = pArgs->GetItemIfSet( SID_OPEN_SMARTTAGOPTIONS, false )) )
430 aSet.Put( *pOpenSmartTagOptionsItem );
432 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
433 VclPtr<SfxAbstractTabDialog> pDlg = pFact->CreateAutoCorrTabDialog(GetView()->GetFrameWeld(), &aSet);
434 pDlg->Execute();
435 pDlg.disposeAndClear();
438 rACW.SetLockWordLstLocked( bOldLocked );
440 SwEditShell::SetAutoFormatFlags( pAFlags );
441 rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen );
442 rACW.SetMaxCount( pAFlags->nAutoCmpltListLen );
443 if (pAFlags->m_pAutoCompleteList) // any changes?
445 rACW.CheckChangedList( aTmpLst );
446 // clear the temp WordList pointer
447 pAFlags->m_pAutoCompleteList = nullptr;
450 if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords !=
451 pAFlags->bAutoCmpltCollectWords )
453 // call on all Docs the idle formatter to start
454 // the collection of Words
455 for( SwDocShell *pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetFirst(checkSfxObjectShell<SwDocShell>));
456 pDocSh;
457 pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetNext( *pDocSh, checkSfxObjectShell<SwDocShell> )) )
459 SwDoc* pTmp = pDocSh->GetDoc();
460 if ( pTmp->getIDocumentLayoutAccess().GetCurrentViewShell() )
461 pTmp->InvalidateAutoCompleteFlag();
465 break;
467 case SID_PRINTPREVIEW:
469 bool bSet = false;
470 bool bFound = false, bOnly = true;
471 SfxViewFrame *pTmpFrame = SfxViewFrame::GetFirst(this);
472 SfxViewShell* pViewShell = SfxViewShell::Current();
473 SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell );
474 bool bCurrent = isType<SwPagePreview>( pViewShell );
476 while( pTmpFrame ) // search Preview
478 if( isType<SwView>( pTmpFrame->GetViewShell()) )
479 bOnly = false;
480 else if( isType<SwPagePreview>( pTmpFrame->GetViewShell()))
482 pTmpFrame->GetFrame().Appear();
483 bFound = true;
485 if( bFound && !bOnly )
486 break;
487 pTmpFrame = SfxViewFrame::GetNext(*pTmpFrame, this);
490 if( pArgs && SfxItemState::SET ==
491 pArgs->GetItemState( SID_PRINTPREVIEW, false, &pItem ))
492 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
493 else
494 bSet = !bCurrent;
496 sal_uInt16 nSlotId = 0;
497 if( bSet && !bFound ) // Nothing found, so create new Preview
498 nSlotId = SID_VIEWSHELL1;
499 else if( bFound && !bSet )
500 nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1;
502 if( nSlotId )
504 // PagePreview in the WebDocShell
505 // is found under Id VIEWSHELL2.
506 if( dynamic_cast< const SwWebDocShell *>( this ) != nullptr && SID_VIEWSHELL1 == nSlotId )
507 nSlotId = SID_VIEWSHELL2;
509 if( pCurrView && pCurrView->GetDocShell() == this )
510 pTmpFrame = &pCurrView->GetViewFrame();
511 else
512 pTmpFrame = SfxViewFrame::GetFirst( this );
514 if (pTmpFrame)
515 pTmpFrame->GetDispatcher()->Execute( nSlotId, SfxCallMode::ASYNCHRON );
518 rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet ));
520 break;
521 case SID_TEMPLATE_LOAD:
523 OUString aFileName;
524 static bool bText = true;
525 static bool bFrame = false;
526 static bool bPage = false;
527 static bool bNum = false;
528 static bool bMerge = false;
530 SfxTemplateFlags nFlags = bFrame ? SfxTemplateFlags::LOAD_FRAME_STYLES : SfxTemplateFlags::NONE;
531 if(bPage)
532 nFlags |= SfxTemplateFlags::LOAD_PAGE_STYLES;
533 if(bNum)
534 nFlags |= SfxTemplateFlags::LOAD_NUM_STYLES;
535 if(nFlags == SfxTemplateFlags::NONE || bText)
536 nFlags |= SfxTemplateFlags::LOAD_TEXT_STYLES;
537 if(bMerge)
538 nFlags |= SfxTemplateFlags::MERGE_STYLES;
540 if ( pArgs )
542 const SfxStringItem* pTemplateItem = rReq.GetArg<SfxStringItem>(SID_TEMPLATE_NAME);
543 if ( pTemplateItem )
545 aFileName = pTemplateItem->GetValue();
546 const SfxInt32Item* pFlagsItem = rReq.GetArg<SfxInt32Item>(SID_TEMPLATE_LOAD);
547 if ( pFlagsItem )
548 nFlags = static_cast<SfxTemplateFlags>(o3tl::narrowing<sal_uInt16>(pFlagsItem->GetValue()));
552 if ( aFileName.isEmpty() )
554 SfxNewFileDialog aNewFileDlg(GetView()->GetFrameWeld(), SfxNewFileDialogMode::LoadTemplate);
555 aNewFileDlg.SetTemplateFlags(nFlags);
557 sal_uInt16 nRet = aNewFileDlg.run();
558 if(RET_TEMPLATE_LOAD == nRet)
560 FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
561 FileDialogFlags::NONE, GetView()->GetFrameWeld());
562 aDlgHelper.SetContext(FileDialogHelper::WriterLoadTemplate);
563 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
565 SfxObjectFactory &rFact = GetFactory();
566 SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
567 SfxFilterMatcherIter aIter( aMatcher );
568 std::shared_ptr<const SfxFilter> pFlt = aIter.First();
569 while( pFlt )
571 // --> OD #i117339#
572 if( pFlt && pFlt->IsAllowedAsTemplate() &&
573 ( pFlt->GetUserData() == "CXML" ||
574 pFlt->GetUserData() == "CXMLV" ) )
576 const OUString sWild = pFlt->GetWildcard().getGlob();
577 xFP->appendFilter( pFlt->GetUIName(), sWild );
579 pFlt = aIter.Next();
581 bool bWeb = dynamic_cast< SwWebDocShell *>( this ) != nullptr;
582 std::shared_ptr<const SfxFilter> pOwnFlt =
583 SwDocShell::Factory().GetFilterContainer()->
584 GetFilter4FilterName("writer8");
586 // make sure the default file format is also available
587 if(bWeb)
589 const OUString sWild = pOwnFlt->GetWildcard().getGlob();
590 xFP->appendFilter( pOwnFlt->GetUIName(), sWild );
593 bool bError = false;
594 // catch exception if wrong filter is selected - should not happen anymore
597 xFP->setCurrentFilter( pOwnFlt->GetUIName() );
599 catch (const uno::Exception&)
601 bError = true;
604 if( !bError && ERRCODE_NONE == aDlgHelper.Execute() )
606 aFileName = xFP->getSelectedFiles().getConstArray()[0];
609 else if( RET_OK == nRet)
611 aFileName = aNewFileDlg.GetTemplateFileName();
614 nFlags = aNewFileDlg.GetTemplateFlags();
615 rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) );
616 rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, static_cast<tools::Long>(nFlags) ) );
619 if( !aFileName.isEmpty() )
621 SwgReaderOption aOpt;
622 bText = bool(nFlags & SfxTemplateFlags::LOAD_TEXT_STYLES );
623 aOpt.SetTextFormats(bText);
624 bFrame = bool(nFlags & SfxTemplateFlags::LOAD_FRAME_STYLES);
625 aOpt.SetFrameFormats(bFrame);
626 bPage = bool(nFlags & SfxTemplateFlags::LOAD_PAGE_STYLES );
627 aOpt.SetPageDescs(bPage);
628 bNum = bool(nFlags & SfxTemplateFlags::LOAD_NUM_STYLES );
629 aOpt.SetNumRules(bNum);
630 //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge!
631 bMerge = bool(nFlags & SfxTemplateFlags::MERGE_STYLES);
632 aOpt.SetMerge( !bMerge );
634 SetError(LoadStylesFromFile(aFileName, aOpt, false));
635 if ( !GetError() )
636 rReq.Done();
639 break;
640 case SID_SOURCEVIEW:
642 SfxViewShell* pViewShell = GetView()
643 ? static_cast<SfxViewShell*>(GetView())
644 : SfxViewShell::Current();
645 SfxViewFrame& rViewFrame = pViewShell->GetViewFrame();
646 SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell );
647 if(!pSrcView)
649 // 3 possible state:
650 // 1 - file unsaved -> save as HTML
651 // 2 - file modified and HTML filter active -> save
652 // 3 - file saved in non-HTML -> QueryBox to save as HTML
653 std::shared_ptr<const SfxFilter> pHtmlFlt =
654 SwIoSystem::GetFilterOfFormat(
655 u"HTML",
656 SwWebDocShell::Factory().GetFilterContainer() );
657 bool bLocalHasName = HasName();
658 if(bLocalHasName)
660 //check for filter type
661 std::shared_ptr<const SfxFilter> pFlt = GetMedium()->GetFilter();
662 if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData())
664 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(rViewFrame.GetFrameWeld(), "modules/swriter/ui/saveashtmldialog.ui"));
665 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("SaveAsHTMLDialog"));
666 if (RET_YES == xQuery->run())
667 bLocalHasName = false;
668 else
669 break;
672 if(!bLocalHasName)
674 FileDialogHelper aDlgHelper(TemplateDescription::FILESAVE_AUTOEXTENSION,
675 FileDialogFlags::NONE,
676 GetView()->GetFrameWeld());
677 aDlgHelper.SetContext(FileDialogHelper::WriterSaveHTML);
678 aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() );
679 aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() );
680 if( ERRCODE_NONE != aDlgHelper.Execute())
682 break;
684 OUString sPath = aDlgHelper.GetPath();
685 SfxStringItem aName(SID_FILE_NAME, sPath);
686 SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName());
687 const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(
688 rViewFrame.GetDispatcher()->ExecuteList(
689 SID_SAVEASDOC, SfxCallMode::SYNCHRON,
690 { &aName, &aFilter }));
691 if(!pBool || !pBool->GetValue())
692 break;
696 assert(dynamic_cast<SwWebDocShell*>(this) && "SourceView only in WebDocShell");
698 // the SourceView is not the 1 for SwWebDocShell
699 sal_uInt16 nSlot = SID_VIEWSHELL1;
700 bool bSetModified = false;
701 VclPtr<SfxPrinter> pSavePrinter;
702 if( nullptr != pSrcView)
704 SfxPrinter* pTemp = GetDoc()->getIDocumentDeviceAccess().getPrinter( false );
705 if(pTemp)
706 pSavePrinter = VclPtr<SfxPrinter>::Create(*pTemp);
707 bSetModified = IsModified() || pSrcView->IsModified();
708 if(pSrcView->IsModified()||pSrcView->HasSourceSaved())
710 utl::TempFileNamed aTempFile;
711 aTempFile.EnableKillingFile();
712 pSrcView->SaveContent(aTempFile.GetURL());
713 bDone = true;
714 SvxMacro aMac(OUString(), OUString(), STARBASIC);
715 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::OPENDOC ), aMac, this);
716 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::PREPARECLOSEDOC ), aMac, this);
717 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::ACTIVATEDOC ), aMac, this);
718 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::DEACTIVATEDOC ), aMac, this);
719 ReloadFromHtml(aTempFile.GetURL(), pSrcView);
720 nSlot = 0;
722 else
724 nSlot = SID_VIEWSHELL0;
727 if (nSlot)
728 rViewFrame.GetDispatcher()->Execute(nSlot, SfxCallMode::SYNCHRON);
729 if(bSetModified)
730 GetDoc()->getIDocumentState().SetModified();
731 if(pSavePrinter)
733 GetDoc()->getIDocumentDeviceAccess().setPrinter( pSavePrinter, true, true);
734 //pSavePrinter must not be deleted again
736 rViewFrame.GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, false)); // not SID_VIEWSHELL2
737 rViewFrame.GetBindings().Invalidate( SID_NEWWINDOW );
738 rViewFrame.GetBindings().Invalidate( SID_BROWSER_MODE );
739 rViewFrame.GetBindings().Invalidate( FN_PRINT_LAYOUT );
741 break;
742 case SID_GET_COLORLIST:
744 const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE);
745 const XColorListRef& pList = pColItem->GetColorList();
746 rReq.SetReturnValue(OfaXColorListItem(SID_GET_COLORLIST, pList));
748 break;
749 case FN_ABSTRACT_STARIMPRESS:
750 case FN_ABSTRACT_NEWDOC:
752 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
753 ScopedVclPtr<AbstractSwInsertAbstractDlg> pDlg(pFact->CreateSwInsertAbstractDlg(GetView()->GetFrameWeld()));
754 if(RET_OK == pDlg->Execute())
756 sal_uInt8 nLevel = pDlg->GetLevel();
757 sal_uInt8 nPara = pDlg->GetPara();
758 SwDoc* pSmryDoc = new SwDoc();
759 SfxObjectShellLock xDocSh(new SwDocShell(*pSmryDoc, SfxObjectCreateMode::STANDARD));
760 xDocSh->DoInitNew();
762 bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
763 m_xDoc->Summary(*pSmryDoc, nLevel, nPara, bImpress);
764 if( bImpress )
766 WriterRef xWrt;
767 // mba: looks as if relative URLs don't make sense here
768 ::GetRTFWriter(std::u16string_view(), OUString(), xWrt);
769 SvMemoryStream *pStrm = new SvMemoryStream();
770 pStrm->SetBufferSize( 16348 );
771 SwWriter aWrt( *pStrm, *pSmryDoc );
772 ErrCode eErr = aWrt.Write( xWrt );
773 if( !eErr.IgnoreWarning() )
775 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
776 uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
778 uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
779 pStrm->Seek( STREAM_SEEK_TO_END );
780 pStrm->WriteChar( '\0' );
781 pStrm->Seek( STREAM_SEEK_TO_BEGIN );
783 // Transfer ownership of stream to a lockbytes object
784 SvLockBytes aLockBytes( pStrm, true );
785 SvLockBytesStat aStat;
786 if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONE )
788 sal_uInt32 nLen = aStat.nSize;
789 std::size_t nRead = 0;
790 uno::Sequence< sal_Int8 > aSeq( nLen );
791 aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
793 uno::Sequence< beans::PropertyValue > aArgs{
794 comphelper::makePropertyValue("RtfOutline", aSeq)
796 xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs );
799 else
800 ErrorHandler::HandleError( eErr );
802 else
804 // Create new document
805 SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, SFX_INTERFACE_NONE );
806 SwView *pCurrView = static_cast<SwView*>( pFrame->GetViewShell());
808 // Set document's title
809 OUString aTmp = SwResId(STR_ABSTRACT_TITLE) + GetTitle();
810 xDocSh->SetTitle( aTmp );
811 pCurrView->GetWrtShell().SetNewDoc();
812 pFrame->Show();
813 pSmryDoc->getIDocumentState().SetModified();
818 break;
819 case FN_OUTLINE_TO_CLIPBOARD:
820 case FN_OUTLINE_TO_IMPRESS:
822 bool bEnable = IsEnableSetModified();
823 EnableSetModified( false );
824 WriterRef xWrt;
825 // mba: looks as if relative URLs don't make sense here
826 ::GetRTFWriter( u"O", OUString(), xWrt );
827 std::unique_ptr<SvMemoryStream> pStrm (new SvMemoryStream());
828 pStrm->SetBufferSize( 16348 );
829 SwWriter aWrt( *pStrm, *GetDoc() );
830 ErrCode eErr = aWrt.Write( xWrt );
831 EnableSetModified( bEnable );
832 if( !eErr.IgnoreWarning() )
834 pStrm->Seek( STREAM_SEEK_TO_END );
835 pStrm->WriteChar( '\0' );
836 pStrm->Seek( STREAM_SEEK_TO_BEGIN );
837 if ( nWhich == FN_OUTLINE_TO_IMPRESS )
839 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
840 uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
842 uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
843 pStrm->Seek( STREAM_SEEK_TO_END );
844 pStrm->WriteChar( '\0' );
845 pStrm->Seek( STREAM_SEEK_TO_BEGIN );
847 // Transfer ownership of stream to a lockbytes object
848 SvLockBytes aLockBytes( pStrm.release(), true );
849 SvLockBytesStat aStat;
850 if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONE )
852 sal_uInt32 nLen = aStat.nSize;
853 std::size_t nRead = 0;
854 uno::Sequence< sal_Int8 > aSeq( nLen );
855 aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
857 uno::Sequence< beans::PropertyValue > aArgs{
858 comphelper::makePropertyValue("RtfOutline", aSeq)
860 xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs );
863 else
865 rtl::Reference<TransferDataContainer> pClipCntnr = new TransferDataContainer;
867 pClipCntnr->CopyAnyData( SotClipboardFormatId::RTF, static_cast<char const *>(
868 pStrm->GetData()), pStrm->GetEndOfData() );
869 pClipCntnr->CopyToClipboard(
870 GetView()? &GetView()->GetEditWin() : nullptr );
873 else
874 ErrorHandler::HandleError( eErr );
876 break;
877 case SID_SPELLCHECKER_CHANGED:
878 //! false, true, true is on the save side but a probably overdone
879 SwModule::CheckSpellChanges(false, true, true, false );
880 break;
882 case SID_MAIL_PREPAREEXPORT:
884 const SfxBoolItem* pNoUpdate = pArgs ?
885 pArgs->GetItem<SfxBoolItem>(FN_NOUPDATE, false) :
886 nullptr;
888 //pWrtShell is not set in page preview
889 if (m_pWrtShell)
890 m_pWrtShell->StartAllAction();
892 if (!pNoUpdate || !pNoUpdate->GetValue())
894 m_xDoc->getIDocumentFieldsAccess().UpdateFields( false );
895 m_xDoc->getIDocumentLinksAdministration().EmbedAllLinks();
898 m_IsRemovedInvisibleContent
899 = officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get();
900 if (m_IsRemovedInvisibleContent)
901 m_xDoc->RemoveInvisibleContent();
902 if (m_pWrtShell)
903 m_pWrtShell->EndAllAction();
905 break;
907 case SID_MAIL_EXPORT_FINISHED:
909 if (m_pWrtShell)
910 m_pWrtShell->StartAllAction();
911 //try to undo the removal of invisible content
912 if (m_IsRemovedInvisibleContent)
913 m_xDoc->RestoreInvisibleContent();
914 if (m_pWrtShell)
915 m_pWrtShell->EndAllAction();
917 break;
918 case FN_NEW_HTML_DOC:
919 case FN_NEW_GLOBAL_DOC:
921 bDone = false;
922 bool bCreateHtml = FN_NEW_HTML_DOC == nWhich;
924 bool bCreateByOutlineLevel = false;
925 sal_Int32 nTemplateOutlineLevel = 0;
927 OUString aFileName, aTemplateName;
928 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich, false, &pItem ) )
930 aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
931 const SfxStringItem* pTemplItem = SfxItemSet::GetItem<SfxStringItem>(pArgs, SID_TEMPLATE_NAME, false);
932 if ( pTemplItem )
933 aTemplateName = pTemplItem->GetValue();
935 if ( aFileName.isEmpty() )
937 bool bError = false;
939 FileDialogHelper aDlgHelper(TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, FileDialogFlags::NONE,
940 GetView()->GetFrameWeld());
941 aDlgHelper.SetContext(FileDialogHelper::WriterNewHTMLGlobalDoc);
943 const sal_Int16 nControlIds[] = {
944 CommonFilePickerElementIds::PUSHBUTTON_OK,
945 CommonFilePickerElementIds::PUSHBUTTON_CANCEL,
946 CommonFilePickerElementIds::LISTBOX_FILTER,
947 CommonFilePickerElementIds::CONTROL_FILEVIEW,
948 CommonFilePickerElementIds::EDIT_FILEURL,
949 ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION,
950 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
954 if (bCreateHtml)
956 const char* aHTMLHelpIds[] =
958 HID_SEND_HTML_CTRL_PUSHBUTTON_OK,
959 HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL,
960 HID_SEND_HTML_CTRL_LISTBOX_FILTER,
961 HID_SEND_HTML_CTRL_CONTROL_FILEVIEW,
962 HID_SEND_HTML_CTRL_EDIT_FILEURL,
963 HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION,
964 HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE,
967 aDlgHelper.SetControlHelpIds( nControlIds, aHTMLHelpIds );
969 else
971 const char* aMasterHelpIds[] =
973 HID_SEND_MASTER_CTRL_PUSHBUTTON_OK,
974 HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL,
975 HID_SEND_MASTER_CTRL_LISTBOX_FILTER,
976 HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW,
977 HID_SEND_MASTER_CTRL_EDIT_FILEURL,
978 HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION,
979 HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE,
982 aDlgHelper.SetControlHelpIds( nControlIds, aMasterHelpIds );
984 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
986 std::shared_ptr<const SfxFilter> pFlt;
987 TranslateId pStrId;
989 if( bCreateHtml )
991 // for HTML there is only one filter!!
992 pFlt = SwIoSystem::GetFilterOfFormat(
993 u"HTML",
994 SwWebDocShell::Factory().GetFilterContainer() );
995 pStrId = STR_LOAD_HTML_DOC;
997 else
999 // for Global-documents we now only offer the current one.
1000 pFlt = SwGlobalDocShell::Factory().GetFilterContainer()->
1001 GetFilter4Extension( "odm" );
1002 pStrId = STR_LOAD_GLOBAL_DOC;
1005 if( pFlt )
1007 const OUString sWild = pFlt->GetWildcard().getGlob();
1008 xFP->appendFilter( pFlt->GetUIName(), sWild );
1011 xFP->setCurrentFilter( pFlt->GetUIName() ) ;
1013 catch (const uno::Exception&)
1015 bError = true;
1018 if(!bError)
1020 uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY);
1022 bool bOutline[MAXLEVEL] = {false};
1023 const SwOutlineNodes& rOutlNds = m_xDoc->GetNodes().GetOutLineNds();
1024 for( size_t n = 0; n < rOutlNds.size(); ++n )
1026 const int nLevel = rOutlNds[n]->GetTextNode()->GetAttrOutlineLevel();
1027 if( nLevel > 0 && ! bOutline[nLevel-1] )
1029 bOutline[nLevel-1] = true;
1033 const sal_uInt16 nStyleCount = m_xDoc->GetTextFormatColls()->size();
1034 Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount);
1035 OUString* pEntries = aListBoxEntries.getArray();
1036 sal_Int32 nIdx = 0 ;
1038 OUString sOutline( SwResId(STR_FDLG_OUTLINE_LEVEL) );
1039 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
1041 if( bOutline[i] )
1042 pEntries[nIdx++] = sOutline + OUString::number( i+1 );
1045 OUString sStyle( SwResId(STR_FDLG_STYLE) );
1046 for(sal_uInt16 i = 0; i < nStyleCount; ++i)
1048 SwTextFormatColl &rTextColl = *(*m_xDoc->GetTextFormatColls())[ i ];
1049 if( !rTextColl.IsDefault() && rTextColl.IsAtDocNodeSet() )
1051 pEntries[nIdx++] = sStyle + rTextColl.GetName();
1055 aListBoxEntries.realloc(nIdx);
1056 sal_Int16 nSelect = 0;
1060 Any aTemplates(&aListBoxEntries, cppu::UnoType<decltype(aListBoxEntries)>::get());
1062 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1063 ListboxControlActions::ADD_ITEMS , aTemplates );
1064 Any aSelectPos(&nSelect, cppu::UnoType<decltype(nSelect)>::get());
1065 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1066 ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
1067 xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1068 SwResId( STR_FDLG_TEMPLATE_NAME ));
1070 catch (const Exception&)
1072 OSL_FAIL("control access failed");
1075 xFP->setTitle(SwResId(pStrId));
1076 SvtPathOptions aPathOpt;
1077 xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
1078 if( ERRCODE_NONE == aDlgHelper.Execute())
1080 aFileName = xFP->getSelectedFiles().getConstArray()[0];
1081 Any aTemplateValue = xCtrlAcc->getValue(
1082 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1083 ListboxControlActions::GET_SELECTED_ITEM );
1084 OUString sTmpl;
1085 aTemplateValue >>= sTmpl;
1087 OUString aStyle(SwResId(STR_FDLG_STYLE));
1088 OUString aOutline(SwResId(STR_FDLG_OUTLINE_LEVEL));
1090 if ( sTmpl.startsWith(aStyle) )
1092 aTemplateName = sTmpl.copy( aStyle.getLength() ); //get string behind "Style: "
1094 else if ( sTmpl.startsWith(aOutline) )
1096 nTemplateOutlineLevel = o3tl::toInt32(sTmpl.subView(aOutline.getLength())); //get string behind "Outline: Level ";
1097 bCreateByOutlineLevel = true;
1100 if ( !aFileName.isEmpty() )
1102 rReq.AppendItem( SfxStringItem( nWhich, aFileName ) );
1103 if( !aTemplateName.isEmpty() )
1104 rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) );
1110 if( !aFileName.isEmpty() )
1112 if( PrepareClose( false ) )
1114 SwWait aWait( *this, true );
1116 if ( bCreateByOutlineLevel )
1118 bDone = bCreateHtml
1119 ? m_xDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel )
1120 : m_xDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel );
1122 else
1124 const SwTextFormatColl* pSplitColl = nullptr;
1125 if ( !aTemplateName.isEmpty() )
1126 pSplitColl = m_xDoc->FindTextFormatCollByName(aTemplateName);
1127 bDone = bCreateHtml
1128 ? m_xDoc->GenerateHTMLDoc( aFileName, pSplitColl )
1129 : m_xDoc->GenerateGlobalDoc( aFileName, pSplitColl );
1131 if( bDone )
1133 SfxStringItem aName( SID_FILE_NAME, aFileName );
1134 SfxStringItem aReferer(SID_REFERER, OUString());
1135 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
1136 while(pViewShell)
1138 //search for the view that created the call
1139 if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher())
1141 SfxFrameItem aFrameItem(SID_DOCFRAME, &pViewShell->GetViewFrame());
1142 SfxDispatcher* pDispatch = pViewShell->GetDispatcher();
1143 pDispatch->ExecuteList(SID_OPENDOC,
1144 SfxCallMode::ASYNCHRON,
1145 { &aName, &aReferer, &aFrameItem });
1146 break;
1148 pViewShell = SfxViewShell::GetNext(*pViewShell);
1152 if( !bDone && !rReq.IsAPI() )
1154 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr,
1155 VclMessageType::Info, VclButtonsType::Ok,
1156 SwResId(STR_CANTCREATE)));
1157 xInfoBox->run();
1161 rReq.SetReturnValue(SfxBoolItem( nWhich, bDone ));
1162 if (bDone)
1163 rReq.Done();
1164 else
1165 rReq.Ignore();
1166 break;
1168 case SID_ATTR_YEAR2000:
1169 if ( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich , false, &pItem ))
1171 assert(dynamic_cast< const SfxUInt16Item *>( pItem ) && "wrong Item");
1172 sal_uInt16 nYear2K = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1173 // iterate over Views and put the State to FormShells
1175 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this );
1176 SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : nullptr;
1177 SwView* pCurrView = dynamic_cast< SwView* >( pViewShell );
1178 while(pCurrView)
1180 FmFormShell* pFormShell = pCurrView->GetFormShell();
1181 if(pFormShell)
1182 pFormShell->SetY2KState(nYear2K);
1183 pVFrame = SfxViewFrame::GetNext( *pVFrame, this );
1184 pViewShell = pVFrame ? pVFrame->GetViewShell() : nullptr;
1185 pCurrView = dynamic_cast<SwView*>( pViewShell );
1187 m_xDoc->GetNumberFormatter()->SetYear2000(nYear2K);
1189 break;
1190 case FN_OPEN_FILE:
1192 SfxViewShell* pViewShell = GetView();
1193 if (!pViewShell)
1194 pViewShell = SfxViewShell::Current();
1196 if (!pViewShell)
1197 // Ok. I did my best.
1198 break;
1200 if (SfxDispatcher* pDispatch = pViewShell->GetDispatcher())
1202 SfxStringItem aApp(SID_DOC_SERVICE, "com.sun.star.text.TextDocument");
1203 SfxStringItem aTarget(SID_TARGETNAME, "_blank");
1204 pDispatch->ExecuteList(SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON, { &aApp, &aTarget });
1207 break;
1208 case SID_CLASSIFICATION_APPLY:
1210 if (pArgs && pArgs->GetItemState(nWhich, false, &pItem) == SfxItemState::SET)
1212 SwWrtShell* pSh = GetWrtShell();
1213 const OUString& rValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
1214 auto eType = SfxClassificationPolicyType::IntellectualProperty;
1215 if (const SfxStringItem* pTypeNameItem = pArgs->GetItemIfSet(SID_TYPE_NAME, false))
1217 const OUString& rType = pTypeNameItem->GetValue();
1218 eType = SfxClassificationHelper::stringToPolicyType(rType);
1220 pSh->SetClassification(rValue, eType);
1222 else
1223 SAL_WARN("sw.ui", "missing parameter for SID_CLASSIFICATION_APPLY");
1225 break;
1226 case SID_CLASSIFICATION_DIALOG:
1227 if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
1229 auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), pObjSh->getDocProperties(), false);
1231 SwWrtShell* pShell = GetWrtShell();
1232 std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification();
1233 xDialog->setupValues(std::move(aInput));
1235 weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
1236 if (RET_OK == nResult)
1237 pShell->ApplyAdvancedClassification(xDialog->getResult());
1240 break;
1241 case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
1242 if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
1244 SwWrtShell* pShell = GetWrtShell();
1245 auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), pObjSh->getDocProperties(), true, [pShell]()
1247 pShell->SignParagraph();
1250 std::vector<svx::ClassificationResult> aInput = pShell->CollectParagraphClassification();
1251 xDialog->setupValues(std::move(aInput));
1253 weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
1254 if (RET_OK == nResult)
1255 pShell->ApplyParagraphClassification(xDialog->getResult());
1258 break;
1259 case SID_WATERMARK:
1261 SwWrtShell* pSh = GetWrtShell();
1262 if ( pSh )
1264 if (pArgs && pArgs->GetItemState( SID_WATERMARK, false, &pItem ) == SfxItemState::SET)
1266 SfxWatermarkItem aItem;
1267 aItem.SetText( static_cast<const SfxStringItem*>( pItem )->GetValue() );
1269 if ( const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_WATERMARK_FONT, false ) )
1270 aItem.SetFont( pFontItem->GetValue() );
1271 if ( const SfxInt16Item* pAngleItem = pArgs->GetItemIfSet( SID_WATERMARK_ANGLE, false ) )
1272 aItem.SetAngle( pAngleItem->GetValue() );
1273 if ( const SfxInt16Item* pTransItem = pArgs->GetItemIfSet( SID_WATERMARK_TRANSPARENCY, false ) )
1274 aItem.SetTransparency( pTransItem->GetValue() );
1275 if ( const SfxUInt32Item* pColorItem = pArgs->GetItemIfSet( SID_WATERMARK_COLOR, false ) )
1276 aItem.SetColor( Color(ColorTransparency, pColorItem->GetValue()) );
1278 pSh->SetWatermark( aItem );
1280 else
1282 SfxViewShell* pViewShell = GetView() ? GetView() : SfxViewShell::Current();
1283 SfxBindings& rBindings( pViewShell->GetViewFrame().GetBindings() );
1284 auto xDlg = std::make_shared<SwWatermarkDialog>(pViewShell->GetViewFrame().GetFrameWeld(),
1285 rBindings);
1286 weld::DialogController::runAsync(xDlg, [](sal_Int32 /*nResult*/){});
1290 break;
1291 case SID_NOTEBOOKBAR:
1293 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR );
1294 SfxViewShell* pViewShell = GetView()? GetView(): SfxViewShell::Current();
1295 SfxBindings& rBindings( pViewShell->GetViewFrame().GetBindings() );
1297 if ( SfxNotebookBar::IsActive() )
1298 sfx2::SfxNotebookBar::ExecMethod( rBindings, pFile ? pFile->GetValue() : "" );
1299 else
1301 sfx2::SfxNotebookBar::CloseMethod( rBindings );
1304 break;
1305 case FN_REDLINE_ACCEPT_ALL:
1306 case FN_REDLINE_REJECT_ALL:
1308 IDocumentRedlineAccess& rRedlineAccess = GetDoc()->getIDocumentRedlineAccess();
1309 SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell());
1311 if (rRedlineAccess.GetRedlineTable().empty())
1313 break;
1316 // tables with tracked deletion need Show Changes
1317 bool bHideChanges = pWrtShell && pWrtShell->GetLayout() &&
1318 pWrtShell->GetLayout()->IsHideRedlines();
1319 bool bChangedHideChanges = false;
1320 if ( bHideChanges )
1322 SwTableNode* pOldTableNd = nullptr;
1323 const SwRedlineTable& aRedlineTable = rRedlineAccess.GetRedlineTable();
1324 for (SwRedlineTable::size_type n = 0; n < aRedlineTable.size(); ++n)
1326 const SwRangeRedline* pRedline = aRedlineTable[n];
1327 if ( pRedline->GetType() == RedlineType::Delete )
1329 SwTableNode* pTableNd =
1330 pRedline->GetPoint()->GetNode().FindTableNode();
1331 if ( pTableNd && pTableNd !=
1332 pOldTableNd && pTableNd->GetTable().HasDeletedRowOrCell() )
1334 SfxBoolItem aShow(FN_REDLINE_SHOW, true);
1335 SfxViewShell* pViewShell = GetView()
1336 ? GetView()
1337 : SfxViewShell::Current();
1338 pViewShell->GetViewFrame().GetDispatcher()->ExecuteList(
1339 FN_REDLINE_SHOW, SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
1340 { &aShow });
1341 bChangedHideChanges = true;
1342 break;
1344 pOldTableNd = pTableNd;
1349 if (pWrtShell)
1351 pWrtShell->StartAllAction();
1354 rRedlineAccess.AcceptAllRedline(nWhich == FN_REDLINE_ACCEPT_ALL);
1356 if (pWrtShell)
1358 pWrtShell->EndAllAction();
1361 if ( bChangedHideChanges )
1363 SfxBoolItem aShow(FN_REDLINE_SHOW, false);
1364 SfxViewShell* pViewShell = GetView()? GetView(): SfxViewShell::Current();
1365 pViewShell->GetViewFrame().GetDispatcher()->ExecuteList(
1366 FN_REDLINE_SHOW, SfxCallMode::SYNCHRON|SfxCallMode::RECORD, { &aShow });
1369 Broadcast(SfxHint(SfxHintId::RedlineChanged));
1370 rReq.Done();
1372 break;
1374 default: OSL_FAIL("wrong Dispatcher");
1378 #if defined(_WIN32)
1379 bool SwDocShell::DdeGetData( const OUString& rItem, const OUString& rMimeType,
1380 uno::Any & rValue )
1382 return m_xDoc->getIDocumentLinksAdministration().GetData( rItem, rMimeType, rValue );
1385 bool SwDocShell::DdeSetData( const OUString& rItem, const OUString& /*rMimeType*/,
1386 const uno::Any & /*rValue*/ )
1388 m_xDoc->getIDocumentLinksAdministration().SetData( rItem );
1389 return false;
1392 #endif
1394 ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const OUString& rItem )
1396 return m_xDoc->getIDocumentLinksAdministration().CreateLinkSource( rItem );
1399 void SwDocShell::ReconnectDdeLink(SfxObjectShell& rServer)
1401 if (m_xDoc)
1403 ::sfx2::LinkManager& rLinkManager = m_xDoc->getIDocumentLinksAdministration().GetLinkManager();
1404 rLinkManager.ReconnectDdeLink(rServer);
1408 void SwDocShell::FillClass( SvGlobalName * pClassName,
1409 SotClipboardFormatId * pClipFormat,
1410 OUString * pLongUserName,
1411 sal_Int32 nVersion,
1412 bool bTemplate /* = false */) const
1414 if (nVersion == SOFFICE_FILEFORMAT_60)
1416 *pClassName = SvGlobalName( SO3_SW_CLASSID_60 );
1417 *pClipFormat = SotClipboardFormatId::STARWRITER_60;
1418 *pLongUserName = SwResId(STR_WRITER_DOCUMENT_FULLTYPE);
1420 else if (nVersion == SOFFICE_FILEFORMAT_8)
1422 *pClassName = SvGlobalName( SO3_SW_CLASSID_60 );
1423 *pClipFormat = bTemplate ? SotClipboardFormatId::STARWRITER_8_TEMPLATE : SotClipboardFormatId::STARWRITER_8;
1424 *pLongUserName = SwResId(STR_WRITER_DOCUMENT_FULLTYPE);
1426 // #FIXME check with new Event handling
1427 #if 0
1428 uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = m_xDoc->GetVbaEventsHelper();
1429 if( xVbaEventsHelper.is() )
1430 lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint );
1431 #endif
1434 void SwDocShell::SetModified( bool bSet )
1436 if (utl::ConfigManager::IsFuzzing())
1437 return;
1438 SfxObjectShell::SetModified( bSet );
1439 if( !IsEnableSetModified())
1440 return;
1442 if (!m_xDoc->getIDocumentState().IsInCallModified())
1444 EnableSetModified( false );
1445 if( bSet )
1447 bool const bOld = m_xDoc->getIDocumentState().IsModified();
1448 m_xDoc->getIDocumentState().SetModified();
1449 if( !bOld )
1451 m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1454 else
1455 m_xDoc->getIDocumentState().ResetModified();
1457 EnableSetModified();
1460 UpdateChildWindows();
1461 Broadcast(SfxHint(SfxHintId::DocChanged));
1464 void SwDocShell::UpdateChildWindows()
1466 // if necessary newly initialize Fielddlg (i.e. for TYP_SETVAR)
1467 if(!GetView())
1468 return;
1469 SfxViewFrame& rVFrame = GetView()->GetViewFrame();
1470 SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(rVFrame.
1471 GetChildWindow( SwFieldDlgWrapper::GetChildWindowId() ));
1472 if( pWrp )
1473 pWrp->ReInitDlg( this );
1475 // if necessary newly initialize RedlineDlg
1476 SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(rVFrame.
1477 GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() ));
1478 if( pRed )
1479 pRed->ReInitDlg( this );
1482 namespace {
1484 // #i48748#
1485 class SwReloadFromHtmlReader : public SwReader
1487 public:
1488 SwReloadFromHtmlReader( SfxMedium& _rTmpMedium,
1489 const OUString& _rFilename,
1490 SwDoc* _pDoc )
1491 : SwReader( _rTmpMedium, _rFilename, _pDoc )
1493 SetBaseURL( _rFilename );
1499 void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView )
1501 bool bModified = IsModified();
1503 // The HTTP-Header fields have to be removed, otherwise
1504 // there are some from Meta-Tags duplicated or triplicated afterwards.
1505 ClearHeaderAttributesForSourceViewHack();
1507 #if HAVE_FEATURE_SCRIPTING
1508 // The Document-Basic also bites the dust ...
1509 // A EnterBasicCall is not needed here, because nothing is called and
1510 // there can't be any Dok-Basic, that has not yet been loaded inside
1511 // of an HTML document.
1512 //#59620# HasBasic() shows, that there already is a BasicManager at the DocShell.
1513 // That was always generated in HTML-Import, when there are
1514 // Macros in the source code.
1515 if( officecfg::Office::Common::Filter::HTML::Export::Basic::get() && HasBasic())
1517 BasicManager *pBasicMan = GetBasicManager();
1518 if( pBasicMan && (pBasicMan != SfxApplication::GetBasicManager()) )
1520 sal_uInt16 nLibCount = pBasicMan->GetLibCount();
1521 while( nLibCount )
1523 StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount );
1524 if( pBasic )
1526 // Notify the IDE
1527 SfxUnoAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, Any( GetModel() ) );
1528 OUString aLibName( pBasic->GetName() );
1529 SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
1530 pSrcView->GetViewFrame().GetDispatcher()->ExecuteList(
1531 SID_BASICIDE_LIBREMOVED,
1532 SfxCallMode::SYNCHRON,
1533 { &aShellItem, &aLibNameItem });
1535 // Only the modules are deleted from the standard-lib
1536 if( nLibCount )
1537 pBasicMan->RemoveLib( nLibCount, true );
1538 else
1539 pBasic->Clear();
1543 OSL_ENSURE( pBasicMan->GetLibCount() <= 1,
1544 "Deleting Basics didn't work" );
1547 #endif
1548 bool bWasBrowseMode = m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE);
1549 RemoveLink();
1551 // now also the UNO-Model has to be informed about the new Doc #51535#
1552 uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY);
1553 text::XTextDocument* pxDoc = xDoc.get();
1554 static_cast<SwXTextDocument*>(pxDoc)->InitNewDoc();
1556 AddLink();
1557 //#116402# update font list when new document is created
1558 UpdateFontList();
1559 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bWasBrowseMode);
1560 pSrcView->SetPool(&GetPool());
1562 const OUString& rMedname = GetMedium()->GetName();
1564 // The HTML template still has to be set
1565 SetHTMLTemplate( *GetDoc() ); //Styles from HTML.vor
1567 SfxViewShell* pViewShell = GetView() ? static_cast<SfxViewShell*>(GetView())
1568 : SfxViewShell::Current();
1569 SfxViewFrame& rViewFrame = pViewShell->GetViewFrame();
1570 rViewFrame.GetDispatcher()->Execute( SID_VIEWSHELL0, SfxCallMode::SYNCHRON );
1572 SubInitNew();
1574 SfxMedium aMed( rStreamName, StreamMode::READ );
1575 // #i48748# - use class <SwReloadFromHtmlReader>, because
1576 // the base URL has to be set to the filename of the document <rMedname>
1577 // and not to the base URL of the temporary file <aMed> in order to get
1578 // the URLs of the linked graphics correctly resolved.
1579 SwReloadFromHtmlReader aReader( aMed, rMedname, m_xDoc.get() );
1581 aReader.Read( *ReadHTML );
1583 const SwView* pCurrView = GetView();
1584 //in print layout the first page(s) may have been formatted as a mix of browse
1585 //and print layout
1586 if(!bWasBrowseMode && pCurrView)
1588 SwWrtShell& rWrtSh = pCurrView->GetWrtShell();
1589 if( rWrtSh.GetLayout())
1590 rWrtSh.InvalidateLayout( true );
1593 // Take HTTP-Header-Attributes over into the DocInfo again.
1594 // The Base-URL doesn't matter here because TLX uses the one from the document
1595 // for absolutization.
1596 SetHeaderAttributesForSourceViewHack();
1598 if(bModified && !IsReadOnly())
1599 SetModified();
1600 else
1601 m_xDoc->getIDocumentState().ResetModified();
1604 ErrCode SwDocShell::LoadStylesFromFile(const OUString& rURL, SwgReaderOption& rOpt, bool bUnoCall)
1606 ErrCode nErr = ERRCODE_NONE;
1608 // Set filter:
1609 SfxFilterMatcher aMatcher( SwDocShell::Factory().GetFactoryName() );
1611 // search for filter in WebDocShell, too
1612 SfxMedium aMed( rURL, StreamMode::STD_READ );
1613 if (rURL == "private:stream")
1614 aMed.setStreamToLoadFrom(rOpt.GetInputStream(), true);
1615 std::shared_ptr<const SfxFilter> pFlt;
1616 aMatcher.DetectFilter( aMed, pFlt );
1617 if(!pFlt)
1619 SfxFilterMatcher aWebMatcher( SwWebDocShell::Factory().GetFactoryName() );
1620 aWebMatcher.DetectFilter( aMed, pFlt );
1622 // --> OD #i117339# - trigger import only for own formats
1623 bool bImport( false );
1624 if ( aMed.IsStorage() )
1626 // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat()
1627 // does not work correct (e.g., MS Word 2007 XML Template),
1628 // use workaround provided by MAV.
1629 uno::Reference< embed::XStorage > xStorage = aMed.GetStorage();
1630 if ( xStorage.is() )
1632 // use <try-catch> on retrieving <MediaType> in order to check,
1633 // if the storage is one of our own ones.
1636 uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW );
1637 xProps->getPropertyValue( "MediaType" );
1638 bImport = true;
1640 catch (const uno::Exception&)
1642 bImport = false;
1646 if ( bImport )
1648 Reader* pRead = ReadXML;
1649 SwReaderPtr pReader;
1650 std::optional<SwPaM> pPam;
1651 // the SW3IO - Reader need the pam/wrtshell, because only then he
1652 // insert the styles!
1653 if( bUnoCall )
1655 SwNodeIndex aIdx( m_xDoc->GetNodes().GetEndOfContent(), -1 );
1656 pPam.emplace( aIdx );
1657 pReader.reset(new SwReader( aMed, rURL, *pPam ));
1659 else
1661 pReader.reset(new SwReader( aMed, rURL, *m_pWrtShell->GetCursor() ));
1664 pRead->GetReaderOpt().SetTextFormats( rOpt.IsTextFormats() );
1665 pRead->GetReaderOpt().SetFrameFormats( rOpt.IsFrameFormats() );
1666 pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() );
1667 pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() );
1668 pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() );
1670 if( bUnoCall )
1672 UnoActionContext aAction( m_xDoc.get() );
1673 nErr = pReader->Read( *pRead );
1675 else
1677 m_pWrtShell->StartAllAction();
1678 nErr = pReader->Read( *pRead );
1679 m_pWrtShell->EndAllAction();
1683 return nErr;
1686 // Get a client for an embedded object if possible.
1687 SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef )
1689 SfxInPlaceClient* pResult = nullptr;
1691 SwWrtShell* pShell = GetWrtShell();
1692 if ( pShell )
1694 pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), &pShell->GetView().GetEditWin() );
1695 if ( !pResult )
1696 pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef );
1699 return pResult;
1702 int SwFindDocShell( SfxObjectShellRef& xDocSh,
1703 SfxObjectShellLock& xLockRef,
1704 std::u16string_view rFileName,
1705 const OUString& rPasswd,
1706 const OUString& rFilter,
1707 sal_Int16 nVersion,
1708 SwDocShell* pDestSh )
1710 if ( rFileName.empty() )
1711 return 0;
1713 // 1. Does the file already exist in the list of all Documents?
1714 INetURLObject aTmpObj( rFileName );
1715 aTmpObj.SetMark( u"" );
1717 // Iterate over the DocShell and get the ones with the name
1719 SfxObjectShell* pShell = pDestSh;
1720 bool bFirst = nullptr != pShell;
1722 if( !bFirst )
1723 // No DocShell passed, starting with the first from the DocShell list
1724 pShell = SfxObjectShell::GetFirst( checkSfxObjectShell<SwDocShell> );
1726 while( pShell )
1728 // We want this one
1729 SfxMedium* pMed = pShell->GetMedium();
1730 if( pMed && pMed->GetURLObject() == aTmpObj )
1732 const SfxPoolItem* pItem;
1733 if( ( SfxItemState::SET == pMed->GetItemSet()->GetItemState(
1734 SID_VERSION, false, &pItem ) )
1735 ? (nVersion == static_cast<const SfxInt16Item*>(pItem)->GetValue())
1736 : !nVersion )
1738 // Found, thus return
1739 xDocSh = pShell;
1740 return 1;
1744 if( bFirst )
1746 bFirst = false;
1747 pShell = SfxObjectShell::GetFirst( checkSfxObjectShell<SwDocShell> );
1749 else
1750 pShell = SfxObjectShell::GetNext( *pShell, checkSfxObjectShell<SwDocShell> );
1753 // 2. Open the file ourselves
1754 std::unique_ptr<SfxMedium> xMed(new SfxMedium( aTmpObj.GetMainURL(
1755 INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
1756 if( INetProtocol::File == aTmpObj.GetProtocol() )
1757 xMed->Download(); // Touch the medium (download it)
1759 std::shared_ptr<const SfxFilter> pSfxFlt;
1760 if (!xMed->GetError())
1762 SfxFilterMatcher aMatcher( rFilter == "writerglobal8"
1763 ? SwGlobalDocShell::Factory().GetFactoryName()
1764 : SwDocShell::Factory().GetFactoryName() );
1766 // No Filter, so search for it. Else test if the one passed is a valid one
1767 if( !rFilter.isEmpty() )
1769 pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
1772 if( nVersion )
1773 xMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
1775 if( !rPasswd.isEmpty() )
1776 xMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
1778 if( !pSfxFlt )
1779 aMatcher.DetectFilter( *xMed, pSfxFlt );
1781 if( pSfxFlt )
1783 // We cannot do anything without a Filter
1784 xMed->SetFilter( pSfxFlt );
1786 // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
1787 SwDocShell *const pNew(new SwDocShell(SfxObjectCreateMode::INTERNAL));
1788 xLockRef = pNew;
1789 xDocSh = static_cast<SfxObjectShell*>(xLockRef);
1790 if (xDocSh->DoLoad(xMed.release()))
1792 return 2;
1797 return 0;
1800 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */