LibreOffice Module basctl (master) 1
iderdll.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 <memory>
23
24#include <iderdll.hxx>
25#include "iderdll2.hxx"
26#include <iderid.hxx>
27#include <basidesh.hxx>
28#include <basobj.hxx>
29#include "basdoc.hxx"
30#include "basicmod.hxx"
31
32#include <basic/sbstar.hxx>
33#include <com/sun/star/frame/Desktop.hpp>
34#include <com/sun/star/script/XLibraryContainerPassword.hpp>
35#include <unotools/resmgr.hxx>
36#include <sfx2/app.hxx>
37#include <osl/diagnose.h>
38
39namespace basctl
40{
41
42using namespace ::com::sun::star;
43using namespace ::com::sun::star::uno;
44
45namespace
46{
47
48class Dll
49{
51 std::unique_ptr<ExtraData> m_xExtraData;
52
53public:
54 Dll ();
55
56 Shell* GetShell() const { return m_pShell; }
57 void SetShell (Shell* pShell) { m_pShell = pShell; }
58 ExtraData* GetExtraData ();
59};
60
61// Holds a basctl::Dll and release it on exit, or dispose of the
62//default XComponent, whichever comes first
63class DllInstance : public comphelper::unique_disposing_solar_mutex_reset_ptr<Dll>
64{
65public:
66 DllInstance() : comphelper::unique_disposing_solar_mutex_reset_ptr<Dll>(Reference<lang::XComponent>( frame::Desktop::create(comphelper::getProcessComponentContext()), UNO_QUERY_THROW), new Dll, true)
67 { }
68};
69
70struct theDllInstance : public rtl::Static<DllInstance, theDllInstance> { };
71
72} // namespace
73
74void EnsureIde ()
75{
76 // coverity[side_effect_free : FALSE] - not actually side-effect-free
77 theDllInstance::get();
78}
79
81{
82 if (Dll* pDll = theDllInstance::get().get())
83 return pDll->GetShell();
84 return nullptr;
85}
86
87void ShellCreated (Shell* pShell)
88{
89 Dll* pDll = theDllInstance::get().get();
90 if (pDll && !pDll->GetShell())
91 pDll->SetShell(pShell);
92}
93
94void ShellDestroyed (Shell const * pShell)
95{
96 Dll* pDll = theDllInstance::get().get();
97 if (pDll && pDll->GetShell() == pShell)
98 pDll->SetShell(nullptr);
99}
100
102{
103 if (Dll* pDll = theDllInstance::get().get())
104 return pDll->GetExtraData();
105 return nullptr;
106}
107
109{
110 return Translate::get(aId, SfxApplication::GetModule(SfxToolsModule::Basic)->GetResLocale());
111}
112
113namespace
114{
115
116Dll::Dll () :
117 m_pShell(nullptr)
118{
119 SfxObjectFactory& rFactory = DocShell::Factory();
120
121 auto pModule = std::make_unique<Module>("basctl", &rFactory);
122 SfxModule* pMod = pModule.get();
123 SfxApplication::SetModule(SfxToolsModule::Basic, std::move(pModule));
124
125 GetExtraData(); // to cause GlobalErrorHdl to be set
126
127 rFactory.SetDocumentServiceName( "com.sun.star.script.BasicIDE" );
128
129 DocShell::RegisterInterface( pMod );
130 Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
131 Shell::RegisterInterface( pMod );
132}
133
134ExtraData* Dll::GetExtraData ()
135{
136 if (!m_xExtraData)
137 m_xExtraData.reset(new ExtraData);
138 return m_xExtraData.get();
139}
140
141} // namespace
142
143
144// basctl::ExtraData
145
146
147ExtraData::ExtraData () :
148 bChoosingMacro(false),
149 bShellInCriticalSection(false)
150{
151 StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl));
152}
153
155{
156 // Resetting ErrorHdl is cleaner indeed but this instance is destroyed
157 // pretty late, after the last Basic, anyway.
158 // Due to the call there is AppData created then though and not
159 // destroyed anymore => MLK's at Purify
160// StarBASIC::SetGlobalErrorHdl( Link() );
161// StarBASIC::SetGlobalBreakHdl( Link() );
162// StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
163}
164
165IMPL_STATIC_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, BasicDebugFlags)
166{
167 BasicDebugFlags nRet = BasicDebugFlags::NONE;
168 if (Shell* pShell = GetShell())
169 {
170 if (BasicManager* pBasMgr = FindBasicManager(pBasic))
171 {
172 // I do get here twice if Step into protected Basic
173 // => bad, if password query twice, also you don't see
174 // the lib in the PasswordDlg...
175 // => start no password query at this point
177 OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
178 if ( aDocument.isValid() )
179 {
180 OUString aOULibName( pBasic->GetName() );
182 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
183 {
184 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
185 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
186 {
187 // a step-out should get me out of the protected area...
188 nRet = BasicDebugFlags::StepOut;
189 }
190 else
191 {
192 nRet = pShell->CallBasicBreakHdl( pBasic );
193 }
194 }
195 }
196 }
197 }
198
199 return nRet;
200}
201
202
203} // namespace basctl
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScriptDocument aDocument
Definition: basobj2.cxx:194
static void SetModule(SfxToolsModule nSharedLib, std::unique_ptr< SfxModule > pModule)
static SfxModule * GetModule(SfxToolsModule nSharedLib)
void SetDocumentServiceName(const OUString &rServiceName)
static void SetGlobalBreakHdl(const Link< StarBASIC *, BasicDebugFlags > &rNewHdl)
encapsulates a document which contains Basic scripts and dialogs
css::uno::Reference< css::script::XLibraryContainer > getLibraryContainer(LibraryContainerType _eType) const
returns the Basic or Dialog library container of the document
static ScriptDocument getDocumentForBasicManager(const BasicManager *_pManager)
returns a (newly created) ScriptDocument instance for the document to which a given BasicManager belo...
bool isValid() const
determines whether the document is actually able to contain Basic/Dialog libraries
Shell * m_pShell
Definition: iderdll.cxx:50
std::unique_ptr< ExtraData > m_xExtraData
Definition: iderdll.cxx:51
void SetShell(SwViewShell *pSh)
OUString get(TranslateId sContextAndId, const std::locale &loc)
IMPL_STATIC_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, BasicDebugFlags)
Definition: iderdll.cxx:165
ExtraData * GetExtraData()
Definition: iderdll.cxx:101
Shell * GetShell()
Definition: iderdll.cxx:80
void ShellCreated(Shell *pShell)
Definition: iderdll.cxx:87
void EnsureIde()
Definition: iderdll.cxx:74
BasicManager * FindBasicManager(StarBASIC const *pLib)
Definition: basobj3.cxx:225
OUString IDEResId(TranslateId aId)
Definition: iderdll.cxx:108
void ShellDestroyed(Shell const *pShell)
Definition: iderdll.cxx:94
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Reference
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
BasicDebugFlags
Shell