Files
libreoffice/basic/source/app/appbased.cxx
Rüdiger Timm e9433641f5 INTEGRATION: CWS residcleanup (1.10.62); FILE MERGED
2007/02/18 21:06:55 pl 1.10.62.1: #i74635# get rid of implicit global ResMgr
2007-04-26 07:31:20 +00:00

321 lines
8.6 KiB
C++
Raw Blame History

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: appbased.cxx,v $
*
* $Revision: 1.11 $
*
* last change: $Author: rt $ $Date: 2007-04-26 08:31:09 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basic.hxx"
#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SBXCLASS_HXX //autogen
#include <sbx.hxx>
#endif
#ifndef _TEXTENG_HXX //autogen
#include <svtools/texteng.hxx>
#endif
#ifndef _TEXTVIEW_HXX //autogen
#include <svtools/textview.hxx>
#endif
#ifndef _SB_SBMETH_HXX //autogen
#include <sbmeth.hxx>
#endif
#ifndef _SVTOOLS_STRINGTRANSFER_HXX_
#include <svtools/stringtransfer.hxx>
#endif
#ifndef _BASIC_TTRESHLP_HXX
#include "ttstrhlp.hxx"
#endif
#include "basic.hrc"
#include "status.hxx"
#include "appbased.hxx"
#include "brkpnts.hxx"
#include "testtool.hxx" // defines f<>r das Syntaxhighlighting
#include "basrid.hxx"
TYPEINIT1(AppBasEd,AppEdit);
AppBasEd::AppBasEd( BasicFrame* pParent, SbModule* p )
: AppEdit( pParent )
, pBreakpoints( NULL )
{
pBreakpoints = new BreakpointWindow( this );
pBreakpoints->SetFont( ((TextEdit*)pDataEdit)->GetTextEditImp().pTextEngine->GetFont() );
pBreakpoints->Show();
((TextEdit*)pDataEdit)->GetTextEditImp().pTextView->SetAutoIndentMode( TRUE );
((TextEdit*)pDataEdit)->GetTextEditImp().pTextEngine->SetMaxTextLen( STRING_MAXLEN );
// ((TextEdit*)pDataEdit)->GetTextEditImp().pTextEngine->SetWordDelimiters( CUniString(" ,.;:(){}[]\"'+-*/<>^\\") );
((TextEdit*)pDataEdit)->GetTextEditImp().SyntaxHighlight( TRUE );
((TextEdit*)pDataEdit)->SaveAsUTF8( TRUE );
String aEmpty;
pMod = p;
if( !pMod )
{
String aModName = *pNoName;
aModName += String::CreateFromInt32( nCount );
pMod = pFrame->Basic().MakeModule( aModName, aEmpty );
}
bCompiled = pMod->IsCompiled();
pBreakpoints->SetModule( pMod );
// Icon definieren:
// pIcon = new Icon( ResId( RID_WORKICON ) );
// if( pIcon ) SetIcon( *pIcon );
SetText( pMod->GetName() );
pDataEdit->SetText( pMod->GetSource() );
// Wurde ein Modul <20>bergeben, dann den Quelltext von Platte laden
if ( p )
LoadSource();
// Erst nach Laden des Quelltextes die Events weiterleiten
((TextEdit*)pDataEdit)->SetBreakpointWindow( pBreakpoints );
// Compiled-Flag pflegen:
pDataEdit->SetModifyHdl( LINK( this, AppBasEd, EditChange ) );
}
AppBasEd::~AppBasEd()
{
pBreakpoints->SaveBreakpoints( GetText() );
delete pBreakpoints;
pMod->SetName( CUniString("--").Append( pMod->GetName() ) );
}
void AppBasEd::SFX_NOTIFY( SfxBroadcaster&, const TypeId&,
const SfxHint& rHint, const TypeId& )
{
const SfxSimpleHint* p = PTR_CAST(SfxSimpleHint,&rHint);
if( p )
{
ULONG nHintId = p->GetId();
if( nHintId == SBX_HINT_LANGUAGE_EXTENSION_LOADED )
{
((TextEdit*)pDataEdit)->GetTextEditImp().InvalidateSyntaxHighlight();
}
}
}
FileType AppBasEd::GetFileType()
{
return FT_BASIC_SOURCE;
}
IMPL_LINK_INLINE_START( AppBasEd, EditChange, void *, p )
{
(void) p; /* avoid warning about unused parameter */
bCompiled = FALSE;
return TRUE;
}
IMPL_LINK_INLINE_END( AppBasEd, EditChange, void *, p )
// Set up the menu
long AppBasEd::InitMenu( Menu* pMenu )
{
AppEdit::InitMenu (pMenu );
BOOL bRunning = pFrame->Basic().IsRunning();
pMenu->EnableItem( RID_RUNCOMPILE, !bCompiled && !bRunning );
return TRUE;
}
long AppBasEd::DeInitMenu( Menu* pMenu )
{
AppEdit::DeInitMenu (pMenu );
pMenu->EnableItem( RID_RUNCOMPILE );
return TRUE;
}
// Menu Handler
void AppBasEd::Command( const CommandEvent& rCEvt )
{
switch( rCEvt.GetCommand() ) {
case RID_TOGLEBRKPNT:
((TextEdit*)pDataEdit)->GetBreakpointWindow()->ToggleBreakpoint( pDataEdit->GetLineNr() );
break;
default:
AppEdit::Command( rCEvt );
}
}
// Sourcecode-Datei laden
void AppBasEd::Resize()
{
if( pDataEdit ) {
AppEdit::Resize();
// Breakpoint window einf<6E>gen
Size aEditSize = pDataEdit->GetSizePixel();
Point aEditPos = pDataEdit->GetPosPixel();
pBreakpoints->SetPosPixel( aEditPos );
aEditPos.X() += BREAKPOINTSWIDTH;
pDataEdit->SetPosPixel( aEditPos );
aEditSize.Width() -= BREAKPOINTSWIDTH;
pDataEdit->SetSizePixel( aEditSize );
aEditSize.Width() = BREAKPOINTSWIDTH;
pBreakpoints->SetSizePixel( aEditSize );
}
}
void AppBasEd::PostLoad()
{
pMod->SetName( GetText() );
pMod->Clear();
pMod->SetSource( pDataEdit->GetText() );
bCompiled = FALSE; // because the code might have changed in the meantime
AppEdit::PostLoad();
pBreakpoints->LoadBreakpoints( GetText() );
}
USHORT AppBasEd::ImplSave()
{
pBreakpoints->SaveBreakpoints( GetText() );
return AppEdit::ImplSave();
}
void AppBasEd::Reload()
{
TextSelection aSelMemo = pDataEdit->GetSelection();
LoadSource();
pDataEdit->SetSelection( aSelMemo );
}
// Sourcecode-Datei nach <20>nderung auf Platte neu laden
void AppBasEd::LoadSource()
{
BOOL bErr;
// if( pDataEdit->GetText().Len() != 0 ) return;
String aName = pMod->GetName();
bErr = !pDataEdit->Load( aName );
pBreakpoints->LoadBreakpoints( GetText() );
if( bErr )
ErrorBox( this, SttResId( IDS_READERROR ) ).Execute();
else
UpdateFileInfo( HAS_BEEN_LOADED );
bCompiled = FALSE; // because the code might have changed in the meantime
}
// mit neuem Namen speichern
void AppBasEd::PostSaveAs()
{
pMod->SetName( GetText() );
AppEdit::PostSaveAs();
}
// Compilieren
BOOL AppBasEd::Compile()
{
if( !pDataEdit->HasText() || bCompiled )
return TRUE;
pMod->SetSource( pDataEdit->GetText() );
BOOL bRes = FALSE;
if( pFrame->Basic().Compile( pMod ) )
{
bRes = TRUE;
if( pFrame->bDisas )
Disassemble();
TextSelection aSel( pDataEdit->GetSelection() );
String aString;
pFrame->pStatus->Message( aString );
if( aSel.HasRange() )
aSel.GetStart() = aSel.GetEnd(), pDataEdit->SetSelection( aSel );
pBreakpoints->SetBPsInModule();
}
else
{
BasicError* pErr = pFrame->Basic().aErrors.First();
if( pErr ) pErr->Show();
}
return bCompiled = bRes;
}
void AppBasEd::Disassemble()
{
String aText;
if( pFrame->Basic().Disassemble( pMod, aText ) )
::svt::OStringTransfer::CopyString( aText, this );
}
void AppBasEd::Run()
{
pFrame->Basic().Reset();
SbxArray* pAllModules = pFrame->Basic().GetModules();
for (USHORT i = 0; i < pAllModules->Count(); i++)
{
if ( (pAllModules->Get(i)->GetName()).Copy(0,2).CompareToAscii( "--" ) == COMPARE_EQUAL )
{
SbxVariableRef pRMod = pAllModules->Get(i); // Kleiner Hack um ums basic rumzukommen. Sollte demn<6D>chst wieder dirkt gehen.
pFrame->Basic().Remove(pRMod);
i--;
}
}
SbMethod* pMain = (SbMethod*) pMod->Find( CUniString("Main"), SbxCLASS_METHOD );
if( pMain )
{
pMain->SetDebugFlags( pFrame->nFlags );
// Loest Call aus!
pFrame->SetAppMode( String( SttResId( IDS_APPMODE_RUN ) ) );
pMain->Run();
if (aBasicApp.pFrame)
{
BasicError* pErr = aBasicApp.pFrame->Basic().aErrors.First();
if( pErr ) pErr->Show();
aBasicApp.pFrame->SetAppMode( String() );
}
pMain->SetDebugFlags( 0 );
}
}