Line data Source code
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 <comphelper/scoped_disposing_ptr.hxx>
21 : #include <comphelper/processfactory.hxx>
22 :
23 : #include <svheader.hxx>
24 : #include <sfx2/app.hxx>
25 : #include <sfx2/dispatch.hxx>
26 : #include <sfx2/genlink.hxx>
27 :
28 : #include <svl/solar.hrc>
29 : #include <iderdll.hxx>
30 : #include <iderdll2.hxx>
31 : #include <iderid.hxx>
32 : #include <svx/svxids.hrc>
33 : #include <basidesh.hxx>
34 : #include <basidesh.hrc>
35 : #include <basobj.hxx>
36 : #include <bastypes.hxx>
37 : #include <basdoc.hxx>
38 : #include <basicmod.hxx>
39 : #include <propbrw.hxx>
40 :
41 : #include <svl/srchitem.hxx>
42 : #include <com/sun/star/frame/Desktop.hpp>
43 : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
44 :
45 : #include <boost/scoped_ptr.hpp>
46 :
47 : namespace basctl
48 : {
49 :
50 : using namespace ::com::sun::star;
51 : using namespace ::com::sun::star::uno;
52 :
53 : namespace
54 : {
55 :
56 0 : class Dll
57 : {
58 : Shell* m_pShell;
59 : boost::scoped_ptr<ExtraData> m_pExtraData;
60 :
61 : public:
62 : Dll ();
63 :
64 0 : Shell* GetShell() const { return m_pShell; }
65 0 : void SetShell (Shell* pShell) { m_pShell = pShell; }
66 : ExtraData* GetExtraData ();
67 : };
68 :
69 : // Holds a basctl::Dll and release it on exit, or dispose of the
70 : //default XComponent, whichever comes first
71 0 : class DllInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr<Dll>
72 : {
73 : public:
74 0 : DllInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr<Dll>(Reference<lang::XComponent>( frame::Desktop::create(comphelper::getProcessComponentContext()), UNO_QUERY_THROW), new Dll)
75 0 : { }
76 : };
77 :
78 : struct theDllInstance : public rtl::Static<DllInstance, theDllInstance> { };
79 :
80 : } // namespace
81 :
82 0 : void EnsureIde ()
83 : {
84 0 : theDllInstance::get();
85 0 : }
86 :
87 0 : Shell* GetShell ()
88 : {
89 0 : if (Dll* pDll = theDllInstance::get().get())
90 0 : return pDll->GetShell();
91 0 : return 0;
92 : }
93 :
94 0 : void ShellCreated (Shell* pShell)
95 : {
96 0 : Dll* pDll = theDllInstance::get().get();
97 0 : if (pDll && !pDll->GetShell())
98 0 : pDll->SetShell(pShell);
99 0 : }
100 :
101 0 : void ShellDestroyed (Shell* pShell)
102 : {
103 0 : Dll* pDll = theDllInstance::get().get();
104 0 : if (pDll && pDll->GetShell() == pShell)
105 0 : pDll->SetShell(0);
106 0 : }
107 :
108 0 : ExtraData* GetExtraData()
109 : {
110 0 : if (Dll* pDll = theDllInstance::get().get())
111 0 : return pDll->GetExtraData();
112 0 : return 0;
113 : }
114 :
115 :
116 0 : IDEResId::IDEResId( sal_uInt16 nId ):
117 0 : ResId(nId, *Module::Get()->GetResMgr())
118 0 : { }
119 :
120 : namespace
121 : {
122 :
123 0 : Dll::Dll () :
124 0 : m_pShell(0)
125 : {
126 0 : SfxObjectFactory* pFact = &DocShell::Factory();
127 : (void)pFact;
128 :
129 : ResMgr* pMgr = ResMgr::CreateResMgr(
130 0 : "basctl", Application::GetSettings().GetUILanguageTag().getLocale()
131 0 : );
132 :
133 0 : Module::Get() = new Module( pMgr, &DocShell::Factory() );
134 :
135 0 : GetExtraData(); // to cause GlobalErrorHdl to be set
136 :
137 0 : SfxModule* pMod = Module::Get();
138 :
139 0 : SfxObjectFactory& rFactory = DocShell::Factory();
140 0 : rFactory.SetDocumentServiceName( "com.sun.star.script.BasicIDE" );
141 :
142 0 : DocShell::RegisterInterface( pMod );
143 0 : Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
144 0 : Shell::RegisterInterface( pMod );
145 0 : }
146 :
147 0 : ExtraData* Dll::GetExtraData ()
148 : {
149 0 : if (!m_pExtraData)
150 0 : m_pExtraData.reset(new ExtraData);
151 0 : return m_pExtraData.get();
152 : }
153 :
154 : } // namespace
155 :
156 : //
157 : // basctl::ExtraData
158 : // ===================
159 : //
160 :
161 0 : ExtraData::ExtraData () :
162 0 : pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM)),
163 : nBasicDialogCount(0),
164 : bChoosingMacro(false),
165 0 : bShellInCriticalSection(false)
166 : {
167 0 : StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl));
168 0 : }
169 :
170 0 : ExtraData::~ExtraData ()
171 : {
172 : // Resetting ErrorHdl is cleaner indeed but this instance is destroyed
173 : // pretty late, after the last Basic, anyway.
174 : // Due to the call there is AppData created then though and not
175 : // destroyed anymore => MLK's at Purify
176 : // StarBASIC::SetGlobalErrorHdl( Link() );
177 : // StarBASIC::SetGlobalBreakHdl( Link() );
178 : // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
179 0 : }
180 :
181 0 : void ExtraData::SetSearchItem (const SvxSearchItem& rItem)
182 : {
183 0 : pSearchItem.reset((SvxSearchItem*)rItem.Clone());
184 0 : }
185 :
186 0 : IMPL_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic )
187 : {
188 0 : long nRet = 0;
189 0 : if (Shell* pShell = GetShell())
190 : {
191 0 : if (BasicManager* pBasMgr = FindBasicManager(pBasic))
192 : {
193 : // I do get here twice if Step into protected Basic
194 : // => bad, if password query twice, also you don't see
195 : // the lib in the PasswordDlg...
196 : // => start no password query at this point
197 0 : ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
198 : OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
199 0 : if ( aDocument.isValid() )
200 : {
201 0 : OUString aOULibName( pBasic->GetName() );
202 0 : Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
203 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
204 : {
205 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
206 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
207 : {
208 : // a step-out should get me out of the protected area...
209 0 : nRet = SbDEBUG_STEPOUT;
210 : }
211 : else
212 : {
213 0 : nRet = pShell->CallBasicBreakHdl( pBasic );
214 0 : }
215 0 : }
216 0 : }
217 : }
218 : }
219 :
220 0 : return nRet;
221 : }
222 :
223 :
224 : } // namespace basctl
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|