1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <comphelper/unique_disposing_ptr.hxx>
22 #include <comphelper/processfactory.hxx>
24 #include <iderdll.hxx>
25 #include "iderdll2.hxx"
27 #include <basidesh.hxx>
28 #include <strings.hrc>
30 #include "basicmod.hxx"
32 #include <svl/srchitem.hxx>
33 #include <svx/svxids.hrc>
34 #include <com/sun/star/frame/Desktop.hpp>
35 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
36 #include <unotools/resmgr.hxx>
37 #include <vcl/settings.hxx>
38 #include <o3tl/make_unique.hxx>
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
52 std::unique_ptr
<ExtraData
> m_xExtraData
;
57 Shell
* GetShell() const { return m_pShell
; }
58 void SetShell (Shell
* pShell
) { m_pShell
= pShell
; }
59 ExtraData
* GetExtraData ();
62 // Holds a basctl::Dll and release it on exit, or dispose of the
63 //default XComponent, whichever comes first
64 class DllInstance
: public comphelper::unique_disposing_solar_mutex_reset_ptr
<Dll
>
67 DllInstance() : comphelper::unique_disposing_solar_mutex_reset_ptr
<Dll
>(Reference
<lang::XComponent
>( frame::Desktop::create(comphelper::getProcessComponentContext()), UNO_QUERY_THROW
), new Dll
, true)
71 struct theDllInstance
: public rtl::Static
<DllInstance
, theDllInstance
> { };
77 theDllInstance::get();
82 if (Dll
* pDll
= theDllInstance::get().get())
83 return pDll
->GetShell();
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();
108 OUString
IDEResId(const char *pId
)
110 return Translate::get(pId
, SfxApplication::GetModule(SfxToolsModule::Basic
)->GetResLocale());
119 SfxObjectFactory
& rFactory
= DocShell::Factory();
121 auto pModule
= o3tl::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( "com.sun.star.script.BasicIDE" );
129 DocShell::RegisterInterface( pMod
);
130 Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH
);
131 Shell::RegisterInterface( pMod
);
134 ExtraData
* Dll::GetExtraData ()
137 m_xExtraData
.reset(new ExtraData
);
138 return m_xExtraData
.get();
147 ExtraData::ExtraData () :
148 pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM
)),
149 bChoosingMacro(false),
150 bShellInCriticalSection(false)
152 StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData
, GlobalBasicBreakHdl
));
155 ExtraData::~ExtraData ()
157 // Resetting ErrorHdl is cleaner indeed but this instance is destroyed
158 // pretty late, after the last Basic, anyway.
159 // Due to the call there is AppData created then though and not
160 // destroyed anymore => MLK's at Purify
161 // StarBASIC::SetGlobalErrorHdl( Link() );
162 // StarBASIC::SetGlobalBreakHdl( Link() );
163 // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
166 void ExtraData::SetSearchItem (const SvxSearchItem
& rItem
)
168 pSearchItem
.reset(static_cast<SvxSearchItem
*>(rItem
.Clone()));
171 IMPL_STATIC_LINK(ExtraData
, GlobalBasicBreakHdl
, StarBASIC
*, pBasic
, BasicDebugFlags
)
173 BasicDebugFlags nRet
= BasicDebugFlags::NONE
;
174 if (Shell
* pShell
= GetShell())
176 if (BasicManager
* pBasMgr
= FindBasicManager(pBasic
))
178 // I do get here twice if Step into protected Basic
179 // => bad, if password query twice, also you don't see
180 // the lib in the PasswordDlg...
181 // => start no password query at this point
182 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
183 OSL_ENSURE( aDocument
.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
184 if ( aDocument
.isValid() )
186 OUString
aOULibName( pBasic
->GetName() );
187 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
188 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) )
190 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
191 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
193 // a step-out should get me out of the protected area...
194 nRet
= BasicDebugFlags::StepOut
;
198 nRet
= pShell
->CallBasicBreakHdl( pBasic
);
209 } // namespace basctl
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */