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

Generated by: LCOV version 1.11