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 <appdata.hxx>
23 #include <sfxpicklist.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/doctempl.hxx>
26 #include <sfx2/fcontnr.hxx>
27 #include <sfx2/module.hxx>
28 #include <sfx2/msgpool.hxx>
29 #include <sfx2/sidebar/Theme.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <appbaslib.hxx>
32 #include <childwinimpl.hxx>
33 #include <ctrlfactoryimpl.hxx>
34 #include <shellimpl.hxx>
35 #include <unoctitm.hxx>
36 #include <svl/svdde.hxx>
37
38 #include <basic/basicmanagerrepository.hxx>
39 #include <basic/basmgr.hxx>
40 #include <basic/basrdll.hxx>
41
42 using ::basic::BasicManagerRepository;
43 using ::basic::BasicManagerCreationListener;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::frame::XModel;
46 using ::com::sun::star::uno::XInterface;
47
48 static BasicDLL* pBasic = nullptr;
49
50 class SfxBasicManagerCreationListener : public ::basic::BasicManagerCreationListener
51 {
52 private:
53 SfxAppData_Impl& m_rAppData;
54
55 public:
SfxBasicManagerCreationListener(SfxAppData_Impl & _rAppData)56 explicit SfxBasicManagerCreationListener(SfxAppData_Impl& _rAppData)
57 : m_rAppData(_rAppData)
58 {
59 }
60
61 virtual ~SfxBasicManagerCreationListener();
62
63 virtual void onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager ) override;
64 };
65
~SfxBasicManagerCreationListener()66 SfxBasicManagerCreationListener::~SfxBasicManagerCreationListener()
67 {
68 }
69
onBasicManagerCreated(const Reference<XModel> & _rxForDocument,BasicManager & _rBasicManager)70 void SfxBasicManagerCreationListener::onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager )
71 {
72 if ( _rxForDocument == nullptr )
73 m_rAppData.OnApplicationBasicManagerCreated( _rBasicManager );
74 }
75
SfxAppData_Impl()76 SfxAppData_Impl::SfxAppData_Impl()
77 : pPool(nullptr)
78 , pProgress(nullptr)
79 , nDocModalMode(0)
80 , nRescheduleLocks(0)
81 , pBasicManager( new SfxBasicManagerHolder )
82 , pBasMgrListener( new SfxBasicManagerCreationListener( *this ) )
83 , pViewFrame( nullptr )
84 , bDowning( true )
85 , bInQuit( false )
86
87 {
88 pBasic = new BasicDLL;
89
90 #if HAVE_FEATURE_SCRIPTING
91 BasicManagerRepository::registerCreationListener( *pBasMgrListener );
92 #endif
93 }
94
~SfxAppData_Impl()95 SfxAppData_Impl::~SfxAppData_Impl()
96 {
97 DeInitDDE();
98 pBasicManager.reset();
99
100 #if HAVE_FEATURE_SCRIPTING
101 BasicManagerRepository::revokeCreationListener( *pBasMgrListener );
102 pBasMgrListener.reset();
103 #endif
104
105 delete pBasic;
106 }
107
GetDocumentTemplates()108 SfxDocumentTemplates* SfxAppData_Impl::GetDocumentTemplates()
109 {
110 if ( !pTemplates )
111 pTemplates.reset(new SfxDocumentTemplates);
112 else
113 pTemplates->ReInitFromComponent();
114 return pTemplates.get();
115 }
116
OnApplicationBasicManagerCreated(BasicManager & _rBasicManager)117 void SfxAppData_Impl::OnApplicationBasicManagerCreated( BasicManager& _rBasicManager )
118 {
119 #if !HAVE_FEATURE_SCRIPTING
120 (void) _rBasicManager;
121 #else
122 pBasicManager->reset( &_rBasicManager );
123
124 // global constants, additionally to the ones already added by createApplicationBasicManager:
125 // ThisComponent
126 Reference< XInterface > xCurrentComponent = SfxObjectShell::GetCurrentComponent();
127 _rBasicManager.SetGlobalUNOConstant( "ThisComponent", makeAny( xCurrentComponent ) );
128 #endif
129 }
130
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
132