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 .
19 #ifndef INCLUDED_SW_INC_DOCSH_HXX
20 #define INCLUDED_SW_INC_DOCSH_HXX
24 #include <rtl/ref.hxx>
25 #include <com/sun/star/uno/Sequence.h>
26 #include <sfx2/docfac.hxx>
27 #include <sfx2/objsh.hxx>
29 #include "shellid.hxx"
31 #include <svl/lstner.hxx>
32 #include <sfx2/StyleManager.hxx>
33 #include <o3tl/deleter.hxx>
36 class SfxDocumentInfoDialog
;
37 class SfxInPlaceClient
;
45 typedef std::unique_ptr
<SwReader
, o3tl::default_delete
<SwReader
>> SwReaderPtr
;
49 class SwgReaderOption
;
50 class IDocumentDeviceAccess
;
51 class IDocumentChartDataProviderAccess
;
57 class EmbeddedObjectRef
;
59 namespace com::sun::star::frame
{ class XController
; }
60 namespace ooo::vba
{ class XSinkCaller
; }
61 namespace ooo::vba::word
{ class XDocument
; }
63 // initialize DrawModel (in form of a SwDrawModel) and DocShell (in form of a SwDocShell)
64 // as needed, one or both parameters may be zero
65 void InitDrawModelAndDocShell(SwDocShell
* pSwDocShell
, SwDrawModel
* pSwDrawModel
);
67 class SW_DLLPUBLIC SwDocShell
68 : public SfxObjectShell
71 rtl::Reference
< SwDoc
> m_xDoc
; ///< Document.
72 rtl::Reference
< SfxStyleSheetBasePool
> m_xBasePool
; ///< Passing through for formats.
73 std::unique_ptr
<FontList
> m_pFontList
; ///< Current Fontlist.
74 bool m_IsInUpdateFontList
; ///< prevent nested calls of UpdateFontList
76 std::unique_ptr
<sfx2::StyleManager
> m_pStyleManager
;
78 /** For "historical reasons" nothing can be done without the WrtShell.
79 Back-pointer on View (again "for historical reasons").
80 Back-pointer is valid until in Activate a new one is set
81 or until it is deleted in the View's Dtor. */
84 SwWrtShell
* m_pWrtShell
;
86 std::unique_ptr
<comphelper::EmbeddedObjectContainer
> m_pOLEChildList
;
87 sal_Int16 m_nUpdateDocMode
; ///< contains the css::document::UpdateDocMode
88 bool m_IsATemplate
; ///< prevent nested calls of UpdateFontList
90 bool m_IsRemovedInvisibleContent
;
91 ///< whether SID_MAIL_PREPAREEXPORT removed content that
92 ///< SID_MAIL_EXPORT_FINISHED needs to restore
94 css::uno::Reference
< ooo::vba::XSinkCaller
> mxAutomationDocumentEventsCaller
;
95 css::uno::Reference
< ooo::vba::word::XDocument
> mxAutomationDocumentObject
;
97 /// Methods for access to doc.
98 SAL_DLLPRIVATE
void AddLink();
99 SAL_DLLPRIVATE
void RemoveLink();
101 /// Catch hint for DocInfo.
102 SAL_DLLPRIVATE
virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
105 SAL_DLLPRIVATE
virtual bool InitNew( const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
106 SAL_DLLPRIVATE
virtual bool Load( SfxMedium
& rMedium
) override
;
107 SAL_DLLPRIVATE
virtual bool LoadFrom( SfxMedium
& rMedium
) override
;
108 SAL_DLLPRIVATE
virtual bool ConvertFrom( SfxMedium
&rMedium
) override
;
109 SAL_DLLPRIVATE
virtual bool ConvertTo( SfxMedium
&rMedium
) override
;
110 SAL_DLLPRIVATE
virtual bool SaveAs( SfxMedium
& rMedium
) override
;
111 SAL_DLLPRIVATE
virtual bool SaveCompleted( const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
113 SAL_DLLPRIVATE
virtual bool PrepareClose( bool bUI
= true ) override
;
115 SAL_DLLPRIVATE
virtual bool InsertGeneratedStream(SfxMedium
& rMedium
,
116 css::uno::Reference
<css::text::XTextRange
> const& xInsertPosition
)
119 /// Make DocInfo known to the Doc.
120 SAL_DLLPRIVATE
virtual std::shared_ptr
<SfxDocumentInfoDialog
> CreateDocumentInfoDialog(weld::Window
* pParent
,
121 const SfxItemSet
&rSet
) override
;
123 SAL_DLLPRIVATE
virtual void Draw(OutputDevice
*, const JobSetup
&, sal_uInt16 nAspect
, bool bOutputToWindow
) override
;
125 /// Methods for StyleSheets
128 /// Only used for nFamily == SfxStyleFamily::Page. Identifies optional Slot by which the edit is triggered.
129 /// Used to activate certain dialog pane
130 SAL_DLLPRIVATE
void Edit(
131 weld::Window
* pDialogParent
,
132 const OUString
&rName
,
133 const OUString
& rParent
,
134 const SfxStyleFamily nFamily
,
135 SfxStyleSearchBits nMask
,
137 const OUString
& sPageId
,
138 SwWrtShell
* pActShell
,
139 SfxRequest
* pRequest
= nullptr,
140 sal_uInt16 nSlot
= 0);
142 SAL_DLLPRIVATE
void Delete(const OUString
&rName
, SfxStyleFamily nFamily
);
143 SAL_DLLPRIVATE
void Hide(const OUString
&rName
, SfxStyleFamily nFamily
, bool bHidden
);
144 SAL_DLLPRIVATE SfxStyleFamily
ApplyStyles(const OUString
&rName
,
145 const SfxStyleFamily nFamily
,
148 SAL_DLLPRIVATE SfxStyleFamily
DoWaterCan( const OUString
&rName
, SfxStyleFamily nFamily
);
149 SAL_DLLPRIVATE
void UpdateStyle(const OUString
&rName
, SfxStyleFamily nFamily
, SwWrtShell
* pShell
);
150 SAL_DLLPRIVATE
void MakeByExample(const OUString
&rName
,
151 SfxStyleFamily nFamily
, SfxStyleSearchBits nMask
, SwWrtShell
* pShell
);
153 SAL_DLLPRIVATE
void SubInitNew(); ///< for InitNew and HtmlSourceMode.
155 SAL_DLLPRIVATE
void RemoveOLEObjects();
156 SAL_DLLPRIVATE
void CalcLayoutForOLEObjects();
158 SAL_DLLPRIVATE
void Init_Impl();
160 using SfxObjectShell::GetVisArea
;
163 /// override to update text fields
164 virtual void DoFlushDocInfo() override
;
167 /// but we implement this ourselves.
168 SFX_DECL_INTERFACE(SW_DOCSHELL
)
169 SFX_DECL_OBJECTFACTORY()
172 /// SfxInterface initializer.
173 static void InitInterface_Impl();
176 static OUString
GetEventName( sal_Int32 nId
);
178 /// Doc is required for SO data exchange!
179 SwDocShell( SfxObjectCreateMode eMode
= SfxObjectCreateMode::EMBEDDED
);
180 SwDocShell( SfxModelFlags i_nSfxCreationFlags
);
181 SwDocShell( SwDoc
& rDoc
, SfxObjectCreateMode eMode
);
182 virtual ~SwDocShell() override
;
184 /// OLE 2.0-notification.
185 DECL_DLLPRIVATE_LINK( Ole2ModifiedHdl
, bool, void );
188 virtual void SetVisArea( const tools::Rectangle
&rRect
) override
;
189 virtual tools::Rectangle
GetVisArea( sal_uInt16 nAspect
) const override
;
190 virtual Printer
*GetDocumentPrinter() override
;
191 virtual OutputDevice
* GetDocumentRefDev() override
;
192 virtual void OnDocumentPrinterChanged( Printer
* pNewPrinter
) override
;
194 virtual void SetModified( bool = true ) override
;
197 void Execute(SfxRequest
&);
198 void ExecStyleSheet(SfxRequest
&);
200 void GetState(SfxItemSet
&);
201 void StateStyleSheet(SfxItemSet
&, SwWrtShell
* pSh
= nullptr );
203 /// returns Doc. But be careful!
204 SwDoc
* GetDoc() { return m_xDoc
.get(); }
205 const SwDoc
* GetDoc() const { return m_xDoc
.get(); }
206 IDocumentDeviceAccess
& getIDocumentDeviceAccess();
207 IDocumentChartDataProviderAccess
& getIDocumentChartDataProviderAccess();
209 void UpdateFontList();
210 void UpdateChildWindows();
213 virtual bool Save() override
;
216 virtual SfxStyleSheetBasePool
* GetStyleSheetPool() override
;
217 virtual sfx2::StyleManager
* GetStyleManager() override
;
219 /// Set View for actions via Shell.
220 void SetView(SwView
* pVw
);
221 const SwView
*GetView() const { return m_pView
; }
222 SwView
*GetView() { return m_pView
; }
224 /// Access to the SwWrtShell belonging to SwView.
225 SwWrtShell
*GetWrtShell() { return m_pWrtShell
; }
226 const SwWrtShell
*GetWrtShell() const { return m_pWrtShell
; }
227 // Same as GetWrtShell, but return pointer to SwEditShell base of
228 // (potentially incomplete) SwWrtShell:
229 SwEditShell
* GetEditShell();
231 /// For Core - it knows the DocShell but not the WrtShell!
232 SwFEShell
*GetFEShell();
233 const SwFEShell
*GetFEShell() const
234 { return const_cast<SwDocShell
*>(this)->GetFEShell(); }
236 /// For inserting document.
237 Reader
* StartConvertFrom(SfxMedium
& rMedium
, SwReaderPtr
& rpRdr
,
238 SwCursorShell
const * pCursorSh
= nullptr, SwPaM
* pPaM
= nullptr);
241 virtual bool DdeGetData( const OUString
& rItem
, const OUString
& rMimeType
,
242 css::uno::Any
& rValue
) override
;
243 virtual bool DdeSetData( const OUString
& rItem
, const OUString
& rMimeType
,
244 const css::uno::Any
& rValue
) override
;
246 virtual ::sfx2::SvLinkSource
* DdeCreateLinkSource( const OUString
& rItem
) override
;
247 virtual void ReconnectDdeLink(SfxObjectShell
& rServer
) override
;
249 virtual void FillClass( SvGlobalName
* pClassName
,
250 SotClipboardFormatId
* pClipFormat
,
251 OUString
* pLongUserName
,
252 sal_Int32 nFileFormat
,
253 bool bTemplate
= false ) const override
;
255 virtual std::set
<Color
> GetDocColors() override
;
257 virtual std::shared_ptr
<model::ColorSet
> GetThemeColors() override
;
259 sfx::AccessibilityIssueCollection
runAccessibilityCheck() override
;
261 virtual void LoadStyles( SfxObjectShell
& rSource
) override
;
263 void LoadStyles_( SfxObjectShell
& rSource
, bool bPreserveCurrentDocument
);
265 /// Show page style format dialog
267 /// Identifies slot by which the dialog is triggered. Used to activate certain dialog pane
269 weld::Window
* pDialogParent
,
270 const OUString
& rPage
,
271 const OUString
& rPageId
,
272 SwWrtShell
& rActShell
,
273 SfxRequest
* pRequest
= nullptr);
276 /** linked graphics are now loaded on demand.
277 Thus, loading of linked graphics no longer needed and necessary for
278 the load of document being finished. */
280 void LoadingFinished();
282 /// Cancel transfer (called from SFX).
283 virtual void CancelTransfers() override
;
285 /// Re-read Doc from Html-source.
286 void ReloadFromHtml( const OUString
& rStreamName
, SwSrcView
* pSrcView
);
288 sal_Int16
GetUpdateDocMode() const { return m_nUpdateDocMode
; }
290 void ToggleLayoutMode(SwView
* pView
);
292 ErrCode
LoadStylesFromFile(const OUString
& rURL
, SwgReaderOption
& rOpt
, bool bUnoCall
);
293 void InvalidateModel();
294 void ReactivateModel();
296 virtual css::uno::Sequence
< OUString
> GetEventNames() override
;
298 /// #i20883# Digital Signatures and Encryption
299 virtual HiddenInformation
GetHiddenInformationState( HiddenInformation nStates
) override
;
301 /** #i42634# Overwrites SfxObjectShell::UpdateLinks
302 This new function is necessary to trigger update of links in docs
303 read by the binary filter: */
304 virtual void UpdateLinks() override
;
306 css::uno::Reference
< css::frame::XController
>
309 SfxInPlaceClient
* GetIPClient( const ::svt::EmbeddedObjectRef
& xObjRef
);
310 SAL_DLLPRIVATE
bool IsTemplate() const { return m_IsATemplate
; }
311 SAL_DLLPRIVATE
void SetIsTemplate( bool bValue
) { m_IsATemplate
= bValue
; }
313 virtual const ::sfx2::IXmlIdRegistry
* GetXmlIdRegistry() const override
;
315 /** passwword protection for Writer (derived from SfxObjectShell)
316 see also: FN_REDLINE_ON, FN_REDLINE_ON */
317 virtual bool IsChangeRecording() const override
;
318 virtual bool HasChangeRecordProtection() const override
;
319 virtual void SetChangeRecording( bool bActivate
, bool bLockAllViews
= false ) override
;
320 virtual void SetProtectionPassword( const OUString
&rPassword
) override
;
321 virtual bool GetProtectionHash( /*out*/ css::uno::Sequence
< sal_Int8
> &rPasswordHash
) override
;
323 void RegisterAutomationDocumentEventsCaller(css::uno::Reference
< ooo::vba::XSinkCaller
> const& xCaller
);
324 void CallAutomationDocumentEventSinks(const OUString
& Method
, css::uno::Sequence
< css::uno::Any
>& Arguments
);
325 void RegisterAutomationDocumentObject(css::uno::Reference
< ooo::vba::word::XDocument
> const& xDocument
);
327 // Lock all unlocked views, and returns a guard object which unlocks those views when destructed
328 virtual std::unique_ptr
<LockAllViewsGuard
> LockAllViews() override
;
331 class LockAllViewsGuard_Impl final
: public LockAllViewsGuard
333 std::vector
<SwViewShell
*> m_aViewWasUnLocked
;
336 explicit LockAllViewsGuard_Impl(SwViewShell
* pViewShell
);
337 ~LockAllViewsGuard_Impl();
342 /** Find the right DocShell and create a new one:
343 The return value specifies what should happen to the Shell
344 0 - Error, could not find the DocShell
345 1 - DocShell is an existing Document
346 2 - DocShell was created anew, thus it needs to be closed again
347 (will be assigned to xLockRef additionally)
349 int SwFindDocShell( SfxObjectShellRef
& xDocSh
,
350 SfxObjectShellLock
& xLockRef
,
351 std::u16string_view rFileName
,
352 const OUString
& rPasswd
,
353 const OUString
& rFilter
,
355 SwDocShell
* pDestSh
);
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */