Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / docsh.hxx
blob9d2114516c5ddfec098cdd1a222df1484dcdc558
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 <rtl/ref.hxx>
24 #include <com/sun/star/frame/XController.hpp>
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 <svtools/embedhlp.hxx>
33 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
35 #include <sfx2/StyleManager.hxx>
37 class SwDoc;
38 class SfxDocumentInfoDialog;
39 class SfxStyleSheetBasePool;
40 class SfxInPlaceClient;
41 class FontList;
42 class SwEditShell;
43 class SwView;
44 class SwWrtShell;
45 class SwFEShell;
46 class Reader;
47 class SwReader;
48 class SwCursorShell;
49 class SwSrcView;
50 class SwPaM;
51 class SwgReaderOption;
52 class SwOLEObj;
53 class IDocumentDeviceAccess;
54 class IDocumentSettingAccess;
55 class IDocumentChartDataProviderAccess;
56 class SwDocShell;
57 class SwDrawModel;
59 // initialize DrawModel (in form of a SwDrawModel) and DocShell (in form of a SwDocShell)
60 // as needed, one or both parameters may be zero
61 void InitDrawModelAndDocShell(SwDocShell* pSwDocShell, SwDrawModel* pSwDrawModel);
63 class SW_DLLPUBLIC SwDocShell
64 : public SfxObjectShell
65 , public SfxListener
67 SwDoc* m_pDoc; ///< Document.
68 rtl::Reference< SfxStyleSheetBasePool > m_xBasePool; ///< Passing through for formats.
69 FontList* m_pFontList; ///< Current Fontlist.
70 bool m_IsInUpdateFontList; ///< prevent nested calls of UpdateFontList
72 std::unique_ptr<sfx2::StyleManager> m_pStyleManager;
74 /** For "historical reasons" nothing can be done without the WrtShell.
75 Back-pointer on View (again "for historical reasons").
76 Back-pointer is valid until in Activate a new one is set
77 or until it is deleted in the View's Dtor. */
79 SwView* m_pView;
80 SwWrtShell* m_pWrtShell;
82 comphelper::EmbeddedObjectContainer* m_pOLEChildList;
83 sal_Int16 m_nUpdateDocMode; ///< contains the css::document::UpdateDocMode
84 bool m_IsATemplate; ///< prevent nested calls of UpdateFontList
86 bool m_IsRemovedInvisibleContent;
87 ///< whether SID_MAIL_PREPAREEXPORT removed content that
88 ///< SID_MAIL_EXPORT_FINISHED needs to restore
90 /// Methods for access to doc.
91 SAL_DLLPRIVATE void AddLink();
92 SAL_DLLPRIVATE void RemoveLink();
94 /// Catch hint for DocInfo.
95 SAL_DLLPRIVATE virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
97 /// FileIO
98 SAL_DLLPRIVATE virtual bool InitNew( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
99 SAL_DLLPRIVATE virtual bool Load( SfxMedium& rMedium ) override;
100 SAL_DLLPRIVATE virtual bool LoadFrom( SfxMedium& rMedium ) override;
101 SAL_DLLPRIVATE virtual bool ConvertFrom( SfxMedium &rMedium ) override;
102 SAL_DLLPRIVATE virtual bool ConvertTo( SfxMedium &rMedium ) override;
103 SAL_DLLPRIVATE virtual bool SaveAs( SfxMedium& rMedium ) override;
104 SAL_DLLPRIVATE virtual bool SaveCompleted( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
106 SAL_DLLPRIVATE virtual bool PrepareClose( bool bUI = true ) override;
108 SAL_DLLPRIVATE virtual bool InsertGeneratedStream(SfxMedium& rMedium,
109 css::uno::Reference<css::text::XTextRange> const& xInsertPosition)
110 override;
112 /// Make DocInfo known to the Doc.
113 SAL_DLLPRIVATE virtual VclPtr<SfxDocumentInfoDialog> CreateDocumentInfoDialog(const SfxItemSet &) override;
114 /// OLE-stuff
115 SAL_DLLPRIVATE virtual void Draw( OutputDevice*, const JobSetup&, sal_uInt16 = ASPECT_CONTENT) override;
117 /// Methods for StyleSheets
119 /// @param nSlot
120 /// Only used for nFamily == SfxStyleFamily::Page. Identifies optional Slot by which the edit is triggered.
121 /// Used to activate certain dialog pane
122 SAL_DLLPRIVATE sal_uInt16 Edit(
123 const OUString &rName,
124 const OUString& rParent,
125 const SfxStyleFamily nFamily,
126 sal_uInt16 nMask,
127 const bool bNew,
128 const OString& sPageId,
129 SwWrtShell* pActShell = nullptr,
130 const bool bBasic = false );
132 SAL_DLLPRIVATE bool Delete(const OUString &rName, SfxStyleFamily nFamily);
133 SAL_DLLPRIVATE bool Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden);
134 SAL_DLLPRIVATE SfxStyleFamily ApplyStyles(const OUString &rName,
135 const SfxStyleFamily nFamily,
136 SwWrtShell* pShell,
137 sal_uInt16 nMode = 0);
138 SAL_DLLPRIVATE SfxStyleFamily DoWaterCan( const OUString &rName, SfxStyleFamily nFamily);
139 SAL_DLLPRIVATE SfxStyleFamily UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWrtShell* pShell);
140 SAL_DLLPRIVATE SfxStyleFamily MakeByExample(const OUString &rName,
141 SfxStyleFamily nFamily, sal_uInt16 nMask, SwWrtShell* pShell);
143 SAL_DLLPRIVATE void SubInitNew(); ///< for InitNew and HtmlSourceMode.
145 SAL_DLLPRIVATE void RemoveOLEObjects();
146 SAL_DLLPRIVATE void CalcLayoutForOLEObjects();
148 SAL_DLLPRIVATE void Init_Impl();
150 using SfxObjectShell::GetVisArea;
152 protected:
153 /// override to update text fields
154 virtual void DoFlushDocInfo() override;
156 public:
157 /// but we implement this ourselves.
158 SFX_DECL_INTERFACE(SW_DOCSHELL)
159 SFX_DECL_OBJECTFACTORY()
161 private:
162 /// SfxInterface initializer.
163 static void InitInterface_Impl();
165 public:
166 static OUString GetEventName( sal_Int32 nId );
168 /// Doc is required for SO data exchange!
169 SwDocShell( SfxObjectCreateMode eMode = SfxObjectCreateMode::EMBEDDED );
170 SwDocShell( SfxModelFlags i_nSfxCreationFlags );
171 SwDocShell( SwDoc *pDoc, SfxObjectCreateMode eMode = SfxObjectCreateMode::STANDARD );
172 virtual ~SwDocShell() override;
174 /// OLE 2.0-notification.
175 DECL_LINK( Ole2ModifiedHdl, bool, void );
177 /// OLE-stuff.
178 virtual void SetVisArea( const tools::Rectangle &rRect ) override;
179 virtual tools::Rectangle GetVisArea( sal_uInt16 nAspect ) const override;
180 virtual Printer *GetDocumentPrinter() override;
181 virtual OutputDevice* GetDocumentRefDev() override;
182 virtual void OnDocumentPrinterChanged( Printer * pNewPrinter ) override;
183 virtual sal_uLong GetMiscStatus() const override;
185 virtual void PrepareReload() override;
186 virtual void SetModified( bool = true ) override;
188 /// Dispatcher
189 void Execute(SfxRequest &);
190 void ExecStyleSheet(SfxRequest&);
192 void GetState(SfxItemSet &);
193 void StateStyleSheet(SfxItemSet&, SwWrtShell* pSh = nullptr );
195 /// returns Doc. But be careful!
196 SwDoc* GetDoc() { return m_pDoc; }
197 const SwDoc* GetDoc() const { return m_pDoc; }
198 IDocumentDeviceAccess& getIDocumentDeviceAccess();
199 IDocumentChartDataProviderAccess& getIDocumentChartDataProviderAccess();
201 void UpdateFontList();
202 void UpdateChildWindows();
204 /// global IO.
205 virtual bool Save() override;
207 /// For Style PI.
208 virtual SfxStyleSheetBasePool* GetStyleSheetPool() override;
209 virtual sfx2::StyleManager* GetStyleManager() override;
211 /// Set View for actions via Shell.
212 void SetView(SwView* pVw);
213 const SwView *GetView() const { return m_pView; }
214 SwView *GetView() { return m_pView; }
216 /// Access to the SwWrtShell belonging to SwView.
217 SwWrtShell *GetWrtShell() { return m_pWrtShell; }
218 const SwWrtShell *GetWrtShell() const { return m_pWrtShell; }
219 // Same as GetWrtShell, but return pointer to SwEditShell base of
220 // (potentially incomplete) SwWrtShell:
221 SwEditShell * GetEditShell();
223 /// For Core - it knows the DocShell but not the WrtShell!
224 SwFEShell *GetFEShell();
225 const SwFEShell *GetFEShell() const
226 { return const_cast<SwDocShell*>(this)->GetFEShell(); }
228 /// For inserting document.
229 Reader* StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
230 SwCursorShell* pCursorSh = nullptr, SwPaM* pPaM = nullptr);
232 #if defined(_WIN32)
233 virtual bool DdeGetData( const OUString& rItem, const OUString& rMimeType,
234 css::uno::Any & rValue ) override;
235 virtual bool DdeSetData( const OUString& rItem, const OUString& rMimeType,
236 const css::uno::Any & rValue ) override;
237 #endif
238 virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) override;
239 virtual void ReconnectDdeLink(SfxObjectShell& rServer) override;
241 virtual void FillClass( SvGlobalName * pClassName,
242 SotClipboardFormatId * pClipFormat,
243 OUString * pAppName,
244 OUString * pLongUserName,
245 OUString * pUserName,
246 sal_Int32 nFileFormat,
247 bool bTemplate = false ) const override;
249 virtual std::set<Color> GetDocColors() override;
251 virtual void LoadStyles( SfxObjectShell& rSource ) override;
253 void LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument );
255 /// Show page style format dialog
256 /// @param nSlot
257 /// Identifies slot by which the dialog is triggered. Used to activate certain dialog pane
258 void FormatPage(
259 const OUString& rPage,
260 const OString& rPageId,
261 SwWrtShell& rActShell );
263 // #i59688#
264 /** linked graphics are now loaded on demand.
265 Thus, loading of linked graphics no longer needed and necessary for
266 the load of document being finished. */
268 void LoadingFinished();
269 virtual void SetFormatSpecificCompatibilityOptions( const OUString& rFilterTypeName ) override;
271 /// Cancel transfer (called from SFX).
272 virtual void CancelTransfers() override;
274 /// Re-read Doc from Html-source.
275 void ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView );
277 sal_Int16 GetUpdateDocMode() const { return m_nUpdateDocMode; }
279 void ToggleLayoutMode(SwView* pView);
281 sal_uLong LoadStylesFromFile( const OUString& rURL, SwgReaderOption& rOpt,
282 bool bUnoCall );
283 void InvalidateModel();
284 void ReactivateModel();
286 virtual css::uno::Sequence< OUString > GetEventNames() override;
288 /// #i20883# Digital Signatures and Encryption
289 virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override;
291 /** #i42634# Overwrites SfxObjectShell::UpdateLinks
292 This new function is necessary to trigger update of links in docs
293 read by the binary filter: */
294 virtual void UpdateLinks() override;
296 css::uno::Reference< css::frame::XController >
297 GetController();
299 SfxInPlaceClient* GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef );
300 SAL_DLLPRIVATE bool IsTemplate() { return m_IsATemplate; }
301 SAL_DLLPRIVATE void SetIsTemplate( bool bValue ) { m_IsATemplate = bValue; }
303 virtual const ::sfx2::IXmlIdRegistry* GetXmlIdRegistry() const override;
305 /** passwword protection for Writer (derived from SfxObjectShell)
306 see also: FN_REDLINE_ON, FN_REDLINE_ON */
307 virtual bool IsChangeRecording() const override;
308 virtual bool HasChangeRecordProtection() const override;
309 virtual void SetChangeRecording( bool bActivate ) override;
310 virtual void SetProtectionPassword( const OUString &rPassword ) override;
311 virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;
314 /** Find the right DocShell and create a new one:
315 The return value specifies what should happen to the Shell
316 0 - Error, could not find the DocShell
317 1 - DocShell is an existing Document
318 2 - DocShell was created anew, thus it needs to be closed again
319 (will be assigned to xLockRef additionally)
321 int SwFindDocShell( SfxObjectShellRef& xDocSh,
322 SfxObjectShellLock& xLockRef,
323 const OUString& rFileName,
324 const OUString& rPasswd,
325 const OUString& rFilter,
326 sal_Int16 nVersion,
327 SwDocShell* pDestSh );
329 #endif
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */