merge the formfield patch from ooo-build
[ooovba.git] / basic / source / app / mybasic.cxx
blob335db6c21cb32d8c7817e171e29175032a35a0e7
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: mybasic.cxx,v $
10 * $Revision: 1.14 $
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_basic.hxx"
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
36 #endif
37 #include <basic/sbx.hxx>
39 // AB-Uno-Test
40 //#define unotest
41 #ifdef unotest
42 #ifndef _USR_UNO_HXX
43 #include <usr/uno.hxx>
44 #endif
45 #include <basic/sbuno.hxx>
46 #include <sbunoobj.hxx>
47 #endif
49 #include "sbintern.hxx"
51 #ifndef _BASIC_TTRESHLP_HXX
52 #include <basic/ttstrhlp.hxx>
53 #endif
54 #include <basic/mybasic.hxx>
55 #include "basic.hrc"
56 #include "appbased.hxx"
58 #include "status.hxx"
59 #include "basic.hrc"
61 #include "object.hxx"
63 #include "processw.hxx"
64 #include "basrid.hxx"
66 TYPEINIT1(MyBasic,StarBASIC)
68 class MyFactory : public SbxFactory
70 public:
71 virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
74 static SampleObjectFac aFac1;
75 static MyFactory aFac2;
76 static ProcessFactory aProcessFac;
77 static short nInst = 0;
79 SbxBase* MyFactory::Create( UINT16 nSbxId, UINT32 nCr )
81 if( nCr == SBXCR_TEST && nSbxId == SBXID_MYBASIC )
82 return new MyBasic;
83 else
84 return NULL;
87 MyBasic::MyBasic() : StarBASIC()
89 nError = 0;
90 if( !nInst++ )
92 AddFactory( &aFac1 );
93 AddFactory( &aFac2 );
94 AddFactory( &aProcessFac );
96 SbxVariable* p = new SbxCollection( CUniString("MyColl") );
97 p->SetName( CUniString("Objects") );
98 Insert( p );
100 // AB-Uno-Test
101 #ifdef unotest
102 // Get Uno-Service-Manager and Reflection Service
103 createAndSetDefaultServiceManager(); // done later
105 // Get Uno-Test-Object
106 UsrAny aObjAny = getIntrospectionTestObject();
108 // Box object into SbUnoObject
109 String aName( "UnoObject" );
110 SbxObjectRef xSbUnoObj = GetSbUnoObject( aName, aObjAny );
111 //SbxObjectRef xSbUnoObj = new SbUnoObject( aName, aObjAny );
112 Insert( (SbxObject*)xSbUnoObj );
113 #endif
115 pTestObject = NULL;
118 Link MyBasic::GenLogHdl()
120 return LINK( GetpApp()->GetAppWindow(), BasicFrame, Log );
123 Link MyBasic::GenWinInfoHdl()
125 return LINK( GetpApp()->GetAppWindow(), BasicFrame, WinInfo );
128 Link MyBasic::GenModuleWinExistsHdl()
130 return LINK( GetpApp()->GetAppWindow(), BasicFrame, ModuleWinExists );
133 Link MyBasic::GenWriteStringHdl()
135 return LINK( GetpApp()->GetAppWindow(), BasicFrame, WriteString );
138 void MyBasic::StartListeningTT( SfxBroadcaster &rBroadcaster )
140 ((BasicFrame*)GetpApp()->GetAppWindow())->StartListening( rBroadcaster );
143 void MyBasic::SetCompileModule( SbModule *pMod )
145 GetSbData()->pCompMod = pMod;
148 SbModule *MyBasic::GetCompileModule()
150 return GetSbData()->pCompMod;
153 String MyBasic::GenRealString( const String &aResString )
155 return ((BasicFrame*)GetpApp()->GetAppWindow())->GenRealString( aResString );
158 void MyBasic::LoadIniFile()
162 SbTextType MyBasic::GetSymbolType( const String &rSymbol, BOOL bWasTTControl )
164 (void) rSymbol; /* avoid warning about unused parameter */
165 (void) bWasTTControl; /* avoid warning about unused parameter */
166 return SB_SYMBOL; // Everything here is of type SB_SYMBOL and continues to be so
170 MyBasic::~MyBasic()
172 aErrors.Clear();
173 if( !--nInst )
175 RemoveFactory( &aFac1 );
176 RemoveFactory( &aFac2 );
177 RemoveFactory( &aProcessFac );
181 void MyBasic::Reset()
183 aErrors.Clear();
184 nError = 0;
187 BOOL MyBasic::Compile( SbModule* p )
189 Reset();
190 return StarBASIC::Compile( p );
193 BOOL MyBasic::ErrorHdl()
195 AppBasEd* pWin = aBasicApp.pFrame->FindModuleWin( GetActiveModule()->GetName() );
196 if( !pWin )
197 { // open a window
198 pWin = aBasicApp.pFrame->CreateModuleWin( GetActiveModule() );
200 else
201 pWin->ToTop();
202 if( IsCompilerError() )
204 aErrors.Insert(
205 new BasicError
206 ( pWin,
207 0, StarBASIC::GetErrorText(), GetLine(), GetCol1(), GetCol2() ),
208 LIST_APPEND );
209 nError++;
210 return BOOL( nError < 20 ); // Cancel after 20 errors
212 else
214 ReportRuntimeError( pWin );
215 return FALSE;
219 void MyBasic::ReportRuntimeError( AppBasEd *pEditWin )
221 String nErrorText;
222 nErrorText = GetSpechialErrorText();
224 if ( pEditWin ) // just in case the focus is not right
225 pEditWin->ToTop();
227 BasicError( pEditWin,
228 GetVBErrorCode( GetErrorCode() ), nErrorText, GetLine(),
229 GetCol1(), GetCol2() ).Show();
232 void MyBasic::DebugFindNoErrors( BOOL bDebugFindNoErrors )
234 (void) bDebugFindNoErrors; /* avoid warning about unused parameter */
237 const String MyBasic::GetSpechialErrorText()
239 return GetErrorText();
242 USHORT MyBasic::BreakHdl()
244 SbModule* pMod = GetActiveModule();
245 if( pMod )
247 AppBasEd* pWin = aBasicApp.pFrame->FindModuleWin( pMod->GetName() );
248 if( !pWin )
249 { // open a window
250 pWin = aBasicApp.pFrame->CreateModuleWin( pMod );
252 else
253 pWin->ToTop();
254 pWin->Highlight( GetLine(), GetCol1(), GetCol2() );
257 if( IsBreak() ) // If Breakpoint (or "Run to Cursor")
259 // if ( GetActiveModule()->IsBP(GetLine()) )
260 // GetActiveModule()->ClearBP(GetLine());
261 return aBasicApp.pFrame->BreakHandler();
263 else
265 return aBasicApp.pFrame->BreakHandler();
269 /***************************************************************************
271 |* class BasicError
273 ***************************************************************************/
275 BasicError::BasicError
276 ( AppBasEd* w, USHORT nE, const String& r, USHORT nL, USHORT nC1, USHORT nC2 )
277 : aText( SttResId( IDS_ERROR1 ) )
279 pWin = w;
280 nLine = nL;
281 nCol1 = nC1;
282 nCol2 = nC2;
283 if( nE )
285 aText += String::CreateFromInt32( nE );
286 aText.AppendAscii(": ");
287 aText += r;
289 else
290 aText = r;
293 // This is a sample how to build the error information
294 // to highlight a statement
295 void BasicError::Show()
297 if( pWin && aBasicApp.pFrame->IsWinValid( pWin ) )
299 pWin->Highlight( nLine, nCol1, nCol2 );
300 aBasicApp.pFrame->pStatus->Message( aText );
302 else
303 MessBox( aBasicApp.pFrame, WB_OK, aBasicApp.pFrame->GetText(),
304 aText ).Execute();