Line data Source code
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 <svx/svdobj.hxx>
21 : #include <rtl/logfile.hxx>
22 :
23 : #include "globdoc.hrc"
24 :
25 : #include <swdll.hxx>
26 : #include <wdocsh.hxx>
27 : #include <globdoc.hxx>
28 : #include <initui.hxx>
29 : #include <swmodule.hxx>
30 : #include <swtypes.hxx>
31 : #include <init.hxx>
32 : #include <dobjfac.hxx>
33 : #include <cfgid.h>
34 :
35 : #include <unotools/moduleoptions.hxx>
36 : #include <comphelper/scoped_disposing_ptr.hxx>
37 : #include <comphelper/processfactory.hxx>
38 :
39 : #include <svx/fmobjfac.hxx>
40 : #include <svx/svdfield.hxx>
41 : #include <svx/objfac3d.hxx>
42 :
43 : #include <unomid.h>
44 :
45 : #include "swdllimpl.hxx"
46 :
47 : namespace
48 : {
49 : //Holds a SwDLL and release it on exit, or dispose of the
50 : //default XComponent, whichever comes first
51 24 : class SwDLLInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr<SwDLL>
52 : {
53 : public:
54 24 : SwDLLInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr<SwDLL>(::com::sun::star::uno::Reference<com::sun::star::lang::XComponent>(comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), ::com::sun::star::uno::UNO_QUERY_THROW), new SwDLL)
55 : {
56 24 : }
57 : };
58 :
59 : struct theSwDLLInstance : public rtl::Static<SwDLLInstance, theSwDLLInstance> {};
60 : }
61 :
62 : namespace SwGlobals
63 : {
64 500 : void ensure()
65 : {
66 500 : theSwDLLInstance::get();
67 500 : }
68 :
69 16 : sw::Filters & getFilters()
70 : {
71 16 : return theSwDLLInstance::get().get()->getFilters();
72 : }
73 : }
74 :
75 24 : SwDLL::SwDLL()
76 : {
77 : RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDLL" );
78 :
79 : // the SdModule must be created
80 24 : SwModule** ppShlPtr = (SwModule**) GetAppData(SHL_WRITER);
81 24 : if ( *ppShlPtr )
82 24 : return;
83 :
84 24 : SvtModuleOptions aOpt;
85 24 : SfxObjectFactory* pDocFact = 0;
86 24 : SfxObjectFactory* pGlobDocFact = 0;
87 24 : if ( aOpt.IsWriter() )
88 : {
89 20 : pDocFact = &SwDocShell::Factory();
90 20 : pGlobDocFact = &SwGlobalDocShell::Factory();
91 : }
92 :
93 24 : SfxObjectFactory* pWDocFact = &SwWebDocShell::Factory();
94 :
95 24 : SwModule* pModule = new SwModule( pWDocFact, pDocFact, pGlobDocFact );
96 24 : *ppShlPtr = pModule;
97 :
98 24 : pWDocFact->SetDocumentServiceName(rtl::OUString("com.sun.star.text.WebDocument"));
99 :
100 24 : if ( aOpt.IsWriter() )
101 : {
102 20 : pGlobDocFact->SetDocumentServiceName(rtl::OUString("com.sun.star.text.GlobalDocument"));
103 20 : pDocFact->SetDocumentServiceName(rtl::OUString("com.sun.star.text.TextDocument"));
104 : }
105 :
106 : // register SvDraw-Fields
107 24 : SdrRegisterFieldClasses();
108 :
109 : // register 3D-Objekt-Factory
110 24 : E3dObjFactory();
111 :
112 : // register form::component::Form-Objekt-Factory
113 24 : FmFormObjFactory();
114 :
115 24 : SdrObjFactory::InsertMakeObjectHdl( LINK( &aSwObjectFactory, SwObjectFactory, MakeObject ) );
116 :
117 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "Init Core/UI/Filter" );
118 :
119 : // Initialisation of Statics
120 24 : ::_InitCore();
121 24 : filters_.reset(new sw::Filters);
122 24 : ::_InitUI();
123 :
124 24 : pModule->InitAttrPool();
125 : // now SWModule can create its Pool
126 :
127 : // register your view-factories here
128 24 : RegisterFactories();
129 :
130 : // register your shell-interfaces here
131 24 : RegisterInterfaces();
132 :
133 : // register your controllers here
134 24 : RegisterControls();
135 : }
136 :
137 48 : SwDLL::~SwDLL()
138 : {
139 : // Pool has to be deleted before statics are
140 24 : SW_MOD()->RemoveAttrPool();
141 :
142 24 : ::_FinitUI();
143 24 : filters_.reset();
144 24 : ::_FinitCore();
145 : // sign out Objekt-Factory
146 24 : SdrObjFactory::RemoveMakeObjectHdl(LINK(&aSwObjectFactory, SwObjectFactory, MakeObject ));
147 : #if 0
148 : // the SwModule must be destroyed
149 : SwModule** ppShlPtr = (SwModule**) GetAppData(SHL_WRITER);
150 : delete (*ppShlPtr);
151 : (*ppShlPtr) = NULL;
152 : #endif
153 24 : }
154 :
155 16 : sw::Filters & SwDLL::getFilters()
156 : {
157 : OSL_ASSERT(filters_);
158 16 : return *filters_.get();
159 : }
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|