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

Generated by: LCOV version 1.10