Bump version to 21.06.18.1
[LibreOffice.git] / sw / inc / docsh.hxx
blob070033306af4867fb469d2203ebfd78e47a8f780
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_SW_INC_DOCSH_HXX
20 #define INCLUDED_SW_INC_DOCSH_HXX
22 #include <memory>
23 #include <vector>
24 #include <rtl/ref.hxx>
25 #include <com/sun/star/uno/Sequence.h>
26 #include <sfx2/docfac.hxx>
27 #include <sfx2/objsh.hxx>
28 #include "swdllapi.h"
29 #include "shellid.hxx"
31 #include <svl/lstner.hxx>
32 #include <sfx2/StyleManager.hxx>
33 #include <o3tl/deleter.hxx>
35 class SwDoc;
36 class SfxDocumentInfoDialog;
37 class SfxInPlaceClient;
38 class FontList;
39 class SwEditShell;
40 class SwView;
41 class SwWrtShell;
42 class SwFEShell;
43 class Reader;
44 class SwReader;
45 typedef std::unique_ptr<SwReader, o3tl::default_delete<SwReader>> SwReaderPtr;
46 class SwCursorShell;
47 class SwSrcView;
48 class SwPaM;
49 class SwgReaderOption;
50 class IDocumentDeviceAccess;
51 class IDocumentChartDataProviderAccess;
52 class SwDocShell;
53 class SwDrawModel;
54 class SwViewShell;
55 namespace svt
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
69 , public SfxListener
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. */
83 SwView* m_pView;
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;
104 /// FileIO
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)
117 override;
119 /// Make DocInfo known to the Doc.
120 SAL_DLLPRIVATE virtual std::shared_ptr<SfxDocumentInfoDialog> CreateDocumentInfoDialog(weld::Window* pParent,
121 const SfxItemSet &rSet) override;
122 /// OLE-stuff
123 SAL_DLLPRIVATE virtual void Draw( OutputDevice*, const JobSetup&, sal_uInt16 nAspect) override;
125 /// Methods for StyleSheets
127 /// @param nSlot
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,
135 const bool bNew,
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,
145 SwWrtShell* pShell,
146 sal_uInt16 nMode);
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;
161 protected:
162 /// override to update text fields
163 virtual void DoFlushDocInfo() override;
165 public:
166 /// but we implement this ourselves.
167 SFX_DECL_INTERFACE(SW_DOCSHELL)
168 SFX_DECL_OBJECTFACTORY()
170 private:
171 /// SfxInterface initializer.
172 static void InitInterface_Impl();
174 public:
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& rDoc, SfxObjectCreateMode eMode );
181 virtual ~SwDocShell() override;
183 /// OLE 2.0-notification.
184 DECL_LINK( Ole2ModifiedHdl, bool, void );
186 /// OLE-stuff.
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;
195 /// Dispatcher
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();
211 /// global IO.
212 virtual bool Save() override;
214 /// For Style PI.
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);
239 #if defined(_WIN32)
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;
244 #endif
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;
255 sfx::AccessibilityIssueCollection runAccessibilityCheck() override;
257 virtual void LoadStyles( SfxObjectShell& rSource ) override;
259 void LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument );
261 /// Show page style format dialog
262 /// @param nSlot
263 /// Identifies slot by which the dialog is triggered. Used to activate certain dialog pane
264 void FormatPage(
265 const OUString& rPage,
266 const OString& rPageId,
267 SwWrtShell& rActShell,
268 SfxRequest* pRequest = nullptr);
270 // #i59688#
271 /** linked graphics are now loaded on demand.
272 Thus, loading of linked graphics no longer needed and necessary for
273 the load of document being finished. */
275 void LoadingFinished();
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& rOpt, bool bUnoCall);
288 void InvalidateModel();
289 void ReactivateModel();
291 virtual css::uno::Sequence< OUString > GetEventNames() override;
293 /// #i20883# Digital Signatures and Encryption
294 virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override;
296 /** #i42634# Overwrites SfxObjectShell::UpdateLinks
297 This new function is necessary to trigger update of links in docs
298 read by the binary filter: */
299 virtual void UpdateLinks() override;
301 css::uno::Reference< css::frame::XController >
302 GetController();
304 SfxInPlaceClient* GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef );
305 SAL_DLLPRIVATE bool IsTemplate() const { return m_IsATemplate; }
306 SAL_DLLPRIVATE void SetIsTemplate( bool bValue ) { m_IsATemplate = bValue; }
308 virtual const ::sfx2::IXmlIdRegistry* GetXmlIdRegistry() const override;
310 /** passwword protection for Writer (derived from SfxObjectShell)
311 see also: FN_REDLINE_ON, FN_REDLINE_ON */
312 virtual bool IsChangeRecording() const override;
313 virtual bool HasChangeRecordProtection() const override;
314 virtual void SetChangeRecording( bool bActivate, bool bLockAllViews = false ) override;
315 virtual void SetProtectionPassword( const OUString &rPassword ) override;
316 virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;
318 void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller);
319 void CallAutomationDocumentEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments);
320 void RegisterAutomationDocumentObject(css::uno::Reference< ooo::vba::word::XDocument > const& xDocument);
322 // Lock all unlocked views, and returns a guard object which unlocks those views when destructed
323 virtual std::unique_ptr<LockAllViewsGuard> LockAllViews() override;
325 protected:
326 class LockAllViewsGuard_Impl : public LockAllViewsGuard
328 std::vector<SwViewShell*> m_aViewWasUnLocked;
330 public:
331 explicit LockAllViewsGuard_Impl(SwViewShell* pViewShell);
332 ~LockAllViewsGuard_Impl();
337 /** Find the right DocShell and create a new one:
338 The return value specifies what should happen to the Shell
339 0 - Error, could not find the DocShell
340 1 - DocShell is an existing Document
341 2 - DocShell was created anew, thus it needs to be closed again
342 (will be assigned to xLockRef additionally)
344 int SwFindDocShell( SfxObjectShellRef& xDocSh,
345 SfxObjectShellLock& xLockRef,
346 const OUString& rFileName,
347 const OUString& rPasswd,
348 const OUString& rFilter,
349 sal_Int16 nVersion,
350 SwDocShell* pDestSh );
352 #endif
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */