merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / basidesh.cxx
blob2727c9029eed4af6b2955a8cf7451220b134c14a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basidesh.cxx,v $
10 * $Revision: 1.49.26.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_basctl.hxx"
34 // CLOOKS:
35 //#define _MENUBTN_HXX
36 #define _SPIN_HXX
37 #define _PRVWIN_HXX
38 //#define _FIELD_HXX ***
39 //#define _TAB_HXX ***
40 #define _DIALOGS_HXX
41 #define _SVRTF_HXX
42 #define _ISETBRW_HXX
43 #define _VCTRLS_HXX
44 #define SI_NOCONTROL
45 #define SI_NOSBXCONTROLS
47 #define ITEMID_SIZE 0
49 // Falls ohne PCH's:
50 #include <ide_pch.hxx>
53 #define _SOLAR__PRIVATE 1
54 #include <basic/sbx.hxx>
55 #include <svtools/hint.hxx>
56 #include <tools/diagnose_ex.h>
57 #include <basidesh.hrc>
58 #include <basidesh.hxx>
59 #include <basdoc.hxx>
60 #include <basobj.hxx>
61 #include <bastypes.hxx>
62 #include <basicbox.hxx>
63 #include <objdlg.hxx>
64 #include <sbxitem.hxx>
65 #include <tbxctl.hxx>
66 #include <iderdll2.hxx>
67 #include <basidectrlr.hxx>
68 #include <localizationmgr.hxx>
70 #define BasicIDEShell
71 #define SFX_TYPEMAP
72 #include <idetemp.hxx>
73 #include <basslots.hxx>
74 #include <iderdll.hxx>
75 #include <svx/pszctrl.hxx>
76 #include <svx/insctrl.hxx>
77 #include <svx/srchdlg.hxx>
78 #include <svx/lboxctrl.hxx>
79 #include <svx/tbcontrl.hxx>
80 #include <com/sun/star/script/XLibraryContainer.hpp>
81 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
82 #include <com/sun/star/container/XNameContainer.hpp>
83 #include <com/sun/star/container/XContainer.hpp>
84 #include <com/sun/star/container/XContainerListener.hpp>
85 #include <com/sun/star/script/XLibraryContainer.hpp>
87 #include <svx/xmlsecctrl.hxx>
89 using namespace ::com::sun::star::uno;
90 using namespace ::com::sun::star;
91 using ::rtl::OUString;
93 static const rtl::OUString sStandardLibName( rtl::OUString::createFromAscii("Standard") );
95 typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
97 class ContainerListenerImpl : public ContainerListenerBASE
99 BasicIDEShell* mpShell;
100 public:
102 ContainerListenerImpl( BasicIDEShell* pShell ) : mpShell( pShell ) {}
104 ~ContainerListenerImpl()
108 void addContainerListener( const ScriptDocument& rScriptDocument )
110 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
111 if ( rScriptDocument.isDocument() && xContainer.is() )
113 uno::Reference< container::XContainerListener > xContainerListener( this );
116 xContainer->addContainerListener( xContainerListener );
118 catch( uno::Exception& ) {}
121 void removeContainerListener( const ScriptDocument& rScriptDocument )
123 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
124 if ( rScriptDocument.isDocument(), xContainer.is() )
126 uno::Reference< container::XContainerListener > xContainerListener( this );
129 xContainer->removeContainerListener( xContainerListener );
131 catch( uno::Exception& ) {}
135 // XEventListener
136 virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
138 // XContainerListener
139 virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
141 rtl::OUString sModuleName;
142 if( mpShell && ( Event.Accessor >>= sModuleName ) )
143 mpShell->FindBasWin( mpShell->m_aCurDocument, sStandardLibName, sModuleName, TRUE, FALSE );
145 virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
146 virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
148 rtl::OUString sModuleName;
149 if( mpShell && ( Event.Accessor >>= sModuleName ) )
151 IDEBaseWindow* pWin = mpShell->FindWindow( mpShell->m_aCurDocument, sStandardLibName, sModuleName, BASICIDE_TYPE_MODULE, TRUE );
152 if( pWin )
153 mpShell->RemoveWindow( pWin, FALSE, TRUE );
159 TYPEINIT1( BasicIDEShell, SfxViewShell );
161 SFX_IMPL_VIEWFACTORY( BasicIDEShell, IDEResId( SVX_INTERFACE_BASIDE_VIEWSH ) )
163 SFX_VIEW_REGISTRATION( BasicDocShell );
167 // MI: Prinzipiel IDL, aber ich lieber doch nicht?
168 // SFX_IMPL_ /*IDL_*/ INTERFACE( BasicIDEShell, SfxViewShell, IDEResId( RID_STR_IDENAME ) )
169 SFX_IMPL_INTERFACE( BasicIDEShell, SfxViewShell, IDEResId( RID_STR_IDENAME ) )
171 SFX_CHILDWINDOW_REGISTRATION( SID_SEARCH_DLG );
172 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_SHOW_PROPERTYBROWSER, BASICIDE_UI_FEATURE_SHOW_BROWSER);
173 SFX_POPUPMENU_REGISTRATION( IDEResId( RID_POPUP_DLGED ) );
178 #define IDE_VIEWSHELL_FLAGS SFX_VIEW_MAXIMIZE_FIRST|SFX_VIEW_CAN_PRINT|SFX_VIEW_NO_NEWWINDOW
181 // Hack for #101048
182 static sal_Int32 GnBasicIDEShellCount;
183 sal_Int32 getBasicIDEShellCount( void )
184 { return GnBasicIDEShellCount; }
186 BasicIDEShell::BasicIDEShell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
187 SfxViewShell( pFrame_, IDE_VIEWSHELL_FLAGS ),
188 m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
189 aHScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG ) ),
190 aVScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG ) ),
191 aScrollBarBox( &GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE ) ),
192 m_bAppBasicModified( FALSE ),
193 m_aNotifier( *this )
195 m_xLibListener = new ContainerListenerImpl( this );
196 Init();
197 GnBasicIDEShellCount++;
202 void BasicIDEShell::Init()
204 TbxControls::RegisterControl( SID_CHOOSE_CONTROLS );
205 SvxPosSizeStatusBarControl::RegisterControl();
206 SvxInsertStatusBarControl::RegisterControl();
207 XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
208 SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
209 SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
211 SvxSearchDialogWrapper::RegisterChildWindow( sal_False );
213 IDE_DLL()->GetExtraData()->ShellInCriticalSection() = TRUE;
215 SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BasicIDE" ) ) );
216 SetHelpId( SVX_INTERFACE_BASIDE_VIEWSH );
218 SFX_APP()->EnterBasicCall();
220 LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
221 LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
223 CreateModulWindowLayout();
225 GetViewFrame()->GetWindow().SetBackground();
227 pCurWin = 0;
228 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
229 pObjectCatalog = 0;
230 bCreatingWindow = FALSE;
232 m_pCurLocalizationMgr = NULL;
234 pTabBar = new BasicIDETabBar( &GetViewFrame()->GetWindow() );
235 pTabBar->SetSplitHdl( LINK( this, BasicIDEShell, TabBarSplitHdl ) );
236 bTabBarSplitted = FALSE;
238 nCurKey = 100;
239 InitScrollBars();
240 InitTabBar();
242 SetCurLib( ScriptDocument::getApplicationScriptDocument(), String::CreateFromAscii( "Standard" ), false, false );
244 if ( IDE_DLL() && IDE_DLL()->pShell == NULL )
245 IDE_DLL()->pShell = this;
247 IDE_DLL()->GetExtraData()->ShellInCriticalSection() = FALSE;
249 // It's enough to create the controller ...
250 // It will be public by using magic :-)
251 new BasicIDEController( this );
253 // Force updating the title ! Because it must be set to the controller
254 // it has to be called directly after creating those controller.
255 SetMDITitle ();
257 UpdateWindows();
260 __EXPORT BasicIDEShell::~BasicIDEShell()
262 m_aNotifier.dispose();
264 if ( IDE_DLL() && IDE_DLL()->pShell == this )
265 IDE_DLL()->pShell = NULL;
267 // Damit bei einem Basic-Fehler beim Speichern die Shell nicht sofort
268 // wieder hoch kommt:
269 IDE_DLL()->GetExtraData()->ShellInCriticalSection() = TRUE;
271 SetWindow( 0 );
272 SetCurWindow( 0 );
274 // Alle Fenster zerstoeren:
275 IDEBaseWindow* pWin = aIDEWindowTable.First();
276 while ( pWin )
278 // Kein Store, passiert bereits, wenn die BasicManager zerstoert werden.
279 delete pWin;
280 pWin = aIDEWindowTable.Next();
283 aIDEWindowTable.Clear();
284 delete pTabBar;
285 delete pObjectCatalog;
286 DestroyModulWindowLayout();
288 ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
289 // Destroy all ContainerListeners for Basic Container.
290 if ( pListener )
291 pListener->removeContainerListener( m_aCurDocument );
293 // MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die
294 // ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war.
295 // GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
297 SFX_APP()->LeaveBasicCall();
298 IDE_DLL()->GetExtraData()->ShellInCriticalSection() = FALSE;
300 GnBasicIDEShellCount--;
303 void BasicIDEShell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
305 UpdateWindows();
308 void BasicIDEShell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
310 UpdateWindows();
313 void BasicIDEShell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
315 StoreAllWindowData();
318 void BasicIDEShell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
320 // not interested in
323 void BasicIDEShell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
325 StoreAllWindowData();
328 void BasicIDEShell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
330 // not interested in
333 void BasicIDEShell::onDocumentClosed( const ScriptDocument& _rDocument )
335 if ( !_rDocument.isValid() )
336 return;
338 bool bSetCurWindow = false;
339 bool bSetCurLib = ( _rDocument == m_aCurDocument );
341 // remove all windows which belong to this document
342 for ( ULONG nWin = aIDEWindowTable.Count(); nWin; )
344 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( --nWin );
345 if ( pWin->IsDocument( _rDocument ) )
347 if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
349 pWin->AddStatus( BASWIN_TOBEKILLED );
350 pWin->Hide();
351 StarBASIC::Stop();
352 // there's no notify
353 pWin->BasicStopped();
355 else
357 pWin->StoreData();
358 if ( pWin == pCurWin )
359 bSetCurWindow = true;
360 RemoveWindow( pWin, TRUE, FALSE );
365 // remove lib info
366 BasicIDEData* pData = IDE_DLL()->GetExtraData();
367 if ( pData )
368 pData->GetLibInfos().RemoveInfoFor( _rDocument );
370 if ( bSetCurLib )
371 SetCurLib( ScriptDocument::getApplicationScriptDocument(), String::CreateFromAscii( "Standard" ), true, false );
372 else if ( bSetCurWindow )
373 SetCurWindow( FindApplicationWindow(), TRUE );
376 void BasicIDEShell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
378 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
379 if ( pBindings )
380 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, TRUE, FALSE );
381 SetMDITitle();
384 void BasicIDEShell::onDocumentModeChanged( const ScriptDocument& _rDocument )
386 for ( ULONG nWin = aIDEWindowTable.Count(); nWin; )
388 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( --nWin );
389 if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
390 pWin->SetReadOnly( _rDocument.isReadOnly() );
394 void BasicIDEShell::StoreAllWindowData( BOOL bPersistent )
396 for ( ULONG nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
398 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
399 DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
400 if ( !pWin->IsSuspended() )
401 pWin->StoreData();
404 if ( bPersistent )
406 SFX_APP()->SaveBasicAndDialogContainer();
407 SetAppBasicModified( FALSE );
409 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
410 if ( pBindings )
412 pBindings->Invalidate( SID_SAVEDOC );
413 pBindings->Update( SID_SAVEDOC );
419 USHORT __EXPORT BasicIDEShell::PrepareClose( BOOL bUI, BOOL bForBrowsing )
421 (void)bForBrowsing;
423 // da es nach Drucken etc. (DocInfo) modifiziert ist, hier resetten
424 GetViewFrame()->GetObjectShell()->SetModified(FALSE);
426 if ( StarBASIC::IsRunning() )
428 if( bUI )
430 String aErrorStr( IDEResId( RID_STR_CANNOTCLOSE ) );
431 Window *pParent = &GetViewFrame()->GetWindow();
432 InfoBox( pParent, aErrorStr ).Execute();
434 return FALSE;
436 else
438 // Hier unguenstig, wird zweimal gerufen...
439 // StoreAllWindowData();
441 BOOL bCanClose = TRUE;
442 for ( ULONG nWin = 0; bCanClose && ( nWin < aIDEWindowTable.Count() ); nWin++ )
444 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
445 if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
447 if ( m_aCurLibName.Len() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
448 SetCurLib( ScriptDocument::getApplicationScriptDocument(), String(), false );
449 SetCurWindow( pWin, TRUE );
450 bCanClose = FALSE;
454 if ( bCanClose )
455 StoreAllWindowData( FALSE ); // Nicht auf Platte schreiben, das passiert am Ende automatisch
457 return bCanClose;
461 void BasicIDEShell::InitScrollBars()
463 aVScrollBar.SetLineSize( 300 );
464 aVScrollBar.SetPageSize( 2000 );
465 aHScrollBar.SetLineSize( 300 );
466 aHScrollBar.SetPageSize( 2000 );
467 aHScrollBar.Enable();
468 aVScrollBar.Enable();
469 aVScrollBar.Show();
470 aHScrollBar.Show();
471 aScrollBarBox.Show();
476 void BasicIDEShell::InitTabBar()
478 pTabBar->Enable();
479 pTabBar->Show();
480 pTabBar->SetSelectHdl( LINK( this, BasicIDEShell, TabBarHdl ) );
484 Size __EXPORT BasicIDEShell::GetOptimalSizePixel() const
486 return Size( 400, 300 );
491 void __EXPORT BasicIDEShell::OuterResizePixel( const Point &rPos, const Size &rSize )
493 // Adjust fliegt irgendwann raus...
494 AdjustPosSizePixel( rPos, rSize );
498 IMPL_LINK_INLINE_START( BasicIDEShell, TabBarSplitHdl, TabBar *, pTBar )
500 (void)pTBar;
501 bTabBarSplitted = TRUE;
502 ArrangeTabBar();
504 return 0;
506 IMPL_LINK_INLINE_END( BasicIDEShell, TabBarSplitHdl, TabBar *, pTBar )
510 IMPL_LINK( BasicIDEShell, TabBarHdl, TabBar *, pCurTabBar )
512 USHORT nCurId = pCurTabBar->GetCurPageId();
513 IDEBaseWindow* pWin = aIDEWindowTable.Get( nCurId );
514 DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
515 SetCurWindow( pWin );
517 return 0;
522 BOOL BasicIDEShell::NextPage( BOOL bPrev )
524 BOOL bRet = FALSE;
525 USHORT nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
527 if ( bPrev )
528 --nPos;
529 else
530 ++nPos;
532 if ( nPos < pTabBar->GetPageCount() )
534 IDEBaseWindow* pWin = aIDEWindowTable.Get( pTabBar->GetPageId( nPos ) );
535 SetCurWindow( pWin, TRUE );
536 bRet = TRUE;
539 return bRet;
544 void BasicIDEShell::ArrangeTabBar()
546 Size aSz( GetViewFrame()->GetWindow().GetOutputSizePixel() );
547 long nBoxPos = aScrollBarBox.GetPosPixel().X() - 1;
548 long nPos = pTabBar->GetSplitSize();
549 if ( nPos <= nBoxPos )
551 Point aPnt( pTabBar->GetPosPixel() );
552 long nH = aHScrollBar.GetSizePixel().Height();
553 pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
554 long nScrlStart = aPnt.X() + nPos;
555 aHScrollBar.SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
556 aHScrollBar.Update();
562 SfxUndoManager* BasicIDEShell::GetUndoManager()
564 SfxUndoManager* pMgr = NULL;
565 if( pCurWin )
566 pMgr = pCurWin->GetUndoManager();
568 return pMgr;
573 void BasicIDEShell::ShowObjectDialog( BOOL bShow, BOOL bCreateOrDestroy )
575 if ( bShow )
577 if ( !pObjectCatalog && bCreateOrDestroy )
579 pObjectCatalog = new ObjectCatalog( &GetViewFrame()->GetWindow() );
580 // Position wird in BasicIDEData gemerkt und vom Dlg eingestellt
581 if ( pObjectCatalog )
583 pObjectCatalog->SetCancelHdl( LINK( this, BasicIDEShell, ObjectDialogCancelHdl ) );
584 BasicEntryDescriptor aDesc;
585 IDEBaseWindow* pCurWin_ = GetCurWindow();
586 if ( pCurWin_ )
587 aDesc = pCurWin_->CreateEntryDescriptor();
588 pObjectCatalog->SetCurrentEntry( aDesc );
592 // Die allerletzten Aenderungen...
593 if ( pCurWin )
594 pCurWin->StoreData();
596 if ( pObjectCatalog )
598 pObjectCatalog->UpdateEntries();
599 pObjectCatalog->Show();
602 else if ( pObjectCatalog )
604 pObjectCatalog->Hide();
605 if ( bCreateOrDestroy )
607 // Wegen OS/2-Focus-Problem pObjectCatalog vorm delete auf NULL
608 ObjectCatalog* pTemp = pObjectCatalog;
609 pObjectCatalog = 0;
610 delete pTemp;
617 void __EXPORT BasicIDEShell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
618 const SfxHint& rHint, const TypeId& )
620 if ( IDE_DLL()->GetShell() )
622 if ( rHint.IsA( TYPE( SfxSimpleHint ) ) )
624 switch ( ((SfxSimpleHint&)rHint).GetId() )
626 case SFX_HINT_DYING:
628 EndListening( rBC, TRUE /* Alle abmelden */ );
629 if ( pObjectCatalog )
630 pObjectCatalog->UpdateEntries();
632 break;
635 if ( rHint.IsA( TYPE( SbxHint ) ) )
637 SbxHint& rSbxHint = (SbxHint&)rHint;
638 ULONG nHintId = rSbxHint.GetId();
639 if ( ( nHintId == SBX_HINT_BASICSTART ) ||
640 ( nHintId == SBX_HINT_BASICSTOP ) )
642 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
643 if ( pBindings )
645 pBindings->Invalidate( SID_BASICRUN );
646 pBindings->Update( SID_BASICRUN );
647 pBindings->Invalidate( SID_BASICCOMPILE );
648 pBindings->Update( SID_BASICCOMPILE );
649 pBindings->Invalidate( SID_BASICSTEPOVER );
650 pBindings->Update( SID_BASICSTEPOVER );
651 pBindings->Invalidate( SID_BASICSTEPINTO );
652 pBindings->Update( SID_BASICSTEPINTO );
653 pBindings->Invalidate( SID_BASICSTEPOUT );
654 pBindings->Update( SID_BASICSTEPOUT );
655 pBindings->Invalidate( SID_BASICSTOP );
656 pBindings->Update( SID_BASICSTOP );
657 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
658 pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
659 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
660 pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
661 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
662 pBindings->Update( SID_BASICIDE_MODULEDLG );
663 pBindings->Invalidate( SID_BASICLOAD );
664 pBindings->Update( SID_BASICLOAD );
667 if ( nHintId == SBX_HINT_BASICSTOP )
669 // Nicht nur bei Error/Break oder explizitem anhalten,
670 // falls durch einen Programmierfehler das Update abgeschaltet ist.
671 BasicIDE::BasicStopped();
672 UpdateModulWindowLayout( true ); // Leer machen...
673 if( m_pCurLocalizationMgr )
674 m_pCurLocalizationMgr->handleBasicStopped();
676 else if( m_pCurLocalizationMgr )
678 m_pCurLocalizationMgr->handleBasicStarted();
681 IDEBaseWindow* pWin = aIDEWindowTable.First();
682 while ( pWin )
684 if ( nHintId == SBX_HINT_BASICSTART )
685 pWin->BasicStarted();
686 else
687 pWin->BasicStopped();
688 pWin = aIDEWindowTable.Next();
698 void BasicIDEShell::CheckWindows()
700 BOOL bSetCurWindow = FALSE;
701 for ( ULONG nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
703 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
704 if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
706 pWin->StoreData();
707 if ( pWin == pCurWin )
708 bSetCurWindow = TRUE;
709 RemoveWindow( pWin, TRUE, FALSE );
710 nWin--;
713 if ( bSetCurWindow )
714 SetCurWindow( FindApplicationWindow(), TRUE );
719 void BasicIDEShell::RemoveWindows( const ScriptDocument& rDocument, const String& rLibName, BOOL bDestroy )
721 BOOL bChangeCurWindow = pCurWin ? FALSE : TRUE;
722 for ( ULONG nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
724 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
725 if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
727 if ( pWin == pCurWin )
728 bChangeCurWindow = TRUE;
729 pWin->StoreData();
730 RemoveWindow( pWin, bDestroy, FALSE );
731 nWin--;
734 if ( bChangeCurWindow )
735 SetCurWindow( FindApplicationWindow(), TRUE );
740 void BasicIDEShell::UpdateWindows()
742 // Alle Fenster, die nicht angezeigt werden duerfen, entfernen
743 BOOL bChangeCurWindow = pCurWin ? FALSE : TRUE;
744 if ( m_aCurLibName.Len() )
746 for ( ULONG nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
748 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
749 if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
751 if ( pWin == pCurWin )
752 bChangeCurWindow = TRUE;
753 pWin->StoreData();
754 // Die Abfrage auf RUNNING verhindert den Absturz, wenn in Reschedule.
755 // Fenster bleibt erstmal stehen, spaeter sowieso mal umstellen,
756 // dass Fenster nur als Hidden markiert werden und nicht
757 // geloescht.
758 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
760 RemoveWindow( pWin, FALSE, FALSE );
761 nWin--;
767 if ( bCreatingWindow )
768 return;
770 IDEBaseWindow* pNextActiveWindow = 0;
772 // Alle anzuzeigenden Fenster anzeigen
773 ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
774 for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
775 doc != aDocuments.end();
776 ++doc
779 StartListening( *doc->getBasicManager(), TRUE /* Nur einmal anmelden */ );
781 // libraries
782 Sequence< ::rtl::OUString > aLibNames( doc->getLibraryNames() );
783 sal_Int32 nLibCount = aLibNames.getLength();
784 const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
786 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
788 String aLibName = pLibNames[ i ];
790 if ( !m_aCurLibName.Len() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
792 // check, if library is password protected and not verified
793 BOOL bProtected = FALSE;
794 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
795 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
797 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
798 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
800 bProtected = TRUE;
804 if ( !bProtected )
806 LibInfoItem* pLibInfoItem = 0;
807 BasicIDEData* pData = IDE_DLL()->GetExtraData();
808 if ( pData )
809 pLibInfoItem = pData->GetLibInfos().GetInfo( LibInfoKey( *doc, aLibName ) );
811 // modules
812 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
814 StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
815 if ( pLib )
816 ImplStartListening( pLib );
820 Sequence< ::rtl::OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
821 sal_Int32 nModCount = aModNames.getLength();
822 const ::rtl::OUString* pModNames = aModNames.getConstArray();
824 for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
826 String aModName = pModNames[ j ];
827 ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, FALSE );
828 if ( !pWin )
829 pWin = CreateBasWin( *doc, aLibName, aModName );
830 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
831 pLibInfoItem->GetCurrentType() == BASICIDE_TYPE_MODULE )
833 pNextActiveWindow = (IDEBaseWindow*)pWin;
837 catch ( container::NoSuchElementException& )
839 DBG_UNHANDLED_EXCEPTION();
843 // dialogs
844 Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
845 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
849 Sequence< ::rtl::OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
850 sal_Int32 nDlgCount = aDlgNames.getLength();
851 const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray();
853 for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
855 String aDlgName = pDlgNames[ j ];
856 // this find only looks for non-suspended windows;
857 // suspended windows are handled in CreateDlgWin
858 DialogWindow* pWin = FindDlgWin( *doc, aLibName, aDlgName, FALSE );
859 if ( !pWin )
860 pWin = CreateDlgWin( *doc, aLibName, aDlgName );
861 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
862 pLibInfoItem->GetCurrentType() == BASICIDE_TYPE_DIALOG )
864 pNextActiveWindow = (IDEBaseWindow*)pWin;
868 catch ( container::NoSuchElementException& )
870 DBG_UNHANDLED_EXCEPTION();
878 if ( bChangeCurWindow )
880 if ( !pNextActiveWindow )
881 pNextActiveWindow = FindApplicationWindow();
882 SetCurWindow( pNextActiveWindow, TRUE );
886 void BasicIDEShell::RemoveWindow( IDEBaseWindow* pWindow_, BOOL bDestroy, BOOL bAllowChangeCurWindow )
888 DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
889 ULONG nKey = aIDEWindowTable.GetKey( pWindow_ );
890 pTabBar->RemovePage( (USHORT)nKey );
891 aIDEWindowTable.Remove( nKey );
892 if ( pWindow_ == pCurWin )
894 if ( bAllowChangeCurWindow )
895 SetCurWindow( FindApplicationWindow(), TRUE );
896 else
897 SetCurWindow( NULL, FALSE );
899 if ( bDestroy )
901 if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
903 delete pWindow_;
905 else
907 pWindow_->AddStatus( BASWIN_TOBEKILLED );
908 pWindow_->Hide();
909 StarBASIC::Stop();
910 // Es kommt kein Notify...
911 pWindow_->BasicStopped();
912 aIDEWindowTable.Insert( nKey, pWindow_ ); // wieder einhaegen
915 else
917 pWindow_->Hide();
918 pWindow_->AddStatus( BASWIN_SUSPENDED );
919 pWindow_->Deactivating();
920 aIDEWindowTable.Insert( nKey, pWindow_ ); // wieder einhaegen
927 USHORT BasicIDEShell::InsertWindowInTable( IDEBaseWindow* pNewWin )
929 // Eigentlich prueffen,
930 nCurKey++;
931 aIDEWindowTable.Insert( nCurKey, pNewWin );
932 return nCurKey;
937 void BasicIDEShell::InvalidateBasicIDESlots()
939 // Nur die, die eine optische Auswirkung haben...
941 if ( IDE_DLL()->GetShell() )
943 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
944 if ( pBindings )
946 pBindings->Invalidate( SID_UNDO );
947 pBindings->Invalidate( SID_REDO );
948 pBindings->Invalidate( SID_SAVEDOC );
949 pBindings->Invalidate( SID_SIGNATURE );
950 pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
951 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
952 pBindings->Invalidate( SID_BASICIDE_OBJCAT );
953 pBindings->Invalidate( SID_BASICSTOP );
954 pBindings->Invalidate( SID_BASICRUN );
955 pBindings->Invalidate( SID_BASICCOMPILE );
956 pBindings->Invalidate( SID_BASICLOAD );
957 pBindings->Invalidate( SID_BASICSAVEAS );
958 pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
959 pBindings->Invalidate( SID_BASICSTEPINTO );
960 pBindings->Invalidate( SID_BASICSTEPOVER );
961 pBindings->Invalidate( SID_BASICSTEPOUT );
962 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
963 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
964 pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
965 pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
966 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
967 pBindings->Invalidate( SID_PRINTDOC );
968 pBindings->Invalidate( SID_PRINTDOCDIRECT );
969 pBindings->Invalidate( SID_SETUPPRINTER );
970 pBindings->Invalidate( SID_DIALOG_TESTMODE );
972 pBindings->Invalidate( SID_DOC_MODIFIED );
973 pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
974 pBindings->Invalidate( SID_BASICIDE_STAT_POS );
975 pBindings->Invalidate( SID_ATTR_INSERT );
976 pBindings->Invalidate( SID_ATTR_SIZE );
981 void BasicIDEShell::EnableScrollbars( BOOL bEnable )
983 if ( bEnable )
985 aHScrollBar.Enable();
986 aVScrollBar.Enable();
988 else
990 aHScrollBar.Disable();
991 aVScrollBar.Disable();
995 void BasicIDEShell::SetCurLib( const ScriptDocument& rDocument, String aLibName, bool bUpdateWindows, bool bCheck )
997 if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
999 ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
1000 if ( pListener )
1001 pListener->removeContainerListener( m_aCurDocument );
1003 m_aCurDocument = rDocument;
1005 if ( pListener )
1006 pListener->addContainerListener( m_aCurDocument );
1008 m_aCurLibName = aLibName;
1009 if ( bUpdateWindows )
1010 UpdateWindows();
1012 SetMDITitle();
1014 SetCurLibForLocalization( rDocument, aLibName );
1016 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
1017 if ( pBindings )
1019 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
1020 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
1021 pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
1026 void BasicIDEShell::SetCurLibForLocalization( const ScriptDocument& rDocument, String aLibName )
1028 // Create LocalizationMgr
1029 delete m_pCurLocalizationMgr;
1030 Reference< resource::XStringResourceManager > xStringResourceManager;
1033 if( aLibName.Len() )
1035 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, TRUE ) );
1036 xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
1039 catch ( container::NoSuchElementException& )
1041 m_pCurLocalizationMgr = new LocalizationMgr
1042 ( this, rDocument, aLibName, xStringResourceManager );
1044 m_pCurLocalizationMgr->handleTranslationbar();
1047 void BasicIDEShell::ImplStartListening( StarBASIC* pBasic )
1049 StartListening( pBasic->GetBroadcaster(), TRUE /* Nur einmal anmelden */ );