merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / iderdll.cxx
blob69217665cc3f1261081b2acf5ecf7bf550b06de2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iderdll.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
35 #include <ide_pch.hxx>
38 #include <svheader.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/genlink.hxx>
44 #include <svtools/solar.hrc>
45 #include <iderdll.hxx>
46 #include <iderdll2.hxx>
47 #include <iderid.hxx>
48 #include <svx/svxids.hrc>
49 #include <basidesh.hxx>
50 #include <basidesh.hrc>
51 #include <basobj.hxx>
52 #include <bastypes.hxx>
53 #include <basdoc.hxx>
54 #include <basicmod.hxx>
55 #include <propbrw.hxx>
58 #define ITEMID_SEARCH 0
59 #include <svx/srchitem.hxx>
60 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
62 using ::rtl::OUString;
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
67 static BasicIDEDLL* pBasicIDEDLL = 0;
69 BasicIDEDLL* BasicIDEDLL::GetDLL()
71 return pBasicIDEDLL;
74 IDEResId::IDEResId( USHORT nId ):
75 ResId( nId, *(*(BasicIDEModule**)GetAppData(SHL_IDE))->GetResMgr() )
79 BasicIDEDLL::BasicIDEDLL()
81 pBasicIDEDLL = this;
82 pShell = 0;
83 pExtraData = 0;
85 GetExtraData(); // damit GlobalErrorHdl gesetzt wird.
88 BasicIDEDLL::~BasicIDEDLL()
90 delete pExtraData;
91 *(BasicIDEDLL**)GetAppData(SHL_IDE) = NULL;
94 void BasicIDEDLL::Init()
96 if ( pBasicIDEDLL )
97 return;
99 SfxObjectFactory* pFact = &BasicDocShell::Factory();
100 (void)pFact;
102 ByteString aResMgrName( "basctl" );
103 ResMgr* pMgr = ResMgr::CreateResMgr(
104 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
106 BASIC_MOD() = new BasicIDEModule( pMgr, &BasicDocShell::Factory() );
108 new BasicIDEDLL;
109 SfxModule* pMod = BASIC_MOD();
111 SfxObjectFactory& rFactory = BasicDocShell::Factory();
112 rFactory.SetDocumentServiceName( String::CreateFromAscii( "com.sun.star.script.BasicIDE" ) );
114 BasicDocShell::RegisterInterface( pMod );
115 BasicIDEShell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
116 BasicIDEShell::RegisterInterface( pMod );
118 PropBrwMgr::RegisterChildWindow();
121 /*************************************************************************
123 |* Deinitialisierung
125 \************************************************************************/
126 void BasicIDEDLL::Exit()
128 // the BasicIDEModule must be destroyed
129 BasicIDEModule** ppShlPtr = (BasicIDEModule**) GetAppData(SHL_IDE);
130 delete (*ppShlPtr);
131 (*ppShlPtr) = NULL;
132 DELETEZ( pBasicIDEDLL );
135 BasicIDEData* BasicIDEDLL::GetExtraData()
137 if ( !pExtraData )
138 pExtraData = new BasicIDEData;
139 return pExtraData;
142 BasicIDEData::BasicIDEData() : aObjCatPos( INVPOSITION, INVPOSITION )
144 nBasicDialogCount = 0;
145 bChoosingMacro = FALSE;
146 bShellInCriticalSection = FALSE;
147 pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
149 StarBASIC::SetGlobalBreakHdl( LINK( this, BasicIDEData, GlobalBasicBreakHdl ) );
151 pAccelerator = 0;
154 BasicIDEData::~BasicIDEData()
156 // ErrorHdl zuruecksetzen ist zwar sauberer, aber diese Instanz wird
157 // sowieso sehr spaet, nach dem letzten Basic, zerstoert.
158 // Durch den Aufruf werden dann aber wieder AppDaten erzeugt und nicht
159 // mehr zerstoert => MLK's beim Purify
160 // StarBASIC::SetGlobalErrorHdl( Link() );
161 // StarBASIC::SetGlobalBreakHdl( Link() );
162 // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
164 delete pSearchItem;
165 //delete pAccelerator;
168 SvxSearchItem& BasicIDEData::GetSearchItem() const
170 return *pSearchItem;
173 void BasicIDEData::SetSearchItem( const SvxSearchItem& rItem )
175 delete pSearchItem;
176 pSearchItem = (SvxSearchItem*)rItem.Clone();
179 IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic )
181 long nRet = 0;
182 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
183 if ( pIDEShell )
185 BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic );
186 if ( pBasMgr )
188 // Hier lande ich zweimal, wenn Step into protected Basic
189 // => schlecht, wenn Passwortabfrage 2x, ausserdem sieht man in
190 // dem PasswordDlg nicht, fuer welche Lib...
191 // => An dieser Stelle keine Passwort-Abfrage starten
192 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
193 OSL_ENSURE( aDocument.isValid(), "BasicIDEData::GlobalBasicBreakHdl: no document for the basic manager!" );
194 if ( aDocument.isValid() )
196 ::rtl::OUString aOULibName( pBasic->GetName() );
197 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
198 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
200 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
201 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
203 // Ein Step-Out muesste mich aus den geschuetzten Bereich befoerdern...
204 nRet = SbDEBUG_STEPOUT;
206 else
208 nRet = pIDEShell->CallBasicBreakHdl( pBasic );
215 return nRet;
218 IMPL_LINK( BasicIDEData, ExecuteMacroEvent, void *, pData )
220 if ( pData )
222 SFX_APP()->EnterBasicCall();
223 SbMethod* pMethod = (SbMethod*)pData;
225 // Ist es eine StarScript-Methode? Am Parent erkennen
226 DBG_ASSERT( pMethod->GetParent()->GetFlags() & SBX_EXTSEARCH, "Kein EXTSEARCH!" );
227 BasicIDE::RunMethod( pMethod );
228 pMethod->ReleaseRef(); // muss vorher inkrementiert worden sein!
229 SFX_APP()->LeaveBasicCall();
231 return 0;