1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basic.hxx" 30*cdf0e10cSrcweir #include <vcl/svapp.hxx> 31*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 32*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 33*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 34*cdf0e10cSrcweir #include <vcl/sound.hxx> 35*cdf0e10cSrcweir #include <basic/basmgr.hxx> 36*cdf0e10cSrcweir #include <basic/sbx.hxx> 37*cdf0e10cSrcweir #include <basic/sbmod.hxx> 38*cdf0e10cSrcweir #include <basic/basrdll.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //#include <sv.hxx> 41*cdf0e10cSrcweir //#include <basic.hxx> 42*cdf0e10cSrcweir //#include <sostor.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // Defines for ToolBox-Id's 45*cdf0e10cSrcweir #define TB_NEW 1 46*cdf0e10cSrcweir #define TB_OPENSTORAGE 2 47*cdf0e10cSrcweir #define TB_SAVESTORAGE 3 48*cdf0e10cSrcweir #define TB_ORG 4 49*cdf0e10cSrcweir #define TB_CREATELIB1 10 50*cdf0e10cSrcweir #define TB_CREATELIB2 11 51*cdf0e10cSrcweir #define TB_CREATELIB3 12 52*cdf0e10cSrcweir #define TB_LOADLIB1 20 53*cdf0e10cSrcweir #define TB_LOADLIB2 21 54*cdf0e10cSrcweir #define TB_LOADLIB3 22 55*cdf0e10cSrcweir #define TB_STORELIBX 30 56*cdf0e10cSrcweir #define TB_UNLOADX 31 57*cdf0e10cSrcweir #define TB_LOADX 32 58*cdf0e10cSrcweir #define TB_EXECX 33 59*cdf0e10cSrcweir #define TB_REMOVEX 34 60*cdf0e10cSrcweir #define TB_REMOVEDELX 35 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #define TB_LIB0 40 63*cdf0e10cSrcweir #define TB_LIB1 41 64*cdf0e10cSrcweir #define TB_LIB2 42 65*cdf0e10cSrcweir #define TB_LIB3 43 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir const char* pLib1Str = "Lib1"; 68*cdf0e10cSrcweir const char* pLib2Str = "Lib2"; 69*cdf0e10cSrcweir const char* pLib3Str = "Lib3"; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // Test-Application 72*cdf0e10cSrcweir class TestApp : public Application 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir public: 75*cdf0e10cSrcweir virtual void Main( void ); 76*cdf0e10cSrcweir virtual void Main( int, char*[] ); 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // Test-Window with a ToolBox to choose a test from 80*cdf0e10cSrcweir // and the typically used virtual methods 81*cdf0e10cSrcweir class TestWindow : public WorkWindow 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir private: 84*cdf0e10cSrcweir ToolBox aToolBox; 85*cdf0e10cSrcweir BasicManager* pBasMgr; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir void CheckError(); 88*cdf0e10cSrcweir sal_uInt16 nLibX; 89*cdf0e10cSrcweir DECL_LINK( BasicErrorHdl, StarBASIC * ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir public: 93*cdf0e10cSrcweir TestWindow(); 94*cdf0e10cSrcweir ~TestWindow(); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir virtual void Paint( const Rectangle& ); 97*cdf0e10cSrcweir virtual void Resize(); 98*cdf0e10cSrcweir virtual void KeyInput( const KeyEvent& rKeyEvt ); 99*cdf0e10cSrcweir virtual void MouseMove( const MouseEvent& rMEvt ); 100*cdf0e10cSrcweir virtual void MouseButtonDown( const MouseEvent& rMEvt ); 101*cdf0e10cSrcweir virtual void MouseButtonUp( const MouseEvent& rMEvt ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir DECL_LINK( TBSelect, ToolBox * ); 104*cdf0e10cSrcweir void UpdateToolBox(); 105*cdf0e10cSrcweir void ShowInfo(); 106*cdf0e10cSrcweir }; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir TestWindow::~TestWindow() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir TestWindow::TestWindow() : 113*cdf0e10cSrcweir WorkWindow( NULL, WB_APP | WB_STDWORK | WB_3DLOOK | WB_CLIPCHILDREN ) , 114*cdf0e10cSrcweir aToolBox( this, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_LINESPACING ) ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir nLibX = 0; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir aToolBox.SetButtonType( BUTTON_TEXT ); 119*cdf0e10cSrcweir aToolBox.SetLineCount( 2 ); 120*cdf0e10cSrcweir aToolBox.SetPosPixel( Point( 0, 0 ) ); 121*cdf0e10cSrcweir aToolBox.SetSelectHdl( LINK( this, TestWindow, TBSelect ) ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir Font aFont; 124*cdf0e10cSrcweir aFont.SetName( "Helv" ); 125*cdf0e10cSrcweir aFont.SetSize( Size( 0, 6 ) ); 126*cdf0e10cSrcweir aFont.SetPitch( PITCH_VARIABLE ); 127*cdf0e10cSrcweir aFont.SetFamily( FAMILY_SWISS ); 128*cdf0e10cSrcweir aFont.SetTransparent( sal_True ); 129*cdf0e10cSrcweir aFont.SetAlign( ALIGN_TOP ); 130*cdf0e10cSrcweir aToolBox.SetFont( aFont ); 131*cdf0e10cSrcweir SetFont( aFont ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir aToolBox.InsertItem( TB_NEW, "New" ); 134*cdf0e10cSrcweir aToolBox.SetHelpText( TB_NEW, "New BasicManager" ); 135*cdf0e10cSrcweir aToolBox.InsertItem( TB_OPENSTORAGE, "Load" ); 136*cdf0e10cSrcweir aToolBox.SetHelpText( TB_OPENSTORAGE, "Load Storage D:\\MYSTORE.SVS" ); 137*cdf0e10cSrcweir aToolBox.InsertItem( TB_SAVESTORAGE, "Save" ); 138*cdf0e10cSrcweir aToolBox.SetHelpText( TB_SAVESTORAGE, "Save Storage D:\\MYSTORE.SVS" ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir aToolBox.InsertSeparator(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir aToolBox.InsertItem( TB_ORG, "Verwalten" ); 143*cdf0e10cSrcweir aToolBox.SetHelpText( TB_ORG, "Libaries verwalten" ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir aToolBox.InsertSeparator(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir aToolBox.InsertItem( TB_LIB0, "0" ); 148*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LIB0, "Aktuelle Lib: STANDARD" ); 149*cdf0e10cSrcweir aToolBox.InsertItem( TB_LIB1, "1" ); 150*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LIB1, "Aktuelle Lib: 1" ); 151*cdf0e10cSrcweir aToolBox.InsertItem( TB_LIB2, "2" ); 152*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LIB2, "Aktuelle Lib: 2" ); 153*cdf0e10cSrcweir aToolBox.InsertItem( TB_LIB3, "3" ); 154*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LIB3, "Aktuelle Lib: 3" ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir aToolBox.InsertBreak(); 157*cdf0e10cSrcweir aToolBox.InsertItem( TB_CREATELIB1, "CreateLib1" ); 158*cdf0e10cSrcweir aToolBox.SetHelpText( TB_CREATELIB1, "Create Libary LIB1" ); 159*cdf0e10cSrcweir aToolBox.InsertItem( TB_CREATELIB2, "CreateLib2" ); 160*cdf0e10cSrcweir aToolBox.SetHelpText( TB_CREATELIB2, "Create Libary LIB2" ); 161*cdf0e10cSrcweir aToolBox.InsertItem( TB_CREATELIB3, "CreateLib3" ); 162*cdf0e10cSrcweir aToolBox.SetHelpText( TB_CREATELIB3, "Create Libary LIB3" ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir aToolBox.InsertSeparator(); 165*cdf0e10cSrcweir aToolBox.InsertItem( TB_LOADLIB1, "LoadLib1" ); 166*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LOADLIB1, "Load Libary LIB1" ); 167*cdf0e10cSrcweir aToolBox.InsertItem( TB_LOADLIB2, "LoadLib2" ); 168*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LOADLIB2, "Load Libary LIB2" ); 169*cdf0e10cSrcweir aToolBox.InsertItem( TB_LOADLIB3, "LoadLib3" ); 170*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LOADLIB3, "Load Libary LIB3" ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir aToolBox.InsertSeparator(); 173*cdf0e10cSrcweir aToolBox.InsertItem( TB_STORELIBX, "StoreLibX" ); 174*cdf0e10cSrcweir aToolBox.SetHelpText( TB_STORELIBX, "Store Libary LIBX" ); 175*cdf0e10cSrcweir aToolBox.InsertItem( TB_UNLOADX, "UnloadX" ); 176*cdf0e10cSrcweir aToolBox.SetHelpText( TB_UNLOADX, "Unload Libary LIBX" ); 177*cdf0e10cSrcweir aToolBox.InsertItem( TB_LOADX, "LoadX" ); 178*cdf0e10cSrcweir aToolBox.SetHelpText( TB_LOADX, "Load Libary LIBX" ); 179*cdf0e10cSrcweir aToolBox.InsertItem( TB_EXECX, "ExecX" ); 180*cdf0e10cSrcweir aToolBox.SetHelpText( TB_EXECX, "Execute 'Libary' LIBX" ); 181*cdf0e10cSrcweir aToolBox.InsertItem( TB_REMOVEX, "RemoveX" ); 182*cdf0e10cSrcweir aToolBox.SetHelpText( TB_REMOVEX, "Remove Libary LIBX" ); 183*cdf0e10cSrcweir aToolBox.InsertItem( TB_REMOVEDELX, "RemDelX" ); 184*cdf0e10cSrcweir aToolBox.SetHelpText( TB_REMOVEDELX, "Remove and delete Libary LIBX" ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir pBasMgr = 0; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir Show(); 189*cdf0e10cSrcweir UpdateToolBox(); 190*cdf0e10cSrcweir aToolBox.Show(); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir void TestWindow::ShowInfo() 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir Invalidate(); 195*cdf0e10cSrcweir Update(); 196*cdf0e10cSrcweir long nH = GetTextSize( "X" ).Height(); 197*cdf0e10cSrcweir if ( pBasMgr ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir Point aPos( 10, aToolBox.GetSizePixel().Height()+5 ); 200*cdf0e10cSrcweir for ( sal_uInt16 nLib = 0; nLib < pBasMgr->GetLibCount(); nLib++ ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir String aOutStr( nLib ); 203*cdf0e10cSrcweir aOutStr +=": "; 204*cdf0e10cSrcweir StarBASIC* pL = pBasMgr->GetLib( nLib ); 205*cdf0e10cSrcweir aOutStr += '['; 206*cdf0e10cSrcweir aOutStr += pBasMgr->GetLibName( nLib ); 207*cdf0e10cSrcweir aOutStr += "]<"; 208*cdf0e10cSrcweir if ( pL ) 209*cdf0e10cSrcweir aOutStr += pL->GetName(); 210*cdf0e10cSrcweir else 211*cdf0e10cSrcweir aOutStr += "NoLoaded"; 212*cdf0e10cSrcweir aOutStr += ">, Storage='"; 213*cdf0e10cSrcweir aOutStr += pBasMgr->GetLibStorageName( nLib ); 214*cdf0e10cSrcweir aOutStr += "', bLoaded="; 215*cdf0e10cSrcweir aOutStr += (sal_uInt16)pBasMgr->IsLibLoaded( nLib ); 216*cdf0e10cSrcweir DrawText( aPos, aOutStr ); 217*cdf0e10cSrcweir aPos.Y() += nH; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir void TestWindow::UpdateToolBox() 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // View of some buttons as checked or disabled if 225*cdf0e10cSrcweir // wished by tests 226*cdf0e10cSrcweir aToolBox.EnableItem( TB_ORG, (sal_Bool)(sal_uIntPtr)pBasMgr ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir aToolBox.EnableItem( TB_CREATELIB1, (sal_Bool)(sal_uIntPtr)pBasMgr ); 229*cdf0e10cSrcweir aToolBox.EnableItem( TB_CREATELIB2, (sal_Bool)(sal_uIntPtr)pBasMgr ); 230*cdf0e10cSrcweir aToolBox.EnableItem( TB_CREATELIB3, (sal_Bool)(sal_uIntPtr)pBasMgr ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir aToolBox.EnableItem( TB_LOADLIB1, (sal_Bool)(sal_uIntPtr)pBasMgr ); 233*cdf0e10cSrcweir aToolBox.EnableItem( TB_LOADLIB2, (sal_Bool)(sal_uIntPtr)pBasMgr ); 234*cdf0e10cSrcweir aToolBox.EnableItem( TB_LOADLIB3, (sal_Bool)(sal_uIntPtr)pBasMgr ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir aToolBox.EnableItem( TB_STORELIBX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 237*cdf0e10cSrcweir aToolBox.EnableItem( TB_EXECX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 238*cdf0e10cSrcweir aToolBox.EnableItem( TB_UNLOADX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 239*cdf0e10cSrcweir aToolBox.EnableItem( TB_LOADX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 240*cdf0e10cSrcweir aToolBox.EnableItem( TB_REMOVEX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 241*cdf0e10cSrcweir aToolBox.EnableItem( TB_REMOVEDELX, (sal_Bool)(sal_uIntPtr)pBasMgr ); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir aToolBox.CheckItem( TB_LIB0, nLibX == 0 ); 244*cdf0e10cSrcweir aToolBox.CheckItem( TB_LIB1, nLibX == 1 ); 245*cdf0e10cSrcweir aToolBox.CheckItem( TB_LIB2, nLibX == 2 ); 246*cdf0e10cSrcweir aToolBox.CheckItem( TB_LIB3, nLibX == 3 ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir IMPL_LINK( TestWindow, TBSelect, ToolBox *, p ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir sal_uInt16 nId = aToolBox.GetCurItemId(); 252*cdf0e10cSrcweir sal_Bool bChecked = aToolBox.IsItemChecked( nId ); 253*cdf0e10cSrcweir switch ( nId ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir case TB_NEW: 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir delete pBasMgr; 258*cdf0e10cSrcweir pBasMgr = new BasicManager( new StarBASIC ); 259*cdf0e10cSrcweir pBasMgr->SetStorageName( "d:\\mystore.svs" ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir break; 262*cdf0e10cSrcweir case TB_OPENSTORAGE: 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir delete pBasMgr; 265*cdf0e10cSrcweir SvStorageRef xStorage = new SvStorage( "d:\\mystore.svs", STREAM_READ | STREAM_SHARE_DENYWRITE ); 266*cdf0e10cSrcweir DBG_ASSERT( xStorage.Is(), "Kein Storage!" ); 267*cdf0e10cSrcweir pBasMgr = new BasicManager( *xStorage ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir break; 270*cdf0e10cSrcweir case TB_SAVESTORAGE: 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir if ( pBasMgr) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir SvStorageRef xStorage = new SvStorage( "d:\\mystore.svs" ); 275*cdf0e10cSrcweir DBG_ASSERT( xStorage.Is(), "Kein Storage!" ); 276*cdf0e10cSrcweir pBasMgr->Store( *xStorage ); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir break; 280*cdf0e10cSrcweir case TB_ORG: 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir if ( pBasMgr) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir InfoBox( 0, "Organisieren..." ).Execute(); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir break; 288*cdf0e10cSrcweir case TB_CREATELIB1: 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir if ( pBasMgr ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir sal_uInt16 nLib = pBasMgr->GetLibId( pBasMgr->CreateLib( pLib1Str ) ); 293*cdf0e10cSrcweir if ( nLib != LIB_NOTFOUND ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir pBasMgr->SetLibStorageName( nLib, "d:\\mystore.svs" ); 296*cdf0e10cSrcweir StarBASIC* pLib = pBasMgr->GetLib( pLib1Str ); 297*cdf0e10cSrcweir DBG_ASSERT( pLib, "Lib?!" ); 298*cdf0e10cSrcweir String aSource( "Sub SubInLib1Mod1\nprint\"XXX\"\nEnd Sub"); 299*cdf0e10cSrcweir SbModule* pM = pLib->MakeModule( "ModLib1", aSource ); 300*cdf0e10cSrcweir DBG_ASSERT( pM, "Modul?" ); 301*cdf0e10cSrcweir pLib->Compile( pM ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir else 304*cdf0e10cSrcweir InfoBox( 0, "CreateLibary fehlgeschlagen..." ).Execute(); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir break; 308*cdf0e10cSrcweir case TB_CREATELIB2: 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir if ( pBasMgr ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir sal_uInt16 nLib = pBasMgr->GetLibId( pBasMgr->CreateLib( pLib2Str ) ); 313*cdf0e10cSrcweir if ( nLib != LIB_NOTFOUND ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir pBasMgr->SetLibStorageName( nLib, "d:\\mystore.svs" ); 316*cdf0e10cSrcweir StarBASIC* pLib = pBasMgr->GetLib( pLib2Str ); 317*cdf0e10cSrcweir DBG_ASSERT( pLib, "Lib?!" ); 318*cdf0e10cSrcweir SbModule* pM = pLib->MakeModule( "ModuleLib2", "Sub SubInLib2\n print \"Tralala\" \nEnd Sub\n" ); 319*cdf0e10cSrcweir pLib->Compile( pM ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir else 322*cdf0e10cSrcweir InfoBox( 0, "CreateLibary fehlgeschlagen..." ).Execute(); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir break; 326*cdf0e10cSrcweir case TB_CREATELIB3: 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir if ( pBasMgr ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir // liegt in einem anderen Storage !!! 331*cdf0e10cSrcweir sal_uInt16 nLib = pBasMgr->GetLibId( pBasMgr->CreateLib( pLib3Str ) ); 332*cdf0e10cSrcweir if ( nLib != LIB_NOTFOUND ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir pBasMgr->SetLibStorageName( nLib, "d:\\mystore2.svs" ); 335*cdf0e10cSrcweir StarBASIC* pLib = pBasMgr->GetLib( pLib3Str ); 336*cdf0e10cSrcweir DBG_ASSERT( pLib, "Lib?!" ); 337*cdf0e10cSrcweir SbModule* pM = pLib->MakeModule( "ModuleLib2", "Sub XYZInLib3\n print \"?!\" \nEnd Sub\n" ); 338*cdf0e10cSrcweir pLib->Compile( pM ); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir else 341*cdf0e10cSrcweir InfoBox( 0, "CreateLibary fehlgeschlagen..." ).Execute(); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir break; 345*cdf0e10cSrcweir case TB_LOADLIB1: 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir if ( pBasMgr ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir SvStorageRef xStorage = new SvStorage( "d:\\mystore.svs" ); 350*cdf0e10cSrcweir if ( !pBasMgr->AddLib( *xStorage, pLib1Str, sal_False ) ) 351*cdf0e10cSrcweir Sound::Beep(); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir break; 355*cdf0e10cSrcweir case TB_LOADLIB2: 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir if ( pBasMgr ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir SvStorageRef xStorage = new SvStorage( "d:\\mystore.svs" ); 360*cdf0e10cSrcweir if ( !pBasMgr->AddLib( *xStorage, pLib2Str, sal_False ) ) 361*cdf0e10cSrcweir Sound::Beep(); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir break; 365*cdf0e10cSrcweir case TB_LOADLIB3: 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir if ( pBasMgr ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir // liegt in einem anderen Storage !!! 370*cdf0e10cSrcweir SvStorageRef xStorage = new SvStorage( "d:\\mystore2.svs" ); 371*cdf0e10cSrcweir if ( !pBasMgr->AddLib( *xStorage, pLib3Str, sal_False ) ) 372*cdf0e10cSrcweir Sound::Beep(); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir break; 376*cdf0e10cSrcweir case TB_STORELIBX: 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir if ( pBasMgr ) 379*cdf0e10cSrcweir pBasMgr->StoreLib( nLibX ); 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir break; 382*cdf0e10cSrcweir case TB_UNLOADX: 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir if ( pBasMgr ) 385*cdf0e10cSrcweir pBasMgr->UnloadLib( nLibX ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir break; 388*cdf0e10cSrcweir case TB_LOADX: 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir if ( pBasMgr ) 391*cdf0e10cSrcweir pBasMgr->LoadLib( nLibX ); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir break; 394*cdf0e10cSrcweir case TB_REMOVEX: 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir if ( pBasMgr ) 397*cdf0e10cSrcweir pBasMgr->RemoveLib( nLibX, sal_False ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir break; 400*cdf0e10cSrcweir case TB_REMOVEDELX: 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir if ( pBasMgr ) 403*cdf0e10cSrcweir pBasMgr->RemoveLib( nLibX, sal_True ); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir break; 406*cdf0e10cSrcweir case TB_EXECX: 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir if ( pBasMgr ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir StarBASIC* pBasic = pBasMgr->GetLib( nLibX ); 411*cdf0e10cSrcweir if ( pBasic && pBasic->GetModules()->Count() ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir pBasic->SetErrorHdl( LINK( this, TestWindow, BasicErrorHdl ) ); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir SbModule* pMod = (SbModule*)pBasic->GetModules()->Get( 0 ); 416*cdf0e10cSrcweir if ( pMod && pMod->GetMethods()->Count() ) 417*cdf0e10cSrcweir pMod->GetMethods()->Get(0)->GetInteger(); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir break; 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir case TB_LIB0: nLibX = 0; 424*cdf0e10cSrcweir break; 425*cdf0e10cSrcweir case TB_LIB1: nLibX = 1; 426*cdf0e10cSrcweir break; 427*cdf0e10cSrcweir case TB_LIB2: nLibX = 2; 428*cdf0e10cSrcweir break; 429*cdf0e10cSrcweir case TB_LIB3: nLibX = 3; 430*cdf0e10cSrcweir break; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir UpdateToolBox(); 434*cdf0e10cSrcweir CheckError(); 435*cdf0e10cSrcweir ShowInfo(); 436*cdf0e10cSrcweir return 0; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir void TestWindow::CheckError() 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir if ( pBasMgr ) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir BasicError* pError = pBasMgr->GetFirstError(); 444*cdf0e10cSrcweir while ( pError ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir String aErrorStr; 447*cdf0e10cSrcweir String aReasonStr; 448*cdf0e10cSrcweir switch ( pError->GetErrorId() ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir case BASERR_ID_STDLIBOPEN: 451*cdf0e10cSrcweir aErrorStr = "Standard-Lib konnte nicht geoffnet werden."; 452*cdf0e10cSrcweir break; 453*cdf0e10cSrcweir case BASERR_ID_STDLIBSAVE: 454*cdf0e10cSrcweir aErrorStr = "Standard-Lib konnte nicht gespeichert werden."; 455*cdf0e10cSrcweir break; 456*cdf0e10cSrcweir case BASERR_ID_LIBLOAD: 457*cdf0e10cSrcweir aErrorStr = "Lib konnte nicht geoffnet werden."; 458*cdf0e10cSrcweir break; 459*cdf0e10cSrcweir case BASERR_ID_LIBCREATE: 460*cdf0e10cSrcweir aErrorStr = "Lib konnte nicht erzeugt werden."; 461*cdf0e10cSrcweir break; 462*cdf0e10cSrcweir case BASERR_ID_LIBSAVE: 463*cdf0e10cSrcweir aErrorStr = "Lib konnte nicht gespeichert werden."; 464*cdf0e10cSrcweir break; 465*cdf0e10cSrcweir case BASERR_ID_MGROPEN: 466*cdf0e10cSrcweir aErrorStr = "Manager konnte nicht geladen werden."; 467*cdf0e10cSrcweir break; 468*cdf0e10cSrcweir case BASERR_ID_MGRSAVE: 469*cdf0e10cSrcweir aErrorStr = "Manager konnte nicht gespeichert werden."; 470*cdf0e10cSrcweir break; 471*cdf0e10cSrcweir case BASERR_ID_UNLOADLIB: 472*cdf0e10cSrcweir aErrorStr = "Libary konnte nicht entladen werden."; 473*cdf0e10cSrcweir break; 474*cdf0e10cSrcweir case BASERR_ID_REMOVELIB: 475*cdf0e10cSrcweir aErrorStr = "Libary konnte nicht entfernt werden."; 476*cdf0e10cSrcweir break; 477*cdf0e10cSrcweir default: 478*cdf0e10cSrcweir aErrorStr = "Unbekannter Fehler!"; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir switch ( pError->GetReason() ) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir case BASERR_REASON_OPENSTORAGE: 484*cdf0e10cSrcweir aReasonStr = "Der Storage konnte nicht geoeffnet werden"; 485*cdf0e10cSrcweir break; 486*cdf0e10cSrcweir case BASERR_REASON_OPENLIBSTORAGE: 487*cdf0e10cSrcweir aReasonStr = "Der Lib-Storage konnte nicht geoeffnet werden"; 488*cdf0e10cSrcweir break; 489*cdf0e10cSrcweir case BASERR_REASON_OPENMGRSTREAM: 490*cdf0e10cSrcweir aReasonStr = "Der Manager-Stream konnte nicht geoeffnet werden"; 491*cdf0e10cSrcweir break; 492*cdf0e10cSrcweir case BASERR_REASON_OPENLIBSTREAM: 493*cdf0e10cSrcweir aReasonStr = "Der Basic-Stream konnte nicht geoeffnet werden"; 494*cdf0e10cSrcweir break; 495*cdf0e10cSrcweir case BASERR_REASON_STDLIB: 496*cdf0e10cSrcweir aReasonStr = "STANDARD-Lib"; 497*cdf0e10cSrcweir break; 498*cdf0e10cSrcweir case BASERR_REASON_BASICLOADERROR: 499*cdf0e10cSrcweir aReasonStr = "Fehler beim Laden des Basics"; 500*cdf0e10cSrcweir default: 501*cdf0e10cSrcweir aReasonStr = " - "; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir String aErr( aErrorStr ); 505*cdf0e10cSrcweir aErr += "\nGrund: "; 506*cdf0e10cSrcweir aErr += aReasonStr; 507*cdf0e10cSrcweir InfoBox( 0, aErr ).Execute(); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir pError = pBasMgr->GetNextError(); 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir pBasMgr->ClearErrors(); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir void __EXPORT TestWindow::Paint( const Rectangle& rRec ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir void __EXPORT TestWindow::Resize() 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir Size aTBSz = aToolBox.CalcWindowSizePixel(); 522*cdf0e10cSrcweir aToolBox.SetSizePixel( Size( GetOutputSizePixel().Width(), aTBSz.Height()) ); 523*cdf0e10cSrcweir Invalidate(); 524*cdf0e10cSrcweir ShowInfo(); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir void __EXPORT TestWindow::KeyInput( const KeyEvent& rKEvt ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir char nCharCode = rKEvt.GetCharCode(); 530*cdf0e10cSrcweir sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir // Nur bei Alt-Return 533*cdf0e10cSrcweir if ( ( nCode == KEY_RETURN ) && rKEvt.GetKeyCode().IsMod2() ) 534*cdf0e10cSrcweir ; 535*cdf0e10cSrcweir else 536*cdf0e10cSrcweir WorkWindow::KeyInput( rKEvt ); 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir UpdateToolBox(); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir void __EXPORT TestWindow::MouseMove( const MouseEvent& rMEvt ) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir void __EXPORT TestWindow::MouseButtonDown( const MouseEvent& rMEvt ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir ShowInfo(); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir void __EXPORT TestWindow::MouseButtonUp( const MouseEvent& rMEvt ) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir UpdateToolBox(); 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir IMPL_LINK( TestWindow, BasicErrorHdl, StarBASIC *, pBasic ) 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir String aErrorText( pBasic->GetErrorText() ); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir String aErrorTextPrefix; 560*cdf0e10cSrcweir if( pBasic->IsCompilerError() ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir aErrorTextPrefix = "Compilererror: "; 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir else 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir aErrorTextPrefix = "Runtimeerror: "; 567*cdf0e10cSrcweir aErrorTextPrefix += pBasic->GetErrorCode(); 568*cdf0e10cSrcweir aErrorTextPrefix += " "; 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir InfoBox( 0, String( aErrorTextPrefix + aErrorText ) ).Execute(); 572*cdf0e10cSrcweir return 0; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir void __EXPORT TestApp::Main( void ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir Main( 0, NULL ); 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir void __EXPORT TestApp::Main( int, char*[] ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir BasicDLL aBasiDLL; 583*cdf0e10cSrcweir SvFactory::Init(); 584*cdf0e10cSrcweir EnableSVLook(); 585*cdf0e10cSrcweir TestWindow aWindow; 586*cdf0e10cSrcweir Execute(); 587*cdf0e10cSrcweir SvFactory::DeInit(); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir TestApp aTestApp; 592