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: 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>
37 #include <tools/fsys.hxx>
38 #ifndef _SV_FILEDLG_HXX //autogen
39 #include <svtools/filedlg.hxx>
41 #include <tools/config.hxx>
43 #include <vcl/font.hxx>
45 #ifndef _BASIC_TTRESHLP_HXX
46 #include <basic/ttstrhlp.hxx>
48 #include <basic/sbx.hxx>
49 #include <svtools/filedlg.hxx>
51 #include <osl/module.h>
55 #include "printer.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>
67 #include "runtime.hxx"
69 #include "sbintern.hxx"
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
;
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
;
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
)
108 static_bInsideFilter
= TRUE
;
110 ByteString
aMessage( pString
);
112 BOOL bIgnore
= FALSE
;
117 if ( aMessage
.Search( CByteString("Cannot open Configuration: Connector: unknown delegatee com.sun.star.connection.Connector.portal") ) != STRING_NOTFOUND
)
123 #if ! (OSL_DEBUG_LEVEL > 1)
124 if ( aMessage
.Search( CByteString("SelectAppIconPixmap") ) != STRING_NOTFOUND
)
127 if ( aMessage
.Search( CByteString("PropertySetRegistry::") ) != STRING_NOTFOUND
)
129 if ( aMessage
.Search( CByteString("property value missing") ) != STRING_NOTFOUND
)
131 if ( aMessage
.Search( CByteString("getDateFormatsImpl") ) != STRING_NOTFOUND
132 && aMessage
.Search( CByteString("no date formats") ) != STRING_NOTFOUND
)
134 if ( aMessage
.Search( CByteString("ucb::configureUcb(): Bad arguments") ) != STRING_NOTFOUND
)
136 if ( aMessage
.Search( CByteString("CreateInstance with arguments exception") ) != STRING_NOTFOUND
)
138 if ( aMessage
.Search( CByteString("AcquireTree failed") ) != STRING_NOTFOUND
)
145 static_bInsideFilter
= FALSE
;
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
);
159 aBasicApp
.DbgPrintMsgBox( pString
);
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
);
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
214 , "connector.uno" SAL_DLLEXTENSION
215 , "bridgefac.uno" SAL_DLLEXTENSION
216 , "remotebridge.uno" SAL_DLLEXTENSION
219 , SVLIBRARY( "dtransaqua" ) // Mac OS X Aqua uses a dedicated libdtransaqua
221 , SVLIBRARY( "dtransX11" ) // OBR
225 , SAL_MODULENAME( "sysdtrans" )
226 , SAL_MODULENAME( "ftransl" )
227 , SAL_MODULENAME( "dnd" )
232 uno::Reference
< XContentProviderManager
> InitializeUCB( void )
234 uno::Reference
< XMultiServiceFactory
> xSMgr
;
237 xSMgr
= uno::Reference
< XMultiServiceFactory
>(
238 defaultBootstrap_InitialComponentContext()->getServiceManager(),
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();
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 );
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( )
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");
315 ResMgr::SetReadStringHook( ReplaceStringHookProc
);
320 uno::Reference
< XContentProviderManager
> xUcb
= InitializeUCB();
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
;
336 aFileName
= "testtoolrc";
338 aFileName
= "testtool.ini";
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 );
384 // Help::EnableContextHelp();
385 // Help::EnableExtHelp();
386 // DeactivateExtHelp();
389 Accelerator
aAccel( SttResId( MAIN_ACCEL
) );
390 InsertAccel( &aAccel
);
391 pMainAccel
= &aAccel
;
394 pFrame
= new BasicFrame
;
395 aAccel
.SetSelectHdl( LINK( pFrame
, BasicFrame
, Accel
) );
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
) );
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();
427 printf( "unknown Exception not caught\n" );
428 InfoBox( NULL
, String::CreateFromAscii( "unknown Exception not caught" ) ).Execute();
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 */
448 for ( i
= 0 ; i
< Application::GetCommandLineParamCount() ; i
++ )
450 if ( Application::GetCommandLineParam( i
).Copy(0,4).CompareIgnoreCaseToAscii("-run") == COMPARE_EQUAL
452 || Application::GetCommandLineParam( i
).Copy(0,4).CompareIgnoreCaseToAscii("/run") == COMPARE_EQUAL
455 pFrame
->SetAutoRun( TRUE
);
456 else if ( Application::GetCommandLineParam( i
).Copy(0,7).CompareIgnoreCaseToAscii("-result") == COMPARE_EQUAL
458 || Application::GetCommandLineParam( i
).Copy(0,7).CompareIgnoreCaseToAscii("/result") == COMPARE_EQUAL
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() ) );
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
478 && Application::GetCommandLineParam( i
).Copy(0,1).CompareToAscii("/") != COMPARE_EQUAL
482 pFrame
->LoadFile( Application::GetCommandLineParam( i
) );
484 else if ( Application::GetCommandLineParam( i
).Copy(0,7).CompareIgnoreCaseToAscii("-result") == COMPARE_EQUAL
486 || Application::GetCommandLineParam( i
).Copy(0,7).CompareIgnoreCaseToAscii("/result") == COMPARE_EQUAL
489 { // Increment count to skip the parameter. This works even if it is not given
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
);
508 //////////////////////////////////////////////////////////////////////////
510 class FloatingExecutionStatus
: public FloatingWindow
513 FloatingExecutionStatus( Window
* pParent
);
514 void SetStatus( String aW
);
515 void SetAdditionalInfo( String aF
);
519 DECL_LINK(HideNow
, FloatingExecutionStatus
* );
521 FixedText aAdditionalInfo
;
525 FloatingExecutionStatus::FloatingExecutionStatus( Window
* pParent
)
526 : FloatingWindow( pParent
, SttResId(LOAD_CONF
) ),
527 aStatus( this, SttResId( WORK
) ),
528 aAdditionalInfo( this, SttResId( FILENAME
) )
531 aAusblend
.SetTimeoutHdl( LINK(this, FloatingExecutionStatus
, HideNow
) );
532 aAusblend
.SetTimeout(5000); // in ms
536 void FloatingExecutionStatus::SetStatus( String aW
)
538 Show( TRUE
, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
539 ToTop( TOTOP_NOGRABFOCUS
);
541 aStatus
.SetText( aW
);
544 void FloatingExecutionStatus::SetAdditionalInfo( String aF
)
546 Show( TRUE
, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
547 ToTop( TOTOP_NOGRABFOCUS
);
549 aAdditionalInfo
.SetText( aF
);
552 IMPL_LINK(FloatingExecutionStatus
, HideNow
, FloatingExecutionStatus
*, pFLC
)
554 (void) pFLC
; /* avoid warning about unused parameter */
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
)
568 , bAutoReload( FALSE
)
571 , pExecutionStatus( NULL
)
578 Application::SetDefDialogParent( this );
579 AlwaysEnableInput( TRUE
);
580 pBasic
= TTBasic::CreateMyBasic(); // depending on what was linked to the executable
586 if ( pBasic
->pTestObject
) // Are we the testtool?
588 // aAppIcon = Icon( ResId( RID_APPICON2 ) );
589 aAppName
= String( SttResId( IDS_APPNAME2
) );
593 // aAppIcon = Icon( ResId( RID_APPICON ) );
594 aAppName
= String( SttResId( IDS_APPNAME
) );
598 MenuBar
*pBar
= new MenuBar( SttResId( RID_APPMENUBAR
) );
601 pBar
->SetHighlightHdl( LINK( this, BasicFrame
, HighlightMenu
) );
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
) );
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
) );
656 pPrn
= new BasicPrinter
;
660 pList
= new EditList
;
661 pStatus
= new StatusLine( this );
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 );
679 aLineNum
.SetTimeoutHdl( LINK( this, BasicFrame
, ShowLineNr
) );
680 aLineNum
.SetTimeout(200);
684 aCheckFiles
.SetTimeout( 10000 );
685 aCheckFiles
.SetTimeoutHdl( LINK( this, BasicFrame
, CheckAllFiles
) );
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()
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");
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
);
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");
738 while( (p
= pList
->Remove() ) != NULL
)
741 MenuBar
*pBar
= GetMenuBar();
748 // delete pExecutionStatus;
753 void BasicFrame::Command( const CommandEvent
& rCEvt
)
755 switch( rCEvt
.GetCommand() ) {
756 case COMMAND_SHOWDIALOG
:
758 const CommandDialogData
* pData
= rCEvt
.GetDialogData();
761 const int nCommand
= pData
->GetDialogId();
765 case SHOWDIALOG_ID_PREFERENCES
:
766 Command( RID_OPTIONS
);
769 case SHOWDIALOG_ID_ABOUT
:
770 Command( RID_HELPABOUT
);
782 void BasicFrame::UpdateTitle()
786 if ( aAppMode
.Len() )
788 aTitle
.AppendAscii(" [");
790 aTitle
.AppendAscii("]");
792 aTitle
.AppendAscii(" - ");
797 IMPL_LINK( BasicFrame
, CheckAllFiles
, Timer
*, pTimer
)
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
)
812 pFocusWin
->GrabFocus();
818 BOOL
BasicFrame::IsAutoRun()
823 void BasicFrame::SetAutoRun( BOOL 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
:
840 case TT_EXECUTION_LEAVEWAIT
:
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() );*/
857 case TT_EXECUTION_HIDE_ACTION
:
859 /* if ( pExecutionStatus )
861 delete pExecutionStatus;
862 pExecutionStatus = NULL;
873 void BasicFrame::Resize()
875 Config
aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
876 aConf
.SetGroup("WinGeom");
877 aConf
.WriteKey("WinParams",GetWindowState());
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
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()
911 IMPL_LINK( BasicFrame
, CloseButtonClick
, void*, EMPTYARG
)
914 for ( p
= pList
->Last() ; p
&& p
->GetWinState() != TT_WIN_STATE_MAX
; p
= pList
->Prev() )
918 return Command( RID_FILECLOSE
, FALSE
);
921 IMPL_LINK( BasicFrame
, FloatButtonClick
, void*, EMPTYARG
)
924 for ( p
= pList
->Last() ; p
&& p
->GetWinState() != TT_WIN_STATE_MAX
; p
= pList
->Prev() )
927 p
->TitleButtonClick( TITLE_BUTTON_DOCKING
);
931 IMPL_LINK( BasicFrame
, HideButtonClick
, void*, EMPTYARG
)
934 for ( p
= pList
->Last() ; p
&& p
->GetWinState() != TT_WIN_STATE_MAX
; p
= pList
->Prev() )
937 p
->TitleButtonClick( TITLE_BUTTON_HIDE
);
941 void BasicFrame::WinShow_Hide()
943 if ( !pList
->Count() )
947 BOOL bWasFullscreen
= FALSE
;
948 for ( p
= pList
->Last() ; p
; p
= pList
->Prev() )
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
);
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
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
);
974 void BasicFrame::RemoveWindow( AppWin
*pWin
)
977 pList
->Remove( pWin
);
978 pWork
= pList
->Last();
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() ) );
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
);
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();
1028 USHORT nFreeID
= RID_WIN_FILE1
;
1029 while ( pWinMenu
->GetItemPos( nFreeID
) != MENU_ITEM_NOTFOUND
&& nFreeID
< RID_WIN_FILEn
)
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();
1049 void BasicFrame::FocusWindow( AppWin
*pWin
)
1052 pList
->Remove( pWin
);
1053 pList
->Insert( pWin
, LIST_APPEND
);
1054 pWin
->Minimize( FALSE
);
1056 aAppFile
= pWin
->GetText();
1060 pStatus
->LoadTaskToolBox();
1063 BOOL
BasicFrame::Close()
1065 if( bInBreak
|| Basic().IsRunning() )
1066 if( RET_NO
== QueryBox( this, SttResId( IDS_RUNNING
) ).Execute() )
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();
1085 } else return FALSE
;
1088 BOOL
BasicFrame::CloseAll()
1090 while ( pList
->Count() )
1091 if ( !pList
->Last()->Close() )
1096 BOOL
BasicFrame::CompileAll()
1099 for( p
= pList
->First(); p
; p
= pList
->Next() )
1100 if( p
->ISA(AppBasEd
) && !((AppBasEd
*)p
)->Compile() ) return FALSE
;
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
)
1111 aRet
= CUniString("~").Append( UniString::CreateFromInt32( nNr
) );
1112 else if ( nNr
== 10 )
1113 aRet
= CUniString("1~0");
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
)
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) ) ));
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
));
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();
1166 bAddSep
= pPopup
->GetItemPos( IDM_FILE_LRU1
) == MENU_ITEM_NOTFOUND
;
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)
1177 pPopup
->InsertSeparator();
1181 if ( pPopup
->GetItemPos( IDM_FILE_LRU1
+ i
-1 ) == MENU_ITEM_NOTFOUND
)
1182 pPopup
->InsertItem(IDM_FILE_LRU1
+ i
-1, FILENAME2MENU( i
, aFile
));
1184 pPopup
->SetItemText(IDM_FILE_LRU1
+ i
-1, FILENAME2MENU( i
, aFile
));
1188 while ( pPopup
->GetItemPos( IDM_FILE_LRU1
+ i
-1 ) != MENU_ITEM_NOTFOUND
)
1190 pPopup
->RemoveItem( pPopup
->GetItemPos( IDM_FILE_LRU1
+ i
-1 ) );
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
;
1217 ULONG n
= pBasic
->aErrors
.GetCurPos();
1220 if( USHORT(n
+1) == pBasic
->GetErrors() )
1223 pMenu
->EnableItem( RID_RUNNEXTERR
, bNext
);
1224 pMenu
->EnableItem( RID_RUNPREVERR
, bPrev
);
1225 pMenu
->CheckItem( RID_RUNDISAS
, bDisas
);
1227 pWork
->InitMenu( pMenu
);
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
);
1251 pStatus
->Message( aString
);
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
);
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 */
1283 if ( pWork
&& pWork
->ISA(AppBasEd
))
1285 aPos
= String::CreateFromInt32(pWork
->GetLineNr());
1287 pStatus
->Pos( aPos
);
1290 IMPL_LINK_INLINE_END( BasicFrame
, ShowLineNr
, AutoTimer
*, pTimer
)
1293 MsgEdit
* BasicFrame::GetMsgTree( String aLogFileName
)
1295 if ( FindErrorWin( aLogFileName
) )
1297 return FindErrorWin( aLogFileName
)->GetMsgTree();
1300 { // create new Window on the fly
1301 AppError
*pNewWindow
= new AppError( this, aLogFileName
);
1303 pNewWindow
->GrabFocus();
1304 return pNewWindow
->GetMsgTree();
1308 IMPL_LINK( BasicFrame
, Log
, TTLogMsg
*, pLogMsg
)
1310 GetMsgTree( pLogMsg
->aLogFileName
)->AddAnyMsg( pLogMsg
);
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();
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
);
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
;
1346 BOOL bSuccess
= TRUE
;
1349 p
= new AppError( this, aFilename
);
1351 else if ( bIsBasic
)
1353 p
= new AppBasEd( this, NULL
);
1354 bSuccess
= p
->Load( aFilename
);
1358 p
= new AppEdit( this );
1359 bSuccess
= p
->Load( aFilename
);
1373 long BasicFrame::Command( short nID
, BOOL bChecked
)
1379 AppBasEd
* p
= new AppBasEd( this, NULL
);
1382 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1387 if( QueryFileName( s
, FT_BASIC_SOURCE
| FT_RESULT_FILE
, FALSE
) ) {
1390 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1393 case RID_FILELOADLIB
:
1396 case RID_FILESAVELIB
:
1400 if( pWork
&& pWork
->Close() ){};
1401 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1406 pPrn
->Print( pWork
->GetText(), pWork
->pDataEdit
->GetText(), this );
1408 InfoBox( this, SttResId( IDS_NOPRINTERERROR
) ).Execute();
1415 InfoBox( this, SttResId( IDS_NOPRINTERERROR
) ).Execute();
1419 if( Close() ) aBasicApp
.Quit();
1424 nFlags
= SbDEBUG_BREAK
;
1426 case RID_RUNSTEPOVER
:
1427 nFlags
= SbDEBUG_STEPINTO
| SbDEBUG_STEPOVER
;
1429 case RID_RUNSTEPINTO
:
1430 nFlags
= SbDEBUG_STEPINTO
;
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
1438 x
= pWork
->GetLineNr();
1439 x
= ((AppBasEd
*)pWork
)->GetModule()->GetBPCount();
1441 x
= pModule
->SetBP(pWork
->GetLineNr());
1442 x
= pModule
->GetBPCount();
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
;
1455 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1456 if ( !Basic().IsRunning() || bInBreak
)
1459 if( pWork
&& pWork
->ISA(AppBasEd
) )
1461 p
= ((AppBasEd
*)pWork
);
1467 for ( w
= pList
->Last() ; w
? !w
->ISA(AppBasEd
) : FALSE
; w
= pList
->Prev() ) ;
1475 printf( "No file loaded to run.\n" );
1483 if( IsAutoSave() && !SaveAll() ) break;
1484 if( !CompileAll() ) break;
1486 pStatus
->Message( aString
);
1489 BasicDLL::SetDebugMode( TRUE
);
1490 Basic().ClearGlobalVars();
1492 BasicDLL::SetDebugMode( FALSE
);
1493 // If cancelled during Interactive=FALSE
1494 // BasicDLL::EnableBreak( TRUE );
1498 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN )); // after run
1500 case RID_RUNCOMPILE
:
1501 if( pWork
&& pWork
->ISA(AppBasEd
) && SaveAll() )
1503 ((AppBasEd
*)pWork
)->Compile();
1509 bDisas
= BOOL( !bChecked
);
1512 if ( Basic().IsRunning() && !bInBreak
)
1514 // pINST->CalcBreakCallLevel(SbDEBUG_STEPINTO);
1515 pINST
->nBreakCallLvl
= pINST
->nCallLvl
;
1522 case RID_RUNNEXTERR
:
1523 pErr
= pBasic
->aErrors
.Next();
1524 if( pErr
) pErr
->Show();
1526 case RID_RUNPREVERR
:
1527 pErr
= pBasic
->aErrors
.Prev();
1528 if( pErr
) pErr
->Show();
1533 OptionsDialog
*pOptions
= new OptionsDialog( this, SttResId(IDD_OPTIONS_DLG
) );
1537 case RID_DECLARE_HELPER
:
1538 InfoBox( this, SttResId( IDS_NOT_YET_IMPLEMENTED
) ).Execute();
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
);
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
);
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
);
1617 case RID_WINCASCADE
:
1619 for ( USHORT i
= 0 ; i
< pList
->Count() ; i
++ )
1621 pList
->GetObject( i
)->Cascade( i
);
1626 /* case RID_HELPTOPIC:
1627 if( pWork ) pWork->Help();
1630 aBasicApp.pHelp->Start( CUniString( "Keyboard" ) );
1633 aBasicApp.pHelp->Start( OOO_HELP_INDEX );
1636 aBasicApp.pHelp->Start( OOO_HELP_HELPONHELP );
1638 */ case RID_HELPABOUT
:
1640 SttResId
aResId( IDD_ABOUT_DIALOG
);
1641 if ( Basic().pTestObject
) // Are we TestTool?
1642 aResId
= SttResId( IDD_TT_ABOUT_DIALOG
);
1644 aResId
= SttResId( IDD_ABOUT_DIALOG
);
1645 AboutDialog
aAbout( this, aResId
);
1649 case RID_POPUPEDITVAR
:
1651 new VarEditDialog( this, pEditVar
);
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
);
1665 else if ( nID
>= IDM_FILE_LRU1
&& nID
<= IDM_FILE_LRUn
)
1667 String s
= MENU2FILENAME( GetMenuBar()->GetPopupMenu(RID_APPFILE
)->GetItemText(nID
) );
1671 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1675 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPEDIT )); // So daß Delete richtig ist
1677 pWork
->Command( CommandEvent( Point(), nID
) );
1678 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPEDIT )); // So daß Delete richtig ist
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
) )
1699 IMPL_LINK( BasicFrame
, ModuleWinExists
, String
*, pFilename
)
1701 return FindModuleWin( *pFilename
) != NULL
;
1704 AppBasEd
* BasicFrame::FindModuleWin( const String
& rName
)
1707 for( p
= pList
->First(); p
; p
= pList
->Next() )
1709 if( p
->ISA(AppBasEd
) && ((AppBasEd
*)p
)->GetModName() == rName
)
1710 return ((AppBasEd
*)p
);
1715 AppError
* BasicFrame::FindErrorWin( const String
& rName
)
1718 for( p
= pList
->First(); p
; p
= pList
->Next() )
1720 if( p
->ISA(AppError
) && ((AppError
*)p
)->GetText() == rName
)
1721 return ((AppError
*)p
);
1726 AppWin
* BasicFrame::FindWin( const String
& rName
)
1729 for( p
= pList
->First(); p
; p
= pList
->Next() )
1731 if( p
->GetText() == rName
)
1737 AppWin
* BasicFrame::FindWin( USHORT nWinId
)
1740 for( p
= pList
->First(); p
; p
= pList
->Next() )
1742 if( p
->GetWinId() == nWinId
)
1748 AppWin
* BasicFrame::IsWinValid( AppWin
* pMaybeWin
)
1751 for( p
= pList
->First(); p
; p
= pList
->Next() )
1753 if( p
== pMaybeWin
)
1759 IMPL_LINK( BasicFrame
, WriteString
, String
*, pString
)
1761 if ( pList
->Last() )
1763 pList
->Last()->pDataEdit
->ReplaceSelected( *pString
);
1770 class NewFileDialog
: public FileDialog
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
) )
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() )
1807 short NewFileDialog::Execute()
1809 BOOL bRet
= (BOOL
)FileDialog::Execute();
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
) );
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
) );
1860 aDlg
.SetCurFilter( String( SttResId( IDS_BASFILTER
) ) );
1862 aDlg
.FilterSelect(); // Selects the last used path
1864 if ( rName
.Len() > 0 )
1865 aDlg
.SetPath( rName
);
1867 if( aDlg
.Execute() )
1869 rName
= aDlg
.GetPath();
1870 /* rExtension = aDlg.GetCurrentFilter();
1872 for ( i = 0 ; i < aDlg.GetFilterCount() ; i++ )
1873 if ( rExtension == aDlg.GetFilterName( i ) )
1874 rExtension = aDlg.GetFilterType( i );
1877 } else return FALSE
;
1880 USHORT
BasicFrame::BreakHandler()
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
) ) );
1889 SetAppMode( String( SttResId ( IDS_APPMODE_RUN
) ) );
1890 // aBar.EnableItem( RID_APPEDIT, TRUE );
1891 // InitMenu(GetMenuBar()->GetPopupMenu( RID_APPRUN ));
1895 void BasicFrame::LoadLibrary()
1898 if( QueryFileName( s
, FT_BASIC_LIBRARY
, FALSE
) )
1901 SvFileStream
aStrm( s
, STREAM_STD_READ
);
1902 MyBasic
* pNew
= (MyBasic
*) SbxBase::Load( aStrm
);
1903 if( pNew
&& pNew
->ISA( MyBasic
) )
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
);
1918 ErrorBox( this, SttResId( IDS_READERROR
) ).Execute();
1923 void BasicFrame::SaveLibrary()
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
);
1939 xub_StrLen nInsertPos
= 0;
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
)
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();
1960 // if ( Resource::GetResManager()->IsAvailable( ResId( aValue ) ) )
1961 aString
= String( SttResId( (USHORT
)(aValue
.ToInt32()) ) );
1964 // DBG_ERROR( "Could not load resource!" );
1965 // return aResString;
1967 nInsertPos
= nStart
;
1969 aResult
.Erase( nStart
, nEnd
-nStart
+1 );
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
);
1979 aResult
.Erase( nStart
, nEnd
-nStart
+1 );
1983 DBG_ERROR( CByteString("Unknown replacement in String: ").Append( ByteString( aResult
.Copy(nStart
,nEnd
-nStart
), RTL_TEXTENCODING_UTF8
) ).GetBuffer() );
1984 nStartPos
= nStartPos
+ StartKenn
.Len();
1989 DBG_ASSERT( aString
.SearchAscii( "($Arg" ) == STRING_NOTFOUND
, "Argument missing in String");
1990 aResult
.Insert( aString
, nInsertPos
);