Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / app / swdll.cxx
blobc4564a4741f34ee558bbed612507e290123c6f73
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 .
20 #include <memory>
22 #include <svx/svdobj.hxx>
24 #include <swdll.hxx>
25 #include <wdocsh.hxx>
26 #include <globdoc.hxx>
27 #include <initui.hxx>
28 #include <swmodule.hxx>
29 #include <init.hxx>
30 #include <dobjfac.hxx>
32 #include <com/sun/star/frame/Desktop.hpp>
33 #include <unotools/configmgr.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include <comphelper/unique_disposing_ptr.hxx>
36 #include <comphelper/processfactory.hxx>
38 #include <sal/log.hxx>
39 #include <svx/fmobjfac.hxx>
40 #include <svx/objfac3d.hxx>
41 #include <editeng/acorrcfg.hxx>
43 #include <swacorr.hxx>
44 #include <swabstdlg.hxx>
46 #include "swdllimpl.hxx"
48 using namespace com::sun::star;
50 namespace
52 //Holds a SwDLL and release it on exit, or dispose of the
53 //default XComponent, whichever comes first
54 class SwDLLInstance : public comphelper::unique_disposing_solar_mutex_reset_ptr<SwDLL>
56 public:
57 SwDLLInstance() : comphelper::unique_disposing_solar_mutex_reset_ptr<SwDLL>(uno::Reference<lang::XComponent>( frame::Desktop::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY_THROW), new SwDLL, true)
62 SwDLLInstance& theSwDLLInstance()
64 static SwDLLInstance aInstance;
65 return aInstance;
69 namespace SwGlobals
71 void ensure()
73 // coverity[side_effect_free : FALSE] - not actually side-effect-free
74 theSwDLLInstance();
77 sw::Filters & getFilters()
79 return theSwDLLInstance()->getFilters();
83 SwDLL::SwDLL()
84 : m_pAutoCorrCfg(nullptr)
86 if ( SfxApplication::GetModule(SfxToolsModule::Writer) ) // Module already active
87 return;
89 std::unique_ptr<SvtModuleOptions> xOpt;
90 if (!utl::ConfigManager::IsFuzzing())
91 xOpt.reset(new SvtModuleOptions);
92 SfxObjectFactory* pDocFact = nullptr;
93 SfxObjectFactory* pGlobDocFact = nullptr;
94 if (!xOpt || xOpt->IsWriter())
96 pDocFact = &SwDocShell::Factory();
97 pGlobDocFact = &SwGlobalDocShell::Factory();
100 SfxObjectFactory* pWDocFact = &SwWebDocShell::Factory();
102 auto pUniqueModule = std::make_unique<SwModule>(pWDocFact, pDocFact, pGlobDocFact);
103 SwModule* pModule = pUniqueModule.get();
104 SfxApplication::SetModule(SfxToolsModule::Writer, std::move(pUniqueModule));
106 pWDocFact->SetDocumentServiceName("com.sun.star.text.WebDocument");
108 if (!xOpt || xOpt->IsWriter())
110 pGlobDocFact->SetDocumentServiceName("com.sun.star.text.GlobalDocument");
111 pDocFact->SetDocumentServiceName("com.sun.star.text.TextDocument");
114 // register 3D-object-Factory
115 E3dObjFactory();
117 // register form::component::Form-object-Factory
118 FmFormObjFactory();
120 SdrObjFactory::InsertMakeObjectHdl( LINK( &aSwObjectFactory, SwObjectFactory, MakeObject ) );
122 SAL_INFO( "sw.ui", "Init Core/UI/Filter" );
123 // Initialisation of Statics
124 ::InitCore();
125 m_pFilters.reset(new sw::Filters);
126 ::InitUI();
128 pModule->InitAttrPool();
129 // now SWModule can create its Pool
131 // register your view-factories here
132 RegisterFactories();
134 // register your shell-interfaces here
135 RegisterInterfaces();
137 // register your controllers here
138 RegisterControls();
140 if (!utl::ConfigManager::IsFuzzing())
142 // replace SvxAutocorrect with SwAutocorrect
143 SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
144 const SvxAutoCorrect* pOld = rACfg.GetAutoCorrect();
145 rACfg.SetAutoCorrect(new SwAutoCorrect( *pOld ));
146 m_pAutoCorrCfg = &rACfg;
150 SwDLL::~SwDLL() COVERITY_NOEXCEPT_FALSE
152 if (m_pAutoCorrCfg)
154 // fdo#86494 SwAutoCorrect must be deleted before FinitCore
155 m_pAutoCorrCfg->SetAutoCorrect(nullptr); // delete SwAutoCorrect before exit handlers
158 // Pool has to be deleted before statics are
159 SW_MOD()->RemoveAttrPool();
161 ::FinitUI();
162 m_pFilters.reset();
163 ::FinitCore();
164 // sign out object-Factory
165 SdrObjFactory::RemoveMakeObjectHdl(LINK(&aSwObjectFactory, SwObjectFactory, MakeObject ));
168 sw::Filters & SwDLL::getFilters()
170 assert(m_pFilters);
171 return *m_pFilters;
174 #ifndef DISABLE_DYNLOADING
176 extern "C" SAL_DLLPUBLIC_EXPORT
177 void lok_preload_hook()
179 SwAbstractDialogFactory::Create();
182 #endif
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */