LCOV - code coverage report
Current view: top level - cui/source/customize - cfgutil.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 596 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 40 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 "cfgutil.hxx"
      21             : 
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      24             : #include <com/sun/star/container/XEnumeration.hpp>
      25             : #include <com/sun/star/document/XScriptInvocationContext.hpp>
      26             : #include <com/sun/star/frame/ModuleManager.hpp>
      27             : #include <com/sun/star/frame/Desktop.hpp>
      28             : #include <com/sun/star/frame/theUICommandDescription.hpp>
      29             : #include <com/sun/star/frame/XDispatchInformationProvider.hpp>
      30             : #include <com/sun/star/script/browse/XBrowseNode.hpp>
      31             : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
      32             : #include <com/sun/star/script/browse/theBrowseNodeFactory.hpp>
      33             : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
      34             : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
      35             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      36             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      37             : #include <com/sun/star/uno/RuntimeException.hpp>
      38             : #include <com/sun/star/ui/theUICategoryDescription.hpp>
      39             : 
      40             : #include "acccfg.hrc"
      41             : #include "helpid.hrc"
      42             : #include <basic/sbx.hxx>
      43             : #include <basic/basicmanagerrepository.hxx>
      44             : #include <basic/sbstar.hxx>
      45             : #include <basic/sbxmeth.hxx>
      46             : #include <basic/sbmod.hxx>
      47             : #include <basic/basmgr.hxx>
      48             : #include <tools/urlobj.hxx>
      49             : #include "cuires.hrc"
      50             : #include <sfx2/app.hxx>
      51             : #include <sfx2/minfitem.hxx>
      52             : #include <comphelper/documentinfo.hxx>
      53             : #include <comphelper/processfactory.hxx>
      54             : #include <comphelper/sequenceashashmap.hxx>
      55             : #include <comphelper/string.hxx>
      56             : #include <svtools/imagemgr.hxx>
      57             : #include "svtools/treelistentry.hxx"
      58             : #include <rtl/ustrbuf.hxx>
      59             : #include <unotools/configmgr.hxx>
      60             : #include "dialmgr.hxx"
      61             : #include <svl/stritem.hxx>
      62             : #include <vcl/builderfactory.hxx>
      63             : 
      64             : using namespace ::com::sun::star;
      65             : using namespace ::com::sun::star::uno;
      66             : using namespace ::com::sun::star::script;
      67             : using namespace ::com::sun::star::frame;
      68             : using namespace ::com::sun::star::document;
      69             : 
      70           0 : SfxStylesInfo_Impl::SfxStylesInfo_Impl()
      71           0 : {}
      72             : 
      73           0 : void SfxStylesInfo_Impl::setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel)
      74             : {
      75           0 :     m_xDoc = xModel;
      76           0 : }
      77             : 
      78             : static const char CMDURL_SPART [] = ".uno:StyleApply?Style:string=";
      79             : static const char CMDURL_FPART2[] = "&FamilyName:string=";
      80             : 
      81             : static const char CMDURL_STYLEPROT_ONLY[] = ".uno:StyleApply?";
      82             : static const char CMDURL_SPART_ONLY    [] = "Style:string=";
      83             : static const char CMDURL_FPART_ONLY    [] = "FamilyName:string=";
      84             : 
      85             : static const char STYLEPROP_UINAME[] = "DisplayName";
      86             : 
      87           0 : OUString SfxStylesInfo_Impl::generateCommand(const OUString& sFamily, const OUString& sStyle)
      88             : {
      89           0 :     OUStringBuffer sCommand(1024);
      90           0 :     sCommand.append(CMDURL_SPART );
      91           0 :     sCommand.append(sStyle       );
      92           0 :     sCommand.append(CMDURL_FPART2);
      93           0 :     sCommand.append(sFamily      );
      94           0 :     return sCommand.makeStringAndClear();
      95             : }
      96             : 
      97           0 : bool SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl& aStyle)
      98             : {
      99             :     static const sal_Int32 LEN_STYLEPROT = strlen(CMDURL_STYLEPROT_ONLY);
     100             :     static const sal_Int32 LEN_SPART     = strlen(CMDURL_SPART_ONLY);
     101             :     static const sal_Int32 LEN_FPART     = strlen(CMDURL_FPART_ONLY);
     102             : 
     103           0 :     if (!aStyle.sCommand.startsWith(CMDURL_STYLEPROT_ONLY))
     104           0 :         return false;
     105             : 
     106           0 :     aStyle.sFamily.clear();
     107           0 :     aStyle.sStyle.clear();
     108             : 
     109           0 :     sal_Int32       nCmdLen  = aStyle.sCommand.getLength();
     110           0 :     OUString sCmdArgs = aStyle.sCommand.copy(LEN_STYLEPROT, nCmdLen-LEN_STYLEPROT);
     111           0 :     sal_Int32       i        = sCmdArgs.indexOf('&');
     112           0 :     if (i<0)
     113           0 :         return false;
     114             : 
     115           0 :     OUString sArg = sCmdArgs.copy(0, i);
     116           0 :     if (sArg.startsWith(CMDURL_SPART_ONLY))
     117           0 :         aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
     118           0 :     else if (sArg.startsWith(CMDURL_FPART_ONLY))
     119           0 :         aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
     120             : 
     121           0 :     sArg = sCmdArgs.copy(i+1, sCmdArgs.getLength()-i-1);
     122           0 :     if (sArg.startsWith(CMDURL_SPART_ONLY))
     123           0 :         aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
     124           0 :     else if (sArg.startsWith(CMDURL_FPART_ONLY))
     125           0 :         aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
     126             : 
     127           0 :     if (!(aStyle.sFamily.isEmpty() || aStyle.sStyle.isEmpty()))
     128           0 :         return true;
     129             : 
     130           0 :     return false;
     131             : }
     132             : 
     133           0 : void SfxStylesInfo_Impl::getLabel4Style(SfxStyleInfo_Impl& aStyle)
     134             : {
     135             :     try
     136             :     {
     137           0 :         css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
     138             : 
     139           0 :         css::uno::Reference< css::container::XNameAccess > xFamilies;
     140           0 :         if (xModel.is())
     141           0 :             xFamilies = xModel->getStyleFamilies();
     142             : 
     143           0 :         css::uno::Reference< css::container::XNameAccess > xStyleSet;
     144           0 :         if (xFamilies.is())
     145           0 :             xFamilies->getByName(aStyle.sFamily) >>= xStyleSet;
     146             : 
     147           0 :         css::uno::Reference< css::beans::XPropertySet > xStyle;
     148           0 :         if (xStyleSet.is())
     149           0 :             xStyleSet->getByName(aStyle.sStyle) >>= xStyle;
     150             : 
     151           0 :         aStyle.sLabel.clear();
     152           0 :         if (xStyle.is())
     153           0 :             xStyle->getPropertyValue(STYLEPROP_UINAME) >>= aStyle.sLabel;
     154             :     }
     155           0 :     catch(const css::uno::RuntimeException&)
     156           0 :         { throw; }
     157           0 :     catch(const css::uno::Exception&)
     158           0 :         { aStyle.sLabel.clear(); }
     159             : 
     160           0 :     if (aStyle.sLabel.isEmpty())
     161             :     {
     162           0 :         aStyle.sLabel = aStyle.sCommand;
     163             :     }
     164           0 : }
     165             : 
     166           0 : ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyleFamilies()
     167             : {
     168             :     // Its an optional interface!
     169           0 :     css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY);
     170           0 :     if (!xModel.is())
     171           0 :         return ::std::vector< SfxStyleInfo_Impl >();
     172             : 
     173           0 :     css::uno::Reference< css::container::XNameAccess > xCont = xModel->getStyleFamilies();
     174           0 :     css::uno::Sequence< OUString > lFamilyNames = xCont->getElementNames();
     175           0 :     ::std::vector< SfxStyleInfo_Impl > lFamilies;
     176           0 :     sal_Int32 c = lFamilyNames.getLength();
     177           0 :     sal_Int32 i = 0;
     178           0 :     for(i=0; i<c; ++i)
     179             :     {
     180           0 :         SfxStyleInfo_Impl aFamilyInfo;
     181           0 :         aFamilyInfo.sFamily = lFamilyNames[i];
     182             : 
     183             :         try
     184             :         {
     185           0 :             css::uno::Reference< css::beans::XPropertySet > xFamilyInfo;
     186           0 :             xCont->getByName(aFamilyInfo.sFamily) >>= xFamilyInfo;
     187           0 :             if (!xFamilyInfo.is())
     188             :             {
     189             :                 // TODO_AS currently there is no support for an UIName property .. use internal family name instead
     190           0 :                 aFamilyInfo.sLabel = aFamilyInfo.sFamily;
     191             :             }
     192             :             else
     193           0 :                 xFamilyInfo->getPropertyValue(STYLEPROP_UINAME) >>= aFamilyInfo.sLabel;
     194             :         }
     195           0 :         catch(const css::uno::RuntimeException&)
     196           0 :             { throw; }
     197           0 :         catch(const css::uno::Exception&)
     198           0 :             { return ::std::vector< SfxStyleInfo_Impl >(); }
     199             : 
     200           0 :         lFamilies.push_back(aFamilyInfo);
     201           0 :     }
     202             : 
     203           0 :     return lFamilies;
     204             : }
     205             : 
     206           0 : ::std::vector< SfxStyleInfo_Impl > SfxStylesInfo_Impl::getStyles(const OUString& sFamily)
     207             : {
     208             :     static const char PROP_UINAME[] = "DisplayName";
     209             : 
     210           0 :     css::uno::Sequence< OUString > lStyleNames;
     211           0 :     css::uno::Reference< css::style::XStyleFamiliesSupplier > xModel(m_xDoc, css::uno::UNO_QUERY_THROW);
     212           0 :     css::uno::Reference< css::container::XNameAccess > xFamilies = xModel->getStyleFamilies();
     213           0 :     css::uno::Reference< css::container::XNameAccess > xStyleSet;
     214             :     try
     215             :     {
     216           0 :         xFamilies->getByName(sFamily) >>= xStyleSet;
     217           0 :         lStyleNames = xStyleSet->getElementNames();
     218             :     }
     219           0 :     catch(const css::uno::RuntimeException&)
     220           0 :         { throw; }
     221           0 :     catch(const css::uno::Exception&)
     222           0 :         { return ::std::vector< SfxStyleInfo_Impl >(); }
     223             : 
     224           0 :     ::std::vector< SfxStyleInfo_Impl > lStyles;
     225           0 :     sal_Int32                          c      = lStyleNames.getLength();
     226           0 :     sal_Int32                          i      = 0;
     227           0 :     for (i=0; i<c; ++i)
     228             :     {
     229           0 :         SfxStyleInfo_Impl aStyleInfo;
     230           0 :         aStyleInfo.sFamily  = sFamily;
     231           0 :         aStyleInfo.sStyle   = lStyleNames[i];
     232           0 :         aStyleInfo.sCommand = SfxStylesInfo_Impl::generateCommand(aStyleInfo.sFamily, aStyleInfo.sStyle);
     233             : 
     234             :         try
     235             :         {
     236           0 :             css::uno::Reference< css::beans::XPropertySet > xStyle;
     237           0 :             xStyleSet->getByName(aStyleInfo.sStyle) >>= xStyle;
     238           0 :             if (!xStyle.is())
     239           0 :                 continue;
     240           0 :             xStyle->getPropertyValue(PROP_UINAME) >>= aStyleInfo.sLabel;
     241             :         }
     242           0 :         catch(const css::uno::RuntimeException&)
     243           0 :             { throw; }
     244           0 :         catch(const css::uno::Exception&)
     245           0 :             { continue; }
     246             : 
     247           0 :         lStyles.push_back(aStyleInfo);
     248           0 :     }
     249           0 :     return lStyles;
     250             : }
     251             : 
     252           0 : SfxConfigFunctionListBox::SfxConfigFunctionListBox(vcl::Window* pParent, WinBits nStyle)
     253             :     : SvTreeListBox( pParent, nStyle )
     254             :     , pCurEntry( 0 )
     255           0 :     , pStylesInfo( 0 )
     256             : {
     257           0 :     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
     258           0 :     GetModel()->SetSortMode( SortAscending );
     259           0 : }
     260             : 
     261           0 : VCL_BUILDER_DECL_FACTORY(SfxConfigFunctionListBox)
     262             : {
     263           0 :     WinBits nWinBits = WB_TABSTOP;
     264             : 
     265           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
     266           0 :     if (!sBorder.isEmpty())
     267           0 :        nWinBits |= WB_BORDER;
     268             : 
     269           0 :     rRet = VclPtr<SfxConfigFunctionListBox>::Create(pParent, nWinBits);
     270           0 : }
     271             : 
     272           0 : SfxConfigFunctionListBox::~SfxConfigFunctionListBox()
     273             : {
     274           0 :     disposeOnce();
     275           0 : }
     276             : 
     277           0 : void SfxConfigFunctionListBox::dispose()
     278             : {
     279           0 :     ClearAll();
     280           0 :     SvTreeListBox::dispose();
     281           0 : }
     282             : 
     283           0 : void SfxConfigFunctionListBox::MouseMove( const MouseEvent& )
     284             : {
     285           0 : }
     286             : 
     287           0 : void SfxConfigFunctionListBox::ClearAll()
     288             : /*  Description
     289             :     Deletes all entries in the FunctionListBox, all UserData and all
     290             :     possibly existing MacroInfo.
     291             : */
     292             : {
     293           0 :     sal_uInt16 nCount = aArr.size();
     294           0 :     for ( sal_uInt16 i=0; i<nCount; ++i )
     295             :     {
     296           0 :         SfxGroupInfo_Impl *pData = &aArr[i];
     297             : 
     298           0 :         if ( pData->nKind == SFX_CFGFUNCTION_SCRIPT )
     299             :         {
     300           0 :             OUString* pScriptURI = static_cast<OUString*>(pData->pObject);
     301           0 :             delete pScriptURI;
     302             :         }
     303             : 
     304           0 :         if ( pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER )
     305             :         {
     306           0 :             XInterface* xi = static_cast<XInterface *>(pData->pObject);
     307           0 :             if (xi != NULL)
     308             :             {
     309           0 :                 xi->release();
     310             :             }
     311             :         }
     312             :     }
     313             : 
     314           0 :     aArr.clear();
     315           0 :     Clear();
     316           0 : }
     317             : 
     318           0 : OUString SfxConfigFunctionListBox::GetSelectedScriptURI()
     319             : {
     320           0 :     SvTreeListEntry *pEntry = FirstSelected();
     321           0 :     if ( pEntry )
     322             :     {
     323           0 :         SfxGroupInfo_Impl *pData = static_cast<SfxGroupInfo_Impl*>(pEntry->GetUserData());
     324           0 :         if ( pData && ( pData->nKind == SFX_CFGFUNCTION_SCRIPT ) )
     325           0 :             return *static_cast<OUString*>(pData->pObject);
     326             :     }
     327           0 :     return OUString();
     328             : }
     329             : 
     330           0 : OUString SfxConfigFunctionListBox::GetCurCommand()
     331             : {
     332           0 :     SvTreeListEntry *pEntry = FirstSelected();
     333           0 :     if (!pEntry)
     334           0 :         return OUString();
     335           0 :     SfxGroupInfo_Impl *pData = static_cast<SfxGroupInfo_Impl*>(pEntry->GetUserData());
     336           0 :     if (!pData)
     337           0 :         return OUString();
     338           0 :     return pData->sCommand;
     339             : }
     340             : 
     341           0 : OUString SfxConfigFunctionListBox::GetCurLabel()
     342             : {
     343           0 :     SvTreeListEntry *pEntry = FirstSelected();
     344           0 :     if (!pEntry)
     345           0 :         return OUString();
     346           0 :     SfxGroupInfo_Impl *pData = static_cast<SfxGroupInfo_Impl*>(pEntry->GetUserData());
     347           0 :     if (!pData)
     348           0 :         return OUString();
     349           0 :     if (!pData->sLabel.isEmpty())
     350           0 :         return pData->sLabel;
     351           0 :     return pData->sCommand;
     352             : }
     353             : 
     354           0 : void SfxConfigFunctionListBox::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
     355             : {
     356           0 :     pStylesInfo = pStyles;
     357           0 : }
     358             : 
     359             : struct SvxConfigGroupBoxResource_Impl : public Resource
     360             : {
     361             :     Image m_hdImage;
     362             :     Image m_libImage;
     363             :     Image m_macImage;
     364             :     Image m_docImage;
     365             :     OUString m_sMyMacros;
     366             :     OUString m_sProdMacros;
     367             :     OUString m_sMacros;
     368             :     OUString m_sDlgMacros;
     369             :     OUString m_aHumanAppName;
     370             :     OUString m_aStrGroupStyles;
     371             :     Image m_collapsedImage;
     372             :     Image m_expandedImage;
     373             : 
     374             :     SvxConfigGroupBoxResource_Impl();
     375             : };
     376             : 
     377           0 : SvxConfigGroupBoxResource_Impl::SvxConfigGroupBoxResource_Impl() :
     378           0 :     Resource(CUI_RES(RID_SVXPAGE_CONFIGGROUPBOX)),
     379           0 :     m_hdImage(CUI_RES(RID_CUIIMG_HARDDISK)),
     380           0 :     m_libImage(CUI_RES(RID_CUIIMG_LIB)),
     381           0 :     m_macImage(CUI_RES(RID_CUIIMG_MACRO)),
     382           0 :     m_docImage(CUI_RES(RID_CUIIMG_DOC)),
     383           0 :     m_sMyMacros(CUI_RESSTR(RID_SVXSTR_MYMACROS)),
     384           0 :     m_sProdMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS)),
     385           0 :     m_sMacros(CUI_RESSTR(STR_BASICMACROS)),
     386           0 :     m_sDlgMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS)),
     387           0 :     m_aHumanAppName(CUI_RESSTR(STR_HUMAN_APPNAME)),
     388           0 :     m_aStrGroupStyles(CUI_RESSTR(STR_GROUP_STYLES)),
     389           0 :     m_collapsedImage(CUI_RES(BMP_COLLAPSED)),
     390           0 :     m_expandedImage(CUI_RES(BMP_EXPANDED))
     391             : {
     392           0 :     FreeResource();
     393           0 : }
     394             : 
     395           0 : SfxConfigGroupListBox::SfxConfigGroupListBox(vcl::Window* pParent, WinBits nStyle)
     396             :     : SvTreeListBox(pParent, nStyle)
     397           0 :     , pImp(new SvxConfigGroupBoxResource_Impl()), pFunctionListBox(0), pStylesInfo(0)
     398             : {
     399           0 :     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT );
     400           0 :     SetNodeBitmaps( pImp->m_collapsedImage, pImp->m_expandedImage );
     401           0 : }
     402             : 
     403           0 : VCL_BUILDER_DECL_FACTORY(SfxConfigGroupListBox)
     404             : {
     405           0 :     WinBits nWinBits = WB_TABSTOP;
     406             : 
     407           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
     408           0 :     if (!sBorder.isEmpty())
     409           0 :        nWinBits |= WB_BORDER;
     410             : 
     411           0 :     rRet = VclPtr<SfxConfigGroupListBox>::Create(pParent, nWinBits);
     412           0 : }
     413             : 
     414           0 : SfxConfigGroupListBox::~SfxConfigGroupListBox()
     415             : {
     416           0 :     disposeOnce();
     417           0 : }
     418             : 
     419           0 : void SfxConfigGroupListBox::dispose()
     420             : {
     421           0 :     ClearAll();
     422           0 :     pFunctionListBox.clear();
     423           0 :     SvTreeListBox::dispose();
     424           0 : }
     425             : 
     426           0 : void SfxConfigGroupListBox::ClearAll()
     427             : {
     428           0 :     sal_uInt16 nCount = aArr.size();
     429           0 :     for ( sal_uInt16 i=0; i<nCount; ++i )
     430             :     {
     431           0 :         SfxGroupInfo_Impl *pData = &aArr[i];
     432           0 :         if (pData->nKind == SFX_CFGGROUP_SCRIPTCONTAINER)
     433             :         {
     434           0 :             XInterface* xi = static_cast<XInterface *>(pData->pObject);
     435           0 :             if (xi != NULL)
     436             :             {
     437           0 :                 xi->release();
     438             :             }
     439             :         }
     440             :     }
     441             : 
     442           0 :     aArr.clear();
     443           0 :     Clear();
     444           0 : }
     445             : 
     446           0 : void SfxConfigGroupListBox::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
     447             : {
     448           0 :     pStylesInfo = pStyles;
     449           0 : }
     450             : 
     451             : 
     452           0 : void SfxConfigGroupListBox::InitModule()
     453             : {
     454             :     try
     455             :     {
     456           0 :         css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider(m_xFrame, css::uno::UNO_QUERY_THROW);
     457           0 :         css::uno::Sequence< sal_Int16 > lGroups = xProvider->getSupportedCommandGroups();
     458           0 :         sal_Int32                       c1      = lGroups.getLength();
     459           0 :         sal_Int32                       i1      = 0;
     460             : 
     461           0 :         for (i1=0; i1<c1; ++i1)
     462             :         {
     463           0 :             sal_Int16&      rGroupID   = lGroups[i1];
     464           0 :             OUString sGroupID   = OUString::number(rGroupID);
     465           0 :             OUString sGroupName ;
     466             : 
     467             :             try
     468             :             {
     469           0 :                 m_xModuleCategoryInfo->getByName(sGroupID) >>= sGroupName;
     470           0 :                 if (sGroupName.isEmpty())
     471           0 :                     continue;
     472             :             }
     473           0 :             catch(const css::container::NoSuchElementException&)
     474           0 :                 { continue; }
     475             : 
     476           0 :             SvTreeListEntry*        pEntry = InsertEntry(sGroupName, NULL);
     477           0 :             SfxGroupInfo_Impl* pInfo   = new SfxGroupInfo_Impl(SFX_CFGGROUP_FUNCTION, rGroupID);
     478           0 :             pEntry->SetUserData(pInfo);
     479           0 :         }
     480             :     }
     481           0 :     catch(const css::uno::RuntimeException&)
     482           0 :         { throw; }
     483           0 :     catch(const css::uno::Exception&)
     484             :         {}
     485           0 : }
     486             : 
     487             : 
     488             : namespace
     489             : {
     490             : 
     491             :     /** examines a component whether it supports XEmbeddedScripts, or provides access to such a
     492             :         component by implementing XScriptInvocationContext.
     493             :         @return
     494             :             the model which supports the embedded scripts, or <NULL/> if it cannot find such a
     495             :             model
     496             :     */
     497           0 :     static Reference< XModel > lcl_getDocumentWithScripts_throw( const Reference< XInterface >& _rxComponent )
     498             :     {
     499           0 :         Reference< XEmbeddedScripts > xScripts( _rxComponent, UNO_QUERY );
     500           0 :         if ( !xScripts.is() )
     501             :         {
     502           0 :             Reference< XScriptInvocationContext > xContext( _rxComponent, UNO_QUERY );
     503           0 :             if ( xContext.is() )
     504           0 :                 xScripts.set( xContext->getScriptContainer(), UNO_QUERY );
     505             :         }
     506             : 
     507           0 :         return Reference< XModel >( xScripts, UNO_QUERY );
     508             :     }
     509             : 
     510             : 
     511           0 :     static Reference< XModel > lcl_getScriptableDocument_nothrow( const Reference< XFrame >& _rxFrame )
     512             :     {
     513           0 :         Reference< XModel > xDocument;
     514             : 
     515             :         // examine our associated frame
     516             :         try
     517             :         {
     518             :             OSL_ENSURE( _rxFrame.is(), "lcl_getScriptableDocument_nothrow: you need to pass a frame to this dialog/tab page!" );
     519           0 :             if ( _rxFrame.is() )
     520             :             {
     521             :                 // first try the model in the frame
     522           0 :                 Reference< XController > xController( _rxFrame->getController(), UNO_SET_THROW );
     523           0 :                 xDocument = lcl_getDocumentWithScripts_throw( xController->getModel() );
     524             : 
     525           0 :                 if ( !xDocument.is() )
     526             :                 {
     527             :                     // if there is no suitable document in the frame, try the controller
     528           0 :                     xDocument = lcl_getDocumentWithScripts_throw( _rxFrame->getController() );
     529           0 :                 }
     530             :             }
     531             :         }
     532           0 :         catch( const Exception& )
     533             :         {
     534             :         }
     535             : 
     536           0 :         return xDocument;
     537             :     }
     538             : }
     539             : 
     540             : 
     541           0 : void SfxConfigGroupListBox::Init(const css::uno::Reference< css::uno::XComponentContext >& xContext,
     542             :     const css::uno::Reference< css::frame::XFrame >& xFrame,
     543             :     const OUString& sModuleLongName,
     544             :     bool bEventMode)
     545             : {
     546           0 :     SetUpdateMode(false);
     547           0 :     ClearAll(); // Remove all old entries from treelist box
     548             : 
     549           0 :     m_xFrame = xFrame;
     550           0 :     if( xContext.is() )
     551             :     {
     552           0 :         m_xContext        = xContext;
     553           0 :         m_sModuleLongName = sModuleLongName;
     554             : 
     555           0 :         m_xGlobalCategoryInfo = css::ui::theUICategoryDescription::get( m_xContext );
     556           0 :         m_xModuleCategoryInfo = css::uno::Reference< css::container::XNameAccess >(m_xGlobalCategoryInfo->getByName(m_sModuleLongName), css::uno::UNO_QUERY_THROW);
     557           0 :         m_xUICmdDescription   = css::frame::theUICommandDescription::get( m_xContext );
     558             : 
     559           0 :         InitModule();
     560             :     }
     561             : 
     562             :     SAL_INFO("cui.customize", "** ** About to initialise SF Scripts");
     563             :     // Add Scripting Framework entries
     564           0 :     Reference< browse::XBrowseNode > rootNode;
     565             :     Reference< XComponentContext > xCtx(
     566           0 :         comphelper::getProcessComponentContext() );
     567             :     try
     568             :     {
     569           0 :         Reference< browse::XBrowseNodeFactory > xFac = browse::theBrowseNodeFactory::get( xCtx );
     570           0 :         rootNode.set( xFac->createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) );
     571             :     }
     572           0 :     catch( Exception& e )
     573             :     {
     574             :         SAL_INFO("cui.customize", "Caught some exception whilst retrieving browse nodes from factory... Exception: " << e.Message);
     575             :         // TODO exception handling
     576             :     }
     577             : 
     578             : 
     579           0 :     if ( rootNode.is() )
     580             :     {
     581           0 :         if ( bEventMode )
     582             :         {
     583             :                 //We call acquire on the XBrowseNode so that it does not
     584             :                 //get autodestructed and become invalid when accessed later.
     585           0 :             rootNode->acquire();
     586             : 
     587             :             SfxGroupInfo_Impl *pInfo =
     588             :                 new SfxGroupInfo_Impl( SFX_CFGGROUP_SCRIPTCONTAINER, 0,
     589           0 :                     static_cast<void *>(rootNode.get()));
     590             : 
     591           0 :             OUString aTitle(pImp->m_sDlgMacros);
     592           0 :             SvTreeListEntry *pNewEntry = InsertEntry( aTitle, NULL );
     593           0 :             pNewEntry->SetUserData( pInfo );
     594           0 :             pNewEntry->EnableChildrenOnDemand( true );
     595           0 :             aArr.push_back( pInfo );
     596             :         }
     597             :         else
     598             :         {
     599             :              //We are only showing scripts not slot APIs so skip
     600             :              //Root node and show location nodes
     601             :             try {
     602           0 :                 if ( rootNode->hasChildNodes() )
     603             :                 {
     604             :                     Sequence< Reference< browse::XBrowseNode > > children =
     605           0 :                         rootNode->getChildNodes();
     606           0 :                     bool bIsRootNode = false;
     607             : 
     608           0 :                     OUString user("user");
     609           0 :                     OUString share("share");
     610           0 :                     if ( rootNode->getName() == "Root" )
     611             :                     {
     612           0 :                         bIsRootNode = true;
     613             :                     }
     614             : 
     615             :                     //To mimic current starbasic behaviour we
     616             :                     //need to make sure that only the current document
     617             :                     //is displayed in the config tree. Tests below
     618             :                     //set the bDisplay flag to FALSE if the current
     619             :                     //node is a first level child of the Root and is NOT
     620             :                     //either the current document, user or share
     621           0 :                     OUString currentDocTitle;
     622           0 :                     Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
     623           0 :                     if ( xDocument.is() )
     624             :                     {
     625           0 :                         currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
     626             :                     }
     627             : 
     628           0 :                     for ( sal_Int32 n = 0; n < children.getLength(); ++n )
     629             :                     {
     630           0 :                         Reference< browse::XBrowseNode >& theChild = children[n];
     631           0 :                         bool bDisplay = true;
     632           0 :                         OUString uiName = theChild->getName();
     633           0 :                         if ( bIsRootNode )
     634             :                         {
     635           0 :                             if (  ! ((theChild->getName().equals( user )  || theChild->getName().equals( share ) ||
     636           0 :                                 theChild->getName().equals( currentDocTitle ) ) ) )
     637             :                             {
     638           0 :                                 bDisplay=false;
     639             :                             }
     640             :                             else
     641             :                             {
     642           0 :                                 if ( uiName.equals( user ) )
     643             :                                 {
     644           0 :                                     uiName = pImp->m_sMyMacros;
     645             :                                 }
     646           0 :                                 else if ( uiName.equals( share ) )
     647             :                                 {
     648           0 :                                     uiName = pImp->m_sProdMacros;
     649             :                                 }
     650             :                             }
     651             :                         }
     652           0 :                         if (children[n]->getType() != browse::BrowseNodeTypes::SCRIPT  && bDisplay )
     653             :                         {
     654             : //                              We call acquire on the XBrowseNode so that it does not
     655             : //                              get autodestructed and become invalid when accessed later.
     656           0 :                             theChild->acquire();
     657             : 
     658             :                             SfxGroupInfo_Impl* pInfo =
     659             :                                 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
     660           0 :                                     0, static_cast<void *>( theChild.get()));
     661             : 
     662           0 :                             Image aImage = GetImage( theChild, xCtx, bIsRootNode );
     663             :                             SvTreeListEntry* pNewEntry =
     664           0 :                                 InsertEntry( uiName, NULL);
     665           0 :                             SetExpandedEntryBmp(  pNewEntry, aImage );
     666           0 :                             SetCollapsedEntryBmp( pNewEntry, aImage );
     667             : 
     668           0 :                             pNewEntry->SetUserData( pInfo );
     669           0 :                             aArr.push_back( pInfo );
     670             : 
     671           0 :                             if ( children[n]->hasChildNodes() )
     672             :                             {
     673             :                                 Sequence< Reference< browse::XBrowseNode > > grandchildren =
     674           0 :                                     children[n]->getChildNodes();
     675             : 
     676           0 :                                 for ( sal_Int32 m = 0; m < grandchildren.getLength(); ++m )
     677             :                                 {
     678           0 :                                     if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
     679             :                                     {
     680           0 :                                         pNewEntry->EnableChildrenOnDemand( true );
     681           0 :                                         m = grandchildren.getLength();
     682             :                                     }
     683           0 :                                 }
     684           0 :                             }
     685             :                         }
     686           0 :                     }
     687             :                 }
     688             :             }
     689           0 :             catch (RuntimeException&) {
     690             :                 // do nothing, the entry will not be displayed in the UI
     691             :             }
     692             :         }
     693             :     }
     694             : 
     695             :     // add styles
     696           0 :     if ( m_xContext.is() )
     697             :     {
     698           0 :         OUString sStyle( pImp->m_aStrGroupStyles );
     699           0 :         SvTreeListEntry *pEntry = InsertEntry( sStyle, 0 );
     700           0 :         SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, 0 ); // TODO last parameter should contain user data
     701           0 :         aArr.push_back( pInfo );
     702           0 :         pEntry->SetUserData( pInfo );
     703           0 :         pEntry->EnableChildrenOnDemand( true );
     704             :     }
     705             : 
     706           0 :     MakeVisible( GetEntry( 0,0 ) );
     707           0 :     SetUpdateMode( true );
     708           0 : }
     709             : 
     710           0 : Image SfxConfigGroupListBox::GetImage(
     711             :     Reference< browse::XBrowseNode > node,
     712             :     Reference< XComponentContext > xCtx,
     713             :     bool bIsRootNode
     714             : )
     715             : {
     716           0 :     Image aImage;
     717           0 :     if ( bIsRootNode )
     718             :     {
     719           0 :         OUString user("user");
     720           0 :         OUString share("share");
     721           0 :         if (node->getName().equals( user ) || node->getName().equals(share ) )
     722             :         {
     723           0 :             aImage = pImp->m_hdImage;
     724             :         }
     725             :         else
     726             :         {
     727           0 :             OUString factoryURL;
     728           0 :             OUString nodeName = node->getName();
     729           0 :             Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
     730           0 :             if ( xDocumentModel.is() )
     731             :             {
     732           0 :                 Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xCtx) );
     733             :                 // get the long name of the document:
     734           0 :                 OUString appModule( xModuleManager->identify(
     735           0 :                                     xDocumentModel ) );
     736           0 :                 Sequence<beans::PropertyValue> moduleDescr;
     737           0 :                 Any aAny = xModuleManager->getByName(appModule);
     738           0 :                 if( !( aAny >>= moduleDescr ) )
     739             :                 {
     740           0 :                     throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue");
     741             :                 }
     742             :                 beans::PropertyValue const * pmoduleDescr =
     743           0 :                     moduleDescr.getConstArray();
     744           0 :                 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
     745             :                 {
     746           0 :                     if ( pmoduleDescr[ pos ].Name == "ooSetupFactoryEmptyDocumentURL" )
     747             :                     {
     748           0 :                         pmoduleDescr[ pos ].Value >>= factoryURL;
     749             :                         SAL_INFO("cui.customize", "factory url for doc images is " << factoryURL);
     750           0 :                         break;
     751             :                     }
     752           0 :                 }
     753             :             }
     754           0 :             if( !factoryURL.isEmpty() )
     755             :             {
     756           0 :                 aImage = SvFileInformationManager::GetFileImage( INetURLObject(factoryURL), false );
     757             :             }
     758             :             else
     759             :             {
     760           0 :                 aImage = pImp->m_docImage;
     761           0 :             }
     762           0 :         }
     763             :     }
     764             :     else
     765             :     {
     766           0 :         if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
     767           0 :             aImage = pImp->m_macImage;
     768             :         else
     769           0 :             aImage = pImp->m_libImage;
     770             :     }
     771           0 :     return aImage;
     772             : }
     773             : 
     774             : Reference< XInterface  >
     775           0 : SfxConfigGroupListBox::getDocumentModel( Reference< XComponentContext >& xCtx, OUString& docName )
     776             : {
     777           0 :     Reference< XInterface > xModel;
     778           0 :     Reference< frame::XDesktop2 > desktop = frame::Desktop::create( xCtx );
     779             : 
     780             :     Reference< container::XEnumerationAccess > componentsAccess =
     781           0 :         desktop->getComponents();
     782             :     Reference< container::XEnumeration > components =
     783           0 :         componentsAccess->createEnumeration();
     784           0 :     while (components->hasMoreElements())
     785             :     {
     786             :         Reference< frame::XModel > model(
     787           0 :             components->nextElement(), UNO_QUERY );
     788           0 :         if ( model.is() )
     789             :         {
     790             :             OUString sTdocUrl =
     791           0 :                 ::comphelper::DocumentInfo::getDocumentTitle( model );
     792           0 :             if( sTdocUrl.equals( docName ) )
     793             :             {
     794           0 :                 xModel = model;
     795           0 :                 break;
     796           0 :             }
     797             :         }
     798           0 :     }
     799           0 :     return xModel;
     800             : }
     801             : 
     802             : 
     803           0 : OUString SfxConfigGroupListBox::MapCommand2UIName(const OUString& sCommand)
     804             : {
     805           0 :     OUString sUIName;
     806             :     try
     807             :     {
     808           0 :         css::uno::Reference< css::container::XNameAccess > xModuleConf;
     809           0 :         m_xUICmdDescription->getByName(m_sModuleLongName) >>= xModuleConf;
     810           0 :         if (xModuleConf.is())
     811             :         {
     812           0 :             ::comphelper::SequenceAsHashMap lProps(xModuleConf->getByName(sCommand));
     813           0 :             sUIName = lProps.getUnpackedValueOrDefault("Name", OUString());
     814           0 :         }
     815             :     }
     816           0 :     catch(const css::uno::RuntimeException&)
     817           0 :         { throw; }
     818           0 :     catch(css::uno::Exception&)
     819           0 :         { sUIName.clear(); }
     820             : 
     821             :     // fallback for missing UINames !?
     822           0 :     if (sUIName.isEmpty())
     823             :     {
     824           0 :         sUIName = sCommand;
     825             :     }
     826             : 
     827           0 :     return sUIName;
     828             : }
     829             : 
     830             : 
     831           0 : void SfxConfigGroupListBox::GroupSelected()
     832             : /*  Description
     833             :     A function group or a basic module has been selected.
     834             :     All functions/macros are displayed in the functionlistbox.
     835             : */
     836             : {
     837           0 :     SvTreeListEntry *pEntry = FirstSelected();
     838           0 :     SfxGroupInfo_Impl *pInfo = static_cast<SfxGroupInfo_Impl*>(pEntry->GetUserData());
     839           0 :     pFunctionListBox->SetUpdateMode(false);
     840           0 :     pFunctionListBox->ClearAll();
     841           0 :     if ( pInfo->nKind != SFX_CFGGROUP_FUNCTION &&
     842           0 :              pInfo->nKind != SFX_CFGGROUP_SCRIPTCONTAINER &&
     843           0 :              pInfo->nKind != SFX_CFGGROUP_STYLES )
     844             :     {
     845           0 :         pFunctionListBox->SetUpdateMode(true);
     846           0 :         return;
     847             :     }
     848             : 
     849           0 :     switch ( pInfo->nKind )
     850             :     {
     851             :         case SFX_CFGGROUP_FUNCTION :
     852             :         {
     853           0 :             sal_uInt16                                                          nGroup    = pInfo->nUniqueID;
     854           0 :             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider (m_xFrame, css::uno::UNO_QUERY_THROW);
     855           0 :             css::uno::Sequence< css::frame::DispatchInformation >           lCommands = xProvider->getConfigurableDispatchInformation(nGroup);
     856           0 :             sal_Int32                                                       c         = lCommands.getLength();
     857           0 :             sal_Int32                                                       i         = 0;
     858             : 
     859           0 :             for (i=0; i<c; ++i)
     860             :             {
     861           0 :                 const css::frame::DispatchInformation& rInfo      = lCommands[i];
     862           0 :                 OUString                        sUIName    = MapCommand2UIName(rInfo.Command);
     863           0 :                 SvTreeListEntry*                           pFuncEntry = pFunctionListBox->InsertEntry(sUIName, NULL);
     864           0 :                 SfxGroupInfo_Impl*                     pGrpInfo   = new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SLOT, 0);
     865           0 :                 pGrpInfo->sCommand = rInfo.Command;
     866           0 :                 pGrpInfo->sLabel   = sUIName;
     867           0 :                 pFuncEntry->SetUserData(pGrpInfo);
     868           0 :             }
     869             : 
     870           0 :             break;
     871             :         }
     872             : 
     873             :         case SFX_CFGGROUP_SCRIPTCONTAINER:
     874             :         {
     875           0 :             if ( !GetChildCount( pEntry ) )
     876             :             {
     877             :                 Reference< browse::XBrowseNode > rootNode(
     878           0 :                     static_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
     879             : 
     880             :                 try {
     881           0 :                     if ( rootNode->hasChildNodes() )
     882             :                     {
     883             :                         Sequence< Reference< browse::XBrowseNode > > children =
     884           0 :                             rootNode->getChildNodes();
     885             : 
     886           0 :                         for ( sal_Int32 n = 0; n < children.getLength(); ++n )
     887             :                         {
     888           0 :                             if (children[n]->getType() == browse::BrowseNodeTypes::SCRIPT)
     889             :                             {
     890           0 :                                 OUString uri;
     891             : 
     892           0 :                                 Reference < beans::XPropertySet >xPropSet( children[n], UNO_QUERY );
     893           0 :                                 if (!xPropSet.is())
     894             :                                 {
     895           0 :                                     continue;
     896             :                                 }
     897             : 
     898             :                                 Any value =
     899           0 :                                     xPropSet->getPropertyValue("URI");
     900           0 :                                 value >>= uri;
     901             : 
     902           0 :                                 OUString* pScriptURI = new OUString( uri );
     903           0 :                                 SfxGroupInfo_Impl* pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGFUNCTION_SCRIPT, 0, pScriptURI );
     904             : 
     905           0 :                                 Image aImage = GetImage( children[n], Reference< XComponentContext >(), false );
     906             :                                 SvTreeListEntry* pNewEntry =
     907           0 :                                     pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
     908           0 :                                 pFunctionListBox->SetExpandedEntryBmp( pNewEntry, aImage );
     909           0 :                                 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage );
     910             : 
     911           0 :                                 pGrpInfo->sCommand = uri;
     912           0 :                                 pGrpInfo->sLabel = children[n]->getName();
     913           0 :                                 pNewEntry->SetUserData( pGrpInfo );
     914             : 
     915           0 :                                 pFunctionListBox->aArr.push_back( pGrpInfo );
     916             : 
     917             :                             }
     918           0 :                         }
     919             :                     }
     920             :                 }
     921           0 :                 catch (RuntimeException&) {
     922             :                     // do nothing, the entry will not be displayed in the UI
     923           0 :                 }
     924             :             }
     925           0 :             break;
     926             :         }
     927             : 
     928             :         case SFX_CFGGROUP_STYLES :
     929             :         {
     930           0 :             SfxStyleInfo_Impl* pFamily = static_cast<SfxStyleInfo_Impl*>(pInfo->pObject);
     931           0 :             if (pFamily)
     932             :             {
     933           0 :                 const ::std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pFamily->sFamily);
     934           0 :                 ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
     935           0 :                 for (  pIt  = lStyles.begin();
     936           0 :                        pIt != lStyles.end()  ;
     937             :                      ++pIt                   )
     938             :                 {
     939           0 :                     SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(*pIt);
     940           0 :                     SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry( pStyle->sLabel, NULL );
     941           0 :                     SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pStyle );
     942           0 :                     pFunctionListBox->aArr.push_back( pGrpInfo );
     943           0 :                     pGrpInfo->sCommand = pStyle->sCommand;
     944           0 :                     pGrpInfo->sLabel = pStyle->sLabel;
     945           0 :                     pFuncEntry->SetUserData( pGrpInfo );
     946           0 :                 }
     947             :             }
     948           0 :             break;
     949             :         }
     950             : 
     951             :         default:
     952           0 :             return;
     953             :     }
     954             : 
     955           0 :     if ( pFunctionListBox->GetEntryCount() )
     956           0 :         pFunctionListBox->Select( pFunctionListBox->GetEntry( 0, 0 ) );
     957             : 
     958           0 :     pFunctionListBox->SetUpdateMode(true);
     959             : }
     960             : 
     961           0 : bool SfxConfigGroupListBox::Expand( SvTreeListEntry* pParent )
     962             : {
     963           0 :     bool bRet = SvTreeListBox::Expand( pParent );
     964           0 :     if ( bRet )
     965             :     {
     966           0 :         sal_uLong nEntries = GetOutputSizePixel().Height() / GetEntryHeight();
     967             : 
     968           0 :         sal_uLong nChildCount = GetVisibleChildCount( pParent );
     969             : 
     970           0 :         if ( nChildCount+1 > nEntries )
     971             :         {
     972           0 :             MakeVisible( pParent, true );
     973             :         }
     974             :         else
     975             :         {
     976           0 :             SvTreeListEntry *pEntry = GetFirstEntryInView();
     977           0 :             sal_uLong nParentPos = 0;
     978           0 :             while ( pEntry && pEntry != pParent )
     979             :             {
     980           0 :                 ++nParentPos;
     981           0 :                 pEntry = GetNextEntryInView( pEntry );
     982             :             }
     983             : 
     984           0 :             if ( nParentPos + nChildCount + 1 > nEntries )
     985           0 :                 ScrollOutputArea( (short)( nEntries - ( nParentPos + nChildCount + 1 ) ) );
     986             :         }
     987             :     }
     988             : 
     989           0 :     return bRet;
     990             : }
     991             : 
     992           0 : void SfxConfigGroupListBox::RequestingChildren( SvTreeListEntry *pEntry )
     993             : /*  Description
     994             :     A basic or a library is opened.
     995             : */
     996             : {
     997           0 :     SfxGroupInfo_Impl *pInfo = static_cast<SfxGroupInfo_Impl*>(pEntry->GetUserData());
     998           0 :     pInfo->bWasOpened = true;
     999           0 :     switch ( pInfo->nKind )
    1000             :     {
    1001             :         case SFX_CFGGROUP_SCRIPTCONTAINER:
    1002             :         {
    1003           0 :             if ( !GetChildCount( pEntry ) )
    1004             :             {
    1005             :                 Reference< browse::XBrowseNode > rootNode(
    1006           0 :                     static_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
    1007             : 
    1008             :                 try {
    1009           0 :                     if ( rootNode->hasChildNodes() )
    1010             :                     {
    1011             :                         Sequence< Reference< browse::XBrowseNode > > children =
    1012           0 :                             rootNode->getChildNodes();
    1013           0 :                         bool bIsRootNode = false;
    1014             : 
    1015           0 :                         OUString user("user");
    1016           0 :                         OUString share("share" );
    1017           0 :                         if ( rootNode->getName() == "Root" )
    1018             :                         {
    1019           0 :                             bIsRootNode = true;
    1020             :                         }
    1021             : 
    1022             :                         /* To mimic current starbasic behaviour we
    1023             :                         need to make sure that only the current document
    1024             :                         is displayed in the config tree. Tests below
    1025             :                         set the bDisplay flag to sal_False if the current
    1026             :                         node is a first level child of the Root and is NOT
    1027             :                         either the current document, user or share */
    1028           0 :                         OUString currentDocTitle;
    1029           0 :                         Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
    1030           0 :                         if ( xDocument.is() )
    1031             :                         {
    1032           0 :                             currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
    1033             :                         }
    1034             : 
    1035           0 :                         sal_Int32 nLen = children.getLength();
    1036           0 :                         for ( sal_Int32 n = 0; n < nLen; ++n )
    1037             :                         {
    1038           0 :                             Reference< browse::XBrowseNode >& theChild = children[n];
    1039           0 :                             OUString aName( theChild->getName() );
    1040           0 :                             bool bDisplay = true;
    1041           0 :                             if ( bIsRootNode )
    1042             :                             {
    1043           0 :                                 if ( !( (aName.equals(user) || aName.equals(share) || aName.equals(currentDocTitle) ) ) )
    1044           0 :                                     bDisplay=false;
    1045             :                             }
    1046           0 :                             if ( children[n].is() && children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
    1047             :                             {
    1048             : 
    1049             :                                 /*
    1050             :                                     We call acquire on the XBrowseNode so that it does not
    1051             :                                     get autodestructed and become invalid when accessed later.
    1052             :                                 */
    1053           0 :                                 theChild->acquire();
    1054             : 
    1055             :                                 SfxGroupInfo_Impl* pGrpInfo =
    1056             :                                     new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
    1057           0 :                                         0, static_cast<void *>( theChild.get()));
    1058             : 
    1059           0 :                                 Image aImage = GetImage( theChild, Reference< XComponentContext >(), false );
    1060             :                                 SvTreeListEntry* pNewEntry =
    1061           0 :                                     InsertEntry( theChild->getName(), pEntry );
    1062           0 :                                 SetExpandedEntryBmp( pNewEntry, aImage );
    1063           0 :                                 SetCollapsedEntryBmp(pNewEntry, aImage );
    1064             : 
    1065           0 :                                 pNewEntry->SetUserData( pGrpInfo );
    1066           0 :                                 aArr.push_back( pGrpInfo );
    1067             : 
    1068           0 :                                 if ( children[n]->hasChildNodes() )
    1069             :                                 {
    1070             :                                     Sequence< Reference< browse::XBrowseNode > > grandchildren =
    1071           0 :                                         children[n]->getChildNodes();
    1072             : 
    1073           0 :                                     for ( sal_Int32 m = 0; m < grandchildren.getLength(); ++m )
    1074             :                                     {
    1075           0 :                                         if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
    1076             :                                         {
    1077           0 :                                             pNewEntry->EnableChildrenOnDemand( true );
    1078           0 :                                             m = grandchildren.getLength();
    1079             :                                         }
    1080           0 :                                     }
    1081           0 :                                 }
    1082             :                             }
    1083           0 :                         }
    1084             :                     }
    1085             :                 }
    1086           0 :                 catch (RuntimeException&) {
    1087             :                     // do nothing, the entry will not be displayed in the UI
    1088           0 :                 }
    1089             :             }
    1090           0 :             break;
    1091             :         }
    1092             : 
    1093             :         case SFX_CFGGROUP_STYLES:
    1094             :         {
    1095           0 :             if ( !GetChildCount( pEntry ) )
    1096             :             {
    1097           0 :                 const ::std::vector< SfxStyleInfo_Impl >                 lStyleFamilies = pStylesInfo->getStyleFamilies();
    1098           0 :                       ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
    1099           0 :                 for (  pIt  = lStyleFamilies.begin();
    1100           0 :                        pIt != lStyleFamilies.end()  ;
    1101             :                      ++pIt                          )
    1102             :                 {
    1103           0 :                     SfxStyleInfo_Impl* pFamily = new SfxStyleInfo_Impl(*pIt);
    1104           0 :                     SvTreeListEntry* pStyleEntry = InsertEntry( pFamily->sLabel, pEntry );
    1105           0 :                     SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pFamily );
    1106           0 :                     aArr.push_back( pGrpInfo );
    1107           0 :                     pStyleEntry->SetUserData( pGrpInfo );
    1108           0 :                     pStyleEntry->EnableChildrenOnDemand( false );
    1109           0 :                 }
    1110             :             }
    1111           0 :             break;
    1112             :         }
    1113             : 
    1114             :         default:
    1115             :             OSL_FAIL( "Falscher Gruppentyp!" );
    1116           0 :             break;
    1117             :     }
    1118           0 : }
    1119             : 
    1120           0 : void SfxConfigGroupListBox::SelectMacro( const SfxMacroInfoItem *pItem )
    1121             : {
    1122             :     SelectMacro( pItem->GetBasicManager()->GetName(),
    1123           0 :                  pItem->GetQualifiedName() );
    1124           0 : }
    1125             : 
    1126           0 : void SfxConfigGroupListBox::SelectMacro( const OUString& rBasic,
    1127             :          const OUString& rMacro )
    1128             : {
    1129           0 :     OUString aBasicName( rBasic );
    1130           0 :     aBasicName += " ";
    1131           0 :     aBasicName += pImp->m_sMacros;
    1132           0 :     OUString aLib, aModule, aMethod;
    1133           0 :     sal_uInt16 nCount = comphelper::string::getTokenCount(rMacro, '.');
    1134           0 :     aMethod = rMacro.getToken( nCount-1, '.' );
    1135           0 :     if ( nCount > 2 )
    1136             :     {
    1137           0 :         aLib = rMacro.getToken( 0, '.' );
    1138           0 :         aModule = rMacro.getToken( nCount-2, '.' );
    1139             :     }
    1140             : 
    1141           0 :     SvTreeListEntry *pEntry = FirstChild(0);
    1142           0 :     while ( pEntry )
    1143             :     {
    1144           0 :         OUString aEntryBas = GetEntryText( pEntry );
    1145           0 :         if ( aEntryBas == aBasicName )
    1146             :         {
    1147           0 :             Expand( pEntry );
    1148           0 :             SvTreeListEntry *pLib = FirstChild( pEntry );
    1149           0 :             while ( pLib )
    1150             :             {
    1151           0 :                 OUString aEntryLib = GetEntryText( pLib );
    1152           0 :                 if ( aEntryLib == aLib )
    1153             :                 {
    1154           0 :                     Expand( pLib );
    1155           0 :                     SvTreeListEntry *pMod = FirstChild( pLib );
    1156           0 :                     while ( pMod )
    1157             :                     {
    1158           0 :                         OUString aEntryMod = GetEntryText( pMod );
    1159           0 :                         if ( aEntryMod == aModule )
    1160             :                         {
    1161           0 :                             Expand( pMod );
    1162           0 :                             MakeVisible( pMod );
    1163           0 :                             Select( pMod );
    1164           0 :                             SvTreeListEntry *pMethod = pFunctionListBox->First();
    1165           0 :                             while ( pMethod )
    1166             :                             {
    1167           0 :                                 OUString aEntryMethod = GetEntryText( pMethod );
    1168           0 :                                 if ( aEntryMethod == aMethod )
    1169             :                                 {
    1170           0 :                                     pFunctionListBox->Select( pMethod );
    1171           0 :                                     pFunctionListBox->MakeVisible( pMethod );
    1172           0 :                                     return;
    1173             :                                 }
    1174           0 :                                 pMethod = pFunctionListBox->Next( pMethod );
    1175           0 :                             }
    1176             :                         }
    1177           0 :                         pMod = NextSibling( pMod );
    1178           0 :                     }
    1179             :                 }
    1180           0 :                 pLib = NextSibling( pLib );
    1181           0 :             }
    1182             :         }
    1183           0 :         pEntry = NextSibling( pEntry );
    1184           0 :     }
    1185           0 : }
    1186             : 
    1187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11