Bump version to 6.0-36
[LibreOffice.git] / basctl / source / basicide / basidesh.cxx
blob2519d39ea845992662e0300fc7f116ae7699aba9
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 <svx/svxids.hrc>
25 #include <strings.hrc>
26 #include "baside2.hxx"
27 #include <baside3.hxx>
28 #include "basdoc.hxx"
29 #include "basicbox.hxx"
30 #include <editeng/sizeitem.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 #ifdef DISABLE_DYNLOADING
44 /* Avoid clash with the ones from svx/source/form/typemap.cxx */
45 #define aSfxDocumentInfoItem_Impl basctl_source_basicide_basidesh_aSfxDocumentInfoItem_Impl
46 #endif
48 #define basctl_Shell
49 #define SFX_TYPEMAP
50 #include <basslots.hxx>
52 #ifdef DISABLE_DYNLOADING
53 #undef aSfxDocumentInfoItem_Impl
54 #endif
56 #include <iderdll.hxx>
57 #include <svx/pszctrl.hxx>
58 #include <svx/insctrl.hxx>
59 #include <svx/srchdlg.hxx>
60 #include <svx/tbcontrl.hxx>
61 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
62 #include <com/sun/star/container/XContainer.hpp>
63 #include <svx/xmlsecctrl.hxx>
64 #include <sfx2/viewfac.hxx>
65 #include <vcl/msgbox.hxx>
66 #include <vcl/settings.hxx>
67 #include <cppuhelper/implbase.hxx>
69 namespace basctl
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star;
75 class ContainerListenerImpl : public ::cppu::WeakImplHelper< container::XContainerListener >
77 Shell* mpShell;
78 public:
79 explicit ContainerListenerImpl(Shell* pShell)
80 : mpShell(pShell)
84 void addContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
86 try
88 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
89 if ( xContainer.is() )
91 uno::Reference< container::XContainerListener > xContainerListener( this );
92 xContainer->addContainerListener( xContainerListener );
95 catch(const uno::Exception& ) {}
97 void removeContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
99 try
101 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
102 if ( xContainer.is() )
104 uno::Reference< container::XContainerListener > xContainerListener( this );
105 xContainer->removeContainerListener( xContainerListener );
108 catch(const uno::Exception& ) {}
111 // XEventListener
112 virtual void SAL_CALL disposing( const lang::EventObject& ) override {}
114 // XContainerListener
115 virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) override
117 OUString sModuleName;
118 if( mpShell && ( Event.Accessor >>= sModuleName ) )
119 mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true );
121 virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) override { }
122 virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) override
124 OUString sModuleName;
125 if( mpShell && ( Event.Accessor >>= sModuleName ) )
127 VclPtr<ModulWindow> pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
128 if( pWin )
129 mpShell->RemoveWindow( pWin, true );
135 SFX_IMPL_NAMED_VIEWFACTORY( Shell, "Default" )
137 SFX_VIEW_REGISTRATION( DocShell );
140 SFX_IMPL_INTERFACE(basctl_Shell, SfxViewShell)
142 void basctl_Shell::InitInterface_Impl()
144 GetStaticInterface()->RegisterChildWindow(SID_SEARCH_DLG);
145 GetStaticInterface()->RegisterChildWindow(SID_SHOW_PROPERTYBROWSER, false, SfxShellFeature::BasicShowBrowser);
146 GetStaticInterface()->RegisterChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
148 GetStaticInterface()->RegisterPopupMenu("dialog");
151 unsigned Shell::nShellCount = 0;
153 Shell::Shell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
154 SfxViewShell( pFrame_, SfxViewShellFlags::NO_NEWWINDOW ),
155 m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
156 aHScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG )) ),
157 aVScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG )) ),
158 aScrollBarBox( VclPtr<ScrollBarBox>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE )) ),
159 pLayout(nullptr),
160 aObjectCatalog(VclPtr<ObjectCatalog>::Create(&GetViewFrame()->GetWindow())),
161 m_bAppBasicModified( false ),
162 m_aNotifier( *this )
164 m_xLibListener = new ContainerListenerImpl( this );
165 Init();
166 nShellCount++;
169 void Shell::Init()
171 SvxPosSizeStatusBarControl::RegisterControl();
172 SvxInsertStatusBarControl::RegisterControl();
173 XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
174 SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
175 SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
177 SvxSearchDialogWrapper::RegisterChildWindow();
179 GetExtraData()->ShellInCriticalSection() = true;
181 SetName( "BasicIDE" );
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 = nullptr;
191 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
192 bCreatingWindow = false;
194 pTabBar.reset(VclPtr<TabBar>::Create(&GetViewFrame()->GetWindow()));
196 nCurKey = 100;
197 InitScrollBars();
198 InitTabBar();
200 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
202 ShellCreated(this);
204 GetExtraData()->ShellInCriticalSection() = false;
206 // It's enough to create the controller ...
207 // It will be public by using magic :-)
208 new Controller(this);
210 // Force updating the title ! Because it must be set to the controller
211 // it has to be called directly after creating those controller.
212 SetMDITitle ();
214 UpdateWindows();
217 Shell::~Shell()
219 m_aNotifier.dispose();
221 ShellDestroyed(this);
223 // so that on a basic saving error, the shell doesn't pop right up again
224 GetExtraData()->ShellInCriticalSection() = true;
226 SetWindow( nullptr );
227 SetCurWindow( nullptr );
229 aObjectCatalog.disposeAndClear();
230 aScrollBarBox.disposeAndClear();
231 aVScrollBar.disposeAndClear();
232 aHScrollBar.disposeAndClear();
234 for (WindowTable::iterator it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
236 // no store; does already happen when the BasicManagers are destroyed
237 it->second.disposeAndClear();
240 // no store; does already happen when the BasicManagers are destroyed
241 aWindowTable.clear();
243 // Destroy all ContainerListeners for Basic Container.
244 if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
245 pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
247 GetExtraData()->ShellInCriticalSection() = false;
249 nShellCount--;
251 pDialogLayout.disposeAndClear();
252 pModulLayout.disposeAndClear();
253 pTabBar.disposeAndClear();
256 void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
258 if (pCurWin)
259 pCurWin->OnNewDocument();
261 UpdateWindows();
264 void Shell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
266 if (pCurWin)
267 pCurWin->OnNewDocument();
268 UpdateWindows();
271 void Shell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
273 StoreAllWindowData();
276 void Shell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
278 // #i115671: Update SID_SAVEDOC after saving is completed
279 if (SfxBindings* pBindings = GetBindingsPtr())
280 pBindings->Invalidate( SID_SAVEDOC );
283 void Shell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
285 StoreAllWindowData();
288 void Shell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
290 // not interested in
293 void Shell::onDocumentClosed( const ScriptDocument& _rDocument )
295 if ( !_rDocument.isValid() )
296 return;
298 bool bSetCurWindow = false;
299 bool bSetCurLib = ( _rDocument == m_aCurDocument );
300 std::vector<VclPtr<BaseWindow> > aDeleteVec;
302 // remove all windows which belong to this document
303 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
305 BaseWindow* pWin = it->second;
306 if ( pWin->IsDocument( _rDocument ) )
308 if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
310 pWin->AddStatus( BASWIN_TOBEKILLED );
311 pWin->Hide();
312 StarBASIC::Stop();
313 // there's no notify
314 pWin->BasicStopped();
316 else
317 aDeleteVec.emplace_back(pWin );
320 // delete windows outside main loop so we don't invalidate the original iterator
321 for (VclPtr<BaseWindow> const & pWin : aDeleteVec)
323 pWin->StoreData();
324 if ( pWin == pCurWin )
325 bSetCurWindow = true;
326 RemoveWindow( pWin, true, false );
329 // remove lib info
330 if (ExtraData* pData = GetExtraData())
331 pData->GetLibInfo().RemoveInfoFor( _rDocument );
333 if ( bSetCurLib )
334 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", true, false );
335 else if ( bSetCurWindow )
336 SetCurWindow( FindApplicationWindow(), true );
339 void Shell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
341 if (SfxBindings* pBindings = GetBindingsPtr())
342 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true );
343 SetMDITitle();
346 void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )
348 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
350 BaseWindow* pWin = it->second;
351 if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
352 pWin->SetReadOnly( _rDocument.isReadOnly() );
356 void Shell::StoreAllWindowData( bool bPersistent )
358 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
360 BaseWindow* pWin = it->second;
361 DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
362 if ( !pWin->IsSuspended() )
363 pWin->StoreData();
366 if ( bPersistent )
368 SfxGetpApp()->SaveBasicAndDialogContainer();
369 SetAppBasicModified(false);
371 if (SfxBindings* pBindings = GetBindingsPtr())
373 pBindings->Invalidate( SID_SAVEDOC );
374 pBindings->Update( SID_SAVEDOC );
380 bool Shell::PrepareClose( bool bUI )
382 // reset here because it's modified after printing etc. (DocInfo)
383 GetViewFrame()->GetObjectShell()->SetModified(false);
385 if ( StarBASIC::IsRunning() )
387 if( bUI )
389 vcl::Window *pParent = &GetViewFrame()->GetWindow();
390 ScopedVclPtrInstance<InfoBox>(pParent, IDEResId(RID_STR_CANNOTCLOSE))->Execute();
392 return false;
394 else
396 bool bCanClose = true;
397 for (WindowTableIt it = aWindowTable.begin(); bCanClose && (it != aWindowTable.end()); ++it)
399 BaseWindow* pWin = it->second;
400 if ( !pWin->CanClose() )
402 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
403 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
404 SetCurWindow( pWin, true );
405 bCanClose = false;
409 if ( bCanClose )
410 StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
412 return bCanClose;
416 void Shell::InitScrollBars()
418 aVScrollBar->SetLineSize( 300 );
419 aVScrollBar->SetPageSize( 2000 );
420 aHScrollBar->SetLineSize( 300 );
421 aHScrollBar->SetPageSize( 2000 );
422 aHScrollBar->Enable();
423 aVScrollBar->Enable();
424 aVScrollBar->Show();
425 aHScrollBar->Show();
426 aScrollBarBox->Show();
430 void Shell::InitTabBar()
432 pTabBar->Enable();
433 pTabBar->Show();
434 pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
438 void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
440 AdjustPosSizePixel( rPos, rSize );
444 IMPL_LINK( Shell, TabBarHdl, ::TabBar *, pCurTabBar, void )
446 sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
447 BaseWindow* pWin = aWindowTable[ nCurId ].get();
448 DBG_ASSERT( pWin, "Entry in TabBar is not matching a window!" );
449 SetCurWindow( pWin );
453 bool Shell::NextPage( bool bPrev )
455 bool bRet = false;
456 sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
458 if ( bPrev )
459 --nPos;
460 else
461 ++nPos;
463 if ( nPos < pTabBar->GetPageCount() )
465 VclPtr<BaseWindow> pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
466 SetCurWindow( pWin, true );
467 bRet = true;
470 return bRet;
473 ::svl::IUndoManager* Shell::GetUndoManager()
475 ::svl::IUndoManager* pMgr = nullptr;
476 if( pCurWin )
477 pMgr = pCurWin->GetUndoManager();
479 return pMgr;
483 void Shell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
485 if (GetShell())
487 if (rHint.GetId() == SfxHintId::Dying)
489 EndListening( rBC, true /* log off all */ );
490 aObjectCatalog->UpdateEntries();
493 if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
495 const SfxHintId nHintId = pSbxHint->GetId();
496 if ( ( nHintId == SfxHintId::BasicStart ) ||
497 ( nHintId == SfxHintId::BasicStop ) )
499 if (SfxBindings* pBindings = GetBindingsPtr())
501 pBindings->Invalidate( SID_BASICRUN );
502 pBindings->Update( SID_BASICRUN );
503 pBindings->Invalidate( SID_BASICCOMPILE );
504 pBindings->Update( SID_BASICCOMPILE );
505 pBindings->Invalidate( SID_BASICSTEPOVER );
506 pBindings->Update( SID_BASICSTEPOVER );
507 pBindings->Invalidate( SID_BASICSTEPINTO );
508 pBindings->Update( SID_BASICSTEPINTO );
509 pBindings->Invalidate( SID_BASICSTEPOUT );
510 pBindings->Update( SID_BASICSTEPOUT );
511 pBindings->Invalidate( SID_BASICSTOP );
512 pBindings->Update( SID_BASICSTOP );
513 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
514 pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
515 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
516 pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
517 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
518 pBindings->Update( SID_BASICIDE_MODULEDLG );
519 pBindings->Invalidate( SID_BASICLOAD );
520 pBindings->Update( SID_BASICLOAD );
523 if ( nHintId == SfxHintId::BasicStop )
525 // not only at error/break or explicit stoppage,
526 // if the update is turned off due to a programming bug
527 BasicStopped();
528 if (pLayout)
529 pLayout->UpdateDebug(true); // clear...
530 if( m_pCurLocalizationMgr )
531 m_pCurLocalizationMgr->handleBasicStopped();
533 else if( m_pCurLocalizationMgr )
535 m_pCurLocalizationMgr->handleBasicStarted();
538 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
540 BaseWindow* pWin = it->second;
541 if ( nHintId == SfxHintId::BasicStart )
542 pWin->BasicStarted();
543 else
544 pWin->BasicStopped();
552 void Shell::CheckWindows()
554 bool bSetCurWindow = false;
555 std::vector<VclPtr<BaseWindow> > aDeleteVec;
556 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
558 BaseWindow* pWin = it->second;
559 if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
560 aDeleteVec.emplace_back(pWin );
562 for ( VclPtr<BaseWindow> const & pWin : aDeleteVec )
564 pWin->StoreData();
565 if ( pWin == pCurWin )
566 bSetCurWindow = true;
567 RemoveWindow( pWin, true, false );
569 if ( bSetCurWindow )
570 SetCurWindow( FindApplicationWindow(), true );
574 void Shell::RemoveWindows( const ScriptDocument& rDocument, const OUString& rLibName )
576 bool bChangeCurWindow = pCurWin;
577 std::vector<VclPtr<BaseWindow> > aDeleteVec;
578 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
580 BaseWindow* pWin = it->second;
581 if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
582 aDeleteVec.emplace_back(pWin );
584 for ( VclPtr<BaseWindow> const & pWin : aDeleteVec )
586 if ( pWin == pCurWin )
587 bChangeCurWindow = true;
588 pWin->StoreData();
589 RemoveWindow( pWin, true/*bDestroy*/, false );
591 if ( bChangeCurWindow )
592 SetCurWindow( FindApplicationWindow(), true );
596 void Shell::UpdateWindows()
598 // remove all windows that may not be displayed
599 bool bChangeCurWindow = pCurWin == nullptr;
600 if ( !m_aCurLibName.isEmpty() )
602 std::vector<VclPtr<BaseWindow> > aDeleteVec;
603 for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
605 BaseWindow* pWin = it->second;
606 if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
608 if ( pWin == pCurWin )
609 bChangeCurWindow = true;
610 pWin->StoreData();
611 // The request of RUNNING prevents the crash when in reschedule.
612 // Window is frozen at first, later the windows should be changed
613 // anyway to be marked as hidden instead of being deleted.
614 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
615 aDeleteVec.emplace_back(pWin );
618 for ( auto it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
620 RemoveWindow( *it, false, false );
624 if ( bCreatingWindow )
625 return;
627 BaseWindow* pNextActiveWindow = nullptr;
629 // show all windows that are to be shown
630 ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
631 for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
632 doc != aDocuments.end();
633 ++doc
636 StartListening(*doc->getBasicManager(), DuplicateHandling::Prevent /* log on only once */);
638 // libraries
639 Sequence< OUString > aLibNames( doc->getLibraryNames() );
640 sal_Int32 nLibCount = aLibNames.getLength();
641 const OUString* pLibNames = aLibNames.getConstArray();
643 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
645 OUString aLibName = pLibNames[ i ];
647 if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
649 // check, if library is password protected and not verified
650 bool bProtected = false;
651 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
652 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
654 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
655 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
657 bProtected = true;
661 if ( !bProtected )
663 LibInfo::Item const* pLibInfoItem = nullptr;
664 if (ExtraData* pData = GetExtraData())
665 pLibInfoItem = pData->GetLibInfo().GetInfo(*doc, aLibName);
667 // modules
668 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
670 StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
671 if ( pLib )
672 StartListening(pLib->GetBroadcaster(), DuplicateHandling::Prevent /* log on only once */);
676 Sequence< OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
677 sal_Int32 nModCount = aModNames.getLength();
678 const OUString* pModNames = aModNames.getConstArray();
680 for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
682 OUString aModName = pModNames[ j ];
683 VclPtr<ModulWindow> pWin = FindBasWin( *doc, aLibName, aModName );
684 if ( !pWin )
685 pWin = CreateBasWin( *doc, aLibName, aModName );
686 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
687 pLibInfoItem->GetCurrentType() == TYPE_MODULE )
689 pNextActiveWindow = static_cast<BaseWindow*>(pWin);
693 catch (const container::NoSuchElementException& )
695 DBG_UNHANDLED_EXCEPTION();
699 // dialogs
700 Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
701 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
705 Sequence< OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
706 sal_Int32 nDlgCount = aDlgNames.getLength();
707 const OUString* pDlgNames = aDlgNames.getConstArray();
709 for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
711 OUString aDlgName = pDlgNames[ j ];
712 // this find only looks for non-suspended windows;
713 // suspended windows are handled in CreateDlgWin
714 VclPtr<DialogWindow> pWin = FindDlgWin( *doc, aLibName, aDlgName );
715 if ( !pWin )
716 pWin = CreateDlgWin( *doc, aLibName, aDlgName );
717 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
718 pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
720 pNextActiveWindow = static_cast<BaseWindow*>(pWin);
724 catch (const container::NoSuchElementException& )
726 DBG_UNHANDLED_EXCEPTION();
734 if ( bChangeCurWindow )
736 if ( !pNextActiveWindow )
738 pNextActiveWindow = FindApplicationWindow().get();
740 SetCurWindow( pNextActiveWindow, true );
744 void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
746 VclPtr<BaseWindow> pWindowTmp( pWindow_ );
748 DBG_ASSERT( pWindow_, "Cannot delete NULL-Pointer!" );
749 sal_uLong nKey = GetWindowId( pWindow_ );
750 pTabBar->RemovePage( (sal_uInt16)nKey );
751 aWindowTable.erase( nKey );
752 if ( pWindow_ == pCurWin )
754 if ( bAllowChangeCurWindow )
756 SetCurWindow( FindApplicationWindow(), true );
758 else
760 SetCurWindow( nullptr );
763 if ( bDestroy )
765 if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
767 pWindowTmp.disposeAndClear();
769 else
771 pWindow_->AddStatus( BASWIN_TOBEKILLED );
772 pWindow_->Hide();
773 // In normal mode stop basic in windows to be deleted
774 // In VBA stop basic only if the running script is trying to delete
775 // its parent module
776 bool bStop = true;
777 if ( pWindow_->GetDocument().isInVBAMode() )
779 SbModule* pMod = StarBASIC::GetActiveModule();
780 if ( !pMod || pMod->GetName() != pWindow_->GetName() )
782 bStop = false;
785 if ( bStop )
787 StarBASIC::Stop();
788 // there will be no notify...
789 pWindow_->BasicStopped();
791 aWindowTable[ nKey ] = pWindow_; // jump in again
794 else
796 pWindow_->AddStatus( BASWIN_SUSPENDED );
797 pWindow_->Deactivating();
798 aWindowTable[ nKey ] = pWindow_; // jump in again
804 sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
806 nCurKey++;
807 aWindowTable[ nCurKey ] = pNewWin;
808 return nCurKey;
812 void Shell::InvalidateBasicIDESlots()
814 // only those that have an optic effect...
816 if (GetShell())
818 if (SfxBindings* pBindings = GetBindingsPtr())
820 pBindings->Invalidate( SID_COPY );
821 pBindings->Invalidate( SID_CUT );
822 pBindings->Invalidate( SID_PASTE );
823 pBindings->Invalidate( SID_UNDO );
824 pBindings->Invalidate( SID_REDO );
825 pBindings->Invalidate( SID_SAVEDOC );
826 pBindings->Invalidate( SID_SIGNATURE );
827 pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
828 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
829 pBindings->Invalidate( SID_BASICIDE_OBJCAT );
830 pBindings->Invalidate( SID_BASICSTOP );
831 pBindings->Invalidate( SID_BASICRUN );
832 pBindings->Invalidate( SID_BASICCOMPILE );
833 pBindings->Invalidate( SID_BASICLOAD );
834 pBindings->Invalidate( SID_BASICSAVEAS );
835 pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
836 pBindings->Invalidate( SID_BASICSTEPINTO );
837 pBindings->Invalidate( SID_BASICSTEPOVER );
838 pBindings->Invalidate( SID_BASICSTEPOUT );
839 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
840 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
841 pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
842 pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
844 pBindings->Invalidate( SID_PRINTDOC );
845 pBindings->Invalidate( SID_PRINTDOCDIRECT );
846 pBindings->Invalidate( SID_SETUPPRINTER );
847 pBindings->Invalidate( SID_DIALOG_TESTMODE );
849 pBindings->Invalidate( SID_DOC_MODIFIED );
850 pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
851 pBindings->Invalidate( SID_BASICIDE_STAT_POS );
852 pBindings->Invalidate( SID_ATTR_INSERT );
853 pBindings->Invalidate( SID_ATTR_SIZE );
858 void Shell::InvalidateControlSlots()
860 if (GetShell())
862 if (SfxBindings* pBindings = GetBindingsPtr())
864 pBindings->Invalidate( SID_INSERT_FORM_RADIO );
865 pBindings->Invalidate( SID_INSERT_FORM_CHECK );
866 pBindings->Invalidate( SID_INSERT_FORM_LIST );
867 pBindings->Invalidate( SID_INSERT_FORM_COMBO );
868 pBindings->Invalidate( SID_INSERT_FORM_VSCROLL );
869 pBindings->Invalidate( SID_INSERT_FORM_HSCROLL );
870 pBindings->Invalidate( SID_INSERT_FORM_SPIN );
872 pBindings->Invalidate( SID_INSERT_SELECT );
873 pBindings->Invalidate( SID_INSERT_PUSHBUTTON );
874 pBindings->Invalidate( SID_INSERT_RADIOBUTTON );
875 pBindings->Invalidate( SID_INSERT_CHECKBOX );
876 pBindings->Invalidate( SID_INSERT_LISTBOX );
877 pBindings->Invalidate( SID_INSERT_COMBOBOX );
878 pBindings->Invalidate( SID_INSERT_GROUPBOX );
879 pBindings->Invalidate( SID_INSERT_EDIT );
880 pBindings->Invalidate( SID_INSERT_FIXEDTEXT );
881 pBindings->Invalidate( SID_INSERT_IMAGECONTROL );
882 pBindings->Invalidate( SID_INSERT_PROGRESSBAR );
883 pBindings->Invalidate( SID_INSERT_HSCROLLBAR );
884 pBindings->Invalidate( SID_INSERT_VSCROLLBAR );
885 pBindings->Invalidate( SID_INSERT_HFIXEDLINE );
886 pBindings->Invalidate( SID_INSERT_VFIXEDLINE );
887 pBindings->Invalidate( SID_INSERT_DATEFIELD );
888 pBindings->Invalidate( SID_INSERT_TIMEFIELD );
889 pBindings->Invalidate( SID_INSERT_NUMERICFIELD );
890 pBindings->Invalidate( SID_INSERT_CURRENCYFIELD );
891 pBindings->Invalidate( SID_INSERT_FORMATTEDFIELD );
892 pBindings->Invalidate( SID_INSERT_PATTERNFIELD );
893 pBindings->Invalidate( SID_INSERT_FILECONTROL );
894 pBindings->Invalidate( SID_INSERT_SPINBUTTON );
895 pBindings->Invalidate( SID_INSERT_TREECONTROL );
896 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
901 void Shell::EnableScrollbars( bool bEnable )
903 aHScrollBar->Enable(bEnable);
904 aVScrollBar->Enable(bEnable);
907 void Shell::SetCurLib( const ScriptDocument& rDocument, const 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, const 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 = std::make_shared<LocalizationMgr>(this, rDocument, aLibName, xStringResourceManager);
954 m_pCurLocalizationMgr->handleTranslationbar();
957 } // namespace basctl
959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */