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
{ namespace sun
{ namespace star
{ namespace frame
{ class XController
; } } } }
60 namespace ooo
{ namespace vba
{ class XSinkCaller
; } }
61 namespace ooo
{ namespace vba
{ namespace 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::unique_ptr
<SfxDocumentInfoDialog
> CreateDocumentInfoDialog(weld::Window
* pParent
,
121 const SfxItemSet
&rSet
) override
;
123 SAL_DLLPRIVATE
virtual void Draw( OutputDevice
*, const JobSetup
&, sal_uInt16 nAspect
) 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 const OUString
&rName
,
132 const OUString
& rParent
,
133 const SfxStyleFamily nFamily
,
134 SfxStyleSearchBits nMask
,
136 const OString
& sPageId
,
137 SwWrtShell
* pActShell
,
138 SfxRequest
* pRequest
= nullptr,
139 sal_uInt16 nSlot
= 0);
141 SAL_DLLPRIVATE
void Delete(const OUString
&rName
, SfxStyleFamily nFamily
);
142 SAL_DLLPRIVATE
void Hide(const OUString
&rName
, SfxStyleFamily nFamily
, bool bHidden
);
143 SAL_DLLPRIVATE SfxStyleFamily
ApplyStyles(const OUString
&rName
,
144 const SfxStyleFamily nFamily
,
147 SAL_DLLPRIVATE SfxStyleFamily
DoWaterCan( const OUString
&rName
, SfxStyleFamily nFamily
);
148 SAL_DLLPRIVATE
void UpdateStyle(const OUString
&rName
, SfxStyleFamily nFamily
, SwWrtShell
* pShell
);
149 SAL_DLLPRIVATE
void MakeByExample(const OUString
&rName
,
150 SfxStyleFamily nFamily
, SfxStyleSearchBits nMask
, SwWrtShell
* pShell
);
152 SAL_DLLPRIVATE
void SubInitNew(); ///< for InitNew and HtmlSourceMode.
154 SAL_DLLPRIVATE
void RemoveOLEObjects();
155 SAL_DLLPRIVATE
void CalcLayoutForOLEObjects();
157 SAL_DLLPRIVATE
void Init_Impl();
159 using SfxObjectShell::GetVisArea
;
162 /// override to update text fields
163 virtual void DoFlushDocInfo() override
;
166 /// but we implement this ourselves.
167 SFX_DECL_INTERFACE(SW_DOCSHELL
)
168 SFX_DECL_OBJECTFACTORY()
171 /// SfxInterface initializer.
172 static void InitInterface_Impl();
175 static OUString
GetEventName( sal_Int32 nId
);
177 /// Doc is required for SO data exchange!
178 SwDocShell( SfxObjectCreateMode eMode
= SfxObjectCreateMode::EMBEDDED
);
179 SwDocShell( SfxModelFlags i_nSfxCreationFlags
);
180 SwDocShell( SwDoc
*pDoc
, SfxObjectCreateMode eMode
);
181 virtual ~SwDocShell() override
;
183 /// OLE 2.0-notification.
184 DECL_LINK( Ole2ModifiedHdl
, bool, void );
187 virtual void SetVisArea( const tools::Rectangle
&rRect
) override
;
188 virtual tools::Rectangle
GetVisArea( sal_uInt16 nAspect
) const override
;
189 virtual Printer
*GetDocumentPrinter() override
;
190 virtual OutputDevice
* GetDocumentRefDev() override
;
191 virtual void OnDocumentPrinterChanged( Printer
* pNewPrinter
) override
;
193 virtual void SetModified( bool = true ) override
;
196 void Execute(SfxRequest
&);
197 void ExecStyleSheet(SfxRequest
&);
199 void GetState(SfxItemSet
&);
200 void StateStyleSheet(SfxItemSet
&, SwWrtShell
* pSh
= nullptr );
202 /// returns Doc. But be careful!
203 SwDoc
* GetDoc() { return m_xDoc
.get(); }
204 const SwDoc
* GetDoc() const { return m_xDoc
.get(); }
205 IDocumentDeviceAccess
& getIDocumentDeviceAccess();
206 IDocumentChartDataProviderAccess
& getIDocumentChartDataProviderAccess();
208 void UpdateFontList();
209 void UpdateChildWindows();
212 virtual bool Save() override
;
215 virtual SfxStyleSheetBasePool
* GetStyleSheetPool() override
;
216 virtual sfx2::StyleManager
* GetStyleManager() override
;
218 /// Set View for actions via Shell.
219 void SetView(SwView
* pVw
);
220 const SwView
*GetView() const { return m_pView
; }
221 SwView
*GetView() { return m_pView
; }
223 /// Access to the SwWrtShell belonging to SwView.
224 SwWrtShell
*GetWrtShell() { return m_pWrtShell
; }
225 const SwWrtShell
*GetWrtShell() const { return m_pWrtShell
; }
226 // Same as GetWrtShell, but return pointer to SwEditShell base of
227 // (potentially incomplete) SwWrtShell:
228 SwEditShell
* GetEditShell();
230 /// For Core - it knows the DocShell but not the WrtShell!
231 SwFEShell
*GetFEShell();
232 const SwFEShell
*GetFEShell() const
233 { return const_cast<SwDocShell
*>(this)->GetFEShell(); }
235 /// For inserting document.
236 Reader
* StartConvertFrom(SfxMedium
& rMedium
, SwReaderPtr
& rpRdr
,
237 SwCursorShell
const * pCursorSh
= nullptr, SwPaM
* pPaM
= nullptr);
240 virtual bool DdeGetData( const OUString
& rItem
, const OUString
& rMimeType
,
241 css::uno::Any
& rValue
) override
;
242 virtual bool DdeSetData( const OUString
& rItem
, const OUString
& rMimeType
,
243 const css::uno::Any
& rValue
) override
;
245 virtual ::sfx2::SvLinkSource
* DdeCreateLinkSource( const OUString
& rItem
) override
;
246 virtual void ReconnectDdeLink(SfxObjectShell
& rServer
) override
;
248 virtual void FillClass( SvGlobalName
* pClassName
,
249 SotClipboardFormatId
* pClipFormat
,
250 OUString
* pLongUserName
,
251 sal_Int32 nFileFormat
,
252 bool bTemplate
= false ) const override
;
254 virtual std::set
<Color
> GetDocColors() override
;
256 virtual void LoadStyles( SfxObjectShell
& rSource
) override
;
258 void LoadStyles_( SfxObjectShell
& rSource
, bool bPreserveCurrentDocument
);
260 /// Show page style format dialog
262 /// Identifies slot by which the dialog is triggered. Used to activate certain dialog pane
264 const OUString
& rPage
,
265 const OString
& rPageId
,
266 SwWrtShell
& rActShell
,
267 SfxRequest
* pRequest
= nullptr);
270 /** linked graphics are now loaded on demand.
271 Thus, loading of linked graphics no longer needed and necessary for
272 the load of document being finished. */
274 void LoadingFinished();
275 virtual void SetFormatSpecificCompatibilityOptions( const OUString
& rFilterTypeName
) override
;
277 /// Cancel transfer (called from SFX).
278 virtual void CancelTransfers() override
;
280 /// Re-read Doc from Html-source.
281 void ReloadFromHtml( const OUString
& rStreamName
, SwSrcView
* pSrcView
);
283 sal_Int16
GetUpdateDocMode() const { return m_nUpdateDocMode
; }
285 void ToggleLayoutMode(SwView
* pView
);
287 ErrCode
LoadStylesFromFile( const OUString
& rURL
, SwgReaderOption
const & rOpt
,
289 void InvalidateModel();
290 void ReactivateModel();
292 virtual css::uno::Sequence
< OUString
> GetEventNames() override
;
294 /// #i20883# Digital Signatures and Encryption
295 virtual HiddenInformation
GetHiddenInformationState( HiddenInformation nStates
) override
;
297 /** #i42634# Overwrites SfxObjectShell::UpdateLinks
298 This new function is necessary to trigger update of links in docs
299 read by the binary filter: */
300 virtual void UpdateLinks() override
;
302 css::uno::Reference
< css::frame::XController
>
305 SfxInPlaceClient
* GetIPClient( const ::svt::EmbeddedObjectRef
& xObjRef
);
306 SAL_DLLPRIVATE
bool IsTemplate() const { return m_IsATemplate
; }
307 SAL_DLLPRIVATE
void SetIsTemplate( bool bValue
) { m_IsATemplate
= bValue
; }
309 virtual const ::sfx2::IXmlIdRegistry
* GetXmlIdRegistry() const override
;
311 /** passwword protection for Writer (derived from SfxObjectShell)
312 see also: FN_REDLINE_ON, FN_REDLINE_ON */
313 virtual bool IsChangeRecording() const override
;
314 virtual bool HasChangeRecordProtection() const override
;
315 virtual void SetChangeRecording( bool bActivate
) override
;
316 virtual void SetProtectionPassword( const OUString
&rPassword
) override
;
317 virtual bool GetProtectionHash( /*out*/ css::uno::Sequence
< sal_Int8
> &rPasswordHash
) override
;
319 void RegisterAutomationDocumentEventsCaller(css::uno::Reference
< ooo::vba::XSinkCaller
> const& xCaller
);
320 void CallAutomationDocumentEventSinks(const OUString
& Method
, css::uno::Sequence
< css::uno::Any
>& Arguments
);
321 void RegisterAutomationDocumentObject(css::uno::Reference
< ooo::vba::word::XDocument
> const& xDocument
);
323 class LockAllViewsGuard
325 std::vector
<SwViewShell
*> m_aViewWasUnLocked
;
328 explicit LockAllViewsGuard(SwViewShell
* pViewShell
);
329 ~LockAllViewsGuard();
331 // Lock all unlocked views, and returns a guard object which unlocks those views when destructed
332 std::unique_ptr
<LockAllViewsGuard
> LockAllViews();
335 /** Find the right DocShell and create a new one:
336 The return value specifies what should happen to the Shell
337 0 - Error, could not find the DocShell
338 1 - DocShell is an existing Document
339 2 - DocShell was created anew, thus it needs to be closed again
340 (will be assigned to xLockRef additionally)
342 int SwFindDocShell( SfxObjectShellRef
& xDocSh
,
343 SfxObjectShellLock
& xLockRef
,
344 const OUString
& rFileName
,
345 const OUString
& rPasswd
,
346 const OUString
& rFilter
,
348 SwDocShell
* pDestSh
);
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */