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