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

Generated by: LCOV version 1.10