LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ResourceManager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 308 0.0 %
Date: 2014-04-14 Functions: 0 16 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 "ResourceManager.hxx"
      21             : #include <sfx2/sidebar/Tools.hxx>
      22             : 
      23             : #include <unotools/confignode.hxx>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <comphelper/namedvaluecollection.hxx>
      26             : #include <comphelper/types.hxx>
      27             : 
      28             : #include <rtl/ustrbuf.hxx>
      29             : #include <tools/diagnose_ex.h>
      30             : 
      31             : #include <com/sun/star/frame/ModuleManager.hpp>
      32             : 
      33             : #include <map>
      34             : 
      35             : using ::rtl::OUString;
      36             : using namespace css;
      37             : using namespace cssu;
      38             : 
      39             : namespace sfx2 { namespace sidebar {
      40             : 
      41           0 : ResourceManager& ResourceManager::Instance (void)
      42             : {
      43           0 :     static ResourceManager maInstance;
      44           0 :     return maInstance;
      45             : }
      46             : 
      47             : 
      48             : 
      49             : 
      50           0 : ResourceManager::ResourceManager (void)
      51             :     : maDecks(),
      52             :       maPanels(),
      53           0 :       maProcessedApplications()
      54             : {
      55           0 :     ReadDeckList();
      56           0 :     ReadPanelList();
      57           0 : }
      58             : 
      59             : 
      60             : 
      61             : 
      62           0 : ResourceManager::~ResourceManager (void)
      63             : {
      64           0 :     maPanels.clear();
      65           0 :     maDecks.clear();
      66           0 : }
      67             : 
      68             : 
      69             : 
      70             : 
      71           0 : const DeckDescriptor* ResourceManager::GetDeckDescriptor (
      72             :     const ::rtl::OUString& rsDeckId) const
      73             : {
      74           0 :     for (DeckContainer::const_iterator
      75           0 :              iDeck(maDecks.begin()),
      76           0 :              iEnd(maDecks.end());
      77             :          iDeck!=iEnd;
      78             :          ++iDeck)
      79             :     {
      80           0 :         if (iDeck->msId.equals(rsDeckId))
      81           0 :             return &*iDeck;
      82             :     }
      83           0 :     return NULL;
      84             : }
      85             : 
      86             : 
      87             : 
      88             : 
      89           0 : const PanelDescriptor* ResourceManager::GetPanelDescriptor (
      90             :     const ::rtl::OUString& rsPanelId) const
      91             : {
      92           0 :     for (PanelContainer::const_iterator
      93           0 :              iPanel(maPanels.begin()),
      94           0 :              iEnd(maPanels.end());
      95             :          iPanel!=iEnd;
      96             :          ++iPanel)
      97             :     {
      98           0 :         if (iPanel->msId.equals(rsPanelId))
      99           0 :             return &*iPanel;
     100             :     }
     101           0 :     return NULL;
     102             : }
     103             : 
     104             : 
     105             : 
     106             : 
     107           0 : void ResourceManager::SetIsDeckEnabled (
     108             :     const ::rtl::OUString& rsDeckId,
     109             :     const bool bIsEnabled)
     110             : {
     111           0 :     for (DeckContainer::iterator
     112           0 :              iDeck(maDecks.begin()),
     113           0 :              iEnd(maDecks.end());
     114             :          iDeck!=iEnd;
     115             :          ++iDeck)
     116             :     {
     117           0 :         if (iDeck->msId.equals(rsDeckId))
     118             :         {
     119           0 :             iDeck->mbIsEnabled = bIsEnabled;
     120           0 :             return;
     121             :         }
     122             :     }
     123             : }
     124             : 
     125             : 
     126             : 
     127             : 
     128           0 : const ResourceManager::DeckContextDescriptorContainer& ResourceManager::GetMatchingDecks (
     129             :     DeckContextDescriptorContainer& rDecks,
     130             :     const Context& rContext,
     131             :     const bool bIsDocumentReadOnly,
     132             :     const Reference<frame::XFrame>& rxFrame)
     133             : {
     134           0 :     ReadLegacyAddons(rxFrame);
     135             : 
     136           0 :     ::std::multimap<sal_Int32,DeckContextDescriptor> aOrderedIds;
     137           0 :     for (DeckContainer::const_iterator
     138           0 :              iDeck(maDecks.begin()),
     139           0 :              iEnd (maDecks.end());
     140             :          iDeck!=iEnd;
     141             :          ++iDeck)
     142             :     {
     143           0 :         const DeckDescriptor& rDeckDescriptor (*iDeck);
     144           0 :         if (rDeckDescriptor.maContextList.GetMatch(rContext) == NULL)
     145           0 :             continue;
     146           0 :         DeckContextDescriptor aDeckContextDescriptor;
     147           0 :         aDeckContextDescriptor.msId = rDeckDescriptor.msId;
     148             :         aDeckContextDescriptor.mbIsEnabled =
     149           0 :             ! bIsDocumentReadOnly
     150           0 :             || IsDeckEnabled(rDeckDescriptor.msId, rContext, rxFrame);
     151             :         aOrderedIds.insert(::std::multimap<sal_Int32,DeckContextDescriptor>::value_type(
     152             :                 rDeckDescriptor.mnOrderIndex,
     153           0 :                 aDeckContextDescriptor));
     154           0 :     }
     155             : 
     156           0 :     for (::std::multimap<sal_Int32,DeckContextDescriptor>::const_iterator
     157           0 :              iId(aOrderedIds.begin()),
     158           0 :              iEnd(aOrderedIds.end());
     159             :          iId!=iEnd;
     160             :          ++iId)
     161             :     {
     162           0 :         rDecks.push_back(iId->second);
     163             :     }
     164             : 
     165           0 :     return rDecks;
     166             : }
     167             : 
     168             : 
     169             : 
     170             : 
     171           0 : const ResourceManager::PanelContextDescriptorContainer& ResourceManager::GetMatchingPanels (
     172             :     PanelContextDescriptorContainer& rPanelIds,
     173             :     const Context& rContext,
     174             :     const ::rtl::OUString& rsDeckId,
     175             :     const Reference<frame::XFrame>& rxFrame)
     176             : {
     177           0 :     ReadLegacyAddons(rxFrame);
     178             : 
     179           0 :     ::std::multimap<sal_Int32,PanelContextDescriptor> aOrderedIds;
     180           0 :     for (PanelContainer::const_iterator
     181           0 :              iPanel(maPanels.begin()),
     182           0 :              iEnd(maPanels.end());
     183             :          iPanel!=iEnd;
     184             :          ++iPanel)
     185             :     {
     186           0 :         const PanelDescriptor& rPanelDescriptor (*iPanel);
     187           0 :         if ( ! rPanelDescriptor.msDeckId.equals(rsDeckId))
     188           0 :             continue;
     189             : 
     190           0 :         const ContextList::Entry* pEntry = rPanelDescriptor.maContextList.GetMatch(rContext);
     191           0 :         if (pEntry == NULL)
     192           0 :             continue;
     193             : 
     194           0 :         PanelContextDescriptor aPanelContextDescriptor;
     195           0 :         aPanelContextDescriptor.msId = rPanelDescriptor.msId;
     196           0 :         aPanelContextDescriptor.msMenuCommand = pEntry->msMenuCommand;
     197           0 :         aPanelContextDescriptor.mbIsInitiallyVisible = pEntry->mbIsInitiallyVisible;
     198           0 :         aPanelContextDescriptor.mbShowForReadOnlyDocuments = rPanelDescriptor.mbShowForReadOnlyDocuments;
     199             :         aOrderedIds.insert(::std::multimap<sal_Int32,PanelContextDescriptor>::value_type(
     200             :                 rPanelDescriptor.mnOrderIndex,
     201           0 :                 aPanelContextDescriptor));
     202           0 :     }
     203             : 
     204           0 :     for (::std::multimap<sal_Int32,PanelContextDescriptor>::const_iterator
     205           0 :              iId(aOrderedIds.begin()),
     206           0 :              iEnd(aOrderedIds.end());
     207             :          iId!=iEnd;
     208             :          ++iId)
     209             :     {
     210           0 :         rPanelIds.push_back(iId->second);
     211             :     }
     212             : 
     213           0 :     return rPanelIds;
     214             : }
     215             : 
     216             : 
     217             : 
     218             : 
     219           0 : void ResourceManager::ReadDeckList (void)
     220             : {
     221             :     const ::utl::OConfigurationTreeRoot aDeckRootNode (
     222             :         ::comphelper::getProcessComponentContext(),
     223             :         OUString("org.openoffice.Office.UI.Sidebar/Content/DeckList"),
     224           0 :         false);
     225           0 :     if ( ! aDeckRootNode.isValid() )
     226           0 :         return;
     227             : 
     228           0 :     const Sequence<OUString> aDeckNodeNames (aDeckRootNode.getNodeNames());
     229           0 :     const sal_Int32 nCount (aDeckNodeNames.getLength());
     230           0 :     maDecks.resize(nCount);
     231           0 :     sal_Int32 nWriteIndex(0);
     232           0 :     for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex)
     233             :     {
     234           0 :         const ::utl::OConfigurationNode aDeckNode (aDeckRootNode.openNode(aDeckNodeNames[nReadIndex]));
     235           0 :         if ( ! aDeckNode.isValid())
     236           0 :             continue;
     237             : 
     238           0 :         DeckDescriptor& rDeckDescriptor (maDecks[nWriteIndex++]);
     239             : 
     240           0 :         rDeckDescriptor.msTitle = ::comphelper::getString(
     241           0 :             aDeckNode.getNodeValue("Title"));
     242           0 :         rDeckDescriptor.msId = ::comphelper::getString(
     243           0 :             aDeckNode.getNodeValue("Id"));
     244           0 :         rDeckDescriptor.msIconURL = ::comphelper::getString(
     245           0 :             aDeckNode.getNodeValue("IconURL"));
     246           0 :         rDeckDescriptor.msHighContrastIconURL = ::comphelper::getString(
     247           0 :             aDeckNode.getNodeValue("HighContrastIconURL"));
     248           0 :         rDeckDescriptor.msTitleBarIconURL = ::comphelper::getString(
     249           0 :             aDeckNode.getNodeValue("TitleBarIconURL"));
     250           0 :         rDeckDescriptor.msHighContrastTitleBarIconURL = ::comphelper::getString(
     251           0 :             aDeckNode.getNodeValue("HighContrastTitleBarIconURL"));
     252           0 :         rDeckDescriptor.msHelpURL = ::comphelper::getString(
     253           0 :             aDeckNode.getNodeValue("HelpURL"));
     254           0 :         rDeckDescriptor.msHelpText = rDeckDescriptor.msTitle;
     255           0 :         rDeckDescriptor.mbIsEnabled = true;
     256             :         rDeckDescriptor.mnOrderIndex = ::comphelper::getINT32(
     257           0 :             aDeckNode.getNodeValue("OrderIndex"));
     258             : 
     259             :         ReadContextList(
     260             :             aDeckNode,
     261             :             rDeckDescriptor.maContextList,
     262           0 :             OUString());
     263           0 :     }
     264             : 
     265             :     // When there where invalid nodes then we have to adapt the size
     266             :     // of the deck vector.
     267           0 :     if (nWriteIndex<nCount)
     268           0 :         maDecks.resize(nWriteIndex);
     269             : }
     270             : 
     271             : 
     272             : 
     273             : 
     274           0 : void ResourceManager::ReadPanelList (void)
     275             : {
     276             :     const ::utl::OConfigurationTreeRoot aPanelRootNode (
     277             :         ::comphelper::getProcessComponentContext(),
     278             :         OUString("org.openoffice.Office.UI.Sidebar/Content/PanelList"),
     279           0 :         false);
     280           0 :     if ( ! aPanelRootNode.isValid() )
     281           0 :         return;
     282             : 
     283           0 :     const Sequence<OUString> aPanelNodeNames (aPanelRootNode.getNodeNames());
     284           0 :     const sal_Int32 nCount (aPanelNodeNames.getLength());
     285           0 :     maPanels.resize(nCount);
     286           0 :     sal_Int32 nWriteIndex (0);
     287           0 :     for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex)
     288             :     {
     289           0 :         const ::utl::OConfigurationNode aPanelNode (aPanelRootNode.openNode(aPanelNodeNames[nReadIndex]));
     290           0 :         if ( ! aPanelNode.isValid())
     291           0 :             continue;
     292             : 
     293           0 :         PanelDescriptor& rPanelDescriptor (maPanels[nWriteIndex++]);
     294             : 
     295           0 :         rPanelDescriptor.msTitle = ::comphelper::getString(
     296           0 :             aPanelNode.getNodeValue("Title"));
     297             :         rPanelDescriptor.mbIsTitleBarOptional = ::comphelper::getBOOL(
     298           0 :             aPanelNode.getNodeValue("TitleBarIsOptional"));
     299           0 :         rPanelDescriptor.msId = ::comphelper::getString(
     300           0 :             aPanelNode.getNodeValue("Id"));
     301           0 :         rPanelDescriptor.msDeckId = ::comphelper::getString(
     302           0 :             aPanelNode.getNodeValue("DeckId"));
     303           0 :         rPanelDescriptor.msTitleBarIconURL = ::comphelper::getString(
     304           0 :             aPanelNode.getNodeValue("TitleBarIconURL"));
     305           0 :         rPanelDescriptor.msHighContrastTitleBarIconURL = ::comphelper::getString(
     306           0 :             aPanelNode.getNodeValue("HighContrastTitleBarIconURL"));
     307           0 :         rPanelDescriptor.msHelpURL = ::comphelper::getString(
     308           0 :             aPanelNode.getNodeValue("HelpURL"));
     309           0 :         rPanelDescriptor.msImplementationURL = ::comphelper::getString(
     310           0 :             aPanelNode.getNodeValue("ImplementationURL"));
     311             :         rPanelDescriptor.mnOrderIndex = ::comphelper::getINT32(
     312           0 :             aPanelNode.getNodeValue("OrderIndex"));
     313             :         rPanelDescriptor.mbShowForReadOnlyDocuments = ::comphelper::getBOOL(
     314           0 :             aPanelNode.getNodeValue("ShowForReadOnlyDocument"));
     315             :         rPanelDescriptor.mbWantsCanvas = ::comphelper::getBOOL(
     316           0 :             aPanelNode.getNodeValue("WantsCanvas"));
     317             :         const OUString sDefaultMenuCommand (::comphelper::getString(
     318           0 :                 aPanelNode.getNodeValue("DefaultMenuCommand")));
     319             : 
     320             :         ReadContextList(
     321             :             aPanelNode,
     322             :             rPanelDescriptor.maContextList,
     323           0 :             sDefaultMenuCommand);
     324           0 :     }
     325             : 
     326             :     // When there where invalid nodes then we have to adapt the size
     327             :     // of the deck vector.
     328           0 :     if (nWriteIndex<nCount)
     329           0 :         maPanels.resize(nWriteIndex);
     330             : }
     331             : 
     332             : 
     333             : 
     334             : 
     335           0 : void ResourceManager::ReadContextList (
     336             :     const ::utl::OConfigurationNode& rParentNode,
     337             :     ContextList& rContextList,
     338             :     const OUString& rsDefaultMenuCommand) const
     339             : {
     340           0 :     const Any aValue = rParentNode.getNodeValue("ContextList");
     341           0 :     Sequence<OUString> aValues;
     342             :     sal_Int32 nCount;
     343           0 :     if (aValue >>= aValues)
     344           0 :         nCount = aValues.getLength();
     345             :     else
     346           0 :         nCount = 0;
     347             : 
     348           0 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     349             :     {
     350           0 :         const OUString sValue (aValues[nIndex]);
     351           0 :         sal_Int32 nCharacterIndex (0);
     352           0 :         const OUString sApplicationName (sValue.getToken(0, ',', nCharacterIndex).trim());
     353           0 :         if (nCharacterIndex < 0)
     354             :         {
     355           0 :             if (sApplicationName.getLength() == 0)
     356             :             {
     357             :                 // This is a valid case: in the XML file the separator
     358             :                 // was used as terminator.  Using it in the last line
     359             :                 // creates an additional but empty entry.
     360           0 :                 break;
     361             :             }
     362             :             else
     363             :             {
     364             :                 OSL_FAIL("expecting three or four values per ContextList entry, separated by comma");
     365           0 :                 continue;
     366             :             }
     367             :         }
     368             : 
     369           0 :         const OUString sContextName (sValue.getToken(0, ',', nCharacterIndex).trim());
     370           0 :         if (nCharacterIndex < 0)
     371             :         {
     372             :             OSL_FAIL("expecting three or four values per ContextList entry, separated by comma");
     373           0 :             continue;
     374             :         }
     375             : 
     376           0 :         const OUString sInitialState (sValue.getToken(0, ',', nCharacterIndex).trim());
     377             : 
     378             :         // The fourth argument is optional.
     379             :         const OUString sMenuCommandOverride (
     380           0 :             nCharacterIndex<0
     381             :                 ? OUString()
     382           0 :                 : sValue.getToken(0, ',', nCharacterIndex).trim());
     383             :         const OUString sMenuCommand (
     384           0 :             sMenuCommandOverride.getLength()>0
     385           0 :                 ? (sMenuCommandOverride.equalsAscii("none")
     386             :                     ? OUString()
     387             :                     : sMenuCommandOverride)
     388           0 :                 : rsDefaultMenuCommand);
     389             : 
     390             :         // Setup a list of application enums.  Note that the
     391             :         // application name may result in more than one value (eg
     392             :         // DrawImpress will result in two enums, one for Draw and one
     393             :         // for Impress).
     394           0 :         ::std::vector<EnumContext::Application> aApplications;
     395           0 :         EnumContext::Application eApplication (EnumContext::GetApplicationEnum(sApplicationName));
     396           0 :         if (eApplication == EnumContext::Application_None
     397           0 :             && !sApplicationName.equals(EnumContext::GetApplicationName(EnumContext::Application_None)))
     398             :         {
     399             :             // Handle some special names: abbreviations that make
     400             :             // context descriptions more readable.
     401           0 :             if (sApplicationName.equalsAscii("Writer"))
     402           0 :                 aApplications.push_back(EnumContext::Application_Writer);
     403           0 :             else if (sApplicationName.equalsAscii("Calc"))
     404           0 :                 aApplications.push_back(EnumContext::Application_Calc);
     405           0 :             else if (sApplicationName.equalsAscii("Draw"))
     406           0 :                 aApplications.push_back(EnumContext::Application_Draw);
     407           0 :             else if (sApplicationName.equalsAscii("Impress"))
     408           0 :                 aApplications.push_back(EnumContext::Application_Impress);
     409           0 :             else if (sApplicationName.equalsAscii("DrawImpress"))
     410             :             {
     411             :                 // A special case among the special names:  it is
     412             :                 // common to use the same context descriptions for
     413             :                 // both Draw and Impress.  This special case helps to
     414             :                 // avoid duplication in the .xcu file.
     415           0 :                 aApplications.push_back(EnumContext::Application_Draw);
     416           0 :                 aApplications.push_back(EnumContext::Application_Impress);
     417             :             }
     418           0 :             else if (sApplicationName.equalsAscii("WriterVariants"))
     419             :             {
     420             :                 // Another special case for all Writer variants.
     421           0 :                 aApplications.push_back(EnumContext::Application_Writer);
     422           0 :                 aApplications.push_back(EnumContext::Application_WriterGlobal);
     423           0 :                 aApplications.push_back(EnumContext::Application_WriterWeb);
     424           0 :                 aApplications.push_back(EnumContext::Application_WriterXML);
     425           0 :                 aApplications.push_back(EnumContext::Application_WriterForm);
     426           0 :                 aApplications.push_back(EnumContext::Application_WriterReport);
     427             :             }
     428             :             else
     429             :             {
     430             :                 OSL_FAIL("application name not recognized");
     431           0 :                 continue;
     432             :             }
     433             :         }
     434             :         else
     435             :         {
     436             :             // No conversion of the application name necessary.
     437           0 :             aApplications.push_back(eApplication);
     438             :         }
     439             : 
     440             :         // Setup the actual context enum.
     441           0 :         const EnumContext::Context eContext (EnumContext::GetContextEnum(sContextName));
     442           0 :         if (eContext == EnumContext::Context_Unknown)
     443             :         {
     444             :             OSL_FAIL("context name not recognized");
     445           0 :             continue;
     446             :         }
     447             : 
     448             :         // Setup the flag that controls whether a deck/pane is
     449             :         // initially visible/expanded.
     450             :         bool bIsInitiallyVisible;
     451           0 :         if (sInitialState.equalsAscii("visible"))
     452           0 :             bIsInitiallyVisible = true;
     453           0 :         else if (sInitialState.equalsAscii("hidden"))
     454           0 :             bIsInitiallyVisible = false;
     455             :         else
     456             :         {
     457             :             OSL_FAIL("unrecognized state");
     458           0 :             continue;
     459             :         }
     460             : 
     461             :         // Add context descriptors.
     462           0 :         for (::std::vector<EnumContext::Application>::const_iterator
     463           0 :                  iApplication(aApplications.begin()),
     464           0 :                  iEnd(aApplications.end());
     465             :              iApplication!=iEnd;
     466             :              ++iApplication)
     467             :         {
     468           0 :             if (*iApplication != EnumContext::Application_None)
     469             :                 rContextList.AddContextDescription(
     470             :                     Context(
     471           0 :                         EnumContext::GetApplicationName(*iApplication),
     472           0 :                         EnumContext::GetContextName(eContext)),
     473             :                     bIsInitiallyVisible,
     474           0 :                     sMenuCommand);
     475             :         }
     476           0 :     }
     477           0 : }
     478             : 
     479             : 
     480             : 
     481             : 
     482           0 : void ResourceManager::ReadLegacyAddons (const Reference<frame::XFrame>& rxFrame)
     483             : {
     484             :     // Get module name for given frame.
     485           0 :     ::rtl::OUString sModuleName (Tools::GetModuleName(rxFrame));
     486           0 :     if (sModuleName.getLength() == 0)
     487           0 :         return;
     488           0 :     if (maProcessedApplications.find(sModuleName) != maProcessedApplications.end())
     489             :     {
     490             :         // Addons for this application have already been read.
     491             :         // There is nothing more to do.
     492           0 :         return;
     493             :     }
     494             : 
     495             :     // Mark module as processed.  Even when there is an error that
     496             :     // prevents the configuration data from being read, this error
     497             :     // will not be triggered a second time.
     498           0 :     maProcessedApplications.insert(sModuleName);
     499             : 
     500             :     // Get access to the configuration root node for the application.
     501           0 :     ::utl::OConfigurationTreeRoot aLegacyRootNode (GetLegacyAddonRootNode(sModuleName));
     502           0 :     if ( ! aLegacyRootNode.isValid())
     503           0 :         return;
     504             : 
     505             :     // Process child nodes.
     506           0 :     ::std::vector<OUString> aMatchingNodeNames;
     507           0 :     GetToolPanelNodeNames(aMatchingNodeNames, aLegacyRootNode);
     508           0 :     const sal_Int32 nCount (aMatchingNodeNames.size());
     509           0 :     size_t nDeckWriteIndex (maDecks.size());
     510           0 :     size_t nPanelWriteIndex (maPanels.size());
     511           0 :     maDecks.resize(maDecks.size() + nCount);
     512           0 :     maPanels.resize(maPanels.size() + nCount);
     513           0 :     for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex)
     514             :     {
     515           0 :         const OUString& rsNodeName (aMatchingNodeNames[nReadIndex]);
     516           0 :         const ::utl::OConfigurationNode aChildNode (aLegacyRootNode.openNode(rsNodeName));
     517           0 :         if ( ! aChildNode.isValid())
     518           0 :             continue;
     519             : 
     520           0 :         if ( rsNodeName == "private:resource/toolpanel/DrawingFramework/CustomAnimations" ||
     521           0 :              rsNodeName == "private:resource/toolpanel/DrawingFramework/Layouts" ||
     522           0 :              rsNodeName == "private:resource/toolpanel/DrawingFramework/MasterPages" ||
     523           0 :              rsNodeName == "private:resource/toolpanel/DrawingFramework/SlideTransitions" ||
     524           0 :              rsNodeName == "private:resource/toolpanel/DrawingFramework/TableDesign" )
     525           0 :           continue;
     526             : 
     527           0 :         DeckDescriptor& rDeckDescriptor (maDecks[nDeckWriteIndex++]);
     528           0 :         rDeckDescriptor.msTitle = ::comphelper::getString(aChildNode.getNodeValue("UIName"));
     529           0 :         rDeckDescriptor.msId = rsNodeName;
     530           0 :         rDeckDescriptor.msIconURL = ::comphelper::getString(aChildNode.getNodeValue("ImageURL"));
     531           0 :         rDeckDescriptor.msHighContrastIconURL = rDeckDescriptor.msIconURL;
     532           0 :         rDeckDescriptor.msTitleBarIconURL = OUString();
     533           0 :         rDeckDescriptor.msHighContrastTitleBarIconURL = OUString();
     534           0 :         rDeckDescriptor.msHelpURL = ::comphelper::getString(aChildNode.getNodeValue("HelpURL"));
     535           0 :         rDeckDescriptor.msHelpText = rDeckDescriptor.msTitle;
     536           0 :         rDeckDescriptor.mbIsEnabled = true;
     537           0 :         rDeckDescriptor.mnOrderIndex = 100000 + nReadIndex;
     538           0 :         rDeckDescriptor.maContextList.AddContextDescription(Context(sModuleName, OUString("any")), true, OUString());
     539             : 
     540           0 :         PanelDescriptor& rPanelDescriptor (maPanels[nPanelWriteIndex++]);
     541           0 :         rPanelDescriptor.msTitle = ::comphelper::getString(aChildNode.getNodeValue("UIName"));
     542           0 :         rPanelDescriptor.mbIsTitleBarOptional = true;
     543           0 :         rPanelDescriptor.msId = rsNodeName;
     544           0 :         rPanelDescriptor.msDeckId = rsNodeName;
     545           0 :         rPanelDescriptor.msTitleBarIconURL = OUString();
     546           0 :         rPanelDescriptor.msHighContrastTitleBarIconURL = OUString();
     547           0 :         rPanelDescriptor.msHelpURL = ::comphelper::getString(aChildNode.getNodeValue("HelpURL"));
     548           0 :         rPanelDescriptor.msImplementationURL = rsNodeName;
     549           0 :         rPanelDescriptor.mnOrderIndex = 100000 + nReadIndex;
     550           0 :         rPanelDescriptor.mbShowForReadOnlyDocuments = false;
     551           0 :         rPanelDescriptor.mbWantsCanvas = false;
     552           0 :         rPanelDescriptor.maContextList.AddContextDescription(Context(sModuleName, OUString("any")), true, OUString());
     553           0 :     }
     554             : 
     555             :     // When there where invalid nodes then we have to adapt the size
     556             :     // of the deck and panel vectors.
     557           0 :     if (nDeckWriteIndex < maDecks.size())
     558           0 :         maDecks.resize(nDeckWriteIndex);
     559           0 :     if (nPanelWriteIndex < maPanels.size())
     560           0 :         maPanels.resize(nPanelWriteIndex);
     561             : }
     562             : 
     563             : 
     564             : 
     565             : 
     566           0 : void ResourceManager::StorePanelExpansionState (
     567             :     const ::rtl::OUString& rsPanelId,
     568             :     const bool bExpansionState,
     569             :     const Context& rContext)
     570             : {
     571           0 :     for (PanelContainer::iterator
     572           0 :              iPanel(maPanels.begin()),
     573           0 :              iEnd(maPanels.end());
     574             :          iPanel!=iEnd;
     575             :          ++iPanel)
     576             :     {
     577           0 :         if (iPanel->msId.equals(rsPanelId))
     578             :         {
     579             :             ContextList::Entry* pEntry (
     580           0 :                 iPanel->maContextList.GetMatch (rContext));
     581           0 :             if (pEntry != NULL)
     582           0 :                 pEntry->mbIsInitiallyVisible = bExpansionState;
     583             :         }
     584             :     }
     585           0 : }
     586             : 
     587             : 
     588             : 
     589             : 
     590           0 : ::utl::OConfigurationTreeRoot ResourceManager::GetLegacyAddonRootNode (
     591             :     const ::rtl::OUString& rsModuleName) const
     592             : {
     593             :     try
     594             :     {
     595           0 :         const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext() );
     596             :         const Reference<frame::XModuleManager2> xModuleAccess =
     597           0 :             frame::ModuleManager::create( xContext );
     598           0 :         const ::comphelper::NamedValueCollection aModuleProperties (xModuleAccess->getByName(rsModuleName));
     599             :         const ::rtl::OUString sWindowStateRef (aModuleProperties.getOrDefault(
     600             :                 "ooSetupFactoryWindowStateConfigRef",
     601           0 :                 ::rtl::OUString()));
     602             : 
     603           0 :         ::rtl::OUStringBuffer aPathComposer;
     604           0 :         aPathComposer.appendAscii("org.openoffice.Office.UI.");
     605           0 :         aPathComposer.append(sWindowStateRef);
     606           0 :         aPathComposer.appendAscii("/UIElements/States");
     607             : 
     608             :         return ::utl::OConfigurationTreeRoot(xContext,
     609           0 :             aPathComposer.makeStringAndClear(), false);
     610             :     }
     611           0 :     catch( const Exception& )
     612             :     {
     613             :         DBG_UNHANDLED_EXCEPTION();
     614             :     }
     615             : 
     616           0 :     return ::utl::OConfigurationTreeRoot();
     617             : }
     618             : 
     619             : 
     620             : 
     621             : 
     622           0 : void ResourceManager::GetToolPanelNodeNames (
     623             :     ::std::vector<OUString>& rMatchingNames,
     624             :     const ::utl::OConfigurationTreeRoot aRoot) const
     625             : {
     626           0 :     Sequence<OUString> aChildNodeNames (aRoot.getNodeNames());
     627           0 :     const sal_Int32 nCount (aChildNodeNames.getLength());
     628           0 :     for (sal_Int32 nIndex(0); nIndex<nCount; ++nIndex)
     629             :     {
     630           0 :         if (aChildNodeNames[nIndex].startsWith( "private:resource/toolpanel/" ))
     631           0 :             rMatchingNames.push_back(aChildNodeNames[nIndex]);
     632           0 :     }
     633           0 : }
     634             : 
     635             : 
     636             : 
     637             : 
     638           0 : bool ResourceManager::IsDeckEnabled (
     639             :     const OUString& rsDeckId,
     640             :     const Context& rContext,
     641             :     const Reference<frame::XFrame>& rxFrame) const
     642             : {
     643             :     // Check if any panel that matches the current context can be
     644             :     // displayed.
     645           0 :     ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors;
     646           0 :     ResourceManager::Instance().GetMatchingPanels(
     647             :         aPanelContextDescriptors,
     648             :         rContext,
     649             :         rsDeckId,
     650           0 :         rxFrame);
     651             : 
     652           0 :     for (ResourceManager::PanelContextDescriptorContainer::const_iterator
     653           0 :              iPanel(aPanelContextDescriptors.begin()),
     654           0 :              iEnd(aPanelContextDescriptors.end());
     655             :          iPanel!=iEnd;
     656             :          ++iPanel)
     657             :     {
     658           0 :         if (iPanel->mbShowForReadOnlyDocuments)
     659           0 :             return true;
     660             :     }
     661             : 
     662           0 :     return false;
     663             : }
     664             : 
     665             : 
     666             : } } // end of namespace sfx2::sidebar
     667             : 
     668             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10