bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / iderdll.cxx
blob535397b3193333b03dd2b0ca8ef3570e8a9e652c
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 <comphelper/unique_disposing_ptr.hxx>
21 #include <comphelper/processfactory.hxx>
23 #include <iderdll.hxx>
24 #include <iderdll2.hxx>
25 #include <iderid.hxx>
26 #include <basidesh.hxx>
27 #include <basidesh.hrc>
28 #include <basdoc.hxx>
29 #include <basicmod.hxx>
31 #include <svl/srchitem.hxx>
32 #include <com/sun/star/frame/Desktop.hpp>
33 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
34 #include <vcl/settings.hxx>
37 namespace basctl
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
43 Module* Module::mpModule = 0;
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)
67 { }
70 struct theDllInstance : public rtl::Static<DllInstance, theDllInstance> { };
72 } // namespace
74 void EnsureIde ()
76 theDllInstance::get();
79 Shell* GetShell ()
81 if (Dll* pDll = theDllInstance::get().get())
82 return pDll->GetShell();
83 return 0;
86 void ShellCreated (Shell* pShell)
88 Dll* pDll = theDllInstance::get().get();
89 if (pDll && !pDll->GetShell())
90 pDll->SetShell(pShell);
93 void ShellDestroyed (Shell* pShell)
95 Dll* pDll = theDllInstance::get().get();
96 if (pDll && pDll->GetShell() == pShell)
97 pDll->SetShell(0);
100 ExtraData* GetExtraData()
102 if (Dll* pDll = theDllInstance::get().get())
103 return pDll->GetExtraData();
104 return 0;
108 IDEResId::IDEResId( sal_uInt16 nId ):
109 ResId(nId, *Module::Get()->GetResMgr())
112 namespace
115 Dll::Dll () :
116 m_pShell(0)
118 SfxObjectFactory* pFact = &DocShell::Factory();
119 (void)pFact;
121 ResMgr* pMgr = ResMgr::CreateResMgr(
122 "basctl", Application::GetSettings().GetUILanguageTag());
124 Module::Get() = new Module( pMgr, &DocShell::Factory() );
126 GetExtraData(); // to cause GlobalErrorHdl to be set
128 SfxModule* pMod = Module::Get();
130 SfxObjectFactory& rFactory = DocShell::Factory();
131 rFactory.SetDocumentServiceName( "com.sun.star.script.BasicIDE" );
133 DocShell::RegisterInterface( pMod );
134 Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
135 Shell::RegisterInterface( pMod );
138 ExtraData* Dll::GetExtraData ()
140 if (!m_xExtraData)
141 m_xExtraData.reset(new ExtraData);
142 return m_xExtraData.get();
145 } // namespace
148 // basctl::ExtraData
152 ExtraData::ExtraData () :
153 pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM)),
154 nBasicDialogCount(0),
155 bChoosingMacro(false),
156 bShellInCriticalSection(false)
158 StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl));
161 ExtraData::~ExtraData ()
163 // Resetting ErrorHdl is cleaner indeed but this instance is destroyed
164 // pretty late, after the last Basic, anyway.
165 // Due to the call there is AppData created then though and not
166 // destroyed anymore => MLK's at Purify
167 // StarBASIC::SetGlobalErrorHdl( Link() );
168 // StarBASIC::SetGlobalBreakHdl( Link() );
169 // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
172 void ExtraData::SetSearchItem (const SvxSearchItem& rItem)
174 pSearchItem.reset(static_cast<SvxSearchItem*>(rItem.Clone()));
177 IMPL_STATIC_LINK_TYPED(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, sal_uInt16)
179 sal_uInt16 nRet = 0;
180 if (Shell* pShell = GetShell())
182 if (BasicManager* pBasMgr = FindBasicManager(pBasic))
184 // I do get here twice if Step into protected Basic
185 // => bad, if password query twice, also you don't see
186 // the lib in the PasswordDlg...
187 // => start no password query at this point
188 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
189 OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
190 if ( aDocument.isValid() )
192 OUString aOULibName( pBasic->GetName() );
193 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
194 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
196 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
197 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
199 // a step-out should get me out of the protected area...
200 nRet = SbDEBUG_STEPOUT;
202 else
204 nRet = pShell->CallBasicBreakHdl( pBasic );
211 return nRet;
215 } // namespace basctl
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */