LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ResourceManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 241 309 78.0 %
Date: 2014-11-03 Functions: 16 18 88.9 %
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 css::uno;
      38             : 
      39             : namespace sfx2 { namespace sidebar {
      40             : 
      41       35350 : ResourceManager& ResourceManager::Instance (void)
      42             : {
      43       35350 :     static ResourceManager maInstance;
      44       35350 :     return maInstance;
      45             : }
      46             : 
      47             : 
      48             : 
      49             : 
      50          84 : ResourceManager::ResourceManager (void)
      51             :     : maDecks(),
      52             :       maPanels(),
      53          84 :       maProcessedApplications()
      54             : {
      55          84 :     ReadDeckList();
      56          84 :     ReadPanelList();
      57          84 : }
      58             : 
      59             : 
      60             : 
      61             : 
      62         168 : ResourceManager::~ResourceManager (void)
      63             : {
      64          84 :     maPanels.clear();
      65          84 :     maDecks.clear();
      66          84 : }
      67             : 
      68             : 
      69             : 
      70             : 
      71       17412 : const DeckDescriptor* ResourceManager::GetDeckDescriptor (
      72             :     const ::rtl::OUString& rsDeckId) const
      73             : {
      74       41848 :     for (DeckContainer::const_iterator
      75       17412 :              iDeck(maDecks.begin()),
      76       17412 :              iEnd(maDecks.end());
      77             :          iDeck!=iEnd;
      78             :          ++iDeck)
      79             :     {
      80       41848 :         if (iDeck->msId.equals(rsDeckId))
      81       17412 :             return &*iDeck;
      82             :     }
      83           0 :     return NULL;
      84             : }
      85             : 
      86             : 
      87             : 
      88             : 
      89       12922 : const PanelDescriptor* ResourceManager::GetPanelDescriptor (
      90             :     const ::rtl::OUString& rsPanelId) const
      91             : {
      92      165364 :     for (PanelContainer::const_iterator
      93       12922 :              iPanel(maPanels.begin()),
      94       12922 :              iEnd(maPanels.end());
      95             :          iPanel!=iEnd;
      96             :          ++iPanel)
      97             :     {
      98      165364 :         if (iPanel->msId.equals(rsPanelId))
      99       12922 :             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         786 : const ResourceManager::DeckContextDescriptorContainer& ResourceManager::GetMatchingDecks (
     129             :     DeckContextDescriptorContainer& rDecks,
     130             :     const Context& rContext,
     131             :     const bool bIsDocumentReadOnly,
     132             :     const Reference<frame::XFrame>& rxFrame)
     133             : {
     134         786 :     ReadLegacyAddons(rxFrame);
     135             : 
     136         786 :     ::std::multimap<sal_Int32,DeckContextDescriptor> aOrderedIds;
     137        7074 :     for (DeckContainer::const_iterator
     138         786 :              iDeck(maDecks.begin()),
     139         786 :              iEnd (maDecks.end());
     140             :          iDeck!=iEnd;
     141             :          ++iDeck)
     142             :     {
     143        6288 :         const DeckDescriptor& rDeckDescriptor (*iDeck);
     144        6288 :         if (rDeckDescriptor.maContextList.GetMatch(rContext) == NULL)
     145        3072 :             continue;
     146        3216 :         DeckContextDescriptor aDeckContextDescriptor;
     147        3216 :         aDeckContextDescriptor.msId = rDeckDescriptor.msId;
     148             :         aDeckContextDescriptor.mbIsEnabled =
     149        3216 :             ! bIsDocumentReadOnly
     150        3216 :             || IsDeckEnabled(rDeckDescriptor.msId, rContext, rxFrame);
     151             :         aOrderedIds.insert(::std::multimap<sal_Int32,DeckContextDescriptor>::value_type(
     152             :                 rDeckDescriptor.mnOrderIndex,
     153        3216 :                 aDeckContextDescriptor));
     154        3216 :     }
     155             : 
     156        4002 :     for (::std::multimap<sal_Int32,DeckContextDescriptor>::const_iterator
     157         786 :              iId(aOrderedIds.begin()),
     158         786 :              iEnd(aOrderedIds.end());
     159             :          iId!=iEnd;
     160             :          ++iId)
     161             :     {
     162        3216 :         rDecks.push_back(iId->second);
     163             :     }
     164             : 
     165         786 :     return rDecks;
     166             : }
     167             : 
     168             : 
     169             : 
     170             : 
     171       10202 : 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       10202 :     ReadLegacyAddons(rxFrame);
     178             : 
     179       10202 :     ::std::multimap<sal_Int32,PanelContextDescriptor> aOrderedIds;
     180      285656 :     for (PanelContainer::const_iterator
     181       10202 :              iPanel(maPanels.begin()),
     182       10202 :              iEnd(maPanels.end());
     183             :          iPanel!=iEnd;
     184             :          ++iPanel)
     185             :     {
     186      275454 :         const PanelDescriptor& rPanelDescriptor (*iPanel);
     187      275454 :         if ( ! rPanelDescriptor.msDeckId.equals(rsDeckId))
     188      380874 :             continue;
     189             : 
     190      163008 :         const ContextList::Entry* pEntry = rPanelDescriptor.maContextList.GetMatch(rContext);
     191      163008 :         if (pEntry == NULL)
     192      155982 :             continue;
     193             : 
     194        7026 :         PanelContextDescriptor aPanelContextDescriptor;
     195        7026 :         aPanelContextDescriptor.msId = rPanelDescriptor.msId;
     196        7026 :         aPanelContextDescriptor.msMenuCommand = pEntry->msMenuCommand;
     197        7026 :         aPanelContextDescriptor.mbIsInitiallyVisible = pEntry->mbIsInitiallyVisible;
     198        7026 :         aPanelContextDescriptor.mbShowForReadOnlyDocuments = rPanelDescriptor.mbShowForReadOnlyDocuments;
     199             :         aOrderedIds.insert(::std::multimap<sal_Int32,PanelContextDescriptor>::value_type(
     200             :                 rPanelDescriptor.mnOrderIndex,
     201        7026 :                 aPanelContextDescriptor));
     202        7026 :     }
     203             : 
     204       17228 :     for (::std::multimap<sal_Int32,PanelContextDescriptor>::const_iterator
     205       10202 :              iId(aOrderedIds.begin()),
     206       10202 :              iEnd(aOrderedIds.end());
     207             :          iId!=iEnd;
     208             :          ++iId)
     209             :     {
     210        7026 :         rPanelIds.push_back(iId->second);
     211             :     }
     212             : 
     213       10202 :     return rPanelIds;
     214             : }
     215             : 
     216             : 
     217             : 
     218             : 
     219          84 : void ResourceManager::ReadDeckList (void)
     220             : {
     221             :     const ::utl::OConfigurationTreeRoot aDeckRootNode (
     222             :         ::comphelper::getProcessComponentContext(),
     223             :         OUString("org.openoffice.Office.UI.Sidebar/Content/DeckList"),
     224          84 :         false);
     225          84 :     if ( ! aDeckRootNode.isValid() )
     226          84 :         return;
     227             : 
     228         168 :     const Sequence<OUString> aDeckNodeNames (aDeckRootNode.getNodeNames());
     229          84 :     const sal_Int32 nCount (aDeckNodeNames.getLength());
     230          84 :     maDecks.resize(nCount);
     231          84 :     sal_Int32 nWriteIndex(0);
     232         756 :     for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex)
     233             :     {
     234         672 :         const ::utl::OConfigurationNode aDeckNode (aDeckRootNode.openNode(aDeckNodeNames[nReadIndex]));
     235         672 :         if ( ! aDeckNode.isValid())
     236           0 :             continue;
     237             : 
     238         672 :         DeckDescriptor& rDeckDescriptor (maDecks[nWriteIndex++]);
     239             : 
     240        1344 :         rDeckDescriptor.msTitle = ::comphelper::getString(
     241         672 :             aDeckNode.getNodeValue("Title"));
     242        1344 :         rDeckDescriptor.msId = ::comphelper::getString(
     243         672 :             aDeckNode.getNodeValue("Id"));
     244        1344 :         rDeckDescriptor.msIconURL = ::comphelper::getString(
     245         672 :             aDeckNode.getNodeValue("IconURL"));
     246        1344 :         rDeckDescriptor.msHighContrastIconURL = ::comphelper::getString(
     247         672 :             aDeckNode.getNodeValue("HighContrastIconURL"));
     248        1344 :         rDeckDescriptor.msTitleBarIconURL = ::comphelper::getString(
     249         672 :             aDeckNode.getNodeValue("TitleBarIconURL"));
     250        1344 :         rDeckDescriptor.msHighContrastTitleBarIconURL = ::comphelper::getString(
     251         672 :             aDeckNode.getNodeValue("HighContrastTitleBarIconURL"));
     252        1344 :         rDeckDescriptor.msHelpURL = ::comphelper::getString(
     253         672 :             aDeckNode.getNodeValue("HelpURL"));
     254         672 :         rDeckDescriptor.msHelpText = rDeckDescriptor.msTitle;
     255         672 :         rDeckDescriptor.mbIsEnabled = true;
     256             :         rDeckDescriptor.mnOrderIndex = ::comphelper::getINT32(
     257         672 :             aDeckNode.getNodeValue("OrderIndex"));
     258             : 
     259             :         ReadContextList(
     260             :             aDeckNode,
     261             :             rDeckDescriptor.maContextList,
     262         672 :             OUString());
     263         672 :     }
     264             : 
     265             :     // When there where invalid nodes then we have to adapt the size
     266             :     // of the deck vector.
     267          84 :     if (nWriteIndex<nCount)
     268          84 :         maDecks.resize(nWriteIndex);
     269             : }
     270             : 
     271             : 
     272             : 
     273             : 
     274          84 : void ResourceManager::ReadPanelList (void)
     275             : {
     276             :     const ::utl::OConfigurationTreeRoot aPanelRootNode (
     277             :         ::comphelper::getProcessComponentContext(),
     278             :         OUString("org.openoffice.Office.UI.Sidebar/Content/PanelList"),
     279          84 :         false);
     280          84 :     if ( ! aPanelRootNode.isValid() )
     281          84 :         return;
     282             : 
     283         168 :     const Sequence<OUString> aPanelNodeNames (aPanelRootNode.getNodeNames());
     284          84 :     const sal_Int32 nCount (aPanelNodeNames.getLength());
     285          84 :     maPanels.resize(nCount);
     286          84 :     sal_Int32 nWriteIndex (0);
     287        2352 :     for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex)
     288             :     {
     289        2268 :         const ::utl::OConfigurationNode aPanelNode (aPanelRootNode.openNode(aPanelNodeNames[nReadIndex]));
     290        2268 :         if ( ! aPanelNode.isValid())
     291           0 :             continue;
     292             : 
     293        2268 :         PanelDescriptor& rPanelDescriptor (maPanels[nWriteIndex++]);
     294             : 
     295        4536 :         rPanelDescriptor.msTitle = ::comphelper::getString(
     296        2268 :             aPanelNode.getNodeValue("Title"));
     297             :         rPanelDescriptor.mbIsTitleBarOptional = ::comphelper::getBOOL(
     298        2268 :             aPanelNode.getNodeValue("TitleBarIsOptional"));
     299        4536 :         rPanelDescriptor.msId = ::comphelper::getString(
     300        2268 :             aPanelNode.getNodeValue("Id"));
     301        4536 :         rPanelDescriptor.msDeckId = ::comphelper::getString(
     302        2268 :             aPanelNode.getNodeValue("DeckId"));
     303        4536 :         rPanelDescriptor.msTitleBarIconURL = ::comphelper::getString(
     304        2268 :             aPanelNode.getNodeValue("TitleBarIconURL"));
     305        4536 :         rPanelDescriptor.msHighContrastTitleBarIconURL = ::comphelper::getString(
     306        2268 :             aPanelNode.getNodeValue("HighContrastTitleBarIconURL"));
     307        4536 :         rPanelDescriptor.msHelpURL = ::comphelper::getString(
     308        2268 :             aPanelNode.getNodeValue("HelpURL"));
     309        4536 :         rPanelDescriptor.msImplementationURL = ::comphelper::getString(
     310        2268 :             aPanelNode.getNodeValue("ImplementationURL"));
     311             :         rPanelDescriptor.mnOrderIndex = ::comphelper::getINT32(
     312        2268 :             aPanelNode.getNodeValue("OrderIndex"));
     313             :         rPanelDescriptor.mbShowForReadOnlyDocuments = ::comphelper::getBOOL(
     314        2268 :             aPanelNode.getNodeValue("ShowForReadOnlyDocument"));
     315             :         rPanelDescriptor.mbWantsCanvas = ::comphelper::getBOOL(
     316        2268 :             aPanelNode.getNodeValue("WantsCanvas"));
     317             :         const OUString sDefaultMenuCommand (::comphelper::getString(
     318        4536 :                 aPanelNode.getNodeValue("DefaultMenuCommand")));
     319             : 
     320             :         ReadContextList(
     321             :             aPanelNode,
     322             :             rPanelDescriptor.maContextList,
     323        2268 :             sDefaultMenuCommand);
     324        2268 :     }
     325             : 
     326             :     // When there where invalid nodes then we have to adapt the size
     327             :     // of the deck vector.
     328          84 :     if (nWriteIndex<nCount)
     329          84 :         maPanels.resize(nWriteIndex);
     330             : }
     331             : 
     332             : 
     333             : 
     334             : 
     335        2940 : void ResourceManager::ReadContextList (
     336             :     const ::utl::OConfigurationNode& rParentNode,
     337             :     ContextList& rContextList,
     338             :     const OUString& rsDefaultMenuCommand) const
     339             : {
     340        2940 :     const Any aValue = rParentNode.getNodeValue("ContextList");
     341        5880 :     Sequence<OUString> aValues;
     342             :     sal_Int32 nCount;
     343        2940 :     if (aValue >>= aValues)
     344        2940 :         nCount = aValues.getLength();
     345             :     else
     346           0 :         nCount = 0;
     347             : 
     348       13188 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     349             :     {
     350       13188 :         const OUString sValue (aValues[nIndex]);
     351       13188 :         sal_Int32 nCharacterIndex (0);
     352       23352 :         const OUString sApplicationName (sValue.getToken(0, ',', nCharacterIndex).trim());
     353       13188 :         if (nCharacterIndex < 0)
     354             :         {
     355        2940 :             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        2940 :                 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       20412 :         const OUString sContextName (sValue.getToken(0, ',', nCharacterIndex).trim());
     370       10248 :         if (nCharacterIndex < 0)
     371             :         {
     372             :             OSL_FAIL("expecting three or four values per ContextList entry, separated by comma");
     373           0 :             continue;
     374             :         }
     375             : 
     376       20412 :         const OUString sInitialState (sValue.getToken(0, ',', nCharacterIndex).trim());
     377             : 
     378             :         // The fourth argument is optional.
     379             :         const OUString sMenuCommandOverride (
     380       10248 :             nCharacterIndex<0
     381             :                 ? OUString()
     382       20412 :                 : sValue.getToken(0, ',', nCharacterIndex).trim());
     383             :         const OUString sMenuCommand (
     384       10248 :             sMenuCommandOverride.getLength()>0
     385         504 :                 ? (sMenuCommandOverride.equalsAscii("none")
     386             :                     ? OUString()
     387             :                     : sMenuCommandOverride)
     388       20916 :                 : 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       20412 :         ::std::vector<EnumContext::Application> aApplications;
     395       10248 :         EnumContext::Application eApplication (EnumContext::GetApplicationEnum(sApplicationName));
     396       20496 :         if (eApplication == EnumContext::Application_None
     397       10248 :             && !sApplicationName.equals(EnumContext::GetApplicationName(EnumContext::Application_None)))
     398             :         {
     399             :             // Handle some special names: abbreviations that make
     400             :             // context descriptions more readable.
     401        9492 :             if (sApplicationName.equalsAscii("Writer"))
     402         756 :                 aApplications.push_back(EnumContext::Application_Writer);
     403        8736 :             else if (sApplicationName.equalsAscii("Calc"))
     404        3192 :                 aApplications.push_back(EnumContext::Application_Calc);
     405        5544 :             else if (sApplicationName.equalsAscii("Draw"))
     406           0 :                 aApplications.push_back(EnumContext::Application_Draw);
     407        5544 :             else if (sApplicationName.equalsAscii("Impress"))
     408        1176 :                 aApplications.push_back(EnumContext::Application_Impress);
     409        4368 :             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        2772 :                 aApplications.push_back(EnumContext::Application_Draw);
     416        2772 :                 aApplications.push_back(EnumContext::Application_Impress);
     417             :             }
     418        1596 :             else if (sApplicationName.equalsAscii("WriterVariants"))
     419             :             {
     420             :                 // Another special case for all Writer variants.
     421        1596 :                 aApplications.push_back(EnumContext::Application_Writer);
     422        1596 :                 aApplications.push_back(EnumContext::Application_WriterGlobal);
     423        1596 :                 aApplications.push_back(EnumContext::Application_WriterWeb);
     424        1596 :                 aApplications.push_back(EnumContext::Application_WriterXML);
     425        1596 :                 aApplications.push_back(EnumContext::Application_WriterForm);
     426        1596 :                 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         756 :             aApplications.push_back(eApplication);
     438             :         }
     439             : 
     440             :         // Setup the actual context enum.
     441       10248 :         const EnumContext::Context eContext (EnumContext::GetContextEnum(sContextName));
     442       10248 :         if (eContext == EnumContext::Context_Unknown)
     443             :         {
     444             :             OSL_FAIL("context name not recognized");
     445          84 :             continue;
     446             :         }
     447             : 
     448             :         // Setup the flag that controls whether a deck/pane is
     449             :         // initially visible/expanded.
     450             :         bool bIsInitiallyVisible;
     451       10164 :         if (sInitialState.equalsAscii("visible"))
     452        8232 :             bIsInitiallyVisible = true;
     453        1932 :         else if (sInitialState.equalsAscii("hidden"))
     454        1932 :             bIsInitiallyVisible = false;
     455             :         else
     456             :         {
     457             :             OSL_FAIL("unrecognized state");
     458           0 :             continue;
     459             :         }
     460             : 
     461             :         // Add context descriptors.
     462       31080 :         for (::std::vector<EnumContext::Application>::const_iterator
     463       10164 :                  iApplication(aApplications.begin()),
     464       10164 :                  iEnd(aApplications.end());
     465             :              iApplication!=iEnd;
     466             :              ++iApplication)
     467             :         {
     468       20916 :             if (*iApplication != EnumContext::Application_None)
     469             :                 rContextList.AddContextDescription(
     470             :                     Context(
     471       20832 :                         EnumContext::GetApplicationName(*iApplication),
     472       20832 :                         EnumContext::GetContextName(eContext)),
     473             :                     bIsInitiallyVisible,
     474       41664 :                     sMenuCommand);
     475             :         }
     476       13104 :     }
     477        2940 : }
     478             : 
     479             : 
     480             : 
     481             : 
     482       10988 : void ResourceManager::ReadLegacyAddons (const Reference<frame::XFrame>& rxFrame)
     483             : {
     484             :     // Get module name for given frame.
     485       10988 :     ::rtl::OUString sModuleName (Tools::GetModuleName(rxFrame));
     486       10988 :     if (sModuleName.getLength() == 0)
     487           0 :         return;
     488       10988 :     if (maProcessedApplications.find(sModuleName) != maProcessedApplications.end())
     489             :     {
     490             :         // Addons for this application have already been read.
     491             :         // There is nothing more to do.
     492       10898 :         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          90 :     maProcessedApplications.insert(sModuleName);
     499             : 
     500             :     // Get access to the configuration root node for the application.
     501         180 :     ::utl::OConfigurationTreeRoot aLegacyRootNode (GetLegacyAddonRootNode(sModuleName));
     502          90 :     if ( ! aLegacyRootNode.isValid())
     503           0 :         return;
     504             : 
     505             :     // Process child nodes.
     506         180 :     ::std::vector<OUString> aMatchingNodeNames;
     507          90 :     GetToolPanelNodeNames(aMatchingNodeNames, aLegacyRootNode);
     508          90 :     const sal_Int32 nCount (aMatchingNodeNames.size());
     509          90 :     size_t nDeckWriteIndex (maDecks.size());
     510          90 :     size_t nPanelWriteIndex (maPanels.size());
     511          90 :     maDecks.resize(maDecks.size() + nCount);
     512          90 :     maPanels.resize(maPanels.size() + nCount);
     513          90 :     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          90 :     if (nDeckWriteIndex < maDecks.size())
     558           0 :         maDecks.resize(nDeckWriteIndex);
     559          90 :     if (nPanelWriteIndex < maPanels.size())
     560          90 :         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          90 : ::utl::OConfigurationTreeRoot ResourceManager::GetLegacyAddonRootNode (
     591             :     const ::rtl::OUString& rsModuleName) const
     592             : {
     593             :     try
     594             :     {
     595          90 :         const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext() );
     596             :         const Reference<frame::XModuleManager2> xModuleAccess =
     597         180 :             frame::ModuleManager::create( xContext );
     598         180 :         const ::comphelper::NamedValueCollection aModuleProperties (xModuleAccess->getByName(rsModuleName));
     599             :         const ::rtl::OUString sWindowStateRef (aModuleProperties.getOrDefault(
     600             :                 "ooSetupFactoryWindowStateConfigRef",
     601         180 :                 ::rtl::OUString()));
     602             : 
     603         180 :         ::rtl::OUStringBuffer aPathComposer;
     604          90 :         aPathComposer.appendAscii("org.openoffice.Office.UI.");
     605          90 :         aPathComposer.append(sWindowStateRef);
     606          90 :         aPathComposer.appendAscii("/UIElements/States");
     607             : 
     608             :         return ::utl::OConfigurationTreeRoot(xContext,
     609         180 :             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          90 : void ResourceManager::GetToolPanelNodeNames (
     623             :     ::std::vector<OUString>& rMatchingNames,
     624             :     const ::utl::OConfigurationTreeRoot& aRoot) const
     625             : {
     626          90 :     Sequence<OUString> aChildNodeNames (aRoot.getNodeNames());
     627          90 :     const sal_Int32 nCount (aChildNodeNames.getLength());
     628        3798 :     for (sal_Int32 nIndex(0); nIndex<nCount; ++nIndex)
     629             :     {
     630        3708 :         if (aChildNodeNames[nIndex].startsWith( "private:resource/toolpanel/" ))
     631           0 :             rMatchingNames.push_back(aChildNodeNames[nIndex]);
     632          90 :     }
     633          90 : }
     634             : 
     635             : 
     636             : 
     637             : 
     638          16 : 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          16 :     ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors;
     646          16 :     ResourceManager::Instance().GetMatchingPanels(
     647             :         aPanelContextDescriptors,
     648             :         rContext,
     649             :         rsDeckId,
     650          16 :         rxFrame);
     651             : 
     652          36 :     for (ResourceManager::PanelContextDescriptorContainer::const_iterator
     653          16 :              iPanel(aPanelContextDescriptors.begin()),
     654          16 :              iEnd(aPanelContextDescriptors.end());
     655             :          iPanel!=iEnd;
     656             :          ++iPanel)
     657             :     {
     658          24 :         if (iPanel->mbShowForReadOnlyDocuments)
     659           4 :             return true;
     660             :     }
     661             : 
     662          12 :     return false;
     663             : }
     664             : 
     665             : 
     666         951 : } } // end of namespace sfx2::sidebar
     667             : 
     668             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10