LCOV - code coverage report
Current view: top level - cui/source/customize - cfgutil.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 607 0.0 %
Date: 2014-04-14 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 : sal_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 sal_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 sal_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 sal_True;
     129             : 
     130           0 :     return sal_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(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 Window* SAL_CALL makeSfxConfigFunctionListBox(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(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 Window* SAL_CALL makeSfxConfigGroupListBox(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             :     OSL_TRACE("** ** 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             :         OSL_TRACE(" Caught some exception whilst retrieving browse nodes from factory... Exception: %s",
     598             :             OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     599             :         // TODO exception handling
     600             :     }
     601             : 
     602             : 
     603           0 :     if ( rootNode.is() )
     604             :     {
     605           0 :         if ( bEventMode )
     606             :         {
     607             :                 //We call acquire on the XBrowseNode so that it does not
     608             :                 //get autodestructed and become invalid when accessed later.
     609           0 :             rootNode->acquire();
     610             : 
     611             :             SfxGroupInfo_Impl *pInfo =
     612             :                 new SfxGroupInfo_Impl( SFX_CFGGROUP_SCRIPTCONTAINER, 0,
     613           0 :                     static_cast<void *>(rootNode.get()));
     614             : 
     615           0 :             OUString aTitle(pImp->m_sDlgMacros);
     616           0 :             SvTreeListEntry *pNewEntry = InsertEntry( aTitle, NULL );
     617           0 :             pNewEntry->SetUserData( pInfo );
     618           0 :             pNewEntry->EnableChildrenOnDemand( true );
     619           0 :             aArr.push_back( pInfo );
     620             :         }
     621             :         else
     622             :         {
     623             :              //We are only showing scripts not slot APIs so skip
     624             :              //Root node and show location nodes
     625             :             try {
     626           0 :                 if ( rootNode->hasChildNodes() )
     627             :                 {
     628             :                     Sequence< Reference< browse::XBrowseNode > > children =
     629           0 :                         rootNode->getChildNodes();
     630           0 :                     sal_Bool bIsRootNode = sal_False;
     631             : 
     632           0 :                     OUString user("user");
     633           0 :                     OUString share("share");
     634           0 :                     if ( rootNode->getName() == "Root" )
     635             :                     {
     636           0 :                         bIsRootNode = sal_True;
     637             :                     }
     638             : 
     639             :                     //To mimic current starbasic behaviour we
     640             :                     //need to make sure that only the current document
     641             :                     //is displayed in the config tree. Tests below
     642             :                     //set the bDisplay flag to FALSE if the current
     643             :                     //node is a first level child of the Root and is NOT
     644             :                     //either the current document, user or share
     645           0 :                     OUString currentDocTitle;
     646           0 :                     Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
     647           0 :                     if ( xDocument.is() )
     648             :                     {
     649           0 :                         currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
     650             :                     }
     651             : 
     652           0 :                     for ( sal_Int32 n = 0; n < children.getLength(); ++n )
     653             :                     {
     654           0 :                         Reference< browse::XBrowseNode >& theChild = children[n];
     655           0 :                         sal_Bool bDisplay = sal_True;
     656           0 :                         OUString uiName = theChild->getName();
     657           0 :                         if ( bIsRootNode )
     658             :                         {
     659           0 :                             if (  ! ((theChild->getName().equals( user )  || theChild->getName().equals( share ) ||
     660           0 :                                 theChild->getName().equals( currentDocTitle ) ) ) )
     661             :                             {
     662           0 :                                 bDisplay=sal_False;
     663             :                             }
     664             :                             else
     665             :                             {
     666           0 :                                 if ( uiName.equals( user ) )
     667             :                                 {
     668           0 :                                     uiName = pImp->m_sMyMacros;
     669             :                                 }
     670           0 :                                 else if ( uiName.equals( share ) )
     671             :                                 {
     672           0 :                                     uiName = pImp->m_sProdMacros;
     673             :                                 }
     674             :                             }
     675             :                         }
     676           0 :                         if (children[n]->getType() != browse::BrowseNodeTypes::SCRIPT  && bDisplay )
     677             :                         {
     678             : //                              We call acquire on the XBrowseNode so that it does not
     679             : //                              get autodestructed and become invalid when accessed later.
     680           0 :                             theChild->acquire();
     681             : 
     682             :                             SfxGroupInfo_Impl* pInfo =
     683             :                                 new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
     684           0 :                                     0, static_cast<void *>( theChild.get()));
     685             : 
     686           0 :                             Image aImage = GetImage( theChild, xCtx, bIsRootNode );
     687             :                             SvTreeListEntry* pNewEntry =
     688           0 :                                 InsertEntry( uiName, NULL);
     689           0 :                             SetExpandedEntryBmp(  pNewEntry, aImage );
     690           0 :                             SetCollapsedEntryBmp( pNewEntry, aImage );
     691             : 
     692           0 :                             pNewEntry->SetUserData( pInfo );
     693           0 :                             aArr.push_back( pInfo );
     694             : 
     695           0 :                             if ( children[n]->hasChildNodes() )
     696             :                             {
     697             :                                 Sequence< Reference< browse::XBrowseNode > > grandchildren =
     698           0 :                                     children[n]->getChildNodes();
     699             : 
     700           0 :                                 for ( sal_Int32 m = 0; m < grandchildren.getLength(); ++m )
     701             :                                 {
     702           0 :                                     if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
     703             :                                     {
     704           0 :                                         pNewEntry->EnableChildrenOnDemand( true );
     705           0 :                                         m = grandchildren.getLength();
     706             :                                     }
     707           0 :                                 }
     708           0 :                             }
     709             :                         }
     710           0 :                     }
     711             :                 }
     712             :             }
     713           0 :             catch (RuntimeException&) {
     714             :                 // do nothing, the entry will not be displayed in the UI
     715             :             }
     716             :         }
     717             :     }
     718             : 
     719             :     // add styles
     720           0 :     if ( m_xContext.is() )
     721             :     {
     722           0 :         OUString sStyle( pImp->m_aStrGroupStyles );
     723           0 :         SvTreeListEntry *pEntry = InsertEntry( sStyle, 0 );
     724           0 :         SfxGroupInfo_Impl *pInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, 0 ); // TODO last parameter should contain user data
     725           0 :         aArr.push_back( pInfo );
     726           0 :         pEntry->SetUserData( pInfo );
     727           0 :         pEntry->EnableChildrenOnDemand( true );
     728             :     }
     729             : 
     730           0 :     MakeVisible( GetEntry( 0,0 ) );
     731           0 :     SetUpdateMode( true );
     732           0 : }
     733             : 
     734           0 : Image SfxConfigGroupListBox::GetImage(
     735             :     Reference< browse::XBrowseNode > node,
     736             :     Reference< XComponentContext > xCtx,
     737             :     bool bIsRootNode
     738             : )
     739             : {
     740           0 :     Image aImage;
     741           0 :     if ( bIsRootNode )
     742             :     {
     743           0 :         OUString user("user");
     744           0 :         OUString share("share");
     745           0 :         if (node->getName().equals( user ) || node->getName().equals(share ) )
     746             :         {
     747           0 :             aImage = pImp->m_hdImage;
     748             :         }
     749             :         else
     750             :         {
     751           0 :             OUString factoryURL;
     752           0 :             OUString nodeName = node->getName();
     753           0 :             Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
     754           0 :             if ( xDocumentModel.is() )
     755             :             {
     756           0 :                 Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xCtx) );
     757             :                 // get the long name of the document:
     758           0 :                 OUString appModule( xModuleManager->identify(
     759           0 :                                     xDocumentModel ) );
     760           0 :                 Sequence<beans::PropertyValue> moduleDescr;
     761           0 :                 Any aAny = xModuleManager->getByName(appModule);
     762           0 :                 if( !( aAny >>= moduleDescr ) )
     763             :                 {
     764           0 :                     throw RuntimeException("SFTreeListBox::Init: failed to get PropertyValue", Reference< XInterface >());
     765             :                 }
     766             :                 beans::PropertyValue const * pmoduleDescr =
     767           0 :                     moduleDescr.getConstArray();
     768           0 :                 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
     769             :                 {
     770           0 :                     if ( pmoduleDescr[ pos ].Name == "ooSetupFactoryEmptyDocumentURL" )
     771             :                     {
     772           0 :                         pmoduleDescr[ pos ].Value >>= factoryURL;
     773             :                         OSL_TRACE("factory url for doc images is %s",
     774             :                         OUStringToOString( factoryURL , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     775           0 :                         break;
     776             :                     }
     777           0 :                 }
     778             :             }
     779           0 :             if( !factoryURL.isEmpty() )
     780             :             {
     781           0 :                 aImage = SvFileInformationManager::GetFileImage( INetURLObject(factoryURL), false );
     782             :             }
     783             :             else
     784             :             {
     785           0 :                 aImage = pImp->m_docImage;
     786           0 :             }
     787           0 :         }
     788             :     }
     789             :     else
     790             :     {
     791           0 :         if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
     792           0 :             aImage = pImp->m_macImage;
     793             :         else
     794           0 :             aImage = pImp->m_libImage;
     795             :     }
     796           0 :     return aImage;
     797             : }
     798             : 
     799             : Reference< XInterface  >
     800           0 : SfxConfigGroupListBox::getDocumentModel( Reference< XComponentContext >& xCtx, OUString& docName )
     801             : {
     802           0 :     Reference< XInterface > xModel;
     803           0 :     Reference< frame::XDesktop2 > desktop = frame::Desktop::create( xCtx );
     804             : 
     805             :     Reference< container::XEnumerationAccess > componentsAccess =
     806           0 :         desktop->getComponents();
     807             :     Reference< container::XEnumeration > components =
     808           0 :         componentsAccess->createEnumeration();
     809           0 :     while (components->hasMoreElements())
     810             :     {
     811             :         Reference< frame::XModel > model(
     812           0 :             components->nextElement(), UNO_QUERY );
     813           0 :         if ( model.is() )
     814             :         {
     815             :             OUString sTdocUrl =
     816           0 :                 ::comphelper::DocumentInfo::getDocumentTitle( model );
     817           0 :             if( sTdocUrl.equals( docName ) )
     818             :             {
     819           0 :                 xModel = model;
     820           0 :                 break;
     821           0 :             }
     822             :         }
     823           0 :     }
     824           0 :     return xModel;
     825             : }
     826             : 
     827             : 
     828           0 : OUString SfxConfigGroupListBox::MapCommand2UIName(const OUString& sCommand)
     829             : {
     830           0 :     OUString sUIName;
     831             :     try
     832             :     {
     833           0 :         css::uno::Reference< css::container::XNameAccess > xModuleConf;
     834           0 :         m_xUICmdDescription->getByName(m_sModuleLongName) >>= xModuleConf;
     835           0 :         if (xModuleConf.is())
     836             :         {
     837           0 :             ::comphelper::SequenceAsHashMap lProps(xModuleConf->getByName(sCommand));
     838           0 :             sUIName = lProps.getUnpackedValueOrDefault("Name", OUString());
     839           0 :         }
     840             :     }
     841           0 :     catch(const css::uno::RuntimeException&)
     842           0 :         { throw; }
     843           0 :     catch(css::uno::Exception&)
     844           0 :         { sUIName = OUString(); }
     845             : 
     846             :     // fallback for missing UINames !?
     847           0 :     if (sUIName.isEmpty())
     848             :     {
     849           0 :         sUIName = sCommand;
     850             :     }
     851             : 
     852           0 :     return sUIName;
     853             : }
     854             : 
     855             : 
     856           0 : void SfxConfigGroupListBox::GroupSelected()
     857             : /*  Description
     858             :     A function group or a basic module has been selected.
     859             :     All functions/macros are displayed in the functionlistbox.
     860             : */
     861             : {
     862           0 :     SvTreeListEntry *pEntry = FirstSelected();
     863           0 :     SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
     864           0 :     pFunctionListBox->SetUpdateMode(false);
     865           0 :     pFunctionListBox->ClearAll();
     866           0 :     if ( pInfo->nKind != SFX_CFGGROUP_FUNCTION &&
     867           0 :              pInfo->nKind != SFX_CFGGROUP_SCRIPTCONTAINER &&
     868           0 :              pInfo->nKind != SFX_CFGGROUP_STYLES )
     869             :     {
     870           0 :         pFunctionListBox->SetUpdateMode(true);
     871           0 :         return;
     872             :     }
     873             : 
     874           0 :     switch ( pInfo->nKind )
     875             :     {
     876             :         case SFX_CFGGROUP_FUNCTION :
     877             :         {
     878           0 :             sal_uInt16                                                          nGroup    = pInfo->nUniqueID;
     879           0 :             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider (m_xFrame, css::uno::UNO_QUERY_THROW);
     880           0 :             css::uno::Sequence< css::frame::DispatchInformation >           lCommands = xProvider->getConfigurableDispatchInformation(nGroup);
     881           0 :             sal_Int32                                                       c         = lCommands.getLength();
     882           0 :             sal_Int32                                                       i         = 0;
     883             : 
     884           0 :             for (i=0; i<c; ++i)
     885             :             {
     886           0 :                 const css::frame::DispatchInformation& rInfo      = lCommands[i];
     887           0 :                 OUString                        sUIName    = MapCommand2UIName(rInfo.Command);
     888           0 :                 SvTreeListEntry*                           pFuncEntry = pFunctionListBox->InsertEntry(sUIName, NULL);
     889           0 :                 SfxGroupInfo_Impl*                     pGrpInfo   = new SfxGroupInfo_Impl(SFX_CFGFUNCTION_SLOT, 0);
     890           0 :                 pGrpInfo->sCommand = rInfo.Command;
     891           0 :                 pGrpInfo->sLabel   = sUIName;
     892           0 :                 pFuncEntry->SetUserData(pGrpInfo);
     893           0 :             }
     894             : 
     895           0 :             break;
     896             :         }
     897             : 
     898             :         case SFX_CFGGROUP_SCRIPTCONTAINER:
     899             :         {
     900           0 :             if ( !GetChildCount( pEntry ) )
     901             :             {
     902             :                 Reference< browse::XBrowseNode > rootNode(
     903           0 :                     reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
     904             : 
     905             :                 try {
     906           0 :                     if ( rootNode->hasChildNodes() )
     907             :                     {
     908             :                         Sequence< Reference< browse::XBrowseNode > > children =
     909           0 :                             rootNode->getChildNodes();
     910             : 
     911           0 :                         for ( sal_Int32 n = 0; n < children.getLength(); ++n )
     912             :                         {
     913           0 :                             if (children[n]->getType() == browse::BrowseNodeTypes::SCRIPT)
     914             :                             {
     915           0 :                                 OUString uri;
     916             : 
     917           0 :                                 Reference < beans::XPropertySet >xPropSet( children[n], UNO_QUERY );
     918           0 :                                 if (!xPropSet.is())
     919             :                                 {
     920           0 :                                     continue;
     921             :                                 }
     922             : 
     923             :                                 Any value =
     924           0 :                                     xPropSet->getPropertyValue("URI");
     925           0 :                                 value >>= uri;
     926             : 
     927           0 :                                 OUString* pScriptURI = new OUString( uri );
     928           0 :                                 SfxGroupInfo_Impl* pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGFUNCTION_SCRIPT, 0, pScriptURI );
     929             : 
     930           0 :                                 Image aImage = GetImage( children[n], Reference< XComponentContext >(), false );
     931             :                                 SvTreeListEntry* pNewEntry =
     932           0 :                                     pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
     933           0 :                                 pFunctionListBox->SetExpandedEntryBmp( pNewEntry, aImage );
     934           0 :                                 pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage );
     935             : 
     936           0 :                                 pGrpInfo->sCommand = uri;
     937           0 :                                 pGrpInfo->sLabel = children[n]->getName();
     938           0 :                                 pNewEntry->SetUserData( pGrpInfo );
     939             : 
     940           0 :                                 pFunctionListBox->aArr.push_back( pGrpInfo );
     941             : 
     942             :                             }
     943           0 :                         }
     944             :                     }
     945             :                 }
     946           0 :                 catch (RuntimeException&) {
     947             :                     // do nothing, the entry will not be displayed in the UI
     948           0 :                 }
     949             :             }
     950           0 :             break;
     951             :         }
     952             : 
     953             :         case SFX_CFGGROUP_STYLES :
     954             :         {
     955           0 :             SfxStyleInfo_Impl* pFamily = (SfxStyleInfo_Impl*)(pInfo->pObject);
     956           0 :             if (pFamily)
     957             :             {
     958           0 :                 const ::std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pFamily->sFamily);
     959           0 :                 ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
     960           0 :                 for (  pIt  = lStyles.begin();
     961           0 :                        pIt != lStyles.end()  ;
     962             :                      ++pIt                   )
     963             :                 {
     964           0 :                     SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(*pIt);
     965           0 :                     SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry( pStyle->sLabel, NULL );
     966           0 :                     SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pStyle );
     967           0 :                     pFunctionListBox->aArr.push_back( pGrpInfo );
     968           0 :                     pGrpInfo->sCommand = pStyle->sCommand;
     969           0 :                     pGrpInfo->sLabel = pStyle->sLabel;
     970           0 :                     pFuncEntry->SetUserData( pGrpInfo );
     971           0 :                 }
     972             :             }
     973           0 :             break;
     974             :         }
     975             : 
     976             :         default:
     977           0 :             return;
     978             :     }
     979             : 
     980           0 :     if ( pFunctionListBox->GetEntryCount() )
     981           0 :         pFunctionListBox->Select( pFunctionListBox->GetEntry( 0, 0 ) );
     982             : 
     983           0 :     pFunctionListBox->SetUpdateMode(true);
     984             : }
     985             : 
     986           0 : sal_Bool SfxConfigGroupListBox::Expand( SvTreeListEntry* pParent )
     987             : {
     988           0 :     sal_Bool bRet = SvTreeListBox::Expand( pParent );
     989           0 :     if ( bRet )
     990             :     {
     991           0 :         sal_uLong nEntries = GetOutputSizePixel().Height() / GetEntryHeight();
     992             : 
     993           0 :         sal_uLong nChildCount = GetVisibleChildCount( pParent );
     994             : 
     995           0 :         if ( nChildCount+1 > nEntries )
     996             :         {
     997           0 :             MakeVisible( pParent, true );
     998             :         }
     999             :         else
    1000             :         {
    1001           0 :             SvTreeListEntry *pEntry = GetFirstEntryInView();
    1002           0 :             sal_uLong nParentPos = 0;
    1003           0 :             while ( pEntry && pEntry != pParent )
    1004             :             {
    1005           0 :                 ++nParentPos;
    1006           0 :                 pEntry = GetNextEntryInView( pEntry );
    1007             :             }
    1008             : 
    1009           0 :             if ( nParentPos + nChildCount + 1 > nEntries )
    1010           0 :                 ScrollOutputArea( (short)( nEntries - ( nParentPos + nChildCount + 1 ) ) );
    1011             :         }
    1012             :     }
    1013             : 
    1014           0 :     return bRet;
    1015             : }
    1016             : 
    1017           0 : void SfxConfigGroupListBox::RequestingChildren( SvTreeListEntry *pEntry )
    1018             : /*  Description
    1019             :     A basic or a library is opened.
    1020             : */
    1021             : {
    1022           0 :     SfxGroupInfo_Impl *pInfo = (SfxGroupInfo_Impl*) pEntry->GetUserData();
    1023           0 :     pInfo->bWasOpened = sal_True;
    1024           0 :     switch ( pInfo->nKind )
    1025             :     {
    1026             :         case SFX_CFGGROUP_SCRIPTCONTAINER:
    1027             :         {
    1028           0 :             if ( !GetChildCount( pEntry ) )
    1029             :             {
    1030             :                 Reference< browse::XBrowseNode > rootNode(
    1031           0 :                     reinterpret_cast< browse::XBrowseNode* >( pInfo->pObject ) ) ;
    1032             : 
    1033             :                 try {
    1034           0 :                     if ( rootNode->hasChildNodes() )
    1035             :                     {
    1036             :                         Sequence< Reference< browse::XBrowseNode > > children =
    1037           0 :                             rootNode->getChildNodes();
    1038           0 :                         sal_Bool bIsRootNode = sal_False;
    1039             : 
    1040           0 :                         OUString user("user");
    1041           0 :                         OUString share("share" );
    1042           0 :                         if ( rootNode->getName() == "Root" )
    1043             :                         {
    1044           0 :                             bIsRootNode = sal_True;
    1045             :                         }
    1046             : 
    1047             :                         /* To mimic current starbasic behaviour we
    1048             :                         need to make sure that only the current document
    1049             :                         is displayed in the config tree. Tests below
    1050             :                         set the bDisplay flag to sal_False if the current
    1051             :                         node is a first level child of the Root and is NOT
    1052             :                         either the current document, user or share */
    1053           0 :                         OUString currentDocTitle;
    1054           0 :                         Reference< XModel > xDocument( lcl_getScriptableDocument_nothrow( m_xFrame ) );
    1055           0 :                         if ( xDocument.is() )
    1056             :                         {
    1057           0 :                             currentDocTitle = ::comphelper::DocumentInfo::getDocumentTitle( xDocument );
    1058             :                         }
    1059             : 
    1060           0 :                         sal_Int32 nLen = children.getLength();
    1061           0 :                         for ( sal_Int32 n = 0; n < nLen; ++n )
    1062             :                         {
    1063           0 :                             Reference< browse::XBrowseNode >& theChild = children[n];
    1064           0 :                             OUString aName( theChild->getName() );
    1065           0 :                             sal_Bool bDisplay = sal_True;
    1066           0 :                             if ( bIsRootNode )
    1067             :                             {
    1068           0 :                                 if ( !( (aName.equals(user) || aName.equals(share) || aName.equals(currentDocTitle) ) ) )
    1069           0 :                                     bDisplay=sal_False;
    1070             :                             }
    1071           0 :                             if ( children[n].is() && children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
    1072             :                             {
    1073             : 
    1074             :                                 /*
    1075             :                                     We call acquire on the XBrowseNode so that it does not
    1076             :                                     get autodestructed and become invalid when accessed later.
    1077             :                                 */
    1078           0 :                                 theChild->acquire();
    1079             : 
    1080             :                                 SfxGroupInfo_Impl* pGrpInfo =
    1081             :                                     new SfxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
    1082           0 :                                         0, static_cast<void *>( theChild.get()));
    1083             : 
    1084           0 :                                 Image aImage = GetImage( theChild, Reference< XComponentContext >(), false );
    1085             :                                 SvTreeListEntry* pNewEntry =
    1086           0 :                                     InsertEntry( theChild->getName(), pEntry );
    1087           0 :                                 SetExpandedEntryBmp( pNewEntry, aImage );
    1088           0 :                                 SetCollapsedEntryBmp(pNewEntry, aImage );
    1089             : 
    1090           0 :                                 pNewEntry->SetUserData( pGrpInfo );
    1091           0 :                                 aArr.push_back( pGrpInfo );
    1092             : 
    1093           0 :                                 if ( children[n]->hasChildNodes() )
    1094             :                                 {
    1095             :                                     Sequence< Reference< browse::XBrowseNode > > grandchildren =
    1096           0 :                                         children[n]->getChildNodes();
    1097             : 
    1098           0 :                                     for ( sal_Int32 m = 0; m < grandchildren.getLength(); ++m )
    1099             :                                     {
    1100           0 :                                         if ( grandchildren[m]->getType() == browse::BrowseNodeTypes::CONTAINER )
    1101             :                                         {
    1102           0 :                                             pNewEntry->EnableChildrenOnDemand( true );
    1103           0 :                                             m = grandchildren.getLength();
    1104             :                                         }
    1105           0 :                                     }
    1106           0 :                                 }
    1107             :                             }
    1108           0 :                         }
    1109             :                     }
    1110             :                 }
    1111           0 :                 catch (RuntimeException&) {
    1112             :                     // do nothing, the entry will not be displayed in the UI
    1113           0 :                 }
    1114             :             }
    1115           0 :             break;
    1116             :         }
    1117             : 
    1118             :         case SFX_CFGGROUP_STYLES:
    1119             :         {
    1120           0 :             if ( !GetChildCount( pEntry ) )
    1121             :             {
    1122           0 :                 const ::std::vector< SfxStyleInfo_Impl >                 lStyleFamilies = pStylesInfo->getStyleFamilies();
    1123           0 :                       ::std::vector< SfxStyleInfo_Impl >::const_iterator pIt;
    1124           0 :                 for (  pIt  = lStyleFamilies.begin();
    1125           0 :                        pIt != lStyleFamilies.end()  ;
    1126             :                      ++pIt                          )
    1127             :                 {
    1128           0 :                     SfxStyleInfo_Impl* pFamily = new SfxStyleInfo_Impl(*pIt);
    1129           0 :                     SvTreeListEntry* pStyleEntry = InsertEntry( pFamily->sLabel, pEntry );
    1130           0 :                     SfxGroupInfo_Impl *pGrpInfo = new SfxGroupInfo_Impl( SFX_CFGGROUP_STYLES, 0, pFamily );
    1131           0 :                     aArr.push_back( pGrpInfo );
    1132           0 :                     pStyleEntry->SetUserData( pGrpInfo );
    1133           0 :                     pStyleEntry->EnableChildrenOnDemand( false );
    1134           0 :                 }
    1135             :             }
    1136           0 :             break;
    1137             :         }
    1138             : 
    1139             :         default:
    1140             :             OSL_FAIL( "Falscher Gruppentyp!" );
    1141           0 :             break;
    1142             :     }
    1143           0 : }
    1144             : 
    1145           0 : void SfxConfigGroupListBox::SelectMacro( const SfxMacroInfoItem *pItem )
    1146             : {
    1147             :     SelectMacro( pItem->GetBasicManager()->GetName(),
    1148           0 :                  pItem->GetQualifiedName() );
    1149           0 : }
    1150             : 
    1151           0 : void SfxConfigGroupListBox::SelectMacro( const OUString& rBasic,
    1152             :          const OUString& rMacro )
    1153             : {
    1154           0 :     OUString aBasicName( rBasic );
    1155           0 :     aBasicName += " ";
    1156           0 :     aBasicName += pImp->m_sMacros;
    1157           0 :     OUString aLib, aModule, aMethod;
    1158           0 :     sal_uInt16 nCount = comphelper::string::getTokenCount(rMacro, '.');
    1159           0 :     aMethod = rMacro.getToken( nCount-1, '.' );
    1160           0 :     if ( nCount > 2 )
    1161             :     {
    1162           0 :         aLib = rMacro.getToken( 0, '.' );
    1163           0 :         aModule = rMacro.getToken( nCount-2, '.' );
    1164             :     }
    1165             : 
    1166           0 :     SvTreeListEntry *pEntry = FirstChild(0);
    1167           0 :     while ( pEntry )
    1168             :     {
    1169           0 :         OUString aEntryBas = GetEntryText( pEntry );
    1170           0 :         if ( aEntryBas == aBasicName )
    1171             :         {
    1172           0 :             Expand( pEntry );
    1173           0 :             SvTreeListEntry *pLib = FirstChild( pEntry );
    1174           0 :             while ( pLib )
    1175             :             {
    1176           0 :                 OUString aEntryLib = GetEntryText( pLib );
    1177           0 :                 if ( aEntryLib == aLib )
    1178             :                 {
    1179           0 :                     Expand( pLib );
    1180           0 :                     SvTreeListEntry *pMod = FirstChild( pLib );
    1181           0 :                     while ( pMod )
    1182             :                     {
    1183           0 :                         OUString aEntryMod = GetEntryText( pMod );
    1184           0 :                         if ( aEntryMod == aModule )
    1185             :                         {
    1186           0 :                             Expand( pMod );
    1187           0 :                             MakeVisible( pMod );
    1188           0 :                             Select( pMod );
    1189           0 :                             SvTreeListEntry *pMethod = pFunctionListBox->First();
    1190           0 :                             while ( pMethod )
    1191             :                             {
    1192           0 :                                 OUString aEntryMethod = GetEntryText( pMethod );
    1193           0 :                                 if ( aEntryMethod == aMethod )
    1194             :                                 {
    1195           0 :                                     pFunctionListBox->Select( pMethod );
    1196           0 :                                     pFunctionListBox->MakeVisible( pMethod );
    1197           0 :                                     return;
    1198             :                                 }
    1199           0 :                                 pMethod = pFunctionListBox->Next( pMethod );
    1200           0 :                             }
    1201             :                         }
    1202           0 :                         pMod = NextSibling( pMod );
    1203           0 :                     }
    1204             :                 }
    1205           0 :                 pLib = NextSibling( pLib );
    1206           0 :             }
    1207             :         }
    1208           0 :         pEntry = NextSibling( pEntry );
    1209           0 :     }
    1210           0 : }
    1211             : 
    1212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10