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: appbased.cxx,v $
10 * $Revision: 1.13.20.1 $
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>
38 #include <svtools/texteng.hxx>
39 #include <svtools/textview.hxx>
40 #include <basic/sbmeth.hxx>
41 #include <svtools/stringtransfer.hxx>
43 #ifndef _BASIC_TTRESHLP_HXX
44 #include <basic/ttstrhlp.hxx>
49 #include "appbased.hxx"
50 #include "brkpnts.hxx"
51 #include <basic/testtool.hxx> // defines for Syntaxhighlighting
55 TYPEINIT1(AppBasEd
,AppEdit
);
56 AppBasEd::AppBasEd( BasicFrame
* pParent
, SbModule
* p
)
58 , pBreakpoints( NULL
)
60 pBreakpoints
= new BreakpointWindow( this );
61 pBreakpoints
->SetFont( ((TextEdit
*)pDataEdit
)->GetTextEditImp().pTextEngine
->GetFont() );
66 ((TextEdit
*)pDataEdit
)->GetTextEditImp().pTextView
->SetAutoIndentMode( TRUE
);
67 ((TextEdit
*)pDataEdit
)->GetTextEditImp().pTextEngine
->SetMaxTextLen( STRING_MAXLEN
);
68 // ((TextEdit*)pDataEdit)->GetTextEditImp().pTextEngine->SetWordDelimiters( CUniString(" ,.;:(){}[]\"'+-*/<>^\\") );
69 ((TextEdit
*)pDataEdit
)->GetTextEditImp().SyntaxHighlight( TRUE
);
70 ((TextEdit
*)pDataEdit
)->SaveAsUTF8( TRUE
);
77 String aModName
= *pNoName
;
78 aModName
+= String::CreateFromInt32( nCount
);
79 pMod
= pFrame
->Basic().MakeModule( aModName
, aEmpty
);
81 bCompiled
= pMod
->IsCompiled();
83 pBreakpoints
->SetModule( pMod
);
86 // pIcon = new Icon( ResId( RID_WORKICON ) );
87 // if( pIcon ) SetIcon( *pIcon );
89 SetText( pMod
->GetName() );
90 pDataEdit
->SetText( pMod
->GetSource() );
92 // If a module was given, load the source from harddisk
96 // Dispatch event AFTER loading the sourcecode
97 ((TextEdit
*)pDataEdit
)->SetBreakpointWindow( pBreakpoints
);
100 pDataEdit
->SetModifyHdl( LINK( this, AppBasEd
, EditChange
) );
104 AppBasEd::~AppBasEd()
106 pBreakpoints
->SaveBreakpoints( GetText() );
108 pMod
->SetName( CUniString("--").Append( pMod
->GetName() ) );
111 void AppBasEd::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
113 const SfxSimpleHint
* p
= PTR_CAST(SfxSimpleHint
,&rHint
);
116 ULONG nHintId
= p
->GetId();
117 if( nHintId
== SBX_HINT_LANGUAGE_EXTENSION_LOADED
)
119 ((TextEdit
*)pDataEdit
)->GetTextEditImp().InvalidateSyntaxHighlight();
124 FileType
AppBasEd::GetFileType()
126 return FT_BASIC_SOURCE
;
129 IMPL_LINK_INLINE_START( AppBasEd
, EditChange
, void *, p
)
131 (void) p
; /* avoid warning about unused parameter */
135 IMPL_LINK_INLINE_END( AppBasEd
, EditChange
, void *, p
)
138 long AppBasEd::InitMenu( Menu
* pMenu
)
140 AppEdit::InitMenu (pMenu
);
141 BOOL bRunning
= pFrame
->Basic().IsRunning();
142 pMenu
->EnableItem( RID_RUNCOMPILE
, !bCompiled
&& !bRunning
);
146 long AppBasEd::DeInitMenu( Menu
* pMenu
)
148 AppEdit::DeInitMenu (pMenu
);
149 pMenu
->EnableItem( RID_RUNCOMPILE
);
154 void AppBasEd::Command( const CommandEvent
& rCEvt
)
156 switch( rCEvt
.GetCommand() ) {
157 case RID_TOGLEBRKPNT
:
158 ((TextEdit
*)pDataEdit
)->GetBreakpointWindow()->ToggleBreakpoint( pDataEdit
->GetLineNr() );
161 AppEdit::Command( rCEvt
);
165 void AppBasEd::Resize()
171 // Insert breakpoint window
172 Size aEditSize
= pDataEdit
->GetSizePixel();
173 Point aEditPos
= pDataEdit
->GetPosPixel();
175 pBreakpoints
->SetPosPixel( aEditPos
);
177 aEditPos
.X() += BREAKPOINTSWIDTH
;
178 pDataEdit
->SetPosPixel( aEditPos
);
179 aEditSize
.Width() -= BREAKPOINTSWIDTH
;
180 pDataEdit
->SetSizePixel( aEditSize
);
182 aEditSize
.Width() = BREAKPOINTSWIDTH
;
183 pBreakpoints
->SetSizePixel( aEditSize
);
187 void AppBasEd::PostLoad()
189 pMod
->SetName( GetText() );
191 pMod
->SetSource( pDataEdit
->GetText() );
192 bCompiled
= FALSE
; // because the code might have changed in the meantime
195 pBreakpoints
->LoadBreakpoints( GetText() );
198 USHORT
AppBasEd::ImplSave()
200 pBreakpoints
->SaveBreakpoints( GetText() );
201 return AppEdit::ImplSave();
204 void AppBasEd::Reload()
206 TextSelection aSelMemo
= pDataEdit
->GetSelection();
208 pDataEdit
->SetSelection( aSelMemo
);
211 // Reload source code file after change
212 void AppBasEd::LoadSource()
216 // if( pDataEdit->GetText().Len() != 0 ) return;
217 String aName
= pMod
->GetName();
218 bErr
= !pDataEdit
->Load( aName
);
219 pBreakpoints
->LoadBreakpoints( GetText() );
221 ErrorBox( this, SttResId( IDS_READERROR
) ).Execute();
223 UpdateFileInfo( HAS_BEEN_LOADED
);
224 bCompiled
= FALSE
; // because the code might have changed in the meantime
227 // Save as (new name)
228 void AppBasEd::PostSaveAs()
230 pMod
->SetName( GetText() );
231 AppEdit::PostSaveAs();
235 BOOL
AppBasEd::Compile()
237 if( !pDataEdit
->HasText() || bCompiled
)
239 pMod
->SetSource( pDataEdit
->GetText() );
241 if( pFrame
->Basic().Compile( pMod
) )
246 TextSelection
aSel( pDataEdit
->GetSelection() );
248 pFrame
->pStatus
->Message( aString
);
249 if( aSel
.HasRange() )
250 aSel
.GetStart() = aSel
.GetEnd(), pDataEdit
->SetSelection( aSel
);
252 pBreakpoints
->SetBPsInModule();
256 BasicError
* pErr
= pFrame
->Basic().aErrors
.First();
257 if( pErr
) pErr
->Show();
259 return bCompiled
= bRes
;
262 void AppBasEd::Disassemble()
265 if( pFrame
->Basic().Disassemble( pMod
, aText
) )
266 ::svt::OStringTransfer::CopyString( aText
, this );
271 pFrame
->Basic().Reset();
272 SbxArray
* pAllModules
= pFrame
->Basic().GetModules();
273 for (USHORT i
= 0; i
< pAllModules
->Count(); i
++)
275 if ( (pAllModules
->Get(i
)->GetName()).Copy(0,2).CompareToAscii( "--" ) == COMPARE_EQUAL
)
277 // Little hack to get around basic
278 SbxVariableRef pRMod
= pAllModules
->Get(i
);
279 pFrame
->Basic().Remove(pRMod
);
284 SbMethod
* pMain
= (SbMethod
*) pMod
->Find( CUniString("Main"), SbxCLASS_METHOD
);
287 pMain
->SetDebugFlags( pFrame
->nFlags
);
289 pFrame
->SetAppMode( String( SttResId( IDS_APPMODE_RUN
) ) );
291 if (aBasicApp
.pFrame
)
293 BasicError
* pErr
= aBasicApp
.pFrame
->Basic().aErrors
.First();
296 aBasicApp
.pFrame
->SetAppMode( String() );
298 pMain
->SetDebugFlags( 0 );