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 #ifndef INCLUDED_SW_INC_SWMODULE_HXX
20 #define INCLUDED_SW_INC_SWMODULE_HXX
21 
22 #include <sal/config.h>
23 
24 #include <cstddef>
25 
26 #include <o3tl/deleter.hxx>
27 #include <tools/fldunit.hxx>
28 #include <svl/lstner.hxx>
29 #include <svl/itempool.hxx>
30 #include <unotools/options.hxx>
31 #include <sfx2/module.hxx>
32 #include <sfx2/app.hxx>
33 
34 #include "swdllapi.h"
35 #include "shellid.hxx"
36 #include "fldupde.hxx"
37 
38 class Color;
39 class SfxItemSet;
40 class SfxRequest;
41 class SfxErrorHandler;
42 class SwDBConfig;
43 class SwModuleOptions;
44 class SwMasterUsrPref;
45 class SwViewOption;
46 class SwView;
47 class SwWrtShell;
48 class SwPrintOptions;
49 class SwChapterNumRules;
50 class SwStdFontConfig;
51 class SwNavigationConfig;
52 class SwTransferable;
53 class SwToolbarConfigItem;
54 class SwAttrPool;
55 namespace svtools{ class ColorConfig;}
56 class SvtAccessibilityOptions;
57 class SvtCTLOptions;
58 class SvtUserOptions;
59 enum class SwCompareMode;
60 struct SwDBData;
61 namespace tools { class JsonWriter; }
62 
63 enum class SvViewOpt {
64     DestView,
65     DestText,
66     DestWeb,
67     DestViewOnly   //ViewOptions are set only at View, not at the appl.
68 };
69 
70 namespace com::sun::star::scanner { class XScannerManager2; }
71 namespace com::sun::star::linguistic2 { class XLanguageGuessing; }
72 namespace com::sun::star::linguistic2 { class XLinguServiceEventListener; }
73 namespace ooo::vba { class XSinkCaller; }
74 
75 class SW_DLLPUBLIC SwModule final : public SfxModule, public SfxListener, public utl::ConfigurationListener
76 {
77     OUString            m_sActAuthor;
78 
79     // ConfigItems
80     std::unique_ptr<SwModuleOptions, o3tl::default_delete<SwModuleOptions>> m_pModuleConfig;
81     std::unique_ptr<SwMasterUsrPref, o3tl::default_delete<SwMasterUsrPref>> m_pUsrPref;
82     std::unique_ptr<SwMasterUsrPref, o3tl::default_delete<SwMasterUsrPref>> m_pWebUsrPref;
83     std::unique_ptr<SwPrintOptions>      m_pPrintOptions;
84     std::unique_ptr<SwPrintOptions>      m_pWebPrintOptions;
85     std::unique_ptr<SwChapterNumRules>   m_pChapterNumRules;
86     std::unique_ptr<SwStdFontConfig>     m_pStdFontConfig;
87     std::unique_ptr<SwNavigationConfig>  m_pNavigationConfig;
88     std::unique_ptr<SwToolbarConfigItem> m_pToolbarConfig;     //For stacked toolbars. Which one was visible?
89     std::unique_ptr<SwToolbarConfigItem> m_pWebToolbarConfig;
90     std::unique_ptr<SwDBConfig>          m_pDBConfig;
91     std::unique_ptr<svtools::ColorConfig>   m_pColorConfig;
92     std::unique_ptr<SvtAccessibilityOptions> m_pAccessibilityOptions;
93     std::unique_ptr<SvtCTLOptions>       m_pCTLOptions;
94     std::unique_ptr<SvtUserOptions>      m_pUserOptions;
95 
96     std::unique_ptr<SfxErrorHandler> m_pErrorHandler;
97 
98     rtl::Reference<SwAttrPool> m_pAttrPool;
99 
100     // Current view is held here in order to avoid one's being forced
101     // to work via GetActiveView.
102     // View is valid until destroyed in Activate or exchanged.
103     SwView*             m_pView;
104 
105     // List of all Redline-authors.
106     std::vector<OUString> m_pAuthorNames;
107 
108     // DictionaryList listener to trigger spellchecking or hyphenation
109     css::uno::Reference< css::linguistic2::XLinguServiceEventListener > m_xLinguServiceEventListener;
110     css::uno::Reference< css::scanner::XScannerManager2 >    m_xScannerManager;
111     css::uno::Reference< css::linguistic2::XLanguageGuessing >  m_xLanguageGuesser;
112 
113     bool                m_bAuthorInitialised : 1;
114     bool                m_bEmbeddedLoadSave : 1;
115 
116     // Catch hint for DocInfo.
117     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
118 
119     virtual void        ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints ) override;
120 
121     // Envelopes, labels.
122     void                InsertEnv(SfxRequest&);
123     void                InsertLab(SfxRequest&, bool bLabel);
124 
125     css::uno::Reference< ooo::vba::XSinkCaller > mxAutomationApplicationEventsCaller;
126 
127 public:
128     // public Data - used for internal Clipboard / Drag & Drop / XSelection
129     SwTransferable  *m_pDragDrop, *m_pXSelection;
130 
131     SFX_DECL_INTERFACE(SW_INTERFACE_MODULE)
132 
133 private:
134     /// SfxInterface initializer.
135     static void InitInterface_Impl();
136 
137 public:
138     // This Ctor only for SW-Dll.
139     SwModule( SfxObjectFactory* pFact,
140                 SfxObjectFactory* pWebFact,
141                     SfxObjectFactory* pGlobalFact );
142 
143     virtual ~SwModule() override;
144 
145     // Set view for internal use only. It is public only for technical reasons.
SetView(SwView * pVw)146     void        SetView(SwView* pVw) { m_pView = pVw; }
GetView()147     SwView*     GetView() { return m_pView; }
148 
149     // Handler for slots.
150     void                StateOther(SfxItemSet &);
151 
152     void                ExecOther(SfxRequest &);    // Fields, formula...
153 
154     // Modify user settings.
155     const SwMasterUsrPref *GetUsrPref(bool bWeb) const;
156     const SwViewOption* GetViewOption(bool bWeb);
157     void                ApplyUsrPref(const SwViewOption &, SwView*,
158                                      SvViewOpt nDest = SvViewOpt::DestView );
159     void ApplyUserMetric( FieldUnit eMetric, bool bWeb );
160     void ApplyRulerMetric( FieldUnit eMetric, bool bHorizontal, bool bWeb );
161     void ApplyFieldUpdateFlags(SwFieldUpdateFlags eFieldFlags);
162     void ApplyLinkMode(sal_Int32 nNewLinkMode);
163 
164     // Default page mode for text grid.
165     void ApplyDefaultPageMode(bool bIsSquaredPageMode);
166 
167     void ApplyUserCharUnit(bool bApplyChar, bool bWeb);  // apply_char_unit
168 
169     // Create ConfigItems.
GetModuleConfig()170     SwModuleOptions*    GetModuleConfig()       { return m_pModuleConfig.get();}
171     SwPrintOptions*     GetPrtOptions(bool bWeb);
172     SwChapterNumRules*  GetChapterNumRules();
GetStdFontConfig()173     SwStdFontConfig*    GetStdFontConfig()      { return m_pStdFontConfig.get(); }
174     SwNavigationConfig* GetNavigationConfig();
GetToolbarConfig()175     SwToolbarConfigItem*GetToolbarConfig()      { return m_pToolbarConfig.get();    }
GetWebToolbarConfig()176     SwToolbarConfigItem*GetWebToolbarConfig()   { return m_pWebToolbarConfig.get(); }
177     SwDBConfig*         GetDBConfig();
178     svtools::ColorConfig&   GetColorConfig();
179     SvtAccessibilityOptions&    GetAccessibilityOptions();
180     SvtCTLOptions&      GetCTLOptions();
181     SvtUserOptions&     GetUserOptions();
182 
183     // Iterate over views.
184     static SwView*      GetFirstView();
185     static SwView*      GetNextView(SwView const *);
186 
IsEmbeddedLoadSave() const187     bool IsEmbeddedLoadSave() const         { return m_bEmbeddedLoadSave; }
SetEmbeddedLoadSave(bool bFlag)188     void SetEmbeddedLoadSave( bool bFlag )  { m_bEmbeddedLoadSave = bFlag; }
189 
190     static void ShowDBObj( SwView const & rView, const SwDBData& rData);
191 
192     // Table modi.
193     bool            IsInsTableFormatNum(bool bHTML) const;
194     bool            IsInsTableChangeNumFormat(bool bHTML) const;
195     bool            IsInsTableAlignNum(bool bHTML) const;
196     bool            IsSplitVerticalByDefault(bool bHTML) const;
197     void            SetSplitVerticalByDefault(bool bHTML, bool value);
198 
199     // Redlining.
200     std::size_t         GetRedlineAuthor();
201     OUString const &    GetRedlineAuthor(std::size_t nPos);
202     /// See SwXTextDocument::getTrackedChangeAuthors().
203     void                GetRedlineAuthorInfo(tools::JsonWriter& rJsonWriter);
204     std::size_t         InsertRedlineAuthor(const OUString& rAuthor);
205     void                SetRedlineAuthor(const OUString& rAuthor); // for unit tests
206 
207     void                GetInsertAuthorAttr(std::size_t nAuthor, SfxItemSet &rSet);
208     void                GetDeletedAuthorAttr(std::size_t nAuthor, SfxItemSet &rSet);
209     void                GetFormatAuthorAttr(std::size_t nAuthor, SfxItemSet &rSet);
210 
211     sal_uInt16              GetRedlineMarkPos() const;
212     const Color&            GetRedlineMarkColor() const;
213 
214     SwCompareMode      GetCompareMode() const;
215     bool            IsUseRsid() const;
216     bool            IsIgnorePieces() const;
217     sal_uInt16          GetPieceLen() const;
218 
219     // Return defined DocStat - WordDelimiter.
220     OUString const & GetDocStatWordDelim() const;
221 
222     // Pass metric of ModuleConfig (for HTML-export).
223     FieldUnit GetMetric( bool bWeb ) const;
224 
225     // Pass update-statuses.
226     sal_uInt16 GetLinkUpdMode() const;
227     SwFieldUpdateFlags GetFieldUpdateFlags() const;
228 
229     // Virtual methods for options dialog.
230     virtual std::unique_ptr<SfxItemSet> CreateItemSet( sal_uInt16 nId ) override;
231     virtual void         ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) override;
232     virtual std::unique_ptr<SfxTabPage> CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet ) override;
233     virtual std::optional<SfxStyleFamilies> CreateStyleFamilies() override;
234 
235     // Pool is created here and set at SfxShell.
236     void    InitAttrPool();
237     // Delete pool before it is too late.
238     void    RemoveAttrPool();
239 
240     // Invalidates online spell-wrong-lists if necessary.
241     static void  CheckSpellChanges( bool bOnlineSpelling,
242                     bool bIsSpellWrongAgain, bool bIsSpellAllAgain, bool bSmartTags );
243 
244     css::uno::Reference< css::scanner::XScannerManager2 > const &
245             GetScannerManager();
246 
247     css::uno::Reference< css::linguistic2::XLanguageGuessing > const &
248             GetLanguageGuesser();
249 
250     void RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller);
251     void CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments);
252 };
253 
254 //    Access to SwModule, the View and the shell.
255 
256 #define SW_MOD() ( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule::Writer)))
257 
258 SW_DLLPUBLIC SwView*    GetActiveView();
259 SW_DLLPUBLIC SwWrtShell* GetActiveWrtShell();
260 
261 namespace sw
262 {
263 SW_DLLPUBLIC Color* GetActiveRetoucheColor();
264 }
265 
266 extern bool g_bNoInterrupt;
267 
268 #endif
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
271