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

Generated by: LCOV version 1.10