LibreOffice Module sw (master)  1
swmodule.cxx
Go to the documentation of this file.
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 
20 #include <config_features.h>
21 
22 #include <svtools/ehdl.hxx>
24 #include <unotools/resmgr.hxx>
25 #include <unotools/useroptions.hxx>
26 #include <svl/ctloptions.hxx>
28 #include <svx/pszctrl.hxx>
29 #include <svx/insctrl.hxx>
30 #include <svx/selctrl.hxx>
31 #include <svx/linectrl.hxx>
32 #include <svx/tbxctl.hxx>
33 #include <svx/fillctrl.hxx>
35 #include <svx/contdlg.hxx>
36 #include <svx/fontwork.hxx>
38 #include <svx/grafctrl.hxx>
39 #include <svx/clipboardctl.hxx>
40 #include <svx/imapdlg.hxx>
41 #include <svx/srchdlg.hxx>
42 #include <svx/hyperdlg.hxx>
43 #include <svx/modctrl.hxx>
44 #include <com/sun/star/scanner/ScannerManager.hpp>
45 #include <com/sun/star/linguistic2/LanguageGuessing.hpp>
46 #include <ooo/vba/XSinkCaller.hpp>
47 #include <comphelper/lok.hxx>
49 #include <docsh.hxx>
50 #include <swmodule.hxx>
51 #include <cmdid.h>
52 #include <pview.hxx>
53 #include <wview.hxx>
54 #include <wdocsh.hxx>
55 #include <srcview.hxx>
56 #include <glshell.hxx>
57 #include <tabsh.hxx>
58 #include <listsh.hxx>
59 #include <grfsh.hxx>
60 #include <mediash.hxx>
61 #include <olesh.hxx>
62 #include <drawsh.hxx>
63 #include <wformsh.hxx>
64 #include <drwtxtsh.hxx>
65 #include <beziersh.hxx>
66 #include <wtextsh.hxx>
67 #include <wfrmsh.hxx>
68 #include <drformsh.hxx>
69 #include <wgrfsh.hxx>
70 #include <wolesh.hxx>
71 #include <wlistsh.hxx>
72 #include <wtabsh.hxx>
73 #include <navipi.hxx>
74 #include <inputwin.hxx>
75 #include <usrpref.hxx>
76 #include <uinums.hxx>
77 #include <prtopt.hxx>
78 #include <bookctrl.hxx>
79 #include <tmplctrl.hxx>
80 #include <viewlayoutctrl.hxx>
81 #include <svx/zoomsliderctrl.hxx>
82 #include <zoomctrl.hxx>
83 #include <wordcountctrl.hxx>
84 #include <workctrl.hxx>
85 #include <fldwrap.hxx>
86 #include <redlndlg.hxx>
87 #include <syncbtn.hxx>
88 #include <modcfg.hxx>
89 #include <fontcfg.hxx>
92 #include <swatrset.hxx>
93 #include <idxmrk.hxx>
94 #include <wordcountdialog.hxx>
95 #include <dlelstnr.hxx>
96 #include <barcfg.hxx>
97 #include <svx/rubydialog.hxx>
98 #include <svtools/colorcfg.hxx>
99 
100 #include <unotools/configmgr.hxx>
102 
103 #include <avmedia/mediaplayer.hxx>
104 #include <avmedia/mediatoolbox.hxx>
105 
106 #include <annotsh.hxx>
107 #include <navsh.hxx>
108 
109 #include <app.hrc>
110 #include <error.hrc>
111 #include <strings.hrc>
112 #include <bitmaps.hlst>
113 #include <svx/xmlsecctrl.hxx>
114 bool g_bNoInterrupt = false;
115 
116 #include <sfx2/app.hxx>
117 
118 #include <svx/svxerr.hxx>
119 
120 #include "swdllimpl.hxx"
121 #include <dbconfig.hxx>
122 #include <navicfg.hxx>
123 
124 using namespace com::sun::star;
125 using namespace ::com::sun::star::uno;
126 
128  SfxObjectFactory* pFact,
129  SfxObjectFactory* pGlobalFact )
130  : SfxModule("sw", {pWebFact, pFact, pGlobalFact}),
131  m_pView(nullptr),
132  m_bAuthorInitialised(false),
133  m_bEmbeddedLoadSave( false ),
134  m_pDragDrop( nullptr ),
135  m_pXSelection( nullptr )
136 {
137  SetName( "StarWriter" );
139  m_pErrorHandler.reset( new SfxErrorHandler( RID_SW_ERRHDL,
140  ErrCodeArea::Sw,
141  ErrCodeArea::Sw,
142  GetResLocale() ) );
143 
144  m_pModuleConfig.reset(new SwModuleOptions);
145 
146  // We need them anyways
147  m_pToolbarConfig.reset(new SwToolbarConfigItem( false ));
148  m_pWebToolbarConfig.reset(new SwToolbarConfigItem( true ));
149 
150  m_pStdFontConfig.reset(new SwStdFontConfig);
151 
153 
155  {
156  // init color configuration
157  // member <pColorConfig> is created and the color configuration is applied
158  // at the view options.
159  GetColorConfig();
160  m_xLinguServiceEventListener = new SwLinguServiceEventListener;
161  }
162 }
163 
164 OUString SwResId(TranslateId aId)
165 {
166  return Translate::get(aId, SW_MOD()->GetResLocale());
167 }
168 
169 OUString SwResId(TranslateNId aContextSingularPlural, int nCardinality)
170 {
171  return Translate::nget(aContextSingularPlural, nCardinality, SW_MOD()->GetResLocale());
172 }
173 
174 uno::Reference< scanner::XScannerManager2 > const &
176 {
177  static bool bTestScannerManager = true;
178  if (bTestScannerManager && !m_xScannerManager.is())
179  {
180  try {
181  m_xScannerManager = scanner::ScannerManager::create( comphelper::getProcessComponentContext() );
182  }
183  catch (...) {}
184  bTestScannerManager = false;
185  }
186  return m_xScannerManager;
187 }
188 
189 uno::Reference< linguistic2::XLanguageGuessing > const & SwModule::GetLanguageGuesser()
190 {
191  if (!m_xLanguageGuesser.is())
192  {
193  m_xLanguageGuesser = linguistic2::LanguageGuessing::create( comphelper::getProcessComponentContext() );
194  }
195  return m_xLanguageGuesser;
196 }
197 
199 {
200  css::uno::Sequence< css::uno::Any > aArgs;
201  CallAutomationApplicationEventSinks( "Quit", aArgs );
202  m_pErrorHandler.reset();
203  EndListening( *SfxGetpApp() );
204 }
205 
207 {
208  // These Id's must not be changed. Through these Id's the View (resume Documentview)
209  // is created by Sfx.
210  if (utl::ConfigManager::IsFuzzing() || SvtModuleOptions().IsWriter())
211  SwView::RegisterFactory ( SFX_INTERFACE_SFXDOCSH );
212 
213 #if HAVE_FEATURE_DESKTOP
214  SwWebView::RegisterFactory ( SFX_INTERFACE_SFXMODULE );
215 
216  if (utl::ConfigManager::IsFuzzing() || SvtModuleOptions().IsWriter())
217  {
218  SwSrcView::RegisterFactory ( SfxInterfaceId(6) );
219  SwPagePreview::RegisterFactory ( SfxInterfaceId(7) );
220  }
221 #endif
222 }
223 
225 {
226  SwModule* pMod = SW_MOD();
227  SwModule::RegisterInterface( pMod );
228  SwDocShell::RegisterInterface( pMod );
229  SwWebDocShell::RegisterInterface( pMod );
230  SwGlosDocShell::RegisterInterface( pMod );
231  SwWebGlosDocShell::RegisterInterface( pMod );
232  SwView::RegisterInterface( pMod );
233  SwWebView::RegisterInterface( pMod );
234  SwPagePreview::RegisterInterface( pMod );
235  SwSrcView::RegisterInterface( pMod );
236 
237  SwBaseShell::RegisterInterface(pMod);
238  SwTextShell::RegisterInterface(pMod);
239  SwTableShell::RegisterInterface(pMod);
240  SwListShell::RegisterInterface(pMod);
241  SwFrameShell::RegisterInterface(pMod);
242  SwDrawBaseShell::RegisterInterface(pMod);
243  SwDrawShell::RegisterInterface(pMod);
244  SwDrawFormShell::RegisterInterface(pMod);
245  SwDrawTextShell::RegisterInterface(pMod);
246  SwBezierShell::RegisterInterface(pMod);
247  SwGrfShell::RegisterInterface(pMod);
248  SwOleShell::RegisterInterface(pMod);
249  SwNavigationShell::RegisterInterface(pMod);
250  SwWebTextShell::RegisterInterface(pMod);
251  SwWebFrameShell::RegisterInterface(pMod);
252  SwWebGrfShell::RegisterInterface(pMod);
253  SwWebListShell::RegisterInterface(pMod);
254  SwWebTableShell::RegisterInterface(pMod);
255  SwWebDrawFormShell::RegisterInterface(pMod);
256  SwWebOleShell::RegisterInterface(pMod);
257  SwMediaShell::RegisterInterface(pMod);
258  SwAnnotationShell::RegisterInterface(pMod);
259 }
260 
262 {
263  SwModule* pMod = SW_MOD();
264 
265  SvxTbxCtlDraw::RegisterControl(SID_INSERT_DRAW, pMod );
266  SvxTbxCtlDraw::RegisterControl(SID_TRACK_CHANGES_BAR, pMod );
267  SwTbxAutoTextCtrl::RegisterControl(FN_GLOSSARY_DLG, pMod );
268  svx::ParaAboveSpacingControl::RegisterControl(SID_ATTR_PARA_ABOVESPACE, pMod);
269  svx::ParaBelowSpacingControl::RegisterControl(SID_ATTR_PARA_BELOWSPACE, pMod);
270  svx::ParaLeftSpacingControl::RegisterControl(SID_ATTR_PARA_LEFTSPACE, pMod);
271  svx::ParaRightSpacingControl::RegisterControl(SID_ATTR_PARA_RIGHTSPACE, pMod);
272  svx::ParaFirstLineSpacingControl::RegisterControl(SID_ATTR_PARA_FIRSTLINESPACE, pMod);
273 
274  SvxClipBoardControl::RegisterControl(SID_PASTE, pMod );
275  svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod );
276 
277  SvxFillToolBoxControl::RegisterControl(SID_ATTR_FILL_STYLE, pMod );
278  SvxLineWidthToolBoxControl::RegisterControl(SID_ATTR_LINE_WIDTH, pMod );
279 
280  SwZoomControl::RegisterControl(SID_ATTR_ZOOM, pMod );
281  SwPreviewZoomControl::RegisterControl(FN_PREVIEW_ZOOM, pMod);
282  SvxPosSizeStatusBarControl::RegisterControl(0, pMod );
283  SvxInsertStatusBarControl::RegisterControl(SID_ATTR_INSERT, pMod );
284  SvxSelectionModeControl::RegisterControl(FN_STAT_SELMODE, pMod );
285  XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pMod );
286  SwWordCountStatusBarControl::RegisterControl(FN_STAT_WORDCOUNT, pMod);
287 
288  SwBookmarkControl::RegisterControl(FN_STAT_PAGE, pMod );
289  SwTemplateControl::RegisterControl(FN_STAT_TEMPLATE, pMod );
290  SwViewLayoutControl::RegisterControl( SID_ATTR_VIEWLAYOUT, pMod );
291  SvxModifyControl::RegisterControl( SID_DOC_MODIFIED, pMod );
292  SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER, pMod );
293 
294  SvxIMapDlgChildWindow::RegisterChildWindow( false, pMod );
295  SvxSearchDialogWrapper::RegisterChildWindow( false, pMod );
296  SvxHlinkDlgWrapper::RegisterChildWindow( false, pMod );
297  SvxFontWorkChildWindow::RegisterChildWindow( false, pMod );
300  SvxContourDlgChildWindow::RegisterChildWindow( false, pMod );
301  SwInputChild::RegisterChildWindow( false, pMod, SfxChildWindowFlags::FORCEDOCK );
307  SvxRubyChildWindow::RegisterChildWindow( false, pMod);
308  SwSpellDialogChildWindow::RegisterChildWindow(
309  false, pMod, comphelper::LibreOfficeKit::isActive() ? SfxChildWindowFlags::NEVERCLONE
310  : SfxChildWindowFlags::NONE);
312 
313  SvxGrafRedToolBoxControl::RegisterControl( SID_ATTR_GRAF_RED, pMod );
314  SvxGrafGreenToolBoxControl::RegisterControl( SID_ATTR_GRAF_GREEN, pMod );
315  SvxGrafBlueToolBoxControl::RegisterControl( SID_ATTR_GRAF_BLUE, pMod );
316  SvxGrafLuminanceToolBoxControl::RegisterControl( SID_ATTR_GRAF_LUMINANCE, pMod );
317  SvxGrafContrastToolBoxControl::RegisterControl( SID_ATTR_GRAF_CONTRAST, pMod );
318  SvxGrafGammaToolBoxControl::RegisterControl( SID_ATTR_GRAF_GAMMA, pMod );
319  SvxGrafTransparenceToolBoxControl::RegisterControl( SID_ATTR_GRAF_TRANSPARENCE, pMod );
320  SvxGrafModeToolBoxControl::RegisterControl( SID_ATTR_GRAF_MODE, pMod );
321 
322 #if HAVE_FEATURE_AVMEDIA
323  ::avmedia::MediaToolBoxControl::RegisterControl(SID_AVMEDIA_TOOLBOX, pMod);
324  ::avmedia::MediaPlayer::RegisterChildWindow(false, pMod);
325 #endif
326 
328 
329  SwNavigatorWrapper::RegisterChildWindow(false, pMod, SfxChildWindowFlags::NEVERHIDE);
330 
331  SwJumpToSpecificPageControl::RegisterControl(SID_JUMP_TO_SPECIFIC_PAGE, pMod);
332 }
333 
334 // Load Module (only dummy for linking of the DLL)
336 {
337  OSL_ENSURE(!m_pAttrPool, "Pool already exists!");
338  m_pAttrPool = new SwAttrPool(nullptr);
339  SetPool(m_pAttrPool.get());
340 }
341 
343 {
344  SetPool(nullptr);
345  m_pAttrPool.clear();
346 }
347 
348 std::optional<SfxStyleFamilies> SwModule::CreateStyleFamilies()
349 {
350  SfxStyleFamilies aStyleFamilies;
351 
352  aStyleFamilies.emplace_back(SfxStyleFamily::Para,
353  SwResId(STR_PARAGRAPHSTYLEFAMILY),
354  BMP_STYLES_FAMILY_PARA,
355  RID_PARAGRAPHSTYLEFAMILY, GetResLocale());
356 
357  aStyleFamilies.emplace_back(SfxStyleFamily::Char,
358  SwResId(STR_CHARACTERSTYLEFAMILY),
359  BMP_STYLES_FAMILY_CHAR,
360  RID_CHARACTERSTYLEFAMILY, GetResLocale());
361 
362  aStyleFamilies.emplace_back(SfxStyleFamily::Frame,
363  SwResId(STR_FRAMESTYLEFAMILY),
364  BMP_STYLES_FAMILY_FRAME,
365  RID_FRAMESTYLEFAMILY, GetResLocale());
366 
367  aStyleFamilies.emplace_back(SfxStyleFamily::Page,
368  SwResId(STR_PAGESTYLEFAMILY),
369  BMP_STYLES_FAMILY_PAGE,
370  RID_PAGESTYLEFAMILY, GetResLocale());
371 
372  aStyleFamilies.emplace_back(SfxStyleFamily::Pseudo,
373  SwResId(STR_LISTSTYLEFAMILY),
374  BMP_STYLES_FAMILY_LIST,
375  RID_LISTSTYLEFAMILY, GetResLocale());
376 
377  aStyleFamilies.emplace_back(SfxStyleFamily::Table,
378  SwResId(STR_TABLESTYLEFAMILY),
379  BMP_STYLES_FAMILY_TABLE,
380  RID_TABLESTYLEFAMILY, GetResLocale());
381 
382  return aStyleFamilies;
383 }
384 
385 void SwModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller)
386 {
388 }
389 
390 void SwModule::CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments)
391 {
393  mxAutomationApplicationEventsCaller->CallSinks(Method, Arguments);
394 }
395 
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::scanner::XScannerManager2 > const & GetScannerManager()
Definition: swmodule.cxx:175
std::vector< SfxStyleFamilyItem > SfxStyleFamilies
std::locale GetResLocale() const
SwModule(SfxObjectFactory *pFact, SfxObjectFactory *pWebFact, SfxObjectFactory *pGlobalFact)
Definition: swmodule.cxx:127
#define FN_PREVIEW_ZOOM
Definition: cmdid.h:180
void CallAutomationApplicationEventSinks(const OUString &Method, css::uno::Sequence< css::uno::Any > &Arguments)
Definition: swmodule.cxx:390
void RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const &xCaller)
Definition: swmodule.cxx:385
void InitAttrPool()
Definition: swmodule.cxx:335
static void RegisterControls()
Definition: swmodule.cxx:261
#define FN_STAT_PAGE
Definition: cmdid.h:842
SfxApplication * SfxGetpApp()
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
css::uno::Reference< ooo::vba::XSinkCaller > mxAutomationApplicationEventsCaller
Definition: swmodule.hxx:124
static bool IsFuzzing()
#define SID_JUMP_TO_SPECIFIC_PAGE
Definition: cmdid.h:739
#define FN_STAT_SELMODE
Definition: cmdid.h:845
#define FN_STAT_TEMPLATE
Definition: cmdid.h:843
#define SW_MOD()
Definition: swmodule.hxx:255
static void RegisterInterfaces()
Definition: swmodule.cxx:224
#define FN_GLOSSARY_DLG
Definition: cmdid.h:504
constexpr auto SFX_INTERFACE_SFXMODULE
static void RegisterChildWindow(SfxModule *, const SfxChildWinFactory &)
void SetPool(SfxItemPool *pNewPool)
OUString get(TranslateId sContextAndId, const std::locale &loc)
virtual ~SwModule() override
Definition: swmodule.cxx:198
#define FN_STAT_WORDCOUNT
Definition: cmdid.h:847
constexpr auto SFX_INTERFACE_SFXDOCSH
css::uno::Reference< css::scanner::XScannerManager2 > m_xScannerManager
Definition: swmodule.hxx:109
rtl::Reference< SwAttrPool > m_pAttrPool
Definition: swmodule.hxx:97
static void RegisterFactories()
Definition: swmodule.cxx:206
css::uno::Reference< css::linguistic2::XLanguageGuessing > const & GetLanguageGuesser()
Definition: swmodule.cxx:189
OUString nget(TranslateNId aContextSingularPlural, int n, const std::locale &loc)
EventListener that triggers spellchecking and hyphenation.
Definition: dlelstnr.hxx:42
css::uno::Reference< css::linguistic2::XLanguageGuessing > m_xLanguageGuesser
Definition: swmodule.hxx:110
void RemoveAttrPool()
Definition: swmodule.cxx:342
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
Reference< XComponentContext > getProcessComponentContext()
static void ensure()
#define SID_TRACK_CHANGES_BAR
Definition: cmdid.h:740
bool g_bNoInterrupt
Definition: swmodule.cxx:114
virtual std::optional< SfxStyleFamilies > CreateStyleFamilies() override
Definition: swmodule.cxx:348
std::unique_ptr< SfxErrorHandler > m_pErrorHandler
Definition: swmodule.hxx:95