1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mybasic.cxx,v $
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>
37 #include <basic/sbx.hxx>
43 #include <usr/uno.hxx>
45 #include <basic/sbuno.hxx>
46 #include <sbunoobj.hxx>
49 #include "sbintern.hxx"
51 #ifndef _BASIC_TTRESHLP_HXX
52 #include <basic/ttstrhlp.hxx>
54 #include <basic/mybasic.hxx>
56 #include "appbased.hxx"
63 #include "processw.hxx"
66 TYPEINIT1(MyBasic
,StarBASIC
)
68 class MyFactory
: public SbxFactory
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
)
87 MyBasic::MyBasic() : StarBASIC()
94 AddFactory( &aProcessFac
);
96 SbxVariable
* p
= new SbxCollection( CUniString("MyColl") );
97 p
->SetName( CUniString("Objects") );
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
);
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
175 RemoveFactory( &aFac1
);
176 RemoveFactory( &aFac2
);
177 RemoveFactory( &aProcessFac
);
181 void MyBasic::Reset()
187 BOOL
MyBasic::Compile( SbModule
* p
)
190 return StarBASIC::Compile( p
);
193 BOOL
MyBasic::ErrorHdl()
195 AppBasEd
* pWin
= aBasicApp
.pFrame
->FindModuleWin( GetActiveModule()->GetName() );
198 pWin
= aBasicApp
.pFrame
->CreateModuleWin( GetActiveModule() );
202 if( IsCompilerError() )
207 0, StarBASIC::GetErrorText(), GetLine(), GetCol1(), GetCol2() ),
210 return BOOL( nError
< 20 ); // Cancel after 20 errors
214 ReportRuntimeError( pWin
);
219 void MyBasic::ReportRuntimeError( AppBasEd
*pEditWin
)
222 nErrorText
= GetSpechialErrorText();
224 if ( pEditWin
) // just in case the focus is not right
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();
247 AppBasEd
* pWin
= aBasicApp
.pFrame
->FindModuleWin( pMod
->GetName() );
250 pWin
= aBasicApp
.pFrame
->CreateModuleWin( pMod
);
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();
265 return aBasicApp
.pFrame
->BreakHandler();
269 /***************************************************************************
273 ***************************************************************************/
275 BasicError::BasicError
276 ( AppBasEd
* w
, USHORT nE
, const String
& r
, USHORT nL
, USHORT nC1
, USHORT nC2
)
277 : aText( SttResId( IDS_ERROR1
) )
285 aText
+= String::CreateFromInt32( nE
);
286 aText
.AppendAscii(": ");
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
);
303 MessBox( aBasicApp
.pFrame
, WB_OK
, aBasicApp
.pFrame
->GetText(),