xref: /aoo42x/main/basctl/source/basicide/iderdll.cxx (revision 31598a22)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 
27 
28 #include <ide_pch.hxx>
29 
30 
31 #include <svheader.hxx>
32 #include <sfx2/app.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/genlink.hxx>
35 
36 
37 #include <svl/solar.hrc>
38 #include <iderdll.hxx>
39 #include <iderdll2.hxx>
40 #include <iderid.hxx>
41 #include <svx/svxids.hrc>
42 #include <basidesh.hxx>
43 #include <basidesh.hrc>
44 #include <basobj.hxx>
45 #include <bastypes.hxx>
46 #include <basdoc.hxx>
47 #include <basicmod.hxx>
48 #include <propbrw.hxx>
49 
50 
51 #define ITEMID_SEARCH	0
52 #include <svl/srchitem.hxx>
53 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
54 
55 using ::rtl::OUString;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 
59 
60 static BasicIDEDLL* pBasicIDEDLL = 0;
61 
GetDLL()62 BasicIDEDLL* BasicIDEDLL::GetDLL()
63 {
64     return pBasicIDEDLL;
65 }
66 
IDEResId(sal_uInt16 nId)67 IDEResId::IDEResId( sal_uInt16 nId ):
68     ResId( nId, *(*(BasicIDEModule**)GetAppData(SHL_IDE))->GetResMgr() )
69 {
70 }
71 
BasicIDEDLL()72 BasicIDEDLL::BasicIDEDLL()
73 {
74     pBasicIDEDLL = this;
75 	pShell = 0;
76 	pExtraData = 0;
77 
78 	GetExtraData();	// damit GlobalErrorHdl gesetzt wird.
79 }
80 
~BasicIDEDLL()81 BasicIDEDLL::~BasicIDEDLL()
82 {
83     delete pExtraData;
84 	*(BasicIDEDLL**)GetAppData(SHL_IDE) = NULL;
85 }
86 
Init()87 void BasicIDEDLL::Init()
88 {
89 	if ( pBasicIDEDLL )
90 		return;
91 
92 	SfxObjectFactory* pFact = &BasicDocShell::Factory();
93 	(void)pFact;
94 
95 	ByteString aResMgrName( "basctl" );
96     ResMgr* pMgr = ResMgr::CreateResMgr(
97         aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
98 
99     BASIC_MOD() = new BasicIDEModule( pMgr, &BasicDocShell::Factory() );
100 
101     new BasicIDEDLL;
102     SfxModule* pMod = BASIC_MOD();
103 
104     SfxObjectFactory& rFactory = BasicDocShell::Factory();
105     rFactory.SetDocumentServiceName( String::CreateFromAscii( "com.sun.star.script.BasicIDE" ) );
106 
107     BasicDocShell::RegisterInterface( pMod );
108 	BasicIDEShell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
109     BasicIDEShell::RegisterInterface( pMod );
110 
111 	PropBrwMgr::RegisterChildWindow();
112 }
113 
114 /*************************************************************************
115 |*
116 |* Deinitialisierung
117 |*
118 \************************************************************************/
Exit()119 void BasicIDEDLL::Exit()
120 {
121     // the BasicIDEModule must be destroyed
122 	BasicIDEModule** ppShlPtr = (BasicIDEModule**) GetAppData(SHL_IDE);
123 	delete (*ppShlPtr);
124 	(*ppShlPtr) = NULL;
125     DELETEZ( pBasicIDEDLL );
126 }
127 
GetExtraData()128 BasicIDEData* BasicIDEDLL::GetExtraData()
129 {
130 	if ( !pExtraData )
131 		pExtraData = new BasicIDEData;
132 	 return pExtraData;
133 }
134 
BasicIDEData()135 BasicIDEData::BasicIDEData() : aObjCatPos( INVPOSITION, INVPOSITION )
136 {
137 	nBasicDialogCount = 0;
138 	bChoosingMacro = sal_False;
139 	bShellInCriticalSection = sal_False;
140 	pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
141 
142     StarBASIC::SetGlobalBreakHdl( LINK( this, BasicIDEData, GlobalBasicBreakHdl ) );
143 
144 	pAccelerator = 0;
145 }
146 
~BasicIDEData()147 BasicIDEData::~BasicIDEData()
148 {
149 	// ErrorHdl zuruecksetzen ist zwar sauberer, aber diese Instanz wird
150 	// sowieso sehr spaet, nach dem letzten Basic, zerstoert.
151 	// Durch den Aufruf werden dann aber wieder AppDaten erzeugt und nicht
152 	// mehr zerstoert => MLK's beim Purify
153 //	StarBASIC::SetGlobalErrorHdl( Link() );
154 //	StarBASIC::SetGlobalBreakHdl( Link() );
155 //	StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
156 
157 	delete pSearchItem;
158 	//delete pAccelerator;
159 }
160 
GetSearchItem() const161 SvxSearchItem& BasicIDEData::GetSearchItem() const
162 {
163 	return *pSearchItem;
164 }
165 
SetSearchItem(const SvxSearchItem & rItem)166 void BasicIDEData::SetSearchItem( const SvxSearchItem& rItem )
167 {
168 	delete pSearchItem;
169 	pSearchItem = (SvxSearchItem*)rItem.Clone();
170 }
171 
IMPL_LINK(BasicIDEData,GlobalBasicBreakHdl,StarBASIC *,pBasic)172 IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic )
173 {
174     long nRet = 0;
175 	BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
176 	if ( pIDEShell )
177 	{
178 		BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic );
179 		if ( pBasMgr )
180 		{
181             // Hier lande ich zweimal, wenn Step into protected Basic
182 			// => schlecht, wenn Passwortabfrage 2x, ausserdem sieht man in
183 			// dem PasswordDlg nicht, fuer welche Lib...
184 			// => An dieser Stelle keine Passwort-Abfrage starten
185             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
186             OSL_ENSURE( aDocument.isValid(), "BasicIDEData::GlobalBasicBreakHdl: no document for the basic manager!" );
187             if ( aDocument.isValid() )
188             {
189                 ::rtl::OUString aOULibName( pBasic->GetName() );
190                 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
191                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
192                 {
193                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
194                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
195                     {
196            			    // Ein Step-Out muesste mich aus den geschuetzten Bereich befoerdern...
197                         nRet = SbDEBUG_STEPOUT;
198                     }
199                     else
200                     {
201       				    nRet = pIDEShell->CallBasicBreakHdl( pBasic );
202                     }
203                 }
204             }
205         }
206 	}
207 
208 	return nRet;
209 }
210