LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - iderdll.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-12-17 Functions: 0 19 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 <comphelper/scoped_disposing_ptr.hxx>
      21             : #include <comphelper/processfactory.hxx>
      22             : 
      23             : #include <svheader.hxx>
      24             : #include <sfx2/app.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <sfx2/genlink.hxx>
      27             : 
      28             : #include <svl/solar.hrc>
      29             : #include <iderdll.hxx>
      30             : #include <iderdll2.hxx>
      31             : #include <iderid.hxx>
      32             : #include <svx/svxids.hrc>
      33             : #include <basidesh.hxx>
      34             : #include <basidesh.hrc>
      35             : #include <basobj.hxx>
      36             : #include <bastypes.hxx>
      37             : #include <basdoc.hxx>
      38             : #include <basicmod.hxx>
      39             : #include <propbrw.hxx>
      40             : 
      41             : #include <svl/srchitem.hxx>
      42             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      43             : 
      44             : #include <boost/scoped_ptr.hpp>
      45             : 
      46             : namespace basctl
      47             : {
      48             : 
      49             : using namespace ::com::sun::star;
      50             : using namespace ::com::sun::star::uno;
      51             : 
      52             : namespace
      53             : {
      54             : 
      55           0 : class Dll
      56             : {
      57             :     Shell* m_pShell;
      58             :     boost::scoped_ptr<ExtraData> m_pExtraData;
      59             : 
      60             : public:
      61             :     Dll ();
      62             : 
      63           0 :     Shell* GetShell() const { return m_pShell; }
      64           0 :     void SetShell (Shell* pShell) { m_pShell = pShell; }
      65             :     ExtraData* GetExtraData ();
      66             : };
      67             : 
      68             : // Holds a basctl::Dll and release it on exit, or dispose of the
      69             : //default XComponent, whichever comes first
      70           0 : class DllInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr<Dll>
      71             : {
      72             : public:
      73           0 :     DllInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr<Dll>(::com::sun::star::uno::Reference<com::sun::star::lang::XComponent>(comphelper::getProcessServiceFactory()->createInstance(OUString("com.sun.star.frame.Desktop")), ::com::sun::star::uno::UNO_QUERY_THROW), new Dll)
      74           0 :     { }
      75             : };
      76             : 
      77             : struct theDllInstance : public rtl::Static<DllInstance, theDllInstance> { };
      78             : 
      79             : } // namespace
      80             : 
      81           0 : void EnsureIde ()
      82             : {
      83           0 :     theDllInstance::get();
      84           0 : }
      85             : 
      86           0 : Shell* GetShell ()
      87             : {
      88           0 :     if (Dll* pDll = theDllInstance::get().get())
      89           0 :         return pDll->GetShell();
      90           0 :     return 0;
      91             : }
      92             : 
      93           0 : void ShellCreated (Shell* pShell)
      94             : {
      95           0 :     Dll* pDll = theDllInstance::get().get();
      96           0 :     if (pDll && !pDll->GetShell())
      97           0 :         pDll->SetShell(pShell);
      98           0 : }
      99             : 
     100           0 : void ShellDestroyed (Shell* pShell)
     101             : {
     102           0 :     Dll* pDll = theDllInstance::get().get();
     103           0 :     if (pDll && pDll->GetShell() == pShell)
     104           0 :         pDll->SetShell(0);
     105           0 : }
     106             : 
     107           0 : ExtraData* GetExtraData()
     108             : {
     109           0 :     if (Dll* pDll = theDllInstance::get().get())
     110           0 :         return pDll->GetExtraData();
     111           0 :     return 0;
     112             : }
     113             : 
     114             : 
     115           0 : IDEResId::IDEResId( sal_uInt16 nId ):
     116           0 :     ResId(nId, *Module::Get()->GetResMgr())
     117           0 : { }
     118             : 
     119             : namespace
     120             : {
     121             : 
     122           0 : Dll::Dll () :
     123           0 :     m_pShell(0)
     124             : {
     125           0 :     SfxObjectFactory* pFact = &DocShell::Factory();
     126             :     (void)pFact;
     127             : 
     128             :     ResMgr* pMgr = ResMgr::CreateResMgr(
     129           0 :         "basctl", Application::GetSettings().GetUILanguageTag().getLocale()
     130           0 :     );
     131             : 
     132           0 :     Module::Get() = new Module( pMgr, &DocShell::Factory() );
     133             : 
     134           0 :     GetExtraData(); // to cause GlobalErrorHdl to be set
     135             : 
     136           0 :     SfxModule* pMod = Module::Get();
     137             : 
     138           0 :     SfxObjectFactory& rFactory = DocShell::Factory();
     139           0 :     rFactory.SetDocumentServiceName( "com.sun.star.script.BasicIDE" );
     140             : 
     141           0 :     DocShell::RegisterInterface( pMod );
     142           0 :     Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH );
     143           0 :     Shell::RegisterInterface( pMod );
     144           0 : }
     145             : 
     146           0 : ExtraData* Dll::GetExtraData ()
     147             : {
     148           0 :     if (!m_pExtraData)
     149           0 :         m_pExtraData.reset(new ExtraData);
     150           0 :     return m_pExtraData.get();
     151             : }
     152             : 
     153             : } // namespace
     154             : 
     155             : //
     156             : // basctl::ExtraData
     157             : // ===================
     158             : //
     159             : 
     160           0 : ExtraData::ExtraData () :
     161           0 :     pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM)),
     162             :     nBasicDialogCount(0),
     163             :     bChoosingMacro(false),
     164           0 :     bShellInCriticalSection(false)
     165             : {
     166           0 :     StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl));
     167           0 : }
     168             : 
     169           0 : ExtraData::~ExtraData ()
     170             : {
     171             :     // Resetting ErrorHdl is cleaner indeed but this instance is destroyed
     172             :     // pretty late, after the last Basic, anyway.
     173             :     // Due to the call there is AppData created then though and not
     174             :     // destroyed anymore => MLK's at Purify
     175             : //  StarBASIC::SetGlobalErrorHdl( Link() );
     176             : //  StarBASIC::SetGlobalBreakHdl( Link() );
     177             : //  StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
     178           0 : }
     179             : 
     180           0 : void ExtraData::SetSearchItem (const SvxSearchItem& rItem)
     181             : {
     182           0 :     pSearchItem.reset((SvxSearchItem*)rItem.Clone());
     183           0 : }
     184             : 
     185           0 : IMPL_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic )
     186             : {
     187           0 :     long nRet = 0;
     188           0 :     if (Shell* pShell = GetShell())
     189             :     {
     190           0 :         if (BasicManager* pBasMgr = FindBasicManager(pBasic))
     191             :         {
     192             :             // I do get here twice if Step into protected Basic
     193             :             // => bad, if password query twice, also you don't see
     194             :             // the lib in the PasswordDlg...
     195             :             // => start no password query at this point
     196           0 :             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
     197             :             OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" );
     198           0 :             if ( aDocument.isValid() )
     199             :             {
     200           0 :                 OUString aOULibName( pBasic->GetName() );
     201           0 :                 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     202           0 :                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
     203             :                 {
     204           0 :                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     205           0 :                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
     206             :                     {
     207             :                            // a step-out should get me out of the protected area...
     208           0 :                         nRet = SbDEBUG_STEPOUT;
     209             :                     }
     210             :                     else
     211             :                     {
     212           0 :                         nRet = pShell->CallBasicBreakHdl( pBasic );
     213           0 :                     }
     214           0 :                 }
     215           0 :             }
     216             :         }
     217             :     }
     218             : 
     219           0 :     return nRet;
     220             : }
     221             : 
     222             : 
     223             : } // namespace basctl
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10