LCOV - code coverage report
Current view: top level - basctl/source/basicide - bastype2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 462 0.0 %
Date: 2014-04-11 Functions: 0 51 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 <vcl/bitmap.hxx>
      21             : #include <vcl/builder.hxx>
      22             : 
      23             : #include "basidesh.hxx"
      24             : #include "iderdll.hxx"
      25             : #include "iderdll2.hxx"
      26             : #include <basidesh.hrc>
      27             : #include <bastypes.hxx>
      28             : #include <bastype2.hxx>
      29             : #include <basobj.hxx>
      30             : #include <baside2.hrc>
      31             : #include <iderid.hxx>
      32             : #include <tools/urlobj.hxx>
      33             : #include <tools/diagnose_ex.h>
      34             : #include <basic/sbx.hxx>
      35             : #include <svtools/imagemgr.hxx>
      36             : #include <svtools/treelistentry.hxx>
      37             : #include <com/sun/star/script/XLibraryContainer.hpp>
      38             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      39             : #include <com/sun/star/frame/ModuleManager.hpp>
      40             : #include <comphelper/processfactory.hxx>
      41             : #include <sfx2/dispatch.hxx>
      42             : 
      43             : #include <cassert>
      44             : #include <map>
      45             : #include <com/sun/star/script/ModuleType.hpp>
      46             : #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
      47             : #include <com/sun/star/container/XNameContainer.hpp>
      48             : #include <com/sun/star/lang/XServiceInfo.hpp>
      49             : #include <com/sun/star/container/XNamed.hpp>
      50             : 
      51             : namespace basctl
      52             : {
      53             : 
      54             : using namespace ::com::sun::star::uno;
      55             : using namespace ::com::sun::star;
      56             : 
      57           0 : void ModuleInfoHelper::getObjectName( const uno::Reference< container::XNameContainer >& rLib, const OUString& rModName, OUString& rObjName )
      58             : {
      59             :     try
      60             :     {
      61           0 :         uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY );
      62           0 :         if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) )
      63             :         {
      64           0 :             script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName );
      65           0 :             uno::Any aObject( aModuleInfo.ModuleObject );
      66           0 :             uno::Reference< lang::XServiceInfo > xServiceInfo( aObject, uno::UNO_QUERY );
      67           0 :             if( xServiceInfo.is() && xServiceInfo->supportsService( "ooo.vba.excel.Worksheet" ) )
      68             :             {
      69           0 :                 uno::Reference< container::XNamed > xNamed( aObject, uno::UNO_QUERY );
      70           0 :                 if( xNamed.is() )
      71           0 :                     rObjName = xNamed->getName();
      72           0 :             }
      73           0 :         }
      74             :     }
      75           0 :     catch(const uno::Exception& )
      76             :     {
      77             :     }
      78           0 : }
      79             : 
      80           0 : sal_Int32 ModuleInfoHelper::getModuleType(  const uno::Reference< container::XNameContainer >& rLib, const OUString& rModName )
      81             : {
      82           0 :     sal_Int32 nType = script::ModuleType::NORMAL;
      83           0 :     uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( rLib, uno::UNO_QUERY );
      84           0 :     if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( rModName ) )
      85             :     {
      86           0 :         script::ModuleInfo aModuleInfo = xVBAModuleInfo->getModuleInfo( rModName );
      87           0 :         nType = aModuleInfo.ModuleType;
      88             :     }
      89           0 :     return nType;
      90             : }
      91             : 
      92           0 : Entry::~Entry()
      93           0 : { }
      94             : 
      95           0 : DocumentEntry::DocumentEntry (
      96             :     ScriptDocument const& rDocument,
      97             :     LibraryLocation eLocation,
      98             :     EntryType eType
      99             : ) :
     100             :     Entry(eType),
     101             :     m_aDocument(rDocument),
     102           0 :     m_eLocation(eLocation)
     103             : {
     104             :     OSL_ENSURE( m_aDocument.isValid(), "DocumentEntry::DocumentEntry: illegal document!" );
     105           0 : }
     106             : 
     107           0 : DocumentEntry::~DocumentEntry()
     108           0 : { }
     109             : 
     110           0 : LibEntry::LibEntry (
     111             :     ScriptDocument const& rDocument,
     112             :     LibraryLocation eLocation,
     113             :     OUString const& rLibName,
     114             :     EntryType eType
     115             : ) :
     116             :     DocumentEntry(rDocument, eLocation, eType),
     117           0 :     m_aLibName(rLibName)
     118           0 : { }
     119             : 
     120           0 : LibEntry::~LibEntry()
     121           0 : { }
     122             : 
     123           0 : EntryDescriptor::EntryDescriptor () :
     124           0 :     m_aDocument(ScriptDocument::getApplicationScriptDocument()),
     125             :     m_eLocation(LIBRARY_LOCATION_UNKNOWN),
     126           0 :     m_eType(OBJ_TYPE_UNKNOWN)
     127           0 : { }
     128             : 
     129           0 : EntryDescriptor::EntryDescriptor (
     130             :     ScriptDocument const& rDocument,
     131             :     LibraryLocation eLocation,
     132             :     OUString const& rLibName,
     133             :     OUString const& rLibSubName,
     134             :     OUString const& rName,
     135             :     EntryType eType
     136             : ) :
     137             :     m_aDocument(rDocument),
     138             :     m_eLocation(eLocation),
     139             :     m_aLibName(rLibName),
     140             :     m_aLibSubName(rLibSubName),
     141             :     m_aName(rName),
     142           0 :     m_eType(eType)
     143             : {
     144             :     OSL_ENSURE( m_aDocument.isValid(), "EntryDescriptor::EntryDescriptor: invalid document!" );
     145           0 : }
     146             : 
     147           0 : EntryDescriptor::EntryDescriptor (
     148             :     ScriptDocument const& rDocument,
     149             :     LibraryLocation eLocation,
     150             :     OUString const& rLibName,
     151             :     OUString const& rLibSubName,
     152             :     OUString const& rName,
     153             :     OUString const& rMethodName,
     154             :     EntryType eType
     155             : ) :
     156             :     m_aDocument(rDocument),
     157             :     m_eLocation(eLocation),
     158             :     m_aLibName(rLibName),
     159             :     m_aLibSubName(rLibSubName),
     160             :     m_aName(rName),
     161             :     m_aMethodName(rMethodName),
     162           0 :     m_eType(eType)
     163             : {
     164             :     OSL_ENSURE( m_aDocument.isValid(), "EntryDescriptor::EntryDescriptor: invalid document!" );
     165           0 : }
     166             : 
     167           0 : EntryDescriptor::~EntryDescriptor()
     168           0 : { }
     169             : 
     170           0 : bool EntryDescriptor::operator == (EntryDescriptor const& rDesc) const
     171             : {
     172             :     return
     173           0 :         m_aDocument == rDesc.m_aDocument &&
     174           0 :         m_eLocation == rDesc.m_eLocation &&
     175           0 :         m_aLibName == rDesc.m_aLibName &&
     176           0 :         m_aLibSubName == rDesc.m_aLibSubName &&
     177           0 :         m_aName == rDesc.m_aName &&
     178           0 :         m_aMethodName == rDesc.m_aMethodName &&
     179           0 :         m_eType == rDesc.m_eType;
     180             : }
     181             : 
     182             : 
     183             : // TreeListBox
     184             : 
     185             : 
     186             : 
     187           0 : TreeListBox::TreeListBox (Window* pParent, ResId const& rRes)
     188           0 :     : SvTreeListBox( pParent, IDEResId( sal::static_int_cast<sal_uInt16>( rRes.GetId() ) ) )
     189           0 :     , m_aNotifier( *this )
     190             : {
     191           0 :     Init();
     192           0 : }
     193             : 
     194           0 : TreeListBox::TreeListBox (Window* pParent, WinBits nStyle)
     195             :     : SvTreeListBox(pParent, nStyle)
     196           0 :     , m_aNotifier( *this )
     197             : {
     198           0 :     Init();
     199           0 : }
     200             : 
     201           0 : void TreeListBox::Init()
     202             : {
     203           0 :     SetNodeDefaultImages();
     204           0 :     SetSelectionMode( SINGLE_SELECTION );
     205           0 :     nMode = 0xFF;   // everything
     206           0 : }
     207             : 
     208           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeTreeListBox(Window *pParent, VclBuilder::stringmap &rMap)
     209             : {
     210           0 :     WinBits nWinBits = WB_TABSTOP;
     211           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
     212           0 :     if (!sBorder.isEmpty())
     213           0 :        nWinBits |= WB_BORDER;
     214           0 :     return new TreeListBox(pParent, nWinBits);
     215             : }
     216             : 
     217           0 : TreeListBox::~TreeListBox ()
     218             : {
     219           0 :     m_aNotifier.dispose();
     220             : 
     221             :     // destroy user data
     222           0 :     SvTreeListEntry* pEntry = First();
     223           0 :     while ( pEntry )
     224             :     {
     225           0 :         delete static_cast<Entry*>(pEntry->GetUserData());
     226           0 :         pEntry = Next( pEntry );
     227             :     }
     228           0 : }
     229             : 
     230           0 : void TreeListBox::ScanEntry( const ScriptDocument& rDocument, LibraryLocation eLocation )
     231             : {
     232             :     OSL_ENSURE( rDocument.isAlive(), "TreeListBox::ScanEntry: illegal document!" );
     233           0 :     if ( !rDocument.isAlive() )
     234           0 :         return;
     235             : 
     236             :     // can be called multiple times for updating!
     237             : 
     238             :     // actually test if basic's in the tree already?!
     239           0 :     SetUpdateMode(false);
     240             : 
     241             :     // level 1: BasicManager (application, document, ...)
     242           0 :     SvTreeListEntry* pDocumentRootEntry = FindRootEntry( rDocument, eLocation );
     243           0 :     if ( pDocumentRootEntry && IsExpanded( pDocumentRootEntry ) )
     244           0 :         ImpCreateLibEntries( pDocumentRootEntry, rDocument, eLocation );
     245           0 :     if ( !pDocumentRootEntry )
     246             :     {
     247           0 :         OUString aRootName( GetRootEntryName( rDocument, eLocation ) );
     248           0 :         Image aImage;
     249           0 :         GetRootEntryBitmaps( rDocument, aImage );
     250           0 :         o3tl::heap_ptr<Entry> e(new DocumentEntry(rDocument, eLocation));
     251             :         AddEntry(
     252             :             aRootName,
     253             :             aImage,
     254           0 :             0, true, &e);
     255             :     }
     256             : 
     257           0 :     SetUpdateMode(true);
     258             : }
     259             : 
     260           0 : void TreeListBox::ImpCreateLibEntries( SvTreeListEntry* pDocumentRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation )
     261             : {
     262             :     // get a sorted list of library names
     263           0 :     Sequence< OUString > aLibNames( rDocument.getLibraryNames() );
     264           0 :     sal_Int32 nLibCount = aLibNames.getLength();
     265           0 :     const OUString* pLibNames = aLibNames.getConstArray();
     266             : 
     267           0 :     for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     268             :     {
     269           0 :         OUString aLibName = pLibNames[ i ];
     270             : 
     271           0 :         if ( eLocation == rDocument.getLibraryLocation( aLibName ) )
     272             :         {
     273             :             // check, if the module library is loaded
     274           0 :             bool bModLibLoaded = false;
     275           0 :             OUString aOULibName( aLibName );
     276           0 :             Reference< script::XLibraryContainer > xModLibContainer( rDocument.getLibraryContainer( E_SCRIPTS ) );
     277           0 :             if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLoaded( aOULibName ) )
     278           0 :                 bModLibLoaded = true;
     279             : 
     280             :             // check, if the dialog library is loaded
     281           0 :             bool bDlgLibLoaded = false;
     282           0 :             Reference< script::XLibraryContainer > xDlgLibContainer( rDocument.getLibraryContainer( E_DIALOGS ) );
     283           0 :             if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryLoaded( aOULibName ) )
     284           0 :                 bDlgLibLoaded = true;
     285             : 
     286           0 :             bool bLoaded = bModLibLoaded || bDlgLibLoaded;
     287             : 
     288             :             // if only one of the libraries is loaded, load also the other
     289           0 :             if ( bLoaded )
     290             :             {
     291           0 :                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
     292           0 :                     xModLibContainer->loadLibrary( aOULibName );
     293             : 
     294           0 :                 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
     295           0 :                     xDlgLibContainer->loadLibrary( aOULibName );
     296             :             }
     297             : 
     298             :             // create tree list box entry
     299             :             sal_uInt16 nId;
     300           0 :             if ( ( nMode & BROWSEMODE_DIALOGS ) && !( nMode & BROWSEMODE_MODULES ) )
     301           0 :                 nId = bLoaded ? RID_IMG_DLGLIB : RID_IMG_DLGLIBNOTLOADED;
     302             :             else
     303           0 :                 nId = bLoaded ? RID_IMG_MODLIB : RID_IMG_MODLIBNOTLOADED;
     304           0 :             SvTreeListEntry* pLibRootEntry = FindEntry( pDocumentRootEntry, aLibName, OBJ_TYPE_LIBRARY );
     305           0 :             if ( pLibRootEntry )
     306             :             {
     307           0 :                 SetEntryBitmaps( pLibRootEntry, Image( IDEResId( nId ) ) );
     308           0 :                 if ( IsExpanded( pLibRootEntry ) )
     309           0 :                     ImpCreateLibSubEntries( pLibRootEntry, rDocument, aLibName );
     310             :             }
     311             :             else
     312             :             {
     313           0 :                 o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_LIBRARY));
     314             :                 AddEntry(
     315             :                     aLibName,
     316             :                     Image( IDEResId( nId ) ),
     317           0 :                     pDocumentRootEntry, true, &e);
     318           0 :             }
     319             :         }
     320           0 :     }
     321           0 : }
     322             : 
     323           0 : void TreeListBox::ImpCreateLibSubEntries( SvTreeListEntry* pLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName )
     324             : {
     325             :     // modules
     326           0 :     if ( nMode & BROWSEMODE_MODULES )
     327             :     {
     328           0 :         Reference< script::XLibraryContainer > xModLibContainer( rDocument.getLibraryContainer( E_SCRIPTS ) );
     329             : 
     330           0 :         if ( xModLibContainer.is() && xModLibContainer->hasByName( rLibName ) && xModLibContainer->isLibraryLoaded( rLibName ) )
     331             :         {
     332             :             try
     333             :             {
     334           0 :                 if( rDocument.isInVBAMode() )
     335           0 :                     ImpCreateLibSubEntriesInVBAMode( pLibRootEntry, rDocument, rLibName );
     336             :                 else
     337             :                 {
     338             :                     // get a sorted list of module names
     339           0 :                     Sequence< OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
     340           0 :                     sal_Int32 nModCount = aModNames.getLength();
     341           0 :                     const OUString* pModNames = aModNames.getConstArray();
     342             : 
     343           0 :                     for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
     344             :                     {
     345           0 :                         OUString aModName = pModNames[ i ];
     346           0 :                         SvTreeListEntry* pModuleEntry = FindEntry( pLibRootEntry, aModName, OBJ_TYPE_MODULE );
     347           0 :                         if ( !pModuleEntry )
     348             :                         {
     349           0 :                             o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_MODULE));
     350             :                             pModuleEntry = AddEntry(
     351             :                                 aModName,
     352             :                                 Image( IDEResId( RID_IMG_MODULE ) ),
     353           0 :                                 pLibRootEntry, false, &e);
     354             :                         }
     355             : 
     356             :                         // methods
     357           0 :                         if ( nMode & BROWSEMODE_SUBS )
     358             :                         {
     359           0 :                             Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName );
     360           0 :                             sal_Int32 nCount = aNames.getLength();
     361           0 :                             const OUString* pNames = aNames.getConstArray();
     362             : 
     363           0 :                             for ( sal_Int32 j = 0 ; j < nCount ; j++ )
     364             :                             {
     365           0 :                                 OUString aName = pNames[ j ];
     366           0 :                                 SvTreeListEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD );
     367           0 :                                 if ( !pEntry )
     368             :                                 {
     369             :                                     o3tl::heap_ptr<Entry> e(
     370           0 :                                         new Entry(OBJ_TYPE_METHOD));
     371             :                                     pEntry = AddEntry(
     372             :                                         aName,
     373             :                                         Image( IDEResId( RID_IMG_MACRO ) ),
     374           0 :                                         pModuleEntry, false, &e);
     375             :                                 }
     376           0 :                             }
     377             :                         }
     378           0 :                     }
     379             :                 }
     380             :             }
     381           0 :             catch ( const container::NoSuchElementException& )
     382             :             {
     383             :                 DBG_UNHANDLED_EXCEPTION();
     384             :             }
     385           0 :         }
     386             :     }
     387             : 
     388             :     // dialogs
     389           0 :     if ( nMode & BROWSEMODE_DIALOGS )
     390             :     {
     391           0 :          Reference< script::XLibraryContainer > xDlgLibContainer( rDocument.getLibraryContainer( E_DIALOGS ) );
     392             : 
     393           0 :          if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( rLibName ) && xDlgLibContainer->isLibraryLoaded( rLibName ) )
     394             :          {
     395             :             try
     396             :             {
     397             :                 // get a sorted list of dialog names
     398           0 :                 Sequence< OUString > aDlgNames( rDocument.getObjectNames( E_DIALOGS, rLibName ) );
     399           0 :                 sal_Int32 nDlgCount = aDlgNames.getLength();
     400           0 :                 const OUString* pDlgNames = aDlgNames.getConstArray();
     401             : 
     402           0 :                 for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ )
     403             :                 {
     404           0 :                     OUString aDlgName = pDlgNames[ i ];
     405           0 :                     SvTreeListEntry* pDialogEntry = FindEntry( pLibRootEntry, aDlgName, OBJ_TYPE_DIALOG );
     406           0 :                     if ( !pDialogEntry )
     407             :                     {
     408           0 :                         o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_DIALOG));
     409             :                         pDialogEntry = AddEntry(
     410             :                             aDlgName,
     411             :                             Image( IDEResId( RID_IMG_DIALOG ) ),
     412           0 :                             pLibRootEntry, false, &e);
     413             :                     }
     414           0 :                 }
     415             :             }
     416           0 :             catch (const container::NoSuchElementException& )
     417             :             {
     418             :                 DBG_UNHANDLED_EXCEPTION();
     419             :             }
     420           0 :         }
     421             :     }
     422           0 : }
     423             : 
     424           0 : void TreeListBox::ImpCreateLibSubEntriesInVBAMode( SvTreeListEntry* pLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName )
     425             : {
     426             : 
     427           0 :     std::vector<std::pair<EntryType, OUString> > aEntries;
     428           0 :     aEntries.push_back( ::std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS, IDE_RESSTR(RID_STR_DOCUMENT_OBJECTS) ) );
     429           0 :     aEntries.push_back( ::std::make_pair( OBJ_TYPE_USERFORMS, IDE_RESSTR(RID_STR_USERFORMS) ) );
     430           0 :     aEntries.push_back( ::std::make_pair( OBJ_TYPE_NORMAL_MODULES, IDE_RESSTR(RID_STR_NORMAL_MODULES) ) );
     431           0 :     aEntries.push_back( ::std::make_pair( OBJ_TYPE_CLASS_MODULES, IDE_RESSTR(RID_STR_CLASS_MODULES) ) );
     432             : 
     433           0 :     std::vector<std::pair<EntryType, OUString> >::iterator iter;
     434           0 :     for( iter = aEntries.begin(); iter != aEntries.end(); ++iter )
     435             :     {
     436           0 :         EntryType eType = iter->first;
     437           0 :         OUString aEntryName = iter->second;
     438           0 :         SvTreeListEntry* pLibSubRootEntry = FindEntry( pLibRootEntry, aEntryName, eType );
     439           0 :         if( pLibSubRootEntry )
     440             :         {
     441           0 :             SetEntryBitmaps( pLibSubRootEntry, Image( IDEResId( RID_IMG_MODLIB ) ) );
     442           0 :             if ( IsExpanded( pLibSubRootEntry ) )
     443           0 :                 ImpCreateLibSubSubEntriesInVBAMode( pLibSubRootEntry, rDocument, rLibName );
     444             :         }
     445             :         else
     446             :         {
     447           0 :             o3tl::heap_ptr<Entry> e(new Entry(eType));
     448             :             AddEntry(
     449             :                 aEntryName,
     450             :                 Image( IDEResId( RID_IMG_MODLIB ) ),
     451           0 :                 pLibRootEntry, true, &e);
     452             :         }
     453           0 :     }
     454           0 : }
     455             : 
     456           0 : void TreeListBox::ImpCreateLibSubSubEntriesInVBAMode( SvTreeListEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const OUString& rLibName )
     457             : {
     458           0 :     uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, rLibName );
     459           0 :     if( !xLib.is() )
     460           0 :         return;
     461             : 
     462             :     try
     463             :     {
     464             :         // get a sorted list of module names
     465           0 :         Sequence< OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
     466           0 :         sal_Int32 nModCount = aModNames.getLength();
     467           0 :         const OUString* pModNames = aModNames.getConstArray();
     468             : 
     469           0 :         EntryDescriptor aDesc( GetEntryDescriptor( pLibSubRootEntry ) );
     470           0 :         EntryType eCurrentType( aDesc.GetType() );
     471             : 
     472           0 :         for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
     473             :         {
     474           0 :             OUString aModName = pModNames[ i ];
     475           0 :             EntryType eType = OBJ_TYPE_UNKNOWN;
     476           0 :             switch( ModuleInfoHelper::getModuleType( xLib, aModName ) )
     477             :             {
     478             :                 case script::ModuleType::DOCUMENT:
     479           0 :                     eType = OBJ_TYPE_DOCUMENT_OBJECTS;
     480           0 :                     break;
     481             :                 case script::ModuleType::FORM:
     482           0 :                     eType = OBJ_TYPE_USERFORMS;
     483           0 :                     break;
     484             :                 case script::ModuleType::NORMAL:
     485           0 :                     eType = OBJ_TYPE_NORMAL_MODULES;
     486           0 :                     break;
     487             :                 case script::ModuleType::CLASS:
     488           0 :                     eType = OBJ_TYPE_CLASS_MODULES;
     489           0 :                     break;
     490             :             }
     491           0 :             if( eType != eCurrentType )
     492           0 :                 continue;
     493             : 
     494             :             // display a nice friendly name in the ObjectModule tab,
     495             :                // combining the objectname and module name, e.g. Sheet1 ( Financials )
     496           0 :             OUString aEntryName = aModName;
     497           0 :             if( eType == OBJ_TYPE_DOCUMENT_OBJECTS )
     498             :             {
     499           0 :                 OUString sObjName;
     500           0 :                 ModuleInfoHelper::getObjectName( xLib, aModName, sObjName );
     501           0 :                 if( !sObjName.isEmpty() )
     502             :                 {
     503           0 :                     aEntryName += " (" + sObjName + ")";
     504           0 :                 }
     505             :             }
     506           0 :             SvTreeListEntry* pModuleEntry = FindEntry( pLibSubRootEntry, aEntryName, OBJ_TYPE_MODULE );
     507           0 :             if ( !pModuleEntry )
     508             :             {
     509           0 :                 o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_MODULE));
     510             :                 pModuleEntry = AddEntry(
     511             :                     aEntryName,
     512             :                     Image( IDEResId( RID_IMG_MODULE ) ),
     513           0 :                     pLibSubRootEntry, false, &e);
     514             :             }
     515             : 
     516             :             // methods
     517           0 :             if ( nMode & BROWSEMODE_SUBS )
     518             :             {
     519           0 :                 Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName );
     520           0 :                 sal_Int32 nCount = aNames.getLength();
     521           0 :                 const OUString* pNames = aNames.getConstArray();
     522             : 
     523           0 :                 for ( sal_Int32 j = 0 ; j < nCount ; j++ )
     524             :                 {
     525           0 :                     OUString aName = pNames[ j ];
     526           0 :                     SvTreeListEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD );
     527           0 :                     if ( !pEntry )
     528             :                     {
     529           0 :                         o3tl::heap_ptr<Entry> e(new Entry(OBJ_TYPE_METHOD));
     530             :                         pEntry = AddEntry(
     531             :                             aName,
     532             :                             Image( IDEResId( RID_IMG_MACRO ) ),
     533           0 :                             pModuleEntry, false, &e);
     534             :                     }
     535           0 :                 }
     536             :             }
     537           0 :         }
     538             :     }
     539           0 :     catch ( const container::NoSuchElementException& )
     540             :     {
     541             :         DBG_UNHANDLED_EXCEPTION();
     542           0 :     }
     543             : }
     544             : 
     545           0 : SvTreeListEntry* TreeListBox::ImpFindEntry( SvTreeListEntry* pParent, const OUString& rText )
     546             : {
     547           0 :     sal_uLong nRootPos = 0;
     548           0 :     SvTreeListEntry* pEntry = pParent ? FirstChild( pParent ) : GetEntry( nRootPos );
     549           0 :     while ( pEntry )
     550             :     {
     551           0 :         if (  rText.equals(GetEntryText( pEntry )) )
     552           0 :             return pEntry;
     553             : 
     554           0 :         pEntry = pParent ? NextSibling( pEntry ) : GetEntry( ++nRootPos );
     555             :     }
     556           0 :     return 0;
     557             : }
     558             : 
     559           0 : void TreeListBox::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
     560             : {
     561           0 :     UpdateEntries();
     562           0 : }
     563             : 
     564           0 : void TreeListBox::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
     565             : {
     566           0 :     UpdateEntries();
     567           0 : }
     568             : 
     569           0 : void TreeListBox::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
     570             : {
     571             :     // not interested in
     572           0 : }
     573             : 
     574           0 : void TreeListBox::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
     575             : {
     576             :     // not interested in
     577           0 : }
     578             : 
     579           0 : void TreeListBox::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
     580             : {
     581             :     // not interested in
     582           0 : }
     583             : 
     584           0 : void TreeListBox::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
     585             : {
     586           0 :     UpdateEntries();
     587           0 : }
     588             : 
     589           0 : void TreeListBox::onDocumentClosed( const ScriptDocument& rDocument )
     590             : {
     591           0 :     UpdateEntries();
     592             :     // The document is not yet actually deleted, so we need to remove its entry
     593             :     // manually.
     594           0 :     RemoveEntry(rDocument);
     595           0 : }
     596             : 
     597           0 : void TreeListBox::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
     598             : {
     599             :     // not interested in
     600           0 : }
     601             : 
     602           0 : void TreeListBox::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ )
     603             : {
     604             :     // not interested in
     605           0 : }
     606             : 
     607           0 : void TreeListBox::UpdateEntries()
     608             : {
     609           0 :     EntryDescriptor aCurDesc( GetEntryDescriptor( FirstSelected() ) );
     610             : 
     611             :     // removing the invalid entries
     612           0 :     SvTreeListEntry* pLastValid = 0;
     613           0 :     SvTreeListEntry* pEntry = First();
     614           0 :     while ( pEntry )
     615             :     {
     616           0 :         if ( IsValidEntry( pEntry ) )
     617           0 :             pLastValid = pEntry;
     618             :         else
     619           0 :             RemoveEntry(pEntry);
     620           0 :         pEntry = pLastValid ? Next( pLastValid ) : First();
     621             :     }
     622             : 
     623           0 :     ScanAllEntries();
     624             : 
     625           0 :     SetCurrentEntry( aCurDesc );
     626           0 : }
     627             : 
     628             : // Removes the entry from the tree.
     629           0 : void TreeListBox::RemoveEntry (SvTreeListEntry* pEntry)
     630             : {
     631             :     // removing the associated user data
     632           0 :     delete static_cast<Entry*>(pEntry->GetUserData());
     633             :     // removing the entry
     634           0 :     GetModel()->Remove( pEntry );
     635           0 : }
     636             : 
     637             : // Removes the entry of rDocument.
     638           0 : void TreeListBox::RemoveEntry (ScriptDocument const& rDocument)
     639             : {
     640             :     // finding the entry of rDocument
     641           0 :     for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
     642           0 :         if (rDocument == GetEntryDescriptor(pEntry).GetDocument())
     643             :         {
     644           0 :             RemoveEntry(pEntry);
     645           0 :             break;
     646             :         }
     647           0 : }
     648             : 
     649           0 : SvTreeListEntry* TreeListBox::CloneEntry( SvTreeListEntry* pSource )
     650             : {
     651           0 :     SvTreeListEntry* pNew = SvTreeListBox::CloneEntry( pSource );
     652           0 :     Entry* pUser = static_cast<Entry*>(pSource->GetUserData());
     653             : 
     654             :     DBG_ASSERT( pUser, "User-Daten?!" );
     655             :     DBG_ASSERT( pUser->GetType() != OBJ_TYPE_DOCUMENT, "TreeListBox::CloneEntry: document?!" );
     656             : 
     657           0 :     Entry* pNewUser = new Entry( *pUser );
     658           0 :     pNew->SetUserData( pNewUser );
     659           0 :     return pNew;
     660             : }
     661             : 
     662           0 : SvTreeListEntry* TreeListBox::FindEntry( SvTreeListEntry* pParent, const OUString& rText, EntryType eType )
     663             : {
     664           0 :     sal_uLong nRootPos = 0;
     665           0 :     SvTreeListEntry* pEntry = pParent ? FirstChild( pParent ) : GetEntry( nRootPos );
     666           0 :     while ( pEntry )
     667             :     {
     668           0 :         Entry* pBasicEntry = static_cast<Entry*>(pEntry->GetUserData());
     669             :         DBG_ASSERT( pBasicEntry, "FindEntry: no Entry ?!" );
     670           0 :         if ( ( pBasicEntry->GetType() == eType  ) && ( rText.equals(GetEntryText( pEntry )) ) )
     671           0 :             return pEntry;
     672             : 
     673           0 :         pEntry = pParent ? NextSibling( pEntry ) : GetEntry( ++nRootPos );
     674             :     }
     675           0 :     return 0;
     676             : }
     677             : 
     678           0 : bool TreeListBox::ExpandingHdl()
     679             : {
     680             :     // expanding or collapsing?
     681           0 :     bool bOK = true;
     682           0 :     if ( GetModel()->GetDepth( GetHdlEntry() ) == 1 )
     683             :     {
     684           0 :         SvTreeListEntry* pCurEntry = GetCurEntry();
     685           0 :         EntryDescriptor aDesc( GetEntryDescriptor( pCurEntry ) );
     686           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     687             :         OSL_ENSURE( aDocument.isAlive(), "TreeListBox::ExpandingHdl: no document, or document is dead!" );
     688           0 :         if ( aDocument.isAlive() )
     689             :         {
     690           0 :             OUString aLibName( aDesc.GetLibName() );
     691           0 :             OUString aLibSubName( aDesc.GetLibSubName() );
     692           0 :             OUString aName( aDesc.GetName() );
     693           0 :             OUString aMethodName( aDesc.GetMethodName() );
     694             : 
     695           0 :             if ( !aLibName.isEmpty() && aLibSubName.isEmpty() && aName.isEmpty() && aMethodName.isEmpty() )
     696             :             {
     697             :                 // check password, if library is password protected and not verified
     698           0 :                 Reference< script::XLibraryContainer > xModLibContainer( aDocument.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 :                         OUString aPassword;
     705           0 :                         bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
     706           0 :                     }
     707           0 :                 }
     708           0 :             }
     709           0 :         }
     710             :     }
     711           0 :     return bOK;
     712             : }
     713             : 
     714           0 : bool TreeListBox::IsEntryProtected( SvTreeListEntry* pEntry )
     715             : {
     716           0 :     bool bProtected = false;
     717           0 :     if ( pEntry && ( GetModel()->GetDepth( pEntry ) == 1 ) )
     718             :     {
     719           0 :         EntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
     720           0 :         ScriptDocument aDocument( aDesc.GetDocument() );
     721             :         OSL_ENSURE( aDocument.isAlive(), "TreeListBox::IsEntryProtected: no document, or document is dead!" );
     722           0 :         if ( aDocument.isAlive() )
     723             :         {
     724           0 :             OUString aOULibName( aDesc.GetLibName() );
     725           0 :             Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
     726           0 :             if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
     727             :             {
     728           0 :                 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
     729           0 :                 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
     730             :                 {
     731           0 :                     bProtected = true;
     732           0 :                 }
     733           0 :             }
     734           0 :         }
     735             :     }
     736           0 :     return bProtected;
     737             : }
     738             : 
     739           0 : SvTreeListEntry* TreeListBox::AddEntry(
     740             :     OUString const& rText,
     741             :     const Image& rImage,
     742             :     SvTreeListEntry* pParent,
     743             :     bool bChildrenOnDemand,
     744             :     o3tl::heap_ptr<Entry> * aUserData
     745             : )
     746             : {
     747             :     assert(aUserData != 0);
     748             :     SvTreeListEntry* p = InsertEntry(
     749             :         rText, rImage, rImage, pParent, bChildrenOnDemand, TREELIST_APPEND,
     750           0 :         aUserData->get()
     751           0 :     );
     752           0 :     aUserData->release();
     753           0 :     return p;
     754             : }
     755             : 
     756           0 : void TreeListBox::SetEntryBitmaps( SvTreeListEntry * pEntry, const Image& rImage )
     757             : {
     758           0 :     SetExpandedEntryBmp(  pEntry, rImage );
     759           0 :     SetCollapsedEntryBmp( pEntry, rImage );
     760           0 : }
     761             : 
     762           0 : LibraryType TreeListBox::GetLibraryType() const
     763             : {
     764           0 :     LibraryType eType = LIBRARY_TYPE_ALL;
     765           0 :     if ( ( nMode & BROWSEMODE_MODULES ) && !( nMode & BROWSEMODE_DIALOGS ) )
     766           0 :         eType = LIBRARY_TYPE_MODULE;
     767           0 :     else if ( !( nMode & BROWSEMODE_MODULES ) && ( nMode & BROWSEMODE_DIALOGS ) )
     768           0 :         eType = LIBRARY_TYPE_DIALOG;
     769           0 :     return eType;
     770             : }
     771             : 
     772           0 : OUString TreeListBox::GetRootEntryName( const ScriptDocument& rDocument, LibraryLocation eLocation ) const
     773             : {
     774           0 :     return rDocument.getTitle( eLocation, GetLibraryType() );
     775             : }
     776             : 
     777           0 : void TreeListBox::GetRootEntryBitmaps( const ScriptDocument& rDocument, Image& rImage )
     778             : {
     779             :     OSL_ENSURE( rDocument.isValid(), "TreeListBox::GetRootEntryBitmaps: illegal document!" );
     780           0 :     if ( !rDocument.isValid() )
     781           0 :         return;
     782             : 
     783           0 :     if ( rDocument.isDocument() )
     784             :     {
     785           0 :         OUString sFactoryURL;
     786           0 :         Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     787           0 :         Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xContext) );
     788             :         try
     789             :         {
     790           0 :             OUString sModule( xModuleManager->identify( rDocument.getDocument() ) );
     791           0 :             Reference< container::XNameAccess > xModuleConfig( xModuleManager, UNO_QUERY );
     792           0 :             if ( xModuleConfig.is() )
     793             :             {
     794           0 :                 Sequence< beans::PropertyValue > aModuleDescr;
     795           0 :                 xModuleConfig->getByName( sModule ) >>= aModuleDescr;
     796           0 :                 sal_Int32 nCount = aModuleDescr.getLength();
     797           0 :                 const beans::PropertyValue* pModuleDescr = aModuleDescr.getConstArray();
     798           0 :                 for ( sal_Int32 i = 0; i < nCount; ++i )
     799             :                 {
     800           0 :                     if ( pModuleDescr[ i ].Name == "ooSetupFactoryEmptyDocumentURL" )
     801             :                     {
     802           0 :                         pModuleDescr[ i ].Value >>= sFactoryURL;
     803           0 :                         break;
     804             :                     }
     805           0 :                 }
     806           0 :             }
     807             :         }
     808           0 :         catch( const Exception& )
     809             :         {
     810             :             DBG_UNHANDLED_EXCEPTION();
     811             :         }
     812             : 
     813           0 :         if ( !sFactoryURL.isEmpty() )
     814             :         {
     815           0 :             rImage = SvFileInformationManager::GetFileImage( INetURLObject( sFactoryURL ), false );
     816             :         }
     817             :         else
     818             :         {
     819             :             // default icon
     820           0 :             rImage = Image( IDEResId( RID_IMG_DOCUMENT ) );
     821           0 :         }
     822             :     }
     823             :     else
     824             :     {
     825           0 :         rImage = Image( IDEResId( RID_IMG_INSTALLATION ) );
     826             :     }
     827             : }
     828             : 
     829           0 : void TreeListBox::SetCurrentEntry (EntryDescriptor& rDesc)
     830             : {
     831           0 :     SvTreeListEntry* pCurEntry = 0;
     832           0 :     EntryDescriptor aDesc = rDesc;
     833           0 :     if ( aDesc.GetType() == OBJ_TYPE_UNKNOWN )
     834             :     {
     835           0 :         aDesc = EntryDescriptor(
     836           0 :             ScriptDocument::getApplicationScriptDocument(),
     837             :             LIBRARY_LOCATION_USER, "Standard",
     838             :             OUString(), ".", OBJ_TYPE_UNKNOWN
     839           0 :         );
     840             :     }
     841           0 :     ScriptDocument aDocument = aDesc.GetDocument();
     842             :     OSL_ENSURE( aDocument.isValid(), "TreeListBox::SetCurrentEntry: invalid document!" );
     843           0 :     LibraryLocation eLocation = aDesc.GetLocation();
     844           0 :     SvTreeListEntry* pRootEntry = FindRootEntry( aDocument, eLocation );
     845           0 :     if ( pRootEntry )
     846             :     {
     847           0 :         pCurEntry = pRootEntry;
     848           0 :         OUString aLibName( aDesc.GetLibName() );
     849           0 :         if ( !aLibName.isEmpty() )
     850             :         {
     851           0 :             Expand( pRootEntry );
     852           0 :             SvTreeListEntry* pLibEntry = FindEntry( pRootEntry, aLibName, OBJ_TYPE_LIBRARY );
     853           0 :             if ( pLibEntry )
     854             :             {
     855           0 :                 pCurEntry = pLibEntry;
     856           0 :                 OUString aLibSubName( aDesc.GetLibSubName() );
     857           0 :                 if( !aLibSubName.isEmpty() )
     858             :                 {
     859           0 :                     Expand( pLibEntry );
     860           0 :                     SvTreeListEntry* pLibSubEntry = ImpFindEntry( pLibEntry, aLibSubName );
     861           0 :                     if( pLibSubEntry )
     862             :                     {
     863           0 :                         pCurEntry = pLibSubEntry;
     864             :                     }
     865             :                 }
     866           0 :                 OUString aName( aDesc.GetName() );
     867           0 :                 if ( !aName.isEmpty() )
     868             :                 {
     869           0 :                     Expand( pCurEntry );
     870           0 :                     EntryType eType = OBJ_TYPE_MODULE;
     871           0 :                     if ( aDesc.GetType() == OBJ_TYPE_DIALOG )
     872           0 :                         eType = OBJ_TYPE_DIALOG;
     873           0 :                     SvTreeListEntry* pEntry = FindEntry( pCurEntry, aName, eType );
     874           0 :                     if ( pEntry )
     875             :                     {
     876           0 :                         pCurEntry = pEntry;
     877           0 :                         OUString aMethodName( aDesc.GetMethodName() );
     878           0 :                         if ( !aMethodName.isEmpty() )
     879             :                         {
     880           0 :                             Expand( pEntry );
     881           0 :                             SvTreeListEntry* pSubEntry = FindEntry( pEntry, aMethodName, OBJ_TYPE_METHOD );
     882           0 :                             if ( pSubEntry )
     883             :                             {
     884           0 :                                 pCurEntry = pSubEntry;
     885             :                             }
     886             :                             else
     887             :                             {
     888           0 :                                 pSubEntry = FirstChild( pEntry );
     889           0 :                                 if ( pSubEntry )
     890           0 :                                     pCurEntry = pSubEntry;
     891             :                             }
     892           0 :                         }
     893             :                     }
     894             :                     else
     895             :                     {
     896           0 :                         pEntry = FirstChild( pLibEntry );
     897           0 :                         if ( pEntry )
     898           0 :                             pCurEntry = pEntry;
     899             :                     }
     900           0 :                 }
     901             :             }
     902             :             else
     903             :             {
     904           0 :                 pLibEntry = FirstChild( pRootEntry );
     905           0 :                 if ( pLibEntry )
     906           0 :                     pCurEntry = pLibEntry;
     907             :             }
     908           0 :         }
     909             :     }
     910             :     else
     911             :     {
     912           0 :         pRootEntry = First();
     913           0 :         if ( pRootEntry )
     914           0 :             pCurEntry = pRootEntry;
     915             :     }
     916             : 
     917           0 :     SetCurEntry( pCurEntry );
     918           0 : }
     919             : 
     920           0 : void TreeListBox::MouseButtonDown( const MouseEvent& rMEvt )
     921             : {
     922           0 :     SvTreeListBox::MouseButtonDown( rMEvt );
     923           0 :     if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) )
     924             :     {
     925           0 :         EntryDescriptor aDesc = GetEntryDescriptor(GetCurEntry());
     926           0 :         switch (aDesc.GetType())
     927             :         {
     928             :             case OBJ_TYPE_METHOD:
     929             :             case OBJ_TYPE_MODULE:
     930             :             case OBJ_TYPE_DIALOG:
     931           0 :                 if (SfxDispatcher* pDispatcher = GetDispatcher())
     932             :                 {
     933             :                     SbxItem aSbxItem(
     934           0 :                         SID_BASICIDE_ARG_SBX, aDesc.GetDocument(),
     935           0 :                         aDesc.GetLibName(), aDesc.GetName(), aDesc.GetMethodName(),
     936             :                         ConvertType(aDesc.GetType())
     937           0 :                     );
     938             :                     pDispatcher->Execute(
     939             :                         SID_BASICIDE_SHOWSBX,
     940             :                         SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L
     941           0 :                     );
     942             :                 }
     943           0 :                 break;
     944             : 
     945             :             default:
     946           0 :                 break;
     947           0 :         }
     948             :     }
     949           0 : }
     950             : 
     951             : 
     952             : } // namespace basctl
     953             : 
     954             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10