/src/libreoffice/sw/inc/docsh.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | #pragma once |
20 | | |
21 | | #include <memory> |
22 | | #include <vector> |
23 | | #include <rtl/ref.hxx> |
24 | | #include <com/sun/star/uno/Sequence.h> |
25 | | #include <sfx2/docfac.hxx> |
26 | | #include <sfx2/objsh.hxx> |
27 | | #include "swdllapi.h" |
28 | | #include "shellid.hxx" |
29 | | |
30 | | #include <svl/lstner.hxx> |
31 | | #include <sfx2/StyleManager.hxx> |
32 | | #include <o3tl/deleter.hxx> |
33 | | |
34 | | class SwDoc; |
35 | | class SfxInPlaceClient; |
36 | | class FontList; |
37 | | class SwEditShell; |
38 | | class SwView; |
39 | | class SwWrtShell; |
40 | | class SwFEShell; |
41 | | class Reader; |
42 | | class SwReader; |
43 | | typedef std::unique_ptr<SwReader, o3tl::default_delete<SwReader>> SwReaderPtr; |
44 | | class SwCursorShell; |
45 | | class SwSrcView; |
46 | | class SwPaM; |
47 | | class SwgReaderOption; |
48 | | class IDocumentDeviceAccess; |
49 | | class IDocumentChartDataProviderAccess; |
50 | | class SwDocShell; |
51 | | class SwDrawModel; |
52 | | class SwViewShell; |
53 | | class SwDocStyleSheetPool; |
54 | | class SwXTextDocument; |
55 | | class SwTextFormatColl; |
56 | | class UIName; |
57 | | namespace svt |
58 | | { |
59 | | class EmbeddedObjectRef; |
60 | | } |
61 | | namespace com::sun::star::frame { class XController; } |
62 | | namespace ooo::vba { class XSinkCaller; } |
63 | | namespace ooo::vba::word { class XDocument; } |
64 | | |
65 | | // initialize DrawModel (in form of a SwDrawModel) and DocShell (in form of a SwDocShell) |
66 | | // as needed, one or both parameters may be zero |
67 | | void InitDrawModelAndDocShell(SwDocShell* pSwDocShell, SwDrawModel* pSwDrawModel); |
68 | | |
69 | | class SW_DLLPUBLIC SwDocShell |
70 | | : public SfxObjectShell |
71 | | , public SfxListener |
72 | | { |
73 | | rtl::Reference< SwDoc > m_xDoc; ///< Document. |
74 | | rtl::Reference< SwDocStyleSheetPool > m_xBasePool; ///< Passing through for formats. |
75 | | std::unique_ptr<FontList> m_pFontList; ///< Current Fontlist. |
76 | | bool m_IsInUpdateFontList; ///< prevent nested calls of UpdateFontList |
77 | | |
78 | | std::unique_ptr<sfx2::StyleManager> m_pStyleManager; |
79 | | |
80 | | /** For "historical reasons" nothing can be done without the WrtShell. |
81 | | Back-pointer on View (again "for historical reasons"). |
82 | | Back-pointer is valid until in Activate a new one is set |
83 | | or until it is deleted in the View's Dtor. */ |
84 | | |
85 | | SwView* m_pView; |
86 | | SwWrtShell* m_pWrtShell; |
87 | | |
88 | | std::unique_ptr<comphelper::EmbeddedObjectContainer> m_pOLEChildList; |
89 | | sal_Int16 m_nUpdateDocMode; ///< contains the css::document::UpdateDocMode |
90 | | bool m_IsATemplate; ///< prevent nested calls of UpdateFontList |
91 | | |
92 | | bool m_IsRemovedInvisibleContent; |
93 | | ///< whether SID_MAIL_PREPAREEXPORT removed content that |
94 | | ///< SID_MAIL_EXPORT_FINISHED needs to restore |
95 | | |
96 | | css::uno::Reference< ooo::vba::XSinkCaller > mxAutomationDocumentEventsCaller; |
97 | | css::uno::Reference< ooo::vba::word::XDocument> mxAutomationDocumentObject; |
98 | | |
99 | | /// Methods for access to doc. |
100 | | SAL_DLLPRIVATE void AddLink(); |
101 | | SAL_DLLPRIVATE void RemoveLink(); |
102 | | |
103 | | /// Catch hint for DocInfo. |
104 | | SAL_DLLPRIVATE virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; |
105 | | |
106 | | /// FileIO |
107 | | SAL_DLLPRIVATE virtual bool InitNew( const css::uno::Reference< css::embed::XStorage >& xStorage ) override; |
108 | | SAL_DLLPRIVATE virtual bool Load( SfxMedium& rMedium ) override; |
109 | | SAL_DLLPRIVATE virtual bool LoadFrom( SfxMedium& rMedium ) override; |
110 | | SAL_DLLPRIVATE virtual bool ConvertFrom( SfxMedium &rMedium ) override; |
111 | | SAL_DLLPRIVATE virtual bool ConvertTo( SfxMedium &rMedium ) override; |
112 | | SAL_DLLPRIVATE virtual bool SaveAs( SfxMedium& rMedium ) override; |
113 | | SAL_DLLPRIVATE virtual bool SaveCompleted( const css::uno::Reference< css::embed::XStorage >& xStorage ) override; |
114 | | |
115 | | SAL_DLLPRIVATE virtual bool PrepareClose( bool bUI = true ) override; |
116 | | |
117 | | SAL_DLLPRIVATE virtual bool InsertGeneratedStream(SfxMedium& rMedium, |
118 | | css::uno::Reference<css::text::XTextRange> const& xInsertPosition) |
119 | | override; |
120 | | |
121 | | /// Make DocInfo known to the Doc. |
122 | | SAL_DLLPRIVATE virtual std::shared_ptr<SfxDocumentInfoDialog> CreateDocumentInfoDialog(weld::Window* pParent, |
123 | | const SfxItemSet &rSet) override; |
124 | | /// OLE-stuff |
125 | | SAL_DLLPRIVATE virtual void Draw(OutputDevice*, const JobSetup&, sal_uInt16 nAspect, bool bOutputToWindow) override; |
126 | | |
127 | | /// Methods for StyleSheets |
128 | | |
129 | | /// @param nSlot |
130 | | /// Only used for nFamily == SfxStyleFamily::Page. Identifies optional Slot by which the edit is triggered. |
131 | | /// Used to activate certain dialog pane |
132 | | SAL_DLLPRIVATE void Edit( |
133 | | weld::Window* pDialogParent, |
134 | | const UIName& rName, |
135 | | const UIName& rParent, |
136 | | const SfxStyleFamily nFamily, |
137 | | SfxStyleSearchBits nMask, |
138 | | const bool bNew, |
139 | | const OUString& sPageId, |
140 | | SwWrtShell* pActShell, |
141 | | SfxRequest* pRequest = nullptr, |
142 | | sal_uInt16 nSlot = 0); |
143 | | |
144 | | SAL_DLLPRIVATE void Delete(const OUString &rName, SfxStyleFamily nFamily); |
145 | | SAL_DLLPRIVATE void Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden); |
146 | | SAL_DLLPRIVATE bool MakeInlineHeading(SwWrtShell *pSh, SwTextFormatColl* pColl, |
147 | | const sal_uInt16 nMode); |
148 | | SAL_DLLPRIVATE SfxStyleFamily ApplyStyles(const OUString &rName, |
149 | | const SfxStyleFamily nFamily, |
150 | | SwWrtShell* pShell, |
151 | | sal_uInt16 nMode); |
152 | | SAL_DLLPRIVATE SfxStyleFamily DoWaterCan( const OUString &rName, SfxStyleFamily nFamily); |
153 | | SAL_DLLPRIVATE void UpdateStyle(const UIName &rName, SfxStyleFamily nFamily, SwWrtShell* pShell); |
154 | | SAL_DLLPRIVATE void MakeByExample(const UIName &rName, |
155 | | SfxStyleFamily nFamily, SfxStyleSearchBits nMask, SwWrtShell* pShell); |
156 | | |
157 | | SAL_DLLPRIVATE void SubInitNew(); ///< for InitNew and HtmlSourceMode. |
158 | | |
159 | | SAL_DLLPRIVATE void RemoveOLEObjects(); |
160 | | SAL_DLLPRIVATE void CalcLayoutForOLEObjects(); |
161 | | |
162 | | SAL_DLLPRIVATE void Init_Impl(); |
163 | | |
164 | | using SfxObjectShell::GetVisArea; |
165 | | |
166 | | protected: |
167 | | /// override to update text fields |
168 | | virtual void DoFlushDocInfo() override; |
169 | | |
170 | | public: |
171 | | /// but we implement this ourselves. |
172 | | SFX_DECL_INTERFACE(SW_DOCSHELL) |
173 | | SFX_DECL_OBJECTFACTORY() |
174 | | |
175 | | private: |
176 | | /// SfxInterface initializer. |
177 | | static void InitInterface_Impl(); |
178 | | |
179 | | public: |
180 | | static const OUString & GetEventName( sal_Int32 nId ); |
181 | | |
182 | | /// Doc is required for SO data exchange! |
183 | | SwDocShell( SfxObjectCreateMode eMode = SfxObjectCreateMode::EMBEDDED ); |
184 | | SwDocShell( SfxModelFlags i_nSfxCreationFlags ); |
185 | | SwDocShell( SwDoc& rDoc, SfxObjectCreateMode eMode ); |
186 | | virtual ~SwDocShell() override; |
187 | | |
188 | | /// OLE 2.0-notification. |
189 | | DECL_DLLPRIVATE_LINK( Ole2ModifiedHdl, bool, void ); |
190 | | |
191 | | /// Override SfxObjectShell::GetBaseModel and return a more accurate type |
192 | | rtl::Reference<SwXTextDocument> GetBaseModel() const; |
193 | | |
194 | | /// OLE-stuff. |
195 | | virtual void SetVisArea( const tools::Rectangle &rRect ) override; |
196 | | virtual tools::Rectangle GetVisArea( sal_uInt16 nAspect ) const override; |
197 | | virtual Printer *GetDocumentPrinter() override; |
198 | | virtual OutputDevice* GetDocumentRefDev() override; |
199 | | virtual void OnDocumentPrinterChanged( Printer * pNewPrinter ) override; |
200 | | |
201 | | virtual void SetModified( bool = true ) override; |
202 | | |
203 | | /// Dispatcher |
204 | | void Execute(SfxRequest &); |
205 | | void ExecStyleSheet(SfxRequest&); |
206 | | |
207 | | void GetState(SfxItemSet &); |
208 | | void StateStyleSheet(SfxItemSet&, SwWrtShell* pSh = nullptr ); |
209 | | |
210 | | /// returns Doc. But be careful! |
211 | 3.25M | SwDoc* GetDoc() { return m_xDoc.get(); } |
212 | 14 | const SwDoc* GetDoc() const { return m_xDoc.get(); } |
213 | | IDocumentDeviceAccess& getIDocumentDeviceAccess(); |
214 | | IDocumentChartDataProviderAccess& getIDocumentChartDataProviderAccess(); |
215 | | |
216 | | void UpdateFontList(); |
217 | | void UpdateChildWindows(); |
218 | | |
219 | | /// global IO. |
220 | | virtual bool Save() override; |
221 | | |
222 | | /// For Style PI. |
223 | | virtual SfxStyleSheetBasePool* GetStyleSheetPool() override; |
224 | | virtual sfx2::StyleManager* GetStyleManager() override; |
225 | | |
226 | | /// Set View for actions via Shell. |
227 | | void SetView(SwView* pVw); |
228 | 18.0k | const SwView *GetView() const { return m_pView; } |
229 | 7.97M | SwView *GetView() { return m_pView; } |
230 | | |
231 | | /// Access to the SwWrtShell belonging to SwView. |
232 | 166M | SwWrtShell *GetWrtShell() { return m_pWrtShell; } |
233 | 0 | const SwWrtShell *GetWrtShell() const { return m_pWrtShell; } |
234 | | // Same as GetWrtShell, but return pointer to SwEditShell base of |
235 | | // (potentially incomplete) SwWrtShell: |
236 | | SwEditShell * GetEditShell(); |
237 | | |
238 | | /// For Core - it knows the DocShell but not the WrtShell! |
239 | | SwFEShell *GetFEShell(); |
240 | | const SwFEShell *GetFEShell() const |
241 | 0 | { return const_cast<SwDocShell*>(this)->GetFEShell(); } |
242 | | |
243 | | /// For inserting document. |
244 | | Reader* StartConvertFrom(SfxMedium& rMedium, SwReaderPtr& rpRdr, |
245 | | SwCursorShell const * pCursorSh = nullptr, SwPaM* pPaM = nullptr); |
246 | | |
247 | | #if defined(_WIN32) |
248 | | virtual bool DdeGetData( const OUString& rItem, const OUString& rMimeType, |
249 | | css::uno::Any & rValue ) override; |
250 | | virtual bool DdeSetData( const OUString& rItem, const OUString& rMimeType, |
251 | | const css::uno::Any & rValue ) override; |
252 | | #endif |
253 | | virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) override; |
254 | | virtual void ReconnectDdeLink(SfxObjectShell& rServer) override; |
255 | | |
256 | | virtual void FillClass( SvGlobalName * pClassName, |
257 | | SotClipboardFormatId * pClipFormat, |
258 | | OUString * pLongUserName, |
259 | | sal_Int32 nFileFormat, |
260 | | bool bTemplate = false ) const override; |
261 | | |
262 | | virtual std::set<Color> GetDocColors() override; |
263 | | |
264 | | virtual std::shared_ptr<model::ColorSet> GetThemeColors() override; |
265 | | |
266 | | sfx::AccessibilityIssueCollection runAccessibilityCheck() override; |
267 | | |
268 | | virtual void LoadStyles( SfxObjectShell& rSource ) override; |
269 | | |
270 | | void LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument ); |
271 | | |
272 | | /// Show page style format dialog |
273 | | /// @param nSlot |
274 | | /// Identifies slot by which the dialog is triggered. Used to activate certain dialog pane |
275 | | void FormatPage( |
276 | | weld::Window* pDialogParent, |
277 | | const UIName& rPage, |
278 | | const OUString& rPageId, |
279 | | SwWrtShell& rActShell, |
280 | | SfxRequest* pRequest = nullptr); |
281 | | |
282 | | // #i59688# |
283 | | /** linked graphics are now loaded on demand. |
284 | | Thus, loading of linked graphics no longer needed and necessary for |
285 | | the load of document being finished. */ |
286 | | |
287 | | void LoadingFinished(); |
288 | | |
289 | | /// Cancel transfer (called from SFX). |
290 | | virtual void CancelTransfers() override; |
291 | | |
292 | | /// Re-read Doc from Html-source. |
293 | | void ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView ); |
294 | | |
295 | 0 | sal_Int16 GetUpdateDocMode() const { return m_nUpdateDocMode; } |
296 | | |
297 | | void ToggleLayoutMode(SwView* pView); |
298 | | |
299 | | ErrCodeMsg LoadStylesFromFile(const OUString& rURL, SwgReaderOption& rOpt, bool bUnoCall); |
300 | | void InvalidateModel(); |
301 | | void ReactivateModel(); |
302 | | |
303 | | virtual css::uno::Sequence< OUString > GetEventNames() override; |
304 | | |
305 | | /// #i20883# Digital Signatures and Encryption |
306 | | virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override; |
307 | | |
308 | | /** #i42634# Overwrites SfxObjectShell::UpdateLinks |
309 | | This new function is necessary to trigger update of links in docs |
310 | | read by the binary filter: */ |
311 | | virtual void UpdateLinks() override; |
312 | | |
313 | | css::uno::Reference< css::frame::XController > |
314 | | GetController(); |
315 | | |
316 | | SfxInPlaceClient* GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef ); |
317 | 0 | SAL_DLLPRIVATE bool IsTemplate() const { return m_IsATemplate; } |
318 | 18.4k | SAL_DLLPRIVATE void SetIsTemplate( bool bValue ) { m_IsATemplate = bValue; } |
319 | | |
320 | | virtual const ::sfx2::IXmlIdRegistry* GetXmlIdRegistry() const override; |
321 | | |
322 | | /** passwword protection for Writer (derived from SfxObjectShell) |
323 | | see also: FN_REDLINE_ON, FN_REDLINE_ON */ |
324 | | virtual bool IsChangeRecording(SfxViewShell* pViewShell = nullptr, bool bRecordAllViews = true) const override; |
325 | | virtual bool HasChangeRecordProtection() const override; |
326 | | virtual void SetChangeRecording( bool bActivate, bool bLockAllViews = false, SfxRedlineRecordingMode eRedlineRecordingMode = SfxRedlineRecordingMode::ViewAgnostic) override; |
327 | | virtual void SetProtectionPassword( const OUString &rPassword ) override; |
328 | | virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override; |
329 | | |
330 | | void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller); |
331 | | void CallAutomationDocumentEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments); |
332 | | void RegisterAutomationDocumentObject(css::uno::Reference< ooo::vba::word::XDocument > const& xDocument); |
333 | | |
334 | | // Lock all unlocked views, and returns a guard object which unlocks those views when destructed |
335 | | virtual std::unique_ptr<LockAllViewsGuard> LockAllViews() override; |
336 | | |
337 | | protected: |
338 | | class LockAllViewsGuard_Impl final : public LockAllViewsGuard |
339 | | { |
340 | | std::vector<SwViewShell*> m_aViewWasUnLocked; |
341 | | |
342 | | public: |
343 | | explicit LockAllViewsGuard_Impl(SwViewShell* pViewShell); |
344 | | ~LockAllViewsGuard_Impl(); |
345 | | }; |
346 | | |
347 | | }; |
348 | | |
349 | | /** Find the right DocShell and create a new one: |
350 | | The return value specifies what should happen to the Shell |
351 | | 0 - Error, could not find the DocShell |
352 | | 1 - DocShell is an existing Document |
353 | | 2 - DocShell was created anew, thus it needs to be closed again |
354 | | (will be assigned to xLockRef additionally) |
355 | | */ |
356 | | int SwFindDocShell( SfxObjectShellRef& xDocSh, |
357 | | SfxObjectShellLock& xLockRef, |
358 | | std::u16string_view rFileName, |
359 | | const OUString& rPasswd, |
360 | | const OUString& rFilter, |
361 | | sal_Int16 nVersion, |
362 | | SwDocShell* pDestSh ); |
363 | | |
364 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |