Revert "Related tdf#158739: blacklist Nvidia RTX 4050 for Skia hardware"
[LibreOffice.git] / basctl / source / basicide / basidesh.cxx
blobd23da94d268f02d4528cc7e7688eb799d632b543
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 <comphelper/diagnose_ex.hxx>
23 #include <basic/basmgr.hxx>
24 #include <svx/zoomsliderctrl.hxx>
25 #include <svx/zoomslideritem.hxx>
26 #include <svx/svxids.hrc>
27 #include <iderid.hxx>
28 #include <strings.hrc>
29 #include "baside2.hxx"
30 #include <baside3.hxx>
31 #include "basdoc.hxx"
32 #include <IDEComboBox.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include "iderdll2.hxx"
35 #include <basidectrlr.hxx>
36 #include <basidesh.hxx>
37 #include <basobj.hxx>
38 #include <localizationmgr.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/dinfdlg.hxx>
42 #include <sfx2/infobar.hxx>
43 #include <sfx2/minfitem.hxx>
44 #include <sfx2/objface.hxx>
45 #include <sfx2/viewfrm.hxx>
46 #include <svl/srchitem.hxx>
47 #include <tools/debug.hxx>
48 #include <unotools/viewoptions.hxx>
50 #if defined(DISABLE_DYNLOADING) || ENABLE_MERGELIBS
51 /* Avoid clash with the ones from svx/source/form/typemap.cxx */
52 #define aSfxDocumentInfoItem_Impl basctl_source_basicide_basidesh_aSfxDocumentInfoItem_Impl
53 #define aSfxUnoAnyItem_Impl basctl_source_basicide_basidesh_aSfxUnoAnyItem_Impl
54 #endif
56 #define ShellClass_basctl_Shell
57 #define SFX_TYPEMAP
58 #include <basslots.hxx>
60 #if defined(DISABLE_DYNLOADING) || ENABLE_MERGELIBS
61 #undef aSfxDocumentInfoItem_Impl
62 #undef aSfxUnoAnyItem_Impl
63 #endif
65 #include <iderdll.hxx>
66 #include <svx/pszctrl.hxx>
67 #include <svx/insctrl.hxx>
68 #include <svx/srchdlg.hxx>
69 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
70 #include <com/sun/star/container/XContainer.hpp>
71 #include <svx/xmlsecctrl.hxx>
72 #include <sfx2/viewfac.hxx>
73 #include <vcl/weld.hxx>
74 #include <vcl/settings.hxx>
75 #include <vcl/svapp.hxx>
76 #include <cppuhelper/implbase.hxx>
78 namespace basctl
80 constexpr OUString BASIC_IDE_EDITOR_WINDOW = u"BasicIDEEditorWindow"_ustr;
81 constexpr OUString BASIC_IDE_CURRENT_ZOOM = u"CurrentZoom"_ustr;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star;
86 class ContainerListenerImpl : public ::cppu::WeakImplHelper< container::XContainerListener >
88 Shell* mpShell;
89 public:
90 explicit ContainerListenerImpl(Shell* pShell)
91 : mpShell(pShell)
95 void addContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
97 try
99 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
100 if ( xContainer.is() )
102 uno::Reference< container::XContainerListener > xContainerListener( this );
103 xContainer->addContainerListener( xContainerListener );
106 catch(const uno::Exception& ) {}
108 void removeContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
112 uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
113 if ( xContainer.is() )
115 uno::Reference< container::XContainerListener > xContainerListener( this );
116 xContainer->removeContainerListener( xContainerListener );
119 catch(const uno::Exception& ) {}
122 // XEventListener
123 virtual void SAL_CALL disposing( const lang::EventObject& ) override {}
125 // XContainerListener
126 virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) override
128 OUString sModuleName;
129 if( mpShell && ( Event.Accessor >>= sModuleName ) )
130 mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true );
132 virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) override { }
133 virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) override
135 OUString sModuleName;
136 if( mpShell && ( Event.Accessor >>= sModuleName ) )
138 VclPtr<ModulWindow> pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
139 if( pWin )
140 mpShell->RemoveWindow( pWin, true );
146 SFX_IMPL_NAMED_VIEWFACTORY( Shell, "Default" )
148 SFX_VIEW_REGISTRATION( DocShell );
151 SFX_IMPL_INTERFACE(basctl_Shell, SfxViewShell)
153 void basctl_Shell::InitInterface_Impl()
155 GetStaticInterface()->RegisterChildWindow(SID_SEARCH_DLG);
156 GetStaticInterface()->RegisterChildWindow(SID_SHOW_PROPERTYBROWSER, false, SfxShellFeature::BasicShowBrowser);
157 GetStaticInterface()->RegisterChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
159 GetStaticInterface()->RegisterPopupMenu("dialog");
162 unsigned Shell::nShellCount = 0;
164 Shell::Shell( SfxViewFrame& rFrame_, SfxViewShell* /* pOldShell */ ) :
165 SfxViewShell( rFrame_, SfxViewShellFlags::NO_NEWWINDOW ),
166 m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
167 aHScrollBar( VclPtr<ScrollAdaptor>::Create(&GetViewFrame().GetWindow(), true) ),
168 aVScrollBar( VclPtr<ScrollAdaptor>::Create(&GetViewFrame().GetWindow(), false) ),
169 pLayout(nullptr),
170 aObjectCatalog(VclPtr<ObjectCatalog>::Create(&GetViewFrame().GetWindow())),
171 m_bAppBasicModified( false ),
172 m_aNotifier( *this )
174 m_xLibListener = new ContainerListenerImpl( this );
175 Init();
176 nShellCount++;
179 void Shell::Init()
181 SvxPosSizeStatusBarControl::RegisterControl();
182 SvxInsertStatusBarControl::RegisterControl();
183 XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
185 SvxSearchDialogWrapper::RegisterChildWindow();
187 GetExtraData()->ShellInCriticalSection() = true;
189 SetName( "BasicIDE" );
191 LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
192 LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
193 SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER );
195 GetViewFrame().GetWindow().SetBackground(
196 GetViewFrame().GetWindow().GetSettings().GetStyleSettings().GetWindowColor()
199 pCurWin = nullptr;
200 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
201 bCreatingWindow = false;
203 pTabBar.reset(VclPtr<TabBar>::Create(&GetViewFrame().GetWindow()));
205 nCurKey = 100;
206 InitScrollBars();
207 InitTabBar();
208 InitZoomLevel();
210 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
212 ShellCreated(this);
214 GetExtraData()->ShellInCriticalSection() = false;
216 // It's enough to create the controller ...
217 // It will be public by using magic :-)
218 new Controller(this);
220 // Force updating the title ! Because it must be set to the controller
221 // it has to be called directly after creating those controller.
222 SetMDITitle ();
224 UpdateWindows();
227 Shell::~Shell()
229 m_aNotifier.dispose();
231 ShellDestroyed(this);
233 // so that on a basic saving error, the shell doesn't pop right up again
234 GetExtraData()->ShellInCriticalSection() = true;
236 SetWindow( nullptr );
237 SetCurWindow( nullptr );
239 aObjectCatalog.disposeAndClear();
240 aVScrollBar.disposeAndClear();
241 aHScrollBar.disposeAndClear();
243 for (auto & window : aWindowTable)
245 // no store; does already happen when the BasicManagers are destroyed
246 window.second.disposeAndClear();
249 // no store; does already happen when the BasicManagers are destroyed
250 aWindowTable.clear();
252 // Destroy all ContainerListeners for Basic Container.
253 if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
254 pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
256 GetExtraData()->ShellInCriticalSection() = false;
258 nShellCount--;
260 pDialogLayout.disposeAndClear();
261 pModulLayout.disposeAndClear();
262 pTabBar.disposeAndClear();
264 // Remember current zoom level
265 SvtViewOptions(EViewType::Window, BASIC_IDE_EDITOR_WINDOW).SetUserItem(
266 BASIC_IDE_CURRENT_ZOOM, Any(m_nCurrentZoomSliderValue));
269 void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
271 if (pCurWin)
272 pCurWin->OnNewDocument();
274 UpdateWindows();
277 void Shell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
279 if (pCurWin)
280 pCurWin->OnNewDocument();
281 UpdateWindows();
284 void Shell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
286 StoreAllWindowData();
289 void Shell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
291 // #i115671: Update SID_SAVEDOC after saving is completed
292 if (SfxBindings* pBindings = GetBindingsPtr())
293 pBindings->Invalidate( SID_SAVEDOC );
296 void Shell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
298 StoreAllWindowData();
301 void Shell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
303 // not interested in
306 void Shell::onDocumentClosed( const ScriptDocument& _rDocument )
308 if ( !_rDocument.isValid() )
309 return;
311 bool bSetCurWindow = false;
312 bool bSetCurLib = ( _rDocument == m_aCurDocument );
313 std::vector<VclPtr<BaseWindow> > aDeleteVec;
315 // remove all windows which belong to this document
316 for (auto const& window : aWindowTable)
318 BaseWindow* pWin = window.second;
319 if ( pWin->IsDocument( _rDocument ) )
321 if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
323 pWin->AddStatus( BASWIN_TOBEKILLED );
324 pWin->Hide();
325 StarBASIC::Stop();
326 // there's no notify
327 pWin->BasicStopped();
329 else
330 aDeleteVec.emplace_back(pWin );
333 // delete windows outside main loop so we don't invalidate the original iterator
334 for (VclPtr<BaseWindow> const & pWin : aDeleteVec)
336 pWin->StoreData();
337 if ( pWin == pCurWin )
338 bSetCurWindow = true;
339 RemoveWindow( pWin, true, false );
342 // remove lib info
343 if (ExtraData* pData = GetExtraData())
344 pData->GetLibInfo().RemoveInfoFor( _rDocument );
346 if ( bSetCurLib )
347 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", true, false );
348 else if ( bSetCurWindow )
349 SetCurWindow( FindApplicationWindow(), true );
352 void Shell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
354 if (SfxBindings* pBindings = GetBindingsPtr())
355 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true );
356 SetMDITitle();
359 void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )
361 for (auto const& window : aWindowTable)
363 BaseWindow* pWin = window.second;
364 if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
365 pWin->SetReadOnly( _rDocument.isReadOnly() );
369 void Shell::InitZoomLevel()
371 m_nCurrentZoomSliderValue = DEFAULT_ZOOM_LEVEL;
372 SvtViewOptions aWinOpt(EViewType::Window, BASIC_IDE_EDITOR_WINDOW);
373 if (aWinOpt.Exists())
377 aWinOpt.GetUserItem(BASIC_IDE_CURRENT_ZOOM) >>= m_nCurrentZoomSliderValue;
379 catch(const css::container::NoSuchElementException&)
380 { TOOLS_WARN_EXCEPTION("basctl.basicide", "Zoom level not defined"); }
384 // Applies the new zoom level to all open editor windows
385 void Shell::SetGlobalEditorZoomLevel(sal_uInt16 nNewZoomLevel)
387 for (auto const& window : aWindowTable)
389 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(window.second.get());
390 if (pModuleWindow)
392 EditorWindow& pEditorWindow = pModuleWindow->GetEditorWindow();
393 pEditorWindow.SetEditorZoomLevel(nNewZoomLevel);
397 // Update the zoom slider value based on the new global zoom level
398 m_nCurrentZoomSliderValue = nNewZoomLevel;
400 if (SfxBindings* pBindings = GetBindingsPtr())
402 pBindings->Invalidate( SID_BASICIDE_CURRENT_ZOOM );
403 pBindings->Invalidate( SID_ATTR_ZOOMSLIDER );
407 void Shell::StoreAllWindowData( bool bPersistent )
409 for (auto const& window : aWindowTable)
411 BaseWindow* pWin = window.second;
412 DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
413 if ( !pWin->IsSuspended() )
414 pWin->StoreData();
417 if ( bPersistent )
419 SfxGetpApp()->SaveBasicAndDialogContainer();
420 SetAppBasicModified(false);
422 if (SfxBindings* pBindings = GetBindingsPtr())
424 pBindings->Invalidate( SID_SAVEDOC );
425 pBindings->Update( SID_SAVEDOC );
430 bool Shell::PrepareClose( bool bUI )
432 // reset here because it's modified after printing etc. (DocInfo)
433 GetViewFrame().GetObjectShell()->SetModified(false);
435 if ( StarBASIC::IsRunning() )
437 if( bUI )
439 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetViewFrame().GetFrameWeld(),
440 VclMessageType::Info, VclButtonsType::Ok,
441 IDEResId(RID_STR_CANNOTCLOSE)));
442 xInfoBox->run();
444 return false;
446 else
448 StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
449 return true;
453 void Shell::InitScrollBars()
455 aVScrollBar->SetLineSize( 300 );
456 aVScrollBar->SetPageSize( 2000 );
457 aHScrollBar->SetLineSize( 300 );
458 aHScrollBar->SetPageSize( 2000 );
461 void Shell::InitTabBar()
463 pTabBar->Enable();
464 pTabBar->Show();
465 pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
468 void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
470 AdjustPosSizePixel( rPos, rSize );
473 IMPL_LINK( Shell, TabBarHdl, ::TabBar *, pCurTabBar, void )
475 sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
476 BaseWindow* pWin = aWindowTable[ nCurId ].get();
477 DBG_ASSERT( pWin, "Entry in TabBar is not matching a window!" );
478 SetCurWindow( pWin );
482 bool Shell::NextPage( bool bPrev )
484 bool bRet = false;
485 sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
487 if ( bPrev )
488 --nPos;
489 else
490 ++nPos;
492 if ( nPos < pTabBar->GetPageCount() )
494 VclPtr<BaseWindow> pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
495 SetCurWindow( pWin, true );
496 bRet = true;
499 return bRet;
502 SfxUndoManager* Shell::GetUndoManager()
504 SfxUndoManager* pMgr = nullptr;
505 if( pCurWin )
506 pMgr = pCurWin->GetUndoManager();
508 return pMgr;
512 void Shell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
514 if (!GetShell())
515 return;
517 if (rHint.GetId() == SfxHintId::Dying)
519 EndListening( rBC, true /* log off all */ );
520 aObjectCatalog->UpdateEntries();
523 SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint);
524 if (!pSbxHint)
525 return;
527 const SfxHintId nHintId = pSbxHint->GetId();
528 if ( ( nHintId != SfxHintId::BasicStart ) &&
529 ( nHintId != SfxHintId::BasicStop ) )
530 return;
532 if (SfxBindings* pBindings = GetBindingsPtr())
534 pBindings->Invalidate( SID_BASICRUN );
535 pBindings->Update( SID_BASICRUN );
536 pBindings->Invalidate( SID_BASICCOMPILE );
537 pBindings->Update( SID_BASICCOMPILE );
538 pBindings->Invalidate( SID_BASICSTEPOVER );
539 pBindings->Update( SID_BASICSTEPOVER );
540 pBindings->Invalidate( SID_BASICSTEPINTO );
541 pBindings->Update( SID_BASICSTEPINTO );
542 pBindings->Invalidate( SID_BASICSTEPOUT );
543 pBindings->Update( SID_BASICSTEPOUT );
544 pBindings->Invalidate( SID_BASICSTOP );
545 pBindings->Update( SID_BASICSTOP );
546 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
547 pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
548 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
549 pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
550 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
551 pBindings->Update( SID_BASICIDE_MODULEDLG );
552 pBindings->Invalidate( SID_BASICLOAD );
553 pBindings->Update( SID_BASICLOAD );
556 if ( nHintId == SfxHintId::BasicStop )
558 // not only at error/break or explicit stoppage,
559 // if the update is turned off due to a programming bug
560 BasicStopped();
561 if (pLayout)
562 pLayout->UpdateDebug(true); // clear...
563 if( m_pCurLocalizationMgr )
564 m_pCurLocalizationMgr->handleBasicStopped();
566 else if( m_pCurLocalizationMgr )
568 m_pCurLocalizationMgr->handleBasicStarted();
571 for (auto const& window : aWindowTable)
573 BaseWindow* pWin = window.second;
574 if ( nHintId == SfxHintId::BasicStart )
575 pWin->BasicStarted();
576 else
577 pWin->BasicStopped();
582 void Shell::CheckWindows()
584 bool bSetCurWindow = false;
585 std::vector<VclPtr<BaseWindow> > aDeleteVec;
586 for (auto const& window : aWindowTable)
588 BaseWindow* pWin = window.second;
589 if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
590 aDeleteVec.emplace_back(pWin );
592 for ( VclPtr<BaseWindow> const & pWin : aDeleteVec )
594 pWin->StoreData();
595 if ( pWin == pCurWin )
596 bSetCurWindow = true;
597 RemoveWindow( pWin, true, false );
599 if ( bSetCurWindow )
600 SetCurWindow( FindApplicationWindow(), true );
604 void Shell::RemoveWindows( const ScriptDocument& rDocument, std::u16string_view rLibName )
606 bool bChangeCurWindow = pCurWin;
607 std::vector<VclPtr<BaseWindow> > aDeleteVec;
608 for (auto const& window : aWindowTable)
610 BaseWindow* pWin = window.second;
611 if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
612 aDeleteVec.emplace_back(pWin );
614 for ( VclPtr<BaseWindow> const & pWin : aDeleteVec )
616 if ( pWin == pCurWin )
617 bChangeCurWindow = true;
618 pWin->StoreData();
619 RemoveWindow( pWin, true/*bDestroy*/, false );
621 if ( bChangeCurWindow )
622 SetCurWindow( FindApplicationWindow(), true );
626 void Shell::UpdateWindows()
628 // remove all windows that may not be displayed
629 bool bChangeCurWindow = pCurWin == nullptr;
630 // stores the total number of modules and dialogs visible
631 sal_uInt16 nTotalTabs = 0;
633 if ( !m_aCurLibName.isEmpty() )
635 std::vector<VclPtr<BaseWindow> > aDeleteVec;
636 for (auto const& window : aWindowTable)
638 BaseWindow* pWin = window.second;
639 if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
641 if ( pWin == pCurWin )
642 bChangeCurWindow = true;
643 pWin->StoreData();
644 // The request of RUNNING prevents the crash when in reschedule.
645 // Window is frozen at first, later the windows should be changed
646 // anyway to be marked as hidden instead of being deleted.
647 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
648 aDeleteVec.emplace_back(pWin );
651 for (auto const& elem : aDeleteVec)
653 RemoveWindow( elem, false, false );
657 if ( bCreatingWindow )
658 return;
660 BaseWindow* pNextActiveWindow = nullptr;
662 // show all windows that are to be shown
663 ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
664 for (auto const& doc : aDocuments)
666 StartListening(*doc.getBasicManager(), DuplicateHandling::Prevent /* log on only once */);
668 // libraries
669 Sequence< OUString > aLibNames( doc.getLibraryNames() );
670 sal_Int32 nLibCount = aLibNames.getLength();
671 const OUString* pLibNames = aLibNames.getConstArray();
673 for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
675 OUString aLibName = pLibNames[ i ];
677 if ( m_aCurLibName.isEmpty() || ( doc == m_aCurDocument && aLibName == m_aCurLibName ) )
679 // check, if library is password protected and not verified
680 bool bProtected = false;
681 Reference< script::XLibraryContainer > xModLibContainer( doc.getLibraryContainer( E_SCRIPTS ) );
682 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
684 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
685 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
687 bProtected = true;
691 if ( !bProtected )
693 LibInfo::Item const* pLibInfoItem = nullptr;
694 if (ExtraData* pData = GetExtraData())
695 pLibInfoItem = pData->GetLibInfo().GetInfo(doc, aLibName);
697 // modules
698 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
700 StarBASIC* pLib = doc.getBasicManager()->GetLib( aLibName );
701 if ( pLib )
702 StartListening(pLib->GetBroadcaster(), DuplicateHandling::Prevent /* log on only once */);
706 Sequence< OUString > aModNames( doc.getObjectNames( E_SCRIPTS, aLibName ) );
707 sal_Int32 nModCount = aModNames.getLength();
708 const OUString* pModNames = aModNames.getConstArray();
709 nTotalTabs += nModCount;
711 for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
713 OUString aModName = pModNames[ j ];
714 VclPtr<ModulWindow> pWin = FindBasWin( doc, aLibName, aModName );
715 if ( !pWin )
716 pWin = CreateBasWin( doc, aLibName, aModName );
717 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
718 pLibInfoItem->GetCurrentType() == TYPE_MODULE )
720 pNextActiveWindow = pWin;
724 catch (const container::NoSuchElementException& )
726 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
730 // dialogs
731 Reference< script::XLibraryContainer > xDlgLibContainer( doc.getLibraryContainer( E_DIALOGS ) );
732 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
736 Sequence< OUString > aDlgNames = doc.getObjectNames( E_DIALOGS, aLibName );
737 sal_Int32 nDlgCount = aDlgNames.getLength();
738 const OUString* pDlgNames = aDlgNames.getConstArray();
739 nTotalTabs += nDlgCount;
741 for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
743 OUString aDlgName = pDlgNames[ j ];
744 // this find only looks for non-suspended windows;
745 // suspended windows are handled in CreateDlgWin
746 VclPtr<DialogWindow> pWin = FindDlgWin( doc, aLibName, aDlgName );
747 if ( !pWin )
748 pWin = CreateDlgWin( doc, aLibName, aDlgName );
749 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
750 pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
752 pNextActiveWindow = pWin;
756 catch (const container::NoSuchElementException& )
758 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
766 if ( bChangeCurWindow )
768 if ( nTotalTabs == 0 )
770 // If no tabs are opened, create a generic module and make it visible
771 pNextActiveWindow = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() );
773 else if ( !pNextActiveWindow )
775 pNextActiveWindow = FindApplicationWindow().get();
777 SetCurWindow( pNextActiveWindow, true );
781 void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
783 VclPtr<BaseWindow> pWindowTmp( pWindow_ );
785 DBG_ASSERT( pWindow_, "Cannot delete NULL-Pointer!" );
786 sal_uInt16 nKey = GetWindowId( pWindow_ );
787 pTabBar->RemovePage( nKey );
788 aWindowTable.erase( nKey );
789 if ( pWindow_ == pCurWin )
791 if ( bAllowChangeCurWindow )
793 SetCurWindow( FindApplicationWindow(), true );
795 else
797 SetCurWindow( nullptr );
800 if ( bDestroy )
802 if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
804 pWindowTmp.disposeAndClear();
806 else
808 pWindow_->AddStatus( BASWIN_TOBEKILLED );
809 pWindow_->Hide();
810 // In normal mode stop basic in windows to be deleted
811 // In VBA stop basic only if the running script is trying to delete
812 // its parent module
813 bool bStop = true;
814 if ( pWindow_->GetDocument().isInVBAMode() )
816 SbModule* pMod = StarBASIC::GetActiveModule();
817 if ( !pMod || pMod->GetName() != pWindow_->GetName() )
819 bStop = false;
822 if ( bStop )
824 StarBASIC::Stop();
825 // there will be no notify...
826 pWindow_->BasicStopped();
828 aWindowTable[ nKey ] = pWindow_; // jump in again
831 else
833 pWindow_->AddStatus( BASWIN_SUSPENDED );
834 pWindow_->Deactivating();
835 aWindowTable[ nKey ] = pWindow_; // jump in again
841 sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
843 nCurKey++;
844 aWindowTable[ nCurKey ] = pNewWin;
845 return nCurKey;
849 void Shell::InvalidateBasicIDESlots()
851 // only those that have an optic effect...
853 if (!GetShell())
854 return;
856 SfxBindings* pBindings = GetBindingsPtr();
857 if (!pBindings)
858 return;
860 pBindings->Invalidate( SID_COPY );
861 pBindings->Invalidate( SID_CUT );
862 pBindings->Invalidate( SID_PASTE );
863 pBindings->Invalidate( SID_UNDO );
864 pBindings->Invalidate( SID_REDO );
865 pBindings->Invalidate( SID_SAVEDOC );
866 pBindings->Invalidate( SID_SIGNATURE );
867 pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
868 pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
869 pBindings->Invalidate( SID_BASICIDE_OBJCAT );
870 pBindings->Invalidate( SID_BASICSTOP );
871 pBindings->Invalidate( SID_BASICRUN );
872 pBindings->Invalidate( SID_BASICCOMPILE );
873 pBindings->Invalidate( SID_BASICLOAD );
874 pBindings->Invalidate( SID_BASICSAVEAS );
875 pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
876 pBindings->Invalidate( SID_BASICSTEPINTO );
877 pBindings->Invalidate( SID_BASICSTEPOVER );
878 pBindings->Invalidate( SID_BASICSTEPOUT );
879 pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
880 pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
881 pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
882 pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
884 pBindings->Invalidate( SID_PRINTDOC );
885 pBindings->Invalidate( SID_PRINTDOCDIRECT );
886 pBindings->Invalidate( SID_SETUPPRINTER );
887 pBindings->Invalidate( SID_DIALOG_TESTMODE );
889 pBindings->Invalidate( SID_DOC_MODIFIED );
890 pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
891 pBindings->Invalidate( SID_BASICIDE_STAT_POS );
892 pBindings->Invalidate( SID_ATTR_INSERT );
893 pBindings->Invalidate( SID_ATTR_SIZE );
896 void Shell::InvalidateControlSlots()
898 if (!GetShell())
899 return;
901 SfxBindings* pBindings = GetBindingsPtr();
902 if (!pBindings)
903 return;
905 pBindings->Invalidate( SID_INSERT_FORM_RADIO );
906 pBindings->Invalidate( SID_INSERT_FORM_CHECK );
907 pBindings->Invalidate( SID_INSERT_FORM_LIST );
908 pBindings->Invalidate( SID_INSERT_FORM_COMBO );
909 pBindings->Invalidate( SID_INSERT_FORM_VSCROLL );
910 pBindings->Invalidate( SID_INSERT_FORM_HSCROLL );
911 pBindings->Invalidate( SID_INSERT_FORM_SPIN );
913 pBindings->Invalidate( SID_INSERT_SELECT );
914 pBindings->Invalidate( SID_INSERT_PUSHBUTTON );
915 pBindings->Invalidate( SID_INSERT_RADIOBUTTON );
916 pBindings->Invalidate( SID_INSERT_CHECKBOX );
917 pBindings->Invalidate( SID_INSERT_LISTBOX );
918 pBindings->Invalidate( SID_INSERT_COMBOBOX );
919 pBindings->Invalidate( SID_INSERT_GROUPBOX );
920 pBindings->Invalidate( SID_INSERT_EDIT );
921 pBindings->Invalidate( SID_INSERT_FIXEDTEXT );
922 pBindings->Invalidate( SID_INSERT_IMAGECONTROL );
923 pBindings->Invalidate( SID_INSERT_PROGRESSBAR );
924 pBindings->Invalidate( SID_INSERT_HSCROLLBAR );
925 pBindings->Invalidate( SID_INSERT_VSCROLLBAR );
926 pBindings->Invalidate( SID_INSERT_HFIXEDLINE );
927 pBindings->Invalidate( SID_INSERT_VFIXEDLINE );
928 pBindings->Invalidate( SID_INSERT_DATEFIELD );
929 pBindings->Invalidate( SID_INSERT_TIMEFIELD );
930 pBindings->Invalidate( SID_INSERT_NUMERICFIELD );
931 pBindings->Invalidate( SID_INSERT_CURRENCYFIELD );
932 pBindings->Invalidate( SID_INSERT_FORMATTEDFIELD );
933 pBindings->Invalidate( SID_INSERT_PATTERNFIELD );
934 pBindings->Invalidate( SID_INSERT_FILECONTROL );
935 pBindings->Invalidate( SID_INSERT_SPINBUTTON );
936 pBindings->Invalidate( SID_INSERT_GRIDCONTROL );
937 pBindings->Invalidate( SID_INSERT_HYPERLINKCONTROL );
938 pBindings->Invalidate( SID_INSERT_TREECONTROL );
939 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
942 void Shell::SetCurLib( const ScriptDocument& rDocument, const OUString& aLibName, bool bUpdateWindows, bool bCheck )
944 if ( bCheck && rDocument == m_aCurDocument && aLibName == m_aCurLibName )
945 return;
947 ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
949 if (pListener)
950 pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
952 m_aCurDocument = rDocument;
953 m_aCurLibName = aLibName;
955 if ( pListener )
956 pListener->addContainerListener( m_aCurDocument, aLibName );
958 if ( bUpdateWindows )
959 UpdateWindows();
961 SetMDITitle();
963 SetCurLibForLocalization( rDocument, aLibName );
965 if (SfxBindings* pBindings = GetBindingsPtr())
967 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
968 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
969 pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
973 void Shell::SetCurLibForLocalization( const ScriptDocument& rDocument, const OUString& aLibName )
975 // Create LocalizationMgr
976 Reference< resource::XStringResourceManager > xStringResourceManager;
979 if( !aLibName.isEmpty() )
981 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
982 xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
985 catch (const container::NoSuchElementException& )
988 m_pCurLocalizationMgr = std::make_shared<LocalizationMgr>(this, rDocument, aLibName, xStringResourceManager);
989 m_pCurLocalizationMgr->handleTranslationbar();
992 } // namespace basctl
994 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */