LCOV - code coverage report
Current view: top level - basctl/source/basicide - basidesh.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 503 0.0 %
Date: 2014-04-11 Functions: 0 59 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <config_options.h>
      21             : 
      22             : #include "basidesh.hxx"
      23             : 
      24             : #include <tools/diagnose_ex.h>
      25             : #include <basic/basmgr.hxx>
      26             : #include <basidesh.hrc>
      27             : #include "baside2.hxx"
      28             : #include "baside3.hxx"
      29             : #include <basdoc.hxx>
      30             : #include <basicbox.hxx>
      31             : #include <editeng/sizeitem.hxx>
      32             : #include <objdlg.hxx>
      33             : #include <tbxctl.hxx>
      34             : #include <iderdll2.hxx>
      35             : #include <basidectrlr.hxx>
      36             : #include <localizationmgr.hxx>
      37             : #include <sfx2/app.hxx>
      38             : #include <sfx2/dinfdlg.hxx>
      39             : #include <sfx2/dispatch.hxx>
      40             : #include <sfx2/minfitem.hxx>
      41             : #include <sfx2/objface.hxx>
      42             : #include <svl/aeitem.hxx>
      43             : #include <svl/intitem.hxx>
      44             : #include <svl/srchitem.hxx>
      45             : 
      46             : #define basctl_Shell
      47             : #define SFX_TYPEMAP
      48             : #include <idetemp.hxx>
      49             : #include <basslots.hxx>
      50             : #include <iderdll.hxx>
      51             : #include <svx/pszctrl.hxx>
      52             : #include <svx/insctrl.hxx>
      53             : #include <svx/srchdlg.hxx>
      54             : #include <svx/tbcontrl.hxx>
      55             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      56             : #include <com/sun/star/container/XContainer.hpp>
      57             : #include <svx/xmlsecctrl.hxx>
      58             : #include <sfx2/viewfac.hxx>
      59             : #include <vcl/msgbox.hxx>
      60             : #include <vcl/settings.hxx>
      61             : 
      62             : namespace basctl
      63             : {
      64             : 
      65             : using namespace ::com::sun::star::uno;
      66             : using namespace ::com::sun::star;
      67             : 
      68             : typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
      69             : 
      70             : class ContainerListenerImpl : public ContainerListenerBASE
      71             : {
      72             :     Shell* mpShell;
      73             : public:
      74             : 
      75           0 :     ContainerListenerImpl (Shell* pShell) : mpShell(pShell) { }
      76             : 
      77           0 :     virtual ~ContainerListenerImpl()
      78           0 :     { }
      79             : 
      80           0 :     void addContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
      81             :     {
      82             :         try
      83             :         {
      84           0 :             uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
      85           0 :             if ( xContainer.is() )
      86             :             {
      87           0 :                 uno::Reference< container::XContainerListener > xContainerListener( this );
      88           0 :                 xContainer->addContainerListener( xContainerListener );
      89           0 :             }
      90             :         }
      91           0 :         catch(const uno::Exception& ) {}
      92           0 :     }
      93           0 :     void removeContainerListener( const ScriptDocument& rScriptDocument, const OUString& aLibName )
      94             :     {
      95             :         try
      96             :         {
      97           0 :             uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
      98           0 :             if ( xContainer.is() )
      99             :             {
     100           0 :                 uno::Reference< container::XContainerListener > xContainerListener( this );
     101           0 :                 xContainer->removeContainerListener( xContainerListener );
     102           0 :             }
     103             :         }
     104           0 :         catch(const uno::Exception& ) {}
     105           0 :     }
     106             : 
     107             :     // XEventListener
     108           0 :     virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE {}
     109             : 
     110             :     // XContainerListener
     111           0 :     virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
     112             :     {
     113           0 :         OUString sModuleName;
     114           0 :         if( mpShell && ( Event.Accessor >>= sModuleName ) )
     115           0 :             mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true, false );
     116           0 :     }
     117           0 :     virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE { }
     118           0 :     virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
     119             :     {
     120           0 :         OUString sModuleName;
     121           0 :         if( mpShell  && ( Event.Accessor >>= sModuleName ) )
     122             :         {
     123           0 :             ModulWindow* pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
     124           0 :             if( pWin )
     125           0 :                 mpShell->RemoveWindow( pWin, true, true );
     126           0 :         }
     127           0 :     }
     128             : 
     129             : };
     130             : 
     131           0 : TYPEINIT1( Shell, SfxViewShell );
     132             : 
     133           0 : SFX_IMPL_NAMED_VIEWFACTORY( Shell, "Default" )
     134             : {
     135           0 :     SFX_VIEW_REGISTRATION( DocShell );
     136           0 : }
     137             : 
     138             : 
     139           0 : SFX_IMPL_INTERFACE( basctl_Shell, SfxViewShell, IDEResId( RID_STR_IDENAME ) )
     140             : {
     141           0 :     SFX_CHILDWINDOW_REGISTRATION( SID_SEARCH_DLG );
     142           0 :     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_SHOW_PROPERTYBROWSER, BASICIDE_UI_FEATURE_SHOW_BROWSER);
     143           0 :     SFX_POPUPMENU_REGISTRATION( IDEResId( RID_POPUP_DLGED ) );
     144           0 : }
     145             : 
     146             : 
     147             : 
     148             : namespace
     149             : {
     150             : 
     151             : unsigned const ShellFlags = SFX_VIEW_CAN_PRINT | SFX_VIEW_NO_NEWWINDOW;
     152             : 
     153             : }
     154             : 
     155             : 
     156             : unsigned Shell::nShellCount = 0;
     157             : 
     158           0 : Shell::Shell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
     159             :     SfxViewShell( pFrame_, ShellFlags ),
     160           0 :     m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
     161           0 :     aHScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG ) ),
     162           0 :     aVScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG ) ),
     163           0 :     aScrollBarBox( &GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE ) ),
     164             :     pLayout(0),
     165           0 :     aObjectCatalog(&GetViewFrame()->GetWindow()),
     166             :     m_bAppBasicModified( false ),
     167           0 :     m_aNotifier( *this )
     168             : {
     169           0 :     m_xLibListener = new ContainerListenerImpl( this );
     170           0 :     Init();
     171           0 :     nShellCount++;
     172           0 : }
     173             : 
     174           0 : void Shell::Init()
     175             : {
     176           0 :     TbxControls::RegisterControl( SID_CHOOSE_CONTROLS );
     177           0 :     SvxPosSizeStatusBarControl::RegisterControl();
     178           0 :     SvxInsertStatusBarControl::RegisterControl();
     179           0 :     XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
     180           0 :     SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
     181           0 :     SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
     182             : 
     183           0 :     SvxSearchDialogWrapper::RegisterChildWindow(false);
     184             : 
     185           0 :     GetExtraData()->ShellInCriticalSection() = true;
     186             : 
     187           0 :     SetName( OUString( "BasicIDE" ) );
     188           0 :     SetHelpId( SVX_INTERFACE_BASIDE_VIEWSH );
     189             : 
     190           0 :     LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
     191           0 :     LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
     192             : 
     193           0 :     GetViewFrame()->GetWindow().SetBackground(
     194           0 :         GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetWindowColor()
     195           0 :     );
     196             : 
     197           0 :     pCurWin = 0;
     198           0 :     m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
     199           0 :     bCreatingWindow = false;
     200             : 
     201           0 :     pTabBar.reset(new TabBar(&GetViewFrame()->GetWindow()));
     202           0 :     pTabBar->SetSplitHdl( LINK( this, Shell, TabBarSplitHdl ) );
     203           0 :     bTabBarSplitted = false;
     204             : 
     205           0 :     nCurKey = 100;
     206           0 :     InitScrollBars();
     207           0 :     InitTabBar();
     208             : 
     209           0 :     SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", false, false );
     210             : 
     211           0 :     ShellCreated(this);
     212             : 
     213           0 :     GetExtraData()->ShellInCriticalSection() = false;
     214             : 
     215             :     // It's enough to create the controller ...
     216             :     // It will be public by using magic :-)
     217           0 :     new Controller(this);
     218             : 
     219             :     // Force updating the title ! Because it must be set to the controller
     220             :     // it has to be called directly after creating those controller.
     221           0 :     SetMDITitle ();
     222             : 
     223           0 :     UpdateWindows();
     224           0 : }
     225             : 
     226           0 : Shell::~Shell()
     227             : {
     228           0 :     m_aNotifier.dispose();
     229             : 
     230           0 :     ShellDestroyed(this);
     231             : 
     232             :     // so that on a basic saving error, the shell doesn't pop right up again
     233           0 :     GetExtraData()->ShellInCriticalSection() = true;
     234             : 
     235           0 :     SetWindow( 0 );
     236           0 :     SetCurWindow( 0 );
     237             : 
     238           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     239             :     {
     240             :         // no store; does already happen when the BasicManagers are destroyed
     241           0 :         delete it->second;
     242             :     }
     243             : 
     244             :     // Destroy all ContainerListeners for Basic Container.
     245           0 :     if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
     246           0 :         pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
     247             : 
     248           0 :     GetExtraData()->ShellInCriticalSection() = false;
     249             : 
     250           0 :     nShellCount--;
     251           0 : }
     252             : 
     253           0 : void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
     254             : {
     255           0 :     if (pCurWin)
     256           0 :         pCurWin->OnNewDocument();
     257           0 :     UpdateWindows();
     258           0 : }
     259             : 
     260           0 : void Shell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
     261             : {
     262           0 :     if (pCurWin)
     263           0 :         pCurWin->OnNewDocument();
     264           0 :     UpdateWindows();
     265           0 : }
     266             : 
     267           0 : void Shell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
     268             : {
     269           0 :     StoreAllWindowData();
     270           0 : }
     271             : 
     272           0 : void Shell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
     273             : {
     274             :     // #i115671: Update SID_SAVEDOC after saving is completed
     275           0 :     if (SfxBindings* pBindings = GetBindingsPtr())
     276           0 :         pBindings->Invalidate( SID_SAVEDOC );
     277           0 : }
     278             : 
     279           0 : void Shell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
     280             : {
     281           0 :     StoreAllWindowData();
     282           0 : }
     283             : 
     284           0 : void Shell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
     285             : {
     286             :     // not interested in
     287           0 : }
     288             : 
     289           0 : void Shell::onDocumentClosed( const ScriptDocument& _rDocument )
     290             : {
     291           0 :     if ( !_rDocument.isValid() )
     292           0 :         return;
     293             : 
     294           0 :     bool bSetCurWindow = false;
     295           0 :     bool bSetCurLib = ( _rDocument == m_aCurDocument );
     296           0 :     std::vector<BaseWindow*> aDeleteVec;
     297             : 
     298             :     // remove all windows which belong to this document
     299           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     300             :     {
     301           0 :         BaseWindow* pWin = it->second;
     302           0 :         if ( pWin->IsDocument( _rDocument ) )
     303             :         {
     304           0 :             if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
     305             :             {
     306           0 :                 pWin->AddStatus( BASWIN_TOBEKILLED );
     307           0 :                 pWin->Hide();
     308           0 :                 StarBASIC::Stop();
     309             :                 // there's no notify
     310           0 :                 pWin->BasicStopped();
     311             :             }
     312             :             else
     313           0 :                 aDeleteVec.push_back( pWin );
     314             :         }
     315             :     }
     316             :     // delete windows outside main loop so we don't invalidate the original iterator
     317           0 :     for (std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it)
     318             :     {
     319           0 :         BaseWindow* pWin = *it;
     320           0 :         pWin->StoreData();
     321           0 :         if ( pWin == pCurWin )
     322           0 :             bSetCurWindow = true;
     323           0 :         RemoveWindow( pWin, true, false );
     324             :     }
     325             : 
     326             :     // remove lib info
     327           0 :     if (ExtraData* pData = GetExtraData())
     328           0 :         pData->GetLibInfos().RemoveInfoFor( _rDocument );
     329             : 
     330           0 :     if ( bSetCurLib )
     331           0 :         SetCurLib( ScriptDocument::getApplicationScriptDocument(), "Standard", true, false );
     332           0 :     else if ( bSetCurWindow )
     333           0 :         SetCurWindow( FindApplicationWindow(), true );
     334             : }
     335             : 
     336           0 : void Shell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
     337             : {
     338           0 :     if (SfxBindings* pBindings = GetBindingsPtr())
     339           0 :         pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true, false );
     340           0 :     SetMDITitle();
     341           0 : }
     342             : 
     343           0 : void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )
     344             : {
     345           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     346             :     {
     347           0 :         BaseWindow* pWin = it->second;
     348           0 :         if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
     349           0 :             pWin->SetReadOnly( _rDocument.isReadOnly() );
     350             :     }
     351           0 : }
     352             : 
     353           0 : void Shell::StoreAllWindowData( bool bPersistent )
     354             : {
     355           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     356             :     {
     357           0 :         BaseWindow* pWin = it->second;
     358             :         DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
     359           0 :         if ( !pWin->IsSuspended() )
     360           0 :             pWin->StoreData();
     361             :     }
     362             : 
     363           0 :     if ( bPersistent  )
     364             :     {
     365           0 :         SFX_APP()->SaveBasicAndDialogContainer();
     366           0 :         SetAppBasicModified(false);
     367             : 
     368           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     369             :         {
     370           0 :             pBindings->Invalidate( SID_SAVEDOC );
     371           0 :             pBindings->Update( SID_SAVEDOC );
     372             :         }
     373             :     }
     374           0 : }
     375             : 
     376             : 
     377           0 : bool Shell::PrepareClose( bool bUI )
     378             : {
     379             :     // reset here because it's modified after printing etc. (DocInfo)
     380           0 :     GetViewFrame()->GetObjectShell()->SetModified(false);
     381             : 
     382           0 :     if ( StarBASIC::IsRunning() )
     383             :     {
     384           0 :         if( bUI )
     385             :         {
     386           0 :             Window *pParent = &GetViewFrame()->GetWindow();
     387           0 :             InfoBox( pParent, IDE_RESSTR(RID_STR_CANNOTCLOSE)).Execute();
     388             :         }
     389           0 :         return false;
     390             :     }
     391             :     else
     392             :     {
     393           0 :         bool bCanClose = true;
     394           0 :         for (WindowTableIt it = aWindowTable.begin(); bCanClose && (it != aWindowTable.end()); ++it)
     395             :         {
     396           0 :             BaseWindow* pWin = it->second;
     397           0 :             if ( !pWin->CanClose() )
     398             :             {
     399           0 :                 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
     400           0 :                     SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
     401           0 :                 SetCurWindow( pWin, true );
     402           0 :                 bCanClose = false;
     403             :             }
     404             :         }
     405             : 
     406           0 :         if ( bCanClose )
     407           0 :             StoreAllWindowData( false );    // don't write on the disk, that will be done later automatically
     408             : 
     409           0 :         return bCanClose;
     410             :     }
     411             : }
     412             : 
     413           0 : void Shell::InitScrollBars()
     414             : {
     415           0 :     aVScrollBar.SetLineSize( 300 );
     416           0 :     aVScrollBar.SetPageSize( 2000 );
     417           0 :     aHScrollBar.SetLineSize( 300 );
     418           0 :     aHScrollBar.SetPageSize( 2000 );
     419           0 :     aHScrollBar.Enable();
     420           0 :     aVScrollBar.Enable();
     421           0 :     aVScrollBar.Show();
     422           0 :     aHScrollBar.Show();
     423           0 :     aScrollBarBox.Show();
     424           0 : }
     425             : 
     426             : 
     427             : 
     428           0 : void Shell::InitTabBar()
     429             : {
     430           0 :     pTabBar->Enable();
     431           0 :     pTabBar->Show();
     432           0 :     pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
     433           0 : }
     434             : 
     435             : 
     436             : 
     437           0 : void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
     438             : {
     439           0 :     AdjustPosSizePixel( rPos, rSize );
     440           0 : }
     441             : 
     442             : 
     443           0 : IMPL_LINK_INLINE_START( Shell, TabBarSplitHdl, TabBar *, pTBar )
     444             : {
     445             :     (void)pTBar;
     446           0 :     bTabBarSplitted = true;
     447           0 :     ArrangeTabBar();
     448             : 
     449           0 :     return 0;
     450             : }
     451           0 : IMPL_LINK_INLINE_END( Shell, TabBarSplitHdl, TabBar *, pTBar )
     452             : 
     453             : 
     454             : 
     455           0 : IMPL_LINK( Shell, TabBarHdl, TabBar *, pCurTabBar )
     456             : {
     457           0 :     sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
     458           0 :     BaseWindow* pWin = aWindowTable[ nCurId ];
     459             :     DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
     460           0 :     SetCurWindow( pWin );
     461             : 
     462           0 :     return 0;
     463             : }
     464             : 
     465             : 
     466             : 
     467           0 : bool Shell::NextPage( bool bPrev )
     468             : {
     469           0 :     bool bRet = false;
     470           0 :     sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
     471             : 
     472           0 :     if ( bPrev )
     473           0 :         --nPos;
     474             :     else
     475           0 :         ++nPos;
     476             : 
     477           0 :     if ( nPos < pTabBar->GetPageCount() )
     478             :     {
     479           0 :         BaseWindow* pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
     480           0 :         SetCurWindow( pWin, true );
     481           0 :         bRet = true;
     482             :     }
     483             : 
     484           0 :     return bRet;
     485             : }
     486             : 
     487             : 
     488             : 
     489           0 : void Shell::ArrangeTabBar()
     490             : {
     491           0 :     long nBoxPos = aScrollBarBox.GetPosPixel().X() - 1;
     492           0 :     long nPos = pTabBar->GetSplitSize();
     493           0 :     if ( nPos <= nBoxPos )
     494             :     {
     495           0 :         Point aPnt( pTabBar->GetPosPixel() );
     496           0 :         long nH = aHScrollBar.GetSizePixel().Height();
     497           0 :         pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
     498           0 :         long nScrlStart = aPnt.X() + nPos;
     499           0 :         aHScrollBar.SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
     500           0 :         aHScrollBar.Update();
     501             :     }
     502           0 : }
     503             : 
     504             : 
     505             : 
     506           0 : ::svl::IUndoManager* Shell::GetUndoManager()
     507             : {
     508           0 :     ::svl::IUndoManager* pMgr = NULL;
     509           0 :     if( pCurWin )
     510           0 :         pMgr = pCurWin->GetUndoManager();
     511             : 
     512           0 :     return pMgr;
     513             : }
     514             : 
     515             : 
     516             : 
     517           0 : void Shell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
     518             :                                         const SfxHint& rHint, const TypeId& )
     519             : {
     520           0 :     if (GetShell())
     521             :     {
     522           0 :         if (SfxSimpleHint const* pSimpleHint = dynamic_cast<SfxSimpleHint const*>(&rHint))
     523             :         {
     524           0 :             switch (pSimpleHint->GetId())
     525             :             {
     526             :                 case SFX_HINT_DYING:
     527             :                 {
     528           0 :                     EndListening( rBC, true /* log off all */ );
     529           0 :                     aObjectCatalog.UpdateEntries();
     530             :                 }
     531           0 :                 break;
     532             :             }
     533             : 
     534           0 :             if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
     535             :             {
     536           0 :                 sal_uLong nHintId = pSbxHint->GetId();
     537           0 :                 if (    ( nHintId == SBX_HINT_BASICSTART ) ||
     538             :                         ( nHintId == SBX_HINT_BASICSTOP ) )
     539             :                 {
     540           0 :                     if (SfxBindings* pBindings = GetBindingsPtr())
     541             :                     {
     542           0 :                         pBindings->Invalidate( SID_BASICRUN );
     543           0 :                         pBindings->Update( SID_BASICRUN );
     544           0 :                         pBindings->Invalidate( SID_BASICCOMPILE );
     545           0 :                         pBindings->Update( SID_BASICCOMPILE );
     546           0 :                         pBindings->Invalidate( SID_BASICSTEPOVER );
     547           0 :                         pBindings->Update( SID_BASICSTEPOVER );
     548           0 :                         pBindings->Invalidate( SID_BASICSTEPINTO );
     549           0 :                         pBindings->Update( SID_BASICSTEPINTO );
     550           0 :                         pBindings->Invalidate( SID_BASICSTEPOUT );
     551           0 :                         pBindings->Update( SID_BASICSTEPOUT );
     552           0 :                         pBindings->Invalidate( SID_BASICSTOP );
     553           0 :                         pBindings->Update( SID_BASICSTOP );
     554           0 :                         pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
     555           0 :                         pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
     556           0 :                         pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
     557           0 :                         pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
     558           0 :                         pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
     559           0 :                         pBindings->Update( SID_BASICIDE_MODULEDLG );
     560           0 :                         pBindings->Invalidate( SID_BASICLOAD );
     561           0 :                         pBindings->Update( SID_BASICLOAD );
     562             :                     }
     563             : 
     564           0 :                     if ( nHintId == SBX_HINT_BASICSTOP )
     565             :                     {
     566             :                         // not only at error/break or explicit stoppage,
     567             :                         // if the update is turned off due to a programming bug
     568           0 :                         BasicStopped();
     569           0 :                         if (pLayout)
     570           0 :                             pLayout->UpdateDebug(true); // clear...
     571           0 :                         if( m_pCurLocalizationMgr )
     572           0 :                             m_pCurLocalizationMgr->handleBasicStopped();
     573             :                     }
     574           0 :                     else if( m_pCurLocalizationMgr )
     575             :                     {
     576           0 :                         m_pCurLocalizationMgr->handleBasicStarted();
     577             :                     }
     578             : 
     579           0 :                     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     580             :                     {
     581           0 :                         BaseWindow* pWin = it->second;
     582           0 :                         if ( nHintId == SBX_HINT_BASICSTART )
     583           0 :                             pWin->BasicStarted();
     584             :                         else
     585           0 :                             pWin->BasicStopped();
     586             :                     }
     587             :                 }
     588             :             }
     589             :         }
     590             :     }
     591           0 : }
     592             : 
     593             : 
     594             : 
     595           0 : void Shell::CheckWindows()
     596             : {
     597           0 :     bool bSetCurWindow = false;
     598           0 :     std::vector<BaseWindow*> aDeleteVec;
     599           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     600             :     {
     601           0 :         BaseWindow* pWin = it->second;
     602           0 :         if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
     603           0 :             aDeleteVec.push_back( pWin );
     604             :     }
     605           0 :     for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     606             :     {
     607           0 :         BaseWindow* pWin = *it;
     608           0 :         pWin->StoreData();
     609           0 :         if ( pWin == pCurWin )
     610           0 :             bSetCurWindow = true;
     611           0 :         RemoveWindow( pWin, true, false );
     612             :     }
     613           0 :     if ( bSetCurWindow )
     614           0 :         SetCurWindow( FindApplicationWindow(), true );
     615           0 : }
     616             : 
     617             : 
     618             : 
     619           0 : void Shell::RemoveWindows( const ScriptDocument& rDocument, const OUString& rLibName, bool bDestroy )
     620             : {
     621           0 :     bool bChangeCurWindow = pCurWin ? false : true;
     622           0 :     std::vector<BaseWindow*> aDeleteVec;
     623           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     624             :     {
     625           0 :         BaseWindow* pWin = it->second;
     626           0 :         if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
     627           0 :             aDeleteVec.push_back( pWin );
     628             :     }
     629           0 :     for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     630             :     {
     631           0 :         BaseWindow* pWin = *it;
     632           0 :         if ( pWin == pCurWin )
     633           0 :             bChangeCurWindow = true;
     634           0 :         pWin->StoreData();
     635           0 :         RemoveWindow( pWin, bDestroy, false );
     636             :     }
     637           0 :     if ( bChangeCurWindow )
     638           0 :         SetCurWindow( FindApplicationWindow(), true );
     639           0 : }
     640             : 
     641             : 
     642             : 
     643           0 : void Shell::UpdateWindows()
     644             : {
     645             :     // remove all windows that may not be displayed
     646           0 :     bool bChangeCurWindow = pCurWin ? false : true;
     647           0 :     if ( !m_aCurLibName.isEmpty() )
     648             :     {
     649           0 :         std::vector<BaseWindow*> aDeleteVec;
     650           0 :         for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     651             :         {
     652           0 :             BaseWindow* pWin = it->second;
     653           0 :             if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
     654             :             {
     655           0 :                 if ( pWin == pCurWin )
     656           0 :                     bChangeCurWindow = true;
     657           0 :                 pWin->StoreData();
     658             :                 // The request of RUNNING prevents the crash when in reschedule.
     659             :                 // Window is frozen at first, later the windows should be changed
     660             :                 // anyway to be marked as hidden instead of being deleted.
     661           0 :                 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
     662           0 :                     aDeleteVec.push_back( pWin );
     663             :             }
     664             :         }
     665           0 :         for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     666             :         {
     667           0 :             RemoveWindow( *it, false, false );
     668           0 :         }
     669             :     }
     670             : 
     671           0 :     if ( bCreatingWindow )
     672           0 :         return;
     673             : 
     674           0 :     BaseWindow* pNextActiveWindow = 0;
     675             : 
     676             :     // show all windows that are to be shown
     677           0 :     ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
     678           0 :     for (   ScriptDocuments::const_iterator doc = aDocuments.begin();
     679           0 :             doc != aDocuments.end();
     680             :             ++doc
     681             :         )
     682             :     {
     683           0 :         StartListening( *doc->getBasicManager(), true /* log on only once */ );
     684             : 
     685             :         // libraries
     686           0 :         Sequence< OUString > aLibNames( doc->getLibraryNames() );
     687           0 :         sal_Int32 nLibCount = aLibNames.getLength();
     688           0 :         const OUString* pLibNames = aLibNames.getConstArray();
     689             : 
     690           0 :         for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     691             :         {
     692           0 :             OUString aLibName = pLibNames[ i ];
     693             : 
     694           0 :             if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
     695             :             {
     696             :                 // check, if library is password protected and not verified
     697           0 :                 bool bProtected = false;
     698           0 :                 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
     699           0 :                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     700             :                 {
     701           0 :                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     702           0 :                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
     703             :                     {
     704           0 :                         bProtected = true;
     705           0 :                     }
     706             :                 }
     707             : 
     708           0 :                 if ( !bProtected )
     709             :                 {
     710           0 :                     LibInfos::Item const* pLibInfoItem = 0;
     711           0 :                     if (ExtraData* pData = GetExtraData())
     712           0 :                         pLibInfoItem = pData->GetLibInfos().GetInfo(*doc, aLibName);
     713             : 
     714             :                     // modules
     715           0 :                     if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     716             :                     {
     717           0 :                         StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
     718           0 :                         if ( pLib )
     719           0 :                             ImplStartListening( pLib );
     720             : 
     721             :                         try
     722             :                         {
     723           0 :                             Sequence< OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
     724           0 :                             sal_Int32 nModCount = aModNames.getLength();
     725           0 :                             const OUString* pModNames = aModNames.getConstArray();
     726             : 
     727           0 :                             for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
     728             :                             {
     729           0 :                                 OUString aModName = pModNames[ j ];
     730           0 :                                 ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, false );
     731           0 :                                 if ( !pWin )
     732           0 :                                     pWin = CreateBasWin( *doc, aLibName, aModName );
     733           0 :                                 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
     734           0 :                                      pLibInfoItem->GetCurrentType() == TYPE_MODULE )
     735             :                                 {
     736           0 :                                     pNextActiveWindow = (BaseWindow*)pWin;
     737             :                                 }
     738           0 :                             }
     739             :                         }
     740           0 :                         catch (const container::NoSuchElementException& )
     741             :                         {
     742             :                             DBG_UNHANDLED_EXCEPTION();
     743             :                         }
     744             :                     }
     745             : 
     746             :                     // dialogs
     747           0 :                     Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
     748           0 :                     if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
     749             :                     {
     750             :                         try
     751             :                         {
     752           0 :                             Sequence< OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
     753           0 :                             sal_Int32 nDlgCount = aDlgNames.getLength();
     754           0 :                             const OUString* pDlgNames = aDlgNames.getConstArray();
     755             : 
     756           0 :                             for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
     757             :                             {
     758           0 :                                 OUString aDlgName = pDlgNames[ j ];
     759             :                                 // this find only looks for non-suspended windows;
     760             :                                 // suspended windows are handled in CreateDlgWin
     761           0 :                                 DialogWindow* pWin = FindDlgWin( *doc, aLibName, aDlgName, false );
     762           0 :                                 if ( !pWin )
     763           0 :                                     pWin = CreateDlgWin( *doc, aLibName, aDlgName );
     764           0 :                                 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
     765           0 :                                      pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
     766             :                                 {
     767           0 :                                     pNextActiveWindow = (BaseWindow*)pWin;
     768             :                                 }
     769           0 :                             }
     770             :                         }
     771           0 :                         catch (const container::NoSuchElementException& )
     772             :                         {
     773             :                             DBG_UNHANDLED_EXCEPTION();
     774             :                         }
     775           0 :                     }
     776           0 :                 }
     777             :             }
     778           0 :         }
     779           0 :     }
     780             : 
     781           0 :     if ( bChangeCurWindow )
     782             :     {
     783           0 :         if ( !pNextActiveWindow )
     784             :         {
     785           0 :             pNextActiveWindow = FindApplicationWindow();
     786             :         }
     787           0 :         SetCurWindow( pNextActiveWindow, true );
     788           0 :     }
     789             : }
     790             : 
     791           0 : void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
     792             : {
     793             :     DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
     794           0 :     sal_uLong nKey = GetWindowId( pWindow_ );
     795           0 :     pTabBar->RemovePage( (sal_uInt16)nKey );
     796           0 :     aWindowTable.erase( nKey );
     797           0 :     if ( pWindow_ == pCurWin )
     798             :     {
     799           0 :         if ( bAllowChangeCurWindow )
     800             :         {
     801           0 :             SetCurWindow( FindApplicationWindow(), true );
     802             :         }
     803             :         else
     804             :         {
     805           0 :             SetCurWindow( NULL, false );
     806             :         }
     807             :     }
     808           0 :     if ( bDestroy )
     809             :     {
     810           0 :         if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
     811             :         {
     812           0 :             delete pWindow_;
     813             :         }
     814             :         else
     815             :         {
     816           0 :             pWindow_->AddStatus( BASWIN_TOBEKILLED );
     817           0 :             pWindow_->Hide();
     818             :             // In normal mode stop basic in windows to be deleted
     819             :             // In VBA stop basic only if the running script is trying to delete
     820             :             // its parent module
     821           0 :             bool bStop = true;
     822           0 :             if ( pWindow_->GetDocument().isInVBAMode() )
     823             :             {
     824           0 :                 SbModule* pMod = StarBASIC::GetActiveModule();
     825           0 :                 if ( !pMod || ( pMod && ( !pMod->GetName().equals(pWindow_->GetName()) ) ) )
     826             :                 {
     827           0 :                     bStop = false;
     828             :                 }
     829             :             }
     830           0 :             if ( bStop )
     831             :             {
     832           0 :                 StarBASIC::Stop();
     833             :                 // there will be no notify...
     834           0 :                 pWindow_->BasicStopped();
     835             :             }
     836           0 :             aWindowTable[ nKey ] = pWindow_;   // jump in again
     837             :         }
     838             :     }
     839             :     else
     840             :     {
     841           0 :         pWindow_->AddStatus( BASWIN_SUSPENDED );
     842           0 :         pWindow_->Deactivating();
     843           0 :         aWindowTable[ nKey ] = pWindow_;   // jump in again
     844             :     }
     845             : 
     846           0 : }
     847             : 
     848             : 
     849             : 
     850           0 : sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
     851             : {
     852           0 :     nCurKey++;
     853           0 :     aWindowTable[ nCurKey ] = pNewWin;
     854           0 :     return nCurKey;
     855             : }
     856             : 
     857             : 
     858             : 
     859           0 : void Shell::InvalidateBasicIDESlots()
     860             : {
     861             :     // only those that have an optic effect...
     862             : 
     863           0 :     if (GetShell())
     864             :     {
     865           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     866             :         {
     867           0 :             pBindings->Invalidate( SID_COPY );
     868           0 :             pBindings->Invalidate( SID_CUT );
     869           0 :             pBindings->Invalidate( SID_PASTE );
     870           0 :             pBindings->Invalidate( SID_UNDO );
     871           0 :             pBindings->Invalidate( SID_REDO );
     872           0 :             pBindings->Invalidate( SID_SAVEDOC );
     873           0 :             pBindings->Invalidate( SID_SIGNATURE );
     874           0 :             pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
     875           0 :             pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
     876           0 :             pBindings->Invalidate( SID_BASICIDE_OBJCAT );
     877           0 :             pBindings->Invalidate( SID_BASICSTOP );
     878           0 :             pBindings->Invalidate( SID_BASICRUN );
     879           0 :             pBindings->Invalidate( SID_BASICCOMPILE );
     880           0 :             pBindings->Invalidate( SID_BASICLOAD );
     881           0 :             pBindings->Invalidate( SID_BASICSAVEAS );
     882           0 :             pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
     883           0 :             pBindings->Invalidate( SID_BASICSTEPINTO );
     884           0 :             pBindings->Invalidate( SID_BASICSTEPOVER );
     885           0 :             pBindings->Invalidate( SID_BASICSTEPOUT );
     886           0 :             pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
     887           0 :             pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
     888           0 :             pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
     889           0 :             pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
     890           0 :             pBindings->Invalidate( SID_CHOOSE_CONTROLS );
     891           0 :             pBindings->Invalidate( SID_PRINTDOC );
     892           0 :             pBindings->Invalidate( SID_PRINTDOCDIRECT );
     893           0 :             pBindings->Invalidate( SID_SETUPPRINTER );
     894           0 :             pBindings->Invalidate( SID_DIALOG_TESTMODE );
     895             : 
     896           0 :             pBindings->Invalidate( SID_DOC_MODIFIED );
     897           0 :             pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
     898           0 :             pBindings->Invalidate( SID_BASICIDE_STAT_POS );
     899           0 :             pBindings->Invalidate( SID_ATTR_INSERT );
     900           0 :             pBindings->Invalidate( SID_ATTR_SIZE );
     901             :         }
     902             :     }
     903           0 : }
     904             : 
     905           0 : void Shell::EnableScrollbars( bool bEnable )
     906             : {
     907           0 :     aHScrollBar.Enable(bEnable);
     908           0 :     aVScrollBar.Enable(bEnable);
     909           0 : }
     910             : 
     911           0 : void Shell::SetCurLib( const ScriptDocument& rDocument, const OUString& aLibName, bool bUpdateWindows, bool bCheck )
     912             : {
     913           0 :     if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
     914             :     {
     915           0 :         ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
     916             : 
     917           0 :         m_aCurDocument = rDocument;
     918           0 :         m_aCurLibName = aLibName;
     919             : 
     920           0 :         if ( pListener )
     921             :         {
     922           0 :             pListener->removeContainerListener( m_aCurDocument, m_aCurLibName );
     923           0 :             pListener->addContainerListener( m_aCurDocument, aLibName );
     924             :         }
     925             : 
     926           0 :         if ( bUpdateWindows )
     927           0 :             UpdateWindows();
     928             : 
     929           0 :         SetMDITitle();
     930             : 
     931           0 :         SetCurLibForLocalization( rDocument, aLibName );
     932             : 
     933           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     934             :         {
     935           0 :             pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
     936           0 :             pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
     937           0 :             pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
     938             :         }
     939             :     }
     940           0 : }
     941             : 
     942           0 : void Shell::SetCurLibForLocalization( const ScriptDocument& rDocument, const OUString& aLibName )
     943             : {
     944             :     // Create LocalizationMgr
     945           0 :     Reference< resource::XStringResourceManager > xStringResourceManager;
     946             :     try
     947             :     {
     948           0 :         if( !aLibName.isEmpty() )
     949             :         {
     950           0 :             Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
     951           0 :             xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
     952             :         }
     953             :     }
     954           0 :     catch (const container::NoSuchElementException& )
     955             :     {}
     956             : 
     957           0 :     m_pCurLocalizationMgr = boost::shared_ptr<LocalizationMgr>(new LocalizationMgr(this, rDocument, aLibName, xStringResourceManager));
     958           0 :     m_pCurLocalizationMgr->handleTranslationbar();
     959           0 : }
     960             : 
     961           0 : void Shell::ImplStartListening( StarBASIC* pBasic )
     962             : {
     963           0 :     StartListening( pBasic->GetBroadcaster(), true /* log on only once */ );
     964           0 : }
     965             : 
     966           0 : } // namespace basctl
     967             : 
     968             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10