bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / basidesh.cxx
blob9eb86f8e862674995c1cbd492443150e36aa4cca
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 <config_options.h>
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 <tbxctl.hxx>
31 #include <iderdll2.hxx>
32 #include <basidectrlr.hxx>
33 #include <localizationmgr.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/dinfdlg.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/infobar.hxx>
38 #include <sfx2/minfitem.hxx>
39 #include <sfx2/objface.hxx>
40 #include <svl/aeitem.hxx>
41 #include <svl/srchitem.hxx>
43 #define basctl_Shell
44 #define SFX_TYPEMAP
45 #include <idetemp.hxx>
46 #include <basslots.hxx>
47 #include <iderdll.hxx>
48 #include <svx/pszctrl.hxx>
49 #include <svx/insctrl.hxx>
50 #include <svx/srchdlg.hxx>
51 #include <svx/tbcontrl.hxx>
52 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
53 #include <com/sun/star/container/XContainer.hpp>
54 #include <svx/xmlsecctrl.hxx>
55 #include <sfx2/viewfac.hxx>
56 #include <vcl/msgbox.hxx>
57 #include <vcl/settings.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:
71 explicit ContainerListenerImpl(Shell* pShell)
72 : mpShell(pShell)
76 virtual ~ContainerListenerImpl()
80 void addContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
82 try
84 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
85 if ( xContainer.is() )
87 uno::Reference< container::XContainerListener > xContainerListener( this );
88 xContainer->addContainerListener( xContainerListener );
91 catch(const uno::Exception& ) {}
93 void removeContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
95 try
97 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
98 if ( xContainer.is() )
100 uno::Reference< container::XContainerListener > xContainerListener( this );
101 xContainer->removeContainerListener( xContainerListener );
104 catch(const uno::Exception& ) {}
107 // XEventListener
108 virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE {}
110 // XContainerListener
111 virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
113 OUString sModuleName;
114 if( mpShell && ( Event.Accessor >>= sModuleName ) )
115 mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true, false );
117 virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE { }
118 virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
120 OUString sModuleName;
121 if( mpShell && ( Event.Accessor >>= sModuleName ) )
123 VclPtr<ModulWindow> pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
124 if( pWin )
125 mpShell->RemoveWindow( pWin, true, true );
131 TYPEINIT1( Shell, SfxViewShell );
133 SFX_IMPL_NAMED_VIEWFACTORY( Shell, "Default" )
135 SFX_VIEW_REGISTRATION( DocShell );
138 SFX_IMPL_INTERFACE(basctl_Shell, SfxViewShell)
140 void basctl_Shell::InitInterface_Impl()
142 GetStaticInterface()->RegisterChildWindow(SID_SEARCH_DLG);
143 GetStaticInterface()->RegisterChildWindow(SID_SHOW_PROPERTYBROWSER, false, BASICIDE_UI_FEATURE_SHOW_BROWSER);
144 GetStaticInterface()->RegisterChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
146 GetStaticInterface()->RegisterPopupMenu(IDEResId(RID_POPUP_DLGED));
149 unsigned Shell::nShellCount = 0;
151 Shell::Shell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
152 SfxViewShell( pFrame_, SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::NO_NEWWINDOW ),
153 m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
154 aHScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG )) ),
155 aVScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG )) ),
156 aScrollBarBox( VclPtr<ScrollBarBox>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE )) ),
157 pLayout(0),
158 aObjectCatalog(VclPtr<ObjectCatalog>::Create(&GetViewFrame()->GetWindow())),
159 m_bAppBasicModified( false ),
160 m_aNotifier( *this )
162 m_xLibListener = new ContainerListenerImpl( this );
163 Init();
164 nShellCount++;
167 void Shell::Init()
169 TbxControls::RegisterControl( SID_CHOOSE_CONTROLS );
170 SvxPosSizeStatusBarControl::RegisterControl();
171 SvxInsertStatusBarControl::RegisterControl();
172 XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
173 SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
174 SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
176 SvxSearchDialogWrapper::RegisterChildWindow(false);
178 GetExtraData()->ShellInCriticalSection() = true;
180 SetName( OUString( "BasicIDE" ) );
181 SetHelpId( SVX_INTERFACE_BASIDE_VIEWSH );
183 LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
184 LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
186 GetViewFrame()->GetWindow().SetBackground(
187 GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetWindowColor()
190 pCurWin = 0;
191 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
192 bCreatingWindow = false;
194 pTabBar.reset(VclPtr<TabBar>::Create(&GetViewFrame()->GetWindow()));
195 pTabBar->SetSplitHdl( LINK( this, Shell, TabBarSplitHdl ) );
196 bTabBarSplitted = false;
198 nCurKey = 100;
199 InitScrollBars();
200 InitTabBar();
202 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
204 ShellCreated(this);
206 GetExtraData()->ShellInCriticalSection() = false;
208 // It's enough to create the controller ...
209 // It will be public by using magic :-)
210 new Controller(this);
212 // Force updating the title ! Because it must be set to the controller
213 // it has to be called directly after creating those controller.
214 SetMDITitle ();
216 UpdateWindows();
219 Shell::~Shell()
221 m_aNotifier.dispose();
223 ShellDestroyed(this);
225 // so that on a basic saving error, the shell doesn't pop right up again
226 GetExtraData()->ShellInCriticalSection() = true;
228 SetWindow( 0 );
229 SetCurWindow( 0 );
231 aObjectCatalog.disposeAndClear();
232 aScrollBarBox.disposeAndClear();
233 aVScrollBar.disposeAndClear();
234 aHScrollBar.disposeAndClear();
236 for (WindowTable::iterator it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
238 // no store; does already happen when the BasicManagers are destroyed
239 it->second.disposeAndClear();
242 // no store; does already happen when the BasicManagers are destroyed
243 aWindowTable.clear();
245 // Destroy all ContainerListeners for Basic Container.
246 if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
247 pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
249 GetExtraData()->ShellInCriticalSection() = false;
251 nShellCount--;
253 pDialogLayout.disposeAndClear();
254 pModulLayout.disposeAndClear();
255 pTabBar.disposeAndClear();
258 void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
260 if (pCurWin)
262 pCurWin->OnNewDocument();
264 // for VBA documents, show a warning that we can save them only in ODF
265 if (pCurWin->GetDocument().isInVBAMode())
266 GetViewFrame()->AppendInfoBar("vba_save", IDE_RESSTR(RID_STR_CANNOTSAVEVBA));
269 UpdateWindows();
272 void Shell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
274 if (pCurWin)
275 pCurWin->OnNewDocument();
276 UpdateWindows();
279 void Shell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
281 StoreAllWindowData();
284 void Shell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
286 // #i115671: Update SID_SAVEDOC after saving is completed
287 if (SfxBindings* pBindings = GetBindingsPtr())
288 pBindings->Invalidate( SID_SAVEDOC );
291 void Shell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
293 StoreAllWindowData();
296 void Shell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
298 // not interested in
301 void Shell::onDocumentClosed( const ScriptDocument& _rDocument )
303 if ( !_rDocument.isValid() )
304 return;
306 bool bSetCurWindow = false;
307 bool bSetCurLib = ( _rDocument == m_aCurDocument );
308 std::vector<VclPtr<BaseWindow> > aDeleteVec;
310 // remove all windows which belong to this document
311 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
313 BaseWindow* pWin = it->second;
314 if ( pWin->IsDocument( _rDocument ) )
316 if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
318 pWin->AddStatus( BASWIN_TOBEKILLED );
319 pWin->Hide();
320 StarBASIC::Stop();
321 // there's no notify
322 pWin->BasicStopped();
324 else
325 aDeleteVec.push_back( pWin );
328 // delete windows outside main loop so we don't invalidate the original iterator
329 for (auto it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it)
331 BaseWindow* pWin = *it;
332 pWin->StoreData();
333 if ( pWin == pCurWin )
334 bSetCurWindow = true;
335 RemoveWindow( pWin, true, false );
338 // remove lib info
339 if (ExtraData* pData = GetExtraData())
340 pData->GetLibInfos().RemoveInfoFor( _rDocument );
342 if ( bSetCurLib )
343 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", true, false );
344 else if ( bSetCurWindow )
345 SetCurWindow( FindApplicationWindow(), true );
348 void Shell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
350 if (SfxBindings* pBindings = GetBindingsPtr())
351 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true, false );
352 SetMDITitle();
355 void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )
357 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
359 BaseWindow* pWin = it->second;
360 if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
361 pWin->SetReadOnly( _rDocument.isReadOnly() );
365 void Shell::StoreAllWindowData( bool bPersistent )
367 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
369 BaseWindow* pWin = it->second;
370 DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
371 if ( !pWin->IsSuspended() )
372 pWin->StoreData();
375 if ( bPersistent )
377 SfxGetpApp()->SaveBasicAndDialogContainer();
378 SetAppBasicModified(false);
380 if (SfxBindings* pBindings = GetBindingsPtr())
382 pBindings->Invalidate( SID_SAVEDOC );
383 pBindings->Update( SID_SAVEDOC );
389 bool Shell::PrepareClose( bool bUI )
391 // reset here because it's modified after printing etc. (DocInfo)
392 GetViewFrame()->GetObjectShell()->SetModified(false);
394 if ( StarBASIC::IsRunning() )
396 if( bUI )
398 vcl::Window *pParent = &GetViewFrame()->GetWindow();
399 ScopedVclPtr<InfoBox>::Create( pParent, IDE_RESSTR(RID_STR_CANNOTCLOSE))->Execute();
401 return false;
403 else
405 bool bCanClose = true;
406 for (WindowTableIt it = aWindowTable.begin(); bCanClose && (it != aWindowTable.end()); ++it)
408 BaseWindow* pWin = it->second;
409 if ( !pWin->CanClose() )
411 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
412 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
413 SetCurWindow( pWin, true );
414 bCanClose = false;
418 if ( bCanClose )
419 StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
421 return bCanClose;
425 void Shell::InitScrollBars()
427 aVScrollBar->SetLineSize( 300 );
428 aVScrollBar->SetPageSize( 2000 );
429 aHScrollBar->SetLineSize( 300 );
430 aHScrollBar->SetPageSize( 2000 );
431 aHScrollBar->Enable();
432 aVScrollBar->Enable();
433 aVScrollBar->Show();
434 aHScrollBar->Show();
435 aScrollBarBox->Show();
440 void Shell::InitTabBar()
442 pTabBar->Enable();
443 pTabBar->Show();
444 pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
449 void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
451 AdjustPosSizePixel( rPos, rSize );
455 IMPL_LINK( Shell, TabBarSplitHdl, TabBar *, pTBar )
457 (void)pTBar;
458 bTabBarSplitted = true;
459 ArrangeTabBar();
461 return 0;
464 IMPL_LINK( Shell, TabBarHdl, TabBar *, pCurTabBar )
466 sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
467 BaseWindow* pWin = aWindowTable[ nCurId ];
468 DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
469 SetCurWindow( pWin );
471 return 0;
476 bool Shell::NextPage( bool bPrev )
478 bool bRet = false;
479 sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
481 if ( bPrev )
482 --nPos;
483 else
484 ++nPos;
486 if ( nPos < pTabBar->GetPageCount() )
488 BaseWindow* pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
489 SetCurWindow( pWin, true );
490 bRet = true;
493 return bRet;
498 void Shell::ArrangeTabBar()
500 long nBoxPos = aScrollBarBox->GetPosPixel().X() - 1;
501 long nPos = pTabBar->GetSplitSize();
502 if ( nPos <= nBoxPos )
504 Point aPnt( pTabBar->GetPosPixel() );
505 long nH = aHScrollBar->GetSizePixel().Height();
506 pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
507 long nScrlStart = aPnt.X() + nPos;
508 aHScrollBar->SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
509 aHScrollBar->Update();
515 ::svl::IUndoManager* Shell::GetUndoManager()
517 ::svl::IUndoManager* pMgr = NULL;
518 if( pCurWin )
519 pMgr = pCurWin->GetUndoManager();
521 return pMgr;
526 void Shell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
527 const SfxHint& rHint, const TypeId& )
529 if (GetShell())
531 if (SfxSimpleHint const* pSimpleHint = dynamic_cast<SfxSimpleHint const*>(&rHint))
533 switch (pSimpleHint->GetId())
535 case SFX_HINT_DYING:
537 EndListening( rBC, true /* log off all */ );
538 aObjectCatalog->UpdateEntries();
540 break;
543 if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
545 sal_uLong nHintId = pSbxHint->GetId();
546 if ( ( nHintId == SBX_HINT_BASICSTART ) ||
547 ( nHintId == SBX_HINT_BASICSTOP ) )
549 if (SfxBindings* pBindings = GetBindingsPtr())
551 pBindings->Invalidate( SID_BASICRUN );
552 pBindings->Update( SID_BASICRUN );
553 pBindings->Invalidate( SID_BASICCOMPILE );
554 pBindings->Update( SID_BASICCOMPILE );
555 pBindings->Invalidate( SID_BASICSTEPOVER );
556 pBindings->Update( SID_BASICSTEPOVER );
557 pBindings->Invalidate( SID_BASICSTEPINTO );
558 pBindings->Update( SID_BASICSTEPINTO );
559 pBindings->Invalidate( SID_BASICSTEPOUT );
560 pBindings->Update( SID_BASICSTEPOUT );
561 pBindings->Invalidate( SID_BASICSTOP );
562 pBindings->Update( SID_BASICSTOP );
563 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
564 pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
565 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
566 pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
567 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
568 pBindings->Update( SID_BASICIDE_MODULEDLG );
569 pBindings->Invalidate( SID_BASICLOAD );
570 pBindings->Update( SID_BASICLOAD );
573 if ( nHintId == SBX_HINT_BASICSTOP )
575 // not only at error/break or explicit stoppage,
576 // if the update is turned off due to a programming bug
577 BasicStopped();
578 if (pLayout)
579 pLayout->UpdateDebug(true); // clear...
580 if( m_pCurLocalizationMgr )
581 m_pCurLocalizationMgr->handleBasicStopped();
583 else if( m_pCurLocalizationMgr )
585 m_pCurLocalizationMgr->handleBasicStarted();
588 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
590 BaseWindow* pWin = it->second;
591 if ( nHintId == SBX_HINT_BASICSTART )
592 pWin->BasicStarted();
593 else
594 pWin->BasicStopped();
604 void Shell::CheckWindows()
606 bool bSetCurWindow = false;
607 std::vector<VclPtr<BaseWindow> > aDeleteVec;
608 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
610 BaseWindow* pWin = it->second;
611 if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
612 aDeleteVec.push_back( pWin );
614 for ( auto it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
616 BaseWindow* pWin = *it;
617 pWin->StoreData();
618 if ( pWin == pCurWin )
619 bSetCurWindow = true;
620 RemoveWindow( pWin, true, false );
622 if ( bSetCurWindow )
623 SetCurWindow( FindApplicationWindow(), true );
628 void Shell::RemoveWindows( const ScriptDocument& rDocument, const OUString& rLibName, bool bDestroy )
630 bool bChangeCurWindow = pCurWin;
631 std::vector<VclPtr<BaseWindow> > aDeleteVec;
632 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
634 BaseWindow* pWin = it->second;
635 if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
636 aDeleteVec.push_back( pWin );
638 for ( auto it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
640 BaseWindow* pWin = *it;
641 if ( pWin == pCurWin )
642 bChangeCurWindow = true;
643 pWin->StoreData();
644 RemoveWindow( pWin, bDestroy, false );
646 if ( bChangeCurWindow )
647 SetCurWindow( FindApplicationWindow(), true );
652 void Shell::UpdateWindows()
654 // remove all windows that may not be displayed
655 bool bChangeCurWindow = pCurWin == nullptr;
656 if ( !m_aCurLibName.isEmpty() )
658 std::vector<VclPtr<BaseWindow> > aDeleteVec;
659 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
661 BaseWindow* pWin = it->second;
662 if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
664 if ( pWin == pCurWin )
665 bChangeCurWindow = true;
666 pWin->StoreData();
667 // The request of RUNNING prevents the crash when in reschedule.
668 // Window is frozen at first, later the windows should be changed
669 // anyway to be marked as hidden instead of being deleted.
670 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
671 aDeleteVec.push_back( pWin );
674 for ( auto it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
676 RemoveWindow( *it, false, false );
680 if ( bCreatingWindow )
681 return;
683 BaseWindow* pNextActiveWindow = 0;
685 // show all windows that are to be shown
686 ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
687 for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
688 doc != aDocuments.end();
689 ++doc
692 StartListening( *doc->getBasicManager(), true /* log on only once */ );
694 // libraries
695 Sequence< OUString > aLibNames( doc->getLibraryNames() );
696 sal_Int32 nLibCount = aLibNames.getLength();
697 const OUString* pLibNames = aLibNames.getConstArray();
699 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
701 OUString aLibName = pLibNames[ i ];
703 if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
705 // check, if library is password protected and not verified
706 bool bProtected = false;
707 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
708 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
710 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
711 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
713 bProtected = true;
717 if ( !bProtected )
719 LibInfos::Item const* pLibInfoItem = 0;
720 if (ExtraData* pData = GetExtraData())
721 pLibInfoItem = pData->GetLibInfos().GetInfo(*doc, aLibName);
723 // modules
724 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
726 StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
727 if ( pLib )
728 ImplStartListening( pLib );
732 Sequence< OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
733 sal_Int32 nModCount = aModNames.getLength();
734 const OUString* pModNames = aModNames.getConstArray();
736 for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
738 OUString aModName = pModNames[ j ];
739 ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, false );
740 if ( !pWin )
741 pWin = CreateBasWin( *doc, aLibName, aModName );
742 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
743 pLibInfoItem->GetCurrentType() == TYPE_MODULE )
745 pNextActiveWindow = static_cast<BaseWindow*>(pWin);
749 catch (const container::NoSuchElementException& )
751 DBG_UNHANDLED_EXCEPTION();
755 // dialogs
756 Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
757 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
761 Sequence< OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
762 sal_Int32 nDlgCount = aDlgNames.getLength();
763 const OUString* pDlgNames = aDlgNames.getConstArray();
765 for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
767 OUString aDlgName = pDlgNames[ j ];
768 // this find only looks for non-suspended windows;
769 // suspended windows are handled in CreateDlgWin
770 VclPtr<DialogWindow> pWin = FindDlgWin( *doc, aLibName, aDlgName, false );
771 if ( !pWin )
772 pWin = CreateDlgWin( *doc, aLibName, aDlgName );
773 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
774 pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
776 pNextActiveWindow = static_cast<BaseWindow*>(pWin);
780 catch (const container::NoSuchElementException& )
782 DBG_UNHANDLED_EXCEPTION();
790 if ( bChangeCurWindow )
792 if ( !pNextActiveWindow )
794 pNextActiveWindow = FindApplicationWindow();
796 SetCurWindow( pNextActiveWindow, true );
800 void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
802 VclPtr<BaseWindow> pWindowTmp( pWindow_ );
804 DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
805 sal_uLong nKey = GetWindowId( pWindow_ );
806 pTabBar->RemovePage( (sal_uInt16)nKey );
807 aWindowTable.erase( nKey );
808 if ( pWindow_ == pCurWin )
810 if ( bAllowChangeCurWindow )
812 SetCurWindow( FindApplicationWindow(), true );
814 else
816 SetCurWindow( NULL, false );
819 if ( bDestroy )
821 if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
823 pWindowTmp.disposeAndClear();
825 else
827 pWindow_->AddStatus( BASWIN_TOBEKILLED );
828 pWindow_->Hide();
829 // In normal mode stop basic in windows to be deleted
830 // In VBA stop basic only if the running script is trying to delete
831 // its parent module
832 bool bStop = true;
833 if ( pWindow_->GetDocument().isInVBAMode() )
835 SbModule* pMod = StarBASIC::GetActiveModule();
836 if ( !pMod || ( pMod && ( !pMod->GetName().equals(pWindow_->GetName()) ) ) )
838 bStop = false;
841 if ( bStop )
843 StarBASIC::Stop();
844 // there will be no notify...
845 pWindow_->BasicStopped();
847 aWindowTable[ nKey ] = pWindow_; // jump in again
850 else
852 pWindow_->AddStatus( BASWIN_SUSPENDED );
853 pWindow_->Deactivating();
854 aWindowTable[ nKey ] = pWindow_; // jump in again
861 sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
863 nCurKey++;
864 aWindowTable[ nCurKey ] = pNewWin;
865 return nCurKey;
870 void Shell::InvalidateBasicIDESlots()
872 // only those that have an optic effect...
874 if (GetShell())
876 if (SfxBindings* pBindings = GetBindingsPtr())
878 pBindings->Invalidate( SID_COPY );
879 pBindings->Invalidate( SID_CUT );
880 pBindings->Invalidate( SID_PASTE );
881 pBindings->Invalidate( SID_UNDO );
882 pBindings->Invalidate( SID_REDO );
883 pBindings->Invalidate( SID_SAVEDOC );
884 pBindings->Invalidate( SID_SIGNATURE );
885 pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
886 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
887 pBindings->Invalidate( SID_BASICIDE_OBJCAT );
888 pBindings->Invalidate( SID_BASICSTOP );
889 pBindings->Invalidate( SID_BASICRUN );
890 pBindings->Invalidate( SID_BASICCOMPILE );
891 pBindings->Invalidate( SID_BASICLOAD );
892 pBindings->Invalidate( SID_BASICSAVEAS );
893 pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
894 pBindings->Invalidate( SID_BASICSTEPINTO );
895 pBindings->Invalidate( SID_BASICSTEPOVER );
896 pBindings->Invalidate( SID_BASICSTEPOUT );
897 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
898 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
899 pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
900 pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
901 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
902 pBindings->Invalidate( SID_PRINTDOC );
903 pBindings->Invalidate( SID_PRINTDOCDIRECT );
904 pBindings->Invalidate( SID_SETUPPRINTER );
905 pBindings->Invalidate( SID_DIALOG_TESTMODE );
907 pBindings->Invalidate( SID_DOC_MODIFIED );
908 pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
909 pBindings->Invalidate( SID_BASICIDE_STAT_POS );
910 pBindings->Invalidate( SID_ATTR_INSERT );
911 pBindings->Invalidate( SID_ATTR_SIZE );
916 void Shell::EnableScrollbars( bool bEnable )
918 aHScrollBar->Enable(bEnable);
919 aVScrollBar->Enable(bEnable);
922 void Shell::SetCurLib( const ScriptDocument& rDocument, const OUString& aLibName, bool bUpdateWindows, bool bCheck )
924 if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
926 ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
928 m_aCurDocument = rDocument;
929 m_aCurLibName = aLibName;
931 if ( pListener )
933 pListener->removeContainerListener( m_aCurDocument, m_aCurLibName );
934 pListener->addContainerListener( m_aCurDocument, aLibName );
937 if ( bUpdateWindows )
938 UpdateWindows();
940 SetMDITitle();
942 SetCurLibForLocalization( rDocument, aLibName );
944 if (SfxBindings* pBindings = GetBindingsPtr())
946 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
947 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
948 pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
953 void Shell::SetCurLibForLocalization( const ScriptDocument& rDocument, const OUString& aLibName )
955 // Create LocalizationMgr
956 Reference< resource::XStringResourceManager > xStringResourceManager;
959 if( !aLibName.isEmpty() )
961 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
962 xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
965 catch (const container::NoSuchElementException& )
968 m_pCurLocalizationMgr = boost::shared_ptr<LocalizationMgr>(new LocalizationMgr(this, rDocument, aLibName, xStringResourceManager));
969 m_pCurLocalizationMgr->handleTranslationbar();
972 void Shell::ImplStartListening( StarBASIC* pBasic )
974 StartListening( pBasic->GetBroadcaster(), true /* log on only once */ );
977 } // namespace basctl
979 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */