bump product version to 4.1.6.2
[LibreOffice.git] / basctl / source / basicide / basidesh.cxx
blobfddf8bbb03c5b88cdb55fd6bffcc64b6ca20f312
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "basidesh.hxx"
22 #include <tools/diagnose_ex.h>
23 #include <basic/basmgr.hxx>
24 #include <basidesh.hrc>
25 #include "baside2.hxx"
26 #include "baside3.hxx"
27 #include <basdoc.hxx>
28 #include <basicbox.hxx>
29 #include <editeng/sizeitem.hxx>
30 #include <objdlg.hxx>
31 #include <tbxctl.hxx>
32 #include <iderdll2.hxx>
33 #include <basidectrlr.hxx>
34 #include <localizationmgr.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/dinfdlg.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/minfitem.hxx>
39 #include <sfx2/objface.hxx>
40 #include <svl/aeitem.hxx>
41 #include <svl/intitem.hxx>
42 #include <svl/srchitem.hxx>
44 #define basctl_Shell
45 #define SFX_TYPEMAP
46 #include <idetemp.hxx>
47 #include <basslots.hxx>
48 #include <iderdll.hxx>
49 #include <svx/pszctrl.hxx>
50 #include <svx/insctrl.hxx>
51 #include <svx/srchdlg.hxx>
52 #include <svx/tbcontrl.hxx>
53 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
54 #include <com/sun/star/container/XContainer.hpp>
55 #include <svx/xmlsecctrl.hxx>
56 #include <sfx2/viewfac.hxx>
57 #include <vcl/msgbox.hxx>
59 namespace basctl
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star;
65 typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
67 class ContainerListenerImpl : public ContainerListenerBASE
69 Shell* mpShell;
70 public:
72 ContainerListenerImpl (Shell* pShell) : mpShell(pShell) { }
74 ~ContainerListenerImpl()
75 { }
77 void addContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
79 try
81 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
82 if ( xContainer.is() )
84 uno::Reference< container::XContainerListener > xContainerListener( this );
85 xContainer->addContainerListener( xContainerListener );
88 catch(const uno::Exception& ) {}
90 void removeContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
92 try
94 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
95 if ( xContainer.is() )
97 uno::Reference< container::XContainerListener > xContainerListener( this );
98 xContainer->removeContainerListener( xContainerListener );
101 catch(const uno::Exception& ) {}
104 // XEventListener
105 virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
107 // XContainerListener
108 virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
110 OUString sModuleName;
111 if( mpShell && ( Event.Accessor >>= sModuleName ) )
112 mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true, false );
114 virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
115 virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
117 OUString sModuleName;
118 if( mpShell && ( Event.Accessor >>= sModuleName ) )
120 ModulWindow* pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
121 if( pWin )
122 mpShell->RemoveWindow( pWin, true, true );
128 TYPEINIT1( Shell, SfxViewShell );
130 SFX_IMPL_NAMED_VIEWFACTORY( Shell, "Default" )
132 SFX_VIEW_REGISTRATION( DocShell );
136 SFX_IMPL_INTERFACE( basctl_Shell, SfxViewShell, IDEResId( RID_STR_IDENAME ) )
138 SFX_CHILDWINDOW_REGISTRATION( SID_SEARCH_DLG );
139 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_SHOW_PROPERTYBROWSER, BASICIDE_UI_FEATURE_SHOW_BROWSER);
140 SFX_POPUPMENU_REGISTRATION( IDEResId( RID_POPUP_DLGED ) );
145 namespace
148 unsigned const ShellFlags = SFX_VIEW_CAN_PRINT | SFX_VIEW_NO_NEWWINDOW;
153 unsigned Shell::nShellCount = 0;
155 Shell::Shell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
156 SfxViewShell( pFrame_, ShellFlags ),
157 m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
158 aHScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG ) ),
159 aVScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG ) ),
160 aScrollBarBox( &GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE ) ),
161 pLayout(0),
162 aObjectCatalog(&GetViewFrame()->GetWindow()),
163 m_bAppBasicModified( false ),
164 m_aNotifier( *this )
166 m_xLibListener = new ContainerListenerImpl( this );
167 Init();
168 nShellCount++;
171 void Shell::Init()
173 TbxControls::RegisterControl( SID_CHOOSE_CONTROLS );
174 SvxPosSizeStatusBarControl::RegisterControl();
175 SvxInsertStatusBarControl::RegisterControl();
176 XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
177 SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
178 SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
180 SvxSearchDialogWrapper::RegisterChildWindow(false);
182 GetExtraData()->ShellInCriticalSection() = true;
184 SetName( OUString( "BasicIDE" ) );
185 SetHelpId( SVX_INTERFACE_BASIDE_VIEWSH );
187 LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
188 LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
190 GetViewFrame()->GetWindow().SetBackground(
191 GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetWindowColor()
194 pCurWin = 0;
195 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
196 bCreatingWindow = false;
198 pTabBar.reset(new TabBar(&GetViewFrame()->GetWindow()));
199 pTabBar->SetSplitHdl( LINK( this, Shell, TabBarSplitHdl ) );
200 bTabBarSplitted = false;
202 nCurKey = 100;
203 InitScrollBars();
204 InitTabBar();
206 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
208 ShellCreated(this);
210 GetExtraData()->ShellInCriticalSection() = false;
212 // It's enough to create the controller ...
213 // It will be public by using magic :-)
214 new Controller(this);
216 // Force updating the title ! Because it must be set to the controller
217 // it has to be called directly after creating those controller.
218 SetMDITitle ();
220 UpdateWindows();
223 Shell::~Shell()
225 m_aNotifier.dispose();
227 ShellDestroyed(this);
229 // so that on a basic saving error, the shell doesn't pop right up again
230 GetExtraData()->ShellInCriticalSection() = true;
232 SetWindow( 0 );
233 SetCurWindow( 0 );
235 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
237 // no store; does already happen when the BasicManagers are destroyed
238 delete it->second;
241 // Destroy all ContainerListeners for Basic Container.
242 if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
243 pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
245 GetExtraData()->ShellInCriticalSection() = false;
247 nShellCount--;
250 void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
252 if (pCurWin)
253 pCurWin->OnNewDocument();
254 UpdateWindows();
257 void Shell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
259 if (pCurWin)
260 pCurWin->OnNewDocument();
261 UpdateWindows();
264 void Shell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
266 StoreAllWindowData();
269 void Shell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
271 // #i115671: Update SID_SAVEDOC after saving is completed
272 if (SfxBindings* pBindings = GetBindingsPtr())
273 pBindings->Invalidate( SID_SAVEDOC );
276 void Shell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
278 StoreAllWindowData();
281 void Shell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
283 // not interested in
286 void Shell::onDocumentClosed( const ScriptDocument& _rDocument )
288 if ( !_rDocument.isValid() )
289 return;
291 bool bSetCurWindow = false;
292 bool bSetCurLib = ( _rDocument == m_aCurDocument );
293 std::vector<BaseWindow*> aDeleteVec;
295 // remove all windows which belong to this document
296 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
298 BaseWindow* pWin = it->second;
299 if ( pWin->IsDocument( _rDocument ) )
301 if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
303 pWin->AddStatus( BASWIN_TOBEKILLED );
304 pWin->Hide();
305 StarBASIC::Stop();
306 // there's no notify
307 pWin->BasicStopped();
309 else
310 aDeleteVec.push_back( pWin );
313 // delete windows outside main loop so we don't invalidate the original iterator
314 for (std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it)
316 BaseWindow* pWin = *it;
317 pWin->StoreData();
318 if ( pWin == pCurWin )
319 bSetCurWindow = true;
320 RemoveWindow( pWin, true, false );
323 // remove lib info
324 if (ExtraData* pData = GetExtraData())
325 pData->GetLibInfos().RemoveInfoFor( _rDocument );
327 if ( bSetCurLib )
328 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", true, false );
329 else if ( bSetCurWindow )
330 SetCurWindow( FindApplicationWindow(), true );
333 void Shell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
335 if (SfxBindings* pBindings = GetBindingsPtr())
336 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true, false );
337 SetMDITitle();
340 void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )
342 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
344 BaseWindow* pWin = it->second;
345 if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
346 pWin->SetReadOnly( _rDocument.isReadOnly() );
350 void Shell::StoreAllWindowData( bool bPersistent )
352 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
354 BaseWindow* pWin = it->second;
355 DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
356 if ( !pWin->IsSuspended() )
357 pWin->StoreData();
360 if ( bPersistent )
362 SFX_APP()->SaveBasicAndDialogContainer();
363 SetAppBasicModified(false);
365 if (SfxBindings* pBindings = GetBindingsPtr())
367 pBindings->Invalidate( SID_SAVEDOC );
368 pBindings->Update( SID_SAVEDOC );
374 sal_uInt16 Shell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
376 (void)bForBrowsing;
378 // reset here because it's modified after printing etc. (DocInfo)
379 GetViewFrame()->GetObjectShell()->SetModified(false);
381 if ( StarBASIC::IsRunning() )
383 if( bUI )
385 Window *pParent = &GetViewFrame()->GetWindow();
386 InfoBox( pParent, IDE_RESSTR(RID_STR_CANNOTCLOSE)).Execute();
388 return false;
390 else
392 bool bCanClose = true;
393 for (WindowTableIt it = aWindowTable.begin(); bCanClose && (it != aWindowTable.end()); ++it)
395 BaseWindow* pWin = it->second;
396 if ( !pWin->CanClose() )
398 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
399 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
400 SetCurWindow( pWin, true );
401 bCanClose = false;
405 if ( bCanClose )
406 StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
408 return bCanClose;
412 void Shell::InitScrollBars()
414 aVScrollBar.SetLineSize( 300 );
415 aVScrollBar.SetPageSize( 2000 );
416 aHScrollBar.SetLineSize( 300 );
417 aHScrollBar.SetPageSize( 2000 );
418 aHScrollBar.Enable();
419 aVScrollBar.Enable();
420 aVScrollBar.Show();
421 aHScrollBar.Show();
422 aScrollBarBox.Show();
427 void Shell::InitTabBar()
429 pTabBar->Enable();
430 pTabBar->Show();
431 pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
436 void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
438 AdjustPosSizePixel( rPos, rSize );
442 IMPL_LINK_INLINE_START( Shell, TabBarSplitHdl, TabBar *, pTBar )
444 (void)pTBar;
445 bTabBarSplitted = true;
446 ArrangeTabBar();
448 return 0;
450 IMPL_LINK_INLINE_END( Shell, TabBarSplitHdl, TabBar *, pTBar )
454 IMPL_LINK( Shell, TabBarHdl, TabBar *, pCurTabBar )
456 sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
457 BaseWindow* pWin = aWindowTable[ nCurId ];
458 DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
459 SetCurWindow( pWin );
461 return 0;
466 bool Shell::NextPage( bool bPrev )
468 bool bRet = false;
469 sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
471 if ( bPrev )
472 --nPos;
473 else
474 ++nPos;
476 if ( nPos < pTabBar->GetPageCount() )
478 BaseWindow* pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
479 SetCurWindow( pWin, true );
480 bRet = true;
483 return bRet;
488 void Shell::ArrangeTabBar()
490 long nBoxPos = aScrollBarBox.GetPosPixel().X() - 1;
491 long nPos = pTabBar->GetSplitSize();
492 if ( nPos <= nBoxPos )
494 Point aPnt( pTabBar->GetPosPixel() );
495 long nH = aHScrollBar.GetSizePixel().Height();
496 pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
497 long nScrlStart = aPnt.X() + nPos;
498 aHScrollBar.SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
499 aHScrollBar.Update();
505 ::svl::IUndoManager* Shell::GetUndoManager()
507 ::svl::IUndoManager* pMgr = NULL;
508 if( pCurWin )
509 pMgr = pCurWin->GetUndoManager();
511 return pMgr;
516 void Shell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
517 const SfxHint& rHint, const TypeId& )
519 if (GetShell())
521 if (SfxSimpleHint const* pSimpleHint = dynamic_cast<SfxSimpleHint const*>(&rHint))
523 switch (pSimpleHint->GetId())
525 case SFX_HINT_DYING:
527 EndListening( rBC, true /* log off all */ );
528 aObjectCatalog.UpdateEntries();
530 break;
533 if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
535 sal_uLong nHintId = pSbxHint->GetId();
536 if ( ( nHintId == SBX_HINT_BASICSTART ) ||
537 ( nHintId == SBX_HINT_BASICSTOP ) )
539 if (SfxBindings* pBindings = GetBindingsPtr())
541 pBindings->Invalidate( SID_BASICRUN );
542 pBindings->Update( SID_BASICRUN );
543 pBindings->Invalidate( SID_BASICCOMPILE );
544 pBindings->Update( SID_BASICCOMPILE );
545 pBindings->Invalidate( SID_BASICSTEPOVER );
546 pBindings->Update( SID_BASICSTEPOVER );
547 pBindings->Invalidate( SID_BASICSTEPINTO );
548 pBindings->Update( SID_BASICSTEPINTO );
549 pBindings->Invalidate( SID_BASICSTEPOUT );
550 pBindings->Update( SID_BASICSTEPOUT );
551 pBindings->Invalidate( SID_BASICSTOP );
552 pBindings->Update( SID_BASICSTOP );
553 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
554 pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
555 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
556 pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
557 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
558 pBindings->Update( SID_BASICIDE_MODULEDLG );
559 pBindings->Invalidate( SID_BASICLOAD );
560 pBindings->Update( SID_BASICLOAD );
563 if ( nHintId == SBX_HINT_BASICSTOP )
565 // not only at error/break or explicit stoppage,
566 // if the update is turned off due to a programming bug
567 BasicStopped();
568 if (pLayout)
569 pLayout->UpdateDebug(true); // clear...
570 if( m_pCurLocalizationMgr )
571 m_pCurLocalizationMgr->handleBasicStopped();
573 else if( m_pCurLocalizationMgr )
575 m_pCurLocalizationMgr->handleBasicStarted();
578 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
580 BaseWindow* pWin = it->second;
581 if ( nHintId == SBX_HINT_BASICSTART )
582 pWin->BasicStarted();
583 else
584 pWin->BasicStopped();
594 void Shell::CheckWindows()
596 bool bSetCurWindow = false;
597 std::vector<BaseWindow*> aDeleteVec;
598 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
600 BaseWindow* pWin = it->second;
601 if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
602 aDeleteVec.push_back( pWin );
604 for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
606 BaseWindow* pWin = *it;
607 pWin->StoreData();
608 if ( pWin == pCurWin )
609 bSetCurWindow = true;
610 RemoveWindow( pWin, true, false );
612 if ( bSetCurWindow )
613 SetCurWindow( FindApplicationWindow(), true );
618 void Shell::RemoveWindows( const ScriptDocument& rDocument, const OUString& rLibName, bool bDestroy )
620 bool bChangeCurWindow = pCurWin ? false : true;
621 std::vector<BaseWindow*> aDeleteVec;
622 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
624 BaseWindow* pWin = it->second;
625 if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
626 aDeleteVec.push_back( pWin );
628 for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
630 BaseWindow* pWin = *it;
631 if ( pWin == pCurWin )
632 bChangeCurWindow = true;
633 pWin->StoreData();
634 RemoveWindow( pWin, bDestroy, false );
636 if ( bChangeCurWindow )
637 SetCurWindow( FindApplicationWindow(), true );
642 void Shell::UpdateWindows()
644 // remove all windows that may not be displayed
645 bool bChangeCurWindow = pCurWin ? false : true;
646 if ( !m_aCurLibName.isEmpty() )
648 std::vector<BaseWindow*> aDeleteVec;
649 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
651 BaseWindow* pWin = it->second;
652 if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
654 if ( pWin == pCurWin )
655 bChangeCurWindow = true;
656 pWin->StoreData();
657 // The request of RUNNING prevents the crash when in reschedule.
658 // Window is frozen at first, later the windows should be changed
659 // anyway to be marked as hidden instead of being deleted.
660 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
661 aDeleteVec.push_back( pWin );
664 for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
666 RemoveWindow( *it, false, false );
670 if ( bCreatingWindow )
671 return;
673 BaseWindow* pNextActiveWindow = 0;
675 // show all windows that are to be shown
676 ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
677 for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
678 doc != aDocuments.end();
679 ++doc
682 StartListening( *doc->getBasicManager(), true /* log on only once */ );
684 // libraries
685 Sequence< OUString > aLibNames( doc->getLibraryNames() );
686 sal_Int32 nLibCount = aLibNames.getLength();
687 const OUString* pLibNames = aLibNames.getConstArray();
689 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
691 OUString aLibName = pLibNames[ i ];
693 if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
695 // check, if library is password protected and not verified
696 bool bProtected = false;
697 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
698 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
700 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
701 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
703 bProtected = true;
707 if ( !bProtected )
709 LibInfos::Item const* pLibInfoItem = 0;
710 if (ExtraData* pData = GetExtraData())
711 pLibInfoItem = pData->GetLibInfos().GetInfo(*doc, aLibName);
713 // modules
714 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
716 StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
717 if ( pLib )
718 ImplStartListening( pLib );
722 Sequence< OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
723 sal_Int32 nModCount = aModNames.getLength();
724 const OUString* pModNames = aModNames.getConstArray();
726 for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
728 OUString aModName = pModNames[ j ];
729 ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, false );
730 if ( !pWin )
731 pWin = CreateBasWin( *doc, aLibName, aModName );
732 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
733 pLibInfoItem->GetCurrentType() == TYPE_MODULE )
735 pNextActiveWindow = (BaseWindow*)pWin;
739 catch (const container::NoSuchElementException& )
741 DBG_UNHANDLED_EXCEPTION();
745 // dialogs
746 Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
747 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
751 Sequence< OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
752 sal_Int32 nDlgCount = aDlgNames.getLength();
753 const OUString* pDlgNames = aDlgNames.getConstArray();
755 for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
757 OUString aDlgName = pDlgNames[ j ];
758 // this find only looks for non-suspended windows;
759 // suspended windows are handled in CreateDlgWin
760 DialogWindow* pWin = FindDlgWin( *doc, aLibName, aDlgName, false );
761 if ( !pWin )
762 pWin = CreateDlgWin( *doc, aLibName, aDlgName );
763 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
764 pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
766 pNextActiveWindow = (BaseWindow*)pWin;
770 catch (const container::NoSuchElementException& )
772 DBG_UNHANDLED_EXCEPTION();
780 if ( bChangeCurWindow )
782 if ( !pNextActiveWindow )
784 pNextActiveWindow = FindApplicationWindow();
786 SetCurWindow( pNextActiveWindow, true );
790 void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
792 DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
793 sal_uLong nKey = GetWindowId( pWindow_ );
794 pTabBar->RemovePage( (sal_uInt16)nKey );
795 aWindowTable.erase( nKey );
796 if ( pWindow_ == pCurWin )
798 if ( bAllowChangeCurWindow )
800 SetCurWindow( FindApplicationWindow(), true );
802 else
804 SetCurWindow( NULL, false );
807 if ( bDestroy )
809 if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
811 delete pWindow_;
813 else
815 pWindow_->AddStatus( BASWIN_TOBEKILLED );
816 pWindow_->Hide();
817 // In normal mode stop basic in windows to be deleted
818 // In VBA stop basic only if the running script is trying to delete
819 // its parent module
820 bool bStop = true;
821 if ( pWindow_->GetDocument().isInVBAMode() )
823 SbModule* pMod = StarBASIC::GetActiveModule();
824 if ( !pMod || ( pMod && ( !pMod->GetName().equals(pWindow_->GetName()) ) ) )
826 bStop = false;
829 if ( bStop )
831 StarBASIC::Stop();
832 // there will be no notify...
833 pWindow_->BasicStopped();
835 aWindowTable[ nKey ] = pWindow_; // jump in again
838 else
840 pWindow_->AddStatus( BASWIN_SUSPENDED );
841 pWindow_->Deactivating();
842 aWindowTable[ nKey ] = pWindow_; // jump in again
849 sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
851 nCurKey++;
852 aWindowTable[ nCurKey ] = pNewWin;
853 return nCurKey;
858 void Shell::InvalidateBasicIDESlots()
860 // only those that have an optic effect...
862 if (GetShell())
864 if (SfxBindings* pBindings = GetBindingsPtr())
866 pBindings->Invalidate( SID_UNDO );
867 pBindings->Invalidate( SID_REDO );
868 pBindings->Invalidate( SID_SAVEDOC );
869 pBindings->Invalidate( SID_SIGNATURE );
870 pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
871 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
872 pBindings->Invalidate( SID_BASICIDE_OBJCAT );
873 pBindings->Invalidate( SID_BASICSTOP );
874 pBindings->Invalidate( SID_BASICRUN );
875 pBindings->Invalidate( SID_BASICCOMPILE );
876 pBindings->Invalidate( SID_BASICLOAD );
877 pBindings->Invalidate( SID_BASICSAVEAS );
878 pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
879 pBindings->Invalidate( SID_BASICSTEPINTO );
880 pBindings->Invalidate( SID_BASICSTEPOVER );
881 pBindings->Invalidate( SID_BASICSTEPOUT );
882 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
883 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
884 pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
885 pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
886 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
887 pBindings->Invalidate( SID_PRINTDOC );
888 pBindings->Invalidate( SID_PRINTDOCDIRECT );
889 pBindings->Invalidate( SID_SETUPPRINTER );
890 pBindings->Invalidate( SID_DIALOG_TESTMODE );
892 pBindings->Invalidate( SID_DOC_MODIFIED );
893 pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
894 pBindings->Invalidate( SID_BASICIDE_STAT_POS );
895 pBindings->Invalidate( SID_ATTR_INSERT );
896 pBindings->Invalidate( SID_ATTR_SIZE );
901 void Shell::EnableScrollbars( bool bEnable )
903 aHScrollBar.Enable(bEnable);
904 aVScrollBar.Enable(bEnable);
907 void Shell::SetCurLib( const ScriptDocument& rDocument, OUString aLibName, bool bUpdateWindows, bool bCheck )
909 if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
911 ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
913 m_aCurDocument = rDocument;
914 m_aCurLibName = aLibName;
916 if ( pListener )
918 pListener->removeContainerListener( m_aCurDocument, m_aCurLibName );
919 pListener->addContainerListener( m_aCurDocument, aLibName );
922 if ( bUpdateWindows )
923 UpdateWindows();
925 SetMDITitle();
927 SetCurLibForLocalization( rDocument, aLibName );
929 if (SfxBindings* pBindings = GetBindingsPtr())
931 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
932 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
933 pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
938 void Shell::SetCurLibForLocalization( const ScriptDocument& rDocument, OUString aLibName )
940 // Create LocalizationMgr
941 Reference< resource::XStringResourceManager > xStringResourceManager;
944 if( !aLibName.isEmpty() )
946 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
947 xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
950 catch (const container::NoSuchElementException& )
953 m_pCurLocalizationMgr = boost::shared_ptr<LocalizationMgr>(new LocalizationMgr(this, rDocument, aLibName, xStringResourceManager));
954 m_pCurLocalizationMgr->handleTranslationbar();
957 void Shell::ImplStartListening( StarBASIC* pBasic )
959 StartListening( pBasic->GetBroadcaster(), true /* log on only once */ );
962 } // namespace basctl
964 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */