merge the formfield patch from ooo-build
[ooovba.git] / basic / source / app / app.cxx
blob00a7877fcf06d9791b927426a9dfbf11440ae051
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: app.cxx,v $
10 * $Revision: 1.79.14.2 $
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 <tools/fsys.hxx>
38 #ifndef _SV_FILEDLG_HXX //autogen
39 #include <svtools/filedlg.hxx>
40 #endif
41 #include <tools/config.hxx>
43 #include <vcl/font.hxx>
45 #ifndef _BASIC_TTRESHLP_HXX
46 #include <basic/ttstrhlp.hxx>
47 #endif
48 #include <basic/sbx.hxx>
49 #include <svtools/filedlg.hxx>
51 #include <osl/module.h>
53 #include "basic.hrc"
54 #include "app.hxx"
55 #include "printer.hxx"
56 #include "status.hxx"
57 #include "appedit.hxx"
58 #include "appbased.hxx"
59 #include "apperror.hxx"
60 #include <basic/mybasic.hxx>
61 #include "ttbasic.hxx"
62 #include "dialogs.hxx"
63 #include <basic/basrdll.hxx>
64 #include "basrid.hxx"
66 #ifndef _RUNTIME_HXX
67 #include "runtime.hxx"
68 #endif
69 #include "sbintern.hxx"
71 #ifdef _USE_UNO
72 #include <ucbhelper/contentbroker.hxx>
73 #include <ucbhelper/configurationkeys.hxx>
74 #include <comphelper/regpathhelper.hxx>
75 #include <comphelper/processfactory.hxx>
76 #include <com/sun/star/beans/PropertyValue.hpp>
77 #include <com/sun/star/lang/XComponent.hpp>
78 #include <cppuhelper/bootstrap.hxx>
79 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
80 #include <com/sun/star/ucb/XContentProviderManager.hpp>
82 #include <ucbhelper/content.hxx>
83 #include <svtools/syslocale.hxx>
85 using namespace comphelper;
86 using namespace cppu;
87 using namespace rtl;
88 using namespace com::sun::star;
89 using namespace com::sun::star::uno;
90 using namespace com::sun::star::lang;
91 using namespace com::sun::star::ucb;
92 using namespace com::sun::star::beans;
94 #endif /* _USE_UNO */
96 IMPL_GEN_RES_STR;
98 #ifdef DBG_UTIL
99 // filter Messages generated due to missing configuration Bug:#83887#
100 void TestToolDebugMessageFilter( const sal_Char *pString, BOOL bIsOsl )
102 static BOOL static_bInsideFilter = FALSE;
104 // Ignore messages during filtering to avoid endless recursions
105 if ( static_bInsideFilter )
106 return;
108 static_bInsideFilter = TRUE;
110 ByteString aMessage( pString );
112 BOOL bIgnore = FALSE;
114 if ( bIsOsl )
116 // OSL
117 if ( aMessage.Search( CByteString("Cannot open Configuration: Connector: unknown delegatee com.sun.star.connection.Connector.portal") ) != STRING_NOTFOUND )
118 bIgnore = TRUE;
120 else
122 // DBG
123 #if ! (OSL_DEBUG_LEVEL > 1)
124 if ( aMessage.Search( CByteString("SelectAppIconPixmap") ) != STRING_NOTFOUND )
125 bIgnore = TRUE;
126 #endif
127 if ( aMessage.Search( CByteString("PropertySetRegistry::") ) != STRING_NOTFOUND )
128 bIgnore = TRUE;
129 if ( aMessage.Search( CByteString("property value missing") ) != STRING_NOTFOUND )
130 bIgnore = TRUE;
131 if ( aMessage.Search( CByteString("getDateFormatsImpl") ) != STRING_NOTFOUND
132 && aMessage.Search( CByteString("no date formats") ) != STRING_NOTFOUND )
133 bIgnore = TRUE;
134 if ( aMessage.Search( CByteString("ucb::configureUcb(): Bad arguments") ) != STRING_NOTFOUND )
135 bIgnore = TRUE;
136 if ( aMessage.Search( CByteString("CreateInstance with arguments exception") ) != STRING_NOTFOUND )
137 bIgnore = TRUE;
138 if ( aMessage.Search( CByteString("AcquireTree failed") ) != STRING_NOTFOUND )
139 bIgnore = TRUE;
143 if ( bIgnore )
145 static_bInsideFilter = FALSE;
146 return;
149 if ( bIsOsl )
151 // due to issue #i36895 only print on console
152 // unfortunately the osl assertions deadlock by design :-( on recursive calls of assertions
153 printf("%s\n", pString );
155 else
159 aBasicApp.DbgPrintMsgBox( pString );
161 catch ( ... )
164 printf("DbgPrintMsgBox failed: %s\n", pString );
167 /* DBG_INSTOUTERROR( DBG_OUT_MSGBOX )
168 DBG_ERROR( pString );
169 DBG_INSTOUTERROR( DBG_OUT_TESTTOOL )*/
170 static_bInsideFilter = FALSE;
172 void SAL_CALL DBG_TestToolDebugMessageFilter( const sal_Char *pString )
174 TestToolDebugMessageFilter( pString, FALSE );
176 extern "C" void SAL_CALL osl_TestToolDebugMessageFilter( const sal_Char *pString )
178 if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
179 TestToolDebugMessageFilter( pString, TRUE );
181 #endif
183 // #94145# Due to a tab in TT_SIGNATURE_FOR_UNICODE_TEXTFILES which is changed to blanks by some editors
184 // this routine became necessary
185 BOOL IsTTSignatureForUnicodeTextfile( String aLine )
187 aLine.SearchAndReplace( '\t', ' ' );
188 String ThreeBlanks = CUniString(" ");
189 String TwoBlanks = CUniString(" ");
190 while ( aLine.SearchAndReplace( ThreeBlanks, TwoBlanks ) != STRING_NOTFOUND )
192 return aLine.EqualsAscii( TT_SIGNATURE_FOR_UNICODE_TEXTFILES );
195 BasicApp aBasicApp; // Application instance
197 static const char * const components[] =
199 SAL_MODULENAME( "ucb1" ) // KSO, ABI
200 , SAL_MODULENAME( "ucpfile1" )
201 , "configmgr2.uno" SAL_DLLEXTENSION
202 , "sax.uno" SAL_DLLEXTENSION
203 , "stocservices.uno" SAL_DLLEXTENSION
204 , SAL_MODULENAME( "fileacc" )
205 , SAL_MODULENAME( "mcnttype" ) // Clipboard Ask Oliver Braun
206 , "i18npool.uno" SAL_DLLEXTENSION
207 // Reading of files in specific encodings like UTF-8 using
208 // createUnoService( "com.sun.star.io.TextInputStream" ) and such
209 , "textinstream.uno" SAL_DLLEXTENSION
210 , "textoutstream.uno" SAL_DLLEXTENSION
211 , "introspection.uno" SAL_DLLEXTENSION
212 , "reflection.uno" SAL_DLLEXTENSION
213 // RemoteUno
214 , "connector.uno" SAL_DLLEXTENSION
215 , "bridgefac.uno" SAL_DLLEXTENSION
216 , "remotebridge.uno" SAL_DLLEXTENSION
217 #ifdef SAL_UNX
218 #ifdef QUARTZ
219 , SVLIBRARY( "dtransaqua" ) // Mac OS X Aqua uses a dedicated libdtransaqua
220 #else
221 , SVLIBRARY( "dtransX11" ) // OBR
222 #endif
223 #endif
224 #ifdef SAL_W32
225 , SAL_MODULENAME( "sysdtrans" )
226 , SAL_MODULENAME( "ftransl" )
227 , SAL_MODULENAME( "dnd" )
228 #endif
232 uno::Reference< XContentProviderManager > InitializeUCB( void )
234 uno::Reference< XMultiServiceFactory > xSMgr;
237 xSMgr = uno::Reference< XMultiServiceFactory >(
238 defaultBootstrap_InitialComponentContext()->getServiceManager(),
239 UNO_QUERY_THROW);
241 catch( com::sun::star::uno::Exception & exc )
243 fprintf( stderr, "Couldn't bootstrap uno servicemanager for reason : %s\n" ,
244 OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
245 InfoBox( NULL, String( exc.Message ) ).Execute();
246 throw ;
250 //////////////////////////////////////////////////////////////////////
251 // set global factory
252 setProcessServiceFactory( xSMgr );
254 /* // Create simple ConfigManager
255 Sequence< Any > aConfArgs(3);
256 aConfArgs[0] <<= PropertyValue( OUString::createFromAscii("servertype"), 0, makeAny( OUString::createFromAscii("local") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
257 aConfArgs[1] <<= PropertyValue( OUString::createFromAscii("sourcepath"), 0, makeAny( OUString::createFromAscii("g:\\") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
258 aConfArgs[2] <<= PropertyValue( OUString::createFromAscii("updatepath"), 0, makeAny( OUString::createFromAscii("g:\\") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
260 uno::Reference< XContentProvider > xConfProvider
261 ( xSMgr->createInstanceWithArguments( OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ), aConfArgs), UNO_QUERY );
265 // Create unconfigured Ucb:
266 /* Sequence< Any > aArgs(1);
267 aArgs[1] = makeAny ( xConfProvider );*/
268 Sequence< Any > aArgs;
269 ::ucbhelper::ContentBroker::initialize( xSMgr, aArgs );
270 uno::Reference< XContentProviderManager > xUcb =
271 ::ucbhelper::ContentBroker::get()->getContentProviderManagerInterface();
273 uno::Reference< XContentProvider > xFileProvider
274 ( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ) ), UNO_QUERY );
275 xUcb->registerContentProvider( xFileProvider, OUString::createFromAscii( "file" ), sal_True );
278 /* uno::Reference< XContentProvider > xPackageProvider
279 ( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.ucb.PackageContentProvider" ) ), UNO_QUERY );
280 xUcb->registerContentProvider( xPackageProvider, OUString::createFromAscii( "vnd.sun.star.pkg" ), sal_True );
283 return xUcb;
286 static void ReplaceStringHookProc( UniString& rStr )
288 static String aTestToolName( RTL_CONSTASCII_USTRINGPARAM( "VCLTestTool" ) ); // HACK, should be read from ressources
290 if ( rStr.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND )
292 rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", aTestToolName );
294 rStr.SearchAndReplaceAllAscii( "%PRODUCTVERSION", rVersion );
295 rStr.SearchAndReplaceAllAscii( "%ABOUTBOXPRODUCTVERSION", rAboutBoxVersion );
296 rStr.SearchAndReplaceAllAscii( "%PRODUCTEXTENSION", rExtension );
297 rStr.SearchAndReplaceAllAscii( "%PRODUCTXMLFILEFORMATNAME", rXMLFileFormatName );
298 rStr.SearchAndReplaceAllAscii( "%PRODUCTXMLFILEFORMATVERSION", rXMLFileFormatVersion );
303 void BasicApp::Main( )
305 #ifdef DBG_UTIL
306 // Install filter for OSLAsserts
307 DbgPrintMsgBox = DbgGetPrintMsgBox();
308 DbgSetPrintTestTool( DBG_TestToolDebugMessageFilter );
309 DBG_INSTOUTERROR( DBG_OUT_TESTTOOL );
311 if ( osl_setDebugMessageFunc( osl_TestToolDebugMessageFilter ) )
312 DBG_ERROR("osl_setDebugMessageFunc returns non NULL pointer");
313 #endif
315 ResMgr::SetReadStringHook( ReplaceStringHookProc );
319 #ifdef _USE_UNO
320 uno::Reference< XContentProviderManager > xUcb = InitializeUCB();
321 #endif
324 DirEntry aIniPath( Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ) );
325 if ( !aIniPath.Exists() )
326 { // look for it besides the executable
327 DirEntry aAppFileName( GetAppFileName() );
328 String aAppDir ( aAppFileName.GetPath().GetFull() );
330 // DirEntry aDefIniPath( Config::GetConfigName( aAppDir, CUniString("testtool") ) );
331 // Do not use Config::GetConfigName here because is uses a hidden file for UNIX
333 DirEntry aDefIniPath( aAppDir );
334 ByteString aFileName;
335 #ifdef UNX
336 aFileName = "testtoolrc";
337 #else
338 aFileName = "testtool.ini";
339 #endif
340 aDefIniPath += DirEntry( aFileName );
342 if ( aDefIniPath.Exists() )
344 aDefIniPath.CopyTo( aIniPath, FSYS_ACTION_COPYFILE );
345 FileStat::SetReadOnlyFlag( aIniPath, FALSE );
351 LanguageType aRequestedLanguage;
352 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
354 // 1033 = LANGUAGE_ENGLISH_US
355 // 1031 = LANGUAGE_GERMAN
356 aConf.SetGroup("Misc");
357 ByteString aLang = aConf.ReadKey( "Language", ByteString::CreateFromInt32( LANGUAGE_SYSTEM ) );
358 aRequestedLanguage = LanguageType( aLang.ToInt32() );
360 AllSettings aSettings = GetSettings();
361 aSettings.SetUILanguage( aRequestedLanguage );
362 aSettings.SetLanguage( aRequestedLanguage );
363 // International aInternational;
364 // aInternational = GetSettings().GetInternational();
365 // aInternational = International( aRequestedLanguage );
366 // aSettings.SetInternational( aInternational );
367 SetSettings( aSettings );
368 // aInternational = GetSettings().GetInternational();
371 // ResMgr::CreateResMgr( CREATEVERSIONRESMGR( stt ), )
372 //const char* ResMgr::GetLang( LanguageType& nType, USHORT nPrio )
374 // ResMgr::CreateResMgr( CREATEVERSIONRESMGR( stt )
375 // ResMgr *pRes = new ResMgr( "testtool.res" );
376 // Resource::SetResManager( pRes );
378 BasicDLL aBasicDLL;
379 nWait = 0;
381 // Hilfe:
382 // pHelp = new Help;
383 // SetHelp( pHelp );
384 // Help::EnableContextHelp();
385 // Help::EnableExtHelp();
386 // DeactivateExtHelp();
388 // Acceleratoren
389 Accelerator aAccel( SttResId( MAIN_ACCEL ) );
390 InsertAccel( &aAccel );
391 pMainAccel = &aAccel;
393 // Frame Window:
394 pFrame = new BasicFrame;
395 aAccel.SetSelectHdl( LINK( pFrame, BasicFrame, Accel ) );
397 pFrame->Show();
399 SetSystemWindowMode( SYSTEMWINDOW_MODE_NOAUTOMODE );
400 SetSystemWindowMode( SYSTEMWINDOW_MODE_DIALOG );
402 // Instantiate a SvtSysLocale to avoid permant instatiation
403 // and deletion of SvtSysLocale_Impl in SvtSysLocale Ctor/Dtor
404 // because in the testtool szenario Basic is the only instance
405 // instatiating SvtSysLocale (#107417).
406 SvtSysLocale aSysLocale;
408 PostUserEvent( LINK( this, BasicApp, LateInit ) );
409 Execute();
411 // delete pHelp;
412 delete pFrame;
414 RemoveAccel( pMainAccel );
417 catch( class Exception & rEx)
419 printf( "Exception not caught: %s\n", ByteString( String(rEx.Message), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
420 String aMsg( String::CreateFromAscii( "Exception not caught: " ) );
421 aMsg.Append( String( rEx.Message ) );
422 InfoBox( NULL, aMsg ).Execute();
423 throw;
425 catch( ... )
427 printf( "unknown Exception not caught\n" );
428 InfoBox( NULL, String::CreateFromAscii( "unknown Exception not caught" ) ).Execute();
429 throw;
433 void BasicApp::LoadIniFile()
435 pFrame->LoadIniFile();
438 void BasicApp::SetFocus()
440 if( pFrame->pWork && pFrame->pWork->ISA(AppEdit) )
441 ((AppEdit*)pFrame->pWork)->pDataEdit->GrabFocus();
444 IMPL_LINK( BasicApp, LateInit, void *, pDummy )
446 (void) pDummy; /* avoid warning about unused parameter */
447 USHORT i;
448 for ( i = 0 ; i < Application::GetCommandLineParamCount() ; i++ )
450 if ( Application::GetCommandLineParam( i ).Copy(0,4).CompareIgnoreCaseToAscii("-run") == COMPARE_EQUAL
451 #ifndef UNX
452 || Application::GetCommandLineParam( i ).Copy(0,4).CompareIgnoreCaseToAscii("/run") == COMPARE_EQUAL
453 #endif
455 pFrame->SetAutoRun( TRUE );
456 else if ( Application::GetCommandLineParam( i ).Copy(0,7).CompareIgnoreCaseToAscii("-result") == COMPARE_EQUAL
457 #ifndef UNX
458 || Application::GetCommandLineParam( i ).Copy(0,7).CompareIgnoreCaseToAscii("/result") == COMPARE_EQUAL
459 #endif
462 if ( (i+1) < Application::GetCommandLineParamCount() )
464 if ( ByteString( Application::GetCommandLineParam( i+1 ), osl_getThreadTextEncoding() ).IsNumericAscii() )
466 MsgEdit::SetMaxLogLen( sal::static_int_cast< USHORT >( Application::GetCommandLineParam( i+1 ).ToInt32() ) );
468 i++;
473 // now load the files after the switches have been set. Espechially -run is of interest sunce it changes the behavior
474 for ( i = 0 ; i < Application::GetCommandLineParamCount() ; i++ )
476 if ( Application::GetCommandLineParam( i ).Copy(0,1).CompareToAscii("-") != COMPARE_EQUAL
477 #ifndef UNX
478 && Application::GetCommandLineParam( i ).Copy(0,1).CompareToAscii("/") != COMPARE_EQUAL
479 #endif
482 pFrame->LoadFile( Application::GetCommandLineParam( i ) );
484 else if ( Application::GetCommandLineParam( i ).Copy(0,7).CompareIgnoreCaseToAscii("-result") == COMPARE_EQUAL
485 #ifndef UNX
486 || Application::GetCommandLineParam( i ).Copy(0,7).CompareIgnoreCaseToAscii("/result") == COMPARE_EQUAL
487 #endif
489 { // Increment count to skip the parameter. This works even if it is not given
490 i++;
494 pFrame->pStatus->SetStatusSize( pFrame->pStatus->GetStatusSize()+1 );
495 pFrame->pStatus->SetStatusSize( pFrame->pStatus->GetStatusSize()-1 );
497 if ( pFrame->IsAutoRun() )
499 pFrame->Command( RID_RUNSTART );
502 if ( pFrame->IsAutoRun() )
503 pFrame->Command( RID_QUIT );
505 return 0;
508 //////////////////////////////////////////////////////////////////////////
510 class FloatingExecutionStatus : public FloatingWindow
512 public:
513 FloatingExecutionStatus( Window * pParent );
514 void SetStatus( String aW );
515 void SetAdditionalInfo( String aF );
517 private:
518 Timer aAusblend;
519 DECL_LINK(HideNow, FloatingExecutionStatus* );
520 FixedText aStatus;
521 FixedText aAdditionalInfo;
525 FloatingExecutionStatus::FloatingExecutionStatus( Window * pParent )
526 : FloatingWindow( pParent, SttResId(LOAD_CONF) ),
527 aStatus( this, SttResId( WORK ) ),
528 aAdditionalInfo( this, SttResId( FILENAME ) )
530 FreeResource();
531 aAusblend.SetTimeoutHdl( LINK(this, FloatingExecutionStatus, HideNow ) );
532 aAusblend.SetTimeout(5000); // in ms
533 aAusblend.Start();
536 void FloatingExecutionStatus::SetStatus( String aW )
538 Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
539 ToTop( TOTOP_NOGRABFOCUS );
540 aAusblend.Start();
541 aStatus.SetText( aW );
544 void FloatingExecutionStatus::SetAdditionalInfo( String aF )
546 Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
547 ToTop( TOTOP_NOGRABFOCUS );
548 aAusblend.Start();
549 aAdditionalInfo.SetText( aF );
552 IMPL_LINK(FloatingExecutionStatus, HideNow, FloatingExecutionStatus*, pFLC )
554 (void) pFLC; /* avoid warning about unused parameter */
555 Hide();
556 return 0;
559 //////////////////////////////////////////////////////////////////////////
561 TYPEINIT1(TTExecutionStatusHint, SfxSimpleHint);
563 BasicFrame::BasicFrame() : WorkWindow( NULL,
564 WinBits( WB_APP | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) )
565 , bIsAutoRun( FALSE )
566 , pDisplayHidDlg( NULL )
567 , pEditVar ( 0 )
568 , bAutoReload( FALSE )
569 , bAutoSave( TRUE )
570 , pBasic( NULL )
571 , pExecutionStatus( NULL )
572 , pStatus( NULL )
573 , pList( NULL )
574 , pWork( NULL )
575 , pPrn( NULL )
578 Application::SetDefDialogParent( this );
579 AlwaysEnableInput( TRUE );
580 pBasic = TTBasic::CreateMyBasic(); // depending on what was linked to the executable
581 bInBreak = FALSE;
582 bDisas = FALSE;
583 nFlags = 0;
584 // Icon aAppIcon;
586 if ( pBasic->pTestObject ) // Are we the testtool?
588 // aAppIcon = Icon( ResId( RID_APPICON2 ) );
589 aAppName = String( SttResId( IDS_APPNAME2 ) );
591 else
593 // aAppIcon = Icon( ResId( RID_APPICON ) );
594 aAppName = String( SttResId( IDS_APPNAME ) );
597 // Menu:
598 MenuBar *pBar = new MenuBar( SttResId( RID_APPMENUBAR ) );
599 SetMenuBar( pBar );
601 pBar->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
604 // Menu Handler:
605 PopupMenu* pFileMenu = pBar->GetPopupMenu( RID_APPFILE );
606 pFileMenu->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
607 pFileMenu->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
608 pFileMenu->SetActivateHdl( LINK( this, BasicFrame, InitMenu ) );
609 pFileMenu->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
610 if (Basic().pTestObject ) // Are we TestTool?
612 pFileMenu->RemoveItem( pFileMenu->GetItemPos( RID_FILELOADLIB ) -1 ); // Separator before
613 pFileMenu->RemoveItem( pFileMenu->GetItemPos( RID_FILELOADLIB ) );
614 pFileMenu->RemoveItem( pFileMenu->GetItemPos( RID_FILESAVELIB ) );
617 PopupMenu* pEditMenu = pBar->GetPopupMenu( RID_APPEDIT );
618 pEditMenu->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
619 pEditMenu->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
620 pEditMenu->SetActivateHdl( LINK( this, BasicFrame, InitMenu ) );
621 pEditMenu->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
622 PopupMenu* pRunMenu = pBar->GetPopupMenu( RID_APPRUN );
623 pRunMenu->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
624 pRunMenu->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
625 pRunMenu->SetActivateHdl( LINK( this, BasicFrame, InitMenu ) );
626 pRunMenu->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
627 if (Basic().pTestObject ) // Are we TestTool?
629 pRunMenu->RemoveItem( pRunMenu->GetItemPos( RID_RUNDISAS ) );
630 pRunMenu->RemoveItem( pRunMenu->GetItemPos( RID_RUNCOMPILE ) );
633 PopupMenu *pExtras;
634 if (Basic().pTestObject ) // Are we TestTool?
636 pExtras = new PopupMenu( SttResId( RID_TT_EXTRAS ) );
637 pBar->InsertItem( RID_TT_EXTRAS, String( SttResId( RID_TT_EXTRAS_NAME ) ), 0, pBar->GetItemPos( RID_APPWINDOW ) );
638 pBar->SetPopupMenu( RID_TT_EXTRAS, pExtras );
640 pExtras->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
641 pExtras->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
642 pExtras->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
645 PopupMenu* pWinMenu = pBar->GetPopupMenu( RID_APPWINDOW );
646 pWinMenu->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
647 pWinMenu->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
648 pWinMenu->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
649 PopupMenu* pHelpMenu = pBar->GetPopupMenu( RID_APPHELP );
650 pHelpMenu->SetSelectHdl( LINK( this, BasicFrame, MenuCommand ) );
651 pHelpMenu->SetHighlightHdl( LINK( this, BasicFrame, HighlightMenu ) );
652 pHelpMenu->SetActivateHdl( LINK( this, BasicFrame, InitMenu ) );
653 pHelpMenu->SetDeactivateHdl( LINK( this, BasicFrame, DeInitMenu ) );
655 #ifndef UNX
656 pPrn = new BasicPrinter;
657 #else
658 pPrn = NULL;
659 #endif
660 pList = new EditList;
661 pStatus = new StatusLine( this );
663 LoadIniFile();
665 UpdateTitle();
666 // SetIcon( aAppIcon );
668 // Size: half width, 0.75 * height - 2 * IconSize
670 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
671 aConf.SetGroup("WinGeom");
672 SetWindowState( aConf.ReadKey("WinParams", "") );
675 // pWork = new AppEdit( this, NULL );
676 // pWork->Show();
677 // pWork->Close();
679 aLineNum.SetTimeoutHdl( LINK( this, BasicFrame, ShowLineNr ) );
680 aLineNum.SetTimeout(200);
681 aLineNum.Start();
684 aCheckFiles.SetTimeout( 10000 );
685 aCheckFiles.SetTimeoutHdl( LINK( this, BasicFrame, CheckAllFiles ) );
686 aCheckFiles.Start();
688 GetMenuBar()->SetCloserHdl( LINK( this, BasicFrame, CloseButtonClick ) );
689 GetMenuBar()->SetFloatButtonClickHdl( LINK( this, BasicFrame, FloatButtonClick ) );
690 GetMenuBar()->SetHideButtonClickHdl( LINK( this, BasicFrame, HideButtonClick ) );
693 const ByteString ProfilePrefix("_profile_");
694 const USHORT ProfilePrefixLen = ProfilePrefix.Len();
696 void BasicFrame::LoadIniFile()
698 USHORT i;
699 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
701 for ( i = 0 ; i < aConf.GetGroupCount() ; i++ )
703 aConf.SetGroup( ByteString( aConf.GetGroupName( i ) ) );
704 if ( ( aConf.ReadKey( "Aktuell" ).Len() || aConf.ReadKey( "Alle" ).Len() )
705 &&( !aConf.ReadKey( "Current" ).Len() && !aConf.ReadKey( "All" ).Len() ) )
707 aConf.WriteKey( "Current", aConf.ReadKey( "Aktuell" ) );
708 aConf.WriteKey( "All", aConf.ReadKey( "Alle" ) );
712 aConf.SetGroup("Misc");
713 ByteString aTemp;
714 ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Misc" );
716 pStatus->SetProfileName( String( aCurrentProfile.Copy( ProfilePrefixLen ), RTL_TEXTENCODING_UTF8 ) );
718 aConf.SetGroup( aCurrentProfile );
719 aTemp = aConf.ReadKey( "AutoReload", "0" );
720 bAutoReload = ( aTemp.CompareTo("1") == COMPARE_EQUAL );
721 aTemp = aConf.ReadKey( "AutoSave", "0" );
722 bAutoSave = ( aTemp.CompareTo("1") == COMPARE_EQUAL );
724 LoadLRU();
726 if ( pBasic )
727 pBasic->LoadIniFile();
729 for ( i = 0 ; i < pList->Count() ; i++ )
730 pList->GetObject( i )->LoadIniFile();
733 BasicFrame::~BasicFrame()
735 AppWin* p = pList->First();
736 DBG_ASSERT( !p, "Still open FileWindows");
737 if( p )
738 while( (p = pList->Remove() ) != NULL )
739 delete p;
741 MenuBar *pBar = GetMenuBar();
742 SetMenuBar( NULL );
743 delete pBar;
745 delete pStatus;
746 delete pPrn;
747 delete pList;
748 // delete pExecutionStatus;
749 // delete pBasic;
750 pBasic.Clear();
753 void BasicFrame::Command( const CommandEvent& rCEvt )
755 switch( rCEvt.GetCommand() ) {
756 case COMMAND_SHOWDIALOG:
758 const CommandDialogData* pData = rCEvt.GetDialogData();
759 if ( pData)
761 const int nCommand = pData->GetDialogId();
763 switch (nCommand)
765 case SHOWDIALOG_ID_PREFERENCES :
766 Command( RID_OPTIONS );
767 break;
769 case SHOWDIALOG_ID_ABOUT :
770 Command( RID_HELPABOUT );
771 break;
773 default :
778 break;
782 void BasicFrame::UpdateTitle()
784 String aTitle;
785 aTitle += aAppName;
786 if ( aAppMode.Len() )
788 aTitle.AppendAscii(" [");
789 aTitle += aAppMode;
790 aTitle.AppendAscii("]");
792 aTitle.AppendAscii(" - ");
793 aTitle += aAppFile;
794 SetText( aTitle );
797 IMPL_LINK( BasicFrame, CheckAllFiles, Timer*, pTimer )
799 if ( pWork )
801 AppWin* pStartWin = pWork;
802 Window* pFocusWin = Application::GetFocusWindow();
803 for ( int i = pList->Count()-1 ; i >= 0 ; i-- )
804 pList->GetObject( i )->CheckReload();
806 if ( pWork != pStartWin )
808 pWork = pStartWin;
809 pWork->ToTop();
811 if ( pFocusWin )
812 pFocusWin->GrabFocus();
814 pTimer->Start();
815 return 0;
818 BOOL BasicFrame::IsAutoRun()
820 return bIsAutoRun;
823 void BasicFrame::SetAutoRun( BOOL bAuto )
825 bIsAutoRun = bAuto;
828 void BasicFrame::Notify( SfxBroadcaster&, const SfxHint& rHint )
830 if ( rHint.ISA( TTExecutionStatusHint ) )
832 TTExecutionStatusHint *pStatusHint = ( TTExecutionStatusHint* )&rHint;
833 switch ( pStatusHint->GetType() )
835 case TT_EXECUTION_ENTERWAIT:
837 EnterWait();
839 break;
840 case TT_EXECUTION_LEAVEWAIT:
842 LeaveWait();
844 break;
845 case TT_EXECUTION_SHOW_ACTION:
847 String aTotalStatus( pStatusHint->GetExecutionStatus() );
848 aTotalStatus.AppendAscii( " " );
849 aTotalStatus.Append( pStatusHint->GetAdditionalExecutionStatus() );
850 pStatus->Message( aTotalStatus );
851 /* if ( !pExecutionStatus )
852 pExecutionStatus = new FloatingExecutionStatus( this );
853 pExecutionStatus->SetStatus( pStatusHint->GetExecutionStatus() );
854 pExecutionStatus->SetAdditionalInfo( pStatusHint->GetAdditionalExecutionStatus() );*/
856 break;
857 case TT_EXECUTION_HIDE_ACTION:
859 /* if ( pExecutionStatus )
861 delete pExecutionStatus;
862 pExecutionStatus = NULL;
865 break;
870 Broadcast( rHint );
873 void BasicFrame::Resize()
875 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
876 aConf.SetGroup("WinGeom");
877 aConf.WriteKey("WinParams",GetWindowState());
879 // Statusbar
880 Size aOutSize = GetOutputSizePixel();
881 Size aStatusSize = pStatus->GetSizePixel();
882 Point aStatusPos( 0, aOutSize.Height() - aStatusSize.Height() );
883 aStatusSize.Width() = aOutSize.Width();
885 pStatus->SetPosPixel( aStatusPos );
886 pStatus->SetSizePixel( aStatusSize );
889 // Resize possibly maximized window
890 ULONG i;
891 for( i = pList->Count(); i > 0 ; i-- )
893 if ( pList->GetObject( i-1 )->GetWinState() == TT_WIN_STATE_MAX )
894 pList->GetObject( i-1 )->Maximize();
898 void BasicFrame::Move()
900 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
901 aConf.SetGroup("WinGeom");
902 aConf.WriteKey("WinParams",GetWindowState());
905 void BasicFrame::GetFocus()
907 if ( pWork )
908 pWork->GrabFocus();
911 IMPL_LINK( BasicFrame, CloseButtonClick, void*, EMPTYARG )
913 AppWin* p;
914 for ( p = pList->Last() ; p && p->GetWinState() != TT_WIN_STATE_MAX ; p = pList->Prev() )
916 if ( p )
917 p->GrabFocus();
918 return Command( RID_FILECLOSE, FALSE );
921 IMPL_LINK( BasicFrame, FloatButtonClick, void*, EMPTYARG )
923 AppWin* p;
924 for ( p = pList->Last() ; p && p->GetWinState() != TT_WIN_STATE_MAX ; p = pList->Prev() )
926 if ( p )
927 p->TitleButtonClick( TITLE_BUTTON_DOCKING );
928 return 1;
931 IMPL_LINK( BasicFrame, HideButtonClick, void*, EMPTYARG )
933 AppWin* p;
934 for ( p = pList->Last() ; p && p->GetWinState() != TT_WIN_STATE_MAX ; p = pList->Prev() )
936 if ( p )
937 p->TitleButtonClick( TITLE_BUTTON_HIDE );
938 return 1;
941 void BasicFrame::WinShow_Hide()
943 if ( !pList->Count() )
944 return;
946 AppWin* p;
947 BOOL bWasFullscreen = FALSE;
948 for ( p = pList->Last() ; p ; p = pList->Prev() )
950 if ( p->pDataEdit )
952 if ( p->GetWinState() & TT_WIN_STATE_HIDE // Hidden
953 || ( bWasFullscreen && ( !p->IsPined() || p->GetWinState() & TT_WIN_STATE_MAX ))
955 p->Hide( SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
956 else
957 p->Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
959 bWasFullscreen |= p->GetWinState() == TT_WIN_STATE_MAX;
963 void BasicFrame::WinMax_Restore()
965 // The application buttons
966 AppWin* p;
967 BOOL bHasFullscreenWin = FALSE;
968 for( p = pList->First(); p && !bHasFullscreenWin ; p = pList->Next() )
969 bHasFullscreenWin |= ( p->GetWinState() == TT_WIN_STATE_MAX );
970 GetMenuBar()->ShowButtons( bHasFullscreenWin, FALSE, FALSE );
971 WinShow_Hide();
974 void BasicFrame::RemoveWindow( AppWin *pWin )
976 // delete pIcon;
977 pList->Remove( pWin );
978 pWork = pList->Last();
980 WinShow_Hide();
982 if ( pWork )
983 pWork->ToTop();
985 WinMax_Restore();
987 Menu* pMenu = GetMenuBar();
988 if( pList->Count() == 0 ) {
989 pMenu->EnableItem( RID_APPEDIT, FALSE );
990 pMenu->EnableItem( RID_APPRUN, FALSE );
991 pMenu->EnableItem( RID_APPWINDOW, FALSE );
994 PopupMenu* pWinMenu = pMenu->GetPopupMenu( RID_APPWINDOW );
996 pWinMenu->RemoveItem( pWinMenu->GetItemPos( pWin->GetWinId() ) );
998 // Remove separator
999 if ( pWinMenu->GetItemType( pWinMenu->GetItemCount() - 1 ) == MENUITEM_SEPARATOR )
1000 pWinMenu->RemoveItem( pWinMenu->GetItemCount() - 1 );
1002 pStatus->LoadTaskToolBox();
1005 void BasicFrame::AddWindow( AppWin *pWin )
1007 pList->Insert( pWin, LIST_APPEND );
1008 pWork = pWin;
1010 WinMax_Restore();
1012 // Enable main menu
1013 MenuBar* pMenu = GetMenuBar();
1014 if( pList->Count() > 0 ) {
1015 pMenu->EnableItem( RID_APPEDIT, TRUE );
1016 pMenu->EnableItem( RID_APPRUN, TRUE );
1017 pMenu->EnableItem( RID_APPWINDOW, TRUE );
1020 PopupMenu* pWinMenu = pMenu->GetPopupMenu( RID_APPWINDOW );
1021 USHORT nLastID = pWinMenu->GetItemId( pWinMenu->GetItemCount() - 1 );
1023 // Separator necessary
1024 if ( nLastID < RID_WIN_FILE1 && pWinMenu->GetItemType( pWinMenu->GetItemCount() - 1 ) != MENUITEM_SEPARATOR )
1025 pWinMenu->InsertSeparator();
1027 // Find free ID
1028 USHORT nFreeID = RID_WIN_FILE1;
1029 while ( pWinMenu->GetItemPos( nFreeID ) != MENU_ITEM_NOTFOUND && nFreeID < RID_WIN_FILEn )
1030 nFreeID++;
1032 pWin->SetWinId( nFreeID );
1033 pWinMenu->InsertItem( nFreeID, pWin->GetText() );
1036 void BasicFrame::WindowRenamed( AppWin *pWin )
1038 MenuBar* pMenu = GetMenuBar();
1039 PopupMenu* pWinMenu = pMenu->GetPopupMenu( RID_APPWINDOW );
1041 pWinMenu->SetItemText( pWin->GetWinId(), pWin->GetText() );
1043 pStatus->LoadTaskToolBox();
1045 aAppFile = pWin->GetText();
1046 UpdateTitle();
1049 void BasicFrame::FocusWindow( AppWin *pWin )
1051 pWork = pWin;
1052 pList->Remove( pWin );
1053 pList->Insert( pWin, LIST_APPEND );
1054 pWin->Minimize( FALSE );
1056 aAppFile = pWin->GetText();
1057 UpdateTitle();
1059 WinShow_Hide();
1060 pStatus->LoadTaskToolBox();
1063 BOOL BasicFrame::Close()
1065 if( bInBreak || Basic().IsRunning() )
1066 if( RET_NO == QueryBox( this, SttResId( IDS_RUNNING ) ).Execute() )
1067 return FALSE;
1069 StarBASIC::Stop();
1070 bInBreak = FALSE;
1071 if( CloseAll() )
1073 aLineNum.Stop();
1075 // Close remaining dialogs to avoid assertions
1076 while ( GetWindow( WINDOW_OVERLAP )->GetWindow( WINDOW_FIRSTOVERLAP ) )
1078 delete GetWindow( WINDOW_OVERLAP )->GetWindow( WINDOW_FIRSTOVERLAP )->GetWindow( WINDOW_CLIENT );
1081 Application::SetDefDialogParent( NULL );
1082 WorkWindow::Close();
1084 return TRUE;
1085 } else return FALSE;
1088 BOOL BasicFrame::CloseAll()
1090 while ( pList->Count() )
1091 if ( !pList->Last()->Close() )
1092 return FALSE;
1093 return TRUE;
1096 BOOL BasicFrame::CompileAll()
1098 AppWin* p;
1099 for( p = pList->First(); p; p = pList->Next() )
1100 if( p->ISA(AppBasEd) && !((AppBasEd*)p)->Compile() ) return FALSE;
1101 return TRUE;
1104 // Setup menu
1105 #define MENU2FILENAME( Name ) Name.Copy( Name.SearchAscii(" ") +1).EraseAllChars( '~' )
1106 #define LRUNr( nNr ) CByteString("LRU").Append( ByteString::CreateFromInt32( nNr ) )
1107 String FILENAME2MENU( USHORT nNr, String aName )
1109 String aRet;
1110 if ( nNr <= 9 )
1111 aRet = CUniString("~").Append( UniString::CreateFromInt32( nNr ) );
1112 else if ( nNr == 10 )
1113 aRet = CUniString("1~0");
1114 else
1115 aRet = UniString::CreateFromInt32( nNr );
1117 return aRet.AppendAscii(" ").Append( aName );
1120 void BasicFrame::AddToLRU(String const& aFile)
1122 Config aConfig(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
1123 PopupMenu *pPopup = GetMenuBar()->GetPopupMenu(RID_APPFILE);
1125 aConfig.SetGroup("LRU");
1126 USHORT nMaxLRU = (USHORT)aConfig.ReadKey("MaxLRU","4").ToInt32();
1127 DirEntry aFileEntry( aFile );
1128 USHORT i,nLastMove = nMaxLRU;
1130 for ( i = 1 ; i<nMaxLRU && nLastMove == nMaxLRU ; i++ )
1132 if ( DirEntry( UniString( aConfig.ReadKey(LRUNr(i),""), RTL_TEXTENCODING_UTF8 ) ) == aFileEntry )
1133 nLastMove = i;
1136 if ( pPopup->GetItemPos( IDM_FILE_LRU1 ) == MENU_ITEM_NOTFOUND )
1137 pPopup->InsertSeparator();
1138 for ( i = nLastMove ; i>1 ; i-- )
1140 if ( aConfig.ReadKey(LRUNr(i-1),"").Len() )
1142 aConfig.WriteKey(LRUNr(i), aConfig.ReadKey(LRUNr(i-1),""));
1143 if ( pPopup->GetItemPos( IDM_FILE_LRU1 + i-1 ) == MENU_ITEM_NOTFOUND )
1144 pPopup->InsertItem(IDM_FILE_LRU1 + i-1, FILENAME2MENU( i, MENU2FILENAME( pPopup->GetItemText(IDM_FILE_LRU1 + i-1-1) ) ));
1145 else
1146 pPopup->SetItemText(IDM_FILE_LRU1 + i-1,FILENAME2MENU( i, MENU2FILENAME( pPopup->GetItemText(IDM_FILE_LRU1 + i-1-1) ) ));
1149 aConfig.WriteKey(LRUNr(1), ByteString( aFile, RTL_TEXTENCODING_UTF8 ) );
1150 if ( pPopup->GetItemPos( IDM_FILE_LRU1 ) == MENU_ITEM_NOTFOUND )
1151 pPopup->InsertItem(IDM_FILE_LRU1,FILENAME2MENU( 1, aFile));
1152 else
1153 pPopup->SetItemText(IDM_FILE_LRU1,FILENAME2MENU( 1, aFile));
1156 void BasicFrame::LoadLRU()
1158 Config aConfig(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
1159 PopupMenu *pPopup = GetMenuBar()->GetPopupMenu(RID_APPFILE);
1160 BOOL bAddSep = TRUE;
1162 aConfig.SetGroup("LRU");
1163 USHORT nMaxLRU = (USHORT)aConfig.ReadKey("MaxLRU","4").ToInt32();
1165 if ( pPopup )
1166 bAddSep = pPopup->GetItemPos( IDM_FILE_LRU1 ) == MENU_ITEM_NOTFOUND;
1168 USHORT i;
1169 for ( i = 1; i <= nMaxLRU && pPopup != NULL; i++)
1171 String aFile = UniString( aConfig.ReadKey(LRUNr(i)), RTL_TEXTENCODING_UTF8 );
1173 if (aFile.Len() != 0)
1175 if (bAddSep)
1177 pPopup->InsertSeparator();
1178 bAddSep = FALSE;
1181 if ( pPopup->GetItemPos( IDM_FILE_LRU1 + i-1 ) == MENU_ITEM_NOTFOUND )
1182 pPopup->InsertItem(IDM_FILE_LRU1 + i-1, FILENAME2MENU( i, aFile ));
1183 else
1184 pPopup->SetItemText(IDM_FILE_LRU1 + i-1, FILENAME2MENU( i, aFile ));
1187 i = nMaxLRU+1;
1188 while ( pPopup->GetItemPos( IDM_FILE_LRU1 + i-1 ) != MENU_ITEM_NOTFOUND )
1190 pPopup->RemoveItem( pPopup->GetItemPos( IDM_FILE_LRU1 + i-1 ) );
1191 i++;
1195 IMPL_LINK( BasicFrame, InitMenu, Menu *, pMenu )
1197 BOOL bNormal = BOOL( !bInBreak );
1198 pMenu->EnableItem( RID_RUNCOMPILE, bNormal );
1200 BOOL bHasEdit = BOOL( /*bNormal &&*/ pWork != NULL );
1202 // pMenu->EnableItem( RID_FILENEW, bNormal ); // always possible
1203 // pMenu->EnableItem( RID_FILEOPEN, bNormal );
1204 pMenu->EnableItem( RID_FILECLOSE, bHasEdit );
1205 pMenu->EnableItem( RID_FILESAVE, bHasEdit );
1206 pMenu->EnableItem( RID_FILESAVEAS, bHasEdit );
1207 pMenu->EnableItem( RID_FILEPRINT, bHasEdit );
1208 pMenu->EnableItem( RID_FILESETUP, bHasEdit );
1209 pMenu->EnableItem( RID_FILELOADLIB, bNormal );
1210 pMenu->EnableItem( RID_FILESAVELIB, bHasEdit );
1212 BOOL bHasErr = BOOL( bNormal && pBasic->GetErrors() != 0 );
1213 BOOL bNext = bHasErr & bNormal;
1214 BOOL bPrev = bHasErr & bNormal;
1215 if( bHasErr )
1217 ULONG n = pBasic->aErrors.GetCurPos();
1218 if( n == 0 )
1219 bPrev = FALSE;
1220 if( USHORT(n+1) == pBasic->GetErrors() )
1221 bNext = FALSE;
1223 pMenu->EnableItem( RID_RUNNEXTERR, bNext );
1224 pMenu->EnableItem( RID_RUNPREVERR, bPrev );
1225 pMenu->CheckItem( RID_RUNDISAS, bDisas );
1226 if( pWork )
1227 pWork->InitMenu( pMenu );
1229 return TRUE;
1232 IMPL_LINK_INLINE_START( BasicFrame, DeInitMenu, Menu *, pMenu )
1234 (void) pMenu; /* avoid warning about unused parameter */
1235 /* pMenu->EnableItem( RID_RUNCOMPILE );
1237 pMenu->EnableItem( RID_FILECLOSE );
1238 pMenu->EnableItem( RID_FILESAVE );
1239 pMenu->EnableItem( RID_FILESAVEAS );
1240 pMenu->EnableItem( RID_FILEPRINT );
1241 pMenu->EnableItem( RID_FILESETUP );
1242 pMenu->EnableItem( RID_FILELOADLIB );
1243 pMenu->EnableItem( RID_FILESAVELIB );
1245 pMenu->EnableItem( RID_RUNNEXTERR );
1246 pMenu->EnableItem( RID_RUNPREVERR );
1247 if( pWork ) pWork->DeInitMenu( pMenu );
1249 SetAutoRun( FALSE );
1250 String aString;
1251 pStatus->Message( aString );
1252 return 0L;
1254 IMPL_LINK_INLINE_END( BasicFrame, DeInitMenu, Menu *, pMenu )
1256 IMPL_LINK_INLINE_START( BasicFrame, HighlightMenu, Menu *, pMenu )
1258 String s = pMenu->GetHelpText( pMenu->GetCurItemId() );
1259 pStatus->Message( s );
1260 return 0L;
1262 IMPL_LINK_INLINE_END( BasicFrame, HighlightMenu, Menu *, pMenu )
1264 IMPL_LINK_INLINE_START( BasicFrame, MenuCommand, Menu *, pMenu )
1266 USHORT nId = pMenu->GetCurItemId();
1267 BOOL bChecked = pMenu->IsItemChecked( nId );
1268 return Command( nId, bChecked );
1270 IMPL_LINK_INLINE_END( BasicFrame, MenuCommand, Menu *, pMenu )
1272 IMPL_LINK_INLINE_START( BasicFrame, Accel, Accelerator*, pAcc )
1274 SetAutoRun( FALSE );
1275 return Command( pAcc->GetCurItemId() );
1277 IMPL_LINK_INLINE_END( BasicFrame, Accel, Accelerator*, pAcc )
1279 IMPL_LINK_INLINE_START( BasicFrame, ShowLineNr, AutoTimer *, pTimer )
1281 (void) pTimer; /* avoid warning about unused parameter */
1282 String aPos;
1283 if ( pWork && pWork->ISA(AppBasEd))
1285 aPos = String::CreateFromInt32(pWork->GetLineNr());
1287 pStatus->Pos( aPos );
1288 return 0L;
1290 IMPL_LINK_INLINE_END( BasicFrame, ShowLineNr, AutoTimer *, pTimer )
1293 MsgEdit* BasicFrame::GetMsgTree( String aLogFileName )
1295 if ( FindErrorWin( aLogFileName ) )
1297 return FindErrorWin( aLogFileName )->GetMsgTree();
1299 else
1300 { // create new Window on the fly
1301 AppError *pNewWindow = new AppError( this, aLogFileName );
1302 pNewWindow->Show();
1303 pNewWindow->GrabFocus();
1304 return pNewWindow->GetMsgTree();
1308 IMPL_LINK( BasicFrame, Log, TTLogMsg *, pLogMsg )
1310 GetMsgTree( pLogMsg->aLogFileName )->AddAnyMsg( pLogMsg );
1311 return 0L;
1314 IMPL_LINK( BasicFrame, WinInfo, WinInfoRec*, pWinInfo )
1316 if ( !pDisplayHidDlg )
1317 pDisplayHidDlg = new DisplayHidDlg( this );
1318 if ( pDisplayHidDlg )
1320 pDisplayHidDlg->AddData( pWinInfo );
1321 pDisplayHidDlg->Show();
1323 return 0;
1326 AppBasEd* BasicFrame::CreateModuleWin( SbModule* pMod )
1328 String aModName = pMod->GetName();
1329 if ( aModName.Copy(0,2).CompareToAscii("--") == COMPARE_EQUAL )
1330 aModName.Erase(0,2);
1331 pMod->SetName(aModName);
1332 AppBasEd* p = new AppBasEd( this, pMod );
1333 p->Show();
1334 p->GrabFocus();
1335 p->ToTop();
1336 return p;
1339 BOOL BasicFrame::LoadFile( String aFilename )
1341 BOOL bIsResult = DirEntry( aFilename ).GetExtension().CompareIgnoreCaseToAscii("RES") == COMPARE_EQUAL;
1342 BOOL bIsBasic = DirEntry( aFilename ).GetExtension().CompareIgnoreCaseToAscii("BAS") == COMPARE_EQUAL;
1343 bIsBasic |= DirEntry( aFilename ).GetExtension().CompareIgnoreCaseToAscii("INC") == COMPARE_EQUAL;
1345 AppWin* p;
1346 BOOL bSuccess = TRUE;
1347 if ( bIsResult )
1349 p = new AppError( this, aFilename );
1351 else if ( bIsBasic )
1353 p = new AppBasEd( this, NULL );
1354 bSuccess = p->Load( aFilename );
1356 else
1358 p = new AppEdit( this );
1359 bSuccess = p->Load( aFilename );
1361 if ( bSuccess )
1363 p->Show();
1364 p->GrabFocus();
1366 else
1367 delete p;
1369 return bSuccess;
1372 // Execute command
1373 long BasicFrame::Command( short nID, BOOL bChecked )
1375 BasicError* pErr;
1377 switch( nID ) {
1378 case RID_FILENEW: {
1379 AppBasEd* p = new AppBasEd( this, NULL );
1380 p->Show();
1381 p->GrabFocus();
1382 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1383 } break;
1384 case RID_FILEOPEN:
1386 String s;
1387 if( QueryFileName( s, FT_BASIC_SOURCE | FT_RESULT_FILE, FALSE ) ) {
1388 AddToLRU( s );
1389 LoadFile( s );
1390 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1392 } break;
1393 case RID_FILELOADLIB:
1394 LoadLibrary();
1395 break;
1396 case RID_FILESAVELIB:
1397 SaveLibrary();
1398 break;
1399 case RID_FILECLOSE:
1400 if( pWork && pWork->Close() ){};
1401 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1402 break;
1403 case RID_FILEPRINT:
1404 #ifndef UNX
1405 if( pWork )
1406 pPrn->Print( pWork->GetText(), pWork->pDataEdit->GetText(), this );
1407 #else
1408 InfoBox( this, SttResId( IDS_NOPRINTERERROR ) ).Execute();
1409 #endif
1410 break;
1411 case RID_FILESETUP:
1412 #ifndef UNX
1413 pPrn->Setup();
1414 #else
1415 InfoBox( this, SttResId( IDS_NOPRINTERERROR ) ).Execute();
1416 #endif
1417 break;
1418 case RID_QUIT:
1419 if( Close() ) aBasicApp.Quit();
1420 break;
1423 case RID_RUNSTART:
1424 nFlags = SbDEBUG_BREAK;
1425 goto start;
1426 case RID_RUNSTEPOVER:
1427 nFlags = SbDEBUG_STEPINTO | SbDEBUG_STEPOVER;
1428 goto start;
1429 case RID_RUNSTEPINTO:
1430 nFlags = SbDEBUG_STEPINTO;
1431 goto start;
1432 case RID_RUNTOCURSOR:
1433 if ( pWork && pWork->ISA(AppBasEd) && ((AppBasEd*)pWork)->GetModule()->SetBP(pWork->GetLineNr()) )
1435 SbModule *pModule = ((AppBasEd*)pWork)->GetModule();
1436 #if OSL_DEBUG_LEVEL > 1
1437 USHORT x;
1438 x = pWork->GetLineNr();
1439 x = ((AppBasEd*)pWork)->GetModule()->GetBPCount();
1440 if ( !x )
1441 x = pModule->SetBP(pWork->GetLineNr());
1442 x = pModule->GetBPCount();
1443 #endif
1445 for ( USHORT nMethod = 0; nMethod < pModule->GetMethods()->Count(); nMethod++ )
1447 SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Get( nMethod );
1448 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
1449 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
1452 nFlags = SbDEBUG_BREAK;
1453 goto start;
1454 start: {
1455 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1456 if ( !Basic().IsRunning() || bInBreak )
1458 AppBasEd* p = NULL;
1459 if( pWork && pWork->ISA(AppBasEd) )
1461 p = ((AppBasEd*)pWork);
1462 p->ToTop();
1464 else
1466 AppWin *w = NULL;
1467 for ( w = pList->Last() ; w ? !w->ISA(AppBasEd) : FALSE ; w = pList->Prev() ) ;
1468 if ( w )
1470 p = ((AppBasEd*)w);
1471 p->ToTop();
1473 else
1474 if ( IsAutoRun() )
1475 printf( "No file loaded to run.\n" );
1478 if( bInBreak )
1479 // Reset the flag
1480 bInBreak = FALSE;
1481 else
1483 if( IsAutoSave() && !SaveAll() ) break;
1484 if( !CompileAll() ) break;
1485 String aString;
1486 pStatus->Message( aString );
1487 if( p )
1489 BasicDLL::SetDebugMode( TRUE );
1490 Basic().ClearGlobalVars();
1491 p->Run();
1492 BasicDLL::SetDebugMode( FALSE );
1493 // If cancelled during Interactive=FALSE
1494 // BasicDLL::EnableBreak( TRUE );
1498 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN )); // after run
1499 break;
1500 case RID_RUNCOMPILE:
1501 if( pWork && pWork->ISA(AppBasEd) && SaveAll() )
1503 ((AppBasEd*)pWork)->Compile();
1504 pWork->ToTop();
1505 pWork->GrabFocus();
1507 break;
1508 case RID_RUNDISAS:
1509 bDisas = BOOL( !bChecked );
1510 break;
1511 case RID_RUNBREAK:
1512 if ( Basic().IsRunning() && !bInBreak )
1514 // pINST->CalcBreakCallLevel(SbDEBUG_STEPINTO);
1515 pINST->nBreakCallLvl = pINST->nCallLvl;
1517 break;
1518 case RID_RUNSTOP:
1519 Basic().Stop();
1520 bInBreak = FALSE;
1521 break;
1522 case RID_RUNNEXTERR:
1523 pErr = pBasic->aErrors.Next();
1524 if( pErr ) pErr->Show();
1525 break;
1526 case RID_RUNPREVERR:
1527 pErr = pBasic->aErrors.Prev();
1528 if( pErr ) pErr->Show();
1529 break;
1531 case RID_OPTIONS:
1533 OptionsDialog *pOptions = new OptionsDialog( this, SttResId(IDD_OPTIONS_DLG) );
1534 pOptions->Show();
1536 break;
1537 case RID_DECLARE_HELPER:
1538 InfoBox( this, SttResId( IDS_NOT_YET_IMPLEMENTED ) ).Execute();
1539 break;
1541 case RID_WINTILE:
1543 WindowArrange aArange;
1544 for ( ULONG i = 0 ; i < pList->Count() ; i++ )
1546 aArange.AddWindow( pList->GetObject( i ) );
1547 pList->GetObject( i )->Restore();
1551 sal_Int32 nTitleHeight;
1553 sal_Int32 nDummy1, nDummy2, nDummy3;
1554 GetBorder( nDummy1, nTitleHeight, nDummy2, nDummy3 );
1557 Size aSize = GetOutputSizePixel();
1558 aSize.Height() -= nTitleHeight;
1559 Rectangle aRect( Point( 0, nTitleHeight ), aSize );
1561 aArange.Arrange( WINDOWARRANGE_TILE, aRect );
1564 break;
1565 case RID_WINTILEHORZ:
1567 WindowArrange aArange;
1568 for ( ULONG i = 0 ; i < pList->Count() ; i++ )
1570 aArange.AddWindow( pList->GetObject( i ) );
1571 pList->GetObject( i )->Restore();
1575 sal_Int32 nTitleHeight;
1577 sal_Int32 nDummy1, nDummy2, nDummy3;
1578 GetBorder( nDummy1, nTitleHeight, nDummy2, nDummy3 );
1581 Size aSize = GetOutputSizePixel();
1582 aSize.Height() -= nTitleHeight;
1583 Rectangle aRect( Point( 0, nTitleHeight ), aSize );
1585 aArange.Arrange( WINDOWARRANGE_HORZ, aRect );
1588 break;
1589 case RID_WINTILEVERT:
1590 //#define WINDOWARRANGE_TILE 1
1591 //#define WINDOWARRANGE_HORZ 2
1592 //#define WINDOWARRANGE_VERT 3
1593 //#define WINDOWARRANGE_CASCADE 4
1595 WindowArrange aArange;
1596 for ( ULONG i = 0 ; i < pList->Count() ; i++ )
1598 aArange.AddWindow( pList->GetObject( i ) );
1599 pList->GetObject( i )->Restore();
1603 sal_Int32 nTitleHeight;
1605 sal_Int32 nDummy1, nDummy2, nDummy3;
1606 GetBorder( nDummy1, nTitleHeight, nDummy2, nDummy3 );
1609 Size aSize = GetOutputSizePixel();
1610 aSize.Height() -= nTitleHeight;
1611 Rectangle aRect( Point( 0, nTitleHeight ), aSize );
1613 aArange.Arrange( WINDOWARRANGE_VERT, aRect );
1616 break;
1617 case RID_WINCASCADE:
1619 for ( USHORT i = 0 ; i < pList->Count() ; i++ )
1621 pList->GetObject( i )->Cascade( i );
1624 break;
1626 /* case RID_HELPTOPIC:
1627 if( pWork ) pWork->Help();
1628 break;
1629 case RID_HELPKEYS:
1630 aBasicApp.pHelp->Start( CUniString( "Keyboard" ) );
1631 break;
1632 case RID_HELPINDEX:
1633 aBasicApp.pHelp->Start( OOO_HELP_INDEX );
1634 break;
1635 case RID_HELPINTRO:
1636 aBasicApp.pHelp->Start( OOO_HELP_HELPONHELP );
1637 break;
1638 */ case RID_HELPABOUT:
1640 SttResId aResId( IDD_ABOUT_DIALOG );
1641 if ( Basic().pTestObject ) // Are we TestTool?
1642 aResId = SttResId( IDD_TT_ABOUT_DIALOG );
1643 else
1644 aResId = SttResId( IDD_ABOUT_DIALOG );
1645 AboutDialog aAbout( this, aResId );
1646 aAbout.Execute();
1648 break;
1649 case RID_POPUPEDITVAR:
1651 new VarEditDialog( this, pEditVar );
1653 break;
1654 default:
1655 if ( nID >= RID_WIN_FILE1 && nID <= RID_WIN_FILEn )
1657 MenuBar* pMenu = GetMenuBar();
1658 PopupMenu* pWinMenu = pMenu->GetPopupMenu( RID_APPWINDOW );
1659 String aName = pWinMenu->GetItemText( nID );
1660 aName.EraseAllChars( L'~' );
1661 AppWin* pWin = FindWin( aName );
1662 if ( pWin )
1663 pWin->ToTop();
1665 else if ( nID >= IDM_FILE_LRU1 && nID <= IDM_FILE_LRUn )
1667 String s = MENU2FILENAME( GetMenuBar()->GetPopupMenu(RID_APPFILE)->GetItemText(nID) );
1669 AddToLRU( s );
1670 LoadFile( s );
1671 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1673 else
1675 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPEDIT )); // So daß Delete richtig ist
1676 if( pWork )
1677 pWork->Command( CommandEvent( Point(), nID ) );
1678 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPEDIT )); // So daß Delete richtig ist
1681 return TRUE;
1684 BOOL BasicFrame::SaveAll()
1686 AppWin* p, *q = pWork;
1687 for( p = pList->First(); p; p = pList->Next() )
1689 USHORT nRes = p->QuerySave( QUERY_DISK_CHANGED );
1690 if( (( nRes == SAVE_RES_ERROR ) && QueryBox(this,SttResId(IDS_ASKSAVEERROR)).Execute() == RET_NO )
1691 || ( nRes == SAVE_RES_CANCEL ) )
1692 return FALSE;
1694 if ( q )
1695 q->ToTop();
1696 return TRUE;
1699 IMPL_LINK( BasicFrame, ModuleWinExists, String*, pFilename )
1701 return FindModuleWin( *pFilename ) != NULL;
1704 AppBasEd* BasicFrame::FindModuleWin( const String& rName )
1706 AppWin* p;
1707 for( p = pList->First(); p; p = pList->Next() )
1709 if( p->ISA(AppBasEd) && ((AppBasEd*)p)->GetModName() == rName )
1710 return ((AppBasEd*)p);
1712 return NULL;
1715 AppError* BasicFrame::FindErrorWin( const String& rName )
1717 AppWin* p;
1718 for( p = pList->First(); p; p = pList->Next() )
1720 if( p->ISA(AppError) && ((AppError*)p)->GetText() == rName )
1721 return ((AppError*)p);
1723 return NULL;
1726 AppWin* BasicFrame::FindWin( const String& rName )
1728 AppWin* p;
1729 for( p = pList->First(); p; p = pList->Next() )
1731 if( p->GetText() == rName )
1732 return p;
1734 return NULL;
1737 AppWin* BasicFrame::FindWin( USHORT nWinId )
1739 AppWin* p;
1740 for( p = pList->First(); p; p = pList->Next() )
1742 if( p->GetWinId() == nWinId )
1743 return p;
1745 return NULL;
1748 AppWin* BasicFrame::IsWinValid( AppWin* pMaybeWin )
1750 AppWin* p;
1751 for( p = pList->First(); p; p = pList->Next() )
1753 if( p == pMaybeWin )
1754 return p;
1756 return NULL;
1759 IMPL_LINK( BasicFrame, WriteString, String*, pString )
1761 if ( pList->Last() )
1763 pList->Last()->pDataEdit->ReplaceSelected( *pString );
1764 return TRUE;
1766 else
1767 return FALSE;
1770 class NewFileDialog : public FileDialog
1772 private:
1773 String aLastPath;
1774 public:
1775 ByteString aFilterType;
1776 NewFileDialog( Window* pParent, WinBits nWinStyle ):FileDialog( pParent, nWinStyle ){};
1777 virtual short Execute();
1778 virtual void FilterSelect();
1781 void NewFileDialog::FilterSelect()
1783 String aTemp = GetPath();
1784 if ( aLastPath.Len() == 0 )
1785 aLastPath = DirEntry( GetPath() ).GetPath().GetFull();
1786 if ( aLastPath.CompareIgnoreCaseToAscii( DirEntry( GetPath() ).GetPath().GetFull() ) != COMPARE_EQUAL )
1787 return; // User decides after he has changed the path
1789 String aCurFilter = GetCurFilter();
1790 USHORT nFilterNr = 0;
1791 while ( nFilterNr < GetFilterCount() && aCurFilter != GetFilterName( nFilterNr ) )
1793 nFilterNr++;
1795 aFilterType = ByteString( GetFilterType( nFilterNr ), RTL_TEXTENCODING_UTF8 );
1797 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
1798 aConf.SetGroup( "Misc" );
1799 ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Path" );
1800 aConf.SetGroup( aCurrentProfile );
1801 aLastPath = UniString( aConf.ReadKey( aFilterType, aConf.ReadKey( "BaseDir" ) ), RTL_TEXTENCODING_UTF8 );
1802 SetPath( aLastPath );
1803 // if ( IsInExecute() )
1804 // SetPath( "" );
1807 short NewFileDialog::Execute()
1809 BOOL bRet = (BOOL)FileDialog::Execute();
1810 if ( bRet )
1812 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
1813 aConf.SetGroup( "Misc" );
1814 ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Path" );
1815 aConf.SetGroup( aCurrentProfile );
1816 aConf.WriteKey( aFilterType, ByteString( DirEntry( GetPath() ).GetPath().GetFull(), RTL_TEXTENCODING_UTF8 ) );
1817 aConf.WriteKey( "LastFilterName", ByteString( GetCurFilter(), RTL_TEXTENCODING_UTF8 ) );
1819 return bRet;
1822 BOOL BasicFrame::QueryFileName
1823 (String& rName, FileType nFileType, BOOL bSave )
1825 NewFileDialog aDlg( this, bSave ? WinBits( WB_SAVEAS ) :
1826 WinBits( WB_OPEN ) );
1827 aDlg.SetText( String( SttResId( bSave ? IDS_SAVEDLG : IDS_LOADDLG ) ) );
1829 if ( nFileType & FT_RESULT_FILE )
1831 aDlg.SetDefaultExt( String( SttResId( IDS_RESFILE ) ) );
1832 aDlg.AddFilter( String( SttResId( IDS_RESFILTER ) ), String( SttResId( IDS_RESFILE ) ) );
1833 aDlg.AddFilter( String( SttResId( IDS_TXTFILTER ) ), String( SttResId( IDS_TXTFILE ) ) );
1834 aDlg.SetCurFilter( SttResId( IDS_RESFILTER ) );
1837 if ( nFileType & FT_BASIC_SOURCE )
1839 aDlg.SetDefaultExt( String( SttResId( IDS_NONAMEFILE ) ) );
1840 aDlg.AddFilter( String( SttResId( IDS_BASFILTER ) ), String( SttResId( IDS_NONAMEFILE ) ) );
1841 aDlg.AddFilter( String( SttResId( IDS_INCFILTER ) ), String( SttResId( IDS_INCFILE ) ) );
1842 aDlg.SetCurFilter( SttResId( IDS_BASFILTER ) );
1845 if ( nFileType & FT_BASIC_LIBRARY )
1847 aDlg.SetDefaultExt( String( SttResId( IDS_LIBFILE ) ) );
1848 aDlg.AddFilter( String( SttResId( IDS_LIBFILTER ) ), String( SttResId( IDS_LIBFILE ) ) );
1849 aDlg.SetCurFilter( SttResId( IDS_LIBFILTER ) );
1852 Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
1853 aConf.SetGroup( "Misc" );
1854 ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Path" );
1855 aConf.SetGroup( aCurrentProfile );
1856 ByteString aFilter( aConf.ReadKey( "LastFilterName") );
1857 if ( aFilter.Len() )
1858 aDlg.SetCurFilter( String( aFilter, RTL_TEXTENCODING_UTF8 ) );
1859 else
1860 aDlg.SetCurFilter( String( SttResId( IDS_BASFILTER ) ) );
1862 aDlg.FilterSelect(); // Selects the last used path
1863 // if ( bSave )
1864 if ( rName.Len() > 0 )
1865 aDlg.SetPath( rName );
1867 if( aDlg.Execute() )
1869 rName = aDlg.GetPath();
1870 /* rExtension = aDlg.GetCurrentFilter();
1871 var i:integer;
1872 for ( i = 0 ; i < aDlg.GetFilterCount() ; i++ )
1873 if ( rExtension == aDlg.GetFilterName( i ) )
1874 rExtension = aDlg.GetFilterType( i );
1876 return TRUE;
1877 } else return FALSE;
1880 USHORT BasicFrame::BreakHandler()
1882 bInBreak = TRUE;
1883 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1884 // MenuBar aBar( ResId( RID_APPMENUBAR ) );
1885 // aBar.EnableItem( RID_APPEDIT, FALSE );
1886 SetAppMode( String( SttResId ( IDS_APPMODE_BREAK ) ) );
1887 while( bInBreak )
1888 GetpApp()->Yield();
1889 SetAppMode( String( SttResId ( IDS_APPMODE_RUN ) ) );
1890 // aBar.EnableItem( RID_APPEDIT, TRUE );
1891 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1892 return nFlags;
1895 void BasicFrame::LoadLibrary()
1897 String s;
1898 if( QueryFileName( s, FT_BASIC_LIBRARY, FALSE ) )
1900 CloseAll();
1901 SvFileStream aStrm( s, STREAM_STD_READ );
1902 MyBasic* pNew = (MyBasic*) SbxBase::Load( aStrm );
1903 if( pNew && pNew->ISA( MyBasic ) )
1905 pBasic = pNew;
1906 // Show all contents if existing
1907 SbxArray* pMods = pBasic->GetModules();
1908 for( USHORT i = 0; i < pMods->Count(); i++ )
1910 SbModule* pMod = (SbModule*) pMods->Get( i );
1911 AppWin* p = new AppBasEd( this, pMod );
1912 p->Show();
1915 else
1917 delete pNew;
1918 ErrorBox( this, SttResId( IDS_READERROR ) ).Execute();
1923 void BasicFrame::SaveLibrary()
1925 String s;
1926 if( QueryFileName( s, FT_BASIC_LIBRARY, TRUE ) )
1928 SvFileStream aStrm( s, STREAM_STD_WRITE );
1929 if( !Basic().Store( aStrm ) )
1930 ErrorBox( this, SttResId( IDS_WRITEERROR ) ).Execute();
1934 String BasicFrame::GenRealString( const String &aResString )
1936 xub_StrLen nStart,nGleich = 0,nEnd = 0,nStartPos = 0;
1937 String aType,aValue,aResult(aResString);
1938 String aString;
1939 xub_StrLen nInsertPos = 0;
1940 BOOL bFound;
1941 bFound = FALSE;
1943 while ( (nStart = aResult.Search(StartKenn,nStartPos)) != STRING_NOTFOUND &&
1944 (nGleich = aResult.SearchAscii("=",nStart+StartKenn.Len())) != STRING_NOTFOUND &&
1945 (nEnd = aResult.Search(EndKenn,nGleich+1)) != STRING_NOTFOUND)
1947 aType = aResult.Copy(nStart,nGleich-nStart);
1948 aValue = aResult.Copy(nGleich+1,nEnd-nGleich-1);
1949 if ( aType.CompareTo(ResKenn) == COMPARE_EQUAL )
1951 if ( bFound )
1953 // insert results of previous resource
1954 DBG_ASSERT( aString.SearchAscii( "($Arg" ) == STRING_NOTFOUND, "Argument missing in String");
1955 aResult.Insert( aString, nInsertPos );
1956 nStart = nStart + aString.Len();
1957 nEnd = nEnd + aString.Len();
1958 aString.Erase();
1960 // if ( Resource::GetResManager()->IsAvailable( ResId( aValue ) ) )
1961 aString = String( SttResId( (USHORT)(aValue.ToInt32()) ) );
1962 // else
1964 // DBG_ERROR( "Could not load resource!" );
1965 // return aResString;
1967 nInsertPos = nStart;
1968 nStartPos = nStart;
1969 aResult.Erase( nStart, nEnd-nStart+1 );
1970 bFound = TRUE;
1972 else if ( aType.Search(BaseArgKenn) == 0 ) // Starts with BaseArgKenn
1974 // TODO: What the hell is that for??
1975 USHORT nArgNr = USHORT( aType.Copy( BaseArgKenn.Len() ).ToInt32() );
1976 DBG_ASSERT( aString.Search( CUniString("($Arg").Append( String::CreateFromInt32(nArgNr) ).AppendAscii(")") ) != STRING_NOTFOUND, "Extra Argument given in String");
1977 aString.SearchAndReplace( CUniString("($Arg").Append( String::CreateFromInt32(nArgNr) ).AppendAscii(")"), aValue );
1978 nStartPos = nStart;
1979 aResult.Erase( nStart, nEnd-nStart+1 );
1981 else
1983 DBG_ERROR( CByteString("Unknown replacement in String: ").Append( ByteString( aResult.Copy(nStart,nEnd-nStart), RTL_TEXTENCODING_UTF8 ) ).GetBuffer() );
1984 nStartPos = nStartPos + StartKenn.Len();
1987 if ( bFound )
1989 DBG_ASSERT( aString.SearchAscii( "($Arg" ) == STRING_NOTFOUND, "Argument missing in String");
1990 aResult.Insert( aString, nInsertPos );
1992 return aResult;