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