xref: /core/sw/source/uibase/app/swmodule.cxx (revision 18ef3915)
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>
23 #include <svtools/accessibilityoptions.hxx>
24 #include <unotools/resmgr.hxx>
25 #include <unotools/useroptions.hxx>
26 #include <svl/ctloptions.hxx>
27 #include <svx/ParaSpacingControl.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>
34 #include <svx/formatpaintbrushctrl.hxx>
35 #include <svx/contdlg.hxx>
36 #include <svx/fontwork.hxx>
37 #include <SwSpellDialogChildWindow.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>
48 #include <comphelper/processfactory.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 <AccessibilityStatusBarControl.hxx>
85 #include <workctrl.hxx>
86 #include <fldwrap.hxx>
87 #include <redlndlg.hxx>
88 #include <syncbtn.hxx>
89 #include <modcfg.hxx>
90 #include <fontcfg.hxx>
91 #include <sfx2/sidebar/SidebarChildWindow.hxx>
92 #include <sfx2/devtools/DevelopmentToolChildWindow.hxx>
93 #include <swatrset.hxx>
94 #include <idxmrk.hxx>
95 #include <wordcountdialog.hxx>
96 #include <dlelstnr.hxx>
97 #include <barcfg.hxx>
98 #include <svx/rubydialog.hxx>
99 #include <svtools/colorcfg.hxx>
100 
101 #include <comphelper/configuration.hxx>
102 #include <unotools/moduleoptions.hxx>
103 
104 #include <avmedia/mediaplayer.hxx>
105 #include <avmedia/mediatoolbox.hxx>
106 
107 #include <annotsh.hxx>
108 #include <navsh.hxx>
109 
110 #include <app.hrc>
111 #include <error.hrc>
112 #include <strings.hrc>
113 #include <bitmaps.hlst>
114 #include <svx/xmlsecctrl.hxx>
115 bool     g_bNoInterrupt     = false;
116 
117 #include <sfx2/app.hxx>
118 
119 #include <svx/svxerr.hxx>
120 
121 #include "swdllimpl.hxx"
122 #include <dbconfig.hxx>
123 #include <navicfg.hxx>
124 
125 using namespace com::sun::star;
126 using namespace ::com::sun::star::uno;
127 
SwModule(SfxObjectFactory * pWebFact,SfxObjectFactory * pFact,SfxObjectFactory * pGlobalFact)128 SwModule::SwModule( SfxObjectFactory* pWebFact,
129                     SfxObjectFactory* pFact,
130                     SfxObjectFactory* pGlobalFact )
131     : SfxModule("sw"_ostr, {pWebFact, pFact, pGlobalFact}),
132     m_pView(nullptr),
133     m_bAuthorInitialised(false),
134     m_bEmbeddedLoadSave( false ),
135     m_pDragDrop( nullptr ),
136     m_pXSelection( nullptr )
137 {
138     SetName( u"StarWriter"_ustr );
139     SvxErrorHandler::ensure();
140     m_pErrorHandler.reset( new SfxErrorHandler( RID_SW_ERRHDL,
141                                      ErrCodeArea::Sw,
142                                      ErrCodeArea::Sw,
143                                      GetResLocale() ) );
144 
145     m_pModuleConfig.reset(new SwModuleOptions);
146 
147     // We need them anyways
148     m_pToolbarConfig.reset(new SwToolbarConfigItem( false ));
149     m_pWebToolbarConfig.reset(new SwToolbarConfigItem( true ));
150 
151     m_pStdFontConfig.reset(new SwStdFontConfig);
152 
153     {
154         SolarMutexGuard g;
155         StartListening( *SfxGetpApp() );
156     }
157 
158     if (!comphelper::IsFuzzing())
159     {
160         // init color configuration
161         // member <pColorConfig> is created and the color configuration is applied
162         // at the view options.
163         GetColorConfig();
164         m_xLinguServiceEventListener = new SwLinguServiceEventListener;
165     }
166 }
167 
SwResId(TranslateId aId)168 OUString SwResId(TranslateId aId)
169 {
170     return Translate::get(aId, SW_MOD()->GetResLocale());
171 }
172 
SwResId(TranslateNId aContextSingularPlural,int nCardinality)173 OUString SwResId(TranslateNId aContextSingularPlural, int nCardinality)
174 {
175     return Translate::nget(aContextSingularPlural, nCardinality, SW_MOD()->GetResLocale());
176 }
177 
178 uno::Reference< scanner::XScannerManager2 > const &
GetScannerManager()179 SwModule::GetScannerManager()
180 {
181     static bool bTestScannerManager = true;
182     if (bTestScannerManager && !m_xScannerManager.is())
183     {
184         try {
185             m_xScannerManager = scanner::ScannerManager::create( comphelper::getProcessComponentContext() );
186         }
187         catch (...) {}
188         bTestScannerManager = false;
189     }
190     return m_xScannerManager;
191 }
192 
GetLanguageGuesser()193 uno::Reference< linguistic2::XLanguageGuessing > const & SwModule::GetLanguageGuesser()
194 {
195     if (!m_xLanguageGuesser.is())
196     {
197         m_xLanguageGuesser = linguistic2::LanguageGuessing::create( comphelper::getProcessComponentContext() );
198     }
199     return m_xLanguageGuesser;
200 }
201 
~SwModule()202 SwModule::~SwModule()
203 {
204     css::uno::Sequence< css::uno::Any > aArgs;
205     CallAutomationApplicationEventSinks( u"Quit"_ustr, aArgs );
206     m_pErrorHandler.reset();
207     EndListening( *SfxGetpApp() );
208 }
209 
RegisterFactories()210 void SwDLL::RegisterFactories()
211 {
212     // These Id's must not be changed. Through these Id's the View (resume Documentview)
213     // is created by Sfx.
214     if (comphelper::IsFuzzing() || SvtModuleOptions().IsWriter())
215         SwView::RegisterFactory         ( SFX_INTERFACE_SFXDOCSH );
216 
217 #if HAVE_FEATURE_DESKTOP
218     SwWebView::RegisterFactory        ( SFX_INTERFACE_SFXMODULE );
219 
220     if (comphelper::IsFuzzing() || SvtModuleOptions().IsWriter())
221     {
222         SwSrcView::RegisterFactory      ( SfxInterfaceId(6) );
223         SwPagePreview::RegisterFactory  ( SfxInterfaceId(7) );
224     }
225 #endif
226 }
227 
RegisterInterfaces()228 void SwDLL::RegisterInterfaces()
229 {
230     SwModule* pMod = SW_MOD();
231     SwModule::RegisterInterface( pMod );
232     SwDocShell::RegisterInterface( pMod );
233     SwWebDocShell::RegisterInterface( pMod );
234     SwGlosDocShell::RegisterInterface( pMod );
235     SwWebGlosDocShell::RegisterInterface( pMod );
236     SwView::RegisterInterface( pMod );
237     SwWebView::RegisterInterface( pMod );
238     SwPagePreview::RegisterInterface( pMod );
239     SwSrcView::RegisterInterface( pMod );
240 
241     SwBaseShell::RegisterInterface(pMod);
242     SwTextShell::RegisterInterface(pMod);
243     SwTableShell::RegisterInterface(pMod);
244     SwListShell::RegisterInterface(pMod);
245     SwFrameShell::RegisterInterface(pMod);
246     SwDrawBaseShell::RegisterInterface(pMod);
247     SwDrawShell::RegisterInterface(pMod);
248     SwDrawFormShell::RegisterInterface(pMod);
249     SwDrawTextShell::RegisterInterface(pMod);
250     SwBezierShell::RegisterInterface(pMod);
251     SwGrfShell::RegisterInterface(pMod);
252     SwOleShell::RegisterInterface(pMod);
253     SwNavigationShell::RegisterInterface(pMod);
254     SwWebTextShell::RegisterInterface(pMod);
255     SwWebFrameShell::RegisterInterface(pMod);
256     SwWebGrfShell::RegisterInterface(pMod);
257     SwWebListShell::RegisterInterface(pMod);
258     SwWebTableShell::RegisterInterface(pMod);
259     SwWebDrawFormShell::RegisterInterface(pMod);
260     SwWebOleShell::RegisterInterface(pMod);
261     SwMediaShell::RegisterInterface(pMod);
262     SwAnnotationShell::RegisterInterface(pMod);
263 }
264 
RegisterControls()265 void SwDLL::RegisterControls()
266 {
267     SwModule* pMod = SW_MOD();
268 
269     SvxTbxCtlDraw::RegisterControl(SID_INSERT_DRAW, pMod );
270     SvxTbxCtlDraw::RegisterControl(SID_TRACK_CHANGES_BAR, pMod );
271     SwTbxAutoTextCtrl::RegisterControl(FN_GLOSSARY_DLG, pMod );
272     svx::ParaAboveSpacingControl::RegisterControl(SID_ATTR_PARA_ABOVESPACE, pMod);
273     svx::ParaBelowSpacingControl::RegisterControl(SID_ATTR_PARA_BELOWSPACE, pMod);
274     svx::ParaLeftSpacingControl::RegisterControl(SID_ATTR_PARA_LEFTSPACE, pMod);
275     svx::ParaRightSpacingControl::RegisterControl(SID_ATTR_PARA_RIGHTSPACE, pMod);
276     svx::ParaFirstLineSpacingControl::RegisterControl(SID_ATTR_PARA_FIRSTLINESPACE, pMod);
277 
278     SvxClipBoardControl::RegisterControl(SID_PASTE, pMod );
279     svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod );
280 
281     SvxFillToolBoxControl::RegisterControl(SID_ATTR_FILL_STYLE, pMod );
282     SvxLineWidthToolBoxControl::RegisterControl(SID_ATTR_LINE_WIDTH, pMod );
283 
284     SwZoomControl::RegisterControl(SID_ATTR_ZOOM, pMod );
285     SwPreviewZoomControl::RegisterControl(FN_PREVIEW_ZOOM, pMod);
286     SvxPosSizeStatusBarControl::RegisterControl(0, pMod );
287     SvxInsertStatusBarControl::RegisterControl(SID_ATTR_INSERT, pMod );
288     SvxSelectionModeControl::RegisterControl(FN_STAT_SELMODE, pMod );
289     XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pMod );
290     SwWordCountStatusBarControl::RegisterControl(FN_STAT_WORDCOUNT, pMod);
291     sw::AccessibilityStatusBarControl::RegisterControl(FN_STAT_ACCESSIBILITY_CHECK, pMod);
292 
293     SwBookmarkControl::RegisterControl(FN_STAT_PAGE, pMod );
294     SwTemplateControl::RegisterControl(FN_STAT_TEMPLATE, pMod );
295     SwViewLayoutControl::RegisterControl( SID_ATTR_VIEWLAYOUT, pMod );
296     SvxModifyControl::RegisterControl( SID_DOC_MODIFIED, pMod );
297     SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER, pMod );
298 
299     SvxIMapDlgChildWindow::RegisterChildWindow( false, pMod );
300     SvxSearchDialogWrapper::RegisterChildWindow( false, pMod );
301     SvxHlinkDlgWrapper::RegisterChildWindow( false, pMod );
302     SvxFontWorkChildWindow::RegisterChildWindow( false, pMod );
303     SwFieldDlgWrapper::RegisterChildWindow( false, pMod );
304     SwFieldDataOnlyDlgWrapper::RegisterChildWindow( false, pMod );
305     SvxContourDlgChildWindow::RegisterChildWindow( false, pMod );
306     SwInputChild::RegisterChildWindow( false, pMod, SfxChildWindowFlags::FORCEDOCK );
307     SwRedlineAcceptChild::RegisterChildWindow( false, pMod );
308     SwSyncChildWin::RegisterChildWindow( true, pMod );
309     SwInsertIdxMarkWrapper::RegisterChildWindow( false, pMod );
310     SwInsertAuthMarkWrapper::RegisterChildWindow( false, pMod );
311     SwWordCountWrapper::RegisterChildWindow( false, pMod );
312     SvxRubyChildWindow::RegisterChildWindow( false, pMod);
313     SwSpellDialogChildWindow::RegisterChildWindow(
314         false, pMod, comphelper::LibreOfficeKit::isActive() ? SfxChildWindowFlags::NEVERCLONE
315                                                             : SfxChildWindowFlags::NONE);
316     DevelopmentToolChildWindow::RegisterChildWindow(false, pMod);
317 
318     SvxGrafRedToolBoxControl::RegisterControl( SID_ATTR_GRAF_RED, pMod );
319     SvxGrafGreenToolBoxControl::RegisterControl( SID_ATTR_GRAF_GREEN, pMod );
320     SvxGrafBlueToolBoxControl::RegisterControl( SID_ATTR_GRAF_BLUE, pMod );
321     SvxGrafLuminanceToolBoxControl::RegisterControl( SID_ATTR_GRAF_LUMINANCE, pMod );
322     SvxGrafContrastToolBoxControl::RegisterControl( SID_ATTR_GRAF_CONTRAST, pMod );
323     SvxGrafGammaToolBoxControl::RegisterControl( SID_ATTR_GRAF_GAMMA, pMod );
324     SvxGrafTransparenceToolBoxControl::RegisterControl( SID_ATTR_GRAF_TRANSPARENCE, pMod );
325     SvxGrafModeToolBoxControl::RegisterControl( SID_ATTR_GRAF_MODE, pMod );
326 
327 #if HAVE_FEATURE_AVMEDIA
328     ::avmedia::MediaToolBoxControl::RegisterControl(SID_AVMEDIA_TOOLBOX, pMod);
329     ::avmedia::MediaPlayer::RegisterChildWindow(false, pMod);
330 #endif
331 
332     ::sfx2::sidebar::SidebarChildWindow::RegisterChildWindow(false, pMod);
333 
334     SwNavigatorWrapper::RegisterChildWindow(false, pMod, SfxChildWindowFlags::NEVERHIDE);
335 
336     SwJumpToSpecificPageControl::RegisterControl(SID_JUMP_TO_SPECIFIC_PAGE, pMod);
337 }
338 
339 // Load Module (only dummy for linking of the DLL)
InitAttrPool()340 void    SwModule::InitAttrPool()
341 {
342     OSL_ENSURE(!m_pAttrPool, "Pool already exists!");
343     m_pAttrPool = new SwAttrPool(nullptr);
344     SetPool(m_pAttrPool.get());
345 }
346 
RemoveAttrPool()347 void    SwModule::RemoveAttrPool()
348 {
349     SetPool(nullptr);
350     m_pAttrPool.clear();
351 }
352 
CreateStyleFamilies()353 std::optional<SfxStyleFamilies> SwModule::CreateStyleFamilies()
354 {
355     SfxStyleFamilies aStyleFamilies;
356 
357     aStyleFamilies.emplace_back(SfxStyleFamily::Para,
358                                  SwResId(STR_PARAGRAPHSTYLEFAMILY),
359                                  BMP_STYLES_FAMILY_PARA,
360                                  RID_PARAGRAPHSTYLEFAMILY, GetResLocale());
361 
362     aStyleFamilies.emplace_back(SfxStyleFamily::Char,
363                                  SwResId(STR_CHARACTERSTYLEFAMILY),
364                                  BMP_STYLES_FAMILY_CHAR,
365                                  RID_CHARACTERSTYLEFAMILY, GetResLocale());
366 
367     aStyleFamilies.emplace_back(SfxStyleFamily::Frame,
368                                  SwResId(STR_FRAMESTYLEFAMILY),
369                                  BMP_STYLES_FAMILY_FRAME,
370                                  RID_FRAMESTYLEFAMILY, GetResLocale());
371 
372     aStyleFamilies.emplace_back(SfxStyleFamily::Page,
373                                  SwResId(STR_PAGESTYLEFAMILY),
374                                  BMP_STYLES_FAMILY_PAGE,
375                                  RID_PAGESTYLEFAMILY, GetResLocale());
376 
377     aStyleFamilies.emplace_back(SfxStyleFamily::Pseudo,
378                                  SwResId(STR_LISTSTYLEFAMILY),
379                                  BMP_STYLES_FAMILY_LIST,
380                                  RID_LISTSTYLEFAMILY, GetResLocale());
381 
382     aStyleFamilies.emplace_back(SfxStyleFamily::Table,
383                                  SwResId(STR_TABLESTYLEFAMILY),
384                                  BMP_STYLES_FAMILY_TABLE,
385                                  RID_TABLESTYLEFAMILY, GetResLocale());
386 
387     return aStyleFamilies;
388 }
389 
RegisterAutomationApplicationEventsCaller(css::uno::Reference<ooo::vba::XSinkCaller> const & xCaller)390 void SwModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller)
391 {
392     mxAutomationApplicationEventsCaller = xCaller;
393 }
394 
CallAutomationApplicationEventSinks(const OUString & Method,css::uno::Sequence<css::uno::Any> & Arguments)395 void SwModule::CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments)
396 {
397     if (mxAutomationApplicationEventsCaller.is())
398         mxAutomationApplicationEventsCaller->CallSinks(Method, Arguments);
399 }
400 
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
402