LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - basidesh.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 502 0.0 %
Date: 2012-12-17 Functions: 0 60 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             : // CLOOKS:
      21             : #define _SPIN_HXX
      22             : 
      23             : #include "basidesh.hxx"
      24             : 
      25             : #include <tools/diagnose_ex.h>
      26             : #include <basic/basmgr.hxx>
      27             : #include <basidesh.hrc>
      28             : #include "baside2.hxx"
      29             : #include "baside3.hxx"
      30             : #include <basdoc.hxx>
      31             : #include <basicbox.hxx>
      32             : #include <editeng/sizeitem.hxx>
      33             : #include <objdlg.hxx>
      34             : #include <tbxctl.hxx>
      35             : #include <iderdll2.hxx>
      36             : #include <basidectrlr.hxx>
      37             : #include <localizationmgr.hxx>
      38             : #include <sfx2/app.hxx>
      39             : #include <sfx2/dinfdlg.hxx>
      40             : #include <sfx2/dispatch.hxx>
      41             : #include <sfx2/minfitem.hxx>
      42             : #include <sfx2/objface.hxx>
      43             : #include <svl/aeitem.hxx>
      44             : #include <svl/intitem.hxx>
      45             : #include <svl/srchitem.hxx>
      46             : 
      47             : #define basctl_Shell
      48             : #define SFX_TYPEMAP
      49             : #include <idetemp.hxx>
      50             : #include <basslots.hxx>
      51             : #include <iderdll.hxx>
      52             : #include <svx/pszctrl.hxx>
      53             : #include <svx/insctrl.hxx>
      54             : #include <svx/srchdlg.hxx>
      55             : #include <svx/tbcontrl.hxx>
      56             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      57             : #include <com/sun/star/container/XContainer.hpp>
      58             : #include <svx/xmlsecctrl.hxx>
      59             : #include <sfx2/viewfac.hxx>
      60             : #include <vcl/msgbox.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 :     ~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 ) {}
     109             : 
     110             :     // XContainerListener
     111           0 :     virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
     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 ) { }
     118           0 :     virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
     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 : sal_uInt16 Shell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
     378             : {
     379             :     (void)bForBrowsing;
     380             : 
     381             :     // reset here because it's modified after printing etc. (DocInfo)
     382           0 :     GetViewFrame()->GetObjectShell()->SetModified(false);
     383             : 
     384           0 :     if ( StarBASIC::IsRunning() )
     385             :     {
     386           0 :         if( bUI )
     387             :         {
     388           0 :             Window *pParent = &GetViewFrame()->GetWindow();
     389           0 :             InfoBox( pParent, IDE_RESSTR(RID_STR_CANNOTCLOSE)).Execute();
     390             :         }
     391           0 :         return false;
     392             :     }
     393             :     else
     394             :     {
     395           0 :         bool bCanClose = true;
     396           0 :         for (WindowTableIt it = aWindowTable.begin(); bCanClose && (it != aWindowTable.end()); ++it)
     397             :         {
     398           0 :             BaseWindow* pWin = it->second;
     399           0 :             if ( !pWin->CanClose() )
     400             :             {
     401           0 :                 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
     402           0 :                     SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
     403           0 :                 SetCurWindow( pWin, true );
     404           0 :                 bCanClose = false;
     405             :             }
     406             :         }
     407             : 
     408           0 :         if ( bCanClose )
     409           0 :             StoreAllWindowData( false );    // don't write on the disk, that will be done later automatically
     410             : 
     411           0 :         return bCanClose;
     412             :     }
     413             : }
     414             : 
     415           0 : void Shell::InitScrollBars()
     416             : {
     417           0 :     aVScrollBar.SetLineSize( 300 );
     418           0 :     aVScrollBar.SetPageSize( 2000 );
     419           0 :     aHScrollBar.SetLineSize( 300 );
     420           0 :     aHScrollBar.SetPageSize( 2000 );
     421           0 :     aHScrollBar.Enable();
     422           0 :     aVScrollBar.Enable();
     423           0 :     aVScrollBar.Show();
     424           0 :     aHScrollBar.Show();
     425           0 :     aScrollBarBox.Show();
     426           0 : }
     427             : 
     428             : 
     429             : 
     430           0 : void Shell::InitTabBar()
     431             : {
     432           0 :     pTabBar->Enable();
     433           0 :     pTabBar->Show();
     434           0 :     pTabBar->SetSelectHdl( LINK( this, Shell, TabBarHdl ) );
     435           0 : }
     436             : 
     437             : 
     438           0 : Size Shell::GetOptimalSizePixel() const
     439             : {
     440           0 :     return Size( 400, 300 );
     441             : }
     442             : 
     443             : 
     444             : 
     445           0 : void Shell::OuterResizePixel( const Point &rPos, const Size &rSize )
     446             : {
     447           0 :     AdjustPosSizePixel( rPos, rSize );
     448           0 : }
     449             : 
     450             : 
     451           0 : IMPL_LINK_INLINE_START( Shell, TabBarSplitHdl, TabBar *, pTBar )
     452             : {
     453             :     (void)pTBar;
     454           0 :     bTabBarSplitted = true;
     455           0 :     ArrangeTabBar();
     456             : 
     457           0 :     return 0;
     458             : }
     459           0 : IMPL_LINK_INLINE_END( Shell, TabBarSplitHdl, TabBar *, pTBar )
     460             : 
     461             : 
     462             : 
     463           0 : IMPL_LINK( Shell, TabBarHdl, TabBar *, pCurTabBar )
     464             : {
     465           0 :     sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
     466           0 :     BaseWindow* pWin = aWindowTable[ nCurId ];
     467             :     DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
     468           0 :     SetCurWindow( pWin );
     469             : 
     470           0 :     return 0;
     471             : }
     472             : 
     473             : 
     474             : 
     475           0 : bool Shell::NextPage( bool bPrev )
     476             : {
     477           0 :     bool bRet = false;
     478           0 :     sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
     479             : 
     480           0 :     if ( bPrev )
     481           0 :         --nPos;
     482             :     else
     483           0 :         ++nPos;
     484             : 
     485           0 :     if ( nPos < pTabBar->GetPageCount() )
     486             :     {
     487           0 :         BaseWindow* pWin = aWindowTable[ pTabBar->GetPageId( nPos ) ];
     488           0 :         SetCurWindow( pWin, true );
     489           0 :         bRet = true;
     490             :     }
     491             : 
     492           0 :     return bRet;
     493             : }
     494             : 
     495             : 
     496             : 
     497           0 : void Shell::ArrangeTabBar()
     498             : {
     499           0 :     long nBoxPos = aScrollBarBox.GetPosPixel().X() - 1;
     500           0 :     long nPos = pTabBar->GetSplitSize();
     501           0 :     if ( nPos <= nBoxPos )
     502             :     {
     503           0 :         Point aPnt( pTabBar->GetPosPixel() );
     504           0 :         long nH = aHScrollBar.GetSizePixel().Height();
     505           0 :         pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
     506           0 :         long nScrlStart = aPnt.X() + nPos;
     507           0 :         aHScrollBar.SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
     508           0 :         aHScrollBar.Update();
     509             :     }
     510           0 : }
     511             : 
     512             : 
     513             : 
     514           0 : ::svl::IUndoManager* Shell::GetUndoManager()
     515             : {
     516           0 :     ::svl::IUndoManager* pMgr = NULL;
     517           0 :     if( pCurWin )
     518           0 :         pMgr = pCurWin->GetUndoManager();
     519             : 
     520           0 :     return pMgr;
     521             : }
     522             : 
     523             : 
     524             : 
     525           0 : void Shell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
     526             :                                         const SfxHint& rHint, const TypeId& )
     527             : {
     528           0 :     if (GetShell())
     529             :     {
     530           0 :         if (SfxSimpleHint const* pSimpleHint = dynamic_cast<SfxSimpleHint const*>(&rHint))
     531             :         {
     532           0 :             switch (pSimpleHint->GetId())
     533             :             {
     534             :                 case SFX_HINT_DYING:
     535             :                 {
     536           0 :                     EndListening( rBC, true /* log off all */ );
     537           0 :                     aObjectCatalog.UpdateEntries();
     538             :                 }
     539           0 :                 break;
     540             :             }
     541             : 
     542           0 :             if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
     543             :             {
     544           0 :                 sal_uLong nHintId = pSbxHint->GetId();
     545           0 :                 if (    ( nHintId == SBX_HINT_BASICSTART ) ||
     546             :                         ( nHintId == SBX_HINT_BASICSTOP ) )
     547             :                 {
     548           0 :                     if (SfxBindings* pBindings = GetBindingsPtr())
     549             :                     {
     550           0 :                         pBindings->Invalidate( SID_BASICRUN );
     551           0 :                         pBindings->Update( SID_BASICRUN );
     552           0 :                         pBindings->Invalidate( SID_BASICCOMPILE );
     553           0 :                         pBindings->Update( SID_BASICCOMPILE );
     554           0 :                         pBindings->Invalidate( SID_BASICSTEPOVER );
     555           0 :                         pBindings->Update( SID_BASICSTEPOVER );
     556           0 :                         pBindings->Invalidate( SID_BASICSTEPINTO );
     557           0 :                         pBindings->Update( SID_BASICSTEPINTO );
     558           0 :                         pBindings->Invalidate( SID_BASICSTEPOUT );
     559           0 :                         pBindings->Update( SID_BASICSTEPOUT );
     560           0 :                         pBindings->Invalidate( SID_BASICSTOP );
     561           0 :                         pBindings->Update( SID_BASICSTOP );
     562           0 :                         pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
     563           0 :                         pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
     564           0 :                         pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
     565           0 :                         pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
     566           0 :                         pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
     567           0 :                         pBindings->Update( SID_BASICIDE_MODULEDLG );
     568           0 :                         pBindings->Invalidate( SID_BASICLOAD );
     569           0 :                         pBindings->Update( SID_BASICLOAD );
     570             :                     }
     571             : 
     572           0 :                     if ( nHintId == SBX_HINT_BASICSTOP )
     573             :                     {
     574             :                         // not only at error/break or explicit stoppage,
     575             :                         // if the update is turned off due to a programming bug
     576           0 :                         BasicStopped();
     577           0 :                         if (pLayout)
     578           0 :                             pLayout->UpdateDebug(true); // clear...
     579           0 :                         if( m_pCurLocalizationMgr )
     580           0 :                             m_pCurLocalizationMgr->handleBasicStopped();
     581             :                     }
     582           0 :                     else if( m_pCurLocalizationMgr )
     583             :                     {
     584           0 :                         m_pCurLocalizationMgr->handleBasicStarted();
     585             :                     }
     586             : 
     587           0 :                     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     588             :                     {
     589           0 :                         BaseWindow* pWin = it->second;
     590           0 :                         if ( nHintId == SBX_HINT_BASICSTART )
     591           0 :                             pWin->BasicStarted();
     592             :                         else
     593           0 :                             pWin->BasicStopped();
     594             :                     }
     595             :                 }
     596             :             }
     597             :         }
     598             :     }
     599           0 : }
     600             : 
     601             : 
     602             : 
     603           0 : void Shell::CheckWindows()
     604             : {
     605           0 :     bool bSetCurWindow = false;
     606           0 :     std::vector<BaseWindow*> aDeleteVec;
     607           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     608             :     {
     609           0 :         BaseWindow* pWin = it->second;
     610           0 :         if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
     611           0 :             aDeleteVec.push_back( pWin );
     612             :     }
     613           0 :     for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     614             :     {
     615           0 :         BaseWindow* pWin = *it;
     616           0 :         pWin->StoreData();
     617           0 :         if ( pWin == pCurWin )
     618           0 :             bSetCurWindow = true;
     619           0 :         RemoveWindow( pWin, true, false );
     620             :     }
     621           0 :     if ( bSetCurWindow )
     622           0 :         SetCurWindow( FindApplicationWindow(), true );
     623           0 : }
     624             : 
     625             : 
     626             : 
     627           0 : void Shell::RemoveWindows( const ScriptDocument& rDocument, const OUString& rLibName, bool bDestroy )
     628             : {
     629           0 :     bool bChangeCurWindow = pCurWin ? false : true;
     630           0 :     std::vector<BaseWindow*> aDeleteVec;
     631           0 :     for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     632             :     {
     633           0 :         BaseWindow* pWin = it->second;
     634           0 :         if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
     635           0 :             aDeleteVec.push_back( pWin );
     636             :     }
     637           0 :     for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     638             :     {
     639           0 :         BaseWindow* pWin = *it;
     640           0 :         if ( pWin == pCurWin )
     641           0 :             bChangeCurWindow = true;
     642           0 :         pWin->StoreData();
     643           0 :         RemoveWindow( pWin, bDestroy, false );
     644             :     }
     645           0 :     if ( bChangeCurWindow )
     646           0 :         SetCurWindow( FindApplicationWindow(), true );
     647           0 : }
     648             : 
     649             : 
     650             : 
     651           0 : void Shell::UpdateWindows()
     652             : {
     653             :     // remove all windows that may not be displayed
     654           0 :     bool bChangeCurWindow = pCurWin ? false : true;
     655           0 :     if ( !m_aCurLibName.isEmpty() )
     656             :     {
     657           0 :         std::vector<BaseWindow*> aDeleteVec;
     658           0 :         for (WindowTableIt it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
     659             :         {
     660           0 :             BaseWindow* pWin = it->second;
     661           0 :             if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
     662             :             {
     663           0 :                 if ( pWin == pCurWin )
     664           0 :                     bChangeCurWindow = true;
     665           0 :                 pWin->StoreData();
     666             :                 // The request of RUNNING prevents the crash when in reschedule.
     667             :                 // Window is frozen at first, later the windows should be changed
     668             :                 // anyway to be marked as hidden instead of being deleted.
     669           0 :                 if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
     670           0 :                     aDeleteVec.push_back( pWin );
     671             :             }
     672             :         }
     673           0 :         for ( std::vector<BaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
     674             :         {
     675           0 :             RemoveWindow( *it, false, false );
     676           0 :         }
     677             :     }
     678             : 
     679           0 :     if ( bCreatingWindow )
     680           0 :         return;
     681             : 
     682           0 :     BaseWindow* pNextActiveWindow = 0;
     683             : 
     684             :     // show all windows that are to be shown
     685           0 :     ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
     686           0 :     for (   ScriptDocuments::const_iterator doc = aDocuments.begin();
     687           0 :             doc != aDocuments.end();
     688             :             ++doc
     689             :         )
     690             :     {
     691           0 :         StartListening( *doc->getBasicManager(), true /* log on only once */ );
     692             : 
     693             :         // libraries
     694           0 :         Sequence< OUString > aLibNames( doc->getLibraryNames() );
     695           0 :         sal_Int32 nLibCount = aLibNames.getLength();
     696           0 :         const OUString* pLibNames = aLibNames.getConstArray();
     697             : 
     698           0 :         for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     699             :         {
     700           0 :             OUString aLibName = pLibNames[ i ];
     701             : 
     702           0 :             if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
     703             :             {
     704             :                 // check, if library is password protected and not verified
     705           0 :                 bool bProtected = false;
     706           0 :                 Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
     707           0 :                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     708             :                 {
     709           0 :                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     710           0 :                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
     711             :                     {
     712           0 :                         bProtected = true;
     713           0 :                     }
     714             :                 }
     715             : 
     716           0 :                 if ( !bProtected )
     717             :                 {
     718           0 :                     LibInfos::Item const* pLibInfoItem = 0;
     719           0 :                     if (ExtraData* pData = GetExtraData())
     720           0 :                         pLibInfoItem = pData->GetLibInfos().GetInfo(*doc, aLibName);
     721             : 
     722             :                     // modules
     723           0 :                     if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
     724             :                     {
     725           0 :                         StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
     726           0 :                         if ( pLib )
     727           0 :                             ImplStartListening( pLib );
     728             : 
     729             :                         try
     730             :                         {
     731           0 :                             Sequence< OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
     732           0 :                             sal_Int32 nModCount = aModNames.getLength();
     733           0 :                             const OUString* pModNames = aModNames.getConstArray();
     734             : 
     735           0 :                             for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
     736             :                             {
     737           0 :                                 OUString aModName = pModNames[ j ];
     738           0 :                                 ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, false );
     739           0 :                                 if ( !pWin )
     740           0 :                                     pWin = CreateBasWin( *doc, aLibName, aModName );
     741           0 :                                 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
     742           0 :                                      pLibInfoItem->GetCurrentType() == TYPE_MODULE )
     743             :                                 {
     744           0 :                                     pNextActiveWindow = (BaseWindow*)pWin;
     745             :                                 }
     746           0 :                             }
     747             :                         }
     748           0 :                         catch (const container::NoSuchElementException& )
     749             :                         {
     750             :                             DBG_UNHANDLED_EXCEPTION();
     751             :                         }
     752             :                     }
     753             : 
     754             :                     // dialogs
     755           0 :                     Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
     756           0 :                     if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
     757             :                     {
     758             :                         try
     759             :                         {
     760           0 :                             Sequence< OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
     761           0 :                             sal_Int32 nDlgCount = aDlgNames.getLength();
     762           0 :                             const OUString* pDlgNames = aDlgNames.getConstArray();
     763             : 
     764           0 :                             for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
     765             :                             {
     766           0 :                                 OUString aDlgName = pDlgNames[ j ];
     767             :                                 // this find only looks for non-suspended windows;
     768             :                                 // suspended windows are handled in CreateDlgWin
     769           0 :                                 DialogWindow* pWin = FindDlgWin( *doc, aLibName, aDlgName, false );
     770           0 :                                 if ( !pWin )
     771           0 :                                     pWin = CreateDlgWin( *doc, aLibName, aDlgName );
     772           0 :                                 if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
     773           0 :                                      pLibInfoItem->GetCurrentType() == TYPE_DIALOG )
     774             :                                 {
     775           0 :                                     pNextActiveWindow = (BaseWindow*)pWin;
     776             :                                 }
     777           0 :                             }
     778             :                         }
     779           0 :                         catch (const container::NoSuchElementException& )
     780             :                         {
     781             :                             DBG_UNHANDLED_EXCEPTION();
     782             :                         }
     783           0 :                     }
     784           0 :                 }
     785             :             }
     786           0 :         }
     787           0 :     }
     788             : 
     789           0 :     if ( bChangeCurWindow )
     790             :     {
     791           0 :         if ( !pNextActiveWindow )
     792             :         {
     793           0 :             pNextActiveWindow = FindApplicationWindow();
     794             :         }
     795           0 :         SetCurWindow( pNextActiveWindow, true );
     796           0 :     }
     797             : }
     798             : 
     799           0 : void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
     800             : {
     801             :     DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
     802           0 :     sal_uLong nKey = GetWindowId( pWindow_ );
     803           0 :     pTabBar->RemovePage( (sal_uInt16)nKey );
     804           0 :     aWindowTable.erase( nKey );
     805           0 :     if ( pWindow_ == pCurWin )
     806             :     {
     807           0 :         if ( bAllowChangeCurWindow )
     808             :         {
     809           0 :             SetCurWindow( FindApplicationWindow(), true );
     810             :         }
     811             :         else
     812             :         {
     813           0 :             SetCurWindow( NULL, false );
     814             :         }
     815             :     }
     816           0 :     if ( bDestroy )
     817             :     {
     818           0 :         if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
     819             :         {
     820           0 :             delete pWindow_;
     821             :         }
     822             :         else
     823             :         {
     824           0 :             pWindow_->AddStatus( BASWIN_TOBEKILLED );
     825           0 :             pWindow_->Hide();
     826             :             // In normal mode stop basic in windows to be deleted
     827             :             // In VBA stop basic only if the running script is trying to delete
     828             :             // its parent module
     829           0 :             bool bStop = true;
     830           0 :             if ( pWindow_->GetDocument().isInVBAMode() )
     831             :             {
     832           0 :                 SbModule* pMod = StarBASIC::GetActiveModule();
     833           0 :                 if ( !pMod || ( pMod && ( !pMod->GetName().equals(pWindow_->GetName()) ) ) )
     834             :                 {
     835           0 :                     bStop = false;
     836             :                 }
     837             :             }
     838           0 :             if ( bStop )
     839             :             {
     840           0 :                 StarBASIC::Stop();
     841             :                 // there will be no notify...
     842           0 :                 pWindow_->BasicStopped();
     843             :             }
     844           0 :             aWindowTable[ nKey ] = pWindow_;   // jump in again
     845             :         }
     846             :     }
     847             :     else
     848             :     {
     849           0 :         pWindow_->AddStatus( BASWIN_SUSPENDED );
     850           0 :         pWindow_->Deactivating();
     851           0 :         aWindowTable[ nKey ] = pWindow_;   // jump in again
     852             :     }
     853             : 
     854           0 : }
     855             : 
     856             : 
     857             : 
     858           0 : sal_uInt16 Shell::InsertWindowInTable( BaseWindow* pNewWin )
     859             : {
     860           0 :     nCurKey++;
     861           0 :     aWindowTable[ nCurKey ] = pNewWin;
     862           0 :     return nCurKey;
     863             : }
     864             : 
     865             : 
     866             : 
     867           0 : void Shell::InvalidateBasicIDESlots()
     868             : {
     869             :     // only those that have an optic effect...
     870             : 
     871           0 :     if (GetShell())
     872             :     {
     873           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     874             :         {
     875           0 :             pBindings->Invalidate( SID_UNDO );
     876           0 :             pBindings->Invalidate( SID_REDO );
     877           0 :             pBindings->Invalidate( SID_SAVEDOC );
     878           0 :             pBindings->Invalidate( SID_SIGNATURE );
     879           0 :             pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
     880           0 :             pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
     881           0 :             pBindings->Invalidate( SID_BASICIDE_OBJCAT );
     882           0 :             pBindings->Invalidate( SID_BASICSTOP );
     883           0 :             pBindings->Invalidate( SID_BASICRUN );
     884           0 :             pBindings->Invalidate( SID_BASICCOMPILE );
     885           0 :             pBindings->Invalidate( SID_BASICLOAD );
     886           0 :             pBindings->Invalidate( SID_BASICSAVEAS );
     887           0 :             pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
     888           0 :             pBindings->Invalidate( SID_BASICSTEPINTO );
     889           0 :             pBindings->Invalidate( SID_BASICSTEPOVER );
     890           0 :             pBindings->Invalidate( SID_BASICSTEPOUT );
     891           0 :             pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
     892           0 :             pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
     893           0 :             pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
     894           0 :             pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
     895           0 :             pBindings->Invalidate( SID_CHOOSE_CONTROLS );
     896           0 :             pBindings->Invalidate( SID_PRINTDOC );
     897           0 :             pBindings->Invalidate( SID_PRINTDOCDIRECT );
     898           0 :             pBindings->Invalidate( SID_SETUPPRINTER );
     899           0 :             pBindings->Invalidate( SID_DIALOG_TESTMODE );
     900             : 
     901           0 :             pBindings->Invalidate( SID_DOC_MODIFIED );
     902           0 :             pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
     903           0 :             pBindings->Invalidate( SID_BASICIDE_STAT_POS );
     904           0 :             pBindings->Invalidate( SID_ATTR_INSERT );
     905           0 :             pBindings->Invalidate( SID_ATTR_SIZE );
     906             :         }
     907             :     }
     908           0 : }
     909             : 
     910           0 : void Shell::EnableScrollbars( bool bEnable )
     911             : {
     912           0 :     aHScrollBar.Enable(bEnable);
     913           0 :     aVScrollBar.Enable(bEnable);
     914           0 : }
     915             : 
     916           0 : void Shell::SetCurLib( const ScriptDocument& rDocument, OUString aLibName, bool bUpdateWindows, bool bCheck )
     917             : {
     918           0 :     if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
     919             :     {
     920           0 :         ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
     921             : 
     922           0 :         m_aCurDocument = rDocument;
     923           0 :         m_aCurLibName = aLibName;
     924             : 
     925           0 :         if ( pListener )
     926             :         {
     927           0 :             pListener->removeContainerListener( m_aCurDocument, m_aCurLibName );
     928           0 :             pListener->addContainerListener( m_aCurDocument, aLibName );
     929             :         }
     930             : 
     931           0 :         if ( bUpdateWindows )
     932           0 :             UpdateWindows();
     933             : 
     934           0 :         SetMDITitle();
     935             : 
     936           0 :         SetCurLibForLocalization( rDocument, aLibName );
     937             : 
     938           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     939             :         {
     940           0 :             pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
     941           0 :             pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
     942           0 :             pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
     943             :         }
     944             :     }
     945           0 : }
     946             : 
     947           0 : void Shell::SetCurLibForLocalization( const ScriptDocument& rDocument, OUString aLibName )
     948             : {
     949             :     // Create LocalizationMgr
     950           0 :     Reference< resource::XStringResourceManager > xStringResourceManager;
     951             :     try
     952             :     {
     953           0 :         if( !aLibName.isEmpty() )
     954             :         {
     955           0 :             Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
     956           0 :             xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
     957             :         }
     958             :     }
     959           0 :     catch (const container::NoSuchElementException& )
     960             :     {}
     961             : 
     962           0 :     m_pCurLocalizationMgr = boost::shared_ptr<LocalizationMgr>(new LocalizationMgr(this, rDocument, aLibName, xStringResourceManager));
     963           0 :     m_pCurLocalizationMgr->handleTranslationbar();
     964           0 : }
     965             : 
     966           0 : void Shell::ImplStartListening( StarBASIC* pBasic )
     967             : {
     968           0 :     StartListening( pBasic->GetBroadcaster(), true /* log on only once */ );
     969           0 : }
     970             : 
     971           0 : } // namespace basctl
     972             : 
     973             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10