tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basctl / source / basicide / iderdll.cxx
blob6796cc640c463160ff92c13b789f336aea4d3ba7
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>
21 #include <comphelper/unique_disposing_ptr.hxx>
22 #include <comphelper/processfactory.hxx>
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"
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>
39 namespace basctl
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
45 namespace
48 class Dll
50 Shell* m_pShell;
51 std::unique_ptr<ExtraData> m_xExtraData;
53 public:
54 Dll ();
56 Shell* GetShell() const { return m_pShell; }
57 void SetShell (Shell* pShell) { m_pShell = pShell; }
58 ExtraData* GetExtraData ();
61 // Holds a basctl::Dll and release it on exit, or dispose of the
62 //default XComponent, whichever comes first
63 class DllInstance : public comphelper::unique_disposing_solar_mutex_reset_ptr<Dll>
65 public:
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 { }
70 struct theDllInstance : public rtl::Static<DllInstance, theDllInstance> { };
72 } // namespace
74 void EnsureIde ()
76 // coverity[side_effect_free : FALSE] - not actually side-effect-free
77 theDllInstance::get();
80 Shell* GetShell ()
82 if (Dll* pDll = theDllInstance::get().get())
83 return pDll->GetShell();
84 return nullptr;
87 void ShellCreated (Shell* pShell)
89 Dll* pDll = theDllInstance::get().get();
90 if (pDll && !pDll->GetShell())
91 pDll->SetShell(pShell);
94 void ShellDestroyed (Shell const * pShell)
96 Dll* pDll = theDllInstance::get().get();
97 if (pDll && pDll->GetShell() == pShell)
98 pDll->SetShell(nullptr);
101 ExtraData* GetExtraData()
103 if (Dll* pDll = theDllInstance::get().get())
104 return pDll->GetExtraData();
105 return nullptr;
108 OUString IDEResId(TranslateId aId)
110 return Translate::get(aId, SfxApplication::GetModule(SfxToolsModule::Basic)->GetResLocale());
113 namespace
116 Dll::Dll () :
117 m_pShell(nullptr)
119 SfxObjectFactory& rFactory = DocShell::Factory();
121 auto pModule = std::make_unique<Module>("basctl", &rFactory);
122 SfxModule* pMod = pModule.get();
123 SfxApplication::SetModule(SfxToolsModule::Basic, std::move(pModule));
125 GetExtraData(); // to cause GlobalErrorHdl to be set
127 rFactory.SetDocumentServiceName( u"com.sun.star.script.BasicIDE"_ustr );
129 DocShell::RegisterInterface( pMod );
130 Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
131 Shell::RegisterInterface( pMod );
134 ExtraData* Dll::GetExtraData ()
136 if (!m_xExtraData)
137 m_xExtraData.reset(new ExtraData);
138 return m_xExtraData.get();
141 } // namespace
144 // basctl::ExtraData
147 ExtraData::ExtraData () :
148 bChoosingMacro(false),
149 bShellInCriticalSection(false)
151 StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl));
154 ExtraData::~ExtraData ()
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() );
165 IMPL_STATIC_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, BasicDebugFlags)
167 BasicDebugFlags nRet = BasicDebugFlags::NONE;
168 if (Shell* pShell = GetShell())
170 if (BasicManager* pBasMgr = FindBasicManager(pBasic))
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
176 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
177 OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
178 if ( aDocument.isValid() )
180 const OUString& aOULibName( pBasic->GetName() );
181 Reference< script::XLibraryContainer > xModLibContainer = aDocument.getLibraryContainer( E_SCRIPTS );
182 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
184 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
185 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
187 // a step-out should get me out of the protected area...
188 nRet = BasicDebugFlags::StepOut;
190 else
192 nRet = pShell->CallBasicBreakHdl( pBasic );
199 return nRet;
203 } // namespace basctl
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */