1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <strings.hrc>
29 #include "baside2.hxx"
30 #include <baside3.hxx>
32 #include <IDEComboBox.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include "iderdll2.hxx"
35 #include <basidectrlr.hxx>
36 #include <basidesh.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
56 #define ShellClass_basctl_Shell
58 #include <basslots.hxx>
60 #if defined(DISABLE_DYNLOADING) || ENABLE_MERGELIBS
61 #undef aSfxDocumentInfoItem_Impl
62 #undef aSfxUnoAnyItem_Impl
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>
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
>
90 explicit ContainerListenerImpl(Shell
* pShell
)
95 void addContainerListener( const ScriptDocument
& rScriptDocument
, const OUString
& aLibName
)
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
& ) {}
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);
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) ),
170 aObjectCatalog(VclPtr
<ObjectCatalog
>::Create(&GetViewFrame().GetWindow())),
171 m_bAppBasicModified( false ),
174 m_xLibListener
= new ContainerListenerImpl( this );
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()
200 m_aCurDocument
= ScriptDocument::getApplicationScriptDocument();
201 bCreatingWindow
= false;
203 pTabBar
.reset(VclPtr
<TabBar
>::Create(&GetViewFrame().GetWindow()));
210 SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
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.
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;
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*/ )
272 pCurWin
->OnNewDocument();
277 void Shell::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
280 pCurWin
->OnNewDocument();
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*/ )
306 void Shell::onDocumentClosed( const ScriptDocument
& _rDocument
)
308 if ( !_rDocument
.isValid() )
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
);
327 pWin
->BasicStopped();
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
)
337 if ( pWin
== pCurWin
)
338 bSetCurWindow
= true;
339 RemoveWindow( pWin
, true, false );
343 if (ExtraData
* pData
= GetExtraData())
344 pData
->GetLibInfo().RemoveInfoFor( _rDocument
);
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 );
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());
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() )
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() )
439 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(GetViewFrame().GetFrameWeld(),
440 VclMessageType::Info
, VclButtonsType::Ok
,
441 IDEResId(RID_STR_CANNOTCLOSE
)));
448 StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
453 void Shell::InitScrollBars()
455 aVScrollBar
->SetLineSize( 300 );
456 aVScrollBar
->SetPageSize( 2000 );
457 aHScrollBar
->SetLineSize( 300 );
458 aHScrollBar
->SetPageSize( 2000 );
461 void Shell::InitTabBar()
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
)
485 sal_uInt16 nPos
= pTabBar
->GetPagePos( pTabBar
->GetCurPageId() );
492 if ( nPos
< pTabBar
->GetPageCount() )
494 VclPtr
<BaseWindow
> pWin
= aWindowTable
[ pTabBar
->GetPageId( nPos
) ];
495 SetCurWindow( pWin
, true );
502 SfxUndoManager
* Shell::GetUndoManager()
504 SfxUndoManager
* pMgr
= nullptr;
506 pMgr
= pCurWin
->GetUndoManager();
512 void Shell::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
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
);
527 const SfxHintId nHintId
= pSbxHint
->GetId();
528 if ( ( nHintId
!= SfxHintId::BasicStart
) &&
529 ( nHintId
!= SfxHintId::BasicStop
) )
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
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();
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
)
595 if ( pWin
== pCurWin
)
596 bSetCurWindow
= true;
597 RemoveWindow( pWin
, true, false );
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;
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;
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
)
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 */);
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
) )
693 LibInfo::Item
const* pLibInfoItem
= nullptr;
694 if (ExtraData
* pData
= GetExtraData())
695 pLibInfoItem
= pData
->GetLibInfo().GetInfo(doc
, aLibName
);
698 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
700 StarBASIC
* pLib
= doc
.getBasicManager()->GetLib( aLibName
);
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
);
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");
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
);
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 );
797 SetCurWindow( nullptr );
802 if ( !( pWindow_
->GetStatus() & BASWIN_INRESCHEDULE
) )
804 pWindowTmp
.disposeAndClear();
808 pWindow_
->AddStatus( BASWIN_TOBEKILLED
);
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
814 if ( pWindow_
->GetDocument().isInVBAMode() )
816 SbModule
* pMod
= StarBASIC::GetActiveModule();
817 if ( !pMod
|| pMod
->GetName() != pWindow_
->GetName() )
825 // there will be no notify...
826 pWindow_
->BasicStopped();
828 aWindowTable
[ nKey
] = pWindow_
; // jump in again
833 pWindow_
->AddStatus( BASWIN_SUSPENDED
);
834 pWindow_
->Deactivating();
835 aWindowTable
[ nKey
] = pWindow_
; // jump in again
841 sal_uInt16
Shell::InsertWindowInTable( BaseWindow
* pNewWin
)
844 aWindowTable
[ nCurKey
] = pNewWin
;
849 void Shell::InvalidateBasicIDESlots()
851 // only those that have an optic effect...
856 SfxBindings
* pBindings
= GetBindingsPtr();
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()
901 SfxBindings
* pBindings
= GetBindingsPtr();
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
)
947 ContainerListenerImpl
* pListener
= static_cast< ContainerListenerImpl
* >( m_xLibListener
.get() );
950 pListener
->removeContainerListener(m_aCurDocument
, m_aCurLibName
);
952 m_aCurDocument
= rDocument
;
953 m_aCurLibName
= aLibName
;
956 pListener
->addContainerListener( m_aCurDocument
, aLibName
);
958 if ( bUpdateWindows
)
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: */